Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IntOperations turned into Math plugin #116

Merged
merged 7 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,20 @@
- new opcode **2302 ([write_block_to_file](https://library.sannybuilder.com/#/sa/file/2302))**
- new opcode **2303 ([resolve_filepath](https://library.sannybuilder.com/#/sa/file/2303))**
- new opcode **2304 ([get_script_filename](https://library.sannybuilder.com/#/sa/file/2304))**
- new [Math](https://github.com/cleolibrary/CLEO5/tree/master/cleo_plugins/Math) plugin
- math related opcodes moved from CLEO core into separated plugin
- new opcode **2700 ([is_bit_set](https://library.sannybuilder.com/#/sa/math/2700))**
- new opcode **2701 ([set_bit](https://library.sannybuilder.com/#/sa/math/2701))**
- new opcode **2702 ([clear_bit](https://library.sannybuilder.com/#/sa/math/2702))**
- new opcode **2703 ([toggle_bit](https://library.sannybuilder.com/#/sa/math/2703))**
- new opcode **2704 ([is_truthy](https://library.sannybuilder.com/#/sa/math/2704))**
- new [MemoryOperations](https://github.com/cleolibrary/CLEO5/tree/master/cleo_plugins/MemoryOperations) plugin
- memory related opcodes moved from CLEO core into separated plugin
- validation of input and output parameters for all opcodes
- opcode **0A8C ([write_memory](https://library.sannybuilder.com/#/sa/memory/0A8C))** now supports strings
- new opcode **2400 ([copy_memory](https://library.sannybuilder.com/#/sa/memory/2400))**
- new opcode **2401 ([read_memory_with_offset](https://library.sannybuilder.com/#/sa/memory/2401))**
- new opcode **2402 ([writememory_with_offset](https://library.sannybuilder.com/#/sa/memory/2402))**
- new opcode **2402 ([write_memory_with_offset](https://library.sannybuilder.com/#/sa/memory/2402))**
- new opcode **2403 ([forget_memory](https://library.sannybuilder.com/#/sa/memory/2403))**
- new opcode **2404 ([get_script_struct_just_created](https://library.sannybuilder.com/#/sa/memory/2404))**
- new opcode **2405 ([is_script_running](https://library.sannybuilder.com/#/sa/memory/2405))**
Expand Down
12 changes: 6 additions & 6 deletions cleo_plugins/CLEO_Plugins.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FileSystemOperations", "Fil
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "IniFiles", "IniFiles\IniFiles.vcxproj", "{6831362D-5226-4634-9DB4-266A1B6C3E6C}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "IntOperations", "IntOperations\IntOperations.vcxproj", "{68A434CF-6390-4FDF-9A15-36A8A9ECEAA9}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DebugUtils", "DebugUtils\DebugUtils.vcxproj", "{481896C4-0C19-4992-9602-729537774B32}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MemoryOperations", "MemoryOperations\MemoryOperations.vcxproj", "{35C80F79-8B18-4925-8C32-94B320DBE76F}"
Expand All @@ -17,6 +15,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Audio", "Audio\Audio.vcxpro
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Text", "Text\Text.vcxproj", "{BD19AEFD-626B-40AE-8D83-6D444D2EFBF8}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Math", "Math\Math.vcxproj", "{68A434CF-6390-4FDF-9A15-36A8A9ECEAA9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Expand All @@ -31,10 +31,6 @@ Global
{6831362D-5226-4634-9DB4-266A1B6C3E6C}.Debug|x86.Build.0 = Debug|Win32
{6831362D-5226-4634-9DB4-266A1B6C3E6C}.Release|x86.ActiveCfg = Release|Win32
{6831362D-5226-4634-9DB4-266A1B6C3E6C}.Release|x86.Build.0 = Release|Win32
{68A434CF-6390-4FDF-9A15-36A8A9ECEAA9}.Debug|x86.ActiveCfg = Debug|Win32
{68A434CF-6390-4FDF-9A15-36A8A9ECEAA9}.Debug|x86.Build.0 = Debug|Win32
{68A434CF-6390-4FDF-9A15-36A8A9ECEAA9}.Release|x86.ActiveCfg = Release|Win32
{68A434CF-6390-4FDF-9A15-36A8A9ECEAA9}.Release|x86.Build.0 = Release|Win32
{481896C4-0C19-4992-9602-729537774B32}.Debug|x86.ActiveCfg = Debug|Win32
{481896C4-0C19-4992-9602-729537774B32}.Debug|x86.Build.0 = Debug|Win32
{481896C4-0C19-4992-9602-729537774B32}.Release|x86.ActiveCfg = Release|Win32
Expand All @@ -51,6 +47,10 @@ Global
{BD19AEFD-626B-40AE-8D83-6D444D2EFBF8}.Debug|x86.Build.0 = Debug|Win32
{BD19AEFD-626B-40AE-8D83-6D444D2EFBF8}.Release|x86.ActiveCfg = Release|Win32
{BD19AEFD-626B-40AE-8D83-6D444D2EFBF8}.Release|x86.Build.0 = Release|Win32
{68A434CF-6390-4FDF-9A15-36A8A9ECEAA9}.Debug|x86.ActiveCfg = Debug|Win32
{68A434CF-6390-4FDF-9A15-36A8A9ECEAA9}.Debug|x86.Build.0 = Debug|Win32
{68A434CF-6390-4FDF-9A15-36A8A9ECEAA9}.Release|x86.ActiveCfg = Release|Win32
{68A434CF-6390-4FDF-9A15-36A8A9ECEAA9}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
6 changes: 0 additions & 6 deletions cleo_plugins/IntOperations/IntOperations.vcxproj.filters

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
using namespace CLEO;
using namespace plugin;

class IntOperations
class Math
{
public:
IntOperations()
Math()
{
auto cleoVer = CLEO_GetVersion();
if (cleoVer < CLEO_VERSION)
Expand All @@ -18,12 +18,15 @@ class IntOperations
return;
}

//register opcodes
// register opcodes
CLEO_RegisterOpcode(0x0A8E, opcode_0A8E); // x = a + b (int)
CLEO_RegisterOpcode(0x0A8F, opcode_0A8F); // x = a - b (int)
CLEO_RegisterOpcode(0x0A90, opcode_0A90); // x = a * b (int)
CLEO_RegisterOpcode(0x0A91, opcode_0A91); // x = a / b (int)

CLEO_RegisterOpcode(0x0AEE, opcode_0AEE); // pow
CLEO_RegisterOpcode(0x0AEF, opcode_0AEF); // log

CLEO_RegisterOpcode(0x0B10, Script_IntOp_AND);
CLEO_RegisterOpcode(0x0B11, Script_IntOp_OR);
CLEO_RegisterOpcode(0x0B12, Script_IntOp_XOR);
Expand All @@ -39,6 +42,12 @@ class IntOperations
CLEO_RegisterOpcode(0x0B1C, Scr_IntOp_SHR);
CLEO_RegisterOpcode(0x0B1D, Scr_IntOp_SHL);
CLEO_RegisterOpcode(0x0B1E, Sign_Extend);

CLEO_RegisterOpcode(0x2700, opcode_2700); // is_bit_set
CLEO_RegisterOpcode(0x2701, opcode_2701); // set_bit
CLEO_RegisterOpcode(0x2702, opcode_2702); // clear_bit
CLEO_RegisterOpcode(0x2703, opcode_2703); // toggle_bit
CLEO_RegisterOpcode(0x2704, opcode_2704); // is_truthy
}

//0A8E=3,%3d% = %1d% + %2d% ; int
Expand Down Expand Up @@ -89,6 +98,30 @@ class IntOperations
return OR_CONTINUE;
}

//0AEE=3,%3d% = %1d% exp %2d% // all floats
static OpcodeResult __stdcall opcode_0AEE(CRunningScript* thread)
{
auto base = OPCODE_READ_PARAM_FLOAT();
auto exponent = OPCODE_READ_PARAM_FLOAT();

auto result = (float)pow(base, exponent);

OPCODE_WRITE_PARAM_FLOAT(result);
return OR_CONTINUE;
}

//0AEF=3,%3d% = log %1d% base %2d% // all floats
static OpcodeResult __stdcall opcode_0AEF(CRunningScript* thread)
{
auto argument = OPCODE_READ_PARAM_FLOAT();
auto base = OPCODE_READ_PARAM_FLOAT();

auto exponent = log(argument) / log(base);

OPCODE_WRITE_PARAM_FLOAT(exponent);
return OR_CONTINUE;
}

static OpcodeResult WINAPI Script_IntOp_AND(CScriptThread* thread)
/****************************************************************
Opcode Format
Expand Down Expand Up @@ -310,4 +343,95 @@ class IntOperations

return OR_CONTINUE;
}
} intOperations;

//2700=2, is_bit_set value %1d% bit_index %2d%
static OpcodeResult WINAPI opcode_2700(CScriptThread* thread)
{
auto value = OPCODE_READ_PARAM_UINT();
auto bitIndex = OPCODE_READ_PARAM_INT();

if (bitIndex < 0 || bitIndex > 31)
{
SHOW_ERROR("Invalid '%d' bit index argument in script %s\nScript suspended.", bitIndex, ScriptInfoStr(thread).c_str());
return thread->Suspend();
}

bool result = (value >> bitIndex) & 1;

OPCODE_CONDITION_RESULT(result);
return OR_CONTINUE;
}

//2701=2,set_bit value %1d% bit_index %2d%
static OpcodeResult WINAPI opcode_2701(CScriptThread* thread)
{
auto value = OPCODE_READ_PARAM_OUTPUT_VAR_INT();
auto bitIndex = OPCODE_READ_PARAM_INT();

if (bitIndex < 0 || bitIndex > 31)
{
SHOW_ERROR("Invalid '%d' bit index argument in script %s\nScript suspended.", bitIndex, ScriptInfoStr(thread).c_str());
return thread->Suspend();
}

*value |= 1 << bitIndex;

return OR_CONTINUE;
}

//2702=2,clear_bit value %1d% bit_index %2d%
static OpcodeResult WINAPI opcode_2702(CScriptThread* thread)
{
auto value = OPCODE_READ_PARAM_OUTPUT_VAR_INT();
auto bitIndex = OPCODE_READ_PARAM_INT();

if (bitIndex < 0 || bitIndex > 31)
{
SHOW_ERROR("Invalid '%d' bit index argument in script %s\nScript suspended.", bitIndex, ScriptInfoStr(thread).c_str());
return thread->Suspend();
}

*value &= ~(1 << bitIndex);

return OR_CONTINUE;
}

//2703=3,toggle_bit value %1d% bit_index %2d% state %3d%
static OpcodeResult WINAPI opcode_2703(CScriptThread* thread)
{
auto value = OPCODE_READ_PARAM_OUTPUT_VAR_INT();
auto bitIndex = OPCODE_READ_PARAM_INT();
auto state = OPCODE_READ_PARAM_BOOL();

if (bitIndex < 0 || bitIndex > 31)
{
SHOW_ERROR("Invalid '%d' bit index argument in script %s\nScript suspended.", bitIndex, ScriptInfoStr(thread).c_str());
return thread->Suspend();
}

DWORD flag = 1 << bitIndex;
if (state)
*value |= flag;
else
*value &= ~flag;

return OR_CONTINUE;
}

//2704=1, is_truthy value %1d%
static OpcodeResult WINAPI opcode_2704(CScriptThread* thread)
{
auto paramType = OPCODE_PEEK_PARAM_TYPE();

if(IsImmString(paramType) || IsVarString(paramType))
{
OPCODE_READ_PARAM_STRING_LEN(text, 1); // one character is all we need
OPCODE_CONDITION_RESULT(text[0] != '\0');
return OR_CONTINUE;
}

auto value = OPCODE_READ_PARAM_ANY32();
OPCODE_CONDITION_RESULT(value != 0);
return OR_CONTINUE;
}
} Math;
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<ProjectGuid>{68A434CF-6390-4FDF-9A15-36A8A9ECEAA9}</ProjectGuid>
<IgnoreWarnCompileDuplicatedFilename>true</IgnoreWarnCompileDuplicatedFilename>
<Keyword>Win32Proj</Keyword>
<RootNamespace>IntOperations</RootNamespace>
<RootNamespace>Math</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
Expand Down Expand Up @@ -44,13 +44,13 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(SolutionDir).output\</OutDir>
<IntDir>$(ProjectDir).obj\$(Configuration)\</IntDir>
<TargetName>SA.IntOperations</TargetName>
<TargetName>SA.Math</TargetName>
<TargetExt>.cleo</TargetExt>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir).output\</OutDir>
<IntDir>$(ProjectDir).obj\$(Configuration)\</IntDir>
<TargetName>SA.IntOperations</TargetName>
<TargetName>SA.Math</TargetName>
<TargetExt>.cleo</TargetExt>
</PropertyGroup>
<PropertyGroup>
Expand Down Expand Up @@ -114,7 +114,11 @@ xcopy /Y "$(OutDir)$(TargetName).*" "$(GTA_SA_DIR)\cleo\cleo_plugins\"
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="IntOperations.cpp" />
<ClCompile Include="Math.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\cleo_sdk\CLEO.h" />
<ClInclude Include="..\..\cleo_sdk\CLEO_Utils.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
19 changes: 19 additions & 0 deletions cleo_plugins/Math/Math.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="Math.cpp" />
</ItemGroup>
<ItemGroup>
<Filter Include="cleo_sdk">
<UniqueIdentifier>{20ddb375-f549-46bb-814d-53e534880d23}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\cleo_sdk\CLEO.h">
<Filter>cleo_sdk</Filter>
</ClInclude>
<ClInclude Include="..\..\cleo_sdk\CLEO_Utils.h">
<Filter>cleo_sdk</Filter>
</ClInclude>
</ItemGroup>
</Project>
5 changes: 4 additions & 1 deletion cleo_sdk/CLEO_Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ namespace CLEO

OPCODE_CONDITION_RESULT(value) // set result
OPCODE_SKIP_PARAMS(count) // ignore X params

OPCODE_PEEK_PARAM_TYPE() // get param type without advancing the script

// reading opcode input arguments
OPCODE_READ_PARAM_BOOL()
Expand Down Expand Up @@ -458,11 +460,12 @@ namespace CLEO
}

#define OPCODE_SKIP_PARAMS(_count) CLEO_SkipOpcodeParams(thread, _count)
#define OPCODE_PEEK_PARAM_TYPE() thread->PeekDataType()

// macros for reading opcode input params. Performs type validation, throws error and suspends script if user provided invalid argument type
// TOD: add range checks for limited size types?

#define OPCODE_READ_PARAM_BOOL() _readParam(thread).bParam; \
#define OPCODE_READ_PARAM_BOOL() _readParam(thread).dwParam != false; \
if (!_paramWasInt()) { SHOW_ERROR("Input argument %s expected to be integer, got %s in script %s\nScript suspended.", GetParamInfo().c_str(), CLEO::ToKindStr(_lastParamType, _lastParamArrayType), CLEO::ScriptInfoStr(thread).c_str()); return thread->Suspend(); }

#define OPCODE_READ_PARAM_INT8() _readParam(thread).cParam; \
Expand Down
22 changes: 0 additions & 22 deletions source/CCustomOpcodeSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ namespace CLEO
OpcodeResult __stdcall opcode_0AE2(CRunningScript* thread); // get_random_car_in_sphere_no_save_recursive
OpcodeResult __stdcall opcode_0AE3(CRunningScript* thread); // get_random_object_in_sphere_no_save_recursive

OpcodeResult __stdcall opcode_0AEE(CRunningScript* thread); // pow
OpcodeResult __stdcall opcode_0AEF(CRunningScript* thread); // log
OpcodeResult __stdcall opcode_0DD5(CRunningScript* thread); // get_platform
// 2000 free slot
// 2001 free slot
Expand Down Expand Up @@ -246,8 +244,6 @@ namespace CLEO
CLEO_RegisterOpcode(0x0AE1, opcode_0AE1);
CLEO_RegisterOpcode(0x0AE2, opcode_0AE2);
CLEO_RegisterOpcode(0x0AE3, opcode_0AE3);
CLEO_RegisterOpcode(0x0AEE, opcode_0AEE);
CLEO_RegisterOpcode(0x0AEF, opcode_0AEF);

CLEO_RegisterOpcode(0x0DD5, opcode_0DD5); // get_platform

Expand Down Expand Up @@ -1516,24 +1512,6 @@ namespace CLEO
return OR_CONTINUE;
}

//0AEE=3,%3d% = %1d% exp %2d% //all floats
OpcodeResult __stdcall opcode_0AEE(CRunningScript *thread)
{
float base, arg;
*thread >> base >> arg;
*thread << (float)pow(base, arg);
return OR_CONTINUE;
}

//0AEF=3,%3d% = log %1d% base %2d% //all floats
OpcodeResult __stdcall opcode_0AEF(CRunningScript *thread)
{
float base, arg;
*thread >> arg >> base;
*thread << (float)(log(arg) / log(base));
return OR_CONTINUE;
}

//0DD5=1,%1d% = get_platform
OpcodeResult __stdcall opcode_0DD5(CRunningScript* thread)
{
Expand Down
Loading
Loading