Skip to content

Commit

Permalink
add set_olmec_cutscene_enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Auto committed Sep 20, 2023
1 parent 2f80598 commit 019dd36
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/game_api/game_patches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ void patch_olmec_kill_crash()
// patch the cutscene

const auto function_offset = get_virtual_function_address(VTABLE_OFFSET::THEME_OLMEC, 24); // spawn_effects
// find the jump out of olmec lookup loop
auto jump_out_lookup = find_inst(memory.exe(), "\x48\x03\x58\x28"sv, function_offset, function_offset + 0x51C, "patch_olmec_kill_crash");
const auto jump_out_lookup = get_address("olmec_lookup_in_theme");
if (jump_out_lookup == 0)
return;

Expand All @@ -122,7 +121,6 @@ void patch_olmec_kill_crash()
if (end_function_jump == 0)
return;

auto end_loop_jump = memory.at_exe(jump_out_lookup + 9); // +9 to skip the pattern and some other stuff
auto jump_addr = memory.at_exe(end_function_jump);
auto addr_to_jump_to = jump_addr + 6 + memory_read<int32_t>(jump_addr + 2);
std::string clear_ic8_code = fmt::format(
Expand All @@ -137,7 +135,7 @@ void patch_olmec_kill_crash()
* hopefully there isn't something important that we're skipping
*/

patch_and_redirect(end_loop_jump, 5, clear_ic8_code, true, addr_to_jump_to);
patch_and_redirect(jump_out_lookup, 5, clear_ic8_code, true, addr_to_jump_to);
}

/* The idea:
Expand Down Expand Up @@ -205,3 +203,15 @@ void patch_liquid_OOB()

once = true;
}

void set_skip_olmec_cutscene(bool skip)
{
static const auto jump_out_lookup = get_address("olmec_lookup_in_theme");
if (jump_out_lookup == 0)
return;

if (skip)
write_mem_recoverable("set_skip_olmec_cutscene", jump_out_lookup - 2, "\x90\x90"sv, true);
else
recover_mem("set_skip_olmec_cutscene");
}
1 change: 1 addition & 0 deletions src/game_api/game_patches.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
void patch_orbs_limit();
void patch_olmec_kill_crash();
void patch_liquid_OOB();
void set_skip_olmec_cutscene(bool skip);
6 changes: 6 additions & 0 deletions src/game_api/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "entities_mounts.hpp" // for Mount
#include "entity.hpp" // for get_entity_ptr, to_id, Entity, EntityDB
#include "game_manager.hpp" //
#include "game_patches.hpp" //
#include "items.hpp" // for Items
#include "layer.hpp" // for EntityList, EntityList::Range, Layer
#include "logger.h" // for DEBUG
Expand Down Expand Up @@ -1880,3 +1881,8 @@ void set_ending_unlock(ENT_TYPE type)
recover_mem("ending_unlock");
}
}

void set_olmec_cutscene_enabled(bool enable)
{
set_skip_olmec_cutscene(!enable);
}
1 change: 1 addition & 0 deletions src/game_api/rpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,4 @@ void call_death_screen();
void save_progress();
void set_level_string(std::u16string_view text);
void set_ending_unlock(ENT_TYPE type);
void set_olmec_cutscene_enabled(bool enable);
2 changes: 2 additions & 0 deletions src/game_api/script/lua_vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2014,6 +2014,8 @@ end
return AABB(ax + index * w + 0.02f * f, ay, ax + index * w + w - 0.02f * f, ay - h);
};

lua["set_olmec_cutscene_enabled"] = set_olmec_cutscene_enabled;

lua.create_named_table("INPUTS", "NONE", 0, "JUMP", 1, "WHIP", 2, "BOMB", 4, "ROPE", 8, "RUN", 16, "DOOR", 32, "MENU", 64, "JOURNAL", 128, "LEFT", 256, "RIGHT", 512, "UP", 1024, "DOWN", 2048);

lua.create_named_table(
Expand Down
9 changes: 9 additions & 0 deletions src/game_api/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1984,6 +1984,15 @@ std::unordered_map<std::string_view, AddressRule> g_address_rules{
.find_after_inst("F3 41 0F 5E F1 F3 48 0F 2C EE"_gh)
.at_exe(),
},
{
"olmec_lookup_in_theme"sv,
// find the jump out of olmec lookup loop
PatternCommandBuffer{}
.get_virtual_function_address(VTABLE_OFFSET::THEME_OLMEC, (VIRT_FUNC)24) // spawn_effects
.find_after_inst("\x48\x03\x58\x28"sv)
.offset(0x5)
.at_exe(),
},
};
std::unordered_map<std::string_view, size_t> g_cached_addresses;

Expand Down

0 comments on commit 019dd36

Please sign in to comment.