Skip to content

Commit

Permalink
switch interop asi to use MinHook instead of detours
Browse files Browse the repository at this point in the history
  • Loading branch information
SirCxyrtyx committed Jun 23, 2021
1 parent 3ad1d70 commit 27c0774
Show file tree
Hide file tree
Showing 24 changed files with 3,049 additions and 9 deletions.
Binary file modified Binaries/ME3ExplorerInteropME2.asi
Binary file not shown.
14 changes: 12 additions & 2 deletions ME2-ASI-Plugins.sln
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ME3ExpInterop", "ME3ExpInte
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SeqActLogEnabler", "SeqActLogEnabler\SeqActLogEnabler.vcxproj", "{FCA74B26-594C-48AC-9206-00FAC7884944}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "minhook", "minhook\minhook.vcxproj", "{01EF0695-7E2C-45B5-9BFC-F5AC1DD254AF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Expand Down Expand Up @@ -75,8 +77,8 @@ Global
{7DCB9FDD-7BBA-4CF4-8253-EAC3C530556D}.Debug|x64.Build.0 = Debug|x64
{7DCB9FDD-7BBA-4CF4-8253-EAC3C530556D}.Debug|x86.ActiveCfg = Debug|Win32
{7DCB9FDD-7BBA-4CF4-8253-EAC3C530556D}.Debug|x86.Build.0 = Debug|Win32
{7DCB9FDD-7BBA-4CF4-8253-EAC3C530556D}.Release|x64.ActiveCfg = Release|x64
{7DCB9FDD-7BBA-4CF4-8253-EAC3C530556D}.Release|x64.Build.0 = Release|x64
{7DCB9FDD-7BBA-4CF4-8253-EAC3C530556D}.Release|x64.ActiveCfg = Release|Win32
{7DCB9FDD-7BBA-4CF4-8253-EAC3C530556D}.Release|x64.Build.0 = Release|Win32
{7DCB9FDD-7BBA-4CF4-8253-EAC3C530556D}.Release|x86.ActiveCfg = Release|Win32
{7DCB9FDD-7BBA-4CF4-8253-EAC3C530556D}.Release|x86.Build.0 = Release|Win32
{FCA74B26-594C-48AC-9206-00FAC7884944}.Debug|x64.ActiveCfg = Debug|Win32
Expand All @@ -85,6 +87,14 @@ Global
{FCA74B26-594C-48AC-9206-00FAC7884944}.Release|x64.ActiveCfg = Release|Win32
{FCA74B26-594C-48AC-9206-00FAC7884944}.Release|x86.ActiveCfg = Release|Win32
{FCA74B26-594C-48AC-9206-00FAC7884944}.Release|x86.Build.0 = Release|Win32
{01EF0695-7E2C-45B5-9BFC-F5AC1DD254AF}.Debug|x64.ActiveCfg = Debug|x64
{01EF0695-7E2C-45B5-9BFC-F5AC1DD254AF}.Debug|x64.Build.0 = Debug|x64
{01EF0695-7E2C-45B5-9BFC-F5AC1DD254AF}.Debug|x86.ActiveCfg = Debug|Win32
{01EF0695-7E2C-45B5-9BFC-F5AC1DD254AF}.Debug|x86.Build.0 = Debug|Win32
{01EF0695-7E2C-45B5-9BFC-F5AC1DD254AF}.Release|x64.ActiveCfg = Release|Win32
{01EF0695-7E2C-45B5-9BFC-F5AC1DD254AF}.Release|x64.Build.0 = Release|Win32
{01EF0695-7E2C-45B5-9BFC-F5AC1DD254AF}.Release|x86.ActiveCfg = Release|Win32
{01EF0695-7E2C-45B5-9BFC-F5AC1DD254AF}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
13 changes: 6 additions & 7 deletions ME3ExpInterop/ME3ExpInterop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
#include "Strsafe.h"

#include "..\ME2-SDK\ME3TweaksHeader.h"
#include "..\detours\detours.h"
#include "..\minhook\include\MinHook.h"

#define _CRT_SECURE_NO_WARNINGS
#pragma comment(lib, "detours.lib") //Library needed for Hooking part.
#pragma comment(lib, "shlwapi.lib")

TCHAR SplashPath[MAX_PATH];
Expand Down Expand Up @@ -259,6 +258,7 @@ void GetCamPOV(USequenceOp* const op)
}
}

tProcessEvent ProcessEvent_Orig = NULL;
void __fastcall HookedPE(UObject* pObject, void* edx, UFunction* pFunction, void* pParms, void* pResult)
{
const auto className = pObject->Class->GetName();
Expand Down Expand Up @@ -299,15 +299,14 @@ void __fastcall HookedPE(UObject* pObject, void* edx, UFunction* pFunction, void
const auto playerController = static_cast<ABioPlayerController*>(pObject);
cachedPOV = playerController->PlayerCamera->CameraCache.POV;
}
ProcessEvent(pObject, pFunction, pParms, pResult);
ProcessEvent_Orig(pObject, pFunction, pParms, pResult);
}

void onAttach()
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread()); //This command set the current working thread to the game current thread.
DetourAttach(&(PVOID&)ProcessEvent, HookedPE); //This command will start your Hook.
DetourTransactionCommit();
MH_Initialize();
MH_CreateHook(reinterpret_cast<LPVOID*>(ProcessEvent_Orig), HookedPE, reinterpret_cast<LPVOID*>(ProcessEvent));
MH_EnableHook(reinterpret_cast<LPVOID*>(ProcessEvent));
}

BOOL WINAPI DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
Expand Down
9 changes: 9 additions & 0 deletions ME3ExpInterop/ME3ExpInterop.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<TargetExt>.asi</TargetExt>
<TargetName>ME3ExplorerInteropME2</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<TargetExt>.asi</TargetExt>
<TargetName>ME3ExplorerInteropME2</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
Expand All @@ -93,6 +95,7 @@
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<IntrinsicFunctions>false</IntrinsicFunctions>
<FunctionLevelLinking>false</FunctionLevelLinking>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -110,6 +113,7 @@
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down Expand Up @@ -156,6 +160,11 @@
<ItemGroup>
<ClCompile Include="ME3ExpInterop.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\minhook\minhook.vcxproj">
<Project>{01ef0695-7e2c-45b5-9bfc-f5ac1dd254af}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
8 changes: 8 additions & 0 deletions minhook/AUTHORS.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Tsuda Kageyu <[email protected]>
Creator, maintainer

Michael Maltsev <[email protected]>
Added "Queue" functions. A lot of bug fixes.

Andrey Unis <[email protected]>
Rewrote the hook engine in plain C.
8 changes: 8 additions & 0 deletions minhook/CHANGES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
MinHook library is used in this project in a modified, non-original form.

- All public functions but MH_Initialize, MH_CreateHook, MH_EnableHook have been stripped off.
- HDE code for x32 has been stripped off.
- Number of changes were made to avoid false positives from MS Defender:
- FindHookEntry and EnterSpinLock have been given some dummy arguments.
- MH_Initialize has been given a nonsensical loop calling memcpy on a small buffer.
- MH_CreateHook has had its argument order reversed.
81 changes: 81 additions & 0 deletions minhook/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
MinHook - The Minimalistic API Hooking Library for x64/x86
Copyright (C) 2009-2017 Tsuda Kageyu.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

================================================================================
Portions of this software are Copyright (c) 2008-2009, Vyacheslav Patkov.
================================================================================
Hacker Disassembler Engine 32 C
Copyright (c) 2008-2009, Vyacheslav Patkov.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

-------------------------------------------------------------------------------
Hacker Disassembler Engine 64 C
Copyright (c) 2008-2009, Vyacheslav Patkov.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Loading

0 comments on commit 27c0774

Please sign in to comment.