This repository has been archived by the owner on Oct 30, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
198 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
/* | ||
********************************************************************* | ||
* File : Common.cpp | ||
* Project : Smooth Interior Camera | ||
* Developers : Piotr Krupa ([email protected]) | ||
* License : MIT License | ||
********************************************************************* | ||
*/ | ||
/** @file Common.cpp | ||
** @author Piotr Krupa ([email protected]) | ||
** @license MIT License | ||
**/ | ||
|
||
#include "Common.h" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
/* | ||
********************************************************************* | ||
* File : Common.h | ||
* Project : Smooth Interior Camera | ||
* Developers : Piotr Krupa ([email protected]) | ||
* License : MIT License | ||
********************************************************************* | ||
*/ | ||
/** @file Common.h | ||
** @author Piotr Krupa ([email protected]) | ||
** @license MIT License | ||
**/ | ||
|
||
#pragma once | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
/* | ||
********************************************************************* | ||
* File : Hooks.cpp | ||
* Project : Smooth Interior Camera | ||
* Developers : Piotr Krupa ([email protected]) | ||
* License : MIT License | ||
********************************************************************* | ||
*/ | ||
/** @file Hooks.cpp | ||
** @author Piotr Krupa ([email protected]) | ||
** @license MIT License | ||
**/ | ||
|
||
#include "Hooks.h" | ||
|
||
|
@@ -14,15 +10,14 @@ | |
#include <sstream> | ||
#include <iomanip> | ||
|
||
#include <jitasm.h> | ||
|
||
#include "Memory/Hooking.Patterns.h" | ||
#include "Memory/MemMgr.h" | ||
#include "Mod/Mod.h" | ||
#include "Mod/Camera.h" | ||
#include "Mod/Config.h" | ||
#include "Game/prism.h" | ||
#include "Common.h" | ||
#include "Version.h" | ||
|
||
namespace Hooks | ||
{ | ||
|
@@ -42,7 +37,7 @@ namespace Hooks | |
pGameCam->m_ry = pGameCam->m_ry_predef; | ||
pGameCam->m_keyboardEv = false; | ||
} | ||
else if (g_pMod->IsConfigurating()) | ||
else if (g_pMod->IsConfiguring()) | ||
{ | ||
if (pGameCam->m_keyboardEv) | ||
{ | ||
|
@@ -72,9 +67,9 @@ namespace Hooks | |
{ | ||
rx = Config::Get()->GetValue((Config::CameraPos)i); | ||
|
||
#ifdef TESTING | ||
#ifdef TESTING | ||
std::cout << "New value for '" << pGameCam->m_rx_predef << "' is '" << rx << "'\n"; | ||
#endif | ||
#endif | ||
|
||
break; | ||
} | ||
|
@@ -88,88 +83,63 @@ namespace Hooks | |
} | ||
} | ||
|
||
struct : jitasm::Frontend | ||
{ | ||
uintptr_t callAddr; | ||
|
||
void InternalMain() override | ||
{ | ||
push(rax); | ||
push(rcx); | ||
push(rdx); | ||
push(r8); | ||
|
||
{ | ||
mov(rax, callAddr); | ||
call(rax); | ||
} | ||
|
||
pop(r8); | ||
pop(rdx); | ||
pop(rcx); | ||
pop(rax); | ||
uintptr_t CameraEvent_addr; | ||
|
||
add(rsp, 0x38); | ||
ret(); | ||
} | ||
} Asm_CameraEvent; | ||
#if defined(HOOK_V1) | ||
auto CameraEvent_pattern = "8B 81 B0 02 00 00 89 81 48 03 00 00 8B 81 B4 02 00 00 89 81 4C 03 00 00 C7 81 AC 02 00 00 00 00 00 00"; | ||
#elif defined(HOOK_V2) | ||
auto CameraEvent_pattern = "8B 81 B8 02 00 00 89 81 50 03 00 00 8B 81 BC 02 00 00 89 81 54 03 00 00 C7 81 B4 02 00 00 00 00 00 00"; | ||
#endif | ||
|
||
uintptr_t CameraEvent_addr; | ||
uint8_t CameraEvent_pattern[] = { 0x8B, 0x81, 0xB0, 0x02, 0x00, 0x00, 0x89, 0x81, 0x48, 0x03, 0x00, 0x00, 0x8B, 0x81, 0xB4, 0x02, 0x00, 0x00, 0x89, 0x81, 0x4C, 0x03, 0x00, 0x00, 0xC7, 0x81, 0xAC, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; | ||
extern "C" | ||
{ | ||
ptrdiff_t CameraEvent_Address = 0; | ||
void Asm_CameraEvent(); | ||
} | ||
|
||
bool Hook_CameraEvent() | ||
{ | ||
std::stringstream patternStr; | ||
|
||
for (int i = 0; i < sizeof(CameraEvent_pattern); ++i) | ||
{ | ||
patternStr << std::setfill('0') << std::setw(2) << std::hex << static_cast<int>(CameraEvent_pattern[i]) << " "; | ||
} | ||
|
||
auto pattern = hook::pattern(static_cast<const char*>(patternStr.str().c_str())); | ||
auto pattern = hook::pattern(CameraEvent_pattern); | ||
|
||
if (pattern.size() > 0) | ||
{ | ||
CameraEvent_addr = reinterpret_cast<uintptr_t>(pattern.count(1).get(0).get<void>(0)); | ||
|
||
#ifdef TESTING | ||
#ifdef TESTING | ||
std::cout << "CameraEvent addr: " << std::hex << CameraEvent_addr << "\n"; | ||
#endif | ||
#endif | ||
|
||
Asm_CameraEvent.callAddr = (uintptr_t)CameraEvent; | ||
MemMgr::LongJmpHook(CameraEvent_addr, (uintptr_t)Asm_CameraEvent.GetCode()); | ||
CameraEvent_Address = (uintptr_t)CameraEvent; | ||
MemMgr::LongJmpHook(CameraEvent_addr, (uintptr_t)Asm_CameraEvent); | ||
|
||
return true; | ||
} | ||
else | ||
{ | ||
Mod::Get()->Log(SCS_LOG_TYPE_error, "Data structure is incorrect!"); | ||
#ifdef TESTING | ||
#ifdef TESTING | ||
std::cout << "Hook for CameraEvent not found!\n"; | ||
#endif | ||
#endif | ||
return false; | ||
} | ||
} | ||
|
||
bool Init() | ||
{ | ||
#ifdef TESTING | ||
#ifdef TESTING | ||
std::cout << "Initializing hooks...\n"; | ||
#endif | ||
|
||
bool inited = true; | ||
#endif | ||
|
||
if (!Hook_CameraEvent()) | ||
inited = false; | ||
return false; | ||
|
||
#ifdef TESTING | ||
if (inited) | ||
std::cout << "Hooks initialized!\n"; | ||
#endif | ||
#ifdef TESTING | ||
std::cout << "Hooks initialized!\n"; | ||
#endif | ||
|
||
g_pMod = Mod::Get(); | ||
|
||
return inited; | ||
return true; | ||
} | ||
|
||
void Unhook() | ||
|
@@ -183,4 +153,4 @@ namespace Hooks | |
memcpy((uint8_t*)CameraEvent_addr, CameraEvent_pattern, sizeof(CameraEvent_pattern)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
/* | ||
********************************************************************* | ||
* File : Hooks.h | ||
* Project : Smooth Interior Camera | ||
* Developers : Piotr Krupa ([email protected]) | ||
* License : MIT License | ||
********************************************************************* | ||
*/ | ||
/** @file Hooks.h | ||
** @author Piotr Krupa ([email protected]) | ||
** @license MIT License | ||
**/ | ||
|
||
#pragma once | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
; ** @file HooksASM.asm | ||
; ** @author Piotr Krupa ([email protected]) | ||
; ** @license MIT License | ||
; ** | ||
|
||
extern CameraEvent_Address: qword | ||
|
||
.code | ||
|
||
Asm_CameraEvent PROC | ||
|
||
; backup registers | ||
push rax | ||
push rcx | ||
push rdx | ||
push r8 | ||
|
||
; call library function | ||
mov rax, CameraEvent_Address | ||
call rax | ||
|
||
; restore registers | ||
pop r8 | ||
pop rdx | ||
pop rcx | ||
pop rax | ||
|
||
add rsp, 38h | ||
ret | ||
|
||
Asm_CameraEvent ENDP | ||
|
||
End |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,31 @@ | ||
/* | ||
********************************************************************* | ||
* File : prism.h | ||
* Project : Smooth Interior Camera | ||
* Developers : Piotr Krupa ([email protected]) | ||
* License : MIT License | ||
********************************************************************* | ||
*/ | ||
/** @file prism.h | ||
** @author Piotr Krupa ([email protected]) | ||
** @license MIT License | ||
**/ | ||
|
||
#pragma once | ||
|
||
#include "Version.h" | ||
|
||
namespace prism | ||
{ | ||
class Camera | ||
template <size_t Offset1, size_t Offset2> | ||
class CameraBase | ||
{ | ||
public: | ||
char pad1[684]; // +0 | ||
unsigned m_keyboardEv; // +684 | ||
float m_rx_predef; // +688 | ||
float m_ry_predef; // +692 | ||
char pad3[144]; // +696 | ||
float m_rx; // +840 main camera | ||
float m_ry; // +844 | ||
char pad1[Offset1]; // +0 | ||
unsigned m_keyboardEv; // +Offset1 | ||
float m_rx_predef; // +Offset1 + 4 | ||
float m_ry_predef; // +Offset1 + 8 | ||
char pad2[Offset2]; // +Offset1 + 12 | ||
float m_rx; // +Offset2 | ||
float m_ry; // +Offset2 + 4 | ||
}; | ||
} | ||
|
||
|
||
#if defined(HOOK_V1) | ||
using Camera = CameraBase<684, 144>; | ||
#elif defined(HOOK_V2) | ||
using Camera = CameraBase<692, 144>; | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
/* | ||
********************************************************************* | ||
* File : Main.cpp | ||
* Project : Smooth Interior Camera | ||
* Developers : Piotr Krupa ([email protected]) | ||
* License : MIT License | ||
********************************************************************* | ||
*/ | ||
/** @file Main.cpp | ||
** @author Piotr Krupa ([email protected]) | ||
** @license MIT License | ||
**/ | ||
|
||
#include "Mod\Mod.h" | ||
|
||
|
@@ -41,4 +37,4 @@ int WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) | |
} | ||
|
||
return TRUE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
/* | ||
********************************************************************* | ||
* File : MemMgr.cpp | ||
* Project : Smooth Interior Camera | ||
* Developers : Piotr Krupa ([email protected]) | ||
* License : MIT License | ||
********************************************************************* | ||
*/ | ||
/** @file MemMgr.cpp | ||
** @author Piotr Krupa ([email protected]) | ||
** @license MIT License | ||
**/ | ||
|
||
#include "MemMgr.h" | ||
|
||
|
@@ -17,7 +13,7 @@ | |
xchg qword ptr ss:[rsp], rax | ||
ret | ||
*/ | ||
BYTE g_jmpHook[] = { 0x50, 0x48, 0xB8, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0x48, 0x87, 0x04, 0x24, 0xC3 }; | ||
unsigned char g_jmpHook[] = { 0x50, 0x48, 0xB8, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0x48, 0x87, 0x04, 0x24, 0xC3 }; | ||
|
||
void MemMgr::UnprotectMemory(uintptr_t addr, size_t size) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
/* | ||
********************************************************************* | ||
* File : MemMgr.h | ||
* Project : Smooth Interior Camera | ||
* Developers : Piotr Krupa ([email protected]) | ||
* License : MIT License | ||
********************************************************************* | ||
*/ | ||
/** @file MemMgr.h | ||
** @author Piotr Krupa ([email protected]) | ||
** @license MIT License | ||
**/ | ||
|
||
#pragma once | ||
|
||
|
Oops, something went wrong.