From d39e5478623380e78a89b1ee1af09dbac42a2e39 Mon Sep 17 00:00:00 2001 From: Senjay-id <110238760+Senjay-id@users.noreply.github.com> Date: Wed, 6 Dec 2023 12:30:49 +0700 Subject: [PATCH 1/6] fix the nullable warning --- ModPackager/Scripts.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ModPackager/Scripts.cs b/ModPackager/Scripts.cs index 4dbf582..2ecc7d7 100644 --- a/ModPackager/Scripts.cs +++ b/ModPackager/Scripts.cs @@ -8,7 +8,7 @@ public static class Scripts { - public static UndertaleData Data { get; set; } + public static UndertaleData Data { get; set; } = new UndertaleData(); public static string ExportFolder { get; set; } = @"./mod.gmmod"; private static string CodeFolder { get => Path.Combine(ExportFolder, "Code"); } private static string TextureFolder { get => Path.Combine(ExportFolder, "Textures"); } @@ -165,4 +165,4 @@ private static byte[] GetImageBytes(Image image, bool disposeImage = true) } } #endregion -} \ No newline at end of file +} From e782e9b8b2c86783be66e92291fa3025b59d0194 Mon Sep 17 00:00:00 2001 From: Senjay-id <110238760+Senjay-id@users.noreply.github.com> Date: Wed, 6 Dec 2023 19:20:01 +0700 Subject: [PATCH 2/6] Null Handling --- ModPackager/Program.cs | 56 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/ModPackager/Program.cs b/ModPackager/Program.cs index de5416b..05774bf 100644 --- a/ModPackager/Program.cs +++ b/ModPackager/Program.cs @@ -1,5 +1,4 @@ -#region Using Directives -using System.Linq; +#region Using Directives using UndertaleModLib; using UndertaleModLib.Models; using UndertaleModLib.Decompiler; @@ -7,9 +6,10 @@ #endregion #region Fields -string ogGameDataPath = args[0]; -string moddedGameDataPath = args[1]; -string exportPath = args[2]; // .gmmod folder +string ogGameDataPath = "og.win"; +string moddedGameDataPath = "modded.win"; +string exportPath = "/export"; // .gmmod folder +int numberOfErrors = 0; Scripts.ExportFolder = exportPath; UndertaleData ogGameData; @@ -40,7 +40,14 @@ string ogAsm = (ogGameData.Code[i] != null ? ogGameData.Code[i].Disassemble(ogGameData.Variables, ogGameData.CodeLocals.For(ogGameData.Code[i])) : ""); string moddedAsm = (moddedGameData.Code[i] != null ? moddedGameData.Code[i].Disassemble(moddedGameData.Variables, moddedGameData.CodeLocals.For(moddedGameData.Code[i])) : ""); - + + if (ogAsm == null || moddedAsm == null) + { + Console.WriteLine($"[{i}] Skipping Code export due to null reference."); + numberOfErrors++; + continue; + } + if (ogAsm == moddedAsm) continue; @@ -75,6 +82,14 @@ texturesProgressBar.UpdateProgress(j); var ogTexture = ogGameData.Sprites[i].Textures[j].Texture; var moddedTexture = moddedGameData.Sprites[i].Textures[j].Texture; + + if (ogTexture == null || moddedTexture == null) + { + Console.WriteLine($"[{i}] Skipping Sprite export due to null reference."); + numberOfErrors++; + continue; + } + string moddedTexturePageName = moddedTexture.TexturePage.Name.Content; if (ogTexture.TexturePage.Name.Content != moddedTexturePageName) @@ -120,6 +135,14 @@ var ogTexture = ogGameData.Fonts[i].Texture; var moddedTexture = moddedGameData.Fonts[i].Texture; + + if (ogTexture == null || moddedTexture == null) + { + Console.WriteLine($"[{i}] Skipping Fonts export due to null reference."); + numberOfErrors++; + continue; + } + string moddedTexturePageName = moddedTexture.TexturePage.Name.Content; if (ogTexture.TexturePage.Name.Content == moddedTexturePageName) @@ -155,6 +178,14 @@ var ogTexture = ogGameData.Backgrounds[i].Texture; var moddedTexture = moddedGameData.Backgrounds[i].Texture; + + if (ogTexture == null || moddedTexture == null) + { + Console.WriteLine($"[{i}] Skipping background export due to null reference."); + numberOfErrors++; + continue; + } + string moddedTexturePageName = moddedTexture.TexturePage.Name.Content; if (ogTexture.TexturePage.Name.Content == moddedTexturePageName) @@ -210,6 +241,13 @@ var ogFont = ogGameData.Fonts[i]; var moddedFont = moddedGameData.Fonts[i]; + if (ogFont == null || moddedFont == null) + { + Console.WriteLine($"[{i}] Skipping FontData export due to null reference."); + numberOfErrors++; + continue; + } + if (ogFont.DisplayName.Content == moddedFont.DisplayName.Content && Scripts.PropertiesEqual(ogFont, moddedFont, properties) && ogFont.Glyphs.Count == moddedFont.Glyphs.Count) { bool export = false; @@ -238,5 +276,9 @@ #endregion Console.WriteLine("Done!"); +if (numberOfErrors > 1) +{ + Console.WriteLine($"There's a total of {numberOfErrors} errors during exporting"); +} Console.ReadKey(); -#endregion \ No newline at end of file +#endregion From ccad2003e50d0de8ae6b88f1a44fdc3b47a3744e Mon Sep 17 00:00:00 2001 From: Senjay-id <110238760+Senjay-id@users.noreply.github.com> Date: Wed, 6 Dec 2023 19:22:59 +0700 Subject: [PATCH 3/6] Null Handling Hotfix --- ModPackager/Program.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ModPackager/Program.cs b/ModPackager/Program.cs index 05774bf..e269f4d 100644 --- a/ModPackager/Program.cs +++ b/ModPackager/Program.cs @@ -6,9 +6,9 @@ #endregion #region Fields -string ogGameDataPath = "og.win"; -string moddedGameDataPath = "modded.win"; -string exportPath = "/export"; // .gmmod folder +string ogGameDataPath = args[0]; +string moddedGameDataPath = args[1]; +string exportPath = args[3]; // .gmmod folder int numberOfErrors = 0; Scripts.ExportFolder = exportPath; From d25d93b606274305d985dce95ac744b468aa2024 Mon Sep 17 00:00:00 2001 From: Senjay-id <110238760+Senjay-id@users.noreply.github.com> Date: Wed, 6 Dec 2023 19:23:32 +0700 Subject: [PATCH 4/6] Null Handling hotfix, again smh --- ModPackager/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ModPackager/Program.cs b/ModPackager/Program.cs index e269f4d..96cd7bd 100644 --- a/ModPackager/Program.cs +++ b/ModPackager/Program.cs @@ -8,7 +8,7 @@ #region Fields string ogGameDataPath = args[0]; string moddedGameDataPath = args[1]; -string exportPath = args[3]; // .gmmod folder +string exportPath = args[2]; // .gmmod folder int numberOfErrors = 0; Scripts.ExportFolder = exportPath; From 56100ed7a3952ba527757d1c1b44b2c8719be967 Mon Sep 17 00:00:00 2001 From: Senjay-id <110238760+Senjay-id@users.noreply.github.com> Date: Wed, 6 Dec 2023 20:50:18 +0700 Subject: [PATCH 5/6] Improved Null Handling --- ModPackager/Program.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ModPackager/Program.cs b/ModPackager/Program.cs index 96cd7bd..4ee2d2c 100644 --- a/ModPackager/Program.cs +++ b/ModPackager/Program.cs @@ -43,7 +43,7 @@ if (ogAsm == null || moddedAsm == null) { - Console.WriteLine($"[{i}] Skipping Code export due to null reference."); + Console.WriteLine($"Skipping {ogGameData.Code[1]} Code export due to null reference."); numberOfErrors++; continue; } @@ -85,7 +85,7 @@ if (ogTexture == null || moddedTexture == null) { - Console.WriteLine($"[{i}] Skipping Sprite export due to null reference."); + Console.WriteLine($"Skipping {ogGameData.Sprites[1]} Sprite export due to null reference."); numberOfErrors++; continue; } @@ -138,7 +138,7 @@ if (ogTexture == null || moddedTexture == null) { - Console.WriteLine($"[{i}] Skipping Fonts export due to null reference."); + Console.WriteLine($"Skipping {ogGameData.Fonts[1]} Fonts export due to null reference."); numberOfErrors++; continue; } @@ -181,7 +181,7 @@ if (ogTexture == null || moddedTexture == null) { - Console.WriteLine($"[{i}] Skipping background export due to null reference."); + Console.WriteLine($"Skipping {ogGameData.Backgrounds[1]} Background Texture export due to null reference."); numberOfErrors++; continue; } @@ -243,7 +243,7 @@ if (ogFont == null || moddedFont == null) { - Console.WriteLine($"[{i}] Skipping FontData export due to null reference."); + Console.WriteLine($"Skipping {ogGameData.Fonts[1]} FontData export due to null reference."); numberOfErrors++; continue; } From cd9a316cfd22ec952ac2a5befa94ea15dcd82beb Mon Sep 17 00:00:00 2001 From: Senjay-id <110238760+Senjay-id@users.noreply.github.com> Date: Thu, 7 Dec 2023 10:54:38 +0700 Subject: [PATCH 6/6] Null Handling Improvement, again --- ModPackager/Program.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ModPackager/Program.cs b/ModPackager/Program.cs index 4ee2d2c..0651dec 100644 --- a/ModPackager/Program.cs +++ b/ModPackager/Program.cs @@ -20,10 +20,10 @@ #region Init Console.CursorVisible = false; Console.WriteLine("Reading original game data..."); -using (FileStream stream = new FileStream(ogGameDataPath, FileMode.Open)) +using (FileStream stream = new(ogGameDataPath, FileMode.Open)) ogGameData = UndertaleIO.Read(stream); Console.WriteLine("Reading modded game data..."); -using (FileStream stream = new FileStream(moddedGameDataPath, FileMode.Open)) +using (FileStream stream = new(moddedGameDataPath, FileMode.Open)) moddedGameData = UndertaleIO.Read(stream); Scripts.Data = moddedGameData; Console.WriteLine(); @@ -43,7 +43,7 @@ if (ogAsm == null || moddedAsm == null) { - Console.WriteLine($"Skipping {ogGameData.Code[1]} Code export due to null reference."); + Console.WriteLine($"[{i}] Skipping {ogGameData.Code[i]} Code export due to null reference."); numberOfErrors++; continue; } @@ -85,7 +85,7 @@ if (ogTexture == null || moddedTexture == null) { - Console.WriteLine($"Skipping {ogGameData.Sprites[1]} Sprite export due to null reference."); + Console.WriteLine($"[{i}] Skipping {ogGameData.Sprites[i]} Sprite export due to null reference."); numberOfErrors++; continue; } @@ -138,7 +138,7 @@ if (ogTexture == null || moddedTexture == null) { - Console.WriteLine($"Skipping {ogGameData.Fonts[1]} Fonts export due to null reference."); + Console.WriteLine($"[{i}] Skipping {ogGameData.Fonts[i]} Fonts export due to null reference."); numberOfErrors++; continue; } @@ -181,7 +181,7 @@ if (ogTexture == null || moddedTexture == null) { - Console.WriteLine($"Skipping {ogGameData.Backgrounds[1]} Background Texture export due to null reference."); + Console.WriteLine($"[{i}] Skipping {ogGameData.Backgrounds[i]} Background Texture export due to null reference."); numberOfErrors++; continue; } @@ -243,7 +243,7 @@ if (ogFont == null || moddedFont == null) { - Console.WriteLine($"Skipping {ogGameData.Fonts[1]} FontData export due to null reference."); + Console.WriteLine($"[{i}] Skipping {ogGameData.Fonts[i]} FontData export due to null reference."); numberOfErrors++; continue; }