Skip to content

Commit

Permalink
v1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
JuniorDjjr committed Nov 20, 2020
1 parent eabba1c commit fc7bdb9
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 52 deletions.
127 changes: 79 additions & 48 deletions CLEOPlus/CLEOPlus.cpp
Expand Up @@ -18,10 +18,13 @@
#include "rw/rpworld.h"
#include <set>

constexpr uint32_t CLEOPLUS_VERSION_INT = 0x01000300;

using namespace plugin;
using namespace std;
using namespace injector;


// -- Variables
int gameVersion = -1;
char bufferA[128] = { 0 };
Expand Down Expand Up @@ -427,6 +430,8 @@ OpcodeResult WINAPI LIST_REMOVE_STRING_VALUE(CScriptThread* thread);
OpcodeResult WINAPI LIST_REMOVE_INDEX_RANGE(CScriptThread* thread);
OpcodeResult WINAPI REVERSE_LIST(CScriptThread* thread);



class CLEOPlus
{
public:
Expand Down Expand Up @@ -924,41 +929,18 @@ class CLEOPlus
if (activeTaskIndex < 31) xdata.activeTasks[activeTaskIndex] = -1; // set terminator
}
}

};

afterGameProcess +=[]
Events::processScriptsEvent.after += []
{
if (!CTimer::m_UserPause && !CTimer::m_CodePause) {
pausedLastFrame = false;
}

// Update camera rotation disable.
if (disableCamControl)
{
// Disables it each frame to make it compatible with GTA V Hud.
for (int i = 0; i < 14; ++i)
{
patch::SetPointer(disableCamMoveAddresses[i], &fZero);
}
disabledCamControlLastFrame = true;
}
else if (disabledCamControlLastFrame)
{
// Get using address (to make it compatible with other mods)
for (int i = 0; i < 14; ++i)
{
patch::SetInt(disableCamMoveAddresses[i], (i > 4) ? defaultMouseAccelHorizontalAddress : defaultMouseAccelVerticalAddress);
}
disabledCamControlLastFrame = false;
}

// Reset ped data per frame
auto& pedsPool = CPools::ms_pPedPool;
auto &pedsPool = CPools::ms_pPedPool;
for (int index = 0; index < pedsPool->m_nSize; ++index)
{
if (CPed *ped = pedsPool->GetAt(index))
if (CPed* ped = pedsPool->GetAt(index))
{
PedExtended &xdata = extData.Get(ped);
PedExtended& xdata = extData.Get(ped);

// Reset last damage;
xdata.lastDamageEntity = nullptr;
Expand All @@ -967,14 +949,13 @@ class CLEOPlus
xdata.lastDamageIntensity = 0.0f;
}
}

// Reset vehicle data per frame
auto& vehsPool = CPools::ms_pVehiclePool;
for (int index = 0; index < vehsPool->m_nSize; ++index)
{
if (CVehicle *vehicle = vehsPool->GetAt(index))
if (CVehicle* vehicle = vehsPool->GetAt(index))
{
VehExtended &xdata = vehExtData.Get(vehicle);
VehExtended& xdata = vehExtData.Get(vehicle);

// Reset last damage;
xdata.lastDamagePed = nullptr;
Expand All @@ -985,6 +966,33 @@ class CLEOPlus
controllerMode = ReadMemory<uint8_t>(0x47F399, false);
};

afterGameProcess +=[]
{
if (!CTimer::m_UserPause && !CTimer::m_CodePause) {
pausedLastFrame = false;
}

// Update camera rotation disable.
if (disableCamControl)
{
// Disables it each frame to make it compatible with GTA V Hud.
for (int i = 0; i < 14; ++i)
{
patch::SetPointer(disableCamMoveAddresses[i], &fZero);
}
disabledCamControlLastFrame = true;
}
else if (disabledCamControlLastFrame)
{
// Get using address (to make it compatible with other mods)
for (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)
{
Expand Down Expand Up @@ -1092,7 +1100,7 @@ class CLEOPlus

}
};

// ----------------------------------------------------------------------------------------

startSaveGame += []
Expand Down Expand Up @@ -1206,36 +1214,44 @@ class CLEOPlus
};

// Bullet impact event
injector::MakeInline<0x73B5B0, 0x73B5B0 + 7>([](injector::reg_pack& regs)
patch::RedirectCall(0x73CD92, MyDoBulletImpact);
patch::RedirectCall(0x741199, MyDoBulletImpact);
patch::RedirectCall(0x7411DF, MyDoBulletImpact);
patch::RedirectCall(0x7412DF, MyDoBulletImpact);
patch::RedirectCall(0x741E30, MyDoBulletImpact);
/*injector::MakeInline<0x73B57C, 0x73B57C + 7>([](injector::reg_pack& regs)
{
regs.esi = *(uint32_t*)(regs.esp + 0x88 + 0x8); //mov esi, [esp+88h+_victim]
// not compatible with Bullet Mod and
regs.ebx = *(uint32_t*)(regs.esp + 0x90 + 0x4); //mov ebx, [esp+90h+owner]
CWeapon *weapon = (CWeapon *)regs.edi;
CPed *owner = (CPed *)regs.ebx;
CEntity *victim = (CEntity*)regs.esi;
CColPoint *colPoint = *(CColPoint**)(regs.esp + 0x88 + 0x14);
CEntity *victim = *(CEntity**)(regs.esp + 0x90 + 0x8);
CColPoint *colPoint = *(CColPoint**)(regs.esp + 0x90 + 0x14);
if (scriptEvents[ScriptEvent::List::BulletImpact].size() > 0) {
int ownerRef = -1;
if (owner) ownerRef = CPools::GetPedRef(owner);
for (auto scriptEvent : scriptEvents[ScriptEvent::List::BulletImpact]) scriptEvent->RunScriptEvent((DWORD)ownerRef, (DWORD)victim, (DWORD)weapon->m_nType, (DWORD)colPoint);
}
});
});*/

// Ped damage event
injector::MakeInline<0x4B3238, 0x4B3238 + 6>([](injector::reg_pack& regs)
{
regs.eax = *(uint32_t*)(regs.esi + 0x540); //mov eax, [esi+540h]
CPedDamageResponseCalculator *damageCalculator = (CPedDamageResponseCalculator *)regs.ebp;
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;

if (scriptEvents[ScriptEvent::List::CharDamage].size() > 0) {
int ref = CPools::GetPedRef(ped);
for (auto scriptEvent : scriptEvents[ScriptEvent::List::CharDamage]) scriptEvent->RunScriptEvent(ref);
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;

if (scriptEvents[ScriptEvent::List::CharDamage].size() > 0) {
int ref = CPools::GetPedRef(ped);
for (auto scriptEvent : scriptEvents[ScriptEvent::List::CharDamage]) scriptEvent->RunScriptEvent(ref);
}
}
});

Expand Down Expand Up @@ -1337,13 +1353,23 @@ class CLEOPlus
ClearMySprites(sprites[DrawEvent::AfterFade]);
textDrawer[DrawEvent::AfterFade].DrawPrints();

UpdateKeyPresses(); // It's better to update all keys and buttons after all game processing, to make it compatible with script events
// It's better to update all keys and buttons after all game processing, to make it compatible with script events
UpdateKeyPresses();
};


CLEO_AddScriptDeleteDelegate(ScriptDeleteEvent);
}

static void __fastcall MyDoBulletImpact(CWeapon* weapon, int i, CEntity* owner, CEntity* victim, CVector* startPoint, CVector* endPoint, CColPoint* colPoint, int a7)
{
if (scriptEvents[ScriptEvent::List::BulletImpact].size() > 0) {
for (auto scriptEvent : scriptEvents[ScriptEvent::List::BulletImpact]) scriptEvent->RunScriptEvent((DWORD)owner, (DWORD)victim, (DWORD)weapon->m_nType, (DWORD)colPoint);
}
weapon->DoBulletImpact(owner, victim, startPoint, endPoint, colPoint, a7);
return;
}

static void UpdateKeyPresses()
{

Expand Down Expand Up @@ -1389,3 +1415,8 @@ class CLEOPlus
}

} cLEOPlus;

extern "C" uint32_t __declspec(dllexport) GetCleoPlusVersion(CVehicle * vehicle)
{
return CLEOPLUS_VERSION_INT;
}
9 changes: 5 additions & 4 deletions CLEOPlus/Misc.cpp
Expand Up @@ -1261,7 +1261,7 @@ OpcodeResult WINAPI GET_CHAR_DAMAGE_LAST_FRAME(CScriptThread* thread)
CLEO_SetIntOpcodeParam(thread, data.lastDamageWeapon);
CLEO_SetIntOpcodeParam(thread, data.lastDamagePart);
CLEO_SetFloatOpcodeParam(thread, data.lastDamageIntensity);
if (data.lastDamageIntensity != 0) bResult = true;
if (data.lastDamageIntensity > 0.0f) bResult = true;
reinterpret_cast<CRunningScript*>(thread)->UpdateCompareFlag(bResult);
return OR_CONTINUE;
}
Expand Down Expand Up @@ -1363,16 +1363,17 @@ OpcodeResult WINAPI LOCATE_CAMERA_DISTANCE_TO_COORDINATES(CScriptThread* thread)
// 0xEBF=2,get_fx_system_pointer %1d% store_to %2d%
OpcodeResult WINAPI GET_FX_SYSTEM_POINTER(CScriptThread* thread)
{
bool bResult = false;
int handle = CLEO_GetIntOpcodeParam(thread);
if (handle >= 0) {
handle = CTheScripts::GetActualScriptThingIndex(handle, 1);
if (handle >= 0) {
CLEO_SetIntOpcodeParam(thread, (DWORD)ScriptEffectSystemArray[handle].m_pFxSystem);
bResult = true;
reinterpret_cast<CRunningScript*>(thread)->UpdateCompareFlag(true);
return OR_CONTINUE;
}
}
reinterpret_cast<CRunningScript*>(thread)->UpdateCompareFlag(bResult);
CLEO_SetIntOpcodeParam(thread, 0);
reinterpret_cast<CRunningScript*>(thread)->UpdateCompareFlag(false);
return OR_CONTINUE;
}

Expand Down

0 comments on commit fc7bdb9

Please sign in to comment.