Fix reading demo file

# Conflicts:
#	source/exhumed/src/exhumed.cpp
This commit is contained in:
nukeykt 2019-12-03 04:28:02 +09:00 committed by Christoph Oelckers
parent 7a7a0e16e8
commit 75789eee50
4 changed files with 108 additions and 40 deletions

View file

@ -1441,6 +1441,10 @@ void FinishLevel()
} }
} }
EDUKE32_STATIC_ASSERT(sizeof(demo_header) == 75);
EDUKE32_STATIC_ASSERT(sizeof(demo_input) == 36);
void WritePlaybackInputs() void WritePlaybackInputs()
{ {
fwrite(&moveframes, sizeof(moveframes), 1, vcrfp); fwrite(&moveframes, sizeof(moveframes), 1, vcrfp);
@ -1449,43 +1453,20 @@ void WritePlaybackInputs()
uint8_t ReadPlaybackInputs() uint8_t ReadPlaybackInputs()
{ {
assert(sizeof(PlayerInput) == 32); demo_input input;
if (fread(&input, 1, sizeof(input), vcrfp))
if (fread(&moveframes, 1, sizeof(moveframes), vcrfp))
{ {
#if 0 moveframes = input.moveframes;
fread(&sPlayerInput[nLocalPlayer], 1, sizeof(PlayerInput), vcrfp); sPlayerInput[nLocalPlayer].xVel = input.xVel;
#else sPlayerInput[nLocalPlayer].yVel = input.yVel;
/* sPlayerInput[nLocalPlayer].nAngle = fix16_from_int(input.nAngle<<2);
struct PlayerInput sPlayerInput[nLocalPlayer].buttons = input.buttons;
{ sPlayerInput[nLocalPlayer].nTarget = input.nTarget;
int xVel; sPlayerInput[nLocalPlayer].horizon = fix16_from_int(input.horizon);
int yVel; sPlayerInput[nLocalPlayer].nItem = input.nItem;
short nAngle; sPlayerInput[nLocalPlayer].h = input.h;
short buttons; sPlayerInput[nLocalPlayer].i = input.i;
short nTarget;
char horizon;
int8_t nItem;
int h;
char i;
char field_15[11];
};
*/
fread(&sPlayerInput[nLocalPlayer].xVel, 1, sizeof(sPlayerInput[nLocalPlayer].xVel), vcrfp);
fread(&sPlayerInput[nLocalPlayer].yVel, 1, sizeof(sPlayerInput[nLocalPlayer].yVel), vcrfp);
fread(&sPlayerInput[nLocalPlayer].nAngle, 1, sizeof(sPlayerInput[nLocalPlayer].nAngle), vcrfp);
fread(&sPlayerInput[nLocalPlayer].buttons, 1, sizeof(sPlayerInput[nLocalPlayer].buttons), vcrfp);
fread(&sPlayerInput[nLocalPlayer].nTarget, 1, sizeof(sPlayerInput[nLocalPlayer].nTarget), vcrfp);
fread(&sPlayerInput[nLocalPlayer].horizon, 1, sizeof(sPlayerInput[nLocalPlayer].horizon), vcrfp);
fread(&sPlayerInput[nLocalPlayer].nItem, 1, sizeof(sPlayerInput[nLocalPlayer].nItem), vcrfp);
fread(&sPlayerInput[nLocalPlayer].h, 1, sizeof(sPlayerInput[nLocalPlayer].h), vcrfp);
fread(&sPlayerInput[nLocalPlayer].i, 1, sizeof(sPlayerInput[nLocalPlayer].i), vcrfp);
// skip pad
fseek(vcrfp, 11, SEEK_CUR);
#endif
besttarget = sPlayerInput[nLocalPlayer].nTarget; besttarget = sPlayerInput[nLocalPlayer].nTarget;
Ra[nLocalPlayer].nTarget = besttarget; Ra[nLocalPlayer].nTarget = besttarget;
return kTrue; return kTrue;
@ -2149,7 +2130,7 @@ STARTGAME2:
if (bPlayback) if (bPlayback)
{ {
menu_GameLoad2(vcrfp); menu_GameLoad2(vcrfp, true);
levelnew = GameStats.nMap; levelnew = GameStats.nMap;
levelnum = GameStats.nMap; levelnum = GameStats.nMap;
forcelevel = GameStats.nMap; forcelevel = GameStats.nMap;
@ -2327,7 +2308,7 @@ LOOP3:
if (bPlayback) if (bPlayback)
{ {
// YELLOW // YELLOW
if ((bInDemo && inputState.keyBufferWaiting() || !ReadPlaybackInputs()) && inputState.keyGetChar()) if (((bInDemo && inputState.keyBufferWaiting()) || !ReadPlaybackInputs()) && inputState.keyGetChar())
{ {
inputState.keyFlushChars(); inputState.keyFlushChars();
inputState.ClearAllKeyStatus(); inputState.ClearAllKeyStatus();

View file

@ -43,6 +43,58 @@ enum basepal_t {
BASEPALCOUNT BASEPALCOUNT
}; };
#pragma pack(push, 1)
struct demo_header
{
uint8_t nMap;
int16_t nWeapons;
int16_t nCurrentWeapon;
int16_t clip;
int16_t items;
int16_t nHealth;
int16_t field_2;
int16_t nAction;
int16_t nSprite;
int16_t bIsMummified;
int16_t someNetVal;
int16_t invincibility;
int16_t nAir;
int16_t nSeq;
int16_t nMaskAmount;
uint16_t keys;
int16_t nMagic;
uint8_t item[8];
int16_t nAmmo[7]; // TODO - kMaxWeapons?
int16_t pad[2];
int16_t nCurrentWeapon2;
int16_t field_3FOUR;
int16_t bIsFiring;
int16_t field_38;
int16_t field_3A;
int16_t field_3C;
int16_t nRun;
int16_t nLives;
};
struct demo_input
{
int32_t moveframes;
int32_t xVel;
int32_t yVel;
int16_t nAngle;
uint16_t buttons;
int16_t nTarget;
uint8_t horizon;
int8_t nItem;
int32_t h;
uint8_t i;
uint8_t pad[11];
};
#pragma pack(pop)
void ShutDown(void); void ShutDown(void);
void DebugOut(const char *fmt, ...); void DebugOut(const char *fmt, ...);
int ExhumedMain(int argc, char *argv[]); int ExhumedMain(int argc, char *argv[]);

View file

@ -1374,9 +1374,44 @@ void menu_ResetKeyTimer()
keytimer = (int)totalclock + 2400; keytimer = (int)totalclock + 2400;
} }
void menu_GameLoad2(FILE *fp) void menu_GameLoad2(FILE *fp, bool bIsDemo)
{ {
fread(&GameStats, sizeof(GameStats), 1, fp); if (bIsDemo)
{
demo_header header;
fread(&header, 1, sizeof(demo_header), fp);
GameStats.nMap = header.nMap;
GameStats.nWeapons = header.nWeapons;
GameStats.nCurrentWeapon = header.nCurrentWeapon;
GameStats.clip = header.clip;
GameStats.items = header.items;
GameStats.player.nHealth = header.nHealth;
GameStats.player.field_2 = header.field_2;
GameStats.player.nAction = header.nAction;
GameStats.player.nSprite = header.nSprite;
GameStats.player.bIsMummified = header.bIsMummified;
GameStats.player.someNetVal = header.someNetVal;
GameStats.player.invincibility = header.invincibility;
GameStats.player.nAir = header.nAir;
GameStats.player.nSeq = header.nSeq;
GameStats.player.nMaskAmount = header.nMaskAmount;
GameStats.player.keys = header.keys;
GameStats.player.nMagic = header.nMagic;
Bmemcpy(GameStats.player.items, header.item, sizeof(header.item));
Bmemcpy(GameStats.player.nAmmo, header.nAmmo, sizeof(header.nAmmo));
Bmemcpy(GameStats.player.pad, header.pad, sizeof(header.pad));
GameStats.player.nCurrentWeapon = header.nCurrentWeapon2;
GameStats.player.field_3FOUR = header.field_3FOUR;
GameStats.player.bIsFiring = header.bIsFiring;
GameStats.player.field_38 = header.field_38;
GameStats.player.field_3A = header.field_3A;
GameStats.player.field_3C = header.field_3C;
GameStats.player.nRun = header.nRun;
GameStats.nLives = header.nLives;
}
else
fread(&GameStats, sizeof(GameStats), 1, fp);
nPlayerWeapons[nLocalPlayer] = GameStats.nWeapons; nPlayerWeapons[nLocalPlayer] = GameStats.nWeapons;

View file

@ -54,7 +54,7 @@ void menu_DoPlasma();
int menu_Menu(int val); int menu_Menu(int val);
void menu_AdjustVolume(); void menu_AdjustVolume();
short menu_GameLoad(int nSlot); short menu_GameLoad(int nSlot);
void menu_GameLoad2(FILE *fp); void menu_GameLoad2(FILE *fp, bool bIsDemo = false);
void menu_GameSave2(FILE *fp); void menu_GameSave2(FILE *fp);
void menu_GameSave(int nSaveSlot); void menu_GameSave(int nSaveSlot);