1814 Commits

Author SHA1 Message Date
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
ser-pounce
1c0debf74d
Decompile NO3 func_801CC820 (#937)
Surrounding code also seems to use the same entity struct
2024-01-01 16:28:02 -05:00
Luciano Ciccariello
8af8569e75
SEL func_801B78BC (#936)
Quick win. It is obviously inspired by #926 , so thanks @ser-pounce to
have decompiled that function!
2024-01-01 15:57:53 -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
ser-pounce
87835ffb04
Decompile NP3 func_801CDF1C (#933)
Previously attempted by @sonicdcer https://decomp.me/scratch/CMSl2.

I'm not sure the signature for func_801CDD80 is correct, which led me
down this rabbit hole. It matches, but there's a lot of ugliness going
on, I'm not sure if `arg1` has the correct type, or that `GH_Props` is
the right struct to access..
2024-01-01 19:42:16 +00:00
bismurphy
0513b639e4
Decompile RIC func_8016F198 (#928)
This one is pretty weird, there are a whole bunch of temp variables that
I couldn't figure out how to solve.

There are 8 blocks which set a variable, capped between 0 and an upper
limit (0xF0 or 0xFF). For the upper limit, I have created a `MIN()`
macro. I tried to make a `CLIP()` which would handle both limits in one
macro, but couldn't create one that would match.

Scratch here if anyone can improve things:
https://decomp.me/scratch/fY8js
2024-01-01 11:00:48 -05:00
ser-pounce
7aac720708
Decompile NZ0 func_801C0A3C (#932)
Already 99% complete by @sonicdcer and @Xeeynamo on decomp.me, match was
completed by copying func_801C090C.
2024-01-01 14:44:43 +00:00
Luciano Ciccariello
fcf49bfc06
SEL func_801B4C68 (#931) 2023-12-31 23:05:15 +01: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
d45cb9c8d3
Fix func_8011A870 (#929)
I was casually browsing this file and I found some potential
improvements for this function.
2023-12-31 15:48:00 -05:00
ser-pounce
1445e1a3b6
Decompile ST0 func_801B11E8 (#926) 2023-12-31 12:05:50 -05: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
bismurphy
57a99f25a6
Decompile RIC func_8016E9E4 (#925)
This required an update to maspsx, so that update is also included as
part of this PR.
2023-12-31 15:08:02 +00:00
ser-pounce
bbf8be1e4b
dedupe FindFirstUnkPrim2 (#924)
Sorry for the unimaginative function name, not really sure what it's for
yet. Pulled into the existing header as these two functions always
appear together. Slightly refactored the function.
2023-12-31 14:55:12 +00:00
ser-pounce
315bb17310
Decompile ST0 func_801B0414 (#923)
Slightly ugly (including the return type), but it's the best of a bad
bunch of alternatives so far.
2023-12-31 14:24:38 +00:00
ser-pounce
456e076265
Dedupe DestroyEntity (#920)
Needs a little macro magic to work with DRA, unless there's a better way
of doing this?
2023-12-31 10:54:07 +00:00
ser-pounce
a46a70b251
Dedupe SetTexturedPrimRect (#921)
config/symbols.us.ric.txt change unrelated
2023-12-31 10:25:30 +00:00
sozud
437a970d6e
SpuVmSetProgPan (#919)
https://decomp.me/scratch/fimdr
https://decomp.me/scratch/SNovV
2023-12-31 09:34:45 +00:00
bismurphy
c41176bfc5
Decompile DRA EntityStopWatchExpandingCircle (#918)
Realized this matches a function in RIC, so this PR decompiles the DRA
version, and also renames the RIC version to match.
2023-12-30 14:29:02 -05:00
bismurphy
cfd20eb437
Decompile RIC func_80162870 (#917)
Keeping them coming, nothing notable about this one.
2023-12-30 13:25:19 -05:00
bismurphy
bc2da02023
Decompile RIC func_80161FF0 (#916)
Some entity, don't know what. There seem to be a lot of entities that
just use 7C and 7E from the `ext`, might be something we think about
unifying in the future.
2023-12-30 13:16:09 -05:00
bismurphy
e649812bd6
Decompile RIC func_8016147C (#915)
Similar to an existing DRA function, which is noted.
2023-12-30 11:36:45 -05:00
sozud
b3160407b5
_spu_FiDMA (#914)
Trying the remaining one from this again
https://github.com/Xeeynamo/sotn-decomp/pull/859
https://decomp.me/scratch/ergMa
2023-12-30 11:24:22 -05:00
sozud
2d2eb200f1
SsSetTickMode, add jpt splits (#911)
https://decomp.me/scratch/N9Af7
2023-12-30 08:57:44 +00:00
Luciano Ciccariello
22c86430ea
Add File specific funcs (#898)
I am not sure if we want to use this pattern. Here I am proposing to
wrap functions to open files and read the entirety of a file.

The objective is to avoid performing sanity checks for `fopen`, `fread`
and `malloc`, other than ensuring allocated resources are correctly
de-allocated on both happy and unhappy paths.

How it works is the first parameter is always the callback, while
starting from the second are all the parameters necessary to instantiate
and allocate the resources to be passed to the callback.
2023-12-30 08:54:50 +00:00
bismurphy
00269c82fc
Decompile RIC func_80160FC4 (#913)
Credit to @ser-pounce for some of the variable names here; apologies to
them for the overlap on decompiling the same function.
2023-12-29 23:32:32 -05:00
bismurphy
65a9a413bf
Decompile RIC EntityEntFactory (#912)
Found this function in RIC, it's very similar to the one in DRA, which
is nice.

Patterns of zeros in the rodata indicated that this should be the start
of a new file, which also makes sense since CreateEntFactoryFromEntity
comes with it.

RIC has its own array of blueprints, I'll probably add that to the splat
later on but that seems like material for a separate PR. For now we
focus on the entity function.
2023-12-29 20:09:52 -05:00