Skip to content

Commit

Permalink
Add function call helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
TheIndra55 committed Jan 15, 2024
1 parent 22594d7 commit f9f7a8d
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 19 deletions.
1 change: 0 additions & 1 deletion src/Hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Hook::Hook() : m_menu(nullptr), m_modules()

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

RegisterModules();
Expand Down
13 changes: 13 additions & 0 deletions src/instance/Instance.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "Instance.h"

#include "util/Hooking.h"

void INSTANCE_Post(Instance* instance, int message, int data)
{
Hooking::Call(0x4580B0, instance, message, data);
}

void INSTANCE_HideUnhideDrawGroup(Instance* instance, int drawGroup, int on)
{
Hooking::Call(0x4319B0, instance, drawGroup, on);
}
19 changes: 17 additions & 2 deletions src/instance/Instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ struct Intro
{
};

struct ObjectData
{
unsigned __int16 version;
unsigned __int16 family;
unsigned __int16 id;
unsigned __int16 type;
};

struct HModel;
struct SoundInstanceData;
struct Body;
Expand Down Expand Up @@ -49,7 +57,11 @@ struct BaseInstance
Object* object;
Intro* intro;

char pad2[100];
char pad2[64];

unsigned int noDrawGroups;

char pad3[32];
};

struct Instance : BaseInstance
Expand All @@ -61,4 +73,7 @@ struct Instance : BaseInstance
char pad2[12];

int introUniqueID;
};
};

void INSTANCE_Post(Instance* instance, int message, int data);
void INSTANCE_HideUnhideDrawGroup(Instance* instance, int drawGroup, int on);
12 changes: 0 additions & 12 deletions src/instance/Instances.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
#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 @@ -15,9 +8,4 @@ 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: 0 additions & 3 deletions src/instance/Instances.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,5 @@
class Instances
{
public:
static void Init();

static void Iterate(std::function<void(Instance*)> callback);
static void Post(Instance* instance, int message, int data);
};
2 changes: 1 addition & 1 deletion src/modules/Skew.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ void Skew::ToggleSkew()
auto tracker = Game::GetGameTracker();

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

void Skew::Process(UINT msg, WPARAM wParam)
Expand Down
20 changes: 20 additions & 0 deletions src/util/Hooking.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

// Helpers for hooking and calling functions
class Hooking
{
public:
// Calls a function
template<typename... Args>
static inline void Call(unsigned int address, Args... args)
{
reinterpret_cast<void(*)(Args...)>(address)(args...);
}

// Calls a function with a return value
template<typename T, typename... Args>
static inline T CallReturn(unsigned int address, Args... args)
{
reinterpret_cast<T(*)(Args...)>(address)(args...);
}
};

0 comments on commit f9f7a8d

Please sign in to comment.