Enable the Load Game menu

This commit is contained in:
Lephenixnoir 2021-09-18 19:31:24 +02:00
parent db04c99446
commit f13aeb14e7
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
4 changed files with 104 additions and 10 deletions

View File

@ -921,12 +921,69 @@ void G_DoWorldDone (void)
extern boolean setsizeneeded;
void R_ExecuteSetViewSize (void);
#define VERSIONSIZE 16
char savename[256];
void G_LoadGame (char* name)
{
CGDstrcpy (savename, name);
gameaction = ga_loadgame;
}
#define VERSIONSIZE 16
void G_DoLoadGame (void)
{
}
int length;
int i;
int a,b,c;
char vcheck[VERSIONSIZE];
gameaction = ga_nothing;
length = M_ReadFile (savename, &savebuffer);
I_ReinitAfterError();
save_p = savebuffer + SAVESTRINGSIZE;
if (length < 0)
return;
// skip the description field
memset (vcheck,0,sizeof(vcheck));
sprintf (vcheck,"version %i",VERSION);
if (strcmp ((const char *)save_p, vcheck))
return; // bad version
save_p += VERSIONSIZE;
gameskill = *save_p++;
gameepisode = *save_p++;
gamemap = *save_p++;
for (i=0 ; i<MAXPLAYERS ; i++)
playeringame[i] = *save_p++;
// load a base level
G_InitNew (gameskill, gameepisode, gamemap);
// get the times
a = *save_p++;
b = *save_p++;
c = *save_p++;
leveltime = (a<<16) + (b<<8) + c;
// dearchive all the modifications
P_UnArchivePlayers ();
P_UnArchiveWorld ();
P_UnArchiveThinkers ();
P_UnArchiveSpecials ();
if (*save_p != 0x1d)
I_Error ("Bad savegame");
// done
Z_Free (savebuffer);
if (setsizeneeded)
R_ExecuteSetViewSize ();
}
//

View File

@ -49,6 +49,7 @@ void G_DeferedPlayDemo (char* demo);
void G_DoLoadGame (void);
// Called by M_Responder.
void G_LoadGame (char* name);
void G_SaveGame (int slot, char* description);
void G_TimeDemo (char* name);

View File

@ -531,15 +531,10 @@ void M_DrawSaveLoadBorder(int x,int y)
//
void M_LoadSelect(int choice)
{
(void)choice;
/* char name[256];
if (M_CheckParm("-cdrom"))
sprintf(name,"c:\\doomdata\\"SAVEGAMENAME"%d.dsg",choice);
else
sprintf(name,SAVEGAMENAME"%d.dsg",choice);
char name[64];
sprintf(name, SAVEGAMENAME "%d.dsg", choice);
G_LoadGame (name);
M_ClearMenus (); */
M_ClearMenus ();
}
//
@ -547,6 +542,8 @@ void M_LoadSelect(int choice)
//
void M_LoadGame(int choice)
{
(void)choice;
if (netgame)
{
M_StartMessage(LOADNET,NULL,false);

View File

@ -121,6 +121,45 @@ boolean M_WriteFile(char const *name, void *source, int length)
return true;
}
//
// M_ReadFile
//
int M_ReadFile(const char *name, byte **buffer)
{
uint16_t fc_path[100] = u"\\\\fls0\\";
int j = 7;
int fd;
for (int i = 0; name[i]; i++)
fc_path[j++] = name[i];
fc_path[j++] = 0x0000;
fd = Bfile_OpenFile_OS(fc_path, READ, 0);
if (fd < 0) {
I_Error("Bfile_OpenFile_OS(%s): %d", name, fd);
return -1;
}
int size = Bfile_GetFileSize_OS(fd);
if (size <= 0) {
I_Error("Bfile_GetFileSize_OS(%s): %d", name, size);
Bfile_CloseFile_OS(fd);
return -1;
}
void *buf = Z_Malloc(size, PU_STATIC, NULL);
if (!buf) {
Bfile_CloseFile_OS(fd);
return -1;
}
Bfile_ReadFile_OS(fd, buf, size, -1);
Bfile_CloseFile_OS(fd);
*buffer = buf;
return size;
}
//
// DEFAULTS
//