Please disclose if your mod was created primarily using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of LetalisHookGunPatch v1.0.1
HookGun.dll
Decompiled 2 years agousing System; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Logging; using GameNetcodeStuff; using HarmonyLib; using HookGun.Patches; using LethalLib.Modules; using UnityEngine; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("HookGun")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("HookGun")] [assembly: AssemblyCopyright("Copyright © 2023")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("56cd2431-e59f-4623-8b05-4f3a954ed7df")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("1.0.0.0")] namespace HookGun { [BepInPlugin("com.BLKNeko.HookGun", "HookGun", "1.0.0.0")] public class HookGunPlugin : BaseUnityPlugin { public class HookGunScript : GrabbableObject { private AudioSource audioSource; private RoundManager roundManager; private MeshRenderer HookGO; public Transform gunTip; public LayerMask whatIsGrappleable = LayerMask.op_Implicit(234918657); public LayerMask whatIsGrappleableToPull = LayerMask.op_Implicit(1048640); public LineRenderer lr; public float maxGrappleDistance = 60f; public float grappleDelayTime = 1f; public float overshootYAxis = 1.5f; public float HookSpeed = 48f; public float OkDistance = 0.5f; public float HookmaxTimer = 6f; public float HookTimer; public float smoothTime = 1.3f; public static bool grappling; public static bool shoudFall; public static bool DisableJump; public static bool DisableFall; private bool grapplingSlowY; public static bool NoDmg; private Vector3 grapplePoint = Vector3.zero; private Vector3 targetPosition = Vector3.zero; private Vector3 forces = Vector3.zero; public void Awake() { //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Expected O, but got Unknown HookGO = ((Component)this).GetComponentInChildren<MeshRenderer>(); audioSource = ((Component)this).GetComponent<AudioSource>(); roundManager = Object.FindObjectOfType<RoundManager>(); base.grabbable = true; base.grabbableToEnemies = true; base.useCooldown = 3f; base.insertedBattery = new Battery(false, 1f); base.mainObjectRenderer = ((Component)this).GetComponent<MeshRenderer>(); } public override void Update() { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: 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_0181: Unknown result type (might be due to invalid IL or missing references) //IL_0186: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) ((GrabbableObject)this).Update(); bool flag; if (grappling) { _ = targetPosition; if (targetPosition != Vector3.zero) { flag = !base.playerHeldBy.isPlayerDead; goto IL_0039; } } flag = false; goto IL_0039; IL_0039: if (flag) { if (!base.playerHeldBy.isInsideFactory) { NoDmg = true; } if (HookTimer >= HookmaxTimer) { ((MonoBehaviour)this).Invoke("backToNormal", 1f); ((MonoBehaviour)this).Invoke("enableDamage", 2f); HookTimer = 0f; } else { HookTimer += Time.fixedDeltaTime; } if (Vector3.Distance(((Component)base.playerHeldBy).transform.position, targetPosition) >= OkDistance) { if (base.playerHeldBy.isInsideFactory) { HookSpeed = 40f; } else { HookSpeed = 48f; } forces = Vector3.Normalize(targetPosition - ((Component)base.playerHeldBy).transform.position) * HookSpeed; if (base.playerHeldBy.isInsideFactory) { forces.y *= 2f; } else { forces.y *= 1.5f; } } else { HookSpeed = 0f; forces = Vector3.zero; grappling = false; targetPosition = Vector3.zero; ((MonoBehaviour)this).Invoke("backToNormal", 3f); ((MonoBehaviour)this).Invoke("enableDamage", 5f); } } PlayerControllerB playerHeldBy = base.playerHeldBy; playerHeldBy.externalForces.x = playerHeldBy.externalForces.x + forces.x; PlayerControllerB playerHeldBy2 = base.playerHeldBy; playerHeldBy2.externalForces.z = playerHeldBy2.externalForces.z + forces.z; PlayerControllerB playerHeldBy3 = base.playerHeldBy; playerHeldBy3.externalForces.y = playerHeldBy3.externalForces.y + forces.y; } public override void ItemActivate(bool used, bool buttonDown = true) { //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: 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) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) ((GrabbableObject)this).ItemActivate(used, buttonDown); Debug.Log((object)"Item active"); if (base.playerHeldBy.isInsideFactory) { OkDistance = 2f; HookmaxTimer = 4f; } else { OkDistance = 0.5f; HookmaxTimer = 6f; } if (base.insertedBattery.charge >= 0.05f) { Battery insertedBattery = base.insertedBattery; insertedBattery.charge -= 0.05f; if (base.insertedBattery.charge < 0.05f) { base.insertedBattery.charge = 0f; } audioSource.PlayOneShot(Assets.ShootSFX); StartGrapple(); } else { audioSource.PlayOneShot(Assets.NoAmmoSFX); } GameObject val = new GameObject("bar"); val.transform.SetParent(((Component)base.playerHeldBy.gameplayCamera).transform); RectTransform obj = val.AddComponent<RectTransform>(); obj.anchorMin = new Vector2(0.57f, 0.7f); obj.anchorMax = new Vector2(0.782f, 0.72f); obj.sizeDelta = new Vector2(0.2f, 0.2f); val.AddComponent<Image>(); val.GetComponent<Image>().sprite = Assets.HGSprite; } private void StartGrapple() { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: 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_00c7: 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_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) LineRenderer component = ((Component)Object.Instantiate<HookGunScript>(this, ((Component)this).gameObject.transform.GetChild(0))).GetComponent<LineRenderer>(); RaycastHit val = default(RaycastHit); if (Physics.Raycast(((Component)base.playerHeldBy.gameplayCamera).transform.position, ((Component)base.playerHeldBy.gameplayCamera).transform.forward, ref val, maxGrappleDistance, LayerMask.op_Implicit(whatIsGrappleable))) { grapplePoint = ((RaycastHit)(ref val)).point; SpawnTrail(component, ((RaycastHit)(ref val)).point); targetPosition = grapplePoint; ((Component)HookGO).transform.position = targetPosition; Vector3 position = ((Component)base.playerHeldBy).transform.position; Vector3 val2 = position - ((RaycastHit)(ref val)).point; ((Vector3)(ref val2)).Normalize(); val2 *= 1f; position = ((RaycastHit)(ref val)).point + val2; position.y *= 1.1f; targetPosition = position; grappling = true; audioSource.PlayOneShot(Assets.HitSFX); } else { audioSource.PlayOneShot(Assets.MissSFX); ((Component)component).gameObject.AddComponent<LineRendererFadeOut>(); Battery insertedBattery = base.insertedBattery; insertedBattery.charge += 0.05f; } } private void SpawnTrail(LineRenderer Trail, Vector3 HitPoint) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: 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_0027: Unknown result type (might be due to invalid IL or missing references) Trail.SetPositions((Vector3[])(object)new Vector3[2] { ((Component)this).gameObject.transform.GetChild(0).position, HitPoint }); ((Component)Trail).gameObject.AddComponent<LineRendererFadeOut>(); } private void backToNormal() { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) HookSpeed = 0f; HookTimer = 0f; forces = Vector3.zero; grappling = false; targetPosition = Vector3.zero; } private void enableDamage() { NoDmg = false; } } public class LineRendererFadeOut : MonoBehaviour { public LineRenderer lineRenderer; public float fadeDuration = 1f; public float destroyDelay = 0.5f; private float elapsed; private bool isFading = true; private void Start() { lineRenderer = ((Component)this).GetComponent<LineRenderer>(); } private void Update() { //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0079: 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) if (isFading) { if (elapsed < fadeDuration) { float num = Mathf.Lerp(1f, 0f, elapsed / fadeDuration); ((Renderer)lineRenderer).material.color = new Color(((Renderer)lineRenderer).material.color.r, ((Renderer)lineRenderer).material.color.g, ((Renderer)lineRenderer).material.color.b, num); elapsed += Time.deltaTime; } else { ((Renderer)lineRenderer).material.color = new Color(((Renderer)lineRenderer).material.color.r, ((Renderer)lineRenderer).material.color.g, ((Renderer)lineRenderer).material.color.b, 0f); isFading = false; Object.Destroy((Object)(object)((Component)this).gameObject, destroyDelay); } } } } private class Assets { internal static AssetBundle mainAssetBundle; private const string assetbundleName = "hookgunitem"; private static string[] assetNames; public static Item HGItem; public static Sprite HGSprite; public static AudioClip ShootSFX; public static AudioClip HitSFX; public static AudioClip MissSFX; public static AudioClip NoAmmoSFX; public static Mesh HGMesh; public static Mesh HOMesh; internal static void LoadAssetBundle() { if ((Object)(object)mainAssetBundle == (Object)null) { using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("HookGun.hookgunitem"); mainAssetBundle = AssetBundle.LoadFromStream(stream); } assetNames = mainAssetBundle.GetAllAssetNames(); } internal static void PopulateAssets() { if (!Object.op_Implicit((Object)(object)mainAssetBundle)) { Debug.LogError((object)"There is no AssetBundle to load assets from."); return; } HGSprite = mainAssetBundle.LoadAsset<Sprite>("HGSprite"); ShootSFX = mainAssetBundle.LoadAsset<AudioClip>("ShootSFX"); HitSFX = mainAssetBundle.LoadAsset<AudioClip>("HitSFX"); MissSFX = mainAssetBundle.LoadAsset<AudioClip>("MissSFX"); NoAmmoSFX = mainAssetBundle.LoadAsset<AudioClip>("NoAmmoSFX"); HGItem = mainAssetBundle.LoadAsset<Item>("HookGunItem"); } static Assets() { assetNames = new string[0]; } } private const string MODUID = "com.BLKNeko.HookGun"; private const string MODNAME = "HookGun"; private const string MODVERSION = "1.0.0.0"; private readonly Harmony harmony = new Harmony("com.BLKNeko.HookGun"); private static HookGunPlugin Instance; internal ManualLogSource mls; private void Awake() { if ((Object)(object)Instance == (Object)null) { Instance = this; } mls = Logger.CreateLogSource("com.BLKNeko.HookGun"); harmony.PatchAll(typeof(HookGunPlugin)); harmony.PatchAll(typeof(AllowDeathPatch)); harmony.PatchAll(); Assets.LoadAssetBundle(); Assets.PopulateAssets(); Type[] types = Assembly.GetExecutingAssembly().GetTypes(); for (int i = 0; i < types.Length; i++) { MethodInfo[] methods = types[i].GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic); foreach (MethodInfo methodInfo in methods) { if (methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false).Length != 0) { methodInfo.Invoke(null, null); } } } Item hGItem = Assets.HGItem; ((GrabbableObject)hGItem.spawnPrefab.AddComponent<HookGunScript>()).itemProperties = hGItem; Items.RegisterShopItem(hGItem, 1750); NetworkPrefabs.RegisterNetworkPrefab(hGItem.spawnPrefab); } } } namespace HookGun.Patches { [HarmonyPatch(typeof(PlayerControllerB))] public class JumpPatch { [HarmonyPatch("Jump_performed")] [HarmonyPrefix] private static void ChangeJump(ref bool ___isJumping, ref bool ___isFallingFromJump) { } } [HarmonyPatch(typeof(PlayerControllerB))] public class AllowDeathPatch { [HarmonyPatch("AllowPlayerDeath")] [HarmonyPrefix] private static bool ChangeAllowDeath() { if (HookGunPlugin.HookGunScript.NoDmg) { return false; } return true; } } }