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 Kill It With Shovel v1.0.1
KillItWithShovel.dll
Decompiled 2 years agousing System; using System.Collections; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using GameNetcodeStuff; using HarmonyLib; using KillItWithShovel.Patches; using Microsoft.CodeAnalysis; using Unity.Collections; using Unity.Netcode; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("KillItWithShovel")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyDescription("A template for Lethal Company")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+43206f0475d7dae18e393eaa115cfd192399712f")] [assembly: AssemblyProduct("KillItWithShovel")] [assembly: AssemblyTitle("KillItWithShovel")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace KillItWithShovel { [Serializable] public class Config : SyncedInstance<Config> { [CompilerGenerated] private static class <>O { public static HandleNamedMessageDelegate <0>__OnRequestSync; public static HandleNamedMessageDelegate <1>__OnReceiveSync; } public static ConfigEntry<bool> configEnterBerserkMode; public bool bMode; public static ConfigEntry<float> configDisableDuration; public float dDuration; public Config(ConfigFile cfg) { InitInstance(this); configEnterBerserkMode = cfg.Bind<bool>("General", "Berseker Mode when being waked", true, "Turret will enter berseker mode if being rudely waken by weapons. (Dafault: true)"); configDisableDuration = cfg.Bind<float>("General", "Disable Duration", 5f, "How many seconds the turret will be disabled. (Dafault: 5)"); } public static void BuildServerConfigSync() { SyncedInstance<Config>.Default.bMode = configEnterBerserkMode.Value; SyncedInstance<Config>.Default.dDuration = configDisableDuration.Value; SyncedInstance<Config>.Instance.dDuration = SyncedInstance<Config>.Default.dDuration; SyncedInstance<Config>.Instance.bMode = SyncedInstance<Config>.Default.bMode; } public static void RequestSync() { //IL_0029: Unknown result type (might be due to invalid IL or missing references) if (!SyncedInstance<Config>.IsClient) { return; } FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(SyncedInstance<Config>.IntSize, (Allocator)2, -1); try { SyncedInstance<Config>.MessageManager.SendNamedMessage("KillItWithShovel_OnRequestConfigSync", 0uL, val, (NetworkDelivery)3); } finally { ((IDisposable)(FastBufferWriter)(ref val)).Dispose(); } } public static void OnRequestSync(ulong clientId, FastBufferReader _) { //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) if (!SyncedInstance<Config>.IsHost) { return; } SyncedInstance<Config>.mls2.LogInfo((object)$"Config sync request received from client: {clientId}"); byte[] array = SyncedInstance<Config>.SerializeToBytes(SyncedInstance<Config>.Instance); int num = array.Length; FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(num + SyncedInstance<Config>.IntSize, (Allocator)2, -1); try { ((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteBytesSafe(array, -1, 0); SyncedInstance<Config>.MessageManager.SendNamedMessage("KillItWithShovel_OnReceiveConfigSync", clientId, val, (NetworkDelivery)3); } catch (Exception arg) { SyncedInstance<Config>.mls2.LogInfo((object)$"Error occurred syncing config with client: {clientId}\n{arg}"); } finally { ((IDisposable)(FastBufferWriter)(ref val)).Dispose(); } } public static void OnReceiveSync(ulong _, FastBufferReader reader) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) if (!((FastBufferReader)(ref reader)).TryBeginRead(SyncedInstance<Config>.IntSize)) { SyncedInstance<Config>.mls2.LogError((object)"Config sync error: Could not begin reading buffer."); return; } int num = default(int); ((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num, default(ForPrimitives)); if (!((FastBufferReader)(ref reader)).TryBeginRead(num)) { SyncedInstance<Config>.mls2.LogError((object)"Config sync error: Host could not sync."); return; } byte[] data = new byte[num]; ((FastBufferReader)(ref reader)).ReadBytesSafe(ref data, num, 0); SyncedInstance<Config>.SyncInstance(data); SyncedInstance<Config>.mls2.LogInfo((object)"Successfully synced config with host."); } [HarmonyPostfix] [HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")] public static void InitializeLocalPlayer() { //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Expected O, but got Unknown //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown if (SyncedInstance<Config>.IsHost) { BuildServerConfigSync(); CustomMessagingManager messageManager = SyncedInstance<Config>.MessageManager; object obj = <>O.<0>__OnRequestSync; if (obj == null) { HandleNamedMessageDelegate val = OnRequestSync; <>O.<0>__OnRequestSync = val; obj = (object)val; } messageManager.RegisterNamedMessageHandler("KillItWithShovel_OnRequestConfigSync", (HandleNamedMessageDelegate)obj); SyncedInstance<Config>.Synced = true; } else { SyncedInstance<Config>.Synced = false; CustomMessagingManager messageManager2 = SyncedInstance<Config>.MessageManager; object obj2 = <>O.<1>__OnReceiveSync; if (obj2 == null) { HandleNamedMessageDelegate val2 = OnReceiveSync; <>O.<1>__OnReceiveSync = val2; obj2 = (object)val2; } messageManager2.RegisterNamedMessageHandler("KillItWithShovel_OnReceiveConfigSync", (HandleNamedMessageDelegate)obj2); RequestSync(); } } [HarmonyPostfix] [HarmonyPatch(typeof(GameNetworkManager), "StartDisconnect")] public static void PlayerLeave() { SyncedInstance<Config>.RevertSync(); } } [BepInPlugin("MiffyL.KillItWithShovel", "KillItWithShovel", "1.0.0")] public class Plugin : BaseUnityPlugin { private const string modGUID = "MiffyL.KillItWithShovel"; private const string modName = "KillItWithShovel"; private const string modVersion = "1.0.0"; private readonly Harmony harmony = new Harmony("MiffyL.KillItWithShovel"); public static Plugin Instance; internal ManualLogSource mls; public static Config MyConfig { get; internal set; } private void Awake() { if ((Object)(object)Instance == (Object)null) { Instance = this; } ((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin MiffyL.KillItWithShovel is loaded!"); mls = Logger.CreateLogSource("MiffyL.KillItWithShovel"); harmony.PatchAll(typeof(Plugin)); harmony.PatchAll(typeof(TurretPatch)); harmony.PatchAll(typeof(Config)); MyConfig = new Config(((BaseUnityPlugin)this).Config); } } [Serializable] public class SyncedInstance<T> { public static ManualLogSource mls2 = Logger.CreateLogSource("MiffyL.KillItWithShovel"); [NonSerialized] protected static int IntSize = 4; internal static CustomMessagingManager MessageManager => NetworkManager.Singleton.CustomMessagingManager; internal static bool IsClient => NetworkManager.Singleton.IsClient; internal static bool IsHost => NetworkManager.Singleton.IsHost; public static T Default { get; private set; } public static T Instance { get; private set; } public static bool Synced { get; internal set; } protected void InitInstance(T instance) { Default = instance; Instance = instance; IntSize = 4; } internal static void SyncInstance(byte[] data) { Instance = DeserializeFromBytes(data); Synced = true; } internal static void RevertSync() { Instance = Default; Synced = false; } public static byte[] SerializeToBytes(T val) { BinaryFormatter binaryFormatter = new BinaryFormatter(); using MemoryStream memoryStream = new MemoryStream(); try { binaryFormatter.Serialize(memoryStream, val); return memoryStream.ToArray(); } catch (Exception arg) { mls2.LogError((object)$"Error serializing instance: {arg}"); return null; } } public static T DeserializeFromBytes(byte[] data) { BinaryFormatter binaryFormatter = new BinaryFormatter(); using MemoryStream serializationStream = new MemoryStream(data); try { return (T)binaryFormatter.Deserialize(serializationStream); } catch (Exception arg) { mls2.LogError((object)$"Error deserializing instance: {arg}"); return default(T); } } } public static class PluginInfo { public const string PLUGIN_GUID = "KillItWithShovel"; public const string PLUGIN_NAME = "KillItWithShovel"; public const string PLUGIN_VERSION = "1.0.0"; } } namespace KillItWithShovel.Patches { [HarmonyPatch(typeof(EnemyAI))] internal class EnemyAIPatch { [HarmonyPatch(typeof(EnemyAI), "HitEnemy")] [HarmonyPrefix] public static bool HitPushBackPatch(ref int force, ref PlayerControllerB playerWhoHit, ref EnemyAI __instance) { string enemyName = __instance.enemyType.enemyName; string text = enemyName; if (text == "SpringManAI" || text == "JesterAI") { PushBackHit(ref force, ref playerWhoHit, ref __instance); } return true; } private static void PushBackHit(ref int force, ref PlayerControllerB playerWhoHit, ref EnemyAI __instance) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: 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_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_004e: 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_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0074: 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) Vector3 position = ((Component)__instance).gameObject.transform.position; Vector3 position2 = ((Component)playerWhoHit).gameObject.transform.position; float num = position2.y - position.y; if (num > 40f) { __instance.KillEnemy(false); return; } Vector3 val = Vector3.Normalize((position2 - position) * (float)force); Transform transform = ((Component)__instance).gameObject.transform; transform.position += val; } } [HarmonyPatch(typeof(Turret))] internal class TurretPatch { public class TurretHitPatchMB : MonoBehaviour { } private static TurretHitPatchMB turretHitPatchMB; [HarmonyPatch(typeof(Turret), "IHittable.Hit")] [HarmonyPrefix] public static bool HitDisablePatch(ref TurretMode ___turretMode, ref Turret __instance) { if ((Object)(object)turretHitPatchMB == (Object)null) { turretHitPatchMB = ((Component)__instance).gameObject.AddComponent<TurretHitPatchMB>(); } if (!__instance.turretActive || (int)___turretMode == 3) { if (SyncedInstance<Config>.Instance.bMode) { __instance.ToggleTurretEnabled(true); return true; } return false; } ((MonoBehaviour)turretHitPatchMB).StartCoroutine(TurnOffAndOnTurret(__instance, SyncedInstance<Config>.Instance.dDuration)); return false; } public static IEnumerator TurnOffAndOnTurret(Turret _turret, float duration) { _turret.ToggleTurretEnabled(false); yield return (object)new WaitForSeconds(duration); _turret.ToggleTurretEnabled(true); } } }