Skip to content

Commit dd7050d

Browse files
committed
Minor code changes.
Code Cleanup Made startup optimizations optional. They're proving unstable.
1 parent 1ccd4cc commit dd7050d

6 files changed

Lines changed: 84 additions & 32 deletions

File tree

ShortStartLoader/GetFilesFix.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static bool DirGetFilesCache(ref string __0, ref string __1, ref SearchOp
1919

2020
__result = Directory.GetFiles(__0, "*", searchOption).Where(path => reg.IsMatch(Path.GetFileName(path))).ToArray();
2121
#if DEBUG
22-
Main.PLogger.LogInfo($"Returning: {__result.Count()} files... Found with reg {reg} converted from wildcard {__1}.");
22+
ShortStartLoader.PluginLogger.LogDebug($"Returning: {__result.Count()} files... Found with reg {reg} converted from wildcard {__1}.");
2323
#endif
2424

2525
return false;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using HarmonyLib;
2+
3+
namespace ShortStartLoader
4+
{
5+
public class MultiThreadingFixes
6+
{
7+
[HarmonyPatch(typeof(FileSystemArchive))]
8+
[HarmonyPatch(typeof(FileSystemWindows))]
9+
[HarmonyPatch(nameof(AFileSystemBase.GetList))]
10+
[HarmonyPatch(nameof(AFileSystemBase.GetFileListAtExtension))]
11+
[HarmonyPatch(nameof(AFileSystemBase.GetNameMapLastArchive))]
12+
[HarmonyPrefix]
13+
public static void MultiThreadLocker(ref FileSystemWindows __instance)
14+
{
15+
System.Threading.Monitor.TryEnter(__instance);
16+
}
17+
18+
[HarmonyPatch(typeof(FileSystemArchive))]
19+
[HarmonyPatch(typeof(FileSystemWindows))]
20+
[HarmonyPatch(nameof(AFileSystemBase.GetList))]
21+
[HarmonyPatch(nameof(AFileSystemBase.GetFileListAtExtension))]
22+
[HarmonyPatch(nameof(AFileSystemBase.GetNameMapLastArchive))]
23+
[HarmonyFinalizer]
24+
public static void MultiThreadUnlocker(ref FileSystemWindows __instance)
25+
{
26+
System.Threading.Monitor.Exit(__instance);
27+
}
28+
}
29+
}
Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,40 @@
1010

1111
namespace ShortStartLoader
1212
{
13-
[BepInPlugin("ShortStartLoader", "ShortStartLoader", "1.2")]
13+
[BepInPlugin("ShortStartLoader", "ShortStartLoader", "1.3.2")]
1414
[BepInDependency("BepInEx.SybarisLoader.Patcher", BepInDependency.DependencyFlags.SoftDependency)]
15-
public class SslMain : BaseUnityPlugin
15+
public class ShortStartLoader : BaseUnityPlugin
1616
{
17-
public static ManualLogSource PubLogger;
18-
public static ConfigEntry<bool> UseNewMethod;
19-
public static ConfigEntry<bool> GetFileFilterFix;
20-
public static ConfigEntry<bool> FileOpOptimize;
21-
private static Harmony _harmony;
17+
public static ShortStartLoader Instance { get; private set; }
18+
public static ManualLogSource PluginLogger => Instance.Logger;
19+
20+
public static ConfigEntry<bool> MultiThreadStartup { get; private set; }
21+
public static ConfigEntry<bool> UseNewMethod { get; private set; }
22+
public static ConfigEntry<bool> GetFileFilterFix { get; private set; }
23+
public static ConfigEntry<bool> FileOpOptimize { get; private set; }
2224

2325
private void Awake()
2426
{
25-
PubLogger = Logger;
26-
27+
Instance = this;
28+
MultiThreadStartup = Config.Bind("General", "Multi-thread startup", false, "Can increase initial load times of the game, but at the cost of stability. If you're getting crashes at game startup, disable this.");
2729
UseNewMethod = Config.Bind("General", "Use New Method", true, "Uses a new method that further incorporates optimization from the built in WSQO. Confers a nice speed boost but stability is unsure.");
2830
GetFileFilterFix = Config.Bind("General", "Fix GetFiles (Restart Required)", true, "Fixes an issue with GetFiles where using any search pattern would be significantly slower than fetching every file and filtering.");
2931
FileOpOptimize = Config.Bind("General", "Optimize File Operations", true, "Same functionality as ModMenuAccel or WSQO. It speeds up various file operations that were slow and had room for improvement.");
3032

31-
_harmony = Harmony.CreateAndPatchAll(typeof(StartupOptimize));
33+
var harmony = Harmony.CreateAndPatchAll(typeof(ShortStartLoader));
34+
35+
if (MultiThreadStartup.Value)
36+
{
37+
harmony.PatchAll(typeof(MultiThreadingFixes));
38+
harmony.PatchAll(typeof(StartupOptimize));
39+
}
3240
if (FileOpOptimize.Value)
3341
{
34-
_harmony.PatchAll(typeof(FileOpOptimize));
42+
harmony.PatchAll(typeof(FileOpOptimize));
3543
}
36-
3744
if (GetFileFilterFix.Value)
3845
{
39-
_harmony.PatchAll(typeof(GetFilesFix));
46+
harmony.PatchAll(typeof(GetFilesFix));
4047
}
4148
}
4249
}

ShortStartLoader/ShortStartLoader.csproj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@
3737
<HintPath>..\packages\HarmonyX.2.9.0\lib\net35\0Harmony.dll</HintPath>
3838
</Reference>
3939
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
40-
<HintPath>..\packages\COM3D2.GameLibs.2.24.0-r.1\lib\net35\Assembly-CSharp.dll</HintPath>
40+
<HintPath>..\packages\COM3D2.GameLibs.2.34.0-r.0\lib\net35\Assembly-CSharp.dll</HintPath>
4141
</Reference>
4242
<Reference Include="Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
43-
<HintPath>..\packages\COM3D2.GameLibs.2.24.0-r.1\lib\net35\Assembly-CSharp-firstpass.dll</HintPath>
43+
<HintPath>..\packages\COM3D2.GameLibs.2.34.0-r.0\lib\net35\Assembly-CSharp-firstpass.dll</HintPath>
4444
</Reference>
4545
<Reference Include="BepInEx, Version=5.4.21.0, Culture=neutral, processorArchitecture=MSIL">
4646
<HintPath>..\packages\BepInEx.BaseLib.5.4.21\lib\net35\BepInEx.dll</HintPath>
@@ -79,15 +79,16 @@
7979
<HintPath>..\packages\UnityEngine.5.6.1\lib\net35\UnityEngine.dll</HintPath>
8080
</Reference>
8181
<Reference Include="UnityEngine.UI, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
82-
<HintPath>..\packages\COM3D2.GameLibs.2.24.0-r.1\lib\net35\UnityEngine.UI.dll</HintPath>
82+
<HintPath>..\packages\COM3D2.GameLibs.2.34.0-r.0\lib\net35\UnityEngine.UI.dll</HintPath>
8383
</Reference>
8484
</ItemGroup>
8585
<ItemGroup>
8686
<Compile Include="GetFilesFix.cs" />
8787
<Compile Include="FileOpOptimize.cs" />
88+
<Compile Include="MultiThreadingFixes.cs" />
8889
<Compile Include="StartupOptimize.cs" />
8990
<Compile Include="WildcardToRegex.cs" />
90-
<Compile Include="SslMain.cs" />
91+
<Compile Include="ShortStartLoader.cs" />
9192
<Compile Include="Properties\AssemblyInfo.cs" />
9293
<None Include="packages.config" />
9394
</ItemGroup>

ShortStartLoader/StartupOptimize.cs

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static void WaitForLegacy()
4040

4141
if (_legacyLoadTask.IsFaulted)
4242
{
43-
SslMain.PubLogger.LogFatal("The legacy loader thread encountered a fatal error!");
43+
ShortStartLoader.PluginLogger.LogFatal("The legacy loader thread encountered a fatal error!");
4444

4545
if (_legacyLoadTask.Exception?.InnerException != null)
4646
{
@@ -86,7 +86,7 @@ private static void WaitForThread()
8686

8787
if (_modLoadTask.IsFaulted)
8888
{
89-
SslMain.PubLogger.LogFatal("The mod loader thread encountered a fatal error!");
89+
ShortStartLoader.PluginLogger.LogFatal("The mod loader thread encountered a fatal error!");
9090

9191
if (_modLoadTask.Exception?.InnerException != null)
9292
{
@@ -220,29 +220,30 @@ void LoadAllArcOfPrefix2(string prefix)
220220
var stopWatchLoc = new Stopwatch();
221221
stopWatchLoc.Start();
222222

223-
SslMain.PubLogger.LogInfo("■■■■■■■■ SSL's FileSystemOld Loading Thread has begun.");
223+
ShortStartLoader.PluginLogger.LogInfo("■■■■■■■■ SSL's FileSystemOld Loading Thread has begun.");
224224

225225
GameUty.UpdateFileSystemPathOld();
226226

227-
SslMain.PubLogger.LogInfo($"■■■■■■■■ SSL's FileSystemOld Loading Thread has finished in {stopWatchLoc.Elapsed}");
227+
ShortStartLoader.PluginLogger.LogInfo($"■■■■■■■■ SSL's FileSystemOld Loading Thread has finished in {stopWatchLoc.Elapsed}");
228228
});
229229

230230
_modLoadTask = Task.Factory.StartNew(delegate
231231
{
232232
var stopwatch1 = new Stopwatch();
233233
stopwatch1.Start();
234234

235-
SslMain.PubLogger.LogInfo("■■■■■■■■ SSL's Mod Loading Thread has begun...");
235+
ShortStartLoader.PluginLogger.LogInfo("■■■■■■■■ SSL's Mod Loading Thread has begun...");
236236

237237
if (Directory.Exists(gamePath + "Mod"))
238238
{
239239
GameUty.m_ModFileSystem = new FileSystemWindows();
240240
GameUty.m_ModFileSystem.SetBaseDirectory(gamePath);
241241
GameUty.m_ModFileSystem.AddFolder("Mod");
242242

243-
var listOfDirsInModFolder = GameUty.m_ModFileSystem.GetList(string.Empty, AFileSystemBase.ListType.AllFolder);
243+
var listOfDirsInModFolder =
244+
GameUty.m_ModFileSystem.GetList(string.Empty, AFileSystemBase.ListType.AllFolder);
244245

245-
SslMain.PubLogger.LogDebug($"{listOfDirsInModFolder.Count()} have been found in the Mod Folder.");
246+
ShortStartLoader.PluginLogger.LogDebug($"{listOfDirsInModFolder.Count()} have been found in the Mod Folder.");
246247

247248
//Supposedly it's useless since we're using AddFolder above. but maybe it isn't.
248249
for (var c = 0; c < listOfDirsInModFolder.Length; c++)
@@ -253,17 +254,22 @@ void LoadAllArcOfPrefix2(string prefix)
253254
}
254255
}
255256

256-
if (SslMain.UseNewMethod.Value)
257+
if (ShortStartLoader.UseNewMethod.Value)
257258
{
258259
GameUty.m_aryModOnlysMenuFiles = GameUty.m_ModFileSystem.GetFileListAtExtension(".menu");
259260
for (var r = 0; r < GameUty.m_aryModOnlysMenuFiles.Length; r++)
260261
{
262+
#if DEBUG
263+
ShortStartLoader.PluginLogger.LogDebug($"Getting file name of {GameUty.m_aryModOnlysMenuFiles[r]}");
264+
#endif
261265
GameUty.m_aryModOnlysMenuFiles[r] = Path.GetFileName(GameUty.m_aryModOnlysMenuFiles[r]);
262266
}
263267
}
264268
else
265269
{
266-
var listOfMenusInModFolder = GameUty.m_ModFileSystem.GetList(string.Empty, AFileSystemBase.ListType.AllFile);
270+
var listOfMenusInModFolder =
271+
GameUty.m_ModFileSystem.GetList(string.Empty, AFileSystemBase.ListType.AllFile);
272+
267273
GameUty.m_aryModOnlysMenuFiles = listOfMenusInModFolder.Where(strFile => Regex.IsMatch(strFile, ".*\\.menu$")).ToArray();
268274
}
269275

@@ -274,7 +280,7 @@ void LoadAllArcOfPrefix2(string prefix)
274280
}
275281
}
276282

277-
SslMain.PubLogger.LogInfo($"■■■■■■■■ SSL's Mod Load Thread has finished @ {stopwatch1.Elapsed}");
283+
ShortStartLoader.PluginLogger.LogInfo($"■■■■■■■■ SSL's Mod Load Thread has finished @ {stopwatch1.Elapsed}");
278284
});
279285

280286
/* Informative, off for now.
@@ -512,6 +518,9 @@ void LoadAllArcOfPrefix2(string prefix)
512518
{
513519
foreach (var path in bgArcs)
514520
{
521+
#if DEBUG
522+
ShortStartLoader.PluginLogger.LogDebug($"Getting file name of {path}");
523+
#endif
515524
var fileName = Path.GetFileName(path);
516525
var flag27 = Path.GetExtension(fileName) == ".asset_bg" && !GameUty.BgFiles.ContainsKey(fileName);
517526
if (flag27)
@@ -529,6 +538,9 @@ void LoadAllArcOfPrefix2(string prefix)
529538
{
530539
foreach (var arcPath in bgArcs)
531540
{
541+
#if DEBUG
542+
ShortStartLoader.PluginLogger.LogDebug($"Getting file name of {arcPath}");
543+
#endif
532544
var file = Path.GetFileName(arcPath);
533545
if (!Path.GetExtension(file).Equals(".asset_language"))
534546
{
@@ -556,7 +568,7 @@ void LoadAllArcOfPrefix2(string prefix)
556568
}
557569
}
558570

559-
Debug.Log($"■■■■■■■■ Done @ {stopwatch.Elapsed}");
571+
ShortStartLoader.PluginLogger.LogInfo($"\n■■■■■■■■ Done @ {stopwatch.Elapsed}");
560572

561573
//UnityEngine.Debug.Log("■■■■■■■■ Done!");
562574

@@ -579,7 +591,7 @@ public static bool UpdateFileSystemPathOld()
579591

580592
stopwatch.Start();
581593

582-
Debug.Log("■■■■■■■■ Archive Log[Legacy]");
594+
ShortStartLoader.PluginLogger.LogInfo("■■■■■■■■ Archive Log[Legacy]");
583595

584596
bool AddFolderOrArchive(string name)
585597
{
@@ -681,6 +693,9 @@ void Action(string prefix)
681693

682694
foreach (var path in bgFiles)
683695
{
696+
#if DEBUG
697+
ShortStartLoader.PluginLogger.LogDebug($"Getting file name of {path}");
698+
#endif
684699
var fileName = Path.GetFileName(path);
685700
if (Path.GetExtension(fileName) == ".asset_bg" && !GameUty.BgFiles.ContainsKey(fileName))
686701
{
@@ -689,7 +704,7 @@ void Action(string prefix)
689704
}
690705
}
691706

692-
Debug.Log($"■■■■■■■■ Done Loading Legacy Files @ {stopwatch.Elapsed}");
707+
ShortStartLoader.PluginLogger.LogInfo($"■■■■■■■■ Done Loading Legacy Files @ {stopwatch.Elapsed}");
693708
stopwatch.Stop();
694709

695710
return false;

ShortStartLoader/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<packages>
33
<package id="BepInEx.BaseLib" version="5.4.21" targetFramework="net35" />
44
<package id="BepInEx.Core" version="5.4.21" targetFramework="net35" />
5-
<package id="COM3D2.GameLibs" version="2.24.0-r.1" targetFramework="net35" />
5+
<package id="COM3D2.GameLibs" version="2.34.0-r.0" targetFramework="net35" />
66
<package id="HarmonyX" version="2.9.0" targetFramework="net35" />
77
<package id="Mono.Cecil" version="0.10.4" targetFramework="net35" />
88
<package id="MonoMod.RuntimeDetour" version="22.1.29.1" targetFramework="net35" />

0 commit comments

Comments
 (0)