Skip to content

Commit

Permalink
Add opcode 0DD5 (get_platform) (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
MiranDMC authored Sep 19, 2023
1 parent 03bdb17 commit efe00ef
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 4.4.5

- Added opcode 0DD5 (get_platform).

## 4.4.4

- added string arguments support to 0AB1 (cleo_call)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# CLEO Library for GTA San Andreas
# CLEO Library for GTA San Andreas (Windows PC)

CLEO is a hugely popular extensible library plugin which brings new possibilities in scripting for the game Grand Theft Auto: San Andreas by Rockstar Games, allowing the use of thousands of unique mods which change or expand the gameplay. You may find more information about CLEO on the official website https://cleo.li

Expand Down
32 changes: 11 additions & 21 deletions source/CCustomOpcodeSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ namespace CLEO {
OpcodeResult __stdcall opcode_0AEE(CRunningScript *thread);
OpcodeResult __stdcall opcode_0AEF(CRunningScript *thread);

OpcodeResult __stdcall opcode_0DD5(CRunningScript* thread); // get_platform

CustomOpcodeHandler customOpcodeHandlers[100] =
{
opcode_0A8C, opcode_0A8D, opcode_0A8E, opcode_0A8F, opcode_0A90,
Expand Down Expand Up @@ -262,6 +264,8 @@ namespace CLEO {
// fill the rest with default handler
std::fill(newOpcodeHandlerTable + 28, newOpcodeHandlerTable + 329, reinterpret_cast<_OpcodeHandler>(extraOpcodeHandler));

CLEO_RegisterOpcode(0x0DD5, opcode_0DD5); // get_platform

FUNC_fopen = gvm.TranslateMemoryAddress(MA_FOPEN_FUNCTION);
FUNC_fclose = gvm.TranslateMemoryAddress(MA_FCLOSE_FUNCTION);
FUNC_fread = gvm.TranslateMemoryAddress(MA_FREAD_FUNCTION);
Expand Down Expand Up @@ -2645,6 +2649,13 @@ namespace CLEO {
*thread << (float)(log(arg) / log(base));
return OR_CONTINUE;
}

//0DD5=1,%1d% = get_platform
OpcodeResult __stdcall opcode_0DD5(CRunningScript* thread)
{
*thread << PLATFORM_WINDOWS;
return OR_CONTINUE;
}
}


Expand All @@ -2655,27 +2666,6 @@ namespace CLEO {
extern "C"
{
using namespace CLEO;

// Define external symbols with MSVC decorating schemes
BOOL WINAPI CLEO_RegisterOpcode(WORD opcode, CustomOpcodeHandler callback);
DWORD WINAPI CLEO_GetIntOpcodeParam(CRunningScript* thread);
float WINAPI CLEO_GetFloatOpcodeParam(CRunningScript* thread);
void WINAPI CLEO_SetIntOpcodeParam(CRunningScript* thread, DWORD value);
void WINAPI CLEO_SetFloatOpcodeParam(CRunningScript* thread, float value);
LPSTR WINAPI CLEO_ReadStringOpcodeParam(CRunningScript* thread, char *buf, int size);
LPSTR WINAPI CLEO_ReadStringPointerOpcodeParam(CRunningScript* thread, char *buf, int size);
void WINAPI CLEO_WriteStringOpcodeParam(CRunningScript* thread, LPCSTR str);
void WINAPI CLEO_SetThreadCondResult(CRunningScript* thread, BOOL result);
void WINAPI CLEO_SkipOpcodeParams(CRunningScript* thread, int count);
void WINAPI CLEO_ThreadJumpAtLabelPtr(CRunningScript* thread, int labelPtr);
int WINAPI CLEO_GetOperandType(CRunningScript* thread);
void WINAPI CLEO_RetrieveOpcodeParams(CRunningScript *thread, int count);
void WINAPI CLEO_RecordOpcodeParams(CRunningScript *thread, int count);
SCRIPT_VAR * WINAPI CLEO_GetPointerToScriptVariable(CRunningScript* thread);
RwTexture * WINAPI CLEO_GetScriptTextureById(CRunningScript* thread, int id);
HSTREAM WINAPI CLEO_GetInternalAudioStream(CRunningScript* thread, CAudioStream *stream);
CRunningScript* WINAPI CLEO_CreateCustomScript(CRunningScript* fromThread, const char *fileName, int label);

#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable:4550)
Expand Down
25 changes: 25 additions & 0 deletions source/CCustomOpcodeSystem.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include "CCodeInjector.h"
#include "CDebug.h"
#include "CSoundSystem.h"
#include <direct.h>
#include <set>

Expand Down Expand Up @@ -75,4 +76,28 @@ namespace CLEO
};

extern void(__thiscall * ProcessScript)(CRunningScript*);

// Exports
extern "C"
{
// Define external symbols with MSVC decorating schemes
BOOL WINAPI CLEO_RegisterOpcode(WORD opcode, CustomOpcodeHandler callback);
DWORD WINAPI CLEO_GetIntOpcodeParam(CRunningScript* thread);
float WINAPI CLEO_GetFloatOpcodeParam(CRunningScript* thread);
void WINAPI CLEO_SetIntOpcodeParam(CRunningScript* thread, DWORD value);
void WINAPI CLEO_SetFloatOpcodeParam(CRunningScript* thread, float value);
LPSTR WINAPI CLEO_ReadStringOpcodeParam(CRunningScript* thread, char* buf, int size);
LPSTR WINAPI CLEO_ReadStringPointerOpcodeParam(CRunningScript* thread, char* buf, int size);
void WINAPI CLEO_WriteStringOpcodeParam(CRunningScript* thread, LPCSTR str);
void WINAPI CLEO_SetThreadCondResult(CRunningScript* thread, BOOL result);
void WINAPI CLEO_SkipOpcodeParams(CRunningScript* thread, int count);
void WINAPI CLEO_ThreadJumpAtLabelPtr(CRunningScript* thread, int labelPtr);
int WINAPI CLEO_GetOperandType(CRunningScript* thread);
void WINAPI CLEO_RetrieveOpcodeParams(CRunningScript* thread, int count);
void WINAPI CLEO_RecordOpcodeParams(CRunningScript* thread, int count);
SCRIPT_VAR* WINAPI CLEO_GetPointerToScriptVariable(CRunningScript* thread);
RwTexture* WINAPI CLEO_GetScriptTextureById(CRunningScript* thread, int id);
HSTREAM WINAPI CLEO_GetInternalAudioStream(CRunningScript* thread, CAudioStream* stream);
CRunningScript* WINAPI CLEO_CreateCustomScript(CRunningScript* fromThread, const char* fileName, int label);
}
}
15 changes: 15 additions & 0 deletions source/CGameVersionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ namespace CLEO
GV_UNK = -1
};

// returned by 0DD5: get_platform opcode
enum ePlatform
{
PLATFORM_NONE,
PLATFORM_ANDROID,
PLATFORM_PSP,
PLATFORM_IOS,
PLATFORM_FOS,
PLATFORM_XBOX,
PLATFORM_PS2,
PLATFORM_PS3,
PLATFORM_MAC,
PLATFORM_WINDOWS
};

// determines the list of memory adresses, that can be translated
// considering to game version
enum eMemoryAddress
Expand Down

0 comments on commit efe00ef

Please sign in to comment.