Skip to content

Commit

Permalink
ChaosMod: Use DoesFeatureFlagExist helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
pongo1231 committed Feb 16, 2024
1 parent 197f859 commit ad9bc47
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion ChaosMod/Components/Voting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ bool Voting::Init()
auto str = _wcsdup(VOTING_PROXY_START_ARGS);
#ifdef _DEBUG
DWORD attributes = NULL;
if (DoesFileExist("chaosmod\\.forcenovotingconsole"))
if (DoesFeatureFlagExist("forcenovotingconsole"))
{
attributes = CREATE_NO_WINDOW;
}
Expand Down
2 changes: 1 addition & 1 deletion ChaosMod/Effects/Effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class RegisterEffect
{
static bool disableEffectRegistration = []()
{
return DoesFileExist("chaosmod\\.disablebuiltineffects");
return DoesFeatureFlagExist("disablebuiltineffects");
}();

if (disableEffectRegistration)
Expand Down
8 changes: 4 additions & 4 deletions ChaosMod/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static void Init()
}();

static std::streambuf *oldStreamBuf;
if (DoesFileExist("chaosmod\\.enableconsole"))
if (DoesFeatureFlagExist("enableconsole"))
{
if (GetConsoleWindow())
{
Expand Down Expand Up @@ -147,7 +147,7 @@ static void Init()
g_Random.SetSeed(g_OptionsManager.GetConfigValue({ "Seed" }, 0));

std::set<std::string> blacklistedComponentNames;
if (DoesFileExist("chaosmod\\.blacklistedcomponents"))
if (DoesFeatureFlagExist("blacklistedcomponents"))
{
std::ifstream file("chaosmod\\.blacklistedcomponents");
if (!file.fail())
Expand Down Expand Up @@ -200,7 +200,7 @@ static void Init()
INIT_COMPONENT("HelpTextQueue", "script help text queue", HelpTextQueue);

#ifdef WITH_DEBUG_PANEL_SUPPORT
if (DoesFileExist("chaosmod\\.enabledebugsocket"))
if (DoesFeatureFlagExist("enabledebugsocket"))
{
INIT_COMPONENT("DebugSocket", "Debug Websocket", DebugSocket);
}
Expand Down Expand Up @@ -276,7 +276,7 @@ static void MainRun()
{
isDisabled = false;

if (DoesFileExist("chaosmod\\.clearlogfileonreset"))
if (DoesFeatureFlagExist("clearlogfileonreset"))
{
// Clear log
g_Log = std::ofstream(CHAOS_LOG_FILE);
Expand Down
6 changes: 3 additions & 3 deletions ChaosMod/Memory/Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Memory

MH_Initialize();

if (DoesFileExist("chaosmod\\.skipintro"))
if (DoesFeatureFlagExist("skipintro"))
{
// Splash screen
Handle handle = FindPattern("E8 ? ? ? ? 8B CF 40 88 2D");
Expand Down Expand Up @@ -58,7 +58,7 @@ namespace Memory
}
}

if (DoesFileExist("chaosmod\\.skipdlcs"))
if (DoesFeatureFlagExist("skipdlcs"))
{
Handle handle = FindPattern("84 C0 74 2C 48 8D 15 ? ? ? ? 48 8D 0D ? ? ? ? 45 33 C9 41 B0 01");
if (!handle.IsValid())
Expand All @@ -73,7 +73,7 @@ namespace Memory
}
}

if (DoesFileExist("chaosmod\\.blacklistedhooks"))
if (DoesFeatureFlagExist("blacklistedhooks"))
{
std::ifstream file("chaosmod\\.blacklistedhooks");
if (!file.fail())
Expand Down
4 changes: 2 additions & 2 deletions ChaosMod/Util/CrashHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

inline LONG WINAPI CrashHandler(_EXCEPTION_POINTERS *exceptionInfo)
{
if (DoesFileExist("chaosmod\\.nodumps"))
if (DoesFeatureFlagExist("nodumps"))
{
return EXCEPTION_CONTINUE_SEARCH;
}
Expand All @@ -37,7 +37,7 @@ inline LONG WINAPI CrashHandler(_EXCEPTION_POINTERS *exceptionInfo)

DWORD flags = MiniDumpWithIndirectlyReferencedMemory | MiniDumpScanMemory;

if (DoesFileExist("chaosmod\\.fulldumps"))
if (DoesFeatureFlagExist("fulldumps"))
{
flags = MiniDumpWithFullMemory | MiniDumpWithHandleData | MiniDumpWithUnloadedModules
| MiniDumpWithProcessThreadData | MiniDumpWithFullMemoryInfo | MiniDumpWithThreadInfo;
Expand Down
5 changes: 5 additions & 0 deletions ChaosMod/Util/File.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ inline bool DoesFileExist(std::string_view fileName)
return stat(fileName.data(), &temp) == 0;
}

inline bool DoesFeatureFlagExist(const std::string &featureFlagName)
{
return DoesFileExist("chaosmod\\." + featureFlagName);
}

inline std::vector<std::filesystem::directory_entry> GetFiles(std::string path, std::string extension, bool recursive,
std::vector<std::string> blacklistedFiles = {})
{
Expand Down

0 comments on commit ad9bc47

Please sign in to comment.