EasyRPG / liblcf

Library to handle RPG Maker 2000/2003 and EasyRPG projects
https://easyrpg.org
MIT License
113 stars 52 forks source link

Add "codepage" field to easyrpg_data #452

Closed Ghabry closed 1 year ago

Ghabry commented 1 year ago

This allows specifying an encoding for the savegame. Useful for the saving of translated games to prevent data loss.

Usage on Player side:

diff --git a/src/scene_save.cpp b/src/scene_save.cpp
index ca470de00..97aa49d30 100644
--- a/src/scene_save.cpp
+++ b/src/scene_save.cpp
@@ -16,6 +16,7 @@
  */

 // Headers
+#include "translation.h"
 #include <sstream>

 #ifdef EMSCRIPTEN
@@ -124,7 +125,10 @@ bool Scene_Save::Save(std::ostream& os, int slot_id, bool prepare_save) {
    Game_Map::PrepareSave(save);

    if (prepare_save) {
-       lcf::LSD_Reader::PrepareSave(save, PLAYER_SAVEGAME_VERSION);
+       // When a translation is loaded always store in Unicode to prevent data loss
+       int codepage = Tr::HasActiveTranslation() ? 65001 : 0;
+
+       lcf::LSD_Reader::PrepareSave(save, PLAYER_SAVEGAME_VERSION, codepage);
        Main_Data::game_system->IncSaveCount();
    }