Decompiled source of Rofl Items v1.0.0

RoflItems.dll

Decompiled 4 hours 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 Microsoft.CodeAnalysis;
using On.RoR2;
using R2API;
using RoR2;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.ResourceManagement.ResourceLocations;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("RoflItems")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RoflItems")]
[assembly: AssemblyTitle("RoflItems")]
[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 ExamplePlugin
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("idolfan.RoflItems", "RoflItems", "1.0.0")]
	public class RoflItems : BaseUnityPlugin
	{
		public const string PluginGUID = "idolfan.RoflItems";

		public const string PluginAuthor = "idolfan";

		public const string PluginName = "RoflItems";

		public const string PluginVersion = "1.0.0";

		private static readonly int[] PrimeNumbers = new int[8] { 2, 3, 5, 7, 11, 13, 17, 19 };

		private readonly Dictionary<CharacterBody, int> playerPrimes = new Dictionary<CharacterBody, int>();

		public ItemDef sledgehammerDef;

		public ItemDef armorplateDef;

		public static BuffDef firstHitBuff;

		public static ConfigEntry<float> armorPerStack { get; set; }

		public static ConfigEntry<float> bonusDamageForFirstStack { get; set; }

		public static ConfigEntry<float> bonusDamageForMoreStacks { get; set; }

		public static ConfigEntry<bool> debugEnabled { get; set; }

		public void Awake()
		{
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Expected O, but got Unknown
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Expected O, but got Unknown
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Expected O, but got Unknown
			armorPerStack = ((BaseUnityPlugin)this).Config.Bind<float>("Armorplate", "Armor per Stack", 4f, "The armor the item gives per Stack.");
			bonusDamageForFirstStack = ((BaseUnityPlugin)this).Config.Bind<float>("Sledgehammer", "First stack bonus", 0.75f, "The damage bonus given on one stack of the item.");
			bonusDamageForMoreStacks = ((BaseUnityPlugin)this).Config.Bind<float>("Sledgehammer", "Further stacks bonus", 0.3f, "The damage bonus given for each further stack of the item.");
			debugEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "Logs debug messages", false, "");
			createItems();
			CharacterBody.RecalculateStats += new hook_RecalculateStats(grantStats);
			CharacterMaster.OnBodyStart += new hook_OnBodyStart(CharacterMaster_OnStart);
			firstHitBuff = ScriptableObject.CreateInstance<BuffDef>();
			((Object)firstHitBuff).name = "FirstHitMarker";
			firstHitBuff.iconSprite = null;
			firstHitBuff.canStack = true;
			firstHitBuff.isDebuff = true;
			ContentAddition.AddBuffDef(firstHitBuff);
			HealthComponent.TakeDamage += new hook_TakeDamage(extraDamageOnFirstHit);
			Stage.onStageStartGlobal += onStageStart;
		}

		private void onStageStart(Stage stage)
		{
			playerPrimes.Clear();
			if (debugEnabled.Value)
			{
				Console.WriteLine("MEGAROFL playerPrimes wurde gecleared");
			}
		}

		private void createItems()
		{
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Expected O, but got Unknown
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Expected O, but got Unknown
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Expected O, but got Unknown
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Expected O, but got Unknown
			AssetBundle val = AssetBundle.LoadFromFile(Assembly.GetExecutingAssembly().Location.Replace("RoflItems.dll", "rofl_items_assets"));
			((MonoBehaviour)this).StartCoroutine(UpgradeStubbedShadersAsync(val));
			armorplateDef = ScriptableObject.CreateInstance<ItemDef>();
			((Object)armorplateDef).name = "Armorplate";
			armorplateDef.nameToken = "Armorplate";
			armorplateDef.pickupToken = "You become the tank.";
			armorplateDef.descriptionToken = $"Grants {armorPerStack.Value}(+{armorPerStack.Value} per Stack) Armor.";
			armorplateDef.loreToken = "Es war einmal ein Panzer.\nSchaden hat er keinen bekommen.";
			armorplateDef._itemTierDef = Addressables.LoadAssetAsync<ItemTierDef>((object)"RoR2/Base/Common/Tier1Def.asset").WaitForCompletion();
			armorplateDef.pickupIconSprite = val.LoadAsset<Sprite>("armorplate.png");
			armorplateDef.pickupModelPrefab = val.LoadAsset<GameObject>("armorplate.prefab");
			armorplateDef.canRemove = true;
			armorplateDef.hidden = false;
			ItemDisplayRuleDict val2 = new ItemDisplayRuleDict((ItemDisplayRule[])null);
			ItemAPI.Add(new CustomItem(armorplateDef, val2));
			sledgehammerDef = ScriptableObject.CreateInstance<ItemDef>();
			((Object)sledgehammerDef).name = "Sledgehammer";
			sledgehammerDef.nameToken = "Sledgehammer";
			sledgehammerDef.pickupToken = "You make the suggestion.";
			sledgehammerDef.descriptionToken = $"Your first hit against an enemy deals {bonusDamageForFirstStack.Value * 100f}% (+{bonusDamageForMoreStacks.Value * 100f}% per Stack) more damage";
			sledgehammerDef.loreToken = "Ich geh mal den Garten durchsuchen (-> Stärke 9 :)).";
			sledgehammerDef._itemTierDef = Addressables.LoadAssetAsync<ItemTierDef>((object)"RoR2/Base/Common/Tier2Def.asset").WaitForCompletion();
			sledgehammerDef.pickupIconSprite = val.LoadAsset<Sprite>("sledgehammer.png");
			sledgehammerDef.pickupModelPrefab = val.LoadAsset<GameObject>("sledgehammer.prefab");
			sledgehammerDef.canRemove = true;
			sledgehammerDef.hidden = false;
			ItemDisplayRuleDict val3 = new ItemDisplayRuleDict((ItemDisplayRule[])null);
			ItemAPI.Add(new CustomItem(sledgehammerDef, val3));
		}

		private void CharacterMaster_OnStart(orig_OnBodyStart orig, CharacterMaster self, CharacterBody body)
		{
			if (debugEnabled.Value)
			{
				Console.WriteLine("MEGAROFLL " + ((Object)self).name);
			}
			orig.Invoke(self, body);
			if ((Object)(object)self.playerCharacterMasterController != (Object)null)
			{
				AssignPrimeToPlayer(body);
			}
		}

		private void AssignPrimeToPlayer(CharacterBody body)
		{
			if (debugEnabled.Value)
			{
				Console.WriteLine("MEGAROFL body " + (object)body);
			}
			if (!((Object)(object)body != (Object)null) || playerPrimes.ContainsKey(body))
			{
				return;
			}
			if (playerPrimes.Count < PrimeNumbers.Length)
			{
				playerPrimes[body] = PrimeNumbers[playerPrimes.Count];
				if (debugEnabled.Value)
				{
					Console.WriteLine($"MEGAROFL Primzahl {PrimeNumbers[playerPrimes.Count - 1]} zugewiesen an Spieler {((Object)body).name}");
				}
			}
			else if (debugEnabled.Value)
			{
				Console.WriteLine("MEGAROFL Nicht genug Primzahlen für alle Spieler!");
			}
		}

		private void extraDamageOnFirstHit(orig_TakeDamage orig, HealthComponent self, DamageInfo damageInfo)
		{
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			CharacterBody body = self.body;
			if (!Object.op_Implicit((Object)(object)damageInfo.attacker) || !Object.op_Implicit((Object)(object)body))
			{
				orig.Invoke(self, damageInfo);
				return;
			}
			CharacterBody component = damageInfo.attacker.GetComponent<CharacterBody>();
			if ((Object)(object)component == (Object)null || (Object)(object)body == (Object)null)
			{
				orig.Invoke(self, damageInfo);
				return;
			}
			int valueOrDefault = playerPrimes.GetValueOrDefault(component);
			if (valueOrDefault == 0)
			{
				orig.Invoke(self, damageInfo);
				return;
			}
			Inventory inventory = component.inventory;
			int itemCount = inventory.GetItemCount(sledgehammerDef);
			if ((Object)(object)inventory == (Object)null || itemCount <= 0)
			{
				orig.Invoke(self, damageInfo);
				return;
			}
			if (!body.HasBuff(firstHitBuff))
			{
				body.AddBuff(firstHitBuff);
				body.SetBuffCount(firstHitBuff.buffIndex, valueOrDefault);
				damageInfo.damage *= calculateFirstHitMult(itemCount);
			}
			else
			{
				int buffCount = body.GetBuffCount(firstHitBuff);
				if (buffCount % valueOrDefault != 0)
				{
					body.SetBuffCount(firstHitBuff.buffIndex, buffCount * valueOrDefault);
					damageInfo.damage *= calculateFirstHitMult(itemCount);
				}
			}
			orig.Invoke(self, damageInfo);
		}

		private float calculateFirstHitMult(int itemCount)
		{
			return 1f + bonusDamageForFirstStack.Value + (float)(itemCount - 1) * bonusDamageForMoreStacks.Value;
		}

		private void grantStats(orig_RecalculateStats orig, CharacterBody self)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self);
			if (Object.op_Implicit((Object)(object)self.inventory))
			{
				int itemCount = self.inventory.GetItemCount(armorplateDef.itemIndex);
				if (itemCount > 0)
				{
					self.armor += armorPerStack.Value * (float)itemCount;
				}
			}
		}

		public IEnumerator UpgradeStubbedShadersAsync(AssetBundle assetBundle)
		{
			Object[] _ = Array.Empty<Object>();
			if ((Object)(object)assetBundle == (Object)null)
			{
				throw new ArgumentNullException("assetBundle");
			}
			AssetBundleRequest loadMaterials = assetBundle.LoadAllAssetsAsync<Material>();
			while (!((AsyncOperation)loadMaterials).isDone)
			{
				yield return null;
			}
			Object[] allMaterials = loadMaterials.allAssets;
			int materialCount = allMaterials.Length;
			if (materialCount <= 0)
			{
				yield break;
			}
			List<AsyncOperationHandle> loadResourceLocationsOperations = new List<AsyncOperationHandle>(materialCount);
			for (int k = materialCount - 1; k >= 0; k--)
			{
				string cachedShaderName = ((Object)((Material)allMaterials[k]).shader).name;
				if (cachedShaderName.StartsWith("Stubbed"))
				{
					loadResourceLocationsOperations.Add(AsyncOperationHandle<IList<IResourceLocation>>.op_Implicit(Addressables.LoadResourceLocationsAsync((object)(cachedShaderName.Substring(7) + ".shader"), typeof(Shader))));
				}
				else
				{
					materialCount--;
					for (int l = k; l < materialCount; l++)
					{
						allMaterials[l] = allMaterials[l + 1];
					}
				}
			}
			if (materialCount <= 0)
			{
				yield break;
			}
			AsyncOperationHandle<IList<AsyncOperationHandle>> loadResourceLocationsGroup = Addressables.ResourceManager.CreateGenericGroupOperation(loadResourceLocationsOperations, false);
			while (!loadResourceLocationsGroup.IsDone)
			{
				yield return null;
			}
			List<IResourceLocation> resourceLocations = new List<IResourceLocation>(materialCount);
			for (int j = materialCount - 1; j >= 0; j--)
			{
				AsyncOperationHandle val = loadResourceLocationsGroup.Result[j];
				IList<IResourceLocation> result = (IList<IResourceLocation>)((AsyncOperationHandle)(ref val)).Result;
				if (result.Count > 0)
				{
					resourceLocations.Add(result[0]);
				}
				else
				{
					materialCount--;
					for (int m = materialCount - j; m < materialCount; m++)
					{
						allMaterials[m] = allMaterials[m + 1];
					}
				}
			}
			if (materialCount > 0)
			{
				AsyncOperationHandle<IList<Shader>> loadShaders = Addressables.LoadAssetsAsync<Shader>((IList<IResourceLocation>)resourceLocations, (Action<Shader>)null, false);
				while (!loadShaders.IsDone)
				{
					yield return null;
				}
				int startIndex = _.Length;
				Array.Resize(ref _, startIndex + materialCount);
				for (int i = 0; i < materialCount; i++)
				{
					SwapShader((Material)allMaterials[i], loadShaders.Result[i]);
					_[startIndex + i] = allMaterials[i];
				}
			}
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		private void SwapShader(Material material, Shader shader)
		{
			int renderQueue = material.renderQueue;
			material.shader = shader;
			material.renderQueue = renderQueue;
		}
	}
}
namespace EntityStates.Abathur.test
{
	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);
		}
	}
}