Merge branch 'master' into miami

# Conflicts:
#	src/modelinfo/ClumpModelInfo.cpp
This commit is contained in:
Sergeanur 2020-05-14 17:05:42 +03:00
commit 24875f34d0
18 changed files with 211 additions and 153 deletions

View file

@ -1450,6 +1450,10 @@ cSampleManager::IsPedCommentLoaded(uint32 nComment)
for ( int32 i = 0; i < _TODOCONST(3); i++ ) for ( int32 i = 0; i < _TODOCONST(3); i++ )
{ {
slot = nCurrentPedSlot - i - 1; slot = nCurrentPedSlot - i - 1;
#ifdef FIX_BUGS
if (slot < 0)
slot += ARRAY_SIZE(nPedSlotSfx);
#endif
if ( nComment == nPedSlotSfx[slot] ) if ( nComment == nPedSlotSfx[slot] )
return true; return true;
} }

View file

@ -780,6 +780,10 @@ cSampleManager::IsPedCommentLoaded(uint32 nComment)
for ( int32 i = 0; i < _TODOCONST(3); i++ ) for ( int32 i = 0; i < _TODOCONST(3); i++ )
{ {
slot = nCurrentPedSlot - i - 1; slot = nCurrentPedSlot - i - 1;
#ifdef FIX_BUGS
if (slot < 0)
slot += ARRAY_SIZE(nPedSlotSfx);
#endif
if ( nComment == nPedSlotSfx[slot] ) if ( nComment == nPedSlotSfx[slot] )
return true; return true;
} }

View file

@ -498,8 +498,6 @@ CCarCtrl::GenerateOneRandomCar()
directionCurrentLinkY = pCurrentLink->GetDirY() * pVehicle->AutoPilot.m_nCurrentDirection; directionCurrentLinkY = pCurrentLink->GetDirY() * pVehicle->AutoPilot.m_nCurrentDirection;
directionNextLinkX = pNextLink->GetDirX() * pVehicle->AutoPilot.m_nNextDirection; directionNextLinkX = pNextLink->GetDirX() * pVehicle->AutoPilot.m_nNextDirection;
directionNextLinkY = pNextLink->GetDirY() * pVehicle->AutoPilot.m_nNextDirection; directionNextLinkY = pNextLink->GetDirY() * pVehicle->AutoPilot.m_nNextDirection;
pCurNode = &ThePaths.m_pathNodes[pVehicle->AutoPilot.m_nCurrentRouteNode];
pNextNode = &ThePaths.m_pathNodes[pVehicle->AutoPilot.m_nNextRouteNode];
} }
#else #else
float currentPathLinkForwardX = pVehicle->AutoPilot.m_nCurrentDirection * ThePaths.m_carPathLinks[pVehicle->AutoPilot.m_nCurrentPathNodeInfo].GetDirX(); float currentPathLinkForwardX = pVehicle->AutoPilot.m_nCurrentDirection * ThePaths.m_carPathLinks[pVehicle->AutoPilot.m_nCurrentPathNodeInfo].GetDirX();

View file

@ -5661,8 +5661,7 @@ int8 CRunningScript::ProcessCommands700To799(int32 command)
{ {
CollectParameters(&m_nIp, 1); CollectParameters(&m_nIp, 1);
CVehicle* pVehicle = CPools::GetVehiclePool()->GetAt(ScriptParams[0]); CVehicle* pVehicle = CPools::GetVehiclePool()->GetAt(ScriptParams[0]);
assert(pVehicle); UpdateCompareFlag(pVehicle && pVehicle->bIsInWater);
UpdateCompareFlag(pVehicle->bIsInWater);
return 0; return 0;
} }
case COMMAND_GET_CLOSEST_CHAR_NODE: case COMMAND_GET_CLOSEST_CHAR_NODE:

View file

@ -137,7 +137,7 @@ void
CTrafficLights::ScanForLightsOnMap(void) CTrafficLights::ScanForLightsOnMap(void)
{ {
int x, y; int x, y;
int i, j, l; int i, j, k, l;
CPtrNode *node; CPtrNode *node;
for(x = 0; x < NUMSECTORS_X; x++) for(x = 0; x < NUMSECTORS_X; x++)
@ -188,8 +188,9 @@ CTrafficLights::ScanForLightsOnMap(void)
for(l = 0; l < ThePaths.m_pathNodes[i].numLinks; l++){ for(l = 0; l < ThePaths.m_pathNodes[i].numLinks; l++){
j = ThePaths.m_pathNodes[i].firstLink + l; j = ThePaths.m_pathNodes[i].firstLink + l;
if(ThePaths.ConnectionCrossesRoad(j)){ if(ThePaths.ConnectionCrossesRoad(j)){
dist2 = Abs(ThePaths.m_pathNodes[j].GetX() - light->GetPosition().x) + k = ThePaths.ConnectedNode(j);
Abs(ThePaths.m_pathNodes[j].GetY() - light->GetPosition().y); dist2 = Abs(ThePaths.m_pathNodes[k].GetX() - light->GetPosition().x) +
Abs(ThePaths.m_pathNodes[k].GetY() - light->GetPosition().y);
if(dist1 < 15.0f || dist2 < 15.0f) if(dist1 < 15.0f || dist2 < 15.0f)
ThePaths.ConnectionSetTrafficLight(j); ThePaths.ConnectionSetTrafficLight(j);
} }

View file

@ -168,7 +168,7 @@ CdStreamInit(int32 numChannels)
gNumChannels = numChannels; gNumChannels = numChannels;
gpReadInfo = (CdReadInfo *)calloc(sizeof(CdReadInfo), numChannels); gpReadInfo = (CdReadInfo *)calloc(numChannels, sizeof(CdReadInfo));
ASSERT( gpReadInfo != nil ); ASSERT( gpReadInfo != nil );
CDDEBUG("read info %p", gpReadInfo); CDDEBUG("read info %p", gpReadInfo);

View file

@ -275,47 +275,41 @@ CPlayerInfo::SavePlayerInfo(uint8 *buf, uint32 *size)
// Interesting // Interesting
*size = sizeof(CPlayerInfo); *size = sizeof(CPlayerInfo);
INITSAVEBUF #define CopyToBuf(buf, data) memcpy(buf, &data, sizeof(data)); buf += sizeof(data);
WriteSaveBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nMoney); CopyToBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nMoney);
WriteSaveBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_WBState); CopyToBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_WBState);
WriteSaveBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nWBTime); CopyToBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nWBTime);
WriteSaveBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nTrafficMultiplier); CopyToBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nTrafficMultiplier);
WriteSaveBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_fRoadDensity); CopyToBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_fRoadDensity);
WriteSaveBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nVisibleMoney); CopyToBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nVisibleMoney);
WriteSaveBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nCollectedPackages); CopyToBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nCollectedPackages);
WriteSaveBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nTotalPackages); CopyToBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nTotalPackages);
WriteSaveBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_bInfiniteSprint); CopyToBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_bInfiniteSprint);
WriteSaveBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_bFastReload); CopyToBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_bFastReload);
WriteSaveBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_bGetOutOfJailFree); CopyToBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_bGetOutOfJailFree);
WriteSaveBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_bGetOutOfHospitalFree); CopyToBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_bGetOutOfHospitalFree);
for (int i = 0; i < sizeof(CWorld::Players[CWorld::PlayerInFocus].m_aPlayerName); i++) { CopyToBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_aPlayerName);
WriteSaveBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_aPlayerName[i]); #undef CopyToBuf
}
// Save struct is different
// VALIDATESAVEBUF(*size)
} }
void void
CPlayerInfo::LoadPlayerInfo(uint8 *buf, uint32 size) CPlayerInfo::LoadPlayerInfo(uint8 *buf, uint32 size)
{ {
INITSAVEBUF #define CopyFromBuf(buf, data) memcpy(&data, buf, sizeof(data)); buf += sizeof(data);
CWorld::Players[CWorld::PlayerInFocus].m_nMoney = ReadSaveBuf<uint32>(buf); CopyFromBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nMoney);
CWorld::Players[CWorld::PlayerInFocus].m_WBState = ReadSaveBuf<int8>(buf); CopyFromBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_WBState);
CWorld::Players[CWorld::PlayerInFocus].m_nWBTime = ReadSaveBuf<uint32>(buf); CopyFromBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nWBTime);
CWorld::Players[CWorld::PlayerInFocus].m_nTrafficMultiplier = ReadSaveBuf<int16>(buf); CopyFromBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nTrafficMultiplier);
CWorld::Players[CWorld::PlayerInFocus].m_fRoadDensity = ReadSaveBuf<float>(buf); CopyFromBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_fRoadDensity);
CWorld::Players[CWorld::PlayerInFocus].m_nVisibleMoney = ReadSaveBuf<int32>(buf); CopyFromBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nVisibleMoney);
CWorld::Players[CWorld::PlayerInFocus].m_nCollectedPackages = ReadSaveBuf<int32>(buf); CopyFromBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nCollectedPackages);
CWorld::Players[CWorld::PlayerInFocus].m_nTotalPackages = ReadSaveBuf<int32>(buf); CopyFromBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_nTotalPackages);
CWorld::Players[CWorld::PlayerInFocus].m_bInfiniteSprint = ReadSaveBuf<bool>(buf); CopyFromBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_bInfiniteSprint);
CWorld::Players[CWorld::PlayerInFocus].m_bFastReload = ReadSaveBuf<bool>(buf); CopyFromBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_bFastReload);
CWorld::Players[CWorld::PlayerInFocus].m_bGetOutOfJailFree = ReadSaveBuf<bool>(buf); CopyFromBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_bGetOutOfJailFree);
CWorld::Players[CWorld::PlayerInFocus].m_bGetOutOfHospitalFree = ReadSaveBuf<bool>(buf); CopyFromBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_bGetOutOfHospitalFree);
for (int i = 0; i < sizeof(CWorld::Players[CWorld::PlayerInFocus].m_aPlayerName); i++) { CopyFromBuf(buf, CWorld::Players[CWorld::PlayerInFocus].m_aPlayerName)
CWorld::Players[CWorld::PlayerInFocus].m_aPlayerName[i] = ReadSaveBuf<char>(buf); #undef CopyFromBuf
}
// Save struct is different
// VALIDATESAVEBUF(size)
} }
void void

View file

@ -90,7 +90,7 @@ CPools::MakeSureSlotInObjectPoolIsEmpty(int32 slot)
// relocate to another slot?? // relocate to another slot??
CObject *newObject = new CObject(object->GetModelIndex(), false); CObject *newObject = new CObject(object->GetModelIndex(), false);
CWorld::Remove(object); CWorld::Remove(object);
#ifdef FIX_BUGS #if 0 // todo better
*newObject = *object; *newObject = *object;
#else #else
memcpy(newObject, object, ms_pObjectPool->GetMaxEntrySize()); memcpy(newObject, object, ms_pObjectPool->GetMaxEntrySize());
@ -102,6 +102,9 @@ CPools::MakeSureSlotInObjectPoolIsEmpty(int32 slot)
} }
} }
#define CopyFromBuf(buf, data) memcpy(&data, buf, sizeof(data)); SkipSaveBuf(buf, sizeof(data));
#define CopyToBuf(buf, data) memcpy(buf, &data, sizeof(data)); SkipSaveBuf(buf, sizeof(data));
void CPools::LoadVehiclePool(uint8* buf, uint32 size) void CPools::LoadVehiclePool(uint8* buf, uint32 size)
{ {
INITSAVEBUF INITSAVEBUF
@ -266,10 +269,10 @@ INITSAVEBUF
if (pObject->ObjectCreatedBy == MISSION_OBJECT) if (pObject->ObjectCreatedBy == MISSION_OBJECT)
++nObjects; ++nObjects;
} }
*size = nObjects * (sizeof(int16) + sizeof(int) + sizeof(CCompressedMatrixNotAligned) + sizeof(uint32) + *size = nObjects * (sizeof(int16) + sizeof(int) + sizeof(CCompressedMatrix) +
sizeof(float) + sizeof(CCompressedMatrixNotAligned) + sizeof(uint32) + sizeof(int8) + 7 * sizeof(bool) + sizeof(float) + sizeof(float) + sizeof(CCompressedMatrix) + sizeof(int8) + 7 * sizeof(bool) + sizeof(float) +
sizeof(int8) + sizeof(int8) + sizeof(uint32) + 2 * sizeof(uint32)) + sizeof(int); sizeof(int8) + sizeof(int8) + sizeof(uint32) + 2 * sizeof(uint32)) + sizeof(int);
WriteSaveBuf(buf, nObjects); CopyToBuf(buf, nObjects);
for (int i = 0; i < nPoolSize; i++) { for (int i = 0; i < nPoolSize; i++) {
CObject* pObject = GetObjectPool()->GetSlot(i); CObject* pObject = GetObjectPool()->GetSlot(i);
if (!pObject) if (!pObject)
@ -282,33 +285,32 @@ INITSAVEBUF
bool bGlassBroken = pObject->bGlassBroken; bool bGlassBroken = pObject->bGlassBroken;
bool bHasBeenDamaged = pObject->bHasBeenDamaged; bool bHasBeenDamaged = pObject->bHasBeenDamaged;
bool bUseVehicleColours = pObject->bUseVehicleColours; bool bUseVehicleColours = pObject->bUseVehicleColours;
CCompressedMatrixNotAligned tmp; CCompressedMatrix tmp;
WriteSaveBuf(buf, pObject->GetModelIndex()); CopyToBuf(buf, pObject->m_modelIndex);
WriteSaveBuf(buf, GetObjectRef(pObject)); int32 ref = GetObjectRef(pObject);
CopyToBuf(buf, ref);
tmp.CompressFromFullMatrix(pObject->GetMatrix()); tmp.CompressFromFullMatrix(pObject->GetMatrix());
WriteSaveBuf(buf, tmp); CopyToBuf(buf, tmp);
WriteSaveBuf(buf, (uint32)0); // game writes ununitialized data here CopyToBuf(buf, pObject->m_fUprootLimit);
WriteSaveBuf(buf, pObject->m_fUprootLimit);
tmp.CompressFromFullMatrix(pObject->m_objectMatrix); tmp.CompressFromFullMatrix(pObject->m_objectMatrix);
WriteSaveBuf(buf, tmp); CopyToBuf(buf, tmp);
WriteSaveBuf(buf, (uint32)0); // same CopyToBuf(buf, pObject->ObjectCreatedBy);
WriteSaveBuf(buf, pObject->ObjectCreatedBy); CopyToBuf(buf, bIsPickup);
WriteSaveBuf(buf, bIsPickup); CopyToBuf(buf, bPickupObjWithMessage);
WriteSaveBuf(buf, bPickupObjWithMessage); CopyToBuf(buf, bOutOfStock);
WriteSaveBuf(buf, bOutOfStock); CopyToBuf(buf, bGlassCracked);
WriteSaveBuf(buf, bGlassCracked); CopyToBuf(buf, bGlassBroken);
WriteSaveBuf(buf, bGlassBroken); CopyToBuf(buf, bHasBeenDamaged);
WriteSaveBuf(buf, bHasBeenDamaged); CopyToBuf(buf, bUseVehicleColours);
WriteSaveBuf(buf, bUseVehicleColours); CopyToBuf(buf, pObject->m_fCollisionDamageMultiplier);
WriteSaveBuf(buf, pObject->m_fCollisionDamageMultiplier); CopyToBuf(buf, pObject->m_nCollisionDamageEffect);
WriteSaveBuf(buf, pObject->m_nCollisionDamageEffect); CopyToBuf(buf, pObject->m_nSpecialCollisionResponseCases);
WriteSaveBuf(buf, pObject->m_nSpecialCollisionResponseCases); CopyToBuf(buf, pObject->m_nEndOfLifeTime);
WriteSaveBuf(buf, pObject->m_nEndOfLifeTime);
#ifdef COMPATIBLE_SAVES #ifdef COMPATIBLE_SAVES
pObject->SaveEntityFlags(buf); pObject->SaveEntityFlags(buf);
#else #else
WriteSaveBuf(buf, (pObject->GetAddressOfEntityProperties())[0]); CopyToBuf(buf, (pObject->GetAddressOfEntityProperties())[0]);
WriteSaveBuf(buf, (pObject->GetAddressOfEntityProperties())[1]); CopyToBuf(buf, (pObject->GetAddressOfEntityProperties())[1]);
#endif #endif
} }
} }
@ -318,35 +320,44 @@ VALIDATESAVEBUF(*size)
void CPools::LoadObjectPool(uint8* buf, uint32 size) void CPools::LoadObjectPool(uint8* buf, uint32 size)
{ {
INITSAVEBUF INITSAVEBUF
int nObjects = ReadSaveBuf<int>(buf); int nObjects;
CopyFromBuf(buf, nObjects);
for (int i = 0; i < nObjects; i++) { for (int i = 0; i < nObjects; i++) {
int16 mi = ReadSaveBuf<int16>(buf); int16 mi;
int ref = ReadSaveBuf<int>(buf); CopyFromBuf(buf, mi);
int ref;
CopyFromBuf(buf, ref);
char* obuf = new char[sizeof(CObject)]; char* obuf = new char[sizeof(CObject)];
CObject* pBufferObject = (CObject*)obuf; CObject* pBufferObject = (CObject*)obuf;
CCompressedMatrixNotAligned tmp; CCompressedMatrix tmp;
tmp = ReadSaveBuf<CCompressedMatrixNotAligned>(buf); CopyFromBuf(buf, tmp);
tmp.DecompressIntoFullMatrix(pBufferObject->GetMatrix()); tmp.DecompressIntoFullMatrix(pBufferObject->GetMatrix());
ReadSaveBuf<uint32>(buf); CopyFromBuf(buf, pBufferObject->m_fUprootLimit);
pBufferObject->m_fUprootLimit = ReadSaveBuf<float>(buf); CopyFromBuf(buf, tmp);
tmp = ReadSaveBuf<CCompressedMatrixNotAligned>(buf);
tmp.DecompressIntoFullMatrix(pBufferObject->m_objectMatrix); tmp.DecompressIntoFullMatrix(pBufferObject->m_objectMatrix);
ReadSaveBuf<uint32>(buf); CopyFromBuf(buf, pBufferObject->ObjectCreatedBy);
pBufferObject->ObjectCreatedBy = ReadSaveBuf<int8>(buf); int8 bitFlag;
pBufferObject->bIsPickup = ReadSaveBuf<bool>(buf); CopyFromBuf(buf, bitFlag);
pBufferObject->bPickupObjWithMessage = ReadSaveBuf<bool>(buf); pBufferObject->bIsPickup = bitFlag;
pBufferObject->bOutOfStock = ReadSaveBuf<bool>(buf); CopyFromBuf(buf, bitFlag);
pBufferObject->bGlassCracked = ReadSaveBuf<bool>(buf); pBufferObject->bPickupObjWithMessage = bitFlag;
pBufferObject->bGlassBroken = ReadSaveBuf<bool>(buf); CopyFromBuf(buf, bitFlag);
pBufferObject->bHasBeenDamaged = ReadSaveBuf<bool>(buf); pBufferObject->bOutOfStock = bitFlag;
pBufferObject->bUseVehicleColours = ReadSaveBuf<bool>(buf); CopyFromBuf(buf, bitFlag);
pBufferObject->m_fCollisionDamageMultiplier = ReadSaveBuf<float>(buf); pBufferObject->bGlassCracked = bitFlag;
pBufferObject->m_nCollisionDamageEffect = ReadSaveBuf<uint8>(buf); CopyFromBuf(buf, bitFlag);
pBufferObject->m_nSpecialCollisionResponseCases = ReadSaveBuf<uint8>(buf); pBufferObject->bGlassBroken = bitFlag;
pBufferObject->m_nEndOfLifeTime = ReadSaveBuf<uint32>(buf); CopyFromBuf(buf, bitFlag);
pBufferObject->bHasBeenDamaged = bitFlag;
CopyFromBuf(buf, bitFlag);
pBufferObject->bUseVehicleColours = bitFlag;
CopyFromBuf(buf, pBufferObject->m_fCollisionDamageMultiplier);
CopyFromBuf(buf, pBufferObject->m_nCollisionDamageEffect);
CopyFromBuf(buf, pBufferObject->m_nSpecialCollisionResponseCases);
CopyFromBuf(buf, pBufferObject->m_nEndOfLifeTime);
#ifndef COMPATIBLE_SAVES #ifndef COMPATIBLE_SAVES
(pBufferObject->GetAddressOfEntityProperties())[0] = ReadSaveBuf<uint32>(buf); CopyFromBuf(buf, (pBufferObject->GetAddressOfEntityProperties())[0]);
(pBufferObject->GetAddressOfEntityProperties())[1] = ReadSaveBuf<uint32>(buf); CopyFromBuf(buf, (pBufferObject->GetAddressOfEntityProperties())[1]);
#endif #endif
if (GetObjectPool()->GetSlot(ref >> 8)) if (GetObjectPool()->GetSlot(ref >> 8))
CPopulation::ConvertToDummyObject(GetObjectPool()->GetSlot(ref >> 8)); CPopulation::ConvertToDummyObject(GetObjectPool()->GetSlot(ref >> 8));
@ -394,38 +405,45 @@ INITSAVEBUF
} }
*size = sizeof(int) + nNumPeds * (sizeof(uint32) + sizeof(int16) + sizeof(int) + CPlayerPed::nSaveStructSize + *size = sizeof(int) + nNumPeds * (sizeof(uint32) + sizeof(int16) + sizeof(int) + CPlayerPed::nSaveStructSize +
sizeof(CWanted::MaximumWantedLevel) + sizeof(CWanted::nMaximumWantedLevel) + MAX_MODEL_NAME); sizeof(CWanted::MaximumWantedLevel) + sizeof(CWanted::nMaximumWantedLevel) + MAX_MODEL_NAME);
WriteSaveBuf(buf, nNumPeds); CopyToBuf(buf, nNumPeds);
for (int i = 0; i < nPoolSize; i++) { for (int i = 0; i < nPoolSize; i++) {
CPed* pPed = GetPedPool()->GetSlot(i); CPed* pPed = GetPedPool()->GetSlot(i);
if (!pPed) if (!pPed)
continue; continue;
if (!pPed->bInVehicle && pPed->m_nPedType == PEDTYPE_PLAYER1) { if (!pPed->bInVehicle && pPed->m_nPedType == PEDTYPE_PLAYER1) {
WriteSaveBuf(buf, pPed->m_nPedType); CopyToBuf(buf, pPed->m_nPedType);
WriteSaveBuf(buf, pPed->GetModelIndex()); CopyToBuf(buf, pPed->m_modelIndex);
WriteSaveBuf(buf, GetPedRef(pPed)); int32 ref = GetPedRef(pPed);
CopyToBuf(buf, ref);
#ifdef COMPATIBLE_SAVES #ifdef COMPATIBLE_SAVES
pPed->Save(buf); pPed->Save(buf);
#else #else
memcpy(buf, pPed, sizeof(CPlayerPed)); memcpy(buf, pPed, sizeof(CPlayerPed));
SkipSaveBuf(buf, sizeof(CPlayerPed)); SkipSaveBuf(buf, sizeof(CPlayerPed));
#endif #endif
WriteSaveBuf(buf, CWanted::MaximumWantedLevel); CopyToBuf(buf, CWanted::MaximumWantedLevel);
WriteSaveBuf(buf, CWanted::nMaximumWantedLevel); CopyToBuf(buf, CWanted::nMaximumWantedLevel);
memcpy(buf, CModelInfo::GetModelInfo(pPed->GetModelIndex())->GetName(), MAX_MODEL_NAME); memcpy(buf, CModelInfo::GetModelInfo(pPed->GetModelIndex())->GetName(), MAX_MODEL_NAME);
SkipSaveBuf(buf, MAX_MODEL_NAME); SkipSaveBuf(buf, MAX_MODEL_NAME);
} }
} }
VALIDATESAVEBUF(*size); VALIDATESAVEBUF(*size);
#undef CopyToBuf
} }
void CPools::LoadPedPool(uint8* buf, uint32 size) void CPools::LoadPedPool(uint8* buf, uint32 size)
{ {
INITSAVEBUF INITSAVEBUF
int nPeds = ReadSaveBuf<int>(buf); int nPeds;
CopyFromBuf(buf, nPeds);
for (int i = 0; i < nPeds; i++) { for (int i = 0; i < nPeds; i++) {
uint32 pedtype = ReadSaveBuf<uint32>(buf); uint32 pedtype;
int16 model = ReadSaveBuf<int16>(buf); int16 model;
int ref = ReadSaveBuf<int>(buf); int ref;
CopyFromBuf(buf, pedtype);
CopyFromBuf(buf, model);
CopyFromBuf(buf, ref);
#ifdef COMPATIBLE_SAVES #ifdef COMPATIBLE_SAVES
CPed* pPed; CPed* pPed;
@ -443,8 +461,8 @@ INITSAVEBUF
pPed->Load(buf); pPed->Load(buf);
if (pedtype == PEDTYPE_PLAYER1) { if (pedtype == PEDTYPE_PLAYER1) {
CWanted::MaximumWantedLevel = ReadSaveBuf<int32>(buf); CopyFromBuf(buf, CWanted::MaximumWantedLevel);
CWanted::nMaximumWantedLevel = ReadSaveBuf<int32>(buf); CopyFromBuf(buf, CWanted::nMaximumWantedLevel);
SkipSaveBuf(buf, MAX_MODEL_NAME); SkipSaveBuf(buf, MAX_MODEL_NAME);
} }
@ -462,10 +480,9 @@ INITSAVEBUF
if (pedtype == PEDTYPE_PLAYER1) { // always true if (pedtype == PEDTYPE_PLAYER1) { // always true
memcpy(pbuf, buf, sizeof(CPlayerPed)); memcpy(pbuf, buf, sizeof(CPlayerPed));
SkipSaveBuf(buf, sizeof(CPlayerPed)); SkipSaveBuf(buf, sizeof(CPlayerPed));
CWanted::MaximumWantedLevel = ReadSaveBuf<int32>(buf); CopyFromBuf(buf, CWanted::MaximumWantedLevel);
CWanted::nMaximumWantedLevel = ReadSaveBuf<int32>(buf); CopyFromBuf(buf, CWanted::nMaximumWantedLevel);
memcpy(name, buf, MAX_MODEL_NAME); CopyFromBuf(buf, name);
SkipSaveBuf(buf, MAX_MODEL_NAME);
} }
CStreaming::RequestSpecialModel(model, name, STREAMFLAGS_DONT_REMOVE); CStreaming::RequestSpecialModel(model, name, STREAMFLAGS_DONT_REMOVE);
CStreaming::LoadAllRequestedModels(false); CStreaming::LoadAllRequestedModels(false);
@ -476,7 +493,7 @@ INITSAVEBUF
pPlayerPed->m_fMaxStamina = pBufferPlayer->m_fMaxStamina; pPlayerPed->m_fMaxStamina = pBufferPlayer->m_fMaxStamina;
pPed = pPlayerPed; pPed = pPlayerPed;
} }
pPed->GetPosition() = pBufferPlayer->GetPosition(); pPed->SetPosition(pBufferPlayer->GetPosition());
pPed->m_fHealth = pBufferPlayer->m_fHealth; pPed->m_fHealth = pBufferPlayer->m_fHealth;
pPed->m_fArmour = pBufferPlayer->m_fArmour; pPed->m_fArmour = pBufferPlayer->m_fArmour;
pPed->CharCreatedBy = pBufferPlayer->CharCreatedBy; pPed->CharCreatedBy = pBufferPlayer->CharCreatedBy;
@ -495,3 +512,6 @@ INITSAVEBUF
} }
VALIDATESAVEBUF(size) VALIDATESAVEBUF(size)
} }
#undef CopyFromBuf
#undef CopyToBuf

View file

@ -313,3 +313,8 @@ public:
other.Reorthogonalise(); other.Reorthogonalise();
} }
}; };
class CCompressedMatrix : public CCompressedMatrixNotAligned
{
int _alignment; // no clue what would this align to
};

View file

@ -74,7 +74,6 @@ CClumpModelInfo::SetClump(RpClump *clump)
AddTexDictionaryRef(); AddTexDictionaryRef();
if(GetAnimFileIndex() != -1) if(GetAnimFileIndex() != -1)
CAnimManager::AddAnimBlockRef(GetAnimFileIndex()); CAnimManager::AddAnimBlockRef(GetAnimFileIndex());
if(IsClumpSkinned(clump)){ if(IsClumpSkinned(clump)){
int i; int i;
RpHAnimHierarchy *hier; RpHAnimHierarchy *hier;

View file

@ -1127,7 +1127,7 @@ CParticleObject::SaveParticle(uint8 *buffer, uint32 *length)
for ( CParticleObject *p = pCloseListHead; p != NULL; p = p->m_pNext ) for ( CParticleObject *p = pCloseListHead; p != NULL; p = p->m_pNext )
{ {
#ifdef FIX_BUGS #if 0 // todo better
*(CParticleObject*)buffer = *p; *(CParticleObject*)buffer = *p;
#else #else
memcpy(buffer, p, sizeof(CParticleObject)); memcpy(buffer, p, sizeof(CParticleObject));
@ -1137,7 +1137,7 @@ CParticleObject::SaveParticle(uint8 *buffer, uint32 *length)
for ( CParticleObject *p = pFarListHead; p != NULL; p = p->m_pNext ) for ( CParticleObject *p = pFarListHead; p != NULL; p = p->m_pNext )
{ {
#ifdef FIX_BUGS #if 0 // todo better
*(CParticleObject*)buffer = *p; *(CParticleObject*)buffer = *p;
#else #else
memcpy(buffer, p, sizeof(CParticleObject)); memcpy(buffer, p, sizeof(CParticleObject));

View file

@ -16049,7 +16049,11 @@ CPed::SeekCar(void)
} }
if (dest.x == 0.0f && dest.y == 0.0f) { if (dest.x == 0.0f && dest.y == 0.0f) {
#ifdef FIX_BUGS
if ((!IsPlayer() && CharCreatedBy != MISSION_CHAR) || vehToSeek->VehicleCreatedBy != MISSION_VEHICLE || vehToSeek->pDriver || !vehToSeek->CanPedOpenLocks(this)) {
#else
if ((!IsPlayer() && CharCreatedBy != MISSION_CHAR) || vehToSeek->VehicleCreatedBy != MISSION_VEHICLE || vehToSeek->pDriver) { if ((!IsPlayer() && CharCreatedBy != MISSION_CHAR) || vehToSeek->VehicleCreatedBy != MISSION_VEHICLE || vehToSeek->pDriver) {
#endif
RestorePreviousState(); RestorePreviousState();
if (IsPlayer()) { if (IsPlayer()) {
ClearObjective(); ClearObjective();
@ -17621,23 +17625,25 @@ CPed::SetExitBoat(CVehicle *boat)
} }
#ifdef COMPATIBLE_SAVES #ifdef COMPATIBLE_SAVES
#define CopyFromBuf(buf, data) memcpy(&data, buf, sizeof(data)); SkipSaveBuf(buf, sizeof(data));
#define CopyToBuf(buf, data) memcpy(buf, &data, sizeof(data)); SkipSaveBuf(buf, sizeof(data));
void void
CPed::Save(uint8*& buf) CPed::Save(uint8*& buf)
{ {
SkipSaveBuf(buf, 52); SkipSaveBuf(buf, 52);
WriteSaveBuf<float>(buf, GetPosition().x); CopyToBuf(buf, GetPosition().x);
WriteSaveBuf<float>(buf, GetPosition().y); CopyToBuf(buf, GetPosition().y);
WriteSaveBuf<float>(buf, GetPosition().z); CopyToBuf(buf, GetPosition().z);
SkipSaveBuf(buf, 288); SkipSaveBuf(buf, 288);
WriteSaveBuf<uint8>(buf, CharCreatedBy); CopyToBuf(buf, CharCreatedBy);
SkipSaveBuf(buf, 351); SkipSaveBuf(buf, 351);
WriteSaveBuf<float>(buf, m_fHealth); CopyToBuf(buf, m_fHealth);
WriteSaveBuf<float>(buf, m_fArmour); CopyToBuf(buf, m_fArmour);
SkipSaveBuf(buf, 148); SkipSaveBuf(buf, 148);
for (int i = 0; i < 13; i++) // has to be hardcoded for (int i = 0; i < 13; i++) // has to be hardcoded
m_weapons[i].Save(buf); m_weapons[i].Save(buf);
SkipSaveBuf(buf, 5); SkipSaveBuf(buf, 5);
WriteSaveBuf<uint8>(buf, m_maxWeaponTypeAllowed); CopyToBuf(buf, m_maxWeaponTypeAllowed);
SkipSaveBuf(buf, 162); SkipSaveBuf(buf, 162);
} }
@ -17645,19 +17651,21 @@ void
CPed::Load(uint8*& buf) CPed::Load(uint8*& buf)
{ {
SkipSaveBuf(buf, 52); SkipSaveBuf(buf, 52);
GetMatrix().GetPosition().x = ReadSaveBuf<float>(buf); CopyFromBuf(buf, GetMatrix().GetPosition().x);
GetMatrix().GetPosition().y = ReadSaveBuf<float>(buf); CopyFromBuf(buf, GetMatrix().GetPosition().y);
GetMatrix().GetPosition().z = ReadSaveBuf<float>(buf); CopyFromBuf(buf, GetMatrix().GetPosition().z);
SkipSaveBuf(buf, 288); SkipSaveBuf(buf, 288);
CharCreatedBy = ReadSaveBuf<uint8>(buf); CopyFromBuf(buf, CharCreatedBy);
SkipSaveBuf(buf, 351); SkipSaveBuf(buf, 351);
m_fHealth = ReadSaveBuf<float>(buf); CopyFromBuf(buf, m_fHealth);
m_fArmour = ReadSaveBuf<float>(buf); CopyFromBuf(buf, m_fArmour);
SkipSaveBuf(buf, 148); SkipSaveBuf(buf, 148);
for (int i = 0; i < 13; i++) // has to be hardcoded for (int i = 0; i < 13; i++) // has to be hardcoded
m_weapons[i].Load(buf); m_weapons[i].Load(buf);
SkipSaveBuf(buf, 5); SkipSaveBuf(buf, 5);
m_maxWeaponTypeAllowed = ReadSaveBuf<uint8>(buf); CopyFromBuf(buf, m_maxWeaponTypeAllowed);
SkipSaveBuf(buf, 162); SkipSaveBuf(buf, 162);
} }
#undef CopyFromBuf
#undef CopyToBuf
#endif #endif

View file

@ -64,8 +64,8 @@ CPedIK::RotateTorso(AnimBlendFrameData *node, LimbOrientation *limb, bool change
// We can't get the parent matrix of an hanim frame but // We can't get the parent matrix of an hanim frame but
// this function is always called with PED_MID, so we know the parent frame. // this function is always called with PED_MID, so we know the parent frame.
// Trouble is that PED_MID is "Smid" on PS2/PC but BONE_torso on mobile/xbox... // Trouble is that PED_MID is "Smid" on PS2/PC but BONE_torso on mobile/xbox...
// so this doesn't exactly do what we'd like anyway // Assuming BONE_torso, the parent is BONE_mid, so let's use that:
RwMatrix *mat = GetComponentMatrix(m_ped, PED_MID); RwMatrix *mat = GetBoneMatrix(m_ped, BONE_mid);
RwV3d vec1, vec2; RwV3d vec1, vec2;
vec1.x = mat->right.z; vec1.x = mat->right.z;

View file

@ -1513,17 +1513,19 @@ CPlayerPed::ProcessControl(void)
} }
#ifdef COMPATIBLE_SAVES #ifdef COMPATIBLE_SAVES
#define CopyFromBuf(buf, data) memcpy(&data, buf, sizeof(data)); SkipSaveBuf(buf, sizeof(data));
#define CopyToBuf(buf, data) memcpy(buf, &data, sizeof(data)); SkipSaveBuf(buf, sizeof(data));
void void
CPlayerPed::Save(uint8*& buf) CPlayerPed::Save(uint8*& buf)
{ {
CPed::Save(buf); CPed::Save(buf);
SkipSaveBuf(buf, 16); SkipSaveBuf(buf, 16);
WriteSaveBuf<float>(buf, m_fMaxStamina); CopyToBuf(buf, m_fMaxStamina);
SkipSaveBuf(buf, 28); SkipSaveBuf(buf, 28);
WriteSaveBuf<int32>(buf, m_nTargettableObjects[0]); CopyToBuf(buf, m_nTargettableObjects[0]);
WriteSaveBuf<int32>(buf, m_nTargettableObjects[1]); CopyToBuf(buf, m_nTargettableObjects[1]);
WriteSaveBuf<int32>(buf, m_nTargettableObjects[2]); CopyToBuf(buf, m_nTargettableObjects[2]);
WriteSaveBuf<int32>(buf, m_nTargettableObjects[3]); CopyToBuf(buf, m_nTargettableObjects[3]);
SkipSaveBuf(buf, 116); SkipSaveBuf(buf, 116);
} }
@ -1532,12 +1534,14 @@ CPlayerPed::Load(uint8*& buf)
{ {
CPed::Load(buf); CPed::Load(buf);
SkipSaveBuf(buf, 16); SkipSaveBuf(buf, 16);
m_fMaxStamina = ReadSaveBuf<float>(buf); CopyFromBuf(buf, m_fMaxStamina);
SkipSaveBuf(buf, 28); SkipSaveBuf(buf, 28);
m_nTargettableObjects[0] = ReadSaveBuf<int32>(buf); CopyFromBuf(buf, m_nTargettableObjects[0]);
m_nTargettableObjects[1] = ReadSaveBuf<int32>(buf); CopyFromBuf(buf, m_nTargettableObjects[1]);
m_nTargettableObjects[2] = ReadSaveBuf<int32>(buf); CopyFromBuf(buf, m_nTargettableObjects[2]);
m_nTargettableObjects[3] = ReadSaveBuf<int32>(buf); CopyFromBuf(buf, m_nTargettableObjects[3]);
SkipSaveBuf(buf, 116); SkipSaveBuf(buf, 116);
} }
#undef CopyFromBuf
#undef CopyToBuf
#endif #endif

View file

@ -715,10 +715,23 @@ void scrollCB(GLFWwindow* window, double xoffset, double yoffset);
void cursorCB(GLFWwindow* window, double xpos, double ypos); void cursorCB(GLFWwindow* window, double xpos, double ypos);
void joysChangeCB(int jid, int event); void joysChangeCB(int jid, int event);
bool IsThisJoystickBlacklisted(int i)
{
const char *joyname = glfwGetJoystickName(i);
// this is just a keyboard and mouse
// Microsoft Microsoft® 2.4GHz Transceiver v8.0 Consumer Control
// Microsoft Microsoft® 2.4GHz Transceiver v8.0 System Control
if(strstr(joyname, "2.4GHz Transceiver"))
return true;
return false;
}
void _InputInitialiseJoys() void _InputInitialiseJoys()
{ {
for (int i = 0; i <= GLFW_JOYSTICK_LAST; i++) { for (int i = 0; i <= GLFW_JOYSTICK_LAST; i++) {
if (glfwJoystickPresent(i)) { if (glfwJoystickPresent(i) && !IsThisJoystickBlacklisted(i)) {
if (PSGLOBAL(joy1id) == -1) if (PSGLOBAL(joy1id) == -1)
PSGLOBAL(joy1id) = i; PSGLOBAL(joy1id) = i;
else if (PSGLOBAL(joy2id) == -1) else if (PSGLOBAL(joy2id) == -1)

View file

@ -184,7 +184,11 @@ CBoat::ProcessControl(void)
} }
float collisionDamage = pHandling->fCollisionDamageMultiplier * m_fDamageImpulse; float collisionDamage = pHandling->fCollisionDamageMultiplier * m_fDamageImpulse;
#ifdef FIX_BUGS
if (collisionDamage > 25.0f && GetStatus() != STATUS_WRECKED && m_fHealth >= 150.0f && !bCollisionProof) {
#else
if(collisionDamage > 25.0f && GetStatus() != STATUS_WRECKED && m_fHealth >= 150.0f){ if(collisionDamage > 25.0f && GetStatus() != STATUS_WRECKED && m_fHealth >= 150.0f){
#endif
float prevHealth = m_fHealth; float prevHealth = m_fHealth;
if(this == FindPlayerVehicle()){ if(this == FindPlayerVehicle()){
if(bTakeLessDamage) if(bTakeLessDamage)

View file

@ -181,7 +181,7 @@ bool CCranes::IsThisCarPickedUp(float X, float Y, CVehicle* pVehicle)
for (int i = 0; i < NumCranes; i++) { for (int i = 0; i < NumCranes; i++) {
float distance = (CVector2D(X, Y) - aCranes[i].m_pCraneEntity->GetPosition()).Magnitude(); float distance = (CVector2D(X, Y) - aCranes[i].m_pCraneEntity->GetPosition()).Magnitude();
if (distance < MAX_DISTANCE_TO_FIND_CRANE && aCranes[i].m_pVehiclePickedUp == pVehicle) { if (distance < MAX_DISTANCE_TO_FIND_CRANE && aCranes[i].m_pVehiclePickedUp == pVehicle) {
if (aCranes[i].m_nCraneStatus == CCrane::LIFTING_TARGET || aCranes[i].m_nCraneStatus == CCrane::ROTATING_TARGET) if (aCranes[i].m_nCraneState == CCrane::LIFTING_TARGET || aCranes[i].m_nCraneState == CCrane::ROTATING_TARGET)
result = true; result = true;
} }
} }

View file

@ -2284,27 +2284,32 @@ CWeapon::ProcessLineOfSight(CVector const &point1, CVector const &point2, CColPo
} }
#ifdef COMPATIBLE_SAVES #ifdef COMPATIBLE_SAVES
#define CopyFromBuf(buf, data) memcpy(&data, buf, sizeof(data)); SkipSaveBuf(buf, sizeof(data));
#define CopyToBuf(buf, data) memcpy(buf, &data, sizeof(data)); SkipSaveBuf(buf, sizeof(data));
void void
CWeapon::Save(uint8*& buf) CWeapon::Save(uint8*& buf)
{ {
WriteSaveBuf<uint32>(buf, m_eWeaponType); CopyToBuf(buf, m_eWeaponType);
WriteSaveBuf<uint32>(buf, m_eWeaponState); CopyToBuf(buf, m_eWeaponState);
WriteSaveBuf<uint32>(buf, m_nAmmoInClip); CopyToBuf(buf, m_nAmmoInClip);
WriteSaveBuf<uint32>(buf, m_nAmmoTotal); CopyToBuf(buf, m_nAmmoTotal);
WriteSaveBuf<uint32>(buf, m_nTimer); CopyToBuf(buf, m_nTimer);
WriteSaveBuf<bool>(buf, m_bAddRotOffset); CopyToBuf(buf, m_bAddRotOffset);
SkipSaveBuf(buf, 3); SkipSaveBuf(buf, 3);
} }
void void
CWeapon::Load(uint8*& buf) CWeapon::Load(uint8*& buf)
{ {
m_eWeaponType = (eWeaponType)ReadSaveBuf<uint32>(buf); CopyFromBuf(buf, m_eWeaponType);
m_eWeaponState = (eWeaponState)ReadSaveBuf<uint32>(buf); CopyFromBuf(buf, m_eWeaponState);
m_nAmmoInClip = ReadSaveBuf<uint32>(buf); CopyFromBuf(buf, m_nAmmoInClip);
m_nAmmoTotal = ReadSaveBuf<uint32>(buf); CopyFromBuf(buf, m_nAmmoTotal);
m_nTimer = ReadSaveBuf<uint32>(buf); CopyFromBuf(buf, m_nTimer);
m_bAddRotOffset = ReadSaveBuf<bool>(buf); CopyFromBuf(buf, m_bAddRotOffset);
SkipSaveBuf(buf, 3); SkipSaveBuf(buf, 3);
} }
#undef CopyFromBuf
#undef CopyToBuf
#endif #endif