Need to fix client inventory wiping but otherwise almost good. Can't seem to fix client error message on my end when server is disconnected.
This commit is contained in:
parent
97f353743c
commit
98392f520e
|
@ -65,8 +65,6 @@ namespace StardustCore
|
||||||
ModHelper.Events.Multiplayer.PeerDisconnected += Multiplayer_PeerDisconnected;
|
ModHelper.Events.Multiplayer.PeerDisconnected += Multiplayer_PeerDisconnected;
|
||||||
|
|
||||||
|
|
||||||
StardewModdingAPI.Events.TimeEvents.AfterDayStarted += TimeEvents_AfterDayStarted;
|
|
||||||
|
|
||||||
playerJustDisconnected = false;
|
playerJustDisconnected = false;
|
||||||
|
|
||||||
IlluminateFramework.Colors.initializeColors();
|
IlluminateFramework.Colors.initializeColors();
|
||||||
|
@ -88,28 +86,22 @@ namespace StardustCore
|
||||||
StardewModdingAPI.Events.GameEvents.UpdateTick += GameEvents_UpdateTick;
|
StardewModdingAPI.Events.GameEvents.UpdateTick += GameEvents_UpdateTick;
|
||||||
serverHack = false;
|
serverHack = false;
|
||||||
|
|
||||||
|
ModHelper.Events.GameLoop.ReturnedToTitle += GameLoop_ReturnedToTitle;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void TimeEvents_AfterDayStarted(object sender, EventArgs e)
|
private void GameLoop_ReturnedToTitle(object sender, StardewModdingAPI.Events.ReturnedToTitleEventArgs e)
|
||||||
{
|
{
|
||||||
return;
|
if (Game1.player != null)
|
||||||
if (lastMenuType == null) return;
|
|
||||||
if (lastMenuType == typeof(StardewValley.Menus.TitleMenu)) return;
|
|
||||||
if(lastMenuType== typeof(StardewValley.Menus.SaveGameMenu) || lastMenuType== typeof(StardewValley.Menus.ShippingMenu))
|
|
||||||
{
|
{
|
||||||
ModMonitor.Log("Start a new day clean!");
|
|
||||||
SerializationManager.cleanUpInventory();
|
SerializationManager.cleanUpInventory();
|
||||||
SerializationManager.cleanUpWorld();
|
SerializationManager.cleanUpWorld();
|
||||||
SerializationManager.cleanUpStorageContainers();
|
SerializationManager.cleanUpStorageContainers();
|
||||||
|
Monitor.Log("Saved the player data!");
|
||||||
List<long> playerIds = new List<long>();
|
}
|
||||||
foreach (Farmer f in Game1.getAllFarmers())
|
else
|
||||||
{
|
{
|
||||||
if (f == Game1.player) continue;
|
Monitor.Log("NOPE NOT WORKING!");
|
||||||
playerIds.Add(f.uniqueMultiplayerID);
|
|
||||||
|
|
||||||
}
|
|
||||||
ModHelper.Multiplayer.SendMessage<string>(MultiplayerSupport.CleanUpModObjects, MultiplayerSupport.CleanUpModObjects, new string[] { ModManifest.UniqueID }, playerIds.ToArray());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,6 +111,7 @@ namespace StardustCore
|
||||||
SerializationManager.cleanUpInventory();
|
SerializationManager.cleanUpInventory();
|
||||||
SerializationManager.cleanUpWorld();
|
SerializationManager.cleanUpWorld();
|
||||||
SerializationManager.cleanUpStorageContainers();
|
SerializationManager.cleanUpStorageContainers();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Multiplayer_ModMessageReceived(object sender, StardewModdingAPI.Events.ModMessageReceivedEventArgs e)
|
private void Multiplayer_ModMessageReceived(object sender, StardewModdingAPI.Events.ModMessageReceivedEventArgs e)
|
||||||
|
@ -146,6 +139,8 @@ namespace StardustCore
|
||||||
SerializationManager.cleanUpInventory();
|
SerializationManager.cleanUpInventory();
|
||||||
SerializationManager.cleanUpWorld();
|
SerializationManager.cleanUpWorld();
|
||||||
SerializationManager.cleanUpStorageContainers();
|
SerializationManager.cleanUpStorageContainers();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MenuEvents_MenuClosed(object sender, StardewModdingAPI.Events.EventArgsClickableMenuClosed e)
|
private void MenuEvents_MenuClosed(object sender, StardewModdingAPI.Events.EventArgsClickableMenuClosed e)
|
||||||
|
@ -239,6 +234,11 @@ namespace StardustCore
|
||||||
if (playerJustDisconnected)
|
if (playerJustDisconnected)
|
||||||
{
|
{
|
||||||
playerJustDisconnected = false;
|
playerJustDisconnected = false;
|
||||||
|
if (Game1.activeClickableMenu != null)
|
||||||
|
{
|
||||||
|
if (Game1.activeClickableMenu.GetType() == typeof(StardewValley.Menus.TitleMenu)) return;
|
||||||
|
}
|
||||||
|
ModMonitor.Log("Restore after disconnect!");
|
||||||
SerializationManager.restoreAllModObjects(SerializationManager.trackedObjectList);
|
SerializationManager.restoreAllModObjects(SerializationManager.trackedObjectList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -253,6 +253,7 @@ namespace StardustCore
|
||||||
|
|
||||||
private void SaveEvents_AfterLoad(object sender, EventArgs e)
|
private void SaveEvents_AfterLoad(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
Game1.game1.Disposed += Game1_Disposed;
|
||||||
|
|
||||||
string invPath = Path.Combine(ModCore.ModHelper.DirectoryPath, "PlayerData", Game1.player.Name, "PlayerInventory");
|
string invPath = Path.Combine(ModCore.ModHelper.DirectoryPath, "PlayerData", Game1.player.Name, "PlayerInventory");
|
||||||
string worldPath = Path.Combine(ModCore.ModHelper.DirectoryPath, Game1.player.Name, "ObjectsInWorld"); ;
|
string worldPath = Path.Combine(ModCore.ModHelper.DirectoryPath, Game1.player.Name, "ObjectsInWorld"); ;
|
||||||
|
@ -298,6 +299,17 @@ namespace StardustCore
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Game1_Disposed(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (Game1.player != null && lastMenuType!= typeof(StardewValley.Menus.TitleMenu))
|
||||||
|
{
|
||||||
|
ModMonitor.Log("EXIT THE GAME!!!!");
|
||||||
|
SerializationManager.cleanUpInventory();
|
||||||
|
SerializationManager.cleanUpWorld();
|
||||||
|
SerializationManager.cleanUpStorageContainers();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void SaveEvents_AfterSave(object sender, EventArgs e)
|
private void SaveEvents_AfterSave(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,14 @@ namespace StardustCore.Serialization
|
||||||
{
|
{
|
||||||
Game1.player.removeItemFromInventory(i);
|
Game1.player.removeItemFromInventory(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Game1.IsMasterGame)
|
||||||
|
{
|
||||||
|
foreach (Farmer f in Game1.getAllFarmhands())
|
||||||
|
{
|
||||||
|
f.items.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
removalList.Clear();
|
removalList.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue