Skip to content

Fixes for recently found bugs #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: staging
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
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

9 changes: 7 additions & 2 deletions RandomizerCore/Controllers/ControllerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
Expand Down
14 changes: 8 additions & 6 deletions RandomizerCore/Randomizer/Logic/Imports/LogicImports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
31 changes: 22 additions & 9 deletions RandomizerCore/Randomizer/Shuffler/ShufflerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}

/// <summary>
Expand All @@ -195,7 +209,6 @@ public string GetSpoiler()
spoilerBuilder.AppendLine();
AddActualPlaythroughSpoiler(spoilerBuilder);


return spoilerBuilder.ToString();
}

Expand Down
Binary file not shown.
22 changes: 22 additions & 0 deletions RandomizerCore/Resources/Patches/asm/moneyTrapInit.s
Original file line number Diff line number Diff line change
@@ -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
16 changes: 8 additions & 8 deletions RandomizerCore/Resources/Patches/goalHint.event
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@
.thumb
push {r0-r7}

@check if the phonograph is active
ldr r4, =#0x2000050
ldrh r0, [r4,#0x08]
ldr r1, =#0x3301
cmp r0, r1
bne notPhonograph

ldrb r0, [r4]
cmp r0, #0x00
bne notPhonograph

ldr r4, =#0x200AF00
ldrb r0, [r4,#0x01]
cmp r0, #0xFF
beq end

notPhonograph:
ldr r4, =#0x203F300
mov r5, #12
ldr r0, line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions RandomizerCore/Resources/Patches/traps.event
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 14 additions & 4 deletions Vendor/ColorzCore/ColorzCore/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 =
{
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -228,8 +232,14 @@ public static int Main(string[] args)
}

inStream.Close();
outStream.Close();
errorStream.Close();
if (CustomOutputStream == null)
{
outStream.Close();
}
if (CustomErrorStream == null)
{
errorStream.Close();
}

return success ? ExitSuccess : ExitFailure;
}
Expand Down