using System;
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 IL.RoR2;
using IL.RoR2.Items;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On.RoR2;
using RoR2;
using RoR2.CharacterAI;
using RoR2.Items;
using RoR2BepInExPack.Utilities;
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("LordsItemEdits")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+63a795c3ff5a06146841ddfcffda9c8251e1babf")]
[assembly: AssemblyProduct("LordsItemEdits")]
[assembly: AssemblyTitle("LordsItemEdits")]
[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 LordsItemEdits
{
internal static class AssetEdits
{
internal static void DoEdits()
{
if (ConfigOptions.EnableVoidDiosEdit.Value)
{
BlacklistVoidDiosFromEngiTurrets();
GiveReaverAllyBodyInteractionDistance();
GiveJailerAllyBodyInteractionDistance();
GiveDevastatorAllyBodyInteractionDistance();
}
}
private static void BlacklistVoidDiosFromEngiTurrets()
{
//IL_0005: 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)
ItemDef obj = Addressables.LoadAssetAsync<ItemDef>((object)"RoR2/DLC1/ExtraLifeVoid/ExtraLifeVoid.asset").WaitForCompletion();
ItemTag[] tags = obj.tags;
int num = 0;
ItemTag[] array = (ItemTag[])(object)new ItemTag[1 + tags.Length];
ReadOnlySpan<ItemTag> readOnlySpan = new ReadOnlySpan<ItemTag>(tags);
readOnlySpan.CopyTo(new Span<ItemTag>(array).Slice(num, readOnlySpan.Length));
num += readOnlySpan.Length;
array[num] = (ItemTag)13;
obj.tags = array;
}
private static void GiveReaverAllyBodyInteractionDistance()
{
//IL_0005: 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)
Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Nullifier/NullifierAllyBody.prefab").WaitForCompletion().GetComponent<Interactor>()
.maxInteractionDistance = 9f;
}
private static void GiveJailerAllyBodyInteractionDistance()
{
//IL_0005: 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)
Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC1/VoidJailer/VoidJailerAllyBody.prefab").WaitForCompletion().GetComponent<Interactor>()
.maxInteractionDistance = 12f;
}
private static void GiveDevastatorAllyBodyInteractionDistance()
{
//IL_0005: 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)
Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC1/VoidMegaCrab/VoidMegaCrabAllyBody.prefab").WaitForCompletion().GetComponent<Interactor>()
.maxInteractionDistance = 15f;
}
}
public static class ConfigOptions
{
public static ConfigEntry<bool> EnableVoidDiosEdit;
public static ConfigEntry<bool> AllowRespawnAsVoidReaver;
internal static void BindConfigOptions(ConfigFile config)
{
EnableVoidDiosEdit = config.Bind<bool>("Pluripotent Larva", "Enable edit", true, "Enable the Pluripotent Larva edit?");
AllowRespawnAsVoidReaver = config.Bind<bool>("Pluripotent Larva", "Allow respawning as a Void Reaver", false, "Should the Void Reaver be an option to respawn as with the edited Pluripotent Larva? This is configurable since their only attack has bad damage and can't target flying enemies.");
}
}
internal static class ItemEdits
{
private class VoidDios
{
private class LieVoidDiosInfo
{
internal GameObject OriginalBodyPrefab;
}
[CompilerGenerated]
private static class <>O
{
public static Manipulator <0>__ExtraLifeVoidManager_Init;
public static Manipulator <1>__CharacterMaster_RespawnExtraLifeVoid;
public static hook_Start <2>__CharacterBody_Start;
}
private static GameObject _reaverAllyMasterPrefab;
private static GameObject _jailerAllyMasterPrefab;
private static GameObject _devastatorAllyMasterPrefab;
private static readonly FixedConditionalWeakTable<CharacterMaster, LieVoidDiosInfo> _lieVoidDiosTable = new FixedConditionalWeakTable<CharacterMaster, LieVoidDiosInfo>();
internal static void Setup()
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Expected O, but got Unknown
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Expected O, but got Unknown
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Expected O, but got Unknown
if (ConfigOptions.EnableVoidDiosEdit.Value)
{
GetVoidAllyMasterAssets();
object obj = <>O.<0>__ExtraLifeVoidManager_Init;
if (obj == null)
{
Manipulator val = ExtraLifeVoidManager_Init;
<>O.<0>__ExtraLifeVoidManager_Init = val;
obj = (object)val;
}
ExtraLifeVoidManager.Init += (Manipulator)obj;
object obj2 = <>O.<1>__CharacterMaster_RespawnExtraLifeVoid;
if (obj2 == null)
{
Manipulator val2 = CharacterMaster_RespawnExtraLifeVoid;
<>O.<1>__CharacterMaster_RespawnExtraLifeVoid = val2;
obj2 = (object)val2;
}
CharacterMaster.RespawnExtraLifeVoid += (Manipulator)obj2;
object obj3 = <>O.<2>__CharacterBody_Start;
if (obj3 == null)
{
hook_Start val3 = CharacterBody_Start;
<>O.<2>__CharacterBody_Start = val3;
obj3 = (object)val3;
}
CharacterBody.Start += (hook_Start)obj3;
}
}
private static void GetVoidAllyMasterAssets()
{
//IL_0005: 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_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_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
_reaverAllyMasterPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Nullifier/NullifierAllyMaster.prefab").WaitForCompletion();
_jailerAllyMasterPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC1/VoidJailer/VoidJailerAllyMaster.prefab").WaitForCompletion();
_devastatorAllyMasterPrefab = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC1/VoidMegaCrab/VoidMegaCrabAllyMaster.prefab").WaitForCompletion();
}
private static void ExtraLifeVoidManager_Init(ILContext il)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
ILCursor val = new ILCursor(il);
if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchStsfld(x, "RoR2.Items.ExtraLifeVoidManager", "voidBodyNames")
}))
{
LogILError(il, val);
return;
}
val.EmitDelegate<Action>((Action)delegate
{
if (ConfigOptions.AllowRespawnAsVoidReaver.Value)
{
ExtraLifeVoidManager.voidBodyNames = new string[3] { "NullifierAllyBody", "VoidJailerAllyBody", "VoidMegaCrabAllyBody" };
}
else
{
ExtraLifeVoidManager.voidBodyNames = new string[2] { "VoidJailerAllyBody", "VoidMegaCrabAllyBody" };
}
});
}
private static void CharacterMaster_RespawnExtraLifeVoid(ILContext il)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
//IL_0085: 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)
ILCursor val = new ILCursor(il);
if (!val.TryGotoNext((MoveType)1, new Func<Instruction, bool>[3]
{
(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, 0),
(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 0f)
}))
{
LogILError(il, val);
return;
}
val.Emit(OpCodes.Ldarg_0);
val.EmitDelegate<Action<CharacterMaster>>((Action<CharacterMaster>)delegate(CharacterMaster characterMaster)
{
LieVoidDiosInfo lieVoidDiosInfo = default(LieVoidDiosInfo);
if (!_lieVoidDiosTable.TryGetValue(characterMaster, ref lieVoidDiosInfo))
{
_lieVoidDiosTable.Add(characterMaster, new LieVoidDiosInfo
{
OriginalBodyPrefab = characterMaster.bodyPrefab
});
}
BaseAI component = ((Component)characterMaster).GetComponent<BaseAI>();
GameObject nextBodyPrefab = ExtraLifeVoidManager.GetNextBodyPrefab();
GameObject voidAllyMasterPrefabFromBodyPrefab = GetVoidAllyMasterPrefabFromBodyPrefab(nextBodyPrefab);
characterMaster.bodyPrefab = nextBodyPrefab;
if ((Object)(object)component != (Object)null && (Object)(object)voidAllyMasterPrefabFromBodyPrefab != (Object)null)
{
ReplaceAISkillDrivers(characterMaster, component, voidAllyMasterPrefabFromBodyPrefab);
}
});
ILLabel val2 = val.DefineLabel();
MethodReference val3 = default(MethodReference);
if (!val.TryGotoNext((MoveType)1, new Func<Instruction, bool>[3]
{
(Instruction x) => ILPatternMatchingExt.MatchLdloca(x, 4),
(Instruction x) => ILPatternMatchingExt.MatchCall(x, ref val3),
(Instruction x) => ILPatternMatchingExt.MatchStloc(x, 5)
}))
{
LogILError(il, val);
return;
}
val.Emit(OpCodes.Br, (object)val2);
if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[2]
{
(Instruction x) => ILPatternMatchingExt.MatchCallvirt<IDisposable>(x, "Dispose"),
(Instruction x) => ILPatternMatchingExt.MatchEndfinally(x)
}))
{
LogILError(il, val);
}
else
{
val.MarkLabel(val2);
}
}
private static void CharacterBody_Start(orig_Start orig, CharacterBody self)
{
LieVoidDiosInfo lieVoidDiosInfo = default(LieVoidDiosInfo);
if ((Object)(object)self != (Object)null && (Object)(object)self.master != (Object)null && _lieVoidDiosTable.TryGetValue(self.master, ref lieVoidDiosInfo))
{
self.master.bodyPrefab = lieVoidDiosInfo.OriginalBodyPrefab;
_lieVoidDiosTable.Remove(self.master);
}
orig.Invoke(self);
}
private static GameObject GetVoidAllyMasterPrefabFromBodyPrefab(GameObject voidAllyBodyPrefab)
{
switch (((Object)voidAllyBodyPrefab).name)
{
case "NullifierAllyBody":
return _reaverAllyMasterPrefab;
case "VoidJailerAllyBody":
return _jailerAllyMasterPrefab;
case "VoidMegaCrabAllyBody":
return _devastatorAllyMasterPrefab;
default:
Log.Error("Could not get master prefab for void ally body! This really shouldn't happen ever!");
return null;
}
}
private static void ReplaceAISkillDrivers(CharacterMaster characterMaster, BaseAI baseAI, GameObject newCharacterMasterPrefab)
{
//IL_0078: 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_0086: 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_0120: Unknown result type (might be due to invalid IL or missing references)
//IL_0125: Unknown result type (might be due to invalid IL or missing references)
//IL_012e: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
//IL_01db: Unknown result type (might be due to invalid IL or missing references)
//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
//IL_0247: Unknown result type (might be due to invalid IL or missing references)
//IL_024c: Unknown result type (might be due to invalid IL or missing references)
//IL_0253: Unknown result type (might be due to invalid IL or missing references)
//IL_0258: Unknown result type (might be due to invalid IL or missing references)
AISkillDriver[] components = ((Component)characterMaster).GetComponents<AISkillDriver>();
for (int i = 0; i < components.Length; i++)
{
Object.Destroy((Object)(object)components[i]);
}
AISkillDriver[] components2 = newCharacterMasterPrefab.GetComponents<AISkillDriver>();
List<AISkillDriver> list = new List<AISkillDriver>();
components = components2;
foreach (AISkillDriver val in components)
{
AISkillDriver val2 = ((Component)characterMaster).gameObject.AddComponent<AISkillDriver>();
val2.activationRequiresAimConfirmation = val.activationRequiresAimConfirmation;
val2.activationRequiresAimTargetLoS = val.activationRequiresAimTargetLoS;
val2.activationRequiresTargetLoS = val.activationRequiresTargetLoS;
val2.aimType = val.aimType;
val2.buttonPressType = val.buttonPressType;
val2.customName = val.customName;
val2.driverUpdateTimerOverride = val.driverUpdateTimerOverride;
val2.ignoreNodeGraph = val.ignoreNodeGraph;
val2.maxDistance = val.maxDistance;
val2.maxTargetHealthFraction = val.maxTargetHealthFraction;
val2.maxUserHealthFraction = val.maxUserHealthFraction;
val2.minDistance = val.minDistance;
val2.minTargetHealthFraction = val.minTargetHealthFraction;
val2.minUserHealthFraction = val.minUserHealthFraction;
val2.moveInputScale = val.moveInputScale;
val2.movementType = val.movementType;
val2.moveTargetType = val.moveTargetType;
val2.nextHighPriorityOverride = val.nextHighPriorityOverride;
val2.noRepeat = val.noRepeat;
val2.requiredSkill = val.requiredSkill;
val2.requireEquipmentReady = val.requireEquipmentReady;
val2.requireSkillReady = val.requireSkillReady;
val2.resetCurrentEnemyOnNextDriverSelection = val.resetCurrentEnemyOnNextDriverSelection;
val2.selectionRequiresAimTarget = val.selectionRequiresAimTarget;
val2.selectionRequiresOnGround = val.selectionRequiresOnGround;
val2.selectionRequiresTargetLoS = val.selectionRequiresTargetLoS;
val2.shouldFireEquipment = val.shouldFireEquipment;
val2.shouldSprint = val.shouldSprint;
val2.buttonPressType = val.buttonPressType;
val2.skillSlot = val.skillSlot;
((Object)val2).name = ((Object)val).name + "(Clone)";
list.Add(val2);
}
AISkillDriver[] skillDrivers = list.ToArray();
baseAI.skillDrivers = skillDrivers;
EntityStateMachine component = ((Component)characterMaster).GetComponent<EntityStateMachine>();
EntityStateMachine component2 = newCharacterMasterPrefab.GetComponent<EntityStateMachine>();
component.customName = component2.customName;
component.initialStateType = component2.initialStateType;
component.mainStateType = component2.mainStateType;
component.nextState = component2.nextState;
}
}
internal static void DoEdits()
{
VoidDios.Setup();
}
private static void LogILError(ILContext il, ILCursor c)
{
Log.Error("COULD NOT IL HOOK " + ((MemberReference)il.Method).Name);
Log.Warning($"cursor is {c}");
Log.Warning($"il is {il}");
}
}
internal static class Log
{
private static ManualLogSource _logSource;
internal static void Init(ManualLogSource logSource)
{
_logSource = logSource;
}
internal static void Debug(object 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("LordVGames.LordsItemEdits", "LordsItemEdits", "0.1.0")]
public class Plugin : BaseUnityPlugin
{
public const string PluginGUID = "LordVGames.LordsItemEdits";
public const string PluginAuthor = "LordVGames";
public const string PluginName = "LordsItemEdits";
public const string PluginVersion = "0.1.0";
public static PluginInfo PluginInfo { get; private set; }
public void Awake()
{
PluginInfo = ((BaseUnityPlugin)this).Info;
Log.Init(((BaseUnityPlugin)this).Logger);
ConfigOptions.BindConfigOptions(((BaseUnityPlugin)this).Config);
AssetEdits.DoEdits();
ItemEdits.DoEdits();
}
}
}