mirror of
https://github.com/1dot13/source.git
synced 2026-09-16 14:47:17 +02:00
Fix: savegames could be corrupted due to storing implausible map changes
git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@9124 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
+136
-117
@@ -587,30 +587,31 @@ BOOLEAN LoadAllMapChangesFromMapTempFileAndApplyThem( )
|
|||||||
|
|
||||||
void AddStructToMapTempFile( INT32 uiMapIndex, UINT16 usIndex )
|
void AddStructToMapTempFile( INT32 uiMapIndex, UINT16 usIndex )
|
||||||
{
|
{
|
||||||
MODIFY_MAP Map;
|
if ( !gfApplyChangesToTempFile )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if ( gTacticalStatus.uiFlags & LOADING_SAVED_GAME )
|
||||||
|
return;
|
||||||
|
|
||||||
UINT32 uiType;
|
UINT32 uiType;
|
||||||
UINT16 usSubIndex;
|
UINT16 usSubIndex;
|
||||||
|
|
||||||
|
// Flugente: check whether this works, otherwise we'll save nonsense to the map and will likely crash upon reading it
|
||||||
|
if ( GetTileType( usIndex, &uiType )
|
||||||
|
&& GetSubIndexFromTileIndex( usIndex, &usSubIndex ) )
|
||||||
|
{
|
||||||
|
MODIFY_MAP Map;
|
||||||
|
memset( &Map, 0, sizeof( MODIFY_MAP ) );
|
||||||
|
|
||||||
if( !gfApplyChangesToTempFile )
|
Map.usGridNo = uiMapIndex;
|
||||||
return;
|
// Map.usIndex = usIndex;
|
||||||
|
Map.usImageType = (UINT16)uiType;
|
||||||
|
Map.usSubImageIndex = usSubIndex;
|
||||||
|
|
||||||
if( gTacticalStatus.uiFlags & LOADING_SAVED_GAME )
|
Map.ubType = SLM_STRUCT;
|
||||||
return;
|
|
||||||
|
|
||||||
GetTileType( usIndex, &uiType );
|
SaveModifiedMapStructToMapTempFile( &Map, gWorldSectorX, gWorldSectorY, gbWorldSectorZ );
|
||||||
GetSubIndexFromTileIndex( usIndex, &usSubIndex );
|
}
|
||||||
|
|
||||||
memset( &Map, 0, sizeof( MODIFY_MAP ) );
|
|
||||||
|
|
||||||
Map.usGridNo = uiMapIndex;
|
|
||||||
// Map.usIndex = usIndex;
|
|
||||||
Map.usImageType = (UINT16)uiType;
|
|
||||||
Map.usSubImageIndex = usSubIndex;
|
|
||||||
|
|
||||||
Map.ubType = SLM_STRUCT;
|
|
||||||
|
|
||||||
SaveModifiedMapStructToMapTempFile( &Map, gWorldSectorX, gWorldSectorY, gbWorldSectorZ );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -622,29 +623,31 @@ void AddStructFromMapTempFileToMap( INT32 uiMapIndex, UINT16 usIndex )
|
|||||||
|
|
||||||
void AddObjectToMapTempFile( INT32 uiMapIndex, UINT16 usIndex )
|
void AddObjectToMapTempFile( INT32 uiMapIndex, UINT16 usIndex )
|
||||||
{
|
{
|
||||||
MODIFY_MAP Map;
|
if ( !gfApplyChangesToTempFile )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if ( gTacticalStatus.uiFlags & LOADING_SAVED_GAME )
|
||||||
|
return;
|
||||||
|
|
||||||
UINT32 uiType;
|
UINT32 uiType;
|
||||||
UINT16 usSubIndex;
|
UINT16 usSubIndex;
|
||||||
|
|
||||||
if( !gfApplyChangesToTempFile )
|
// Flugente: check whether this works, otherwise we'll save nonsense to the map and will likely crash upon reading it
|
||||||
return;
|
if ( GetTileType( usIndex, &uiType )
|
||||||
|
&& GetSubIndexFromTileIndex( usIndex, &usSubIndex ) )
|
||||||
|
{
|
||||||
|
MODIFY_MAP Map;
|
||||||
|
memset( &Map, 0, sizeof( MODIFY_MAP ) );
|
||||||
|
|
||||||
if( gTacticalStatus.uiFlags & LOADING_SAVED_GAME )
|
Map.usGridNo = uiMapIndex;
|
||||||
return;
|
// Map.usIndex = usIndex;
|
||||||
|
Map.usImageType = (UINT16)uiType;
|
||||||
|
Map.usSubImageIndex = usSubIndex;
|
||||||
|
|
||||||
GetTileType( usIndex, &uiType );
|
Map.ubType = SLM_OBJECT;
|
||||||
GetSubIndexFromTileIndex( usIndex, &usSubIndex );
|
|
||||||
|
|
||||||
memset( &Map, 0, sizeof( MODIFY_MAP ) );
|
SaveModifiedMapStructToMapTempFile( &Map, gWorldSectorX, gWorldSectorY, gbWorldSectorZ );
|
||||||
|
}
|
||||||
Map.usGridNo = uiMapIndex;
|
|
||||||
// Map.usIndex = usIndex;
|
|
||||||
Map.usImageType = (UINT16)uiType;
|
|
||||||
Map.usSubImageIndex = usSubIndex;
|
|
||||||
|
|
||||||
Map.ubType = SLM_OBJECT;
|
|
||||||
|
|
||||||
SaveModifiedMapStructToMapTempFile( &Map, gWorldSectorX, gWorldSectorY, gbWorldSectorZ );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -665,19 +668,21 @@ void AddRemoveObjectToMapTempFile( INT32 uiMapIndex, UINT16 usIndex )
|
|||||||
if( gTacticalStatus.uiFlags & LOADING_SAVED_GAME )
|
if( gTacticalStatus.uiFlags & LOADING_SAVED_GAME )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
GetTileType( usIndex, &uiType );
|
// Flugente: check whether this works, otherwise we'll save nonsense to the map and will likely crash upon reading it
|
||||||
GetSubIndexFromTileIndex( usIndex, &usSubIndex );
|
if ( GetTileType( usIndex, &uiType )
|
||||||
|
&& GetSubIndexFromTileIndex( usIndex, &usSubIndex ) )
|
||||||
|
{
|
||||||
|
memset( &Map, 0, sizeof( MODIFY_MAP ) );
|
||||||
|
|
||||||
memset( &Map, 0, sizeof( MODIFY_MAP ) );
|
Map.usGridNo = uiMapIndex;
|
||||||
|
// Map.usIndex = usIndex;
|
||||||
|
Map.usImageType = (UINT16)uiType;
|
||||||
|
Map.usSubImageIndex = usSubIndex;
|
||||||
|
|
||||||
Map.usGridNo = uiMapIndex;
|
Map.ubType = SLM_REMOVE_OBJECT;
|
||||||
// Map.usIndex = usIndex;
|
|
||||||
Map.usImageType = (UINT16)uiType;
|
|
||||||
Map.usSubImageIndex = usSubIndex;
|
|
||||||
|
|
||||||
Map.ubType = SLM_REMOVE_OBJECT;
|
SaveModifiedMapStructToMapTempFile( &Map, gWorldSectorX, gWorldSectorY, gbWorldSectorZ );
|
||||||
|
}
|
||||||
SaveModifiedMapStructToMapTempFile( &Map, gWorldSectorX, gWorldSectorY, gbWorldSectorZ );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -693,19 +698,21 @@ void RemoveStructFromMapTempFile( INT32 uiMapIndex, UINT16 usIndex )
|
|||||||
if( gTacticalStatus.uiFlags & LOADING_SAVED_GAME )
|
if( gTacticalStatus.uiFlags & LOADING_SAVED_GAME )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
GetTileType( usIndex, &uiType );
|
// Flugente: check whether this works, otherwise we'll save nonsense to the map and will likely crash upon reading it
|
||||||
GetSubIndexFromTileIndex( usIndex, &usSubIndex );
|
if ( GetTileType( usIndex, &uiType )
|
||||||
|
&& GetSubIndexFromTileIndex( usIndex, &usSubIndex ) )
|
||||||
|
{
|
||||||
|
memset( &Map, 0, sizeof( MODIFY_MAP ) );
|
||||||
|
|
||||||
memset( &Map, 0, sizeof( MODIFY_MAP ) );
|
Map.usGridNo = uiMapIndex;
|
||||||
|
// Map.usIndex = usIndex;
|
||||||
|
Map.usImageType = (UINT16)uiType;
|
||||||
|
Map.usSubImageIndex = usSubIndex;
|
||||||
|
|
||||||
Map.usGridNo = uiMapIndex;
|
Map.ubType = SLM_REMOVE_STRUCT;
|
||||||
// Map.usIndex = usIndex;
|
|
||||||
Map.usImageType = (UINT16)uiType;
|
|
||||||
Map.usSubImageIndex = usSubIndex;
|
|
||||||
|
|
||||||
Map.ubType = SLM_REMOVE_STRUCT;
|
SaveModifiedMapStructToMapTempFile( &Map, gWorldSectorX, gWorldSectorY, gbWorldSectorZ );
|
||||||
|
}
|
||||||
SaveModifiedMapStructToMapTempFile( &Map, gWorldSectorX, gWorldSectorY, gbWorldSectorZ );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveRoofFromMapTempFile( INT32 uiMapIndex, UINT16 usIndex )
|
void RemoveRoofFromMapTempFile( INT32 uiMapIndex, UINT16 usIndex )
|
||||||
@@ -720,19 +727,21 @@ void RemoveRoofFromMapTempFile( INT32 uiMapIndex, UINT16 usIndex )
|
|||||||
if ( gTacticalStatus.uiFlags & LOADING_SAVED_GAME )
|
if ( gTacticalStatus.uiFlags & LOADING_SAVED_GAME )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
GetTileType( usIndex, &uiType );
|
// Flugente: check whether this works, otherwise we'll save nonsense to the map and will likely crash upon reading it
|
||||||
GetSubIndexFromTileIndex( usIndex, &usSubIndex );
|
if ( GetTileType( usIndex, &uiType )
|
||||||
|
&& GetSubIndexFromTileIndex( usIndex, &usSubIndex ) )
|
||||||
|
{
|
||||||
|
memset( &Map, 0, sizeof( MODIFY_MAP ) );
|
||||||
|
|
||||||
memset( &Map, 0, sizeof(MODIFY_MAP) );
|
Map.usGridNo = uiMapIndex;
|
||||||
|
// Map.usIndex = usIndex;
|
||||||
|
Map.usImageType = (UINT16)uiType;
|
||||||
|
Map.usSubImageIndex = usSubIndex;
|
||||||
|
|
||||||
Map.usGridNo = uiMapIndex;
|
Map.ubType = SLM_REMOVE_ROOF;
|
||||||
// Map.usIndex = usIndex;
|
|
||||||
Map.usImageType = (UINT16)uiType;
|
|
||||||
Map.usSubImageIndex = usSubIndex;
|
|
||||||
|
|
||||||
Map.ubType = SLM_REMOVE_ROOF;
|
SaveModifiedMapStructToMapTempFile( &Map, gWorldSectorX, gWorldSectorY, gbWorldSectorZ );
|
||||||
|
}
|
||||||
SaveModifiedMapStructToMapTempFile( &Map, gWorldSectorX, gWorldSectorY, gbWorldSectorZ );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveOnRoofFromMapTempFile( INT32 uiMapIndex, UINT16 usIndex )
|
void RemoveOnRoofFromMapTempFile( INT32 uiMapIndex, UINT16 usIndex )
|
||||||
@@ -747,19 +756,21 @@ void RemoveOnRoofFromMapTempFile( INT32 uiMapIndex, UINT16 usIndex )
|
|||||||
if ( gTacticalStatus.uiFlags & LOADING_SAVED_GAME )
|
if ( gTacticalStatus.uiFlags & LOADING_SAVED_GAME )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
GetTileType( usIndex, &uiType );
|
// Flugente: check whether this works, otherwise we'll save nonsense to the map and will likely crash upon reading it
|
||||||
GetSubIndexFromTileIndex( usIndex, &usSubIndex );
|
if ( GetTileType( usIndex, &uiType )
|
||||||
|
&& GetSubIndexFromTileIndex( usIndex, &usSubIndex ) )
|
||||||
|
{
|
||||||
|
memset( &Map, 0, sizeof( MODIFY_MAP ) );
|
||||||
|
|
||||||
memset( &Map, 0, sizeof(MODIFY_MAP) );
|
Map.usGridNo = uiMapIndex;
|
||||||
|
// Map.usIndex = usIndex;
|
||||||
|
Map.usImageType = (UINT16)uiType;
|
||||||
|
Map.usSubImageIndex = usSubIndex;
|
||||||
|
|
||||||
Map.usGridNo = uiMapIndex;
|
Map.ubType = SLM_REMOVE_ONROOF;
|
||||||
// Map.usIndex = usIndex;
|
|
||||||
Map.usImageType = (UINT16)uiType;
|
|
||||||
Map.usSubImageIndex = usSubIndex;
|
|
||||||
|
|
||||||
Map.ubType = SLM_REMOVE_ONROOF;
|
SaveModifiedMapStructToMapTempFile( &Map, gWorldSectorX, gWorldSectorY, gbWorldSectorZ );
|
||||||
|
}
|
||||||
SaveModifiedMapStructToMapTempFile( &Map, gWorldSectorX, gWorldSectorY, gbWorldSectorZ );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1161,20 +1172,22 @@ void AddStructToUnLoadedMapTempFile( INT32 uiMapIndex, UINT16 usIndex, INT16 sSe
|
|||||||
if( gTacticalStatus.uiFlags & LOADING_SAVED_GAME )
|
if( gTacticalStatus.uiFlags & LOADING_SAVED_GAME )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
GetTileType( usIndex, &uiType );
|
// Flugente: check whether this works, otherwise we'll save nonsense to the map and will likely crash upon reading it
|
||||||
GetSubIndexFromTileIndex( usIndex, &usSubIndex );
|
if ( GetTileType( usIndex, &uiType )
|
||||||
|
&& GetSubIndexFromTileIndex( usIndex, &usSubIndex ) )
|
||||||
|
{
|
||||||
|
memset( &Map, 0, sizeof( MODIFY_MAP ) );
|
||||||
|
|
||||||
memset( &Map, 0, sizeof( MODIFY_MAP ) );
|
Map.usGridNo = uiMapIndex;
|
||||||
|
// Map.usIndex = usIndex;
|
||||||
Map.usGridNo = uiMapIndex;
|
Map.usImageType = (UINT16)uiType;
|
||||||
// Map.usIndex = usIndex;
|
Map.usSubImageIndex = usSubIndex;
|
||||||
Map.usImageType = (UINT16)uiType;
|
|
||||||
Map.usSubImageIndex = usSubIndex;
|
|
||||||
|
|
||||||
|
|
||||||
Map.ubType = SLM_STRUCT;
|
Map.ubType = SLM_STRUCT;
|
||||||
|
|
||||||
SaveModifiedMapStructToMapTempFile( &Map, sSectorX, sSectorY, ubSectorZ );
|
SaveModifiedMapStructToMapTempFile( &Map, sSectorX, sSectorY, ubSectorZ );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddObjectToUnLoadedMapTempFile( INT32 uiMapIndex, UINT16 usIndex, INT16 sSectorX, INT16 sSectorY, UINT8 ubSectorZ )
|
void AddObjectToUnLoadedMapTempFile( INT32 uiMapIndex, UINT16 usIndex, INT16 sSectorX, INT16 sSectorY, UINT8 ubSectorZ )
|
||||||
@@ -1186,19 +1199,21 @@ void AddObjectToUnLoadedMapTempFile( INT32 uiMapIndex, UINT16 usIndex, INT16 sSe
|
|||||||
if( gTacticalStatus.uiFlags & LOADING_SAVED_GAME )
|
if( gTacticalStatus.uiFlags & LOADING_SAVED_GAME )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
GetTileType( usIndex, &uiType );
|
// Flugente: check whether this works, otherwise we'll save nonsense to the map and will likely crash upon reading it
|
||||||
GetSubIndexFromTileIndex( usIndex, &usSubIndex );
|
if ( GetTileType( usIndex, &uiType )
|
||||||
|
&& GetSubIndexFromTileIndex( usIndex, &usSubIndex ) )
|
||||||
|
{
|
||||||
|
memset( &Map, 0, sizeof( MODIFY_MAP ) );
|
||||||
|
|
||||||
memset( &Map, 0, sizeof( MODIFY_MAP ) );
|
Map.usGridNo = uiMapIndex;
|
||||||
|
// Map.usIndex = usIndex;
|
||||||
|
Map.usImageType = (UINT16)uiType;
|
||||||
|
Map.usSubImageIndex = usSubIndex;
|
||||||
|
|
||||||
Map.usGridNo = uiMapIndex;
|
Map.ubType = SLM_OBJECT;
|
||||||
// Map.usIndex = usIndex;
|
|
||||||
Map.usImageType = (UINT16)uiType;
|
|
||||||
Map.usSubImageIndex = usSubIndex;
|
|
||||||
|
|
||||||
Map.ubType = SLM_OBJECT;
|
SaveModifiedMapStructToMapTempFile( &Map, sSectorX, sSectorY, ubSectorZ );
|
||||||
|
}
|
||||||
SaveModifiedMapStructToMapTempFile( &Map, sSectorX, sSectorY, ubSectorZ );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1211,19 +1226,21 @@ void RemoveStructFromUnLoadedMapTempFile( INT32 uiMapIndex, UINT16 usIndex, INT1
|
|||||||
if( gTacticalStatus.uiFlags & LOADING_SAVED_GAME )
|
if( gTacticalStatus.uiFlags & LOADING_SAVED_GAME )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
GetTileType( usIndex, &uiType );
|
// Flugente: check whether this works, otherwise we'll save nonsense to the map and will likely crash upon reading it
|
||||||
GetSubIndexFromTileIndex( usIndex, &usSubIndex );
|
if ( GetTileType( usIndex, &uiType )
|
||||||
|
&& GetSubIndexFromTileIndex( usIndex, &usSubIndex ) )
|
||||||
|
{
|
||||||
|
memset( &Map, 0, sizeof( MODIFY_MAP ) );
|
||||||
|
|
||||||
memset( &Map, 0, sizeof( MODIFY_MAP ) );
|
Map.usGridNo = uiMapIndex;
|
||||||
|
// Map.usIndex = usIndex;
|
||||||
|
Map.usImageType = (UINT16)uiType;
|
||||||
|
Map.usSubImageIndex = usSubIndex;
|
||||||
|
|
||||||
Map.usGridNo = uiMapIndex;
|
Map.ubType = SLM_REMOVE_STRUCT;
|
||||||
// Map.usIndex = usIndex;
|
|
||||||
Map.usImageType = (UINT16)uiType;
|
|
||||||
Map.usSubImageIndex = usSubIndex;
|
|
||||||
|
|
||||||
Map.ubType = SLM_REMOVE_STRUCT;
|
SaveModifiedMapStructToMapTempFile( &Map, sSectorX, sSectorY, ubSectorZ );
|
||||||
|
}
|
||||||
SaveModifiedMapStructToMapTempFile( &Map, sSectorX, sSectorY, ubSectorZ );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1236,19 +1253,21 @@ void AddRemoveObjectToUnLoadedMapTempFile( INT32 uiMapIndex, UINT16 usIndex, INT
|
|||||||
if( gTacticalStatus.uiFlags & LOADING_SAVED_GAME )
|
if( gTacticalStatus.uiFlags & LOADING_SAVED_GAME )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
GetTileType( usIndex, &uiType );
|
// Flugente: check whether this works, otherwise we'll save nonsense to the map and will likely crash upon reading it
|
||||||
GetSubIndexFromTileIndex( usIndex, &usSubIndex );
|
if ( GetTileType( usIndex, &uiType )
|
||||||
|
&& GetSubIndexFromTileIndex( usIndex, &usSubIndex ) )
|
||||||
|
{
|
||||||
|
memset( &Map, 0, sizeof( MODIFY_MAP ) );
|
||||||
|
|
||||||
memset( &Map, 0, sizeof( MODIFY_MAP ) );
|
Map.usGridNo = uiMapIndex;
|
||||||
|
// Map.usIndex = usIndex;
|
||||||
|
Map.usImageType = (UINT16)uiType;
|
||||||
|
Map.usSubImageIndex = usSubIndex;
|
||||||
|
|
||||||
Map.usGridNo = uiMapIndex;
|
Map.ubType = SLM_REMOVE_OBJECT;
|
||||||
// Map.usIndex = usIndex;
|
|
||||||
Map.usImageType = (UINT16)uiType;
|
|
||||||
Map.usSubImageIndex = usSubIndex;
|
|
||||||
|
|
||||||
Map.ubType = SLM_REMOVE_OBJECT;
|
SaveModifiedMapStructToMapTempFile( &Map, sSectorX, sSectorY, ubSectorZ );
|
||||||
|
}
|
||||||
SaveModifiedMapStructToMapTempFile( &Map, sSectorX, sSectorY, ubSectorZ );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user