Skip to content

Commit

Permalink
Introduced ModLoader plugin and support
Browse files Browse the repository at this point in the history
  • Loading branch information
MiranDMC committed Jun 16, 2024
1 parent 0da5208 commit 1434dae
Show file tree
Hide file tree
Showing 33 changed files with 1,607 additions and 101 deletions.
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 @@ -83,6 +84,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 @@ -105,6 +105,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>plugin_sdk</Filter>
</ClCompile>
Expand Down Expand Up @@ -173,6 +176,9 @@
<ClInclude Include="source\OpcodeInfoDatabase.h">
<Filter>source\utils</Filter>
</ClInclude>
<ClInclude Include="source\CModLoaderSystem.h">
<Filter>source\extensions</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="source\cleo.def">
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ CLEO itself does not replace any game file, however the following files and fold

- cleo\ (CLEO script directory)
- cleo\\.config\sa.json (opcodes info file)
- cleo\cleo_plugins\SA.Audio.cleo (audio playback utilities powered by BASS.dll library)
- cleo\cleo_plugins\SA.DebugUtils.cleo (script debugging utilities plugin)
- cleo\cleo_plugins\SA.FileSystemOperations.cleo (disk drive files related operations plugin)
- cleo\cleo_plugins\SA.IniFiles.cleo (.ini config files handling plugin)
- cleo\cleo_plugins\SA.Math.cleo (additional math operations plugin)
- cleo\cleo_plugins\SA.MemoryOperations.cleo (memory and .dll libraries utilities plugin)
- cleo\cleo_plugins\SA.Text.cleo (text processing plugin)
- cleo\cleo_plugins\SA.Audio.cleo5 (audio playback utilities powered by BASS.dll library)
- cleo\cleo_plugins\SA.DebugUtils.cleo5 (script debugging utilities plugin)
- cleo\cleo_plugins\SA.FileSystemOperations.cleo5 (disk drive files related operations plugin)
- cleo\cleo_plugins\SA.IniFiles.cleo5 (.ini config files handling plugin)
- cleo\cleo_plugins\SA.Math.cleo5 (additional math operations plugin)
- cleo\cleo_plugins\SA.MemoryOperations.cleo5 (memory and .dll libraries utilities plugin)
- cleo\cleo_plugins\SA.Text.cleo5 (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
4 changes: 2 additions & 2 deletions cleo_plugins/Audio/Audio.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@
<OutDir>$(SolutionDir).output\</OutDir>
<IntDir>$(ProjectDir).obj\$(Configuration)\</IntDir>
<TargetName>SA.Audio</TargetName>
<TargetExt>.cleo</TargetExt>
<TargetExt>.cleo5</TargetExt>
<LibraryPath>$(ProjectDir)bass;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir).output\</OutDir>
<IntDir>$(ProjectDir).obj\$(Configuration)\</IntDir>
<TargetName>SA.Audio</TargetName>
<TargetExt>.cleo</TargetExt>
<TargetExt>.cleo5</TargetExt>
<LibraryPath>$(ProjectDir)bass;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions cleo_plugins/DebugUtils/DebugUtils.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@
<OutDir>$(SolutionDir).output\</OutDir>
<IntDir>$(ProjectDir).obj\$(Configuration)\</IntDir>
<TargetName>SA.DebugUtils</TargetName>
<TargetExt>.cleo</TargetExt>
<TargetExt>.cleo5</TargetExt>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir).output\</OutDir>
<IntDir>$(ProjectDir).obj\$(Configuration)\</IntDir>
<TargetName>SA.DebugUtils</TargetName>
<TargetExt>.cleo</TargetExt>
<TargetExt>.cleo5</TargetExt>
</PropertyGroup>
<PropertyGroup>
<LocalDebuggerCommand>$(GTA_SA_DIR)\gta_sa.exe</LocalDebuggerCommand>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@
<OutDir>$(SolutionDir).output\</OutDir>
<IntDir>$(ProjectDir).obj\$(Configuration)\</IntDir>
<TargetName>SA.FileSystemOperations</TargetName>
<TargetExt>.cleo</TargetExt>
<TargetExt>.cleo5</TargetExt>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir).output\</OutDir>
<IntDir>$(ProjectDir).obj\$(Configuration)\</IntDir>
<TargetName>SA.FileSystemOperations</TargetName>
<TargetExt>.cleo</TargetExt>
<TargetExt>.cleo5</TargetExt>
</PropertyGroup>
<PropertyGroup>
<LocalDebuggerCommand>$(GTA_SA_DIR)\gta_sa.exe</LocalDebuggerCommand>
Expand Down
4 changes: 2 additions & 2 deletions cleo_plugins/IniFiles/IniFiles.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@
<OutDir>$(SolutionDir).output\</OutDir>
<IntDir>$(ProjectDir).obj\$(Configuration)\</IntDir>
<TargetName>SA.IniFiles</TargetName>
<TargetExt>.cleo</TargetExt>
<TargetExt>.cleo5</TargetExt>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir).output\</OutDir>
<IntDir>$(ProjectDir).obj\$(Configuration)\</IntDir>
<TargetName>SA.IniFiles</TargetName>
<TargetExt>.cleo</TargetExt>
<TargetExt>.cleo5</TargetExt>
</PropertyGroup>
<PropertyGroup>
<LocalDebuggerCommand>$(GTA_SA_DIR)\gta_sa.exe</LocalDebuggerCommand>
Expand Down
4 changes: 2 additions & 2 deletions cleo_plugins/Math/Math.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@
<OutDir>$(SolutionDir).output\</OutDir>
<IntDir>$(ProjectDir).obj\$(Configuration)\</IntDir>
<TargetName>SA.Math</TargetName>
<TargetExt>.cleo</TargetExt>
<TargetExt>.cleo5</TargetExt>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir).output\</OutDir>
<IntDir>$(ProjectDir).obj\$(Configuration)\</IntDir>
<TargetName>SA.Math</TargetName>
<TargetExt>.cleo</TargetExt>
<TargetExt>.cleo5</TargetExt>
</PropertyGroup>
<PropertyGroup>
<LocalDebuggerCommand>$(GTA_SA_DIR)\gta_sa.exe</LocalDebuggerCommand>
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
}
};

42 changes: 23 additions & 19 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 @@ -152,25 +153,28 @@ class MemoryOperations
}
}

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
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
5 changes: 3 additions & 2 deletions cleo_plugins/MemoryOperations/MemoryOperations.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@
<OutDir>$(SolutionDir).output\</OutDir>
<IntDir>$(ProjectDir).obj\$(Configuration)\</IntDir>
<TargetName>SA.MemoryOperations</TargetName>
<TargetExt>.cleo</TargetExt>
<TargetExt>.cleo5</TargetExt>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir).output\</OutDir>
<IntDir>$(ProjectDir).obj\$(Configuration)\</IntDir>
<TargetName>SA.MemoryOperations</TargetName>
<TargetExt>.cleo</TargetExt>
<TargetExt>.cleo5</TargetExt>
</PropertyGroup>
<PropertyGroup>
<LocalDebuggerCommand>$(GTA_SA_DIR)\gta_sa.exe</LocalDebuggerCommand>
Expand Down 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
4 changes: 2 additions & 2 deletions cleo_plugins/Text/Text.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@
<OutDir>$(SolutionDir).output\</OutDir>
<IntDir>$(ProjectDir).obj\$(Configuration)\</IntDir>
<TargetName>SA.Text</TargetName>
<TargetExt>.cleo</TargetExt>
<TargetExt>.cleo5</TargetExt>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir).output\</OutDir>
<IntDir>$(ProjectDir).obj\$(Configuration)\</IntDir>
<TargetName>SA.Text</TargetName>
<TargetExt>.cleo</TargetExt>
<TargetExt>.cleo5</TargetExt>
</PropertyGroup>
<PropertyGroup>
<LocalDebuggerCommand>$(GTA_SA_DIR)\gta_sa.exe</LocalDebuggerCommand>
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 1434dae

Please sign in to comment.