Skip to content

Conversation

@emoose
Copy link

@emoose emoose commented Nov 18, 2024

Hi, thanks for the work on RASM, was looking for an RDR script dis/assembler for a while and this was perfect, so tried looking into adding RDR1 PC support to it.

First try was a bit messy, tried changing readers to little-endian and then adding a bunch of endian-swaps to each of the opcodes, only then realized it's just the RSC/RDRHeader that changed to LE while code itself stayed BE, so redid it with just a couple changes to the header reading, and with that it seemed to work fine.

Also added some new opcodes which I guess were added in NSW/PC, not really sure what their purpose is yet other than the names - tested decompiling/recompiling a couple scripts and they seemed to run fine in-game, script changes also seemed to work fine too.

I've just changed the existing DecompileRDR/CompileRDR for this, didn't add separate PC classes, if you want me to change anything here let me know.

allows easier matching between recompiled RDR scripts (sometimes RDR scripts change PushString "" to PushStringNull, and sometimes they don't, best to disasm whatever was there originally so we can reassemble the same way)
mostly seems to assemble to same code as original, other than switch statements having some cases moved around, and the script RDRHeader being moved for some reason
seems statics always have to be big-endian just like code values

fixed switch cases being switched after recompiling, script mostly matches original fine now, only difference seems to be RDRHeader location which doesn't seem to matter

changed zstd compression level to 6 to match magicrdr
@emoose emoose changed the title RDR1 PC support RDR1 PC .WSC support Nov 18, 2024
@emoose
Copy link
Author

emoose commented Nov 19, 2024

Unfortunately seems compiling larger scripts has issues, if I try recompiling content.rpf/content/release64/main.wsc the game just gets stuck on loading screen, seems there's a lot of differences between the OG and recompiled script too (even if I keep nops included with -dcn), not really sure what could be breaking it :/

@NativeFunction
Copy link
Owner

Add me on discord "NativeFunction" and send me the regular main.wsc decompiled and the decompiled-recompiled main.wsc decompiled.

recompiling using value from std::format allows RDR1 bytecode to match pretty much 1:1 with OG
@emoose
Copy link
Author

emoose commented Nov 20, 2024

Oh might have found the issue, the statics were getting placed between two pages, started near the end of one page and then spilled onto the next
Added some code to pad it to the next page if it would spill over and now looks like it can load in fine 🐱

Not sure if natives also have that issue but added the same pad code for those as well, wonder what might happen if a script has more than 1 page worth of natives/statics though...

Anyway recomp seems fine now, code bytes are actually 100% identical between them (when using -dcn), only difference now seems to be RDRHeader/statics/natives being placed at different offset, which I guess game doesn't have issue with

padding statics seems to fix main.wsc failing to load properly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants