Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix corrupted files #325

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions neo/d3xp/Game_local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1345,9 +1345,10 @@ bool idGameLocal::InitFromSaveGame( const char* mapName, idRenderWorld* renderWo

int i_skill;
idStr first_decl_string;
idStr second_decl_string;

// Load the idProgram, also checking to make sure scripting hasn't changed since the savegame
if( program.Restore( &savegame, i_skill, first_decl_string) == false )
if( program.Restore( &savegame, i_skill, first_decl_string, second_decl_string) == false )
{
// Carl: Keep loading even if the scripts have changed since we saved.
loadScriptFailed = true;
Expand All @@ -1371,11 +1372,14 @@ bool idGameLocal::InitFromSaveGame( const char* mapName, idRenderWorld* renderWo
return false;
#endif
}

if (i_skill < 0 || i_skill>4)
{
Error("Critical error while loading save game.", num);
}
g_skill.SetInteger( i_skill );

// precache any media specified in the map
savegame.ReadDecls( first_decl_string );
savegame.ReadDecls( first_decl_string, second_decl_string);

savegame.ReadDict( &si );
SetServerInfo( si );
Expand Down Expand Up @@ -5552,20 +5556,21 @@ bool idGameLocal::IsPortalSkyAcive()
idGameLocal::SelectTimeGroup
============
*/
void idGameLocal::SelectTimeGroup( int timeGroup )
void idGameLocal::SelectTimeGroup(int timeGroup)
{
if( timeGroup )
// Koz: VR: We still render frames when game is paused. Make sure the 'fast' (player) timegroup is selected during pause.
// This prevents issues with player animation timing in pause.
// Nothing in the slow timegroup should change during pause.
if (timeGroup || (commonVr->VR_GAME_PAUSED && commonVr->PDAforced))
{
fast.Get( time, previousTime, realClientTime );
fast.Get(time, previousTime, realClientTime);
}
else
{
slow.Get( time, previousTime, realClientTime );
slow.Get(time, previousTime, realClientTime);
}

selectedGroup = timeGroup;
}

/*
===========
idGameLocal::GetTimeGroupTime
Expand Down
2 changes: 1 addition & 1 deletion neo/d3xp/Game_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class idEntityPtr
int GetEntityNum() const;

private:
int spawnId;
int spawnId = 0;
};

struct timeState_t
Expand Down
8 changes: 8 additions & 0 deletions neo/d3xp/Sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,14 @@ void idSound::DoSound( bool play )
{
if( play )
{
if (refSound.shader == NULL) {
//Npi : fix #231 : can't found where this refSound was created, it comes from an event but shader is null, in creator of refSound it's possible to create a refsound with shader null, so avoid a crash, skip it and warn only
common->Printf("WARNING: DoSound(true) with a refSound.shader == NULL. (%s)\n", name.c_str()); //Npi debug
idSphere tempSphere(refSound.origin, 75);
gameRenderWorld->DebugSphere(colorRed, tempSphere, 2000, true);
playingUntilTime = 0;
return;
}
if( Flicksync_Speaker( name.c_str(), refSound.shader->base->GetName(), refSound.shader->GetLength() * 10000 ) )
StartSoundShader( refSound.shader, SND_CHANNEL_ANY, refSound.parms.soundShaderFlags, true, &playingUntilTime );
playingUntilTime += gameLocal.time;
Expand Down
56 changes: 41 additions & 15 deletions neo/d3xp/gamesys/SaveGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ idSaveGame::WriteDecls
*/
void idSaveGame::WriteDecls()
{
//int start = file->Tell();
// Write out all loaded decls
for( int t = 0; t < declManager->GetNumDeclTypes(); t++ )
{
Expand All @@ -159,9 +160,11 @@ void idSaveGame::WriteDecls()
continue;
}
WriteString( declName );
//common->Printf("WriteDecls # %d name %s\n", t, declName);
}
WriteString( 0 );
}
//common->Printf("idSaveGame::WriteDecls %d bytes, @%d\n", file->Tell() - start, start); //Npi debug
}

/*
Expand All @@ -171,11 +174,14 @@ idSaveGame::WriteObjectList
*/
void idSaveGame::WriteObjectList()
{
//int start = file->Tell();
//common->Printf("idSaveGame::WriteObjectList() start num=%d @%d\n", objects.Num() - 1, file->Tell()); //Npi debug
WriteInt( objects.Num() - 1 );
for( int i = 1; i < objects.Num(); i++ )
{
WriteString( objects[ i ]->GetClassname() );
}
//common->Printf("idSaveGame::WriteObjectList %d bytes, @%d\n", file->Tell() - start, start); //Npi debug
}

/*
Expand Down Expand Up @@ -451,20 +457,25 @@ void idSaveGame::WriteDict( const idDict* dict )
int num;
int i;
const idKeyValue* kv;

//int posi = file->Tell();

if( !dict )
{
WriteInt( -1 );
//common->Printf("idSaveGame::WriteDict num(-1) dict @%d\n", posi); //Npi debug
}
else
{
num = dict->GetNumKeyVals();
//common->Printf("idSaveGame::WriteDict num(%d) dict @%d\n", num, posi); //Npi debug
WriteInt( num );
for( i = 0; i < num; i++ )
{
//posi = file->Tell();
kv = dict->GetKeyVal( i );
WriteString( kv->GetKey() );
WriteString( kv->GetValue() );
//common->Printf("idSaveGame::WriteDict #%d %s=%s @%d\n", i, kv->GetKey().c_str(), kv->GetValue().c_str(), posi); //Npi debug
}
}
}
Expand Down Expand Up @@ -955,12 +966,13 @@ idRestoreGame::ReadDecls
================
Carl: We already read the first declName in the list while reading the script variables.
*/
void idRestoreGame::ReadDecls( idStr& first_decl_string )
void idRestoreGame::ReadDecls( idStr& first_decl_string, idStr& second_decl_string)
{
idStr declName;
bool first = true;
int start = file->Tell() - 4;
common->Printf("idRestoreGame::ReadDecls() start, num=%d, %d\n", declManager->GetNumDeclTypes(), start); //Carl debug
bool second = false;
//int start = file->Tell() - 4;
//common->Printf("idRestoreGame::ReadDecls() start, num=%d, %d\n", declManager->GetNumDeclTypes(), start); //Carl debug
for( int t = 0; t < declManager->GetNumDeclTypes(); t++ )
{
while( true )
Expand All @@ -969,21 +981,27 @@ void idRestoreGame::ReadDecls( idStr& first_decl_string )
{
declName = first_decl_string;
first = false;
second = true;
}
else if (second)
{
declName = second_decl_string;
second = false;
}
else
{
ReadString(declName);
}
if( declName.IsEmpty() )
{
//common->Printf("Empty, breaking.\n");
//common->Printf("ReadDecls Empty, breaking.\n");
break;
}
//common->Printf("Decln # %d name %s\n", t, declName.c_str());
//common->Printf("ReadDecls # %d name %s\n", t, declName.c_str());
declManager->FindType( ( declType_t )t, declName );
}
}
common->Printf("idRestoreGame::ReadDecls() %d bytes, %d\n", file->Tell() - start, start); //Carl debug
//common->Printf("idRestoreGame::ReadDecls() %d bytes, @%d\n", file->Tell() - start, start); //Carl debug
}

/*
Expand Down Expand Up @@ -1444,32 +1462,40 @@ void idRestoreGame::ReadStaticObject( idClass& obj )
idRestoreGame::ReadDict
================
*/
void idRestoreGame::ReadDict( idDict* dict )
void idRestoreGame::ReadDict(idDict* dict)
{
//int start = file->Tell(); //Carl debug
int start = file->Tell(); //Carl debug
int num;
int i;
idStr key;
idStr value;

ReadInt( num );

if( num < 0 )

ReadInt(num);
//common->Printf("idRestoreGame::ReadDict() num=%d @%d\n", num, start); //Npi debug

if (num < 0)
{
dict = NULL;
}
else
else if (num > MAX_DICT_ELEMENTS)
{
dict = NULL;
Error("idRestoreGame::ReadDict: Wrong number of dict read from save game (%d).", num);
}
else
{
dict->Clear();
for( i = 0; i < num; i++ )
{
int posi = file->Tell(); //Carl debug
ReadString( key );
ReadString( value );
dict->Set( key, value );
//common->Printf("idRestoreGame::ReadDict() %s = %s @%d\n", key, value, posi); //Npi debug
}
}
//int end = file->Tell();
//common->Printf(" ReadDict() %d bytes, %d\n", end-start, start); //Carl debug
//common->Printf("idRestoreGame::ReadDict() %d bytes, @%d\n", end-start, start); //Carl debug
//dict->Print();
}

Expand Down
10 changes: 6 additions & 4 deletions neo/d3xp/gamesys/SaveGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ If you have questions concerning this license or the applicable additional terms
#ifndef __SAVEGAME_H__
#define __SAVEGAME_H__

const int MAX_DICT_ELEMENTS = 0x1FFFF;

/*

Save game related helper classes.

*/

class idSaveGame
{
public:
Expand Down Expand Up @@ -102,10 +103,11 @@ class idSaveGame
{
return file->Length();
}

private:
public:
idFile* file;
idFile* stringFile;

private:
idCompressor* compressor;

idList<const idClass*> objects;
Expand All @@ -131,7 +133,7 @@ class idRestoreGame
idRestoreGame( idFile* savefile, idFile* stringTableFile, int saveVersion );
~idRestoreGame();

void ReadDecls( idStr& first_decl_string );
void ReadDecls( idStr& first_decl_string, idStr& second_decl_string);

void CreateObjects();
void RestoreObjects();
Expand Down
Loading