Decompiled source of RemoteVillage v1.0.2

plugins/viliger-RemoteVillage/AgateVillage.dll

Decompiled a month 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.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HG;
using On.RoR2;
using R2API;
using RoR2;
using RoR2.ContentManagement;
using UnityEngine;
using UnityEngine.AddressableAssets;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("AgateVillage")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AgateVillage")]
[assembly: AssemblyTitle("AgateVillage")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace RoR2_AgateVillage;

[BepInPlugin("Viliger.AgateVillagePlugin", "AgateVillagePlugin", "1.0.2")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class AgateVillagePlugin : BaseUnityPlugin
{
	public const string Author = "Viliger";

	public const string Name = "AgateVillagePlugin";

	public const string Version = "1.0.2";

	public const string GUID = "Viliger.AgateVillagePlugin";

	public static ConfigEntry<bool> UseCustomMusic;

	private void Awake()
	{
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Expected O, but got Unknown
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Expected O, but got Unknown
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Expected O, but got Unknown
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Expected O, but got Unknown
		Log.Init(((BaseUnityPlugin)this).Logger);
		UseCustomMusic = ((BaseUnityPlugin)this).Config.Bind<bool>("Custom Music", "Custom Music", true, "Does the stage use custom music.");
		ContentManager.collectContentPackProviders += new CollectContentPackProvidersDelegate(ContentManager_collectContentPackProviders);
		MusicController.StartIntroMusic += new hook_StartIntroMusic(MusicController_StartIntroMusic);
		Language.collectLanguageRootFolders += CollectLanguageRootFolders;
		DirectorCardCategorySelection mixEnemy = Addressables.LoadAssetAsync<DirectorCardCategorySelection>((object)"RoR2/Base/MixEnemy/dccsMixEnemy.asset").WaitForCompletion();
		if (RegigigasCompat.enabled)
		{
			DirectorCard regigigasSpawnCard = RegigigasCompat.GetRegigigasSpawnCard(mixEnemy);
			if (!((object)regigigasSpawnCard).Equals((object?)null))
			{
				Helpers.AddNewMonsterToStage(new DirectorCardHolder
				{
					Card = regigigasSpawnCard,
					MonsterCategory = (MonsterCategory)4
				}, false, (Stage)1, "agatevillage");
				Log.Info("Regigigas added to agatevillage spawn pool.");
			}
		}
		if (TyranitarCompat.enabled)
		{
			DirectorCard tyranitarSpawnCard = TyranitarCompat.GetTyranitarSpawnCard(mixEnemy);
			if (!((object)tyranitarSpawnCard).Equals((object?)null))
			{
				Helpers.AddNewMonsterToStage(new DirectorCardHolder
				{
					Card = tyranitarSpawnCard,
					MonsterCategory = (MonsterCategory)4
				}, false, (Stage)1, "agatevillage");
				Log.Info("Tyranitar added to agatevillage spawn pool.");
			}
		}
	}

	private void MusicController_StartIntroMusic(orig_StartIntroMusic orig, MusicController self)
	{
		orig.Invoke(self);
		AkSoundEngine.PostEvent("Agate_Play_Music_System", ((Component)self).gameObject);
	}

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

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

	internal const string ScenesAssetBundleFileName = "agatevillagescene";

	internal const string AssetsAssetBundleFileName = "agatevillageassets";

	internal const string MusicSoundBankFileName = "AgateVillageMusic.bnk";

	internal const string InitSoundBankFileName = "AgateVillageInit.bnk";

	internal const string SoundsSoundBankFileName = "AgateVillageSounds.bnk";

	public static SceneDef AgateVillageSceneDef;

	public static readonly 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/hgopaquecloudremap", "RoR2/Base/Shaders/HGOpaqueCloudRemap.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" },
		{ "stubbeddecalicious/decaliciousdeferreddecal", "Decalicious/DecaliciousDeferredDecal.shader" }
	};

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

	private static Sprite AgateVillagePreviewSprite;

	public string identifier => "Viliger.AgateVillagePlugin.ContentProvider";

	public IEnumerator FinalizeAsync(FinalizeAsyncArgs args)
	{
		args.ReportProgress(1f);
		yield break;
	}

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

	public IEnumerator LoadStaticContentAsync(LoadStaticContentAsyncArgs args)
	{
		_contentPack.identifier = identifier;
		LoadSoundBanks(Path.Combine(Path.GetDirectoryName(typeof(ContentProvider).Assembly.Location), "soundbanks"));
		string assetsFolderFullPath = Path.Combine(Path.GetDirectoryName(typeof(ContentProvider).Assembly.Location), "assetbundles");
		AssetBundle scenesAssetBundle = null;
		yield return LoadAssetBundle(Path.Combine(assetsFolderFullPath, "agatevillagescene"), args.progressReceiver, delegate(AssetBundle assetBundle)
		{
			scenesAssetBundle = assetBundle;
		});
		AssetBundle assetsAssetBundle = null;
		yield return LoadAssetBundle(Path.Combine(assetsFolderFullPath, "agatevillageassets"), args.progressReceiver, delegate(AssetBundle assetBundle)
		{
			assetsAssetBundle = assetBundle;
		});
		yield return LoadAllAssetsAsync<Material>(assetsAssetBundle, args.progressReceiver, (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 val3 in array)
				{
					if (((Object)val3.shader).name.StartsWith("Stubbed"))
					{
						Shader val4 = Addressables.LoadAssetAsync<Shader>((object)ShaderLookup[((Object)val3.shader).name.ToLower()]).WaitForCompletion();
						if (Object.op_Implicit((Object)(object)val4))
						{
							val3.shader = val4;
							FixMaterials(val3);
							SwappedMaterials.Add(val3);
						}
					}
				}
			}
		});
		yield return LoadAllAssetsAsync<UnlockableDef>(assetsAssetBundle, args.progressReceiver, (Action<UnlockableDef[]>)delegate(UnlockableDef[] assets)
		{
			_contentPack.unlockableDefs.Add(assets);
		});
		yield return LoadAllAssetsAsync<Sprite>(assetsAssetBundle, args.progressReceiver, (Action<Sprite[]>)delegate(Sprite[] assets)
		{
			AgateVillagePreviewSprite = assets.First((Sprite a) => ((Object)a).name == "texAgateVillage");
		});
		yield return LoadAllAssetsAsync<SceneDef>(assetsAssetBundle, args.progressReceiver, (Action<SceneDef[]>)delegate(SceneDef[] assets)
		{
			AgateVillageSceneDef = assets.First((SceneDef sd) => sd.cachedName == "agatevillage");
			_contentPack.sceneDefs.Add(assets);
		});
		Material val = Object.Instantiate<Material>(Addressables.LoadAssetAsync<Material>((object)"RoR2/Base/bazaar/matBazaarSeerWispgraveyard.mat").WaitForCompletion());
		val.mainTexture = (Texture)(object)AgateVillagePreviewSprite.texture;
		AgateVillageSceneDef.previewTexture = (Texture)(object)AgateVillagePreviewSprite.texture;
		AgateVillageSceneDef.portalMaterial = val;
		if (AgateVillagePlugin.UseCustomMusic.Value)
		{
			SetupMusic();
		}
		else
		{
			AgateVillageSceneDef.mainTrack = Addressables.LoadAssetAsync<MusicTrackDef>((object)"RoR2/Base/Common/MusicTrackDefs/muGameplayBase_09.asset").WaitForCompletion();
			AgateVillageSceneDef.bossTrack = Addressables.LoadAssetAsync<MusicTrackDef>((object)"RoR2/Base/Common/MusicTrackDefs/muSong16.asset").WaitForCompletion();
		}
		ref SceneEntry[] sceneEntries = ref Addressables.LoadAssetAsync<SceneCollection>((object)"RoR2/Base/SceneGroups/sgStage3.asset").WaitForCompletion()._sceneEntries;
		SceneEntry val2 = new SceneEntry
		{
			sceneDef = AgateVillageSceneDef
		};
		((SceneEntry)(ref val2)).weight = 1f;
		ArrayUtils.ArrayAppend<SceneEntry>(ref sceneEntries, ref val2);
		AgateVillageSceneDef.destinationsGroup = Addressables.LoadAssetAsync<SceneCollection>((object)"RoR2/Base/SceneGroups/sgStage4.asset").WaitForCompletion();
		ref SceneEntry[] sceneEntries2 = ref Addressables.LoadAssetAsync<SceneCollection>((object)"RoR2/Base/SceneGroups/loopSgStage3.asset").WaitForCompletion()._sceneEntries;
		val2 = new SceneEntry
		{
			sceneDef = AgateVillageSceneDef
		};
		((SceneEntry)(ref val2)).weight = 1f;
		ArrayUtils.ArrayAppend<SceneEntry>(ref sceneEntries2, ref val2);
		AgateVillageSceneDef.loopedDestinationsGroup = Addressables.LoadAssetAsync<SceneCollection>((object)"RoR2/Base/SceneGroups/loopSgStage4.asset").WaitForCompletion();
	}

	private static void FixMaterials(Material material)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		if (((Object)material).name == "matFire")
		{
			material.SetTexture("_RemapTex", (Texture)(object)Addressables.LoadAssetAsync<Texture2D>((object)"RoR2/Base/Common/ColorRamps/texRampCaptainAirstrike.png").WaitForCompletion());
		}
		else if (((Object)material).name == "matHeatGas")
		{
			material.SetTexture("_RemapTex", (Texture)(object)Addressables.LoadAssetAsync<Texture2D>((object)"RoR2/Base/Common/ColorRamps/texRampLunarSmoke.png").WaitForCompletion());
		}
		else if (((Object)material).name == "matClouds")
		{
			material.SetTexture("_RemapTex", (Texture)(object)Addressables.LoadAssetAsync<Texture2D>((object)"RoR2/Base/Common/ColorRamps/texRampDefault.png").WaitForCompletion());
		}
		else if (((Object)material).name == "matRain")
		{
			material.SetTexture("_MainTex", (Texture)(object)Addressables.LoadAssetAsync<Texture2D>((object)"RoR2/Base/Common/VFX/ParticleMasks/texParticleDust1Mask.png").WaitForCompletion());
			material.SetTexture("_RemapTex", (Texture)(object)Addressables.LoadAssetAsync<Texture2D>((object)"RoR2/Base/Common/ColorRamps/texRampTwotoneEnvironment.jpg").WaitForCompletion());
			material.SetTexture("_Cloud1Tex", (Texture)(object)Addressables.LoadAssetAsync<Texture2D>((object)"RoR2/Base/Common/texCloudDifferenceBW1.png").WaitForCompletion());
		}
	}

	private static void SetupMusic()
	{
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		CustomMusicTrackDef val = ScriptableObject.CreateInstance<CustomMusicTrackDef>();
		((Object)val).name = "AgateVillageMainMusic";
		((MusicTrackDef)val).cachedName = "AgateVillageMainMusic";
		((MusicTrackDef)val).comment = "sunnydaze - Barrow's Ceiling\r\nagatevillage";
		val.CustomStates = new List<CustomState>();
		CustomState item = default(CustomState);
		item.GroupId = 3508158228u;
		item.StateId = 2025383728u;
		val.CustomStates.Add(item);
		CustomState item2 = default(CustomState);
		item2.GroupId = 792781730u;
		item2.StateId = 89505537u;
		val.CustomStates.Add(item2);
		AgateVillageSceneDef.mainTrack = (MusicTrackDef)(object)val;
		CustomMusicTrackDef val2 = ScriptableObject.CreateInstance<CustomMusicTrackDef>();
		((Object)val2).name = "AgateVillageBossMusic";
		((MusicTrackDef)val2).cachedName = "AgateVillageBossMusic";
		((MusicTrackDef)val2).comment = "sunnydaze - Fight!\r\nagatevillage";
		val2.CustomStates = new List<CustomState>();
		CustomState item3 = default(CustomState);
		item3.GroupId = 3508158228u;
		item3.StateId = 514064485u;
		val2.CustomStates.Add(item3);
		CustomState item4 = default(CustomState);
		item4.GroupId = 792781730u;
		item4.StateId = 580146960u;
		val2.CustomStates.Add(item4);
		AgateVillageSceneDef.bossTrack = (MusicTrackDef)(object)val2;
	}

	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);
	}

	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());
	}

	internal static void LoadSoundBanks(string soundbanksFolderPath)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Invalid comparison between Unknown and I4
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Invalid comparison between Unknown and I4
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Invalid comparison between Unknown and I4
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Invalid comparison between Unknown and I4
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		AKRESULT val = AkSoundEngine.AddBasePath(soundbanksFolderPath);
		if ((int)val == 1)
		{
			Log.Info("Added bank base path : " + soundbanksFolderPath);
		}
		else
		{
			Log.Error("Error adding base path : " + soundbanksFolderPath + " " + $"Error code : {val}");
		}
		uint num = default(uint);
		val = AkSoundEngine.LoadBank("AgateVillageInit.bnk", ref num);
		if ((int)val == 1)
		{
			Log.Info("Added bank : AgateVillageInit.bnk");
		}
		else
		{
			Log.Error("Error loading bank : AgateVillageInit.bnk " + $"Error code : {val}");
		}
		val = AkSoundEngine.LoadBank("AgateVillageMusic.bnk", ref num);
		if ((int)val == 1)
		{
			Log.Info("Added bank : AgateVillageMusic.bnk");
		}
		else
		{
			Log.Error("Error loading bank : AgateVillageMusic.bnk " + $"Error code : {val}");
		}
		val = AkSoundEngine.LoadBank("AgateVillageSounds.bnk", ref num);
		if ((int)val == 1)
		{
			Log.Info("Added bank : AgateVillageSounds.bnk");
		}
		else
		{
			Log.Error("Error loading bank : AgateVillageSounds.bnk " + $"Error code : {val}");
		}
	}
}
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);
	}
}
public class PlaySound : MonoBehaviour
{
	public string EnableSound;

	public string DisableSound;

	private void Start()
	{
		Util.PlaySound(EnableSound, ((Component)this).gameObject);
	}

	private void OnDisable()
	{
		Util.PlaySound(DisableSound, ((Component)this).gameObject);
	}
}
public class RegigigasCompat
{
	private static bool? _enabled;

	public static bool enabled
	{
		get
		{
			if (!_enabled.HasValue)
			{
				_enabled = Chainloader.PluginInfos.ContainsKey("com.rob.RegigigasMod");
			}
			return _enabled.Value;
		}
	}

	public static DirectorCard GetRegigigasSpawnCard(DirectorCardCategorySelection mixEnemy)
	{
		return ((IEnumerable<DirectorCard>)mixEnemy.categories[0].cards).FirstOrDefault((Func<DirectorCard, bool>)((DirectorCard card) => ((Object)card.spawnCard).name == "cscRegigigas"));
	}
}
public class TyranitarCompat
{
	private static bool? _enabled;

	public static bool enabled
	{
		get
		{
			if (!_enabled.HasValue)
			{
				_enabled = Chainloader.PluginInfos.ContainsKey("com.rob.Tyranitar");
			}
			return _enabled.Value;
		}
	}

	public static DirectorCard GetTyranitarSpawnCard(DirectorCardCategorySelection mixEnemy)
	{
		return ((IEnumerable<DirectorCard>)mixEnemy.categories[0].cards).FirstOrDefault((Func<DirectorCard, bool>)((DirectorCard card) => ((Object)card.spawnCard).name == "cscTyranitar"));
	}
}