Commit Graph

2094 Commits

Author SHA1 Message Date
bismurphy
f04950a94f
Decompile MAD TestCollisions (#1191)
This should finish out the set :)

Can't say I understand the differences here (it's modifying
g_CastleFlags during the item drop randomization routine for crying out
loud) but hey, a match is a match.
2024-05-27 16:15:14 +01:00
bismurphy
c71ab44fdd
Decompile ST0 TestCollisions (#1190)
Got this one done too! ST0 is slightly simpler than the others.

I tried to adapt the existing matching TestCollisions directly, but I
found that it was easier to work on PSP to get the logic right and then
move to PSX instead.
2024-05-27 15:30:02 +01:00
sozud
c7ddd8281b
Wrp funcs 1 (#1188) 2024-05-27 10:06:22 +01:00
bismurphy
205f0e2156
De-duplicate TestCollisions (#1187)
I think I did this right, but this is my first time de-duplicating a
function, so please point out any mistakes :)

ST0 not included because it has different logic internally - will work
on decompiling that one next.
2024-05-27 10:04:31 +01:00
bismurphy
86af165e69
Decompile NP3 TestCollisions (#1186)
Well here we are, TestCollisions matching!

I'm going to start with this one, and once it's in, I will follow up by
de-duplicating it.

Please review this closely, especially the changes that are happening in
other files than the main C file.

I suspect we will learn a lot from studying this function; I've already
made some changes (including to the Entity struct) but there will surely
be more.

Nice that this was possible with only two `goto` statements.

I expect a fair bit of revision here, especially related to any
enums/defines I might not be aware of. Please be liberal with comments
:)
2024-05-26 20:30:40 -04:00
Luciano Ciccariello
88f221fb1f
ST WRP PSX re-organise C files (#1185)
Same as #1181 but on PSX. The imported data falls right at the top of
each new file based on some old assumptions of mine, suggesting we're
probably on the right track.
2024-05-26 23:44:33 +01:00
sozud
cd87f4da0a
WRP PSP ReplaceBreakableWithItemDrop and more (#1184) 2024-05-26 22:29:34 +01:00
sozud
17a6647538
WRP PSP func_8018C1E0 (#1183) 2024-05-26 21:14:27 +01:00
sozud
495e975952
WRP PSP func_8018CAB0 (#1182) 2024-05-26 21:06:41 +01:00
Luciano Ciccariello
92812cc6c9
ST WRP re-organise C files (#1181)
A massive PR, I know. It's the smallest change I could do to make this
happen.

After comparing the function order from both ST/WRP PSX and ST/WRP PSP,
I was able to come up with a file split much different from the one
suggested from Splat. It still returns an 🆗 and it follows the same
group functions order from the two game builds.

As soon as we are on board with the C names, next PR will be to do the
same with the PSX overlay. Then in another PR we will be able to start
merging the C files between the two builds. Ideally the same approach
can be used for sharing C files across the different overlays instead of
relying to floating header files in `src/st`
2024-05-26 20:59:07 +01:00
sozud
2073f27ed0
WRP PSP UpdateRoomPosition (#1180) 2024-05-26 20:47:27 +01:00
sozud
c0222b4a92
CollectHeartVessel (#1179) 2024-05-26 20:44:22 +01:00
Luciano Ciccariello
fdb4b11359
PSP WRP functions (#1178)
A bunch of functions where I am using the shared headers whenever I
could. The plan is to switch into C files on the first good opportunity.
2024-05-26 19:58:12 +01:00
sozud
b0d6f28633
CollectHeart (#1177) 2024-05-26 19:30:35 +01:00
Luciano Ciccariello
61eeba7f23
Prevent entity from respawning refactor (#1176)
Thanks to @sozud for the hint and @bismurphy for the refactoring idea.
The function `PreventEntityFromRespawning` on PSP hints that the struct
starts 8 bytes earlier. Also there's a missing `nop` at
`PreventEntityFromRespawning`, suggesting the function had to be moved
to the previous function.
2024-05-26 18:07:53 +01:00
bismurphy
8fdb4cce13
Rework g_unkGraphicsStruct (#1175)
I noticed that this struct had some overlap with other values in memory,
so I have pulled all those values into this struct.

The boundaries of this struct are uncertain and are a matter of ongoing
research.
2024-05-26 15:51:25 +01:00
sozud
461d3338d9
FallEntity (#1174)
I get
```
mipsel-linux-gnu-ld: build/pspeu/src/st/wrp_psp/BF50.c.o: in function `FallEntity':
(.text+0x0): undefined reference to `g_CurrentEntity'
mipsel-linux-gnu-ld: (.text+0x4): undefined reference to `g_CurrentEntity'
mipsel-linux-gnu-ld: (.text+0x1c): undefined reference to `g_CurrentEntity'
mipsel-linux-gnu-ld: (.text+0x20): undefined reference to `g_CurrentEntity'
```
Not sure what the issue is
2024-05-26 13:26:51 +01:00
sozud
51230ffc05
EntityDummy (#1173) 2024-05-26 13:23:49 +01:00
Luciano Ciccariello
fc1cc4d4b0 Fix progress for main 2024-05-26 13:05:37 +01:00
Luciano Ciccariello
54b55890f1 Fix progress script for PSP (2) 2024-05-26 11:43:16 +01:00
Luciano Ciccariello
bb7b485d29 Fix progress script for PSP 2024-05-26 11:12:00 +01:00
Luciano Ciccariello
5362c8b8da
Add ST/WRP from PSP (#1172)
Extract ST/WRP out of #1119 . All the function symbols should have been
cross-referenced. There as some PSX functions missing from PSP and some
new functions from PSP that are not present on PSX (e.g.
`st_init_wrp.c`).

The files `st_debug.c` and `e_breakable.c` are shared between WRP PSX
and WRP PSP. Everything else from PSP is isolated into its own folder. I
had to do some tricks on the YAML config to allow shared code.

`ST_WRP_MERGE = st_debug e_breakable` in the `Makefile` is a bit
annoying as MWCC complains about every single minute detail from the C
source that has been already decompiled for the PSX US build.

`EntityWarpSmallRocks` is matching on PSP but I couldn't extract the
rodata without having a bunch of linker errors. This might be a Splat
issue. I need to investigate further.

`func_psp_09244760` is soooo interesting. The values from `0x11` to
`0x17` matches the Entity IDs that are unique to the WRP overlay. This
aligns to what we have in `typedef enum EntityIDs`.

Overall I am very excited to the recent discoveries from the PSP build!
2024-05-25 11:56:06 -07:00
Jonathan Hohle
cb5458a693
Refactor entity.h Functions (#1171)
This organizes funcitons believed to be originally found in `entity.c`
into an equivalent `entity.h` based on the research of @Xeeynamo:

* `DestroyEntity`
* `DestroyEntitiesFromIndex`
* `AnimateEntity`
* `PreventEntityFromRespawning`

 Includes `entity.h` in place of stage implementations or ASM.

Co-authored-by: Jonathan Hohle <jon@ttkb.co>
2024-05-24 23:56:59 -07:00
Luciano Ciccariello
a7015bcbd7
Rename D_80072EF4 to padSim (#1168)
Discovered in #1167, where when the player approaches the red door it
forces the input. The line `g_Player.padPressed = g_Player.padSim;`
makes it even more obvious.

This needs to be rebased upon the other PR, otherwise it will break the
build if merged.
2024-05-24 19:59:00 +01:00
Luciano Ciccariello
0b9e94c4d3
EntityRedDoor matching (#1167)
Another One Bites the Dust

It matches 1:1 with the PSP counterpart too:
https://decomp.me/scratch/z1VlU
2024-05-24 19:41:07 +01:00
Jonathan Hohle
d677db6800
Share Stage Function Implementations (#1166)
Pulls out `CreateEntityFromLayout`, `CreateEntityWhenInVerticalRange`,
`CreateEntityWhenInHorizontalRange`, `FindFirstEntityToTheRight`,
`FindFirstEntityToTheLeft`, `CreateEntitiesToTheRight`,
`CreateEntitiesToTheLeft`, `FindFirstEntityAbove`,
`FindFirstEntityBelow`, `CreateEntitiesAbove`, `CreateEntitiesBelow`,
`InitRoomEntities`, `UpdateRoomPosition`,
`CreateEntityFromCurrentEntity`, `CreateEntityFromEntity`,
`EntityIsNearPlayer`, and `InitializeEntity` into headers to share the
implementation between stages.

`libstage.h` is a new header intended to bring in a sequential block of
functions shared by all stages.

`st_private.h` is a new header intended for declaring symbols used by
all stages that aren't otherwise accessible to code outside of a stage.

The only discrepency is `MAD` which has a unique implementation of
`CreateEntitiesToTheLeft`. Instead of being able to blanket include
`libstage.h` it needs to bring in individual headers before and after
its implementation.

Co-authored-by: Jonathan Hohle <jon@ttkb.co>
2024-05-24 18:54:44 +01:00
Josh Lory
8a8a54b7e4
Decompile func_8019F3BC (#1157)
https://decomp.me/scratch/EJ9uP
2024-05-24 18:52:39 +01:00
Jonathan Hohle
3003b0cacd
Decompile MAD CreateEntitiesToTheLeft (#1165)
Every other stage uses the same implementation of
`CreateEntitiesToTheLeft`, but MAD's version does not loop through all
entities which may be in range, it finds the first, and depending on
flags may create it, the array pointer is updated and no other entities
are considered. This function is used when scrolling left, meaning if
multiple entities fall within the scroll delta, only the first will be
created which might have some interesting properties.

Co-authored-by: Jonathan Hohle <jon@ttkb.co>
2024-05-23 19:40:14 -07:00
Jonathan Hohle
d46b6666e9
Rename MAD Functions and Symbols (#1164)
These were missed in 3b0943b25a. Renames common stage functions for
later refactor.

Co-authored-by: Jonathan Hohle <jon@ttkb.co>
2024-05-23 12:21:49 -07:00
Jonathan Hohle
3b0943b25a
Rename Stage Layout Functions and Vars Uniformly (#1162)
This change renames functions and global stage variables uniformly
across the stages so that these functions can be pulled out and shared
across all of the stages. Based on some other tests there are 12 or so
functions that this will allow to be pulled out of each stage. Since
these implementations are shared, an additional 12 asm functions can be
eliminated in a subsequent pass.

**Vars**
* `g_pStObjLayoutHorizontal` - a horizontally sorted array of stage
entities
* `g_pStObjLayoutVertical` - a vertically sorted array of stage entities
* `g_LayoutObjHorizontal` - a pointer to a `LayoutEntity` in
`g_pStObjLayoutHorizontal`
* `g_LayoutObjVertical` - a pointer to a `LayoutEntity` in
`g_pStObjLayoutVertical`
* `g_LayoutObjPosHorizontal` - the direction last traversed in
`g_LayoutObjHorizontal`
* `g_LayoutObjPosVertical` - the direction last traversed in
`g_pStObjLayoutVertical `

**Functions**
* `FindFirstEntityToTheRight` - given an `x` position, update
`g_LayoutObjHorizontal` with the first entity to the right of `x`
* `FindFirstEntityToTheLeft` - given a `x` position, update
`g_LayoutObjHorizontal` with the first entity to the left of `x`
(backwards)
* `CreateEntitiesToTheRight` - given an `x` position, create all
entities to the right (mutates `g_LayoutObjHorizontal`)
* `CreateEntitiesToTheLeft` - given an `x` position, create all entities
to the left (mutates `g_LayoutObjHorizontal`)
* `FindFirstEntityAbove` - given an `y` position, update
`g_LayoutObjVertical ` with the first entity to the above of `y`
* `FindFirstEntityBelow` - given an `y` position, update
`g_LayoutObjVertical ` with the first entity to the below of `y`
* `CreateEntitiesAbove` - given an `y` position, create all entities
above (mutates `g_LayoutObjVertical`)
* `CreateEntitiesBelow` - given an `y` position, create all entities
beneath (mutates `g_LayoutObjVertical`)
* `UpdateRoomPosition` - look at the current game loop scroll delta and
create any entities given the room layout

I believe all of these implementations are shared across all stages
(including `InitRoomEntities`, and two more `CreateEntity` functions)
(in my initial tests I had a small difference in `DER`, but I believe
that had to do with an incorrect symbol table change).

Co-authored-by: Jonathan Hohle <jon@ttkb.co>
2024-05-22 23:34:41 +01:00
Jonathan Hohle
867c7e12c8
Rename Symbols For Scroll Position and Delta (#1158)
Based on their use in the game loop and during stage updates, it appears
the renamed variables store the scroll position delta for the current
loop and store off the current position for future delta calculation.
These vars are then used by stage code to determine if any entities need
to be created or destroyed based on the new position.
2024-05-22 21:28:04 +01:00
Luciano Ciccariello
2ce781a33d
EntityDamageDisplay matching (#1161)
Thanks a lot to @SestrenExsis for doing the majority of the function
matching! I only take the credit for cross-referencing it with the PSP
counterpart and massaging the code until I got a match on PSX.
2024-05-22 21:24:42 +01:00
bismurphy
6fc9172be0
Decompile weapon 23 func_ptr_80170028 (#1160)
Looks like just another weapon function.

Weird uses of the Weapon struct. Unfortunately Weapons don't seem to
have any consistency among them. Would be nice if we could define the
Entity extension in each weapon's `w_0XX.c` file, but I don't think
that's a possibility in C.
2024-05-22 18:51:15 +01:00
sozud
9560ff91c6
Function fixes for PSP (#1159)
https://decomp.me/scratch/mZPXF
https://decomp.me/scratch/CaBA3
2024-05-22 18:49:42 +01:00
bismurphy
8040b1f1ce
Decompile weapon 41 helper 8017A994 (#1156)
Very neat to solve this with the help of the PSP version! I couldn't
solve this without it, so this is a cool development. Hoping to keep
benefiting from that!

This is also the final helper function in the weapons. All other
functions in all the weapon overlays are part of the main Weapon struct
that holds the set of several pointers to call.
2024-05-21 21:12:38 -07:00
bismurphy
0917d1ee3b
Update func_8011A4D0 to match on PSP (#1155)
Based on Sozud's scratch (https://decomp.me/scratch/zVBXP), I got the
function to match, and then confirmed that it also matches on PSX.

I also discovered a few improvements, especially in changing
`D_8016FCC0[entityId];` to instead be
`((PfnEntityUpdate*)FAMILIAR_PTR)[entity->entityId - 0xD0];`

While I was at it, I also updated the D_80170000 variable from a void*
to be g_ServantDesc, just like we have in the servant overlay. The
ServantDesc struct only exists in servant.h, so we update that as well.

Finally, we move g_Weapon to not be at 80170000, since it doesn't belong
there.
2024-05-21 17:34:07 -07:00
Josh Lory
613e268609
Implement SetRCnt (#1153)
https://decomp.me/scratch/jawso
2024-05-20 18:24:18 -07:00
Luciano Ciccariello
eae3cfbe94
TT_000 PSP match more functions (#1150)
Highlights:
* `abs` is a real function the compiler can optimise and inline (thanks
@Mc-muffin for the discovery)
* `-Op` is required to avoid using `div` when dividing integer numbers
* A file split in TT_000 is required to match on PSP
* `UpdateAnim` had the wrong signature
* Splatting the PSP build has been an excellent idea
2024-05-19 19:23:30 +01:00
Luciano Ciccariello
898e90f963
Use built-in abs function (#1151)
Given the recent discovery (thanks @Mc-muffin) I deleted the `ABS` macro
(together with a few other unused ones) and started using `abs` instead.

This is not a simple Find & Replace. I also checked every single code
change and removed previously necessary temporary variables.
2024-05-19 19:16:56 +01:00
Luciano Ciccariello
0c2046984e Update m2c 2024-05-19 12:55:28 +01:00
Luciano Ciccariello
bbdc1b31f0
TT_000 PSP more functions (#1148)
More PSP matches and a lot of fixes on types and symbols from the PSX
counterpart. I am very happy with the results so far.

`func_80173F74` has some weird `#ifdef VERSION_PSP` I cannot remove. Any
help will be very welcomed.
2024-05-19 11:26:23 +01:00
Luciano Ciccariello
c6e1f2517e
TT_000 PSP func_801713C8 (#1143)
Matches `func_801713C8`.

This is an important milestone as it is the first function using the
`SEH` instruction. I got this new compiler (and many more) from someone
in ObscureGamers that kindly shared at
https://archive.org/download/compilers-no-license .

This still gives us no clue on what `f32` and the various `.i.hi` stuff
was actually meant to be.
2024-05-18 13:09:03 -07:00
bismurphy
8b109acb3c
Decompile Weapon 37 func_ptr_80170004 (#1145)
My last PR for the moment; we've burned through my backlog :) No other
real comments to share.
2024-05-18 20:08:44 +01:00
bismurphy
16278437a9
Decompile EntityWeaponAttack for Weapon 21 (food) (#1144)
A couple of the entity fields were different for this compared to the
existing ET_Weapon, so I made a special one for food.
2024-05-18 19:53:01 +01:00
bismurphy
83a17381f4
Decompile Weapon 21 helper (food eating) (#1142)
Surprisingly, this uses an s16 for hitboxOffX, so it turns out we need
to adjust the Entity struct in Weapon. Hopefully that's the last of the
changes needed to Entity :)
2024-05-18 11:33:00 -07:00
bismurphy
f7789029ef
Decompile pair of duplicated weapon helper functions (#1141)
These two functions are extremely similar so I am doing them in one PR.

Not sure what they actually do, the call to LoadImage is a bit
surprising. This is used for the Skull Shield and Shaman Shield; I don't
know what they have in common.
2024-05-18 18:34:10 +01:00
bismurphy
ab09fa7ccd
Decompile duplicates of weapon primitive helper function (#1140)
`func_107000_8017ADF8` is already in the repo and decompiled. I found
that there are several duplicates of this function, so this PR
decompiles all of them.

The only difference between the copies is 1. The address of the data
array, obviously and 2. the assignment to the `size` variable. Some
duplicates use 4 and 6, others use 2 and 3. Otherwise they're exactly
the same.

This is the only heavily-duplicated weapon helper function remaining. I
have decompiled all of the helper functions (the ones that are unique to
the weapon they're part of, rather than being in the standard structure
like `func_ptr_801700XX`) and will be doing PRs for each of them in
sequence.
2024-05-18 10:11:51 -07:00
Jonathan Hohle
00839bcb13
Decompile SEL func_801B9B7C (#1139)
Decompile SEL func_801B9B7C Mostly based on the work of @sonicdcer (who
had the right code, but wrong struct), and @ser-pounce (who had the
right struct, but unfinished code).

Co-authored-by: Jonathan Hohle <jon@ttkb.co>
2024-05-18 09:56:05 -07:00
Mark Street
b6a0ddbeb6
Add mwccgap (#1131)
OK. Here goes. Version 0.0.1 alpha of the MWCC Global Assembly Processor
(mwccgap). It's currently very simple/limited, but it appears to work
for `src/servant/tt_000/10E8.c`.

There is lot more that can be done to improve mwccgap - i.e. supporting
.rodata migration would be a good addition, but let's see how far we can
get with it in it's current state.

Note that the Makefile could do with some improvements - we don't nede
to use mwccgap for any C file that *dont* have INCLUDE_ASM macros (it's
a waste of time) so these could be ignored, i.e. for SSSV I do something
like this to find the files that need fixing up:
```
GLOBAL_ASM_C_FILES := $(shell $(GREP) GLOBAL_ASM $(SRC_DIR) </dev/null 2>/dev/null)
```
.. although this is perhaps too simple given that SOTN has a mix of PSP
and PSX functions (and therefore there may be INCLUDE_ASM for a PSX
function but none for PSP functions...
2024-05-18 11:41:00 +01:00
bismurphy
51ddf51bb3
Decompile duplicates of weapon helper (#1136)
After decompiling `func_107000_8017B0AC`, I moved on to more weapon
helper functions, and was surprised to find several more copies of
nearly identical functions. The only difference between these is the
fractional constants applied to the outPoint results (for example, some
use 2/3, others use 3/4, and others still use 1/2).

Given the fact that these are all substantially the same, we could
probably do some de-duplicating by pulling in a header file, but for now
I'm decompiling each one in place, so that we can have all the functions
done.

I believe this is all of the ones that match this structure; hopefully I
didn't miss any!
2024-05-17 23:24:02 -07:00