Some mods may be broken due to the recent Alloyed Collective update.
Decompiled source of ReturnsDroneRevive v1.0.1
plugins/ReturnsDroneRevive/ReturnsDroneRevive.dll
Decompiled 2 years agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using Microsoft.CodeAnalysis; using On.RoR2; using R2API; using RoR2; using UnityEngine; using UnityEngine.Networking; [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.0", FrameworkDisplayName = ".NET Standard 2.0")] [assembly: AssemblyCompany("ReturnsDroneRevive")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("ReturnsDroneRevive")] [assembly: AssemblyTitle("ReturnsDroneRevive")] [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 ReturnsDroneRevive { internal class InventoryManager { private static ItemDef droneCompartmentItem; public InventoryManager(string filePath) { CreateItem(filePath); } private static void CreateItem(string filePath) { //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Expected O, but got Unknown //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Expected O, but got Unknown droneCompartmentItem = ScriptableObject.CreateInstance<ItemDef>(); ((Object)droneCompartmentItem).name = "DRONECOMPARTMENT_NAME"; droneCompartmentItem.nameToken = "DRONECOMPARTMENT_NAME"; droneCompartmentItem.pickupToken = "DRONECOMPARTMENT_PICKUP"; droneCompartmentItem.descriptionToken = "DRONECOMPARTMENT_DESC"; droneCompartmentItem.loreToken = "DRONECOMPARTMENT_LORE"; droneCompartmentItem.deprecatedTier = (ItemTier)5; AssetBundle val = AssetBundle.LoadFromFile(filePath); Sprite pickupIconSprite = val.LoadAsset<Sprite>("Assets/chest.png"); droneCompartmentItem.pickupIconSprite = pickupIconSprite; droneCompartmentItem.canRemove = false; droneCompartmentItem.hidden = false; ItemDisplayRuleDict val2 = new ItemDisplayRuleDict((ItemDisplayRule[])null); ItemAPI.Add(new CustomItem(droneCompartmentItem, val2)); } public void StoreDroneCollectedItem(ReturnsDroneRevive.PlayerStorage playerStorage) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: 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_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) ItemIndex val = playerStorage.playerInstance.inventory.itemAcquisitionOrder[1]; for (int i = 0; i < playerStorage.savedInventory.Count; i++) { if (playerStorage.savedInventory[i] == val) { playerStorage.savedInventoryStacks[i]++; playerStorage.playerInstance.inventory.RemoveItem(val, 1); return; } } playerStorage.savedInventory.Add(val); playerStorage.savedInventoryStacks.Add(1); playerStorage.playerInstance.inventory.RemoveItem(val, 1); } public void SaveAndRemoveInventory(ReturnsDroneRevive.PlayerStorage playerStorage) { //IL_0036: 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_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) int count = playerStorage.playerInstance.inventory.itemAcquisitionOrder.Count; for (int i = 0; i < count; i++) { playerStorage.savedInventory.Add(playerStorage.playerInstance.inventory.itemAcquisitionOrder[0]); playerStorage.savedInventoryStacks.Add(playerStorage.playerInstance.inventory.GetItemCount(playerStorage.savedInventory[i])); for (int j = 0; j < playerStorage.savedInventoryStacks[i]; j++) { playerStorage.playerInstance.inventory.RemoveItem(playerStorage.savedInventory[i], 1); } } playerStorage.playerInstance.inventory.GiveItem(droneCompartmentItem.itemIndex, 1); } public void AddBackInventory(ReturnsDroneRevive.PlayerStorage playerStorage) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) playerStorage.playerInstance.inventory.RemoveItem(droneCompartmentItem.itemIndex, 1); for (int i = 0; i < playerStorage.savedInventory.Count; i++) { for (int j = 0; j < playerStorage.savedInventoryStacks[i]; j++) { playerStorage.playerInstance.inventory.GiveItem(playerStorage.savedInventory[i], 1); } } playerStorage.savedInventory.Clear(); playerStorage.savedInventoryStacks.Clear(); } public void ResetRegenScrap(ReturnsDroneRevive.PlayerStorage playerStorage) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) playerStorage.playerInstance.inventory.GiveItem(ItemCatalog.FindItemIndex("RegeneratingScrap"), playerStorage.playerInstance.inventory.GetItemCount(ItemCatalog.FindItemIndex("RegeneratingScrapConsumed"))); playerStorage.playerInstance.inventory.RemoveItem(ItemCatalog.FindItemIndex("RegeneratingScrapConsumed"), playerStorage.playerInstance.inventory.GetItemCount(ItemCatalog.FindItemIndex("RegeneratingScrapConsumed"))); } } 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); } } [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInPlugin("Hyenate.ReturnsDroneRevive", "ReturnsDroneRevive", "1.0.0")] public class ReturnsDroneRevive : BaseUnityPlugin { public class PlayerStorage { public CharacterMaster playerInstance = null; public GameObject savedCharacterBody = null; public List<ItemIndex> savedInventory = new List<ItemIndex>(); public List<int> savedInventoryStacks = new List<int>(); } public const string PluginGUID = "Hyenate.ReturnsDroneRevive"; public const string PluginAuthor = "Hyenate"; public const string PluginName = "ReturnsDroneRevive"; public const string PluginVersion = "1.0.0"; public List<PlayerStorage> playerStorage = new List<PlayerStorage>(); private static InventoryManager inventoryManager; private static ConfigFile configFile; private static ConfigEntry<bool> disableInventory; public void Awake() { Log.Init(((BaseUnityPlugin)this).Logger); SetFromConfig(); if (disableInventory.Value) { inventoryManager = new InventoryManager(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "dronereviveassets")); } Run.onRunStartGlobal += Run_onRunStartGlobal; Log.Info("Awake done."); } private void Run_onRunStartGlobal(Run obj) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Expected O, but got Unknown if (NetworkServer.active) { Stage.onServerStageBegin += Stage_onServerStageBegin; GlobalEventManager.OnPlayerCharacterDeath += new hook_OnPlayerCharacterDeath(OnPlayerDeath); } } private void SetFromConfig() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown configFile = new ConfigFile(Paths.ConfigPath + "//ReturnsDroneRevive.cfg", true); disableInventory = configFile.Bind<bool>("DroneRevive", "Disable Inventory as Drone", true, "All collected items will be disabled as a drone. Items are returned next stage."); } private void Stage_onServerStageBegin(Stage obj) { ResetToCharacters(); } private void OnPlayerDeath(orig_OnPlayerCharacterDeath orig, GlobalEventManager self, DamageReport damagereport, NetworkUser networkuser) { orig.Invoke(self, damagereport, networkuser); Log.Info("Player has died: " + ((Object)networkuser.master.bodyPrefab).name); if (!((Object)networkuser.master.bodyPrefab).name.Equals("Drone1Body")) { PlayerStorage playerStorage = new PlayerStorage(); playerStorage.playerInstance = networkuser.master; playerStorage.savedCharacterBody = networkuser.master.bodyPrefab; this.playerStorage.Add(playerStorage); ((MonoBehaviour)this).StartCoroutine(TrySpawnAsDrone(playerStorage)); } } private void DroneInventoryChanged() { if (!disableInventory.Value) { return; } for (int i = 0; i < playerStorage.Count; i++) { if (playerStorage[i].playerInstance.inventory.itemAcquisitionOrder.Count > 1) { inventoryManager.StoreDroneCollectedItem(playerStorage[i]); } } } private IEnumerator TrySpawnAsDrone(PlayerStorage deadPlayer) { Log.Info("Attempting to Spawn as Drone"); yield return (object)new WaitForSeconds(1.5f); int num = ((!((Object)(object)deadPlayer.playerInstance == (Object)null) && (((Object)(object)deadPlayer.playerInstance != (Object)null) ? new bool?(deadPlayer.playerInstance.IsDeadAndOutOfLivesServer()) : null) == false) ? 1 : 0); if (num != 0 || Run.instance.isGameOverServer) { Log.Info("Player is not out of lives"); } else { SpawnAsDrone(deadPlayer.playerInstance.deathFootPosition, deadPlayer); } } private void SpawnAsDrone(Vector3 spawnPosition, PlayerStorage deadPlayer) { //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0069: 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) Log.Info("Spawning as Drone"); if (disableInventory.Value) { inventoryManager.SaveAndRemoveInventory(deadPlayer); deadPlayer.playerInstance.inventory.onInventoryChanged += DroneInventoryChanged; } deadPlayer.playerInstance.bodyPrefab = BodyCatalog.GetBodyPrefab(BodyCatalog.FindBodyIndex("Drone1Body")); ChangePlayerPrefab(deadPlayer.playerInstance, spawnPosition); deadPlayer.playerInstance.bodyPrefab = deadPlayer.savedCharacterBody; } private void ResetToCharacters() { Log.Info("Resetting character bodies"); for (int i = 0; i < playerStorage.Count; i++) { if ((Object)(object)playerStorage[i].playerInstance != (Object)null) { playerStorage[i].playerInstance.bodyPrefab = playerStorage[i].savedCharacterBody; if (disableInventory.Value) { playerStorage[i].playerInstance.inventory.onInventoryChanged -= DroneInventoryChanged; inventoryManager.AddBackInventory(playerStorage[i]); inventoryManager.ResetRegenScrap(playerStorage[i]); } } } playerStorage.Clear(); } private void ChangePlayerPrefab(CharacterMaster master, Vector3 spawnPosition, Quaternion spawnRotation = default(Quaternion)) { //IL_0011: 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) PlayerCharacterMasterController playerCharacterMasterController = master.playerCharacterMasterController; master.playerCharacterMasterController = null; master.Respawn(spawnPosition, spawnRotation); master.playerCharacterMasterController = playerCharacterMasterController; } } }