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 MergeScrap v1.4.0
MergeScrap.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.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using GameNetcodeStuff; using HarmonyLib; using Unity.Netcode; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Controls; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("MergeScrap")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("MergeScrap")] [assembly: AssemblyCopyright("Copyright © 2024")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("8fcfabc9-318d-47a6-93f3-f97a04be27e3")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("1.0.0.0")] namespace MergeScrap; internal static class Config { public static KeyControl mergeKey = Keyboard.current.mKey; public static string IgnoreItemNames = string.Empty; private static string keyDisplayNames; private static bool isBind; public static void Bind() { //IL_001f: Unknown result type (might be due to invalid IL or missing references) if (!isBind) { isBind = true; keyDisplayNames = string.Join(", ", ((IEnumerable<KeyControl>)(object)Keyboard.current.allKeys).Select((KeyControl x) => ((InputControl)x).displayName)); mergeKey = BindKey("按键配置", "合并按键", Keyboard.current.nKey, "按键对应字符串参考: " + keyDisplayNames); IgnoreItemNames = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<string>("配置", "忽略列表", string.Empty, "合并时需要忽略的物品,多个物品使用英文逗号隔开,例如:金条,金杯 \n具体物品中文名称请参考汉化配置文件").Value; } } private static KeyControl BindKey(string section, string key, KeyControl defaultValue, string configDescription = null) { try { ConfigEntry<string> val = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<string>(section, key, ((InputControl)defaultValue).displayName, configDescription); KeyControl val2 = Keyboard.current.FindKeyOnCurrentKeyboardLayout(val.Value); if (val2 != null) { return val2; } Plugin.Log.LogWarning((object)("合并废料按键设置失败!" + key + ":" + val.Value)); return defaultValue; } catch (Exception ex) { Plugin.Log.LogWarning((object)("合并废料按键设置失败!" + ex.Message)); return defaultValue; } } } internal static class MergeScrap { private static List<string> IgnoreItemNameList = new List<string>(); public static void Merge() { GameObject val = GameObject.Find("/Environment/HangarShip"); GrabbableObject[] componentsInChildren = val.GetComponentsInChildren<GrabbableObject>(); Dictionary<string, GrabbableObject> dictionary = new Dictionary<string, GrabbableObject>(); IgnoreItemNameList = Config.IgnoreItemNames.Split(new char[1] { ',' }).ToList(); foreach (GrabbableObject val2 in componentsInChildren) { if (Ckeck(val2)) { if (dictionary.ContainsKey(val2.itemProperties.itemName)) { GrabbableObject val3 = dictionary[val2.itemProperties.itemName]; val3.SetScrapValue(val3.scrapValue + val2.scrapValue); ((NetworkBehaviour)val2).NetworkObject.Despawn(true); } else { dictionary[val2.itemProperties.itemName] = val2; } } } StartOfRound.Instance.SyncShipUnlockablesServerRpc(); Plugin.Log.LogInfo((object)"完成废料合并!"); } private static bool Ckeck(GrabbableObject obj) { if (!obj.itemProperties.isScrap) { return false; } if (obj.isHeld) { return false; } if (obj.heldByPlayerOnServer) { return false; } if (IgnoreItemNameList.Contains(obj.itemProperties.itemName)) { return false; } return true; } } [HarmonyPatch(typeof(PlayerControllerB))] internal class PlayerControllerB_Patch { [HarmonyPatch("Update")] [HarmonyPostfix] private static void UpdatePostfix(PlayerControllerB __instance) { if (((NetworkBehaviour)__instance).IsOwner && ((NetworkBehaviour)__instance).IsServer) { Config.Bind(); if (((ButtonControl)Config.mergeKey).wasPressedThisFrame) { MergeScrap.Merge(); } } } } [BepInPlugin("qh3.MergeScrap", "MergeScrap", "1.0.0")] public class Plugin : BaseUnityPlugin { public static Plugin Instance; private static readonly Harmony harmony = new Harmony("qh3.StealWeapon"); internal static ManualLogSource Log = Logger.CreateLogSource("qh3.StealWeapon"); private void Awake() { Log.LogInfo((object)"Loading BigMap Mod"); Instance = this; harmony.PatchAll(typeof(PlayerControllerB_Patch)); } }