Skip to content

Commit

Permalink
use rune mgr to save/restore runes (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pistonight authored Dec 3, 2024
1 parent 928945d commit 32f2bfa
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 34 deletions.
29 changes: 0 additions & 29 deletions CHANGELOG.md

This file was deleted.

1 change: 1 addition & 0 deletions Megaton.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ includes = [
"libs/nnheaders/include",
]
ldscripts = [
"symbols.ld",
"libs/botw-symbols/ld/ld160.ld",
"libs/botw-symbols/ld/toolkit160.ld",
]
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ The following will always be enabled, and you cannot turn them off:
- Current Stamina
- Position (Havok Position and Main Position Matrix)
- Camera Matrix
- Selected Rune

Additionally, the following will happen when you restore, regardless of the setting:
- Runes will finish cooldown
Expand Down
23 changes: 23 additions & 0 deletions src/core/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "core/state.hpp"
#include "core/version.hpp"
#include "impl/raw_ptr.hpp"
#include "impl/rune.hpp"

namespace botw::savs {

Expand Down Expand Up @@ -53,6 +54,14 @@ void State::read_from_game(Reporter& r, const StateConfig& config) {
raw_ptr::camera_pan_matrix().get_array(m_camera_pan_matrix, 12));
r.report("CamZoom", raw_ptr::camera_zoom().get(&m_camera_zoom));
r.report("CamTilt", raw_ptr::camera_tilt().get(&m_camera_tilt));

auto rune_mgr = RuneMgr::get_instance();
if (rune_mgr == nullptr) {
r.report("RuneMgr", false);
} else {
m_rune = rune_mgr->get_current();
}

if (!r.has_error()) {
m_stored_essentials = true;
}
Expand Down Expand Up @@ -135,6 +144,14 @@ void State::write_to_game(Reporter& r, const StateConfig& config,
r.report("CamZoom", raw_ptr::camera_zoom().set(m_camera_zoom));
r.report("CamTilt", raw_ptr::camera_tilt().set(m_camera_tilt));

// selected rune
auto rune_mgr = RuneMgr::get_instance();
if (rune_mgr == nullptr) {
r.report("RuneMgr", false);
} else {
rune_mgr->set_current(m_rune);
}

// extras
r.report("RdBombCD", raw_ptr::round_bomb_cooldown().set(360.0F));
r.report("SqBombCD", raw_ptr::square_bomb_cooldown().set(360.0F));
Expand Down Expand Up @@ -271,6 +288,10 @@ StateFileResult State::read_from_file(io::DataReader& r) {
m_pmdm_state.read_from_file(r);
}

if (version >= Version::v8) {
r.read_integer(&m_rune);
}

if (!r.is_successful()) {
clear();
return StateFileResult::IOError;
Expand Down Expand Up @@ -325,6 +346,8 @@ StateFileResult State::write_to_file(io::DataWriter& w) const {
w.write_integer(_named(m_num_inventory_count_offset));
m_pmdm_state.write_to_file(w);

w.write_integer(_named(m_rune));

if (!w.is_successful()) {
return StateFileResult::IOError;
}
Expand Down
3 changes: 1 addition & 2 deletions src/core/state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,11 @@ class State {
float m_camera_pan_matrix[12];
float m_camera_zoom;
float m_camera_tilt;
u32 m_rune;
/* Extra stuff always restored:
* - Rune cooldown
* - Delete bombs
* - TODO: fall damage
* - TODO: selected rune
*
*/

// timers
Expand Down
7 changes: 4 additions & 3 deletions src/core/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ namespace botw::savs {
enum Version {
vLegacy = 4, // no longer supported
v5 = 5,
v6 = 6,
v7 = 7,
vLatest = v7
v6 = 6, // inventory (PMDM)
v7 = 7, // speedometer
v8 = 8, // rune
vLatest = v8
};
}
25 changes: 25 additions & 0 deletions src/impl/rune.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <toolkit/scoped_lock.hpp>

#include "rune.hpp"

extern "C" {

// 0x02C9A668
extern botw::savs::RuneMgr* botw_savs__RuneMgr;
}

namespace botw::savs {

RuneMgr* RuneMgr::get_instance() { return botw_savs__RuneMgr; }

void RuneMgr::set_current(u32 rune_type) {
toolkit::ScopedLock lock(&item_cs.mCriticalSectionInner);
this->rune_type = rune_type;
}

u32 RuneMgr::get_current() {
toolkit::ScopedLock lock(&item_cs.mCriticalSectionInner);
return this->rune_type;
}

} // namespace botw::savs
23 changes: 23 additions & 0 deletions src/impl/rune.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include <thread/seadCriticalSection.h>

// TODO: upstream to decomp
//
namespace botw::savs {

class RuneMgr {
public:
static RuneMgr* get_instance();

void set_current(u32 rune_type);
u32 get_current();

char _x0[0x200];
sead::CriticalSection item_cs;
u32 rune_type;
};

static_assert(offsetof(RuneMgr, rune_type) == 0x240, "");

} // namespace botw::savs
1 change: 1 addition & 0 deletions symbols.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PROVIDE_HIDDEN(botw_savs__RuneMgr = 0x02C9A668 - 0x3483000);

0 comments on commit 32f2bfa

Please sign in to comment.