Skip to content
This repository has been archived by the owner on Nov 17, 2024. It is now read-only.

Commit

Permalink
rm detours
Browse files Browse the repository at this point in the history
  • Loading branch information
HIllya51 committed Oct 21, 2024
1 parent 7c2055e commit bab75cb
Show file tree
Hide file tree
Showing 15 changed files with 1,027 additions and 2,184 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/version)
include(generate_product_version)

set(VERSION_MAJOR 3)
set(VERSION_MINOR 15)
set(VERSION_PATCH 1)
set(VERSION_MINOR 16)
set(VERSION_PATCH 0)
set(VERSION_REVISION 0)

if(BUILD_CORE)
Expand Down
2 changes: 1 addition & 1 deletion LunaHook/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ target_precompile_headers(LunaHook REUSE_FROM pchhook)

set_target_properties(LunaHook PROPERTIES OUTPUT_NAME "LunaHook${bitappendix}")

target_link_libraries(LunaHook Version httpapi ws2_32 Shlwapi pch minhook commonengine utils ${YY_Thunks_for_WinXP} ${Detours})
target_link_libraries(LunaHook Version httpapi ws2_32 Shlwapi pch minhook commonengine utils ${YY_Thunks_for_WinXP})
37 changes: 22 additions & 15 deletions LunaHook/embed_util.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "MinHook.h"

DynamicShiftJISCodec *dynamiccodec = new DynamicShiftJISCodec(932);

void cast_back(const HookParam &hp, void *data, size_t *len, const std::wstring &trans, bool normal)
Expand Down Expand Up @@ -72,14 +74,19 @@ bool _1f()
return 0;
}
bool _1 = _1f();
void ReplaceFunction(PVOID *oldf, PVOID newf)
bool ReplaceFunction(PVOID oldf, PVOID newf, PVOID *pOrigin)
{

RemoveHook((uintptr_t)*oldf);
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach((PVOID *)oldf, (PVOID)newf);
DetourTransactionCommit();
PVOID oldx;
if (!pOrigin)
pOrigin = &oldx;
RemoveHook((uintptr_t)oldf);
if (MH_OK == MH_CreateHook(oldf, newf, pOrigin))
return MH_OK == MH_EnableHook(oldf);
else
{
MH_RemoveHook(oldf);
return false;
}
}
void attachFunction(uintptr_t _hook_font_flag)
{
Expand All @@ -89,23 +96,23 @@ void attachFunction(uintptr_t _hook_font_flag)
{
if (_func.second.attached)
continue;
_func.second.attached = true;
*_func.second.oldFunction = _func.second.addr;
replacedfuns.push_back(_func.first);
ReplaceFunction((PVOID *)_func.second.oldFunction, (PVOID)_func.second.newFunction);

if (ReplaceFunction((PVOID)_func.second.addr, (PVOID)_func.second.newFunction, (PVOID *)_func.second.oldFunction))
{
_func.second.attached = true;
replacedfuns.push_back(_func.first);
}
}
}
}
void detachall()
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
for (auto _flag : replacedfuns)
{
auto info = funcs.at(_flag);
DetourDetach((PVOID *)info.oldFunction, (PVOID)info.newFunction);
if (MH_OK == MH_DisableHook((LPVOID)info.addr))
MH_RemoveHook((LPVOID)info.addr);
}
DetourTransactionCommit();
}
void solvefont(HookParam hp)
{
Expand Down
2 changes: 1 addition & 1 deletion LunaHook/embed_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Engine
};
}
inline std::atomic<void (*)()> patch_fun = nullptr;
void ReplaceFunction(PVOID *oldf, PVOID newf);
bool ReplaceFunction(PVOID oldf, PVOID newf, PVOID *pOrigin = nullptr);
bool check_embed_able(const ThreadParam &tp);
bool checktranslatedok(void *data, size_t len);
#endif
2 changes: 1 addition & 1 deletion LunaHook/engine32/CatSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ namespace
hp.hook_font = F_GetGlyphOutlineA;
patch_fun = []()
{
ReplaceFunction((PVOID *)&p, (PVOID)(ULONG)Patch::Private::isLeadByteChar);
ReplaceFunction((PVOID)p, (PVOID)(ULONG)Patch::Private::isLeadByteChar);
};
}

Expand Down
Loading

0 comments on commit bab75cb

Please sign in to comment.