From b6bcde41b12bd6b8a25357ed64b2ac9bd06a1a06 Mon Sep 17 00:00:00 2001 From: devbeni Date: Sun, 14 Dec 2025 00:03:32 +0100 Subject: [PATCH] asd gatya --- Main.cs | 31 +++++++++ UI/MultiplayerMenuInjector.cs | 125 ++++++++++++++++++++++++++++++++++ 2 files changed, 156 insertions(+) create mode 100644 UI/MultiplayerMenuInjector.cs diff --git a/Main.cs b/Main.cs index 79a9ef7..a35e0bb 100644 --- a/Main.cs +++ b/Main.cs @@ -35,6 +35,37 @@ namespace KCM public static string PlayerSteamID => SteamUser.GetSteamID().ToString(); + // K&C mod loader entrypoint + public void Preload(KCModHelper modHelper) + { + helper = modHelper; + + try + { + EnsureNetworking(); + + if (harmony == null) + harmony = HarmonyInstance.Create("com.kcm.mod"); + + harmony.PatchAll(Assembly.GetExecutingAssembly()); + + try + { + new PrefabManager().PreScriptLoad(modHelper); + } + catch (Exception ex) + { + Log("Prefab preload failed"); + Log(ex); + } + } + catch (Exception ex) + { + Log("Preload failed"); + Log(ex); + } + } + void Awake() { Log("KCM Awake"); diff --git a/UI/MultiplayerMenuInjector.cs b/UI/MultiplayerMenuInjector.cs new file mode 100644 index 0000000..15c75b3 --- /dev/null +++ b/UI/MultiplayerMenuInjector.cs @@ -0,0 +1,125 @@ +using Harmony; +using I2.Loc; +using Riptide.Demos.Steam.PlayerHosted; +using TMPro; +using UnityEngine; +using UnityEngine.UI; + +namespace KCM.UI +{ + [HarmonyPatch(typeof(GameState), "SetNewMode")] + public static class MultiplayerMenuInjector + { + private static bool injected; + + public static void Postfix() + { + try + { + EnsureInjected(); + } + catch (System.Exception ex) + { + Main.Log("MultiplayerMenuInjector failed"); + Main.Log(ex); + } + } + + private static void EnsureInjected() + { + if (injected) + return; + + if (GameState.inst == null || GameState.inst.mainMenuMode == null) + return; + + GameObject mainMenuUi = GameState.inst.mainMenuMode.mainMenuUI; + if (mainMenuUi == null) + return; + + Transform buttonContainer = mainMenuUi.transform.Find("TopLevelUICanvas/TopLevel/Body/ButtonContainer"); + if (buttonContainer == null) + return; + + if (buttonContainer.Find("KCM_Multiplayer") != null) + { + injected = true; + return; + } + + Button template = mainMenuUi.transform.Find("TopLevelUICanvas/TopLevel/Body/ButtonContainer/New")?.GetComponent