asd gatya

This commit is contained in:
2025-12-14 00:03:32 +01:00
parent 9b5fb2c632
commit b6bcde41b1
2 changed files with 156 additions and 0 deletions

31
Main.cs
View File

@@ -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");

View File

@@ -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<Button>();
if (template == null)
return;
Button button = Object.Instantiate(template, buttonContainer);
button.name = "KCM_Multiplayer";
foreach (Localize loc in button.GetComponentsInChildren<Localize>())
Object.Destroy(loc);
button.onClick = new Button.ButtonClickedEvent();
TextMeshProUGUI label = button.GetComponentInChildren<TextMeshProUGUI>();
if (label != null)
label.text = "Multiplayer";
int insertIndex = template.transform.GetSiblingIndex() + 1;
button.transform.SetSiblingIndex(insertIndex);
button.onClick.AddListener(OpenServerBrowser);
injected = true;
Main.Log("Injected Multiplayer menu button");
}
private static void OpenServerBrowser()
{
try
{
// Ensure Steam + lobby manager exist
_ = KCMSteamManager.Instance;
LobbyManager lobbyManager = Object.FindObjectOfType<LobbyManager>();
if (lobbyManager == null)
{
GameObject go = new GameObject("KCM_LobbyManager");
Object.DontDestroyOnLoad(go);
lobbyManager = go.AddComponent<LobbyManager>();
}
// Ensure prefabs loaded
if (PrefabManager.serverBrowserPrefab == null || PrefabManager.serverLobbyPrefab == null)
{
if (Main.helper != null)
new PrefabManager().PreScriptLoad(Main.helper);
}
// Ensure UI initialized
KCM.ServerBrowser browser = Object.FindObjectOfType<KCM.ServerBrowser>();
if (browser == null)
{
GameObject go = new GameObject("KCM_ServerBrowser");
Object.DontDestroyOnLoad(go);
browser = go.AddComponent<KCM.ServerBrowser>();
}
browser.EnsureUi();
if (KCM.ServerBrowser.serverLobbyRef != null)
KCM.ServerBrowser.serverLobbyRef.SetActive(false);
if (KCM.ServerBrowser.serverBrowserRef != null)
KCM.ServerBrowser.serverBrowserRef.SetActive(true);
if (GameState.inst != null && GameState.inst.mainMenuMode != null)
GameState.inst.mainMenuMode.mainMenuUI.SetActive(false);
}
catch (System.Exception ex)
{
Main.Log("Failed opening server browser");
Main.Log(ex);
}
}
}
}