From 6583787d8f196eed937661bde742a012eeb1f3ab Mon Sep 17 00:00:00 2001 From: LukeFZ <17146677+LukeFZ@users.noreply.github.com> Date: Tue, 29 Jul 2025 20:39:12 +0200 Subject: [PATCH] seperate redux ui impl into FrontendCore project --- .../Extensions.cs | 54 +++++++++++++++++++ .../FrontendCoreJsonSerializerContext.cs | 4 +- .../Il2CppHub.cs | 2 +- .../Il2CppInspector.Redux.FrontendCore.csproj | 16 ++++++ .../LoadingSession.cs | 2 +- .../Outputs/CSharpStubOutput.cs | 2 +- .../Outputs/CppScaffoldingOutput.cs | 2 +- .../Outputs/DisassemblerMetadataOutput.cs | 2 +- .../Outputs/DummyDllOutput.cs | 2 +- .../Outputs/IOutputFormat.cs | 2 +- .../Outputs/OutputFormatRegistry.cs | 2 +- .../Outputs/VsSolutionOutput.cs | 2 +- .../PathHeuristics.cs | 2 +- .../Properties/launchSettings.json | 12 +++++ .../UiClient.cs | 2 +- .../UiContext.cs | 4 +- Il2CppInspector.Redux.GUI/Extensions.cs | 26 --------- .../Il2CppInspector.Redux.GUI.csproj | 8 ++- Il2CppInspector.Redux.GUI/Program.cs | 28 +++------- Il2CppInspector.Redux.GUI/UiProcessService.cs | 1 + Il2CppInspector.sln | 6 +++ 21 files changed, 113 insertions(+), 68 deletions(-) create mode 100644 Il2CppInspector.Redux.FrontendCore/Extensions.cs rename Il2CppInspector.Redux.GUI/AppJsonSerializerContext.cs => Il2CppInspector.Redux.FrontendCore/FrontendCoreJsonSerializerContext.cs (57%) rename {Il2CppInspector.Redux.GUI => Il2CppInspector.Redux.FrontendCore}/Il2CppHub.cs (96%) create mode 100644 Il2CppInspector.Redux.FrontendCore/Il2CppInspector.Redux.FrontendCore.csproj rename {Il2CppInspector.Redux.GUI => Il2CppInspector.Redux.FrontendCore}/LoadingSession.cs (90%) rename {Il2CppInspector.Redux.GUI => Il2CppInspector.Redux.FrontendCore}/Outputs/CSharpStubOutput.cs (98%) rename {Il2CppInspector.Redux.GUI => Il2CppInspector.Redux.FrontendCore}/Outputs/CppScaffoldingOutput.cs (95%) rename {Il2CppInspector.Redux.GUI => Il2CppInspector.Redux.FrontendCore}/Outputs/DisassemblerMetadataOutput.cs (97%) rename {Il2CppInspector.Redux.GUI => Il2CppInspector.Redux.FrontendCore}/Outputs/DummyDllOutput.cs (93%) rename {Il2CppInspector.Redux.GUI => Il2CppInspector.Redux.FrontendCore}/Outputs/IOutputFormat.cs (84%) rename {Il2CppInspector.Redux.GUI => Il2CppInspector.Redux.FrontendCore}/Outputs/OutputFormatRegistry.cs (95%) rename {Il2CppInspector.Redux.GUI => Il2CppInspector.Redux.FrontendCore}/Outputs/VsSolutionOutput.cs (94%) rename {Il2CppInspector.Redux.GUI => Il2CppInspector.Redux.FrontendCore}/PathHeuristics.cs (96%) create mode 100644 Il2CppInspector.Redux.FrontendCore/Properties/launchSettings.json rename {Il2CppInspector.Redux.GUI => Il2CppInspector.Redux.FrontendCore}/UiClient.cs (97%) rename {Il2CppInspector.Redux.GUI => Il2CppInspector.Redux.FrontendCore}/UiContext.cs (98%) delete mode 100644 Il2CppInspector.Redux.GUI/Extensions.cs diff --git a/Il2CppInspector.Redux.FrontendCore/Extensions.cs b/Il2CppInspector.Redux.FrontendCore/Extensions.cs new file mode 100644 index 0000000..717c3e4 --- /dev/null +++ b/Il2CppInspector.Redux.FrontendCore/Extensions.cs @@ -0,0 +1,54 @@ +using System.Reflection; + +namespace Il2CppInspector.Redux.FrontendCore; + +public static class Extensions +{ + internal static bool GetAsBooleanOrDefault(this Dictionary dict, string key, bool defaultValue) + { + if (dict.TryGetValue(key, out var value) && bool.TryParse(value, out var boolResult)) + return boolResult; + + return defaultValue; + } + + internal static T GetAsEnumOrDefault(this Dictionary dict, string key, T defaultValue) + where T : struct, Enum + { + if (dict.TryGetValue(key, out var value) && Enum.TryParse(value, true, out var enumResult)) + return enumResult; + + return defaultValue; + } + + internal static string? GetAssemblyVersion(this Assembly assembly) + => assembly.GetCustomAttribute()?.InformationalVersion; + + public static WebApplication MapFrontendCore(this WebApplication app) + { + app.MapHub("/il2cpp"); + return app; + } + + public static IServiceCollection AddFrontendCore(this IServiceCollection services) + { + services.AddSignalR(config => + { +#if DEBUG + config.EnableDetailedErrors = true; +#endif + }); + + return services.AddCors(options => + { + options.AddDefaultPolicy(policy => + { + policy.SetIsOriginAllowed(origin => + origin.StartsWith("http://localhost") || origin.StartsWith("http://tauri.localhost")) + .AllowAnyHeader() + .WithMethods("GET", "POST") + .AllowCredentials(); + }); + }); + } +} \ No newline at end of file diff --git a/Il2CppInspector.Redux.GUI/AppJsonSerializerContext.cs b/Il2CppInspector.Redux.FrontendCore/FrontendCoreJsonSerializerContext.cs similarity index 57% rename from Il2CppInspector.Redux.GUI/AppJsonSerializerContext.cs rename to Il2CppInspector.Redux.FrontendCore/FrontendCoreJsonSerializerContext.cs index 37fd212..50e88b2 100644 --- a/Il2CppInspector.Redux.GUI/AppJsonSerializerContext.cs +++ b/Il2CppInspector.Redux.FrontendCore/FrontendCoreJsonSerializerContext.cs @@ -1,8 +1,8 @@ using System.Text.Json.Serialization; -namespace Il2CppInspector.Redux.GUI; +namespace Il2CppInspector.Redux.FrontendCore; [JsonSerializable(typeof(string))] [JsonSerializable(typeof(List))] [JsonSerializable(typeof(Dictionary))] -internal partial class AppJsonSerializerContext : JsonSerializerContext; \ No newline at end of file +public partial class FrontendCoreJsonSerializerContext : JsonSerializerContext; \ No newline at end of file diff --git a/Il2CppInspector.Redux.GUI/Il2CppHub.cs b/Il2CppInspector.Redux.FrontendCore/Il2CppHub.cs similarity index 96% rename from Il2CppInspector.Redux.GUI/Il2CppHub.cs rename to Il2CppInspector.Redux.FrontendCore/Il2CppHub.cs index c4d3651..b8b6918 100644 --- a/Il2CppInspector.Redux.GUI/Il2CppHub.cs +++ b/Il2CppInspector.Redux.FrontendCore/Il2CppHub.cs @@ -1,6 +1,6 @@ using Microsoft.AspNetCore.SignalR; -namespace Il2CppInspector.Redux.GUI; +namespace Il2CppInspector.Redux.FrontendCore; internal class Il2CppHub : Hub { diff --git a/Il2CppInspector.Redux.FrontendCore/Il2CppInspector.Redux.FrontendCore.csproj b/Il2CppInspector.Redux.FrontendCore/Il2CppInspector.Redux.FrontendCore.csproj new file mode 100644 index 0000000..037937b --- /dev/null +++ b/Il2CppInspector.Redux.FrontendCore/Il2CppInspector.Redux.FrontendCore.csproj @@ -0,0 +1,16 @@ + + + + net9.0 + enable + enable + true + Library + + + + + + + + diff --git a/Il2CppInspector.Redux.GUI/LoadingSession.cs b/Il2CppInspector.Redux.FrontendCore/LoadingSession.cs similarity index 90% rename from Il2CppInspector.Redux.GUI/LoadingSession.cs rename to Il2CppInspector.Redux.FrontendCore/LoadingSession.cs index 52189e1..d53bb21 100644 --- a/Il2CppInspector.Redux.GUI/LoadingSession.cs +++ b/Il2CppInspector.Redux.FrontendCore/LoadingSession.cs @@ -1,4 +1,4 @@ -namespace Il2CppInspector.Redux.GUI; +namespace Il2CppInspector.Redux.FrontendCore; public class LoadingSession : IAsyncDisposable { diff --git a/Il2CppInspector.Redux.GUI/Outputs/CSharpStubOutput.cs b/Il2CppInspector.Redux.FrontendCore/Outputs/CSharpStubOutput.cs similarity index 98% rename from Il2CppInspector.Redux.GUI/Outputs/CSharpStubOutput.cs rename to Il2CppInspector.Redux.FrontendCore/Outputs/CSharpStubOutput.cs index 9d4eddd..cdb7ba6 100644 --- a/Il2CppInspector.Redux.GUI/Outputs/CSharpStubOutput.cs +++ b/Il2CppInspector.Redux.FrontendCore/Outputs/CSharpStubOutput.cs @@ -1,7 +1,7 @@ using Il2CppInspector.Model; using Il2CppInspector.Outputs; -namespace Il2CppInspector.Redux.GUI.Outputs; +namespace Il2CppInspector.Redux.FrontendCore.Outputs; public class CSharpStubOutput : IOutputFormatProvider { diff --git a/Il2CppInspector.Redux.GUI/Outputs/CppScaffoldingOutput.cs b/Il2CppInspector.Redux.FrontendCore/Outputs/CppScaffoldingOutput.cs similarity index 95% rename from Il2CppInspector.Redux.GUI/Outputs/CppScaffoldingOutput.cs rename to Il2CppInspector.Redux.FrontendCore/Outputs/CppScaffoldingOutput.cs index fcc01ed..991b55e 100644 --- a/Il2CppInspector.Redux.GUI/Outputs/CppScaffoldingOutput.cs +++ b/Il2CppInspector.Redux.FrontendCore/Outputs/CppScaffoldingOutput.cs @@ -3,7 +3,7 @@ using Il2CppInspector.Cpp.UnityHeaders; using Il2CppInspector.Model; using Il2CppInspector.Outputs; -namespace Il2CppInspector.Redux.GUI.Outputs; +namespace Il2CppInspector.Redux.FrontendCore.Outputs; public class CppScaffoldingOutput : IOutputFormatProvider { diff --git a/Il2CppInspector.Redux.GUI/Outputs/DisassemblerMetadataOutput.cs b/Il2CppInspector.Redux.FrontendCore/Outputs/DisassemblerMetadataOutput.cs similarity index 97% rename from Il2CppInspector.Redux.GUI/Outputs/DisassemblerMetadataOutput.cs rename to Il2CppInspector.Redux.FrontendCore/Outputs/DisassemblerMetadataOutput.cs index e26190d..3613a84 100644 --- a/Il2CppInspector.Redux.GUI/Outputs/DisassemblerMetadataOutput.cs +++ b/Il2CppInspector.Redux.FrontendCore/Outputs/DisassemblerMetadataOutput.cs @@ -3,7 +3,7 @@ using Il2CppInspector.Cpp.UnityHeaders; using Il2CppInspector.Model; using Il2CppInspector.Outputs; -namespace Il2CppInspector.Redux.GUI.Outputs; +namespace Il2CppInspector.Redux.FrontendCore.Outputs; public class DisassemblerMetadataOutput : IOutputFormatProvider { diff --git a/Il2CppInspector.Redux.GUI/Outputs/DummyDllOutput.cs b/Il2CppInspector.Redux.FrontendCore/Outputs/DummyDllOutput.cs similarity index 93% rename from Il2CppInspector.Redux.GUI/Outputs/DummyDllOutput.cs rename to Il2CppInspector.Redux.FrontendCore/Outputs/DummyDllOutput.cs index 31bfb2f..b8b98dd 100644 --- a/Il2CppInspector.Redux.GUI/Outputs/DummyDllOutput.cs +++ b/Il2CppInspector.Redux.FrontendCore/Outputs/DummyDllOutput.cs @@ -1,7 +1,7 @@ using Il2CppInspector.Model; using Il2CppInspector.Outputs; -namespace Il2CppInspector.Redux.GUI.Outputs; +namespace Il2CppInspector.Redux.FrontendCore.Outputs; public class DummyDllOutput : IOutputFormatProvider { diff --git a/Il2CppInspector.Redux.GUI/Outputs/IOutputFormat.cs b/Il2CppInspector.Redux.FrontendCore/Outputs/IOutputFormat.cs similarity index 84% rename from Il2CppInspector.Redux.GUI/Outputs/IOutputFormat.cs rename to Il2CppInspector.Redux.FrontendCore/Outputs/IOutputFormat.cs index 86b0992..3df6024 100644 --- a/Il2CppInspector.Redux.GUI/Outputs/IOutputFormat.cs +++ b/Il2CppInspector.Redux.FrontendCore/Outputs/IOutputFormat.cs @@ -1,6 +1,6 @@ using Il2CppInspector.Model; -namespace Il2CppInspector.Redux.GUI.Outputs; +namespace Il2CppInspector.Redux.FrontendCore.Outputs; public interface IOutputFormat { diff --git a/Il2CppInspector.Redux.GUI/Outputs/OutputFormatRegistry.cs b/Il2CppInspector.Redux.FrontendCore/Outputs/OutputFormatRegistry.cs similarity index 95% rename from Il2CppInspector.Redux.GUI/Outputs/OutputFormatRegistry.cs rename to Il2CppInspector.Redux.FrontendCore/Outputs/OutputFormatRegistry.cs index 1d9f319..0e25611 100644 --- a/Il2CppInspector.Redux.GUI/Outputs/OutputFormatRegistry.cs +++ b/Il2CppInspector.Redux.FrontendCore/Outputs/OutputFormatRegistry.cs @@ -1,4 +1,4 @@ -namespace Il2CppInspector.Redux.GUI.Outputs; +namespace Il2CppInspector.Redux.FrontendCore.Outputs; public static class OutputFormatRegistry { diff --git a/Il2CppInspector.Redux.GUI/Outputs/VsSolutionOutput.cs b/Il2CppInspector.Redux.FrontendCore/Outputs/VsSolutionOutput.cs similarity index 94% rename from Il2CppInspector.Redux.GUI/Outputs/VsSolutionOutput.cs rename to Il2CppInspector.Redux.FrontendCore/Outputs/VsSolutionOutput.cs index 059edab..a6107dc 100644 --- a/Il2CppInspector.Redux.GUI/Outputs/VsSolutionOutput.cs +++ b/Il2CppInspector.Redux.FrontendCore/Outputs/VsSolutionOutput.cs @@ -1,7 +1,7 @@ using Il2CppInspector.Model; using Il2CppInspector.Outputs; -namespace Il2CppInspector.Redux.GUI.Outputs; +namespace Il2CppInspector.Redux.FrontendCore.Outputs; public class VsSolutionOutput : IOutputFormatProvider { diff --git a/Il2CppInspector.Redux.GUI/PathHeuristics.cs b/Il2CppInspector.Redux.FrontendCore/PathHeuristics.cs similarity index 96% rename from Il2CppInspector.Redux.GUI/PathHeuristics.cs rename to Il2CppInspector.Redux.FrontendCore/PathHeuristics.cs index 7d52a39..bc0d9fb 100644 --- a/Il2CppInspector.Redux.GUI/PathHeuristics.cs +++ b/Il2CppInspector.Redux.FrontendCore/PathHeuristics.cs @@ -1,4 +1,4 @@ -namespace Il2CppInspector.Redux.GUI; +namespace Il2CppInspector.Redux.FrontendCore; public static class PathHeuristics { diff --git a/Il2CppInspector.Redux.FrontendCore/Properties/launchSettings.json b/Il2CppInspector.Redux.FrontendCore/Properties/launchSettings.json new file mode 100644 index 0000000..6902527 --- /dev/null +++ b/Il2CppInspector.Redux.FrontendCore/Properties/launchSettings.json @@ -0,0 +1,12 @@ +{ + "profiles": { + "Il2CppInspector.Redux.FrontendCore": { + "commandName": "Project", + "launchBrowser": false, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:43298;http://localhost:43299" + } + } +} \ No newline at end of file diff --git a/Il2CppInspector.Redux.GUI/UiClient.cs b/Il2CppInspector.Redux.FrontendCore/UiClient.cs similarity index 97% rename from Il2CppInspector.Redux.GUI/UiClient.cs rename to Il2CppInspector.Redux.FrontendCore/UiClient.cs index 3dfbb86..1bd298b 100644 --- a/Il2CppInspector.Redux.GUI/UiClient.cs +++ b/Il2CppInspector.Redux.FrontendCore/UiClient.cs @@ -1,6 +1,6 @@ using Microsoft.AspNetCore.SignalR; -namespace Il2CppInspector.Redux.GUI; +namespace Il2CppInspector.Redux.FrontendCore; public class UiClient(ISingleClientProxy client) { diff --git a/Il2CppInspector.Redux.GUI/UiContext.cs b/Il2CppInspector.Redux.FrontendCore/UiContext.cs similarity index 98% rename from Il2CppInspector.Redux.GUI/UiContext.cs rename to Il2CppInspector.Redux.FrontendCore/UiContext.cs index 596bb34..dfcb1cf 100644 --- a/Il2CppInspector.Redux.GUI/UiContext.cs +++ b/Il2CppInspector.Redux.FrontendCore/UiContext.cs @@ -1,11 +1,11 @@ using System.Diagnostics; using Il2CppInspector.Cpp.UnityHeaders; using Il2CppInspector.Model; -using Il2CppInspector.Redux.GUI.Outputs; +using Il2CppInspector.Redux.FrontendCore.Outputs; using Il2CppInspector.Reflection; using Inspector = Il2CppInspector.Il2CppInspector; -namespace Il2CppInspector.Redux.GUI; +namespace Il2CppInspector.Redux.FrontendCore; public class UiContext { diff --git a/Il2CppInspector.Redux.GUI/Extensions.cs b/Il2CppInspector.Redux.GUI/Extensions.cs deleted file mode 100644 index 3219443..0000000 --- a/Il2CppInspector.Redux.GUI/Extensions.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Reflection; - -namespace Il2CppInspector.Redux.GUI; - -public static class Extensions -{ - public static bool GetAsBooleanOrDefault(this Dictionary dict, string key, bool defaultValue) - { - if (dict.TryGetValue(key, out var value) && bool.TryParse(value, out var boolResult)) - return boolResult; - - return defaultValue; - } - - public static T GetAsEnumOrDefault(this Dictionary dict, string key, T defaultValue) - where T : struct, Enum - { - if (dict.TryGetValue(key, out var value) && Enum.TryParse(value, true, out var enumResult)) - return enumResult; - - return defaultValue; - } - - public static string? GetAssemblyVersion(this Assembly assembly) - => assembly.GetCustomAttribute()?.InformationalVersion; -} \ No newline at end of file diff --git a/Il2CppInspector.Redux.GUI/Il2CppInspector.Redux.GUI.csproj b/Il2CppInspector.Redux.GUI/Il2CppInspector.Redux.GUI.csproj index de085f7..384f3ef 100644 --- a/Il2CppInspector.Redux.GUI/Il2CppInspector.Redux.GUI.csproj +++ b/Il2CppInspector.Redux.GUI/Il2CppInspector.Redux.GUI.csproj @@ -11,11 +11,6 @@ true - - - - - @@ -23,5 +18,8 @@ + + + diff --git a/Il2CppInspector.Redux.GUI/Program.cs b/Il2CppInspector.Redux.GUI/Program.cs index 6d42fb0..289d2aa 100644 --- a/Il2CppInspector.Redux.GUI/Program.cs +++ b/Il2CppInspector.Redux.GUI/Program.cs @@ -1,3 +1,4 @@ +using Il2CppInspector.Redux.FrontendCore; using Il2CppInspector.Redux.GUI; using Microsoft.AspNetCore.SignalR; @@ -5,40 +6,23 @@ var builder = WebApplication.CreateSlimBuilder(args); builder.Services.ConfigureHttpJsonOptions(options => { - options.SerializerOptions.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default); -}); - -builder.Services.AddSignalR(config => -{ -#if DEBUG - config.EnableDetailedErrors = true; -#endif + options.SerializerOptions.TypeInfoResolverChain.Insert(0, FrontendCoreJsonSerializerContext.Default); }); builder.Services.Configure(options => { - options.PayloadSerializerOptions.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default); -}); - -builder.Services.AddCors(options => -{ - options.AddDefaultPolicy(policy => - { - policy.SetIsOriginAllowed(origin => origin.StartsWith("http://localhost") || origin.StartsWith("http://tauri.localhost")) - .AllowAnyHeader() - .WithMethods("GET", "POST") - .AllowCredentials(); - }); + options.PayloadSerializerOptions.TypeInfoResolverChain.Insert(0, FrontendCoreJsonSerializerContext.Default); }); +builder.Services.AddFrontendCore(); builder.Services.AddSingleton(); -builder.Services.AddSingleton(p => p.GetRequiredService()); +builder.Services.AddHostedService(p => p.GetRequiredService()); var app = builder.Build(); app.UseCors(); -app.MapHub("/il2cpp"); +app.MapFrontendCore(); await app.StartAsync(); diff --git a/Il2CppInspector.Redux.GUI/UiProcessService.cs b/Il2CppInspector.Redux.GUI/UiProcessService.cs index aa7210f..f9e9e12 100644 --- a/Il2CppInspector.Redux.GUI/UiProcessService.cs +++ b/Il2CppInspector.Redux.GUI/UiProcessService.cs @@ -23,6 +23,7 @@ public class UiProcessService(IHostApplicationLifetime lifetime) : BackgroundSer using var executable = typeof(UiProcessService).Assembly.GetManifestResourceStream( $"{typeof(UiProcessService).Namespace!}.{UiExecutableName}"); + if (executable == null) throw new FileNotFoundException("Failed to open resource as stream."); diff --git a/Il2CppInspector.sln b/Il2CppInspector.sln index 5ba592e..62a20c7 100644 --- a/Il2CppInspector.sln +++ b/Il2CppInspector.sln @@ -46,6 +46,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VersionedSerialization.Gene EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Il2CppInspector.Redux.GUI", "Il2CppInspector.Redux.GUI\Il2CppInspector.Redux.GUI.csproj", "{CB6CE40B-0805-49B1-82DD-4CAAE58F9D6E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Il2CppInspector.Redux.FrontendCore", "Il2CppInspector.Redux.FrontendCore\Il2CppInspector.Redux.FrontendCore.csproj", "{D80D0FCE-4C9C-4BF1-8936-71DFB0B2D86A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -82,6 +84,10 @@ Global {CB6CE40B-0805-49B1-82DD-4CAAE58F9D6E}.Debug|Any CPU.Build.0 = Debug|Any CPU {CB6CE40B-0805-49B1-82DD-4CAAE58F9D6E}.Release|Any CPU.ActiveCfg = Release|Any CPU {CB6CE40B-0805-49B1-82DD-4CAAE58F9D6E}.Release|Any CPU.Build.0 = Release|Any CPU + {D80D0FCE-4C9C-4BF1-8936-71DFB0B2D86A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D80D0FCE-4C9C-4BF1-8936-71DFB0B2D86A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D80D0FCE-4C9C-4BF1-8936-71DFB0B2D86A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D80D0FCE-4C9C-4BF1-8936-71DFB0B2D86A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE