// Reference: 0Harmony using HarmonyLib; using System.Collections.Generic; using System.Reflection.Emit; using UnityEngine; using System.Linq; using Facepunch; namespace Oxide.Plugins { [Info("No Free Spray", "ViolationHandler", "0.0.2")] [Description("Prevents ALL users from using Free Spray with Spray Cans.")] public class NoFreeSpray : RustPlugin { private Harmony _harmonyInstance; private void Loaded() { _harmonyInstance = new Harmony("com.ViolationHandler" + Name); _harmonyInstance.Patch(AccessTools.Method(typeof(SprayCan), nameof(SprayCan.CanSprayFreehand)), transpiler: new HarmonyMethod(typeof(SprayFreehandFix), nameof(SprayFreehandFix.Transpiler))); } private void Unload() { _harmonyInstance?.UnpatchAll(_harmonyInstance.Id); } public class SprayFreehandFix { internal static IEnumerable Transpiler(IEnumerable instructions) { List list = instructions.ToList(); list.InsertRange(0, new List { new CodeInstruction(OpCodes.Ldc_I4_0), new CodeInstruction(OpCodes.Ret) }); return list; } } } }