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 815efb3 commit 94a996a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 161 deletions.
132 changes: 2 additions & 130 deletions src/PCH.h
Original file line number Diff line number Diff line change
@@ -1,137 +1,9 @@
#pragma once

// c
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfenv>
#include <cfloat>
#include <cinttypes>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cuchar>
#include <cwchar>
#include <cwctype>

// cxx
#include <algorithm>
#include <any>
#include <array>
#include <atomic>
#include <barrier>
#include <bit>
#include <bitset>
#include <charconv>
#include <chrono>
#include <compare>
#include <complex>
#include <concepts>
#include <condition_variable>
#include <deque>
#include <exception>
#include <execution>
#include <filesystem>
#include <format>
#include <forward_list>
#include <fstream>
#include <functional>
#include <future>
#include <initializer_list>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <latch>
#include <limits>
#include <locale>
#include <map>
#include <memory>
#include <memory_resource>
#include <mutex>
#include <new>
#include <numbers>
#include <numeric>
#include <optional>
#include <ostream>
#include <queue>
#include <random>
#include <ranges>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <semaphore>
#include <set>
#include <shared_mutex>
#include <source_location>
#include <span>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <string_view>
#include <syncstream>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <variant>
#include <vector>
#include <version>

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

// winnt
#include <ShlObj_core.h>

#undef min
#undef max
#include <xbyak/xbyak.h>

using namespace std::literals;

#define DLLEXPORT extern "C" [[maybe_unused]] __declspec(dllexport)

// Plugin
#include "Plugin.h"

// DKUtil
#include "DKUtil/Config.hpp"
#include "DKUtil/Hook.hpp"
#include "DKUtil/Logger.hpp"

// F4SEPlugin_Version
DLLEXPORT constinit auto F4SEPlugin_Version = []() noexcept
{
F4SE::PluginVersionData data{};

data.PluginVersion(Plugin::Version);
data.PluginName(Plugin::NAME);
data.AuthorName(Plugin::AUTHOR);
data.UsesAddressLibrary(true);
data.UsesSigScanning(false);
data.IsLayoutDependent(true);
data.HasNoStructUse(false);
data.CompatibleVersions({ F4SE::RUNTIME_LATEST });

return data;
}();
69 changes: 38 additions & 31 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
class Config
namespace Config
{
public:
class Fixes
namespace Fixes
{
public:
inline static DKUtil::Alias::Boolean bFixToggleScriptsCommand{ "bFixToggleScriptsCommand", "Fixes" };
inline static DKUtil::Alias::Boolean bFixScriptPageAllocation{ "bFixScriptPageAllocation", "Fixes" };
};
inline static REX::INI::Bool bFixToggleScriptsCommand{ "Fixes", "bFixToggleScriptsCommand", true };
inline static REX::INI::Bool bFixScriptPageAllocation{ "Fixes", "bFixScriptPageAllocation", true };
}

class Tweaks
namespace Tweaks
{
public:
inline static DKUtil::Alias::Integer iMaxPapyrusOpsPerFrame{ "iMaxPapyrusOpsPerFrame", "Tweaks" };
};
inline static REX::INI::I32 iMaxPapyrusOpsPerFrame{ "Tweaks", "iMaxPapyrusOpsPerFrame", 500 };
}

static void Load()
{
static auto Config = COMPILE_PROXY("BakaMaxPapyrusOps.ini");
Config.Bind(Fixes::bFixToggleScriptsCommand, true);
Config.Bind(Fixes::bFixScriptPageAllocation, true);
Config.Bind(Tweaks::iMaxPapyrusOpsPerFrame, 500);
Config.Load();
const auto ini = REX::INI::SettingStore::GetSingleton();
ini->Init(
"Data/F4SE/plugins/BakaMaxPapyrusOps.ini",
"Data/F4SE/plugins/BakaMaxPapyrusOpsCustom.ini");
ini->Load();
}
};
}

class Fixes
{
public:
static void Install()
{
if (*Config::Fixes::bFixScriptPageAllocation)
if (Config::Fixes::bFixScriptPageAllocation.GetValue())
{
FixScriptPageAllocation::Install();
}

if (*Config::Fixes::bFixToggleScriptsCommand)
if (Config::Fixes::bFixToggleScriptsCommand.GetValue())
{
FixToggleScriptsCommand::Install();
}
Expand Down Expand Up @@ -191,9 +188,9 @@ class Tweaks
public:
static void Install()
{
if (*Config::Tweaks::iMaxPapyrusOpsPerFrame > 0)
if (Config::Tweaks::iMaxPapyrusOpsPerFrame.GetValue() > 0)
{
MaxPapyrusOpsPerFrame::Update(*Config::Tweaks::iMaxPapyrusOpsPerFrame);
MaxPapyrusOpsPerFrame::Update(Config::Tweaks::iMaxPapyrusOpsPerFrame.GetValue());
MaxPapyrusOpsPerFrame::Install();
}
}
Expand Down Expand Up @@ -243,22 +240,32 @@ class Tweaks
};
};

DLLEXPORT bool F4SEAPI F4SEPlugin_Load(const F4SE::LoadInterface* a_F4SE)
namespace
{
#ifndef NDEBUG
MessageBoxA(NULL, "Loaded. You can now attach the debugger or continue execution.", Plugin::NAME.data(), NULL);
#endif
void MessageCallback(F4SE::MessagingInterface::Message* a_msg)
{
switch (a_msg->type)
{
case F4SE::MessagingInterface::kPostLoad:
{
Fixes::Install();
Tweaks::Install();
break;
}
default:
break;
}
}
}

F4SEPluginLoad(const F4SE::LoadInterface* a_F4SE)
{
F4SE::Init(a_F4SE);
F4SE::AllocTrampoline(1 << 8);

DKUtil::Logger::Init(Plugin::NAME, std::to_string(Plugin::Version));
INFO("{} v{} loaded."sv, Plugin::NAME, Plugin::Version);

Config::Load();

Fixes::Install();
Tweaks::Install();
F4SE::AllocTrampoline(1 << 8);
F4SE::GetMessagingInterface()->RegisterListener(MessageCallback);

return true;
}
4 changes: 4 additions & 0 deletions xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ set_policy("build.optimization.lto", true)
add_rules("mode.debug", "mode.releasedbg")
add_rules("plugin.vsxmake.autoupdate")

-- add config
set_config("f4se_xbyak", true)
set_config("rex_ini", true)

-- setup targets
target("BakaMaxPapyrusOps")
-- bind local dependencies
Expand Down

0 comments on commit 94a996a

Please sign in to comment.