Skip to content

Commit

Permalink
ASM hack QoL changes & upgrade to .NET 8.0 (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonko0493 authored Jan 12, 2024
1 parent ea433e5 commit c54451e
Show file tree
Hide file tree
Showing 33 changed files with 203 additions and 215 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Please file bugs in the Issues tab in this repository. Please include the follow
Serial Loops is licensed under the GPLv3. See [LICENSE](LICENSE) for more information.

### Building
Serial Loops requires the .NET 6.0 SDK to build. You can download it [here](https://dotnet.microsoft.com/download/dotnet/6.0). To build Serial Loops for your platform, run:
Serial Loops requires the .NET 8.0 SDK to build. You can download it [here](https://dotnet.microsoft.com/download/dotnet/8.0). To build Serial Loops for your platform, run:

```bash
dotnet build src/PLATFORM
Expand All @@ -97,4 +97,4 @@ Remember to replace `PLATFORM` with the platform you're on:
* `SerialLoops.Mac` for macOS
* `SerialLoops.Wpf` for Windows

We recommend Visual Studio 2022 for development. If you'd like to contribute new features or fixes, we recommend [getting in touch on Discord first](https://discord.gg/nesRSbpeFM) before submitting a Pull Request!
We recommend [Visual Studio 2022](https://visualstudio.microsoft.com/) on Windows or [Rider](https://www.jetbrains.com/rider/) on Linux/Mac for development. If you'd like to contribute new features or fixes, we recommend [getting in touch on Discord first](https://discord.gg/nesRSbpeFM) before submitting a pull request!
2 changes: 1 addition & 1 deletion src/SerialLoops.Gtk/SerialLoops.Gtk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<Version>$(SLAssemblyVersion)</Version>
<InformationalVersion>$(SLVersion)</InformationalVersion>
Expand Down
2 changes: 1 addition & 1 deletion src/SerialLoops.Lib/Items/BackgroundItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public BackgroundItem(string name, int id, BgTableEntry entry, Project project)
BackgroundType = entry.Type;
Graphic1 = project.Grp.Files.First(g => g.Index == entry.BgIndex1);
Graphic2 = project.Grp.Files.FirstOrDefault(g => g.Index == entry.BgIndex2); // can be null if type is SINGLE_TEX
CgStruct cgEntry = project.Extra.Cgs.FirstOrDefault(c => c.BgId == Id);
CgExtraData cgEntry = project.Extra.Cgs.FirstOrDefault(c => c.BgId == Id);
if (cgEntry is not null)
{
CgName = cgEntry?.Name?.GetSubstitutedString(project);
Expand Down
4 changes: 2 additions & 2 deletions src/SerialLoops.Lib/Items/GroupSelectionItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ namespace SerialLoops.Lib.Items
{
public class GroupSelectionItem : Item
{
public ScenarioSelectionStruct Selection { get; set; }
public ScenarioSelection Selection { get; set; }
public int Index { get; set; }

public GroupSelectionItem(ScenarioSelectionStruct selection, int index, Project project) : base($"Selection {index}", ItemType.Group_Selection)
public GroupSelectionItem(ScenarioSelection selection, int index, Project project) : base($"Selection {index}", ItemType.Group_Selection)
{
Selection = selection;
Index = index;
Expand Down
4 changes: 2 additions & 2 deletions src/SerialLoops.Lib/Items/ItemDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ public List<ItemDescription> GetReferencesTo(Project project)
{
references.Add(scenario);
}
references.AddRange(project.Items.Where(i => i.Type == ItemType.Group_Selection && ((GroupSelectionItem)i).Selection.RouteSelections.Where(s => s is not null).Any(s => s.Routes.Any(r => r.ScriptIndex == script.Event.Index))));
references.AddRange(project.Items.Where(i => i.Type == ItemType.Group_Selection && ((GroupSelectionItem)i).Selection.Activities.Where(s => s is not null).Any(s => s.Routes.Any(r => r.ScriptIndex == script.Event.Index))));
references.AddRange(project.Items.Where(i => i.Type == ItemType.Topic &&
(((TopicItem)i).Topic.CardType != TopicCardType.Main && ((TopicItem)i).Topic.EventIndex == script.Event.Index ||
(((TopicItem)i).TopicEntry.CardType != TopicCardType.Main && ((TopicItem)i).TopicEntry.EventIndex == script.Event.Index ||
(((TopicItem)i).HiddenMainTopic?.EventIndex ?? -1) == script.Event.Index)));
references.AddRange(project.Items.Where(i => i.Type == ItemType.Script && ((ScriptItem)i).Event.ConditionalsSection.Objects.Contains(Name)));
return references;
Expand Down
8 changes: 4 additions & 4 deletions src/SerialLoops.Lib/Items/PuzzleItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ public override void Refresh(Project project, ILogger log)
GraphicsFile singularityLayout = project.Grp.Files.First(f => f.Index == Puzzle.Settings.SingularityLayout);
GraphicsFile singularityTexture = project.Grp.Files.First(f => f.Index == Puzzle.Settings.SingularityTexture);
SingularityImage = singularityLayout.GetLayout(
new List<GraphicsFile>() { singularityTexture },
[singularityTexture],
0,
singularityLayout.LayoutEntries.Count,
false,
true).bitmap;
}

public static readonly List<string> Characters = new()
{
public static readonly List<string> Characters =
[
"UNKNOWN (0)",
"KYON",
"HARUHI",
"MIKURU",
"NAGATO",
"KOIZUMI",
"ANY",
};
];
}
}
4 changes: 2 additions & 2 deletions src/SerialLoops.Lib/Items/ScriptItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public Dictionary<ScriptSection, List<ScriptItemCommand>> GetScriptCommandTree(P
{
try
{
Dictionary<ScriptSection, List<ScriptItemCommand>> commands = new();
Dictionary<ScriptSection, List<ScriptItemCommand>> commands = [];
foreach (ScriptSection section in Event.ScriptSections)
{
commands.Add(section, new());
commands.Add(section, []);
foreach (ScriptCommandInvocation command in section.Objects)
{
commands[section].Add(ScriptItemCommand.FromInvocation(command, section, commands[section].Count, Event, project, log));
Expand Down
12 changes: 6 additions & 6 deletions src/SerialLoops.Lib/Items/TopicItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ namespace SerialLoops.Lib.Items
{
public class TopicItem : Item
{
public TopicStruct Topic { get; set; }
public TopicStruct HiddenMainTopic { get; set; }
public Topic TopicEntry { get; set; }
public Topic HiddenMainTopic { get; set; }
public (string ScriptName, ScriptCommandInvocation command)[] ScriptUses { get; set; }

public TopicItem(TopicStruct topicStruct, Project project) : base($"{topicStruct.Id}", ItemType.Topic)
public TopicItem(Topic topic, Project project) : base($"{topic.Id}", ItemType.Topic)
{
DisplayName = $"{topicStruct.Id} - {topicStruct.Title.GetSubstitutedString(project)}";
DisplayName = $"{topic.Id} - {topic.Title.GetSubstitutedString(project)}";
CanRename = false;
Topic = topicStruct;
TopicEntry = topic;
PopulateScriptUses(project);
}

Expand All @@ -29,7 +29,7 @@ public void PopulateScriptUses(Project project)
ScriptUses = project.Evt.Files.SelectMany(e =>
e.ScriptSections.SelectMany(sec =>
sec.Objects.Where(c => c.Command.Mnemonic == EventFile.CommandVerb.TOPIC_GET.ToString()).Select(c => (e.Name[0..^1], c))))
.Where(t => t.c.Parameters[0] == Topic.Id).ToArray();
.Where(t => t.c.Parameters[0] == TopicEntry.Id).ToArray();
}
}
}
4 changes: 2 additions & 2 deletions src/SerialLoops.Lib/Items/VoicedLineItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace SerialLoops.Lib.Items
{
public class VoicedLineItem : Item, ISoundItem
{
private string _vceFile;
private readonly string _vceFile;

public string VoiceFile { get; set; }
public int Index { get; set; }
Expand All @@ -31,7 +31,7 @@ public VoicedLineItem(string voiceFile, int index, Project project) : base(Path.

public IWaveProvider GetWaveProvider(ILogger log, bool loop = false)
{
byte[] adxBytes = Array.Empty<byte>();
byte[] adxBytes = [];
try
{
adxBytes = File.ReadAllBytes(_vceFile);
Expand Down
8 changes: 4 additions & 4 deletions src/SerialLoops.Lib/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -609,15 +609,15 @@ public LoadProjectResult LoadArchives(ILogger log, IProgressTracker tracker)
{
Evt.Files.First(f => f.Name == "TOPICS").InitializeTopicFile();
TopicFile = Evt.Files.First(f => f.Name == "TOPICS");
tracker.Focus("Topics", TopicFile.TopicStructs.Count);
foreach (TopicStruct topic in TopicFile.TopicStructs)
tracker.Focus("Topics", TopicFile.Topics.Count);
foreach (Topic topic in TopicFile.Topics)
{
// Main topics have shadow topics that are located at ID + 40 (this is actually how the game finds them)
// So if we're a main topic and we see another topic 40 back, we know we're one of these shadow topics and should really be
// rolled into the original main topic
if (topic.Type == TopicType.Main && Items.Any(i => i.Type == ItemDescription.ItemType.Topic && ((TopicItem)i).Topic.Id == topic.Id - 40))
if (topic.Type == TopicType.Main && Items.Any(i => i.Type == ItemDescription.ItemType.Topic && ((TopicItem)i).TopicEntry.Id == topic.Id - 40))
{
((TopicItem)Items.First(i => i.Type == ItemDescription.ItemType.Topic && ((TopicItem)i).Topic.Id == topic.Id - 40)).HiddenMainTopic = topic;
((TopicItem)Items.First(i => i.Type == ItemDescription.ItemType.Topic && ((TopicItem)i).TopicEntry.Id == topic.Id - 40)).HiddenMainTopic = topic;
}
else
{
Expand Down
16 changes: 8 additions & 8 deletions src/SerialLoops.Lib/SerialLoops.Lib.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>disable</Nullable>
<Version>$(SLAssemblyVersion)</Version>
Expand All @@ -10,15 +10,15 @@

<ItemGroup>
<PackageReference Include="BunLabs.NAudio.Flac" Version="2.0.1" />
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="2.8.2.3" />
<PackageReference Include="HarfBuzzSharp.NativeAssets.macOS" Version="2.8.2.3" />
<PackageReference Include="HaruhiChokuretsuLib" Version="0.34.7" />
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="7.3.0" />
<PackageReference Include="HarfBuzzSharp.NativeAssets.macOS" Version="7.3.0" />
<PackageReference Include="HaruhiChokuretsuLib" Version="0.35.2" />
<PackageReference Include="NAudio.Vorbis" Version="1.5.0" />
<PackageReference Include="NitroPacker.Core" Version="2.2.5" />
<PackageReference Include="NLayer" Version="1.14.0" />
<PackageReference Include="NLayer.NAudioSupport" Version="1.3.0" />
<PackageReference Include="NitroPacker.Core" Version="2.4.3" />
<PackageReference Include="NLayer" Version="1.15.0" />
<PackageReference Include="NLayer.NAudioSupport" Version="1.4.0" />
<PackageReference Include="QuikGraph" Version="2.5.0" />
<PackageReference Include="Topten.RichTextKit" Version="0.4.165" />
<PackageReference Include="Topten.RichTextKit" Version="0.4.166" />
<PackageReference Include="VCDiff" Version="4.0.1" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/SerialLoops.Mac/SerialLoops.Mac.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RuntimeIdentifiers>osx-x64;osx-arm64</RuntimeIdentifiers>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<Version>$(SLAssemblyVersion)</Version>
Expand Down
2 changes: 1 addition & 1 deletion src/SerialLoops.Wpf/SerialLoops.Wpf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net8.0-windows</TargetFramework>
<ApplicationIcon>WindowsIcon.ico</ApplicationIcon>
<Version>$(SLAssemblyVersion)</Version>
<InformationalVersion>$(SLVersion)</InformationalVersion>
Expand Down
64 changes: 52 additions & 12 deletions src/SerialLoops/Dialogs/AsmHacksDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using HaruhiChokuretsuLib.Util;
using SerialLoops.Lib;
using SerialLoops.Lib.Hacks;
using SerialLoops.Lib.Util;
using SerialLoops.Utility;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -156,7 +157,7 @@ public AsmHacksDialog(Project project, Config config, ILogger log)
};
saveButton.Click += (sender, args) =>
{
List<AsmHack> appliedHacks = new();
List<AsmHack> appliedHacks = [];
foreach (CheckBox checkBox in hacksLayout.Items.Select(s => s.Control).Cast<CheckBox>())
{
AsmHack hack = config.Hacks.First(f => f.Name == checkBox.Text);
Expand Down Expand Up @@ -199,12 +200,18 @@ public AsmHacksDialog(Project project, Config config, ILogger log)
log.LogException($"Failed to read ARM9 from '{arm9Path}'", ex);
}
List<string> dockerContainerNames = ["sl-arm9-container"];
try
{
ARM9AsmHack.Insert(Path.Combine(project.BaseDirectory, "src"), arm9, 0x02005ECC, config.UseDocker ? config.DevkitArmDockerTag : string.Empty,
(object sender, DataReceivedEventArgs e) => log.Log(e.Data),
(object sender, DataReceivedEventArgs e) => log.LogWarning(e.Data),
devkitArmPath: config.DevkitArmPath);
LoopyProgressTracker tracker = new();
ProgressDialog _ = new(() =>
{
ARM9AsmHack.Insert(Path.Combine(project.BaseDirectory, "src"), arm9, 0x02005ECC, config.UseDocker ? config.DevkitArmDockerTag : string.Empty,
(object sender, DataReceivedEventArgs e) => { log.Log(e.Data); ((IProgressTracker)tracker).Focus(e.Data, 1); },
(object sender, DataReceivedEventArgs e) => log.LogWarning(e.Data),
devkitArmPath: config.DevkitArmPath, dockerContainerName: dockerContainerNames.Last());
}, () => {}, tracker, "Patching ARM9");
}
catch (Exception ex)
{
Expand All @@ -230,7 +237,7 @@ public AsmHacksDialog(Project project, Config config, ILogger log)
}
// Get the overlays
List<Overlay> overlays = new();
List<Overlay> overlays = [];
string originalOverlaysDir = Path.Combine(project.BaseDirectory, "original", "overlay");
string romInfoPath = Path.Combine(project.BaseDirectory, "original", $"{project.Name}.xml");
string newRomInfoPath = Path.Combine(project.BaseDirectory, "rom", $"{project.Name}.xml");
Expand All @@ -247,18 +254,24 @@ public AsmHacksDialog(Project project, Config config, ILogger log)
if (Directory.GetDirectories(overlaySourceDir).Contains(Path.Combine(overlaySourceDir, overlays[i].Name)))
{
// If the overlay directory is empty, we've reverted all the hacks in it and should clean it up
if (!Directory.GetFiles(Path.Combine(overlaySourceDir, overlays[i].Name, "source")).Any())
if (Directory.GetFiles(Path.Combine(overlaySourceDir, overlays[i].Name, "source")).Length == 0)
{
Directory.Delete(Path.Combine(overlaySourceDir, overlays[i].Name), true);
}
else
{
try
{
OverlayAsmHack.Insert(overlaySourceDir, overlays[i], newRomInfoPath, config.UseDocker ? config.DevkitArmDockerTag : string.Empty,
(object sender, DataReceivedEventArgs e) => log.Log(e.Data),
dockerContainerNames.Add($"sl-overlay-container{i}");
LoopyProgressTracker tracker = new();
ProgressDialog _ = new(() =>
{
OverlayAsmHack.Insert(overlaySourceDir, overlays[i], newRomInfoPath, config.UseDocker ? config.DevkitArmDockerTag : string.Empty,
(object sender, DataReceivedEventArgs e) => { log.Log(e.Data); ((IProgressTracker)tracker).Focus(e.Data, 1); },
(object sender, DataReceivedEventArgs e) => log.LogWarning(e.Data),
devkitArmPath: config.DevkitArmPath);
devkitArmPath: config.DevkitArmPath, dockerContainerName: dockerContainerNames.Last());
}, () => { }, tracker, $"Patching Overlay {overlays[i].Name}");
}
catch (Exception ex)
{
Expand Down Expand Up @@ -291,11 +304,26 @@ public AsmHacksDialog(Project project, Config config, ILogger log)
IEnumerable<string> failedHackNames = appliedHacks.Where(h => !h.Applied(project)).Select(h => h.Name);
if (failedHackNames.Any())
{
log.LogError($"Failed to apply the following hacks to the ROM:\n{string.Join(", ", failedHackNames)}\n\nPlease check the log file for more information.");
log.LogError($"Failed to apply the following hacks to the ROM:\n{string.Join(", ", failedHackNames)}\n\nPlease check the log file for more information.\n\nIn order to preserve state, no hacks were applied.");
foreach (AsmHack hack in appliedHacks)
{
hack.Revert(project, log);
}
IEnumerable<string> dirsToDelete = Directory.GetDirectories(Path.Combine(project.BaseDirectory, "src"), "-p", SearchOption.AllDirectories)
.Concat(Directory.GetDirectories(Path.Combine(project.BaseDirectory, "src"), "build", SearchOption.AllDirectories));
foreach (string dir in dirsToDelete)
{
Directory.Delete(dir, recursive: true);
}
string[] filesToDelete = Directory.GetFiles(Path.Combine(project.BaseDirectory, "src"), "arm9_newcode.x", SearchOption.AllDirectories);
foreach (string file in filesToDelete)
{
File.Delete(file);
}
}
else
{
if (appliedHacks.Any())
if (appliedHacks.Count != 0)
{
MessageBox.Show($"Successfully applied the following hacks:\n{string.Join(", ", appliedHacks.Select(h => h.Name))}", "Successfully applied hacks!", MessageBoxType.Information);
}
Expand All @@ -305,6 +333,18 @@ public AsmHacksDialog(Project project, Config config, ILogger log)
}
}
if (config.UseDocker)
{
Process.Start(new ProcessStartInfo
{
FileName = "docker",
Arguments = $"rm {string.Join(' ', dockerContainerNames)}",
UseShellExecute = false,
RedirectStandardError = true,
RedirectStandardOutput = true,
});
}
Close();
};

Expand Down
6 changes: 1 addition & 5 deletions src/SerialLoops/Editors/BackgroundEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@

namespace SerialLoops.Editors
{
public class BackgroundEditor : Editor
public class BackgroundEditor(BackgroundItem item, Project project, ILogger log) : Editor(item, log, project)
{
private BackgroundItem _bg;

public BackgroundEditor(BackgroundItem item, Project project, ILogger log) : base(item, log, project)
{
}

public override Container GetEditorPanel()
{
_bg = (BackgroundItem)Description;
Expand Down
Loading

0 comments on commit c54451e

Please sign in to comment.