Skip to content

Commit 6618816

Browse files
authored
Merge pull request #1 from ShrineFox/master
Add ability to patch RSTB via commandline
2 parents 73b68fd + b805c70 commit 6618816

File tree

4 files changed

+109
-79
lines changed

4 files changed

+109
-79
lines changed

Forms/RSTB/RSTBEditor.cs

Lines changed: 78 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -266,88 +266,107 @@ private async void UpdateFromModdedRomFs_Click(object sender, EventArgs e)
266266

267267
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
268268
{
269-
var moddedRomFsPath = folderBrowserDialog.SelectedPath;
269+
CreateUpdatedRSTBFromModdedRomFs(LoadedFile, folderBrowserDialog.SelectedPath);
270270

271-
var allFiles = Directory.GetFiles(moddedRomFsPath, "*", SearchOption.AllDirectories);
271+
TopMenu.Enabled = true;
272+
statusBar.Visible = false;
273+
statusProgressBar.Visible = false;
274+
275+
PopulateGridView();
272276

273-
List<string> changedFiles = [];
274-
List<string> addedFiles = [];
275-
int skippedFiles = 0;
276-
int removedFiles = 0;
277+
//foreach (DataGridViewRow row in mainDataGridView.Rows)
278+
//{
279+
// var name = row.Cells[0].Value.ToString();
277280

278-
TopMenu.Enabled = false;
281+
// if (changedFiles.Contains(name))
282+
// row.DefaultCellStyle.BackColor = Color.Yellow;
279283

280-
statusLabel.Text = $"";
281-
statusBar.Visible = true;
282-
statusProgressBar.Visible = true;
283-
statusProgressBar.Maximum = allFiles.Length;
284-
statusProgressBar.Value = 0;
284+
// if (addedFiles.Contains(name))
285+
// row.DefaultCellStyle.BackColor = Color.Green;
286+
//}
287+
}
288+
}
285289

286-
var progress = new Progress<(int Index, string FileName)>(value =>
287-
{
288-
statusLabel.Text = $"Getting file size... {value.FileName} ({value.Index}/{allFiles.Length})";
289-
statusProgressBar.Value = value.Index;
290-
});
290+
public async void CreateUpdatedRSTBFromModdedRomFs(ResourceTable rstb, string moddedRomFsPath, bool showResults = true)
291+
{
292+
var allFiles = Directory.GetFiles(moddedRomFsPath, "*", SearchOption.AllDirectories);
293+
294+
List<string> changedFiles = [];
295+
List<string> addedFiles = [];
296+
int skippedFiles = 0;
297+
int removedFiles = 0;
298+
299+
TopMenu.Enabled = false;
300+
301+
statusLabel.Text = $"";
302+
statusBar.Visible = true;
303+
statusProgressBar.Visible = true;
304+
statusProgressBar.Maximum = allFiles.Length;
305+
statusProgressBar.Value = 0;
291306

292-
await Task.Run(() =>
307+
var progress = new Progress<(int Index, string FileName)>(value =>
308+
{
309+
statusLabel.Text = $"Getting file size... {value.FileName} ({value.Index}/{allFiles.Length})";
310+
statusProgressBar.Value = value.Index;
311+
});
312+
313+
await Task.Run(() =>
314+
{
315+
int currentPosition = 1;
316+
317+
foreach (var originalFile in allFiles)
293318
{
294-
int currentPosition = 1;
319+
if (IsDisposed || Disposing) break;
295320

296-
foreach (var originalFile in allFiles)
321+
var path = Path.GetRelativePath(moddedRomFsPath, originalFile).Replace('\\', '/');
322+
if (path == "System/Resource/ResourceSizeTable.srsizetable" || path == "System/Resource/ResourceSizeTable.rsizetable")
297323
{
298-
if (IsDisposed || Disposing) break;
299-
300-
var path = Path.GetRelativePath(moddedRomFsPath, originalFile).Replace('\\', '/');
301-
if (path == "System/Resource/ResourceSizeTable.srsizetable" || path == "System/Resource/ResourceSizeTable.rsizetable")
302-
{
303-
skippedFiles++;
304-
continue;
305-
}
324+
skippedFiles++;
325+
continue;
326+
}
306327

307-
if (path.EndsWith(".byml") && path != "EventFlow/Info/EventFlowInfoProduct.byml")
308-
continue;
309-
328+
if (path.EndsWith(".byml") && path != "EventFlow/Info/EventFlowInfoProduct.byml")
329+
continue;
310330

311-
(progress as IProgress<(int, string)>).Report((currentPosition, path));
312331

313-
if (path.EndsWith(".zs"))
314-
path = path[..^3];
332+
(progress as IProgress<(int, string)>).Report((currentPosition, path));
315333

316-
var fileSize = GetFileSize(originalFile);
334+
if (path.EndsWith(".zs"))
335+
path = path[..^3];
317336

318-
if (fileSize < 0)
319-
{
320-
// remove unsupported file from rstb
321-
if (fileSize == -2)
322-
Console.WriteLine("Unsupported: {0}", path);
337+
var fileSize = GetFileSize(originalFile);
323338

324-
LoadedFile.Dictionary.Remove(path);
325-
removedFiles++;
326-
}
327-
else if (LoadedFile.Dictionary.TryGetValue(path, out var result) && fileSize >= 0 && fileSize != result.FileSize)
328-
{
329-
result.FileSize = (uint) fileSize;
330-
changedFiles.Add(path);
331-
}
339+
if (fileSize < 0)
340+
{
341+
// remove unsupported file from rstb
342+
if (fileSize == -2)
343+
Console.WriteLine("Unsupported: {0}", path);
332344

333-
else if (!LoadedFile.Dictionary.ContainsKey(path) && fileSize >= 0)
334-
{
335-
LoadedFile.AddEntry(new ResourceTable.ResourceTableEntry(path, (uint) fileSize, 0, false));
345+
rstb.Dictionary.Remove(path);
346+
removedFiles++;
347+
}
348+
else if (rstb.Dictionary.TryGetValue(path, out var result) && fileSize >= 0 && fileSize != result.FileSize)
349+
{
350+
result.FileSize = (uint)fileSize;
351+
changedFiles.Add(path);
352+
}
336353

337-
addedFiles.Add(path);
338-
}
354+
else if (!rstb.Dictionary.ContainsKey(path) && fileSize >= 0)
355+
{
356+
rstb.AddEntry(new ResourceTable.ResourceTableEntry(path, (uint)fileSize, 0, false));
339357

340-
currentPosition++;
358+
addedFiles.Add(path);
341359
}
342360

343-
if (IsDisposed || Disposing) return;
361+
currentPosition++;
362+
}
344363

345-
});
364+
if (IsDisposed || Disposing) return;
346365

347-
TopMenu.Enabled = true;
348-
statusBar.Visible = false;
349-
statusProgressBar.Visible = false;
366+
});
350367

368+
if (showResults)
369+
{
351370
if (changedFiles.Count > 0 || addedFiles.Count > 0)
352371
{
353372
MessageBox.Show($"Successfully updated table values!" +
@@ -358,20 +377,6 @@ await Task.Run(() =>
358377
"\n\nYou need to manually save your file in File > Save as...",
359378
"Complete", MessageBoxButtons.OK, MessageBoxIcon.Information);
360379
}
361-
362-
363-
PopulateGridView();
364-
365-
//foreach (DataGridViewRow row in mainDataGridView.Rows)
366-
//{
367-
// var name = row.Cells[0].Value.ToString();
368-
369-
// if (changedFiles.Contains(name))
370-
// row.DefaultCellStyle.BackColor = Color.Yellow;
371-
372-
// if (addedFiles.Contains(name))
373-
// row.DefaultCellStyle.BackColor = Color.Green;
374-
//}
375380
}
376381
}
377382

Program.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using HeavenTool.Forms.RSTB;
2+
using HeavenTool.Utility.FileTypes.RSTB;
23
using HeavenTool.Utility.IO;
34
using Microsoft.Win32.SafeHandles;
45
using System;
@@ -103,10 +104,24 @@ public static Form HandleInput(string[] originalArguments)
103104
return bcsvEditor;
104105

105106
case ".srsizetable":
106-
var rstbEditor = new RSTBEditor();
107-
rstbEditor.LoadFile(path);
108-
return rstbEditor;
109-
107+
if (originalArguments.Length >= 2)
108+
{
109+
var rstbEditor = new RSTBEditor();
110+
rstbEditor.LoadFile(path);
111+
rstbEditor.CreateUpdatedRSTBFromModdedRomFs(rstbEditor.LoadedFile, originalArguments[1], false);
112+
string outPath = path;
113+
if (originalArguments.Length >= 3)
114+
outPath = originalArguments[2];
115+
rstbEditor.LoadedFile.SaveTo(outPath, false);
116+
Environment.Exit(0);
117+
return null;
118+
}
119+
else
120+
{
121+
var rstbEditor = new RSTBEditor();
122+
rstbEditor.LoadFile(path);
123+
return rstbEditor;
124+
}
110125
default:
111126
return null;
112127
}

Properties/launchSettings.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"profiles": {
3+
"Heaven Tool": {
4+
"commandName": "Project",
5+
"commandLineArgs": "C:\\Users\\Ryan\\Documents\\GitHub\\ACNH-Tutorial-Skip\\RSTB_OG\\ResourceSizeTableTest.srsizetable C:\\Users\\Ryan\\AppData\\Roaming\\Ryujinx\\mods\\contents\\01006f8002326000\\romfs"
6+
}
7+
}
8+
}

Utility/FileTypes/RSTB/ResourceTable.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ public void UpdateUniques()
306306
/// Save the file
307307
/// </summary>
308308
/// <param name="filePath">File Location</param>
309-
public void SaveTo(string filePath)
309+
public void SaveTo(string filePath, bool showPrompt = true)
310310
{
311311
UpdateUniques();
312312

@@ -337,7 +337,9 @@ public void SaveTo(string filePath)
337337
memoryStream.Position = 0;
338338
memoryStream.Read(array, 0, array.Length);
339339

340-
var wantToCompress = MessageBox.Show("Do you want to compress the file?", "Compress to Yaz0?", MessageBoxButtons.YesNo);
340+
var wantToCompress = DialogResult.Yes;
341+
if (showPrompt)
342+
wantToCompress = MessageBox.Show("Do you want to compress the file?", "Compress to Yaz0?", MessageBoxButtons.YesNo);
341343
var result = wantToCompress == DialogResult.Yes ? Yaz0CompressionAlgorithm.Compress(array) : new MemoryStream(array);
342344

343345
result.ExportToFile(filePath);

0 commit comments

Comments
 (0)