From 882d8a3fcd929605e38508b6d7ebc77e7fb83862 Mon Sep 17 00:00:00 2001 From: "Denilson M. Amorim" Date: Sat, 26 Nov 2016 19:01:02 -0300 Subject: [PATCH 1/2] Replace libgtasa by plugin-sdk --- CCustomOpcodeSystem.cpp | 78 ++++++------ CGameMenu.cpp | 1 - CScriptEngine.cpp | 4 +- CSoundSystem.cpp | 19 ++- CTextManager.cpp | 9 +- CTextManager.h | 1 - CTheScripts.h | 260 ++++++++++++++++++++++++++++++++++++++++ stdafx.h | 102 ++++++++++++++-- 8 files changed, 406 insertions(+), 68 deletions(-) create mode 100644 CTheScripts.h diff --git a/CCustomOpcodeSystem.cpp b/CCustomOpcodeSystem.cpp index 775ea0b8..d0376c52 100644 --- a/CCustomOpcodeSystem.cpp +++ b/CCustomOpcodeSystem.cpp @@ -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; } @@ -1645,13 +1645,13 @@ namespace CLEO *thread >> actor; auto pPlayerPed = GetPedPool().GetAt(actor); CPedIntelligence * pedintel; - if(pPlayerPed && (pedintel = pPlayerPed->GetPedIntelligence())) + if(pPlayerPed && (pedintel = pPlayerPed->m_pIntelligence)) { CVehicle * pVehicle = nullptr; for(int i=0; im_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; } @@ -1659,8 +1659,8 @@ namespace CLEO CPed * pPed = nullptr; for(int i=0; im_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; } @@ -1676,12 +1676,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); } @@ -1699,8 +1699,8 @@ namespace CLEO { DWORD hVehicle; *thread >> hVehicle; - auto id = reinterpret_cast(Models[GetVehiclePool().GetAt(hVehicle)->GetModelIndex() - 400])->vehicleHandlingID; - *thread << Handling->Automobile[id].m_Transmission.ucNumberOfGears; + auto id = reinterpret_cast(Models[GetVehiclePool().GetAt(hVehicle)->m_wModelIndex - 400])->m_wHandlingIndex; + *thread << Handling->m_aVehicleHandling[id].m_transmissionData.m_nNumberOfGears; return OR_CONTINUE; } @@ -1759,7 +1759,7 @@ namespace CLEO { DWORD hVehicle; *thread >> hVehicle; - SetScriptCondResult(thread, GetVehiclePool().GetAt(hVehicle)->m_nVehicleFlags.bSirenOrAlarm); + SetScriptCondResult(thread, GetVehiclePool().GetAt(hVehicle)->m_nFlags.bSirenOrAlarm); return OR_CONTINUE; } @@ -1768,7 +1768,7 @@ namespace CLEO { DWORD hVehicle; *thread >> hVehicle; - SetScriptCondResult(thread, GetVehiclePool().GetAt(hVehicle)->m_nVehicleFlags.bEngineOn); + SetScriptCondResult(thread, GetVehiclePool().GetAt(hVehicle)->m_nFlags.bEngineOn); return OR_CONTINUE; } @@ -1779,7 +1779,7 @@ namespace CLEO state; *thread >> hVehicle >> state; auto veh = GetVehiclePool().GetAt(hVehicle); - veh->m_nVehicleFlags.bEngineOn = state != false; + veh->m_nFlags.bEngineOn = state != false; return OR_CONTINUE; } @@ -1979,9 +1979,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(pTargetEntity)); SetScriptCondResult(thread, true); @@ -2149,7 +2149,7 @@ namespace CLEO auto model = reinterpret_cast(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; } @@ -2166,7 +2166,7 @@ namespace CLEO DWORD mi; *thread >> mi; auto model = reinterpret_cast(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; } @@ -2216,16 +2216,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; @@ -2261,16 +2259,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; @@ -2303,15 +2299,13 @@ 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; // empty slot - - if(auto obj = pool.Get(index)) + if(auto obj = pool.GetAt(index)) { - if(obj->GetFlags().bFadeOut) continue; + //if(obj->m_nObjectFlags.bFadeOut) continue; -- ??? this flag doesn't exist? - 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; diff --git a/CGameMenu.cpp b/CGameMenu.cpp index 2e087b8e..a42a2544 100644 --- a/CGameMenu.cpp +++ b/CGameMenu.cpp @@ -1,5 +1,4 @@ #include "stdafx.h" -#include "StdInc.h" #include "CGameMenu.h" #include "cleo.h" #include "CDebug.h" diff --git a/CScriptEngine.cpp b/CScriptEngine.cpp index 73edb9de..359007b6 100644 --- a/CScriptEngine.cpp +++ b/CScriptEngine.cpp @@ -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); @@ -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); diff --git a/CSoundSystem.cpp b/CSoundSystem.cpp index d7a4d921..ff17d321 100644 --- a/CSoundSystem.cpp +++ b/CSoundSystem.cpp @@ -3,7 +3,6 @@ #include "bass\bass.h" #include "CDebug.h" #include "cleo.h" -#include "CMenuManager.h" #include namespace CLEO @@ -187,14 +186,14 @@ namespace CLEO // not in menu // process camera movements - RwMatrix * pMatrix = nullptr; - RwV3D * pVec = nullptr; - if(camera->matrix) + CMatrixLink * pMatrix = nullptr; + CVector * pVec = nullptr; + if(camera->m_matrix) { - pMatrix = &camera->matrix->matrix; + pMatrix = camera->m_matrix; pVec = &pMatrix->pos; } - else pVec = &camera->m_transform.m_translate; + else pVec = &camera->m_placement.m_vPosn; BASS_Set3DPosition( &BASS_3DVECTOR(pVec->y, pVec->z, pVec->x), @@ -353,9 +352,9 @@ namespace CLEO void C3DAudioStream::Set3dPosition(const CVector& pos) { - position.x = pos.fY; - position.y = pos.fZ; - position.z = pos.fX; + position.x = pos.y; + position.y = pos.z; + position.z = pos.x; link = nullptr; BASS_ChannelSet3DPosition(streamInternal, &position, nullptr, nullptr); } @@ -386,7 +385,7 @@ namespace CLEO { if (link) { - RwV3D * pVec = link->matrix ? &link->matrix->matrix.pos : &link->m_transform.m_translate; + CVector * pVec = link->m_matrix ? &link->m_matrix->pos : &link->m_placement.m_vPosn; BASS_ChannelSet3DPosition(streamInternal, &BASS_3DVECTOR(pVec->y, pVec->z, pVec->x), nullptr, nullptr); } else diff --git a/CTextManager.cpp b/CTextManager.cpp index f26518c6..2b43c290 100644 --- a/CTextManager.cpp +++ b/CTextManager.cpp @@ -1,5 +1,4 @@ #include "stdafx.h" -#include "StdInc.h" #include "CTextManager.h" #include "cleo.h" @@ -23,7 +22,7 @@ namespace CLEO char message_buf[0x80]; - const char * __fastcall CText__TKey__locate(CText::CKeyArray *key, int dummy, const char *gxt, bool& found) + const char * __fastcall CText__TKey__locate(CText__TKey *key, int dummy, const char *gxt, bool& found) { const char * result; _asm @@ -86,13 +85,13 @@ namespace CLEO szResult = GetInstance().TextManager.LocateFxt(gxt); if(szResult) return szResult; - szResult = CText__TKey__locate(&text->MainKeys, 0, gxt, bFound); + szResult = CText__TKey__locate(&text->tkeyMain, 0, gxt, bFound); if(!bFound) { - if (text->m_bMissionLoaded || *mpackNumber || text->haveTabl) + if (text->missionTableLoaded || *mpackNumber || text->haveTabl) { - szResult = CText__TKey__locate(&text->MissionKeys, 0, gxt, bFound); + szResult = CText__TKey__locate(&text->tkeyMission, 0, gxt, bFound); if (!bFound) return ""; //else TRACE("Failed to find used text label '%s'", gxt); } diff --git a/CTextManager.h b/CTextManager.h index 37771299..4217814d 100644 --- a/CTextManager.h +++ b/CTextManager.h @@ -1,6 +1,5 @@ #pragma once #include "stdafx.h" -#include "StdInc.h" #include "CCodeInjector.h" #include "crc32.h" #include diff --git a/CTheScripts.h b/CTheScripts.h new file mode 100644 index 00000000..b676126a --- /dev/null +++ b/CTheScripts.h @@ -0,0 +1,260 @@ +#pragma once + +enum eDataType +{ + DT_END, + DT_DWORD, + DT_VAR, + DT_LVAR, + DT_BYTE, + DT_WORD, + DT_FLOAT, + DT_VAR_ARRAY, + DT_LVAR_ARRAY, + DT_TEXTLABEL, + DT_VAR_TEXTLABEL, + DT_LVAR_TEXTLABEL, + DT_VAR_TEXTLABEL_ARRAY, + DT_LVAR_TEXTLABEL_ARRAY, + DT_VARLEN_STRING, + DT_STRING, + DT_VAR_STRING, + DT_LVAR_STRING, + DT_VAR_STRING_ARRAY, + DT_LVAR_STRING_ARRAY +}; + +union SCRIPT_VAR +{ + DWORD dwParam; + short wParam; + WORD usParam; + BYTE ucParam; + char cParam; + bool bParam; + int nParam; + float fParam; + void* pParam; + char* pcParam; +}; + +class CRunningScript +{ +protected: + CRunningScript *Previous; // +0x0 + CRunningScript *Next; // +0x4 + char Name[8]; // +0x8 + void *BaseIP; // +0x10 + BYTE *CurrentIP; // +0x14 + BYTE *Stack[8]; // +0x18 + WORD SP; // +0x38 + SCRIPT_VAR LocalVar[32]; // +0x3C + DWORD Timers[2]; // +0xBC + bool bIsActive; // +0xC4 + bool bCondResult; // +0xC5 + bool bUseMissionCleanup; // +0xC6 + bool bIsExternal; // +0xC7 + bool bTextBlockOverride; // +0xC8 + BYTE bExternalType; // +0xC9 + DWORD WakeTime; // +0xCC + WORD LogicalOp; // +0xD0 + bool NotFlag; // +0xD2 + bool bWastedBustedCheck; // +0xD3 + bool bWastedOrBusted; // +0xD4 + void *SceneSkipIP; // +0xD8 + bool bIsMission; // +0xDC + +public: + inline bool IsActive() { + return bIsActive; + } + inline bool IsExternal() { + return bIsExternal; + } + inline bool IsMission() { + return bIsMission; + } + inline const char * GetName() { + return Name; + } + inline BYTE * GetBasePointer() { + return (BYTE*)BaseIP; + } + inline BYTE * GetBytePointer() { + return CurrentIP; + } + inline void SetIp(void *ip) { + CurrentIP = (BYTE*)ip; + } + inline void SetBaseIp(void *ip) { + BaseIP = ip; + } + inline CRunningScript * GetNext() { + return Next; + } + inline CRunningScript * GetPrev() { + return Previous; + } + inline void SetIsExternal(bool b) { + bIsExternal = b; + } + inline void SetActive(bool b) { + bIsActive = b; + } + inline void SetNext(CRunningScript *v) { + Next = v; + } + inline void SetPrev(CRunningScript *v) { + Previous = v; + } + inline SCRIPT_VAR * GetVarPtr() { + return LocalVar; + } + inline SCRIPT_VAR * GetVarPtr(int i) { + return &LocalVar[i]; + } + inline int * GetIntVarPtr(int i) { + return (int*)&LocalVar[i].dwParam; + } + inline int GetIntVar(int i) { + return LocalVar[i].dwParam; + } + inline void SetIntVar(int i, int v) { + LocalVar[i].dwParam = v; + } + inline void SetFloatVar(int i, float v) { + LocalVar[i].fParam = v; + } + inline char GetByteVar(int i) { + return LocalVar[i].bParam; + } + inline bool GetConditionResult() { + return bCondResult != 0; + } + /* + inline int GetLocalVarVal(int i) { + return IsMission() ? CTheScripts::GetMissionLocal(i) : GetIntVar(i); + } + inline int * GetLocalVarPtr(int i) { + return IsMission() ? CTheScripts::GetMissionLocalPtr(i) : GetIntVarPtr(i); + }*/ + + inline char ReadDataType() { + return ReadDataByte(); + } + inline short ReadDataVarIndex() { + return ReadDataWord(); + } + inline short ReadDataArrayOffset() { + return ReadDataWord(); + } + inline short ReadDataArrayIndex() { + return ReadDataWord(); + } + inline short ReadDataArraySize() { + return ReadDataByte(); + } + inline short ReadDataArrayFlags() { + return ReadDataByte(); + } + /* + inline int ReadDataGlobalIntVal() + { + short i = ReadDataVarIndex(); + return CTheScripts::GetGlobalVarVal(i); + }; + + inline int ReadDataLocalIntVal() + { + short i = ReadDataVarIndex(); + return IsMission() ? CTheScripts::GetMissionLocal(i) : GetIntVar(i); + };*/ + /* + inline int ReadDataGlobalArrayIntVal() + { + short offset = ReadDataArrayOffset(), + index = ReadDataArrayIndex(), + size = ReadDataArraySize(), + flags = ReadDataArrayFlags(), + indexVal; + + if(flags >= 0x80) indexVal = GetLocalVarVal(index); + else indexVal = CTheScripts::GetGlobalVarVal(index); + + return CTheScripts::GetGlobalVarVal(indexVal + offset); + }; + + inline int ReadDataLocalArrayIntVal() + { + short offset = ReadDataArrayOffset(), + index = ReadDataArrayIndex(), + size = ReadDataArraySize(), + flags = ReadDataArrayFlags(), + indexVal; + + if(flags >= 0x80) indexVal = GetLocalVarVal(index); + else indexVal = CTheScripts::GetGlobalVarVal(index); + + return GetLocalVarVal(indexVal + offset); + };*/ + + inline void IncPtr(int n = 1) { + CurrentIP += n; + }; + + inline int ReadDataByte() + { + char b = *CurrentIP; + ++CurrentIP; + return b; + }; + + inline short ReadDataWord() + { + short v = *(short*)CurrentIP; + CurrentIP += 2; + return v; + }; + + inline int ReadDataInt() + { + int i = *(int*)CurrentIP; + CurrentIP += 4; + return i; + }; + + inline void PushStack(BYTE *ptr) + { + Stack[SP++] = ptr; + } + + inline BYTE * PopStack() + { + return Stack[--SP]; + } + + CRunningScript() + { + strcpy(Name, "noname"); + BaseIP = 0; + Previous = 0; + Next = 0; + CurrentIP = 0; + memset(Stack, 0, sizeof(Stack)); + SP = 0; + WakeTime = 0; + bIsActive = 0; + bCondResult = 0; + bUseMissionCleanup = 0; + bIsExternal = 0; + bTextBlockOverride = 0; + bExternalType = -1; + memset(LocalVar, 0, sizeof(LocalVar)); + LogicalOp = 0; + NotFlag = 0; + bWastedOrBusted = 0; + SceneSkipIP = 0; + bIsMission = 0; + bWastedBustedCheck = 1; + } +}; diff --git a/stdafx.h b/stdafx.h index 0e4e6e9a..dcf22f02 100644 --- a/stdafx.h +++ b/stdafx.h @@ -15,7 +15,19 @@ #include #include #include +#include #include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "CTheScripts.h" enum CLEO_Version { @@ -32,15 +44,91 @@ enum CLEO_Version #define VERSION_LONG 0x04030000 #define VERSION_STRING "4.3" +#define CPOOL_USE_HANDLE_ACCESS + +//#define VALIDATE_SIZE(struc, size) static_assert(sizeof(struc) == size, #struc " (Invalid Structure Size)") + +#define NUM_SCAN_ENTITIES 16 + +using CPedPool = CPool; +using CVehiclePool = CPool; +using CObjectPool = CPool; +using CBuildingPool = CPool; +using RGBA = CRGBA; +using RwV3D = RwV3d; +struct RwRect2D; +using CHandling = cHandlingDataMgr; +using CMarker = tRadarTrace; + +class CTexture +{ + RwTexture *texture; +}; + +// stolen from GTASA +class CTextDrawer +{ +public: + float m_fScaleX; + float m_fScaleY; + CRGBA m_Colour; + BYTE m_bJustify; + BYTE m_bCenter; + BYTE m_bBackground; + BYTE m_bUnk1; + float m_fLineHeight; + float m_fLineWidth; + CRGBA m_BackgroundColour; + BYTE m_bProportional; + CRGBA m_EffectColour; + BYTE m_ucShadow; + BYTE m_ucOutline; + BYTE m_bDrawBeforeFade; + BYTE m_bAlignRight; + int m_nFont; + float m_fPosX; + float m_fPosY; + char m_szGXT[8]; + int m_nParam1; + int m_nParam2; +}; + +VALIDATE_SIZE(CTextDrawer, 0x44); + +enum +{ + VEHICLE_TYPE_AUTOMOBILE, + VEHICLE_TYPE_PLANE, + VEHICLE_TYPE_BIKE, + VEHICLE_TYPE_HELI, + VEHICLE_TYPE_BOAT, + VEHICLE_TYPE_TRAIN, + VEHICLE_TYPE_TRAILER, + VEHICLE_TYPE_BMX, + VEHICLE_TYPE_MTRUCK, + VEHICLE_TYPE_QUAD, + VEHICLE_TYPE_UNKNOWN = -1, +}; + +inline CEntity* GetWeaponTarget(CPed* pSelf) +{ + return reinterpret_cast(pSelf->m_pTargetedObject) != -1? pSelf->m_pTargetedObject : nullptr; +} + +inline bool IsAvailable(CPed* pSelf) +{ + return pSelf->m_pedState != PEDSTATE_DIE && pSelf->m_pedState != PEDSTATE_DEAD; +} + +inline bool IsWrecked(CVehicle* pSelf) +{ + return pSelf->m_nStatus == STATUS_WRECKED || pSelf->m_nFlags.bIsDrowning; +} + + #define OP_NOP 0x90 #define OP_RET 0xC3 #define OP_CALL 0xE8 #define OP_JMP 0xE9 #define OP_JMPSHORT 0xEB - -#define CPOOL_USE_HANDLE_ACCESS - -//#define VALIDATE_SIZE(struc, size) static_assert(sizeof(struc) == size, #struc " (Invalid Structure Size)") - -#include "StdInc.h" -#include "Mem.h" \ No newline at end of file +#include "Mem.h" From 6efb3997ac212e03dad8175ca1e059d8494c77ed Mon Sep 17 00:00:00 2001 From: "Denilson M. Amorim" Date: Sun, 27 Nov 2016 16:44:44 -0300 Subject: [PATCH 2/2] Fixes for plugin-sdk port --- CCustomOpcodeSystem.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/CCustomOpcodeSystem.cpp b/CCustomOpcodeSystem.cpp index d0376c52..6283e3d5 100644 --- a/CCustomOpcodeSystem.cpp +++ b/CCustomOpcodeSystem.cpp @@ -1016,7 +1016,7 @@ namespace CLEO { DWORD handle; *thread >> handle; - *thread << GetPedPool().GetAt(handle); + *thread << GetPedPool().AtHandle(handle); return OR_CONTINUE; } @@ -1025,7 +1025,7 @@ namespace CLEO { DWORD handle; *thread >> handle; - *thread << GetVehiclePool().GetAt(handle); + *thread << GetVehiclePool().AtHandle(handle); return OR_CONTINUE; } @@ -1034,7 +1034,7 @@ namespace CLEO { DWORD handle; *thread >> handle; - *thread << GetObjectPool().GetAt(handle); + *thread << GetObjectPool().AtHandle(handle); return OR_CONTINUE; } @@ -1643,7 +1643,7 @@ namespace CLEO { DWORD actor; *thread >> actor; - auto pPlayerPed = GetPedPool().GetAt(actor); + auto pPlayerPed = GetPedPool().AtHandle(actor); CPedIntelligence * pedintel; if(pPlayerPed && (pedintel = pPlayerPed->m_pIntelligence)) { @@ -1699,7 +1699,7 @@ namespace CLEO { DWORD hVehicle; *thread >> hVehicle; - auto id = reinterpret_cast(Models[GetVehiclePool().GetAt(hVehicle)->m_wModelIndex - 400])->m_wHandlingIndex; + auto id = reinterpret_cast(Models[GetVehiclePool().AtHandle(hVehicle)->m_wModelIndex - 400])->m_wHandlingIndex; *thread << Handling->m_aVehicleHandling[id].m_transmissionData.m_nNumberOfGears; return OR_CONTINUE; } @@ -1709,7 +1709,7 @@ namespace CLEO { DWORD hVehicle; *thread >> hVehicle; - *thread << GetVehiclePool().GetAt(hVehicle)->m_nCurrentGear; + *thread << GetVehiclePool().AtHandle(hVehicle)->m_nCurrentGear; return OR_CONTINUE; } @@ -1759,7 +1759,7 @@ namespace CLEO { DWORD hVehicle; *thread >> hVehicle; - SetScriptCondResult(thread, GetVehiclePool().GetAt(hVehicle)->m_nFlags.bSirenOrAlarm); + SetScriptCondResult(thread, GetVehiclePool().AtHandle(hVehicle)->m_nFlags.bSirenOrAlarm); return OR_CONTINUE; } @@ -1768,7 +1768,7 @@ namespace CLEO { DWORD hVehicle; *thread >> hVehicle; - SetScriptCondResult(thread, GetVehiclePool().GetAt(hVehicle)->m_nFlags.bEngineOn); + SetScriptCondResult(thread, GetVehiclePool().AtHandle(hVehicle)->m_nFlags.bEngineOn); return OR_CONTINUE; } @@ -1778,7 +1778,7 @@ namespace CLEO DWORD hVehicle, state; *thread >> hVehicle >> state; - auto veh = GetVehiclePool().GetAt(hVehicle); + auto veh = GetVehiclePool().AtHandle(hVehicle); veh->m_nFlags.bEngineOn = state != false; return OR_CONTINUE; } @@ -1818,7 +1818,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; } @@ -1828,7 +1828,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; } @@ -1838,7 +1838,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; } @@ -2207,7 +2207,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(thread)->IsCustom() ? @@ -2250,7 +2250,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(thread)->IsCustom() ? @@ -2291,7 +2291,7 @@ 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(thread); @@ -2303,7 +2303,7 @@ namespace CLEO { if(auto obj = pool.GetAt(index)) { - //if(obj->m_nObjectFlags.bFadeOut) continue; -- ??? this flag doesn't exist? + if(obj->m_nObjectFlags.bFadingIn) continue; // this is actually .bFadingOut if((obj->GetPosition() - center).Magnitude() <= radius) {