1
0
Fork 0
mirror of https://git.rip/DMCA_FUCKER/re3.git synced 2024-12-23 11:10:01 +00:00

Zones save/load

This commit is contained in:
Sergeanur 2020-04-18 12:23:20 +03:00
parent 555f933780
commit eadb5a16aa

View file

@ -625,218 +625,113 @@ CTheZones::InitialiseAudioZoneArray(void)
} }
void void
CTheZones::SaveAllZones(uint8 *buffer, uint32 *length) CTheZones::SaveAllZones(uint8 *buffer, uint32 *size)
{ {
INITSAVEBUF
int i; int i;
*length = 8 + 12 + *size = SAVE_HEADER_SIZE
NUMZONES*56 + 2*NUMZONES*58 + 4 + + sizeof(int32) // GetIndexForZonePointer
NUMMAPZONES*56 + NUMAUDIOZONES*2 + 4; + sizeof(m_CurrLevel) + sizeof(FindIndex)
+ sizeof(int16) // padding
+ sizeof(ZoneArray) + sizeof(ZoneInfoArray)
+ sizeof(TotalNumberOfZones) + sizeof(TotalNumberOfZoneInfos)
+ sizeof(MapZoneArray) + sizeof(AudioZoneArray)
+ sizeof(TotalNumberOfMapZones) + sizeof(NumberOfAudioZones);
buffer[0] = 'Z'; WriteSaveHeader(buffer, 'Z', 'N', 'S', '\0', *size - SAVE_HEADER_SIZE);
buffer[1] = 'N';
buffer[2] = 'S';
buffer[3] = '\0';
*(uint32*)(buffer+4) = *length - 8;
buffer += 8;
*(int32*)(buffer) = GetIndexForZonePointer(m_pPlayersZone); WriteSaveBuf(buffer, GetIndexForZonePointer(m_pPlayersZone));
*(int32*)(buffer+4) = m_CurrLevel; WriteSaveBuf(buffer, m_CurrLevel);
*(int16*)(buffer+8) = FindIndex; WriteSaveBuf(buffer, FindIndex);
*(int16*)(buffer+10) = 0; WriteSaveBuf(buffer, (int16)0); // padding
buffer += 12;
for(i = 0; i < NUMZONES; i++){ for(i = 0; i < ARRAY_SIZE(ZoneArray); i++){
memcpy(buffer, ZoneArray[i].name, 8); CZone *zone = WriteSaveBuf(buffer, ZoneArray[i]);
*(float*)(buffer+8) = ZoneArray[i].minx; zone->child = (CZone*)GetIndexForZonePointer(ZoneArray[i].child);
*(float*)(buffer+12) = ZoneArray[i].miny; zone->parent = (CZone*)GetIndexForZonePointer(ZoneArray[i].parent);
*(float*)(buffer+16) = ZoneArray[i].minz; zone->next = (CZone*)GetIndexForZonePointer(ZoneArray[i].next);
*(float*)(buffer+20) = ZoneArray[i].maxx;
*(float*)(buffer+24) = ZoneArray[i].maxy;
*(float*)(buffer+28) = ZoneArray[i].maxz;
*(int32*)(buffer+32) = ZoneArray[i].type;
*(int32*)(buffer+36) = ZoneArray[i].level;
*(int16*)(buffer+40) = ZoneArray[i].zoneinfoDay;
*(int16*)(buffer+42) = ZoneArray[i].zoneinfoNight;
*(int32*)(buffer+44) = GetIndexForZonePointer(ZoneArray[i].child);
*(int32*)(buffer+48) = GetIndexForZonePointer(ZoneArray[i].parent);
*(int32*)(buffer+52) = GetIndexForZonePointer(ZoneArray[i].next);
buffer += 56;
} }
for(i = 0; i < 2*NUMZONES; i++){ for(i = 0; i < ARRAY_SIZE(ZoneInfoArray); i++)
*(int16*)(buffer) = ZoneInfoArray[i].carDensity; WriteSaveBuf(buffer, ZoneInfoArray[i]);
*(int16*)(buffer+2) = ZoneInfoArray[i].carThreshold[0];
*(int16*)(buffer+4) = ZoneInfoArray[i].carThreshold[1]; WriteSaveBuf(buffer, TotalNumberOfZones);
*(int16*)(buffer+6) = ZoneInfoArray[i].carThreshold[2]; WriteSaveBuf(buffer, TotalNumberOfZoneInfos);
*(int16*)(buffer+8) = ZoneInfoArray[i].carThreshold[3];
*(int16*)(buffer+10) = ZoneInfoArray[i].carThreshold[4]; for(i = 0; i < ARRAY_SIZE(MapZoneArray); i++) {
*(int16*)(buffer+12) = ZoneInfoArray[i].carThreshold[5]; CZone* zone = WriteSaveBuf(buffer, MapZoneArray[i]);
*(int16*)(buffer+14) = ZoneInfoArray[i].copThreshold;
*(int16*)(buffer+16) = ZoneInfoArray[i].gangThreshold[0]; /*
*(int16*)(buffer+18) = ZoneInfoArray[i].gangThreshold[1]; The call of GetIndexForZonePointer is wrong, as it is
*(int16*)(buffer+20) = ZoneInfoArray[i].gangThreshold[2]; meant for a different array, but the game doesn't brake
*(int16*)(buffer+22) = ZoneInfoArray[i].gangThreshold[3]; if those fields are nil. Let's make sure they are.
*(int16*)(buffer+24) = ZoneInfoArray[i].gangThreshold[4]; */
*(int16*)(buffer+26) = ZoneInfoArray[i].gangThreshold[5]; assert(MapZoneArray[i].child == nil);
*(int16*)(buffer+28) = ZoneInfoArray[i].gangThreshold[6]; assert(MapZoneArray[i].parent == nil);
*(int16*)(buffer+30) = ZoneInfoArray[i].gangThreshold[7]; assert(MapZoneArray[i].next == nil);
*(int16*)(buffer+32) = ZoneInfoArray[i].gangThreshold[8]; zone->child = (CZone*)GetIndexForZonePointer(MapZoneArray[i].child);
*(uint16*)(buffer+34) = ZoneInfoArray[i].pedDensity; zone->parent = (CZone*)GetIndexForZonePointer(MapZoneArray[i].parent);
*(uint16*)(buffer+36) = ZoneInfoArray[i].copDensity; zone->next = (CZone*)GetIndexForZonePointer(MapZoneArray[i].next);
*(uint16*)(buffer+38) = ZoneInfoArray[i].gangDensity[0];
*(uint16*)(buffer+40) = ZoneInfoArray[i].gangDensity[1];
*(uint16*)(buffer+42) = ZoneInfoArray[i].gangDensity[2];
*(uint16*)(buffer+44) = ZoneInfoArray[i].gangDensity[3];
*(uint16*)(buffer+46) = ZoneInfoArray[i].gangDensity[4];
*(uint16*)(buffer+48) = ZoneInfoArray[i].gangDensity[5];
*(uint16*)(buffer+50) = ZoneInfoArray[i].gangDensity[6];
*(uint16*)(buffer+52) = ZoneInfoArray[i].gangDensity[7];
*(uint16*)(buffer+54) = ZoneInfoArray[i].gangDensity[8];
*(uint16*)(buffer+56) = ZoneInfoArray[i].pedGroup;
buffer += 58;
} }
*(uint16*)(buffer) = TotalNumberOfZones; for(i = 0; i < ARRAY_SIZE(AudioZoneArray); i++)
*(uint16*)(buffer+2) = TotalNumberOfZoneInfos; WriteSaveBuf(buffer, AudioZoneArray[i]);
buffer += 4;
for(i = 0; i < NUMMAPZONES; i++){ WriteSaveBuf(buffer, TotalNumberOfMapZones);
memcpy(buffer, MapZoneArray[i].name, 8); WriteSaveBuf(buffer, NumberOfAudioZones);
*(float*)(buffer+8) = MapZoneArray[i].minx;
*(float*)(buffer+12) = MapZoneArray[i].miny;
*(float*)(buffer+16) = MapZoneArray[i].minz;
*(float*)(buffer+20) = MapZoneArray[i].maxx;
*(float*)(buffer+24) = MapZoneArray[i].maxy;
*(float*)(buffer+28) = MapZoneArray[i].maxz;
*(int32*)(buffer+32) = MapZoneArray[i].type;
*(int32*)(buffer+36) = MapZoneArray[i].level;
*(int16*)(buffer+40) = MapZoneArray[i].zoneinfoDay;
*(int16*)(buffer+42) = MapZoneArray[i].zoneinfoNight;
#ifdef STANDALONE
// BUG: GetIndexForZonePointer uses ZoneArray
// so indices will be unpredictable with different memory layout
assert(0);
#endif
*(int32*)(buffer+44) = GetIndexForZonePointer(MapZoneArray[i].child);
*(int32*)(buffer+48) = GetIndexForZonePointer(MapZoneArray[i].parent);
*(int32*)(buffer+52) = GetIndexForZonePointer(MapZoneArray[i].next);
buffer += 56;
}
for(i = 0; i < NUMAUDIOZONES; i++){ VALIDATESAVEBUF(*size)
*(int16*)buffer = AudioZoneArray[i];
buffer += 2;
}
*(uint16*)(buffer) = TotalNumberOfMapZones;
*(uint16*)(buffer+2) = NumberOfAudioZones;
} }
void void
CTheZones::LoadAllZones(uint8 *buffer, uint32 length) CTheZones::LoadAllZones(uint8 *buffer, uint32 size)
{ {
INITSAVEBUF
int i; int i;
assert(length == 8 + 12 + CheckSaveHeader(buffer, 'Z', 'N', 'S', '\0', size - SAVE_HEADER_SIZE);
NUMZONES*56 + 2*NUMZONES*58 + 4 +
NUMMAPZONES*56 + NUMAUDIOZONES*2 + 4);
assert(buffer[0] == 'Z');
assert(buffer[1] == 'N');
assert(buffer[2] == 'S');
assert(buffer[3] == '\0');
assert(*(uint32*)(buffer+4) == length - 8);
buffer += 8;
m_pPlayersZone = GetPointerForZoneIndex(*(int32*)(buffer)); m_pPlayersZone = GetPointerForZoneIndex(ReadSaveBuf<int32>(buffer));
m_CurrLevel = (eLevelName)*(int32*)(buffer+4); m_CurrLevel = ReadSaveBuf<eLevelName>(buffer);
FindIndex = *(int16*)(buffer+8); FindIndex = ReadSaveBuf<int16>(buffer);
assert(*(int16*)(buffer+10) == 0); ReadSaveBuf<int16>(buffer);
buffer += 12;
for(i = 0; i < NUMZONES; i++){ for(i = 0; i < ARRAY_SIZE(ZoneArray); i++){
memcpy(ZoneArray[i].name, buffer, 8); ZoneArray[i] = ReadSaveBuf<CZone>(buffer);
ZoneArray[i].minx = *(float*)(buffer+8);
ZoneArray[i].miny = *(float*)(buffer+12); ZoneArray[i].child = GetPointerForZoneIndex((int32)ZoneArray[i].child);
ZoneArray[i].minz = *(float*)(buffer+16); ZoneArray[i].parent = GetPointerForZoneIndex((int32)ZoneArray[i].parent);
ZoneArray[i].maxx = *(float*)(buffer+20); ZoneArray[i].next = GetPointerForZoneIndex((int32)ZoneArray[i].next);
ZoneArray[i].maxy = *(float*)(buffer+24);
ZoneArray[i].maxz = *(float*)(buffer+28);
ZoneArray[i].type = (eZoneType)*(int32*)(buffer+32);
ZoneArray[i].level = (eLevelName)*(int32*)(buffer+36);
ZoneArray[i].zoneinfoDay = *(int16*)(buffer+40);
ZoneArray[i].zoneinfoNight = *(int16*)(buffer+42);
ZoneArray[i].child = GetPointerForZoneIndex(*(int32*)(buffer+44));
ZoneArray[i].parent = GetPointerForZoneIndex(*(int32*)(buffer+48));
ZoneArray[i].next = GetPointerForZoneIndex(*(int32*)(buffer+52));
buffer += 56;
} }
for(i = 0; i < 2*NUMZONES; i++){ for(i = 0; i < ARRAY_SIZE(ZoneInfoArray); i++)
ZoneInfoArray[i].carDensity = *(int16*)(buffer); ZoneInfoArray[i] = ReadSaveBuf<CZoneInfo>(buffer);
ZoneInfoArray[i].carThreshold[0] = *(int16*)(buffer+2);
ZoneInfoArray[i].carThreshold[1] = *(int16*)(buffer+4); TotalNumberOfZones = ReadSaveBuf<int16>(buffer);
ZoneInfoArray[i].carThreshold[2] = *(int16*)(buffer+6); TotalNumberOfZoneInfos = ReadSaveBuf<int16>(buffer);
ZoneInfoArray[i].carThreshold[3] = *(int16*)(buffer+8);
ZoneInfoArray[i].carThreshold[4] = *(int16*)(buffer+10); for(i = 0; i < ARRAY_SIZE(MapZoneArray); i++){
ZoneInfoArray[i].carThreshold[5] = *(int16*)(buffer+12); MapZoneArray[i] = ReadSaveBuf<CZone>(buffer);
ZoneInfoArray[i].copThreshold = *(int16*)(buffer+14);
ZoneInfoArray[i].gangThreshold[0] = *(int16*)(buffer+16); /*
ZoneInfoArray[i].gangThreshold[1] = *(int16*)(buffer+18); The call of GetPointerForZoneIndex is wrong, as it is
ZoneInfoArray[i].gangThreshold[2] = *(int16*)(buffer+20); meant for a different array, but the game doesn't brake
ZoneInfoArray[i].gangThreshold[3] = *(int16*)(buffer+22); if save data stored is -1.
ZoneInfoArray[i].gangThreshold[4] = *(int16*)(buffer+24); */
ZoneInfoArray[i].gangThreshold[5] = *(int16*)(buffer+26); MapZoneArray[i].child = GetPointerForZoneIndex((int32)MapZoneArray[i].child);
ZoneInfoArray[i].gangThreshold[6] = *(int16*)(buffer+28); MapZoneArray[i].parent = GetPointerForZoneIndex((int32)MapZoneArray[i].parent);
ZoneInfoArray[i].gangThreshold[7] = *(int16*)(buffer+30); MapZoneArray[i].next = GetPointerForZoneIndex((int32)MapZoneArray[i].next);
ZoneInfoArray[i].gangThreshold[8] = *(int16*)(buffer+32); assert(MapZoneArray[i].child == nil);
ZoneInfoArray[i].pedDensity = *(uint16*)(buffer+34); assert(MapZoneArray[i].parent == nil);
ZoneInfoArray[i].copDensity = *(uint16*)(buffer+36); assert(MapZoneArray[i].next == nil);
ZoneInfoArray[i].gangDensity[0] = *(uint16*)(buffer+38);
ZoneInfoArray[i].gangDensity[1] = *(uint16*)(buffer+40);
ZoneInfoArray[i].gangDensity[2] = *(uint16*)(buffer+42);
ZoneInfoArray[i].gangDensity[3] = *(uint16*)(buffer+44);
ZoneInfoArray[i].gangDensity[4] = *(uint16*)(buffer+46);
ZoneInfoArray[i].gangDensity[5] = *(uint16*)(buffer+48);
ZoneInfoArray[i].gangDensity[6] = *(uint16*)(buffer+50);
ZoneInfoArray[i].gangDensity[7] = *(uint16*)(buffer+52);
ZoneInfoArray[i].gangDensity[8] = *(uint16*)(buffer+54);
ZoneInfoArray[i].pedGroup = *(uint16*)(buffer+56);
buffer += 58;
} }
TotalNumberOfZones = *(uint16*)(buffer); for(i = 0; i < ARRAY_SIZE(AudioZoneArray); i++)
TotalNumberOfZoneInfos = *(uint16*)(buffer+2); AudioZoneArray[i] = ReadSaveBuf<int16>(buffer);
buffer += 4;
for(i = 0; i < NUMMAPZONES; i++){ TotalNumberOfMapZones = ReadSaveBuf<uint16>(buffer);
memcpy(MapZoneArray[i].name, buffer, 8); NumberOfAudioZones = ReadSaveBuf<uint16>(buffer);
MapZoneArray[i].minx = *(float*)(buffer+8);
MapZoneArray[i].miny = *(float*)(buffer+12);
MapZoneArray[i].minz = *(float*)(buffer+16);
MapZoneArray[i].maxx = *(float*)(buffer+20);
MapZoneArray[i].maxy = *(float*)(buffer+24);
MapZoneArray[i].maxz = *(float*)(buffer+28);
MapZoneArray[i].type = (eZoneType)*(int32*)(buffer+32);
MapZoneArray[i].level = (eLevelName)*(int32*)(buffer+36);
MapZoneArray[i].zoneinfoDay = *(int16*)(buffer+40);
MapZoneArray[i].zoneinfoNight = *(int16*)(buffer+42);
#ifdef STANDALONE
// BUG: GetPointerForZoneIndex uses ZoneArray
// so pointers will be unpredictable with different memory layout
assert(0);
#endif
MapZoneArray[i].child = GetPointerForZoneIndex(*(int32*)(buffer+44));
MapZoneArray[i].parent = GetPointerForZoneIndex(*(int32*)(buffer+48));
MapZoneArray[i].next = GetPointerForZoneIndex(*(int32*)(buffer+52));
buffer += 56;
}
for(i = 0; i < NUMAUDIOZONES; i++){ VALIDATESAVEBUF(size)
AudioZoneArray[i] = *(int16*)buffer;
buffer += 2;
}
TotalNumberOfMapZones = *(uint16*)(buffer);
NumberOfAudioZones = *(uint16*)(buffer+2);
} }