Skip to content

Commit

Permalink
change get_location to get_offset, remove get_state_offset
Browse files Browse the repository at this point in the history
  • Loading branch information
estebanfer committed Aug 3, 2024
1 parent 98cb792 commit 9f70235
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
24 changes: 10 additions & 14 deletions src/game_api/savestate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(addr);
return 0x4a0;
}

StateMemory* get_save_state_raw(int slot)
{
size_t arr = get_address("save_states");
size_t base = memory_read<size_t>(arr + (slot - 1) * 8);
auto state = reinterpret_cast<StateMemory*>(base + get_state_offset());
auto state = reinterpret_cast<StateMemory*>(base + State::get().get_offset());
return state;
}

Expand Down Expand Up @@ -95,15 +87,17 @@ StateMemory* SaveState::get_state() const
{
if (!addr)
return nullptr;
return reinterpret_cast<StateMemory*>(addr + get_state_offset());
return reinterpret_cast<StateMemory*>(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<StateMemory*>(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<StateMemory*>(addr + offset);
if (pre_load_state(-1, state))
return;
copy_state(addr, to);
Expand All @@ -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<StateMemory*>(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<StateMemory*>(addr + offset);
if (pre_save_state(-1, state))
return;
copy_state(from, addr);
Expand Down
2 changes: 1 addition & 1 deletion src/game_api/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint64_t>(State::get().get_location());
uint64_t location = State::get().get_offset();
StateMemory* state_from = reinterpret_cast<StateMemory*>(memory_read<uint64_t>(heap_container_from + 0x88) + location);
StateMemory* state_to = reinterpret_cast<StateMemory*>(heap_to + location);
pre_copy_state_event(state_from, state_to);
Expand Down
6 changes: 4 additions & 2 deletions src/game_api/state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<size_t>(location);
}

private:
Expand Down

0 comments on commit 9f70235

Please sign in to comment.