From f115ab94a8d544dd4f78ce43aa8af408178f699e Mon Sep 17 00:00:00 2001
From: Jakob Harder <12190313+jakobharder@users.noreply.github.com>
Date: Mon, 15 Apr 2024 19:19:47 +0200
Subject: [PATCH 1/5] fix crash.txt logging

---
 .../CustomExceptionHandler.cs                 | 32 +++++++------------
 source/Burntime.MonoGame/Program.cs           | 19 +++--------
 2 files changed, 16 insertions(+), 35 deletions(-)

diff --git a/source/Burntime.MonoGame/CustomExceptionHandler.cs b/source/Burntime.MonoGame/CustomExceptionHandler.cs
index a391016..9730239 100644
--- a/source/Burntime.MonoGame/CustomExceptionHandler.cs
+++ b/source/Burntime.MonoGame/CustomExceptionHandler.cs
@@ -1,30 +1,22 @@
 using System;
-//using System.Windows.Forms;
 using System.IO;
-using System.Threading;
 
 namespace Burntime
 {
-    //public class CustomExceptionHandler
-    //{
-    //    public void OnThreadException(object sender, UnhandledExceptionEventArgs args)
-    //    {
-    //        Exception e = args.ExceptionObject as Exception;
-    //        if (e == null)
-    //        {
-    //            MessageBox.Show("Error: Unknown", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
-    //        }
-    //        else
-    //        {
-    //            ErrorMsg.LogException(e);
+    public class CustomExceptionHandler
+    {
+        public static void OnThreadException(object sender, UnhandledExceptionEventArgs args)
+        {
+            var e = args.ExceptionObject as Exception;
+            if (e is not null)
+                ErrorMsg.LogException(e);
 
-    //            MessageBox.Show("Error: " + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
-    //        }
+            //MessageBox.Show("Error: " + e?.Message ?? "Unknown", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
 
-    //        // close
-    //        Environment.Exit(1);
-    //    }
-    //};
+            // close
+            Environment.Exit(1);
+        }
+    };
 
     static class ErrorMsg
     {
diff --git a/source/Burntime.MonoGame/Program.cs b/source/Burntime.MonoGame/Program.cs
index 744c098..69e0988 100644
--- a/source/Burntime.MonoGame/Program.cs
+++ b/source/Burntime.MonoGame/Program.cs
@@ -1,21 +1,10 @@
 
 using Burntime;
+using System;
 
-#if (DEBUG)
+#if !(DEBUG)
+    AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CustomExceptionHandler.OnThreadException);
+#endif
 
 using var game = new Burntime.MonoGame.BurntimeGame();
 game.Run();
-
-#else
-
-try
-{
-    using var game = new Burntime.MonoGame.BurntimeGame();
-    game.Run();
-}
-catch (System.Exception exception)
-{
-    ErrorMsg.LogException(exception);
-}
-
-#endif
\ No newline at end of file

From 5839f571420e948e56dc936fa1644ea26957b999 Mon Sep 17 00:00:00 2001
From: Jakob Harder <12190313+jakobharder@users.noreply.github.com>
Date: Mon, 15 Apr 2024 19:21:42 +0200
Subject: [PATCH 2/5] fix crash when starting a game without AI players

---
 source/Burntime.Remaster/Logic/Character/Character.cs | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/source/Burntime.Remaster/Logic/Character/Character.cs b/source/Burntime.Remaster/Logic/Character/Character.cs
index 3509c39..d759d2d 100644
--- a/source/Burntime.Remaster/Logic/Character/Character.cs
+++ b/source/Burntime.Remaster/Logic/Character/Character.cs
@@ -401,9 +401,12 @@ public void Dismiss()
         public virtual void Die()
         {
             // drop items
-            Location.Items.DropPosition = Position;
-            Items.MoveTo(Location.Items);
-            
+            if (Location is not null)
+            {
+                Location.Items.DropPosition = Position;
+                Items.MoveTo(Location.Items);
+            }
+
             // remove from player empire
             if (Player != null && Player.Character != this)
                 Dismiss();

From c011a0089471b092f82fd89c3f93764fc46931ea Mon Sep 17 00:00:00 2001
From: Jakob Harder <12190313+jakobharder@users.noreply.github.com>
Date: Mon, 15 Apr 2024 19:37:47 +0200
Subject: [PATCH 3/5] fix crash when adding a 6th person to your group

---
 source/Burntime.Remaster/GUI/InventoryWindow.cs      | 12 +++++++-----
 source/Burntime.Remaster/Logic/Character/Group.cs    |  2 ++
 source/Burntime.Remaster/Logic/Interaction/Dialog.cs |  3 ++-
 source/Burntime.Remaster/Scenes/LocationScene.cs     |  2 +-
 4 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/source/Burntime.Remaster/GUI/InventoryWindow.cs b/source/Burntime.Remaster/GUI/InventoryWindow.cs
index 132df2d..6b62a35 100644
--- a/source/Burntime.Remaster/GUI/InventoryWindow.cs
+++ b/source/Burntime.Remaster/GUI/InventoryWindow.cs
@@ -66,8 +66,6 @@ public Character ActiveCharacter
         public InventoryWindow(Module App, InventorySide Side)
             : base(App)
         {
-            const int MAX_PEOPLE = 5;
-
             side = (Side == InventorySide.Right);
 
             back = side ? "inv.raw?2" : "gfx/inventory_left.png";
@@ -88,7 +86,7 @@ public InventoryWindow(Module App, InventorySide Side)
 
             pageName = "";
 
-            for (int i = 0; i < MAX_PEOPLE; i++)
+            for (int i = 0; i < Logic.Group.MAX_PEOPLE; i++)
             {
                 pageButtons[i] = new Button(App);
                 pageButtons[i].Image = "munt.raw?" + (5 + i);
@@ -99,7 +97,7 @@ public InventoryWindow(Module App, InventorySide Side)
                 pageButtons[i].Hide();
                 pageButtons[i].Command += new CommandHandler(OnPage, i);
                 pageIndices[i] = i;
-                pageButtons[i].Layer = Layer + MAX_PEOPLE + 1;
+                pageButtons[i].Layer = Layer + Logic.Group.MAX_PEOPLE + 1;
                 Windows += pageButtons[i];
             }
 
@@ -109,7 +107,7 @@ public InventoryWindow(Module App, InventorySide Side)
                 Position = new Vector2(side ? 9 : 19, side ? 72 : 83) + basePos,
                 Spacing = new Vector2(4, side ? 16 : 5),
                 Grid = new Vector2(3, 2),
-                Layer = Layer + MAX_PEOPLE + 1
+                Layer = Layer + Logic.Group.MAX_PEOPLE + 1
             };
             grid.LeftClickItemEvent += OnLeftClickItem;
             grid.RightClickItemEvent += OnRightClickItem;
@@ -163,6 +161,10 @@ void Refresh()
 
                     for (int i = 0; i < group.Count; i++)
                     {
+                        // should not happen but well
+                        if (count >= pageButtons.Length)
+                            continue;
+
                         // show only if in range
                         if (group.IsInRange(leader, group[i]))
                         {
diff --git a/source/Burntime.Remaster/Logic/Character/Group.cs b/source/Burntime.Remaster/Logic/Character/Group.cs
index e60a7cb..c624390 100644
--- a/source/Burntime.Remaster/Logic/Character/Group.cs
+++ b/source/Burntime.Remaster/Logic/Character/Group.cs
@@ -10,6 +10,8 @@ namespace Burntime.Remaster.Logic
     [Serializable]
     public class Group : StateObject, ICharacterCollection
     {
+        public const int MAX_PEOPLE = 5;
+
         StateLinkList<Character> characterList;
         float rangeFilterValue;
 
diff --git a/source/Burntime.Remaster/Logic/Interaction/Dialog.cs b/source/Burntime.Remaster/Logic/Interaction/Dialog.cs
index d778587..a4654f9 100644
--- a/source/Burntime.Remaster/Logic/Interaction/Dialog.cs
+++ b/source/Burntime.Remaster/Logic/Interaction/Dialog.cs
@@ -113,7 +113,8 @@ Conversation GetGreetingConversation(Character boss)
                 conv.Choices[1].Action = new ConversationAction(ConversationActionType.Talk);
                 conv.Choices[1].Text = ResourceManager.GetString("burn?492");
             }
-            else if (Parent.Class != CharClass.Mutant && Parent.Class != CharClass.Dog && boss.IsPlayerCharacter && file != 510 && boss.Player.Group.Count < 5)
+            else if (Parent.Class != CharClass.Mutant && Parent.Class != CharClass.Dog && boss.IsPlayerCharacter && file != 510
+                && boss.Player.Group.Count < Logic.Group.MAX_PEOPLE)
             {
                 conv.Choices[0].Action = new ConversationAction(ConversationActionType.Talk);
                 conv.Choices[0].Text = ResourceManager.GetString("burn?492");
diff --git a/source/Burntime.Remaster/Scenes/LocationScene.cs b/source/Burntime.Remaster/Scenes/LocationScene.cs
index 7e29ed1..0187f2e 100644
--- a/source/Burntime.Remaster/Scenes/LocationScene.cs
+++ b/source/Burntime.Remaster/Scenes/LocationScene.cs
@@ -351,7 +351,7 @@ void ShowMenu(Vector2 position)
                 {
                     menu.AddLine("@burn?364", (CommandHandler)OnMenuMakeCamp);
                 }
-                else
+                else if (view.Player.Group.Count < Logic.Group.MAX_PEOPLE)
                 {
                     menu.AddLine("@burn?365", (CommandHandler)OnMenuLeaveCamp);
                 }

From 0d97520a414a0e3186d550013937615222c67930 Mon Sep 17 00:00:00 2001
From: Jakob Harder <12190313+jakobharder@users.noreply.github.com>
Date: Mon, 15 Apr 2024 19:39:15 +0200
Subject: [PATCH 4/5] fix translation inventory -> inventar

---
 resources/game/classic_de/lang/de/BURN.TXT | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/resources/game/classic_de/lang/de/BURN.TXT b/resources/game/classic_de/lang/de/BURN.TXT
index d2456f9..f5bc5e1 100644
--- a/resources/game/classic_de/lang/de/BURN.TXT
+++ b/resources/game/classic_de/lang/de/BURN.TXT
@@ -365,7 +365,7 @@ ENTLASSEN}
 ZUM LAGER}
 ZUM TRUPP}
 EIGENER}
-INVENTORY}
+INVENTAR}
 ABBRECHEN}
 HEILEN}
 BESTENLISTE}

From d1da907ced699a53354391d8f385643a37e52b8b Mon Sep 17 00:00:00 2001
From: Jakob Harder <12190313+jakobharder@users.noreply.github.com>
Date: Mon, 15 Apr 2024 19:42:20 +0200
Subject: [PATCH 5/5] update changelog

---
 resources/Changelog.md | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/resources/Changelog.md b/resources/Changelog.md
index 85ebc6a..7e510ea 100644
--- a/resources/Changelog.md
+++ b/resources/Changelog.md
@@ -2,6 +2,13 @@
 
 ## 1.0 - Feature complete (2024-02-25)
 
+### 1.0.2
+
+- Fixed crash with 6 people in your group - or rather prevent that
+- Fixed crash when starting without AI players
+- Fixed crash log
+- Corrected "Inventar" in German translation
+
 ### 1.0.1
 
 - Fixed New Village water source for older saves