Commit Graph

770 Commits

Author SHA1 Message Date
bismurphy
c2efce5a9a
Decompile RIC EntityHolyWater (#1016)
There is already EntityHolyWater in DRA, but this one is quite different
(which makes sense, because Richter's is very different in behavior from
Alucard's). Still, there are some small overlaps here and there.

Due to the ongoing failure to match `func_80166784` (the previous
rodata-using function), this is being split out to a new file, even
though I'm pretty sure they're supposed to be in the same file. We will
reunify the files once `func_80166784` can be solved.

There is a function which is identical in the overlays, and is only used
by this function. I have gone ahead and named it identically in both
overlays.
2024-01-31 01:14:14 +00:00
bismurphy
4c4c570ef0
Decompile DRA DrawRichterHudSubweapon (#1013)
This one was tricky and required some restructuring of an area of
memory, but it matches now, so that's cool!

No big comments from me but this one has a lot of random stuff so let me
know if I missed some enum or something!
2024-01-29 16:17:29 -08:00
bismurphy
7ffc733cd8
Decompile RIC EntityHydroStorm (#1011)
Several things with this one.

1) In order to determine what this actually was, I needed to extract
Richter's subweapon definitions. I decided, at least for now, to add
that extraction for RIC, using the `assets.py` script.

2) In order to match this function, we need a new Primitive, which is
similar to the existing one (and FakePrim) but has a few totally
incompatible fields. Most importantly, we have s16's at offsets 0x0C and
0x0E, which don't match either of those. Therefore, I introduce a new
primitive that I am, at least for now, calling PrimLineG2, since this is
the first time we're using LineG2, and is also the first use of this
struct, so those may be connected. If a different primitive is found
using these fields, we can rename this.

3) Recognizing that we now have 3 different varieties of Primitive, I
have taken the definitions for all of them and moved them to a dedicated
`primitive.h`, which I think is a good home for them. We should rename
the variations eventually, but having them in one place makes sense, I
think.

Otherwise, this one is fairly straightforward. It's interesting that we
have the hardcoded values for the color of the hydro storm rain in there
- using this knowledge I have made a fun PR for the randomizer which
randomizes the colors of the rain. That PR is here:
https://github.com/3snowp7im/SotN-Randomizer/pull/121

I think that's about it!
2024-01-29 16:10:09 -08:00
bismurphy
a39bde6127
Decompile RIC UpdateEntityRichter (#1010)
Again, huge thanks to @ser-pounce for figuring out the final puzzle on
this function!

Getting this in and parsing all the rodata before and after meant I
discovered some different file splits, but now it's all set, with no
`const s32 rodata_padding` type of stuff, which is great.

I imagine having this working will be a great resource for learning more
about how Richter works.
2024-01-27 16:20:03 +00:00
Luciano Ciccariello
04c9f49aef
DRA RenderTilemap (#1008)
I've been wanting to match this for a long time. I matched it by pure
coincidence by moving things around. This is one of the few functions
were the permuter was completely useless.

The function renders a room tilemap, with its background and foreground
layers. This is also the first function that uses the PlayStation 1
scratchpad. It took me a few trials to understand how to use it. This
match gives me the confidence to match the much bigger functions
`RenderPrimitives` and `RenderEntities`. They will be my next targets.

I noticed there were a few wrongs in the rendering system. I used one of
the PSY-Q SDK samples to help me understanding how to implement
`PutDrawEnv` and how to render a `SPRT`. The stealth changes in this PR
aims to easily have the tilemap rendering working. The map currently
appears black. This is not a regression, but the lack of logic of
loading a room.
2024-01-25 00:18:29 +00:00
ser-pounce
251531a5e1
Decomp SEL func_801B69F8 (#1007)
This took forever but was great to finally nail down.
2024-01-24 18:34:05 +00:00
Luciano Ciccariello
beea0a07d6
DRE func_801A2C9C (#1006)
While looking into understanding the scratchpad, I ended up decompiling
this function.
2024-01-22 14:57:16 -08:00
Luciano Ciccariello
8eb7795b4f
Decompile some PSX SDK functions (#1002) 2024-01-21 17:58:32 +00:00
Luciano Ciccariello
beb89d55a6
ItemTypes to EquipKind and blendMode to drawMode (#999)
[EquipKind](https://discord.com/channels/1079389589950705684/1087866009983139870/1196073673392652388)
group decision


[drawMode](https://discord.com/channels/1079389589950705684/1087866009983139870/1197935480428302476)
group decision

I was thinking a more soft PR, but in the light of `BLEND_VISIBLE` to
`DRAW_HIDE`, a mass rename would have happened anyway. So I decided to
rename everything since the majority of the code stands on the same line
of `BLEND_VISIBLE`.

The only changes other than the mass rename are:

```c
#define blendMode drawMode // maintained to easily migrate existing scratches
```
this might or not be useful

.

```c
#define DRAW_DEFAULT 0x00
#define DRAW_TRANSP 0x01   // make it semi transparent
#define DRAW_COLORS 0x04   // use color blending
#define DRAW_HIDE 0x08     // do not render the primitive
#define DRAW_TPAGE 0x10    // use custom tpage
#define DRAW_NOMENU 0x80   // do not render if D_800973EC is set
#define DRAW_ABSPOS 0x2000 // use absolute coordinates with DRAW_NOMENU
```
This is based on the research from the
[RenderPrimitives](https://decomp.me/scratch/geI8L) function.
2024-01-20 13:16:03 -08:00
bismurphy
455e18c920
Decompile DRA EntityAlucard (#1000)
This was a community effort relying on the work of myself, @ser-pounce ,
@Xeeynamo , and others. Thanks all for helping to put this together and
it will be very exciting to have such a large and important function in
the repo!

Lots of room for improving this one in terms of code style, but having a
baseline functional version in is huge.
2024-01-20 17:36:01 +00:00
Luciano Ciccariello
9cb02a6974
DRA AnimateNowLoading (#997)
![image](https://github.com/Xeeynamo/sotn-decomp/assets/6128729/59bc485b-53cb-47c6-aa41-f5727d35f825)
2024-01-19 09:24:09 -08:00
bismurphy
29da40b790
Decompile EntityTeleport in RIC and DRA (#996)
These functions both have very difficult functions before them in their
files, so need to split to new files to make the rodata work.

Originally decompiled RIC func_80166060, then once that was done I dug
through the blueprints and realized it matches EntityTeleport, which
made decompiling EntityTeleport an easy task, at which point I renamed
the RIC function to match.

I've also gone through a lot of the functions they call and labeled the
ones that match between overlays; I expect this to be helpful in the
task of identifying names for a bunch more functions.
2024-01-19 15:58:03 +00:00
Luciano Ciccariello
f9ed954c29
EntityStageNamePopup (#994)
Decompile and de-duplicate EntityStageNamePopup for all the overlays the
function is in.

I also detected a helper function I renamed as `PrimDecreaseBrightness`
that was originally accepting a completely wrong parameter type. This
helped me to get rid of `Unkstruct_80128BBC` too.
2024-01-19 03:07:13 +00:00
Luciano Ciccariello
0e29dcc0a5
WRP EntityWarpSmallRocks (#993)
A very old match of mine. I still think it belongs to `6FD0.c` but I had
to split it as I still cannot match `EntityWarpRoom`.
2024-01-18 19:18:49 +00:00
Luciano Ciccariello
81f236f66b
Extract equip icons (#992)
Quick win I had stashed for a while. This is NOT exporting the icons as
PNGs.
2024-01-18 11:09:22 -08:00
Luciano Ciccariello
a5fb6df72c
Deduplicate functions and un-fake use of some Primitive structs (#991) 2024-01-18 19:04:04 +00:00
bismurphy
5bb9e12e22
Decompile DRA func_8011B5A4 (#990)
Progress on RIC has been hugely beneficial for solving some old DRA
functions. I'm going to start going through all the entities and try to
identify all of the ones that are in common between the two. I tried
this one in DRA a long time ago, but once I identified the
correspondence between these two functions, having the RIC version
available made things a HUGE amount easier.

One very important thing in the analysis of these functions: Take a look
at the RIC version, func_80160FC4:
https://github.com/Xeeynamo/sotn-decomp/blob/master/src/ric/24788.c#L260

The first thing the function does is it loads paramsLo and paramsHi.
Then there is an if-statement which takes paramsHi into account.

But in this new function, those variables aren't given values until the
switch statement. This means that in the if-statement, paramsHi is not
initialized and will be undefined. I believe this is a bug, but would
like to hear someone else's thoughts before giving it an official bug
label.
2024-01-18 10:53:57 -08:00
bismurphy
6837cbfedc
Decompile DRA and RIC EntityHitByLightning (#988)
Working in parallel on these two overlays has been hugely beneficial, I
think I will continue to try to do things this way.

I don't think I have any major comments besides that. This code required
more fake stuff than usual in order to make registers agree.
2024-01-18 09:59:41 +00:00
bismurphy
7ddf0a7f31
Decompile RIC and DRA EntityHitByIce (#987)
Originally decompiled this for RIC, then in the process of figuring out
what this entity was, I realized it was a duplicate of one in DRA which
was already named EntityHitByIce. Therefore, I have gone ahead and
decompiled it for DRA as well.

I think there are a whole lot more functions that are duplicated between
RIC and DRA, but there are enough subtle differences that the
duplicate-finder script misses them.

Because of the close relation between this and AlucardHandleDamage and a
previously-unnamed RIC function, I have named that function
RichterHandleDamage to match.
2024-01-17 08:50:56 +00:00
bismurphy
3a8fd22bb4
Decompile DRA AlucardHandleDamage (#985)
This is a pretty big one!

There are a lot of unknown SFX entries, I'll leave that as a future
thing to work out what all the hex codes for the sounds are.

Pulling in the rodata gave the usual mismatch with 00 bytes, so I moved
the following C file into this one.

Several other changes here and there, this is a fairly large commit so
please be sure to examine it carefully.
2024-01-16 23:05:47 +00:00
sozud
23a143b295
Mark SEL handwritten functions as asm (#977) 2024-01-14 11:27:34 -08:00
Luciano Ciccariello
025dc35e2c
Extract config_jp from DRA HD (#976)
I need help on this pull request. While it matches as it is, I cannot
decode the Japanese strings from bytes to UTF-8 convertible into
Shift-JIS into a C file that is able to give me an `OK`. I think the
problem lies on how Python decodes Shift-JIS byte arrays.

I [wrote a
tool](https://gist.github.com/Xeeynamo/d75c73431eaf54b42f955ca8740bb754)
to automate the process:
```bash
python3 sotn_config.py > src/dra/config_jp.c && make
```

To extract some of the strings as Shift-JIS, uncomment the first line at
the function `get_sjis_str`. I am tempted to make a custom decoder. But
first I want to gather your insight in case I am missing something
obvious.
2024-01-14 10:00:10 -08:00
Luciano Ciccariello
c539d3be9a
DRA AddToInventory (#978)
It took me over a year to understand this one.
2024-01-14 09:52:36 -08:00
Luciano Ciccariello
930fcf4a81
Menu sound fix (#981)
Imports the `D_800C1ECC` table straight into `953A0.c`, so
`ApplyQuadChannelSetting` can populate the fields correctly.

Also removes a fake symbol from `menu.c`, which allows to access the new
merged `g_ChButton` array correctly. This fixes the _"Button Settings"_
sub-menu in _"System"_
2024-01-14 09:23:13 -08:00
Luciano Ciccariello
aa78e31920
DRA func_800F2288 (#979)
The function is not referenced anywhere other than by being exported in
`GameAPI`. I suspect only the LIB overlay uses it. I added a comment
speculating what the function might be about.
2024-01-14 09:20:51 -08:00
bismurphy
ef86fd2b45
Refactor DRA func_800FD5BC (#980)
Came across this function today and found several improvements for it.

- Unkstruct_800FD5BC is a duplicate of DamageParam. Therefore, I have
changed all instances of Unkstruct_800FD5BC to DamageParam. The fields
make sense in context and everything.
- Because func_800FD5BC is in GameApi, which is defined in `game.h`, its
argument (now a DamageParam) needs to be accessible in `game.h`.
Therefore, DamageParam moves from dra.h to game.h.
- We had a fake division being done with using a `temp` and checking a
comparison to zero; this has been changed to be a normal division. This
is a common pattern I see in initial m2c output and I'm sure it exists
in other places in the repo, would be nice if we could find an automated
way to search for this type of structure to simplify the code.
- Changed a 0x14 to 20 since it makes way more sense that way
- Changed an `if(){dostuff; return} else{morestuff}` to just
`if(){dostuff; return} morestuff`, eliminating the `else`

I think this function should not be in `menu.c` since it has no close
connection to any kind of menu. It would also be nice if we could figure
out what damageKind actually is, and maybe make an enum for it.

Overall, no new decompiling here, but lots of improvement to the
readability of the code. This might actually be a good PR to keep in
mind as an example for people who are interested in the project but
aren't comfortable with assembly, since this is a lot of improvement and
change, without touching assembly at all.
2024-01-14 16:37:35 +00:00
ser-pounce
ba34bcfb31
RWRP related deduping and refactoring (#975)
Some deduping and renaming that might help later

- Dedupe DestroyEntity
- Dedupe ST EntityIsNearPlayer
- Dedupe DestroyEntitiesFromIndex
- Dedupe ST CollectHeart
- Dedupe ST UnkEntityFunc0
- Decompile + rename rwrp EntityExplosionSpawn
2024-01-13 11:40:56 +00:00
bismurphy
3575871485
Decompile RIC StopwatchCrashDoneSparkle (#967)
Comment describes what this function is for. I identified it by setting
a breakpoint in an emulator and waiting for it to trigger, then verified
by NOP-ing it out.

Here is a screenshot of the sparkle appearing: 

![image](https://github.com/Xeeynamo/sotn-decomp/assets/15314202/d071e946-b012-4878-a050-41ada78fe2bc)

This is the last function using rodata in 32324.c. However, once I
decompiled it and did the normal rodata steps, I had a mismatch of `00
00 00 00` bytes, which signalled that this should not be the end of the
file. Therefore, I pulled 345EC.c into this file, which now matches.

Function scratch is here: https://decomp.me/scratch/PSKCu
2024-01-11 20:25:45 +00:00
bismurphy
be8eb7f39e
Improve handling of DRA and RIC entity tables (#966)
My main goal was to extract the .data for the table in RIC, but while I
was doing that, I also decided to clean things up a bit, so now:

- Both tables have proper names
- Both tables have all the entities forward-declared in the proper .h
file
- Attempted to remove all repeated forward-declarations in the .h file,
not sure if I got them all

Overall this should improve readability and should be pretty close to
how I would expect the original game to have done it.
2024-01-11 18:14:01 +00:00
bismurphy
0f0827ec20
Remove file split in RIC (#961)
I noticed that there was a mismatch in the rodata where a set of 4 `00`
bytes was being skipped, and those indicate that these should be the
same file.
2024-01-10 16:37:01 -08:00
Luciano Ciccariello
6b9519841e
SEL export palette data (#962)
It would be cool one day to look into how exporting palette data as a
modifiable asset. Until then, take a load of arrays.
2024-01-10 22:39:13 +00:00
bismurphy
90f210367b
Extract RIC factory blueprints (#959)
Adjusts the splat to extract these blueprints the same as the DRA ones,
and also adjusts `assets.py` to work with assets besides those in DRA.
2024-01-10 17:52:14 +00:00
sozud
587980e896
Extract DRA VH and VB files (#956)
The VH files are followed by SEQ data, but it's not aligned by 4 so not
sure how to extract it.

```
1A07C aPqes_1
1C37D aPqes
1CAC3 aPqes_0
```
2024-01-09 15:06:31 -08:00
bismurphy
9426820831
Decompile DRA func_80135D8C (#957)
The last of those remaining sound functions. Very weird and confusing,
and does bizarre things with pointers. But it matches.
2024-01-09 22:09:08 +00:00
bismurphy
21a8549eb0
Decompile DRA func_801327B4 (#955)
One of those last remaining sound functions. The assembly for this one
was complicated but it's nice to see the C come out fairly nice.
2024-01-09 17:53:02 +00:00
bismurphy
945cfdaab9
Decompile DRA func_8013572C (#954)
This is one of the few remaining sound functions.

It calls `ApplyQuadChannelSetting` and `func_80135624` in extremely
similar ways, so I've adjusted the arguments to those functions so they
match. `func_80135624` should probably get its own name which is similar
to `ApplyQuadChannelSetting`, but I don't know enough about these
functions to actually tell what it's doing.
2024-01-08 22:51:03 -06:00
bismurphy
1479f4eaa8
Decompile DRA func_80136010 (#943)
One of the few remaining DRA functions.

Some of the code here seems fake, but it matches so I'm going with it. I
tried to change all the pointers to use the loop indexing but it didn't
work. Might have been written by a coder who was more comfortable
working with pointers than with loops.
2024-01-08 15:50:03 -05:00
Luciano Ciccariello
dfecba007f
DRA DecompressData (#953)
This function was over 1 year old. I finally managed to match it today.
2024-01-08 18:34:30 +00:00
Luciano Ciccariello
819e91c77b
SEL import banks and fix headers (#951) 2024-01-07 20:41:47 +00:00
Luciano Ciccariello
e3ecdb1d0f
SEL config_us.c (#950)
Simple PR that aims to re-use the same `config_us` file from #948 but
for SEL. The file is de-duplicated since it is identical.

The file `lba_stage` has to be split again since in DRA it comes before
`config_us` but in SEL it comes after. That indicates it could have been
a stand-alone file.

I also imported the exp table responsible for levelling up.
2024-01-07 16:41:18 +00:00
Luciano Ciccariello
181f715ff2
DRA assets config (#948)
Creates the file `config_us.c` with all the configuration needed for the
game to know where to locate files in the disc (previously
`lba_stage.c`), equipments, accessories, menu strings (previously
`lang_us.c`, , spells, relics and enemy structures. There is also an exp
table for levelling up but I did not import it yet.

This is a major change in the codebase on how we handle assets.
Previously they were exported as JSON in `assets/dra`. The main problem
is that strings were not properly compiled, still relying on hardcoded
offsets expected to be found in the `.rodata` section.

I deducted all those information belong to a single C file because the
same strings in rodata were referenced from equipment to enemies. If
those strings are found in the same C file, the compiler will optimise
duplicated strings by de-duplicating them. This is how I reached the
conclusion of having all those definitions in a single file.

Obviously the major pain point of this is that a JSON was much more
declarative and easy to be consumed. Especially if tools were going to
use those files. Counting the commas with the struct definition on the
side is not the best thing for modding.

I had to comment out the HD `lba_stage` as it would require a major work
to support the Japanese text.
2024-01-07 02:28:34 +00:00
Luciano Ciccariello
c0840259c8
SEL import code data&rodata (#947)
I had to merge `2C048.c`, `2D260.c` and `2EED8.c`. The hint was in a
string that had to be in `2C048.c` but it was also used in the other two
files. I couldn't still merge this with `33164.c` due to the same
problem I described in #946 .

EDIT: I kept importing more data. SEL also contains its own `lba_stage`,
but some offsets and OVL size are out of sync compared to DRA. I have
the suspect the table was manually maintained, unlike our _"top class
engineering"_
2024-01-06 16:26:09 +00:00
Luciano Ciccariello
17daabb254
SEL func_801B3A94 (#946)
I spent some time trying to merge `2EED8` and `33164` as the rodata
seems to suggest it. But there is a weird 4-bytes padding that is added
when the file split does NOT happen. If you want to have a look before
merging this, please do.
2024-01-06 11:02:41 +00:00
ser-pounce
5eb58a48ce
Decompile SEL func_801B3164 (#945)
Another one down thanks to @Xeeynamo!
2024-01-05 08:57:55 +00:00
ser-pounce
1a54079b62
Dedupe AdjustValueWithinThreshold (#942)
Credit to ChatGPT for helping my ape brain understand what this
function actually does...
2024-01-02 15:24:38 -05:00
ser-pounce
89cdcbfda3
Decompile NO3 EntityUnkId15 & dedupe EntityUnkId15Spawner (#941)
- Decompile NO3 func_801C8C84
- Dedupe EntityUnkId15Spawner (+ some entity enum normalization)
2024-01-02 11:08:30 -05:00
ser-pounce
de2ca461a5
Dedupe ST func_8018D8F0 (#935)
- Decompile NP3 func_801CDF1C
- Tiny refactor
- Dedupe ST func_8018D8F0
2024-01-01 19:54:13 +00:00
Luciano Ciccariello
d599bad642
SEL func_801B2108 (#930)
99% similar to `func_800F99B8` from DRA. The only difference is that a
third parameter that sets `var_s4` is missing.
2023-12-31 21:28:04 +00:00
Luciano Ciccariello
4b9db58076
Import cd data (#927)
and resolving some fake symbols
2023-12-31 15:55:32 +00:00
Luciano Ciccariello
322222adfe
Import LBA data (#922)
This is a historical W.I.P. that held me back due to some dirty bytes in
the US version. It is now done.

I renamed the file to `lba_stage.c` as I plan to add another file called
`lba_bin.c` right after this PR.

To quickly build the HD LBA, which is very different, I wrote a quick
script to duplicate and patch the US one:

```python
def s16(f):
    return int.from_bytes(f.read(2), byteorder='little', signed=False)

def s32(f):
    return int.from_bytes(f.read(4), byteorder='little', signed=False)
    
with open("disks/pspeu/PSP_GAME/USRDIR/res/ps/hdbin/dra.bin", "rb") as f:
    f.seek(0x3C50)
    for i in range(0, 0x50):
        print(f"0x{s32(f):04X}, 0x{s32(f):04X}, 0x{s32(f):05X}, 0x{s32(f):04X}, 0x{s32(f):04X}, 0x{s32(f):05X}, 0x{s32(f):04X},")
        s32(f)
        s32(f)
        s32(f)
        s32(f)
```

---------

Co-authored-by: sozud <122322823+sozud@users.noreply.github.com>
2023-12-31 15:44:56 +00:00