diff --git a/ModPackager/Program.cs b/ModPackager/Program.cs index de5416b..0651dec 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; @@ -10,6 +9,7 @@ string ogGameDataPath = args[0]; string moddedGameDataPath = args[1]; string exportPath = args[2]; // .gmmod folder +int numberOfErrors = 0; Scripts.ExportFolder = exportPath; UndertaleData ogGameData; @@ -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(); @@ -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 {ogGameData.Code[i]} 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 {ogGameData.Sprites[i]} 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 {ogGameData.Fonts[i]} 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 {ogGameData.Backgrounds[i]} Background Texture 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 {ogGameData.Fonts[i]} 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 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 +}