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 AutoLootDistribution v1.0.0
AutoLootDistribution.dll
Decompiled 2 days ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using EntityStates; using EntityStates.Drifter; using EntityStates.Drifter.Hoard; using EntityStates.Drone.DroneJunk; using EntityStates.DroneScrapper; using EntityStates.ExtractorUnit; using EntityStates.MealPrep; using EntityStates.Mimic; using EntityStates.Missions.RepurposedCrater; using EntityStates.Scrapper; using EntityStates.SolusVendorShrine; using H1xl.Shared; using MonoMod.RuntimeDetour; using RiskOfOptions; using RiskOfOptions.OptionConfigs; using RiskOfOptions.Options; using RoR2; using RoR2.Artifacts; using RoR2.Items; using RoR2.Orbs; using RoR2.Projectile; using UnityEngine; using UnityEngine.Networking; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("AutoLootDistribution")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+ce506a003f6b860f69637908a165c39e5efa07f9")] [assembly: AssemblyProduct("AutoLootDistribution")] [assembly: AssemblyTitle("AutoLootDistribution")] [assembly: AssemblyVersion("1.0.0.0")] namespace H1xl.Shared { internal static class Log { private static ManualLogSource source; private static readonly HashSet<string> logged = new HashSet<string>(); internal static Func<bool> IsVerbose = null; internal static bool Verbose { get { if (IsVerbose != null) { return IsVerbose(); } return false; } } internal static void Init(ManualLogSource logger) { source = logger; } internal static void Info(object message) { ManualLogSource obj = source; if (obj != null) { obj.LogInfo(message); } } internal static void Warn(object message) { ManualLogSource obj = source; if (obj != null) { obj.LogWarning(message); } } internal static void Error(object message) { ManualLogSource obj = source; if (obj != null) { obj.LogError(message); } } internal static void Debug(object message) { if (Verbose) { ManualLogSource obj = source; if (obj != null) { obj.LogInfo(message); } } } internal static bool ErrorOnce(string key, object message) { if (!logged.Add(key)) { return false; } ManualLogSource obj = source; if (obj != null) { obj.LogError(message); } return true; } internal static bool WarnOnce(string key, object message) { if (!logged.Add(key)) { return false; } ManualLogSource obj = source; if (obj != null) { obj.LogWarning(message); } return true; } } internal static class HookUtil { private static readonly List<Hook> hooks = new List<Hook>(); internal static bool Add(GameMethod method, Type handlerType, string handler) { //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Expected O, but got Unknown MethodInfo methodInfo = method.Find(); if (methodInfo == null) { Log.Warn($"{method} not found (game updated?). The feature using it is disabled."); return false; } MethodInfo method2 = handlerType.GetMethod(handler, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (method2 == null) { Log.Error($"Hook handler {handlerType.Name}.{handler} not found (mod bug). {method} is not hooked."); return false; } try { hooks.Add(new Hook((MethodBase)methodInfo, method2)); return true; } catch (Exception arg) { Log.Error($"Failed to hook {method}: {arg}"); return false; } } internal static void DisposeAll() { foreach (Hook hook in hooks) { hook.Dispose(); } hooks.Clear(); } } internal abstract class GameMember { internal const BindingFlags Any = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; internal readonly Type Type; internal readonly string Name; protected GameMember(Type type, string name) { Type = type; Name = name; } internal abstract MemberInfo FindMember(); internal static Type Nested(Type outer, string name) { return outer.GetNestedType(name, BindingFlags.Public | BindingFlags.NonPublic); } public override string ToString() { return (Type?.Name ?? "<missing type>") + "." + Name; } } internal sealed class GameMethod : GameMember { internal readonly Type[] Args; internal GameMethod(Type type, string name, params Type[] args) : base(type, name) { Args = args; } internal MethodInfo Find() { try { return Type?.GetMethod(Name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, Args, null); } catch (Exception) { return null; } } internal override MemberInfo FindMember() { return Find(); } } internal sealed class GameField : GameMember { internal GameField(Type type, string name) : base(type, name) { } internal FieldInfo Find() { try { return Type?.GetField(Name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); } catch (Exception) { return null; } } internal override MemberInfo FindMember() { return Find(); } } internal sealed class GameProperty : GameMember { internal GameProperty(Type type, string name) : base(type, name) { } internal PropertyInfo Find() { try { return Type?.GetProperty(Name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); } catch (Exception) { return null; } } internal override MemberInfo FindMember() { return Find(); } } internal static class SharedGameMembers { internal static readonly GameField PickupTransferOrb_orbEffectPrefab = new GameField(typeof(PickupTransferOrb), "orbEffectPrefab"); internal static readonly GameMethod DynamicBone_SetupParticles = new GameMethod(typeof(DynamicBone), "SetupParticles"); internal static readonly GameMethod DynamicBone_InitTransforms = new GameMethod(typeof(DynamicBone), "InitTransforms"); internal static readonly GameMethod DynamicBone_ResetParticlesPosition = new GameMethod(typeof(DynamicBone), "ResetParticlesPosition"); internal static readonly GameMethod DynamicBone_UpdateDynamicBones = new GameMethod(typeof(DynamicBone), "UpdateDynamicBones", typeof(float)); } internal static class RooPage { internal const string GUID = "com.rune580.riskofoptions"; internal static void TryRegister(Action register) { if (!Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions")) { return; } try { register(); } catch (Exception ex) { Log.Error("Risk Of Options page failed: " + ex); } } } internal static class RooHelper { internal static void Page(string description, string pluginFolder) { ModSettingsManager.SetModDescription(description); Sprite val = LoadIcon(Path.Combine(pluginFolder, "icon.png")); if (Object.op_Implicit((Object)(object)val)) { ModSettingsManager.SetModIcon(val); } } internal static void CheckBox(ConfigEntry<bool> entry, IsDisabledDelegate disabled = null) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(entry, new CheckBoxConfig { checkIfDisabled = disabled })); } internal static void Choice(ConfigEntryBase entry, IsDisabledDelegate disabled = null) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown ModSettingsManager.AddOption((BaseOption)new ChoiceOption(entry, new ChoiceConfig { checkIfDisabled = disabled })); } internal static void Key(ConfigEntry<KeyboardShortcut> entry) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Expected O, but got Unknown ModSettingsManager.AddOption((BaseOption)new KeyBindOption(entry)); } internal static void IntSlider(ConfigEntry<int> entry, int min, int max, string format = "{0}", IsDisabledDelegate disabled = null) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: 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_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Expected O, but got Unknown //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown ModSettingsManager.AddOption((BaseOption)new IntSliderOption(entry, new IntSliderConfig { min = min, max = max, formatString = format, checkIfDisabled = disabled })); } internal static void Slider(ConfigEntry<float> entry, float min, float max, float step, string format, IsDisabledDelegate disabled = null) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: 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_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001b: 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) //IL_0030: Expected O, but got Unknown //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Expected O, but got Unknown ModSettingsManager.AddOption((BaseOption)new StepSliderOption(entry, new StepSliderConfig { min = min, max = max, increment = step, FormatString = format, checkIfDisabled = disabled })); } internal static void Text(ConfigEntry<string> entry, IsDisabledDelegate disabled = null) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //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_0019: Expected O, but got Unknown //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected O, but got Unknown ModSettingsManager.AddOption((BaseOption)new StringInputFieldOption(entry, new InputFieldConfig { submitOn = (SubmitEnum)6, checkIfDisabled = disabled })); } private static Sprite LoadIcon(string path) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Expected O, but got Unknown //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) if (!File.Exists(path)) { return null; } Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false); if (!ImageConversion.LoadImage(val, File.ReadAllBytes(path))) { return null; } return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f)); } } internal sealed class ItemFlightOrb : ItemTransferOrb { internal PickupIndex iconPickup = PickupIndex.none; internal Action<EffectData> decorate; internal Action<bool> deliver; internal bool done; public override void Begin() { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Invalid comparison between Unknown and I4 //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0067: 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_0073: 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) //IL_0096: Expected O, but got Unknown GameObject val = (((PickupIndex)(ref iconPickup)).isValid ? ItemFlight.PickupOrbEffect : null); if (!Object.op_Implicit((Object)(object)val)) { if ((int)base.itemIndex != -1) { ((ItemTransferOrb)this).Begin(); } else { ((Orb)this).duration = base.travelDuration; } return; } ((Orb)this).duration = base.travelDuration; if (Object.op_Implicit((Object)(object)((Orb)this).target) || Object.op_Implicit((Object)(object)base.orbEffectTargetObjectOverride)) { EffectData val2 = new EffectData { origin = ((Orb)this).origin, genericFloat = ((Orb)this).duration, genericUInt = Util.IntToUintPlusOne(iconPickup.value) }; if (Object.op_Implicit((Object)(object)base.orbEffectTargetObjectOverride)) { val2.SetNetworkedObjectReference(((Component)base.orbEffectTargetObjectOverride).gameObject); } else { val2.SetHurtBoxReference(((Orb)this).target); } decorate?.Invoke(val2); EffectManager.SpawnEffect(val, val2, true); } } public override void OnArrival() { ItemFlight.Arrive(this, stageEnding: false); } } internal static class ItemFlight { private static readonly List<ItemFlightOrb> inFlight = new List<ItemFlightOrb>(64); private static readonly FieldInfo pickupOrbEffectField = SharedGameMembers.PickupTransferOrb_orbEffectPrefab.Find(); private static GameObject pickupOrbEffect; internal static bool PickupOrbEffectFound => pickupOrbEffectField != null; internal static GameObject PickupOrbEffect { get { if (!Object.op_Implicit((Object)(object)pickupOrbEffect) && pickupOrbEffectField != null) { object? value = pickupOrbEffectField.GetValue(null); pickupOrbEffect = (GameObject)((value is GameObject) ? value : null); } return pickupOrbEffect; } } internal static Vector3 DropPoint(CharacterBody body, Vector3 fallback) { //IL_000b: 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_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_0008: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)body)) { return fallback; } return body.footPosition + Vector3.up * 1.5f; } internal static void Launch(ItemFlightOrb orb, CharacterMaster recipient, float travelTime, bool animate, Action<bool> deliver) { orb.deliver = deliver; if (!animate || !Object.op_Implicit((Object)(object)OrbManager.instance)) { Arrive(orb, stageEnding: false); return; } ((ItemTransferOrb)orb).travelDuration = travelTime; CharacterBody val = (Object.op_Implicit((Object)(object)recipient) ? recipient.GetBody() : null); if (Object.op_Implicit((Object)(object)val)) { if (Object.op_Implicit((Object)(object)val.mainHurtBox)) { ((Orb)orb).target = val.mainHurtBox; } else { ((ItemTransferOrb)orb).orbEffectTargetObjectOverride = val.networkIdentity; } } inFlight.Add(orb); try { OrbManager.instance.AddOrb((Orb)(object)orb); } catch (Exception ex) { Log.Error("Item orb failed to start, delivering at once: " + ex); Arrive(orb, stageEnding: false); } } internal static void FlushAll() { if (inFlight.Count != 0) { ItemFlightOrb[] array = inFlight.ToArray(); inFlight.Clear(); for (int num = array.Length - 1; num >= 0; num--) { Arrive(array[num], stageEnding: true); } } } internal static void Arrive(ItemFlightOrb orb, bool stageEnding) { if (orb.done) { return; } orb.done = true; int num = inFlight.IndexOf(orb); if (num >= 0) { int index = inFlight.Count - 1; inFlight[num] = inFlight[index]; inFlight.RemoveAt(index); } try { orb.deliver?.Invoke(stageEnding); } catch (Exception ex) { Log.Error("Item delivery failed: " + ex); } } } } namespace AutoLootDistribution { public enum CubeIcon { None, White, Green, Red, Yellow, Lunar, Equipment, Hallowed, Hex, Page, VoidWhite, VoidGreen, VoidRed, VoidYellow } internal static class CubeIcons { public const float Marker = 7331001f; private static readonly string[] FileNames = new string[14] { null, "white", "green", "red", "yellow", "lunar", "equipment", "hallowed", "hex", "page", "void_white", "void_green", "void_red", "void_yellow" }; private static readonly Texture2D[] textures = (Texture2D[])(object)new Texture2D[FileNames.Length]; private static readonly Sprite[] sprites = (Sprite[])(object)new Sprite[FileNames.Length]; public static bool CommandEnabled { get { if (Object.op_Implicit((Object)(object)RunArtifactManager.instance)) { return CommandArtifactManager.IsCommandArtifactEnabled; } return false; } } public static void Load(string pluginFolder) { //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007a: 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_008a: Expected O, but got Unknown Dictionary<string, string> dictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); string[] files = Directory.GetFiles(pluginFolder, "cube_*.png", SearchOption.AllDirectories); foreach (string text in files) { if (!dictionary.ContainsKey(Path.GetFileName(text))) { dictionary[Path.GetFileName(text)] = text; } } int num = 0; for (int j = 1; j < FileNames.Length; j++) { if (dictionary.TryGetValue("cube_" + FileNames[j] + ".png", out var value)) { Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false) { wrapMode = (TextureWrapMode)1, filterMode = (FilterMode)1 }; if (ImageConversion.LoadImage(val, File.ReadAllBytes(value))) { textures[j] = val; num++; } } } if (num < FileNames.Length - 1) { Log.Warn($"Command cube icons: {num} of {FileNames.Length - 1} loaded from {pluginFolder}; missing ones keep the vanilla icon."); } } public static CubeIcon For(PickupDef def) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Invalid comparison between Unknown and I4 //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Expected I4, but got Unknown //IL_000a: Unknown result type (might be due to invalid IL or missing references) if ((int)def.equipmentIndex != -1) { EquipmentDef equipmentDef = EquipmentCatalog.GetEquipmentDef(def.equipmentIndex); if (!Object.op_Implicit((Object)(object)equipmentDef) || !equipmentDef.isLunar) { return CubeIcon.Equipment; } return CubeIcon.Lunar; } ItemTier itemTier = def.itemTier; return (int)itemTier switch { 0 => CubeIcon.White, 1 => CubeIcon.Green, 2 => CubeIcon.Red, 4 => CubeIcon.Yellow, 3 => CubeIcon.Lunar, 10 => CubeIcon.Equipment, 11 => CubeIcon.Hallowed, 13 => CubeIcon.Hex, 12 => CubeIcon.Page, 6 => CubeIcon.VoidWhite, 7 => CubeIcon.VoidGreen, 8 => CubeIcon.VoidRed, 9 => CubeIcon.VoidYellow, _ => CubeIcon.None, }; } public static void Mark(EffectData data, CubeIcon icon) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) data.genericBool = true; data.start = new Vector3(7331001f, (float)icon, 0f); } public static CubeIcon Read(EffectData data) { if (data == null || !data.genericBool || data.start.x != 7331001f) { return CubeIcon.None; } int num = Mathf.RoundToInt(data.start.y); if (num <= 0 || num >= FileNames.Length) { return CubeIcon.None; } return (CubeIcon)num; } public static Sprite GetSprite(CubeIcon icon, Sprite like) { //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_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) Texture2D val = textures[(int)icon]; if (!Object.op_Implicit((Object)(object)val)) { return null; } if (!Object.op_Implicit((Object)(object)sprites[(int)icon])) { float num; if (!Object.op_Implicit((Object)(object)like)) { num = 1f; } else { Bounds bounds = like.bounds; num = ((Bounds)(ref bounds)).size.x; } float num2 = num; sprites[(int)icon] = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), (float)((Texture)val).width / num2); } return sprites[(int)icon]; } public static Color ColorOf(CubeIcon icon) { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003b: 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_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004c: 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_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0060: 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_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: 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_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: 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_00a5: Unknown result type (might be due to invalid IL or missing references) return (Color)(icon switch { CubeIcon.White => Color32.op_Implicit(ColorCatalog.GetColor((ColorIndex)1)), CubeIcon.Green => Color32.op_Implicit(ColorCatalog.GetColor((ColorIndex)2)), CubeIcon.Red => Color32.op_Implicit(ColorCatalog.GetColor((ColorIndex)3)), CubeIcon.Yellow => Color32.op_Implicit(ColorCatalog.GetColor((ColorIndex)13)), CubeIcon.Lunar => Color32.op_Implicit(ColorCatalog.GetColor((ColorIndex)4)), CubeIcon.Equipment => Color32.op_Implicit(ColorCatalog.GetColor((ColorIndex)5)), CubeIcon.Hallowed => Color32.op_Implicit(ColorCatalog.GetColor((ColorIndex)34)), CubeIcon.Hex => Color32.op_Implicit(ColorCatalog.GetColor((ColorIndex)35)), CubeIcon.Page => Color32.op_Implicit(ColorCatalog.GetColor((ColorIndex)38)), _ => Color32.op_Implicit(ColorCatalog.GetColor((ColorIndex)25)), }); } } internal sealed class CubeIconSwapper : MonoBehaviour { private PickupTakenOrbEffect effect; private EffectComponent effectComponent; private Color trailStart; private Color trailEnd; public static void Attach(PickupTakenOrbEffect effect) { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) CubeIconSwapper cubeIconSwapper = default(CubeIconSwapper); if (!((Component)effect).TryGetComponent<CubeIconSwapper>(ref cubeIconSwapper)) { cubeIconSwapper = ((Component)effect).gameObject.AddComponent<CubeIconSwapper>(); cubeIconSwapper.effect = effect; cubeIconSwapper.effectComponent = ((Component)effect).GetComponent<EffectComponent>(); if (Object.op_Implicit((Object)(object)effect.trailToColor)) { cubeIconSwapper.trailStart = effect.trailToColor.startColor; cubeIconSwapper.trailEnd = effect.trailToColor.endColor; } } if (Settings.CommandIcons && CubeIcons.CommandEnabled) { ((MonoBehaviour)cubeIconSwapper).StartCoroutine(cubeIconSwapper.Run()); } } private IEnumerator Run() { yield return null; yield return null; CubeIcon icon = CubeIcons.Read(Object.op_Implicit((Object)(object)effectComponent) ? effectComponent.effectData : null); if (icon == CubeIcon.None || !Settings.CommandIcons || !CubeIcons.CommandEnabled) { yield break; } SpriteRenderer renderer = effect.iconSpriteRenderer; if (!Object.op_Implicit((Object)(object)renderer)) { yield break; } for (int i = 0; i < 30; i++) { if (Object.op_Implicit((Object)(object)renderer.sprite)) { break; } yield return null; } Sprite sprite = CubeIcons.GetSprite(icon, renderer.sprite); if (!Object.op_Implicit((Object)(object)sprite)) { yield break; } renderer.sprite = sprite; if (Log.Verbose) { Log.Info($"Command cube icon shown: {icon}"); } Color val = CubeIcons.ColorOf(icon); if (Object.op_Implicit((Object)(object)effect.trailToColor)) { effect.trailToColor.startColor = trailStart * val; effect.trailToColor.endColor = trailEnd * val; } ParticleSystem[] particlesToColor = effect.particlesToColor; foreach (ParticleSystem val2 in particlesToColor) { if (Object.op_Implicit((Object)(object)val2)) { MainModule main = val2.main; ((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(val); } } SpriteRenderer[] spritesToColor = effect.spritesToColor; foreach (SpriteRenderer val3 in spritesToColor) { if (Object.op_Implicit((Object)(object)val3)) { val3.color = val; } } while (true) { if ((Object)(object)renderer.sprite != (Object)(object)sprite) { renderer.sprite = sprite; } yield return null; } } } internal sealed class Loot { public Vector3 origin; public ItemIndex itemIndex; public UniquePickup pickup; public CharacterMaster recipient; public int tierSlot; public bool commandCube; public bool recycled; public bool duplicated; public ChestBehavior chest; public Vector3? lastRecipientPosition; public CreatePickupInfo cubeInfo; public bool counted; } internal static class Distributor { public static bool SpawningOwnDroplet; public static bool HandedOver; private static int roundRobin; private static PickupIndex scrapWhite = PickupIndex.none; private static PickupIndex scrapGreen = PickupIndex.none; private static PickupIndex scrapRed = PickupIndex.none; private static PickupIndex scrapYellow = PickupIndex.none; private static PickupIndex strangeWhite = PickupIndex.none; private static PickupIndex strangeGreen = PickupIndex.none; private static PickupIndex strangeRed = PickupIndex.none; private static PickupIndex fuelArray = PickupIndex.none; private static readonly Dictionary<CharacterMaster, int[]> pending = new Dictionary<CharacterMaster, int[]>(); private static readonly List<(CreatePickupInfo info, CharacterMaster recipient)> carriedOver = new List<(CreatePickupInfo, CharacterMaster)>(); private static bool nextStageStarted; private static Candidate[] candidates = new Candidate[4]; private static readonly Func<int, int> randomBelow = (int n) => Random.Range(0, n); private const int TierSlots = 16; private const int EquipmentSlot = 16; public static void InitIcons() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: 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) //IL_0028: 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_0041: 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_0050: 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_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) scrapWhite = ItemPickup("ScrapWhite"); scrapGreen = ItemPickup("ScrapGreen"); scrapRed = ItemPickup("ScrapRed"); scrapYellow = ItemPickup("ScrapYellow"); strangeWhite = ItemPickup("ScrapWhiteSuppressed"); strangeGreen = ItemPickup("ScrapGreenSuppressed"); strangeRed = ItemPickup("ScrapRedSuppressed"); fuelArray = PickupCatalog.FindPickupIndex(EquipmentCatalog.FindEquipmentIndex("QuestVolatileBattery")); if (!ItemFlight.PickupOrbEffectFound) { Log.Warn("Pickup orb effect not found: command cubes will fly with their item's icon."); } } private static PickupIndex ItemPickup(string name) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) return PickupCatalog.FindPickupIndex(ItemCatalog.FindItemIndex(name)); } private static PickupIndex VanillaCubeIcon(PickupDef def, PickupIndex dropped) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Invalid comparison between Unknown and I4 //IL_001b: 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) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Expected I4, but got Unknown //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0056: 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_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0061: 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_006e: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_007d: 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_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: 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_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) PickupIndex result = PickupIndex.none; if ((int)def.equipmentIndex != -1) { result = fuelArray; } else { ItemTier itemTier = def.itemTier; switch ((int)itemTier) { case 0: result = scrapWhite; break; case 1: result = scrapGreen; break; case 2: result = scrapRed; break; case 4: case 9: result = scrapYellow; break; case 6: result = (((PickupIndex)(ref strangeWhite)).isValid ? strangeWhite : scrapWhite); break; case 7: result = (((PickupIndex)(ref strangeGreen)).isValid ? strangeGreen : scrapGreen); break; case 8: result = (((PickupIndex)(ref strangeRed)).isValid ? strangeRed : scrapRed); break; } } if (!((PickupIndex)(ref result)).isValid) { return dropped; } return result; } public static void Reset() { roundRobin = 0; pending.Clear(); carriedOver.Clear(); nextStageStarted = false; } public static void OnStageBegin() { nextStageStarted = true; } public static void SpawnCarriedOver() { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: 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) if (carriedOver.Count == 0 || !nextStageStarted || !NetworkServer.active) { return; } for (int num = carriedOver.Count - 1; num >= 0; num--) { (CreatePickupInfo info, CharacterMaster recipient) tuple = carriedOver[num]; CreatePickupInfo info = tuple.info; CharacterMaster item = tuple.recipient; PlayerCharacterMasterController val = (Object.op_Implicit((Object)(object)item) ? item.playerCharacterMasterController : null); CharacterBody val2 = ((!Object.op_Implicit((Object)(object)item) || (Settings.IgnoreDisconnected && Object.op_Implicit((Object)(object)val) && !val.isConnected)) ? AnyPlayerBody() : item.GetBody()); if (Object.op_Implicit((Object)(object)val2) && !Object.op_Implicit((Object)(object)val2.currentVehicle)) { carriedOver.RemoveAt(num); SpawnDroplet(in info, ItemFlight.DropPoint(val2, val2.footPosition)); } } } private static CharacterBody AnyPlayerBody() { foreach (PlayerCharacterMasterController instance in PlayerCharacterMasterController.instances) { CharacterBody val = ((Object.op_Implicit((Object)(object)instance) && Object.op_Implicit((Object)(object)instance.master)) ? instance.master.GetBody() : null); if (Object.op_Implicit((Object)(object)val) && !Object.op_Implicit((Object)(object)val.currentVehicle)) { return val; } } return null; } public static bool TryDistribute(Source source, CharacterMaster owner, in CreatePickupInfo info, Vector3 position) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: 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) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_003f: 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_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Invalid comparison between Unknown and I4 //IL_005d: 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_006c: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Invalid comparison between Unknown and I4 //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) DistributionMode distributionMode = Settings.ModeFor(source); if (distributionMode == DistributionMode.Disabled) { return false; } if (info.pickerOptions != null || Object.op_Implicit((Object)(object)info.prefabOverride)) { return false; } if ((info.artifactFlag & 2) != 0) { return false; } CreatePickupInfo val = info; UniquePickup pickup = ((CreatePickupInfo)(ref val)).pickup; PickupDef pickupDef = PickupCatalog.GetPickupDef(pickup.pickupIndex); if (pickupDef == null) { return false; } bool flag = (int)pickupDef.itemIndex != -1; bool flag2 = !pickup.ignoreArtifactBasedPickupReplacements && ((info.artifactFlag & 1) != 0 || CubeIcons.CommandEnabled); bool flag3 = source == Source.WanderingChef || source == Source.Drifter || source == Source.SolusExtractor; int num; if (!flag2) { if (flag) { num = ((flag3 ? (!ItemCatalog.GetItemDef(pickupDef.itemIndex).hidden) : Settings.IsItemAllowed(pickupDef.itemIndex)) ? 1 : 0); goto IL_00ec; } } else if (Settings.CommandToPlayer) { if (!flag) { num = (((int)pickupDef.equipmentIndex != -1) ? 1 : 0); } else { if (flag3) { goto IL_00f0; } num = (Settings.IsTierAllowed(pickupDef.itemIndex) ? 1 : 0); } goto IL_00ec; } goto IL_00ee; IL_00ee: return false; IL_00f0: ItemTier itemTier = pickupDef.itemTier; CharacterMaster val2 = ResolvePlayer(owner); bool equipment = !flag; CharacterMaster val3 = Choose(distributionMode, val2, position, itemTier, equipment); DistributionMode fallback = Settings.Fallback; bool flag4 = false; if (!Object.op_Implicit((Object)(object)val3) && fallback != DistributionMode.Disabled) { val3 = Choose(fallback, null, position, itemTier, equipment); flag4 = true; } if (!Object.op_Implicit((Object)(object)val3)) { return false; } if (source == Source.WanderingChef && !flag2 && Settings.ChefProtect && WouldBeCorrupted(val3, pickupDef.itemIndex)) { if (Log.Verbose) { Log.Info($"{source}: {pickupDef.internalName} left on the ground, " + val3.playerCharacterMasterController.GetDisplayName() + "'s void item would corrupt it"); } return false; } Send(val3, pickupDef.itemIndex, itemTier, pickup, position, flag2, in info); if (Log.Verbose) { string text = (Object.op_Implicit((Object)(object)val2) ? val2.playerCharacterMasterController.GetDisplayName() : "none"); Log.Info($"{source}: {pickupDef.internalName} -> {val3.playerCharacterMasterController.GetDisplayName()} " + string.Format("(mode {0}{1}, owner {2}{3})", distributionMode, flag4 ? (", fallback " + fallback) : "", text, flag2 ? ", command cube" : "")); } return true; IL_00ec: if (num == 0) { goto IL_00ee; } goto IL_00f0; } public static bool GiveChoice(CharacterMaster chooser, UniquePickup pickup, Vector3 origin, ChestBehavior chest) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: 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_0016: Invalid comparison between Unknown and I4 //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003b: 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_0041: 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) PickupDef pickupDef = PickupCatalog.GetPickupDef(pickup.pickupIndex); if (pickupDef == null || (int)pickupDef.itemIndex == -1) { return false; } CharacterMaster val = ResolvePlayer(chooser); if (!IsValid(val)) { return false; } pickup.ignoreArtifactBasedPickupReplacements = true; Send(val, pickupDef.itemIndex, pickupDef.itemTier, pickup, origin, cube: false, new CreatePickupInfo { chest = chest }); if (Log.Verbose) { Log.Info("Choice: " + pickupDef.internalName + " -> " + val.playerCharacterMasterController.GetDisplayName()); } return true; } private static bool WouldBeCorrupted(CharacterMaster player, ItemIndex item) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Invalid comparison between Unknown and I4 //IL_001e: Unknown result type (might be due to invalid IL or missing references) ItemIndex transformedItemIndex = ContagiousItemManager.GetTransformedItemIndex(item); if ((int)transformedItemIndex != -1 && Object.op_Implicit((Object)(object)player.inventory)) { return player.inventory.GetItemCountEffective(transformedItemIndex) > 0; } return false; } private static CharacterMaster ResolvePlayer(CharacterMaster master) { int num = 0; while (Object.op_Implicit((Object)(object)master) && num < 8) { if (Object.op_Implicit((Object)(object)master.playerCharacterMasterController)) { return master; } CharacterMaster val = (Object.op_Implicit((Object)(object)master.minionOwnership) ? master.minionOwnership.ownerMaster : null); if ((Object)(object)val == (Object)(object)master) { break; } master = val; num++; } return null; } private static bool IsValid(CharacterMaster m) { if (!Object.op_Implicit((Object)(object)m) || !Object.op_Implicit((Object)(object)m.inventory)) { return false; } PlayerCharacterMasterController playerCharacterMasterController = m.playerCharacterMasterController; if (!Object.op_Implicit((Object)(object)playerCharacterMasterController)) { return false; } if (Settings.IgnoreDisconnected && !playerCharacterMasterController.isConnected) { return false; } if (Settings.AllowDead) { return true; } CharacterBody body = m.GetBody(); if (Object.op_Implicit((Object)(object)body) && Object.op_Implicit((Object)(object)body.healthComponent)) { return body.healthComponent.alive; } return false; } private static CharacterMaster Choose(DistributionMode mode, CharacterMaster owner, Vector3 pos, ItemTier tier, bool equipment) { //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Invalid comparison between Unknown and I4 //IL_00ef: Unknown result type (might be due to invalid IL or missing references) switch (mode) { case DistributionMode.Owner: if (!IsValid(owner)) { return null; } return owner; case DistributionMode.Disabled: return null; default: { ReadOnlyCollection<PlayerCharacterMasterController> instances = PlayerCharacterMasterController.instances; int count = instances.Count; if (candidates.Length < count) { candidates = new Candidate[count]; } int num = (equipment ? 16 : Slot(tier)); for (int i = 0; i < count; i++) { CharacterMaster val = (Object.op_Implicit((Object)(object)instances[i]) ? instances[i].master : null); Candidate candidate = new Candidate { valid = IsValid(val) }; if (candidate.valid && mode == DistributionMode.Nearest) { CharacterBody body = val.GetBody(); candidate.hasBody = Object.op_Implicit((Object)(object)body); if (Object.op_Implicit((Object)(object)body)) { Vector3 val2 = body.corePosition - pos; candidate.sqrDistance = ((Vector3)(ref val2)).sqrMagnitude; } } else if (candidate.valid && mode == DistributionMode.Balanced) { candidate.count = (equipment ? (((int)val.inventory.currentEquipmentIndex != -1) ? 1 : 0) : val.inventory.GetTotalItemCountOfTier(tier)); if (pending.TryGetValue(val, out var value)) { candidate.count += value[num]; } } candidates[i] = candidate; } int num2 = RecipientChoice.Pick(mode, candidates, count, ref roundRobin, randomBelow); if (num2 < 0) { return null; } return instances[num2].master; } } } private static int Slot(ItemTier tier) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected I4, but got Unknown return RecipientChoice.Slot((int)tier); } private static void Send(CharacterMaster target, ItemIndex item, ItemTier tier, UniquePickup pickup, Vector3 origin, bool cube, in CreatePickupInfo info) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_000f: 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_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Invalid comparison between Unknown and I4 //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0077: 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: 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) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: 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_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) Loot loot = new Loot { origin = origin, itemIndex = item, pickup = pickup, recipient = target, tierSlot = (((int)item == -1) ? 16 : Slot(tier)), commandCube = cube, recycled = info.recycled, duplicated = info.duplicated, chest = info.chest }; ItemFlightOrb itemFlightOrb = new ItemFlightOrb { origin = origin, itemIndex = item, stack = 1 }; if (cube) { loot.cubeInfo = info; PickupDef pickupDef = PickupCatalog.GetPickupDef(pickup.pickupIndex); itemFlightOrb.iconPickup = VanillaCubeIcon(pickupDef, pickup.pickupIndex); CubeIcon cubeIcon = CubeIcons.For(pickupDef); if (cubeIcon != CubeIcon.None) { itemFlightOrb.decorate = delegate(EffectData data) { CubeIcons.Mark(data, cubeIcon); }; } } HandedOver = true; if (Settings.Animation && Object.op_Implicit((Object)(object)OrbManager.instance)) { CharacterBody body = target.GetBody(); if (Object.op_Implicit((Object)(object)body)) { loot.lastRecipientPosition = ItemFlight.DropPoint(body, body.footPosition); } if (!pending.TryGetValue(target, out var value)) { value = (pending[target] = new int[17]); } value[loot.tierSlot]++; loot.counted = true; } ItemFlight.Launch(itemFlightOrb, target, Settings.TravelTime, Settings.Animation, delegate(bool stageEnding) { Complete(loot, stageEnding); }); } private static void Complete(Loot loot, bool stageEnding) { if (loot.counted && pending.TryGetValue(loot.recipient, out var value) && value[loot.tierSlot] > 0) { value[loot.tierSlot]--; } SafeDeliver(loot, stageEnding); } public static void FlushInFlight() { nextStageStarted = false; ItemFlight.FlushAll(); pending.Clear(); } private static void SafeDeliver(Loot orb, bool stageEnding) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) try { Deliver(orb, stageEnding); } catch (Exception arg) { Log.Error(string.Format("Delivering {0} failed: {1}", PickupCatalog.GetPickupDef(orb.pickup.pickupIndex)?.internalName ?? "a pickup", arg)); } } private static void Deliver(Loot orb, bool stageEnding) { //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: 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_0111: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0130: 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_0132: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_0247: Unknown result type (might be due to invalid IL or missing references) //IL_0263: Unknown result type (might be due to invalid IL or missing references) //IL_025b: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_0193: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_01ce: Unknown result type (might be due to invalid IL or missing references) //IL_01d3: Unknown result type (might be due to invalid IL or missing references) //IL_01da: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_01e7: Unknown result type (might be due to invalid IL or missing references) //IL_01ec: Unknown result type (might be due to invalid IL or missing references) //IL_01ee: Unknown result type (might be due to invalid IL or missing references) //IL_01b3: Unknown result type (might be due to invalid IL or missing references) //IL_0223: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Unknown result type (might be due to invalid IL or missing references) //IL_021b: Unknown result type (might be due to invalid IL or missing references) CharacterMaster recipient = orb.recipient; CharacterBody val = (Object.op_Implicit((Object)(object)recipient) ? recipient.GetBody() : null); if (orb.commandCube) { if (stageEnding) { carriedOver.Add((orb.cubeInfo, recipient)); } else { SpawnDroplet(in orb.cubeInfo, ItemFlight.DropPoint(val, orb.origin)); } return; } PlayerCharacterMasterController val2 = (Object.op_Implicit((Object)(object)recipient) ? recipient.playerCharacterMasterController : null); if (!Object.op_Implicit((Object)(object)recipient) || !Object.op_Implicit((Object)(object)recipient.inventory) || (Settings.IgnoreDisconnected && Object.op_Implicit((Object)(object)val2) && !val2.isConnected)) { CreatePickupInfo val3 = default(CreatePickupInfo); ((CreatePickupInfo)(ref val3)).pickup = orb.pickup; val3.rotation = Quaternion.identity; val3.recycled = orb.recycled; val3.duplicated = orb.duplicated; val3.chest = orb.chest; CreatePickupInfo info = val3; if (stageEnding) { carriedOver.Add((info, null)); } else { SpawnDroplet(in info, ItemFlight.DropPoint(val, (Vector3)(((??)orb.lastRecipientPosition) ?? orb.origin))); } return; } UniquePickup pickup = orb.pickup; PickupDef pickupDef = PickupCatalog.GetPickupDef(pickup.pickupIndex); if (Settings.Notify && Object.op_Implicit((Object)(object)val) && pickupDef != null && pickupDef.attemptGrant != null) { if (orb.duplicated || Settings.BlocksDuplicatorCopy(orb.itemIndex)) { DropMutuallyExclusive(recipient.inventory, orb.itemIndex); GiveToInventory(recipient.inventory, orb.itemIndex, in pickup); val.OnPickup((PickupClass)(((UniquePickup)(ref pickup)).isTempItem ? 2 : 3)); GenericPickupController.SendPickupMessage(recipient, pickup); } else { GrantContext val4 = new GrantContext { body = val, position = orb.origin, rotation = Quaternion.identity, uniquePickup = pickup }; pickupDef.attemptGrant.Invoke(ref val4); val.OnPickup((PickupClass)(((UniquePickup)(ref pickup)).isTempItem ? 2 : 3)); if (val4.shouldNotify) { GenericPickupController.SendPickupMessage(recipient, pickup); } } JustDropItemsCompat.Notify(recipient, orb.itemIndex, orb.recycled, orb.duplicated); SetDelusionPickup(orb); } else { GiveToInventory(recipient.inventory, orb.itemIndex, in pickup); if (Settings.Notify) { GenericPickupController.SendPickupMessage(recipient, pickup); } JustDropItemsCompat.Notify(recipient, orb.itemIndex, orb.recycled, orb.duplicated); SetDelusionPickup(orb); } } private static void SetDelusionPickup(Loot orb) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)orb.chest) && Object.op_Implicit((Object)(object)RunArtifactManager.instance) && DelusionChestController.isDelusionEnable) { orb.chest.CallRpcSetDelusionPickupIndex(orb.pickup.pickupIndex); } } private static void GiveToInventory(Inventory inv, ItemIndex item, in UniquePickup pickup) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0028: 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) if (pickup.isRental) { inv.GiveItemRented(item, 1); } else if (((UniquePickup)(ref pickup)).isTempItem) { inv.GiveItemTemp(item, pickup.decayValue); } else { inv.GiveItemPermanent(item, 1); } } private static void DropMutuallyExclusive(Inventory inv, ItemIndex item) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0034: 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) //IL_003e: Unknown result type (might be due to invalid IL or missing references) ItemDef itemDef = ItemCatalog.GetItemDef(item); Group val = default(Group); ItemDef val2 = default(ItemDef); if (Object.op_Implicit((Object)(object)itemDef) && ItemCatalog.IsPartOfGroup(itemDef, ItemGroupTypes.MutualExclusivity, ref val) && ((Group)(ref val)).IsCarryingItemInGroup(inv, ref val2, itemDef) && Object.op_Implicit((Object)(object)val2) && val2.itemIndex != item) { inv.ResetItemPermanent(val2.itemIndex); } } private static void SpawnDroplet(in CreatePickupInfo info, Vector3 at) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: 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) SpawningOwnDroplet = true; try { PickupDropletController.CreatePickupDroplet(info, at, Vector3.zero); } finally { SpawningOwnDroplet = false; } } } internal static class GameMembers { internal static readonly GameMethod PickupTakenOrbEffect_OnEnable = new GameMethod(typeof(PickupTakenOrbEffect), "OnEnable"); internal static readonly GameMethod PickupDropletController_CreatePickupDroplet = new GameMethod(typeof(PickupDropletController), "CreatePickupDroplet", typeof(CreatePickupInfo), typeof(Vector3), typeof(Vector3)); internal static readonly GameMethod Interactor_PerformInteraction = new GameMethod(typeof(Interactor), "PerformInteraction", typeof(GameObject)); internal static readonly GameMethod SacrificeArtifactManager_OnServerCharacterDeath = new GameMethod(typeof(SacrificeArtifactManager), "OnServerCharacterDeath", typeof(DamageReport)); internal static readonly GameMethod GlobalDeathRewards_OnCharacterDeathGlobal = new GameMethod(typeof(GlobalDeathRewards), "OnCharacterDeathGlobal", typeof(DamageReport)); internal static readonly GameMethod GlobalEventManager_OnCharacterDeath = new GameMethod(typeof(GlobalEventManager), "OnCharacterDeath", typeof(DamageReport)); internal static readonly GameMethod PickupDropTable_GeneratePickup = new GameMethod(typeof(PickupDropTable), "GeneratePickup", typeof(Xoroshiro128Plus)); internal static readonly GameMethod ChestBehavior_ItemDrop = new GameMethod(typeof(ChestBehavior), "ItemDrop"); internal static readonly GameMethod RouletteChestController_EjectPickupServer = new GameMethod(typeof(RouletteChestController), "EjectPickupServer", typeof(UniquePickup)); internal static readonly GameMethod ScavBackpackBehavior_ItemDrop = new GameMethod(typeof(ScavBackpackBehavior), "ItemDrop"); internal static readonly GameMethod ShrineChanceBehavior_AddShrineStack = new GameMethod(typeof(ShrineChanceBehavior), "AddShrineStack", typeof(Interactor)); internal static readonly GameMethod ShopTerminalBehavior_DropPickup = new GameMethod(typeof(ShopTerminalBehavior), "DropPickup", typeof(bool)); internal static readonly GameMethod ScrappingToIdle_OnEnter = new GameMethod(typeof(ScrappingToIdle), "OnEnter"); internal static readonly GameMethod DroneScrappingToIdle_DropPickup = new GameMethod(typeof(DroneScrappingToIdle), "DropPickup"); internal static readonly GameMethod DropItem_OnEnter = new GameMethod(typeof(DropItem), "OnEnter"); internal static readonly GameMethod MealPrepController_BeginCookingServer = new GameMethod(typeof(MealPrepController), "BeginCookingServer", typeof(Interactor), typeof(PickupIndex[]), typeof(PickupIndex), typeof(int)); internal static readonly GameMethod CookingToIdle_DropItem = new GameMethod(typeof(CookingToIdle), "DropItem"); internal static readonly GameMethod PowerOrbKeySpawner_SpawnKey = new GameMethod(typeof(PowerOrbKeySpawner), "SpawnKey", typeof(DamageReport)); internal static readonly GameMethod PowerOrbEventIdle_SpawnKey = new GameMethod(typeof(PowerOrbEventIdle), "SpawnKey", typeof(DamageReport)); internal static readonly GameMethod PowerOrbEventSpawnOrb_SpawnKey = new GameMethod(typeof(PowerOrbEventSpawnOrb), "SpawnKey", typeof(DamageReport)); internal static readonly GameMethod ItemDef_AttemptGrant = new GameMethod(typeof(ItemDef), "AttemptGrant", typeof(GrantContext).MakeByRefType()); internal static readonly GameMethod Death_SpawnDropletServer = new GameMethod(typeof(Death), "SpawnDropletServer"); internal static readonly GameMethod ItemDuplicatorController_DuplicateItem = new GameMethod(typeof(ItemDuplicatorController), "DuplicateItem", typeof(ItemIndex)); internal static readonly GameMethod ItemDuplicatorController_OnDestroy = new GameMethod(typeof(ItemDuplicatorController), "OnDestroy"); internal static readonly GameMethod Salvage_DropTempItemServer = new GameMethod(typeof(Salvage), "DropTempItemServer"); internal static readonly GameMethod TinkerProjectile_TransmuteTargetObject = new GameMethod(typeof(TinkerProjectile), "TransmuteTargetObject", typeof(GameObject)); internal static readonly GameMethod Surprise_DropTempItemServer = new GameMethod(typeof(Surprise), "DropTempItemServer", typeof(Vector3)); internal static readonly GameMethod Destroy_FixedUpdate = new GameMethod(typeof(Destroy), "FixedUpdate"); internal static readonly GameMethod PickupPickerController_CreatePickup = new GameMethod(typeof(PickupPickerController), "CreatePickup", typeof(UniquePickup)); internal static readonly GameMethod BossGroup_DropRewards = new GameMethod(typeof(BossGroup), "DropRewards"); internal static readonly GameMethod WakeController_DropShamanRewards = new GameMethod(typeof(WakeController), "DropShamanRewards", typeof(int)); internal static readonly GameMethod SpawnAltarZoneController_DropItems = new GameMethod(typeof(SpawnAltarZoneController), "DropItems"); internal static readonly GameField ItemDuplicatorController__itemStealController = new GameField(typeof(ItemDuplicatorController), "_itemStealController"); internal static readonly GameField ItemStealController_stolenInventoryInfos = new GameField(typeof(ItemStealController), "stolenInventoryInfos"); internal static readonly GameField StolenInventoryInfo_victimMaster = new GameField(GameMember.Nested(typeof(ItemStealController), "StolenInventoryInfo"), "victimMaster"); internal static readonly GameField DroneScrapperController_interactor = new GameField(typeof(DroneScrapperController), "interactor"); } internal static class JustDropItemsCompat { private static Action<CharacterMaster, ItemIndex, bool, bool> itemGranted; private static bool searched; public static void Notify(CharacterMaster master, ItemIndex item, bool recycled, bool duplicated) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Invalid comparison between Unknown and I4 //IL_0020: Unknown result type (might be due to invalid IL or missing references) if ((!recycled && !duplicated) || !Object.op_Implicit((Object)(object)master) || (int)item == -1) { return; } Action<CharacterMaster, ItemIndex, bool, bool> action = Find(); if (action == null) { return; } try { action(master, item, recycled, duplicated); } catch (Exception ex) { Log.Warn("JustDropItems.Api.ItemGranted: " + ex.Message); } } private static Action<CharacterMaster, ItemIndex, bool, bool> Find() { if (searched) { return itemGranted; } searched = true; Type type = Type.GetType("JustDropItems.Api, JustDropItems"); if (type == null) { Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); for (int i = 0; i < assemblies.Length; i++) { type = assemblies[i].GetType("JustDropItems.Api", throwOnError: false); if (type != null) { break; } } } MethodInfo methodInfo = type?.GetMethod("ItemGranted", BindingFlags.Static | BindingFlags.Public, null, new Type[4] { typeof(CharacterMaster), typeof(ItemIndex), typeof(bool), typeof(bool) }, null); if (methodInfo == null || methodInfo.ReturnType != typeof(void)) { return null; } try { itemGranted = (Action<CharacterMaster, ItemIndex, bool, bool>)Delegate.CreateDelegate(typeof(Action<CharacterMaster, ItemIndex, bool, bool>), methodInfo); } catch (Exception ex) { Log.Warn("JustDropItems.Api.ItemGranted found but not usable: " + ex.Message); return null; } Log.Info("Just Drop Items found: printed and recycled items are reported to it."); return itemGranted; } } internal static class ItemFilter { internal struct Item { public string internalName; public string englishName; public bool tierOk; public bool hidden; public bool questTag; public bool worldUnique; public bool hex; } internal struct Options { public bool useList; public bool includeOnly; public bool skipObjective; } internal struct Result { public bool allowed; public bool allowedNoList; public bool noDuplicatorCopy; public bool inList; } private static readonly HashSet<string> ObjectiveItems = new HashSet<string> { "artifactkey", "powercube", "powerpyramid", "powerorbsphere", "masterbattery", "mastercore", "helpwake" }; public static string Normalize(string s) { if (string.IsNullOrEmpty(s)) { return string.Empty; } StringBuilder stringBuilder = new StringBuilder(s.Length); foreach (char c in s) { if (char.IsLetterOrDigit(c)) { stringBuilder.Append(char.ToLowerInvariant(c)); } } return stringBuilder.ToString(); } public static HashSet<string> ParseList(string value) { HashSet<string> hashSet = new HashSet<string>(); string[] array = value.Split(','); for (int i = 0; i < array.Length; i++) { string text = Normalize(array[i]); if (text.Length > 0) { hashSet.Add(text); } } return hashSet; } public static bool TierAllowed(HashSet<string> tierNames, string tierEnumName, string tierDefName) { if (!tierNames.Contains(Normalize(tierEnumName))) { if (tierDefName != null) { return tierNames.Contains(Normalize(tierDefName)); } return false; } return true; } public static Result Decide(in Item item, in Options o, HashSet<string> listed) { Result result = new Result { inList = (listed.Contains(item.internalName) || listed.Contains(item.englishName)) }; bool flag = ObjectiveItems.Contains(item.internalName) || item.questTag; bool flag2 = item.tierOk && !item.hidden; if (flag2 && o.skipObjective && flag) { flag2 = false; } result.noDuplicatorCopy = item.hex || flag || item.worldUnique; result.allowedNoList = flag2; if (flag2 && o.useList) { flag2 = (o.includeOnly ? result.inList : (!result.inList)); } result.allowed = flag2; return result; } } public enum DistributionMode { Disabled, Owner, Nearest, Random, RoundRobin, Balanced } internal struct Candidate { public bool valid; public bool hasBody; public float sqrDistance; public int count; } internal static class RecipientChoice { public const int TierSlots = 16; public const int EquipmentSlot = 16; public static int Pick(DistributionMode mode, Candidate[] players, int n, ref int roundRobin, Func<int, int> randomBelow) { switch (mode) { case DistributionMode.Nearest: { int num4 = -1; int num5 = -1; float num6 = float.MaxValue; for (int k = 0; k < n; k++) { if (!players[k].valid) { continue; } if (!players[k].hasBody) { if (num5 < 0) { num5 = k; } } else if (players[k].sqrDistance < num6) { num6 = players[k].sqrDistance; num4 = k; } } if (num4 < 0) { return num5; } return num4; } case DistributionMode.Random: { int result2 = -1; int num3 = 0; for (int j = 0; j < n; j++) { if (players[j].valid && randomBelow(++num3) == 0) { result2 = j; } } return result2; } case DistributionMode.RoundRobin: { for (int l = 0; l < n; l++) { int num7 = (roundRobin + l) % n; if (players[num7].valid) { roundRobin = num7 + 1; return num7; } } return -1; } case DistributionMode.Balanced: { int result = -1; int num = int.MaxValue; int num2 = 0; for (int i = 0; i < n; i++) { if (players[i].valid) { int count = players[i].count; if (count < num) { num = count; result = i; num2 = 1; } else if (count == num && randomBelow(++num2) == 0) { result = i; } } } return result; } default: return -1; } } public static int Slot(int tier) { if ((uint)tier >= 15u) { return 15; } return tier; } } [BepInPlugin("com.H1xl.AutoLootDistribution", "AutoLootDistribution", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public sealed class Plugin : BaseUnityPlugin { private readonly struct Scope : IDisposable { private readonly Source prevSource; private readonly CharacterMaster prevOwner; public Scope(Source source, CharacterMaster owner) { prevSource = ctxSource; prevOwner = ctxOwner; ctxSource = source; ctxOwner = owner; } public void Dispose() { ctxSource = prevSource; ctxOwner = prevOwner; } } internal delegate void ItemGrantOrig(ref GrantContext context); public const string GUID = "com.H1xl.AutoLootDistribution"; public const string NAME = "AutoLootDistribution"; public const string VERSION = "1.0.0"; private static Source ctxSource; private static CharacterMaster ctxOwner; private static readonly Dictionary<GameObject, CharacterMaster> interactors = new Dictionary<GameObject, CharacterMaster>(); private static bool interactionSucceeded; private static CharacterMaster deathAttacker; private static bool inCharacterDeath; private static bool sonorousNext; private static readonly FieldInfo droneScrapperInteractor = GameMembers.DroneScrapperController_interactor.Find(); private static readonly Dictionary<ItemDuplicatorController, CharacterMaster> extractorVictims = new Dictionary<ItemDuplicatorController, CharacterMaster>(); private static readonly FieldInfo duplicatorStealer = GameMembers.ItemDuplicatorController__itemStealController.Find(); private static readonly FieldInfo stolenInfos = GameMembers.ItemStealController_stolenInventoryInfos.Find(); private static readonly FieldInfo stolenVictim = GameMembers.StolenInventoryInfo_victimMaster.Find(); private void Awake() { Log.Init(((BaseUnityPlugin)this).Logger); Log.IsVerbose = () => Settings.Verbose; Settings.Init(((BaseUnityPlugin)this).Config); RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(Settings.RebuildItemTable)); RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(Distributor.InitIcons)); CubeIcons.Load(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location)); HookUtil.Add(GameMembers.PickupTakenOrbEffect_OnEnable, typeof(Plugin), "OnPickupOrbEffectEnable"); string folder = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location); RooPage.TryRegister(delegate { RiskOfOptionsCompat.Register(folder); }); HookUtil.Add(GameMembers.PickupDropletController_CreatePickupDroplet, typeof(Plugin), "OnCreatePickupDroplet"); HookUtil.Add(GameMembers.Interactor_PerformInteraction, typeof(Plugin), "OnPerformInteraction"); GlobalEventManager.OnInteractionsGlobal += delegate { interactionSucceeded = true; }; HookUtil.Add(GameMembers.SacrificeArtifactManager_OnServerCharacterDeath, typeof(Plugin), "OnSacrificeDeath"); HookUtil.Add(GameMembers.GlobalDeathRewards_OnCharacterDeathGlobal, typeof(Plugin), "OnGlobalDeathRewards"); HookUtil.Add(GameMembers.GlobalEventManager_OnCharacterDeath, typeof(Plugin), "OnCharacterDeath"); HookUtil.Add(GameMembers.PickupDropTable_GeneratePickup, typeof(Plugin), "OnGeneratePickup"); HookUtil.Add(GameMembers.ChestBehavior_ItemDrop, typeof(Plugin), "OnChestItemDrop"); HookUtil.Add(GameMembers.RouletteChestController_EjectPickupServer, typeof(Plugin), "OnRouletteEject"); HookUtil.Add(GameMembers.ScavBackpackBehavior_ItemDrop, typeof(Plugin), "OnScavBackpackDrop"); HookUtil.Add(GameMembers.ShrineChanceBehavior_AddShrineStack, typeof(Plugin), "OnShrineChance"); HookUtil.Add(GameMembers.ShopTerminalBehavior_DropPickup, typeof(Plugin), "OnShopDrop"); HookUtil.Add(GameMembers.ScrappingToIdle_OnEnter, typeof(Plugin), "OnScrapperDrop"); HookUtil.Add(GameMembers.DroneScrappingToIdle_DropPickup, typeof(Plugin), "OnDroneScrapperDrop"); HookUtil.Add(GameMembers.DropItem_OnEnter, typeof(Plugin), "OnSolusVendorDrop"); HookUtil.Add(GameMembers.MealPrepController_BeginCookingServer, typeof(Plugin), "OnBeginCooking"); HookUtil.Add(GameMembers.CookingToIdle_DropItem, typeof(Plugin), "OnChefDrop"); HookUtil.Add(GameMembers.PowerOrbKeySpawner_SpawnKey, typeof(Plugin), "OnKeySpawner"); HookUtil.Add(GameMembers.PowerOrbEventIdle_SpawnKey, typeof(Plugin), "OnKeyEventIdle"); HookUtil.Add(GameMembers.PowerOrbEventSpawnOrb_SpawnKey, typeof(Plugin), "OnKeyEventSpawnOrb"); HookUtil.Add(GameMembers.ItemDef_AttemptGrant, typeof(Plugin), "OnItemAttemptGrant"); HookUtil.Add(GameMembers.Death_SpawnDropletServer, typeof(Plugin), "OnMimicDrop"); HookUtil.Add(GameMembers.ItemDuplicatorController_DuplicateItem, typeof(Plugin), "OnExtractorDuplicate"); HookUtil.Add(GameMembers.ItemDuplicatorController_OnDestroy, typeof(Plugin), "OnExtractorDestroy"); HookUtil.Add(GameMembers.Salvage_DropTempItemServer, typeof(Plugin), "OnDrifterSalvage"); HookUtil.Add(GameMembers.TinkerProjectile_TransmuteTargetObject, typeof(Plugin), "OnTinkerTransmute"); HookUtil.Add(GameMembers.Surprise_DropTempItemServer, typeof(Plugin), "OnJunkDroneDrop"); HookUtil.Add(GameMembers.Destroy_FixedUpdate, typeof(Plugin), "OnHoardDestroy"); HookUtil.Add(GameMembers.PickupPickerController_CreatePickup, typeof(Plugin), "OnPickerCreatePickup"); HookUtil.Add(GameMembers.BossGroup_DropRewards, typeof(Plugin), "OnBossRewards"); HookUtil.Add(GameMembers.WakeController_DropShamanRewards, typeof(Plugin), "OnWakeRewards"); HookUtil.Add(GameMembers.SpawnAltarZoneController_DropItems, typeof(Plugin), "OnAltarZoneRewards"); Stage.onServerStageBegin += delegate { interactors.Clear(); Distributor.OnStageBegin(); }; Stage.onServerStageComplete += delegate { Distributor.FlushInFlight(); }; SceneExitController.onFinishExit += delegate { Distributor.FlushInFlight(); }; Run.onRunStartGlobal += delegate { interactors.Clear(); Distributor.Reset(); }; Run.onRunDestroyGlobal += delegate { interactors.Clear(); extractorVictims.Clear(); Distributor.FlushInFlight(); Distributor.Reset(); }; Log.Info("AutoLootDistribution 1.0.0 ready."); } private void FixedUpdate() { Distributor.SpawnCarriedOver(); } private static void OnSacrificeDeath(Action<DamageReport> orig, DamageReport report) { Scope scope = new Scope(Source.MonsterKill, report?.attackerMaster); try { orig(report); } finally { ((IDisposable)scope/*cast due to .constrained prefix*/).Dispose(); } } private static void OnGlobalDeathRewards(Action<GlobalDeathRewards, DamageReport> orig, GlobalDeathRewards self, DamageReport report) { Scope scope = new Scope(Source.MonsterKill, report?.attackerMaster); try { orig(self, report); } finally { ((IDisposable)scope/*cast due to .constrained prefix*/).Dispose(); } } private static void OnCharacterDeath(Action<GlobalEventManager, DamageReport> orig, GlobalEventManager self, DamageReport report) { CharacterMaster val = deathAttacker; bool flag = inCharacterDeath; deathAttacker = report?.attackerMaster; inCharacterDeath = true; try { orig(self, report); } finally { deathAttacker = val; inCharacterDeath = flag; sonorousNext = false; } } private static UniquePickup OnGeneratePickup(Func<PickupDropTable, Xoroshiro128Plus, UniquePickup> orig, PickupDropTable self, Xoroshiro128Plus rng) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) UniquePickup result = orig(self, rng); if (inCharacterDeath && Object.op_Implicit((Object)(object)self) && (Object)(object)self == (Object)(object)CommonAssets.dtSonorousEchoPath) { sonorousNext = true; } return result; } private static void OnChestItemDrop(Action<ChestBehavior> orig, ChestBehavior self) { //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) DelusionChestController val = default(DelusionChestController); if (DelusionChestController.isDelusionEnable && ((Component)self).TryGetComponent<DelusionChestController>(ref val) && val.SelectedPickupIndex != PickupIndex.none) { orig(self); return; } using (new Scope(ChestSource(((Component)self).gameObject), OwnerOf(((Component)self).gameObject))) { orig(self); } } private static Source ChestSource(GameObject go) { string text = PrefabName(go); if (text.Contains("backpack")) { return Source.ScavengerBag; } if (text.Contains("lunarchest")) { return Source.LunarPod; } if (text.StartsWith("voidchest")) { return Source.VoidCradle; } if (text == "lockbox") { return Source.RustedLockbox; } if (text == "lockboxvoid") { return Source.EncrustedLockbox; } return Source.Chest; } private static Source ShopSource(GameObject go) { string text = PrefabName(go); if (text.Contains("duplicator")) { return Source.Printer; } if (text.Contains("cauldron")) { return Source.Cauldron; } if (text.Contains("shrinecleanse")) { return Source.CleansingPool; } if (text.StartsWith("lunarshopterminal")) { return Source.LunarShop; } return Source.Multishop; } private static string PrefabName(GameObject go) { if (!Object.op_Implicit((Object)(object)go)) { return string.Empty; } string text = ((Object)go).name; int num = text.IndexOf("(Clone)", StringComparison.Ordinal); if (num >= 0) { text = text.Substring(0, num); } return text.Trim().ToLowerInvariant(); } private static void OnRouletteEject(Action<RouletteChestController, UniquePickup> orig, RouletteChestController self, UniquePickup pickup) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) using (new Scope(Source.AdaptiveChest, OwnerOf(((Component)self).gameObject))) { orig(self, pickup); } } private static void OnScavBackpackDrop(Action<ScavBackpackBehavior> orig, ScavBackpackBehavior self) { using (new Scope(Source.ScavengerBag, OwnerOf(((Component)self).gameObject))) { orig(self); } } private static void OnShrineChance(Action<ShrineChanceBehavior, Interactor> orig, ShrineChanceBehavior self, Interactor activator) { CharacterBody val = (Object.op_Implicit((Object)(object)activator) ? ((Component)activator).GetComponent<CharacterBody>() : null); using (new Scope(Source.ShrineOfChance, Object.op_Implicit((Object)(object)val) ? val.master : null)) { orig(self, activator); } } private static void OnShopDrop(Action<ShopTerminalBehavior, bool> orig, ShopTerminalBehavior self, bool duplicated) { using (new Scope(ShopSource(((Component)self).gameObject), OwnerOf(((Component)self).gameObject))) { orig(self, duplicated); } } private static void OnScrapperDrop(Action<ScrappingToIdle> orig, ScrappingToIdle self) { Scope scope = new Scope(Source.Scrapper, OwnerOf(Object.op_Implicit((Object)(object)((EntityState)self).outer) ? ((Component)((EntityState)self).outer).gameObject : null)); try { orig(self); } finally { ((IDisposable)scope/*cast due to .constrained prefix*/).Dispose(); } } private static void OnDroneScrapperDrop(Action<DroneScrappingToIdle> orig, DroneScrappingToIdle self) { CharacterMaster owner = null; if (NetworkServer.active && droneScrapperInteractor != null) { DroneScrapperController val = (Object.op_Implicit((Object)(object)((EntityState)self).outer) ? ((Component)((EntityState)self).outer).GetComponent<DroneScrapperController>() : null); Interactor val2 = (Interactor)(Object.op_Implicit((Object)(object)val) ? /*isinst with value type is only supported in some contexts*/: null); CharacterBody val3 = (Object.op_Implicit((Object)(object)val2) ? ((Component)val2).GetComponent<CharacterBody>() : null); owner = (Object.op_Implicit((Object)(object)val3) ? val3.master : null); } using (new Scope(Source.DroneScrapper, owner)) { orig(self); } } private static void OnSolusVendorDrop(Action<DropItem> orig, DropItem self) { Scope scope = new Scope(Source.CharityNode, OwnerOf(Object.op_Implicit((Object)(object)((EntityState)self).outer) ? ((Component)((EntityState)self).outer).gameObject : null)); try { orig(self); } finally { ((IDisposable)scope/*cast due to .constrained prefix*/).Dispose(); } } private static void OnBeginCooking(Action<MealPrepController, Interactor, PickupIndex[], PickupIndex, int> orig, MealPrepController self, Interactor activator, PickupIndex[] itemsToTake, PickupIndex reward, int count) { //IL_0033: Unknown result type (might be due to invalid IL or missing references) CharacterBody val = default(CharacterBody); if (NetworkServer.active && Object.op_Implicit((Object)(object)activator) && ((Component)activator).TryGetComponent<CharacterBody>(ref val)) { interactors[((Component)self).gameObject] = val.master; } orig(self, activator, itemsToTake, reward, count); } private static void OnKeySpawner(Action<PowerOrbKeySpawner, DamageReport> orig, PowerOrbKeySpawner self, DamageReport report) { Scope scope = new Scope(Source.CraterKeys, report?.attackerMaster); try { orig(self, report); } finally { ((IDisposable)scope/*cast due to .constrained prefix*/).Dispose(); } } private static void OnKeyEventIdle(Action<PowerOrbEventIdle, DamageReport> orig, PowerOrbEventIdle self, DamageReport report) { Scope scope = new Scope(Source.CraterKeys, report?.attackerMaster); try { orig(self, report); } finally { ((IDisposable)scope/*cast due to .constrained prefix*/).Dispose(); } } private static void OnKeyEventSpawnOrb(Action<PowerOrbEventSpawnOrb, DamageReport> orig, PowerOrbEventSpawnOrb self, DamageReport report) { Scope scope = new Scope(Source.CraterKeys, report?.attackerMaster); try { orig(self, report); } finally { ((IDisposable)scope/*cast due to .constrained prefix*/).Dispose(); } } private static void OnItemAttemptGrant(ItemGrantOrig orig, ref GrantContext context) { //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_0033: Unknown result type (might be due to invalid IL or missing references) GenericPickupController controller = context.controller; PickupDef pickupDef = PickupCatalog.GetPickupDef(((GrantContext)(ref context)).pickup.pickupIndex); bool flag = NetworkServer.active && Object.op_Implicit((Object)(object)controller) && !controller.Duplicated && pickupDef != null && Settings.BlocksDuplicatorCopy(pickupDef.itemIndex); if (flag) { controller.NetworkDuplicated = true; } try { orig(ref context); } finally { if (flag && Object.op_Implicit((Object)(object)controller)) { controller.NetworkDuplicated = false; } } } private static void OnMimicDrop(Action<Death> orig, Death self) { CharacterMaster owner = null; HealthComponent val = default(HealthComponent); CharacterBody val2 = default(CharacterBody); if (Object.op_Implicit((Object)(object)((EntityState)self).outer) && ((Component)((EntityState)self).outer).TryGetComponent<HealthComponent>(ref val) && Object.op_Implicit((Object)(object)val.lastHitAttacker) && val.lastHitAttacker.TryGetComponent<CharacterBody>(ref val2)) { owner = val2.master; } using (new Scope(Source.Mimic, owner)) { orig(self); } } private static void OnExtractorDuplicate(Action<ItemDuplicatorController, ItemIndex> orig, ItemDuplicatorController self, ItemIndex item) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) orig(self, item); if (!NetworkServer.active) { return; } try { object? obj = duplicatorStealer?.GetValue(self); ItemStealController val = (ItemStealController)((obj is ItemStealController) ? obj : null); if (val == null || !(stolenInfos?.GetValue(val) is Array { Length: >0 } array)) { return; } object value = array.GetValue(0); if (value != null) { object? obj2 = stolenVictim?.GetValue(value); CharacterMaster val2 = (CharacterMaster)((obj2 is CharacterMaster) ? obj2 : null); if (val2 != null && Object.op_Implicit((Object)(object)val2)) { extractorVictims[self] = val2; } } } catch (Exception ex) { Log.Warn("Solus Extractor: couldn't find the robbed player. " + ex.Message); } } private static void OnExtractorDestroy(Action<ItemDuplicatorController> orig, ItemDuplicatorController self) { extractorVictims.TryGetValue(self, out var value); extractorVictims.Remove(self); using (new Scope(Source.SolusExtractor, value)) { orig(self); } } private static void OnDrifterSalvage(Action<Salvage> orig, Salvage self) { using (new Scope(Source.Drifter, MasterOf((EntityState)(object)self))) { orig(self); } } private static CharacterMaster MasterOf(EntityState state) { CharacterBody val = default(CharacterBody); if (!Object.op_Implicit((Object)(object)state.outer) || !((Component)state.outer).TryGetComponent<CharacterBody>(ref val)) { return null; } return val.master; } private static void OnTinkerTransmute(Action<TinkerProjectile, GameObject> orig, TinkerProjectile self, GameObject target) { CharacterMaster owner = null; ProjectileController val = default(ProjectileController); CharacterBody val2 = default(CharacterBody); if (((Component)self).TryGetComponent<ProjectileController>(ref val) && Object.op_Implicit((Object)(object)val.owner) && val.owner.TryGetComponent<CharacterBody>(ref val2)) { owner = val2.master; } using (new Scope(Source.Drifter, owner)) { orig(self, target); } } private static void OnJunkDroneDrop(Action<Surprise, Vector3> orig, Surprise self, Vector3 velocity) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) using (new Scope(Source.JunkDrone, MasterOf((EntityState)(object)self))) { orig(self, velocity); } } private static void OnHoardDestroy(Action<Destroy> orig, Destroy self) { using (new Scope(Source.Ignored, null)) { orig(self); } } private static void OnChefDrop(Action<CookingToIdle> orig, CookingToIdle self) { Scope scope = new Scope(Source.WanderingChef, OwnerOf(Object.op_Implicit((Object)(object)((EntityState)self).outer) ? ((Component)((EntityState)self).outer).gameObject : null)); try { orig(self); } finally { ((IDisposable)scope/*cast due to .constrained prefix*/).Dispose(); } } private static void OnBossRewards(Action<BossGroup> orig, BossGroup self) { using (new Scope(Source.Boss, null)) { orig(self); } } private static void OnWakeRewards(Action<WakeController, int> orig, WakeController self, int killed) { using (new Scope(Source.Wake, null)) { orig(self, killed); } } private static void OnAltarZoneRewards(Action<SpawnAltarZoneController> orig, SpawnAltarZoneController self) { using (new Scope(Source.TotemOfSacrifice, null)) { orig(self); } } private static void OnPickerCreatePickup(Action<PickupPickerController, UniquePickup> orig, PickupPickerController self, UniquePickup pickup) { //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0030: 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) if (Settings.Enabled && Settings.AutoPickupChoices && NetworkServer.active) { Distributor.HandedOver = false; try { NetworkUIPromptController component = ((Component)self).GetComponent<NetworkUIPromptController>(); if (Object.op_Implicit((Object)(object)component) && Distributor.GiveChoice(component.currentParticipantMaster, pickup, ((Component)self).transform.position, self.chestGeneratedFrom)) { return; } } catch (Exception message) { Log.Error(message); if (Distributor.HandedOver) { return; } } } using (new Scope(Source.Ignored, null)) { orig(self, pickup); } } private static void OnPickupOrbEffectEnable(Action<PickupTakenOrbEffect> orig, PickupTakenOrbEffect self) { orig(self); CubeIconSwapper.Attach(self); } private static CharacterMaster OwnerOf(GameObject go) { if (!Object.op_Implicit((Object)(object)go) || !interactors.TryGetValue(go, out var value)) { return null; } return value; } private static void OnPerformInteraction(Action<Interactor, GameObject> orig, Interactor self, GameObject target) { if (!NetworkServer.active || !Object.op_Implicit((Object)(object)target)) { orig(self, target); return; } CharacterMaster value; bool flag = interactors.TryGetValue(target, out value); CharacterBody component = ((Component)self).GetComponent<CharacterBody>(); interactors[target] = (Object.op_Implicit((Object)(object)component) ? component.master : null); interactionSucceeded = false; orig(self, target); if (!interactionSucceeded) { if (flag) { interactors[target] = value; } else { interactors.Remove(target); } } } private static void OnCreatePickupDroplet(Action<CreatePickupInfo, Vector3, Vector3> orig, CreatePickupInfo info, Vector3 position, Vector3 velocity) { //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0073: 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) Source source = ctxSource; CharacterMaster owner = ctxOwner; if (sonorousNext) { sonorousNext = false; source = Source.SonorousWhispers; owner = deathAttacker; } else if (source == Source.None && Settings.ModeFor(Source.Unknown) != DistributionMode.Disabled) { source = Source.Unknown; } if (source != Source.None && !Distributor.SpawningOwnDroplet && Settings.Enabled && NetworkServer.active) { Distributor.HandedOver = false; try { if (Distributor.TryDistribute(source, owner, in info, position)) { return; } } catch (Exception message) { Log.Error(message); if (Distributor.HandedOver) { return; } } } orig(info, position, velocity); } } internal static class RiskOfOptionsCompat { [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static IsDisabledDelegate <>9__0_0; internal bool <Register>b__0_0() { return !Settings.animation.Value; } } [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)] public static void Register(string pluginFolder) { //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Expected O, but got Unknown //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Expected O, but got Unknown //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Expected O, but got Unknown //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Expected O, but got Unknown //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Expected O, but got Unknown RooHelper.Page("Items from kills (Artifact of Sacrifice), chests, shrines, printers and scrappers fly to the player who earned them. Only the host's settings matter.", pluginFolder); RooHelper.CheckBox(Settings.enabled); RooHelper.CheckBox(Settings.animation); ConfigEntry<float> travelTime = Settings.travelTime; object obj = <>c.<>9__0_0; if (obj == null) { IsDisabledDelegate val = () => !Settings.animation.Value; <>c.<>9__0_0 = val; obj = (object)val; } RooHelper.Slider(travelTime, 0.1f, 5f, 0.1f, "{0:0.0} s", (IsDisabledDelegate)obj); RooHelper.CheckBox(Settings.notify); RooHelper.CheckBox(Settings.commandToPlayer); RooHelper.CheckBox(Settings.commandIcons); RooHelper.CheckBox(Settings.autoPickupChoices); RooHelper.CheckBox(Settings.allowDead); RooHelper.CheckBox(Settings.ignoreDisconnected); foreach (Settings.SourceSetting s in Settings.Sources) { RooHelper.Choice((ConfigEntryBase)(object)s.mode); if (s.source == Source.WanderingChef) { RooHelper.CheckBox(Settings.chefProtect, (IsDisabledDelegate)(() => s.mode.Value == DistributionMode.Disabled)); } } RooHelper.Text(Settings.tiers); RooHelper.CheckBox(Settings.skipObjective); RooHelper.CheckBox(Settings.listEnabled); RooHelper.CheckBox(Settings.listIgnoredSolo, new IsDisabledDelegate(ListOff)); RooHelper.Choice((ConfigEntryBase)(object)Settings.listMode, new IsDisabledDelegate(ListOff)); RooHelper.Text(Settings.itemList, new IsDisabledDelegate(ListOff)); RooHelper.Choice((ConfigEntryBase)(object)Settings.fallback); RooHelper.CheckBox(Settings.verbose); RooHelper.CheckBox(Settings.duplicatorSkip); } private static bool ListOff() { return !Settings.listEnabled.Value; } } public enum Source : byte { None, MonsterKill, SonorousWhispers, Mimic, SolusExtractor, CraterKeys, Chest, LunarPod, VoidCradle, RustedLockbox, EncrustedLockbox, AdaptiveChest, ScavengerBag, ShrineOfChance, CleansingPool, CharityNode, Printer, Scrapper, DroneScrapper, Multishop, Cauldron, LunarShop, WanderingChef, Boss, Wake, TotemOfSacrifice, Drifter, JunkDrone, Unknown, Ignored, Count } public enum FallbackMode { Disabled, Nearest, Random, RoundRobin, Balanced } public enum ListMode { Exclude, IncludeOnly } internal static class Settings { internal sealed class SourceSetting { public Source source; public string section; public string key; public string oldKey; public DistributionMode defaultMode; public string description; public ConfigEntry<DistributionMode> mode; } private const string DefaultItemList = "Bustling Fungus, Rejuvenation Rack, Spare Drone Parts, Box of Dynamite, Lysate Cell, Shatterspleen, Rose Buckler, Ignition Tank, H3AD-5T v2, Purity, Collector's Compulsion"; private const string DefaultTiers = "Tier1, Tier2, Tier3, Boss"; internal static ConfigEntry<bool> duplicatorSkip; public static bool DuplicatorSkip; internal static ConfigEntry<bool> enabled; internal static ConfigEntry<bool> verbose; internal static ConfigEntry<bool> animation; internal static ConfigEntry<bool> notify; internal static ConfigEntry<bool> commandToPlayer; internal static ConfigEntry<bool> commandIcons; internal static ConfigEntry<bool> autoPickupChoices; internal static ConfigEntry<bool> allowDead; internal static ConfigEntry<bool> ignoreDisconnected; internal static ConfigEntry<float> travelTime; private const string SMonsters = "4.1 Sources - Monsters"; private const string SChests = "4.2 Sources - Chests"; private const string SShrines = "4.3 Sources - Shrines"; private const string SShops = "4.4 Sources - Shops and crafting"; private const string SEvents = "4.5 Sources - Events"; private const string SMade = "4.6 Sources - Survivors and drones"; private const string SUnknown = "4.7 Sources - Unknown"; private const string OldSources = "4. Sources"; private const string OldFallbacks = "6. Fallbacks"; internal static readonly List<SourceSetting> Sources = new List<SourceSetting>(); internal static ConfigEntry<bool> skipObjective; internal static ConfigEntry<bool> listEnabled; internal static ConfigEntry<b