codex talán fixálta idk
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
using Assets.Code;
|
using Assets.Code;
|
||||||
using Assets.Interface;
|
|
||||||
using Riptide;
|
using Riptide;
|
||||||
using Riptide.Transports;
|
using Riptide.Transports;
|
||||||
using Steamworks;
|
using Steamworks;
|
||||||
@@ -25,7 +24,6 @@ namespace KCM.LoadSaveOverrides
|
|||||||
|
|
||||||
Main.helper.Log($"Saving data for {Main.kCPlayers.Count} ({KCServer.server.ClientCount}) players.");
|
Main.helper.Log($"Saving data for {Main.kCPlayers.Count} ({KCServer.server.ClientCount}) players.");
|
||||||
|
|
||||||
//this.PlayerSaveData = new PlayerSaveDataOverride().Pack(Player.inst);
|
|
||||||
foreach (var player in Main.kCPlayers.Values)
|
foreach (var player in Main.kCPlayers.Values)
|
||||||
{
|
{
|
||||||
Main.helper.Log($"Attempting to pack data for: " + player.name + $"({player.steamId})");
|
Main.helper.Log($"Attempting to pack data for: " + player.name + $"({player.steamId})");
|
||||||
@@ -58,7 +56,6 @@ namespace KCM.LoadSaveOverrides
|
|||||||
|
|
||||||
public override object Unpack(object obj)
|
public override object Unpack(object obj)
|
||||||
{
|
{
|
||||||
//original Player reset was up here
|
|
||||||
foreach (var kvp in players)
|
foreach (var kvp in players)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -89,7 +86,6 @@ namespace KCM.LoadSaveOverrides
|
|||||||
this.TownNameSaveData.Unpack(TownNameUI.inst);
|
this.TownNameSaveData.Unpack(TownNameUI.inst);
|
||||||
|
|
||||||
|
|
||||||
//TownNameUI.inst.townName = kingdomNames[Main.PlayerSteamID];
|
|
||||||
TownNameUI.inst.SetTownName(kingdomNames[Main.PlayerSteamID]);
|
TownNameUI.inst.SetTownName(kingdomNames[Main.PlayerSteamID]);
|
||||||
|
|
||||||
Main.helper.Log("Unpacking player data");
|
Main.helper.Log("Unpacking player data");
|
||||||
@@ -270,14 +266,14 @@ namespace KCM.LoadSaveOverrides
|
|||||||
if (building == null) continue;
|
if (building == null) continue;
|
||||||
|
|
||||||
// Re-register resource storages
|
// Re-register resource storages
|
||||||
var storages = building.GetComponents<IResourceStorage>();
|
var storages = KCM.ResourceStorageHelper.GetStorages(building);
|
||||||
foreach (var storage in storages)
|
foreach (var storage in storages)
|
||||||
{
|
{
|
||||||
if (storage != null && !storage.IsPrivate())
|
if (storage != null && !KCM.ResourceStorageHelper.IsPrivate(storage))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
FreeResourceManager.inst.AddResourceStorage(storage);
|
KCM.ResourceStorageHelper.Register(storage);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
19
Main.cs
19
Main.cs
@@ -1,6 +1,5 @@
|
|||||||
using Assets.Code;
|
using Assets.Code;
|
||||||
using Assets.Code.UI;
|
using Assets.Code.UI;
|
||||||
using Assets.Interface;
|
|
||||||
using Harmony;
|
using Harmony;
|
||||||
using KCM.Enums;
|
using KCM.Enums;
|
||||||
using KCM.LoadSaveOverrides;
|
using KCM.LoadSaveOverrides;
|
||||||
@@ -645,17 +644,17 @@ namespace KCM
|
|||||||
if (KCClient.client.IsConnected)
|
if (KCClient.client.IsConnected)
|
||||||
{
|
{
|
||||||
LogStep(true);
|
LogStep(true);
|
||||||
__instance.Buildings.Add(b);
|
__instance.Buildings.Add(b);
|
||||||
IResourceStorage[] storages = b.GetComponents<IResourceStorage>();
|
Component[] storages = ResourceStorageHelper.GetStorages(b);
|
||||||
LogStep();
|
LogStep();
|
||||||
for (int i = 0; i < storages.Length; i++)
|
for (int i = 0; i < storages.Length; i++)
|
||||||
|
{
|
||||||
|
bool flag = !ResourceStorageHelper.IsPrivate(storages[i]);
|
||||||
|
if (flag)
|
||||||
{
|
{
|
||||||
bool flag = !storages[i].IsPrivate();
|
ResourceStorageHelper.Register(storages[i]);
|
||||||
if (flag)
|
|
||||||
{
|
|
||||||
FreeResourceManager.inst.AddResourceStorage(storages[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
LogStep();
|
LogStep();
|
||||||
int landMass = b.LandMass();
|
int landMass = b.LandMass();
|
||||||
Home res = b.GetComponent<Home>();
|
Home res = b.GetComponent<Home>();
|
||||||
|
|||||||
@@ -33,12 +33,21 @@ namespace KCM.Packets.Network
|
|||||||
CloudSystem.inst.BaseFreq = 4.5f;
|
CloudSystem.inst.BaseFreq = 4.5f;
|
||||||
Weather.inst.SetSeason(Weather.Season.Summer);
|
Weather.inst.SetSeason(Weather.Season.Summer);
|
||||||
|
|
||||||
//inst = new KCClient(KCServer.IsRunning ? "Ryan" : "Orion");
|
|
||||||
KCClient.inst = new KCClient(SteamFriends.GetPersonaName());
|
KCClient.inst = new KCClient(SteamFriends.GetPersonaName());
|
||||||
|
|
||||||
Main.helper.Log("Sending client connected. Client ID is: " + clientId);
|
Main.helper.Log("Sending client connected. Client ID is: " + clientId);
|
||||||
|
|
||||||
Main.kCPlayers.Add(Main.PlayerSteamID, new KCPlayer(KCClient.inst.Name, clientId, Main.PlayerSteamID));
|
KCPlayer localPlayer;
|
||||||
|
if (!Main.kCPlayers.TryGetValue(Main.PlayerSteamID, out localPlayer))
|
||||||
|
{
|
||||||
|
localPlayer = new KCPlayer(KCClient.inst.Name, clientId, Main.PlayerSteamID);
|
||||||
|
Main.kCPlayers.Add(Main.PlayerSteamID, localPlayer);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
localPlayer.id = clientId;
|
||||||
|
localPlayer.name = KCClient.inst.Name;
|
||||||
|
}
|
||||||
|
|
||||||
Player.inst.PlayerLandmassOwner.teamId = clientId * 10 + 2;
|
Player.inst.PlayerLandmassOwner.teamId = clientId * 10 + 2;
|
||||||
|
|
||||||
|
|||||||
60
ResourceStorageHelper.cs
Normal file
60
ResourceStorageHelper.cs
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace KCM
|
||||||
|
{
|
||||||
|
internal static class ResourceStorageHelper
|
||||||
|
{
|
||||||
|
private static Type resourceStorageType;
|
||||||
|
private static MethodInfo getComponentsMethod;
|
||||||
|
private static MethodInfo isPrivateMethod;
|
||||||
|
private static MethodInfo addResourceStorageMethod;
|
||||||
|
|
||||||
|
private static void EnsureInitialized()
|
||||||
|
{
|
||||||
|
if (resourceStorageType != null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
resourceStorageType = AppDomain.CurrentDomain
|
||||||
|
.GetAssemblies()
|
||||||
|
.Select(a => a.GetType("Assets.Interface.IResourceStorage", false))
|
||||||
|
.FirstOrDefault(t => t != null);
|
||||||
|
|
||||||
|
if (resourceStorageType == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
getComponentsMethod = typeof(Component).GetMethod("GetComponents", new[] { typeof(Type) });
|
||||||
|
isPrivateMethod = resourceStorageType.GetMethod("IsPrivate", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
|
||||||
|
addResourceStorageMethod = typeof(FreeResourceManager).GetMethod("AddResourceStorage", new[] { resourceStorageType });
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Component[] GetStorages(Component owner)
|
||||||
|
{
|
||||||
|
EnsureInitialized();
|
||||||
|
if (resourceStorageType == null || getComponentsMethod == null)
|
||||||
|
return Array.Empty<Component>();
|
||||||
|
|
||||||
|
return (Component[])getComponentsMethod.Invoke(owner, new object[] { resourceStorageType });
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool IsPrivate(Component storage)
|
||||||
|
{
|
||||||
|
EnsureInitialized();
|
||||||
|
if (isPrivateMethod == null)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return (bool)isPrivateMethod.Invoke(storage, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Register(Component storage)
|
||||||
|
{
|
||||||
|
EnsureInitialized();
|
||||||
|
if (addResourceStorageMethod == null || FreeResourceManager.inst == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
addResourceStorageMethod.Invoke(FreeResourceManager.inst, new object[] { storage });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user