-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
108 lines (93 loc) · 2.27 KB
/
Program.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using SDL2;
namespace TsMod
{
public static class Program
{
// ReSharper disable InconsistentNaming
const string Win_Steam_V1_033 = "B7A81613D3B3933FB1CBF5D96E1198CD";
const string Win_DrmFree_V1_033 = "F207565C0E364F749CCE02E4F46CF027";
const string Win_DrmFree_GOG_Galaxy_V1_033 = "F7CDB06A80180A2E494B26438AD9362C";
// ReSharper restore InconsistentNaming
public static bool IsSteam;
[STAThread]
public static int Main()
{
var md5 = GetTimespinnerMd5Hash();
switch (md5)
{
case Win_Steam_V1_033:
IsSteam = true;
break;
case Win_DrmFree_V1_033:
case Win_DrmFree_GOG_Galaxy_V1_033:
IsSteam = false;
break;
case null:
return -1;
default:
SDL.SDL_ShowSimpleMessageBox(
SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_ERROR,
"VersionMismatch",
"TsMod version missmatch!, pleaze update your mod\r\nThe installed version of your mod is not made to work with the installed version of Timespinner",
IntPtr.Zero
);
return -1;
}
StartTimeSpinner();
return 0;
}
static string GetTimespinnerMd5Hash()
{
var md5 = MD5.Create();
try
{
return ByteArrayToString(md5.ComputeHash(File.ReadAllBytes("Timespinner.exe")));
}
catch (FileNotFoundException)
{
SDL.SDL_ShowSimpleMessageBox(
SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_ERROR,
"FileNotFound",
"Timespinner.exe not found in current directory\r\nPleaze place TsRandomizer.exe in the same folder as the original game",
IntPtr.Zero
);
return null;
}
}
static string ByteArrayToString(byte[] bytes)
{
var hex = new StringBuilder(bytes.Length * 2);
foreach (var b in bytes)
hex.Append(b.ToString("X2"));
return hex.ToString();
}
static void StartTimeSpinner()
{
WithExceptionLogging(() => {
var platformHelper = IsSteam
? DummyPlatformHelper.CreateSteamInstance()
: DummyPlatformHelper.CreateDrmFreeInstance();
new TimeSpinnerGame(platformHelper).Run();
});
}
static void WithExceptionLogging(Action action)
{
#if DEBUG
action();
#else
try
{
action();
}
catch (Exception e)
{
ExceptionLogger.LogException(e);
}
#endif
}
}
}