mirror of
https://github.com/halpz/re3.git
synced 2025-07-15 23:28:15 +00:00
Remove hacky way of injecting PS2 matfx on RW 3.3, remove static patcher
This commit is contained in:
@ -149,6 +149,10 @@ CGame::InitialiseOnceBeforeRW(void)
|
||||
return true;
|
||||
}
|
||||
|
||||
#if !defined(LIBRW) && defined(PS2_MATFX)
|
||||
void ReplaceMatFxCallback();
|
||||
#endif
|
||||
|
||||
bool
|
||||
CGame::InitialiseRenderWare(void)
|
||||
{
|
||||
@ -199,6 +203,8 @@ CGame::InitialiseRenderWare(void)
|
||||
#else
|
||||
rw::MatFX::modulateEnvMap = false;
|
||||
#endif
|
||||
#elif defined(PS2_MATFX)
|
||||
ReplaceMatFxCallback();
|
||||
#endif
|
||||
|
||||
CFont::Initialise();
|
||||
|
@ -1,94 +0,0 @@
|
||||
#define WITHWINDOWS
|
||||
#include "common.h"
|
||||
#include "patcher.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
StaticPatcher *StaticPatcher::ms_head;
|
||||
|
||||
StaticPatcher::StaticPatcher(Patcher func)
|
||||
: m_func(func)
|
||||
{
|
||||
m_next = ms_head;
|
||||
ms_head = this;
|
||||
}
|
||||
|
||||
void
|
||||
StaticPatcher::Apply()
|
||||
{
|
||||
StaticPatcher *current = ms_head;
|
||||
while(current){
|
||||
current->Run();
|
||||
current = current->m_next;
|
||||
}
|
||||
ms_head = nil;
|
||||
}
|
||||
#ifdef _WIN32
|
||||
std::vector<uint32> usedAddresses;
|
||||
|
||||
static DWORD protect[2];
|
||||
static uint32 protect_address;
|
||||
static uint32 protect_size;
|
||||
|
||||
void
|
||||
Protect_internal(uint32 address, uint32 size)
|
||||
{
|
||||
protect_address = address;
|
||||
protect_size = size;
|
||||
VirtualProtect((void*)address, size, PAGE_EXECUTE_READWRITE, &protect[0]);
|
||||
}
|
||||
|
||||
void
|
||||
Unprotect_internal(void)
|
||||
{
|
||||
VirtualProtect((void*)protect_address, protect_size, protect[0], &protect[1]);
|
||||
}
|
||||
|
||||
void
|
||||
InjectHook_internal(uint32 address, uint32 hook, int type)
|
||||
{
|
||||
if(std::any_of(usedAddresses.begin(), usedAddresses.end(),
|
||||
[address](uint32 value) { return value == address; })) {
|
||||
debug("Used address %#06x twice when injecting hook\n", address);
|
||||
}
|
||||
|
||||
usedAddresses.push_back(address);
|
||||
|
||||
|
||||
switch(type){
|
||||
case PATCH_JUMP:
|
||||
VirtualProtect((void*)address, 5, PAGE_EXECUTE_READWRITE, &protect[0]);
|
||||
*(uint8*)address = 0xE9;
|
||||
break;
|
||||
case PATCH_CALL:
|
||||
VirtualProtect((void*)address, 5, PAGE_EXECUTE_READWRITE, &protect[0]);
|
||||
*(uint8*)address = 0xE8;
|
||||
break;
|
||||
default:
|
||||
VirtualProtect((void*)(address + 1), 4, PAGE_EXECUTE_READWRITE, &protect[0]);
|
||||
break;
|
||||
}
|
||||
|
||||
*(ptrdiff_t*)(address + 1) = hook - address - 5;
|
||||
if(type == PATCH_NOTHING)
|
||||
VirtualProtect((void*)(address + 1), 4, protect[0], &protect[1]);
|
||||
else
|
||||
VirtualProtect((void*)address, 5, protect[0], &protect[1]);
|
||||
}
|
||||
#else
|
||||
void
|
||||
Protect_internal(uint32 address, uint32 size)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
Unprotect_internal(void)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
InjectHook_internal(uint32 address, uint32 hook, int type)
|
||||
{
|
||||
}
|
||||
#endif
|
@ -1,144 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#define WRAPPER __declspec(naked)
|
||||
#define DEPRECATED __declspec(deprecated)
|
||||
#define EAXJMP(a) { _asm mov eax, a _asm jmp eax }
|
||||
#define VARJMP(a) { _asm jmp a }
|
||||
#define WRAPARG(a) UNREFERENCED_PARAMETER(a)
|
||||
|
||||
#include <string.h> //memset
|
||||
|
||||
enum
|
||||
{
|
||||
PATCH_CALL,
|
||||
PATCH_JUMP,
|
||||
PATCH_NOTHING,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
III_10 = 1,
|
||||
III_11,
|
||||
III_STEAM,
|
||||
VC_10,
|
||||
VC_11,
|
||||
VC_STEAM
|
||||
};
|
||||
|
||||
extern int gtaversion;
|
||||
|
||||
class StaticPatcher
|
||||
{
|
||||
private:
|
||||
using Patcher = void(*)();
|
||||
|
||||
Patcher m_func;
|
||||
StaticPatcher *m_next;
|
||||
static StaticPatcher *ms_head;
|
||||
|
||||
void Run() { m_func(); }
|
||||
public:
|
||||
StaticPatcher(Patcher func);
|
||||
static void Apply();
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
inline T AddressByVersion(uint32_t addressIII10, uint32_t addressIII11, uint32_t addressIIISteam, uint32_t addressvc10, uint32_t addressvc11, uint32_t addressvcSteam)
|
||||
{
|
||||
if(gtaversion == -1){
|
||||
if(*(uint32_t*)0x5C1E75 == 0xB85548EC) gtaversion = III_10;
|
||||
else if(*(uint32_t*)0x5C2135 == 0xB85548EC) gtaversion = III_11;
|
||||
else if(*(uint32_t*)0x5C6FD5 == 0xB85548EC) gtaversion = III_STEAM;
|
||||
else if(*(uint32_t*)0x667BF5 == 0xB85548EC) gtaversion = VC_10;
|
||||
else if(*(uint32_t*)0x667C45 == 0xB85548EC) gtaversion = VC_11;
|
||||
else if(*(uint32_t*)0x666BA5 == 0xB85548EC) gtaversion = VC_STEAM;
|
||||
else gtaversion = 0;
|
||||
}
|
||||
switch(gtaversion){
|
||||
case III_10:
|
||||
return (T)addressIII10;
|
||||
case III_11:
|
||||
return (T)addressIII11;
|
||||
case III_STEAM:
|
||||
return (T)addressIIISteam;
|
||||
case VC_10:
|
||||
return (T)addressvc10;
|
||||
case VC_11:
|
||||
return (T)addressvc11;
|
||||
case VC_STEAM:
|
||||
return (T)addressvcSteam;
|
||||
default:
|
||||
return (T)0;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool
|
||||
is10(void)
|
||||
{
|
||||
return gtaversion == III_10 || gtaversion == VC_10;
|
||||
}
|
||||
|
||||
inline bool
|
||||
isIII(void)
|
||||
{
|
||||
return gtaversion >= III_10 && gtaversion <= III_STEAM;
|
||||
}
|
||||
|
||||
inline bool
|
||||
isVC(void)
|
||||
{
|
||||
return gtaversion >= VC_10 && gtaversion <= VC_STEAM;
|
||||
}
|
||||
|
||||
#define PTRFROMCALL(addr) (uint32_t)(*(uint32_t*)((uint32_t)addr+1) + (uint32_t)addr + 5)
|
||||
#define INTERCEPT(saved, func, a) \
|
||||
{ \
|
||||
saved = PTRFROMCALL(a); \
|
||||
InjectHook(a, func); \
|
||||
}
|
||||
|
||||
void InjectHook_internal(uint32 address, uint32 hook, int type);
|
||||
void Protect_internal(uint32 address, uint32 size);
|
||||
void Unprotect_internal(void);
|
||||
|
||||
template<typename T, typename AT> inline void
|
||||
Patch(AT address, T value)
|
||||
{
|
||||
Protect_internal((uint32)address, sizeof(T));
|
||||
*(T*)address = value;
|
||||
Unprotect_internal();
|
||||
}
|
||||
|
||||
template<typename AT> inline void
|
||||
Nop(AT address, unsigned int nCount)
|
||||
{
|
||||
Protect_internal((uint32)address, nCount);
|
||||
memset((void*)address, 0x90, nCount);
|
||||
Unprotect_internal();
|
||||
}
|
||||
|
||||
template <typename T> inline void
|
||||
InjectHook(uintptr_t address, T hook, unsigned int nType = PATCH_NOTHING)
|
||||
{
|
||||
InjectHook_internal(address, reinterpret_cast<uintptr_t>((void *&)hook), nType);
|
||||
}
|
||||
|
||||
inline void ExtractCall(void *dst, uint32_t a)
|
||||
{
|
||||
*(uint32_t*)dst = (uint32_t)(*(uint32_t*)(a+1) + a + 5);
|
||||
}
|
||||
template<typename T>
|
||||
inline void InterceptCall(void *dst, T func, uint32_t a)
|
||||
{
|
||||
ExtractCall(dst, a);
|
||||
InjectHook(a, func);
|
||||
}
|
||||
template<typename T>
|
||||
inline void InterceptVmethod(void *dst, T func, uint32_t a)
|
||||
{
|
||||
*(uint32_t*)dst = *(uint32_t*)a;
|
||||
Patch(a, func);
|
||||
}
|
||||
|
||||
#define STARTPATCHES static StaticPatcher Patcher([](){
|
||||
#define ENDPATCHES });
|
@ -2,7 +2,6 @@
|
||||
#define WITHWINDOWS
|
||||
#include "common.h"
|
||||
#include "crossplatform.h"
|
||||
#include "patcher.h"
|
||||
#include "Renderer.h"
|
||||
#include "Credits.h"
|
||||
#include "Camera.h"
|
||||
|
Reference in New Issue
Block a user