Skip to content
This repository has been archived by the owner on Sep 12, 2021. It is now read-only.

Commit

Permalink
Merge 016c9f3 into ea0f82a
Browse files Browse the repository at this point in the history
  • Loading branch information
DronCode authored Mar 16, 2020
2 parents ea0f82a + 016c9f3 commit daddfb0
Show file tree
Hide file tree
Showing 43 changed files with 2,671 additions and 567 deletions.
16 changes: 16 additions & 0 deletions HM3CoreKill/HM3CoreKill/HM3CoreKill.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="ck\Features.h" />
<ClInclude Include="ck\HM3CutSequencesRegistry.h" />
<ClInclude Include="ck\HM3DoorsRegistry.h" />
<ClInclude Include="ck\HM3ActionFactory.h" />
<ClInclude Include="ck\HM3AnimationRegistry.h" />
Expand All @@ -197,6 +198,7 @@
<ClInclude Include="ck\HM3FreeFileSystemLocatorProxy.h" />
<ClInclude Include="ck\HM3Function.h" />
<ClInclude Include="ck\HM3Game.h" />
<ClInclude Include="ck\HM3GamepadSupport.h" />
<ClInclude Include="ck\HM3Hooks.h" />
<ClInclude Include="ck\HM3InGameTools.h" />
<ClInclude Include="ck\HM3MemoryProvider.h" />
Expand All @@ -209,6 +211,7 @@
<ClInclude Include="sdk\actions\ZHitmanActionPickLock.h" />
<ClInclude Include="sdk\actions\ZHM3ActorPunch.h" />
<ClInclude Include="sdk\actions\ZLnkAction.h" />
<ClInclude Include="sdk\CCutSequence.h" />
<ClInclude Include="sdk\CDoor.h" />
<ClInclude Include="sdk\CIngameMap.h" />
<ClInclude Include="sdk\CInventory.h" />
Expand All @@ -229,12 +232,14 @@
<ClInclude Include="sdk\ResourceCollection.h" />
<ClInclude Include="sdk\scripting\ZScriptC.h" />
<ClInclude Include="sdk\ZActionDispatcher.h" />
<ClInclude Include="sdk\ZActionManager.h" />
<ClInclude Include="sdk\ZAnimationInfo.h" />
<ClInclude Include="sdk\ZBoxPrimitive.h" />
<ClInclude Include="sdk\ZDirect3DDevice.h" />
<ClInclude Include="sdk\ZEngineDatabase.h" />
<ClInclude Include="sdk\ZEntityLocator.h" />
<ClInclude Include="sdk\ZEventBuffer.h" />
<ClInclude Include="sdk\ZGameControlWintel.h" />
<ClInclude Include="sdk\ZGameFunctions.h" />
<ClInclude Include="sdk\ZGEOM.h" />
<ClInclude Include="sdk\ZGeomBuffer.h" />
Expand All @@ -257,19 +262,28 @@
<ClInclude Include="sdk\ZHM3ItemTemplateAmmo.h" />
<ClInclude Include="sdk\ZHM3LevelControl.h" />
<ClInclude Include="sdk\ZHM3MenuElements.h" />
<ClInclude Include="sdk\ZHM3MenuFactory.h" />
<ClInclude Include="sdk\ZHM3WeaponItem.h" />
<ClInclude Include="sdk\ZHumanBoid.h" />
<ClInclude Include="sdk\ZIKHAND.h" />
<ClInclude Include="sdk\ZKeyboardWintel.h" />
<ClInclude Include="sdk\ZLinkedListNodeBase.h" />
<ClInclude Include="sdk\ZLNKWHANDS.h" />
<ClInclude Include="sdk\ZMouseWintel.h" />
<ClInclude Include="sdk\ZOnlineElements.h" />
<ClInclude Include="sdk\ZOSD.h" />
<ClInclude Include="sdk\ZPathFollower.h" />
<ClInclude Include="sdk\ZRenderWintelD3D.h" />
<ClInclude Include="sdk\ZStandardMenuFactory.h" />
<ClInclude Include="sdk\ZSTD.h" />
<ClInclude Include="sdk\ZSysFile.h" />
<ClInclude Include="sdk\ZSysInputWintel.h" />
<ClInclude Include="sdk\ZSysInterfaceWintel.h" />
<ClInclude Include="sdk\ZSysMem.h" />
<ClInclude Include="sdk\ZCar.h" />
<ClInclude Include="sdk\ZWINDOW.h" />
<ClInclude Include="sdk\ZWINDOWS.h" />
<ClInclude Include="sdk\ZXMLGUISystem.h" />
<ClInclude Include="third_party\fmt\include\fmt\chrono.h" />
<ClInclude Include="third_party\fmt\include\fmt\color.h" />
<ClInclude Include="third_party\fmt\include\fmt\compile.h" />
Expand Down Expand Up @@ -301,11 +315,13 @@
<ClCompile Include="ck\HM3ActionFactory.cpp" />
<ClCompile Include="ck\HM3AnimationRegistry.cpp" />
<ClCompile Include="ck\HM3CrashHandler.cpp" />
<ClCompile Include="ck\HM3CutSequencesRegistry.cpp" />
<ClCompile Include="ck\HM3DebugConsole.cpp" />
<ClCompile Include="ck\HM3Direct3D.cpp" />
<ClCompile Include="ck\HM3DoorsRegistry.cpp" />
<ClCompile Include="ck\HM3FreeFileSystemLocatorProxy.cpp" />
<ClCompile Include="ck\HM3Game.cpp" />
<ClCompile Include="ck\HM3GamepadSupport.cpp" />
<ClCompile Include="ck\HM3Hooks.cpp" />
<ClCompile Include="ck\HM3InGameTools.cpp" />
<ClCompile Include="ck\HM3MemoryProvider.cpp" />
Expand Down
48 changes: 48 additions & 0 deletions HM3CoreKill/HM3CoreKill/HM3CoreKill.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,48 @@
<ClInclude Include="sdk\game\ZHM3MovementGuideToMatPos.h">
<Filter>sdk\game</Filter>
</ClInclude>
<ClInclude Include="sdk\ZCar.h">
<Filter>sdk</Filter>
</ClInclude>
<ClInclude Include="sdk\ZHumanBoid.h">
<Filter>sdk</Filter>
</ClInclude>
<ClInclude Include="sdk\ZPathFollower.h">
<Filter>sdk</Filter>
</ClInclude>
<ClInclude Include="sdk\CCutSequence.h">
<Filter>sdk</Filter>
</ClInclude>
<ClInclude Include="ck\HM3CutSequencesRegistry.h">
<Filter>ck</Filter>
</ClInclude>
<ClInclude Include="sdk\ZGameControlWintel.h">
<Filter>sdk</Filter>
</ClInclude>
<ClInclude Include="ck\HM3GamepadSupport.h">
<Filter>ck</Filter>
</ClInclude>
<ClInclude Include="sdk\ZActionManager.h">
<Filter>sdk</Filter>
</ClInclude>
<ClInclude Include="sdk\ZXMLGUISystem.h">
<Filter>sdk</Filter>
</ClInclude>
<ClInclude Include="sdk\ZWINDOWS.h">
<Filter>sdk</Filter>
</ClInclude>
<ClInclude Include="sdk\ZHM3MenuFactory.h">
<Filter>sdk</Filter>
</ClInclude>
<ClInclude Include="sdk\ZStandardMenuFactory.h">
<Filter>sdk</Filter>
</ClInclude>
<ClInclude Include="sdk\ZOnlineElements.h">
<Filter>sdk</Filter>
</ClInclude>
<ClInclude Include="sdk\ZWINDOW.h">
<Filter>sdk</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="ck\HM3DebugConsole.cpp">
Expand Down Expand Up @@ -466,5 +508,11 @@
<ClCompile Include="third_party\fmt\src\format.cc">
<Filter>third_party\fmt\src</Filter>
</ClCompile>
<ClCompile Include="ck\HM3CutSequencesRegistry.cpp">
<Filter>ck</Filter>
</ClCompile>
<ClCompile Include="ck\HM3GamepadSupport.cpp">
<Filter>ck</Filter>
</ClCompile>
</ItemGroup>
</Project>
37 changes: 37 additions & 0 deletions HM3CoreKill/HM3CoreKill/ck/HM3CutSequencesRegistry.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <ck/HM3CutSequencesRegistry.h>
#include <sdk/ZSTD.h>

namespace ck {

HM3CutSequencesRegistry& HM3CutSequencesRegistry::getRegistry()
{
static HM3CutSequencesRegistry instance;
return instance;
}

void HM3CutSequencesRegistry::registerCutSequence(ioi::hm3::CCutSequence* sequence)
{
if (!sequence)
return;

m_registry.push_back(sequence);
}

void HM3CutSequencesRegistry::reset()
{
m_registry.clear();
}

void HM3CutSequencesRegistry::forEach(std::function<void(ioi::hm3::CCutSequence*)> pred)
{
for (const auto& sequence : m_registry)
{
pred(sequence);
}
}

const std::list<ioi::hm3::CCutSequence*>& HM3CutSequencesRegistry::getList() const
{
return m_registry;
}
}
24 changes: 24 additions & 0 deletions HM3CoreKill/HM3CoreKill/ck/HM3CutSequencesRegistry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include <set>
#include <string>
#include <functional>
#include <sdk/CCutSequence.h>

namespace ck
{

class HM3CutSequencesRegistry
{
std::list<ioi::hm3::CCutSequence*> m_registry;
public:
static HM3CutSequencesRegistry& getRegistry();

void registerCutSequence(ioi::hm3::CCutSequence* sequence);
void reset();
void forEach(std::function<void(ioi::hm3::CCutSequence*)> pred);

const std::list<ioi::hm3::CCutSequence*>& getList() const;
};

}
34 changes: 20 additions & 14 deletions HM3CoreKill/HM3CoreKill/ck/HM3Direct3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,28 @@
#include <ck/HM3Function.h>
#include <ck/HM3InGameTools.h>

//#define CKD3D_USE_TEXTURES_HOOK
#define CKD3D_USE_VERTEX_BINDER_HOOK

namespace ck
{
static constexpr const int BeginSceneIndex = 41;
static constexpr const int EndSceneIndex = 42;
static constexpr const int ResetIndex = 16;
static constexpr const int CreateVertexBufferIndex = 26;
static constexpr const int SetTextureIndex = 65;
static constexpr const int DrawIndexedPrimitiveIndex = 82;

typedef HRESULT(__stdcall* D3DBeginScene_t)(IDirect3DDevice9*);
typedef HRESULT(__stdcall* D3DEndScene_t)(IDirect3DDevice9*);
typedef HRESULT(__stdcall* D3DReset_t)(IDirect3DDevice9*, D3DPRESENT_PARAMETERS*);
typedef HRESULT(__stdcall* D3DCreateVertexBuffer_t)(IDirect3DDevice9*, UINT, DWORD, DWORD, D3DPOOL, IDirect3DVertexBuffer9**, HANDLE*);
typedef HRESULT(__stdcall* D3DDrawIndexedPrimitive_t)(IDirect3DDevice9*, D3DPRIMITIVETYPE, INT, UINT, UINT, UINT, UINT);
typedef HRESULT(__stdcall* D3DSetTexture_t)(IDirect3DDevice9*, DWORD, IDirect3DBaseTexture9*);

D3DBeginScene_t originalBeginSceneFunc;
D3DEndScene_t originalEndSceneFunc;
D3DReset_t originalResetFunc;
D3DCreateVertexBuffer_t originalCreateVertexBufferFunc;
D3DDrawIndexedPrimitive_t originalDrawIndexedPrimitiveFunc;
D3DSetTexture_t originalD3DSetTextureFunc;

HRESULT __stdcall Direct3DDevice_OnBeginScene(IDirect3DDevice9* device)
{
Expand Down Expand Up @@ -55,12 +58,6 @@ namespace ck
return result;
}

HRESULT __stdcall Direct3DDevice_CreateVertexBuffer(IDirect3DDevice9* device, UINT Length, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer9** ppVertexBuffer, HANDLE* pSharedHandle)
{
auto result = originalCreateVertexBufferFunc(device, Length, Usage, FVF, Pool, ppVertexBuffer, pSharedHandle);
return result;
}

HRESULT __stdcall Direct3DDevice_DrawIndexedPrimitive(IDirect3DDevice9* device, D3DPRIMITIVETYPE primType, INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount)
{
HRESULT result = 0;
Expand Down Expand Up @@ -98,6 +95,11 @@ namespace ck
return result;
}

HRESULT __stdcall Direct3DDevice_SetTexture(IDirect3DDevice9* device, DWORD stage, IDirect3DBaseTexture9* texture)
{
return originalD3DSetTextureFunc(device, stage, texture);
}

HM3Direct3D& HM3Direct3D::getInstance()
{
static HM3Direct3D instance;
Expand All @@ -109,8 +111,6 @@ namespace ck
auto beginScenePtr = reinterpret_cast<D3DBeginScene_t>(HM3Function::hookVFTable((DWORD)device, BeginSceneIndex, (DWORD)Direct3DDevice_OnBeginScene, false));
auto endScenePtr = reinterpret_cast<D3DEndScene_t>(HM3Function::hookVFTable((DWORD)device, EndSceneIndex, (DWORD)Direct3DDevice_OnEndScene, false));
auto resetPtr = reinterpret_cast<D3DReset_t>(HM3Function::hookVFTable((DWORD)device, ResetIndex, (DWORD)Direct3DDevice_OnReset, false));
auto createVertexBufferPtr = reinterpret_cast<D3DCreateVertexBuffer_t>(HM3Function::hookVFTable((DWORD)device, CreateVertexBufferIndex, (DWORD)Direct3DDevice_CreateVertexBuffer, false));
auto drawIndexedPrimitivePtr = reinterpret_cast<D3DDrawIndexedPrimitive_t>(HM3Function::hookVFTable((DWORD)device, DrawIndexedPrimitiveIndex, (DWORD)Direct3DDevice_DrawIndexedPrimitive, false));

if ((DWORD)beginScenePtr != (DWORD)&Direct3DDevice_OnBeginScene)
originalBeginSceneFunc = (D3DBeginScene_t)beginScenePtr;
Expand All @@ -121,11 +121,17 @@ namespace ck
if ((DWORD)resetPtr != (DWORD)&Direct3DDevice_OnReset)
originalResetFunc = (D3DReset_t)resetPtr;

if ((DWORD)createVertexBufferPtr != (DWORD)&Direct3DDevice_CreateVertexBuffer)
originalCreateVertexBufferFunc = (D3DCreateVertexBuffer_t)createVertexBufferPtr;

#ifdef CKD3D_USE_VERTEX_BINDER_HOOK
auto drawIndexedPrimitivePtr = reinterpret_cast<D3DDrawIndexedPrimitive_t>(HM3Function::hookVFTable((DWORD)device, DrawIndexedPrimitiveIndex, (DWORD)Direct3DDevice_DrawIndexedPrimitive, false));
if ((DWORD)drawIndexedPrimitivePtr != (DWORD)&Direct3DDevice_DrawIndexedPrimitive)
originalDrawIndexedPrimitiveFunc = (D3DDrawIndexedPrimitive_t)drawIndexedPrimitivePtr;
#endif

#ifdef CKD3D_USE_TEXTURES_HOOK
auto setTexturePtr = reinterpret_cast<D3DSetTexture_t>(HM3Function::hookVFTable((DWORD)device, SetTextureIndex, (DWORD)Direct3DDevice_SetTexture, false));
if ((DWORD)setTexturePtr != (DWORD)&Direct3DDevice_SetTexture)
originalD3DSetTextureFunc = (D3DSetTexture_t)setTexturePtr;
#endif
}

void HM3Direct3D::initialize(IDirect3DDevice9* device)
Expand Down
Loading

0 comments on commit daddfb0

Please sign in to comment.