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 DeadPlayerCatchup v3.0.0
plugins/DeadPlayerCatchup.dll
Decompiled 3 weeks agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using Microsoft.CodeAnalysis; using On.RoR2; using RoR2; 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("DeadPlayerCatchup")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("3.0.0.0")] [assembly: AssemblyInformationalVersion("3.0.0")] [assembly: AssemblyProduct("DeadPlayerCatchup")] [assembly: AssemblyTitle("DeadPlayerCatchup")] [assembly: AssemblyVersion("3.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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; } } } [BepInPlugin("com.yourname.deadplayercatchup", "DeadPlayerCatchup", "3.0.0")] public class DeadPlayerCatchupPlugin : BaseUnityPlugin { private class RarityCounter { public int Count; public bool FirstAwarded; } private class PlayerCatchupState { public int LastStageIndex = -1; public readonly Dictionary<ItemTier, RarityCounter> Counters = new Dictionary<ItemTier, RarityCounter>(); } private readonly Dictionary<CharacterMaster, PlayerCatchupState> playerStates = new Dictionary<CharacterMaster, PlayerCatchupState>(); private readonly HashSet<ShopTerminalBehavior> suppressMachineDrops = new HashSet<ShopTerminalBehavior>(); public void Awake() { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown GenericPickupController.AttemptGrant += new hook_AttemptGrant(OnAttemptGrant); PurchaseInteraction.OnInteractionBegin += new hook_OnInteractionBegin(OnPurchaseInteractionBegin); ShopTerminalBehavior.DropPickup += new hook_DropPickup(OnShopTerminalDropPickup); GlobalEventManager.onCharacterDeathServer += OnCharacterDeath; Run.onRunStartGlobal += OnRunStart; ((BaseUnityPlugin)this).Logger.LogInfo((object)"DeadPlayerCatchup loaded!"); } private void OnRunStart(Run run) { playerStates.Clear(); suppressMachineDrops.Clear(); } private void OnCharacterDeath(DamageReport report) { if (report != null && !((Object)(object)report.victimMaster == (Object)null)) { CharacterMaster victimMaster = report.victimMaster; if (!((Object)(object)victimMaster.playerCharacterMasterController == (Object)null)) { playerStates.Remove(victimMaster); } } } private void OnAttemptGrant(orig_AttemptGrant orig, GenericPickupController self, CharacterBody body) { //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0049: 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_0074: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Invalid comparison between Unknown and I4 //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Invalid comparison between Unknown and I4 //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) orig.Invoke(self, body); if ((Object)(object)self == (Object)null || (Object)(object)body == (Object)null || (Object)(object)body.inventory == (Object)null || self.pickupIndex == PickupIndex.none) { return; } PickupDef pickupDef = PickupCatalog.GetPickupDef(self.pickupIndex); if (pickupDef == null || (int)pickupDef.equipmentIndex != -1) { return; } ItemIndex itemIndex = pickupDef.itemIndex; if ((int)itemIndex != -1) { ItemDef itemDef = ItemCatalog.GetItemDef(itemIndex); if (IsAllowedItem(itemDef)) { GiveRandomSameTierItemsToDeadPlayers(body.inventory, itemDef.tier); } } } private void OnPurchaseInteractionBegin(orig_OnInteractionBegin orig, PurchaseInteraction self, Interactor activator) { //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Invalid comparison between Unknown and I4 //IL_00d3: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)self == (Object)null || (Object)(object)activator == (Object)null) { orig.Invoke(self, activator); return; } ShopTerminalBehavior component = ((Component)self).GetComponent<ShopTerminalBehavior>(); if ((Object)(object)component == (Object)null) { orig.Invoke(self, activator); return; } if (!IsPrinterScrapperOrCauldronCost(self.costType)) { orig.Invoke(self, activator); return; } CharacterBody component2 = ((Component)activator).GetComponent<CharacterBody>(); if ((Object)(object)component2 == (Object)null || (Object)(object)component2.inventory == (Object)null) { orig.Invoke(self, activator); return; } PickupIndex pickupIndex = component.CurrentPickup().pickupIndex; PickupDef pickupDef = PickupCatalog.GetPickupDef(pickupIndex); if (pickupDef != null && (int)pickupDef.itemIndex != -1) { component2.inventory.GiveItemPermanent(pickupDef.itemIndex, 1); } suppressMachineDrops.Add(component); orig.Invoke(self, activator); } private void OnShopTerminalDropPickup(orig_DropPickup orig, ShopTerminalBehavior self) { if ((Object)(object)self != (Object)null && suppressMachineDrops.Contains(self)) { suppressMachineDrops.Remove(self); } else { orig.Invoke(self); } } private bool IsPrinterScrapperOrCauldronCost(CostTypeIndex costType) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Expected I4, but got Unknown int num = (int)costType; return num == 4 || num == 5 || num == 6 || num == 9 || num == 10; } private void GiveRandomSameTierItemsToDeadPlayers(Inventory pickerInventory, ItemTier tier) { //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_0175: 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_017c: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Invalid comparison between Unknown and I4 //IL_0190: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) int alivePlayerCount = GetAlivePlayerCount(); if (alivePlayerCount <= 0) { return; } int num = (((Object)(object)Run.instance != (Object)null) ? Run.instance.stageClearCount : (-1)); foreach (CharacterMaster readOnlyInstances in CharacterMaster.readOnlyInstancesList) { if ((Object)(object)readOnlyInstances == (Object)null || (Object)(object)readOnlyInstances.inventory == (Object)null || (Object)(object)readOnlyInstances.inventory == (Object)(object)pickerInventory || !IsDeadOrRemoteOperationPlayer(readOnlyInstances)) { continue; } if (!playerStates.TryGetValue(readOnlyInstances, out var value)) { value = new PlayerCatchupState(); playerStates[readOnlyInstances] = value; } if (value.LastStageIndex != num) { value.LastStageIndex = num; value.Counters.Clear(); } if (!value.Counters.TryGetValue(tier, out var value2)) { value2 = new RarityCounter(); value.Counters[tier] = value2; } value2.Count++; int num2 = ((!value2.FirstAwarded) ? 1 : alivePlayerCount); if (value2.Count >= num2) { value2.Count = 0; value2.FirstAwarded = true; ItemIndex randomItemFromTier = GetRandomItemFromTier(tier); if ((int)randomItemFromTier != -1) { readOnlyInstances.inventory.GiveItemPermanent(randomItemFromTier, 1); SendPickupMessage(randomItemFromTier); } } } } private int GetAlivePlayerCount() { int num = 0; foreach (PlayerCharacterMasterController instance in PlayerCharacterMasterController.instances) { if (!((Object)(object)instance == (Object)null) && !((Object)(object)instance.master == (Object)null) && !IsDeadOrRemoteOperationPlayer(instance.master)) { num++; } } return num; } private bool IsAllowedItem(ItemDef itemDef) { //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Invalid comparison between Unknown and I4 //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Invalid comparison between Unknown and I4 //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Invalid comparison between Unknown and I4 //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Invalid comparison between Unknown and I4 //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Invalid comparison between Unknown and I4 //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Invalid comparison between Unknown and I4 //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Invalid comparison between Unknown and I4 //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Invalid comparison between Unknown and I4 if ((Object)(object)itemDef == (Object)null) { return false; } if (itemDef.hidden) { return false; } if (((Object)itemDef).name.ToLowerInvariant().Contains("scrap")) { return false; } if ((int)itemDef.tier == 3) { return false; } if ((int)itemDef.tier == 6 || (int)itemDef.tier == 7 || (int)itemDef.tier == 8 || (int)itemDef.tier == 9) { return false; } if (itemDef.ContainsTag((ItemTag)13)) { return false; } string text = ((Object)itemDef).name.ToLowerInvariant(); if (text.Contains("temporary") || text.Contains("temp")) { return false; } return (int)itemDef.tier == 0 || (int)itemDef.tier == 1 || (int)itemDef.tier == 2 || (int)itemDef.tier == 4; } private bool IsDeadOrRemoteOperationPlayer(CharacterMaster master) { if ((Object)(object)master == (Object)null) { return false; } if ((Object)(object)master.playerCharacterMasterController == (Object)null) { return false; } if (!master.hasBody) { return true; } CharacterBody body = master.GetBody(); if ((Object)(object)body == (Object)null) { return true; } string text = ((Object)body).name.ToLowerInvariant(); return text.Contains("drone") || text.Contains("turret") || text.Contains("beetleguard") || text.Contains("equipmentdrone") || text.Contains("emergencydrone") || text.Contains("flamedrone") || text.Contains("missiledrone") || text.Contains("megadrone") || text.Contains("roboball") || text.Contains("squidturret"); } private unsafe ItemIndex GetRandomItemFromTier(ItemTier tier) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: 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_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) List<ItemIndex> list = new List<ItemIndex>(); GenericStaticEnumerable<ItemIndex, AllItemsEnumerator> allItems = ItemCatalog.allItems; AllItemsEnumerator enumerator = allItems.GetEnumerator(); try { while (((AllItemsEnumerator)(ref enumerator)).MoveNext()) { ItemIndex current = ((AllItemsEnumerator)(ref enumerator)).Current; ItemDef itemDef = ItemCatalog.GetItemDef(current); if (IsAllowedItem(itemDef) && itemDef.tier == tier) { list.Add(current); } } } finally { ((IDisposable)(*(AllItemsEnumerator*)(&enumerator))/*cast due to .constrained prefix*/).Dispose(); } if (list.Count == 0) { return (ItemIndex)(-1); } int index = Random.Range(0, list.Count); return list[index]; } private void SendPickupMessage(ItemIndex itemIndex) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Expected O, but got Unknown ItemDef itemDef = ItemCatalog.GetItemDef(itemIndex); if (!((Object)(object)itemDef == (Object)null)) { string text = Language.GetString(itemDef.nameToken); if (string.IsNullOrEmpty(text)) { text = ((Object)itemDef).name; } Chat.SendBroadcastChat((ChatMessageBase)new SimpleChatMessage { baseToken = "<color=#7CFF95>A dead player received " + text + "</color>" }); } } }