Author Topic: [Solved] Battlescape saves don't work (yaml-cpp issue)  (Read 10865 times)

Online Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: Bugs (?) with my saved games
« Reply #15 on: December 03, 2020, 12:54:47 am »
Could you try load this hacked save game?

Offline Heybeardy

  • Sergeant
  • **
  • Posts: 17
    • View Profile
Re: Bugs (?) with my saved games
« Reply #16 on: December 03, 2020, 11:15:00 am »
Could you try load this hacked save game?

I tried the hacked save game, while it worked fine initially the same black map cropped up. It only happened after I have saved it as new saved game & exit from the battlescape. The new saved game opened to the same black map.

Incidentally, I pulled & compiled a fresh git OXC and OXCE overnight, the black map bug still occurred.

Seem to be something up with the save game option for battlescape mission.

Fyi, OXC &compiled in just under an hour (40-50 mins)  while OXCE it was slightly longer probably 1.5 hrs in Raspberry Pi 3 B+ board.

Regards,
Heybeardy.



Online Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: Bugs (?) with my saved games
« Reply #17 on: December 03, 2020, 11:28:16 am »
Quote
I tried the hacked save game, while it worked fine initially the same black map cropped up.
This mean it loaded correctly? What you did after is irrelevant to this test.

Offline Heybeardy

  • Sergeant
  • **
  • Posts: 17
    • View Profile
Re: Bugs (?) with my saved games
« Reply #18 on: December 03, 2020, 03:27:39 pm »
This mean it loaded correctly? What you did after is irrelevant to this test.

Yes the hacked save game loaded correctly. The game play was fine.

It's only when I saved the (battlescape) game, exited and loaded it, I ended up with the black map.

Online Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: Bugs (?) with my saved games
« Reply #19 on: December 03, 2020, 03:53:51 pm »
What version of yaml did you use to compile your binary?

Offline Heybeardy

  • Sergeant
  • **
  • Posts: 17
    • View Profile
Re: Bugs (?) with my saved games
« Reply #20 on: December 03, 2020, 06:36:37 pm »
What version of yaml did you use to compile your binary?

I used the git version 0.6.3.

The one available for my RPi debian system is 0.6.2-4, though it is not installed.

Online Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: Bugs (?) with my saved games
« Reply #21 on: December 03, 2020, 07:34:04 pm »
Overall it look that somting is broken in code that load binary serialized map in your code.

Code: [Select]
diff --git a/src/Savegame/SavedBattleGame.cpp b/src/Savegame/SavedBattleGame.cpp
index 37fc2f9d2..2b950148c 100644
--- a/src/Savegame/SavedBattleGame.cpp
+++ b/src/Savegame/SavedBattleGame.cpp
@@ -505,7 +505,7 @@ YAML::Node SavedBattleGame::save() const
        {
                node["mapdatasets"].push_back((*i)->getName());
        }
-#if 0
+#if 1
        for (int i = 0; i < _mapsize_z * _mapsize_y * _mapsize_x; ++i)
        {
                if (!_tiles[i].isVoid())
diff --git a/src/Savegame/Tile.cpp b/src/Savegame/Tile.cpp
index 85a9f38f7..76ac20a41 100644
--- a/src/Savegame/Tile.cpp
+++ b/src/Savegame/Tile.cpp
@@ -167,11 +167,10 @@ YAML::Node Tile::save() const
                node["fire"] = _fire;
        if (_objectsCache[O_FLOOR].discovered || _objectsCache[O_WESTWALL].discovered || _objectsCache[O_NORTHWALL].discovered)
        {
-               throw Exception("Obsolete code");
-//             for (int i = O_FLOOR; i <= O_NORTHWALL; i++)
-//             {
-//                     node["discovered"].push_back(_objectsCache[i].discovered);
-//             }
+               for (int i = O_FLOOR; i <= O_NORTHWALL; i++)
+               {
+                       node["discovered"].push_back((bool)_objectsCache[i].discovered);
+               }
        }
        if (isUfoDoorOpen(O_WESTWALL))
        {

This diff should enable old save mechanism that look like it work for you

Offline Heybeardy

  • Sergeant
  • **
  • Posts: 17
    • View Profile
Re: Bugs (?) with my saved games
« Reply #22 on: December 03, 2020, 09:45:18 pm »
I'm sure that I have done it a few times but it was a while ago, how do I make change to these two files SavedBattleGame.cpp & Tile.cpp? I 'm aware of the specific parts of the code that needed to be remove & added. I assumed that I'll have to recompile OXCE with these code fixes?

Online Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: Bugs (?) with my saved games
« Reply #23 on: December 03, 2020, 10:19:56 pm »
This is part of diff, lines that start with `-` need be removed, and ones start with `+` added in same place. Of corse do not add this `+` in final file.
After you did it, you can compile it again to have new binary that you can run.
Of corse you can commit this changes to not lose them in future.

Offline Heybeardy

  • Sergeant
  • **
  • Posts: 17
    • View Profile
Re: Bugs (?) with my saved games
« Reply #24 on: December 04, 2020, 11:29:09 am »
Thanks for refreshing my memory about the code change Yankes. I have recompiled OXCE with the code changes.

So far the game loaded fine and the game played was fine. But the saved game still have some problems -
 a) Loaded the hacked save game.
 b) Deployed smoke grenades.
 c) Saved the hacked save game.
 d) Loaded the saved game.
 e) Map opened to units in the Skyranger and AIs in the terrain, however smoke grenade deployment are missing. Also, there are still black areas of map and the game play is similar to the pre-hacked version of save game with the black map.

I have attached a 2.3 mins recording.
« Last Edit: December 04, 2020, 11:31:11 am by Heybeardy »

Online Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: Bugs (?) with my saved games
« Reply #25 on: December 04, 2020, 03:09:24 pm »
Also, there are still black areas of map and the game play is similar to the pre-hacked version of save game with the black map.

No, there is no "black" areas any more. Game correctly loaded tiles, but only forget flags for visibility and smoke.
could you show what changes you finally did to source code?

Offline Heybeardy

  • Sergeant
  • **
  • Posts: 17
    • View Profile
Re: Bugs (?) with my saved games
« Reply #26 on: December 04, 2020, 03:47:38 pm »
No, there is no "black" areas any more. Game correctly loaded tiles, but only forget flags for visibility and smoke.
could you show what changes you finally did to source code?

Yes I meant the visibility  - the black area above & behind the skyranger and smoke.

I simply replaced in SavedBattleGame.cpp,

Quote
 
#if 0

with

Quote
 
#if 1

and in Tile.cpp,

Quote
               throw Exception("Obsolete code");
//             for (int i = O_FLOOR; i <= O_NORTHWALL; i++)
//             {
//                     node["discovered"].push_back(_objectsCache.discovered);
//             }

with

Quote
 
               for (int i = O_FLOOR; i <= O_NORTHWALL; i++)
               {
                       node["discovered"].push_back((bool)_objectsCache.discovered);
               }

Then recompiled.
« Last Edit: December 04, 2020, 04:01:06 pm by Heybeardy »

Offline Heybeardy

  • Sergeant
  • **
  • Posts: 17
    • View Profile
Re: Bugs (?) with my saved games
« Reply #27 on: December 04, 2020, 03:54:36 pm »
See attached SavedBattleGame.cpp & Tile.cpp files.

Online Yankes

  • Global Moderator
  • Commander
  • *****
  • Posts: 3350
    • View Profile
Re: Bugs (?) with my saved games
« Reply #28 on: December 04, 2020, 08:17:03 pm »
Overall it look like your yaml-cpp have broken load of `Uint8`.

I have another possbile way to fix your code. First remove all changes you did (preferably by stashing them or putting them on another branch) then add code like this:

Code: [Select]
//YAML::Node SavedBattleGame::save() const
// old code look like:
// node["tileIndexSize"] = Tile::serializationKey.index;

node["tileIndexSize"] = (int)Tile::serializationKey.index;
node["tileTotalBytesPer"] = (int)Tile::serializationKey.totalBytes;
node["tileFireSize"] = (int)Tile::serializationKey._fire;
node["tileSmokeSize"] = (int)Tile::serializationKey._smoke;
node["tileIDSize"] = (int)Tile::serializationKey._mapDataID;
node["tileSetIDSize"] = (int)Tile::serializationKey._mapDataSetID;
node["tileBoolFieldsSize"] = (int)Tile::serializationKey.boolFields;
and
Code: [Select]
//void SavedBattleGame::load(const YAML::Node &node, Mod *mod, SavedGame* savedGame)
// old code look like
// serKey.index = node["tileIndexSize"].as<Uint8>(serKey.index);

serKey.index = node["tileIndexSize"].as<int>(serKey.index);
serKey.totalBytes = node["tileTotalBytesPer"].as<int>(serKey.totalBytes);
serKey._fire = node["tileFireSize"].as<int>(serKey._fire);
serKey._smoke = node["tileSmokeSize"].as<int>(serKey._smoke);
serKey._mapDataID = node["tileIDSize"].as<int>(serKey._mapDataID);
serKey._mapDataSetID = node["tileSetIDSize"].as<int>(serKey._mapDataSetID);
serKey.boolFields = node["tileBoolFieldsSize"].as<int>(1); // boolean flags used to be stored in an unmentioned byte (Uint8) :|
Overall it change use of `Uint8` to `int`.

Offline Heybeardy

  • Sergeant
  • **
  • Posts: 17
    • View Profile
Re: Bugs (?) with my saved games
« Reply #29 on: December 05, 2020, 02:55:48 am »
Yankes, after reading your comments about yaml-cpp being the culprit in most cases and especially your question about what version I used, I decided against to fix the codes per your suggestion in the last post.

What I did instead was to remove the git version of yaml-cpp (0.6.3) and install libyaml-cpp0.6:armhf  (0.6.2-4+rpi1) from the debian system. I also removed the changes in the code for the SavedBattleGame.cpp and Tile.cpp files, simply revert back to the original files. Then recompiled OXCE.

All the saved games worked. I loaded a saved game, saved it, exit, loaded it again - no more black maps and the visibility & smoke effects all are present as they should be. Phew!

The main cause seems to be the git version of yaml-cpp.

Thanks for all the helps in trying to fix the problem.