Decompiled source of ShbonesVariants v1.0.0

plugins/shbones-ShbonesVariants/ShbonesVariants.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using EntityStates;
using EntityStates.BeetleQueenMonster;
using EntityStates.LemurianBruiserMonster;
using HG.Reflection;
using MSU;
using MSU.Config;
using R2API.Utils;
using RoR2;
using RoR2.CharacterAI;
using RoR2.ContentManagement;
using RoR2.Projectile;
using ShbonesVariants;
using UnityEngine;
using VAPI;
using VAPI.Components;

[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")]
[module: UnverifiableCode]
namespace ShbonesVariants
{
	internal class Log
	{
		private static ManualLogSource logger;

		internal Log(ManualLogSource logger_)
		{
			logger = logger_;
		}

		internal static void Debug(object data, [CallerLineNumber] int i = 0, [CallerMemberName] string member = "")
		{
			logger.LogDebug((object)logString(data, i, member));
		}

		internal static void Error(object data, [CallerLineNumber] int i = 0, [CallerMemberName] string member = "")
		{
			logger.LogError((object)logString(data, i, member));
		}

		internal static void Fatal(object data, [CallerLineNumber] int i = 0, [CallerMemberName] string member = "")
		{
			logger.LogFatal((object)logString(data, i, member));
		}

		internal static void Info(object data, [CallerLineNumber] int i = 0, [CallerMemberName] string member = "")
		{
			logger.LogInfo(data);
		}

		internal static void Message(object data, [CallerLineNumber] int i = 0, [CallerMemberName] string member = "")
		{
			logger.LogMessage(data);
		}

		internal static void Warning(object data, [CallerLineNumber] int i = 0, [CallerMemberName] string member = "")
		{
			logger.LogWarning(data);
		}

		private static string logString(object data, [CallerLineNumber] int i = 0, [CallerMemberName] string member = "")
		{
			return $"{data} :: Line: {i}, Method {member}";
		}
	}
	public static class ShbonesVariantsAssets
	{
		private const string ASSET_BUNDLE_NAME = "shbonesvariantsassets";

		private const string ASSET_BUNDLE_FOLDER_NAME = "assetbundles";

		private static AssetBundle _assetBundle;

		public static ResourceAvailability assetsAvailability;

		private static string assetBundleFolderPath => Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)ShbonesVariantsMain.instance).Info.Location), "assetbundles");

		public static TAsset LoadAsset<TAsset>(string name) where TAsset : Object
		{
			return _assetBundle.LoadAsset<TAsset>(name);
		}

		public static SVAssetRequest<TAsset> LoadAssetAsync<TAsset>(string name) where TAsset : Object
		{
			return new SVAssetRequest<TAsset>(_assetBundle.LoadAssetAsync(name));
		}

		public static TAsset[] LoadAssets<TAsset>() where TAsset : Object
		{
			return _assetBundle.LoadAllAssets<TAsset>();
		}

		public static SVAssetRequest<TAsset> LoadAssetsAsync<TAsset>() where TAsset : Object
		{
			return new SVAssetRequest<TAsset>(_assetBundle.LoadAllAssetsAsync<TAsset>());
		}

		internal static IEnumerator Initialize()
		{
			if (!((ResourceAvailability)(ref assetsAvailability)).available)
			{
				IEnumerator loadRoutine = LoadAssetBundle();
				while (!MSUtil.IsDone(loadRoutine))
				{
					yield return null;
				}
				ParallelCoroutine coroutine = new ParallelCoroutine();
				coroutine.Add(SwapShaders());
				coroutine.Add(SwapAddressableShaders());
				coroutine.Add(FinishMaterialVariants());
				while (!coroutine.isDone)
				{
					yield return null;
				}
				((ResourceAvailability)(ref assetsAvailability)).MakeAvailable();
			}
		}

		private static IEnumerator FinishMaterialVariants()
		{
			SVAssetRequest<MaterialVariant> request = ShbonesVariantsAssets.LoadAssetsAsync<MaterialVariant>();
			while (!request.isDone)
			{
				yield return null;
			}
			ParallelCoroutine routine = new ParallelCoroutine();
			MaterialVariant[] assets = request.assets;
			foreach (MaterialVariant val in assets)
			{
				routine.Add(val.ApplyOverrides());
			}
			while (!MSUtil.IsDone((IEnumerator)routine))
			{
				yield return null;
			}
		}

		private static IEnumerator LoadAssetBundle()
		{
			AssetBundleCreateRequest request = AssetBundle.LoadFromFileAsync(Path.Combine(assetBundleFolderPath, "shbonesvariantsassets"));
			while (!((AsyncOperation)request).isDone)
			{
				yield return null;
			}
			_assetBundle = request.assetBundle;
		}

		private static IEnumerator SwapShaders()
		{
			return ShaderUtil.SwapStubbedShadersAsync(_assetBundle);
		}

		private static IEnumerator SwapAddressableShaders()
		{
			return ShaderUtil.LoadAddressableMaterialShadersAsync(_assetBundle);
		}
	}
	public class SVAssetRequest<TAsset> : IEnumerator where TAsset : Object
	{
		private AssetBundleRequest _request;

		public TAsset asset => (TAsset)(object)_request.asset;

		public TAsset[] assets => _request.allAssets.OfType<TAsset>().ToArray();

		public bool isDone => ((AsyncOperation)_request).isDone;

		public float progress => ((AsyncOperation)_request).progress;

		object IEnumerator.Current => _request.asset;

		internal SVAssetRequest(AssetBundleRequest request)
		{
			_request = request;
		}

		bool IEnumerator.MoveNext()
		{
			return !((AsyncOperation)_request).isDone;
		}

		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}
	public class ShbonesVariantsConfig
	{
		public const string PREFIX = "ShbonesVariants.";

		internal static ConfigFactory configFactory { get; private set; }

		internal ShbonesVariantsConfig(BaseUnityPlugin plugin)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			configFactory = new ConfigFactory(plugin);
		}
	}
	public class ShbonesVariantsContent : IContentPackProvider
	{
		internal static ParallelCoroutine _parallelPreLoadDispatchers;

		private static Func<IEnumerator>[] _loadDispatchers;

		internal static ParallelCoroutine _parallelPostLoadDispatchers;

		private static Action[] _fieldAssignDispatchers;

		private bool _initialized;

		private static VariantPackDef _variantPack;

		public string identifier => "com.Shbones.ShbonesVariants";

		public static ReadOnlyContentPack readOnlyContentPack => new ReadOnlyContentPack(contentPack);

		internal static ContentPack contentPack { get; }

		public IEnumerator LoadStaticContentAsync(LoadStaticContentAsyncArgs args)
		{
			if (_initialized)
			{
				yield break;
			}
			IEnumerator enumerator2 = ShbonesVariantsAssets.Initialize();
			while (!MSUtil.IsDone(enumerator2))
			{
				yield return null;
			}
			while (!_parallelPreLoadDispatchers.isDone)
			{
				yield return null;
			}
			for (int i = 0; i < _loadDispatchers.Length; i++)
			{
				args.ReportProgress(Util.Remap((float)(i + 1), 0f, (float)_loadDispatchers.Length, 0.1f, 0.2f));
				enumerator2 = _loadDispatchers[i]();
				while (enumerator2?.MoveNext() ?? false)
				{
					yield return null;
				}
			}
			while (!_parallelPostLoadDispatchers.isDone)
			{
				yield return null;
			}
			for (int j = 0; j < _fieldAssignDispatchers.Length; j++)
			{
				args.ReportProgress(Util.Remap((float)(j + 1), 0f, (float)_fieldAssignDispatchers.Length, 0.95f, 0.99f));
				_fieldAssignDispatchers[j]();
			}
		}

		public IEnumerator GenerateContentPackAsync(GetContentPackAsyncArgs args)
		{
			ContentPack.Copy(contentPack, args.output);
			args.ReportProgress(1f);
			yield return null;
		}

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

		private static IEnumerator AddVariantPack()
		{
			SVAssetRequest<VariantPackDef> variantPackRequest = ShbonesVariantsAssets.LoadAssetAsync<VariantPackDef>("ShbonesVariantPack");
			SVAssetRequest<VariantDef> variantDefsRequest = ShbonesVariantsAssets.LoadAssetsAsync<VariantDef>();
			ParallelCoroutine coroutine = new ParallelCoroutine();
			coroutine.Add((IEnumerator)variantPackRequest);
			coroutine.Add((IEnumerator)variantDefsRequest);
			while (!MSUtil.IsDone((IEnumerator)coroutine))
			{
				yield return null;
			}
			_variantPack = variantPackRequest.asset;
			_variantPack.variants = variantDefsRequest.assets;
			VariantPackCatalog.AddVariantPack(_variantPack, ((BaseUnityPlugin)ShbonesVariantsMain.instance).Config);
		}

		private static IEnumerator AddStates()
		{
			yield return null;
			contentPack.entityStateTypes.Add((from t in typeof(ShbonesVariantsMain).Assembly.GetTypes()
				where t.IsSubclassOf(typeof(EntityState)) && !t.IsAbstract
				select t).ToArray());
		}

		private IEnumerator CallAsyncLoadAttributes()
		{
			ParallelMultiStartCoroutine routine = AsyncAssetLoadAttribute.CreateCoroutineForMod((BaseUnityPlugin)(object)ShbonesVariantsMain.instance);
			routine.Start();
			while (!routine.isDone)
			{
				yield return null;
			}
		}

		private void AddSelf(AddContentPackProviderDelegate addContentPackProvider)
		{
			addContentPackProvider.Invoke((IContentPackProvider)(object)this);
		}

		public ShbonesVariantsContent()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			ContentManager.collectContentPackProviders += new CollectContentPackProvidersDelegate(AddSelf);
			((ResourceAvailability)(ref ShbonesVariantsAssets.assetsAvailability)).CallWhenAvailable((Action)delegate
			{
				_parallelPostLoadDispatchers.Add((IEnumerator)AsyncAssetLoadAttribute.CreateParallelCoroutineForMod((BaseUnityPlugin)(object)ShbonesVariantsMain.instance));
			});
		}

		static ShbonesVariantsContent()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			contentPack = new ContentPack();
			_parallelPreLoadDispatchers = new ParallelCoroutine();
			_parallelPostLoadDispatchers = new ParallelCoroutine();
			_fieldAssignDispatchers = Array.Empty<Action>();
			ShbonesVariantsMain main = ShbonesVariantsMain.instance;
			_loadDispatchers = new Func<IEnumerator>[3]
			{
				() => LanguageFileLoader.AddLanguageFilesFromModAsync((BaseUnityPlugin)(object)main, "languages"),
				AddStates,
				AddVariantPack
			};
		}
	}
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.Shbones.ShbonesVariants", "Shbones Variants", "1.0.0")]
	public class ShbonesVariantsMain : BaseUnityPlugin
	{
		public const string GUID = "com.Shbones.ShbonesVariants";

		public const string MODNAME = "Shbones Variants";

		public const string VERSION = "1.0.0";

		public static ShbonesVariantsMain instance { get; private set; }

		private void Awake()
		{
			instance = this;
			new Log(((BaseUnityPlugin)this).Logger);
			new ShbonesVariantsConfig((BaseUnityPlugin)(object)this);
			new ShbonesVariantsContent();
			Log.Info("Loaded ShbonesVariants", 32, "Awake");
		}
	}
}
namespace ShbonesVariants.Components
{
	public class ExtendAdultLemurianRange : VariantComponent
	{
		public void Awake()
		{
			AISkillDriver[] skillDrivers = ((Component)this).gameObject.GetComponent<BaseAI>().skillDrivers;
			foreach (AISkillDriver val in skillDrivers)
			{
				if (val.customName.Equals("StrafeAndShoot") || val.customName.Equals("StrafeIdley"))
				{
					val.maxDistance *= 2f;
				}
			}
			Object.Destroy((Object)(object)this);
		}
	}
	public class MoveAdultLemurianAimOrigin : VariantComponent
	{
		public void Awake()
		{
			Transform val = ((Component)this).gameObject.GetComponentInChildren<ChildLocator>().FindChild("MuzzleMouth");
			((Component)this).gameObject.GetComponent<CharacterBody>().aimOriginTransform.SetParent(val, false);
			Object.Destroy((Object)(object)this);
		}
	}
}
namespace EntityStates.LemurianMonster.Adult
{
	public class AdultLemurianChargeFireball : ChargeFireball
	{
		public override void FixedUpdate()
		{
			((ChargeFireball)this).FixedUpdate();
			if (((EntityState)this).fixedAge >= base.duration && ((EntityState)this).isAuthority)
			{
				AdultLemurianFireMegaFireball nextState = new AdultLemurianFireMegaFireball();
				((EntityState)this).outer.SetNextState((EntityState)(object)nextState);
			}
		}
	}
	public class AdultLemurianFireMegaFireball : BaseState
	{
		public static int projectileCount = 3;

		public static float totalYawSpread = 5f;

		public static float baseDuration = 2f;

		public static float baseFireDuration = 0.2f;

		public static float damageCoefficient = 1.2f;

		public static float projectileSpeed = FireMegaFireball.projectileSpeed;

		public static float force = 20f;

		public static string attackString;

		private float duration;

		private float fireDuration;

		private int projectilesFired;

		public override void OnEnter()
		{
			((BaseState)this).OnEnter();
			duration = FireMegaFireball.baseDuration / base.attackSpeedStat;
			fireDuration = FireMegaFireball.baseFireDuration / base.attackSpeedStat;
			((EntityState)this).PlayAnimation("Gesture, Additive", FireMegaFireball.FireMegaFireballStateHash, FireMegaFireball.FireMegaFireballParamHash, duration);
			Util.PlaySound(FireMegaFireball.attackString, ((EntityState)this).gameObject);
		}

		public override void FixedUpdate()
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: 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_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			((EntityState)this).FixedUpdate();
			if (((EntityState)this).isAuthority)
			{
				int num = Mathf.FloorToInt(((EntityState)this).fixedAge / fireDuration * (float)projectileCount);
				if (projectilesFired <= num && projectilesFired < projectileCount)
				{
					if (Object.op_Implicit((Object)(object)FireMegaFireball.muzzleflashEffectPrefab))
					{
						EffectManager.SimpleMuzzleFlash(FireMegaFireball.muzzleflashEffectPrefab, ((EntityState)this).gameObject, "MuzzleMouth", false);
					}
					Ray aimRay = ((BaseState)this).GetAimRay();
					float num2 = projectileSpeed;
					float num3 = (float)Mathf.FloorToInt((float)projectilesFired - (float)(projectileCount - 1) / 2f) / (float)(projectileCount - 1) * totalYawSpread;
					Vector3 val = Util.ApplySpread(((Ray)(ref aimRay)).direction, 0f, 0f, 1f, 1f, num3, 0f);
					ProjectileManager.instance.FireProjectileWithoutDamageType(FireMegaFireball.projectilePrefab, ((Ray)(ref aimRay)).origin, Util.QuaternionSafeLookRotation(val), ((EntityState)this).gameObject, base.damageStat * damageCoefficient, force, Util.CheckRoll(base.critStat, ((EntityState)this).characterBody.master), (DamageColorIndex)0, (GameObject)null, num2);
					projectilesFired++;
				}
			}
			if (((EntityState)this).fixedAge >= duration && ((EntityState)this).isAuthority)
			{
				projectilesFired = 0;
				((EntityState)this).outer.SetNextStateToMain();
			}
		}

		public override InterruptPriority GetMinimumInterruptPriority()
		{
			return (InterruptPriority)1;
		}
	}
}
namespace EntityStates.FlyingVermin.Broodmother
{
	public class BroodlingSummon : BaseState
	{
		public static SpawnCard blindPestSpawnCard = Resources.Load<SpawnCard>("SpawnCards/CharacterSpawnCards/cscFlyingVermin");

		public static VariantDef broodling = ShbonesVariantsAssets.LoadAsset<VariantDef>("BroodlingPest");

		public static VariantDef[] variantBroodlings = (VariantDef[])(object)new VariantDef[1] { broodling };

		public bool isSummoning;

		public int summonsPerActivation = 3;

		public float baseDuration = 3f;

		private float duration;

		private int summonsForThisUsage;

		private float summonInterval;

		private int activationNumber;

		public override void OnEnter()
		{
			int num = ++activationNumber;
			Log.Info("Start Summoning Pests " + num, 27, "OnEnter");
			((BaseState)this).OnEnter();
			summonsForThisUsage = 0;
			duration = baseDuration / base.attackSpeedStat;
			summonInterval = duration / (float)summonsPerActivation;
			isSummoning = true;
		}

		public override void OnExit()
		{
			Log.Info("Exiting Summon " + activationNumber, 37, "OnExit");
			((EntityState)this).OnExit();
		}

		public override void FixedUpdate()
		{
			((EntityState)this).FixedUpdate();
			if (((EntityState)this).fixedAge >= duration && ((EntityState)this).isAuthority)
			{
				((EntityState)this).outer.SetNextStateToMain();
			}
			else if (((EntityState)this).fixedAge > summonInterval * (float)summonsForThisUsage)
			{
				summonsForThisUsage++;
				Util.PlaySound(ChargeSpit.attackSoundString, ((EntityState)this).gameObject);
				((BaseState)this).AddRecoil(-5f, 5f, -5f, 5f);
				summonMob();
			}
		}

		public void summonMob()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			new VariantSummon
			{
				masterPrefab = blindPestSpawnCard.prefab,
				position = ((EntityState)this).transform.position + Vector3.down * 3f,
				rotation = ((EntityState)this).transform.rotation,
				summonerBodyObject = ((EntityState)this).gameObject,
				ignoreTeamMemberLimit = true,
				variantDefs = variantBroodlings,
				supressRewards = true,
				teamIndexOverride = ((EntityState)this).teamComponent.teamIndex,
				inventoryToCopy = ((EntityState)this).characterBody.inventory
			}.PerformSummon();
		}

		public override InterruptPriority GetMinimumInterruptPriority()
		{
			return (InterruptPriority)7;
		}
	}
}