-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathScheduleStopwatch.cs
86 lines (79 loc) · 2.86 KB
/
ScheduleStopwatch.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using HarmonyLib;
using System;
using VoxelTycoon.Modding;
using ModSettings;
using VoxelTycoon.Serialization;
using VoxelTycoon;
using VoxelTycoon.Localization;
//using ICSharpCode.SharpZipLib.Checksum;
namespace ScheduleStopwatch
{
[SchemaVersion(3)]
public class ScheduleStopwatch : Mod
{
public const int SAVE_VERSION = 3;
private Harmony harmony;
private const string harmonyID = "cz.xmnovotny.schedulestopwatch.patch";
private static int? _readVersion = null;
public static Logger logger = new Logger("ScheduleStopwatch");
public static int GetSchemaVersion(Type type)
{
if (_readVersion != null)
{
return _readVersion.Value; //legacy version before using SchemaVersion()
}
return SaveSerializer.Current.SchemaVersions.Get(type);
}
protected override void Initialize()
{
Harmony.DEBUG = false;
harmony = (Harmony)(object)new Harmony(harmonyID);
FileLog.Reset();
if (XMNUtils.ModFunctions.IsModInstalled("AdvancedTransferTask"))
{
Manager<AdvancedTransferTaskAdapter>.Initialize();
}
Manager<VehicleScheduleDataManager>.Initialize();
harmony.PatchAll();
}
protected override void OnGameStarted()
{
ModSettingsWindowManager.Current.Register<SettingsWindowPage>(this.GetType().Name, LazyManager<LocaleManager>.Current.Locale.GetString("schedule_stopwatch/settings_window_title"));
Manager<VehicleScheduleDataManager>.Current.StartMeasuring();
}
protected override void Deinitialize()
{
harmony.UnpatchAll(harmonyID);
harmony = null;
}
protected override void Write(StateBinaryWriter writer)
{
if (SaveSerializer.Current.SchemaVersions.Get<ScheduleStopwatch>() < 3)
{
writer.WriteByte(SAVE_VERSION);
}
VehicleScheduleDataManager.Current.Write(writer);
LazyManager<StationDemandManager>.Current.Write(writer);
}
protected override void Read(StateBinaryReader reader)
{
_readVersion = null;
try
{
int antVersion = SchemaVersion<ScheduleStopwatch>.Get();
if (antVersion < 3)
{
_readVersion = reader.ReadByte();
}
VehicleScheduleDataManager.Current.Read(reader);
LazyManager<StationDemandManager>.Current.Read(reader);
}
catch (Exception e)
{
logger.Log(UnityEngine.LogType.Error, "Error when loading ScheduleStopwatch data");
logger.LogException(e);
}
_readVersion = null;
}
}
}