Skip to content
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

Add Disc Support #3

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ A program to build Syati Modules. (Command line tool)


```bat
SyatiModuleBuildTool.exe <REGION> <Path_To_Syati> <Path_To_Modules_Folder> <Path_To_Output>
SyatiModuleBuildTool.exe <REGION> <Path_To_Syati> <Path_To_Modules_Folder> <Path_To_Code_Output_Folder>
```

**Mandatory Arguments:**
- Replace `<REGION>` with one of the following: `USA`, `PAL`, `JPN`, `KOR`, `TWN`. Choose the one that matches your game disc.
- Replace `<Path_To_Syati>` with the complete path to your Syati folder. If your path has spaces in it, surround it with Quotation Marks "
- Replace `<Path_To_Modules>` with the complete path to the folder that you put the modules into. If your path has spaces in it, surround it with Quotation Marks "
- Replace `<Path_To_Output>` with the complete path of the folder that you would like the resulting CustomCode.bin to be saved to. If your path has spaces in it, surround it with Quotation Marks "
- Replace `<Path_To_Code_Output_Folder>` with the complete path of the folder that you would like the resulting CustomCode.bin to be saved to. If your path has spaces in it, surround it with Quotation Marks "
- Replace `<Path_To_Disc_Output_Folder>` with the complete path of the folder that you would like the disc files of the modules to be copied to. If your path has spaces in it, surround it with Quotation Marks ".

**Optional Arguments:**
- If you would like to copy disc files, add `-d <Path>` to the end of the command, and replace `<Path>` with the folder you would like to copy the disc files to. If your path has spaces in it, surround it with Quotation Marks ". (Ensure there is a space between the last path and this argument)
- If you would like to use **UniBuild**, add `-u` to the end of the command. (Ensure there is a space between the last path and the `-u`)
> *Note: UniBuild is an alternative method of compiling modules which may result in smaller output binaries. If you have less than 10 modules, you do not need UniBuild.*

After running the command, you will be given a **CustomCode.bin** and a **CustomCode.map**.
After running the command, you will be given a **CustomCode.bin**, a **CustomCode.map**, and if specified, the disc files of all your modules.
35 changes: 32 additions & 3 deletions SyatiModuleBuildTool/DiscUtility.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
namespace SyatiModuleBuildTool;

public static class DiscUtility
{
// Todo lol
public static class DiscUtility {
public static void CopyAllFiles(List<ModuleInfo> modules, string output) {
foreach (ModuleInfo module in modules)
CopyFiles(module, output);
}

public static void CopyFiles(ModuleInfo module, string output) {
var sourceDiscFolder = Path.Combine(module.FolderPath, "disc");

if (!Directory.Exists(sourceDiscFolder))
return;

Console.WriteLine($"Copying files from {sourceDiscFolder}");

var discPaths = Directory.GetFiles(sourceDiscFolder, "*", SearchOption.AllDirectories);

foreach (var sourcePath in discPaths) {
var relativePath = Path.GetRelativePath(sourceDiscFolder, sourcePath);
var targetPath = Path.Combine(output, relativePath);

try {
var targetDirectory = Path.GetDirectoryName(targetPath);
if (targetDirectory is not null)
Directory.CreateDirectory(targetDirectory);

File.Copy(sourcePath, targetPath, true);
}
catch (Exception e) {
Console.WriteLine($"Error while copying \"{sourceDiscFolder}\": {e.Message}");
}
}
}
}
29 changes: 26 additions & 3 deletions SyatiModuleBuildTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void TryLoadModule(string ModulePath)
$"-D{args[0]}"
];
Console.WriteLine();
if (args.Any(o => o.Equals("-u")))
if (args.Any(s => s.Equals("-u")))
ModuleUtility.CompileAllUnibuild(Modules, Flags, IncludePaths, SyatiFolderPath, args[3], ref AllObjectOutputs);
else
ModuleUtility.CompileAllModules(Modules, Flags, IncludePaths, SyatiFolderPath, ref AllObjectOutputs);
Expand Down Expand Up @@ -185,17 +185,40 @@ void TryLoadModule(string ModulePath)
throw new InvalidOperationException("Linker Failure");
}

if (GetOptionalArgument(ref args, "-d", out var path) && path is not null) {
Console.WriteLine();
Console.WriteLine("Copying disc...");

DiscUtility.CopyAllFiles(Modules, path);
}

Console.WriteLine();
Console.WriteLine("Complete!");
}
static bool GetOptionalArgument(ref string[] args, string flag, out string? str) {
for (int i = 4; i < args.Length; i++) {
if (args[i] == flag) {
if (i + 1 < args.Length)
str = args[i + 1];
else
str = null;

return true;
}
}

str = null;
return false;
}
static void Help()
{
Console.WriteLine(
"""
SyatiModuleBuildTool.exe <REGION> <Path_To_Syati_Repo> <Path_To_Modules_Folder> <Path_To_Output_Folder>
SyatiModuleBuildTool.exe <REGION> <Path_To_Syati_Repo> <Path_To_Modules_Folder> <Path_To_Code_Output_Folder>

Extra options:
-u Enable UniBuild. UniBuild can shrink the final .bin file size at the potential cost of debuggability. Should only be used when you have a lot of modules. (10+)
-d <Path> Copy module disc files. To use this option, replace <Path> with the path you want to copy the disc files to.
-u Enable UniBuild. UniBuild can shrink the final .bin file size at the potential cost of debuggability. Should only be used when you have a lot of modules. (10+)
""");
}
static void Error(Exception ex)
Expand Down