Skip to content

Commit

Permalink
Fix GameStatesManager.LastSaveTime to use real world time
Browse files Browse the repository at this point in the history
  • Loading branch information
starfi5h committed Jun 27, 2024
1 parent d7dc2a9 commit 4da5184
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#region

using System;
using NebulaAPI.Packets;
using NebulaModel.Logger;
using NebulaModel.Networking;
using NebulaModel.Packets;
using NebulaModel.Packets.GameStates;
using NebulaWorld;
using NebulaWorld.GameStates;

#endregion
Expand All @@ -16,5 +19,6 @@ public class GameStateSaveInfoProcessor : PacketProcessor<GameStateSaveInfoPacke
protected override void ProcessPacket(GameStateSaveInfoPacket packet, NebulaConnection conn)
{
GameStatesManager.LastSaveTime = packet.LastSaveTime;
Log.Info("LastSaveTime: " + DateTimeOffset.FromUnixTimeSeconds(packet.LastSaveTime).ToString());
}
}
7 changes: 4 additions & 3 deletions NebulaPatcher/Patches/Dynamic/GameSave_Patch.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#region

using System;
using System.Diagnostics.CodeAnalysis;
using HarmonyLib;
using NebulaModel;
Expand Down Expand Up @@ -49,8 +50,8 @@ public static void SaveCurrentGame_Postfix()
Multiplayer.Session.LocalPlayer.Data.Mecha.SandCount, GameMain.mainPlayer.sandCount);
}
// Update last save time in clients
GameStatesManager.LastSaveTime = GameMain.gameTick;
Multiplayer.Session.Server.SendPacket(new GameStateSaveInfoPacket(GameMain.gameTick));
GameStatesManager.LastSaveTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
Multiplayer.Session.Server.SendPacket(new GameStateSaveInfoPacket(GameStatesManager.LastSaveTime));
}

[HarmonyPrefix]
Expand Down Expand Up @@ -96,7 +97,7 @@ public static void LoadCurrentGame_Postfix(bool __result)
}
if (Multiplayer.IsActive && Multiplayer.Session.LocalPlayer.IsHost)
{
GameStatesManager.LastSaveTime = GameMain.gameTick;
GameStatesManager.LastSaveTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
}
}
}
5 changes: 3 additions & 2 deletions NebulaPatcher/Patches/Dynamic/UIEscMenu_Patch.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#region

using System;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using HarmonyLib;
Expand Down Expand Up @@ -38,8 +39,8 @@ public static void _OnOpen_Postfix(UIEscMenu __instance)
{
if (!Multiplayer.IsActive || Multiplayer.Session.LocalPlayer.IsHost) return;

var timeSinceSave = GameMain.gameTick - GameStatesManager.LastSaveTime;
var second = (int)(timeSinceSave / 60L);
var timeSinceSave = DateTimeOffset.UtcNow.ToUnixTimeSeconds() - GameStatesManager.LastSaveTime;
var second = (int)(timeSinceSave);
var minute = second / 60;
var hour = minute / 60;
var saveBtnText = "存档时间".Translate() + $" {hour}h{minute % 60}m{second % 60}s ago";
Expand Down
2 changes: 1 addition & 1 deletion NebulaWorld/GameStates/GameStatesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class GameStatesManager : IDisposable
public static long RealGameTick => GameMain.gameTick;
public static float RealUPS => (float)FPSController.currentUPS;
public static string ImportedSaveName { get; set; }
public static long LastSaveTime { get; set; }
public static long LastSaveTime { get; set; } // UnixTimeSeconds
public static GameDesc NewGameDesc { get; set; }
public static int FragmentSize { get; set; }

Expand Down

0 comments on commit 4da5184

Please sign in to comment.