-
Notifications
You must be signed in to change notification settings - Fork 11
/
Main.cs
264 lines (238 loc) · 11.6 KB
/
Main.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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
using MAI2System;
using MelonLoader;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using SinmaiAssist.Cheat;
using SinmaiAssist.Common;
using SinmaiAssist.Fix;
using SinmaiAssist.GUI;
using SinmaiAssist.Utils;
using UnityEngine;
using Path = System.IO.Path;
namespace SinmaiAssist
{
public static partial class BuildInfo
{
public const string Name = "Sinmai-Assist";
public const string Description = "SlimMod Melon Version For Sinmai";
public const string Author = "Slim & Error063";
public const string Company = null;
public const string Version = "1.0.0";
public const string DownloadLink = null;
}
public class SinmaiAssist : MelonMod
{
private MainGUI _mainGUI;
private static bool isPatchFailed = false;
public static ConfigManager config;
public static string gameID = "Unknown";
public static uint gameVersion = 00000;
public override void OnInitializeMelon()
{
File.Delete($"{BuildInfo.Name}/Unity.log");
Application.logMessageReceived += OnLogMessageReceived; // 注册Unity日志
PrintLogo();
_mainGUI = new MainGUI();
config = new ConfigManager();
// 加载配置文件
MelonLogger.Msg("Load Mod Config.");
string yamlFilePath = $"{BuildInfo.Name}/config.yml";
if (!File.Exists(yamlFilePath))
{
MelonLogger.Error($"Path: \"{yamlFilePath}\" Not Found.");
return;
}
try
{
config.Initialize(yamlFilePath);
DummyLoginPanel.DummyUserId = config.Common.DummyLogin.DefaultUserId.ToString();
DebugPanel.UnityLogger = config.ModSetting.LogUnity;
MelonLogger.Msg("Config Load Complete.");
}
catch (Exception e)
{
MelonLogger.Error($"Error initializing mod config: \n{e}");
return;
}
// 输出设备摄像头列表
File.Delete($"{BuildInfo.Name}/WebCameraList.txt");
WebCamDevice[] devices = WebCamTexture.devices;
string CameraList = "\nConnected Web Cameras:\n";
for (int i = 0; i < devices.Length; i++)
{
WebCamDevice webCamDevice = devices[i];
CameraList = CameraList + "Name: " + webCamDevice.name + "\n";
CameraList += $"ID: {i}\n";
WebCamTexture webCamTexture = new WebCamTexture(webCamDevice.name);
webCamTexture.Play();
CameraList += $"Resolution: {webCamTexture.width}x{webCamTexture.height}\n";
CameraList += $"FPS: {webCamTexture.requestedFPS}\n";
webCamTexture.Stop();
CameraList += "\n";
}
File.AppendAllText($"{BuildInfo.Name}/WebCameraList.txt", CameraList);
// 检测游戏版本并判断是否为 SDGB
try
{
gameID = (string)typeof(ConstParameter).GetField("GameIDStr",
BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy).GetValue(null);
gameVersion = (uint)typeof(ConstParameter).GetField("NowGameVersion",
BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy).GetValue(null);
if (gameVersion < 24000)
{
MelonLogger.Warning($"Using untested version ({gameVersion}) maybe case some unexcepted problems!");
}
}
catch (Exception e)
{
MelonLogger.Error("Failed to get GameIDStr and GameVersion");
MelonLogger.Error(e);
}
MelonLogger.Msg($"GameInfo: {gameID} {gameVersion} ");
var Codes = new List<int> { 83, 68, 71, 66 };
var str = string.Concat(Codes.Select(code => (char)code));
if (gameID.Equals(str)) Application.Quit();
if (config.ModSetting.SafeMode)
{
MelonLogger.Warning("Safe mode is enabled, Disable all patch");
return;
}
// 加载Patch
// DummyLogin
if (config.Common.DummyLogin.Enable)
{
if (File.Exists("DEVICE/aime.txt"))
DummyLoginPanel.DummyLoginCode = File.ReadAllText("DEVICE/aime.txt").Trim();
Patch(typeof(DummyAimeLogin));
}
if (config.Common.CustomCameraId.Enable)
{
if (config.Common.DummyLogin.Enable)
{
MelonLogger.Warning("DummyLogin enabled, CustomCameraId has been automatically disabled.");
}
else
{
Patch(typeof(CustomCameraId));
}
}
// Common
if (config.Common.InfinityTimer) Patch(typeof(InfinityTimer));
if (config.Common.DisableBackground) Patch(typeof(DisableBackground));
if (config.Common.DisableMask) Patch(typeof(DisableMask));
if (config.Common.SinglePlayer.Enable) Patch(typeof(SinglePlayer));
if (config.Common.ForceQuickRetry) Patch(typeof(ForceQuickRetry));
if (config.Common.ForwardATouchRegionToButton) Patch(typeof(ForwardATouchRegionToButton));
if (config.Common.QuickBoot) Patch(typeof(QuickBoot));
if (config.Common.BlockCoin) Patch(typeof(BlockCoin));
if (config.Common.SkipWarningScreen) Patch(typeof(SkipWarningScreen));
if (config.Common.SkipFade) Patch(typeof(SkipFade));
if (config.Common.NetworkLogger.Enable) Patch(typeof(NetworkLogger));
if (config.Common.CustomVersionText.Enable) Patch(typeof(CustomVersionText));
if (config.Common.IgnoreAnyGameInformation) Patch(typeof(IgnoreAnyGameInformation));
if (config.Common.ChangeDefaultOption) Patch(typeof(ChangeDefaultOption));
if (config.Common.ChangeFadeStyle) Patch(typeof(ChangeFadeStyle));
if (config.Common.ChangeGameSettings.Enable) Patch(typeof(ChangeGameSettings));
//Fix
if (config.Fix.DisableEncryption) Patch(typeof(DisableEncryption));
if (config.Fix.DisableReboot) Patch(typeof(DisableReboot));
if (config.Fix.SkipVersionCheck) Patch(typeof(SkipVersionCheck));
if (config.Fix.RewriteNoteJudgeTiming.Enable) Patch(typeof(RewriteNoteJudgeTiming));
//Cheat
if (config.Cheat.AutoPlay) Patch(typeof(AutoPlay));
if (config.Cheat.FastSkip) Patch(typeof(FastSkip));
if (config.Cheat.ChartTimer) Patch(typeof(ChartTimer));
if (config.Cheat.AllCollection) Patch(typeof(AllCollection));
if (config.Cheat.UnlockMusic) Patch(typeof(UnlockMusic));
if (config.Cheat.UnlockMaster) Patch(typeof(UnlockMaster));
if (config.Cheat.UnlockEvent) Patch(typeof(UnlockEvent));
if (config.Cheat.ResetLoginBonusRecord) Patch(typeof(ResetLoginBonusRecord));
if (config.Cheat.ForceCurrentIsBest) Patch(typeof(ForceCurrentIsBest));
if (config.Cheat.SetAllCharacterAsSameAndLock) Patch(typeof(SetAllCharacterAsSameAndLock));
if (config.Cheat.RewriteLoginBonusStamp.Enable) Patch(typeof(RewriteLoginBonusStamp));
// 默认加载项
Patch(typeof(FixDebugInput));
Patch(typeof(PrintUserData));
Patch(typeof(InputManager));
Patch(typeof(GameMessageManager));
if(isPatchFailed) PatchFailedWarn();
MelonLogger.Msg("Loading completed");
}
public override void OnGUI()
{
_mainGUI.OnGUI();
if (config.Common.ShowFPS) ShowFPS.OnGUI();
if (config.ModSetting.ShowInfo) ShowVersionInfo.OnGUI();
}
private void OnLogMessageReceived(string condition, string stackTrace, LogType type)
{
string logString = $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] [{type}] {condition}\n{stackTrace}";
File.AppendAllText(Path.Combine($"{BuildInfo.Name}/Unity.log"),logString + "\n");
if (DebugPanel.UnityLogger)
{
switch (type)
{
case LogType.Error:
case LogType.Exception:
MelonLogger.Error($"[UnityLogger] [{type}]: {condition}\n{stackTrace}");
break;
case LogType.Warning:
MelonLogger.Warning($"[UnityLogger] [{type}]: {condition}\n{stackTrace}");
break;
case LogType.Assert:
case LogType.Log:
default:
MelonLogger.Msg($"[UnityLogger] [{type}]: {condition}\n{stackTrace}");
break;
}
}
}
private static bool Patch(Type type)
{
try
{
MelonLogger.Msg($"- Patch: {type}");
HarmonyLib.Harmony.CreateAndPatchAll(type);
return true;
}
catch (Exception e)
{
MelonLogger.Error($"Patch {type} failed.");
MelonLogger.Error(e.Message);
MelonLogger.Error(e.Source);
MelonLogger.Error(e.TargetSite);
MelonLogger.Error(e.InnerException);
MelonLogger.Error(e.StackTrace);
isPatchFailed = true;
return false;
}
}
private static void PrintLogo()
{
MelonLogger.Msg("\n" +
"\r\n _____ _ __ ___ _ ___ _ __ " +
"\r\n / ___/(_)___ / |/ /___ _(_) / | __________(_)____/ /_" +
"\r\n \\__ \\/ / __ \\/ /|_/ / __ `/ /_____/ /| | / ___/ ___/ / ___/ __/" +
"\r\n ___/ / / / / / / / / /_/ / /_____/ ___ |(__ |__ ) (__ ) /_ " +
"\r\n/____/_/_/ /_/_/ /_/\\__,_/_/ /_/ |_/____/____/_/____/\\__/ " +
"\r\n " +
"\r\n=================================================================" +
$"\r\n Version: {BuildInfo.Version} ({BuildInfo.CommitHash}) Build Date: {BuildInfo.BuildDate}" +
$"\r\n Author: {BuildInfo.Author}");
MelonLogger.Warning("This is a cheat mod. Use at your own risk!");
}
private static void PatchFailedWarn()
{
MelonLogger.Warning("\r\n=================================================================" +
"\r\nFailed to patch some methods." +
"\r\nPlease ensure that you are using an unmodified version of Assembly-CSharp.dll with a version greater than 1.40.0," +
"\r\nas modifications or lower versions can cause function mismatches, preventing the required functions from being found." +
"\r\nCheck for conflicting mods, or enabled incompatible options." +
"\r\nIf you believe this is an error, please report the issue to the mod author." +
"\r\n=================================================================");
}
}
}