Helco / zzdocs

Zanzarah Knowledge Base
3 stars 1 forks source link

Modifying the contents of _fb0x01.fbs without causing instabilities #3

Closed TyzoneLyraNature closed 4 months ago

TyzoneLyraNature commented 4 months ago

I've been trying to modify the Fairies FBS file to try and shuffle fairies around, in an effort to work on a Zanzarah randomizer. I'm at a very early stage of messing around with the files for now, and noticed for example that by modifying the CardId in this specific spot of the file, I could make the Light fairy Suane appear in place of Tadana as a starter fairy:

image

(Tadana and Suane's CardIds are respectively 6 and 74 as seen here (just subtract 1 to the order value). Note that I also swapped Suane's CardId for Tadana's to avoid overlaps)

image This simple modification of the file allows me to display Suane as a starter fairy, however the game crashes with no error message as soon as I accept this fairy as my starter (picking any other starter fairy still works fine).

Is there another part of the files I should modify to prevent this instability? Do you think there's a cleaner way to go about a mod that would shuffle fairies around?

(I haven't pinpointed the issue yet, but have noticed that swapping Tadana for certain other fairies, such as Blumella or Oceana, will not cause a crash. The icon on the "item get" window will still be Tadana, but other than that, the game lets me own a completely different starter fairy)

image

Helco commented 4 months ago

I briefly looked but don't know why the game would crash at that point. If you are running 1.010 there might be a Trace_*.log file in the System folder that could tell a bit more.

If there is no systemic error I am missing shuffling the IDs might be the easiest way to shuffle fairies as this will also affect any script commands referring to that fairy (e.g. the NPC on the way to the cottage with the silver orb should give a Suane now) as well as fairy groups (e.g. for wild fairies). The alternative would be involve changing any script command one-by-one as well as patching the executable to change the hardcoded fairy groups.

TyzoneLyraNature commented 4 months ago

Thanks for responding! I was unaware of Trace logs being a thing, thanks for that pointer. Here's the content of Trace_0.log in case you're able to make sense of it:

Zanzarah Log File
zanthp.exe caused a EXCEPTION_ACCESS_VIOLATION in module zanthp.exe at 0023:00438CDC

EAX=00000000  EBX=00000000  ECX=00000000  EDX=00006106  ESI=10EC28B0
EDI=10EC293C  EBP=0019F5B0  ESP=0019F590  EIP=00438CDC  FLG=00210246
CS=0023   DS=002B  SS=002B  ES=002B   FS=0053  GS=002B

0023:00438CDC (0x00000000 0x10F94C80 0x10F94C80 0x10EC28B0) zanthp.exe
0023:00437EFA (0x00000006 0xFFFFFFFF 0x0B789A59 0x10F94C80) zanthp.exe
0023:0047628C (0x00000000 0x00000006 0x00000000 0x0019F66C) zanthp.exe
0023:0048F493 (0x0048F1D0 0x0019F688 0x0059C7BC 0xFFFFFFFF) zanthp.exe
0023:0048EFE9 (0x028A0170 0x10F78C64 0x10F94B80 0x00000000) zanthp.exe
0023:00474B82 (0x0019F780 0x10F94B80 0x3F800000 0x3F800000) zanthp.exe
0023:00474C53 (0x00000000 0x0B7F2C20 0x0443F394 0x00000005) zanthp.exe
0023:0058F47D (0x015ABF24 0x10CDABA4 0x0019F774 0x00000005) zanthp.exe
0023:0058F639 (0x0BB2E4D8 0x0BB2E4B0 0x00000001 0x005A8702) zanthp.exe
0023:004AEF40 (0x0280C924 0x0443F058 0x0BB2E4B0 0x0443F020) zanthp.exe
0023:004A9DCB (0x0280C924 0x0443F020 0x0019FE94 0x004A3E24) zanthp.exe
0023:004A9908 (0x0280C924 0x0443F058 0x0280C924 0x004A409E) zanthp.exe
0023:004A3E24 (0x00000002 0x0280C6F8 0x00000000 0x046A4C50) zanthp.exe
0023:00403410 (0x00534E65 0x00000000 0x003FD000 0x00000000) zanthp.exe
0023:00401126 (0x00400000 0x00000000 0xFFFFFFFF 0x0000000A) zanthp.exe
0023:00534F45 (0x003FD000 0x75C6FCB0 0x0019FFDC 0x77CF7C6E) zanthp.exe
0023:75C6FCC9 (0x003FD000 0x0144CBCF 0x00000000 0x00000000) KERNEL32.DLL, BaseThreadInitThunk()+25 byte(s)
0023:77CF7C6E (0xFFFFFFFF 0x77D18C35 0x00000000 0x00000000) ntdll.dll, RtlGetAppContainerNamedObjectPath()+286 byte(s)
0023:77CF7C3E (0x00534E65 0x003FD000 0x00000000 0x78746341) ntdll.dll, RtlGetAppContainerNamedObjectPath()+238 byte(s)

I'd love to patch the game's executable for more advanced modifications, however I have pretty much zero experience in modding games in such a way. Do you have any links I could check out to try and figure that out?

shuffling the IDs

Just so we're on the same page: you are still talking about the CardId, correct? Not the UID found earlier in the FBS file? (screenshot done with an FBS-to-XML converter, feezfuzz)

image

Also, it seems from the previous screenshot (where I successfully picked Blumella as a starter) that a fairy's icon is not defined in the FBS, and that I might also need to make changes elsewhere to make sure I get the correct icon. Do you know where those files are stored?

this will also affect any script commands referring to that fairy (e.g. the NPC on the way to the cottage with the silver orb should give a Suane now) as well as fairy groups (e.g. for wild fairies).

Didn't get to test the Tadana-trading NPC yet, but I noticed that while I was able to select Blumella as a starter, triggering an encounter with a wild-Blumella (now replaced with Tadana) crashes the game (Worgot encounters are completely stable, and Blumella correctly behaves as Blumella and not Tadana in a fight). This is the content of Trace_0.log after crashing due to a modified wild fairy encounter:

Zanzarah Log File
zanthp.exe caused a EXCEPTION_ACCESS_VIOLATION in module zanthp.exe at 0023:00438CDC

EAX=00000000  EBX=00000000  ECX=00000000  EDX=00000435  ESI=11072378
EDI=11072404  EBP=0019F178  ESP=0019F158  EIP=00438CDC  FLG=00210246
CS=0023   DS=002B  SS=002B  ES=002B   FS=0053  GS=002B

0023:00438CDC (0x00000000 0x10EA0B88 0x10EA0B88 0x11072378) zanthp.exe
0023:00437EFA (0x0000001A 0xFFFFFFFF 0x00000004 0x10EA0B88) zanthp.exe
0023:0047628C (0x00000000 0x0000001A 0x00000004 0x02767CB8) zanthp.exe
0023:004760ED (0x00000000 0x00000001 0x00000000 0x10FDEB6C) zanthp.exe
0023:00474B39 (0x0019F7B4 0x10EA0A88 0x3F800000 0x3F800000) zanthp.exe
0023:00474C53 (0x00000000 0x044A033C 0x902391A4 0x10E38A48) zanthp.exe
0023:0058F47D (0x902391A4 0x0019F81C 0x0019F7A8 0x00000015) zanthp.exe
0023:004AE6A8 (0x044A033C 0x004A992F 0x04499008 0x0019FE94) zanthp.exe
0023:004A9AB4 (0x026DC924 0x04499040 0x026DC924 0x004A409E) zanthp.exe
0023:004A3E24 (0x00000002 0x026DC6F8 0x00000000 0x05217DE0) zanthp.exe
0023:00403410 (0x00534E65 0x00000000 0x0036A000 0x2CBD0A34) zanthp.exe
0023:00401126 (0x00400000 0x00000000 0xFFFFFFFF 0x0000000A) zanthp.exe
0023:00534F45 (0x0036A000 0x75C6FCB0 0x0019FFDC 0x77CF7C6E) zanthp.exe
0023:75C6FCC9 (0x0036A000 0x01E5675E 0x00000000 0x00000000) KERNEL32.DLL, BaseThreadInitThunk()+25 byte(s)
0023:77CF7C6E (0xFFFFFFFF 0x77D18C3C 0x00000000 0x00000000) ntdll.dll, RtlGetAppContainerNamedObjectPath()+286 byte(s)
0023:77CF7C3E (0x00534E65 0x0036A000 0x00000000 0x78746341) ntdll.dll, RtlGetAppContainerNamedObjectPath()+238 byte(s)
Helco commented 4 months ago

Just so we're on the same page: you are still talking about the CardId, correct? Not the UID found earlier in the FBS file?

Yes I am talking about changing the CardId, I cannot remember a place where the UID is used for fairies/items/spells. For those they are always referenced by their CardId.

The trace logs both point towards the game not finding the fairy with the given CardId in the database so while the hex snippet in your post do not show anything obvious it is where I would look for an error next (e.g. the byte before and after have to be 0, so 00 02 06 00)

For the images the CardId is used as tile index into two textures stored in the archive (bitmaps/wiz000t and textures/misc/mpi000t)

TyzoneLyraNature commented 4 months ago

I've double-checked my FBS file and you're right that I accidentally messed up the redefinition of Blumella's CardId. After correcting its value, Blumella and Tadana can be swapped properly with no issues whatsoever (aside from the icon being different).

I've made a quick Python script on the side to easily swap out two fairy cardIds in the FBS file, and have made an interesting discovery: the game will crash upon selecting a starter fairy that is any element except Water, Stone and Nature. Trying to select a fairy like JumJum, Oceana or Lana as a starter works fine; trying to select a Pix, Feez, Suane, Segbuzz, etc. does not. This makes me think the game might have a condition in place to keep track of the element you selected at the start of the game, maybe in an effort to adapt dialogues or balance the game (though I don't think I've encountered any change like this when playing the game).

Wild fairy encounters do not seem to have such restrictions: I was able to swap Suane with either Blumella and Pix, and could trigger a fight with Suane in the Fairy Garden and Lava Caves respectively, with no crash.

Helco commented 4 months ago

Yes I can see why his happens, the spell is hardcoded for the three classes if the player does not have a fairy in their deck. For classes other than Nature/Stone/Water the game searches for a spell with ID -1 and thus crashes.

To fix this you would have to patch the executable.