//Reference: 0Harmony using System; using System.Collections.Generic; using System.Reflection; using System.Reflection.Emit; using HarmonyLib; using Network; using UnityEngine; namespace Oxide.Plugins { [Info("EncryptionFix", "Farkas", "1.0.0")] [Description("Decreases the encryption level for admins to 1")] public class EncryptionFix : RustPlugin { private Harmony _harmony; private void Init() { _harmony = new Harmony(Name + "Patches"); _harmony.Patch(AccessTools.Method(typeof(ServerMgr), "JoinGame"), transpiler: new HarmonyMethod(typeof(ServerMgr_JoinGame), nameof(ServerMgr_JoinGame.Transpiler))); } private void Unload() { _harmony?.UnpatchAll(_harmony.Id); } private static class ServerMgr_JoinGame { internal static IEnumerable Transpiler(IEnumerable instructions) { List list = new List(instructions); int index = list.FindIndex(x => x.opcode == OpCodes.Ldsfld && ((FieldInfo)x.operand).Name == "encryption"); if (index == -1 || list[index + 1].opcode != OpCodes.Stloc_1) { Debug.LogError("[EncryptionFix] Failed to patch encryption! Please update the plugin."); return list; } list.InsertRange(index + 2, new List { new CodeInstruction(OpCodes.Ldloca_S, 1), // uint num new CodeInstruction(OpCodes.Ldarg_1), // Connection connection new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(ServerMgr_JoinGame), nameof(FixEncryptionLevel))) }); return list; } private static void FixEncryptionLevel(ref uint encryptionLevel, Connection connection) { if (encryptionLevel > 1 && connection.authLevel > 0) { encryptionLevel = 1; } } } } }