Skip to content

Commit a29feec

Browse files
authored
Merge pull request #96 from minishmaker/small-fixes
Fixes for recently found bugs
2 parents 6c765ad + 81b7905 commit a29feec

File tree

12 files changed

+104
-33
lines changed

12 files changed

+104
-33
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
This file was deleted.

RandomizerCore/Controllers/ControllerBase.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,16 @@ public ShufflerControllerResult CreatePatch(string patchFilename, string? patchF
221221
{
222222
Shuffler.ValidateState(true);
223223
var romBytes = Shuffler.GetRandomizedRom();
224-
var stream = new MemoryStream(romBytes);
224+
// We need this stream to be expandable in case the patch is large
225+
var stream = new MemoryStream(romBytes.Length);
226+
stream.Write(romBytes);
227+
stream.Position = 0;
225228
int exitCode = Shuffler.ApplyPatch(stream, patchFile);
226229
if (exitCode != 0)
227230
throw new Exception("Errors occured when saving the rom");
228-
var patch = BpsPatcher.GeneratePatch(Rom.Instance!.RomData, romBytes, patchFilename);
231+
byte[] patchedRom = stream.ToArray();
232+
stream.Dispose();
233+
var patch = BpsPatcher.GeneratePatch(Rom.Instance!.RomData, patchedRom, patchFilename);
229234
File.WriteAllBytes(patchFilename, patch.Content!);
230235
return new ShufflerControllerResult { WasSuccessful = true };
231236
}

RandomizerCore/Randomizer/Logic/Imports/LogicImports.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@ private static bool NonElementDungeonsBarrenImport(Location.Location self, Item
4949

5050
if (prizeDungeonForItem == null) return true;
5151

52-
var accessible = prizeDungeonForItem.AssociatedPrize is
52+
var isElementDungeon = prizeDungeonForItem.AssociatedPrize is
5353
{
5454
Type: ItemType.EarthElement or ItemType.FireElement or ItemType.WaterElement or ItemType.WindElement
55-
} || (itemToPlace.ShufflePool is ItemPool.DungeonMajor && DependencyBase.BeatVaatiDependency!.DependencyFulfilled());
55+
};
56+
var accessible = isElementDungeon || (itemToPlace.ShufflePool is ItemPool.DungeonMajor && DependencyBase.BeatVaatiDependency!.DependencyFulfilled());
5657

57-
if (!accessible && self.Dependencies.All(dep => dep != DependencyBase.BeatVaatiDependency!))
58+
if (!isElementDungeon && self.Dependencies.All(dep => dep != DependencyBase.BeatVaatiDependency!))
5859
self.Dependencies.Add(DependencyBase.BeatVaatiDependency!);
5960

6061
return accessible;
@@ -70,12 +71,13 @@ private static bool NonElementDungeonsNotRequiredImport(Location.Location self,
7071

7172
if (prizeDungeonForItem == null) return true;
7273

73-
var accessible = prizeDungeonForItem.AssociatedPrize is
74+
var isElementDungeon = prizeDungeonForItem.AssociatedPrize is
7475
{
7576
Type: ItemType.EarthElement or ItemType.FireElement or ItemType.WaterElement or ItemType.WindElement
76-
} || DependencyBase.BeatVaatiDependency!.DependencyFulfilled();
77+
};
78+
var accessible = isElementDungeon || DependencyBase.BeatVaatiDependency!.DependencyFulfilled();
7779

78-
if (!accessible && self.Dependencies.All(dep => dep != DependencyBase.BeatVaatiDependency!))
80+
if (!isElementDungeon && self.Dependencies.All(dep => dep != DependencyBase.BeatVaatiDependency!))
7981
self.Dependencies.Add(DependencyBase.BeatVaatiDependency!);
8082

8183
return accessible;

RandomizerCore/Randomizer/Shuffler/ShufflerBase.cs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,7 @@ public int ApplyPatch(string romLocation, string? patchFile = null)
145145
// Write new patch file to patch folder/extDefinitions.event
146146
File.WriteAllText(Path.GetDirectoryName(patchFile) + "/extDefinitions.event", GetEventWrites());
147147

148-
string[] args = { "A", "FE8", "-input:" + patchFile, "-output:" + romLocation };
149-
150-
Program.CustomOutputStream = null;
151-
152-
return Program.Main(args);
148+
return RunColorzCore(patchFile, romLocation);
153149
}
154150

155151
public int ApplyPatch(Stream patchedRom, string? patchFile = null)
@@ -164,11 +160,29 @@ public int ApplyPatch(Stream patchedRom, string? patchFile = null)
164160
// Write new patch file to patch folder/extDefinitions.event
165161
File.WriteAllText(Path.GetDirectoryName(patchFile) + "/extDefinitions.event", GetEventWrites());
166162

167-
string[] args = { "A", "FE8", "-input:" + patchFile, "-output:" + "usingAlternateStream" };
163+
return RunColorzCore(patchFile, "usingAlternateStream", patchedRom);
164+
}
165+
166+
private static int RunColorzCore(string patchFile, string ouputFile, Stream? customOutputStream = null)
167+
{
168+
string[] args = ["A", "FE8", "-input:" + patchFile, "-output:" + ouputFile, "-error:" + "usingAlternateStream"];
169+
170+
using var errorStream = new MemoryStream(0x1000000);
168171

169-
Program.CustomOutputStream = patchedRom;
172+
Program.CustomOutputStream = customOutputStream;
173+
Program.CustomErrorStream = errorStream;
170174

171-
return Program.Main(args);
175+
var exitCode = Program.Main(args);
176+
177+
errorStream.Position = 0;
178+
using var errorStreamReader = new StreamReader(errorStream);
179+
var errorLogs = errorStreamReader.ReadToEnd().Trim();
180+
if (!errorLogs.StartsWith("No errors. Please continue being awesome."))
181+
{
182+
Logger.Instance.LogInfo($"Warnings or errors from ColorzCore: {errorLogs}");
183+
}
184+
185+
return exitCode;
172186
}
173187

174188
/// <summary>
@@ -195,7 +209,6 @@ public string GetSpoiler()
195209
spoilerBuilder.AppendLine();
196210
AddActualPlaythroughSpoiler(spoilerBuilder);
197211

198-
199212
return spoilerBuilder.ToString();
200213
}
201214

Binary file not shown.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.thumb
2+
ldrb r0,[r4,#0xA]
3+
cmp r0,#0
4+
bne noDeletion
5+
ldrb r0,[r4,#0xB]
6+
cmp r0,#0
7+
bne noDeletion
8+
9+
mov r0,#0x63
10+
@ CheckLocalFlag
11+
ldr r3,=#0x807C5F4
12+
mov lr,r3
13+
.short 0xF800
14+
cmp r0,#0
15+
beq noDeletion
16+
17+
ldr r3,=#0x8085CA3
18+
bx r3
19+
20+
noDeletion:
21+
ldr r3,=#0x8085CA7
22+
bx r3

RandomizerCore/Resources/Patches/goalHint.event

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ SHORT 0x085A 0x1134 // show text box with text defined below
3636

3737
ORG 0x9CC270+0x34*4
3838
WORD goalTextEnglish-0x9CC270
39-
ORG 0x9F7420+0x34*4
40-
WORD goalTextFrench-0x9F7420
41-
ORG 0xA3EEB0+0x34*4
42-
WORD goalTextGerman-0xA3EEB0
43-
ORG 0xA81E70+0x34*4
44-
WORD goalTextSpanish-0xA81E70
45-
ORG 0xAC37A0+0x34*4
46-
WORD goalTextItalian-0xAC37A0
39+
ORG 0xA15B60+0x34*4
40+
WORD goalTextFrench-0xA15B60
41+
ORG 0xA5B450+0x34*4
42+
WORD goalTextGerman-0xA5B450
43+
ORG 0xA9D400+0x34*4
44+
WORD goalTextSpanish-0xA9D400
45+
ORG 0xADFAD0+0x34*4
46+
WORD goalTextItalian-0xADFAD0
4747
POP
4848

4949
goalTextEnglish:
Binary file not shown.

RandomizerCore/Resources/Patches/improvements/asm/keysanityHistory.s

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@
44
.thumb
55
push {r0-r7}
66

7+
@check if the phonograph is active
8+
ldr r4, =#0x2000050
9+
ldrh r0, [r4,#0x08]
10+
ldr r1, =#0x3301
11+
cmp r0, r1
12+
bne notPhonograph
13+
14+
ldrb r0, [r4]
15+
cmp r0, #0x00
16+
bne notPhonograph
17+
18+
ldr r4, =#0x200AF00
19+
ldrb r0, [r4,#0x01]
20+
cmp r0, #0xFF
21+
beq end
22+
23+
notPhonograph:
724
ldr r4, =#0x203F300
825
mov r5, #12
926
ldr r0, line

RandomizerCore/Resources/Patches/save/credits/strings.event

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ rollingTimeCreditsEnglish:
10111011
String("Rolling Time"); BYTE 0
10121012

10131013
rollingTimeCreditsFrench:
1014-
String("Nombre de Roulades"); BYTE 0
1014+
String("Temps de Roulades"); BYTE 0
10151015

10161016
rollingTimeCreditsGerman:
10171017
String("Zeit Rollen"); BYTE 0

RandomizerCore/Resources/Patches/traps.event

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ ALIGN 4
6363
moneyTrapEffect:
6464
#incbin "asm/moneyTrapEffect.dmp"
6565

66+
PUSH; ORG $85C98; jumpToHack(moneyTrapInit); POP
67+
ALIGN 4
68+
moneyTrapInit:
69+
#incbin "asm/moneyTrapInit.dmp"
70+
6671
ALIGN 4
6772
stinkTrap:
6873
#incbin "asm/stinkTrap.dmp"

Vendor/ColorzCore/ColorzCore/Program.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Linq;
5-
using System.Reflection;
65
using ColorzCore.IO;
76
using ColorzCore.Lexer;
87
using ColorzCore.Parser;
@@ -15,6 +14,7 @@ public static class Program
1514
private const int ExitFailure = 1;
1615
public static bool Debug = false;
1716
public static Stream CustomOutputStream { get; set; }
17+
public static Stream CustomErrorStream { get; set; }
1818

1919
private static string[] _helpstringarr =
2020
{
@@ -103,7 +103,11 @@ public static int Main(string[] args)
103103
break;
104104

105105
case "error":
106-
errorStream = new StreamWriter(File.OpenWrite(flag[1]));
106+
errorStream = new StreamWriter(CustomErrorStream ?? File.OpenWrite(flag[1]));
107+
if (CustomErrorStream != null)
108+
{
109+
((StreamWriter)errorStream).AutoFlush = true;
110+
}
107111
options.noColoredLog = true;
108112
break;
109113

@@ -228,8 +232,14 @@ public static int Main(string[] args)
228232
}
229233

230234
inStream.Close();
231-
outStream.Close();
232-
errorStream.Close();
235+
if (CustomOutputStream == null)
236+
{
237+
outStream.Close();
238+
}
239+
if (CustomErrorStream == null)
240+
{
241+
errorStream.Close();
242+
}
233243

234244
return success ? ExitSuccess : ExitFailure;
235245
}

0 commit comments

Comments
 (0)