Compare commits

...

8 Commits

Author SHA1 Message Date
b6bcde41b1 asd gatya 2025-12-14 00:03:32 +01:00
9b5fb2c632 bruh xd 2025-12-13 23:58:12 +01:00
cf76acccf3 talán? 2025-12-13 23:56:51 +01:00
9868d30810 na most talán ez a geci mukodik??? 2025-12-13 23:55:28 +01:00
5abd025860 na vissza geci chatgptre mert nem működött... xdd 2025-12-13 23:46:32 +01:00
d7718c1dff Hááát nem sikerült szegénynek 2. próba 2025-12-13 23:22:43 +01:00
ea57e0a52c javitotta a saját faszságát ez a szar. 2025-12-13 23:21:13 +01:00
c3223d5db9 na most elvileg a grok fixálta de nem hinnem xd 2025-12-13 23:18:30 +01:00
9 changed files with 643 additions and 2615 deletions

View File

@@ -19,7 +19,7 @@ namespace KCM
{
public class KCClient : MonoBehaviour
{
public static Client client = new Client(Main.steamClient);
public static Client client = new Client();
public string Name { get; set; }
@@ -101,7 +101,8 @@ namespace KCM
public static void Connect(string ip)
{
Main.helper.Log("Trying to connect to: " + ip);
Main.EnsureNetworking();
Main.Log("Trying to connect to: " + ip);
client.Connect(ip, useMessageHandlers: false);
}
@@ -112,8 +113,9 @@ namespace KCM
private void Preload(KCModHelper helper)
{
helper.Log("Preload run in client");
Main.helper = helper;
Main.EnsureNetworking();
Main.Log("Preload run in client");
}
private void SceneLoaded(KCModHelper helper)

View File

@@ -18,7 +18,7 @@ namespace KCM
{
public class KCServer : MonoBehaviour
{
public static Server server = new Server(Main.steamServer);
public static Server server = new Server();
public static bool started = false;
private static readonly Dictionary<ushort, Queue<SaveTransferPacket>> saveTransferQueues = new Dictionary<ushort, Queue<SaveTransferPacket>>();
@@ -33,6 +33,7 @@ namespace KCM
public static void StartServer()
{
Main.EnsureNetworking();
server = new Server(Main.steamServer);
server.MessageReceived += PacketHandler.HandlePacketServer;
@@ -203,9 +204,10 @@ namespace KCM
private void Preload(KCModHelper helper)
{
helper.Log("server?");
helper.Log("Preload run in server");
Main.helper = helper;
Main.EnsureNetworking();
Main.Log("server?");
Main.Log("Preload run in server");
}
private void SceneLoaded(KCModHelper helper)

View File

@@ -0,0 +1,79 @@
using Harmony;
using KCM.LoadSaveOverrides;
using System;
using UnityEngine;
namespace KCM
{
public static class LoadSaveLoadAtPathHook
{
public static byte[] saveData = new byte[1];
public static string lastLoadedPath = string.Empty;
}
public static class LoadSaveLoadHook
{
public static byte[] saveBytes = null;
public static bool memoryStreamHook = false;
public static MultiplayerSaveContainer saveContainer = null;
}
[HarmonyPatch(typeof(LoadSave), "LoadAtPath")]
public class LoadSaveLoadAtPathCaptureHook
{
public static void Prefix(string path)
{
try
{
if (string.IsNullOrEmpty(path))
return;
LoadSaveLoadAtPathHook.lastLoadedPath = path;
if (!FileExists(path))
return;
LoadSaveLoadAtPathHook.saveData = ReadAllBytes(path);
Main.Log($"Captured save bytes from: {path} ({LoadSaveLoadAtPathHook.saveData.Length} bytes)");
}
catch (Exception ex)
{
Main.Log("Failed capturing save bytes from LoadSave.LoadAtPath");
Main.Log(ex);
}
}
private static bool FileExists(string path)
{
object result = InvokeSystemIoFile("Exists", new Type[] { typeof(string) }, new object[] { path });
return result is bool && (bool)result;
}
private static byte[] ReadAllBytes(string path)
{
object result = InvokeSystemIoFile("ReadAllBytes", new Type[] { typeof(string) }, new object[] { path });
return result as byte[];
}
private static object InvokeSystemIoFile(string methodName, Type[] parameterTypes, object[] args)
{
// Avoid direct references to System.IO in IL (some mod loaders forbid it).
const string typeName = "System.IO.File";
Type fileType =
Type.GetType(typeName) ??
Type.GetType(typeName + ", mscorlib") ??
Type.GetType(typeName + ", System") ??
Type.GetType(typeName + ", System.Runtime") ??
Type.GetType(typeName + ", System.Private.CoreLib");
if (fileType == null)
return null;
var method = fileType.GetMethod(methodName, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static, null, parameterTypes, null);
if (method == null)
return null;
return method.Invoke(null, args);
}
}
}

2967
Main.cs

File diff suppressed because it is too large Load Diff

View File

@@ -103,15 +103,15 @@ namespace KCM.Packets.Lobby
// Handle completed transfer here
Main.helper.Log("Save Transfer complete!");
LoadSaveLoadHook.saveBytes = saveData;
LoadSaveLoadHook.memoryStreamHook = true;
KCM.LoadSaveLoadHook.saveBytes = saveData;
KCM.LoadSaveLoadHook.memoryStreamHook = true;
LoadSave.Load();
try
{
Main.SetMultiplayerSaveLoadInProgress(true);
LoadSaveLoadHook.saveContainer.Unpack(null);
KCM.LoadSaveLoadHook.saveContainer.Unpack(null);
}
finally
{

View File

@@ -24,11 +24,12 @@ namespace KCM
{
try
{
//Main.helper = _helper;
Main.helper = _helper;
Main.EnsureNetworking();
assetBundle = KCModHelper.LoadAssetBundle(_helper.modPath, "serverbrowserpkg");
Main.helper.Log(String.Join(", ", assetBundle.GetAllAssetNames()));
Main.Log(String.Join(", ", assetBundle.GetAllAssetNames()));
serverBrowserPrefab = assetBundle.LoadAsset("assets/workspace/serverbrowser.prefab") as GameObject;
serverEntryItemPrefab = assetBundle.LoadAsset("assets/workspace/serverentryitem.prefab") as GameObject;
@@ -41,13 +42,13 @@ namespace KCM
modalUIPrefab = assetBundle.LoadAsset("assets/workspace/modalui.prefab") as GameObject;
Main.helper.Log("Loaded assets");
Main.Log("Loaded assets");
}
catch (Exception ex)
{
Main.helper.Log(ex.ToString());
Main.helper.Log(ex.Message);
Main.helper.Log(ex.StackTrace);
Main.Log(ex);
Main.Log(ex.Message);
Main.Log(ex.StackTrace);
}
}
}

View File

@@ -49,7 +49,7 @@ public class KCMSteamManager : MonoBehaviour {
[AOT.MonoPInvokeCallback(typeof(SteamAPIWarningMessageHook_t))]
protected static void SteamAPIDebugTextHook(int nSeverity, System.Text.StringBuilder pchDebugText) {
Main.helper.Log(pchDebugText.ToString());
Main.Log(pchDebugText.ToString());
}
#if UNITY_2019_3_OR_NEWER
@@ -64,7 +64,7 @@ public class KCMSteamManager : MonoBehaviour {
protected virtual void Awake() {
// Only one instance of SteamManager at a time!
Main.helper.Log("Steam awake");
Main.Log("Steam awake");
if (s_instance != null) {
Destroy(gameObject);
return;
@@ -76,7 +76,7 @@ public class KCMSteamManager : MonoBehaviour {
// The most common case where this happens is when SteamManager gets destroyed because of Application.Quit(),
// and then some Steamworks code in some other OnDestroy gets called afterwards, creating a new SteamManager.
// You should never call Steamworks functions in OnDestroy, always prefer OnDisable if possible.
Main.helper.Log("Tried to Initialize the SteamAPI twice in one session!");
Main.Log("Tried to Initialize the SteamAPI twice in one session!");
return;
}
@@ -85,11 +85,11 @@ public class KCMSteamManager : MonoBehaviour {
DontDestroyOnLoad(gameObject);
if (!Packsize.Test()) {
Main.helper.Log("[Steamworks.NET] Packsize Test returned false, the wrong version of Steamworks.NET is being run in this platform.");
Main.Log("[Steamworks.NET] Packsize Test returned false, the wrong version of Steamworks.NET is being run in this platform.");
}
if (!DllCheck.Test()) {
Main.helper.Log("[Steamworks.NET] DllCheck Test returned false, One or more of the Steamworks binaries seems to be the wrong version.");
Main.Log("[Steamworks.NET] DllCheck Test returned false, One or more of the Steamworks binaries seems to be the wrong version.");
}
try {
@@ -101,12 +101,12 @@ public class KCMSteamManager : MonoBehaviour {
// See the Valve documentation for more information: https://partner.steamgames.com/doc/sdk/api#initialization_and_shutdown
if (SteamAPI.RestartAppIfNecessary((AppId_t)569480)) {
//Application.Quit();
Main.helper.Log("Attempted to restart app");
Main.Log("Attempted to restart app");
return;
}
}
catch (System.DllNotFoundException e) { // We catch this exception here, as it will be the first occurrence of it.
Main.helper.Log("[Steamworks.NET] Could not load [lib]steam_api.dll/so/dylib. It's likely not in the correct location. Refer to the README for more details.\n" + e);
Main.Log("[Steamworks.NET] Could not load [lib]steam_api.dll/so/dylib. It's likely not in the correct location. Refer to the README for more details.\n" + e);
//Application.Quit();
return;
@@ -123,7 +123,7 @@ public class KCMSteamManager : MonoBehaviour {
// https://partner.steamgames.com/doc/sdk/api#initialization_and_shutdown
m_bInitialized = SteamAPI.Init();
if (!m_bInitialized) {
Main.helper.Log("[Steamworks.NET] SteamAPI_Init() failed. Refer to Valve's documentation or the comment above this line for more information.");
Main.Log("[Steamworks.NET] SteamAPI_Init() failed. Refer to Valve's documentation or the comment above this line for more information.");
return;
}

View File

@@ -400,7 +400,7 @@ namespace KCM
SfxSystem.PlayUiSelect();
Main.TransitionTo(MenuState.Menu);
Main.TransitionTo(KCM.Enums.MenuState.Menu);
});

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);
}
}
}
}