Skip to content

Commit

Permalink
v1.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
JuniorDjjr authored Jan 15, 2021
1 parent 9ac5e59 commit 317b50b
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 81 deletions.
105 changes: 57 additions & 48 deletions CLEOPlus/CLEOPlus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#include "CTimer.h"
#include "rw/rpworld.h"
#include <set>

constexpr uint32_t CLEOPLUS_VERSION_INT = 0x01000500;
constexpr uint32_t CLEOPLUS_VERSION_INT = 0x01000600;

using namespace plugin;
using namespace std;
Expand Down Expand Up @@ -683,7 +683,7 @@ class CLEOPlus
CLEO_RegisterOpcode(0xEC3, SET_STRING_LOWER); // 0xEC3=1,set_string_lower %1s%
CLEO_RegisterOpcode(0xEC4, STRING_FIND); // 0xEC4=4,string_find %1d% %2s% %3s% store_to %4d%
CLEO_RegisterOpcode(0xEC5, CUT_STRING_AT); // 0xEC5=2,cut_string_at %1d% %2d%
CLEO_RegisterOpcode(0xEC6, IS_STRING_CHARACTER_AT); // 0xEC6=2,is_string_character_at %1d% %2d%
CLEO_RegisterOpcode(0xEC6, IS_STRING_CHARACTER_AT); // 0xEC6=3,is_string_character_at %1d% character %2d% index %2d%
CLEO_RegisterOpcode(0xEC8, GET_CHAR_RANDOM_SEED); // 0xEC8=2,get_char_random_seed %1d% store_to %2d%
CLEO_RegisterOpcode(0xEC9, GET_CAR_RANDOM_SEED); // 0xEC9=2,get_car_random_seed %1d% store_to %2d%
CLEO_RegisterOpcode(0xECA, GET_OBJECT_RANDOM_SEED); // 0xECA=2,get_object_random_seed %1d% store_to %2d%
Expand Down Expand Up @@ -888,8 +888,6 @@ class CLEOPlus
{
if (CPed* ped = pedsPool->GetAt(index))
{
PedExtended& xdata = extData.Get(ped);

// Call char process script event if invisible, because our ped render hook will not call it
if (ped->m_nPedState == 50) {
if (scriptEvents[ScriptEvent::List::CharProcess].size() > 0) {
Expand All @@ -898,35 +896,39 @@ class CLEOPlus
}
}

// Reset AI flags
xdata.aiFlagsIntValue = 0;

// Cache tasks
int activeTaskIndex = 0;
if (ped->m_pIntelligence)
PedExtended& xdata = extData.Get(ped);
if (&xdata != nullptr)
{
CTaskManager* taskMgr = &ped->m_pIntelligence->m_TaskMgr;
for (int i = 0; i < 5; i++)
// Reset AI flags
xdata.aiFlagsIntValue = 0;

// Cache tasks
int activeTaskIndex = 0;
if (ped->m_pIntelligence)
{
CTask* task = taskMgr->m_aPrimaryTasks[i];
while (task)
CTaskManager* taskMgr = &ped->m_pIntelligence->m_TaskMgr;
for (int i = 0; i < 5; i++)
{
CacheOnePedTask(ped, xdata, activeTaskIndex, task, false);
task = task->GetSubTask();
CTask* task = taskMgr->m_aPrimaryTasks[i];
while (task)
{
CacheOnePedTask(ped, xdata, activeTaskIndex, task, false);
task = task->GetSubTask();
}
}
}

for (int i = 0; i < 5; i++)
{
CTask* task = taskMgr->m_aSecondaryTasks[i];
while (task)
for (int i = 0; i < 5; i++)
{
CacheOnePedTask(ped, xdata, activeTaskIndex, task, true);
task = task->GetSubTask();
CTask* task = taskMgr->m_aSecondaryTasks[i];
while (task)
{
CacheOnePedTask(ped, xdata, activeTaskIndex, task, true);
task = task->GetSubTask();
}
}
}
if (activeTaskIndex < 31) xdata.activeTasks[activeTaskIndex] = -1; // set terminator
}
if (activeTaskIndex < 31) xdata.activeTasks[activeTaskIndex] = -1; // set terminator
}
}

Expand All @@ -940,13 +942,14 @@ class CLEOPlus
{
if (CPed* ped = pedsPool->GetAt(index))
{
PedExtended& xdata = extData.Get(ped);

// Reset last damage;
xdata.lastDamageEntity = nullptr;
xdata.lastDamageWeapon = 0;
xdata.lastDamagePart = 0;
xdata.lastDamageIntensity = 0.0f;
PedExtended &xdata = extData.Get(ped);
if (&xdata != nullptr) {
// Reset last damage;
xdata.lastDamageEntity = nullptr;
xdata.lastDamageWeapon = 0;
xdata.lastDamagePart = 0;
xdata.lastDamageIntensity = 0.0f;
}
}
}
// Reset vehicle data per frame
Expand All @@ -955,12 +958,14 @@ class CLEOPlus
{
if (CVehicle* vehicle = vehsPool->GetAt(index))
{
VehExtended& xdata = vehExtData.Get(vehicle);
VehExtended &xdata = vehExtData.Get(vehicle);

// Reset last damage;
xdata.lastDamagePed = nullptr;
xdata.lastDamageType = 0;
xdata.lastDamageIntensity = 0.0f;
if (&xdata) {
// Reset last damage;
xdata.lastDamagePed = nullptr;
xdata.lastDamageType = 0;
xdata.lastDamageIntensity = 0.0f;
}
}
}
controllerMode = ReadMemory<uint8_t>(0x47F399, false);
Expand Down Expand Up @@ -1044,7 +1049,7 @@ class CLEOPlus
// -- Render objects
if (ped->m_bIsVisible && ped->m_pRwObject)
{
if (xdata.renderObjects.size() > 0)
if (&xdata != nullptr && xdata.renderObjects.size() > 0)
{
for (RenderObject *renderObject : xdata.renderObjects)
{
Expand Down Expand Up @@ -1159,7 +1164,7 @@ class CLEOPlus
Events::pedDtorEvent.before += [](CPed *ped)
{
PedExtended &data = extData.Get(ped);
if (&data && data.renderObjects.size() > 0)
if (&data != nullptr && data.renderObjects.size() > 0)
{
DeleteAllRenderObjectsFromChar(data);
}
Expand Down Expand Up @@ -1242,11 +1247,13 @@ class CLEOPlus
CPedDamageResponseCalculator *damageCalculator = (CPedDamageResponseCalculator *)regs.ebp;
if (damageCalculator->m_fDamageFactor != 0.0f) {
CPed* ped = (CPed*)regs.esi;
PedExtended& data = extData.Get(ped);
data.lastDamageEntity = damageCalculator->m_pDamager;
data.lastDamageIntensity = damageCalculator->m_fDamageFactor;
data.lastDamageWeapon = damageCalculator->m_weaponType;
data.lastDamagePart = damageCalculator->m_pedPieceType;
PedExtended &data = extData.Get(ped);
if (&data != nullptr) {
data.lastDamageEntity = damageCalculator->m_pDamager;
data.lastDamageIntensity = damageCalculator->m_fDamageFactor;
data.lastDamageWeapon = damageCalculator->m_weaponType;
data.lastDamagePart = damageCalculator->m_pedPieceType;
}

if (scriptEvents[ScriptEvent::List::CharDamage].size() > 0) {
int ref = CPools::GetPedRef(ped);
Expand All @@ -1262,9 +1269,11 @@ class CLEOPlus
if (intensity != 0.0f) {
CVehicle *vehicle = (CVehicle *)regs.esi;
VehExtended &data = vehExtData.Get(vehicle);
data.lastDamagePed = (CEntity *)regs.edi;
data.lastDamageType = regs.ebx;
data.lastDamageIntensity = intensity;
if (&data != nullptr) {
data.lastDamagePed = (CEntity*)regs.edi;
data.lastDamageType = regs.ebx;
data.lastDamageIntensity = intensity;
}

if (scriptEvents[ScriptEvent::List::CarWeaponDamage].size() > 0) {
int ref = CPools::GetVehicleRef(vehicle);
Expand All @@ -1281,7 +1290,7 @@ class CLEOPlus
regs.ecx = *(uint32_t*)(regs.ebx + 0x534); //mov ecx, [ebx+534h]
CPed *ped = (CPed *)regs.ebx;
PedExtended &data = extData.Get(ped);
if (data.ignoreDamageAnims) {
if (&data != nullptr && data.ignoreDamageAnims) {
*(uintptr_t*)(regs.esp - 0x4) = 0x4B4019; // ret
}
});
Expand Down
36 changes: 19 additions & 17 deletions CLEOPlus/Intelligence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,17 @@ OpcodeResult WINAPI IS_CHAR_DOING_TASK_ID(CScriptThread* thread)
PedExtended &data = extData.Get(ped);
int taskId = CLEO_GetIntOpcodeParam(thread);

for (int i = 0; i < 32; ++i) {
int activeTaskId = data.activeTasks[i];
if (activeTaskId != -1) {
if (activeTaskId == taskId) {
bResult = true;
break;
if (&data != nullptr) {
for (int i = 0; i < 32; ++i) {
int activeTaskId = data.activeTasks[i];
if (activeTaskId != -1) {
if (activeTaskId == taskId) {
bResult = true;
break;
}
}
else break;
}
else break;
}
reinterpret_cast<CRunningScript*>(thread)->UpdateCompareFlag(bResult);
return OR_CONTINUE;
Expand All @@ -176,7 +178,7 @@ OpcodeResult WINAPI GET_CHAR_TASK_POINTER_BY_ID(CScriptThread* thread)

int activeTaskIndex = 0;
CTask* task;
if (ped->m_pIntelligence)
if (ped->m_pIntelligence && &data != nullptr)
{
CTaskManager* taskMgr = &ped->m_pIntelligence->m_TaskMgr;
for (int i = 0; i < 5; i++)
Expand Down Expand Up @@ -220,7 +222,7 @@ OpcodeResult WINAPI GET_CHAR_KILL_TARGET_CHAR(CScriptThread* thread)
CPed *ped = CPools::GetPed(CLEO_GetIntOpcodeParam(thread));
CEntity *entity = nullptr;
PedExtended &data = extData.Get(ped);
entity = data.killTargetPed;
if (&data != nullptr) entity = data.killTargetPed;
if (reinterpret_cast<int>(entity) == -1 && ped->IsPlayer()) {
entity = reinterpret_cast<CPlayerPed*>(ped)->m_pPlayerTargettedPed;
}
Expand All @@ -238,7 +240,7 @@ OpcodeResult WINAPI IS_CHAR_USING_GUN(CScriptThread* thread)
{
CPed *ped = CPools::GetPed(CLEO_GetIntOpcodeParam(thread));
PedExtended &xdata = extData.Get(ped);
reinterpret_cast<CRunningScript*>(thread)->UpdateCompareFlag(xdata.aiFlags.bUsingGun);
reinterpret_cast<CRunningScript*>(thread)->UpdateCompareFlag(&xdata != nullptr && xdata.aiFlags.bUsingGun);
return OR_CONTINUE;
}

Expand All @@ -247,16 +249,16 @@ OpcodeResult WINAPI IS_CHAR_FIGHTING(CScriptThread* thread)
{
CPed *ped = CPools::GetPed(CLEO_GetIntOpcodeParam(thread));
PedExtended &xdata = extData.Get(ped);
reinterpret_cast<CRunningScript*>(thread)->UpdateCompareFlag(xdata.aiFlags.bFighting);
reinterpret_cast<CRunningScript*>(thread)->UpdateCompareFlag(&xdata != nullptr && xdata.aiFlags.bFighting);
return OR_CONTINUE;
}

// 0E48=1,is_char_fallen_on_ground %1d%
OpcodeResult WINAPI IS_CHAR_FALLEN_ON_GROUND(CScriptThread* thread)
{
CPed *ped = CPools::GetPed(CLEO_GetIntOpcodeParam(thread));
PedExtended &xdata = extData.Get(ped);
reinterpret_cast<CRunningScript*>(thread)->UpdateCompareFlag(xdata.aiFlags.bFallenOnGround);
reinterpret_cast<CRunningScript*>(thread)->UpdateCompareFlag(&xdata != nullptr && xdata.aiFlags.bFallenOnGround);
return OR_CONTINUE;
}

Expand All @@ -265,7 +267,7 @@ OpcodeResult WINAPI IS_CHAR_ENTERING_ANY_CAR(CScriptThread* thread)
{
CPed *ped = CPools::GetPed(CLEO_GetIntOpcodeParam(thread));
PedExtended &xdata = extData.Get(ped);
reinterpret_cast<CRunningScript*>(thread)->UpdateCompareFlag(xdata.aiFlags.bEnteringAnyCar);
reinterpret_cast<CRunningScript*>(thread)->UpdateCompareFlag(&xdata != nullptr && xdata.aiFlags.bEnteringAnyCar);
return OR_CONTINUE;
}

Expand All @@ -274,7 +276,7 @@ OpcodeResult WINAPI IS_CHAR_EXITING_ANY_CAR(CScriptThread* thread)
{
CPed *ped = CPools::GetPed(CLEO_GetIntOpcodeParam(thread));
PedExtended &xdata = extData.Get(ped);
reinterpret_cast<CRunningScript*>(thread)->UpdateCompareFlag(xdata.aiFlags.bExitingAnyCar);
reinterpret_cast<CRunningScript*>(thread)->UpdateCompareFlag(&xdata != nullptr && xdata.aiFlags.bExitingAnyCar);
return OR_CONTINUE;
}

Expand All @@ -285,7 +287,7 @@ OpcodeResult WINAPI IS_CHAR_PLAYING_ANY_SCRIPT_ANIMATION(CScriptThread* thread)
CPed *ped = CPools::GetPed(CLEO_GetIntOpcodeParam(thread));
int includeAnims = CLEO_GetIntOpcodeParam(thread);
PedExtended &xdata = extData.Get(ped);
reinterpret_cast<CRunningScript*>(thread)->UpdateCompareFlag(CheckPlayingAnyAnim(xdata, includeAnims));
reinterpret_cast<CRunningScript*>(thread)->UpdateCompareFlag(&xdata != nullptr && CheckPlayingAnyAnim(xdata, includeAnims));
return OR_CONTINUE;
}

Expand All @@ -296,7 +298,7 @@ OpcodeResult WINAPI IS_CHAR_DOING_ANY_IMPORTANT_TASK(CScriptThread* thread)
CPed *ped = CPools::GetPed(CLEO_GetIntOpcodeParam(thread));
int includeAnims = CLEO_GetIntOpcodeParam(thread);
PedExtended &xdata = extData.Get(ped);
if (xdata.aiFlags.bRootTaskIsntImportant && !xdata.aiFlags.bKillingSomething) {
if (&xdata != nullptr && xdata.aiFlags.bRootTaskIsntImportant && !xdata.aiFlags.bKillingSomething) {
bResult = CheckPlayingAnyAnim(xdata, includeAnims);
}
reinterpret_cast<CRunningScript*>(thread)->UpdateCompareFlag(bResult);
Expand Down
47 changes: 34 additions & 13 deletions CLEOPlus/Misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1260,11 +1260,21 @@ OpcodeResult WINAPI GET_CHAR_DAMAGE_LAST_FRAME(CScriptThread* thread)
int ref = CLEO_GetIntOpcodeParam(thread);
CPed *ped = CPools::GetPed(ref);
PedExtended &data = extData.Get(ped);
CLEO_SetIntOpcodeParam(thread, (DWORD)data.lastDamageEntity);
CLEO_SetIntOpcodeParam(thread, data.lastDamageWeapon);
CLEO_SetIntOpcodeParam(thread, data.lastDamagePart);
CLEO_SetFloatOpcodeParam(thread, data.lastDamageIntensity);
if (data.lastDamageIntensity > 0.0f) bResult = true;
if (&data)
{
CLEO_SetIntOpcodeParam(thread, -1);
CLEO_SetIntOpcodeParam(thread, -1);
CLEO_SetIntOpcodeParam(thread, -1);
CLEO_SetFloatOpcodeParam(thread, 0.0f);
}
else
{
CLEO_SetIntOpcodeParam(thread, (DWORD)data.lastDamageEntity);
CLEO_SetIntOpcodeParam(thread, data.lastDamageWeapon);
CLEO_SetIntOpcodeParam(thread, data.lastDamagePart);
CLEO_SetFloatOpcodeParam(thread, data.lastDamageIntensity);
if (data.lastDamageIntensity > 0.0f) bResult = true;
}
reinterpret_cast<CRunningScript*>(thread)->UpdateCompareFlag(bResult);
return OR_CONTINUE;
}
Expand All @@ -1277,14 +1287,22 @@ OpcodeResult WINAPI GET_CAR_WEAPON_DAMAGE_LAST_FRAME(CScriptThread* thread)
VehExtended &data = vehExtData.Get(vehicle);

int pedReturn = -1;
if (data.lastDamagePed) {
pedReturn = CPools::GetPedRef((CPed*)data.lastDamagePed);

if (&data != nullptr) {
CLEO_SetIntOpcodeParam(thread, pedReturn);
CLEO_SetIntOpcodeParam(thread, -1);
CLEO_SetFloatOpcodeParam(thread, 0.0f);
}
if (data.lastDamageIntensity != 0.0f) bResult = true;
else {
if (data.lastDamagePed) {
pedReturn = CPools::GetPedRef((CPed*)data.lastDamagePed);
}
if (data.lastDamageIntensity != 0.0f) bResult = true;

CLEO_SetIntOpcodeParam(thread, pedReturn);
CLEO_SetIntOpcodeParam(thread, data.lastDamageType);
CLEO_SetFloatOpcodeParam(thread, data.lastDamageIntensity);
CLEO_SetIntOpcodeParam(thread, pedReturn);
CLEO_SetIntOpcodeParam(thread, data.lastDamageType);
CLEO_SetFloatOpcodeParam(thread, data.lastDamageIntensity);
}
reinterpret_cast<CRunningScript*>(thread)->UpdateCompareFlag(bResult);
return OR_CONTINUE;
}
Expand Down Expand Up @@ -1454,7 +1472,7 @@ OpcodeResult WINAPI STRING_FIND(CScriptThread* thread)
std::string str = CLEO_ReadStringPointerOpcodeParam(thread, bufferA, 128);
std::string strFind = CLEO_ReadStringPointerOpcodeParam(thread, bufferB, 128);

size_t found;
size_t found = 0;

if (mode == 0)
{
Expand Down Expand Up @@ -1577,7 +1595,10 @@ OpcodeResult WINAPI SET_CHAR_IGNORE_DAMAGE_ANIMS(CScriptThread* thread)
{
CPed *ped = CPools::GetPed(CLEO_GetIntOpcodeParam(thread));
PedExtended &data = extData.Get(ped);
data.ignoreDamageAnims = CLEO_GetIntOpcodeParam(thread) == 1;
bool set = CLEO_GetIntOpcodeParam(thread) == 1;
if (&data != nullptr) {
data.ignoreDamageAnims = set;
}
return OR_CONTINUE;
}

Expand Down
Loading

0 comments on commit 317b50b

Please sign in to comment.