Skip to content

Commit

Permalink
clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
Pistonight committed Sep 8, 2024
1 parent 08ddea1 commit 4640375
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 104 deletions.
50 changes: 29 additions & 21 deletions src/core/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ static const char* get_enabled_text(bool value) {
return value ? "Enabled" : "Disabled";
}

static const char* get_toggle_text(bool value) {
return value ? "On" : "Off";
}
static const char* get_toggle_text(bool value) { return value ? "On" : "Off"; }

Command Controller::update_setting_mode() {
m_tick_since_last_menu_input++;
Expand Down Expand Up @@ -212,11 +210,12 @@ Command Controller::update_setting_mode() {
}
Key new_key = get_hold_keys();
if (finish_configure_key(new_key)) {
mem::StringBuffer<16> key_name;
mem::StringBuffer<16> key_name;
get_key_name(key_name, m_key_being_configured);
mem::StringBuffer<120> buffer;
mem::StringBuffer<120> buffer;
get_key_string(new_key, buffer);
msg::widget::printf("Changed %s key\n to: %s", key_name.content(), buffer.content());
msg::widget::printf("Changed %s key\n to: %s",
key_name.content(), buffer.content());

m_key_being_configured = nullptr;
m_tick_since_last_menu_input = 0;
Expand Down Expand Up @@ -261,16 +260,21 @@ Command Controller::update_setting_mode() {
m_tick_since_last_menu_input = 0;
switch (m_menu_current_option) {
case 0:
msg::widget::print(
"Restore Message\n\nWhen disabled, there will be no\nmessage shown when "
"executing a\nstate restore. Useful for grinding\nBTT segments.");
msg::widget::print("Restore Message\n\nWhen disabled, there "
"will be no\nmessage shown when "
"executing a\nstate restore. Useful for "
"grinding\nBTT segments.");
break;
case 1:
msg::widget::print("Timers\n\nEnable save/restore TOD, Bloodmoon,\nChampion Ability, "
"Master Sword,\nPotion, and Weather Damage Timers.");
msg::widget::print(
"Timers\n\nEnable save/restore TOD, Bloodmoon,\nChampion "
"Ability, "
"Master Sword,\nPotion, and Weather Damage Timers.");
break;
case 2:
msg::widget::print("Inventory\n\nEnable save/restore the inventory\nstate. Equipments will be synced.");
msg::widget::print(
"Inventory\n\nEnable save/restore the inventory\nstate. "
"Equipments will be synced.");
break;
}
}
Expand All @@ -279,7 +283,8 @@ Command Controller::update_setting_mode() {
switch (m_menu_current_option) {
case 0:
value = !m_config->m_show_restore_message;
msg::info::printf("Restore Message: %s", get_enabled_text(value));
msg::info::printf("Restore Message: %s",
get_enabled_text(value));
m_config->m_show_restore_message = value;
break;
case 1:
Expand Down Expand Up @@ -357,12 +362,15 @@ void Controller::refresh_menu() {
m_menu_subtitle.copy("[A] Toggle; [X] Explain");
m_menu_options_count = 3;
m_menu_options[0].clear();
m_menu_options[0].appendf("[%s] Restore Message",
get_toggle_text(m_config->m_show_restore_message));
m_menu_options[0].appendf(
"[%s] Restore Message",
get_toggle_text(m_config->m_show_restore_message));
m_menu_options[1].clear();
m_menu_options[1].appendf("[%s] Timers", get_toggle_text(m_config->m_enable_timers));
m_menu_options[1].appendf("[%s] Timers",
get_toggle_text(m_config->m_enable_timers));
m_menu_options[2].clear();
m_menu_options[2].appendf("[%s] Inventory", get_toggle_text(m_config->m_enable_inventory));
m_menu_options[2].appendf(
"[%s] Inventory", get_toggle_text(m_config->m_enable_inventory));
break;
}
if (m_menu_current_option >= m_menu_options_count) {
Expand Down Expand Up @@ -390,9 +398,9 @@ void Controller::show_configuring_key_message() {
get_key_name(key_name, m_key_being_configured);
mem::StringBuffer<50> current_combo;
get_key_string(*m_key_being_configured, current_combo);
msg::widget::printf(
"Changing: %s\nCurrent:\n%s\nHold new combo for 3 seconds.\nHold ZL to cancel",
key_name.content(), current_combo.content());
msg::widget::printf("Changing: %s\nCurrent:\n%s\nHold new combo for 3 "
"seconds.\nHold ZL to cancel",
key_name.content(), current_combo.content());
}

} // namespace botw::savs
} // namespace botw::savs
14 changes: 9 additions & 5 deletions src/core/controller.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#pragma once

#include <exl/types.h>
#include <toolkit/mem/string.hpp>
#include <toolkit/io/data_reader.hpp>
#include <toolkit/io/data_writer.hpp>
#include <toolkit/mem/string.hpp>

#include "core/state.hpp"

Expand Down Expand Up @@ -40,7 +40,8 @@ inline constexpr Key operator|(Key a, Key b) {
return static_cast<Key>(static_cast<u32>(a) | static_cast<u32>(b));
}

constexpr Key KEY_SETTINGS = Key::DpadDown | Key::ZL | Key::ZR | Key::L | Key::R;
constexpr Key KEY_SETTINGS =
Key::DpadDown | Key::ZL | Key::ZR | Key::L | Key::R;
constexpr Key KEY_INCREASE_LEVEL = Key::R;
constexpr Key KEY_DECREASE_LEVEL = Key::L;

Expand Down Expand Up @@ -115,7 +116,8 @@ enum class Command {
};

constexpr size_t MENU_BUFFER_LEN = 40;
constexpr u32 MENU_REFRESH_TICKS = 60; // refresh menu after this time if there is no input
constexpr u32 MENU_REFRESH_TICKS =
60; // refresh menu after this time if there is no input
constexpr u32 MENU_INPUT_INTERVAL = 3;

class Controller {
Expand Down Expand Up @@ -167,7 +169,9 @@ class Controller {
m_holding_keys = Key::None;
m_hold_counter = 0;
}
bool is_configuring_key() const { return m_key_being_configured != nullptr; }
bool is_configuring_key() const {
return m_key_being_configured != nullptr;
}
void start_configure_key(Key* key);
bool finish_configure_key(Key new_key);
void get_key_name(mem::StringBuffer<16>& out_buffer, Key* key) const {
Expand All @@ -188,4 +192,4 @@ class Controller {
void refresh_menu();
void show_configuring_key_message();
};
} // namespace botw::savs
} // namespace botw::savs
2 changes: 1 addition & 1 deletion src/core/reporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ void Reporter::report(const char* field, bool success) {
}
return;
}
} // namespace botw::savs
} // namespace botw::savs
5 changes: 2 additions & 3 deletions src/core/reporter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ class Reporter {
bool has_error() const { return m_error_count > 0; }
void mark_error() { m_mark_error = m_error_count; }
bool has_more_errors() const { return m_mark_error < m_error_count; }
template <u32 L>
void append_fields_to(mem::StringBuffer<L>& out) const {
template <u32 L> void append_fields_to(mem::StringBuffer<L>& out) const {
u32 max = std::min(m_error_count, 5u);
for (u32 i = 0; i < max; i++) {
out.appendf("--%s", m_fields[i].content());
Expand All @@ -32,4 +31,4 @@ class Reporter {
mem::StringBuffer<36> m_fields[5];
};

} // namespace botw::savs
} // namespace botw::savs
119 changes: 76 additions & 43 deletions src/core/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
#include <Game/UI/uiPauseMenuDataMgr.h>
#include <KingSystem/ActorSystem/actBaseProc.h>
#include <KingSystem/ActorSystem/actBaseProcMgr.h>
#include <toolkit/pmdm.hpp>
#include <toolkit/equipment.hpp>
#include <toolkit/tcp.hpp>
#include <toolkit/io/data_reader.hpp>
#include <toolkit/io/data_writer.hpp>
#include <toolkit/mem/named_value.hpp>
#include <toolkit/pmdm.hpp>
#include <toolkit/sead/list.hpp>
#include <toolkit/tcp.hpp>

#include "core/version.hpp"
#include "core/state.hpp"
#include "core/version.hpp"
#include "impl/raw_ptr.hpp"

namespace botw::savs {
Expand Down Expand Up @@ -40,10 +40,12 @@ void State::read_from_game(Reporter& r, const StateConfig& config) {
m_stored_essentials = false;
r.report("Health", raw_ptr::health().get(&m_health));
r.report("Stamina", raw_ptr::stamina().get(&m_stamina));
r.report("HavokPosition", raw_ptr::havok_position().get_array(m_havok_position, 3));
r.report("MainPositionMatrix",
raw_ptr::main_position_matrix().get_array(m_main_position_matrix, 12));
r.report("CamPanMatrix", raw_ptr::camera_pan_matrix().get_array(m_camera_pan_matrix, 12));
r.report("HavokPosition",
raw_ptr::havok_position().get_array(m_havok_position, 3));
r.report("MainPositionMatrix", raw_ptr::main_position_matrix().get_array(
m_main_position_matrix, 12));
r.report("CamPanMatrix",
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));
if (!r.has_error()) {
Expand All @@ -55,28 +57,41 @@ void State::read_from_game(Reporter& r, const StateConfig& config) {
m_stored_timers = false;
if (config.m_enable_timers) {
r.report("TODPaused", raw_ptr::time_of_day_paused().get(&m_tod_paused));
r.report("TODUnpause", raw_ptr::time_of_day_unpaused().get(&m_tod_unpaused));
r.report("TODUnpause",
raw_ptr::time_of_day_unpaused().get(&m_tod_unpaused));
r.report("BMTimer", raw_ptr::blood_moon().get(&m_blood_moon_timer));
r.report("TempDmg", raw_ptr::temperature_damage_timer().get(&m_temperature_damage_timer));
r.report("TempDmg", raw_ptr::temperature_damage_timer().get(
&m_temperature_damage_timer));
r.report("FlameDmg", raw_ptr::flame_timer().get(&m_flame_timer));
r.report("Gale", raw_ptr::gale_timer().get(&m_gale_timer));
r.report("Fury", raw_ptr::fury_timer().get(&m_fury_timer));
r.report("DarukP", raw_ptr::protection_timer().get(&m_protection_timer));
r.report("DarukP",
raw_ptr::protection_timer().get(&m_protection_timer));
r.report("Grace", raw_ptr::grace_timer().get(&m_grace_timer));
r.report("ChampUse", raw_ptr::ability_uses().get_array(m_ability_uses, 3));
r.report("MS", raw_ptr::master_sword_cooldown().get(&m_master_sword_cooldown));
r.report("Speed1", raw_ptr::speed_potion_timer1().get(&m_speed_potion_timer_1));
r.report("Speed2", raw_ptr::speed_potion_timer2().get(&m_speed_potion_timer_2));
r.report("Speed3", raw_ptr::speed_potion_timer3().get(&m_speed_potion_timer_3));
r.report("AtkTime", raw_ptr::attack_potion_timer().get(&m_attack_potion_timer));
r.report("DefTime", raw_ptr::defense_potion_timer().get(&m_defense_potion_timer));
r.report("HeatResT", raw_ptr::heat_resist_potion_timer().get(&m_heat_resist_potion_timer));
r.report("ColdResT", raw_ptr::cold_resist_potion_timer().get(&m_cold_resist_potion_timer));
r.report("FireResT",
raw_ptr::flame_resist_potion_timer().get(&m_flame_resist_potion_timer));
r.report("ElecResT",
raw_ptr::shock_resist_potion_timer().get(&m_shock_resist_potion_timer));
r.report("StealthT", raw_ptr::stealth_potion_timer().get(&m_stealth_potion_timer));
r.report("ChampUse",
raw_ptr::ability_uses().get_array(m_ability_uses, 3));
r.report("MS", raw_ptr::master_sword_cooldown().get(
&m_master_sword_cooldown));
r.report("Speed1",
raw_ptr::speed_potion_timer1().get(&m_speed_potion_timer_1));
r.report("Speed2",
raw_ptr::speed_potion_timer2().get(&m_speed_potion_timer_2));
r.report("Speed3",
raw_ptr::speed_potion_timer3().get(&m_speed_potion_timer_3));
r.report("AtkTime",
raw_ptr::attack_potion_timer().get(&m_attack_potion_timer));
r.report("DefTime",
raw_ptr::defense_potion_timer().get(&m_defense_potion_timer));
r.report("HeatResT", raw_ptr::heat_resist_potion_timer().get(
&m_heat_resist_potion_timer));
r.report("ColdResT", raw_ptr::cold_resist_potion_timer().get(
&m_cold_resist_potion_timer));
r.report("FireResT", raw_ptr::flame_resist_potion_timer().get(
&m_flame_resist_potion_timer));
r.report("ElecResT", raw_ptr::shock_resist_potion_timer().get(
&m_shock_resist_potion_timer));
r.report("StealthT",
raw_ptr::stealth_potion_timer().get(&m_stealth_potion_timer));
if (!r.has_more_errors()) {
m_stored_timers = true;
}
Expand All @@ -99,15 +114,19 @@ void State::read_from_game(Reporter& r, const StateConfig& config) {
}
}

void State::write_to_game(Reporter& r, const StateConfig& config, bool hold) const {
void State::write_to_game(Reporter& r, const StateConfig& config,
bool hold) const {
// essentials
if (m_stored_essentials) {
r.report("Health", raw_ptr::health().set(m_health));
r.report("Stamina", raw_ptr::stamina().set(m_stamina));
r.report("HavokPosition", raw_ptr::havok_position().set_array(m_havok_position, 3));
r.report("HavokPosition",
raw_ptr::havok_position().set_array(m_havok_position, 3));
r.report("MainPositionMatrix",
raw_ptr::main_position_matrix().set_array(m_main_position_matrix, 12));
r.report("CamPanMatrix", raw_ptr::camera_pan_matrix().set_array(m_camera_pan_matrix, 12));
raw_ptr::main_position_matrix().set_array(
m_main_position_matrix, 12));
r.report("CamPanMatrix", raw_ptr::camera_pan_matrix().set_array(
m_camera_pan_matrix, 12));
r.report("CamZoom", raw_ptr::camera_zoom().set(m_camera_zoom));
r.report("CamTilt", raw_ptr::camera_tilt().set(m_camera_tilt));

Expand Down Expand Up @@ -137,26 +156,40 @@ void State::write_to_game(Reporter& r, const StateConfig& config, bool hold) con
// timers
if (m_stored_timers && config.m_enable_timers) {
r.report("TODPaused", raw_ptr::time_of_day_paused().set(m_tod_paused));
r.report("TODUnpause", raw_ptr::time_of_day_unpaused().set(m_tod_unpaused));
r.report("TODUnpause",
raw_ptr::time_of_day_unpaused().set(m_tod_unpaused));
r.report("BMTimer", raw_ptr::blood_moon().set(m_blood_moon_timer));
r.report("TempDmg", raw_ptr::temperature_damage_timer().set(m_temperature_damage_timer));
r.report("TempDmg", raw_ptr::temperature_damage_timer().set(
m_temperature_damage_timer));
r.report("FlameDmg", raw_ptr::flame_timer().set(m_flame_timer));
r.report("Gale", raw_ptr::gale_timer().set(m_gale_timer));
r.report("Fury", raw_ptr::fury_timer().set(m_fury_timer));
r.report("DarukP", raw_ptr::protection_timer().set(m_protection_timer));
r.report("Grace", raw_ptr::grace_timer().set(m_grace_timer));
r.report("ChampUse", raw_ptr::ability_uses().set_array(m_ability_uses, 3));
r.report("MS", raw_ptr::master_sword_cooldown().set(m_master_sword_cooldown));
r.report("Speed1", raw_ptr::speed_potion_timer1().set(m_speed_potion_timer_1));
r.report("Speed2", raw_ptr::speed_potion_timer2().set(m_speed_potion_timer_2));
r.report("Speed3", raw_ptr::speed_potion_timer3().set(m_speed_potion_timer_3));
r.report("AtkTime", raw_ptr::attack_potion_timer().set(m_attack_potion_timer));
r.report("DefTime", raw_ptr::defense_potion_timer().set(m_defense_potion_timer));
r.report("HeatResT", raw_ptr::heat_resist_potion_timer().set(m_heat_resist_potion_timer));
r.report("ColdResT", raw_ptr::cold_resist_potion_timer().set(m_cold_resist_potion_timer));
r.report("FireResT", raw_ptr::flame_resist_potion_timer().set(m_flame_resist_potion_timer));
r.report("ElecResT", raw_ptr::shock_resist_potion_timer().set(m_shock_resist_potion_timer));
r.report("StealthT", raw_ptr::stealth_potion_timer().set(m_stealth_potion_timer));
r.report("ChampUse",
raw_ptr::ability_uses().set_array(m_ability_uses, 3));
r.report("MS",
raw_ptr::master_sword_cooldown().set(m_master_sword_cooldown));
r.report("Speed1",
raw_ptr::speed_potion_timer1().set(m_speed_potion_timer_1));
r.report("Speed2",
raw_ptr::speed_potion_timer2().set(m_speed_potion_timer_2));
r.report("Speed3",
raw_ptr::speed_potion_timer3().set(m_speed_potion_timer_3));
r.report("AtkTime",
raw_ptr::attack_potion_timer().set(m_attack_potion_timer));
r.report("DefTime",
raw_ptr::defense_potion_timer().set(m_defense_potion_timer));
r.report("HeatResT", raw_ptr::heat_resist_potion_timer().set(
m_heat_resist_potion_timer));
r.report("ColdResT", raw_ptr::cold_resist_potion_timer().set(
m_cold_resist_potion_timer));
r.report("FireResT", raw_ptr::flame_resist_potion_timer().set(
m_flame_resist_potion_timer));
r.report("ElecResT", raw_ptr::shock_resist_potion_timer().set(
m_shock_resist_potion_timer));
r.report("StealthT",
raw_ptr::stealth_potion_timer().set(m_stealth_potion_timer));
}

// inventory
Expand Down Expand Up @@ -293,4 +326,4 @@ StateFileResult State::write_to_file(io::DataWriter& w) const {
return StateFileResult::Ok;
}

} // namespace botw::savs
} // namespace botw::savs
15 changes: 9 additions & 6 deletions src/core/state.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#pragma once

#include <exl/types.h>
#include <toolkit/pmdm.hpp>
#include <toolkit/io/data_reader.hpp>
#include <toolkit/io/data_writer.hpp>
#include <toolkit/pmdm.hpp>

#include "core/reporter.hpp"

Expand All @@ -22,16 +22,19 @@ class StateConfig {
void read_config(io::DataReader& r);
// show info message when restoring
bool m_show_restore_message = true;
// enable TOD, bloodmoon, ability, master sword, potion, and climate damage timers
// enable TOD, bloodmoon, ability, master sword, potion, and climate damage
// timers
bool m_enable_timers = true;
// enable restoring inventory state, including full pmdm and num offset slots
// enable restoring inventory state, including full pmdm and num offset
// slots
bool m_enable_inventory = false;
};

class State {
public:
void read_from_game(Reporter& reporter, const StateConfig& config);
void write_to_game(Reporter& reporter, const StateConfig& config, bool hold) const;
void write_to_game(Reporter& reporter, const StateConfig& config,
bool hold) const;
StateFileResult read_from_file(io::DataReader& reader);
StateFileResult write_to_file(io::DataWriter& writer) const;

Expand Down Expand Up @@ -93,8 +96,8 @@ class State {
// even though the pmdm state covers this
// this field still exists to allow people to change the state manually
// to easily break slots
s32 m_num_inventory_count_offset;
s32 m_num_inventory_count_offset;
toolkit::PmdmSaveState m_pmdm_state;
};

} // namespace botw::savs
} // namespace botw::savs
Loading

0 comments on commit 4640375

Please sign in to comment.