Decompiled source of SuperKickGB v1.1.0

Mods/SuperKickGB.dll

Decompiled 3 weeks ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using HarmonyLib;
using Il2Cpp;
using Il2CppFemur;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using MelonLoader;
using MelonLoader.Preferences;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using SuperKickGB;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(global::SuperKickGB.SuperKickGB), "SuperKickGB", "1.0.0", "Zooks", null)]
[assembly: MelonGame("Boneloaf", "Gang Beasts")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("SuperKickGB")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Super Kick Mod for GB")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SuperKickGB")]
[assembly: AssemblyTitle("SuperKickGB")]
[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 SuperKickGB
{
	public class SuperKickGB : MelonMod
	{
		public static MelonPreferences_Category? ConfigCategory;

		public static MelonPreferences_Entry<float>? NpcLaunchVelocity;

		public static MelonPreferences_Entry<bool>? EnableMod;

		public static AudioClip? KickAudioClip;

		public static GameObject? SoundPlayerObj;

		public static AudioSource? SoundPlayerSource;

		public override void OnInitializeMelon()
		{
			ConfigCategory = MelonPreferences.CreateCategory("SuperKickGBConfig", "Super Kick GB Configuration");
			NpcLaunchVelocity = ConfigCategory.CreateEntry<float>("NpcLaunchVelocity", 50f, "NPC Flight Velocity on Hit", (string)null, false, false, (ValueValidator)null, (string)null);
			EnableMod = ConfigCategory.CreateEntry<bool>("EnableMod", true, "Enable Mod", (string)null, false, false, (ValueValidator)null, (string)null);
			try
			{
				KickAudioClip = WavLoader.LoadWav(Path.Combine(MelonEnvironment.UserDataDirectory, "kick.wav"));
				if ((Object)(object)KickAudioClip != (Object)null)
				{
					((MelonBase)this).LoggerInstance.Msg("Loaded kick.wav successfully.");
				}
			}
			catch (Exception)
			{
			}
			((MelonBase)this).LoggerInstance.Msg("SuperKickGB loaded.");
		}

		public static void PlayKickSound()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			if (!((Object)(object)KickAudioClip == (Object)null))
			{
				if ((Object)(object)SoundPlayerObj == (Object)null)
				{
					SoundPlayerObj = new GameObject("SuperKickGBSoundPlayer");
					Object.DontDestroyOnLoad((Object)(object)SoundPlayerObj);
					SoundPlayerSource = SoundPlayerObj.AddComponent<AudioSource>();
				}
				if ((Object)(object)SoundPlayerSource != (Object)null)
				{
					SoundPlayerSource.volume = 1f;
					SoundPlayerSource.spatialBlend = 0f;
					SoundPlayerSource.PlayOneShot(KickAudioClip);
				}
			}
		}
	}
	public static class WavLoader
	{
		public static AudioClip? LoadWav(string filePath)
		{
			if (!File.Exists(filePath))
			{
				return null;
			}
			byte[] array = File.ReadAllBytes(filePath);
			ushort num = BitConverter.ToUInt16(array, 22);
			uint num2 = BitConverter.ToUInt32(array, 24);
			ushort num3 = BitConverter.ToUInt16(array, 34);
			int num4 = 44;
			for (int i = 36; i < array.Length - 4; i++)
			{
				if (array[i] == 100 && array[i + 1] == 97 && array[i + 2] == 116 && array[i + 3] == 97)
				{
					num4 = i + 8;
					break;
				}
			}
			int num5 = array.Length - num4;
			int num6 = num3 / 8;
			int num7 = num5 / num6;
			float[] array2 = new float[num7];
			switch (num3)
			{
			case 16:
			{
				for (int k = 0; k < num7; k++)
				{
					int num9 = num4 + k * 2;
					if (num9 + 1 < array.Length)
					{
						short num10 = BitConverter.ToInt16(array, num9);
						array2[k] = (float)num10 / 32768f;
					}
				}
				break;
			}
			case 8:
			{
				for (int l = 0; l < num7; l++)
				{
					int num11 = num4 + l;
					if (num11 < array.Length)
					{
						array2[l] = (float)(array[num11] - 128) / 128f;
					}
				}
				break;
			}
			case 32:
			{
				for (int j = 0; j < num7; j++)
				{
					int num8 = num4 + j * 4;
					if (num8 + 3 < array.Length)
					{
						array2[j] = BitConverter.ToSingle(array, num8);
					}
				}
				break;
			}
			default:
				return null;
			}
			AudioClip obj = AudioClip.Create("kick", num7 / num, (int)num, (int)num2, false);
			obj.SetData(Il2CppStructArray<float>.op_Implicit(array2), 0);
			return obj;
		}
	}
	[HarmonyPatch(typeof(CollisionHandeler), "OnCollisionEnter")]
	public static class CollisionHandeler_OnCollisionEnter_Patch
	{
		private static float _lastHitTime;

		private static Rigidbody? GetHipsRigidbody(Actor actor)
		{
			if ((Object)(object)actor == (Object)null || (Object)(object)actor.bodyHandeler == (Object)null)
			{
				return null;
			}
			Il2CppReferenceArray<Rigidbody> allRigidbodies = actor.bodyHandeler.GetAllRigidbodies();
			if (allRigidbodies != null && ((Il2CppArrayBase<Rigidbody>)(object)allRigidbodies).Length > 0)
			{
				for (int i = 0; i < ((Il2CppArrayBase<Rigidbody>)(object)allRigidbodies).Length; i++)
				{
					Rigidbody val = ((Il2CppArrayBase<Rigidbody>)(object)allRigidbodies)[i];
					if ((Object)(object)val != (Object)null && (Object)(object)((Component)val).gameObject != (Object)null && ((Object)((Component)val).gameObject).name.ToLower().Contains("hips"))
					{
						return val;
					}
				}
				return ((Il2CppArrayBase<Rigidbody>)(object)allRigidbodies)[0];
			}
			return null;
		}

		private static Vector3 GetPhysicalPosition(Actor actor)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			Rigidbody hipsRigidbody = GetHipsRigidbody(actor);
			if ((Object)(object)hipsRigidbody != (Object)null)
			{
				return ((Component)hipsRigidbody).transform.position;
			}
			return ((Component)actor).transform.position;
		}

		[HarmonyPostfix]
		public static void Postfix(CollisionHandeler __instance, Collision collision)
		{
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (SuperKickGB.EnableMod == null || !SuperKickGB.EnableMod.Value || (Object)(object)__instance == (Object)null || (Object)(object)__instance.actor == (Object)null || (Object)(object)((Component)__instance).gameObject == (Object)null)
				{
					return;
				}
				string text = ((Object)((Component)__instance).gameObject).name.ToLower();
				if ((!text.Contains("foot") && !text.Contains("leg") && !text.Contains("hips") && !text.Contains("butt") && !text.Contains("shin") && !text.Contains("calf")) || !__instance.actor.IsLocal || Time.time - _lastHitTime < 0.3f)
				{
					return;
				}
				ControlHandeler controlHandeler = __instance.actor.controlHandeler;
				if (controlHandeler == null)
				{
					return;
				}
				bool flag = controlHandeler.leftKick || controlHandeler.rightKick || controlHandeler.kickDuck;
				ControlHandeler_Human val = ((Il2CppObjectBase)controlHandeler).TryCast<ControlHandeler_Human>();
				if (val != null)
				{
					flag = flag || val.leftKickTimer > 0f || val.rightKickTimer > 0f;
				}
				if (!flag || collision == null || (Object)(object)collision.gameObject == (Object)null)
				{
					return;
				}
				Actor val2 = null;
				InteractableObject componentInParent = collision.gameObject.GetComponentInParent<InteractableObject>();
				val2 = ((!((Object)(object)componentInParent != (Object)null)) ? collision.gameObject.GetComponentInParent<Actor>() : componentInParent.actor);
				if ((Object)(object)val2 == (Object)null || (Object)(object)val2 == (Object)(object)__instance.actor)
				{
					return;
				}
				_lastHitTime = Time.time;
				Vector3 physicalPosition = GetPhysicalPosition(val2);
				Vector3 physicalPosition2 = GetPhysicalPosition(__instance.actor);
				Vector3 val3 = physicalPosition - physicalPosition2;
				Vector3 normalized = ((Vector3)(ref val3)).normalized;
				if ((Object)(object)val2.statusHandeler != (Object)null)
				{
					try
					{
						Damage val4 = (Damage)0;
						val2.statusHandeler.AddDamage(val4, 1000f, ((Component)__instance.actor).gameObject);
						val2.statusHandeler.stamina = 0f;
						val2.statusHandeler.unconsciousTime = 5f;
					}
					catch (Exception)
					{
					}
				}
				if ((Object)(object)val2.bodyHandeler != (Object)null)
				{
					Il2CppReferenceArray<Rigidbody> allRigidbodies = val2.bodyHandeler.GetAllRigidbodies();
					if (allRigidbodies != null && ((Il2CppArrayBase<Rigidbody>)(object)allRigidbodies).Length > 0)
					{
						val3 = normalized + Vector3.up * 0.15f;
						Vector3 normalized2 = ((Vector3)(ref val3)).normalized;
						float num = ((SuperKickGB.NpcLaunchVelocity != null) ? SuperKickGB.NpcLaunchVelocity.Value : 50f);
						for (int i = 0; i < ((Il2CppArrayBase<Rigidbody>)(object)allRigidbodies).Length; i++)
						{
							Rigidbody val5 = ((Il2CppArrayBase<Rigidbody>)(object)allRigidbodies)[i];
							if ((Object)(object)val5 != (Object)null)
							{
								val5.velocity += normalized2 * num;
							}
						}
					}
				}
				if ((Object)(object)__instance.actor.effectsHandeler != (Object)null)
				{
					__instance.actor.effectsHandeler.Laugh();
				}
				SuperKickGB.PlayKickSound();
			}
			catch (Exception)
			{
			}
		}
	}
}