Make menu reloadable
This commit is contained in:
parent
86431a9eac
commit
28d7a752a8
@ -17,6 +17,7 @@ set(DIRECTX9_SDK_DIR $ENV{DIRECTX9_SDK_DIR})
|
||||
################################################################################
|
||||
add_subdirectory(deps)
|
||||
add_subdirectory(tests)
|
||||
add_subdirectory(tools)
|
||||
|
||||
################################################################################
|
||||
# Source groups
|
||||
|
@ -171,12 +171,12 @@ void HasGameInit()
|
||||
void MenuThread(void* param)
|
||||
{
|
||||
// Wait till the game is initialized
|
||||
Events::initGameEvent.after += HasGameInit;
|
||||
Events::processScriptsEvent += HasGameInit;
|
||||
|
||||
while (!Globals::game_init)
|
||||
Sleep(1000);
|
||||
|
||||
Events::initGameEvent.after -= HasGameInit;
|
||||
Events::processScriptsEvent -= HasGameInit;
|
||||
|
||||
if (GetModuleHandle("SAMP.dll"))
|
||||
{
|
||||
@ -191,27 +191,28 @@ void MenuThread(void* param)
|
||||
return;
|
||||
}
|
||||
|
||||
flog << "Starting...\nVersion: " MENU_TITLE "\nAuthor: Grinch_\nDiscord: " DISCORD_INVITE "\nMore Info: " GITHUB_LINK "\n\n" << std::endl;
|
||||
flog << "Starting...\nVersion: " MENU_TITLE "\nAuthor: Grinch_\nDiscord: " DISCORD_INVITE "\nMore Info: " GITHUB_LINK "\n" << std::endl;
|
||||
CFastman92limitAdjuster::Init();
|
||||
CheatMenu *menu = new CheatMenu;
|
||||
|
||||
while (true)
|
||||
{
|
||||
Sleep(50);
|
||||
|
||||
if (KeyPressed(VK_TAB))
|
||||
Sleep(100);
|
||||
if (KeyPressed(VK_LSHIFT) && KeyPressed(VK_BACK))
|
||||
break;
|
||||
}
|
||||
|
||||
delete menu;
|
||||
Sleep(100);
|
||||
CHud::SetHelpMessage("CheatMenu unloaded",false,false,false);
|
||||
flog << "Unloaded" << std::endl;
|
||||
|
||||
// reset mouse patches
|
||||
patch::SetUChar(0x6194A0, 0xE9);
|
||||
patch::SetUChar(0x746ED0, 0xA1);
|
||||
patch::SetRaw(0x53F41F, (void*)"\x85\xC0\x0F\x8C", 4);
|
||||
|
||||
FreeLibraryAndExitThread(NULL,0);
|
||||
FreeLibraryAndExitThread(GetModuleHandle("CheatMenu.asi"),0);
|
||||
}
|
||||
|
||||
BOOL WINAPI DllMain(HINSTANCE hDllHandle, DWORD nReason, LPVOID Reserved)
|
||||
|
@ -22,7 +22,11 @@ CJson::CJson(const char* name)
|
||||
else
|
||||
{
|
||||
data = "{}"_json;
|
||||
flog << "File doesn't exist " << file_path << std::endl;
|
||||
|
||||
if (file_path.find("config"))
|
||||
flog << "Creating config.json file" << std::endl;
|
||||
else
|
||||
flog << "Failed to locate file " << file_path << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,10 +2,9 @@
|
||||
#include "Neon.h"
|
||||
#include "Util.h"
|
||||
|
||||
VehicleExtendedData<Neon::NeonData> Neon::VehNeon;
|
||||
VehExtender<Neon::NeonData> Neon::VehNeon;
|
||||
RwTexture* Neon::neon_texture = nullptr;
|
||||
|
||||
|
||||
void Neon::RenderEvent(CVehicle *pVeh)
|
||||
{
|
||||
NeonData* data = &VehNeon.Get(pVeh);
|
||||
@ -48,7 +47,7 @@ Neon::Neon()
|
||||
}
|
||||
|
||||
Neon::~Neon()
|
||||
{
|
||||
{
|
||||
Events::vehicleRenderEvent -= RenderEvent;
|
||||
RwTextureDestroy(neon_texture);
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
static VehicleExtendedData<NeonData> VehNeon;
|
||||
static VehExtender<NeonData> VehNeon;
|
||||
|
||||
public:
|
||||
Neon();
|
||||
|
@ -30,7 +30,7 @@
|
||||
|
||||
std::vector<std::string> Paint::veh_nodes::names_vec{ "Default" };
|
||||
std::string Paint::veh_nodes::selected = "Default";
|
||||
VehicleExtendedData<Paint::VehData> Paint::vehdata;
|
||||
VehExtender<Paint::VehData> Paint::vehdata;
|
||||
|
||||
std::map<std::string, std::shared_ptr<RwTexture>> Paint::textures;
|
||||
|
||||
|
@ -73,7 +73,7 @@ private:
|
||||
void resetMaterialTexture(RpMaterial* material);
|
||||
};
|
||||
|
||||
static VehicleExtendedData<VehData> vehdata;
|
||||
static VehExtender<VehData> vehdata;
|
||||
|
||||
protected:
|
||||
|
||||
|
29
src/VehExtender.h
Normal file
29
src/VehExtender.h
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
VS Code extension doesn't work well with template classes
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include "CVehicle.h"
|
||||
|
||||
template <class T>
|
||||
class VehExtender
|
||||
{
|
||||
public:
|
||||
VehExtender(){};
|
||||
VehExtender(const VehExtender&) = delete;
|
||||
|
||||
T& Get(CVehicle *veh)
|
||||
{
|
||||
static std::vector<std::pair<CVehicle*,T>> data;
|
||||
|
||||
for (auto it = data.begin(); it < data.end(); ++it)
|
||||
{
|
||||
if (it->first == veh)
|
||||
return it->second;
|
||||
}
|
||||
|
||||
data.push_back({veh, T(veh)});
|
||||
return data.back().second;
|
||||
}
|
||||
};
|
@ -61,6 +61,7 @@
|
||||
#include "Events.h"
|
||||
#include "Json.h"
|
||||
#include "VKeys.h"
|
||||
#include "VehExtender.h"
|
||||
|
||||
// Globals
|
||||
typedef std::vector<std::pair<std::string, void(*)()>> CallbackTable;
|
||||
|
16
tools/CMakeLists.txt
Normal file
16
tools/CMakeLists.txt
Normal file
@ -0,0 +1,16 @@
|
||||
################################################################################
|
||||
# Build Tools
|
||||
################################################################################
|
||||
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
project(CheatMenuInjector)
|
||||
|
||||
add_executable(CheatMenuInjector WIN32 "Injector.cpp")
|
||||
|
||||
set_target_properties(CheatMenuInjector PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${GTA_SA_DIR}/$<0:>/"
|
||||
)
|
||||
|
||||
target_link_options(${PROJECT_NAME} PRIVATE
|
||||
/SUBSYSTEM:CONSOLE
|
||||
)
|
64
tools/Injector.cpp
Normal file
64
tools/Injector.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
Simple injector
|
||||
Taken from GuidedHacking
|
||||
*/
|
||||
#include <Windows.h>
|
||||
#include <TlHelp32.h>
|
||||
|
||||
DWORD GetProcId(const char* procName)
|
||||
{
|
||||
DWORD procId = 0;
|
||||
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
||||
|
||||
if (hSnap != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
PROCESSENTRY32 procEntry;
|
||||
procEntry.dwSize = sizeof(procEntry);
|
||||
|
||||
if (Process32First(hSnap, &procEntry))
|
||||
{
|
||||
do
|
||||
{
|
||||
if (!_stricmp((const char*)procEntry.szExeFile, procName))
|
||||
{
|
||||
procId = procEntry.th32ProcessID;
|
||||
break;
|
||||
}
|
||||
} while (Process32Next(hSnap, &procEntry));
|
||||
}
|
||||
}
|
||||
CloseHandle(hSnap);
|
||||
return procId;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
const char* dllPath = "./CheatMenu.asi";
|
||||
const char* procName = "gta_sa.exe";
|
||||
DWORD procId = 0;
|
||||
|
||||
while (!procId)
|
||||
{
|
||||
procId = GetProcId(procName);
|
||||
Sleep(30);
|
||||
}
|
||||
|
||||
HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, 0, procId);
|
||||
|
||||
if (hProc && hProc != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
void* loc = VirtualAllocEx(hProc, 0, MAX_PATH, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
|
||||
|
||||
WriteProcessMemory(hProc, loc, dllPath, strlen(dllPath) + 1, 0);
|
||||
|
||||
HANDLE hThread = CreateRemoteThread(hProc, 0, 0, (LPTHREAD_START_ROUTINE)LoadLibraryA, loc, 0, 0);
|
||||
|
||||
if (hThread)
|
||||
CloseHandle(hThread);
|
||||
}
|
||||
|
||||
if (hProc)
|
||||
CloseHandle(hProc);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user