Some mods may be broken due to the recent Alloyed Collective update.
Decompiled source of TTATweaks v1.0.2
TTATweaks.dll
Decompiled a week 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.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using HG; using Microsoft.CodeAnalysis; using Newtonsoft.Json; using On.RoR2; using RiskOfOptions; using RiskOfOptions.OptionConfigs; using RiskOfOptions.Options; using RoR2; using TTATweaks.Tweaks; 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.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("TTATweaks")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+b864f1966df55112edc5a0c2bafd35d6de12b750")] [assembly: AssemblyProduct("TTATweaks")] [assembly: AssemblyTitle("TTATweaks")] [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 TTATweaks { public class Assets { public static AssetBundle assetBundle; public static Sprite icon; public static void Init() { GetAssetBundle(); icon = assetBundle.LoadAsset<Sprite>("icon"); } private static void GetAssetBundle() { using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("TTATweaks.ttatweaks"); if (stream != null) { assetBundle = AssetBundle.LoadFromStream(stream); } } } 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); } } public class Options { private static bool? _rooEnabled; public static bool rooEnabled { get { if (!_rooEnabled.HasValue) { _rooEnabled = Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions"); } return _rooEnabled.Value; } } public static ConfigEntry<bool> syncMinionItems { get; set; } public static ConfigEntry<bool> honorEliteMinions { get; set; } public static ConfigEntry<string> blacklistJson { get; set; } private static void BlacklistChanged() { try { Dictionary<string, string[]> jsonObject = JsonConvert.DeserializeObject<Dictionary<string, string[]>>("{" + blacklistJson.Value + "}"); SyncItems.blacklist = SyncItems.GenerateBlacklist(jsonObject); Log.Info("Blacklist valid!"); SyncItems.useCustomBlacklist = true; } catch (Exception ex) { if (ex is JsonReaderException || ex is JsonSerializationException) { Log.Warning("Blacklist currently invalid!"); } else { Log.Error(ex.ToString()); } SyncItems.useCustomBlacklist = false; } } public static void Init() { syncMinionItems = TTATweaks.config.Bind<bool>("General", "Sync Minion Items", true, "Whether or not minions share most of their owner's items (like Engi turrets)."); honorEliteMinions = TTATweaks.config.Bind<bool>("Artifact of Honor", "Elite Minions", true, "Whether or not minions spawn as a Tier 1 elite while Artifact of Honor is active."); blacklistJson = TTATweaks.config.Bind<string>("General", "Minion Item Blacklist", "\"all\":[\"MinorConstructOnKill\", \"DroneWeapons\", \"RoboBallBuddy\", \"FocusConvergence\", \"TitanGoldDuringTP\", \"TPHealingNova\", \"VoidMegaCrabItem\", \"BeetleGland\", \"WardOnLevel\", \"PhysicsProjectile\"]", "What items shouldn't be inherited by all or specific minions. Format example: `\"internal_enemy_name_1\":[\"internal_item_name_1\",\"internal_item_name_2\"], \"internal_enemy_name_2\":[\"internal_item_name_3\",\"internal_item_name_4\"]`"); blacklistJson.SettingChanged += delegate { BlacklistChanged(); }; if (rooEnabled) { RoOInit(); } } private static void RoOInit() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Expected O, but got Unknown //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Expected O, but got Unknown //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Expected O, but got Unknown //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Expected O, but got Unknown //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Expected O, but got Unknown ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(syncMinionItems, new CheckBoxConfig())); ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(honorEliteMinions, new CheckBoxConfig())); ModSettingsManager.AddOption((BaseOption)new StringInputFieldOption(blacklistJson, new InputFieldConfig())); ModSettingsManager.SetModDescription("Various tweaks relating to minions and the Artifact of Honor."); ModSettingsManager.SetModIcon(Assets.icon); } public static void OnLoadFinished() { BlacklistChanged(); } } [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInPlugin("mwmw.TTATweaks", "TTATweaks", "1.0.2")] public class TTATweaks : BaseUnityPlugin { public const string PluginGUID = "mwmw.TTATweaks"; public const string PluginAuthor = "mwmw"; public const string PluginName = "TTATweaks"; public const string PluginVersion = "1.0.2"; public static ConfigFile config; public static BaseUnityPlugin plugin; public void Awake() { Log.Init(((BaseUnityPlugin)this).Logger); config = ((BaseUnityPlugin)this).Config; plugin = (BaseUnityPlugin)(object)this; Assets.Init(); Options.Init(); HonorTweaks.Init(); SyncItems.Init(); RoR2Application.onLoadFinished = (Action)Delegate.Combine(RoR2Application.onLoadFinished, new Action(OnLoadFinished)); } private void OnLoadFinished() { Options.OnLoadFinished(); } } } namespace TTATweaks.Tweaks { public class HonorTweaks { private static Xoroshiro128Plus rng; public static void Init() { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown CharacterBody.onBodyStartGlobal += MinionsSpawnElite; rng = new Xoroshiro128Plus(RoR2Application.rng.nextUlong); } private static void MinionsSpawnElite(CharacterBody body) { //IL_009c: Unknown result type (might be due to invalid IL or missing references) if (Options.honorEliteMinions.Value && NetworkServer.active && CombatDirector.IsEliteOnlyArtifactActive() && Object.op_Implicit((Object)(object)body) && ((Object)((Component)body).gameObject).name != "EquipmentDroneBody(Clone)") { CharacterMaster master = body.master; MinionOwnership val = ((master != null) ? ((Component)master).GetComponent<MinionOwnership>() : null); if ((Object)(object)val != (Object)null && !body.isElite && (Object)(object)val.ownerMaster != (Object)null) { EliteDef randomAvailableEliteDef = CombatDirector.eliteTiers[2].GetRandomAvailableEliteDef(rng); master.inventory.SetEquipmentIndex(randomAvailableEliteDef.eliteEquipmentDef.equipmentIndex, false); master.inventory.GiveItemPermanent(Items.BoostHp, Mathf.RoundToInt((randomAvailableEliteDef.healthBoostCoefficient - 1f) * 10f)); master.inventory.GiveItemPermanent(Items.BoostDamage, Mathf.RoundToInt(randomAvailableEliteDef.damageBoostCoefficient - 1f) * 10); } } } } public static class SyncItems { private class MirrorSource : MonoBehaviour { public event Action<ItemIndex, int> onItemGiven; public event Action<EquipmentState> onEquipmentGiven; public void InvokeItemGivenEvent(ItemIndex item, int count) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) this.onItemGiven?.Invoke(item, count); } public void InvokeEquipGivenEvent(EquipmentState equipmentState) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) this.onEquipmentGiven?.Invoke(equipmentState); } } private class MirrorLink : MonoBehaviour { private MirrorSource mirrorSource; private Inventory droneInventory; public void Init(MirrorSource mirrorSource, Inventory droneInventory) { this.droneInventory = droneInventory; this.mirrorSource = mirrorSource; if (Object.op_Implicit((Object)(object)mirrorSource)) { mirrorSource.onItemGiven += OnOwnerGetItem; mirrorSource.onEquipmentGiven += OnOwnerGetEquip; } } private void OnOwnerGetItem(ItemIndex item, int amount) { //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0044: 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) if (NetworkServer.active && Object.op_Implicit((Object)(object)mirrorSource) && Object.op_Implicit((Object)(object)droneInventory)) { droneInventory.ChangeItemStacksCount<GiveItemPermanentImpl>(new GiveItemPermanentImpl { inventory = droneInventory }, item, ItemFilter(item, ((Object)droneInventory).name) ? amount : 0); } } private void OnOwnerGetEquip(EquipmentState equipmentState) { if (NetworkServer.active && Object.op_Implicit((Object)(object)mirrorSource) && Object.op_Implicit((Object)(object)droneInventory)) { SetToOwnerEquip(((Component)mirrorSource).GetComponent<Inventory>(), droneInventory); } } private void OnDestroy() { if (Object.op_Implicit((Object)(object)mirrorSource)) { mirrorSource.onItemGiven -= OnOwnerGetItem; } } } [CompilerGenerated] private static class <>O { public static Action<CharacterMaster> <0>__LinkAllies; public static hook_Add <1>__FireItemGetEvent; public static hook_SetEquipmentInternal_EquipmentState_uint_uint <2>__FireEquipmentGetEvent; public static hook_UpdateMinionInventory <3>__AddDevotionInventoryBack; public static Func<ItemIndex, string, bool> <4>__ItemFilter; } public static Dictionary<string, HashSet<string>> blacklist; public static Dictionary<string, HashSet<string>> defaultBlacklist; public const string defaultBlacklistString = "\"all\":[\"MinorConstructOnKill\", \"DroneWeapons\", \"RoboBallBuddy\", \"FocusConvergence\", \"TitanGoldDuringTP\", \"TPHealingNova\", \"VoidMegaCrabItem\", \"BeetleGland\", \"WardOnLevel\", \"PhysicsProjectile\"]"; public static bool useCustomBlacklist; private const BindingFlags allFlags = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; public static void Init() { //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_003d: Expected O, but got Unknown //IL_0053: 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) //IL_005e: Expected O, but got Unknown //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Expected O, but got Unknown CharacterMaster.onStartGlobal += LinkAllies; object obj = <>O.<1>__FireItemGetEvent; if (obj == null) { hook_Add val = FireItemGetEvent; <>O.<1>__FireItemGetEvent = val; obj = (object)val; } GiveItemPermanentImpl.Add += (hook_Add)obj; object obj2 = <>O.<2>__FireEquipmentGetEvent; if (obj2 == null) { hook_SetEquipmentInternal_EquipmentState_uint_uint val2 = FireEquipmentGetEvent; <>O.<2>__FireEquipmentGetEvent = val2; obj2 = (object)val2; } Inventory.SetEquipmentInternal_EquipmentState_uint_uint += (hook_SetEquipmentInternal_EquipmentState_uint_uint)obj2; object obj3 = <>O.<3>__AddDevotionInventoryBack; if (obj3 == null) { hook_UpdateMinionInventory val3 = AddDevotionInventoryBack; <>O.<3>__AddDevotionInventoryBack = val3; obj3 = (object)val3; } DevotionInventoryController.UpdateMinionInventory += (hook_UpdateMinionInventory)obj3; defaultBlacklist = GenerateBlacklist(JsonConvert.DeserializeObject<Dictionary<string, string[]>>("{\"all\":[\"MinorConstructOnKill\", \"DroneWeapons\", \"RoboBallBuddy\", \"FocusConvergence\", \"TitanGoldDuringTP\", \"TPHealingNova\", \"VoidMegaCrabItem\", \"BeetleGland\", \"WardOnLevel\", \"PhysicsProjectile\"]}")); } public static Dictionary<string, HashSet<string>> GenerateBlacklist(Dictionary<string, string[]> jsonObject) { Dictionary<string, HashSet<string>> dictionary = new Dictionary<string, HashSet<string>>(); foreach (KeyValuePair<string, string[]> item in jsonObject) { dictionary[item.Key] = new HashSet<string>(item.Value); } return dictionary; } private static void LinkAllies(CharacterMaster master) { if (NetworkServer.active && Options.syncMinionItems.Value && NetworkServer.active && Object.op_Implicit((Object)(object)master) && Object.op_Implicit((Object)(object)master.inventory)) { MinionOwnership component = ((Component)master).GetComponent<MinionOwnership>(); if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.ownerMaster) && (Object)(object)component.ownerMaster.playerCharacterMasterController != (Object)null && !Object.op_Implicit((Object)(object)((Component)master).GetComponent<MirrorLink>())) { ((MonoBehaviour)TTATweaks.plugin).StartCoroutine(DeferredLink(master)); } } } private static IEnumerator DeferredLink(CharacterMaster master) { yield return null; object obj; if (master == null) { obj = null; } else { MinionOwnership component = ((Component)master).GetComponent<MinionOwnership>(); obj = ((component != null) ? component.ownerMaster : null); } CharacterMaster ownerMaster = (CharacterMaster)obj; Inventory ownerInventory = ((ownerMaster != null) ? ownerMaster.inventory : null); Inventory droneInventory = master.inventory; if (!((Object)(object)ownerInventory == (Object)null) && !((Object)(object)droneInventory == (Object)null)) { MirrorSource mirrorSource = ((ownerInventory != null) ? ((Component)ownerInventory).GetComponent<MirrorSource>() : null); if ((Object)(object)mirrorSource == (Object)null) { mirrorSource = ((Component)ownerInventory).gameObject.AddComponent<MirrorSource>(); } ((Component)master).gameObject.AddComponent<MirrorLink>().Init(mirrorSource, droneInventory); AddFullOwnerInventory(ownerInventory, droneInventory); } } private static void FireItemGetEvent(orig_Add orig, ref GiveItemPermanentImpl self, ItemIndex itemIndex, int countToAdd) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) orig.Invoke(ref self, itemIndex, countToAdd); MirrorSource component = ((Component)self.inventory).GetComponent<MirrorSource>(); if (Object.op_Implicit((Object)(object)component)) { component.InvokeItemGivenEvent(itemIndex, countToAdd); } } private static bool FireEquipmentGetEvent(orig_SetEquipmentInternal_EquipmentState_uint_uint orig, Inventory self, EquipmentState equipmentState, uint slot, uint set) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) bool result = orig.Invoke(self, equipmentState, slot, set); MirrorSource component = ((Component)self).GetComponent<MirrorSource>(); if (Object.op_Implicit((Object)(object)component)) { component.InvokeEquipGivenEvent(equipmentState); } return result; } private static void AddDevotionInventoryBack(orig_UpdateMinionInventory orig, DevotionInventoryController self, DevotedLemurianController devotedLemurianController, bool shouldEvolve) { orig.Invoke(self, devotedLemurianController, shouldEvolve); MirrorLink component = ((Component)devotedLemurianController).GetComponent<MirrorLink>(); CharacterMaster lemurianMaster = devotedLemurianController._lemurianMaster; object obj; if (lemurianMaster == null) { obj = null; } else { MinionOwnership minionOwnership = lemurianMaster.minionOwnership; if (minionOwnership == null) { obj = null; } else { CharacterMaster ownerMaster = minionOwnership.ownerMaster; obj = ((ownerMaster != null) ? ownerMaster.inventory : null); } } Inventory ownerInventory = (Inventory)obj; if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)devotedLemurianController.LemurianInventory)) { AddFullOwnerInventory(ownerInventory, devotedLemurianController.LemurianInventory); } } private static void AddFullOwnerInventory(Inventory ownerInventory, Inventory minionInventory) { SetToOwnerEquip(ownerInventory, minionInventory); minionInventory.AddItemsFrom(ownerInventory, ItemFilter); } private static void SetToOwnerEquip(Inventory ownerInventory, Inventory minionInventory) { if (Object.op_Implicit((Object)(object)ownerInventory) && Object.op_Implicit((Object)(object)minionInventory) && !CombatDirector.IsEliteOnlyArtifactActive() && ((Object)((Component)minionInventory).gameObject).name != "EquipmentDroneMaster(Clone)") { minionInventory.CopyEquipmentFrom(ownerInventory, true); } } public static void AddItemsFrom(this Inventory owner, Inventory other, Func<ItemIndex, string, bool> bodyFilter) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0068: 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) if (!NetworkServer.active) { Debug.LogWarning((object)"[Server] function 'System.Void RoR2.Inventory::AddItemsFrom(RoR2.Inventory,System.Func`2<RoR2.ItemIndex,System.Boolean>)' called on client"); return; } InventoryChangeScope val = default(InventoryChangeScope); ((InventoryChangeScope)(ref val))..ctor(owner); try { List<ItemIndex> list = default(List<ItemIndex>); DisposableRental<ItemIndex, List<ItemIndex>> val2 = CollectionPool<ItemIndex, List<ItemIndex>>.RentCollection(ref list); try { ((ItemCollection)(ref other.permanentItemStacks)).GetNonZeroIndices(list); foreach (ItemIndex item in list) { owner.ChangeItemStacksCount<GiveItemPermanentImpl>(new GiveItemPermanentImpl { inventory = owner }, item, bodyFilter(item, ((Object)owner).name) ? ((ItemCollection)(ref other.permanentItemStacks)).GetStackValue(item) : 0); } } finally { val2.Dispose(); } } finally { ((InventoryChangeScope)(ref val)).Dispose(); } } public static bool ItemFilter(ItemIndex itemIndex, string masterName) { //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) if (masterName.EndsWith("Master(Clone)")) { masterName = masterName.Substring(0, masterName.Length - "Master(Clone)".Length); } if (useCustomBlacklist) { if (blacklist.TryGetValue("all", out var value) && value.Contains(((Object)ItemCatalog.GetItemDef(itemIndex)).name)) { return false; } if (blacklist.TryGetValue(masterName, out value) && value.Contains(((Object)ItemCatalog.GetItemDef(itemIndex)).name)) { return false; } return true; } return !defaultBlacklist["all"].Contains(((Object)ItemCatalog.GetItemDef(itemIndex)).name); } } }