Skip to content

Commit

Permalink
Add cleo support
Browse files Browse the repository at this point in the history
  • Loading branch information
user-grinch committed Oct 31, 2023
1 parent 59fd977 commit bc7133f
Show file tree
Hide file tree
Showing 16 changed files with 768 additions and 453 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ jobs:
strategy:
matrix:
platform: [Win32, Win64]
buildtype: [Release, ReleaseCleo]
steps:
- name: Checkout
uses: actions/checkout@v3.0.0
Expand All @@ -22,7 +23,7 @@ jobs:
cd tools
premake5 vs2022
cd ../build
MsBuild ImGuiRedux.sln /property:Configuration=Release /p:Platform=${{matrix.platform}} /t:ImGuiRedux
MsBuild ImGuiRedux.sln /property:Configuration=${{matrix.buildtype}} /p:Platform=${{matrix.platform}} /t:ImGuiRedux
- name: Upload plugin
uses: actions/upload-artifact@v3
with:
Expand Down
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
"name": "Launch SA",
"type": "cppvsdbg",
"request": "launch",
"program": "E:/GTASanAndreas/gta_sa.exe",
"program": "F:/GTA San Andreas/gta_sa.exe",
"args": [],
"stopAtEntry": false,
"cwd": "E:/GTASanAndreas/",
"cwd": "F:/GTA San Andreas/",
"environment": [],
"console": "internalConsole"
},
Expand Down
54 changes: 54 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,60 @@
}
},
},
{
"label": "Build Debug CLEO",
"type": "shell",
"command": "${workspaceFolder}/tools/DebugCleo.bat",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": false,
"clear": true
},
"group": {
"kind": "build",
"isDefault": true
},
"windows": {
"options": {
"shell": {
"executable": "cmd.exe",
"args": [
"/d", "/c"
]
}
}
},
},
{
"label": "Build Release CLEO",
"type": "shell",
"command": "${workspaceFolder}/tools/ReleaseCleo.bat",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": false,
"clear": true
},
"group": {
"kind": "build",
"isDefault": true
},
"windows": {
"options": {
"shell": {
"executable": "cmd.exe",
"args": [
"/d", "/c"
]
}
}
},
},
{
"label": "Build Debug64",
"type": "shell",
Expand Down
145 changes: 145 additions & 0 deletions include/cleo/cleo_sdk.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*
CLEO 4.4 header file;
Copyright (c) 2020 Alien, Deji, Junior_Djjr;
*/
#pragma once

#include <wtypes.h>

#define CLEO_VERSION 0x04040400
#define CLEO_VERSIONTEXT "4.4.4"

//result of CLEO_GetGameVersion()
#define GV_US10 0 //1.0 us
#define GV_US11 1 //1.01 us - not supported
#define GV_EU10 2 //1.0 eu
#define GV_EU11 3 //1.01 eu
#define GV_UNK -1 //any other

typedef union
{
DWORD dwParam;
int nParam;
float fParam;
void * pParam;
char * szParam;
} SCRIPT_VAR;

//operand types
#define globalVar 2 //$
#define localVar 3 //@
#define globalArr 7 //$(,)
#define localArr 8 //@(,)
#define imm8 4 //char
#define imm16 5 //short
#define imm32 1 //long, unsigned long
#define imm32f 6 //float
#define vstring 0x0E //""
#define sstring 9 //''
#define globalVarVString 0x10 //v$
#define localVarVString 0x11 //@v
#define globalVarSString 0x0A //s$
#define localVarSString 0x0B //@s


typedef int SCRIPT_HANDLE;
typedef SCRIPT_HANDLE HANDLE_ACTOR, ACTOR, HACTOR, PED, HPED, HANDLE_PED;
typedef SCRIPT_HANDLE HANDLE_CAR, CAR, HCAR, VEHICLE, HVEHICLE, HANDLE_VEHICLE;
typedef SCRIPT_HANDLE HANDLE_OBJECT, OBJECT, HOBJECT;
typedef SCRIPT_HANDLE HSTREAM;

typedef struct CScriptThread CScriptThread;

#pragma pack(push,1)
struct CScriptThread
{
CScriptThread *next; //next script in queue
CScriptThread *prev; //previous script in queue
char threadName[8]; //name of thread, given by 03A4 opcode
BYTE *baseIp; //pointer to begin of script in memory
BYTE *ip; //current index pointer
BYTE *stack[8]; //return stack for 0050, 0051
WORD sp; //current item in stack
WORD _f3A; //padding
SCRIPT_VAR tls[34]; //thread's local variables
BYTE isActive; //is current thread active
char condResult; //condition result (true or false)
char missionCleanupFlag; //clean mission
char external; //is thread external (from script.img)
BYTE _fC8; //unknown
BYTE _fC9; //unknown
BYTE _fCA; //unknown
BYTE _fCB; //unknown
DWORD wakeTime; //time, when script starts again after 0001 opcode
WORD logicalOp; //00D6 parameter
BYTE notFlag; //opcode & 0x8000 != 0
BYTE wbCheckEnabled; //wasted_or_busted check flag
BYTE wastedOrBusted; //is player wasted or busted
BYTE _fD5; //unknown
WORD _fD6; //unknown
DWORD sceneSkip; //scene skip label ptr
BYTE missionFlag; //is mission thread
BYTE _fDD[3]; //padding
};
#pragma pack(pop)

#define OR_CONTINUE 0
#define OR_INTERRUPT 1

typedef int OpcodeResult;

typedef OpcodeResult (CALLBACK* _pOpcodeHandler)(CScriptThread*);
typedef void(*FuncScriptDeleteDelegateT) (CScriptThread*);

#ifdef __cplusplus
extern "C" {
#endif //__cplusplus

DWORD WINAPI CLEO_GetVersion();
int WINAPI CLEO_GetGameVersion();

BOOL WINAPI CLEO_RegisterOpcode(WORD opcode, _pOpcodeHandler callback);

DWORD WINAPI CLEO_GetIntOpcodeParam(CScriptThread* thread);
float WINAPI CLEO_GetFloatOpcodeParam(CScriptThread* thread);

void WINAPI CLEO_SetIntOpcodeParam(CScriptThread* thread, DWORD value);
void WINAPI CLEO_SetFloatOpcodeParam(CScriptThread* thread, float value);

LPSTR WINAPI CLEO_ReadStringOpcodeParam(CScriptThread* thread, LPSTR buf, int size);
LPSTR WINAPI CLEO_ReadStringPointerOpcodeParam(CScriptThread* thread, LPSTR buf, int size);
void WINAPI CLEO_WriteStringOpcodeParam(CScriptThread* thread, LPCSTR str);

void WINAPI CLEO_SetThreadCondResult(CScriptThread* thread, BOOL result);

void WINAPI CLEO_SkipOpcodeParams(CScriptThread* thread, int count);

void WINAPI CLEO_ThreadJumpAtLabelPtr(CScriptThread* thread, int labelPtr);

int WINAPI CLEO_GetOperandType(CScriptThread* thread);

extern SCRIPT_VAR *opcodeParams;

extern SCRIPT_VAR *missionLocals;

//intermediate data is stored in opcodeParams array
void WINAPI CLEO_RetrieveOpcodeParams(CScriptThread *thread, int count);
void WINAPI CLEO_RecordOpcodeParams(CScriptThread *thread, int count);

SCRIPT_VAR * WINAPI CLEO_GetPointerToScriptVariable(CScriptThread *thread);

DWORD WINAPI CLEO_GetScriptTextureById(CScriptThread* thread, int id); // ret RwTexture *

HSTREAM WINAPI CLEO_GetInternalAudioStream(CScriptThread* thread, DWORD stream); // arg CAudioStream *

CScriptThread* WINAPI CLEO_CreateCustomScript(CScriptThread* fromThread, const char *script_name, int label);

CScriptThread* WINAPI CLEO_GetLastCreatedCustomScript();

void WINAPI CLEO_AddScriptDeleteDelegate(FuncScriptDeleteDelegateT func);

void WINAPI CLEO_RemoveScriptDeleteDelegate(FuncScriptDeleteDelegateT func);

#ifdef __cplusplus
}
#endif //__cplusplus
Binary file added lib/CLEO.lib
Binary file not shown.
80 changes: 28 additions & 52 deletions src/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ void f_GTA_SPCheck() {
}

if (!GetModuleHandle(moduleName.c_str())) {
Log("[ImGuiRedux] SilentPatch not found. Please install it from here https://gtaforums.com/topic/669045-silentpatch/");
int msgID = MessageBox(NULL, "SilentPatch not found. Do you want to install Silent Patch? (Game restart required)", "ImGuiRedux", MB_OKCANCEL | MB_DEFBUTTON1);

if (msgID == IDOK) {
ShellExecute(nullptr, "open", "https://gtaforums.com/topic/669045-silentpatch/", nullptr, nullptr, SW_SHOWNORMAL);
};
Expand All @@ -43,7 +41,6 @@ void ImGuiThread(void* param) {
Sleep(5000);

if (!Hook::Inject(&ScriptExData::DrawFrames)) {
Log("[ImGuiRedux] Failed to inject dxhook.");
MessageBox(HWND_DESKTOP, "Failed to inject dxhook..", "ImGuiRedux", MB_ICONERROR);
}

Expand All @@ -54,66 +51,45 @@ void ImGuiThread(void* param) {

BOOL WINAPI DllMain(HINSTANCE hDllHandle, DWORD nReason, LPVOID Reserved) {
if (nReason == DLL_PROCESS_ATTACH) {
HostId id = GetHostId();
auto gvm = injector::game_version_manager();
gvm.Detect();

switch (id) {
#ifdef _WIN64
case HostId::GTA3_UNREAL: {
gGameVer = eGameVer::III_DE;
break;
}
case HostId::VC_UNREAL: {
gGameVer = eGameVer::VC_DE;
break;
}
case HostId::SA_UNREAL: {
gGameVer = eGameVer::SA_DE;
break;
}
#else
case HostId::GTA3: {
// III 1.0 US
if (gvm.IsIII()
&& gvm.GetMajorVersion() == 1
&& gvm.GetMinorVersion() == 0
) {
if (gvm.GetMajorVersion() == 1 && gvm.GetMinorVersion() == 0) {
if (gvm.IsIII()) {
gGameVer = eGameVer::III;
}
break;
}
case HostId::VC: {
// VC 1.0 US
if (gvm.IsVC()
&& gvm.GetMajorVersion() == 1
&& gvm.GetMinorVersion() == 0
) {

if (gvm.IsVC()) {
gGameVer = eGameVer::VC;
}
break;
}
case HostId::SA: {
// SA US 1.0
if (gvm.IsSA()
&& gvm.GetMajorVersion() == 1
&& gvm.GetMinorVersion() == 0
) {

if (gvm.IsSA()) {
gGameVer = eGameVer::SA;
}
break;
}
case HostId::BULLY: {
gGameVer = eGameVer::BullySE;
break;
}
#endif
default: {
gGameVer = eGameVer::Unknown;
break;
}
}

if constexpr (gRunTime == eRunTime::Redux) {
HostId id = GetHostId();
switch (id) {
case HostId::GTA3_UNREAL: {
gGameVer = eGameVer::III_DE;
break;
}
case HostId::VC_UNREAL: {
gGameVer = eGameVer::VC_DE;
break;
}
case HostId::SA_UNREAL: {
gGameVer = eGameVer::SA_DE;
break;
}
case HostId::BULLY: {
gGameVer = eGameVer::BullySE;
break;
}
}
}

OpcodeMgr::RegisterCommands();
CreateThread(nullptr, NULL, (LPTHREAD_START_ROUTINE)&ImGuiThread, nullptr, NULL, nullptr);
}
Expand Down
Loading

0 comments on commit bc7133f

Please sign in to comment.