Skip to content

Commit

Permalink
refactor: wip xmake work
Browse files Browse the repository at this point in the history
  • Loading branch information
shad0wshayd3 committed Nov 21, 2024
1 parent 38be174 commit 6936a27
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 228 deletions.
78 changes: 21 additions & 57 deletions src/MCM/MCM.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,72 +8,36 @@ namespace MCM
class General
{
public:
inline static bool bEnable{ true };
inline static REX::INI::Bool bEnable{ "Genreal", "bEnable", true };
};

class Setting
{
public:
inline static bool bAidWeight{ true };
inline static bool bAmmoWeight{ true };
inline static bool bConsole{ true };
inline static bool bEnemyMarkers{ true };
inline static bool bFastTravel{ true };
inline static bool bLocationMarkers{ true };
inline static bool bMenuSaving{ true };
inline static bool bQuickSaveLoad{ true };
inline static bool bSaveOnLevel{ true };
inline static bool bSaveOnPip{ true };
inline static bool bSaveOnSleep{ true };
inline static bool bSaveOnTravel{ true };
inline static bool bSaveOnWorkshop{ true };
inline static bool bSurvivalLock{ true };
inline static bool bToggleGodMode{ true };
inline static REX::INI::Bool bAidWeight{ "Setting", "bAidWeight", true };
inline static REX::INI::Bool bAmmoWeight{ "Setting", "bAmmoWeight", true };
inline static REX::INI::Bool bConsole{ "Setting", "bConsole", true };
inline static REX::INI::Bool bEnemyMarkers{ "Setting", "bEnemyMarkers", true };
inline static REX::INI::Bool bFastTravel{ "Setting", "bFastTravel", true };
inline static REX::INI::Bool bLocationMarkers{ "Setting", "bLocationMarkers", true };
inline static REX::INI::Bool bMenuSaving{ "Setting", "bMenuSaving", true };
inline static REX::INI::Bool bQuickSaveLoad{ "Setting", "bQuickSaveLoad", true };
inline static REX::INI::Bool bSaveOnLevel{ "Setting", "bSaveOnLevel", true };
inline static REX::INI::Bool bSaveOnPip{ "Setting", "bSaveOnPip", true };
inline static REX::INI::Bool bSaveOnSleep{ "Setting", "bSaveOnSleep", true };
inline static REX::INI::Bool bSaveOnTravel{ "Setting", "bSaveOnTravel", true };
inline static REX::INI::Bool bSaveOnWorkshop{ "Setting", "bSaveOnWorkshop", true };
inline static REX::INI::Bool bSurvivalLock{ "Setting", "bSurvivalLock", true };
inline static REX::INI::Bool bToggleGodMode{ "Setting", "bToggleGodMode", true };
};

static void Update()
{
if (m_FirstRun)
{
m_FirstRun = false;
}

m_ini_base.LoadFile("Data/MCM/Config/BakaSurvivalSettings/settings.ini");
m_ini_user.LoadFile("Data/MCM/Settings/BakaSurvivalSettings.ini");

GetModSettingBool("General", "bEnable", General::bEnable);

GetModSettingBool("Setting", "bAidWeight", Setting::bAidWeight);
GetModSettingBool("Setting", "bAmmoWeight", Setting::bAmmoWeight);
GetModSettingBool("Setting", "bConsole", Setting::bConsole);
GetModSettingBool("Setting", "bEnemyMarkers", Setting::bEnemyMarkers);
GetModSettingBool("Setting", "bFastTravel", Setting::bFastTravel);
GetModSettingBool("Setting", "bLocationMarkers", Setting::bLocationMarkers);
GetModSettingBool("Setting", "bMenuSaving", Setting::bMenuSaving);
GetModSettingBool("Setting", "bQuickSaveLoad", Setting::bQuickSaveLoad);
GetModSettingBool("Setting", "bSaveOnLevel", Setting::bSaveOnLevel);
GetModSettingBool("Setting", "bSaveOnPip", Setting::bSaveOnPip);
GetModSettingBool("Setting", "bSaveOnSleep", Setting::bSaveOnSleep);
GetModSettingBool("Setting", "bSaveOnTravel", Setting::bSaveOnTravel);
GetModSettingBool("Setting", "bSaveOnWorkshop", Setting::bSaveOnWorkshop);
GetModSettingBool("Setting", "bSurvivalLock", Setting::bSurvivalLock);
GetModSettingBool("Setting", "bToggleGodMode", Setting::bToggleGodMode);

m_ini_base.Reset();
m_ini_user.Reset();
const auto ini = REX::INI::SettingStore::GetSingleton();
ini->Init(
"Data/MCM/Config/BakaSurvivalSettings/settings.ini",
"Data/MCM/Settings/BakaSurvivalSettings.ini");
ini->Load();
}

inline static bool m_FirstRun{ true };

private:
static void GetModSettingBool(const std::string& a_section, const std::string& a_setting, bool& a_value)
{
auto base = m_ini_base.GetBoolValue(a_section.c_str(), a_setting.c_str(), a_value);
auto user = m_ini_user.GetBoolValue(a_section.c_str(), a_setting.c_str(), base);
a_value = user;
}

inline static CSimpleIniA m_ini_base{ true };
inline static CSimpleIniA m_ini_user{ true };
};
}
37 changes: 0 additions & 37 deletions src/PCH.cpp

This file was deleted.

25 changes: 2 additions & 23 deletions src/PCH.h
Original file line number Diff line number Diff line change
@@ -1,30 +1,9 @@
#pragma once

#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#pragma once

#include "F4SE/F4SE.h"
#include "RE/Fallout.h"
#include "REX/REX/INI.h"

#include <AutoTOML.hpp>
#include <SimpleIni.h>
#include <spdlog/sinks/basic_file_sink.h>
#include <xbyak/xbyak.h>

#define DLLEXPORT __declspec(dllexport)

using namespace std::literals;

namespace logger = F4SE::log;

namespace stl
{
using namespace F4SE::stl;

void asm_replace(std::uintptr_t a_from, std::size_t a_size, std::uintptr_t a_to);
}

// clang-format off
#include "Version.h"
#include "Settings.h"
// clang-format on
46 changes: 0 additions & 46 deletions src/Settings.h

This file was deleted.

93 changes: 28 additions & 65 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,84 +5,84 @@ class Hooks
public:
static void Install()
{
if (!MCM::Settings::General::bEnable)
if (!MCM::Settings::General::bEnable.GetValue())
{
return;
}

if (!MCM::Settings::Setting::bAidWeight)
if (!MCM::Settings::Setting::bAidWeight.GetValue())
{
hkcmpEAX<1321341, 0x97>::Install(); // TESWeightForm::GetFormWeight
}

if (!MCM::Settings::Setting::bAmmoWeight)
if (!MCM::Settings::Setting::bAmmoWeight.GetValue())
{
hkcmpEAX<1321341, 0x121>::Install(); // TESWeightForm::GetFormWeight
}

if (!MCM::Settings::Setting::bConsole)
if (!MCM::Settings::Setting::bConsole.GetValue())
{
hkcmpEAX<927099, 0x20F>::Install(); // MenuOpenHandler::HandleEvent
}

if (!MCM::Settings::Setting::bEnemyMarkers)
if (!MCM::Settings::Setting::bEnemyMarkers.GetValue())
{
hkcmpEAX<1475119, 0x23>::Install(); // HUDMarkerUtils::GetHostileEnemyMaxDistance
}

if (!MCM::Settings::Setting::bFastTravel)
if (!MCM::Settings::Setting::bFastTravel.GetValue())
{
hkcmpEAX<712982, 0x323>::Install(); // PipboyMenu::PipboyMenu
hkcmpEAX<1327120, 0x18>::Install(); // nsPipboyMenu::CheckHardcoreFastTravel
}

if (!MCM::Settings::Setting::bLocationMarkers)
if (!MCM::Settings::Setting::bLocationMarkers.GetValue())
{
hkcmpEAX<1301956, 0x10>::Install(); // HUDMarkerUtils::GetLocationMaxDistance
hkcmpEAX<1153736, 0xA7>::Install(); // CalculateCompassMarkersFunctor::UpdateLocationMarkers
}

if (!MCM::Settings::Setting::bMenuSaving)
if (!MCM::Settings::Setting::bMenuSaving.GetValue())
{
hkcmpEAX<1330449, 0xC6>::Install(); // PauseMenu::InitMainList
hkcmpEAX<425422, 0x4C>::Install(); // PauseMenu::CheckIfSaveLoadPossible
hkcmpEAX<540706, 0x6FE>::Install(); // BGSSaveLoadManager::DoLoadGame
hkcmpEBX<1103363, 0x81A>::Install(); // StartMenuBase::SendGameplayOptions
}

if (!MCM::Settings::Setting::bQuickSaveLoad)
if (!MCM::Settings::Setting::bQuickSaveLoad.GetValue())
{
hkcmpEAX<1470086, 0x71>::Install(); // QuickSaveLoadHandler::HandleEvent
}

if (!MCM::Settings::Setting::bSaveOnLevel)
if (!MCM::Settings::Setting::bSaveOnLevel.GetValue())
{
hkcmpEAX<1158548, 0x53>::Install(); // LevelUpMenu::~LevelUpMenu
}

if (!MCM::Settings::Setting::bSaveOnPip)
if (!MCM::Settings::Setting::bSaveOnPip.GetValue())
{
hkcmpEAX<1231000, 0x18F>::Install(); // PipboyManager::OnPipboyCloseAnim
}

if (!MCM::Settings::Setting::bSaveOnSleep)
if (!MCM::Settings::Setting::bSaveOnSleep.GetValue())
{
hkcmpEAX<1551767, 0xCC>::Install(); // PlayerCharacter::WakeUp
hkcmpEAX<1551767, 0x14B>::Install(); // PlayerCharacter::WakeUp
}

if (!MCM::Settings::Setting::bSaveOnTravel)
if (!MCM::Settings::Setting::bSaveOnTravel.GetValue())
{
hkcmpEAX<146861, 0x67D>::Install(); // PlayerCharacter::HandlePositionPlayerRequest
hkcmpEAX<374033, 0x2B>::Install(); // PlayerCharacter::RequestQueueDoorAutosave
}

if (!MCM::Settings::Setting::bSaveOnWorkshop)
if (!MCM::Settings::Setting::bSaveOnWorkshop.GetValue())
{
hkcmpEAX<98443, 0x198>::Install(); // WorkshopMenu::~WorkshopMenu
}

if (!MCM::Settings::Setting::bSurvivalLock)
if (!MCM::Settings::Setting::bSurvivalLock.GetValue())
{
// PauseMenu::CheckIfSaveLoadPossible
static REL::Relocation<std::uintptr_t> target{ REL::ID(425422), 0x14D };
Expand All @@ -91,7 +91,7 @@ class Hooks
hkmovEDX<402595, 0x28>::Install(); // ExitSurvivalModeCallback::operator()
}

if (!MCM::Settings::Setting::bToggleGodMode)
if (!MCM::Settings::Setting::bToggleGodMode.GetValue())
{
hkcmpEAX<1032309, 0x35>::Install(); // PlayerCharacter::IsGodMode
hkcmpEAX<500346, 0x35>::Install(); // PlayerCharacter::IsImmortal
Expand Down Expand Up @@ -176,63 +176,26 @@ class Hooks

namespace
{
void InitializeLog()
void MessageCallback(F4SE::MessagingInterface::Message* a_msg)
{
auto path = logger::log_directory();
if (!path)
switch (a_msg->type)
{
stl::report_and_fail("Failed to find standard logging directory"sv);
case F4SE::MessagingInterface::kPostLoad:
{
MCM::Settings::Update();
Hooks::Install();
break;
}
default:
break;
}

*path /= fmt::format(FMT_STRING("{:s}.log"sv), Version::PROJECT);
auto sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(path->string(), true);

auto log = std::make_shared<spdlog::logger>("global log"s, std::move(sink));
auto lvl = *Settings::General::EnableDebugLogging
? spdlog::level::trace
: spdlog::level::info;

log->set_level(lvl);
log->flush_on(lvl);

spdlog::set_default_logger(std::move(log));
spdlog::set_pattern("[%m/%d/%Y - %T] [%^%l%$] %v"s);

logger::info(FMT_STRING("{:s} v{:s}"sv), Version::PROJECT, Version::NAME);
}
}

extern "C" DLLEXPORT bool F4SEAPI F4SEPlugin_Query(const F4SE::QueryInterface* a_F4SE, F4SE::PluginInfo* a_info)
{
a_info->infoVersion = F4SE::PluginInfo::kVersion;
a_info->name = Version::PROJECT.data();
a_info->version = Version::MAJOR;

const auto rtv = a_F4SE->RuntimeVersion();
if (rtv < F4SE::RUNTIME_LATEST)
{
stl::report_and_fail(
fmt::format(
FMT_STRING("{:s} does not support runtime v{:s}."sv),
Version::PROJECT,
rtv.string()));
}

return true;
}

extern "C" DLLEXPORT bool F4SEAPI F4SEPlugin_Load(const F4SE::LoadInterface* a_F4SE)
F4SEPluginLoad(const F4SE::LoadInterface* a_F4SE)
{
Settings::Load();
InitializeLog();

logger::info(FMT_STRING("{:s} loaded."sv), Version::PROJECT);
logger::debug("Debug logging enabled."sv);

F4SE::Init(a_F4SE);

MCM::Settings::Update();
Hooks::Install();
F4SE::GetMessagingInterface()->RegisterListener(MessageCallback);

return true;
}
Loading

0 comments on commit 6936a27

Please sign in to comment.