Commit Graph

1841 Commits

Author SHA1 Message Date
Luciano Ciccariello
ac23ea7c87
Link player-related functions (#983)
This hits new functions that can help us to de-fake more symbols with
address-sanitizer
2024-01-14 23:30:58 +00:00
sozud
23a143b295
Mark SEL handwritten functions as asm (#977) 2024-01-14 11:27:34 -08:00
bismurphy
faaa160129
Adjust analyze_calls to work with handwritten asm functions (#982)
As requested in https://github.com/Xeeynamo/sotn-decomp/pull/977.
2024-01-14 10:14:53 -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
Luciano Ciccariello
2f376b66f9
Fix load of ST/SEL/F_SEL.BIN (#972)
The file is 192KB long. Yet on PSX it seems the game still wants to load
256KB of it. Obviously that only works there where the memory is
unprotected.

There are two other crashes happening at `func_801B1FD8` and
`func_801B2108`. The first one is triggered by `func_801ACF7C` and it
seems to be related to the termination character. The second I have no
idea.

To skip `SEL` and boot straight to WRP, go to `sim_pc.c` and comment the
following lines:
```c
        case STAGE_SEL:
            InitStageSel(&g_api.o);
            break;
```
2024-01-14 14:48:33 +00:00
sozud
d37a9cc33f
SsVabTransBodyPartly (#974)
One of the functions missing from sound_rev
https://decomp.me/scratch/gKUqV
2024-01-13 09:22:23 -08: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
9ba253f776
Decompile RIC EntityShrinkingPowerUpRing (#973)
Happy to rename this one but this is the best I came up with.

This is the entity function for the faint rings that appear around
Richter in two cases. 1: When he gets saved by Maria after dying in the
prologue, and 2: When he powers up for the flame-whip ability when you
press triangle without a subweapon.

Here is a screenshot of the former case: 

![image](https://github.com/Xeeynamo/sotn-decomp/assets/15314202/3719d784-c30c-4c4f-8d51-6662fbb93d5f)

This is actually 4 instances of the ring, nested within each other. I'll
be honest, I never even noticed this existed. This is a huge amount of
code for something so minor.
2024-01-12 22:56:39 +00:00
Luciano Ciccariello
5e42781c29 Fix Saturn CI 2024-01-12 17:57:19 +00:00
Luciano Ciccariello
ba759764e6 Fix Saturn build on the CI 2024-01-12 17:49:47 +00:00
Luciano Ciccariello
a0087f4c3e The flag order matters 2024-01-12 17:38:08 +00:00
Luciano Ciccariello
5f150a649a Update CI with latest fix 2024-01-12 17:36:24 +00:00
Luciano Ciccariello
c43fce4034 Simplify dependency extraction process 2024-01-12 17:34:42 +00:00
Luciano Ciccariello
266846ba84
Add macOS agent to the CI (#968)
`AppleClang` has `-Wimplicit-function-declaration` and `-Wreturn-type`
defined by default. I had to disable them to have parity between
non-Apple default compiler flags.
2024-01-11 14:46:35 -08:00
bismurphy
d65e7ed6c9
Use FACTORY() for all RIC factory calls (#970)
Went through all the current calls to `CreateEntFactoryFromEntity` in
RIC and changed them to use the proper `FACTORY()` syntax. This is
extremely helpful for finding where entities are created since they're
much more searchable.
2024-01-11 22:40:45 +00:00
Luciano Ciccariello
b6614950f9
Flip new implementation of INCLUDE_ASM (#969)
The new `INCLUDE_ASM_NEW` was a test when I decided to slowly import DRA
HD. It essentially removes the need of specifying `asm/us` or `asm/hd`.
which is dictated by `VERSION` found in `include/common.h`.

This PR make the use of `INCLUDE_ASM_NEW` the default. To fall to the
old behaviour, `INCLUDE_ASM_OLD` is required. This is only used by the
overlay MAD, which sets `VERSION` as `beta`.
2024-01-11 22:16:18 +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
Luciano Ciccariello
deefeb4893
Link stage SEL (#963)
This depends from #962 . 

Without `func_800EA7CC` being decompiled, past the title screen you will
be welcomed with a black screen. Using the [non matching
scratch](https://decomp.me/scratch/dlQDD) will work. The input works
regardless the black screen. Getting past the name selection screen
there is a crash at `SetReleaseRate1` due to `D_80138FB4` being `NULL`.
Getting past it you will get another crash at `HandleVideoPlayback` but
I neither investigated on it or tried what's beyond that.

There is a divergence between the Make and CMake. For some reason the
build from CMake gives a black screen. I am not able to detect where the
issue is. I get no warnings or errors. I noticed `g_MegaMenuStrBuffer`
gets full much faster in the CMake build. It might due to a silly size
of any of the atomic C types. It needs further investigation.
2024-01-11 20:13:33 +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
Luciano Ciccariello
12357071c2
Fix clang compilation errors (#964)
It still complains on 🍎 due to the missing SDL header. Doing `brew
install SDL2` does not fix the issue. I think it would eventually be
beneficial to add a macOS agent to the CI.
2024-01-11 09:23:41 +00:00
sozud
558a79d2eb
Load sfx data (#965)
This loads the sfx data from the json and fixes a couple of places with
missing return values that can cause infinite loops.
2024-01-11 09:07:52 +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
sozud
e2212755b6
Load VB,VH files, fix memory bugs (#958)
This turns on address sanitizer, prevents a bunch of memory corruption
bugs, and loads the VB/VH files.
2024-01-10 16:34:12 -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
Luciano Ciccariello
9ae1ffec21
Remove the use of UnkStructClut (#960)
Rewrites SEL's `banks.c` to use an array of `u_long` and make use of
declarations to populate it.

This PR comes after giving up at believing the original developers would
had the decency of using structs instead of crude array of data. They
are really developers from another era.
2024-01-10 19:47:15 +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
ser-pounce
e7d3630183
Decompile SEL func_801B519C (#952)
One annoying `do { } while (0);` left but it matches.
2024-01-07 13:35:40 -05: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
f804dcaa1d
Decompile SEL func_801ADF94 (#944)
Co-authored-by: Luciano Ciccariello <Xeeynamo@users.noreply.github.com>
2024-01-04 08:57:47 +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
c55faf5994
Decompile NO3 func_801CC5A4 (#940) 2024-01-02 10:23:45 +00:00
Luciano Ciccariello
71b086e8b2
Add stage dummy (#939)
Last test app specific PR for a few days. This adds a dummy stage that
gets loaded by `InitStageDummy`. It does very similarly what the game
does by copying the exported stage functions into `g_api.o`. The new
entrypoint is now `InitRoomEntities`.

The dummy stage loads some assets from WRP. The stage layout and tileset
are loaded in-memory. I created a very barebone `RenderTilemap` to draw
the foreground without any scrolling implemented. I am not sure why the
HUD is only showing when entering in the menu and it's black.

There is a hack job in the dummy stage to skip the SEL overlay and ask
the game to load WRP. Choosing WRP is purely arbitrary as any stage but
SEL would result to the same behaviour.

This is a bit of a memory hog. I introduced a memory pool instead of
using `malloc` for the assets loaded dynamically. The dummy stage will
not stay here for long, so I do not find useful to optimise it.

<img width="263" alt="image"
src="https://github.com/Xeeynamo/sotn-decomp/assets/6128729/4c0c0ed9-ddca-4f5b-a35d-a3fe0f8ababa">
2024-01-02 09:22:44 +00:00
ser-pounce
d2be148d68
Decompile NO3 func_801CC6F8 (#938) 2024-01-02 00:56:41 +00:00
Luciano Ciccariello
0df33d1975
Texture render support (#934)
Technically unimpressive, but I had to go through quite a good amount of
changes. Here is the full changelog to make everything work:

* Ensure `ResetPlatform` is always called to avoid memory leaks
* Add `g_RawVram` to emulate the PS1 VRAM
* ~~The engine will load the optional file `disks/vram.bin`, a RAM dump
from an emulator~~
* SDL2 will create 256x256 textures on-the-fly whenever a specific tpage
is requested via `GetVramTexture`
* The function `GetVramTexture` caches the last called tpage to avoid
tanking the performance
* `GetVramTexture` for only renders 4bpp and 8bpp textures with their
specified palette
* Remove `SDL2_image` as the font is now loaded straight from the VRAM
* Calling `VSync` will call the set callback, which the game uses for
DMA operations
* `MyLoadImage` is not yet implemented, but it is a placeholder to then
interact with `g_RawVram`
* The menu font now uses the texture found in the VRAM
* Plugged a custom version of `LoadFileSim`
* The file `sim_pc.c` is similar to the original game's code but it is
used here to load files from custom paths
* Using F5, F6 or F7 can dump the VRAM content on-screen, respectively
in 16bpp, 8bpp and 4bpp

There are new graphical glitches on the font. In some occasions it
appears black. It seems to be related to a flag in `P_TAG.code`. I plan
to dig into it when I can render entities on screen to avoid potential
mistakes. The same problem is present for the first half of Alucard's
portrait. It seems to be related when a texture is transparent? 🤷

I am not sure why the font is completely corrupted when entering in the
Equip menu. It is hard to understand if I introduced any regression.
Maybe the glitch was always there but it was hidden since I was always
forcing the font texture to be rendered.

EDIT: Implemented `LoadImage`, `SaveImage` and `ClearImage`
2024-01-01 23:31:56 +00:00