Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 45 additions & 11 deletions lib/CoHModSDK/include/CoHModSDK.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ extern "C" {
using CoHModSDKConfigModVisitor = bool(*)(const char* modId, void* userData);
using CoHModSDKConfigOptionVisitor = bool(*)(const CoHModSDKConfigOptionV1* option, const CoHModSDKConfigValueV1* currentValue, void* userData);

struct CoHModSDKConfigModInfoV1 {
std::uint32_t abiVersion;
std::uint32_t size;
const char* modId;
const char* name;
const char* version;
const char* author;
};

struct CoHModSDKApiV1 {
std::uint32_t abiVersion;
std::uint32_t size;
Expand All @@ -132,13 +141,12 @@ extern "C" {
std::optional<std::uintptr_t> (*FindPattern)(const char* moduleName, const char* signature);
void (*PatchMemory)(void* destination, const void* source, std::size_t size);
bool (*CreateHook)(void* targetFunction, void* detourFunction, void** originalFunction);
bool (*EnableHook)(void* targetFunction);
bool (*DisableHook)(void* targetFunction);
bool (*RegisterConfigSchema)(const CoHModSDKConfigSchemaV1* schema);
bool (*GetConfigValue)(const char* modId, const char* optionId, CoHModSDKConfigValueV1* outValue);
bool (*SetConfigValue)(const char* modId, const char* optionId, const CoHModSDKConfigValueV1* value);
bool (*EnumerateConfigMods)(CoHModSDKConfigModVisitor visitor, void* userData);
bool (*EnumerateConfigOptions)(const char* modId, CoHModSDKConfigOptionVisitor visitor, void* userData);
bool (*GetConfigModInfo)(const char* modId, CoHModSDKConfigModInfoV1* outInfo);
};

struct CoHModSDKModuleV1 {
Expand All @@ -149,11 +157,11 @@ extern "C" {
const char* version;
const char* author;
bool (*OnInitialize)();
bool (*OnModsLoaded)();
void (*OnShutdown)();
};

COHMODSDK_RUNTIME_API bool CoHModSDKRuntime_Initialize(const CoHModSDKRuntimeInitV1* init);
COHMODSDK_RUNTIME_API void CoHModSDKRuntime_EnableAllHooks();
COHMODSDK_RUNTIME_API void CoHModSDKRuntime_Shutdown();
COHMODSDK_RUNTIME_API bool CoHModSDKRuntime_RegisterMod(HMODULE modHandle, const CoHModSDKModuleV1* module, const CoHModSDKModContextV1** outContext);
COHMODSDK_RUNTIME_API void CoHModSDKRuntime_UnregisterMod(HMODULE modHandle);
Expand Down Expand Up @@ -214,6 +222,22 @@ namespace ModSDK {
inline void Log(CoHModSDKLogLevel level, const char* message) {
Detail::GetApi().Log(Detail::GetModContext(), level, message);
}

inline void LogDebug(const char* message) {
Detail::GetApi().Log(Detail::GetModContext(), CoHModSDKLogLevel_Debug, message);
}

inline void LogInfo(const char* message) {
Detail::GetApi().Log(Detail::GetModContext(), CoHModSDKLogLevel_Info, message);
}

inline void LogWarning(const char* message) {
Detail::GetApi().Log(Detail::GetModContext(), CoHModSDKLogLevel_Warning, message);
}

inline void LogError(const char* message) {
Detail::GetApi().Log(Detail::GetModContext(), CoHModSDKLogLevel_Error, message);
}
}

namespace Dialogs {
Expand All @@ -230,19 +254,24 @@ namespace ModSDK {
inline void PatchMemory(void* destination, const void* source, std::size_t size) {
Detail::GetApi().PatchMemory(destination, source, size);
}
}

namespace Hooks {
inline bool CreateHook(void* targetFunction, void* detourFunction, void** originalFunction) {
return Detail::GetApi().CreateHook(targetFunction, detourFunction, originalFunction);
inline void* GetVTableEntry(void* instance, std::size_t index) {
return (*static_cast<void***>(instance))[index];
}

inline bool EnableHook(void* targetFunction) {
return Detail::GetApi().EnableHook(targetFunction);
template <typename T>
inline T ResolveExport(HMODULE module, const char* exportName) {
if ((module == nullptr) || (exportName == nullptr)) {
return nullptr;
}

return reinterpret_cast<T>(GetProcAddress(module, exportName));
}
}

inline bool DisableHook(void* targetFunction) {
return Detail::GetApi().DisableHook(targetFunction);
namespace Hooks {
inline bool CreateHook(void* targetFunction, void* detourFunction, void** originalFunction) {
return Detail::GetApi().CreateHook(targetFunction, detourFunction, originalFunction);
}
}

Expand All @@ -253,6 +282,7 @@ namespace ModSDK {
using Schema = CoHModSDKConfigSchemaV1;
using Type = CoHModSDKConfigType;
using Flags = CoHModSDKConfigFlags;
using ModInfo = CoHModSDKConfigModInfoV1;
using ChangedCallback = CoHModSDKConfigChangedCallback;
using ModVisitor = CoHModSDKConfigModVisitor;
using OptionVisitor = CoHModSDKConfigOptionVisitor;
Expand Down Expand Up @@ -304,5 +334,9 @@ namespace ModSDK {
inline bool EnumerateOptions(const char* modId, OptionVisitor visitor, void* userData) {
return Detail::GetApi().EnumerateConfigOptions(modId, visitor, userData);
}

inline bool GetModInfo(const char* modId, ModInfo* outInfo) {
return Detail::GetApi().GetConfigModInfo(modId, outInfo);
}
}
}
Binary file modified lib/CoHModSDK/lib/x86/CoHModSDK.lib
Binary file not shown.
8 changes: 4 additions & 4 deletions res/resource.rc
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,1,0,0
PRODUCTVERSION 1,1,0,0
FILEVERSION 1,2,0,0
PRODUCTVERSION 1,2,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -79,12 +79,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "Tosox"
VALUE "FileDescription", "Persists the bot faction when switching their difficulty"
VALUE "FileVersion", "1.1.0"
VALUE "FileVersion", "1.2.0"
VALUE "InternalName", "PersistentBotFaction"
VALUE "LegalCopyright", "Copyright © 2026"
VALUE "OriginalFilename", "PersistentBotFaction.dll"
VALUE "ProductName", "PersistentBotFaction"
VALUE "ProductVersion", "1.1.0"
VALUE "ProductVersion", "1.2.0"
END
END
BLOCK "VarFileInfo"
Expand Down
14 changes: 2 additions & 12 deletions src/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace {
}

int __fastcall HookedApplyPlayerSetupChange(void* _this, void* edx, int playerSlot, int setupCategory, int rawTeamValue,
int normalizedTeamValue, int selectionValue, int optionValue, void* slotAuxData) {
int normalizedTeamValue, int selectionValue, int optionValue, void* slotAuxData) {
HandleFactionCache(playerSlot, setupCategory, selectionValue, slotAuxData);

return oFnApplyPlayerSetupChange(_this, playerSlot, setupCategory, rawTeamValue,
Expand All @@ -74,19 +74,10 @@ namespace {
return false;
}

if (!ModSDK::Hooks::EnableHook(tApplyPlayerSetupChange)) {
ModSDK::Dialogs::ShowError("Failed to enable ApplyPlayerSetupChange hook");
return false;
}

return true;
}

bool OnInitialize() {
return true;
}

bool OnModsLoaded() {
return SetupHook();
}

Expand All @@ -99,10 +90,9 @@ namespace {
.size = sizeof(CoHModSDKModuleV1),
.modId = "de.tosox.persistentbotfaction",
.name = "Persistent Bot Faction",
.version = "1.1.0",
.version = "1.2.0",
.author = "Tosox",
.OnInitialize = &OnInitialize,
.OnModsLoaded = &OnModsLoaded,
.OnShutdown = &OnShutdown
};
}
Expand Down
Loading