Skip to content

Commit

Permalink
Merge pull request #13 from cleolibrary/develop
Browse files Browse the repository at this point in the history
Switch to plugin-sdk on production
  • Loading branch information
x87 authored May 1, 2017
2 parents c731ec5 + 3aa368b commit 07df664
Show file tree
Hide file tree
Showing 10 changed files with 434 additions and 84 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*.VC.db
*.VC.opendb
*.asi
*.dll
*.pdb
Expand Down
108 changes: 52 additions & 56 deletions CLEO4/CCustomOpcodeSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,17 +334,17 @@ namespace CLEO
inline CRunningScript& operator>>(CRunningScript& thread, CVector& vec)
{
GetScriptParams(&thread, 3);
vec.fX = opcodeParams[0].fParam;
vec.fY = opcodeParams[1].fParam;
vec.fZ = opcodeParams[2].fParam;
vec.x = opcodeParams[0].fParam;
vec.y = opcodeParams[1].fParam;
vec.z = opcodeParams[2].fParam;
return thread;
}

inline CRunningScript& operator<<(CRunningScript& thread, const CVector& vec)
{
opcodeParams[0].fParam = vec.fX;
opcodeParams[1].fParam = vec.fY;
opcodeParams[2].fParam = vec.fZ;
opcodeParams[0].fParam = vec.x;
opcodeParams[1].fParam = vec.y;
opcodeParams[2].fParam = vec.z;
SetScriptParams(&thread, 3);
return thread;
}
Expand Down Expand Up @@ -811,8 +811,10 @@ namespace CLEO
prevScmFunctionId(reinterpret_cast<CCustomScript*>(thread)->GetScmFunction()), retnAddress(thread->GetBytePointer())
{
auto cs = reinterpret_cast<CCustomScript*>(thread);

auto scope = cs->IsMission() ? missionLocals : cs->LocalVar;
std::copy(scope, scope + 32, savedTls);

SCRIPT_VAR fill_val; fill_val.dwParam = 0;

// CLEO 3 didnt initialise local storage, so dont do it if we're processing a CLEO 3 script in case the storage is used
Expand Down Expand Up @@ -1016,7 +1018,7 @@ namespace CLEO
{
DWORD handle;
*thread >> handle;
*thread << GetPedPool().GetAt(handle);
*thread << GetPedPool().AtHandle(handle);
return OR_CONTINUE;
}

Expand All @@ -1025,7 +1027,7 @@ namespace CLEO
{
DWORD handle;
*thread >> handle;
*thread << GetVehiclePool().GetAt(handle);
*thread << GetVehiclePool().AtHandle(handle);
return OR_CONTINUE;
}

Expand All @@ -1034,7 +1036,7 @@ namespace CLEO
{
DWORD handle;
*thread >> handle;
*thread << GetObjectPool().GetAt(handle);
*thread << GetObjectPool().AtHandle(handle);
return OR_CONTINUE;
}

Expand Down Expand Up @@ -1644,24 +1646,24 @@ namespace CLEO
{
DWORD actor;
*thread >> actor;
auto pPlayerPed = GetPedPool().GetAt(actor);
auto pPlayerPed = GetPedPool().AtHandle(actor);
CPedIntelligence * pedintel;
if(pPlayerPed && (pedintel = pPlayerPed->GetPedIntelligence()))
if(pPlayerPed && (pedintel = pPlayerPed->m_pIntelligence))
{
CVehicle * pVehicle = nullptr;
for(int i=0; i<NUM_SCAN_ENTITIES; i++)
{
pVehicle = pedintel->m_VehicleScanner.m_pEntities[i];
if(pVehicle && pVehicle->GetOwner() != 2 && !pVehicle->m_nVehicleFlags.bFadeOut)
pVehicle = (CVehicle*) pedintel->m_vehicleScanner.m_apEntities[i];
if(pVehicle && pVehicle->m_nCreatedBy != 2 && !pVehicle->m_nFlags.bFadeOut)
break;
pVehicle = nullptr;
}

CPed * pPed = nullptr;
for(int i=0; i<NUM_SCAN_ENTITIES; i++)
{
pPed = pedintel->m_PedScanner.m_pEntities[i];
if(pPed && pPed != pPlayerPed && pPed->GetOwner() == 1 && !pPed->GetPedFlags().bFadeOut)
pPed = (CPed*) pedintel->m_pedScanner.m_apEntities[i];
if(pPed && pPed != pPlayerPed && (pPed->m_dwUsageType & 0xFF) == 1 && !pPed->m_nPedFlags.bFadeOut)
break;
pPed = nullptr;
}
Expand All @@ -1677,12 +1679,12 @@ namespace CLEO
{
// steam offset is different, so get it manually for now
CGameVersionManager& gvm = GetInstance().VersionManager;
DWORD hMarker = gvm.GetGameVersion() != GV_STEAM ? MenuManager->GetWaypointHandle() : *((DWORD*)0xC3312C);
DWORD hMarker = gvm.GetGameVersion() != GV_STEAM ? MenuManager->m_nTargetBlipIndex : *((DWORD*)0xC3312C);
CMarker *pMarker;
if(hMarker && (pMarker = &RadarBlips[LOWORD(hMarker)]) && /*pMarker->m_nPoolIndex == HIWORD(hMarker) && */pMarker->m_nBlipDisplayFlag)
{
CVector coords(pMarker->m_vCoords);
coords.fZ = FindGroundZ(coords.fX, coords.fY);
CVector coords(pMarker->m_vPosition);
coords.z = FindGroundZ(coords.x, coords.y);
*thread << coords;
SetScriptCondResult(thread, true);
}
Expand All @@ -1700,7 +1702,7 @@ namespace CLEO
{
DWORD hVehicle;
*thread >> hVehicle;
auto id = reinterpret_cast<CVehicleModelInfo*>(Models[GetVehiclePool().GetAt(hVehicle)->GetModelIndex()])->vehicleHandlingID;
auto id = reinterpret_cast<CVehicleModelInfo*>(Models[GetVehiclePool().AtHandle(hVehicle)->m_wModelIndex])->m_wHandlingIndex;
*thread << Handling->Automobile[id].m_Transmission.ucNumberOfGears;
return OR_CONTINUE;
}
Expand All @@ -1710,7 +1712,7 @@ namespace CLEO
{
DWORD hVehicle;
*thread >> hVehicle;
*thread << GetVehiclePool().GetAt(hVehicle)->m_nCurrentGear;
*thread << GetVehiclePool().AtHandle(hVehicle)->m_nCurrentGear;
return OR_CONTINUE;
}

Expand Down Expand Up @@ -1760,7 +1762,7 @@ namespace CLEO
{
DWORD hVehicle;
*thread >> hVehicle;
SetScriptCondResult(thread, GetVehiclePool().GetAt(hVehicle)->m_nVehicleFlags.bSirenOrAlarm);
SetScriptCondResult(thread, GetVehiclePool().AtHandle(hVehicle)->m_nFlags.bSirenOrAlarm);
return OR_CONTINUE;
}

Expand All @@ -1769,7 +1771,7 @@ namespace CLEO
{
DWORD hVehicle;
*thread >> hVehicle;
SetScriptCondResult(thread, GetVehiclePool().GetAt(hVehicle)->m_nVehicleFlags.bEngineOn);
SetScriptCondResult(thread, GetVehiclePool().AtHandle(hVehicle)->m_nFlags.bEngineOn);
return OR_CONTINUE;
}

Expand All @@ -1779,8 +1781,8 @@ namespace CLEO
DWORD hVehicle,
state;
*thread >> hVehicle >> state;
auto veh = GetVehiclePool().GetAt(hVehicle);
veh->m_nVehicleFlags.bEngineOn = state != false;
auto veh = GetVehiclePool().AtHandle(hVehicle);
veh->m_nFlags.bEngineOn = state != false;
return OR_CONTINUE;
}

Expand Down Expand Up @@ -1819,7 +1821,7 @@ namespace CLEO
CAudioStream *stream;
DWORD handle;
*thread >> stream >> handle;
if(stream) stream->Link(GetObjectPool().GetAt(handle));
if(stream) stream->Link(GetObjectPool().AtHandle(handle));
return OR_CONTINUE;
}

Expand All @@ -1829,7 +1831,7 @@ namespace CLEO
CAudioStream *stream;
DWORD handle;
*thread >> stream >> handle;
if(stream) stream->Link(GetPedPool().GetAt(handle));
if(stream) stream->Link(GetPedPool().AtHandle(handle));
return OR_CONTINUE;
}

Expand All @@ -1839,7 +1841,7 @@ namespace CLEO
CAudioStream *stream;
DWORD handle;
*thread >> stream >> handle;
if(stream) stream->Link(GetVehiclePool().GetAt(handle));
if(stream) stream->Link(GetVehiclePool().AtHandle(handle));
return OR_CONTINUE;
}

Expand Down Expand Up @@ -1980,9 +1982,9 @@ namespace CLEO
DWORD playerId;
*thread >> playerId;
auto pPlayerPed = GetPlayerPed(playerId);
auto pTargetEntity = pPlayerPed->GetWeaponTarget();
if(!pTargetEntity) pTargetEntity = pPlayerPed->GetManualWeaponTarget();
if(pTargetEntity && pTargetEntity->IsPed())
auto pTargetEntity = GetWeaponTarget(pPlayerPed);
if(!pTargetEntity) pTargetEntity = (CEntity*) pPlayerPed->m_pPlayerTargettedPed;
if(pTargetEntity && pTargetEntity->m_nType == ENTITY_TYPE_PED)
{
*thread << GetPedPool().GetIndex(reinterpret_cast<CPed*>(pTargetEntity));
SetScriptCondResult(thread, true);
Expand Down Expand Up @@ -2150,7 +2152,7 @@ namespace CLEO
auto model = reinterpret_cast<CVehicleModelInfo*>(Models[mi]);
if (*thread->GetBytePointer() >= 1 && *thread->GetBytePointer() <= 8) *thread >> buf;
else buf = (char *)GetScriptParamPointer(thread);
memcpy(buf, model->Name, 8);
memcpy(buf, model->m_szGameName, 8);
return OR_CONTINUE;
}

Expand All @@ -2167,7 +2169,7 @@ namespace CLEO
DWORD mi;
*thread >> mi;
auto model = reinterpret_cast<CVehicleModelInfo*>(Models[mi]);
if(model->VehicleType != VEHICLE_TYPE_TRAIN && model->VehicleType != VEHICLE_TYPE_UNKNOWN) SpawnCar(mi);
if(model->m_dwType != VEHICLE_TYPE_TRAIN && model->m_dwType != VEHICLE_TYPE_UNKNOWN) SpawnCar(mi);
return OR_CONTINUE;
}

Expand All @@ -2176,9 +2178,9 @@ namespace CLEO
{
const char *gxt = readString(thread);
if(*thread->GetBytePointer() >= 1 && *thread->GetBytePointer() <= 8)
*thread << CText__locate(gameTexts, 0, gxt);
*thread << GetInstance().TextManager.Get(gxt);
else
strcpy((char *)GetScriptParamPointer(thread), CText__locate(gameTexts, 0, gxt));
strcpy((char *)GetScriptParamPointer(thread), GetInstance().TextManager.Get(gxt));
return OR_CONTINUE;
}

Expand Down Expand Up @@ -2208,7 +2210,7 @@ namespace CLEO
float radius;
DWORD next, pass_deads;
static DWORD stat_last_found = 0;
auto pool = GetPedPool();
auto& pool = GetPedPool();
*thread >> center >> radius >> next >> pass_deads;

DWORD& last_found = reinterpret_cast<CCustomScript *>(thread)->IsCustom() ?
Expand All @@ -2217,16 +2219,14 @@ namespace CLEO

if (!next) last_found = 0;

for(int index = last_found; index < pool.GetSize(); ++index)
for(int index = last_found; index < pool.m_Size; ++index)
{
if(!pool.IsValid(index)) continue;

if(auto obj = pool.Get(index))
if(auto obj = pool.GetAt(index))
{
if(obj->IsPlayer() || (pass_deads && !obj->IsAvailable())/* || obj->GetOwner() == 2*/ || obj->PedFlags.bFadeOut)
if(obj->IsPlayer() || (pass_deads && !IsAvailable(obj))/* || obj->GetOwner() == 2*/ || obj->m_nPedFlags.bFadeOut)
continue;

if((obj->GetPos() - center).Length() <= radius)
if((obj->GetPosition() - center).Magnitude() <= radius)
{
last_found = index + 1; // on next opcode call start search from next index
//if(last_found >= (unsigned)pool.GetSize()) last_found = 0;
Expand All @@ -2253,7 +2253,7 @@ namespace CLEO
DWORD next, pass_wrecked;
static DWORD stat_last_found = 0;

auto pool = GetVehiclePool();
auto& pool = GetVehiclePool();
*thread >> center >> radius >> next >> pass_wrecked;

DWORD& last_found = reinterpret_cast<CCustomScript*>(thread)->IsCustom() ?
Expand All @@ -2262,16 +2262,14 @@ namespace CLEO

if (!next) last_found = 0;

for (int index = last_found; index < pool.GetSize(); ++index)
for (int index = last_found; index < pool.m_Size; ++index)
{
if (!pool.IsValid(index)) continue;

if(auto obj = pool.Get(index))
if(auto obj = pool.GetAt(index))
{
if((pass_wrecked && obj->IsWrecked()) || (/*obj->GetOwner() == 2 ||*/ obj->m_nVehicleFlags.bFadeOut))
if((pass_wrecked && IsWrecked(obj)) || (/*obj->GetOwner() == 2 ||*/ obj->m_nFlags.bFadeOut))
continue;

if((obj->GetPos() - center).Length() <= radius)
if((obj->GetPosition() - center).Magnitude() <= radius)
{
last_found = index + 1; // on next opcode call start search from next index
//if(last_found >= (unsigned)pool.GetSize()) last_found = 0;
Expand All @@ -2296,23 +2294,21 @@ namespace CLEO
float radius;
DWORD next;
static DWORD stat_last_found = 0;
auto pool = GetObjectPool();
auto& pool = GetObjectPool();
*thread >> center >> radius >> next;

auto cs = reinterpret_cast<CCustomScript *>(thread);
DWORD& last_found = cs->IsCustom() ? cs->GetLastSearchObject() : stat_last_found;

if(!next) last_found = 0;

for(int index = last_found; index < pool.GetSize(); ++index)
for(int index = last_found; index < pool.m_Size; ++index)
{
if (!pool.IsValid(index)) continue; // empty slot

if(auto obj = pool.Get(index))
if(auto obj = pool.GetAt(index))
{
if(obj->GetFlags().bFadeOut) continue;
if(obj->m_nObjectFlags.bFadingIn) continue; // this is actually .bFadingOut

if((obj->GetPos() - center).Length() <= radius)
if((obj->GetPosition() - center).Magnitude() <= radius)
{
last_found = index + 1; // on next opcode call start search from next index
//if(last_found >= (unsigned)pool.GetSize()) last_found = 0;
Expand Down Expand Up @@ -2681,4 +2677,4 @@ extern "C"
{
return GetScriptParamPointer(thread);
}
}
}
1 change: 0 additions & 1 deletion CLEO4/CGameMenu.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "stdafx.h"
#include "StdInc.h"
#include "CGameMenu.h"
#include "cleo.h"
#include "CDebug.h"
Expand Down
4 changes: 2 additions & 2 deletions CLEO4/CScriptEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ namespace CLEO

// steam offset is different, so get it manually for now
CGameVersionManager& gvm = GetInstance().VersionManager;
int nSlot = gvm.GetGameVersion() != GV_STEAM ? MenuManager->GetSaveSlot() : *((BYTE*)MenuManager+0x15B);
int nSlot = gvm.GetGameVersion() != GV_STEAM ? *(BYTE*)&MenuManager->m_bSelectedSaveGame : *((BYTE*)MenuManager+0x15B);

sprintf(safe_name, "./cleo/cleo_saves/cs%d.sav", nSlot);

Expand Down Expand Up @@ -805,7 +805,7 @@ namespace CLEO

// steam offset is different, so get it manually for now
CGameVersionManager& gvm = GetInstance().VersionManager;
int nSlot = gvm.GetGameVersion() != GV_STEAM ? MenuManager->GetSaveSlot() : *((BYTE*)MenuManager+0x15B);
int nSlot = gvm.GetGameVersion() != GV_STEAM ? *(BYTE*)&MenuManager->m_bSelectedSaveGame : *((BYTE*)MenuManager+0x15B);

char safe_name[MAX_PATH];
sprintf(safe_name, "./cleo/cleo_saves/cs%d.sav", nSlot);
Expand Down
Loading

0 comments on commit 07df664

Please sign in to comment.