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

Commit

Permalink
inject: add ability to finetune injections
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Oct 2, 2023
1 parent 210dd9e commit e764f45
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 31 deletions.
54 changes: 27 additions & 27 deletions src/inject_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,45 @@ static void Inject_Shell(void);

static void Inject_Camera(void)
{
INJECT(0x004105A0, Camera_Initialise);
INJECT(0x00410650, Camera_Move);
INJECT(0x004109D0, Camera_Clip);
INJECT(0x00410AB0, Camera_Shift);
INJECT(0x00410C10, Camera_GoodPosition);
INJECT(0x00410C60, Camera_SmartShift);
INJECT(0x004113F0, Camera_Chase);
INJECT(0x004114E0, Camera_ShiftClamp);
INJECT(0x00411680, Camera_Combat);
INJECT(0x00411810, Camera_Look);
INJECT(0x00411A00, Camera_Fixed);
INJECT(0x00411AA0, Camera_Update);
INJECT(0x004126A0, Camera_LoadCutsceneFrame);
INJECT(0x00412290, Camera_UpdateCutscene);
INJECT(1, 0x004105A0, Camera_Initialise);
INJECT(1, 0x00410650, Camera_Move);
INJECT(1, 0x004109D0, Camera_Clip);
INJECT(1, 0x00410AB0, Camera_Shift);
INJECT(1, 0x00410C10, Camera_GoodPosition);
INJECT(1, 0x00410C60, Camera_SmartShift);
INJECT(1, 0x004113F0, Camera_Chase);
INJECT(1, 0x004114E0, Camera_ShiftClamp);
INJECT(1, 0x00411680, Camera_Combat);
INJECT(1, 0x00411810, Camera_Look);
INJECT(1, 0x00411A00, Camera_Fixed);
INJECT(1, 0x00411AA0, Camera_Update);
INJECT(1, 0x004126A0, Camera_LoadCutsceneFrame);
INJECT(1, 0x00412290, Camera_UpdateCutscene);
}

static void Inject_Matrix(void)
{
INJECT(0x00401000, Matrix_GenerateW2V);
INJECT(0x004011D0, Matrix_LookAt);
INJECT(0x004012D0, Matrix_RotX);
INJECT(0x00401380, Matrix_RotY);
INJECT(0x00401430, Matrix_RotZ);
INJECT(0x004014E0, Matrix_RotYXZ);
INJECT(0x004016C0, Matrix_RotYXZpack);
INJECT(0x004018B0, Matrix_TranslateRel);
INJECT(1, 0x00401000, Matrix_GenerateW2V);
INJECT(1, 0x004011D0, Matrix_LookAt);
INJECT(1, 0x004012D0, Matrix_RotX);
INJECT(1, 0x00401380, Matrix_RotY);
INJECT(1, 0x00401430, Matrix_RotZ);
INJECT(1, 0x004014E0, Matrix_RotYXZ);
INJECT(1, 0x004016C0, Matrix_RotYXZpack);
INJECT(1, 0x004018B0, Matrix_TranslateRel);
}

static void Inject_Math(void)
{
INJECT(0x00457C10, Math_Atan);
INJECT(0x00457C58, Math_Cos);
INJECT(0x00457C5E, Math_Sin);
INJECT(0x00457C93, Math_Sqrt);
INJECT(1, 0x00457C10, Math_Atan);
INJECT(1, 0x00457C58, Math_Cos);
INJECT(1, 0x00457C5E, Math_Sin);
INJECT(1, 0x00457C93, Math_Sqrt);
}

static void Inject_Shell(void)
{
INJECT(0x0044E890, Shell_ExitSystem);
INJECT(1, 0x0044E890, Shell_ExitSystem);
}

void Inject_Exec(void)
Expand Down
9 changes: 8 additions & 1 deletion src/inject_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@

#include <windows.h>

void Inject_Impl(void (*from)(void), void (*to)(void))
void InjectImpl(bool enable, void (*from)(void), void (*to)(void))
{
if (from == to) {
return;
}

if (!enable) {
void (*aux)(void) = from;
from = to;
to = aux;
}

DWORD tmp;
LOG_DEBUG("Patching %p to %p", from, to);
VirtualProtect(from, sizeof(JMP), PAGE_EXECUTE_READWRITE, &tmp);
Expand Down
7 changes: 4 additions & 3 deletions src/inject_util.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <stdbool.h>
#include <stdint.h>

#pragma pack(push, 1)
Expand All @@ -9,12 +10,12 @@ typedef struct {
} JMP;
#pragma pack(pop)

void Inject_Impl(void (*from)(void), void (*to)(void));
void InjectImpl(bool enable, void (*from)(void), void (*to)(void));

#define VAR_U_(address, type) (*(type *)(address))
#define VAR_I_(address, type, value) (*(type *)(address))
#define ARRAY_(address, type, length) (*(type(*) length)(address))
#define INJECT(from, to) \
#define INJECT(enable, from, to) \
{ \
Inject_Impl((void (*)(void))from, (void (*)(void))to); \
InjectImpl(enable, (void (*)(void))from, (void (*)(void))to); \
}

0 comments on commit e764f45

Please sign in to comment.