Decompiled source of FasterLoadTimes v0.0.1

FasterLoadTimes.dll

Decompiled 6 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Reptile;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("FasterLoadTimes")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+f9412eb3db1d83142f7b4a178fa34f498177caf0")]
[assembly: AssemblyProduct("FasterLoadTimes")]
[assembly: AssemblyTitle("FasterLoadTimes")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace FasterLoadTimes
{
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "FasterLoadTimes";

		public const string PLUGIN_NAME = "FasterLoadTimes";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace Cspotcode.FasterLoadTimes
{
	public class FasterLoadTimesConfig
	{
		public static FasterLoadTimesConfig Instance;

		public ConfigEntry<bool> DisableExtendedLoadingTime;

		public FasterLoadTimesConfig(ConfigFile file)
		{
			string text = "General";
			DisableExtendedLoadingTime = file.Bind<bool>(text, "DisableExtendedLoadingTime", true, "Disable BRC's \"extended loading time\" which shows the loading screen for an additional half a second to mask pop-in.");
		}
	}
	internal class Logger
	{
		public delegate object GetMessageDelegate();

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static void Log(GetMessageDelegate fn)
		{
		}

		public static string Timestamp()
		{
			return DateTimeOffset.Now.ToString("HH:mm:ss.ffff");
		}
	}
	[BepInPlugin("com.cspotcode.FasterLoadTimes", "FasterLoadTimes", "1.0.0")]
	public class FasterLoadTimesPlugin : BaseUnityPlugin
	{
		private const string MyGUID = "com.cspotcode.FasterLoadTimes";

		private const string PluginName = "FasterLoadTimes";

		private const string VersionString = "1.0.0";

		private Harmony harmony;

		public static FasterLoadTimesPlugin Instance { get; private set; }

		public ManualLogSource Logger => ((BaseUnityPlugin)this).Logger;

		private void Awake()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			Instance = this;
			harmony = new Harmony("com.cspotcode.FasterLoadTimes");
			FasterLoadTimesConfig.Instance = new FasterLoadTimesConfig(((BaseUnityPlugin)this).Config);
			harmony.PatchAll();
		}
	}
}
namespace Cspotcode.FasterLoadTimes.Patches
{
	[HarmonyPatch(typeof(Assets))]
	internal static class AssetsPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("LoadBundleASync")]
		private static bool LoadBundleASync_Prefix(ref IEnumerator __result, Assets __instance, Bundle bundleToLoad)
		{
			if (bundleToLoad.IsLoaded)
			{
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch("LoadAssetLoadersForSceneASync")]
		public static bool LoadAssetLoadersForSceneASync_Prefix(Assets __instance, ref IEnumerator __result, string sceneName)
		{
			__result = LoadAssetLoadersForSceneASync(__instance, sceneName);
			return false;
		}

		private static IEnumerator LoadAssetLoadersForSceneASync(Assets __instance, string sceneName)
		{
			AssetsToLoadData assetsToLoadData = __instance.GetAssetsToLoadDataForScene(sceneName);
			List<ISceneAssetLoader> list = __instance.RetrieveAllAssetLoaders();
			__instance.assetLoadersToLoad = list.Count;
			foreach (ISceneAssetLoader item in list)
			{
				yield return item.LoadAssetsASync(assetsToLoadData);
				__instance.assetLoadersLoaded++;
			}
		}
	}
	[HarmonyPatch(typeof(BaseModule))]
	internal class BaseModulePatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("WaitForExtendedLoadingTime")]
		private static bool WaitForExtendedLoadingTime_Prefix(ref IEnumerator __result, BaseModule __instance, ASceneSetupInstruction sceneSetupInstruction)
		{
			if (FasterLoadTimesConfig.Instance.DisableExtendedLoadingTime.Value)
			{
				sceneSetupInstruction.extendedLoadingTime = 0.01f;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Bundle))]
	internal class BundlePatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("SetAssetBundle")]
		private static void SetAssetBundle_Prefix(Bundle __instance, AssetBundle assetBundle)
		{
			Logger.Log(() => Logger.Timestamp() + " Loaded " + ((Object)assetBundle).name);
		}

		[HarmonyPrefix]
		[HarmonyPatch("Unload")]
		private static bool Unload_Prefix(Bundle __instance)
		{
			string name = __instance.Name;
			if (name == "characters" || name == "character_animation")
			{
				return false;
			}
			Logger.Log(() => Logger.Timestamp() + " Unloading " + ((Object)__instance.assetBundle).name);
			return true;
		}
	}
	[HarmonyPatch(typeof(CharacterLoader))]
	internal class CharacterLoaderPatch
	{
		private static bool loaded;

		private static Material[,] loadedCharacterMaterials;

		private static GameObject[] loadedCharacterFbxAssets;

		[HarmonyPrefix]
		[HarmonyPatch("LoadAssetsASync")]
		private static bool LoadAssetsASync_Patch(CharacterLoader __instance, AssetsToLoadData assetsToLoadData)
		{
			if (assetsToLoadData.loadCharacters)
			{
				if (loaded)
				{
					__instance.loadedCharacterMaterials = loadedCharacterMaterials;
					__instance.loadedCharacterFbxAssets = loadedCharacterFbxAssets;
					return false;
				}
				loaded = true;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch("UnloadAssets")]
		private static bool UnloadAssets_Prefix(CharacterLoader __instance)
		{
			if (loaded && (Object)(object)__instance.loadedCharacterFbxAssets[0] != (Object)null)
			{
				loadedCharacterMaterials = __instance.loadedCharacterMaterials;
				loadedCharacterFbxAssets = __instance.loadedCharacterFbxAssets;
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(MoveStyleLoader))]
	internal class MoveStyleLoaderPatch
	{
		private static bool loaded;

		private static Texture[,] loadedMoveStyleTextures;

		[HarmonyPrefix]
		[HarmonyPatch("LoadAssetsASync")]
		private static bool LoadAssetsASync_Patch(MoveStyleLoader __instance, AssetsToLoadData assetsToLoadData)
		{
			if (assetsToLoadData.loadCharacters)
			{
				if (loaded)
				{
					Logger.Log(() => $"restoring {loadedMoveStyleTextures}");
					__instance.loadedMoveStyleTextures = loadedMoveStyleTextures;
					for (int i = 0; i < loadedMoveStyleTextures.GetLength(0); i++)
					{
						int j;
						for (j = 0; j < loadedMoveStyleTextures.GetLength(1); j++)
						{
							Logger.Log(() => loadedMoveStyleTextures[i, j]);
						}
					}
					return false;
				}
				loaded = true;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch("UnloadAssets")]
		private static bool UnloadAssets_Prefix(MoveStyleLoader __instance)
		{
			Logger.Log(() => $"{loaded} {__instance.loadedMoveStyleTextures}");
			if (loaded && (Object)(object)__instance.loadedMoveStyleTextures[1, 0] != (Object)null)
			{
				loadedMoveStyleTextures = __instance.loadedMoveStyleTextures;
				for (int i = 0; i < loadedMoveStyleTextures.GetLength(0); i++)
				{
					int j;
					for (j = 0; j < loadedMoveStyleTextures.GetLength(1); j++)
					{
						Logger.Log(() => loadedMoveStyleTextures[i, j]);
					}
				}
				return false;
			}
			return true;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}