From a2f9e9bac150b339436f9472571324ea2b1a245a Mon Sep 17 00:00:00 2001 From: Nico Giansanti Date: Fri, 3 Sep 2021 01:44:44 +0300 Subject: [PATCH] Fix APM3 test menu saves in some games Fix APM3 test menu saves in some games --- .../src/Functions/Games/APM3/Backup.cpp | 19 ++++++++++++------- OpenParrot/src/Functions/Games/APM3/Backup.h | 5 +---- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/OpenParrot/src/Functions/Games/APM3/Backup.cpp b/OpenParrot/src/Functions/Games/APM3/Backup.cpp index 8e58a51..3bed60d 100644 --- a/OpenParrot/src/Functions/Games/APM3/Backup.cpp +++ b/OpenParrot/src/Functions/Games/APM3/Backup.cpp @@ -6,9 +6,11 @@ //#define _LOGAPM3BACKUP 1 char* BackupSaveFileName = "save"; char fileBuffer[256]; -BackupRecord* internal_Records; unsigned int internal_recordCount; +// Prefill some memory for save pointers, only 2-3 are used typically. Can be made dynamic, but this is for testing and seeing live data rn. +static auto backups = new BackupRecord[64]; + BackupRecordStatus CALLPLEB Backup_getRecordStatus(DWORD_PTR recordIndex) { #ifdef _LOGAPM3BACKUP @@ -35,7 +37,7 @@ bool CALLPLEB Backup_saveRecord(unsigned long recordIndex) auto file = fopen(fileBuffer, "wb+"); if (file) { - fwrite(internal_Records[recordIndex].Address, 1, internal_Records[recordIndex].Size, file); + fwrite(backups[recordIndex].Address, 1, backups[recordIndex].Size, file); fclose(file); } return Backup_saveRecordReturnValue; @@ -49,19 +51,22 @@ DWORD_PTR CALLPLEB Backup_saveRecordByAddress(DWORD_PTR recordAddress) return Backup_saveRecordByAddressReturnValue; } - - - //__int64 __fastcall Backup_setupRecords(__int128* a1, unsigned int a2) bool CALLPLEB Backup_setupRecords(BackupRecord* records, unsigned int recordCount) { + for (int i = 0; i < recordCount; i++) + { + backups[i].Address = records[i].Address; + backups[i].Size = records[i].Size; + } + + internal_recordCount = recordCount; + for (int i = 0; i < recordCount; i++) { memset(fileBuffer, 0, sizeof(fileBuffer)); sprintf(fileBuffer, "%s%02d.bin", BackupSaveFileName, i); FILE* fsave = fopen(fileBuffer, "r"); - internal_Records = records; - internal_recordCount = recordCount; if (fsave != NULL) { #ifdef _LOGAPM3BACKUP diff --git a/OpenParrot/src/Functions/Games/APM3/Backup.h b/OpenParrot/src/Functions/Games/APM3/Backup.h index e2bf28b..df0bfe6 100644 --- a/OpenParrot/src/Functions/Games/APM3/Backup.h +++ b/OpenParrot/src/Functions/Games/APM3/Backup.h @@ -9,13 +9,10 @@ extern char fileBuffer[256]; struct BackupRecord { - void* Address; + void *Address; unsigned long Size; }; -extern BackupRecord* internal_Records; -extern unsigned int internal_recordCount; - enum class BackupRecordStatus { BackupRecordStatus_InvalidCall = -1, // 0xFFFFFFFF