AlexKnauth / hollowknight-autosplit-wasm

A cross-platform autosplitter for Hollow Knight that supports Windows, Mac, and Linux
MIT License
4 stars 0 forks source link

Test multiple HK versions #41

Open AlexKnauth opened 5 months ago

AlexKnauth commented 5 months ago

Testing:

AlexKnauth commented 5 months ago

Might be a cattrs difference, look at https://github.com/just-ero/asl-help/blob/main/src/Unity/Structs/mono_v1.xml vs https://github.com/just-ero/asl-help/blob/main/src/Unity/Structs/mono_v1_cattrs.xml

ero: getting the Assembly-CSharp image getting the first class checking its image field if it doesn't return the same pointer to Assembly-CSharp, then it's cattrs

See also: https://github.com/Voxelse/Voxif/blob/main/Voxif.Helpers/Voxif.Helpers.UnityHelper/Mono_v1.txt vs https://github.com/Voxelse/Voxif/blob/main/Voxif.Helpers/Voxif.Helpers.UnityHelper/Mono_v1_cattrs.txt#L16, and https://github.com/Voxelse/Voxif/blob/main/Voxif.Helpers/Voxif.Helpers.UnityHelper/UnityHelper.cs#L343-L344

AlexKnauth commented 5 months ago

Confirmed cattrs is an issue on Windows 1432.

AlexKnauth commented 5 months ago

I think after detecting 64-bit vs 32-bit, Windows 1221 can work now. But 1432 probably won't work on either Mac or Windows until the cattrs stuff is figured out.

AlexKnauth commented 5 months ago

After figuring out cattrs stuff, I think it's working on Windows on 1578, 1432, and 1221. And on Mac on 1578 and 1221. But for some reason Mac 1432 still seems to be broken. Like... the autosplitter is broken but also the game seems to be broken now? I can't seem to get past the main menu?

AlexKnauth commented 2 months ago

Still seems broken on Mac 1432. Even after I fixed my Mac so that it could run 1432, the autosplitter still crashes with this error message:

Unloaded, because the script trapped: error while executing at wasm backtrace:
    0: 0x96688 - <unknown>!asr::file_format::macho::fileoff_to_vmaddr::hd4f69de058f72c4a
    1: 0x8a1f0 - <unknown>!asr::game_engine::unity::mono::Module::attach::h6da9576729c07f79
    2: 0x88270 - <unknown>!hollowknight_autosplit_wasm::main::{{closure}}::{{closure}}::hf75b6f4dfa418170
    3: 0x932ea - <unknown>!update
    4: 0xad507 - <unknown>!update.command_export

Caused by:
    wasm trap: interrupt
AlexKnauth commented 2 months ago

More error message variants:

Unloaded, because the script trapped: error while executing at wasm backtrace:
    0: 0x2d2d53 - core::slice::raw::from_raw_parts_mut::h0bdf3dca63a24936
                    at /rustc/aedd173a2c086e558c2b66d3743b344f977621a7/library/core/src/slice/raw.rs:141
    1: 0x2cc3c9 - asr::runtime::process::Process::read_into_uninit_buf::h9e8b01120657ff8f
                    at /Users/Alex/.cargo/git/checkouts/asr-4a96b37e9805d92c/3943421/src/runtime/process.rs:306:20
    2: 0x2cc4d0 - asr::runtime::process::Process::read::h039e8e1723de7a91
                    at /Users/Alex/.cargo/git/checkouts/asr-4a96b37e9805d92c/3943421/src/runtime/process.rs:262:13
    3: 0x2ca18c - asr::file_format::macho::scan_macho_page::h872ab4264c689c62
                    at /Users/Alex/.cargo/git/checkouts/asr-4a96b37e9805d92c/3943421/src/file_format/macho.rs:39:15
    4: 0x2ca424 - asr::file_format::macho::symbols::h1edc04fce59cbf34
                    at /Users/Alex/.cargo/git/checkouts/asr-4a96b37e9805d92c/3943421/src/file_format/macho.rs:120:16
    5: 0x2c2974 - asr::game_engine::unity::mono::Module::attach::h8707c79a9000152b
                    at /Users/Alex/.cargo/git/checkouts/asr-4a96b37e9805d92c/3943421/src/game_engine/unity/mono.rs:90:17
    6: 0x2c18b0 - asr::game_engine::unity::mono::detect_version::h78e7deaa4633dcf0
                    at /Users/Alex/.cargo/git/checkouts/asr-4a96b37e9805d92c/3943421/src/game_engine/unity/mono.rs:1227:22
    7: 0x2c0886 - asr::game_engine::unity::mono::Module::attach_auto_detect::h02e09e958b102c8a
                    at /Users/Alex/.cargo/git/checkouts/asr-4a96b37e9805d92c/3943421/src/game_engine/unity/mono.rs:36:23
    8: 0x1e1bd5 - asr::game_engine::unity::mono::Module::wait_attach_auto_detect::{{closure}}::{{closure}}::hf6fa6ad2138decb8
                    at /Users/Alex/.cargo/git/checkouts/asr-4a96b37e9805d92c/3943421/src/game_engine/unity/mono.rs:213:18
    9: 0x1a5f00 - <asr::future::Retry<F> as core::future::future::Future>::poll::hac3e9881eb5197f2
                    at /Users/Alex/.cargo/git/checkouts/asr-4a96b37e9805d92c/3943421/src/future/mod.rs:155:15
   10: 0x1e1a56 - asr::game_engine::unity::mono::Module::wait_attach_auto_detect::{{closure}}::h0906bd35206d732c
                    at /Users/Alex/.cargo/git/checkouts/asr-4a96b37e9805d92c/3943421/src/game_engine/unity/mono.rs:213:53
   11: 0x8c6aa - hollowknight_autosplit_wasm::hollow_knight_memory::GameManagerFinder::wait_attach::{{closure}}::h23a6c9a791245bb2
                    at /Users/Alex/git/LiveSplit/hollowknight-autosplit-wasm/src/hollow_knight_memory.rs:1073:73
   12: 0x88d86 - hollowknight_autosplit_wasm::main::{{closure}}::{{closure}}::hc4907e2c62a4fb85
                    at /Users/Alex/git/LiveSplit/hollowknight-autosplit-wasm/src/lib.rs:54:93
   13: 0x1a60d8 - <asr::future::UntilProcessCloses<F> as core::future::future::Future>::poll::h91e643b91a6e9e14
                    at /Users/Alex/.cargo/git/checkouts/asr-4a96b37e9805d92c/3943421/src/future/mod.rs:288:13
   14: 0x8814f - hollowknight_autosplit_wasm::main::{{closure}}::hbc86f448c3f3e319
                    at /Users/Alex/git/LiveSplit/hollowknight-autosplit-wasm/src/lib.rs:96:14
   15: 0x20799a - <core::pin::Pin<P> as core::future::future::Future>::poll::hff2bb2a5c681117a
                    at /rustc/aedd173a2c086e558c2b66d3743b344f977621a7/library/core/src/future/future.rs:124:9
   16: 0x210061 - update
                    at /Users/Alex/.cargo/git/checkouts/asr-4a96b37e9805d92c/3943421/src/future/mod.rs:412:28
   17: 0x30d85a - <unknown>!update.command_export

Caused by:
    wasm trap: interrupt
Unloaded, because the script trapped: error while executing at wasm backtrace:
    0: 0x2d4fc5 - core::option::Option<T>::unwrap_or::h424f6f67cc516034
                    at /rustc/aedd173a2c086e558c2b66d3743b344f977621a7/library/core/src/option.rs:951
    1: 0x2cb311 - asr::file_format::macho::fileoff_to_vmaddr::h7bc58dda48e8be9e
                    at /Users/Alex/.cargo/git/checkouts/asr-4a96b37e9805d92c/3943421/src/file_format/macho.rs:172:5
    2: 0x2c9267 - asr::file_format::macho::symbols::{{closure}}::h4201376bab723d59
                    at /Users/Alex/.cargo/git/checkouts/asr-4a96b37e9805d92c/3943421/src/file_format/macho.rs:159:37
    3: 0x2c8f4a - core::iter::adapters::filter_map::filter_map_try_fold::{{closure}}::hdef68b50513da492
                    at /rustc/aedd173a2c086e558c2b66d3743b344f977621a7/library/core/src/iter/adapters/filter_map.rs:48:28
    4: 0x2daefa - core::iter::traits::iterator::Iterator::try_fold::hd82960b4e900299b
                    at /rustc/aedd173a2c086e558c2b66d3743b344f977621a7/library/core/src/iter/traits/iterator.rs:2462:21
    5: 0x2c74b1 - <core::iter::adapters::filter_map::FilterMap<I,F> as core::iter::traits::iterator::Iterator>::try_fold::h10cc7a1285133c34
                    at /rustc/aedd173a2c086e558c2b66d3743b344f977621a7/library/core/src/iter/adapters/filter_map.rs:140:9
    6: 0x2c7e39 - core::iter::traits::iterator::Iterator::find::h349a53f50c90d8d5
                    at /rustc/aedd173a2c086e558c2b66d3743b344f977621a7/library/core/src/iter/traits/iterator.rs:2931:9
    7: 0x2b10af - <core::iter::adapters::fuse::Fuse<I> as core::iter::adapters::fuse::FuseImpl<I>>::find::h592de16adc3e4e87
                    at /rustc/aedd173a2c086e558c2b66d3743b344f977621a7/library/core/src/iter/adapters/fuse.rs:385:9
    8: 0x2b0fa6 - <core::iter::adapters::fuse::Fuse<I> as core::iter::traits::iterator::Iterator>::find::h68f0ccac5aa5f772
                    at /rustc/aedd173a2c086e558c2b66d3743b344f977621a7/library/core/src/iter/adapters/fuse.rs:108:9
    9: 0x2c3034 - asr::game_engine::unity::mono::Module::attach::h8707c79a9000152b
                    at /Users/Alex/.cargo/git/checkouts/asr-4a96b37e9805d92c/3943421/src/game_engine/unity/mono.rs:90:17
   10: 0x2c18b0 - asr::game_engine::unity::mono::detect_version::h78e7deaa4633dcf0
                    at /Users/Alex/.cargo/git/checkouts/asr-4a96b37e9805d92c/3943421/src/game_engine/unity/mono.rs:1227:22
   11: 0x2c0886 - asr::game_engine::unity::mono::Module::attach_auto_detect::h02e09e958b102c8a
                    at /Users/Alex/.cargo/git/checkouts/asr-4a96b37e9805d92c/3943421/src/game_engine/unity/mono.rs:36:23
   12: 0x1e1bd5 - asr::game_engine::unity::mono::Module::wait_attach_auto_detect::{{closure}}::{{closure}}::hf6fa6ad2138decb8
                    at /Users/Alex/.cargo/git/checkouts/asr-4a96b37e9805d92c/3943421/src/game_engine/unity/mono.rs:213:18
   13: 0x1a5f00 - <asr::future::Retry<F> as core::future::future::Future>::poll::hac3e9881eb5197f2
                    at /Users/Alex/.cargo/git/checkouts/asr-4a96b37e9805d92c/3943421/src/future/mod.rs:155:15
   14: 0x1e1a56 - asr::game_engine::unity::mono::Module::wait_attach_auto_detect::{{closure}}::h0906bd35206d732c
                    at /Users/Alex/.cargo/git/checkouts/asr-4a96b37e9805d92c/3943421/src/game_engine/unity/mono.rs:213:53
   15: 0x8c6aa - hollowknight_autosplit_wasm::hollow_knight_memory::GameManagerFinder::wait_attach::{{closure}}::h23a6c9a791245bb2
                    at /Users/Alex/git/LiveSplit/hollowknight-autosplit-wasm/src/hollow_knight_memory.rs:1073:73
   16: 0x88d86 - hollowknight_autosplit_wasm::main::{{closure}}::{{closure}}::hc4907e2c62a4fb85
                    at /Users/Alex/git/LiveSplit/hollowknight-autosplit-wasm/src/lib.rs:54:93
   17: 0x1a60d8 - <asr::future::UntilProcessCloses<F> as core::future::future::Future>::poll::h91e643b91a6e9e14
                    at /Users/Alex/.cargo/git/checkouts/asr-4a96b37e9805d92c/3943421/src/future/mod.rs:288:13
   18: 0x8814f - hollowknight_autosplit_wasm::main::{{closure}}::hbc86f448c3f3e319
                    at /Users/Alex/git/LiveSplit/hollowknight-autosplit-wasm/src/lib.rs:96:14
   19: 0x20799a - <core::pin::Pin<P> as core::future::future::Future>::poll::hff2bb2a5c681117a
                    at /rustc/aedd173a2c086e558c2b66d3743b344f977621a7/library/core/src/future/future.rs:124:9
   20: 0x210061 - update
                    at /Users/Alex/.cargo/git/checkouts/asr-4a96b37e9805d92c/3943421/src/future/mod.rs:412:28
   21: 0x30d85a - <unknown>!update.command_export

Caused by:
    wasm trap: interrupt
AlexKnauth commented 2 months ago

I think something is wrong with the way I implemented macho::symbols. I'm looking for the symbol _mono_assembly_foreach, and my code isn't finding it even though it should be there according to Cutter. Some of the symbols it "finds" are cut off versions of names. One of the symbols my function is "finding" is _image_get_resource which doesn't exist but _mono_image_get_resource does. Another symbol it "finds" is MD_ASSEMBLY_GET_ENTRY_POIN which doesn't exist but CMD_ASSEMBLY_GET_ENTRY_POINT does.

AlexKnauth commented 2 months ago

I think I need to find the section_64 structures for the sections within a segment, not just the segment_command_64 for the whole segment.

AlexKnauth commented 2 months ago

That still doesn't seem to be enough to find the string table.

The file offset of the string table is 0x2DF66C

The start of the string table should match this signature:

00000000 5F436C6F 73654861 6E646C65 005F436C 6F736550 726F6365 7373005F 436F7079 46696C65 005F4372 65617465 44697265
AlexKnauth commented 1 month ago

The symbol table and string table from the Mach-O file, do not appear to be in memory in-tact anywhere in the module range on Mac 1432.

I might have to fall back on filesystem access when memory access fails.

AlexKnauth commented 1 month ago

Even with filesystem access to find what the contents _mono_assembly_foreach should be, I can't seem to find those contents in memory in the module range on Mac 1432.

AlexKnauth commented 1 month ago

Okay I managed to find, at least the first 23 bytes, of _mono_assembly_foreach in memory on Mac 1432. With that, Module::attach can return some module. However, getting an image from the module fails pretty early at the monoassembly_aname. So the module address might not be correct, or maybe something else is wrong.