-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMPValidator.cs
More file actions
138 lines (116 loc) · 4.02 KB
/
Copy pathMPValidator.cs
File metadata and controls
138 lines (116 loc) · 4.02 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using GetToReWorked.Core;
using Isto.GTW;
using MelonLoader.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using UnityEngine;
namespace GetToReWorked.Core.Validation
{
public static class MPValidator
{
public enum ValidationSeverity
{
Info,
Warning,
Error
}
public class ValidationIssue
{
public ValidationSeverity Severity;
public string Message;
public ValidationIssue(
ValidationSeverity severity,
string message)
{
Severity = severity;
Message = message;
}
}
public static List<ValidationIssue> Issues = new List<ValidationIssue>();
public static bool HasIssues => Issues.Count > 0;
public static void Validate()
{
Issues.Clear();
if (!Core.SteamInitalized)
{
Issues.Add(new(ValidationSeverity.Error, "Steam failed to initialize."));
}
string userDataDir =
Path.Combine(
MelonEnvironment.UserDataDirectory,
"GetToReWorked");
if (!Directory.Exists(userDataDir))
{
Issues.Add(new(ValidationSeverity.Error, "GetToReWorked data folder missing."));
}
// skipped as i dont have access to the networkmanager hash atm
ValidateAssetBundles();
ValidateGameVersion();
}
public static void ValidateAssetBundles()
{
string bundleDir = Path.Combine(
MelonEnvironment.UserDataDirectory,
"GetToReWorked"
);
string[] requiredBundles =
{
"networkmanager.gtmpfile",
"playertest.gtmpfile",
"ui.gtmpfile"
};
foreach (string bundle in requiredBundles)
{
string bundlePath = Path.Combine(bundleDir, bundle);
string hashPath = bundlePath + ".gtmpHash";
if (!File.Exists(bundlePath))
{
Issues.Add(new(ValidationSeverity.Error, $"Missing asset bundle: {bundle}"));
continue;
}
if (!File.Exists(hashPath))
{
Issues.Add(new(ValidationSeverity.Error, $"Missing hash file for: {bundle}"));
continue;
}
try
{
byte[] expectedHash = File.ReadAllBytes(hashPath);
using SHA256 sha256 = SHA256.Create();
byte[] actualHash = sha256.ComputeHash(File.ReadAllBytes(bundlePath));
if (!expectedHash.SequenceEqual(actualHash))
{
Issues.Add(new(ValidationSeverity.Error, $"Bundle hash mismatch: {bundle}"));
}
}
catch
{
Issues.Add(new(ValidationSeverity.Error, $"Failed to read hash for: {bundle}"));
}
}
}
public static void ValidateGameVersion()
{
GTWGameState gameState =
Resources.FindObjectsOfTypeAll<GTWGameState>()
.FirstOrDefault();
if (gameState == null)
{
Issues.Add(new(ValidationSeverity.Error, "Could not determine game version."));
return;
}
string currentVersion =
gameState.version.ActiveVersion.FullVersionText;
string supportedVersion = "1.1.2.0-";
if (currentVersion != supportedVersion)
{
Issues.Add(new(ValidationSeverity.Error,
$"Game version {currentVersion} is not supported. Expected {supportedVersion}."
));
}
}
}
}