Skip to content

Commit

Permalink
Disable assertions for h1 standalone.
Browse files Browse the repository at this point in the history
  • Loading branch information
num0005 committed Jul 19, 2024
1 parent e6bca62 commit 19631d5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
20 changes: 17 additions & 3 deletions H2ToolHooks/H2ToolHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ static bool disable_assertions(const PatternScanner &scanner)
return false;
}

std::array<pattern_entry, 10> assert_pat = {
std::array<pattern_entry, 8> assert_pat = {
PAT_BYTES(2, { 0x6A, 0x01}), // push 1 (is fatal)
PAT_BYTE(0x68), PAT_ANY(4), // push c_line
PAT_BYTE(0x68), PAT_ANY(4), // push c_filename
PAT_BYTE(0x68), PAT_ANY(4), // push c_assertion_message
PAT_CALL(display_assert_offset), // call display_assert
PAT_BYTES(3, { 0x83, 0xC4, 0x10}), // add esp, 10h
PAT_CALL(system_debugger_present_offset) // call system_debugger_present
//PAT_BYTES(3, { 0x83, 0xC4, 0x10}), // add esp, 10h
//PAT_CALL(system_debugger_present_offset) // call system_debugger_present
};
auto asserts = scanner.find_pattern_in_code_multiple(assert_pat);
DebugPrintf("Found %d asserts", asserts.size());
Expand All @@ -78,6 +78,20 @@ static bool disable_assertions(const PatternScanner &scanner)
}
DebugPrintf("Patched all asserts found!");

std::array<pattern_entry, 2> assertion_debug_break_pattern = {
PAT_CALL(display_assert_offset), // call display_assert
PAT_BYTE(0xcc) // __debugbreak
};

auto assertion_debug_break = scanner.find_pattern_in_code_multiple(assertion_debug_break_pattern);
DebugPrintf("Found %d __debugbreak's", assertion_debug_break.size());
for (auto& debugbreak : assertion_debug_break)
{
WriteValue<uint8_t>(debugbreak.offset + 5, 0x90);
}
DebugPrintf("Patched all __debugbreak's found!");


return true;
}
else
Expand Down
20 changes: 19 additions & 1 deletion Launcher/ToolkitInterface/H1AToolkit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,23 @@ public override string GetDocumentationName()
{
return "H1MCC";
}
}

protected override Utility.Process.InjectionConfig? ModifyInjectionSettings(ToolType tool, Utility.Process.InjectionConfig? requestedConfig)
{
static void ModifyEnviroment(IDictionary<string, string?> Enviroment)
{
Enviroment[DLLInjector.GetVariableName("DISABLE_ASSERTIONS")] = "1";
}

// tool, sapien and guerilla codegen correctly identifies _system_exit as noreturn and does not generate code to continue past a failed assertion
// patching out assertions would be more difficult for those targets
if (tool == ToolType.Game && requestedConfig is null && Profile.IsMCC && Profile.DisableAssertions)
{
DLLInjector injector = new(Resources.H2ToolHooks, "h1.asserts.disable.dll", ModifyEnviroment);
return new(injector);
}

return requestedConfig;
}
}
}

0 comments on commit 19631d5

Please sign in to comment.