6
6
#if SUBNAUTICA_STABLE
7
7
using Oculus . Newtonsoft . Json ;
8
8
#else
9
- using Newtonsoft . Json ;
9
+ using Newtonsoft . Json ;
10
10
#endif
11
11
using QModManager . API ;
12
12
using QModManager . Patching ;
13
13
using QModManager . Utility ;
14
14
using System ;
15
+ using System . Collections ;
15
16
using System . Collections . Generic ;
16
17
using System . Diagnostics ;
17
18
using System . IO ;
18
19
using System . Linq ;
19
20
using System . Reflection ;
21
+ using System . Text . RegularExpressions ;
22
+ using QModManager . API . ModLoading ;
20
23
using TypeloaderCache = System . Collections . Generic . Dictionary < string , BepInEx . Bootstrap . CachedAssembly < BepInEx . PluginInfo > > ;
21
24
using QMMAssemblyCache = System . Collections . Generic . Dictionary < string , long > ;
22
- using QModManager . API . ModLoading ;
23
- using System . Collections ;
24
25
25
26
namespace QModManager
26
27
{
@@ -57,14 +58,14 @@ public static void Finish()
57
58
{
58
59
PluginCache = GetPluginCache ( ) ;
59
60
Harmony = new Harmony ( "QModManager.QModPluginGenerator" ) ;
60
- foreach ( Assembly assembly in AppDomain . CurrentDomain . GetAssemblies ( ) )
61
+ foreach ( Assembly assembly in AppDomain . CurrentDomain . GetAssemblies ( ) )
61
62
{
62
- if ( assembly ? . GetName ( ) ? . Name ? . Contains ( "MirrorInternalLogs" ) ?? false )
63
+ if ( assembly ? . GetName ( ) ? . Name ? . Contains ( "MirrorInternalLogs" ) ?? false )
63
64
{
64
65
Type type = AccessTools . TypeByName ( "MirrorInternalLogs.Util.LibcHelper" ) ;
65
66
var method = type ? . GetMethod ( "Format" ) ;
66
67
67
- if ( method != null )
68
+ if ( method != null )
68
69
Harmony . Patch ( method , postfix : new HarmonyMethod ( typeof ( QModPluginGenerator ) , nameof ( QModPluginGenerator . LibcHelper_Format_Postfix ) ) ) ;
69
70
break ;
70
71
}
@@ -82,44 +83,51 @@ public static void Finish()
82
83
}
83
84
}
84
85
85
- public static List < string > DirtyStartStrings = new List < string > ( )
86
- {
87
- "Resetting cell with" , "Replacing cell" ,
88
- "PerformGarbage" , "Fallback handler could not load"
89
- } ;
90
-
91
- public static List < string > DirtyMidStrings = new List < string > ( )
92
- {
93
- "\n (Filename" ,
86
+ private readonly static List < Regex > DirtyRegexPatterns = new List < Regex > ( ) {
87
+ new Regex ( @"([\r\n]+)?(\(Filename: .*\))$" , RegexOptions . Compiled | RegexOptions . Multiline ) ,
88
+ new Regex ( @"^(Replacing cell.*)$" , RegexOptions . Compiled | RegexOptions . Multiline ) ,
89
+ new Regex ( @"^(Resetting cell with.*)$" , RegexOptions . Compiled | RegexOptions . Multiline ) ,
90
+ new Regex ( @"^(PerformGarbage.*)$" , RegexOptions . Compiled | RegexOptions . Multiline ) ,
91
+ new Regex ( @"^(Fallback handler could not load.*)$" , RegexOptions . Compiled | RegexOptions . Multiline ) ,
92
+ new Regex ( @"^(Heartbeat CSV.*,[0-9])$" , RegexOptions . Compiled | RegexOptions . Multiline ) ,
93
+ new Regex ( @"^(L0: PerformGarbageCollection ->.*)$" , RegexOptions . Compiled | RegexOptions . Multiline ) ,
94
+ new Regex ( @"^(L0: CellManager::EstimateBytes.*)$" , RegexOptions . Compiled | RegexOptions . Multiline ) ,
95
+ new Regex ( @"^(Kinematic body only supports Speculative Continuous collision detection.*)$" , RegexOptions . Compiled | RegexOptions . Multiline ) ,
94
96
} ;
95
97
96
98
private static void LibcHelper_Format_Postfix ( ref string __result )
97
99
{
98
- foreach ( string dirtyString in DirtyStartStrings )
100
+ foreach ( Regex pattern in DirtyRegexPatterns )
99
101
{
100
- if ( __result . StartsWith ( dirtyString ) )
101
- {
102
- __result = "" ;
103
- return ;
104
- }
105
- }
106
-
107
- foreach ( string dirtyString in DirtyMidStrings )
108
- {
109
- int i = __result . IndexOf ( dirtyString ) ;
110
- if ( i >= 0 )
111
- {
112
- __result = __result . Remove ( i ) ;
113
- return ;
114
- }
102
+ __result = pattern . Replace ( __result , string . Empty ) . Trim ( ) ;
115
103
}
116
104
}
117
105
118
106
#if SUBNAUTICA_STABLE
119
107
[ HarmonyPatch ( typeof ( SystemsSpawner ) , nameof ( SystemsSpawner . Awake ) ) ]
108
+ [ HarmonyPrefix ]
109
+ private static void PreInitializeQMM ( )
110
+ {
111
+ Patcher . Patch ( ) ; // Run QModManager patch
112
+
113
+ ModsToLoad = QModsToLoad . ToList ( ) ;
114
+ Initializer = new Initializer ( Patcher . CurrentlyRunningGame ) ;
115
+ Initializer . InitializeMods ( ModsToLoad , PatchingOrder . MetaPreInitialize ) ;
116
+ Initializer . InitializeMods ( ModsToLoad , PatchingOrder . PreInitialize ) ;
117
+ Initializer . InitializeMods ( ModsToLoad , PatchingOrder . NormalInitialize ) ;
118
+ Initializer . InitializeMods ( ModsToLoad , PatchingOrder . PostInitialize ) ;
119
+ Initializer . InitializeMods ( ModsToLoad , PatchingOrder . MetaPostInitialize ) ;
120
+
121
+ SummaryLogger . ReportIssues ( ModsToLoad ) ;
122
+ SummaryLogger . LogSummaries ( ModsToLoad ) ;
123
+ foreach ( Dialog dialog in Patcher . Dialogs )
124
+ {
125
+ dialog . Show ( ) ;
126
+ }
127
+
128
+ }
120
129
#else
121
130
[ HarmonyPatch ( typeof ( PreStartScreen ) , nameof ( PreStartScreen . Start ) ) ]
122
- #endif
123
131
[ HarmonyPrefix ]
124
132
private static void PreInitializeQMM ( )
125
133
{
@@ -142,10 +150,10 @@ private static void PreInitializeQMM()
142
150
) , postfix : new HarmonyMethod ( AccessTools . Method ( typeof ( QModPluginGenerator ) , nameof ( QModPluginGenerator . InitializeQMM ) ) ) ) ;
143
151
}
144
152
145
- #if SUBNAUTICA
153
+ #if SUBNAUTICA_EXP
146
154
private static IEnumerator InitializeQMM ( IEnumerator result )
147
155
{
148
- if ( ModsToLoad != null )
156
+ if ( ModsToLoad != null )
149
157
{
150
158
yield return result ;
151
159
@@ -155,7 +163,7 @@ private static IEnumerator InitializeQMM(IEnumerator result)
155
163
156
164
SummaryLogger . ReportIssues ( ModsToLoad ) ;
157
165
SummaryLogger . LogSummaries ( ModsToLoad ) ;
158
- foreach ( Dialog dialog in Patcher . Dialogs )
166
+ foreach ( Dialog dialog in Patcher . Dialogs )
159
167
{
160
168
dialog . Show ( ) ;
161
169
}
@@ -165,7 +173,7 @@ private static IEnumerator InitializeQMM(IEnumerator result)
165
173
#elif BELOWZERO
166
174
private static void InitializeQMM ( )
167
175
{
168
- if ( ModsToLoad != null )
176
+ if ( ModsToLoad != null )
169
177
{
170
178
Initializer . InitializeMods ( ModsToLoad , PatchingOrder . NormalInitialize ) ;
171
179
Initializer . InitializeMods ( ModsToLoad , PatchingOrder . PostInitialize ) ;
@@ -174,12 +182,13 @@ private static void InitializeQMM()
174
182
SummaryLogger . ReportIssues ( ModsToLoad ) ;
175
183
SummaryLogger . LogSummaries ( ModsToLoad ) ;
176
184
177
- foreach ( Dialog dialog in Patcher . Dialogs )
185
+ foreach ( Dialog dialog in Patcher . Dialogs )
178
186
{
179
187
dialog . Show ( ) ;
180
188
}
181
189
}
182
190
}
191
+ #endif
183
192
#endif
184
193
185
194
private static string [ ] QMMKnownAssemblyPaths = new [ ] {
@@ -254,7 +263,7 @@ private static void SaveQMMAssemblyCache()
254
263
255
264
using ( var ms = new MemoryStream ( ) )
256
265
using ( var writer = new StreamWriter ( ms ) )
257
- using ( var jsreader = new JsonTextWriter ( writer ) )
266
+ using ( var jsreader = new JsonTextWriter ( writer ) )
258
267
{
259
268
var serializer = new JsonSerializer ( ) ;
260
269
serializer . Serialize ( jsreader , QMMAssemblyCache ) ;
@@ -283,7 +292,7 @@ private static void ClearBepInExCache()
283
292
{
284
293
Directory . Delete ( BepInExCachePath , true ) ;
285
294
}
286
- catch ( IOException e )
295
+ catch ( IOException e )
287
296
{
288
297
Logger . LogDebug ( $ "Clearing BepInEx cache failed with exception. \n { e } ") ;
289
298
}
0 commit comments