|
| 1 | +using BepInEx; |
| 2 | +using HarmonyLib; |
| 3 | +using HarmonyLib.Tools; |
| 4 | +using Interfaces; |
| 5 | +using UnityEngine; |
| 6 | + |
| 7 | +namespace OneShot |
| 8 | +{ |
| 9 | + [BepInPlugin(ModName, ModGUID, ModVersion)] |
| 10 | + public class Main : BaseUnityPlugin |
| 11 | + { |
| 12 | + public const string ModName = "OneShot"; |
| 13 | + public const string ModAuthor = "Septikai"; |
| 14 | + public const string ModGUID = "me.septikai.OneShot"; |
| 15 | + public const string ModVersion = "1.0.0"; |
| 16 | + internal Harmony Harmony; |
| 17 | + internal void Awake() |
| 18 | + { |
| 19 | + // Creating new harmony instance |
| 20 | + Harmony = new Harmony(ModGUID); |
| 21 | + |
| 22 | + // Applying patches |
| 23 | + Harmony.PatchAll(); |
| 24 | + Logger.LogInfo($"{ModName} successfully loaded! Made by {ModAuthor}"); |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + [HarmonyPatch(typeof(VersionNumberTextMesh), nameof(VersionNumberTextMesh.Start))] |
| 29 | + public class VersionNumberTextMeshPatch |
| 30 | + { |
| 31 | + public static void Postfix(VersionNumberTextMesh __instance) |
| 32 | + { |
| 33 | + __instance.textMesh.text += $"\n<color=red>{Main.ModName} v{Main.ModVersion} by {Main.ModAuthor}</color>"; |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + [HarmonyPatch(typeof(Weapon), nameof(Weapon.ammo), MethodType.Setter)] |
| 38 | + public class AmmoPatchSetter |
| 39 | + { |
| 40 | + [HarmonyPostfix] |
| 41 | + public static void OneAmmo(Weapon __instance, float value) |
| 42 | + { |
| 43 | + var playerCount = LobbyController.instance.GetPlayerCount(); |
| 44 | + if (playerCount != 1) return; |
| 45 | + if (__instance.type.Contains(Weapon.WeaponType.Particle)) return; |
| 46 | + if (value != __instance.maxAmmo) __instance.networkAmmo.Value = 0; |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + [HarmonyPatch(typeof(ForceField), nameof(ForceField.Damage))] |
| 51 | + public class ForceFieldDamagePatch |
| 52 | + { |
| 53 | + [HarmonyPostfix] |
| 54 | + public static void OneUseBlades(ForceField __instance, Collision2D other) |
| 55 | + { |
| 56 | + var playerCount = LobbyController.instance.GetPlayerCount(); |
| 57 | + if (playerCount != 1) return; |
| 58 | + var component = other.gameObject.GetComponent<IDamageable>(); |
| 59 | + if (component.GetType().IsSubclassOf(typeof(Weapon))) return; |
| 60 | + var blades = UnityEngine.Object.FindObjectsOfType<ParticleBlade>(); |
| 61 | + if (blades == null) return; |
| 62 | + foreach (var blade in blades) |
| 63 | + { |
| 64 | + if (blade.particleField.forceField.GetInstanceID() != __instance.GetInstanceID()) continue; |
| 65 | + blade.Disintegrate(); |
| 66 | + } |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + [HarmonyPatch(typeof(RailShot), nameof(RailShot.ReflectShot))] |
| 71 | + public class ShotReflectionPatch |
| 72 | + { |
| 73 | + [HarmonyPostfix] |
| 74 | + public static void OneReflect(RaycastHit2D hit) |
| 75 | + { |
| 76 | + var playerCount = LobbyController.instance.GetPlayerCount(); |
| 77 | + if (playerCount != 1) return; |
| 78 | + var forceField = hit.collider.gameObject.GetComponent<ForceField>(); |
| 79 | + var blades = UnityEngine.Object.FindObjectsOfType<ParticleBlade>(); |
| 80 | + if (blades == null) return; |
| 81 | + foreach (var blade in blades) |
| 82 | + { |
| 83 | + if (blade.particleField.forceField.GetInstanceID() != forceField.GetInstanceID()) |
| 84 | + { |
| 85 | + continue; |
| 86 | + } |
| 87 | + blade.Disintegrate(); |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | +} |
0 commit comments