From 832b0020ebad2ef840eda95f1c7976581e42cd0a Mon Sep 17 00:00:00 2001 From: LukeFZ <17146677+LukeFZ@users.noreply.github.com> Date: Tue, 29 Jul 2025 23:46:14 +0200 Subject: [PATCH] make inspector version a server api, split up output subtypes and tweak some option names --- .../Il2CppHub.cs | 6 +++++- .../Outputs/CSharpLayout.cs | 10 +++++++++ .../Outputs/CSharpStubOutput.cs | 21 +++---------------- .../Outputs/DisassemblerMetadataOutput.cs | 8 ------- .../Outputs/DisassemblerType.cs | 9 ++++++++ .../Outputs/TypeSortingMode.cs | 7 +++++++ .../Outputs/VsSolutionOutput.cs | 2 +- .../UiClient.cs | 3 --- .../UiContext.cs | 20 ++++++++++-------- .../src/lib/components/Footer.svelte | 9 +++----- .../src/lib/signalr/client-api.ts | 6 ------ .../src/lib/signalr/server-api.ts | 4 ++++ .../src/routes/export/[formatId]/+page.ts | 8 +++---- 13 files changed, 57 insertions(+), 56 deletions(-) create mode 100644 Il2CppInspector.Redux.FrontendCore/Outputs/CSharpLayout.cs create mode 100644 Il2CppInspector.Redux.FrontendCore/Outputs/DisassemblerType.cs create mode 100644 Il2CppInspector.Redux.FrontendCore/Outputs/TypeSortingMode.cs diff --git a/Il2CppInspector.Redux.FrontendCore/Il2CppHub.cs b/Il2CppInspector.Redux.FrontendCore/Il2CppHub.cs index b8b6918..35bb7ef 100644 --- a/Il2CppInspector.Redux.FrontendCore/Il2CppHub.cs +++ b/Il2CppInspector.Redux.FrontendCore/Il2CppHub.cs @@ -2,7 +2,7 @@ using Microsoft.AspNetCore.SignalR; namespace Il2CppInspector.Redux.FrontendCore; -internal class Il2CppHub : Hub +public class Il2CppHub : Hub { private const string ContextKey = "context"; @@ -51,4 +51,8 @@ internal class Il2CppHub : Hub { await State.ExportIl2CppFiles(Client, outputDirectory); } + public async Task GetInspectorVersion() + { + return await UiContext.GetInspectorVersion(); + } } \ No newline at end of file diff --git a/Il2CppInspector.Redux.FrontendCore/Outputs/CSharpLayout.cs b/Il2CppInspector.Redux.FrontendCore/Outputs/CSharpLayout.cs new file mode 100644 index 0000000..3dfaa02 --- /dev/null +++ b/Il2CppInspector.Redux.FrontendCore/Outputs/CSharpLayout.cs @@ -0,0 +1,10 @@ +namespace Il2CppInspector.Redux.FrontendCore.Outputs; + +public enum CSharpLayout +{ + SingleFile, + Namespace, + Assembly, + Class, + Tree +} \ No newline at end of file diff --git a/Il2CppInspector.Redux.FrontendCore/Outputs/CSharpStubOutput.cs b/Il2CppInspector.Redux.FrontendCore/Outputs/CSharpStubOutput.cs index cdb7ba6..b24c124 100644 --- a/Il2CppInspector.Redux.FrontendCore/Outputs/CSharpStubOutput.cs +++ b/Il2CppInspector.Redux.FrontendCore/Outputs/CSharpStubOutput.cs @@ -7,28 +7,13 @@ public class CSharpStubOutput : IOutputFormatProvider { public static string Id => "cs"; - private enum CSharpLayout - { - SingleFile, - Namespace, - Assembly, - Class, - Tree - } - - private enum TypeSortingMode - { - Alphabetical, - TypeDefinitionIndex - } - private class Settings(Dictionary settings) { public readonly CSharpLayout Layout = settings.GetAsEnumOrDefault("layout", CSharpLayout.SingleFile); - public readonly bool FlattenHierarchy = settings.GetAsBooleanOrDefault("flatten", false); - public readonly TypeSortingMode SortingMode = settings.GetAsEnumOrDefault("sorting", TypeSortingMode.Alphabetical); + public readonly bool FlattenHierarchy = settings.GetAsBooleanOrDefault("flattenhierarchy", false); + public readonly TypeSortingMode SortingMode = settings.GetAsEnumOrDefault("sortingmode", TypeSortingMode.Alphabetical); public readonly bool SuppressMetadata = settings.GetAsBooleanOrDefault("suppressmetadata", false); - public readonly bool MustCompile = settings.GetAsBooleanOrDefault("compilable", false); + public readonly bool MustCompile = settings.GetAsBooleanOrDefault("mustcompile", false); public readonly bool SeperateAssemblyAttributes = settings.GetAsBooleanOrDefault("seperateassemblyattributes", true); } diff --git a/Il2CppInspector.Redux.FrontendCore/Outputs/DisassemblerMetadataOutput.cs b/Il2CppInspector.Redux.FrontendCore/Outputs/DisassemblerMetadataOutput.cs index 3613a84..a088908 100644 --- a/Il2CppInspector.Redux.FrontendCore/Outputs/DisassemblerMetadataOutput.cs +++ b/Il2CppInspector.Redux.FrontendCore/Outputs/DisassemblerMetadataOutput.cs @@ -9,14 +9,6 @@ public class DisassemblerMetadataOutput : IOutputFormatProvider { public static string Id => "disassemblermetadata"; - private enum DisassemblerType - { - IDA, - Ghidra, - BinaryNinja, - None - } - private class Settings(Dictionary dict) { public readonly DisassemblerType Disassembler = dict.GetAsEnumOrDefault("disassembler", DisassemblerType.IDA); diff --git a/Il2CppInspector.Redux.FrontendCore/Outputs/DisassemblerType.cs b/Il2CppInspector.Redux.FrontendCore/Outputs/DisassemblerType.cs new file mode 100644 index 0000000..4d7e4d9 --- /dev/null +++ b/Il2CppInspector.Redux.FrontendCore/Outputs/DisassemblerType.cs @@ -0,0 +1,9 @@ +namespace Il2CppInspector.Redux.FrontendCore.Outputs; + +public enum DisassemblerType +{ + IDA, + Ghidra, + BinaryNinja, + None +} \ No newline at end of file diff --git a/Il2CppInspector.Redux.FrontendCore/Outputs/TypeSortingMode.cs b/Il2CppInspector.Redux.FrontendCore/Outputs/TypeSortingMode.cs new file mode 100644 index 0000000..a14abb1 --- /dev/null +++ b/Il2CppInspector.Redux.FrontendCore/Outputs/TypeSortingMode.cs @@ -0,0 +1,7 @@ +namespace Il2CppInspector.Redux.FrontendCore.Outputs; + +public enum TypeSortingMode +{ + Alphabetical, + TypeDefinitionIndex +} \ No newline at end of file diff --git a/Il2CppInspector.Redux.FrontendCore/Outputs/VsSolutionOutput.cs b/Il2CppInspector.Redux.FrontendCore/Outputs/VsSolutionOutput.cs index a6107dc..2dac1b0 100644 --- a/Il2CppInspector.Redux.FrontendCore/Outputs/VsSolutionOutput.cs +++ b/Il2CppInspector.Redux.FrontendCore/Outputs/VsSolutionOutput.cs @@ -10,7 +10,7 @@ public class VsSolutionOutput : IOutputFormatProvider private class Settings(Dictionary settings) { public readonly string UnityPath = settings.GetValueOrDefault("unitypath", ""); - public readonly string UnityAssembliesPath = settings.GetValueOrDefault("assembliespath", ""); + public readonly string UnityAssembliesPath = settings.GetValueOrDefault("unityassembliespath", ""); } public async Task Export(AppModel model, UiClient client, string outputPath, Dictionary settingsDict) diff --git a/Il2CppInspector.Redux.FrontendCore/UiClient.cs b/Il2CppInspector.Redux.FrontendCore/UiClient.cs index 1bd298b..1aeb23a 100644 --- a/Il2CppInspector.Redux.FrontendCore/UiClient.cs +++ b/Il2CppInspector.Redux.FrontendCore/UiClient.cs @@ -41,7 +41,4 @@ public class UiClient(ISingleClientProxy client) public async Task OnImportCompleted(CancellationToken cancellationToken = default) => await client.SendAsync(nameof(OnImportCompleted), cancellationToken); - - public async Task SetInspectorVersion(string version, CancellationToken cancellationToken = default) - => await client.SendAsync(nameof(SetInspectorVersion), version, cancellationToken); } \ No newline at end of file diff --git a/Il2CppInspector.Redux.FrontendCore/UiContext.cs b/Il2CppInspector.Redux.FrontendCore/UiContext.cs index dfcb1cf..44eca27 100644 --- a/Il2CppInspector.Redux.FrontendCore/UiContext.cs +++ b/Il2CppInspector.Redux.FrontendCore/UiContext.cs @@ -47,10 +47,8 @@ public class UiContext try { - var file = FileFormatStream.Load(stream, _loadOptions, client.EventHandler); - - if (file == null) - throw new InvalidOperationException("Failed to determine binary file format."); + var file = FileFormatStream.Load(stream, _loadOptions, client.EventHandler) + ?? throw new InvalidOperationException("Failed to determine binary file format."); if (file.NumImages == 0) throw new InvalidOperationException("Failed to find any binary images in the file"); @@ -122,7 +120,6 @@ public class UiContext public async Task Initialize(UiClient client, CancellationToken cancellationToken = default) { await client.ShowSuccessToast("SignalR initialized!", cancellationToken); - await client.SetInspectorVersion(typeof(UiContext).Assembly.GetAssemblyVersion() ?? "", cancellationToken); } public async Task LoadInputFiles(UiClient client, List inputFiles, @@ -200,16 +197,16 @@ public class UiContext { var model = _appModels[0]; - foreach (var queuedExport in _queuedExports) + foreach (var (formatId, outputDirectory, settings) in _queuedExports) { try { - var outputFormat = OutputFormatRegistry.GetOutputFormat(queuedExport.FormatId); - await outputFormat.Export(model, client, queuedExport.OutputDirectory, queuedExport.Settings); + var outputFormat = OutputFormatRegistry.GetOutputFormat(formatId); + await outputFormat.Export(model, client, outputDirectory, settings); } catch (Exception ex) { - await client.ShowErrorToast($"Export for format {queuedExport.FormatId} failed: {ex}", + await client.ShowErrorToast($"Export for format {formatId} failed: {ex}", cancellationToken); } } @@ -246,4 +243,9 @@ public class UiContext }, cancellationToken); } } + + public static Task GetInspectorVersion() + { + return Task.FromResult(typeof(UiContext).Assembly.GetAssemblyVersion() ?? ""); + } } \ No newline at end of file diff --git a/Il2CppInspector.Redux.GUI.UI/src/lib/components/Footer.svelte b/Il2CppInspector.Redux.GUI.UI/src/lib/components/Footer.svelte index 2cb6201..477623f 100644 --- a/Il2CppInspector.Redux.GUI.UI/src/lib/components/Footer.svelte +++ b/Il2CppInspector.Redux.GUI.UI/src/lib/components/Footer.svelte @@ -6,14 +6,11 @@ $effect(() => { if (signalRState.api === undefined) return; - const unregisterSetInspectorVersion = - signalRState.api.client.onSetInspectorVersion(async (version) => { + if (inspectorVersion === undefined) { + signalRState.api.server.getInspectorVersion().then((version) => { inspectorVersion = version; }); - - return () => { - unregisterSetInspectorVersion(); - }; + } }); diff --git a/Il2CppInspector.Redux.GUI.UI/src/lib/signalr/client-api.ts b/Il2CppInspector.Redux.GUI.UI/src/lib/signalr/client-api.ts index ebd9364..2a5b4b9 100644 --- a/Il2CppInspector.Redux.GUI.UI/src/lib/signalr/client-api.ts +++ b/Il2CppInspector.Redux.GUI.UI/src/lib/signalr/client-api.ts @@ -45,12 +45,6 @@ export class SignalRClientApi { return this.registerHandler("OnImportCompleted", handler); } - onSetInspectorVersion( - handler: (version: string) => Promise, - ): () => void { - return this.registerHandler("SetInspectorVersion", handler); - } - private registerHandler( name: string, handler: (...args: any[]) => Promise, diff --git a/Il2CppInspector.Redux.GUI.UI/src/lib/signalr/server-api.ts b/Il2CppInspector.Redux.GUI.UI/src/lib/signalr/server-api.ts index 8cb4981..16280ed 100644 --- a/Il2CppInspector.Redux.GUI.UI/src/lib/signalr/server-api.ts +++ b/Il2CppInspector.Redux.GUI.UI/src/lib/signalr/server-api.ts @@ -41,4 +41,8 @@ export class SignalRServerApi { async exportIl2CppFiles(targetDirectory: string) { return await this.connection.send("ExportIl2CppFiles", targetDirectory); } + + async getInspectorVersion(): Promise { + return await this.connection.invoke("GetInspectorVersion"); + } } diff --git a/Il2CppInspector.Redux.GUI.UI/src/routes/export/[formatId]/+page.ts b/Il2CppInspector.Redux.GUI.UI/src/routes/export/[formatId]/+page.ts index 0956595..b32749b 100644 --- a/Il2CppInspector.Redux.GUI.UI/src/routes/export/[formatId]/+page.ts +++ b/Il2CppInspector.Redux.GUI.UI/src/routes/export/[formatId]/+page.ts @@ -43,7 +43,7 @@ let mockFormatSettings: { { type: "option", name: { - id: "flatten", + id: "flattenhierarchy", label: "Don't nest folders (flatten hierarchy)", }, default: false, @@ -55,7 +55,7 @@ let mockFormatSettings: { { type: "combobox", name: { - id: "sorting", + id: "sortingmode", label: "Type sorting", }, default: "alphabetical", @@ -85,7 +85,7 @@ let mockFormatSettings: { { type: "option", name: { - id: "compilable", + id: "mustcompile", label: "Attempt to generate output that compiles", }, default: false, @@ -117,7 +117,7 @@ let mockFormatSettings: { { type: "filepath", name: { - id: "assembliespath", + id: "unityassembliespath", label: "Unity script assemblies path", }, directoryPath: true,