Skip to content

Commit

Permalink
Add skew cheat
Browse files Browse the repository at this point in the history
  • Loading branch information
TheIndra55 committed Jan 14, 2024
1 parent 8a136c4 commit 22594d7
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

#include "Hook.h"
#include "input/MessageHook.h"
#include "instance/Instances.h"
#include "game/Game.h"

// Modules
#include "modules/InstanceViewer.h"
#include "modules/Skew.h"

#include "cdc/render/PCDeviceManager.h"

Expand All @@ -29,6 +32,9 @@ Hook::Hook() : m_menu(nullptr), m_modules()

void Hook::Initialize()
{
Instances::Init();
Game::Init();

RegisterModules();

MH_Initialize();
Expand Down Expand Up @@ -75,6 +81,7 @@ void Hook::RegisterModule()
void Hook::RegisterModules()
{
RegisterModule<InstanceViewer>();
RegisterModule<Skew>();
}

Hook& Hook::GetInstance()
Expand Down
15 changes: 15 additions & 0 deletions src/game/Game.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "Game.h"

void Game::Init()
{
}

Instance* Game::GetPlayerInstance()
{
return GetGameTracker()->playerInstance;
}

GameTracker* Game::GetGameTracker()
{
return (GameTracker*)0x838330;
}
61 changes: 61 additions & 0 deletions src/game/Game.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#pragma once

#include "instance/Instance.h"

struct menu_t;
struct MemCardInfo;
struct Level;
struct VertexPool;

struct WipeInfo
{
float wipeCur;
float wipeTarget;
float wipeStep;
};

struct GameTracker
{
menu_t* menu;
MemCardInfo* memcard;
Level* level;
Instance* playerInstance;
VertexPool* vertexPool;

int debugFlags;
int debugFlags2;
int debugFlags3;
int debugFlags4;

WipeInfo wipes[12];

unsigned int displayFrameCount;
unsigned int frameCount;

int fpsFast;
int gameFlags;
int streamFlags;
Level* mainDrawUnit;

char baseAreaName[20];

char levelDone;
char levelChange;
char loadingDisplayType;
char gameMode;
char cheatMode;
char savingGame;

char pad1[66];

float timeMult;
};

class Game
{
public:
static void Init();

static Instance* GetPlayerInstance();
static GameTracker* GetGameTracker();
};
12 changes: 12 additions & 0 deletions src/instance/Instances.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#include "Instances.h"

static void(*INSTANCE_Post)(Instance*, int, int);

void Instances::Init()
{
INSTANCE_Post = reinterpret_cast<void(*)(Instance*, int, int)>(0x4580B0);
}

void Instances::Iterate(std::function<void(Instance*)> callback)
{
auto first = *(Instance**)0x817D64;
Expand All @@ -8,4 +15,9 @@ void Instances::Iterate(std::function<void(Instance*)> callback)
{
callback(instance);
}
}

void Instances::Post(Instance* instance, int message, int data)
{
INSTANCE_Post(instance, message, data);
}
3 changes: 3 additions & 0 deletions src/instance/Instances.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
class Instances
{
public:
static void Init();

static void Iterate(std::function<void(Instance*)> callback);
static void Post(Instance* instance, int message, int data);
};
48 changes: 48 additions & 0 deletions src/modules/Skew.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "Skew.h"

#include "instance/Instances.h"
#include "game/Game.h"

void Skew::ToggleSkew()
{
auto tracker = Game::GetGameTracker();

tracker->cheatMode = !tracker->cheatMode;
Instances::Post(tracker->playerInstance, 1048592, tracker->cheatMode);
}

void Skew::Process(UINT msg, WPARAM wParam)
{
// TODO different keyboard layouts
// TODO configurable horizontal speed

auto player = Game::GetPlayerInstance();
auto tracker = Game::GetGameTracker();

auto speed = 200.f * tracker->timeMult;

if (msg == WM_KEYDOWN && wParam == 0x51)
{
player->position.z += speed;
}

if (msg == WM_KEYDOWN && wParam == 0x5A)
{
player->position.z -= speed;
}
}

void Skew::OnInput(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
if (msg == WM_KEYUP && wParam == VK_F2)
{
ToggleSkew();
}

auto tracker = Game::GetGameTracker();

if (tracker->cheatMode)
{
Process(msg, wParam);
}
}
13 changes: 13 additions & 0 deletions src/modules/Skew.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include "Module.h"

class Skew : public Module
{
private:
void ToggleSkew();
void Process(UINT msg, WPARAM wParam);

public:
virtual void OnInput(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
};

0 comments on commit 22594d7

Please sign in to comment.