removed windows.h for most .cpps

This commit is contained in:
aap 2020-03-27 20:53:47 +01:00
parent 43b092033c
commit e7c18fc17f
13 changed files with 362 additions and 331 deletions

View File

@ -3906,8 +3906,8 @@ MACRO_STOP
#pragma warning( disable : 344 ) #pragma warning( disable : 344 )
#endif /* (defined(__ICL)) */ #endif /* (defined(__ICL)) */
//nobody needed that - AAP
#include <windows.h> //#include <windows.h>
#if (defined(RWDEBUG)) #if (defined(RWDEBUG))
#if (defined(RWMEMDEBUG) && !defined(_CRTDBG_MAP_ALLOC)) #if (defined(RWMEMDEBUG) && !defined(_CRTDBG_MAP_ALLOC))

View File

@ -1,3 +1,4 @@
#define WITHWINDOWS // for our script loading hack
#include "common.h" #include "common.h"
#include "patcher.h" #include "patcher.h"

View File

@ -43,6 +43,7 @@ BOOL _gbCdStreamOverlapped;
BOOL _gbCdStreamAsync; BOOL _gbCdStreamAsync;
DWORD _gdwCdStreamFlags; DWORD _gdwCdStreamFlags;
DWORD WINAPI CdStreamThread(LPVOID lpThreadParameter);
void void
CdStreamInitThread(void) CdStreamInitThread(void)

View File

@ -39,7 +39,6 @@ int32 CdStreamSync(int32 channel);
void AddToQueue(Queue *queue, int32 item); void AddToQueue(Queue *queue, int32 item);
int32 GetFirstInQueue(Queue *queue); int32 GetFirstInQueue(Queue *queue);
void RemoveFirstInQueue(Queue *queue); void RemoveFirstInQueue(Queue *queue);
DWORD WINAPI CdStreamThread(LPVOID lpThreadParameter);
bool CdStreamAddImage(char const *path); bool CdStreamAddImage(char const *path);
char *CdStreamGetImageName(int32 cd); char *CdStreamGetImageName(int32 cd);
void CdStreamRemoveImages(void); void CdStreamRemoveImages(void);

View File

@ -1,3 +1,4 @@
#define WITHWINDOWS // just for VK_SPACE
#include "common.h" #include "common.h"
#include "patcher.h" #include "patcher.h"
#include "General.h" #include "General.h"

View File

@ -1,5 +1,7 @@
#pragma once #pragma once
#include <ctype.h>
class CGeneral class CGeneral
{ {
public: public:

View File

@ -198,7 +198,7 @@ CStreaming::Init(void)
// PC only, figure out how much memory we got // PC only, figure out how much memory we got
#ifdef GTA_PC #ifdef GTA_PC
#define MB (1024*1024) #define MB (1024*1024)
extern DWORD &_dwMemAvailPhys; extern unsigned long &_dwMemAvailPhys;
ms_memoryAvailable = (_dwMemAvailPhys - 10*MB)/2; ms_memoryAvailable = (_dwMemAvailPhys - 10*MB)/2;
if(ms_memoryAvailable < 50*MB) if(ms_memoryAvailable < 50*MB)
ms_memoryAvailable = 50*MB; ms_memoryAvailable = 50*MB;

View File

@ -1,5 +1,6 @@
#include "common.h" #include "common.h"
#include "patcher.h" #include "patcher.h"
#include <ctype.h>
#include "Zones.h" #include "Zones.h"

View File

@ -8,10 +8,15 @@
#pragma warning(disable: 4996) // POSIX names #pragma warning(disable: 4996) // POSIX names
#include <stdint.h> #include <stdint.h>
#include <string.h>
#include <math.h> #include <math.h>
//#include <assert.h> //#include <assert.h>
#include <new> #include <new>
#ifdef WITHWINDOWS
#include <Windows.h>
#endif
#ifdef WITHD3D #ifdef WITHD3D
#include <windows.h> #include <windows.h>
#include <d3d8types.h> #include <d3d8types.h>
@ -30,6 +35,16 @@
#undef near #undef near
#endif #endif
#ifndef max
#define max(a,b) ((a) > (b) ? (a) : (b))
#endif
#ifndef min
#define min(a,b) ((a) < (b) ? (a) : (b))
#endif
#ifndef ARRAYSIZE
#define ARRAYSIZE(a) (sizeof(a) / sizeof(*(a)))
#endif
typedef uint8_t uint8; typedef uint8_t uint8;
typedef int8_t int8; typedef int8_t int8;
typedef uint16_t uint16; typedef uint16_t uint16;

View File

@ -6,13 +6,7 @@
#define VARJMP(a) { _asm jmp a } #define VARJMP(a) { _asm jmp a }
#define WRAPARG(a) UNREFERENCED_PARAMETER(a) #define WRAPARG(a) UNREFERENCED_PARAMETER(a)
#define NOVMT __declspec(novtable) #include <string.h> //memset
#define SETVMT(a) *((DWORD_PTR*)this) = (DWORD_PTR)a
#include <algorithm>
#include <vector>
#include "common.h"
enum enum
{ {
@ -103,72 +97,36 @@ isVC(void)
InjectHook(a, func); \ 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 template<typename T, typename AT> inline void
Patch(AT address, T value) Patch(AT address, T value)
{ {
DWORD dwProtect[2]; Protect_internal((uint32)address, sizeof(T));
VirtualProtect((void*)address, sizeof(T), PAGE_EXECUTE_READWRITE, &dwProtect[0]);
*(T*)address = value; *(T*)address = value;
VirtualProtect((void*)address, sizeof(T), dwProtect[0], &dwProtect[1]); Unprotect_internal();
} }
template<typename AT> inline void template<typename AT> inline void
Nop(AT address, unsigned int nCount) Nop(AT address, unsigned int nCount)
{ {
DWORD dwProtect[2]; Protect_internal((uint32)address, nCount);
VirtualProtect((void*)address, nCount, PAGE_EXECUTE_READWRITE, &dwProtect[0]);
memset((void*)address, 0x90, nCount); memset((void*)address, 0x90, nCount);
VirtualProtect((void*)address, nCount, dwProtect[0], &dwProtect[1]); Unprotect_internal();
} }
template<typename AT> inline void
ClearCC(AT address, unsigned int nCount)
{
DWORD dwProtect[2];
VirtualProtect((void*)address, nCount, PAGE_EXECUTE_READWRITE, &dwProtect[0]);
memset((void*)address, 0xCC, nCount);
VirtualProtect((void*)address, nCount, dwProtect[0], &dwProtect[1]);
}
extern std::vector<int32> usedAddresses;
template<typename AT, typename HT> inline void template<typename AT, typename HT> inline void
InjectHook(AT address, HT hook, unsigned int nType=PATCH_NOTHING) InjectHook(AT address, HT hook, unsigned int nType=PATCH_NOTHING)
{ {
if(std::any_of(usedAddresses.begin(), usedAddresses.end(), uint32 uiHook;
[address](AT value) { return (int32)value == address; })) {
debug("Used address %#06x twice when injecting hook\n", address);
}
usedAddresses.push_back((int32)address);
DWORD dwProtect[2];
switch ( nType )
{
case PATCH_JUMP:
VirtualProtect((void*)address, 5, PAGE_EXECUTE_READWRITE, &dwProtect[0]);
*(BYTE*)address = 0xE9;
break;
case PATCH_CALL:
VirtualProtect((void*)address, 5, PAGE_EXECUTE_READWRITE, &dwProtect[0]);
*(BYTE*)address = 0xE8;
break;
default:
VirtualProtect((void*)((DWORD)address + 1), 4, PAGE_EXECUTE_READWRITE, &dwProtect[0]);
break;
}
DWORD dwHook;
_asm _asm
{ {
mov eax, hook mov eax, hook
mov dwHook, eax mov uiHook, eax
} }
InjectHook_internal((uint32)address, uiHook, nType);
*(ptrdiff_t*)((DWORD)address + 1) = (DWORD)dwHook - (DWORD)address - 5;
if ( nType == PATCH_NOTHING )
VirtualProtect((void*)((DWORD)address + 1), 4, dwProtect[0], &dwProtect[1]);
else
VirtualProtect((void*)address, 5, dwProtect[0], &dwProtect[1]);
} }
inline void ExtractCall(void *dst, uint32_t a) inline void ExtractCall(void *dst, uint32_t a)

View File

@ -22,11 +22,62 @@
#include "Console.h" #include "Console.h"
#include "Debug.h" #include "Debug.h"
#include <algorithm>
#include <vector> #include <vector>
#include <list> #include <list>
std::vector<int32> usedAddresses; std::vector<int32> 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 (int32)value == address; })) {
debug("Used address %#06x twice when injecting hook\n", address);
}
usedAddresses.push_back((int32)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*)((uint32)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]);
}
void **rwengine = *(void***)0x5A10E1; void **rwengine = *(void***)0x5A10E1;
DebugMenuAPI gDebugMenuAPI; DebugMenuAPI gDebugMenuAPI;

View File

@ -1,3 +1,4 @@
#define WITHWINDOWS
#include "common.h" #include "common.h"
#include "main.h" #include "main.h"
#include "patcher.h" #include "patcher.h"

View File

@ -1,3 +1,4 @@
#define WITHWINDOWS
#include "common.h" #include "common.h"
#include "patcher.h" #include "patcher.h"
#include "FileMgr.h" #include "FileMgr.h"