Decompiled source of R2API CharacterBody v1.0.0

plugins/R2API.CharacterBody/R2API.CharacterBody.dll

Decompiled 2 months ago
using System;
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.Logging;
using Microsoft.CodeAnalysis;
using R2API.AutoVersionGen;
using R2API.Utils;
using RoR2;

[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("R2API.CharacterBody")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+631a77d7a0ebb37e72586333d9519b46797814f5")]
[assembly: AssemblyProduct("R2API.CharacterBody")]
[assembly: AssemblyTitle("R2API.CharacterBody")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 System.Diagnostics.CodeAnalysis
{
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	internal sealed class MemberNotNullAttribute : Attribute
	{
		public string[] Members { get; }

		public MemberNotNullAttribute(string member)
		{
			Members = new string[1] { member };
		}

		public MemberNotNullAttribute(params string[] members)
		{
			Members = members;
		}
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	internal sealed class MemberNotNullWhenAttribute : Attribute
	{
		public bool ReturnValue { get; }

		public string[] Members { get; }

		public MemberNotNullWhenAttribute(bool returnValue, string member)
		{
			ReturnValue = returnValue;
			Members = new string[1] { member };
		}

		public MemberNotNullWhenAttribute(bool returnValue, params string[] members)
		{
			ReturnValue = returnValue;
			Members = members;
		}
	}
}
namespace R2API
{
	[AutoVersion]
	public static class CharacterBodyAPI
	{
		public enum ModdedBodyFlag
		{

		}

		public const string PluginGUID = "com.bepis.r2api.character_body";

		public const string PluginName = "R2API.CharacterBody";

		private static bool _hooksEnabled;

		public const string PluginVersion = "1.0.0";

		[Obsolete("All submodules are automatically loaded and this property is now unused")]
		public static bool Loaded => true;

		public static int ModdedBodyFlagCount { get; private set; }

		internal static void SetHooks()
		{
			if (!_hooksEnabled)
			{
				_hooksEnabled = true;
			}
		}

		internal static void UnsetHooks()
		{
			if (_hooksEnabled)
			{
				_hooksEnabled = false;
			}
		}

		public static ModdedBodyFlag ReserveBodyFlag()
		{
			SetHooks();
			if (ModdedBodyFlagCount >= 1152)
			{
				throw new IndexOutOfRangeException($"Reached the limit of {1152} ModdedBodyFlags. Please contact R2API developers to increase the limit");
			}
			ModdedBodyFlagCount++;
			return (ModdedBodyFlag)ModdedBodyFlagCount;
		}

		public static void AddModdedBodyFlag(this CharacterBody characterBody, ModdedBodyFlag moddedBodyFlag)
		{
			AddModdedBodyFlagInternal(characterBody, moddedBodyFlag);
		}

		public static bool RemoveModdedBodyFlag(this CharacterBody characterBody, ModdedBodyFlag moddedBodyFlag)
		{
			return RemoveModdedBodyFlagInternal(characterBody, moddedBodyFlag);
		}

		public static bool HasAnyModdedBodyFlag(this CharacterBody characterBody)
		{
			SetHooks();
			byte[] moddedBodyFlags = CharacterBodyInterop.GetModdedBodyFlags(characterBody);
			if (moddedBodyFlags != null)
			{
				return moddedBodyFlags.Length != 0;
			}
			return false;
		}

		public static bool HasModdedBodyFlag(this CharacterBody characterBody, ModdedBodyFlag moddedBodyFlag)
		{
			return HasModdedBodyFlagInternal(characterBody, moddedBodyFlag);
		}

		private static void AddModdedBodyFlagInternal(CharacterBody characterBody, ModdedBodyFlag moddedBodyFlag)
		{
			SetHooks();
			if (CheckRange(characterBody, moddedBodyFlag))
			{
				byte[] moddedBodyFlags = CharacterBodyInterop.GetModdedBodyFlags(characterBody);
				CompressedFlagArrayUtilities.AddImmutable(ref moddedBodyFlags, (int)(moddedBodyFlag - 1));
				CharacterBodyInterop.SetModdedBodyFlags(characterBody, moddedBodyFlags);
			}
		}

		private static bool RemoveModdedBodyFlagInternal(CharacterBody characterBody, ModdedBodyFlag moddedBodyFlag)
		{
			SetHooks();
			if (!CheckRange(characterBody, moddedBodyFlag))
			{
				return false;
			}
			byte[] moddedBodyFlags = CharacterBodyInterop.GetModdedBodyFlags(characterBody);
			bool result = CompressedFlagArrayUtilities.RemoveImmutable(ref moddedBodyFlags, (int)(moddedBodyFlag - 1));
			CharacterBodyInterop.SetModdedBodyFlags(characterBody, moddedBodyFlags);
			return result;
		}

		private static bool HasModdedBodyFlagInternal(CharacterBody characterBody, ModdedBodyFlag moddedBodyFlag)
		{
			SetHooks();
			if (!CheckRange(characterBody, moddedBodyFlag))
			{
				return false;
			}
			return CompressedFlagArrayUtilities.Has(CharacterBodyInterop.GetModdedBodyFlags(characterBody), (int)(moddedBodyFlag - 1));
		}

		private static bool CheckRange(CharacterBody characterBody, ModdedBodyFlag moddedBodyFlag)
		{
			if ((int)moddedBodyFlag > ModdedBodyFlagCount || moddedBodyFlag < (ModdedBodyFlag)1)
			{
				CharacterBodyPlugin.Logger.LogError((object)string.Format("Parameter '{0}' with value {1} is out of range of registered types (1-{2})\n{3}", "moddedBodyFlag", moddedBodyFlag, ModdedBodyFlagCount, new StackTrace(fNeedFileInfo: true)));
				return false;
			}
			return true;
		}
	}
	[BepInPlugin("com.bepis.r2api.character_body", "R2API.CharacterBody", "1.0.0")]
	public sealed class CharacterBodyPlugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			CharacterBodyAPI.SetHooks();
		}

		private void OnDestroy()
		{
			CharacterBodyAPI.UnsetHooks();
		}
	}
}
namespace R2API.AutoVersionGen
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	internal class AutoVersionAttribute : Attribute
	{
	}
}

plugins/R2API.CharacterBody/R2API.CharacterBody.Interop.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Microsoft.CodeAnalysis;
using RoR2;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: InternalsVisibleTo("R2API.CharacterBody")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("R2API.CharacterBody.Interop")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+631a77d7a0ebb37e72586333d9519b46797814f5")]
[assembly: AssemblyProduct("R2API.CharacterBody.Interop")]
[assembly: AssemblyTitle("R2API.CharacterBody.Interop")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 R2API
{
	internal static class CharacterBodyInterop
	{
		public static byte[] GetModdedBodyFlags(CharacterBody characterBody)
		{
			return characterBody.r2api_moddedBodyFlags;
		}

		public static void SetModdedBodyFlags(CharacterBody characterBody, byte[] value)
		{
			characterBody.r2api_moddedBodyFlags = value;
		}
	}
}

patchers/R2API.CharacterBody/R2API.CharacterBody.Patcher.dll

Decompiled 2 months ago
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 Microsoft.CodeAnalysis;
using Mono.Cecil;

[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("R2API.CharacterBody.Patcher")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+631a77d7a0ebb37e72586333d9519b46797814f5")]
[assembly: AssemblyProduct("R2API.CharacterBody.Patcher")]
[assembly: AssemblyTitle("R2API.CharacterBody.Patcher")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 R2API
{
	internal static class CharacterBodyPatcher
	{
		public static IEnumerable<string> TargetDLLs
		{
			get
			{
				yield return "RoR2.dll";
			}
		}

		public static void Patch(AssemblyDefinition assembly)
		{
			PatchCharacterBody(assembly);
		}

		private static void PatchCharacterBody(AssemblyDefinition assembly)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			TypeDefinition type = assembly.MainModule.GetType("RoR2", "CharacterBody");
			FieldDefinition val = new FieldDefinition("r2api_moddedBodyFlags", (FieldAttributes)6, assembly.MainModule.ImportReference(typeof(byte[])));
			if (type != null)
			{
				type.Fields.Add(val);
			}
		}
	}
}