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 ScrapMore v1.3.0
plugins/ScrapMore/ScrapMore.dll
Decompiled a year agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Logging; using Microsoft.CodeAnalysis; using MonoMod.RuntimeDetour; using On.RoR2; using RoR2; using UnityEngine; using UnityEngine.AddressableAssets; using UnityEngine.Events; using UnityEngine.Networking; using UnityEngine.ResourceManagement.AsyncOperations; using UnityEngine.UI; [assembly: AssemblyTitle("ScrapMore")] [assembly: AssemblyProduct("ScrapMore")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyCompany("ScrapMore")] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: CompilationRelaxations(8)] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] [module: UnverifiableCode] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] [Microsoft.CodeAnalysis.Embedded] [CompilerGenerated] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace ScrapMore { internal static class Log { private static ManualLogSource _logSource; internal static void Init(ManualLogSource logSource) { _logSource = logSource; } internal static void Debug(object data) { _logSource.LogDebug(data); } internal static void Error(object data) { _logSource.LogError(data); } internal static void Fatal(object data) { _logSource.LogFatal(data); } internal static void Info(object data) { _logSource.LogInfo(data); } internal static void Message(object data) { _logSource.LogMessage(data); } internal static void Warning(object data) { _logSource.LogWarning(data); } } [BepInPlugin("Rude.ScrapMore", "ScrapMore", "1.0.0")] public class ScrapMorePlugin : BaseUnityPlugin { public const string PluginGUID = "Rude.ScrapMore"; public const string PluginAuthor = "Rude"; public const string PluginName = "ScrapMore"; public const string PluginVersion = "1.0.0"; private static Hook overrideHook; private Queue<QueuedScrapOperation> scrapQueue = new Queue<QueuedScrapOperation>(); private int scrapAmount = 0; public void Start() { } public void Awake() { Log.Init(((BaseUnityPlugin)this).Logger); Log.Info("Initiated logger"); AddNetworkBehaviour(); HookScrapping(); HookWindow(); } public void Update() { if (scrapQueue.Count > 0) { Log.Info("Scrap queue contains item"); QueuedScrapOperation queuedScrapOperation = scrapQueue.Peek(); Log.Info($"Scrap amount we want: {scrapAmount}; Scrap amount we have: {queuedScrapOperation.scrapper.maxItemsToScrapAtATime}"); if (queuedScrapOperation.scrapper.maxItemsToScrapAtATime == scrapAmount) { Log.Info("Doing scrap"); scrapQueue.Dequeue().doScrap(); } } } private void AddNetworkBehaviour() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) AsyncOperationHandle<GameObject> val = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Core/PlayerMaster.prefab"); val.Completed += delegate(AsyncOperationHandle<GameObject> obj) { if (Object.op_Implicit((Object)(object)obj.Result)) { obj.Result.AddComponent<ShareScrapperAmount>(); } }; } private void createSlider(Transform canvasTransform, int maxItems) { //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Expected O, but got Unknown //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Expected O, but got Unknown //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Expected O, but got Unknown //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: 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) //IL_01f0: Unknown result type (might be due to invalid IL or missing references) //IL_0213: Unknown result type (might be due to invalid IL or missing references) //IL_021a: Expected O, but got Unknown //IL_0243: Unknown result type (might be due to invalid IL or missing references) //IL_025a: Unknown result type (might be due to invalid IL or missing references) //IL_0271: Unknown result type (might be due to invalid IL or missing references) //IL_0288: Unknown result type (might be due to invalid IL or missing references) //IL_02b8: Unknown result type (might be due to invalid IL or missing references) //IL_02bf: Expected O, but got Unknown //IL_02df: Unknown result type (might be due to invalid IL or missing references) //IL_02ff: Unknown result type (might be due to invalid IL or missing references) //IL_03a8: Unknown result type (might be due to invalid IL or missing references) //IL_03af: Expected O, but got Unknown //IL_03d3: Unknown result type (might be due to invalid IL or missing references) //IL_03ea: Unknown result type (might be due to invalid IL or missing references) //IL_0439: Unknown result type (might be due to invalid IL or missing references) GameObject val2 = new GameObject("MyManualSlider", new Type[4] { typeof(RectTransform), typeof(CanvasRenderer), typeof(Image), typeof(Slider) }); val2.transform.SetParent(canvasTransform, false); RectTransform component = val2.GetComponent<RectTransform>(); component.sizeDelta = new Vector2(400f, 20f); component.anchoredPosition = new Vector2(0f, 450f); Image component2 = val2.GetComponent<Image>(); ((Graphic)component2).color = new Color(0f, 0f, 0f, 0.5f); GameObject val3 = new GameObject("Fill Area", new Type[1] { typeof(RectTransform) }); val3.transform.SetParent(val2.transform, false); RectTransform component3 = val3.GetComponent<RectTransform>(); component3.anchorMin = new Vector2(0f, 0f); component3.anchorMax = new Vector2(1f, 1f); component3.offsetMin = new Vector2(5f, 5f); component3.offsetMax = new Vector2(-5f, -5f); GameObject val4 = new GameObject("Fill", new Type[2] { typeof(RectTransform), typeof(Image) }); val4.transform.SetParent(val3.transform, false); Image component4 = val4.GetComponent<Image>(); ((Graphic)component4).color = Color.white; RectTransform component5 = val4.GetComponent<RectTransform>(); component5.anchorMin = new Vector2(0f, 0f); component5.anchorMax = new Vector2(1f, 1f); component5.offsetMin = Vector2.zero; component5.offsetMax = Vector2.zero; GameObject val5 = new GameObject("Handle Slide Area", new Type[1] { typeof(RectTransform) }); val5.transform.SetParent(val2.transform, false); RectTransform component6 = val5.GetComponent<RectTransform>(); component6.anchorMin = new Vector2(0f, 0f); component6.anchorMax = new Vector2(1f, 1f); component6.offsetMin = new Vector2(5f, 5f); component6.offsetMax = new Vector2(-5f, -5f); GameObject val6 = new GameObject("Handle", new Type[2] { typeof(RectTransform), typeof(Image) }); val6.transform.SetParent(val5.transform, false); Image component7 = val6.GetComponent<Image>(); ((Graphic)component7).color = Color.white; RectTransform component8 = val6.GetComponent<RectTransform>(); component8.sizeDelta = new Vector2(20f, 20f); Slider component9 = val2.GetComponent<Slider>(); component9.fillRect = component5; component9.handleRect = component8; ((Selectable)component9).targetGraphic = (Graphic)(object)component7; component9.direction = (Direction)0; component9.minValue = 1f; component9.maxValue = Math.Max(10, maxItems); component9.value = 10f; component9.wholeNumbers = true; ((Selectable)component9).interactable = true; GameObject val7 = new GameObject("ScrapAmountText", new Type[3] { typeof(RectTransform), typeof(CanvasRenderer), typeof(Text) }); val7.transform.SetParent(canvasTransform, false); RectTransform component10 = val7.GetComponent<RectTransform>(); component10.sizeDelta = new Vector2(300f, 30f); component10.anchoredPosition = new Vector2(0f, 470f); Text scrapAmountText = val7.GetComponent<Text>(); scrapAmountText.font = Resources.GetBuiltinResource<Font>("Arial.ttf"); scrapAmountText.fontSize = 18; scrapAmountText.alignment = (TextAnchor)4; ((Graphic)scrapAmountText).color = Color.white; scrapAmountText.text = $"Scrap amount: {component9.value}"; ((UnityEvent<float>)(object)component9.onValueChanged).AddListener((UnityAction<float>)delegate(float val) { scrapAmount = Mathf.RoundToInt(val); scrapAmountText.text = $"Scrap amount: {scrapAmount}"; }); } private void changeScrapperAmount(ScrapperController scrapperController, int amount) { LocalUser firstLocalUser = LocalUserManager.GetFirstLocalUser(); if (firstLocalUser != null && (Object)(object)firstLocalUser.cachedMaster != (Object)null) { ((Component)firstLocalUser.cachedMaster).GetComponent<ShareScrapperAmount>().ChangeScrapperAmount(((Component)scrapperController).gameObject, amount); } } private void HookScrapping() { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown ScrapperController.BeginScrapping += (hook_BeginScrapping)delegate(orig_BeginScrapping orig, ScrapperController self, int activator) { ((object)orig).GetType(); changeScrapperAmount(self, scrapAmount); QueuedScrapOperation item = new QueuedScrapOperation(delegate { orig.Invoke(self, activator); }, self, scrapAmount); scrapQueue.Enqueue(item); }; } private void HookWindow() { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Expected O, but got Unknown MethodInfo method = typeof(PickupPickerController).GetMethod("OnDisplayBegin", BindingFlags.Instance | BindingFlags.NonPublic); MethodInfo method2 = typeof(ScrapMorePlugin).GetMethod("OnDisplayBegin", BindingFlags.Instance | BindingFlags.NonPublic); overrideHook = new Hook((MethodBase)method, method2, (object)this); } private void OnDisplayBegin(Action<PickupPickerController, NetworkUIPromptController, LocalUser, CameraRigController> orig, PickupPickerController self, NetworkUIPromptController networkUIPromptController, LocalUser localUser, CameraRigController cameraRigController) { orig(self, networkUIPromptController, localUser, cameraRigController); Transform canvasTransform = ((Component)self.panelInstanceController).transform.Find("MainPanel"); Inventory inventory = LocalUserManager.GetFirstLocalUser().cachedMasterController.master.inventory; scrapAmount = 10; createSlider(canvasTransform, inventory.itemStacks.Max()); Log.Info("Created game object"); } } internal class ShareScrapperAmount : NetworkBehaviour { private static int kCmdCmdChangeScrapperAmount; private static int kRpcRpcChangeScrapperAmount; public void ChangeScrapperAmount(GameObject scrapper, int amount) { if (NetworkServer.active) { CallRpcChangeScrapperAmount(scrapper, amount); } else { CallCmdChangeScrapperAmount(scrapper, amount); } } [Command] private void CmdChangeScrapperAmount(GameObject scrapper, int amount) { Log.Info($"Client changing scrapper amount on {((Object)scrapper).name} to {amount}"); CallRpcChangeScrapperAmount(scrapper, amount); } [ClientRpc] private void RpcChangeScrapperAmount(GameObject scrapper, int amount) { Log.Info($"Server changing scrapper amount on {((Object)scrapper).name} to {amount}"); ChangeScrapperAmountInternal(scrapper, amount); } private void ChangeScrapperAmountInternal(GameObject scrapper, int amount) { if ((Object)(object)scrapper == (Object)null) { Log.Error("Error: Scrapper game object is null"); } ScrapperController component = scrapper.GetComponent<ScrapperController>(); if ((Object)(object)component == (Object)null) { Log.Error("Error: Game object " + ((Object)scrapper).name + " is not a valid scrapper"); } component.maxItemsToScrapAtATime = amount; } private void UNetVersion() { } protected static void InvokeCmdCmdChangeScrapperAmount(NetworkBehaviour obj, NetworkReader reader) { if (!NetworkServer.active) { Debug.LogError((object)"Command CmdChangeScrapperAmount called on client."); } else { ((ShareScrapperAmount)(object)obj).CmdChangeScrapperAmount(reader.ReadGameObject(), (int)reader.ReadPackedUInt32()); } } public void CallCmdChangeScrapperAmount(GameObject scrapper, int amount) { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Expected O, but got Unknown //IL_005c: Unknown result type (might be due to invalid IL or missing references) if (!NetworkClient.active) { Debug.LogError((object)"Command function CmdChangeScrapperAmount called on server."); return; } if (((NetworkBehaviour)this).isServer) { CmdChangeScrapperAmount(scrapper, amount); return; } NetworkWriter val = new NetworkWriter(); val.Write((short)0); val.Write((short)5); val.WritePackedUInt32((uint)kCmdCmdChangeScrapperAmount); val.Write(((Component)this).GetComponent<NetworkIdentity>().netId); val.Write(scrapper); val.WritePackedUInt32((uint)amount); ((NetworkBehaviour)this).SendCommandInternal(val, 0, "CmdChangeScrapperAmount"); } protected static void InvokeRpcRpcChangeScrapperAmount(NetworkBehaviour obj, NetworkReader reader) { if (!NetworkClient.active) { Debug.LogError((object)"RPC RpcChangeScrapperAmount called on server."); } else { ((ShareScrapperAmount)(object)obj).RpcChangeScrapperAmount(reader.ReadGameObject(), (int)reader.ReadPackedUInt32()); } } public void CallRpcChangeScrapperAmount(GameObject scrapper, int amount) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown //IL_0041: Unknown result type (might be due to invalid IL or missing references) if (!NetworkServer.active) { Debug.LogError((object)"RPC Function RpcChangeScrapperAmount called on client."); return; } NetworkWriter val = new NetworkWriter(); val.Write((short)0); val.Write((short)2); val.WritePackedUInt32((uint)kRpcRpcChangeScrapperAmount); val.Write(((Component)this).GetComponent<NetworkIdentity>().netId); val.Write(scrapper); val.WritePackedUInt32((uint)amount); ((NetworkBehaviour)this).SendRPCInternal(val, 0, "RpcChangeScrapperAmount"); } static ShareScrapperAmount() { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Expected O, but got Unknown //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Expected O, but got Unknown kCmdCmdChangeScrapperAmount = -700044649; NetworkBehaviour.RegisterCommandDelegate(typeof(ShareScrapperAmount), kCmdCmdChangeScrapperAmount, new CmdDelegate(InvokeCmdCmdChangeScrapperAmount)); kRpcRpcChangeScrapperAmount = -1824389267; NetworkBehaviour.RegisterRpcDelegate(typeof(ShareScrapperAmount), kRpcRpcChangeScrapperAmount, new CmdDelegate(InvokeRpcRpcChangeScrapperAmount)); NetworkCRC.RegisterBehaviour("ShareScrapperAmount", 0); } public override bool OnSerialize(NetworkWriter writer, bool forceAll) { bool result = default(bool); return result; } public override void OnDeserialize(NetworkReader reader, bool initialState) { } } internal class QueuedScrapOperation { public readonly Action doScrap; public readonly ScrapperController scrapper; public readonly int scrapAmount; public QueuedScrapOperation(Action doScrap, ScrapperController scrapper, int scrapAmount) { this.doScrap = doScrap; this.scrapper = scrapper; this.scrapAmount = scrapAmount; } } }