Skip to content

Commit

Permalink
ChaosMod: Get rid of -fpermissive for non-msvc compilers
Browse files Browse the repository at this point in the history
  • Loading branch information
pongo1231 committed Feb 3, 2024
1 parent 9490ad5 commit f8198fa
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion ChaosMod/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
target_compile_options(ChaosMod PRIVATE -DUNICODE -D_UNICODE -DNOMINMAX /Zi)
target_link_options(ChaosMod PRIVATE /DEBUG /OPT:REF /OPT:ICF)
else()
target_compile_options(ChaosMod PRIVATE -municode -fpermissive)
target_compile_options(ChaosMod PRIVATE -municode)
target_link_options(ChaosMod PRIVATE -static)
endif()

Expand Down
4 changes: 2 additions & 2 deletions ChaosMod/Components/LuaScripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ _LUAFUNC sol::object LuaInvoke(const std::string &scriptName, const sol::this_st
switch (returnType)
{
case LuaNativeReturnType::Bool:
return sol::make_object(lua, reinterpret_cast<bool>(*returned));
return sol::make_object(lua, *reinterpret_cast<bool *>(returned));
case LuaNativeReturnType::Int:
return sol::make_object(lua, reinterpret_cast<int>(*returned));
return sol::make_object(lua, *reinterpret_cast<int *>(returned));
case LuaNativeReturnType::Float:
return sol::make_object(lua, *reinterpret_cast<float *>(returned));
case LuaNativeReturnType::String:
Expand Down
4 changes: 2 additions & 2 deletions ChaosMod/Memory/Hooks/PresentHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static bool OnHook()

ms_PresentAddr = handle.At(64).Get<void *>();
OG_IDXGISwapChain_Present = *(HRESULT(**)(IDXGISwapChain *, UINT, UINT))ms_PresentAddr;
Memory::Write<void *>(ms_PresentAddr, HK_IDXGISwapChain_Present);
Memory::Write<void *>(ms_PresentAddr, reinterpret_cast<void *>(HK_IDXGISwapChain_Present));

return true;
}
Expand All @@ -43,7 +43,7 @@ static void OnCleanup()
// Only reset vftable entries if address still points to our retour
if (ms_PresentAddr && *ms_PresentAddr == HK_IDXGISwapChain_Present)
{
Memory::Write<void *>(ms_PresentAddr, OG_IDXGISwapChain_Present);
Memory::Write<void *>(ms_PresentAddr, reinterpret_cast<void *>(OG_IDXGISwapChain_Present));
}
}

Expand Down
12 changes: 0 additions & 12 deletions ChaosMod/Memory/Memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,6 @@ namespace Memory
return scanPattern();
}

MH_STATUS AddHook(void *target, void *detour, void *orig)
{
auto result = MH_CreateHook(target, detour, reinterpret_cast<void **>(orig));

if (result == MH_OK)
{
MH_EnableHook(target);
}

return result;
}

const char *GetTypeName(__int64 vftAddr)
{
if (vftAddr)
Expand Down
13 changes: 12 additions & 1 deletion ChaosMod/Memory/Memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,18 @@ namespace Memory
};

Handle FindPattern(const std::string &pattern, const PatternScanRange &&scanRange = {});
MH_STATUS AddHook(void *target, void *detour, void *orig);

template <typename T> inline MH_STATUS AddHook(void *target, T detour, T *orig)
{
auto result = MH_CreateHook(target, reinterpret_cast<void *>(detour), reinterpret_cast<void **>(orig));

if (result == MH_OK)
{
MH_EnableHook(target);
}

return result;
}

template <typename T> inline void Write(T *addr, T value, int count = 1)
{
Expand Down

0 comments on commit f8198fa

Please sign in to comment.