Skip to content

Commit

Permalink
Introduced proper ModLoader support with plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
MiranDMC committed Sep 13, 2024
1 parent b099c1c commit d2613fd
Show file tree
Hide file tree
Showing 29 changed files with 1,777 additions and 93 deletions.
35 changes: 31 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,34 @@ jobs:
vt_api_key: ${{ secrets.VT_KEY }}
files: './cleo_plugins/.output/*.cleo'

- name: ModLoader plugin - Build
shell: cmd
run: |
set PLUGIN_SDK_DIR=%GITHUB_WORKSPACE%\third-party\plugin-sdk
msbuild -m modloader_plugin/CLEO_ModLoader_Plugin.sln /property:Configuration=Release /property:Platform=x86
- name: ModLoader plugin - Sign
uses: x87/code-sign-action@develop
with:
certificate: '${{ secrets.DIG_KEY_CERT }}'
password: '${{ secrets.DIG_KEY_PWD }}'
certificatename: 'Seemann'
description: 'CLEO 5 ModLoader plugin'
timestampUrl: 'http://timestamp.digicert.com'
filename: './modloader_plugin/.output/Release/CLEO5_Provider.dll'

- name: ModLoader plugin - VirusTotal Scan
uses: crazy-max/ghaction-virustotal@v4
with:
vt_api_key: ${{ secrets.VT_KEY }}
files: './modloader_plugin/.output/Release/CLEO5_Provider.dll'

- name: Gather Output Files
id: prepare_archive
shell: cmd
run: |
@REM create output directory
echo on
echo Creating output directories
mkdir .output\Release\cleo
mkdir .output\Release\cleo\.config
mkdir .output\Release\cleo\cleo_modules
Expand All @@ -82,19 +105,23 @@ jobs:
mkdir .output\Release\cleo\cleo_text
mkdir .output\Release\cleo_readme
mkdir .output\Release\cleo_readme\examples
mkdir .output\Release\modloader
mkdir .output\Release\modloader\.data
mkdir .output\Release\modloader\.data\plugins
@REM copy files
echo Copying output files
copy source\cleo_config.ini .output\Release\cleo\.cleo_config.ini
copy cleo_plugins\.output\*.cleo .output\Release\cleo\cleo_plugins
copy cleo_plugins\.output\*.ini .output\Release\cleo\cleo_plugins
copy cleo_plugins\Audio\bass\bass.dll .output\Release\bass.dll
copy modloader_plugin\.output\Release\*.dll .output\Release\modloader\.data\plugins
xcopy /E /I tests .output\Release\cleo
xcopy /E /I examples .output\Release\cleo_readme\examples
@REM copy SDK
echo Copying CLEO SDK
copy .output\Release\CLEO.lib cleo_sdk\CLEO.lib
@REM download Sanny Builder Library json
echo Downloading Sanny Builder Library json
curl https://raw.githubusercontent.com/sannybuilder/library/master/sa/sa.json -o .output\Release\cleo\.config\sa.json
- name: Convert Markdown to HTML
Expand Down
37 changes: 32 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,52 @@ jobs:
with:
vt_api_key: ${{ secrets.VT_KEY }}
files: './cleo_plugins/.output/*.cleo'

- name: ModLoader plugin - Build
shell: cmd
run: |
set PLUGIN_SDK_DIR=%GITHUB_WORKSPACE%\third-party\plugin-sdk
msbuild -m modloader_plugin/CLEO_ModLoader_Plugin.sln /property:Configuration=Release /property:Platform=x86
- name: ModLoader plugin - Sign
uses: x87/code-sign-action@develop
with:
certificate: '${{ secrets.DIG_KEY_CERT }}'
password: '${{ secrets.DIG_KEY_PWD }}'
certificatename: 'Seemann'
description: 'CLEO 5 ModLoader plugin'
timestampUrl: 'http://timestamp.digicert.com'
filename: './modloader_plugin/.output/Release/CLEO5_Provider.dll'

- name: ModLoader plugin - VirusTotal Scan
uses: crazy-max/ghaction-virustotal@v4
with:
vt_api_key: ${{ secrets.VT_KEY }}
files: './modloader_plugin/.output/Release/CLEO5_Provider.dll'

- name: Gather Output Files
id: prepare_archive
shell: cmd
run: |
@REM create output directory
echo on
echo Creating output directories
mkdir .output\Release\cleo
mkdir .output\Release\cleo\cleo_plugins
@REM copy files
copy third-party\bass\bass.dll .output\Release\bass.dll
mkdir .output\Release\modloader
mkdir .output\Release\modloader\.data
mkdir .output\Release\modloader\.data\plugins
echo Copying output files
copy source\cleo_config.ini .output\Release\cleo\.cleo_config.ini
copy cleo_plugins\.output\*.cleo .output\Release\cleo\cleo_plugins
copy cleo_plugins\.output\*.ini .output\Release\cleo\cleo_plugins
copy cleo_plugins\Audio\bass\bass.dll .output\Release\bass.dll
copy modloader_plugin\.output\Release\*.dll .output\Release\modloader\.data\plugins
- name: Upload Result
uses: actions/upload-artifact@v4
with:
compression-level: 0
compression-level: 6 #Default
name: SA.CLEO5
path: |
.output\Release\*
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 5.0.0

- support for CLEO modules feature https://github.com/sannybuilder/dev/issues/264
- improved ModLoader support with CLEO plugin
- new [Audio](https://github.com/cleolibrary/CLEO5/tree/master/cleo_plugins/Audio) plugin
- audio related opcodes moved from CLEO core into separated plugin
- CLEO's audio now obey game's volume settings
Expand Down
2 changes: 2 additions & 0 deletions CLEO5.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<ClCompile Include="source\CGameMenu.cpp" />
<ClCompile Include="source\CGameVersionManager.cpp" />
<ClCompile Include="source\CleoBase.cpp" />
<ClCompile Include="source\CModLoaderSystem.cpp" />
<ClCompile Include="source\CModuleSystem.cpp" />
<ClCompile Include="source\CPluginSystem.cpp" />
<ClCompile Include="source\crc32.cpp" />
Expand Down Expand Up @@ -87,6 +88,7 @@
<ClInclude Include="source\CGameMenu.h" />
<ClInclude Include="source\CGameVersionManager.h" />
<ClInclude Include="source\CleoBase.h" />
<ClInclude Include="source\CModLoaderSystem.h" />
<ClInclude Include="source\CModuleSystem.h" />
<ClInclude Include="source\CPluginSystem.h" />
<ClInclude Include="source\crc32.h" />
Expand Down
6 changes: 6 additions & 0 deletions CLEO5.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@
<ClCompile Include="source\CPluginSystem.cpp">
<Filter>source\extensions</Filter>
</ClCompile>
<ClCompile Include="source\CModLoaderSystem.cpp">
<Filter>source\extensions</Filter>
</ClCompile>
<ClCompile Include="$(PLUGIN_SDK_DIR)\plugin_sa\game_sa\CModelInfo.cpp">
<Filter>third_party\plugin_sdk</Filter>
</ClCompile>
Expand Down Expand Up @@ -182,6 +185,9 @@
<ClInclude Include="source\OpcodeInfoDatabase.h">
<Filter>source\utils</Filter>
</ClInclude>
<ClInclude Include="source\CModLoaderSystem.h">
<Filter>source\extensions</Filter>
</ClInclude>
<ClInclude Include="third-party\simdjson\simdjson.h">
<Filter>third_party\simdjson</Filter>
</ClInclude>
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ CLEO itself does not replace any game file, however the following files and fold
- cleo\cleo_plugins\SA.Text.cleo (text processing plugin)
- cleo\cleo_saves\ (CLEO save directory)
- cleo\cleo_text\ (CLEO text directory)
- modloader\.data\plugins\CLEO5_Provider.dll (CLEO5 ModLoader plugin)
- cleo.asi (core library)
- bass.dll (audio engine library)

Expand Down
32 changes: 32 additions & 0 deletions cleo_plugins/MemoryOperations/AntiHacks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#pragma once
#include "CLEO.h"
//#include "CFileMgr.h"
#include <string>

namespace AntiHacks
{
// checks if specific function call should be allowed. Performs replacement action if needed
static bool CheckCall(CLEO::CRunningScript* thread, void* function, void* object, CLEO::SCRIPT_VAR* args, size_t argCount, DWORD& result)
{
switch ((size_t)function)
{
case 0x005387D0: // CFileMgr::SetDir(const char* relPath) // TODO: get the address from Plugin SDK
{
// some older mods use CFileMgr::SetDir directly instead of 0A99 opcode. In older CLEO versions 0A99 supported only few predefined locations
auto resolved = std::string(args[0].pcParam);
resolved.resize(511);
CLEO_ResolvePath(thread, resolved.data(), resolved.size());

CLEO::CLEO_SetScriptWorkDir(thread, resolved.c_str());
return false;
}
break;

default:
break;
}

return true; // allow
}
};

44 changes: 24 additions & 20 deletions cleo_plugins/MemoryOperations/MemoryOperations.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "CLEO.h"
#include "CLEO_Utils.h"
#include "AntiHacks.h"
#include "plugin.h"
#include "CTheScripts.h"
#include <filesystem>
Expand Down Expand Up @@ -159,26 +160,29 @@ class MemoryOperations
}

SCRIPT_VAR* arguments_end = arguments + numArg;
numPop *= 4; // bytes peer argument
DWORD result;
_asm
{
// transfer args to stack
lea ecx, arguments
call_func_loop :
cmp ecx, arguments_end
jae call_func_loop_end
push[ecx]
add ecx, 0x4
jmp call_func_loop
call_func_loop_end :

// call function
mov ecx, obj
xor eax, eax
call func
mov result, eax // get result
add esp, numPop // cleanup stack
numPop *= 4; // bytes peer argument
DWORD result = 0;
if (AntiHacks::CheckCall(thread, func, obj, scriptParams, numArg, result))
{
_asm
{
// transfer args to stack
lea ecx, arguments
call_func_loop :
cmp ecx, arguments_end
jae call_func_loop_end
push[ecx]
add ecx, 0x4
jmp call_func_loop
call_func_loop_end :

// call function
mov ecx, obj
xor eax, eax
call func
mov result, eax // get result
add esp, numPop // cleanup stack
}
}

if (returnArg)
Expand Down
1 change: 1 addition & 0 deletions cleo_plugins/MemoryOperations/MemoryOperations.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ if defined GTA_SA_DIR (
<ItemGroup>
<ClInclude Include="..\..\cleo_sdk\CLEO.h" />
<ClInclude Include="..\..\cleo_sdk\CLEO_Utils.h" />
<ClInclude Include="AntiHacks.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\Resource.rc" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<ClInclude Include="..\..\cleo_sdk\CLEO_Utils.h">
<Filter>cleo_sdk</Filter>
</ClInclude>
<ClInclude Include="AntiHacks.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\Resource.rc" />
Expand Down
25 changes: 25 additions & 0 deletions modloader_plugin/CLEO_ModLoader_Plugin.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33213.308
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CLEO_ModLoader_Plugin", "CLEO_ModLoader_Plugin.vcxproj", "{E04BB51D-A37D-491E-BAA0-D95D0D5C1563}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E04BB51D-A37D-491E-BAA0-D95D0D5C1563}.Debug|x86.ActiveCfg = Debug|Win32
{E04BB51D-A37D-491E-BAA0-D95D0D5C1563}.Debug|x86.Build.0 = Debug|Win32
{E04BB51D-A37D-491E-BAA0-D95D0D5C1563}.Release|x86.ActiveCfg = Release|Win32
{E04BB51D-A37D-491E-BAA0-D95D0D5C1563}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {27E214E3-AE89-40E1-9B76-0C5C9DB3452C}
EndGlobalSection
EndGlobal
Loading

0 comments on commit d2613fd

Please sign in to comment.