Skip to content

Commit

Permalink
Add free camera and pause game for TRAE
Browse files Browse the repository at this point in the history
  • Loading branch information
TheIndra55 committed Mar 25, 2021
1 parent 89bb4bd commit 07cdfb2
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
52 changes: 52 additions & 0 deletions Camera.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "Hooking.hpp"
#include "Camera.hpp"

void(__cdecl* origCAMERA_Process)(Camera* camera);

bool(__cdecl* EVENT_InputActionOn)(int action);
void(__cdecl* CAMERA_CalcPosition)(cdc::Vector* position, cdc::Vector* base, cdc::Vector* rotation, float distance);
double(__thiscall* InputSystem_GetAxisValue)(int _this, int a2);

void CAMERA_Fly(Camera* camera)
{
auto speed = EVENT_InputActionOn(18);

if (EVENT_InputActionOn(1)) // forward
{
CAMERA_CalcPosition(&camera->position, &camera->position, &camera->rotation, speed ? -50.f : -20.f);
}

if (EVENT_InputActionOn(2)) // backward
{
CAMERA_CalcPosition(&camera->position, &camera->position, &camera->rotation, speed ? 50.f : 20.f);
}

auto a = InputSystem_GetAxisValue(*(int*)0x008551A0, 17);
auto b = InputSystem_GetAxisValue(*(int*)0x008551A0, 16);

camera->rotation.x -= a;
camera->rotation.z -= b;
}

void __cdecl CAMERA_Process(Camera* camera)
{
origCAMERA_Process(camera);

if (*(__int16*)0x850984 == 7)
{
CAMERA_Fly(camera);
}
}

void InstallCameraHooks()
{
#if TRAE
MH_CreateHook((void*)0x481D70, CAMERA_Process, (void**)&origCAMERA_Process);

EVENT_InputActionOn = reinterpret_cast<bool(__cdecl*)(int)>(0x42F740);
CAMERA_CalcPosition = reinterpret_cast<void(__cdecl*)(cdc::Vector*, cdc::Vector*, cdc::Vector*, float)>(0x00491320);
InputSystem_GetAxisValue = reinterpret_cast<double(__thiscall*)(int, int)>(0x004E38C0);

MH_EnableHook(MH_ALL_HOOKS);
#endif
}
11 changes: 11 additions & 0 deletions Camera.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once
#include "Game.hpp"

void InstallCameraHooks();

struct Camera
{
cdc::Vector position;
char padding[608];
cdc::Vector rotation;
};
3 changes: 3 additions & 0 deletions Hooking.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "Hooking.hpp"
#include "Game.hpp"
#include "ControlHooks.hpp"
#include "Camera.hpp"

extern Hooking* g_hooking;

Expand All @@ -21,6 +22,8 @@ void Hooking::Initialize()
#endif

InstallControlHooks();
InstallCameraHooks();

Game::Initialize();

MH_EnableHook(MH_ALL_HOOKS);
Expand Down
19 changes: 19 additions & 0 deletions Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,25 @@ void Menu::Process(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
Game::ToggleBinoculars();
}

if (msg == WM_KEYUP && wparam == VK_F3)
{
auto streamFlags = (int*)0x8383F4;
if (*streamFlags & 0x1000)
{
*streamFlags &= 0xFFFFEFFF;
}
else
{
*streamFlags |= 0x1000u;
}
}

if (msg == WM_KEYUP && wparam == VK_F4)
{
auto cameraMode = (int*)0x850984;
*cameraMode = *cameraMode == 7 ? 2 : 7;
}

if (switchPlayerNextFrame)
{
switchPlayerNextFrame = false;
Expand Down

0 comments on commit 07cdfb2

Please sign in to comment.