From 9f702353e564bb770698656596411d7e05e9914c Mon Sep 17 00:00:00 2001 From: Estebanfer Date: Sat, 3 Aug 2024 20:48:07 -0300 Subject: [PATCH] change get_location to get_offset, remove get_state_offset --- src/game_api/savestate.cpp | 24 ++++++++++-------------- src/game_api/state.cpp | 2 +- src/game_api/state.hpp | 6 ++++-- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/game_api/savestate.cpp b/src/game_api/savestate.cpp index 8bac874a4..2774d784c 100644 --- a/src/game_api/savestate.cpp +++ b/src/game_api/savestate.cpp @@ -5,19 +5,11 @@ #include "script/events.hpp" // for pre_load_state #include "state.hpp" // for State, get_state_ptr, enum_to_layer -size_t get_state_offset() -{ - auto addr = get_address("state_location"); - if (addr) - return memory_read(addr); - return 0x4a0; -} - StateMemory* get_save_state_raw(int slot) { size_t arr = get_address("save_states"); size_t base = memory_read(arr + (slot - 1) * 8); - auto state = reinterpret_cast(base + get_state_offset()); + auto state = reinterpret_cast(base + State::get().get_offset()); return state; } @@ -95,15 +87,17 @@ StateMemory* SaveState::get_state() const { if (!addr) return nullptr; - return reinterpret_cast(addr + get_state_offset()); + return reinterpret_cast(addr + State::get().get_offset()); } void SaveState::load() { if (!addr) return; - size_t to = (size_t)(State::get().ptr_main()) - get_state_offset(); - auto state = reinterpret_cast(addr + get_state_offset()); + State& state_g = State::get(); + size_t offset = state_g.get_offset(); + size_t to = (size_t)(state_g.ptr_main()) - offset; + auto state = reinterpret_cast(addr + offset); if (pre_load_state(-1, state)) return; copy_state(addr, to); @@ -114,8 +108,10 @@ void SaveState::save() { if (!addr) return; - size_t from = (size_t)(State::get().ptr_main()) - get_state_offset(); - auto state = reinterpret_cast(addr + get_state_offset()); + State& state_g = State::get(); + size_t offset = state_g.get_offset(); + size_t from = (size_t)(state_g.ptr_main()) - offset; + auto state = reinterpret_cast(addr + offset); if (pre_save_state(-1, state)) return; copy_state(from, addr); diff --git a/src/game_api/state.cpp b/src/game_api/state.cpp index 0cefbfa38..003141c9a 100644 --- a/src/game_api/state.cpp +++ b/src/game_api/state.cpp @@ -699,7 +699,7 @@ void init_state_update_hook() void HeapClone(uint64_t heap_to, uint64_t heap_container_from) { - uint64_t location = memory_read(State::get().get_location()); + uint64_t location = State::get().get_offset(); StateMemory* state_from = reinterpret_cast(memory_read(heap_container_from + 0x88) + location); StateMemory* state_to = reinterpret_cast(heap_to + location); pre_copy_state_event(state_from, state_to); diff --git a/src/game_api/state.hpp b/src/game_api/state.hpp index 73bde2c2e..a76663e48 100644 --- a/src/game_api/state.hpp +++ b/src/game_api/state.hpp @@ -8,6 +8,7 @@ #include "aliases.hpp" // for ENT_TYPE, LAYER #include "containers/custom_vector.hpp" // +#include "memory.hpp" // for memory_read #include "state_structs.hpp" // for JournalProgressStickerSlot, ... class Entity; @@ -397,9 +398,10 @@ struct State void set_seed(uint32_t seed); SaveData* savedata(); LiquidPhysicsEngine* get_correct_liquid_engine(ENT_TYPE liquid_type) const; - size_t get_location() + // Get the 0x4A0 offset + size_t get_offset() const { - return this->location; + return memory_read(location); } private: