Skip to content

Commit

Permalink
v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
JuniorDjjr authored Jun 19, 2022
1 parent 0677df3 commit 6c5581b
Show file tree
Hide file tree
Showing 10 changed files with 188 additions and 115 deletions.
64 changes: 22 additions & 42 deletions CLEOPlus/CLEOPlus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "rw/rpworld.h"
#include <set>

constexpr uint32_t CLEOPLUS_VERSION_INT = 0x01000900;
constexpr uint32_t CLEOPLUS_VERSION_INT = 0x01010000;

using namespace plugin;
using namespace std;
Expand Down Expand Up @@ -55,6 +55,7 @@ bool disableCamControl = false;
bool disabledCamControlLastFrame = false;
bool controllerMode = false;
bool pausedLastFrame = true;
bool isBuildingProcessPatched = false;
CSprite2d *radarBlipSprites;
bool keysPressedLastFrame[0xFF] = { false };
bool buttonsPressedLastFrame[2][20] = { false };
Expand Down Expand Up @@ -481,7 +482,7 @@ class CLEOPlus
}
else sampfuncsInstalled = false;

if (GetModuleHandleA("V_HUD_by_DK22Pac.asi")) {
if (GetModuleHandleA("V_HUD_by_DK22Pac.asi") || GetModuleHandleA("VHud.asi")) {
gtavhudInstalled = true;
}
else gtavhudInstalled = false;
Expand Down Expand Up @@ -713,7 +714,7 @@ class CLEOPlus
CLEO_RegisterOpcode(0xEF8, GET_MODEL_INFO); // 0xEF8=2,get_model_info %1d% store_to %2d%
CLEO_RegisterOpcode(0xEF9, GET_CAR_ANIMGROUP); // 0xEF9=2,get_car_animgroup %1d% store_to %2d%
CLEO_RegisterOpcode(0xEFA, GET_CHAR_FEAR); // 0xEFA=2,get_char_fear %1d% store_to %2d%
CLEO_RegisterOpcode(0xEFB, IS_CAR_CONVERTIBLE); // 0xEFB=1,is_car_double_convertible %1d%
CLEO_RegisterOpcode(0xEFB, IS_CAR_CONVERTIBLE); // 0xEFB=1,is_car_convertible %1d%
CLEO_RegisterOpcode(0xEFC, GET_CAR_VALUE); // 0xEFC=2,get_car_value %1d% store_to %2d%
CLEO_RegisterOpcode(0xEFD, GET_CAR_PEDALS); // 0xEFD=3,get_car_pedals %1d% gas_to %2d% break_to %3d%
CLEO_RegisterOpcode(0xEFE, GET_LOADED_LIBRARY); // 0xEFE=2,get_loaded_library %1d% store_to %2d%
Expand Down Expand Up @@ -752,10 +753,10 @@ class CLEOPlus
CLEO_RegisterOpcode(0xE1F, EASE); // 0E1F=4,ease %1d% mode %2d% way %3d% to %4d%
CLEO_RegisterOpcode(0xE27, GET_ANGLE_FROM_TWO_COORDS); // 0E27=5,get_angle_from_two_coords %1d% %2d% and %3d% %4d% to %5d%
CLEO_RegisterOpcode(0xE03, PERLIN_NOISE); // 0E03=2,perlin_noise %1d% store_to %2d%
CLEO_RegisterOpcode(0xE29, PERLIN_NOISE_FRACTAL); // 0E29=7,perlin_noise %1d% octaves %2d% frequency %3d% amplitude %4d% lacunarity %5d% persistence %6d% store_to %7d%
CLEO_RegisterOpcode(0xE29, PERLIN_NOISE_FRACTAL); // 0E29=6,perlin_noise %1d% frequency %2d% amplitude %3d% lacunarity %4d% persistence %5d% store_to %6d%
CLEO_RegisterOpcode(0xEF0, GET_COORD_FROM_ANGLED_DISTANCE); // 0EF0=6,get_coord_from_angled_distance %1d% %2d% angle %3d% dist %4d% store_to %5d% %6d%
CLEO_RegisterOpcode(0xEF1, PERLIN_NOISE_FRACTAL_2D); // 0EF1=8,perlin_noise_fractal_2d x %1d% y %2d% octaves %3d% frequency %4d% amplitude %5d% lacunarity %6d% persistence %7d% store_to %8d%
CLEO_RegisterOpcode(0xEF2, PERLIN_NOISE_FRACTAL_3D); // 0EF2=9,perlin_noise_fractal_3d x %1d% y %2d% z %3d% octaves %4d% frequency %5d% amplitude %6d% lacunarity %7d% persistence %8d% store_to %9d%
CLEO_RegisterOpcode(0xEF1, PERLIN_NOISE_FRACTAL_2D); // 0xEF1=7,perlin_noise_fractal_2d %1d% %2d% frequency %3d% amplitude %4d% lacunarity %5d% persistence %6d% store_to %7d%
CLEO_RegisterOpcode(0xEF2, PERLIN_NOISE_FRACTAL_3D); // 0xEF2=8,perlin_noise_fractal_3d %1d% %2d% %3d% frequency %4d% amplitude %5d% lacunarity %6d% persistence %7d% store_to %8d%
CLEO_RegisterOpcode(0xEF4, CLAMP_FLOAT); // 0EF4=4,clamp_float %1d% min %2d% max %3d% store_to %4d%
CLEO_RegisterOpcode(0xEF7, CLAMP_INT); // 0EF7=4,clamp_int %1d% min %2d% max %3d% store_to %4d%
CLEO_RegisterOpcode(0xEB3, CONVERT_DIRECTION_TO_QUAT); // 0xEB3=4,convert_direction_to_quat %1d% dir %2d% %3d% %4d%
Expand Down Expand Up @@ -889,7 +890,7 @@ class CLEOPlus
{
// Reset ped data per frame
auto& pedsPool = CPools::ms_pPedPool;
for (int index = 0; index < pedsPool->m_nSize; ++index)
for (unsigned int index = 0; index < pedsPool->m_nSize; ++index)
{
if (CPed* ped = pedsPool->GetAt(index))
{
Expand All @@ -912,7 +913,7 @@ class CLEOPlus
if (ped->m_pIntelligence)
{
CTaskManager* taskMgr = &ped->m_pIntelligence->m_TaskMgr;
for (int i = 0; i < 5; i++)
for (unsigned int i = 0; i < 5; i++)
{
CTask* task = taskMgr->m_aPrimaryTasks[i];
while (task)
Expand All @@ -922,7 +923,7 @@ class CLEOPlus
}
}

for (int i = 0; i < 5; i++)
for (unsigned int i = 0; i < 5; i++)
{
CTask* task = taskMgr->m_aSecondaryTasks[i];
while (task)
Expand All @@ -943,7 +944,7 @@ class CLEOPlus
{
// Reset ped data per frame
auto &pedsPool = CPools::ms_pPedPool;
for (int index = 0; index < pedsPool->m_nSize; ++index)
for (unsigned int index = 0; index < pedsPool->m_nSize; ++index)
{
if (CPed* ped = pedsPool->GetAt(index))
{
Expand All @@ -959,7 +960,7 @@ class CLEOPlus
}
// Reset vehicle data per frame
auto& vehsPool = CPools::ms_pVehiclePool;
for (int index = 0; index < vehsPool->m_nSize; ++index)
for (unsigned int index = 0; index < vehsPool->m_nSize; ++index)
{
if (CVehicle* vehicle = vehsPool->GetAt(index))
{
Expand All @@ -986,7 +987,7 @@ class CLEOPlus
if (disableCamControl)
{
// Disables it each frame to make it compatible with GTA V Hud.
for (int i = 0; i < 14; ++i)
for (unsigned int i = 0; i < 14; ++i)
{
patch::SetPointer(disableCamMoveAddresses[i], &fZero);
}
Expand All @@ -995,37 +996,16 @@ class CLEOPlus
else if (disabledCamControlLastFrame)
{
// Get using address (to make it compatible with other mods)
for (int i = 0; i < 14; ++i)
for (unsigned int i = 0; i < 14; ++i)
{
patch::SetInt(disableCamMoveAddresses[i], (i > 4) ? defaultMouseAccelHorizontalAddress : defaultMouseAccelVerticalAddress);
}
disabledCamControlLastFrame = false;
}
};

// EntityPreRender (caution, this is called A LOT)
injector::MakeInline<0x535FBE, 0x535FBE + 5>([](injector::reg_pack& regs)
{
CEntity *entity = (CEntity *)regs.esi;
if (entity->m_nType == eEntityType::ENTITY_TYPE_BUILDING)
{
if (scriptEvents[ScriptEvent::List::BuildingProcess].size() > 0)
{
for (auto scriptEvent : scriptEvents[ScriptEvent::List::BuildingProcess]) scriptEvent->RunScriptEvent((DWORD)entity);
}
}
else if (entity->m_nType == eEntityType::ENTITY_TYPE_OBJECT)
{
if (scriptEvents[ScriptEvent::List::ObjectProcess].size() > 0)
{
CObject *object = reinterpret_cast<CObject*>(entity);
int ref = CPools::GetObjectRef(object);
for (auto scriptEvent : scriptEvents[ScriptEvent::List::ObjectProcess]) scriptEvent->RunScriptEvent(ref);
}
}
regs.ebx = regs.eax; //mov ebx, eax
regs.eax = *(uint8_t*)(regs.edi + 0xD); //mov al, [edi+0Dh]
});
// EntityPreRender
// PATCH MOVED TO: PatchBuildingProcessIfNeeded Events.cpp

// VehiclePreRender
vehiclePreRenderEvent +=[](CVehicle *vehicle)
Expand Down Expand Up @@ -1127,7 +1107,7 @@ class CLEOPlus
// Fixes corrupted old saves with deleted LOD objects
loadingEventAfterPoolsLoaded.before += []
{
for (int i = 0; i < sizeScriptConnectLodsObjects; ++i)
for (unsigned int i = 0; i < sizeScriptConnectLodsObjects; ++i)
{
if (CTheScripts__ScriptConnectLodsObjects[i] != -1)
{
Expand Down Expand Up @@ -1164,7 +1144,7 @@ class CLEOPlus
CStreaming::RemoveModel(id);
}
//specialCharacterModelsUsed.clear(); // don't clear it, we use this list to reuse IDs in GET_MODEL_DOESNT_EXIST_IN_RANGE
for (int i = 0; i < DrawEvent::TOTAL_DRAW_EVENT; ++i) {
for (unsigned int i = 0; i < DrawEvent::TOTAL_DRAW_EVENT; ++i) {
ClearMySprites(sprites[i]);
textDrawer[i].ClearAll();
}
Expand Down Expand Up @@ -1228,7 +1208,7 @@ class CLEOPlus
if (scriptEvents[ScriptEvent::List::ObjectDelete].size() > 0) {
for (auto scriptEvent : scriptEvents[ScriptEvent::List::ObjectDelete]) scriptEvent->RunScriptEvent(ref);
}
for (int i = 0; i < sizeScriptConnectLodsObjects; ++i)
for (unsigned int i = 0; i < sizeScriptConnectLodsObjects; ++i)
{
if (CTheScripts__ScriptConnectLodsObjects[i] == ref) CTheScripts__ScriptConnectLodsObjects[i] = -1;
}
Expand Down Expand Up @@ -1446,16 +1426,16 @@ class CLEOPlus

// Update keys pressed
memset(keysPressedLastFrame, 0, sizeof(keysPressedLastFrame));
for (int vk = 0x01; vk < 0xFF; ++vk)
for (unsigned int vk = 0x01; vk < 0xFF; ++vk)
{
keysPressedLastFrame[vk] = ((GetKeyState(vk) & 0x8000) != 0);
}

// Update buttons pressed, and control disable
memset(buttonsPressedLastFrame, 0, sizeof(buttonsPressedLastFrame));
for (int pad = 0; pad < 2; ++pad)
for (unsigned int pad = 0; pad < 2; ++pad)
{
for (int id = 0; id < 20; ++id)
for (unsigned int id = 0; id < 20; ++id)
{
// There is old state, but isn't array, and also this function may be changed by some crazy script
buttonsPressedLastFrame[pad][id] = reinterpret_cast<CRunningScript*>(0)->GetPadState(pad, id);
Expand Down
4 changes: 2 additions & 2 deletions CLEOPlus/CLEOPlus.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='GTASA Release|Win32'">
<OutDir>G:\GTA SA The Modded Edition\CLEO\</OutDir>
<OutDir>G:\GTA SA\cleo\</OutDir>
<IntDir>$(ProjectDir).obj\GTASA\Release\</IntDir>
<TargetName>CLEO+</TargetName>
<TargetExt>.cleo</TargetExt>
<IncludePath>$(VC_IncludePath);$(WindowsSDK_IncludePath);E:\Documents\Para GTA\plugin-sdk-2020\shared;E:\Documents\Para GTA\plugin-sdk-2020\plugin_sa\game_sa</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='GTASA zDebug|Win32'">
<OutDir>G:\GTA SA The Modded Edition\CLEO\</OutDir>
<OutDir>G:\GTA SA\cleo\</OutDir>
<IntDir>$(ProjectDir).obj\GTASA\Debug\</IntDir>
<TargetName>CLEO+</TargetName>
<TargetExt>.cleo</TargetExt>
Expand Down
47 changes: 41 additions & 6 deletions CLEOPlus/Events.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#include "OpcodesCommon.h"
#include "Events.h"
#include "CMenuManager.h"
#include "..\injector\assembly.hpp"

vector<ScriptEvent*> scriptEvents[ScriptEvent::TOTAL_SCRIPT_EVENTS];
extern bool pausedLastFrame;
extern bool isBuildingProcessPatched;

void ScriptEvent::ClearAllForScript(CRunningScript* script)
{
for (int i = 0; i < ScriptEvent::TOTAL_SCRIPT_EVENTS; ++i)
for (unsigned int i = 0; i < ScriptEvent::TOTAL_SCRIPT_EVENTS; ++i)
{
for (vector<ScriptEvent*>::iterator it = scriptEvents[i].begin(); it != scriptEvents[i].end();)
{
Expand All @@ -30,7 +32,7 @@ void ScriptEvent::ClearForScriptLabelAndVar(vector<ScriptEvent*> &scriptEvents,
if (scriptEvent->script == script && scriptEvent->eventScriptIP == label)
{
bool ok = true;
for (int i = 0; i < 4; ++i)
for (unsigned int i = 0; i < 4; ++i)
{
if (scriptEvent->varPointer[i] == 0) break;
if (scriptEvent->varPointer[i] != varPointer[i])
Expand All @@ -51,11 +53,11 @@ void ScriptEvent::ClearForScriptLabelAndVar(vector<ScriptEvent*> &scriptEvents,

void ScriptEvent::ClearAllScriptEvents()
{
for (int i = 0; i < ScriptEvent::TOTAL_SCRIPT_EVENTS; ++i)
for (unsigned int i = 0; i < ScriptEvent::TOTAL_SCRIPT_EVENTS; ++i)
{
for (auto& scriptEvent : scriptEvents[i]) delete scriptEvent;
}
for (int i = 0; i < ScriptEvent::TOTAL_SCRIPT_EVENTS; ++i)
for (unsigned int i = 0; i < ScriptEvent::TOTAL_SCRIPT_EVENTS; ++i)
{
scriptEvents[i].clear();
}
Expand Down Expand Up @@ -108,7 +110,7 @@ void AddEvent(CScriptThread* thread, vector<ScriptEvent*> &scriptEventList, int
eventStruct->script = reinterpret_cast<CRunningScript*>(thread);
eventStruct->eventScriptIP = label;

for (int i = 0; i < 4; ++i)
for (unsigned int i = 0; i < 4; ++i)
{
uintptr_t pointer = 0;
if (i < args)
Expand All @@ -123,7 +125,7 @@ void AddEvent(CScriptThread* thread, vector<ScriptEvent*> &scriptEventList, int
else
{
uintptr_t vars[4];
for (int i = 0; i < 4; ++i)
for (unsigned int i = 0; i < 4; ++i)
{
uintptr_t pointer = 0;
if (i < args)
Expand All @@ -138,6 +140,37 @@ void AddEvent(CScriptThread* thread, vector<ScriptEvent*> &scriptEventList, int
return;
}

// This is called A LOT, so patch if only if needed. Note: this will also be called when turning off the event, it's fine.
void PatchBuildingProcessIfNeeded()
{
if (!isBuildingProcessPatched)
{
injector::MakeInline<0x535FBE, 0x535FBE + 5>([](injector::reg_pack& regs)
{
CEntity* entity = (CEntity*)regs.esi;
if (entity->m_nType == eEntityType::ENTITY_TYPE_BUILDING)
{
if (scriptEvents[ScriptEvent::List::BuildingProcess].size() > 0)
{
for (auto scriptEvent : scriptEvents[ScriptEvent::List::BuildingProcess]) scriptEvent->RunScriptEvent((DWORD)entity);
}
}
else if (entity->m_nType == eEntityType::ENTITY_TYPE_OBJECT)
{
if (scriptEvents[ScriptEvent::List::ObjectProcess].size() > 0)
{
CObject* object = reinterpret_cast<CObject*>(entity);
int ref = CPools::GetObjectRef(object);
for (auto scriptEvent : scriptEvents[ScriptEvent::List::ObjectProcess]) scriptEvent->RunScriptEvent(ref);
}
}
regs.ebx = regs.eax; //mov ebx, eax
regs.eax = *(uint8_t*)(regs.edi + 0xD); //mov al, [edi+0Dh]
});
isBuildingProcessPatched = true;
}
}

OpcodeResult WINAPI RETURN_SCRIPT_EVENT(CScriptThread* thread)
{
return OR_INTERRUPT;
Expand Down Expand Up @@ -206,12 +239,14 @@ OpcodeResult WINAPI SET_SCRIPT_EVENT_CAR_PROCESS(CScriptThread* thread)
OpcodeResult WINAPI SET_SCRIPT_EVENT_OBJECT_PROCESS(CScriptThread* thread)
{
AddEvent(thread, scriptEvents[ScriptEvent::List::ObjectProcess]);
PatchBuildingProcessIfNeeded();
return OR_CONTINUE;
}

OpcodeResult WINAPI SET_SCRIPT_EVENT_BUILDING_PROCESS(CScriptThread* thread)
{
AddEvent(thread, scriptEvents[ScriptEvent::List::BuildingProcess]);
PatchBuildingProcessIfNeeded();
return OR_CONTINUE;
}

Expand Down
18 changes: 9 additions & 9 deletions CLEOPlus/ExtendedEntityVars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ OpcodeResult WINAPI INIT_EXTENDED_CHAR_VARS(CScriptThread* thread)
if (&xdata != nullptr && totalVars > 0)
{
if (findId == 2949658545) // "AUTO"
findId = (int)thread;
findId = (uint32_t)thread;

ExtendedVars *extVars = FindExtendedVarsFromId(xdata.extendedVarsList, findId);
if (extVars)
Expand Down Expand Up @@ -146,7 +146,7 @@ OpcodeResult WINAPI SET_EXTENDED_CHAR_VAR(CScriptThread* thread)
if (&xdata && varId >= 0)
{
if (findId == 2949658545) // "AUTO"
findId = (int)thread;
findId = (uint32_t)thread;

ExtendedVars *extVars = FindExtendedVarsFromId(xdata.extendedVarsList, findId);
if (extVars)
Expand All @@ -173,7 +173,7 @@ OpcodeResult WINAPI GET_EXTENDED_CHAR_VAR(CScriptThread* thread)
if (&xdata && varId >= 0)
{
if (findId == 2949658545) // "AUTO"
findId = (int)thread;
findId = (uint32_t)thread;

ExtendedVars *extVars = FindExtendedVarsFromId(xdata.extendedVarsList, findId);
if (extVars)
Expand Down Expand Up @@ -203,7 +203,7 @@ OpcodeResult WINAPI INIT_EXTENDED_CAR_VARS(CScriptThread* thread)
if (&xdata != nullptr && totalVars > 0)
{
if (findId == 2949658545) // "AUTO"
findId = (int)thread;
findId = (uint32_t)thread;

ExtendedVars *extVars = FindExtendedVarsFromId(xdata.extendedVarsList, findId);
if (extVars)
Expand Down Expand Up @@ -234,7 +234,7 @@ OpcodeResult WINAPI SET_EXTENDED_CAR_VAR(CScriptThread* thread)
if (&xdata && varId >= 0)
{
if (findId == 2949658545) // "AUTO"
findId = (int)thread;
findId = (uint32_t)thread;

ExtendedVars *extVars = FindExtendedVarsFromId(xdata.extendedVarsList, findId);
if (extVars)
Expand All @@ -261,7 +261,7 @@ OpcodeResult WINAPI GET_EXTENDED_CAR_VAR(CScriptThread* thread)
if (&xdata && varId >= 0)
{
if (findId == 2949658545) // "AUTO"
findId = (int)thread;
findId = (uint32_t)thread;

ExtendedVars *extVars = FindExtendedVarsFromId(xdata.extendedVarsList, findId);
if (extVars)
Expand Down Expand Up @@ -292,7 +292,7 @@ OpcodeResult WINAPI INIT_EXTENDED_OBJECT_VARS(CScriptThread* thread)
if (&xdata != nullptr && totalVars > 0)
{
if (findId == 2949658545) // "AUTO"
findId = (int)thread;
findId = (uint32_t)thread;

ExtendedVars *extVars = FindExtendedVarsFromId(xdata.extendedVarsList, findId);
if (extVars)
Expand Down Expand Up @@ -323,7 +323,7 @@ OpcodeResult WINAPI SET_EXTENDED_OBJECT_VAR(CScriptThread* thread)
if (&xdata && varId >= 0)
{
if (findId == 2949658545) // "AUTO"
findId = (int)thread;
findId = (uint32_t)thread;

ExtendedVars *extVars = FindExtendedVarsFromId(xdata.extendedVarsList, findId);
if (extVars)
Expand Down Expand Up @@ -351,7 +351,7 @@ OpcodeResult WINAPI GET_EXTENDED_OBJECT_VAR(CScriptThread* thread)
if (&xdata && varId >= 0)
{
if (findId == 2949658545) // "AUTO"
findId = (int)thread;
findId = (uint32_t)thread;

ExtendedVars *extVars = FindExtendedVarsFromId(xdata.extendedVarsList, findId);
if (extVars)
Expand Down
Loading

0 comments on commit 6c5581b

Please sign in to comment.