From d25cbca3d3b0c72ce8172f6af19ef951df0c93fe Mon Sep 17 00:00:00 2001 From: RD42 <42702181+dashr9230@users.noreply.github.com> Date: Fri, 4 Oct 2024 18:32:34 +0800 Subject: [PATCH] [bot] Implement/match `CNetGame::StartRecordingPlayback(...)` --- bot/net/netgame.cpp | 69 +++++++++++++++++++++++++++++++++++++++++++++ bot/net/netgame.h | 3 +- 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/bot/net/netgame.cpp b/bot/net/netgame.cpp index 609b7ec..986f113 100644 --- a/bot/net/netgame.cpp +++ b/bot/net/netgame.cpp @@ -925,6 +925,75 @@ void CNetGame::FUNC_6(FILE *a1, DWORD a2) } } +void CNetGame::StartRecordingPlayback(int iPlaybackType, char *szRecordName) +{ + DWORD v5 = 0; + + if(field_1E2) + { + fclose(field_1E2); + field_1E2 = NULL; + } + + char s[MAX_PATH]; + sprintf(s, "./npcmodes/recordings/%s.rec", szRecordName); + + field_1E2 = fopen(s, "rb"); + if(!field_1E2) + { + //logprintf("NPC: Total failure. Can't open recording playback file %s.", s); + exit(1); + } + + fseek(field_1E2, 0, SEEK_END); + v5 = ftell(field_1E2); + rewind(field_1E2); + + if(v5 == 0) + { + //logprintf("NPC: Total failure. %s is a 0 length file.", s); + exit(1); + } + + DWORD v4 = 0; + DWORD v3 = 0; + fread(&v4, 1, sizeof(DWORD), field_1E2); + fread(&v3, 1, sizeof(DWORD), field_1E2); + + if(v4 != 1000) + { + //logprintf("NPC: %s is not the correct recording version for this bot.", s); + //logprintf("NPC: Trying to upgrade %s...", s); + fclose(field_1E2); + if(!UpgradeRecordFile(s, v5, iPlaybackType)) + { + //logprintf("NPC: Fatal Error. Could not upgrade file. I'm out of options so I'm quiting."); + exit(1); + } + //logprintf("NPC: File %s was upgraded. Please restart the bot.", s); + exit(1); + } + if(iPlaybackType == PLAYER_RECORDING_TYPE_DRIVER) + { + FUNC_5(field_1E2, v5 - 8); + } + else if(iPlaybackType == PLAYER_RECORDING_TYPE_ONFOOT) + { + FUNC_6(field_1E2, v5 - 8); + } + else + { + //logprintf("NPC: Total failure. Unknown recording type specified."); + exit(1); + } + fclose(field_1E2); + field_1E2 = 0; + field_1DA = iPlaybackType; + field_1DE = 1; + field_1EA = GetTickCount(); + field_1E6 = 0; +} + void CNetGame::StopRecordingPlayback() { field_1DE = 0; diff --git a/bot/net/netgame.h b/bot/net/netgame.h index fca5c22..264a750 100644 --- a/bot/net/netgame.h +++ b/bot/net/netgame.h @@ -63,7 +63,7 @@ public: int field_1DA; int field_1DE; FILE *field_1E2; - char _gap1E6[4]; + int field_1E6; int field_1EA; char _gap1EE[4]; int field_1F2; @@ -124,6 +124,7 @@ public: void FUNC_5(FILE *a1, DWORD a2); void FUNC_6(FILE *a1, DWORD a2); + void StartRecordingPlayback(int iPlaybackType, char *szRecordName); void StopRecordingPlayback(); void PauseRecordingPlayback(); void ResumeRecordingPlayback();