na vissza geci chatgptre mert nem működött... xdd
This commit is contained in:
100
Main.cs
100
Main.cs
@@ -1,5 +1,5 @@
|
||||
using Assets.Code;
|
||||
using HarmonyLib;
|
||||
using Harmony;
|
||||
using KCM.Packets;
|
||||
using KCM.Packets.Game;
|
||||
using KCM.Packets.Game.GamePlayer;
|
||||
@@ -10,7 +10,6 @@ using KCM.StateManagement.Observers;
|
||||
using KCM.StateManagement.Sync;
|
||||
using KCM.StateManagement.BuildingState;
|
||||
using Riptide;
|
||||
using Riptide.Utils;
|
||||
using Steamworks;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -19,31 +18,68 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using SteamTransportClient = Riptide.Transports.Steam.SteamClient;
|
||||
using SteamTransportServer = Riptide.Transports.Steam.SteamServer;
|
||||
|
||||
namespace KCM
|
||||
{
|
||||
public class Main : MonoBehaviour
|
||||
{
|
||||
public static Harmony harmony = new Harmony("com.kcm.mod");
|
||||
public static Helper helper;
|
||||
public static HarmonyInstance harmony;
|
||||
public static KCModHelper helper;
|
||||
public static Dictionary<string, KCPlayer> kCPlayers = new Dictionary<string, KCPlayer>();
|
||||
public static Dictionary<ushort, string> clientSteamIds = new Dictionary<ushort, string>();
|
||||
|
||||
public static SteamClient steamClient;
|
||||
public static SteamServer steamServer;
|
||||
public static SteamTransportClient steamClient;
|
||||
public static SteamTransportServer steamServer;
|
||||
|
||||
public static string PlayerSteamID => SteamUser.GetSteamID().ToString();
|
||||
|
||||
void Awake()
|
||||
{
|
||||
helper = new Helper("KCM", true, true, true);
|
||||
helper.Log("KCM Awake");
|
||||
Log("KCM Awake");
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
helper.Log("KCM Start");
|
||||
harmony.PatchAll();
|
||||
Log("KCM Start");
|
||||
|
||||
EnsureNetworking();
|
||||
|
||||
if (harmony == null)
|
||||
harmony = HarmonyInstance.Create("com.kcm.mod");
|
||||
|
||||
harmony.PatchAll(Assembly.GetExecutingAssembly());
|
||||
}
|
||||
|
||||
public static void EnsureNetworking()
|
||||
{
|
||||
if (steamServer == null)
|
||||
steamServer = new SteamTransportServer();
|
||||
|
||||
if (steamClient == null)
|
||||
steamClient = new SteamTransportClient(steamServer);
|
||||
else
|
||||
steamClient.ChangeLocalServer(steamServer);
|
||||
|
||||
if (KCClient.client != null)
|
||||
KCClient.client.ChangeTransport(steamClient);
|
||||
|
||||
if (KCServer.server != null)
|
||||
KCServer.server.ChangeTransport(steamServer);
|
||||
}
|
||||
|
||||
public static void Log(string message)
|
||||
{
|
||||
if (helper != null)
|
||||
helper.Log(message ?? string.Empty);
|
||||
else
|
||||
Debug.Log(message ?? string.Empty);
|
||||
}
|
||||
|
||||
public static void Log(Exception ex)
|
||||
{
|
||||
Log(ex != null ? ex.ToString() : string.Empty);
|
||||
}
|
||||
|
||||
public static void ServerUpdate()
|
||||
@@ -75,6 +111,14 @@ namespace KCM
|
||||
clientSteamIds.Clear();
|
||||
}
|
||||
|
||||
public static void ResetMultiplayerState(string reason)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(reason))
|
||||
Log("ResetMultiplayerState: " + reason);
|
||||
|
||||
ResetMultiplayerState();
|
||||
}
|
||||
|
||||
public static void SetMultiplayerSaveLoadInProgress(bool inProgress)
|
||||
{
|
||||
// Set save/load progress flag
|
||||
@@ -178,7 +222,7 @@ namespace KCM
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
helper?.Log("Error in ForceMultiplayerAIUpdate: " + e.Message);
|
||||
Log("Error in ForceMultiplayerAIUpdate: " + e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,8 +246,8 @@ namespace KCM
|
||||
{
|
||||
try
|
||||
{
|
||||
try { Player.inst.irrigation.UpdateIrrigation(); } catch (Exception e) { helper?.Log(e.ToString()); }
|
||||
try { Player.inst.CalcMaxResources(null, -1); } catch (Exception e) { helper?.Log(e.ToString()); }
|
||||
try { Player.inst.irrigation.UpdateIrrigation(); } catch (Exception e) { Log(e); }
|
||||
try { Player.inst.CalcMaxResources(null, -1); } catch (Exception e) { Log(e); }
|
||||
|
||||
SetLoadTickDelay(Player.inst, 1);
|
||||
SetLoadTickDelay(UnitSystem.inst, 1);
|
||||
@@ -212,8 +256,8 @@ namespace KCM
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
helper?.Log("Post-load rebuild failed");
|
||||
helper?.Log(e.ToString());
|
||||
Log("Post-load rebuild failed");
|
||||
Log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,9 +282,9 @@ namespace KCM
|
||||
? Player.inst.PlayerLandmassOwner.teamId.ToString()
|
||||
: "unknown";
|
||||
|
||||
helper.Log("Failed finding player by teamID: " + teamId + " My teamID is: " + myTeamId);
|
||||
helper.Log(kCPlayers.Count.ToString());
|
||||
helper.Log(string.Join(", ", kCPlayers.Values.Where(p => p != null && p.inst != null && p.inst.PlayerLandmassOwner != null).Select(p => p.inst.PlayerLandmassOwner.teamId.ToString())));
|
||||
Log("Failed finding player by teamID: " + teamId + " My teamID is: " + myTeamId);
|
||||
Log(kCPlayers.Count.ToString());
|
||||
Log(string.Join(", ", kCPlayers.Values.Where(p => p != null && p.inst != null && p.inst.PlayerLandmassOwner != null).Select(p => p.inst.PlayerLandmassOwner.teamId.ToString())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,7 +315,7 @@ namespace KCM
|
||||
{
|
||||
if (__instance.TeamID() == Player.inst.PlayerLandmassOwner.teamId)
|
||||
{
|
||||
helper.Log("Overridden complete build");
|
||||
Log("Overridden complete build");
|
||||
Player player = GetPlayerByTeamID(__instance.TeamID());
|
||||
|
||||
typeof(Building).GetField("built", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(__instance, true);
|
||||
@@ -294,9 +338,9 @@ namespace KCM
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
helper.Log(e.ToString());
|
||||
helper.Log(e.Message);
|
||||
helper.Log(e.StackTrace);
|
||||
Log(e.ToString());
|
||||
Log(e.Message);
|
||||
Log(e.StackTrace);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -321,9 +365,9 @@ namespace KCM
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
helper.Log(e.ToString());
|
||||
helper.Log(e.Message);
|
||||
helper.Log(e.StackTrace);
|
||||
Log(e.ToString());
|
||||
Log(e.Message);
|
||||
Log(e.StackTrace);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -338,7 +382,7 @@ namespace KCM
|
||||
if (!KCClient.client.IsConnected)
|
||||
return;
|
||||
|
||||
helper.Log("SpeedControlUI.SetSpeed (local): " + idx);
|
||||
Log("SpeedControlUI.SetSpeed (local): " + idx);
|
||||
|
||||
// Force AI restart when speed changes from paused to playing
|
||||
if (idx > 0)
|
||||
@@ -367,7 +411,7 @@ namespace KCM
|
||||
if (!paused)
|
||||
{
|
||||
// Game is unpaused, force AI restart
|
||||
helper.Log("Game unpaused, forcing AI restart");
|
||||
Log("Game unpaused, forcing AI restart");
|
||||
ForceMultiplayerAIUpdate();
|
||||
}
|
||||
}
|
||||
@@ -391,4 +435,4 @@ namespace KCM
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user