Decompiled source of Ebony and Ivory v1.2.1

Ebony_and_Ivory.dll

Decompiled 2 months ago
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using OtherLoader;
using UnityEngine;

[assembly: Debuggable(DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
namespace MeatKit
{
	public class HideInNormalInspectorAttribute : PropertyAttribute
	{
	}
}
namespace MeHongo.Ebony_and_Ivory
{
	[BepInPlugin("MeHongo.Ebony_and_Ivory", "Ebony_and_Ivory", "1.2.1")]
	[BepInProcess("h3vr.exe")]
	[Description("Built with MeatKit")]
	[BepInDependency("h3vr.otherloader", "1.3.0")]
	public class Ebony_and_IvoryPlugin : BaseUnityPlugin
	{
		private static readonly string BasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

		internal static ManualLogSource Logger;

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

		private void LoadAssets()
		{
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "MeHongo.Ebony_and_Ivory");
			OtherLoader.RegisterDirectLoad(BasePath, "MeHongo.Ebony_and_Ivory", "", "", "ebonygun", "");
		}
	}
}

EbonyScript.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using FistVR;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("EbonyScript")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("EbonyScript")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
public class EbonyRoundPenetration : Handgun
{
}
public class BallisticProjectileEbony : MonoBehaviour
{
}
namespace mehongo;

[BepInPlugin("h3vr.mehongo.EbonyScript", "Ebony Script", "1.0.0")]
public class EbonyPenSetup : BaseUnityPlugin
{
	public struct EbonyPenStruct
	{
		public float storedFrontArea;

		public float storedMass;

		public GameObject storedBallisticPrefab;
	}

	public Handgun ebony;

	internal static EbonyPenSetup Instance { get; private set; }

	public void Awake()
	{
		Instance = this;
		Harmony.CreateAndPatchAll(((object)this).GetType(), "MeHongo-EbonyScript");
	}

	[HarmonyPatch(typeof(Handgun), "Fire")]
	[HarmonyPrefix]
	public static void prefixEbony(Handgun __instance, ref EbonyPenStruct __state)
	{
		if (__instance is EbonyRoundPenetration && __instance.Chamber.IsFull && (Object)(object)__instance.Chamber.GetRound() != (Object)null && !__instance.Chamber.IsSpent)
		{
			GameObject val = (__state.storedBallisticPrefab = __instance.Chamber.GetRound().BallisticProjectilePrefab);
			__state.storedFrontArea = val.GetComponent<BallisticProjectile>().FrontArea;
			__state.storedMass = val.GetComponent<BallisticProjectile>().Mass;
			val.GetComponent<BallisticProjectile>().FrontArea = 1E-05f;
			val.GetComponent<BallisticProjectile>().Mass = 0.1f;
			val.AddComponent<BallisticProjectileEbony>();
		}
	}

	[HarmonyPatch(typeof(Handgun), "Fire")]
	[HarmonyPostfix]
	public static void postfixEbony(Handgun __instance, ref EbonyPenStruct __state)
	{
		if (__instance is EbonyRoundPenetration && (Object)(object)__state.storedBallisticPrefab != (Object)null)
		{
			GameObject storedBallisticPrefab = __state.storedBallisticPrefab;
			storedBallisticPrefab.GetComponent<BallisticProjectile>().FrontArea = __state.storedFrontArea;
			storedBallisticPrefab.GetComponent<BallisticProjectile>().Mass = __state.storedMass;
			if (storedBallisticPrefab.TryGetComponent<BallisticProjectileEbony>(out BallisticProjectileEbony result))
			{
				Object.Destroy((Object)(object)result);
			}
		}
	}

	[HarmonyPatch(typeof(BallisticProjectile), "MoveBullet")]
	[HarmonyTranspiler]
	public static IEnumerable<CodeInstruction> EbonyBallisticProjectilePen(IEnumerable<CodeInstruction> instructions, ILGenerator generator, MethodBase __originalMethod)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Expected O, but got Unknown
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Expected O, but got Unknown
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Expected O, but got Unknown
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Expected O, but got Unknown
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Expected O, but got Unknown
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Expected O, but got Unknown
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Expected O, but got Unknown
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Expected O, but got Unknown
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Expected O, but got Unknown
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0164: Expected O, but got Unknown
		//IL_016c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0172: Expected O, but got Unknown
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0185: Expected O, but got Unknown
		//IL_018d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0193: Expected O, but got Unknown
		//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b4: Expected O, but got Unknown
		//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: Expected O, but got Unknown
		//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e6: Expected O, but got Unknown
		//IL_0202: Unknown result type (might be due to invalid IL or missing references)
		//IL_0208: Expected O, but got Unknown
		//IL_0226: Unknown result type (might be due to invalid IL or missing references)
		//IL_022c: Expected O, but got Unknown
		//IL_023e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0244: Expected O, but got Unknown
		//IL_0281: Unknown result type (might be due to invalid IL or missing references)
		//IL_0287: Expected O, but got Unknown
		//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ab: Expected O, but got Unknown
		//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c0: Expected O, but got Unknown
		//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d4: Expected O, but got Unknown
		CodeMatcher val = new CodeMatcher(instructions, generator);
		Label label = (Label)val.MatchForward(true, (CodeMatch[])(object)new CodeMatch[5]
		{
			new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(Vector3), "Lerp", (Type[])null, (Type[])null), (string)null),
			new CodeMatch((OpCode?)OpCodes.Stloc_S, (object)null, (string)null),
			new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null),
			new CodeMatch((OpCode?)OpCodes.Stloc_S, (object)null, (string)null),
			new CodeMatch((OpCode?)OpCodes.Br, (object)null, (string)null)
		}).Instruction.operand;
		List<Label> list = CodeInstructionExtensions.ExtractLabels(val.Advance(1).Instruction);
		Label label2 = default(Label);
		val.CreateLabel(ref label2);
		LocalBuilder localBuilder = generator.DeclareLocal(typeof(BallisticProjectileEbony));
		if (!val.ReportFailure(__originalMethod, (Action<string>)((BaseUnityPlugin)Instance).Logger.LogFatal))
		{
			val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[17]
			{
				CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Ldarg_0, (object)null), (IEnumerable<Label>)list),
				new CodeInstruction(OpCodes.Ldloca_S, (object)localBuilder.LocalIndex),
				new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(OnlyForTryGetComponent), "TryGetComponent", (Type[])null, new Type[1] { typeof(BallisticProjectileEbony) })),
				new CodeInstruction(OpCodes.Ldc_I4_1, (object)null),
				new CodeInstruction(OpCodes.Ceq, (object)null),
				new CodeInstruction(OpCodes.Brfalse_S, (object)label2),
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldflda, (object)AccessTools.Field(typeof(BallisticProjectile), "m_hit")),
				new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(RaycastHit), "get_point", (Type[])null, (Type[])null)),
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldflda, (object)AccessTools.Field(typeof(BallisticProjectile), "m_hit")),
				new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(RaycastHit), "get_normal", (Type[])null, (Type[])null)),
				new CodeInstruction(OpCodes.Ldc_R4, (object)0.001f),
				new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Vector3), "op_Multiply", new Type[2]
				{
					typeof(Vector3),
					typeof(float)
				}, (Type[])null)),
				new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Vector3), "op_Subtraction", (Type[])null, (Type[])null)),
				new CodeInstruction(OpCodes.Stloc_S, (object)39),
				new CodeInstruction(OpCodes.Br, (object)label)
			});
		}
		return val.InstructionEnumeration();
	}
}
public static class OnlyForTryGetComponent
{
	public static bool TryGetComponent<T>(this Component component, out T result) where T : Component
	{
		result = component.GetComponent<T>();
		return (Object)(object)result != (Object)null;
	}
}
public static class TryGetComponentFromGameObject
{
	public static bool TryGetComponent<T>(this GameObject gameobject, out T result) where T : Component
	{
		result = gameobject.GetComponent<T>();
		return (Object)(object)result != (Object)null;
	}
}