using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
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 System.Text;
using BepInEx;
using BepInEx.Logging;
using EntityStates;
using EntityStates.Seeker;
using IL.EntityStates.Seeker;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Collections.Generic;
using MonoMod.Cil;
using MonoMod.Utils;
using PalmPatcher.Utilities.Extensions;
using R2API.Utils;
using RoR2;
using RoR2.Projectile;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Networking;
using UnityEngine.ResourceManagement.AsyncOperations;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: NetworkCompatibility(/*Could not decode attribute arguments.*/)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("PalmPatcher")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+d6bd2d235992c64aa0b017a965ab1f1ffe7e8631")]
[assembly: AssemblyProduct("PalmPatcher")]
[assembly: AssemblyTitle("PalmPatcher")]
[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]
internal sealed class ParamCollectionAttribute : Attribute
{
}
[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 PalmPatcher
{
internal static class Log
{
private static readonly StringBuilder _sharedStringBuilder;
private static readonly int _cachedCallerPathPrefixLength;
private static ManualLogSource _logSource;
static Log()
{
_sharedStringBuilder = new StringBuilder(256);
_cachedCallerPathPrefixLength = getCallerPathPrefixLength("D:\\Git\\RoR2\\PalmPatcher\\PalmPatcher\\Log.cs");
static int getCallerPathPrefixLength([CallerFilePath] string callerPath = null)
{
int num = callerPath.LastIndexOf("PalmPatcher\\");
if (num >= 0)
{
return num + "PalmPatcher\\".Length;
}
Debug.LogError((object)"[PalmPatcher] Logger failed to determine caller path prefix length");
return 0;
}
}
internal static void Init(ManualLogSource logSource)
{
_logSource = logSource;
}
private static StringBuilder AppendCallerPrefix(this StringBuilder stringBuilder, string callerPath, string callerMemberName, int callerLineNumber)
{
return stringBuilder.Append(callerPath, _cachedCallerPathPrefixLength, callerPath.Length - _cachedCallerPathPrefixLength).Append(':').Append(callerLineNumber)
.Append(" (")
.Append(callerMemberName)
.Append("):");
}
private static StringBuilder buildCallerLogString(string callerPath, string callerMemberName, int callerLineNumber, object data)
{
return _sharedStringBuilder.Clear().AppendCallerPrefix(callerPath, callerMemberName, callerLineNumber).Append(' ')
.Append(data);
}
[Conditional("DEBUG")]
internal static void Debug(object data, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int callerLineNumber = -1)
{
_logSource.LogDebug((object)buildCallerLogString(callerPath, callerMemberName, callerLineNumber, data));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Conditional("DEBUG")]
internal static void Debug_NoCallerPrefix(object data)
{
_logSource.LogDebug(data);
}
internal static void Error(object data, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int callerLineNumber = -1)
{
_logSource.LogError((object)buildCallerLogString(callerPath, callerMemberName, callerLineNumber, data));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void Error_NoCallerPrefix(object data)
{
_logSource.LogError(data);
}
internal static void Fatal(object data, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int callerLineNumber = -1)
{
_logSource.LogFatal((object)buildCallerLogString(callerPath, callerMemberName, callerLineNumber, data));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void Fatal_NoCallerPrefix(object data)
{
_logSource.LogFatal(data);
}
internal static void Info(object data, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int callerLineNumber = -1)
{
_logSource.LogInfo((object)buildCallerLogString(callerPath, callerMemberName, callerLineNumber, data));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void Info_NoCallerPrefix(object data)
{
_logSource.LogInfo(data);
}
internal static void Message(object data, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int callerLineNumber = -1)
{
_logSource.LogMessage((object)buildCallerLogString(callerPath, callerMemberName, callerLineNumber, data));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void Message_NoCallerPrefix(object data)
{
_logSource.LogMessage(data);
}
internal static void Warning(object data, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int callerLineNumber = -1)
{
_logSource.LogWarning((object)buildCallerLogString(callerPath, callerMemberName, callerLineNumber, data));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void Warning_NoCallerPrefix(object data)
{
_logSource.LogWarning(data);
}
internal static void LogType(LogLevel level, object data, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int callerLineNumber = -1)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
if ((level & 0x20) == 0)
{
_logSource.Log(level, (object)buildCallerLogString(callerPath, callerMemberName, callerLineNumber, data));
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void LogType_NoCallerPrefix(LogLevel level, object data)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
if ((level & 0x20) == 0)
{
_logSource.Log(level, data);
}
}
}
public class PalmBlastProjectileInitializer : MonoBehaviour
{
private void Awake()
{
ProjectileController val = default(ProjectileController);
if (((Component)this).TryGetComponent<ProjectileController>(ref val))
{
val.onInitialized += onInitialized;
}
}
private void onInitialized(ProjectileController projectileController)
{
PalmBlastProjectileController val = default(PalmBlastProjectileController);
if (!((Component)this).TryGetComponent<PalmBlastProjectileController>(ref val))
{
return;
}
CharacterBody val2 = (Object.op_Implicit((Object)(object)projectileController.owner) ? projectileController.owner.GetComponent<CharacterBody>() : null);
if (Object.op_Implicit((Object)(object)val2))
{
val.Init(val2);
ProjectileDamage val3 = default(ProjectileDamage);
if (((Component)this).TryGetComponent<ProjectileDamage>(ref val3))
{
val3.damage = val2.damage;
}
}
}
}
[BepInPlugin("Gorakh.PalmPatcher", "PalmPatcher", "1.1.0")]
public class PalmPatcherPlugin : BaseUnityPlugin
{
[CompilerGenerated]
private static class <>O
{
public static Manipulator <0>__BaseFirePalmBlast_FireProjectile;
public static Action<GameObject> <1>__addPalmInitializer;
public static Action<BaseFirePalmBlast> <2>__actualFireProjectile;
}
public const string PluginGUID = "Gorakh.PalmPatcher";
public const string PluginAuthor = "Gorakh";
public const string PluginName = "PalmPatcher";
public const string PluginVersion = "1.1.0";
private static PalmPatcherPlugin _instance;
internal static PalmPatcherPlugin Instance => _instance;
private void Awake()
{
//IL_0041: 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_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Expected O, but got Unknown
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
Stopwatch stopwatch = Stopwatch.StartNew();
SingletonHelper.Assign<PalmPatcherPlugin>(ref _instance, this);
Log.Init(((BaseUnityPlugin)this).Logger);
object obj = <>O.<0>__BaseFirePalmBlast_FireProjectile;
if (obj == null)
{
Manipulator val = BaseFirePalmBlast_FireProjectile;
<>O.<0>__BaseFirePalmBlast_FireProjectile = val;
obj = (object)val;
}
BaseFirePalmBlast.FireProjectile += (Manipulator)obj;
Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC2/Seeker/PalmBlastProjectile.prefab").CallOnSuccess<GameObject>(addPalmInitializer);
Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC2/Seeker/PalmBlastChargedProjectile.prefab").CallOnSuccess<GameObject>(addPalmInitializer);
stopwatch.Stop();
Log.Message_NoCallerPrefix($"Initialized in {stopwatch.Elapsed.TotalMilliseconds:F0}ms");
static void addPalmInitializer(GameObject palmPrefab)
{
if (!Object.op_Implicit((Object)(object)palmPrefab.GetComponent<PalmBlastProjectileInitializer>()))
{
palmPrefab.AddComponent<PalmBlastProjectileInitializer>();
}
}
}
private void OnDestroy()
{
SingletonHelper.Unassign<PalmPatcherPlugin>(ref _instance, this);
}
private static void BaseFirePalmBlast_FireProjectile(ILContext il)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: 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)
ILCursor val = new ILCursor(il);
if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, typeof(NetworkServer), "get_active")
}))
{
Log.Error("Failed to find patch location", "D:\\Git\\RoR2\\PalmPatcher\\PalmPatcher\\PalmPatcherPlugin.cs", "BaseFirePalmBlast_FireProjectile", 63);
return;
}
val.Emit(OpCodes.Ldarg_0);
val.EmitDelegate<Action<BaseFirePalmBlast>>((Action<BaseFirePalmBlast>)actualFireProjectile);
val.Emit(OpCodes.Pop);
val.Emit(OpCodes.Ldc_I4_0);
static void actualFireProjectile(BaseFirePalmBlast self)
{
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: 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_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: 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_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
if (((EntityState)self).isAuthority)
{
GameObject val2 = ((self.charge < 1f) ? self.projectilePrefab : self.chargedProjectilePrefab);
if (Object.op_Implicit((Object)(object)val2))
{
val2.GetComponent<PalmBlastProjectileController>();
}
Ray aimRay = ((BaseState)self).GetAimRay();
TrajectoryAimAssist.ApplyTrajectoryAimAssist(ref aimRay, val2, ((EntityState)self).gameObject, 1f);
ProjectileManager.instance.FireProjectile(new FireProjectileInfo
{
projectilePrefab = val2,
owner = ((EntityState)self).gameObject,
position = ((Ray)(ref aimRay)).origin,
rotation = Util.QuaternionSafeLookRotation(((Ray)(ref aimRay)).direction),
crit = ((BaseState)self).RollCrit()
});
}
}
}
}
}
namespace PalmPatcher.Utilities
{
public static class FileUtils
{
public static FileInfo SearchUpwards(DirectoryInfo startDir, DirectoryInfo endDir, string searchPattern)
{
if (startDir == null)
{
throw new ArgumentNullException("startDir");
}
if (endDir == null)
{
throw new ArgumentNullException("endDir");
}
if (string.IsNullOrEmpty(searchPattern))
{
throw new ArgumentException("'searchPattern' cannot be null or empty.", "searchPattern");
}
if (!startDir.IsChildOf(endDir))
{
return null;
}
for (DirectoryInfo directoryInfo = startDir; directoryInfo != null; directoryInfo = directoryInfo.Parent)
{
FileInfo fileInfo = directoryInfo.EnumerateFiles(searchPattern, SearchOption.TopDirectoryOnly).FirstOrDefault();
if (fileInfo != null)
{
return fileInfo;
}
if (string.Equals(directoryInfo.FullName, endDir.FullName, StringComparison.OrdinalIgnoreCase))
{
break;
}
}
return null;
}
public static FileInfo SearchUpwards(DirectoryInfo startDir, string searchPattern)
{
return SearchUpwards(startDir, startDir.Root, searchPattern);
}
}
}
namespace PalmPatcher.Utilities.Extensions
{
public static class AssetLoadExtensions
{
public static void CallOnSuccess<T>(this AsyncOperationHandle<T> handle, Action<T> onSuccess)
{
handle.Completed += delegate(AsyncOperationHandle<T> handle)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Invalid comparison between Unknown and I4
if ((int)handle.Status == 2)
{
Log.Error("Failed to load asset '" + handle.LocationName + "'", "D:\\Git\\RoR2\\PalmPatcher\\PalmPatcher\\Utilities\\Extensions\\AssetLoadExtensions.cs", "CallOnSuccess", 19);
}
else
{
onSuccess(handle.Result);
}
};
}
}
public static class CollectionExtensions
{
public static void EnsureCapacity<T>(this List<T> list, int capacity)
{
if (list == null)
{
throw new ArgumentNullException("list");
}
if (list.Capacity < capacity)
{
list.Capacity = capacity;
}
}
}
public static class FileExtensions
{
public static bool IsChildOf(this DirectoryInfo dir, DirectoryInfo other)
{
if (dir != null && other != null)
{
return dir.FullName.StartsWith(other.FullName, ignoreCase: true, CultureInfo.InvariantCulture);
}
return false;
}
}
public static class PatchExtensions
{
public static void EmitSkipMethodCall(this ILCursor c, MethodDefinition method = null)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
c.EmitSkipMethodCall(OpCodes.Br, method);
}
public static void EmitSkipMethodCall(this ILCursor c, OpCode branchOpCode, MethodDefinition method = null)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
c.EmitSkipMethodCall(branchOpCode, null, method);
}
public static void EmitSkipMethodCall(this ILCursor c, OpCode branchOpCode, Action<ILCursor> emitSkippedReturnValue, MethodDefinition method = null)
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Invalid comparison between Unknown and I4
//IL_011d: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_014a: Unknown result type (might be due to invalid IL or missing references)
//IL_0164: Unknown result type (might be due to invalid IL or missing references)
//IL_0234: Unknown result type (might be due to invalid IL or missing references)
//IL_0204: Unknown result type (might be due to invalid IL or missing references)
//IL_0212: Unknown result type (might be due to invalid IL or missing references)
//IL_0224: Unknown result type (might be due to invalid IL or missing references)
if (c == null)
{
throw new ArgumentNullException("c");
}
if ((int)((OpCode)(ref branchOpCode)).FlowControl != 0 && (int)((OpCode)(ref branchOpCode)).FlowControl != 3)
{
throw new ArgumentException($"Invalid branch OpCode: {branchOpCode}");
}
if (method == null)
{
MethodReference val = default(MethodReference);
if (!ILPatternMatchingExt.MatchCallOrCallvirt(c.Next, ref val))
{
Log.Error($"Failed to find method call to skip: {((MemberReference)c.Context.Method).FullName} at instruction {c.Next} ({c.Index})", "D:\\Git\\RoR2\\PalmPatcher\\PalmPatcher\\Utilities\\Extensions\\PatchExtensions.cs", "EmitSkipMethodCall", 34);
return;
}
method = Extensions.SafeResolve(val);
if (method == null)
{
Log.Error($"Failed to resolve method '{((MemberReference)val).FullName}': {((MemberReference)c.Context.Method).FullName} at instruction {c.Next} ({c.Index})", "D:\\Git\\RoR2\\PalmPatcher\\PalmPatcher\\Utilities\\Extensions\\PatchExtensions.cs", "EmitSkipMethodCall", 42);
return;
}
}
int num = ((MethodReference)method).Parameters.Count + ((!method.IsStatic) ? 1 : 0);
bool flag = Extensions.Is((MemberReference)(object)((MethodReference)method).ReturnType, (MemberInfo)typeof(void));
ILLabel val2 = c.DefineLabel();
c.Emit(branchOpCode, (object)val2);
int index = c.Index;
c.Index = index + 1;
if (num > 0 || !flag)
{
ILLabel val3 = c.DefineLabel();
c.Emit(OpCodes.Br, (object)val3);
c.MarkLabel(val2);
for (int i = 0; i < num; i++)
{
c.Emit(OpCodes.Pop);
}
if (emitSkippedReturnValue != null)
{
emitSkippedReturnValue(c);
}
else if (!flag)
{
Log.Warning($"Skipped method ({((MemberReference)method).FullName}) is not void, emitting default value: {((MemberReference)c.Context.Method).FullName} at instruction {c.Next} ({c.Index})", "D:\\Git\\RoR2\\PalmPatcher\\PalmPatcher\\Utilities\\Extensions\\PatchExtensions.cs", "EmitSkipMethodCall", 74);
if (((MethodReference)method).ReturnType.IsValueType)
{
VariableDefinition val4 = c.Context.AddVariable(((MethodReference)method).ReturnType);
c.Emit(OpCodes.Ldloca, val4);
c.Emit(OpCodes.Initobj, ((MethodReference)method).ReturnType);
c.Emit(OpCodes.Ldloc, val4);
}
else
{
c.Emit(OpCodes.Ldnull);
}
}
c.MarkLabel(val3);
}
else
{
c.MarkLabel(val2);
}
}
public static bool TryFindParameter(this MethodReference method, Type type, string name, out ParameterDefinition parameter)
{
//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)
if (type == null && string.IsNullOrEmpty(name))
{
Log.Error("Cannot find parameter for method " + ((MemberReference)method).FullName + ": Neither parameter type or name specified", "D:\\Git\\RoR2\\PalmPatcher\\PalmPatcher\\Utilities\\Extensions\\PatchExtensions.cs", "TryFindParameter", 103);
parameter = null;
return false;
}
Enumerator<ParameterDefinition> enumerator = method.Parameters.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
ParameterDefinition current = enumerator.Current;
if ((string.IsNullOrEmpty(name) || ((ParameterReference)current).Name == name) && (type == null || Extensions.Is((MemberReference)(object)((ParameterReference)current).ParameterType, (MemberInfo)type)))
{
parameter = current;
return true;
}
}
}
finally
{
((IDisposable)enumerator).Dispose();
}
parameter = null;
return false;
}
public static bool TryFindParameter(this MethodReference method, string name, out ParameterDefinition parameter)
{
return method.TryFindParameter(null, name, out parameter);
}
public static bool TryFindParameter(this MethodReference method, Type type, out ParameterDefinition parameter)
{
return method.TryFindParameter(type, null, out parameter);
}
public static bool TryFindParameter<T>(this MethodReference method, string name, out ParameterDefinition parameter)
{
return method.TryFindParameter(typeof(T), name, out parameter);
}
public static bool TryFindParameter<T>(this MethodReference method, out ParameterDefinition parameter)
{
return method.TryFindParameter(typeof(T), null, out parameter);
}
public static VariableDefinition AddVariable(this ILContext context, TypeReference variableType)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
VariableDefinition val = new VariableDefinition(variableType);
context.Method.Body.Variables.Add(val);
return val;
}
public static VariableDefinition AddVariable(this ILContext context, Type variableType)
{
return context.AddVariable(context.Import(variableType));
}
public static VariableDefinition AddVariable<T>(this ILContext context)
{
return context.AddVariable(context.Import(typeof(T)));
}
public static void EmitStoreStack(this ILCursor cursor, [ParamCollection] IReadOnlyList<VariableDefinition> variables)
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: 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_006f: Unknown result type (might be due to invalid IL or missing references)
if (cursor == null)
{
throw new ArgumentNullException("cursor");
}
if (variables == null)
{
throw new ArgumentNullException("variables");
}
if (variables.Count != 0)
{
for (int num = variables.Count - 1; num >= 1; num--)
{
cursor.Emit(OpCodes.Stloc, variables[num]);
}
cursor.Emit(OpCodes.Dup);
cursor.Emit(OpCodes.Stloc, variables[0]);
for (int i = 1; i < variables.Count; i++)
{
cursor.Emit(OpCodes.Ldloc, variables[i]);
}
}
}
}
}