From 39c1f96cef1fc7dc5a3697af480664bca84cc849 Mon Sep 17 00:00:00 2001 From: Nb1X Date: Wed, 7 Oct 2026 15:34:05 +0200 Subject: [PATCH 1/3] Added API + Lite version --- .github/workflows/build.yml | 26 +++++-- src/Api/RegionApi.cs | 137 ++++++++++++++++++++++++++++++++++++ src/RegionFileGenerator.cs | 32 +++++++-- src/RegionInstaller.cs | 16 +++-- src/RegionInstaller.csproj | 27 +++++-- src/ReloadButton.cs | 22 +++--- 6 files changed, 229 insertions(+), 31 deletions(-) create mode 100644 src/Api/RegionApi.cs diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1de20eb..5565797 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,19 +35,31 @@ jobs: - name: Restore Dependencies run: dotnet restore - - name: Build Project (Development) - run: dotnet build --no-restore + - name: Build Project (Default) + run: dotnet build src/RegionInstaller.csproj --no-restore -c Default - - name: Upload Build Artifact + - name: Build Project (Lite) + run: dotnet build src/RegionInstaller.csproj --no-restore -c Lite + + - name: Wait for file system sync + run: sleep 5 + + - name: Upload Build Artifact (Default) uses: actions/upload-artifact@v4 with: name: RegionInstaller.dll - path: src/bin/Debug/net6.0/RegionInstaller.dll + path: src/bin/Default/net6.0/RegionInstaller.dll + + - name: Upload Build Artifact (Lite) + uses: actions/upload-artifact@v4 + with: + name: RegionInstallerLite.dll + path: src/bin/Lite/net6.0/RegionInstallerLite.dll - - name: Upload Release Asset + - name: Upload Release Asset (Default) if: startsWith(github.ref, 'refs/tags/') uses: softprops/action-gh-release@v2 with: - files: src/bin/Debug/net6.0/RegionInstaller.dll + files: src/bin/Default/net6.0/RegionInstaller.dll env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/src/Api/RegionApi.cs b/src/Api/RegionApi.cs new file mode 100644 index 0000000..7ccced5 --- /dev/null +++ b/src/Api/RegionApi.cs @@ -0,0 +1,137 @@ +using System; +using System.Collections.Generic; +using System.IO; +using UnityEngine; + +namespace RegionInstaller +{ + public static class RegionApi + { +#if LITE + public static void AddRegion(string name, string address, bool https, bool dtls, ushort port1, ushort port2) + { + throw new NotSupportedException("RegionInstallerLite does not include the API, please use default RegionInstaller."); + } + + public static void DisableInnerslothRegions() + { + throw new NotSupportedException("RegionInstallerLite does not include the API, please use default RegionInstaller."); + } + + public static void DisableDtlsForAllRegions() + { + throw new NotSupportedException("RegionInstallerLite does not include the API, please use default RegionInstaller."); + } + + public static void ReloadRegionInfo() + { + throw new NotSupportedException("RegionInstallerLite does not include the API, please use default RegionInstaller."); + } +#else + private static readonly List DynamicRegions = new(); + private static bool forceDisableInnersloth = false; + private static bool forceDisableDtls = false; + + public static void AddRegion(string name, string address, bool https, bool dtls, ushort port1, ushort port2) + { + var region = new ParsedRegion + { + Name = name, + Address = address, + Https = https, + Dtls = dtls, + Port1 = port1, + Port2 = port2 + }; + + if (region.IsValid) + { + DynamicRegions.Add(region); + TriggerRefresh(); + Debug.Log($"[RegionInstaller.Api] Dynamic region '{name}' added successfully."); + } + else + { + Debug.LogError($"[RegionInstaller.Api] Failed to add invalid region '{name}'."); + } + } + + public static void DisableInnerslothRegions() + { + if (forceDisableInnersloth) + { + Debug.LogWarning("[RegionInstaller.Api] Innersloth regions are already disabled by another plugin/API call!"); + return; + } + + forceDisableInnersloth = true; + TriggerRefresh(); + Debug.Log("[RegionInstaller.Api] Innersloth regions forcefully disabled via API."); + } + + public static void DisableDtlsForAllRegions() + { + if (forceDisableDtls) + { + Debug.LogWarning("[RegionInstaller.Api] Dtls is already disabled by another plugin/API call!"); + return; + } + + forceDisableDtls = true; + TriggerRefresh(); + Debug.Log("[RegionInstaller.Api] DTLS forcefully disabled for all regions via API."); + } + + public static void ReloadRegionInfo() + { + TriggerRefresh(); + Debug.Log("[RegionInstaller.Api] Region info manually reloaded via API."); + } + + internal static List GetDynamicRegions() => DynamicRegions; + + internal static bool IsInnerslothForcedDisabled() => forceDisableInnersloth; + + private static void TriggerRefresh() + { + try + { + ConfigData configData = ConfigFile.LoadOrCreate(RegionInstallerPlugin.ConfigPath); + + if (forceDisableDtls) + { + foreach (var reg in configData.Regions) + { + reg.Dtls = false; + } + foreach (var reg in DynamicRegions) + { + reg.Dtls = false; + } + } + + configData.Regions.AddRange(DynamicRegions); + + string regionJsonPath = Path.Combine(Application.persistentDataPath, "regionInfo.json"); + RegionFileGenerator.RegenerateRegionFile(regionJsonPath, configData, forceDisableInnersloth); + + if (ServerManager.Instance != null) + { + ServerManager.Instance.LoadServers(); + } + + UnityEngine.Object.FindObjectOfType()?.Start(); + if (UnityEngine.Object.FindObjectOfType() is { } regionMenu) + { + regionMenu.OnDisable(); + regionMenu.OnEnable(); + } + } + catch (Exception ex) + { + Debug.LogError($"[RegionInstaller.Api] Error during dynamic refresh: {ex.Message}"); + } + } +#endif + } +} \ No newline at end of file diff --git a/src/RegionFileGenerator.cs b/src/RegionFileGenerator.cs index 132c32e..074b529 100644 --- a/src/RegionFileGenerator.cs +++ b/src/RegionFileGenerator.cs @@ -9,14 +9,14 @@ namespace RegionInstaller { public static class RegionFileGenerator { - public static void RegenerateRegionFile(string regionFilePath, ConfigData configData) + public static void RegenerateRegionFile(string regionFilePath, ConfigData configData, bool ignoreInnerslothAndGlitch = false) { try { bool needsRewrite = true; JsonNode? rootNode = null; - if (File.Exists(regionFilePath) && new FileInfo(regionFilePath).Length > 0) + if (!ignoreInnerslothAndGlitch && File.Exists(regionFilePath) && new FileInfo(regionFilePath).Length > 0) { string content = File.ReadAllText(regionFilePath); rootNode = JsonNode.Parse(content); @@ -29,26 +29,46 @@ public static void RegenerateRegionFile(string regionFilePath, ConfigData config } } - if (needsRewrite) + if (needsRewrite || ignoreInnerslothAndGlitch) { if (File.Exists(regionFilePath)) { File.Delete(regionFilePath); } - Debug.Log("[RegionInstaller] Rewriting regionInfo.json..."); + Debug.Log("[RegionInstaller] Rewriting regionInfo.json (with strict filters if requested)..."); rootNode = CreateEmptyRegionStructure(); var regionsArray = rootNode["Regions"]!.AsArray(); - foreach (var reg in configData.Regions) + var regionsToProcess = new List(configData.Regions); + + if (!ignoreInnerslothAndGlitch) + { + if (configData.GlitchedLobbiesRegion) + { + GlitchedLobbies.AddGlitchedLobbiesRegion(regionsToProcess); + } + if (configData.KeepInnerslothRegions) + { + InnerslothRegions.AddInnerslothRegions(regionsToProcess); + } + } + + foreach (var reg in regionsToProcess) { if (!reg.IsValid) continue; + + if (ignoreInnerslothAndGlitch && InnerslothRegions.IsOfficialInnersloth(reg.Name)) + { + continue; + } + regionsArray.Add(BuildRegionNode(reg.Name, reg.FullUrl, reg.SelectedPort, reg.Dtls)); } var options = new JsonSerializerOptions { WriteIndented = true }; File.WriteAllText(regionFilePath, rootNode.ToJsonString(options)); - Debug.Log("Region file reloaded!"); + Debug.Log("Region file reloaded successfully!"); } } catch (Exception ex) diff --git a/src/RegionInstaller.cs b/src/RegionInstaller.cs index b0a4f50..5c0d695 100644 --- a/src/RegionInstaller.cs +++ b/src/RegionInstaller.cs @@ -15,15 +15,21 @@ namespace RegionInstaller public class RegionInstallerPlugin : BasePlugin { public const string Id = "com.nb1x.regioninstaller"; + +#if LITE + public const string Name = "RegionInstallerLite"; +#else public const string Name = "RegionInstaller"; - public const string Version = "1.2.1"; +#endif + + public const string Version = "1.0.0"; public static string ConfigPath => Path.Combine(Paths.ConfigPath, "CustomRegions.cfg"); public Harmony Harmony { get; } = new Harmony(Id); public override void Load() { - Log.LogInfo($"[RegionInstaller] Loading {Name} v{Version}..."); + Log.LogInfo($"[{Name}] Loading {Name} v{Version}..."); ConfigData configData = ConfigFile.LoadOrCreate(ConfigPath); @@ -47,7 +53,7 @@ public override void Load() { if (scene.name == "MainMenu") { - Log.LogInfo("[RegionInstaller] MainMenu loaded, injecting regions..."); + Log.LogInfo($"[{Name}] MainMenu loaded, injecting regions..."); InjectRegions(configData.Regions); } })); @@ -68,7 +74,7 @@ private void InjectRegions(List parsedRegions) var regionInfo = new StaticHttpRegionInfo(reg.Name, (StringNames)1003, reg.FullUrl, serversArray); serverMngr.AddOrUpdateRegion(regionInfo.Cast()); - Log.LogInfo($"[RegionInstaller] Region '{reg.Name}' injected into memory."); + Log.LogInfo($"[{Name}] Region '{reg.Name}' injected into memory."); } } } @@ -79,4 +85,4 @@ public static class PatchCleanAndMerge [HarmonyPrefix] public static bool Prefix() => false; } -} +} \ No newline at end of file diff --git a/src/RegionInstaller.csproj b/src/RegionInstaller.csproj index e6c847a..914d96b 100644 --- a/src/RegionInstaller.csproj +++ b/src/RegionInstaller.csproj @@ -2,27 +2,44 @@ net6.0 - RegionInstaller - 1.0.0 latest true enable + 1.0.0 embedded Auto-manages and injects custom modded regions into Among Us while filtering out official servers. Nb1X + + RegionInstaller + TRACE + bin\Default\ + + + + RegionInstaller + RegionInstaller + TRACE;LITE + bin\Lite\ + + - + - + + - + + + + + \ No newline at end of file diff --git a/src/ReloadButton.cs b/src/ReloadButton.cs index 694e265..c28f0e8 100644 --- a/src/ReloadButton.cs +++ b/src/ReloadButton.cs @@ -44,19 +44,25 @@ private static PassiveButton CreateOrangeRefreshButton(MainMenuManager menu) { ConfigData configData = ConfigFile.LoadOrCreate(RegionInstallerPlugin.ConfigPath); - if (configData.GlitchedLobbiesRegion) - { - configData.KeepInnerslothRegions = true; - GlitchedLobbies.AddGlitchedLobbiesRegion(configData.Regions); - } + // On vérifie si l'API a demandé de désactiver Innersloth de force + bool shouldDisableInnersloth = RegionApi.IsInnerslothForcedDisabled(); - if (configData.KeepInnerslothRegions) + if (!shouldDisableInnersloth) { - InnerslothRegions.AddInnerslothRegions(configData.Regions); + if (configData.GlitchedLobbiesRegion) + { + configData.KeepInnerslothRegions = true; + GlitchedLobbies.AddGlitchedLobbiesRegion(configData.Regions); + } + + if (configData.KeepInnerslothRegions) + { + InnerslothRegions.AddInnerslothRegions(configData.Regions); + } } string regionJsonPath = Path.Combine(Application.persistentDataPath, "regionInfo.json"); - RegionFileGenerator.RegenerateRegionFile(regionJsonPath, configData); + RegionFileGenerator.RegenerateRegionFile(regionJsonPath, configData, shouldDisableInnersloth); if (ServerManager.Instance != null) { From b7e24ae01166c87319eebd3dc97a97ad414e1e1a Mon Sep 17 00:00:00 2001 From: Nb1X Date: Wed, 7 Oct 2026 15:43:49 +0200 Subject: [PATCH 2/3] Fix build errors with Lite --- src/ReloadButton.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ReloadButton.cs b/src/ReloadButton.cs index c28f0e8..336fe48 100644 --- a/src/ReloadButton.cs +++ b/src/ReloadButton.cs @@ -44,8 +44,11 @@ private static PassiveButton CreateOrangeRefreshButton(MainMenuManager menu) { ConfigData configData = ConfigFile.LoadOrCreate(RegionInstallerPlugin.ConfigPath); - // On vérifie si l'API a demandé de désactiver Innersloth de force +#if LITE + bool shouldDisableInnersloth = false; +#else bool shouldDisableInnersloth = RegionApi.IsInnerslothForcedDisabled(); +#endif if (!shouldDisableInnersloth) { From ae22fb33ef154320b35f513eb3af163c1b6fb253 Mon Sep 17 00:00:00 2001 From: Nb1X Date: Sun, 11 Oct 2026 15:40:09 +0200 Subject: [PATCH 3/3] Remove DisableDtls --- src/Api/RegionApi.cs | 33 ++------------------------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/src/Api/RegionApi.cs b/src/Api/RegionApi.cs index 7ccced5..5e58270 100644 --- a/src/Api/RegionApi.cs +++ b/src/Api/RegionApi.cs @@ -18,19 +18,15 @@ public static void DisableInnerslothRegions() throw new NotSupportedException("RegionInstallerLite does not include the API, please use default RegionInstaller."); } - public static void DisableDtlsForAllRegions() - { - throw new NotSupportedException("RegionInstallerLite does not include the API, please use default RegionInstaller."); - } - public static void ReloadRegionInfo() { throw new NotSupportedException("RegionInstallerLite does not include the API, please use default RegionInstaller."); } + + internal static bool IsInnerslothForcedDisabled() => false; #else private static readonly List DynamicRegions = new(); private static bool forceDisableInnersloth = false; - private static bool forceDisableDtls = false; public static void AddRegion(string name, string address, bool https, bool dtls, ushort port1, ushort port2) { @@ -69,19 +65,6 @@ public static void DisableInnerslothRegions() Debug.Log("[RegionInstaller.Api] Innersloth regions forcefully disabled via API."); } - public static void DisableDtlsForAllRegions() - { - if (forceDisableDtls) - { - Debug.LogWarning("[RegionInstaller.Api] Dtls is already disabled by another plugin/API call!"); - return; - } - - forceDisableDtls = true; - TriggerRefresh(); - Debug.Log("[RegionInstaller.Api] DTLS forcefully disabled for all regions via API."); - } - public static void ReloadRegionInfo() { TriggerRefresh(); @@ -98,18 +81,6 @@ private static void TriggerRefresh() { ConfigData configData = ConfigFile.LoadOrCreate(RegionInstallerPlugin.ConfigPath); - if (forceDisableDtls) - { - foreach (var reg in configData.Regions) - { - reg.Dtls = false; - } - foreach (var reg in DynamicRegions) - { - reg.Dtls = false; - } - } - configData.Regions.AddRange(DynamicRegions); string regionJsonPath = Path.Combine(Application.persistentDataPath, "regionInfo.json");