fix 2
This commit is contained in:
60
Main.cs
60
Main.cs
@@ -57,6 +57,17 @@ namespace KCM
|
|||||||
|
|
||||||
private static readonly Dictionary<int, long> lastTeamIdLookupLogMs = new Dictionary<int, long>();
|
private static readonly Dictionary<int, long> lastTeamIdLookupLogMs = new Dictionary<int, long>();
|
||||||
private static int resetInProgress = 0;
|
private static int resetInProgress = 0;
|
||||||
|
private static int multiplayerSaveLoadInProgress = 0;
|
||||||
|
|
||||||
|
public static bool IsMultiplayerSaveLoadInProgress
|
||||||
|
{
|
||||||
|
get { return Volatile.Read(ref multiplayerSaveLoadInProgress) != 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetMultiplayerSaveLoadInProgress(bool inProgress)
|
||||||
|
{
|
||||||
|
Interlocked.Exchange(ref multiplayerSaveLoadInProgress, inProgress ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
public static void ResetMultiplayerState(string reason = null)
|
public static void ResetMultiplayerState(string reason = null)
|
||||||
{
|
{
|
||||||
@@ -82,6 +93,7 @@ namespace KCM
|
|||||||
try { LoadSaveLoadAtPathHook.saveData = new byte[0]; } catch { }
|
try { LoadSaveLoadAtPathHook.saveData = new byte[0]; } catch { }
|
||||||
|
|
||||||
try { LobbyManager.loadingSave = false; } catch { }
|
try { LobbyManager.loadingSave = false; } catch { }
|
||||||
|
try { SetMultiplayerSaveLoadInProgress(false); } catch { }
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -1294,20 +1306,18 @@ namespace KCM
|
|||||||
{
|
{
|
||||||
BinaryFormatter bf = new BinaryFormatter();
|
BinaryFormatter bf = new BinaryFormatter();
|
||||||
bf.Binder = new MultiplayerSaveDeserializationBinder();
|
bf.Binder = new MultiplayerSaveDeserializationBinder();
|
||||||
Stream file = new FileStream(path, FileMode.Open);
|
Stream file = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||||
|
MultiplayerSaveContainer loadData = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
object deserialized = bf.Deserialize(file);
|
object deserialized = bf.Deserialize(file);
|
||||||
MultiplayerSaveContainer loadData = deserialized as MultiplayerSaveContainer;
|
loadData = deserialized as MultiplayerSaveContainer;
|
||||||
if (loadData == null)
|
if (loadData == null)
|
||||||
{
|
{
|
||||||
Main.helper.Log("Selected save is not a MultiplayerSaveContainer; falling back to vanilla load.");
|
Main.helper.Log("Selected save is not a MultiplayerSaveContainer; falling back to vanilla load.");
|
||||||
|
saveData = new byte[0];
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
saveData = File.ReadAllBytes(path);
|
|
||||||
loadData.Unpack(null);
|
|
||||||
Broadcast.OnLoadedEvent.Broadcast(new OnLoadedEvent());
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -1326,6 +1336,29 @@ namespace KCM
|
|||||||
file.Dispose();
|
file.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
saveData = File.ReadAllBytes(path);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
saveData = new byte[0];
|
||||||
|
Main.helper.Log("Failed reading save bytes for transfer; clients will not be able to load this save.");
|
||||||
|
Main.helper.Log(e.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Main.SetMultiplayerSaveLoadInProgress(true);
|
||||||
|
loadData.Unpack(null);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
Main.SetMultiplayerSaveLoadInProgress(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
Broadcast.OnLoadedEvent.Broadcast(new OnLoadedEvent());
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -1524,7 +1557,7 @@ namespace KCM
|
|||||||
{
|
{
|
||||||
public static bool Prefix(Building.BuildingSaveData structureData, Player p, ref Building __result)
|
public static bool Prefix(Building.BuildingSaveData structureData, Player p, ref Building __result)
|
||||||
{
|
{
|
||||||
if (KCClient.client.IsConnected)
|
if (KCClient.client.IsConnected && Main.IsMultiplayerSaveLoadInProgress)
|
||||||
{
|
{
|
||||||
|
|
||||||
Building Building = GameState.inst.GetPlaceableByUniqueName(structureData.uniqueName);
|
Building Building = GameState.inst.GetPlaceableByUniqueName(structureData.uniqueName);
|
||||||
@@ -1561,19 +1594,6 @@ namespace KCM
|
|||||||
p.keep = keep;
|
p.keep = keep;
|
||||||
Main.helper.Log(p.keep.ToString());
|
Main.helper.Log(p.keep.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
World.inst.PlaceFromLoad(building);
|
|
||||||
structureData.UnpackStage2(building);
|
|
||||||
building.SetVisibleForFog(false);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Main.helper.Log("Error placing building into world during load");
|
|
||||||
Main.helper.Log(e.Message);
|
|
||||||
Main.helper.Log(e.StackTrace);
|
|
||||||
}
|
|
||||||
__result = building;
|
__result = building;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -108,8 +108,15 @@ namespace KCM.Packets.Lobby
|
|||||||
|
|
||||||
LoadSave.Load();
|
LoadSave.Load();
|
||||||
|
|
||||||
|
try
|
||||||
LoadSaveLoadHook.saveContainer.Unpack(null);
|
{
|
||||||
|
Main.SetMultiplayerSaveLoadInProgress(true);
|
||||||
|
LoadSaveLoadHook.saveContainer.Unpack(null);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
Main.SetMultiplayerSaveLoadInProgress(false);
|
||||||
|
}
|
||||||
Broadcast.OnLoadedEvent.Broadcast(new OnLoadedEvent());
|
Broadcast.OnLoadedEvent.Broadcast(new OnLoadedEvent());
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|||||||
Reference in New Issue
Block a user