Decompiled source of Kratos v1.1.1

KratosMod.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using EntityStates;
using EntityStates.Commando.CommandoWeapon;
using Microsoft.CodeAnalysis;
using R2API;
using RoR2;
using RoR2.Skills;
using UnityEngine;

[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("KratosMod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("KratosMod")]
[assembly: AssemblyTitle("KratosMod")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 KratosMod
{
	[BepInPlugin("com.adrius.kratos", "Kratos", "1.1.1")]
	[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 sealed class KratosPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "com.adrius.kratos";

		public const string PluginName = "Kratos";

		public const string PluginVersion = "1.1.1";

		private static SkillDef _axeThrow;

		private static SkillDef _bladesOfChaos;

		private static SkillDef _spartanRage;

		private static SkillDef _bladeOfOlympus;

		public static GameObject BodyPrefab { get; private set; }

		public static GameObject MasterPrefab { get; private set; }

		public void Awake()
		{
			CreateBodyAndMaster();
			RegisterContent();
			RegisterStates();
			RegisterLanguage();
			RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(AssignSkillIcons));
			Log.Info("Kratos v1.1.1 loaded.");
		}

		private static void CreateBodyAndMaster()
		{
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Resources.Load<GameObject>("Prefabs/CharacterBodies/MercenaryBody");
			GameObject val2 = Resources.Load<GameObject>("Prefabs/CharacterMasters/MercenaryMaster");
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				Log.Fatal("Could not load Mercenary prefabs from resources — aborting Kratos registration.");
				return;
			}
			BodyPrefab = PrefabAPI.InstantiateClone(val, "KratosBody");
			MasterPrefab = PrefabAPI.InstantiateClone(val2, "KratosMaster");
			CharacterBody component = BodyPrefab.GetComponent<CharacterBody>();
			component.baseNameToken = "KRATOS_NAME";
			component.subtitleNameToken = "KRATOS_SUBTITLE";
			component.baseMaxHealth = 180f;
			component.levelMaxHealth = 33f;
			component.baseRegen = 2.5f;
			component.levelRegen = 0.5f;
			component.baseMaxShield = 0f;
			component.baseMoveSpeed = 8.2f;
			component.levelMoveSpeed = 0f;
			component.baseAcceleration = 110f;
			component.baseJumpPower = 21f;
			component.baseJumpCount = 1;
			component.baseDamage = 15f;
			component.levelDamage = 2.7f;
			component.baseAttackSpeed = 1.1f;
			component.levelAttackSpeed = 0.026f;
			component.baseArmor = 20f;
			component.levelArmor = 0f;
			component.baseCrit = 1f;
			component.levelCrit = 0f;
			component.baseVisionDistance = 100f;
			KratosVisuals.ApplyChris(BodyPrefab);
			SkillLocator component2 = BodyPrefab.GetComponent<SkillLocator>();
			_axeThrow = MakeSkill("KratosAxeThrow", "KRATOS_AXE", new SerializableEntityStateType(typeof(AxeThrowState)), "Weapon", 1f, (InterruptPriority)0);
			_bladesOfChaos = MakeSkill("KratosBladesOfChaos", "KRATOS_BLADES", new SerializableEntityStateType(typeof(BladesOfChaosState)), "Weapon", 3.5f, (InterruptPriority)1);
			_spartanRage = MakeSkill("KratosSpartanRage", "KRATOS_RAGE", new SerializableEntityStateType(typeof(SpartanRageState)), "Weapon", 14f, (InterruptPriority)2);
			_bladeOfOlympus = MakeSkill("KratosBladeOfOlympus", "KRATOS_OLYMPUS", new SerializableEntityStateType(typeof(BladeOfOlympusState)), "Weapon", 10f, (InterruptPriority)1);
			ReplaceSlot(component2.primary, _axeThrow);
			ReplaceSlot(component2.secondary, _bladesOfChaos);
			ReplaceSlot(component2.utility, _spartanRage);
			ReplaceSlot(component2.special, _bladeOfOlympus);
			MasterPrefab.GetComponent<CharacterMaster>().bodyPrefab = BodyPrefab;
		}

		private static void RegisterContent()
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			ContentAddition.AddBody(BodyPrefab);
			ContentAddition.AddMaster(MasterPrefab);
			SurvivorDef obj = ScriptableObject.CreateInstance<SurvivorDef>();
			obj.cachedName = "Kratos";
			obj.displayNameToken = "KRATOS_NAME";
			obj.descriptionToken = "KRATOS_DESCRIPTION";
			obj.bodyPrefab = BodyPrefab;
			obj.displayPrefab = BodyPrefab;
			obj.primaryColor = Color32.op_Implicit(new Color32((byte)200, (byte)60, (byte)60, byte.MaxValue));
			obj.desiredSortPosition = 12.5f;
			ContentAddition.AddSurvivorDef(obj);
		}

		private static void RegisterStates()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			bool flag = default(bool);
			ContentAddition.AddEntityState<AxeThrowState>(ref flag);
			ContentAddition.AddEntityState<BladesOfChaosState>(ref flag);
			ContentAddition.AddEntityState<SpartanRageState>(ref flag);
			ContentAddition.AddEntityState<BladeOfOlympusState>(ref flag);
		}

		private static void RegisterLanguage()
		{
			LanguageAPI.Add("KRATOS_NAME", "Kratos");
			LanguageAPI.Add("KRATOS_SUBTITLE", "The Chris Enjoyer");
			LanguageAPI.Add("KRATOS_DESCRIPTION", "<style=cIsHealth>180 HP</style> and <style=cIsHealing>+20 armor</style> from a life of pushing things around.\n<style=cIsDamage>Leviathan Axe</style>: heavy thrown axe.\n<style=cIsDamage>Blades of Chaos</style>: wide chain sweep.\n<style=cIsUtility>OHH CHRISSS</style>: bellow for your beloved Chris — attack speed and speed.\n<style=cIsDamage>Blade of Olympus</style>: divine barrage.");
			LanguageAPI.Add("KRATOS_AXE_NAME", "Leviathan Axe");
			LanguageAPI.Add("KRATOS_AXE_DESC", "<style=cIsDamage>620%</style> damage. Throws the Leviathan Axe in a heavy, unerring arc.");
			LanguageAPI.Add("KRATOS_BLADES_NAME", "Blades of Chaos");
			LanguageAPI.Add("KRATOS_BLADES_DESC", "Sweep the chained blades in a wide arc for <style=cIsDamage>8x140%</style> damage.");
			LanguageAPI.Add("KRATOS_RAGE_NAME", "OHH CHRISSS");
			LanguageAPI.Add("KRATOS_RAGE_DESC", "<style=cIsUtility>Bellow for your beloved Chris.</style> Gain <style=cIsDamage>+50% attack speed</style> and <style=cIsUtility>movement speed</style> for 8 seconds, and mend 10% of max health.");
			LanguageAPI.Add("KRATOS_OLYMPUS_NAME", "Blade of Olympus");
			LanguageAPI.Add("KRATOS_OLYMPUS_DESC", "Five thrusts of the god-killing blade for <style=cIsDamage>5x180%</style> damage.");
		}

		private static SkillDef MakeSkill(string skillName, string token, SerializableEntityStateType state, string machine, float cooldown, InterruptPriority priority)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: 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: Unknown result type (might be due to invalid IL or missing references)
			SkillDef obj = ScriptableObject.CreateInstance<SkillDef>();
			obj.skillName = skillName;
			obj.skillNameToken = token + "_NAME";
			obj.skillDescriptionToken = token + "_DESC";
			obj.keywordTokens = Array.Empty<string>();
			obj.icon = null;
			obj.activationState = state;
			obj.activationStateMachineName = machine;
			obj.interruptPriority = priority;
			obj.baseRechargeInterval = cooldown;
			obj.baseMaxStock = 1;
			obj.rechargeStock = 1;
			obj.requiredStock = 1;
			obj.stockToConsume = 1;
			obj.attackSpeedBuffsRestockSpeed = false;
			obj.resetCooldownTimerOnUse = true;
			obj.fullRestockOnAssign = true;
			obj.dontAllowPastMaxStocks = true;
			obj.beginSkillCooldownOnSkillEnd = true;
			obj.cancelSprintingOnActivation = true;
			obj.canceledFromSprinting = false;
			obj.forceSprintDuringState = false;
			obj.isCombatSkill = true;
			obj.mustKeyPress = false;
			return obj;
		}

		private static void ReplaceSlot(GenericSkill slot, SkillDef def)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			SkillFamily skillFamily = slot.skillFamily;
			skillFamily.variants = (Variant[])(object)new Variant[1]
			{
				new Variant
				{
					skillDef = def,
					unlockableName = string.Empty
				}
			};
			skillFamily.defaultVariantIndex = 0u;
			slot.SetBaseSkill(def);
		}

		private static void AssignSkillIcons()
		{
			GameObject val = BodyCatalog.FindBodyPrefab("MercenaryBody");
			if ((Object)(object)val == (Object)null)
			{
				Log.Warn("MercenaryBody not found for icon assignment; skills will use blank icons.");
				return;
			}
			SkillLocator component = val.GetComponent<SkillLocator>();
			if ((Object)(object)_axeThrow != (Object)null)
			{
				_axeThrow.icon = component.primary.skillDef.icon;
			}
			if ((Object)(object)_bladesOfChaos != (Object)null)
			{
				_bladesOfChaos.icon = component.secondary.skillDef.icon;
			}
			if ((Object)(object)_spartanRage != (Object)null)
			{
				_spartanRage.icon = component.utility.skillDef.icon;
			}
			if ((Object)(object)_bladeOfOlympus != (Object)null)
			{
				_bladeOfOlympus.icon = component.special.skillDef.icon;
			}
		}
	}
	public static class KratosVisuals
	{
		private const string ResourceName = "KratosMod.merc_chris.png";

		private const string StockTextureName = "texMercDiffuse";

		public static void ApplyChris(GameObject bodyPrefab)
		{
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Expected O, but got Unknown
			Texture2D val = LoadChrisTexture();
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			ModelLocator component = bodyPrefab.GetComponent<ModelLocator>();
			Transform val2 = (((Object)(object)component != (Object)null) ? component.modelTransform : bodyPrefab.transform);
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			Renderer[] componentsInChildren = ((Component)val2).GetComponentsInChildren<Renderer>();
			foreach (Renderer val3 in componentsInChildren)
			{
				Material[] sharedMaterials = val3.sharedMaterials;
				bool flag = false;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					Material val4 = sharedMaterials[j];
					if (!((Object)(object)val4 == (Object)null) && val4.HasProperty("_MainTex"))
					{
						Texture texture = val4.GetTexture("_MainTex");
						if (!((Object)(object)texture == (Object)null) && !(((Object)texture).name != "texMercDiffuse"))
						{
							Material val5 = new Material(val4);
							val5.SetTexture("_MainTex", (Texture)(object)val);
							sharedMaterials[j] = val5;
							flag = true;
						}
					}
				}
				if (flag)
				{
					val3.sharedMaterials = sharedMaterials;
				}
			}
		}

		private static Texture2D LoadChrisTexture()
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			Stream manifestResourceStream = typeof(KratosVisuals).Assembly.GetManifestResourceStream("KratosMod.merc_chris.png");
			if (manifestResourceStream == null)
			{
				Log.Error("Embedded resource 'KratosMod.merc_chris.png' missing — visuals stay stock.");
				return null;
			}
			using MemoryStream memoryStream = new MemoryStream();
			manifestResourceStream.CopyTo(memoryStream);
			byte[] array = memoryStream.ToArray();
			Texture2D val = new Texture2D(2048, 2048, (TextureFormat)4, true, false);
			((Object)val).name = "texMercChrisDiffuse";
			if (!ImageConversion.LoadImage(val, array))
			{
				Log.Error("Failed to decode the painted diffuse atlas — visuals stay stock.");
				return null;
			}
			((Texture)val).wrapMode = (TextureWrapMode)0;
			((Texture)val).filterMode = (FilterMode)1;
			((Texture)val).anisoLevel = 4;
			return val;
		}
	}
	public static class Log
	{
		private static readonly ManualLogSource _source = Logger.CreateLogSource("KratosMod");

		public static void Info(object data)
		{
			_source.LogInfo(data);
		}

		public static void Warn(object data)
		{
			_source.LogWarning(data);
		}

		public static void Error(object data)
		{
			_source.LogError(data);
		}

		public static void Fatal(object data)
		{
			_source.LogFatal(data);
		}
	}
	public class AxeThrowState : FireFMJ
	{
		public override void OnEnter()
		{
			((GenericProjectileBaseState)this).baseDuration = 0.6f;
			((GenericProjectileBaseState)this).damageCoefficient = 6.2f;
			((GenericProjectileBaseState)this).force = 900f;
			((GenericProjectileBaseState)this).minSpread = 0f;
			((GenericProjectileBaseState)this).maxSpread = 0f;
			((GenericProjectileBaseState)this).recoilAmplitude = 0.8f;
			((GenericProjectileBaseState)this).bloom = 0f;
			((GenericProjectileBaseState)this).OnEnter();
		}
	}
	public class BladesOfChaosState : FireShotgun
	{
		public override void OnEnter()
		{
			FireShotgun.damageCoefficient = 1.4f;
			FireShotgun.bulletCount = 8;
			FireShotgun.baseMaxDuration = 0.9f;
			FireShotgun.baseMinDuration = 0.55f;
			FireShotgun.force = 180f;
			FireShotgun.recoilAmplitude = 0.4f;
			FireShotgun.spreadBloomValue = 8f;
			((FireShotgun)this).OnEnter();
		}
	}
	public class SpartanRageState : BaseSkillState
	{
		public static float buffDuration = 8f;

		private float duration = 1.1f;

		public override void OnEnter()
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected O, but got Unknown
			((BaseState)this).OnEnter();
			duration = 1.1f;
			((EntityState)this).characterBody.AddTimedBuff(Buffs.WarCryBuff, buffDuration);
			HealthComponent healthComponent = ((EntityState)this).characterBody.healthComponent;
			if (healthComponent != null)
			{
				healthComponent.HealFraction(0.1f, default(ProcChainMask));
			}
			((EntityState)this).PlayAnimation("Gesture, Additive", "FirePistol, Additive");
			Util.PlaySound("Play_commando_roll", ((EntityState)this).gameObject);
			if (((EntityState)this).isAuthority)
			{
				Chat.SendBroadcastChat((ChatMessageBase)new SimpleChatMessage
				{
					baseToken = "<color=#e63946><style=cIsHealth>OHH CHRISSS!</style></color>"
				});
			}
		}

		public override void FixedUpdate()
		{
			((EntityState)this).FixedUpdate();
			if (((EntityState)this).fixedAge >= duration && ((EntityState)this).isAuthority)
			{
				((EntityState)this).outer.SetNextStateToMain();
			}
		}

		public override void OnExit()
		{
			((EntityState)this).OnExit();
		}

		public override InterruptPriority GetMinimumInterruptPriority()
		{
			return (InterruptPriority)2;
		}
	}
	public class BladeOfOlympusState : FireBarrage
	{
		public override void OnEnter()
		{
			FireBarrage.damageCoefficient = 1.8f;
			FireBarrage.baseBulletCount = 5;
			FireBarrage.baseDurationBetweenShots = 0.16f;
			FireBarrage.force = 450f;
			FireBarrage.bulletRadius = 1.5f;
			FireBarrage.minSpread = -0.5f;
			FireBarrage.maxSpread = 0.5f;
			FireBarrage.recoilAmplitude = 0.5f;
			FireBarrage.spreadBloomValue = 6f;
			((FireBarrage)this).OnEnter();
		}
	}
}