-
Notifications
You must be signed in to change notification settings - Fork 101
/
CheckModBuildVersionBeforeJIT.cs
52 lines (42 loc) · 2.02 KB
/
CheckModBuildVersionBeforeJIT.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
using System;
using System.Reflection;
using Terraria.ModLoader;
namespace MagicStorage {
internal class CheckModBuildVersionBeforeJIT : PreJITFilter {
// The GetInstance singleton is only loaded after mod JITing was performed, hence the need for a variable
public static MagicStorageMod Mod;
public static bool versionChecked;
public override bool ShouldJIT(MemberInfo member) {
if (!versionChecked) {
CheckBuildVersion();
versionChecked = true;
}
return base.ShouldJIT(member);
}
private static readonly Version first143Preview = new Version(2022, 10);
private static void CheckBuildVersion() {
// Check if the mod version matches the expected tModLoader build
Version build = Mod.TModLoaderVersion;
Version current = BuildInfo.tMLVersion;
if (build < first143Preview) {
if (current >= first143Preview) {
// Attempted to load the 1.4.3 build of Magic Storage on a 1.4.4 client/server
throw new OutdatedModBuildException();
}
} else if (current < first143Preview) {
// Attempted to load the 1.4.4 build of Magic Storage on a 1.4.3 client/server
throw new IndatedModBuildException();
}
}
}
internal class OutdatedModBuildException : Exception {
private const string MESSAGE = "Attempted to load the 1.4.3 build of Magic Storage on a 1.4.4 tModLoader instance\n" +
"If you installed the mod manually, get the mod file from the \"Steam/steamapps/workshop/content/1281930/2563309347/2022.9\" directory.";
public OutdatedModBuildException(Exception innerException = null) : base(MESSAGE, innerException) { }
}
internal class IndatedModBuildException : Exception {
private const string MESSAGE = "Attempted to load the 1.4.4 build of Magic Storage on a 1.4.3 tModLoader instance\n" +
"If you installed the mod manually, get the mod file from the \"Steam/steamapps/workshop/content/1281930/2563309347/" + MagicStorageMod.build144Version + "\" directory.";
public IndatedModBuildException(Exception innerException = null) : base(MESSAGE, innerException) { }
}
}