From 0d01f476dee4aedc18e592fa4dc030382da93ce6 Mon Sep 17 00:00:00 2001 From: Catobat <69204835+Catobat@users.noreply.github.com> Date: Wed, 28 May 2025 18:58:11 +0200 Subject: [PATCH 1/8] Fix ghost trap after Gregal has been saved --- .../Resources/Patches/asm/moneyTrapInit.dmp | Bin 0 -> 44 bytes .../Resources/Patches/asm/moneyTrapInit.s | 22 ++++++++++++++++++ RandomizerCore/Resources/Patches/traps.event | 5 ++++ 3 files changed, 27 insertions(+) create mode 100644 RandomizerCore/Resources/Patches/asm/moneyTrapInit.dmp create mode 100644 RandomizerCore/Resources/Patches/asm/moneyTrapInit.s diff --git a/RandomizerCore/Resources/Patches/asm/moneyTrapInit.dmp b/RandomizerCore/Resources/Patches/asm/moneyTrapInit.dmp new file mode 100644 index 0000000000000000000000000000000000000000..3fa51dac25ae7f41b159c487eb926cf9790957e2 GIT binary patch literal 44 vcmZ2b#h}4;@d1!zznHAR;yure;Rk~T;{_&f33m|wa+IB8aSR8?av%l(K-mpp literal 0 HcmV?d00001 diff --git a/RandomizerCore/Resources/Patches/asm/moneyTrapInit.s b/RandomizerCore/Resources/Patches/asm/moneyTrapInit.s new file mode 100644 index 0000000..9c1cc45 --- /dev/null +++ b/RandomizerCore/Resources/Patches/asm/moneyTrapInit.s @@ -0,0 +1,22 @@ +.thumb +ldrb r0,[r4,#0xA] +cmp r0,#0 +bne noDeletion +ldrb r0,[r4,#0xB] +cmp r0,#0 +bne noDeletion + +mov r0,#0x63 +@ CheckLocalFlag +ldr r3,=#0x807C5F4 +mov lr,r3 +.short 0xF800 +cmp r0,#0 +beq noDeletion + +ldr r3,=#0x8085CA3 +bx r3 + +noDeletion: +ldr r3,=#0x8085CA7 +bx r3 diff --git a/RandomizerCore/Resources/Patches/traps.event b/RandomizerCore/Resources/Patches/traps.event index 2c33c6a..aed0e8f 100644 --- a/RandomizerCore/Resources/Patches/traps.event +++ b/RandomizerCore/Resources/Patches/traps.event @@ -63,6 +63,11 @@ ALIGN 4 moneyTrapEffect: #incbin "asm/moneyTrapEffect.dmp" +PUSH; ORG $85C98; jumpToHack(moneyTrapInit); POP +ALIGN 4 +moneyTrapInit: +#incbin "asm/moneyTrapInit.dmp" + ALIGN 4 stinkTrap: #incbin "asm/stinkTrap.dmp" From 51b84cade12195707456f79bd3508c70cc9b291d Mon Sep 17 00:00:00 2001 From: Catobat <69204835+Catobat@users.noreply.github.com> Date: Wed, 28 May 2025 21:03:19 +0200 Subject: [PATCH 2/8] Fix Gentari goal hint in non-English languages --- RandomizerCore/Resources/Patches/goalHint.event | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/RandomizerCore/Resources/Patches/goalHint.event b/RandomizerCore/Resources/Patches/goalHint.event index bd00598..2075371 100644 --- a/RandomizerCore/Resources/Patches/goalHint.event +++ b/RandomizerCore/Resources/Patches/goalHint.event @@ -36,14 +36,14 @@ SHORT 0x085A 0x1134 // show text box with text defined below ORG 0x9CC270+0x34*4 WORD goalTextEnglish-0x9CC270 -ORG 0x9F7420+0x34*4 -WORD goalTextFrench-0x9F7420 -ORG 0xA3EEB0+0x34*4 -WORD goalTextGerman-0xA3EEB0 -ORG 0xA81E70+0x34*4 -WORD goalTextSpanish-0xA81E70 -ORG 0xAC37A0+0x34*4 -WORD goalTextItalian-0xAC37A0 +ORG 0xA15B60+0x34*4 +WORD goalTextFrench-0xA15B60 +ORG 0xA5B450+0x34*4 +WORD goalTextGerman-0xA5B450 +ORG 0xA9D400+0x34*4 +WORD goalTextSpanish-0xA9D400 +ORG 0xADFAD0+0x34*4 +WORD goalTextItalian-0xADFAD0 POP goalTextEnglish: From 2309c6849c88cfefb94c2551ae0a1173803dcf7f Mon Sep 17 00:00:00 2001 From: Catobat <69204835+Catobat@users.noreply.github.com> Date: Thu, 29 May 2025 11:58:46 +0200 Subject: [PATCH 3/8] Fix phonograph text with Keysanity History enabled --- .../improvements/asm/keysanityHistory.dmp | Bin 160 -> 196 bytes .../improvements/asm/keysanityHistory.s | 17 +++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/RandomizerCore/Resources/Patches/improvements/asm/keysanityHistory.dmp b/RandomizerCore/Resources/Patches/improvements/asm/keysanityHistory.dmp index caa4f4eb6f372f845c315a4eb8b62255d217c621..07cf021289cd967adbc83cb4d6f95972ac2cc802 100644 GIT binary patch delta 151 zcmZ3$c!W{){}weLg-$ik4kxyY3Ka|*%okOB5-R>{7+g^H;ZfE0(3R5mQ=G`F$S(op zDge0>ehrLfQZf^5CBsC$rnxcvU@>v9W3+v9k=KJ!k+I?b9tI7z3md8!G#D>(c}uv% u@By~~1_mZZV+IC>^$bi5pP8Bd|7Tz@3S?%A<7Z&zJjTeuc$AUD6o>)CXeX@z delta 111 zcmX@YxPX!O{}u%w9#stwT`3JexrwTZVWL2;ERZYe*T85dCF#$gz@S(Vz+$MQ`TL?m z2ZILdg$4$T2xA!`uW4=!KUhp0>= Date: Thu, 29 May 2025 12:17:02 +0200 Subject: [PATCH 4/8] Fix French translation for "Rolling Time" --- RandomizerCore/Resources/Patches/save/credits/strings.event | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RandomizerCore/Resources/Patches/save/credits/strings.event b/RandomizerCore/Resources/Patches/save/credits/strings.event index 6a09573..5e413fe 100644 --- a/RandomizerCore/Resources/Patches/save/credits/strings.event +++ b/RandomizerCore/Resources/Patches/save/credits/strings.event @@ -1011,7 +1011,7 @@ rollingTimeCreditsEnglish: String("Rolling Time"); BYTE 0 rollingTimeCreditsFrench: -String("Nombre de Roulades"); BYTE 0 +String("Temps de Roulades"); BYTE 0 rollingTimeCreditsGerman: String("Zeit Rollen"); BYTE 0 From 13a7c05ccbdd1446d551c147e20899049bf11deb Mon Sep 17 00:00:00 2001 From: Catobat <69204835+Catobat@users.noreply.github.com> Date: Thu, 29 May 2025 20:03:47 +0200 Subject: [PATCH 5/8] Fix BeatVaati logic rule not always getting applied to Unrequired dungeon locations after they got filled --- .../Randomizer/Logic/Imports/LogicImports.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/RandomizerCore/Randomizer/Logic/Imports/LogicImports.cs b/RandomizerCore/Randomizer/Logic/Imports/LogicImports.cs index 5c14c60..4665dba 100644 --- a/RandomizerCore/Randomizer/Logic/Imports/LogicImports.cs +++ b/RandomizerCore/Randomizer/Logic/Imports/LogicImports.cs @@ -49,12 +49,13 @@ private static bool NonElementDungeonsBarrenImport(Location.Location self, Item if (prizeDungeonForItem == null) return true; - var accessible = prizeDungeonForItem.AssociatedPrize is + var isElementDungeon = prizeDungeonForItem.AssociatedPrize is { Type: ItemType.EarthElement or ItemType.FireElement or ItemType.WaterElement or ItemType.WindElement - } || (itemToPlace.ShufflePool is ItemPool.DungeonMajor && DependencyBase.BeatVaatiDependency!.DependencyFulfilled()); + }; + var accessible = isElementDungeon || (itemToPlace.ShufflePool is ItemPool.DungeonMajor && DependencyBase.BeatVaatiDependency!.DependencyFulfilled()); - if (!accessible && self.Dependencies.All(dep => dep != DependencyBase.BeatVaatiDependency!)) + if (!isElementDungeon && self.Dependencies.All(dep => dep != DependencyBase.BeatVaatiDependency!)) self.Dependencies.Add(DependencyBase.BeatVaatiDependency!); return accessible; @@ -70,12 +71,13 @@ private static bool NonElementDungeonsNotRequiredImport(Location.Location self, if (prizeDungeonForItem == null) return true; - var accessible = prizeDungeonForItem.AssociatedPrize is + var isElementDungeon = prizeDungeonForItem.AssociatedPrize is { Type: ItemType.EarthElement or ItemType.FireElement or ItemType.WaterElement or ItemType.WindElement - } || DependencyBase.BeatVaatiDependency!.DependencyFulfilled(); + }; + var accessible = isElementDungeon || DependencyBase.BeatVaatiDependency!.DependencyFulfilled(); - if (!accessible && self.Dependencies.All(dep => dep != DependencyBase.BeatVaatiDependency!)) + if (!isElementDungeon && self.Dependencies.All(dep => dep != DependencyBase.BeatVaatiDependency!)) self.Dependencies.Add(DependencyBase.BeatVaatiDependency!); return accessible; From a16c211f3ee27779d06d75ede4a06ea519e09d24 Mon Sep 17 00:00:00 2001 From: Catobat <69204835+Catobat@users.noreply.github.com> Date: Fri, 30 May 2025 18:39:46 +0200 Subject: [PATCH 6/8] Stop acting like this is using a Git submodule for ColorzCore --- .gitmodules | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .gitmodules diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 5c6e65f..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "Vendor/ColorzCore"] - path = Vendor/ColorzCore - url = https://github.com/minishmaker/ColorzCore.git From 050a2c5c309332b03c9232164ee9b0228277a586 Mon Sep 17 00:00:00 2001 From: Catobat <69204835+Catobat@users.noreply.github.com> Date: Fri, 30 May 2025 18:44:07 +0200 Subject: [PATCH 7/8] Fix saving a seed as a patch when the ROM size exceeds 16 MB --- RandomizerCore/Controllers/ControllerBase.cs | 9 +++++++-- Vendor/ColorzCore/ColorzCore/Program.cs | 5 ++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/RandomizerCore/Controllers/ControllerBase.cs b/RandomizerCore/Controllers/ControllerBase.cs index dabe9e3..8060f51 100644 --- a/RandomizerCore/Controllers/ControllerBase.cs +++ b/RandomizerCore/Controllers/ControllerBase.cs @@ -221,11 +221,16 @@ public ShufflerControllerResult CreatePatch(string patchFilename, string? patchF { Shuffler.ValidateState(true); var romBytes = Shuffler.GetRandomizedRom(); - var stream = new MemoryStream(romBytes); + // We need this stream to be expandable in case the patch is large + var stream = new MemoryStream(romBytes.Length); + stream.Write(romBytes); + stream.Position = 0; int exitCode = Shuffler.ApplyPatch(stream, patchFile); if (exitCode != 0) throw new Exception("Errors occured when saving the rom"); - var patch = BpsPatcher.GeneratePatch(Rom.Instance!.RomData, romBytes, patchFilename); + byte[] patchedRom = stream.ToArray(); + stream.Dispose(); + var patch = BpsPatcher.GeneratePatch(Rom.Instance!.RomData, patchedRom, patchFilename); File.WriteAllBytes(patchFilename, patch.Content!); return new ShufflerControllerResult { WasSuccessful = true }; } diff --git a/Vendor/ColorzCore/ColorzCore/Program.cs b/Vendor/ColorzCore/ColorzCore/Program.cs index a5bd2d9..3467bce 100644 --- a/Vendor/ColorzCore/ColorzCore/Program.cs +++ b/Vendor/ColorzCore/ColorzCore/Program.cs @@ -228,7 +228,10 @@ public static int Main(string[] args) } inStream.Close(); - outStream.Close(); + if (CustomOutputStream == null) + { + outStream.Close(); + } errorStream.Close(); return success ? ExitSuccess : ExitFailure; From 81b7905c5053a04df91b080bdfc3df7bab3428a4 Mon Sep 17 00:00:00 2001 From: Catobat <69204835+Catobat@users.noreply.github.com> Date: Fri, 30 May 2025 20:31:10 +0200 Subject: [PATCH 8/8] Include ColorzCore warning and error logs in Randomizer logs --- .../Randomizer/Shuffler/ShufflerBase.cs | 31 +++++++++++++------ Vendor/ColorzCore/ColorzCore/Program.cs | 13 ++++++-- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/RandomizerCore/Randomizer/Shuffler/ShufflerBase.cs b/RandomizerCore/Randomizer/Shuffler/ShufflerBase.cs index 569a5a5..fc991a8 100644 --- a/RandomizerCore/Randomizer/Shuffler/ShufflerBase.cs +++ b/RandomizerCore/Randomizer/Shuffler/ShufflerBase.cs @@ -145,11 +145,7 @@ public int ApplyPatch(string romLocation, string? patchFile = null) // Write new patch file to patch folder/extDefinitions.event File.WriteAllText(Path.GetDirectoryName(patchFile) + "/extDefinitions.event", GetEventWrites()); - string[] args = { "A", "FE8", "-input:" + patchFile, "-output:" + romLocation }; - - Program.CustomOutputStream = null; - - return Program.Main(args); + return RunColorzCore(patchFile, romLocation); } public int ApplyPatch(Stream patchedRom, string? patchFile = null) @@ -164,11 +160,29 @@ public int ApplyPatch(Stream patchedRom, string? patchFile = null) // Write new patch file to patch folder/extDefinitions.event File.WriteAllText(Path.GetDirectoryName(patchFile) + "/extDefinitions.event", GetEventWrites()); - string[] args = { "A", "FE8", "-input:" + patchFile, "-output:" + "usingAlternateStream" }; + return RunColorzCore(patchFile, "usingAlternateStream", patchedRom); + } + + private static int RunColorzCore(string patchFile, string ouputFile, Stream? customOutputStream = null) + { + string[] args = ["A", "FE8", "-input:" + patchFile, "-output:" + ouputFile, "-error:" + "usingAlternateStream"]; + + using var errorStream = new MemoryStream(0x1000000); - Program.CustomOutputStream = patchedRom; + Program.CustomOutputStream = customOutputStream; + Program.CustomErrorStream = errorStream; - return Program.Main(args); + var exitCode = Program.Main(args); + + errorStream.Position = 0; + using var errorStreamReader = new StreamReader(errorStream); + var errorLogs = errorStreamReader.ReadToEnd().Trim(); + if (!errorLogs.StartsWith("No errors. Please continue being awesome.")) + { + Logger.Instance.LogInfo($"Warnings or errors from ColorzCore: {errorLogs}"); + } + + return exitCode; } /// @@ -195,7 +209,6 @@ public string GetSpoiler() spoilerBuilder.AppendLine(); AddActualPlaythroughSpoiler(spoilerBuilder); - return spoilerBuilder.ToString(); } diff --git a/Vendor/ColorzCore/ColorzCore/Program.cs b/Vendor/ColorzCore/ColorzCore/Program.cs index 3467bce..f4c3f17 100644 --- a/Vendor/ColorzCore/ColorzCore/Program.cs +++ b/Vendor/ColorzCore/ColorzCore/Program.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using System.Reflection; using ColorzCore.IO; using ColorzCore.Lexer; using ColorzCore.Parser; @@ -15,6 +14,7 @@ public static class Program private const int ExitFailure = 1; public static bool Debug = false; public static Stream CustomOutputStream { get; set; } + public static Stream CustomErrorStream { get; set; } private static string[] _helpstringarr = { @@ -103,7 +103,11 @@ public static int Main(string[] args) break; case "error": - errorStream = new StreamWriter(File.OpenWrite(flag[1])); + errorStream = new StreamWriter(CustomErrorStream ?? File.OpenWrite(flag[1])); + if (CustomErrorStream != null) + { + ((StreamWriter)errorStream).AutoFlush = true; + } options.noColoredLog = true; break; @@ -232,7 +236,10 @@ public static int Main(string[] args) { outStream.Close(); } - errorStream.Close(); + if (CustomErrorStream == null) + { + errorStream.Close(); + } return success ? ExitSuccess : ExitFailure; }