using HarmonyLib; using System.Collections.Generic; using System.Reflection.Emit; namespace Oxide.Plugins; [Info("Server Projectile Hit Fix", "nivex", "1.0.2")] [Description("Fix to set initiator for fire entities.")] public class ServerProjectileHitFix : RustPlugin { private Harmony _harmony; private void Loaded() { _harmony = new Harmony(Name + "Patch"); _harmony.PatchAll(); } private void Unload() { _harmony?.UnpatchAll(Name + "Patch"); } [HarmonyPatch(typeof(ItemModProjectileSpawn), "ServerProjectileHit", typeof(HitInfo))] internal class ItemModProjectileSpawn_ServerProjectileHit { [HarmonyTranspiler] private static IEnumerable Transpiler(IEnumerable instructions) { List codes = new(instructions); List patch = new() { new(OpCodes.Ldarg_1), new(OpCodes.Ldfld, AccessTools.Field(typeof(HitInfo), "Initiator")), new(OpCodes.Stfld, AccessTools.Field(typeof(BaseEntity), "creatorEntity")), }; for (int i = 0; i < codes.Count; i++) { if (i - 1 >= 0 && codes[i - 1].ToString() == "callvirt Void set_rotation(UnityEngine.Quaternion)") { CodeInstruction copy = new(OpCodes.Ldloc_S, codes[i].operand); codes.InsertRange(i, patch); codes.Insert(i, copy); } } return codes; } } }