metaforce/DataSpec/DNAMP1/Tweaks/CTweakGame.cpp

47 lines
1.9 KiB
C++
Raw Normal View History

2019-09-29 12:44:37 +00:00
#include "DataSpec/DNAMP1/Tweaks/CTweakGame.hpp"
2019-09-29 15:17:47 +00:00
#include "Runtime/Camera/CCameraManager.hpp"
2019-09-29 12:44:37 +00:00
#include <hecl/CVar.hpp>
#include <hecl/CVarManager.hpp>
2018-01-15 16:00:20 +00:00
2018-12-08 05:30:43 +00:00
namespace DataSpec::DNAMP1 {
2019-09-29 15:17:47 +00:00
hecl::CVar* tw_fov = nullptr;
hecl::CVar* tw_hardmodeDMult = nullptr;
hecl::CVar* tw_hardmodeWMult = nullptr;
2019-09-29 12:44:37 +00:00
namespace {
2019-10-05 14:07:13 +00:00
constexpr std::string_view skFov = "tweak.game.FieldOfView"sv;
constexpr std::string_view skHardModeDamageMultName = "tweak.game.HardModeDamageMult"sv;
constexpr std::string_view skHardModeWeaponMultName = "tweak.game.HardModeWeaponMult"sv;
2019-09-29 15:17:47 +00:00
} // anonymous namespace
2019-09-29 12:44:37 +00:00
void CTweakGame::_tweakGameListener(hecl::CVar* cv) {
2019-09-29 15:17:47 +00:00
if (cv == tw_fov) {
2019-09-29 12:44:37 +00:00
x24_fov = cv->toReal();
2019-09-29 15:17:47 +00:00
} else if (cv == tw_hardmodeDMult) {
2019-09-29 12:44:37 +00:00
x60_hardmodeDamageMult = cv->toReal();
2019-09-29 15:17:47 +00:00
} else if (cv == tw_hardmodeWMult) {
2019-09-29 12:44:37 +00:00
x64_hardmodeWeaponMult = cv->toReal();
}
}
2018-12-08 05:30:43 +00:00
void CTweakGame::initCVars(hecl::CVarManager* mgr) {
2019-09-29 12:44:37 +00:00
auto assignRealValue = [this, mgr](std::string_view name, std::string_view desc, float& v, hecl::CVar::EFlags flags) {
hecl::CVar* cv = mgr->findOrMakeCVar(name, desc, v, flags);
// Check if the CVar was deserialized, this avoid an unnecessary conversion
if (cv->wasDeserialized())
2019-10-05 14:07:13 +00:00
v = static_cast<float>(cv->toReal());
2019-09-29 12:44:37 +00:00
cv->addListener([this](hecl::CVar* cv) { _tweakGameListener(cv); });
2019-09-29 15:17:47 +00:00
return cv;
2019-09-29 12:44:37 +00:00
};
2019-09-29 15:17:47 +00:00
tw_fov = assignRealValue(skFov, "", x24_fov,
hecl::CVar::EFlags::Game | hecl::CVar::EFlags::Archive);
tw_hardmodeDMult =
assignRealValue(skHardModeDamageMultName, "", x60_hardmodeDamageMult,
hecl::CVar::EFlags::Game | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::Cheat);
tw_hardmodeWMult =
assignRealValue(skHardModeWeaponMultName, "", x64_hardmodeWeaponMult,
hecl::CVar::EFlags::Game | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::Cheat);
2018-01-15 16:00:20 +00:00
}
2018-12-08 05:30:43 +00:00
} // namespace DataSpec::DNAMP1