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

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Hary309 committed Dec 19, 2018
2 parents d385485 + 66b5fe6 commit 43313b3
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 26 deletions.
38 changes: 27 additions & 11 deletions src/Smooth Interior Camera/Game/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ namespace Hooks

void __cdecl CameraEvent(uintptr_t gameCamAddr)
{
auto pGameCam = reinterpret_cast<prism::GameCamera*>(gameCamAddr + gameCamOffset);
auto pGameCamPos = reinterpret_cast<prism::GameCameraPos*>(gameCamAddr + gameCamPosOffset);
auto pGameCam = reinterpret_cast<prism::InteriorCamera*>(gameCamAddr + gameCamOffset);
auto pGameCamPos = reinterpret_cast<prism::InteriorCameraPos*>(gameCamAddr + gameCamPosOffset);

auto pCam = g_pMod->GetCamera();
pCam->UpdateGameCamera(pGameCamPos);
Expand All @@ -46,7 +46,7 @@ namespace Hooks
{
for (short i = 0; i < 6; ++i)
{
if (floatEquals(pGameCam->m_rxEnd, Config::Get()->GetDefaultValue((Config::GameCameraPos)i)))
if (floatEquals(pGameCam->m_rxEnd, Config::Get()->GetDefaultValue((Config::InteriorCameraPos)i)))
{
g_pMod->Log(SCS_LOG_TYPE_message, "New value for [%d] %f is %f", i, Config::Get()->m_interiorCamPos[i], pGameCamPos->m_rx);
Config::Get()->m_interiorCamPos[i] = pGameCamPos->m_rx;
Expand All @@ -66,9 +66,9 @@ namespace Hooks

for (short i = 0; i < 6; ++i)
{
if (floatEquals(pGameCam->m_rxEnd, Config::Get()->GetDefaultValue((Config::GameCameraPos)i)))
if (floatEquals(pGameCam->m_rxEnd, Config::Get()->GetDefaultValue((Config::InteriorCameraPos)i)))
{
rx = Config::Get()->GetValue((Config::GameCameraPos)i);
rx = Config::Get()->GetValue((Config::InteriorCameraPos)i);

#ifdef TESTING
std::cout << "New value for '" << pGameCam->m_rxEnd << "' is '" << rx << "'\n";
Expand All @@ -90,31 +90,31 @@ namespace Hooks

auto CameraEvent_pattern = "8B 81 ?? ?? 00 00 89 81 ?? ?? 00 00 8B 81 ?? ?? 00 00 89 81 ?? ?? 00 00 C7 81 ?? ?? 00 00 00 00 00 00";

uint8_t baseBytes[34] = { 0 };

#if defined(X64)

extern "C"
{
uintptr_t CameraEvent_Address = 0;
uintptr_t CameraEvent_RetnAddress = 0;
void Asm_CameraEvent();
}

#elif defined(X86)

uintptr_t CameraEvent_Address = 0;
uintptr_t CameraEvent_RetnAddress = 0;

void __declspec(naked) Asm_CameraEvent()
{
__asm
{
pushad
push ecx
call CameraEvent_Address
add esp, 4
popad

mov esp, ebp
pop ebp
ret
jmp CameraEvent_RetnAddress
}
}

Expand All @@ -135,9 +135,21 @@ namespace Hooks
gameCamOffset = *reinterpret_cast<std::uint16_t*>(CameraEvent_addr + 2) - 4;
gameCamPosOffset = *reinterpret_cast<std::uint16_t*>(CameraEvent_addr + 8);

#ifdef TESTING
printf("Offsets: %i %i\n", gameCamOffset, gameCamPosOffset);
printf("Number of bytes to backup: %lld\n", sizeof(baseBytes));
#endif

// backup bytes
for (int i = 0; i < sizeof(baseBytes); ++i)
{
baseBytes[i] = *reinterpret_cast<std::uint8_t*>(CameraEvent_addr + i);
}

MemMgr::UnprotectMemory(CameraEvent_addr, sizeof(baseBytes));

CameraEvent_Address = reinterpret_cast<uintptr_t>(CameraEvent);
CameraEvent_RetnAddress = CameraEvent_addr + sizeof(baseBytes);
MemMgr::JmpHook(CameraEvent_addr, (uintptr_t)Asm_CameraEvent);

return true;
Expand Down Expand Up @@ -178,7 +190,11 @@ namespace Hooks
std::cout << "Unhooking...\n";
#endif

memcpy((uint8_t*)CameraEvent_addr, CameraEvent_pattern, sizeof(CameraEvent_pattern));
// restore bytes
for (int i = 0; i < sizeof(baseBytes); ++i)
{
*reinterpret_cast<std::uint8_t*>(CameraEvent_addr + i) = baseBytes[i];
}
}
}
}
9 changes: 4 additions & 5 deletions src/Smooth Interior Camera/Game/HooksASM.asm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
IFDEF RAX

extern CameraEvent_Address: qword
extern CameraEvent_RetnAddress: qword

.code

Expand All @@ -18,18 +19,16 @@ Asm_CameraEvent PROC
push r8

; call library function
mov rax, CameraEvent_Address
call rax
call CameraEvent_Address

; restore registers
pop r8
pop rdx
pop rcx
pop rax

add rsp, 38h
ret

; jump to End
jmp CameraEvent_RetnAddress
Asm_CameraEvent ENDP

ENDIF
Expand Down
6 changes: 4 additions & 2 deletions src/Smooth Interior Camera/Game/prism.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@

namespace prism
{
class GameCamera
class InteriorCamera
{
public:
unsigned m_keyboardEv; // +0
float m_rxEnd; // +4
float m_ryEnd; // +8
// +12
};

class GameCameraPos
class InteriorCameraPos
{
public:
float m_rx; // +0
float m_ry; // +4
// +8
};
}
2 changes: 1 addition & 1 deletion src/Smooth Interior Camera/Memory/MemMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#ifdef X64
/*
push rax
mov rax addr ; @addr - address to original
mov rax. [addr] ; @addr - address to original
xchg qword ptr ss:[rsp], rax
ret
*/
Expand Down
6 changes: 3 additions & 3 deletions src/Smooth Interior Camera/Mod/Camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class Camera
{
private:
prism::GameCameraPos *m_pGameCamera = nullptr;
prism::InteriorCameraPos *m_pGameCamera = nullptr;

float m_rxCurr = 0.f;
float m_rxStart = 0.f;
Expand All @@ -34,9 +34,9 @@ class Camera
void MoveTo(float rx);
void UpdateRX(float rx) { m_rxCurr = rx; }

void UpdateGameCamera(prism::GameCameraPos *gameCamera) { m_pGameCamera = gameCamera; }
void UpdateGameCamera(prism::InteriorCameraPos *gameCamera) { m_pGameCamera = gameCamera; }

prism::GameCameraPos *GetGameCamera() { return m_pGameCamera; }
prism::InteriorCameraPos *GetGameCamera() { return m_pGameCamera; }

void Pulse();

Expand Down
2 changes: 1 addition & 1 deletion src/Smooth Interior Camera/Mod/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Config
float m_interiorCamPos[6];


enum GameCameraPos
enum InteriorCameraPos
{
INTERIOR_LOOK_FORWARD = 0,
INTERIOR_LOOK_UP_RIGHT,
Expand Down
6 changes: 3 additions & 3 deletions src/Smooth Interior Camera/Version.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#define CURRENT_VERSION "1.3.0.0"
#define CURRENT_VERSION_SHORT 1300
#define CURRENT_VERSION_NUMBER 1,3,0,0
#define CURRENT_VERSION "1.3.1.0"
#define CURRENT_VERSION_SHORT 1310
#define CURRENT_VERSION_NUMBER 1,3,1,0


#ifdef _WIN64
Expand Down

0 comments on commit 43313b3

Please sign in to comment.