Please disclose if any significant portion of your mod was created 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 BuyableKitchenKnife v1.1.0
BuyableKnife.dll
Decompiled 2 years agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using LethalLib.Modules; using UnityEngine; using UnityEngine.SceneManagement; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("0.0.0.0")] namespace BuyableKnife; [BepInDependency("evaisa.lethallib", "0.13.2")] [BepInPlugin("Columbus.BuyableKnife", "Buyable Knife", "1.1.0")] public class BuyableKnife : BaseUnityPlugin { private const string modGUID = "Columbus.BuyableKnife"; private const string modName = "Buyable Knife"; private const string modVersion = "1.1.0"; private readonly Harmony harmony = new Harmony("Columbus.BuyableKnife"); private static BuyableKnife Instance; private static ConfigEntry<int> KnifePriceConfig; private static Dictionary<string, TerminalNode> infoNodes = new Dictionary<string, TerminalNode>(); private static ManualLogSource LoggerInstance => ((BaseUnityPlugin)Instance).Logger; public static List<Item> AllItems => Resources.FindObjectsOfTypeAll<Item>().Concat(Object.FindObjectsByType<Item>((FindObjectsInactive)1, (FindObjectsSortMode)1)).ToList(); public static Item Knife => ((IEnumerable<Item>)AllItems).FirstOrDefault((Func<Item, bool>)((Item item) => ((Object)item).name.Equals("Knife"))); public static Item KnifeClone { get; private set; } public static GameObject KnifeObjectClone { get; private set; } public static int KnifePrice => KnifePriceConfig.Value; private void Awake() { if ((Object)(object)Instance == (Object)null) { Object.DontDestroyOnLoad((Object)(object)this); Instance = this; } harmony.PatchAll(); KnifePriceConfig = ((BaseUnityPlugin)this).Config.Bind<int>("Prices", "KnifePrice", 25, "Credits needed to buy Knife"); SceneManager.sceneLoaded += OnSceneLoaded; KnifeClone = MakeNonScrap(KnifePrice); AddToShop(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin Buyable Knife is loaded with version 1.1.0!"); } private static Item MakeNonScrap(int price) { //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_01d9: Unknown result type (might be due to invalid IL or missing references) //IL_01e3: Unknown result type (might be due to invalid IL or missing references) Item val = ScriptableObject.CreateInstance<Item>(); Object.DontDestroyOnLoad((Object)(object)val); ((Object)val).name = "Error"; val.itemName = "Error"; val.itemId = 6624; val.isScrap = false; val.creditsWorth = price; val.canBeGrabbedBeforeGameStart = true; val.automaticallySetUsingPower = false; val.batteryUsage = 300f; val.canBeInspected = false; val.isDefensiveWeapon = true; val.saveItemVariable = true; val.syncGrabFunction = false; val.twoHandedAnimation = true; val.verticalOffset = 0.25f; GameObject val2 = NetworkPrefabs.CreateNetworkPrefab("Cube"); GameObject val3 = GameObject.CreatePrimitive((PrimitiveType)3); val3.transform.SetParent(val2.transform, false); ((Renderer)val3.GetComponent<MeshRenderer>()).sharedMaterial.shader = Shader.Find("HDRP/Lit"); val2.AddComponent<BoxCollider>().size = Vector3.one * 2f; val2.AddComponent<AudioSource>(); PhysicsProp val4 = val2.AddComponent<PhysicsProp>(); ((GrabbableObject)val4).itemProperties = val; ((GrabbableObject)val4).grabbable = true; val.spawnPrefab = val2; val2.tag = "PhysicsProp"; val2.layer = LayerMask.NameToLayer("Props"); val3.layer = LayerMask.NameToLayer("Props"); try { GameObject val5 = Object.Instantiate<GameObject>(Items.scanNodePrefab, val2.transform); ((Object)val5).name = "ScanNode"; val5.transform.localPosition = new Vector3(0f, 0f, 0f); Transform transform = val5.transform; transform.localScale *= 2f; ScanNodeProperties component = val5.GetComponent<ScanNodeProperties>(); component.nodeType = 1; component.headerText = "Error"; component.subText = "A mod is incompatible with Buyable Knife"; } catch (Exception ex) { LoggerInstance.LogError((object)ex.ToString()); } val2.transform.localScale = Vector3.one / 2f; return val; } private static GameObject CloneNonScrap(Item original, Item clone, int price) { GameObject val = NetworkPrefabs.CloneNetworkPrefab(original.spawnPrefab, (string)null); Object.DontDestroyOnLoad((Object)(object)val); CopyFields(original, clone); val.GetComponent<GrabbableObject>().itemProperties = clone; clone.spawnPrefab = val; ((Object)clone).name = "Buyable" + ((Object)original).name; clone.creditsWorth = price; return val; } public static void CopyFields(Item source, Item destination) { FieldInfo[] fields = typeof(Item).GetFields(); FieldInfo[] array = fields; foreach (FieldInfo fieldInfo in array) { fieldInfo.SetValue(destination, fieldInfo.GetValue(source)); } } private static TerminalNode CreateInfoNode(string name, string description) { if (infoNodes.ContainsKey(name)) { return infoNodes[name]; } TerminalNode val = ScriptableObject.CreateInstance<TerminalNode>(); Object.DontDestroyOnLoad((Object)(object)val); val.clearPreviousText = true; ((Object)val).name = name + "InfoNode"; val.displayText = description + "\n\n"; infoNodes.Add(name, val); return val; } private static void OnSceneLoaded(Scene scene, LoadSceneMode mode) { LoggerInstance.LogInfo((object)("Scene \"" + ((Scene)(ref scene)).name + "\" loaded with " + ((object)(LoadSceneMode)(ref mode)).ToString() + " mode.")); if (!((Object)(object)Knife == (Object)null) && !((Object)(object)KnifeObjectClone != (Object)null)) { KnifeObjectClone = CloneNonScrap(Knife, KnifeClone, KnifePrice); } } private static void AddToShop() { Item knifeClone = KnifeClone; int knifePrice = KnifePrice; Items.RegisterShopItem(knifeClone, (TerminalNode)null, (TerminalNode)null, CreateInfoNode("Knife", "Kitchen Knife. Can be used to stab enemies or your teammates for the hell of it."), knifePrice); LoggerInstance.LogInfo((object)$"Knife added to Shop for {KnifePrice} credits"); } }