Repository navigation
Expand file tree
/
Copy pathModIoLinuxFixMod.cs
More file actions
223 lines (192 loc) · 6.26 KB
/
Copy pathModIoLinuxFixMod.cs
File metadata and controls
223 lines (192 loc) · 6.26 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
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
using System;
using System.Collections.Generic;
using System.IO;
using PugMod;
using UnityEngine;
public class ModIoLinuxFixMod : IMod
{
private const string LogPrefix = "[ModIoLinuxFix]";
private static bool hasRun;
private static int pendingDialogCopiedCount;
public void EarlyInit()
{
EnsureMonoConfigFiles();
}
public void Init()
{
EnsureMonoConfigFiles();
}
public void Shutdown() { }
public void ModObjectLoaded(UnityEngine.Object obj) { }
public void Update()
{
TryShowCopiedFilesDialog();
}
private static void EnsureMonoConfigFiles()
{
if (hasRun)
{
return;
}
hasRun = true;
if (!IsLinux())
{
return;
}
var dataPath = Application.dataPath;
if (string.IsNullOrEmpty(dataPath) || !Directory.Exists(dataPath))
{
Debug.LogWarning($"{LogPrefix} Could not resolve Application.dataPath.");
return;
}
var patcherEtcPath = Path.Combine(dataPath, "StreamingAssets", "Patcher", "Linux", "Core Keeper Patcher_Data", "MonoBleedingEdge", "etc");
var runtimeEtcPath = Path.Combine(dataPath, "MonoBleedingEdge", "etc");
var filesToCopy = new (string source, string target)[]
{
(
Path.Combine(patcherEtcPath, "config"),
Path.Combine(runtimeEtcPath, "config")
),
(
Path.Combine(patcherEtcPath, "mono", "2.0", "machine.config"),
Path.Combine(runtimeEtcPath, "mono", "2.0", "machine.config")
),
(
Path.Combine(patcherEtcPath, "mono", "4.0", "machine.config"),
Path.Combine(runtimeEtcPath, "mono", "4.0", "machine.config")
),
(
Path.Combine(patcherEtcPath, "mono", "4.5", "machine.config"),
Path.Combine(runtimeEtcPath, "mono", "4.5", "machine.config")
)
};
var allTargetsExist = true;
foreach (var file in filesToCopy)
{
if (!File.Exists(file.target))
{
allTargetsExist = false;
break;
}
}
if (allTargetsExist)
{
return;
}
var copiedCount = 0;
foreach (var file in filesToCopy)
{
if (File.Exists(file.target))
{
continue;
}
if (!File.Exists(file.source))
{
Debug.LogWarning($"{LogPrefix} Missing source file: {file.source}");
continue;
}
var destinationDirectory = Path.GetDirectoryName(file.target);
if (!string.IsNullOrEmpty(destinationDirectory))
{
Directory.CreateDirectory(destinationDirectory);
}
File.Copy(file.source, file.target, overwrite: false);
copiedCount++;
Debug.Log($"{LogPrefix} Copied {file.source} -> {file.target}");
}
if (copiedCount > 0)
{
pendingDialogCopiedCount = copiedCount;
TryShowCopiedFilesDialog();
}
}
private static bool IsLinux()
{
return Application.platform == RuntimePlatform.LinuxEditor || Application.platform == RuntimePlatform.LinuxPlayer;
}
private static void TryShowCopiedFilesDialog()
{
if (pendingDialogCopiedCount <= 0)
{
return;
}
var menuManager = TryGetMenuManager();
if (menuManager == null || menuManager.centerPopUpText == null || !IsTitleMainMenuReady(menuManager))
{
return;
}
var copiedCount = pendingDialogCopiedCount;
Debug.Log($"{LogPrefix} Showing restart dialog after copying {copiedCount} file(s).");
var message = $"Mod.io fix applied. You can uninstall the mod if you wish.\nA restart is required for the fix to take effect. Restart now?";
menuManager.centerPopUpText.StartNewDisplaySequence(
text: message,
menuInputCooldown: true,
fadeTime: 0f,
staticTime: 1.5f,
useUnscaledTime: true,
yPosition: 0f,
textBackgroundAlpha: 1f,
localize: false,
fontFace: TextManager.FontFace.boldMedium,
optionsCallback: response =>
{
if (!response.IsConfirm)
{
return;
}
Debug.Log($"{LogPrefix} Restart button pressed; restarting game.");
if (Manager.platform == null)
{
Debug.LogWarning($"{LogPrefix} Could not restart because Manager.platform is null.");
return;
}
Manager.platform.Restart();
},
options: new List<string> { "cancelDialogue", "yes" },
minWidth: 10f,
backgroundAlpha: 0.8f,
priority: 0,
textMaxWidth: 20f,
secondOptionPopsAllMenus: false,
pauseGame: true,
holdToConfirm: false,
localizePlaceholders: false,
accidentalInputBlockDuration: 0f
);
pendingDialogCopiedCount = 0;
}
private static bool IsTitleMainMenuReady(MenuManager menuManager)
{
try
{
if (Manager.load == null || Manager.sceneHandler == null)
{
return false;
}
if (Manager.load.IsSceneTransitionOrLoading() || Manager.load.IsScreenFadingOutOrBlack())
{
return false;
}
if (!Manager.sceneHandler.isTitle || !Manager.sceneHandler.isSceneHandlerReady || Manager.sceneHandler.isIntro || Manager.sceneHandler.isOutro || Manager.sceneHandler.isGameStartUpLoading)
{
return false;
}
return menuManager.GetTopMenu() is RadicalMainMenu;
}
catch (Exception)
{
return false;
}
}
private static MenuManager TryGetMenuManager()
{
try
{
return Manager.menu;
}
catch (Exception)
{
return null;
}
}
}