Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ad8fb8f
Showing
27 changed files
with
3,175 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
x64* | ||
GTALua.vcxproj* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// ================================================================================= | ||
// Includes | ||
// ================================================================================= | ||
#include "Includes.h" | ||
#include "GTALua.h" | ||
|
||
// ================================================================================= | ||
// Global | ||
// ================================================================================= | ||
GTALua* g_pGTALua = NULL; | ||
|
||
// ================================================================================= | ||
// Init | ||
// ================================================================================= | ||
void Init() | ||
{ | ||
// Init | ||
g_pGTALua = new GTALua(); | ||
} | ||
|
||
// ================================================================================= | ||
// DLLMain | ||
// ================================================================================= | ||
BOOL __stdcall DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID lpReserved) | ||
{ | ||
// Thread | ||
if (dwReason == DLL_PROCESS_ATTACH) | ||
{ | ||
// Go | ||
CreateThread(0, 0, (LPTHREAD_START_ROUTINE)Init, 0, 0, 0); | ||
} | ||
|
||
// Success | ||
return TRUE; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// ================================================================================= | ||
// GTALua | ||
// ================================================================================= | ||
class GTALua | ||
{ | ||
public: | ||
GTALua(); | ||
|
||
// Game Version | ||
bool VersionCheck(); | ||
char* GetGameVersion(); | ||
}; | ||
|
||
// ================================================================================= | ||
// Global Instance | ||
// ================================================================================= | ||
extern GTALua* g_pGTALua; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// ================================================================================= | ||
// Includes | ||
// ================================================================================= | ||
#include "Includes.h" | ||
#include "Memory/Memory.h" | ||
|
||
// ================================================================================= | ||
// Hooks | ||
// ================================================================================= | ||
void GameMemory::InstallHooks() | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// ================================================================================= | ||
// Includes | ||
// ================================================================================= | ||
#include "Includes.h" | ||
#include "Memory/Memory.h" | ||
|
||
// ================================================================================= | ||
// Patches | ||
// ================================================================================= | ||
void GameMemory::InstallPatches() | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// ================================================================================= | ||
// Remove Warnings | ||
// ================================================================================= | ||
#define _CRT_SECURE_NO_WARNINGS | ||
#pragma warning(disable: 4244) | ||
|
||
// ================================================================================= | ||
// Windows Includes | ||
// ================================================================================= | ||
#include <Windows.h> | ||
#include <stdio.h> | ||
#include <vector> | ||
|
||
using namespace std; | ||
|
||
// ================================================================================= | ||
// Libraries | ||
// ================================================================================= | ||
#pragma comment(lib, "version.lib") // GameMemory Version Fetch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// ================================================================================= | ||
// Includes | ||
// ================================================================================= | ||
#include "Includes.h" | ||
#include "GTALua.h" | ||
#include "Memory/Memory.h" | ||
|
||
// ================================================================================= | ||
// Init | ||
// ================================================================================= | ||
GTALua::GTALua() | ||
{ | ||
AllocConsole(); | ||
AttachConsole(GetCurrentProcessId()); | ||
freopen("CON", "w", stdout); | ||
printf("Console allocated and attached!\n"); | ||
|
||
// Prepare Game Memory | ||
GameMemory::Init(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
// ================================================================================= | ||
// Includes | ||
// ================================================================================= | ||
#include "Includes.h" | ||
#include "Memory.h" | ||
|
||
// ================================================================================= | ||
// Init | ||
// ================================================================================= | ||
void GameMemory::Init() | ||
{ | ||
// Module | ||
GameModule = GetModuleHandle("GTA5.exe"); | ||
if (GameModule == NULL) | ||
{ | ||
printf("GameMemory::Init GTA5.exe module not found!"); | ||
return; | ||
} | ||
|
||
// Base | ||
Base = (DWORD64) GameModule; | ||
printf("[GameMemory] Game Base: %p\n", Base); | ||
|
||
// Size | ||
Size = Memory::GetModuleSize(GameModule); | ||
printf("[GameMemory] Game Size: %p\n", Size); | ||
|
||
// Version | ||
Version = NULL; | ||
FetchVersion(); | ||
|
||
// Patches | ||
InstallPatches(); | ||
} | ||
|
||
// ================================================================================= | ||
// Wrapper | ||
// ================================================================================= | ||
DWORD64 GameMemory::At(DWORD64 dwOffset) | ||
{ | ||
return Base + dwOffset; | ||
} | ||
DWORD64 GameMemory::Find(BYTE* bMask, char* szMask) | ||
{ | ||
return Memory::Find(Base, Size, bMask, szMask); | ||
} | ||
|
||
// ================================================================================= | ||
// Version | ||
// ================================================================================= | ||
void GameMemory::FetchVersion() | ||
{ | ||
// One-Time-Only | ||
if (Version != NULL) return; | ||
|
||
// Game EXE | ||
char* sVersionFile = Memory::GetModulePath((HMODULE) Base); | ||
if (sVersionFile == NULL) | ||
{ | ||
printf("GameMemory::FetchVersion failed [Memory::GetModulePath returned 0]\n"); | ||
return; | ||
} | ||
|
||
// Version Info Size | ||
DWORD dwVersionInfoSize = GetFileVersionInfoSize(sVersionFile, NULL); | ||
if (dwVersionInfoSize == NULL) | ||
{ | ||
printf("GameMemory::FetchVersion failed! [GetFileVersionInfoSize returned 0]\n"); | ||
|
||
// Cleanup | ||
free(sVersionFile); | ||
|
||
return; | ||
} | ||
|
||
// Version Info | ||
VS_FIXEDFILEINFO* pFileInfo = (VS_FIXEDFILEINFO*) new BYTE[dwVersionInfoSize]; | ||
DWORD dwVersionHandle = NULL; | ||
if (!GetFileVersionInfo(sVersionFile, dwVersionHandle, dwVersionInfoSize, pFileInfo)) | ||
{ | ||
printf("GameMemory::FetchVersion failed! [GetFileVersionInfo failed]\n"); | ||
|
||
// Cleanup | ||
free(sVersionFile); | ||
delete[] pFileInfo; | ||
|
||
return; | ||
} | ||
|
||
// Query | ||
UINT uiFileInfoLength = 0; | ||
VS_FIXEDFILEINFO* pVersionInfo = NULL; | ||
if (!VerQueryValue(pFileInfo, "\\", (LPVOID*) &pVersionInfo, &uiFileInfoLength) || uiFileInfoLength == 0) | ||
{ | ||
printf("GameMemory::FetchVersion failed! [VerQueryValue failed]\n"); | ||
|
||
// Cleanup | ||
free(sVersionFile); | ||
delete[] pFileInfo; | ||
if (pVersionInfo != NULL) | ||
delete pVersionInfo; | ||
|
||
return; | ||
} | ||
|
||
// Signature | ||
if (pVersionInfo->dwSignature != 0xFEEF04BD) | ||
{ | ||
printf("GameMemory::FetchVersion failed! [Signature mismatch, got %X]\n", pVersionInfo->dwSignature); | ||
|
||
// Cleanup | ||
free(sVersionFile); | ||
delete[] pFileInfo; | ||
if (pVersionInfo != NULL) | ||
delete pVersionInfo; | ||
|
||
return; | ||
} | ||
|
||
// Build Version String | ||
Version = new char[128]; | ||
sprintf(Version, "%d.%d.%d.%d", | ||
(pVersionInfo->dwFileVersionMS >> 16) & 0xffff, | ||
(pVersionInfo->dwFileVersionMS >> 0) & 0xffff, | ||
(pVersionInfo->dwFileVersionLS >> 16) & 0xffff, | ||
(pVersionInfo->dwFileVersionLS >> 0) & 0xffff); | ||
printf("[GameMemory] Detected Version %s\n", Version); | ||
|
||
// Cleanup | ||
free(sVersionFile); | ||
delete[] pFileInfo; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// ================================================================================= | ||
// Game Memory | ||
// ================================================================================= | ||
namespace GameMemory | ||
{ | ||
// Init | ||
void Init(); | ||
void FetchVersion(); | ||
void InstallPatches(); | ||
void InstallHooks(); | ||
|
||
// Module | ||
static HMODULE GameModule; | ||
static DWORD64 Base; | ||
static DWORD64 Size; | ||
|
||
// Version | ||
static char* Version; | ||
|
||
// Function Wrappers | ||
DWORD64 Find(BYTE* bMask, char* szMask); | ||
|
||
// Calculate | ||
DWORD64 At(DWORD64 dwOffset); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// ================================================================================= | ||
// Includes | ||
// ================================================================================= | ||
#include "Includes.h" | ||
#include "Memory.h" | ||
#include "minhook/include/MinHook.h" | ||
|
||
// ================================================================================= | ||
// Init | ||
// ================================================================================= | ||
void Memory::Init() | ||
{ | ||
// Init MinHook | ||
if (MH_Initialize() != MH_OK) | ||
{ | ||
printf("[Memory::Init] MH_Initialize failed!\n"); | ||
return; | ||
} | ||
} | ||
|
||
// ================================================================================= | ||
// Hook Function | ||
// ================================================================================= | ||
bool Memory::HookFunction(DWORD64 pAddress, void* pDetour, void** pOriginal) | ||
{ | ||
// Create Hook | ||
int iResult = MH_CreateHook((void*)pAddress, pDetour, pOriginal); | ||
if (iResult != MH_OK) | ||
{ | ||
printf("[Memory::HookFunction] MH_CreateHook failed: %p [Error %i]\n", pAddress, iResult); | ||
return false; | ||
} | ||
|
||
// Enable Hook | ||
iResult = MH_EnableHook((void*)pAddress); | ||
if (iResult != MH_OK) | ||
{ | ||
printf("[Memory::HookFunction] MH_EnableHook failed: %p [Error %i]\n", pAddress, iResult); | ||
return false; | ||
} | ||
|
||
// Success | ||
return true; | ||
} | ||
bool Memory::HookLibraryFunction(char* sLibrary, char* sName, void* pDetour, void** pOriginal) | ||
{ | ||
// Module | ||
HMODULE hModule = GetModuleHandle(sLibrary); | ||
if (hModule == NULL) | ||
{ | ||
printf("[Memory::HookLibraryFunction] Module %s not (yet) loaded!\n", sLibrary); | ||
return false; | ||
} | ||
|
||
// Proc | ||
void* pProc = GetProcAddress(hModule, sName); | ||
if (pProc == NULL) | ||
{ | ||
printf("[Memory::HookLibraryFunction] Module %s has no exported function %s!\n", sLibrary, sName); | ||
return false; | ||
} | ||
|
||
// Hook | ||
return HookFunction((DWORD64)pProc, pDetour, pOriginal); | ||
} |
Oops, something went wrong.