Decompiled source of SnowtimeStages v0.1.0

plugins/WinterWonderland-SnowtimeStages/SnowtimeStagesAsmdef.dll

Decompiled 4 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HG.Reflection;
using R2API;
using RoR2;
using RoR2.ContentManagement;
using Snowtime.Content;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: OptIn]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace Snowtime
{
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void Debug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void Error(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
	[BepInPlugin("SnowySnowtime.SnowtimeStage", "SnowtimeStage", "1.0.0")]
	public class SnowtimeStage : BaseUnityPlugin
	{
		public const string Author = "SnowySnowtime";

		public const string Name = "SnowtimeStage";

		public const string Version = "1.0.0";

		public const string GUID = "SnowySnowtime.SnowtimeStage";

		public static SnowtimeStage instance;

		private void Awake()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			instance = this;
			Log.Init(((BaseUnityPlugin)this).Logger);
			ContentManager.collectContentPackProviders += new CollectContentPackProvidersDelegate(GiveToRoR2OurContentPackProviders);
			Language.collectLanguageRootFolders += CollectLanguageRootFolders;
		}

		private void Destroy()
		{
			Language.collectLanguageRootFolders -= CollectLanguageRootFolders;
		}

		private void GiveToRoR2OurContentPackProviders(AddContentPackProviderDelegate addContentPackProvider)
		{
			addContentPackProvider.Invoke((IContentPackProvider)(object)new ContentProvider());
		}

		public void CollectLanguageRootFolders(List<string> folders)
		{
			folders.Add(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "Language"));
		}
	}
}
namespace Snowtime.Content
{
	public class ContentProvider : IContentPackProvider
	{
		private readonly ContentPack _contentPack = new ContentPack();

		public static string assetDirectory;

		public string identifier => "SnowySnowtime.SnowtimeStage.ContentProvider";

		public IEnumerator LoadStaticContentAsync(LoadStaticContentAsyncArgs args)
		{
			_contentPack.identifier = identifier;
			string assetsFolderFullPath = (assetDirectory = Path.Combine(Path.GetDirectoryName(typeof(ContentProvider).Assembly.Location), "assetbundles"));
			AssetBundle scenesAssetBundle = null;
			yield return LoadAssetBundle(Path.Combine(assetsFolderFullPath, "snowtimestages"), args.progressReceiver, delegate(AssetBundle assetBundle)
			{
				scenesAssetBundle = assetBundle;
			});
			AssetBundle assetsAssetBundle = null;
			yield return LoadAssetBundle(Path.Combine(assetsFolderFullPath, "snowtimeassets"), args.progressReceiver, delegate(AssetBundle assetBundle)
			{
				assetsAssetBundle = assetBundle;
			});
			yield return SnowtimeContent.LoadAssetBundlesAsync(scenesAssetBundle, assetsAssetBundle, args.progressReceiver, _contentPack);
		}

		private IEnumerator LoadAssetBundle(string assetBundleFullPath, IProgress<float> progress, Action<AssetBundle> onAssetBundleLoaded)
		{
			AssetBundleCreateRequest assetBundleCreateRequest = AssetBundle.LoadFromFileAsync(assetBundleFullPath);
			while (!((AsyncOperation)assetBundleCreateRequest).isDone)
			{
				progress.Report(((AsyncOperation)assetBundleCreateRequest).progress);
				yield return null;
			}
			onAssetBundleLoaded(assetBundleCreateRequest.assetBundle);
		}

		public IEnumerator GenerateContentPackAsync(GetContentPackAsyncArgs args)
		{
			ContentPack.Copy(_contentPack, args.output);
			args.ReportProgress(1f);
			yield break;
		}

		public IEnumerator FinalizeAsync(FinalizeAsyncArgs args)
		{
			args.ReportProgress(1f);
			yield break;
		}
	}
	public static class SnowtimeContent
	{
		internal const string ScenesAssetBundleFileName = "snowtimestages";

		internal const string AssetsAssetBundleFileName = "snowtimeassets";

		private static AssetBundle _scenesAssetBundle;

		private static AssetBundle _assetsAssetBundle;

		internal static UnlockableDef[] UnlockableDefs;

		internal static SceneDef[] SceneDefs;

		internal static SceneDef STSceneDef;

		internal static Sprite STSceneDefPreviewSprite;

		internal static Material STBazaarSeer;

		public static List<Material> SwappedMaterials = new List<Material>();

		public static Dictionary<string, string> ShaderLookup = new Dictionary<string, string>
		{
			{ "stubbedror2/base/shaders/hgstandard", "RoR2/Base/Shaders/HGStandard.shader" },
			{ "stubbedror2/base/shaders/hgsnowtopped", "RoR2/Base/Shaders/HGSnowTopped.shader" },
			{ "stubbedror2/base/shaders/hgtriplanarterrainblend", "RoR2/Base/Shaders/HGTriplanarTerrainBlend.shader" },
			{ "stubbedror2/base/shaders/hgintersectioncloudremap", "RoR2/Base/Shaders/HGIntersectionCloudRemap.shader" },
			{ "stubbedror2/base/shaders/hgcloudremap", "RoR2/Base/Shaders/HGCloudRemap.shader" },
			{ "stubbedror2/base/shaders/hgdistortion", "RoR2/Base/Shaders/HGDistortion.shader" },
			{ "stubbedcalm water/calmwater - dx11 - doublesided", "Calm Water/CalmWater - DX11 - DoubleSided.shader" },
			{ "stubbedcalm water/calmwater - dx11", "Calm Water/CalmWater - DX11.shader" },
			{ "stubbednature/speedtree", "RoR2/Base/Shaders/SpeedTreeCustom.shader" }
		};

		internal static IEnumerator LoadAssetBundlesAsync(AssetBundle scenesAssetBundle, AssetBundle assetsAssetBundle, IProgress<float> progress, ContentPack contentPack)
		{
			_scenesAssetBundle = scenesAssetBundle;
			_assetsAssetBundle = assetsAssetBundle;
			Log.Debug("Asset bundles found. Loading asset bundles...");
			yield return LoadAllAssetsAsync<Material>(_assetsAssetBundle, progress, (Action<Material[]>)delegate(Material[] assets)
			{
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				if (assets != null)
				{
					Material[] array = assets;
					foreach (Material val in array)
					{
						if (((Object)val.shader).name.StartsWith("Stubbed"))
						{
							Shader val2 = Addressables.LoadAssetAsync<Shader>((object)ShaderLookup[((Object)val.shader).name.ToLower()]).WaitForCompletion();
							if (Object.op_Implicit((Object)(object)val2))
							{
								val.shader = val2;
								SwappedMaterials.Add(val);
							}
						}
					}
				}
			});
			yield return LoadAllAssetsAsync<UnlockableDef>(_assetsAssetBundle, progress, (Action<UnlockableDef[]>)delegate(UnlockableDef[] assets)
			{
				UnlockableDefs = assets;
				contentPack.unlockableDefs.Add(assets);
			});
			yield return LoadAllAssetsAsync<Sprite>(_assetsAssetBundle, progress, (Action<Sprite[]>)delegate(Sprite[] assets)
			{
				STSceneDefPreviewSprite = assets.First((Sprite a) => ((Object)a).name == "texSTScenePreview");
			});
			yield return LoadAllAssetsAsync<SceneDef>(_assetsAssetBundle, progress, (Action<SceneDef[]>)delegate(SceneDef[] assets)
			{
				SceneDefs = assets;
				STSceneDef = SceneDefs.First((SceneDef sd) => sd.cachedName == "snowtime_deathisland");
				Log.Debug(STSceneDef.nameToken);
				contentPack.sceneDefs.Add(assets);
			});
			STBazaarSeer = StageRegistration.MakeBazaarSeerMaterial(STSceneDefPreviewSprite.texture);
			STSceneDef.previewTexture = (Texture)(object)STSceneDefPreviewSprite.texture;
			STSceneDef.portalMaterial = STBazaarSeer;
			AsyncOperationHandle<GameObject> dioramaPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/golemplains/GolemplainsDioramaDisplay.prefab");
			while (!dioramaPrefab.IsDone)
			{
				yield return null;
			}
			STSceneDef.dioramaPrefab = dioramaPrefab.Result;
			AsyncOperationHandle<MusicTrackDef> mainTrackDefRequest = Addressables.LoadAssetAsync<MusicTrackDef>((object)"RoR2/Base/Common/muSong13.asset");
			while (!mainTrackDefRequest.IsDone)
			{
				yield return null;
			}
			AsyncOperationHandle<MusicTrackDef> bossTrackDefRequest = Addressables.LoadAssetAsync<MusicTrackDef>((object)"RoR2/Base/Common/muSong05.asset");
			while (!bossTrackDefRequest.IsDone)
			{
				yield return null;
			}
			STSceneDef.mainTrack = mainTrackDefRequest.Result;
			STSceneDef.bossTrack = bossTrackDefRequest.Result;
			StageRegistration.RegisterSceneDefToLoop(STSceneDef);
			Log.Debug(STSceneDef.destinationsGroup);
		}

		private static IEnumerator LoadAllAssetsAsync<T>(AssetBundle assetBundle, IProgress<float> progress, Action<T[]> onAssetsLoaded) where T : Object
		{
			AssetBundleRequest sceneDefsRequest = assetBundle.LoadAllAssetsAsync<T>();
			while (!((AsyncOperation)sceneDefsRequest).isDone)
			{
				progress.Report(((AsyncOperation)sceneDefsRequest).progress);
				yield return null;
			}
			onAssetsLoaded(sceneDefsRequest.allAssets.Cast<T>().ToArray());
		}
	}
}