From 63406703aa0273d3b485fcb0e84b0c78e40e7f84 Mon Sep 17 00:00:00 2001 From: mtabachenko Date: Tue, 19 Nov 2013 10:32:58 +0000 Subject: [PATCH] fix auto import raw (uncompressed) no$gba saves; --- desmume/src/mc.cpp | 16 ++++++++++------ desmume/src/mc.h | 3 +++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/desmume/src/mc.cpp b/desmume/src/mc.cpp index 789af9b8f..bff864462 100644 --- a/desmume/src/mc.cpp +++ b/desmume/src/mc.cpp @@ -271,6 +271,8 @@ BackupDevice::BackupDevice() { if (no_gba_unpack(buf, sz)) printf("Converted from no$gba save.\n"); + else + sz = trim(buf, sz); if (fwrite(buf, 1, sz, fpOut->get_fp()) == sz) { @@ -1069,6 +1071,8 @@ u32 BackupDevice::get_save_nogba_size(u8 *data) return *((u32*)(data+0x48)); if (compressMethod == 1) return *((u32*)(data+0x4C)); + + return 0xFFFFFFFF; } static int no_gba_unpackSAV(void *in_buf, u32 fsize, void *out_buf, u32 &size) @@ -1151,7 +1155,7 @@ static int no_gba_unpackSAV(void *in_buf, u32 fsize, void *out_buf, u32 &size) return (200); } -static u32 no_gba_savTrim(void *buf, u32 size) +u32 BackupDevice::trim(void *buf, u32 size) { u32 rows = size / 16; u32 pos = (size - 16); @@ -1174,7 +1178,7 @@ static u32 no_gba_savTrim(void *buf, u32 size) return (size); } -static u32 no_gba_fillLeft(u32 size) +u32 BackupDevice::fillLeft(u32 size) { for (u32 i = 1; i < ARRAY_SIZE(save_types); i++) { @@ -1211,9 +1215,9 @@ bool BackupDevice::import_no_gba(const char *fname, u32 force_size) if (force_size > 0) size = force_size; //printf("New size %i byte(s)\n", size); - size = no_gba_savTrim(out_buf, size); + size = trim(out_buf, size); //printf("--- new size after trim %i byte(s)\n", size); - size = no_gba_fillLeft(size); + size = fillLeft(size); //printf("--- new size after fill %i byte(s)\n", size); raw_applyUserSettings(size, (force_size > 0)); saveBuffer(out_buf, size, true, true); @@ -1241,8 +1245,8 @@ bool BackupDevice::no_gba_unpack(u8 *&buf, u32 &size) { if (no_gba_unpackSAV(buf, size, out_buf, out_size) == 0) { - out_size = no_gba_savTrim(out_buf, out_size); - out_size = no_gba_fillLeft(out_size); + out_size = trim(out_buf, out_size); + out_size = fillLeft(out_size); delete [] buf; buf = out_buf; size = out_size; diff --git a/desmume/src/mc.h b/desmume/src/mc.h index 8533af039..436f14ca1 100644 --- a/desmume/src/mc.h +++ b/desmume/src/mc.h @@ -114,6 +114,9 @@ public: static u32 pad_up_size(u32 startSize); void raw_applyUserSettings(u32& size, bool manual = false); + u32 trim(void *buf, u32 size); + u32 fillLeft(u32 size); + u32 get_save_duc_size(const char* filename); u32 get_save_nogba_size(const char* filename); u32 get_save_nogba_size(u8 *data);