wwylele / 3ds-save-tool

Tools to extract 3DS format save file. For richer functionality, use https://github.com/wwylele/save3ds
Apache License 2.0
48 stars 5 forks source link

Possible wrong output in diff-extract.py #3

Closed d0k3 closed 6 years ago

d0k3 commented 6 years ago

I'm currently trying a reimplementation of the diff-extractor for GodMode9, and I may have found a bug. Using my own ticket.db (I'll give that to you on request, just contact me on IRC or GBAtemp), diff-extract.py seems to select the wrong DPFS level 3 data at some points. I already double-checked my output, and it looks like the bug is not on my side.

My current (heavily work-in-progress) code is found here: https://gist.github.com/d0k3/6161b268f8c91c02fad92ae944856560

Also, is the first issue opened? :)

wwylele commented 6 years ago

https://gist.github.com/d0k3/6161b268f8c91c02fad92ae944856560#file-diffext-c-L25 I don't think this is correct. idx_lvl2 is a bit index in level 2, not a byte index, so to get the corresponding level 1 index, it should be

u32 idx_lvl1 = (idx_lvl2 / 32 * 4) >> dpfs->log_lvl2;

/32 to convert bit index to 32-bit word index (because the bitarray is grouped by u32) and then *4 to convert to byte index.

wwylele commented 6 years ago

I do need to double check my code though. I made some code change recently and didn't retest them.

d0k3 commented 6 years ago

I may have actually gotten something wrong re bits and bytes, but it's not the idx_lvl1 (at least not what's at fault here). I'll double-check my code, too.

d0k3 commented 6 years ago

Okay. You've been right, I've been wrong. Sorry, I didn't pay enough attention and the fix you proposed actually worked. I now checked the output of your tool vs my tool for all dbs I have available, and all of them match.

Anyways, learning still in progress: https://github.com/d0k3/diff-ext

Thanks for all the research you did! Closing this now....