using System;
using System.Collections;
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 HarmonyLib;
using Il2CppFemur;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using MelonLoader;
using Microsoft.CodeAnalysis;
using OnePunchGB;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(global::OnePunchGB.OnePunchGB), "OnePunchGB", "1.0.0", "Zooks", null)]
[assembly: MelonGame("Boneloaf", "Gang Beasts")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("Zooks")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("OnePunchGB")]
[assembly: AssemblyTitle("OnePunchGB")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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]
[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;
}
}
}
namespace OnePunchGB
{
public class PlayerBases
{
public float force;
public float damage;
public float lift;
public float animSpeed;
public float groundSpeed;
public float upwardForce;
}
public class OnePunchGB : MelonMod
{
public const float DamageMult = 66f;
public const float LiftMult = 5f;
public const float AnimSpeedMult = 1.5f;
public const float SpeedMult = 1.4f;
public const float UpwardLiftMult = 2.8f;
public const float PunchTimerDuration = 1.5f;
public static float ForceMult = 2.5f;
public static bool ObjectOnly = false;
public static bool ShowMenu = false;
public static Dictionary<int, PlayerBases> BaseStats = new Dictionary<int, PlayerBases>();
public static HashSet<int> UnlockedRigidbodies = new HashSet<int>();
public static HashSet<int> ActorRigidbodies = new HashSet<int>();
private object _pollCoroutine;
public static Actor LocalPlayerInstance = null;
public static float LevelLoadTime = 0f;
private bool _wasLeftPunching;
private bool _wasRightPunching;
public override void OnInitializeMelon()
{
MelonLogger.Msg("OnePunchGB loaded.");
}
public override void OnSceneWasLoaded(int buildIndex, string sceneName)
{
BaseStats.Clear();
UnlockedRigidbodies.Clear();
ActorRigidbodies.Clear();
LocalPlayerInstance = null;
LevelLoadTime = Time.time;
_wasLeftPunching = false;
_wasRightPunching = false;
if (_pollCoroutine != null)
{
MelonCoroutines.Stop(_pollCoroutine);
}
_pollCoroutine = MelonCoroutines.Start(PollForPlayer());
}
public override void OnUpdate()
{
Keyboard current = Keyboard.current;
if (current == null)
{
return;
}
if (((ButtonControl)current.gKey).wasPressedThisFrame)
{
ShowMenu = !ShowMenu;
}
if (!((Object)(object)LocalPlayerInstance != (Object)null) || !(Time.time - LevelLoadTime >= 4f))
{
return;
}
Traverse val = Traverse.Create((object)LocalPlayerInstance).Property("controlHandeler", (object[])null);
if (!val.PropertyExists())
{
return;
}
object value = val.GetValue();
if (value == null)
{
return;
}
Traverse val2 = Traverse.Create(value);
Traverse obj = val2.Property("leftPunch", (object[])null);
bool flag = obj != null && obj.GetValue<bool>();
Traverse obj2 = val2.Property("rightPunch", (object[])null);
bool flag2 = obj2 != null && obj2.GetValue<bool>();
if (flag && !_wasLeftPunching)
{
Traverse obj3 = val2.Property("leftPunchTimer", (object[])null);
if (obj3 != null)
{
obj3.SetValue((object)1.5f);
}
TriggerPunchPhysics();
}
if (flag2 && !_wasRightPunching)
{
Traverse obj4 = val2.Property("rightPunchTimer", (object[])null);
if (obj4 != null)
{
obj4.SetValue((object)1.5f);
}
TriggerPunchPhysics();
}
_wasLeftPunching = flag;
_wasRightPunching = flag2;
}
private void TriggerPunchPhysics()
{
if (ObjectOnly)
{
PunchObjectsOnly();
}
}
public override void OnGUI()
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
if (!ShowMenu)
{
return;
}
GUI.Box(new Rect(20f, 20f, 320f, 160f), "OnePunchGB");
GUI.Label(new Rect(30f, 50f, 280f, 20f), "Force: " + ForceMult.ToString("F1"));
ForceMult = GUI.HorizontalSlider(new Rect(30f, 75f, 280f, 20f), ForceMult, 0.1f, 2000f);
string text = (ObjectOnly ? "Objects Only: ON" : "Objects Only: OFF");
if (GUI.Button(new Rect(30f, 105f, 280f, 25f), text))
{
ObjectOnly = !ObjectOnly;
if (ObjectOnly)
{
CacheActorRigidbodies();
}
}
if (GUI.Button(new Rect(30f, 140f, 280f, 25f), "Close"))
{
ShowMenu = false;
}
}
public static void CacheActorRigidbodies()
{
ActorRigidbodies.Clear();
Actor[] array = Il2CppArrayBase<Actor>.op_Implicit(Object.FindObjectsOfType<Actor>());
foreach (Actor val in array)
{
if ((Object)(object)val == (Object)null)
{
continue;
}
Rigidbody[] array2 = Il2CppArrayBase<Rigidbody>.op_Implicit(((Component)val).GetComponentsInChildren<Rigidbody>());
foreach (Rigidbody val2 in array2)
{
if (!((Object)(object)val2 == (Object)null))
{
ActorRigidbodies.Add(((Object)val2).GetInstanceID());
}
}
}
}
public static bool IsActorRigidbody(Rigidbody rb)
{
if ((Object)(object)rb == (Object)null)
{
return false;
}
if (ActorRigidbodies.Count == 0)
{
CacheActorRigidbodies();
}
return ActorRigidbodies.Contains(((Object)rb).GetInstanceID());
}
public static void UnlockObjectRigidbodies()
{
//IL_0116: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: Unknown result type (might be due to invalid IL or missing references)
//IL_012b: Unknown result type (might be due to invalid IL or missing references)
//IL_0134: Unknown result type (might be due to invalid IL or missing references)
//IL_0139: Unknown result type (might be due to invalid IL or missing references)
//IL_0149: Unknown result type (might be due to invalid IL or missing references)
//IL_0152: Unknown result type (might be due to invalid IL or missing references)
//IL_0157: Unknown result type (might be due to invalid IL or missing references)
//IL_0167: Unknown result type (might be due to invalid IL or missing references)
//IL_0170: Unknown result type (might be due to invalid IL or missing references)
//IL_0175: Unknown result type (might be due to invalid IL or missing references)
//IL_0185: Unknown result type (might be due to invalid IL or missing references)
CacheActorRigidbodies();
Rigidbody[] array = Il2CppArrayBase<Rigidbody>.op_Implicit(Object.FindObjectsOfType<Rigidbody>());
foreach (Rigidbody val in array)
{
if ((Object)(object)val == (Object)null || IsActorRigidbody(val))
{
continue;
}
int instanceID = ((Object)val).GetInstanceID();
if (!UnlockedRigidbodies.Contains(instanceID))
{
UnlockedRigidbodies.Add(instanceID);
val.isKinematic = false;
val.useGravity = true;
ConfigurableJoint component = ((Component)val).GetComponent<ConfigurableJoint>();
if ((Object)(object)component != (Object)null)
{
component.xMotion = (ConfigurableJointMotion)2;
component.yMotion = (ConfigurableJointMotion)2;
component.zMotion = (ConfigurableJointMotion)2;
component.angularXMotion = (ConfigurableJointMotion)2;
component.angularYMotion = (ConfigurableJointMotion)2;
component.angularZMotion = (ConfigurableJointMotion)2;
}
FixedJoint component2 = ((Component)val).GetComponent<FixedJoint>();
if ((Object)(object)component2 != (Object)null)
{
Object.Destroy((Object)(object)component2);
}
HingeJoint component3 = ((Component)val).GetComponent<HingeJoint>();
if ((Object)(object)component3 != (Object)null)
{
component3.useLimits = false;
}
SpringJoint component4 = ((Component)val).GetComponent<SpringJoint>();
if ((Object)(object)component4 != (Object)null)
{
component4.spring = 0f;
component4.damper = 0f;
}
CharacterJoint component5 = ((Component)val).GetComponent<CharacterJoint>();
if ((Object)(object)component5 != (Object)null)
{
SoftJointLimit lowTwistLimit = component5.lowTwistLimit;
((SoftJointLimit)(ref lowTwistLimit)).limit = -180f;
component5.lowTwistLimit = lowTwistLimit;
SoftJointLimit highTwistLimit = component5.highTwistLimit;
((SoftJointLimit)(ref highTwistLimit)).limit = 180f;
component5.highTwistLimit = highTwistLimit;
SoftJointLimit swing1Limit = component5.swing1Limit;
((SoftJointLimit)(ref swing1Limit)).limit = 180f;
component5.swing1Limit = swing1Limit;
SoftJointLimit swing2Limit = component5.swing2Limit;
((SoftJointLimit)(ref swing2Limit)).limit = 180f;
component5.swing2Limit = swing2Limit;
}
val.constraints = (RigidbodyConstraints)0;
val.drag = 0.1f;
val.angularDrag = 0.1f;
val.mass = Mathf.Max(val.mass, 1f);
}
}
}
public static void PunchObjectsOnly()
{
//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)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
//IL_010e: Unknown result type (might be due to invalid IL or missing references)
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)LocalPlayerInstance == (Object)null || Time.time - LevelLoadTime < 4f)
{
return;
}
CacheActorRigidbodies();
UnlockObjectRigidbodies();
Transform transform = ((Component)LocalPlayerInstance).transform;
float num = 5f;
Rigidbody[] array = Il2CppArrayBase<Rigidbody>.op_Implicit(Object.FindObjectsOfType<Rigidbody>());
foreach (Rigidbody val in array)
{
if (!((Object)(object)val == (Object)null) && !((Component)val).transform.IsChildOf(transform) && !IsActorRigidbody(val) && !(Vector3.Distance(transform.position, ((Component)val).transform.position) > num))
{
val.isKinematic = false;
val.useGravity = true;
val.constraints = (RigidbodyConstraints)0;
Vector3 val2 = ((Component)val).transform.position - transform.position;
Vector3 normalized = ((Vector3)(ref val2)).normalized;
normalized.y += 0.4f;
normalized = ((Vector3)(ref normalized)).normalized;
val.velocity = Vector3.zero;
val.angularVelocity = Vector3.zero;
val.AddForce(normalized * ForceMult * 100f, (ForceMode)2);
}
}
}
private IEnumerator PollForPlayer()
{
yield return (object)new WaitForSeconds(3f);
while (true)
{
yield return (object)new WaitForSeconds(1f);
if (ObjectOnly)
{
CacheActorRigidbodies();
UnlockObjectRigidbodies();
}
Actor[] array = Il2CppArrayBase<Actor>.op_Implicit(Object.FindObjectsOfType<Actor>());
if (array == null || array.Length == 0)
{
continue;
}
Actor[] array2 = array;
foreach (Actor val in array2)
{
if (!((Object)(object)val == (Object)null))
{
Traverse trv = Traverse.Create((object)val);
if (IsStrictlyLocalPlayer(trv))
{
LocalPlayerInstance = val;
RefreshBuffs(val, trv);
}
}
}
}
}
public static bool IsStrictlyLocalPlayer(Traverse trv)
{
Traverse obj = trv.Property("IsAI", (object[])null);
if (obj != null && obj.GetValue<bool>())
{
return false;
}
Traverse obj2 = trv.Property("_aiMember", (object[])null);
if (obj2 != null && obj2.GetValue<bool>())
{
return false;
}
Traverse obj3 = trv.Property("isAI", (object[])null);
if (obj3 != null && obj3.GetValue<bool>())
{
return false;
}
Traverse obj4 = trv.Property("_controlledBy", (object[])null);
string text = ((obj4 == null) ? null : obj4.GetValue<object>()?.ToString()?.ToLower()) ?? "";
switch (text)
{
case "ai":
case "cpu":
case "bot":
case "npc":
case "wave":
return false;
default:
{
Traverse obj5 = trv.Property("isLocalPlayer", (object[])null);
if (obj5 != null && obj5.GetValue<bool>())
{
return true;
}
switch (text)
{
case "human":
case "player":
case "local":
return true;
default:
{
Traverse obj6 = trv.Property("InputPlayer", (object[])null);
object obj7 = ((obj6 != null) ? obj6.GetValue() : null);
if (obj7 != null)
{
Traverse val = Traverse.Create(obj7).Property("valid", (object[])null);
if (val.PropertyExists() && val.GetValue<bool>())
{
return true;
}
}
return false;
}
}
}
}
}
private void RefreshBuffs(Actor actor, Traverse trv)
{
int instanceID = ((Object)actor).GetInstanceID();
if (!BaseStats.TryGetValue(instanceID, out PlayerBases value))
{
value = new PlayerBases();
BaseStats[instanceID] = value;
}
Traverse obj = trv.Property("_punchForceModifer", (object[])null);
float num = ((obj != null) ? obj.GetValue<float>() : 0f);
if (num > value.force && num <= 10f)
{
value.force = num;
}
if (value.force > 0f)
{
Traverse obj2 = trv.Property("_punchForceModifer", (object[])null);
if (obj2 != null)
{
obj2.SetValue((object)(value.force * ForceMult));
}
}
Traverse obj3 = trv.Property("_punchDamageModifer", (object[])null);
float num2 = ((obj3 != null) ? obj3.GetValue<float>() : 0f);
if (num2 > value.damage && num2 <= 10f)
{
value.damage = num2;
}
if (value.damage > 0f)
{
Traverse obj4 = trv.Property("_punchDamageModifer", (object[])null);
if (obj4 != null)
{
obj4.SetValue((object)(value.damage * 66f));
}
}
Traverse obj5 = trv.Property("liftStrength", (object[])null);
float num3 = ((obj5 != null) ? obj5.GetValue<float>() : 0f);
if (num3 > value.lift && num3 <= 10f)
{
value.lift = num3;
}
if (value.lift > 0f)
{
Traverse obj6 = trv.Property("liftStrength", (object[])null);
if (obj6 != null)
{
obj6.SetValue((object)(value.lift * 5f));
}
}
Traverse obj7 = trv.Property("groundSpeed", (object[])null);
float num4 = ((obj7 != null) ? obj7.GetValue<float>() : 0f);
if (num4 > value.groundSpeed && num4 <= 20f)
{
value.groundSpeed = num4;
}
if (value.groundSpeed > 0f)
{
Traverse obj8 = trv.Property("groundSpeed", (object[])null);
if (obj8 != null)
{
obj8.SetValue((object)(value.groundSpeed * 1.4f));
}
}
Traverse obj9 = trv.Property("applyedForce", (object[])null);
float num5 = ((obj9 != null) ? obj9.GetValue<float>() : 0f);
if (num5 > value.upwardForce && num5 <= 10f)
{
value.upwardForce = num5;
}
if (value.upwardForce > 0f)
{
Traverse obj10 = trv.Property("applyedForce", (object[])null);
if (obj10 != null)
{
obj10.SetValue((object)(value.upwardForce * 2.8f));
}
}
Animator component = ((Component)actor).GetComponent<Animator>();
if ((Object)(object)component != (Object)null)
{
if (value.animSpeed == 0f)
{
value.animSpeed = component.speed;
}
if (value.animSpeed > 0f && value.animSpeed <= 5f)
{
component.speed = value.animSpeed * 1.5f;
}
}
}
}
}