Skip to content
This repository was archived by the owner on Oct 3, 2024. It is now read-only.

fix the nullable warning and Null Handling #3

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 48 additions & 6 deletions ModPackager/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#region Using Directives
using System.Linq;
#region Using Directives
using UndertaleModLib;
using UndertaleModLib.Models;
using UndertaleModLib.Decompiler;
Expand All @@ -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;
Expand All @@ -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();
Expand All @@ -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;

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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<UndertaleFont>(ogFont, moddedFont, properties) && ogFont.Glyphs.Count == moddedFont.Glyphs.Count)
{
bool export = false;
Expand Down Expand Up @@ -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
#endregion
4 changes: 2 additions & 2 deletions ModPackager/Scripts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"); }
Expand Down Expand Up @@ -165,4 +165,4 @@ private static byte[] GetImageBytes(Image image, bool disposeImage = true)
}
}
#endregion
}
}