Script5.cpp

This commit is contained in:
Nikolay Korolev 2021-01-16 13:26:46 +03:00
parent 8b6bcef4b7
commit 708d5831e4
6 changed files with 47 additions and 14 deletions

View file

@ -366,7 +366,7 @@ public:
*/
static void SaveAllScripts(uint8*, uint32*);
static void LoadAllScripts(uint8*, uint32);
static bool LoadAllScripts(uint8*, uint32);
static bool IsDebugOn() { return DbgFlag; };
static void InvertDebugFlag() { DbgFlag = !DbgFlag; }
@ -508,7 +508,7 @@ class CRunningScript
public:
CRunningScript* next;
CRunningScript* prev;
int m_nId;
int32 m_nId;
char m_abScriptName[8];
uint32 m_nIp;
uint32 m_anStack[MAX_STACK_DEPTH];

View file

@ -36,6 +36,8 @@
#include "GameLogic.h"
#include "Bike.h"
// LCS: file done except TODOs
int8 CRunningScript::ProcessCommands500To599(int32 command)
{
switch (command) {

View file

@ -40,6 +40,8 @@
#include "Zones.h"
#include "Bike.h"
// LCS: file done except TODOs
#ifdef FIX_BUGS
static bool IsSlideObjectUsedWrongByScript(const CVector& posTarget, const CVector& slideBy)
{

View file

@ -17,6 +17,8 @@
#include "World.h"
#include "main.h"
// LCS: file done except TODOs
uint32 CRunningScript::CollectLocateParameters(uint32* pIp, bool b3D)
{
CollectParameters(pIp, 1);
@ -2133,6 +2135,9 @@ INITSAVEBUF
WriteSaveBuf(buf, script_data_size);
WriteSaveBuf(buf, OnAMissionFlag);
WriteSaveBuf(buf, LastMissionPassedTime);
for (uint32 i = 0; i < MAX_NUM_COLLECTIVES; i++)
WriteSaveBuf(buf, CollectiveArray[i]);
WriteSaveBuf(buf, NextFreeCollectiveIndex);
for (uint32 i = 0; i < MAX_NUM_BUILDING_SWAPS; i++) {
CBuilding* pBuilding = BuildingSwapArray[i].m_pBuilding;
uint32 type, handle;
@ -2194,14 +2199,26 @@ INITSAVEBUF
VALIDATESAVEBUF(*size)
}
void CTheScripts::LoadAllScripts(uint8* buf, uint32 size)
// TODO: I don't really understand how script loading works, so I leave it the VC way for now.
bool CTheScripts::LoadAllScripts(uint8* buf, uint32 size)
{
Init();
Init(); // TODO: in LCS CTheScripts::Init call GenericLoad, which then calls LoadAllScripts
INITSAVEBUF
CheckSaveHeader(buf, 'S', 'C', 'R', '\0', size - SAVE_HEADER_SIZE);
uint32 varSpace = ReadSaveBuf<uint32>(buf);
for (uint32 i = 0; i < varSpace; i++)
if (*(int32*)&ScriptSpace[0] != *(int32*)&buf[0] || *(int32*)&ScriptSpace[4] != *(int32*)&buf[4]) {
printf("\n===================================================\nSave Game Mismatch!!!\n");
return false;
}
for (uint32 i = 0; i < varSpace; i++) { // this is not exactly what function does
if (i < 8)
ScriptSpace[i] = ReadSaveBuf<uint8>(buf);
else if (GetSaveVarIndex(i / 4 * 4) != -1)
ScriptSpace[i] = ReadSaveBuf<uint8>(buf);
else
ReadSaveBuf<uint8>(buf);
}
// everything else is... gone? TODO
script_assert(ReadSaveBuf<uint32>(buf) == SCRIPT_DATA_SIZE);
OnAMissionFlag = ReadSaveBuf<uint32>(buf);
LastMissionPassedTime = ReadSaveBuf<uint32>(buf);
@ -2270,6 +2287,7 @@ void CRunningScript::Save(uint8*& buf)
{
#ifdef COMPATIBLE_SAVES
SkipSaveBuf(buf, 8);
WriteSaveBuf<int32>(buf, m_nId);
for (int i = 0; i < 8; i++)
WriteSaveBuf<char>(buf, m_abScriptName[i]);
WriteSaveBuf<uint32>(buf, m_nIp);
@ -2281,10 +2299,11 @@ void CRunningScript::Save(uint8*& buf)
WriteSaveBuf<uint16>(buf, m_nStackPointer);
SkipSaveBuf(buf, 2);
#ifdef CHECK_STRUCT_SIZES
static_assert(NUM_LOCAL_VARS + NUM_TIMERS == 18, "Compatibility loss: NUM_LOCAL_VARS + NUM_TIMERS != 18");
static_assert(NUM_LOCAL_VARS + 8 + NUM_TIMERS == 106, "Compatibility loss: NUM_LOCAL_VARS + NUM_TIMERS != 106");
#endif
for (int i = 0; i < NUM_LOCAL_VARS + NUM_TIMERS; i++)
for (int i = 0; i < NUM_LOCAL_VARS + 8 + NUM_TIMERS; i++)
WriteSaveBuf<int32>(buf, m_anLocalVariables[i]);
WriteSaveBuf<int32>(buf, m_nLocalsPointer);
WriteSaveBuf<bool>(buf, m_bIsActive);
WriteSaveBuf<bool>(buf, m_bCondResult);
WriteSaveBuf<bool>(buf, m_bIsMissionScript);
@ -2305,6 +2324,7 @@ void CRunningScript::Load(uint8*& buf)
{
#ifdef COMPATIBLE_SAVES
SkipSaveBuf(buf, 8);
m_nId = ReadSaveBuf<int32>(buf);
for (int i = 0; i < 8; i++)
m_abScriptName[i] = ReadSaveBuf<char>(buf);
m_nIp = ReadSaveBuf<uint32>(buf);
@ -2316,10 +2336,11 @@ void CRunningScript::Load(uint8*& buf)
m_nStackPointer = ReadSaveBuf<uint16>(buf);
SkipSaveBuf(buf, 2);
#ifdef CHECK_STRUCT_SIZES
static_assert(NUM_LOCAL_VARS + NUM_TIMERS == 18, "Compatibility loss: NUM_LOCAL_VARS + NUM_TIMERS != 18");
static_assert(NUM_LOCAL_VARS + 8 + NUM_TIMERS == 106, "Compatibility loss: NUM_LOCAL_VARS + 8 + NUM_TIMERS != 106");
#endif
for (int i = 0; i < NUM_LOCAL_VARS + NUM_TIMERS; i++)
for (int i = 0; i < NUM_LOCAL_VARS + 8 + NUM_TIMERS; i++)
m_anLocalVariables[i] = ReadSaveBuf<int32>(buf);
m_nLocalsPointer = ReadSaveBuf<int32>(buf);
m_bIsActive = ReadSaveBuf<bool>(buf);
m_bCondResult = ReadSaveBuf<bool>(buf);
m_bIsMissionScript = ReadSaveBuf<bool>(buf);
@ -2698,11 +2719,17 @@ void CTheScripts::CleanUpThisPed(CPed* pPed)
}
else {
if (pPed->m_pMyVehicle->m_vehType == VEHICLE_TYPE_CAR) {
if ((pPed->m_fHealth < 1.0f && !pPed->IsPedHeadAbovePos(-0.3f)) || pPed->bBodyPartJustCameOff) {
pPed->SetObjective(OBJECTIVE_LEAVE_CAR_AND_DIE, pPed->m_pMyVehicle);
pPed->bWanderPathAfterExitingCar = false;
}
else {
pPed->SetObjective(OBJECTIVE_LEAVE_CAR, pPed->m_pMyVehicle);
pPed->bWanderPathAfterExitingCar = true;
}
}
}
}
bool flees = false;
PedState state;
eMoveState ms;
@ -2712,6 +2739,7 @@ void CTheScripts::CleanUpThisPed(CPed* pPed)
flees = true;
}
pPed->ClearObjective();
pPed->SetWaitState(WAITSTATE_FALSE, nil); // third parameter is 0 TODO?
pPed->bRespondsToThreats = true;
pPed->bScriptObjectiveCompleted = false;
pPed->bKindaStayInSamePlace = false;
@ -2756,7 +2784,7 @@ void CTheScripts::ReadObjectNamesFromScript()
int32 varSpace = GetSizeOfVariableSpace();
uint32 ip = varSpace + 8;
NumSaveVars = Read4BytesFromScript(&ip);
SavedVarIndices = (short*)&ScriptParams[ip];
SavedVarIndices = (short*)&ScriptSpace[ip];
ip += 2 * NumSaveVars;
NumberOfUsedObjects = Read2BytesFromScript(&ip);
ip += 2;

View file

@ -77,6 +77,7 @@ bool CRunningScript::ThisIsAValidRandomCop(int32 mi, bool cop, bool swat, bool f
default:
return miami && (mi >= MI_VICE1 && mi <= MI_VICE8);
}
return false;
}
int8 CRunningScript::ProcessCommands1000To1099(int32 command)

View file

@ -406,7 +406,7 @@ public:
float m_fCollisionSpeed;
// cf. https://github.com/DK22Pac/plugin-sdk/blob/master/plugin_sa/game_sa/CPed.h from R*
uint32 bIsStanding : 1;
uint32 bIsStanding : 1; // 0x194 on PS2, 0x1A4 on android
uint32 bWasStanding : 1;
uint32 bIsAttacking : 1; // doesn't reset after fist fight
uint32 bIsPointingGunAt : 1;