Skip to content

Commit

Permalink
ModLoader plugin and proper support
Browse files Browse the repository at this point in the history
  • Loading branch information
MiranDMC committed Nov 30, 2024
1 parent 27e9f27 commit 91dec23
Show file tree
Hide file tree
Showing 28 changed files with 1,695 additions and 54 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,28 @@ 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
Expand All @@ -82,12 +104,16 @@ 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
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
Expand Down
30 changes: 29 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,28 @@ 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
Expand All @@ -72,17 +94,23 @@ jobs:
@REM create output directory
mkdir .output\Release\cleo
mkdir .output\Release\cleo\cleo_plugins
mkdir .output\Release\modloader
mkdir .output\Release\modloader\.data
mkdir .output\Release\modloader\.data\plugins
@REM copy files
copy third-party\bass\bass.dll .output\Release\bass.dll
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
include-hidden-files: true
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 @@ -90,6 +91,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 <string>

namespace AntiHacks
{
// checks if specific function call is 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)
//case 0x00836F1E: // int _chdir(LPCSTR lpPathName) TODO?
//case 0x0085824C: // imp_SetCurrentDirectoryA TODO?
{
// some older mods used CFileMgr::SetDir directly instead of 0A99 opcode
auto resolved = std::string(args[0].pcParam);
resolved.resize(MAX_PATH);
CLEO_ResolvePath(thread, resolved.data(), resolved.size());

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

default:
break;
}

return true; // allow
}
};
54 changes: 31 additions & 23 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,29 +160,30 @@ class MemoryOperations
}

SCRIPT_VAR* arguments_end = arguments + numArg;
numPop *= 4; // bytes peer argument
DWORD result;
numPop *= 4; // bytes peer argument
DWORD result = 0;
int oriSp, postSp; // stack validation
_asm
{
_asm
{
mov oriSp, esp

// 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
// 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

mov postSp, esp
}
Expand All @@ -198,6 +200,7 @@ class MemoryOperations
int requiredPop = (numPop + diff) / 4;
SHOW_ERROR("Function call left stack position changed (%s%d). This usually happens when incorrect calling convention is used. \nArgument 'pop' value should have been %d in script %s \nScript suspended.", diff > 0 ? "+" : "", diff, requiredPop, CLEO::ScriptInfoStr(thread).c_str());
return thread->Suspend();
}
}

if (returnArg)
Expand Down Expand Up @@ -397,10 +400,15 @@ class MemoryOperations
HMODULE ptr = nullptr;

// resolve absolute path and try load
char buff[MAX_PATH];
strncpy(buff, path, sizeof(buff));
CLEO_ResolvePath(thread, buff, sizeof(buff));
ptr = LoadLibrary(buff);
std::string buff = path;
buff.resize(MAX_PATH);
CLEO_ResolvePath(thread, buff.data(), buff.size());
buff.resize(strlen(buff.data()));

// ModLoader's hooks require relative paths in LoadLibrary to work
FilepathRemoveParent(buff, CLEO_GetGameDirectory());

ptr = LoadLibrary(buff.c_str());

// in case of just filename let LoadLibrary resolve it itself
if (ptr == nullptr && !std::filesystem::path(path).has_parent_path())
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 91dec23

Please sign in to comment.