- Blood load/save works.

This commit is contained in:
Christoph Oelckers 2019-12-01 22:54:52 +01:00
parent eb668180c8
commit e743268c4b
10 changed files with 60 additions and 97 deletions

View file

@ -95,6 +95,8 @@ struct GameInterface : ::GameInterface
void StartGame(FGameStartup& gs) override; void StartGame(FGameStartup& gs) override;
void DrawNativeMenuText(int fontnum, int state, double xpos, double ypos, float fontscale, const char* text, int flags) override; void DrawNativeMenuText(int fontnum, int state, double xpos, double ypos, float fontscale, const char* text, int flags) override;
void DrawMenuCaption(const DVector2& origin, const char* text) override; void DrawMenuCaption(const DVector2& origin, const char* text) override;
bool SaveGame(FSaveGameNode*) override;
bool LoadGame(FSaveGameNode*) override;
}; };
END_BLD_NS END_BLD_NS

View file

@ -141,29 +141,22 @@ static std::unique_ptr<CGameMenuItemQAV> itemBloodQAV; // This must be global to
void UpdateNetworkMenus(void) void UpdateNetworkMenus(void)
{ {
// Kept as a reminder to reimplement later. // For now disable the network menu item as it is not yet functional.
#if 0 for (auto name : { NAME_MainMenu, NAME_IngameMenu })
if (gGameOptions.nGameType > 0)
{ {
itemMain1.resource = &menuNetStart; FMenuDescriptor** desc = MenuDescriptors.CheckKey(name);
itemMain1.data = 2; if (desc != NULL && (*desc)->mType == MDESC_ListMenu)
{
FListMenuDescriptor* ld = static_cast<FListMenuDescriptor*>(*desc);
for (auto& li : ld->mItems)
{
if (li->GetAction(nullptr) == NAME_MultiMenu)
{
li->mEnabled = false;
}
}
}
} }
else
{
itemMain1.resource = &menuEpisode;
itemMain1.data = -1;
}
if (gGameOptions.nGameType > 0)
{
itemMainSave1.resource = &menuNetStart;
itemMainSave1.data = 2;
}
else
{
itemMainSave1.resource = &menuEpisode;
itemMainSave1.data = -1;
}
#endif
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -181,7 +174,7 @@ protected:
void PostDraw() void PostDraw()
{ {
//itemBloodQAV->Draw(); itemBloodQAV->Draw();
} }
}; };

View file

@ -64,8 +64,6 @@ void ReadGameOptionsLegacy(GAMEOPTIONS &gameOptions, GAMEOPTIONSLEGACY &gameOpti
strcpy(gameOptions.zLevelName, gameOptionsLegacy.zLevelName); strcpy(gameOptions.zLevelName, gameOptionsLegacy.zLevelName);
strcpy(gameOptions.zLevelSong, gameOptionsLegacy.zLevelSong); strcpy(gameOptions.zLevelSong, gameOptionsLegacy.zLevelSong);
gameOptions.nTrackNumber = gameOptionsLegacy.nTrackNumber; gameOptions.nTrackNumber = gameOptionsLegacy.nTrackNumber;
strcpy(gameOptions.szSaveGameName, gameOptionsLegacy.szSaveGameName);
strcpy(gameOptions.szUserGameName, gameOptionsLegacy.szUserGameName);
gameOptions.nSaveGameSlot = gameOptionsLegacy.nSaveGameSlot; gameOptions.nSaveGameSlot = gameOptionsLegacy.nSaveGameSlot;
gameOptions.picEntry = gameOptionsLegacy.picEntry; gameOptions.picEntry = gameOptionsLegacy.picEntry;
gameOptions.uMapCRC = gameOptionsLegacy.uMapCRC; gameOptions.uMapCRC = gameOptionsLegacy.uMapCRC;

View file

@ -50,7 +50,7 @@ BEGIN_BLD_NS
GAMEOPTIONS gGameOptions; GAMEOPTIONS gGameOptions;
GAMEOPTIONS gSingleGameOptions = { GAMEOPTIONS gSingleGameOptions = {
0, 2, 0, 0, "", "", 2, "", "", 0, 0, 0, 1, 0, 0, 0, 0, 0, 2, 3600, 1800, 1800, 7200 0, 2, 0, 0, "", "", 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 2, 3600, 1800, 1800, 7200
}; };
EPISODEINFO gEpisodeInfo[kMaxEpisodes+1]; EPISODEINFO gEpisodeInfo[kMaxEpisodes+1];

View file

@ -41,8 +41,6 @@ struct GAMEOPTIONS {
char zLevelName[BMAX_PATH]; char zLevelName[BMAX_PATH];
char zLevelSong[BMAX_PATH]; char zLevelSong[BMAX_PATH];
int nTrackNumber; //at12a; int nTrackNumber; //at12a;
char szSaveGameName[BMAX_PATH];
char szUserGameName[BMAX_PATH];
short nSaveGameSlot; short nSaveGameSlot;
int picEntry; int picEntry;
unsigned int uMapCRC; unsigned int uMapCRC;

View file

@ -51,7 +51,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
BEGIN_BLD_NS BEGIN_BLD_NS
GAMEOPTIONS gSaveGameOptions[10];
char *gSaveGamePic[10]; char *gSaveGamePic[10];
unsigned int gSavedOffset = 0; unsigned int gSavedOffset = 0;
@ -101,7 +100,7 @@ void LoadSave::Write(void *pData, int nSize)
ThrowError("File error #%d writing save file.", errno); ThrowError("File error #%d writing save file.", errno);
} }
void LoadSave::LoadGame(const char *pzFile) bool GameInterface::LoadGame(FSaveGameNode* node)
{ {
bool demoWasPlayed = gDemo.at1; bool demoWasPlayed = gDemo.at1;
if (gDemo.at1) if (gDemo.at1)
@ -117,18 +116,18 @@ void LoadSave::LoadGame(const char *pzFile)
memset(sprite, 0, sizeof(spritetype)*kMaxSprites); memset(sprite, 0, sizeof(spritetype)*kMaxSprites);
automapping = 1; automapping = 1;
} }
OpenSaveGameForRead(pzFile); OpenSaveGameForRead(node->Filename);
hLFile = ReadSavegameChunk("snapshot.bld"); LoadSave::hLFile = ReadSavegameChunk("snapshot.bld");
if (!hLFile.isOpen()) if (!LoadSave::hLFile.isOpen())
ThrowError("Error loading save file."); return false;
LoadSave *rover = head.next; LoadSave *rover = LoadSave::head.next;
while (rover != &head) while (rover != &LoadSave::head)
{ {
rover->Load(); rover->Load();
rover = rover->next; rover = rover->next;
} }
hLFile.Close(); LoadSave::hLFile.Close();
FinishSavegameRead(); FinishSavegameRead();
if (!gGameStarted) if (!gGameStarted)
scrLoadPLUs(); scrLoadPLUs();
@ -182,30 +181,39 @@ void LoadSave::LoadGame(const char *pzFile)
netBroadcastPlayerInfo(myconnectindex); netBroadcastPlayerInfo(myconnectindex);
//sndPlaySong(gGameOptions.zLevelSong, 1); //sndPlaySong(gGameOptions.zLevelSong, 1);
return true;
} }
void LoadSave::SaveGame(const char *pzFile) bool GameInterface::SaveGame(FSaveGameNode* node)
{ {
OpenSaveGameForWrite(pzFile); OpenSaveGameForWrite(node->Filename);
hSFile = WriteSavegameChunk("snapshot.bld"); LoadSave::hSFile = WriteSavegameChunk("snapshot.bld");
if (hSFile == NULL)
ThrowError("File error #%d creating save file.", errno);
dword_27AA38 = 0;
dword_27AA40 = 0;
LoadSave *rover = head.next;
while (rover != &head)
{
rover->Save();
if (dword_27AA38 > dword_27AA40)
dword_27AA40 = dword_27AA38;
dword_27AA38 = 0;
rover = rover->next;
}
auto & li = gEpisodeInfo[gGameOptions.nEpisode].at28[gGameOptions.nLevel];
G_WriteSaveHeader(gGameOptions.szUserGameName, li.at0, li.at90);
FinishSavegameWrite(); try
hSFile = NULL; {
dword_27AA38 = 0;
dword_27AA40 = 0;
LoadSave* rover = LoadSave::head.next;
while (rover != &LoadSave::head)
{
rover->Save();
if (dword_27AA38 > dword_27AA40)
dword_27AA40 = dword_27AA38;
dword_27AA38 = 0;
rover = rover->next;
}
}
catch (std::runtime_error & err)
{
// Let's not abort for write errors.
Printf(TEXTCOLOR_RED "%s\n", err.what());
return false;
}
auto & li = gEpisodeInfo[gGameOptions.nEpisode].at28[gGameOptions.nLevel];
G_WriteSaveHeader(node->SaveTitle, FStringf("%s.map", li.at0), li.at90);
LoadSave::hSFile = NULL;
return FinishSavegameWrite();
} }
class MyLoadSave : public LoadSave class MyLoadSave : public LoadSave
@ -431,41 +439,6 @@ void MyLoadSave::Save(void)
void LoadSavedInfo(void) void LoadSavedInfo(void)
{ {
FString path = M_GetSavegamesPath() + "game*.sav";
TArray<FString> saves;
D_AddWildFile(saves, path);
int nCount = 0;
for (auto & savename : saves)
{
OpenSaveGameForRead(savename);
auto hFile = ReadSavegameChunk("snapshot.bld");
if (!hFile.isOpen())
{
FinishSavegameRead();
ThrowError("Error loading save file header.");
}
int vc;
short v4;
vc = 0;
v4 = word_27AA54;
if ((uint32_t)hFile.Read(&vc, sizeof(vc)) != sizeof(vc))
{
continue;
}
if (vc != 0x5653424e/*'VSBN'*/)
{
continue;
}
hFile.Read(&v4, sizeof(v4));
if (v4 != BYTEVERSION)
{
continue;
}
if ((uint32_t)hFile.Read(&gSaveGameOptions[nCount], sizeof(gSaveGameOptions[0])) != sizeof(gSaveGameOptions[0]))
ThrowError("Error reading save file.");
nCount++;
}
FinishSavegameRead();
} }
void UpdateSavedInfo(int nSlot) void UpdateSavedInfo(int nSlot)

View file

@ -24,6 +24,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <stdio.h> #include <stdio.h>
#include "levels.h" #include "levels.h"
struct FSavegameNode;
BEGIN_BLD_NS BEGIN_BLD_NS
class LoadSave { class LoadSave {
@ -49,12 +50,11 @@ public:
virtual void Load(void); virtual void Load(void);
void Read(void *, int); void Read(void *, int);
void Write(void *, int); void Write(void *, int);
static void LoadGame(const char *); static void LoadGame(FSavegameNode *);
static void SaveGame(const char *); static void SaveGame(FSavegameNode*);
}; };
extern unsigned int gSavedOffset; extern unsigned int gSavedOffset;
extern GAMEOPTIONS gSaveGameOptions[];
extern char *gSaveGamePic[10]; extern char *gSaveGamePic[10];
void UpdateSavedInfo(int nSlot); void UpdateSavedInfo(int nSlot);
void LoadSavedInfo(void); void LoadSavedInfo(void);

View file

@ -2032,8 +2032,6 @@ void SaveGame(CGameMenuItemZEditBitmap *pItem, CGameMenuEvent *event)
} }
FStringf basename("save%04d", nSlot); FStringf basename("save%04d", nSlot);
auto strSaveGameName = G_BuildSaveName(basename); auto strSaveGameName = G_BuildSaveName(basename);
strcpy(gGameOptions.szUserGameName, strRestoreGameStrings[nSlot]);
sprintf(gGameOptions.szSaveGameName, "%s", strSaveGameName.GetChars());
gGameOptions.nSaveGameSlot = nSlot; gGameOptions.nSaveGameSlot = nSlot;
viewLoadingScreen(2518, "Saving", "Saving Your Game", strRestoreGameStrings[nSlot]); viewLoadingScreen(2518, "Saving", "Saving Your Game", strRestoreGameStrings[nSlot]);
videoNextPage(); videoNextPage();

View file

@ -165,7 +165,7 @@ protected:
if (savegameManager.SavegameCount() > 0) if (savegameManager.SavegameCount() > 0)
{ {
if (Selected > savegameManager.SavegameCount()) Selected = 0; if (Selected >= savegameManager.SavegameCount()) Selected = 0;
FString text = (Selected == -1 || !savegameManager.GetSavegame(Selected)->bOldVersion) ? GStrings("MNU_NOPICTURE") : GStrings("MNU_DIFFVERSION"); FString text = (Selected == -1 || !savegameManager.GetSavegame(Selected)->bOldVersion) ? GStrings("MNU_NOPICTURE") : GStrings("MNU_DIFFVERSION");
int textlen = NewSmallFont->StringWidth(text) * CleanXfac; int textlen = NewSmallFont->StringWidth(text) * CleanXfac;

View file

@ -18,6 +18,7 @@ xx(Controlmessage)
xx(MainMenu) xx(MainMenu)
xx(IngameMenu) xx(IngameMenu)
xx(MultiMenu)
xx(HelpMenu) xx(HelpMenu)
xx(CreditsMenu) xx(CreditsMenu)
xx(SaveGameMenu) xx(SaveGameMenu)