henricj / dunelegacy

GNU General Public License v2.0
27 stars 5 forks source link

Debugging mission level definitions #33

Open juj opened 2 years ago

juj commented 2 years ago

Not sure if this would be something to land in the tree, though wanted to post this somewhere, in case it is useful.

In order to see what the definition of a campaign mission level was, I use the following code:

diff --git a/src/INIMap/INIMapLoader.cpp b/src/INIMap/INIMapLoader.cpp
index 95829504..ab617793 100644
--- a/src/INIMap/INIMapLoader.cpp
+++ b/src/INIMap/INIMapLoader.cpp
@@ -46,6 +46,8 @@ INIMapLoader::~INIMapLoader() = default;

+    /// Prints the full contents of this INI file to stdout.
+    void debugDump() const;
+
     [[nodiscard]] size_t getLineNumber(std::string_view sectionname) const;
     [[nodiscard]] size_t getLineNumber(std::string_view sectionname, std::string_view keyname) const;

diff --git a/src/FileClasses/INIFile.cpp b/src/FileClasses/INIFile.cpp
index 7f2c872c..7f800133 100644
--- a/src/FileClasses/INIFile.cpp
+++ b/src/FileClasses/INIFile.cpp
@@ -224,6 +224,20 @@ INIFile::INIFile(SDL_RWops* RWopsFile, bool bWhitespace) : bWhitespace(bWhitespa
 */
 INIFile::~INIFile() = default;

+void INIFile::debugDump() const {
+    for (const auto& line : lines_) {
+        if (const Line* l = std::get_if<Line>(&line)) {
+            sdl2::log_info("%s", l->line().c_str());
+        } else if (const Key* k = std::get_if<Key>(&line)) {
+            sdl2::log_info("%s", k->line().c_str());
+        } else if (const Section* s = std::get_if<Section>(&line)) {
+            sdl2::log_info("%s", s->line().c_str());
+        } else {
+            sdl2::log_info("Unknown variant type!");
+        }
+    }
+}
+
 size_t INIFile::getLineNumber(std::string_view sectionname) const {
     const auto section = findSectionInternal(sectionname);

diff --git a/src/INIMap/INIMapLoader.cpp b/src/INIMap/INIMapLoader.cpp
index 95829504..ab617793 100644
--- a/src/INIMap/INIMapLoader.cpp
+++ b/src/INIMap/INIMapLoader.cpp
@@ -46,6 +46,8 @@ INIMapLoader::~INIMapLoader() = default;
 std::unique_ptr<Map> INIMapLoader::load() {
     checkFeatures();

+    inifile_->debugDump();
+
     loadMap();

This results in the whole INI block getting printed to log when a mission is started, e.g. Harkonnen level 5:

INFO    :   ; Scenario 14 control for house Harkonnen.
INFO    :   
INFO    :   [BASIC]
INFO    :   LosePicture=LOSTBILD.WSA
INFO    :   WinPicture=WIN1.WSA
INFO    :   BriefPicture=HVYFTRY.WSA
INFO    :   TimeOut=0
INFO    :   MapScale=0
INFO    :   CursorPos=3309
INFO    :   TacticalPos=2982
INFO    :   LoseFlags=1
INFO    :   WinFlags=3
INFO    :   
INFO    :   [MAP]
INFO    :   Seed=500
INFO    :   
INFO    :   [Harkonnen]
INFO    :   Quota=0
INFO    :   Credits=1700
INFO    :   Brain=Human
INFO    :   MaxUnit=25
INFO    :   
INFO    :   [Ordos]
INFO    :   Quota=0
INFO    :   Credits=800
INFO    :   Brain=CPU
INFO    :   MaxUnit=25
INFO    :   
INFO    :   [CHOAM]
INFO    :   Trike=5
INFO    :   Quad=5
INFO    :   Tank=4
INFO    :   Launcher=3
INFO    :   Harvester=2
INFO    :   MCV=2
INFO    :   Carryall=2
INFO    :   
INFO    :   [TEAMS]
INFO    :   1=Ordos,Kamikaze,Foot,4,6
INFO    :   2=Ordos,Kamikaze,Track,6,8
INFO    :   3=Ordos,Normal,Wheel,5,7
INFO    :   4=Ordos,Normal,Foot,4,6
INFO    :   5=Ordos,Kamikaze,Wheel,4,6
INFO    :   6=Ordos,Normal,Track,5,7
INFO    :   7=Ordos,Kamikaze,Track,6,9
INFO    :   
INFO    :   [UNITS]
INFO    :   ID023=Harkonnen,Tank,256,3499,64,Guard
INFO    :   ID050=Ordos,Troopers,256,289,64,Ambush
INFO    :   ID049=Ordos,Siege Tank,256,350,64,Area Guard
INFO    :   ID048=Ordos,Siege Tank,256,427,64,Ambush
INFO    :   ID047=Ordos,Siege Tank,256,673,64,Area Guard
INFO    :   ID046=Ordos,Siege Tank,256,805,64,Area Guard
INFO    :   ID045=Ordos,Siege Tank,256,927,64,Ambush
INFO    :   ID044=Ordos,Troopers,256,1000,64,Ambush
INFO    :   ID043=Ordos,Quad,256,940,64,Ambush
INFO    :   ID042=Ordos,Quad,256,931,64,Ambush
INFO    :   ID041=Ordos,Troopers,256,1161,64,Area Guard
INFO    :   ID040=Ordos,Siege Tank,256,1231,64,Area Guard
INFO    :   ID039=Ordos,Tank,256,1300,64,Ambush
INFO    :   ID038=Ordos,Siege Tank,256,1491,64,Ambush
INFO    :   ID037=Ordos,Troopers,256,1548,64,Area Guard
INFO    :   ID036=Ordos,Troopers,256,1737,64,Area Guard
INFO    :   ID035=Ordos,Siege Tank,256,1748,64,Area Guard
INFO    :   ID034=Ordos,Quad,256,1808,64,Ambush
INFO    :   ID033=Ordos,Siege Tank,256,1934,64,Ambush
INFO    :   ID032=Ordos,Siege Tank,256,1926,64,Area Guard
INFO    :   ID031=Ordos,Tank,256,1939,64,Area Guard
INFO    :   ID030=Ordos,Tank,256,1923,64,Area Guard
INFO    :   ID029=Ordos,Quad,256,1945,64,Ambush
INFO    :   ID028=Harkonnen,Tank,256,3181,64,Guard
INFO    :   ID027=Harkonnen,Quad,256,3248,64,Guard
INFO    :   ID026=Harkonnen,Quad,256,3307,64,Guard
INFO    :   ID025=Harkonnen,Tank,256,3376,64,Guard
INFO    :   ID024=Harkonnen,Quad,256,3439,64,Guard
INFO    :   ID022=Harkonnen,Launcher,256,3501,64,Guard
INFO    :   ID016=Fremen,Sandworm,256,2641,64,Ambush
INFO    :   ID017=Fremen,Sandworm,256,2210,64,Ambush
INFO    :   
INFO    :   [STRUCTURES]
INFO    :   GEN1804=Ordos,Concrete
INFO    :   GEN1802=Ordos,Wall
INFO    :   GEN1801=Ordos,Wall
INFO    :   GEN1800=Ordos,Concrete
INFO    :   GEN1799=Ordos,Concrete
INFO    :   GEN1741=Ordos,Concrete
INFO    :   GEN1740=Ordos,Concrete
INFO    :   GEN1739=Ordos,Concrete
INFO    :   GEN1738=Ordos,Wall
INFO    :   GEN1737=Ordos,Concrete
INFO    :   GEN1736=Ordos,Concrete
INFO    :   GEN1735=Ordos,Concrete
INFO    :   GEN1734=Ordos,Wall
INFO    :   GEN1673=Ordos,Concrete
INFO    :   GEN1672=Ordos,Concrete
INFO    :   GEN1671=Ordos,Concrete
INFO    :   GEN1670=Ordos,Wall
INFO    :   GEN1669=Ordos,Wall
INFO    :   GEN1668=Ordos,Wall
INFO    :   GEN1667=Ordos,Wall
INFO    :   GEN1616=Ordos,Wall
INFO    :   GEN1615=Ordos,Wall
INFO    :   GEN1607=Ordos,Concrete
INFO    :   GEN1606=Ordos,Concrete
INFO    :   GEN1605=Ordos,Wall
INFO    :   GEN1552=Ordos,Concrete
INFO    :   GEN1551=Ordos,Concrete
INFO    :   GEN1550=Ordos,Concrete
INFO    :   GEN1549=Ordos,Concrete
INFO    :   GEN1548=Ordos,Concrete
INFO    :   GEN1542=Ordos,Concrete
INFO    :   GEN1541=Ordos,Wall
INFO    :   GEN1486=Ordos,Concrete
INFO    :   GEN1485=Ordos,Concrete
INFO    :   GEN1484=Ordos,Concrete
INFO    :   GEN1478=Ordos,Concrete
INFO    :   GEN1477=Ordos,Wall
INFO    :   GEN1420=Ordos,Concrete
INFO    :   GEN1419=Ordos,Concrete
INFO    :   GEN1418=Ordos,Concrete
INFO    :   GEN1417=Ordos,Concrete
INFO    :   GEN1416=Ordos,Concrete
INFO    :   GEN1415=Ordos,Concrete
INFO    :   GEN1414=Ordos,Concrete
INFO    :   GEN1413=Ordos,Concrete
INFO    :   GEN1357=Ordos,Wall
INFO    :   GEN1354=Ordos,Concrete
INFO    :   GEN1293=Ordos,Wall
INFO    :   GEN1290=Ordos,Concrete
INFO    :   GEN1227=Ordos,Concrete
INFO    :   GEN1226=Ordos,Concrete
INFO    :   GEN1225=Ordos,Concrete
INFO    :   GEN1224=Ordos,Concrete
INFO    :   GEN1223=Ordos,Concrete
INFO    :   GEN681=Ordos,Wall
INFO    :   GEN680=Ordos,Wall
INFO    :   GEN679=Ordos,Wall
INFO    :   GEN678=Ordos,Wall
INFO    :   GEN677=Ordos,Wall
INFO    :   GEN676=Ordos,Wall
INFO    :   GEN617=Ordos,Wall
INFO    :   GEN612=Ordos,Wall
INFO    :   GEN611=Ordos,Concrete
INFO    :   GEN553=Ordos,Wall
INFO    :   GEN548=Ordos,Wall
INFO    :   GEN547=Ordos,Concrete
INFO    :   GEN489=Ordos,Concrete
INFO    :   GEN488=Ordos,Concrete
INFO    :   GEN487=Ordos,Concrete
INFO    :   GEN486=Ordos,Concrete
INFO    :   GEN485=Ordos,Concrete
INFO    :   GEN484=Ordos,Concrete
INFO    :   GEN483=Ordos,Concrete
INFO    :   GEN425=Ordos,Concrete
INFO    :   GEN419=Ordos,Concrete
INFO    :   GEN361=Ordos,Concrete
INFO    :   GEN355=Ordos,Concrete
INFO    :   GEN290=Ordos,Concrete
INFO    :   GEN289=Ordos,Concrete
INFO    :   GEN163=Ordos,Concrete
INFO    :   ID028=Ordos,Windtrap,256,159
INFO    :   ID027=Ordos,Windtrap,256,1095
INFO    :   ID026=Ordos,R-Turret,256,354
INFO    :   ID025=Ordos,R-Turret,256,744
INFO    :   ID024=Ordos,R-Turret,256,675
INFO    :   ID023=Ordos,R-Turret,256,1617
INFO    :   ID022=Ordos,R-Turret,256,1803
INFO    :   ID021=Ordos,Windtrap,256,549
INFO    :   ID020=Ordos,Const Yard,256,100
INFO    :   ID019=Ordos,R-Turret,256,1421
INFO    :   ID018=Ordos,R-Turret,256,1798
INFO    :   ID017=Ordos,Windtrap,256,161
INFO    :   ID015=Ordos,Windtrap,256,1539
INFO    :   ID014=Ordos,Windtrap,256,1411
INFO    :   ID013=Ordos,Outpost,256,1613
INFO    :   ID012=Ordos,Refinery,256,1731
INFO    :   ID011=Ordos,Spice Silo,256,227
INFO    :   ID010=Ordos,Spice Silo,256,229
INFO    :   ID009=Ordos,WOR,256,551
INFO    :   ID008=Ordos,Light Fctry,256,359
INFO    :   ID007=Ordos,Heavy Fctry,256,356
INFO    :   ID006=Ordos,Refinery,256,231
INFO    :   ID005=Ordos,Repair,256,1610
INFO    :   ID003=Ordos,Hi-Tech,256,1284
INFO    :   ID002=Ordos,WOR,256,1291
INFO    :   ID001=Ordos,Heavy Fctry,256,1287
INFO    :   ID000=Harkonnen,Const Yard,256,3309
INFO    :   
INFO    :   [REINFORCEMENTS]
INFO    :   1=Ordos,Troopers,Enemybase,12
INFO    :   2=Ordos,Quad,Enemybase,12
INFO    :   3=Ordos,Troopers,Enemybase,12
INFO    :   4=Ordos,Troopers,Enemybase,20
INFO    :   5=Ordos,Siege Tank,Enemybase,20
INFO    :   6=Harkonnen,Tank,Homebase,13
INFO    :   7=Harkonnen,Launcher,Homebase,13
INFO    :   8=Harkonnen,Tank,Homebase,21
INFO    :   9=Harkonnen,Siege Tank,Homebase,21

I wonder if there might be an easier/more straightforward way to do this? Or whether this would be a good thing to land? (the runtime does already have some other debug log prints at runtime, so seems friendly to print dev aids to console, which makes it easier to approach development)

henricj commented 2 years ago

There are some tools to manage PAK archives. I know I've used them in the past and even have a vague recollection of compiling one of them myself (C#, IIRC—downloading and the idea of running random EXEs from forum posts has always made me wary). But I can't recall what the thing was called. OTOH, those PAK files are really simple and the tree's existing PAK code can obviously read them and should still be able to write them.

henricj commented 2 years ago

I found the tool I'd compiled and used a while back for extracting from the PAK files, and could (of course), not leave well-enough alone. Here's a .NET 6 version of Nyerguds' Librarian: https://github.com/henricj/Librarian