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 ThreeChoiceChests v1.3.4
ThreeChoiceChests.dll
Decompiled a day 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.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using On.RoR2; using R2API; using RoR2; using RoR2.Networking; using RoR2.UI; using UnityEngine; using UnityEngine.AddressableAssets; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.Networking; using UnityEngine.UI; [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("ThreeChoiceChests")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.3.2.0")] [assembly: AssemblyInformationalVersion("1.3.2")] [assembly: AssemblyProduct("ThreeChoiceChests")] [assembly: AssemblyTitle("ThreeChoiceChests")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.3.2.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace ExamplePlugin { internal static class Log { private static ManualLogSource _logSource; internal static void Init(ManualLogSource logSource) { _logSource = logSource; } private static string Format(object data, string file, int line) { string fileName = Path.GetFileName(file); return $"[{fileName}:{line}] {data}"; } internal static void Debug(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0) { _logSource.LogDebug((object)Format(data, file, line)); } internal static void Error(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0) { _logSource.LogError((object)Format(data, file, line)); } internal static void Fatal(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0) { _logSource.LogFatal((object)Format(data, file, line)); } internal static void Info(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0) { _logSource.LogInfo((object)Format(data, file, line)); } internal static void Message(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0) { _logSource.LogMessage((object)Format(data, file, line)); } internal static void Warning(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0) { _logSource.LogWarning((object)Format(data, file, line)); } } } namespace ThreeChoiceChests { [HarmonyPatch(typeof(ChestBehavior), "BaseItemDrop")] internal static class ChestRewardCapture { internal sealed class Batch { internal ThreeChoiceChestMarker marker; internal Interactor recordedInteractor; internal Interactor activator; internal CharacterMaster ownerMaster; internal string ownerSource; internal Batch previous; internal int captured; } private static void Prefix(ChestBehavior __instance, out Batch __state) { __state = null; if (!NetworkServer.active) { return; } ThreeChoiceChestMarker component = ((Component)__instance).GetComponent<ThreeChoiceChestMarker>(); if (Object.op_Implicit((Object)(object)component)) { Interactor val = component.lastInteractor; if (!Object.op_Implicit((Object)(object)val)) { PurchaseInteraction component2 = ((Component)__instance).GetComponent<PurchaseInteraction>(); val = (Object.op_Implicit((Object)(object)component2) ? component2.lastActivator : null); } CharacterBody val2 = (Object.op_Implicit((Object)(object)val) ? ((Component)val).GetComponent<CharacterBody>() : null); if (!Object.op_Implicit((Object)(object)val2) || !Object.op_Implicit((Object)(object)val2.master)) { ThreeChoiceChestsPlugin.WriteLog("[ThreeChoice RewardCapture] source=" + ((Object)__instance).name + " skipped=missing-owner saleStar=unknown"); return; } __state = new Batch { marker = component, recordedInteractor = component.lastInteractor, activator = val, ownerMaster = val2.master, ownerSource = (Object.op_Implicit((Object)(object)component.lastInteractor) ? "purchase-hook" : "native-lastActivator"), previous = component.rewardBatch }; component.rewardBatch = __state; } } private static void Finalizer(Batch __state) { if (__state != null && Object.op_Implicit((Object)(object)__state.marker) && __state.marker.rewardBatch == __state) { ThreeChoiceChestMarker marker = __state.marker; marker.rewardBatch = __state.previous; if (__state.previous == null && (Object)(object)marker.lastInteractor == (Object)(object)__state.recordedInteractor) { marker.lastInteractor = null; } } } } public readonly struct ChoiceId : IEquatable<ChoiceId> { public Guid SessionId { get; } public ulong RunNumber { get; } public ulong RewardNumber { get; } public ChoiceId(Guid sessionId, ulong runNumber, ulong rewardNumber) { if (sessionId == Guid.Empty || runNumber == 0L || rewardNumber == 0L) { throw new ArgumentException("A choice identity requires a session and nonzero scope/reward sequence."); } SessionId = sessionId; RunNumber = runNumber; RewardNumber = rewardNumber; } public bool Equals(ChoiceId other) { if (SessionId == other.SessionId && RunNumber == other.RunNumber) { return RewardNumber == other.RewardNumber; } return false; } public override bool Equals(object obj) { if (obj is ChoiceId other) { return Equals(other); } return false; } public override int GetHashCode() { return (((SessionId.GetHashCode() * 397) ^ RunNumber.GetHashCode()) * 397) ^ RewardNumber.GetHashCode(); } public override string ToString() { return $"{SessionId:N}/{RunNumber}/{RewardNumber}"; } public static bool operator ==(ChoiceId left, ChoiceId right) { return left.Equals(right); } public static bool operator !=(ChoiceId left, ChoiceId right) { return !left.Equals(right); } } public readonly struct ChoiceCandidate { public int Index { get; } public UniquePickup Pickup { get; } public bool Available { get; } internal ChoiceCandidate(int index, UniquePickup pickup, bool available) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) Index = index; Pickup = pickup; Available = available; } } public sealed class ChoiceSnapshot { public ChoiceId Id { get; } public CharacterMaster Owner { get; } public uint OwnerNetId { get; } public uint RunNetId { get; } public UniquePickup FirstPickup { get; } public IReadOnlyList<ChoiceCandidate> Candidates { get; } internal ChoiceSnapshot(ChoiceId id, CharacterMaster owner, uint runId, UniquePickup first, Option[] options) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) Id = id; Owner = owner; int num; if (!Object.op_Implicit((Object)(object)owner)) { num = 0; } else { NetworkInstanceId netId = ((NetworkBehaviour)owner).netId; num = (int)((NetworkInstanceId)(ref netId)).Value; } OwnerNetId = (uint)num; RunNetId = runId; FirstPickup = first; ChoiceCandidate[] array = new ChoiceCandidate[options.Length]; for (int i = 0; i < array.Length; i++) { array[i] = new ChoiceCandidate(i, options[i].pickup, options[i].available); } Candidates = new ReadOnlyCollection<ChoiceCandidate>(array); } } public sealed class ChoiceBinding { public ChoiceSnapshot Reward { get; } public PickupPickerController Picker { get; } public uint PickerNetId { get; } public ulong DisplayNumber { get; } internal ChoiceBinding(ChoiceSnapshot reward, PickupPickerController picker, ulong display) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) Reward = reward; Picker = picker; int num; if (!Object.op_Implicit((Object)(object)picker)) { num = 0; } else { NetworkInstanceId netId = ((NetworkBehaviour)picker).netId; num = (int)((NetworkInstanceId)(ref netId)).Value; } PickerNetId = (uint)num; DisplayNumber = display; } } public sealed class ChoiceSuccess { public ChoiceSnapshot Reward { get; } public uint PickerNetId { get; } public int SelectedIndex { get; } public UniquePickup SelectedPickup { get; } internal ChoiceSuccess(ChoiceSnapshot reward, uint pickerId, int index, UniquePickup pickup) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) Reward = reward; PickerNetId = pickerId; SelectedIndex = index; SelectedPickup = pickup; } } public enum ChoiceCancellationReason { OwnerDisconnected, NewRun, RunDestroyed, NetworkStopped, PluginUnloaded, InvalidPickerPrefab } public sealed class ChoiceCancellation { public ChoiceSnapshot Reward { get; } public uint LastPickerNetId { get; } public ChoiceCancellationReason Reason { get; } internal ChoiceCancellation(ChoiceSnapshot reward, uint pickerId, ChoiceCancellationReason reason) { Reward = reward; LastPickerNetId = pickerId; Reason = reason; } } public sealed class CandidateTooltipContext { public PickupPickerController Picker { get; } public uint PickerNetId { get; } public CharacterMaster Owner { get; } public uint OwnerNetId { get; } public uint RunNetId { get; } public ChoiceId? LogicalId { get; } public ChoiceCandidate Candidate { get; } internal CandidateTooltipContext(PickupPickerController picker, CharacterMaster owner, ChoiceId? id, int index, Option option) { //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_0035: 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_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0078: 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_007f: Unknown result type (might be due to invalid IL or missing references) Picker = picker; NetworkInstanceId netId = ((NetworkBehaviour)picker).netId; PickerNetId = ((NetworkInstanceId)(ref netId)).Value; Owner = owner; int num; if (!Object.op_Implicit((Object)(object)owner)) { num = 0; } else { netId = ((NetworkBehaviour)owner).netId; num = (int)((NetworkInstanceId)(ref netId)).Value; } OwnerNetId = (uint)num; LogicalId = id; int num2; if (!Object.op_Implicit((Object)(object)Run.instance)) { num2 = 0; } else { netId = ((NetworkBehaviour)Run.instance).netId; num2 = (int)((NetworkInstanceId)(ref netId)).Value; } RunNetId = (uint)num2; Candidate = new ChoiceCandidate(index, option.pickup, option.available); } } public static class ChoiceExtensionApi { public const int ApiVersion = 1; private static readonly HashSet<string> reportedFailures = new HashSet<string>(); private static bool composing; internal static bool HasCandidateText => ChoiceExtensionApi.CandidateText != null; public static event Action<ChoiceSnapshot> RewardQueued; public static event Action<ChoiceBinding> PickerBound; public static event Action<ChoiceSuccess> RewardSucceeded; public static event Action<ChoiceCancellation> RewardCancelled; public static event Func<CandidateTooltipContext, string> CandidateText; public static bool TryGetServerBinding(PickupPickerController picker, out ChoiceBinding binding) { binding = null; if (NetworkServer.active) { return ChoiceExtensionRuntime.TryGetBinding(picker, out binding); } return false; } internal static void SendQueued(ChoiceSnapshot value) { Send(ChoiceExtensionApi.RewardQueued, value, "RewardQueued"); } internal static void SendBound(ChoiceBinding value) { Send(ChoiceExtensionApi.PickerBound, value, "PickerBound"); } internal static void SendSuccess(ChoiceSuccess value) { Send(ChoiceExtensionApi.RewardSucceeded, value, "RewardSucceeded"); } internal static void SendCancellation(ChoiceCancellation value) { Send(ChoiceExtensionApi.RewardCancelled, value, "RewardCancelled"); } private static void Send<T>(Action<T> handlers, T value, string name) { if (handlers == null) { return; } Delegate[] invocationList = handlers.GetInvocationList(); for (int i = 0; i < invocationList.Length; i++) { Action<T> action = (Action<T>)invocationList[i]; try { action(value); } catch (Exception ex) { ReportFailure(name, action, ex); } } } private static void ReportFailure(string name, Delegate handler, Exception ex) { if (reportedFailures.Count < 8) { string text = name + ":" + handler.Method.DeclaringType?.FullName + ":" + handler.Method.Name + ":" + ex.GetType().FullName; if (reportedFailures.Add(text)) { ThreeChoiceChestsPlugin.WriteLog("[Choice Extension] " + text + "; subscriber skipped.\n" + ex); } } } internal static string ComposeBody(PickupPickerController picker, int index, string original) { //IL_008a: Unknown result type (might be due to invalid IL or missing references) Func<CandidateTooltipContext, string> candidateText = ChoiceExtensionApi.CandidateText; if (candidateText == null || composing || !Object.op_Implicit((Object)(object)picker) || !Object.op_Implicit((Object)(object)((Component)picker).GetComponent<OwnedChoiceMarker>()) || picker.options == null || index < 0 || index >= picker.options.Length) { return original; } NetworkUIPromptController component = ((Component)picker).GetComponent<NetworkUIPromptController>(); CharacterMaster owner = (Object.op_Implicit((Object)(object)component) ? component.currentParticipantMaster : null); ChoiceBinding binding; ChoiceId? id = (TryGetServerBinding(picker, out binding) ? new ChoiceId?(binding.Reward.Id) : ((ChoiceId?)null)); CandidateTooltipContext arg = new CandidateTooltipContext(picker, owner, id, index, picker.options[index]); string text = original; int num = 0; composing = true; try { Delegate[] invocationList = candidateText.GetInvocationList(); for (int i = 0; i < invocationList.Length; i++) { Func<CandidateTooltipContext, string> func = (Func<CandidateTooltipContext, string>)invocationList[i]; if (!Object.op_Implicit((Object)(object)picker)) { break; } try { string text2 = func(arg); if (!string.IsNullOrWhiteSpace(text2)) { if (text2.Length > 1024 || num + text2.Length > 4096 || !TooltipFragment.IsBalanced(text2)) { throw new ArgumentException("Text fragment exceeds limits or contains unsupported/unbalanced rich text."); } text = text + "\n" + text2; num += text2.Length; } } catch (Exception ex) { ReportFailure("CandidateText", func, ex); } } } finally { composing = false; } return text; } } internal enum ChoiceRewardState { Pending, Granting, Succeeded, Cancelled } internal sealed class ChoiceRewardRecord { internal readonly ChoiceSnapshot Snapshot; internal ChoiceRewardState State; internal bool Queued; internal ChoiceBinding Binding; internal ChoiceCancellationReason? DeferredCancellation; internal bool Terminal { get { if (State != ChoiceRewardState.Succeeded) { return State == ChoiceRewardState.Cancelled; } return true; } } internal ChoiceRewardRecord(ChoiceSnapshot snapshot) { Snapshot = snapshot; } } internal static class ChoiceExtensionRuntime { private static readonly Guid session = Guid.NewGuid(); private static ulong runNumber; private static ulong rewardNumber; private static Run scope; private static Run closedScope; private static readonly Dictionary<ChoiceId, ChoiceRewardRecord> rewards = new Dictionary<ChoiceId, ChoiceRewardRecord>(); private static readonly Dictionary<PickupPickerController, ChoiceRewardRecord> bindings = new Dictionary<PickupPickerController, ChoiceRewardRecord>(); private static readonly Queue<Action> notifications = new Queue<Action>(); private static bool dispatching; internal static void BeginRun(Run run) { CloseScope(ChoiceCancellationReason.NewRun); checked { if (run != null) { scope = run; closedScope = null; runNumber++; rewardNumber = 0uL; } } } internal static ChoiceRewardRecord CreateReward(CharacterMaster owner, UniquePickup first, Option[] options) { //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_006d: Unknown result type (might be due to invalid IL or missing references) if (!NetworkServer.active || !Object.op_Implicit((Object)(object)Run.instance)) { return null; } if (scope != Run.instance) { if (closedScope == Run.instance) { return null; } BeginRun(Run.instance); } checked { rewardNumber++; ChoiceId id = new ChoiceId(session, runNumber, rewardNumber); NetworkInstanceId netId = ((NetworkBehaviour)Run.instance).netId; ChoiceRewardRecord choiceRewardRecord = new ChoiceRewardRecord(new ChoiceSnapshot(id, owner, ((NetworkInstanceId)(ref netId)).Value, first, options)); rewards.Add(choiceRewardRecord.Snapshot.Id, choiceRewardRecord); return choiceRewardRecord; } } internal static void NotifyQueued(ChoiceRewardRecord record) { if (record != null && !record.Queued && !record.Terminal) { record.Queued = true; notifications.Enqueue(delegate { ChoiceExtensionApi.SendQueued(record.Snapshot); }); Flush(); } } internal static void Bind(ChoiceRewardRecord record, PickupPickerController picker) { if (record != null && !record.Terminal && Object.op_Implicit((Object)(object)picker) && rewards.ContainsKey(record.Snapshot.Id) && (record.Binding == null || !((Object)(object)record.Binding.Picker == (Object)(object)picker))) { Detach(record); ulong display = ((record.Binding == null) ? 1 : checked(record.Binding.DisplayNumber + 1)); ChoiceBinding binding = new ChoiceBinding(record.Snapshot, picker, display); record.Binding = binding; bindings[picker] = record; notifications.Enqueue(delegate { ChoiceExtensionApi.SendBound(binding); }); Flush(); } } internal static bool TryGetBinding(PickupPickerController picker, out ChoiceBinding binding) { binding = null; if (!Object.op_Implicit((Object)(object)picker) || !bindings.TryGetValue(picker, out var value) || value.Terminal) { return false; } binding = value.Binding; return true; } internal static bool BeginGrant(ChoiceRewardRecord record) { if (record == null || record.State != ChoiceRewardState.Pending || record.DeferredCancellation.HasValue || !rewards.ContainsKey(record.Snapshot.Id)) { return false; } record.State = ChoiceRewardState.Granting; return true; } internal static void FinishGrant(ChoiceRewardRecord record, bool granted, int index, UniquePickup pickup) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) if (record == null || record.State != ChoiceRewardState.Granting) { return; } if (granted) { record.State = ChoiceRewardState.Succeeded; ChoiceSuccess success = new ChoiceSuccess(record.Snapshot, record.Binding?.PickerNetId ?? 0, index, pickup); Detach(record); rewards.Remove(record.Snapshot.Id); notifications.Enqueue(delegate { ChoiceExtensionApi.SendSuccess(success); }); } else { record.State = ChoiceRewardState.Pending; if (record.DeferredCancellation.HasValue) { Cancel(record, record.DeferredCancellation.Value); } } } internal static void ReleaseDisplay(ChoiceRewardRecord record) { if (record != null) { Detach(record); } } private static void Detach(ChoiceRewardRecord record) { if (record.Binding != null && record.Binding.Picker != null) { bindings.Remove(record.Binding.Picker); } } internal static void Cancel(ChoiceRewardRecord record, ChoiceCancellationReason reason) { if (record == null || record.Terminal) { return; } if (record.State == ChoiceRewardState.Granting) { record.DeferredCancellation = record.DeferredCancellation ?? reason; Detach(record); return; } record.State = ChoiceRewardState.Cancelled; ChoiceCancellation cancellation = new ChoiceCancellation(record.Snapshot, record.Binding?.PickerNetId ?? 0, reason); Detach(record); rewards.Remove(record.Snapshot.Id); notifications.Enqueue(delegate { ChoiceExtensionApi.SendCancellation(cancellation); }); } internal static void CloseScope(ChoiceCancellationReason reason) { foreach (ChoiceRewardRecord item in new List<ChoiceRewardRecord>(rewards.Values)) { Cancel(item, reason); } rewards.Clear(); bindings.Clear(); if (scope != null) { closedScope = scope; } scope = null; } internal static void Flush() { if (dispatching) { return; } dispatching = true; try { while (notifications.Count > 0) { notifications.Dequeue()(); } } finally { dispatching = false; } } } internal sealed class ChoicePanelState { private struct SelectableState { internal Selectable selectable; internal bool interactable; internal Navigation navigation; } private struct BehaviourState { internal Behaviour behaviour; internal bool enabled; } internal readonly PickupPickerPanel panel; private readonly CanvasGroup visibility; private readonly MPEventSystem eventSystem; private GameObject savedSelection; private SelectableState[] selectables; private BehaviourState[] inputBehaviours; internal bool hidden { get; private set; } internal ChoicePanelState(PickupPickerPanel panel) { this.panel = panel; visibility = ((Component)panel).gameObject.AddComponent<CanvasGroup>(); MPEventSystemLocator component = ((Component)panel).GetComponent<MPEventSystemLocator>(); eventSystem = (((Object)(object)component != (Object)null) ? component.eventSystem : null); } internal void SetHidden(bool value) { //IL_0248: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)panel == (Object)null || (Object)(object)visibility == (Object)null) { return; } if (hidden == value) { if (hidden) { ClearPanelSelection(); } return; } hidden = value; if (hidden) { savedSelection = (((Object)(object)eventSystem != (Object)null && IsPanelObject(((EventSystem)eventSystem).currentSelectedGameObject)) ? ((EventSystem)eventSystem).currentSelectedGameObject : null); ClearPanelSelection(); Selectable[] componentsInChildren = ((Component)panel).GetComponentsInChildren<Selectable>(true); selectables = new SelectableState[componentsInChildren.Length]; for (int i = 0; i < componentsInChildren.Length; i++) { Selectable val = componentsInChildren[i]; selectables[i] = new SelectableState { selectable = val, interactable = val.interactable, navigation = val.navigation }; val.interactable = false; Navigation navigation = val.navigation; ((Navigation)(ref navigation)).mode = (Mode)0; val.navigation = navigation; } List<Behaviour> list = new List<Behaviour>(); list.AddRange((IEnumerable<Behaviour>)(object)((Component)panel).GetComponentsInChildren<GraphicRaycaster>(true)); list.AddRange((IEnumerable<Behaviour>)(object)((Component)panel).GetComponentsInChildren<HGGamepadInputEvent>(true)); list.AddRange((IEnumerable<Behaviour>)(object)((Component)panel).GetComponentsInChildren<UILayerKey>(true)); inputBehaviours = new BehaviourState[list.Count]; for (int j = 0; j < list.Count; j++) { inputBehaviours[j] = new BehaviourState { behaviour = list[j], enabled = list[j].enabled }; list[j].enabled = false; } visibility.alpha = 0f; visibility.interactable = false; visibility.blocksRaycasts = false; } else { visibility.alpha = 1f; visibility.interactable = true; visibility.blocksRaycasts = true; SelectableState[] array = selectables; for (int k = 0; k < array.Length; k++) { SelectableState selectableState = array[k]; if ((Object)(object)selectableState.selectable != (Object)null) { selectableState.selectable.interactable = selectableState.interactable; selectableState.selectable.navigation = selectableState.navigation; } } BehaviourState[] array2 = inputBehaviours; for (int k = 0; k < array2.Length; k++) { BehaviourState behaviourState = array2[k]; if ((Object)(object)behaviourState.behaviour != (Object)null) { behaviourState.behaviour.enabled = behaviourState.enabled; } } if ((Object)(object)eventSystem != (Object)null && (Object)(object)savedSelection != (Object)null && savedSelection.activeInHierarchy) { Selectable component = savedSelection.GetComponent<Selectable>(); if ((Object)(object)component != (Object)null && component.IsInteractable()) { ((EventSystem)eventSystem).SetSelectedGameObject(savedSelection); } } savedSelection = null; selectables = null; inputBehaviours = null; } ((Component)panel).GetComponent<ChoiceTooltipPanel>()?.SetHidden(hidden); } private bool IsPanelObject(GameObject target) { if ((Object)(object)target != (Object)null) { if (!((Object)(object)target == (Object)(object)((Component)panel).gameObject)) { return target.transform.IsChildOf(((Component)panel).transform); } return true; } return false; } private void ClearPanelSelection() { if ((Object)(object)eventSystem != (Object)null && IsPanelObject(((EventSystem)eventSystem).currentSelectedGameObject)) { ((EventSystem)eventSystem).SetSelectedGameObject((GameObject)null); } } } internal sealed class ChoiceTooltipPanel : MonoBehaviour { private PickupPickerPanel panel; private readonly Dictionary<MPButton, PickupDef> candidates = new Dictionary<MPButton, PickupDef>(); private readonly Dictionary<MPButton, int> candidateIndices = new Dictionary<MPButton, int>(); private readonly List<TooltipProvider> ownedProviders = new List<TooltipProvider>(); private readonly Dictionary<PickupDef, Color> tooltipColors = new Dictionary<PickupDef, Color>(); private static readonly HashSet<string> reportedStyleFailures = new HashSet<string>(); private static readonly HashSet<string> reportedStyleSources = new HashSet<string>(); private bool bound; private bool hidden; internal void RecordButtonIndex(MPButton button, int index) { if (Object.op_Implicit((Object)(object)button) && index >= 0) { candidateIndices[button] = index; } } private void Awake() { panel = ((Component)this).GetComponent<PickupPickerPanel>(); ((UnityEvent<MPButton, PickupDef>)(object)panel.pickupBaseContentReady).AddListener((UnityAction<MPButton, PickupDef>)CandidateReady); } private void CandidateReady(MPButton button, PickupDef pickup) { if (!Object.op_Implicit((Object)(object)button)) { return; } if (pickup == null) { candidates.Remove(button); } else { candidates[button] = pickup; } if (!IsOwnedPanel()) { return; } TooltipProvider component = ((Component)button).GetComponent<TooltipProvider>(); if (Object.op_Implicit((Object)(object)component)) { TooltipController.RemoveTooltip(component); } if (pickup == null) { if (Object.op_Implicit((Object)(object)component)) { ((Behaviour)component).enabled = false; } } else { Configure(button, pickup); } } private bool IsOwnedPanel() { if (Object.op_Implicit((Object)(object)panel) && Object.op_Implicit((Object)(object)panel.pickerController)) { return Object.op_Implicit((Object)(object)((Component)panel.pickerController).GetComponent<OwnedChoiceMarker>()); } return false; } private void LateUpdate() { if (!IsOwnedPanel()) { return; } if (!bound) { ThreeChoiceChestsPlugin.BindLocalPanel(panel); bound = true; } foreach (KeyValuePair<MPButton, PickupDef> item in ChoiceExtensionApi.HasCandidateText ? new Dictionary<MPButton, PickupDef>(candidates) : candidates) { MPButton key = item.Key; if (Object.op_Implicit((Object)(object)key)) { Configure(key, item.Value); } } } private void Configure(MPButton button, PickupDef pickup) { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) TooltipProvider val = ((Component)button).GetComponent<TooltipProvider>(); if (!Object.op_Implicit((Object)(object)val)) { val = ((Component)button).gameObject.AddComponent<TooltipProvider>(); } if (!ownedProviders.Contains(val)) { ownedProviders.Add(val); } string text = Language.GetString(pickup.nameToken); string text2 = ThreeChoiceShortTextCatalog.GetEffect(ItemCatalog.GetItemDef(pickup.itemIndex), EquipmentCatalog.GetEquipmentDef(pickup.equipmentIndex)); if (!hidden && ((Behaviour)this).isActiveAndEnabled && ((Selectable)button).IsInteractable() && candidateIndices.TryGetValue(button, out var value)) { text2 = ChoiceExtensionApi.ComposeBody(panel.pickerController, value, text2); } if (Object.op_Implicit((Object)(object)button) && Object.op_Implicit((Object)(object)val) && IsOwnedPanel()) { if (val.overrideTitleText != text || val.overrideBodyText != text2) { TooltipController.RemoveTooltip(val); } val.overrideTitleText = text; val.overrideBodyText = text2; val.titleColor = ((pickup.baseColor != Color.clear) ? pickup.baseColor : Color.white); val.bodyColor = Color.white; val.disableTitleRichText = (val.disableBodyRichText = false); val.AllowTooltipOnNavigationSelect = false; val.extraUIDisplayPrefab = null; ((Behaviour)val).enabled = !hidden && ((Behaviour)this).isActiveAndEnabled && ((Selectable)button).IsInteractable(); val.titleColor = GetSafeTooltipColor(pickup, val.titleColor); } } private unsafe Color GetSafeTooltipColor(PickupDef pickup, Color fallback) { //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0013: 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_0017: 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_0144: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_0108: 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_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002b: 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_007b: Unknown result type (might be due to invalid IL or missing references) if (tooltipColors.TryGetValue(pickup, out var value)) { return value; } Color val = fallback; try { val = ReadNativeTooltipColor(pickup, out var source); if (!IsVisibleColor(val)) { Color val2 = val; throw new InvalidOperationException("Native tooltip color is clear, transparent or non-finite: " + ((object)(*(Color*)(&val2))/*cast due to .constrained prefix*/).ToString()); } if (reportedStyleSources.Count < 8 && reportedStyleSources.Add(source)) { string[] obj = new string[6] { "[Choice Tooltip] Native title source=", source, "; color=", null, null, null }; Color val2 = val; obj[3] = ((object)(*(Color*)(&val2))/*cast due to .constrained prefix*/).ToString(); obj[4] = "; token="; obj[5] = pickup.nameToken; ThreeChoiceChestsPlugin.WriteLog(string.Concat(obj)); } } catch (Exception ex) { val = fallback; string item = pickup.nameToken + ":" + ex.GetType().FullName; if (reportedStyleFailures.Count < 8 && reportedStyleFailures.Add(item)) { string[] obj2 = new string[6] { "[Choice Tooltip] Native title lookup failed; retained working 1.3.1 tooltip color. token=", pickup.nameToken, "; fallback=", null, null, null }; Color val2 = fallback; obj2[3] = ((object)(*(Color*)(&val2))/*cast due to .constrained prefix*/).ToString(); obj2[4] = "\n"; obj2[5] = ex?.ToString(); ThreeChoiceChestsPlugin.WriteLog(string.Concat(obj2)); } } tooltipColors[pickup] = val; return val; } private static bool IsVisibleColor(Color color) { //IL_0000: 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_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0027: 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_0041: 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_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) if (color.a > 0f && !float.IsNaN(color.r) && !float.IsInfinity(color.r) && !float.IsNaN(color.g) && !float.IsInfinity(color.g) && !float.IsNaN(color.b) && !float.IsInfinity(color.b) && !float.IsNaN(color.a)) { return !float.IsInfinity(color.a); } return false; } [MethodImpl(MethodImplOptions.NoInlining)] private static Color ReadNativeTooltipColor(PickupDef pickup, out string source) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_002d: 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_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) ItemDef itemDef = ItemCatalog.GetItemDef(pickup.itemIndex); if (Object.op_Implicit((Object)(object)itemDef)) { source = "ItemIcon.SetItemIndex/ItemDef.darkColorIndex"; return Color32.op_Implicit(ColorCatalog.GetColor(itemDef.darkColorIndex)); } EquipmentDef equipmentDef = EquipmentCatalog.GetEquipmentDef(pickup.equipmentIndex); if (Object.op_Implicit((Object)(object)equipmentDef)) { source = "EquipmentIcon.SetDisplayData/EquipmentDef.colorIndex"; return Color32.op_Implicit(ColorCatalog.GetColor(equipmentDef.colorIndex)); } throw new InvalidOperationException("Candidate has no native item/equipment tooltip color source."); } internal void SetHidden(bool value) { hidden = value; if (!IsOwnedPanel()) { return; } foreach (KeyValuePair<MPButton, PickupDef> item in ChoiceExtensionApi.HasCandidateText ? new Dictionary<MPButton, PickupDef>(candidates) : candidates) { if (Object.op_Implicit((Object)(object)item.Key)) { TooltipProvider component = ((Component)item.Key).GetComponent<TooltipProvider>(); if (value && Object.op_Implicit((Object)(object)component)) { TooltipController.RemoveTooltip(component); } Configure(item.Key, item.Value); } } } private void OnDisable() { ClearTooltips(); } private void ClearTooltips() { foreach (TooltipProvider ownedProvider in ownedProviders) { if (Object.op_Implicit((Object)(object)ownedProvider)) { TooltipController.RemoveTooltip(ownedProvider); ((Behaviour)ownedProvider).enabled = false; } } } private void OnDestroy() { if (Object.op_Implicit((Object)(object)panel)) { ((UnityEvent<MPButton, PickupDef>)(object)panel.pickupBaseContentReady).RemoveListener((UnityAction<MPButton, PickupDef>)CandidateReady); } ClearTooltips(); candidates.Clear(); candidateIndices.Clear(); ownedProviders.Clear(); tooltipColors.Clear(); ThreeChoiceChestsPlugin.LocalPanelEnded(panel); } } [BepInPlugin("com.local.threechoicechests", "ThreeChoiceChests", "1.3.2")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class ThreeChoiceChestsPlugin : BaseUnityPlugin { private sealed class ActiveChoice { public PickupPickerController picker; public NetworkUIPromptController prompt; public PendingChoice pending; public CharacterMaster ownerMaster; public bool completed; public bool restoring; public ChoicePanelState panelState; public int selectedIndex = -1; public bool awarding; } [HarmonyPatch(typeof(PickupPickerPanel), "Awake")] private static class AttachChoiceTooltipPanelPatch { private static void Postfix(PickupPickerPanel __instance) { ((Component)__instance).gameObject.AddComponent<ChoiceTooltipPanel>(); } } [HarmonyPatch(typeof(PickupPickerPanel), "OnCreateButton")] private static class RecordChoiceButtonIndexPatch { private static void Postfix(PickupPickerPanel __instance, int __0, MPButton __1) { ((Component)__instance).GetComponent<ChoiceTooltipPanel>()?.RecordButtonIndex(__1, __0); } } [HarmonyPatch(typeof(PickupPickerController), "OnInteractionBegin")] private static class GuardOwnedInteractionPatch { private static bool Prefix(PickupPickerController __instance, Interactor __0) { ActiveChoice currentChoice = ThreeChoiceChestsPlugin.currentChoice; if (currentChoice == null || (Object)(object)currentChoice.picker != (Object)(object)__instance) { return true; } CharacterBody val = (Object.op_Implicit((Object)(object)__0) ? ((Component)__0).GetComponent<CharacterBody>() : null); if (!currentChoice.completed && Object.op_Implicit((Object)(object)val)) { return (Object)(object)val.master == (Object)(object)currentChoice.ownerMaster; } return false; } } [HarmonyPatch(typeof(PickupPickerController), "FixedUpdateServer")] private static class OwnedPickerDistancePatch { private static bool Prefix(PickupPickerController __instance) { ActiveChoice currentChoice = ThreeChoiceChestsPlugin.currentChoice; if (!NetworkServer.active || !Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<OwnedChoiceMarker>()) || !OwnsPicker(currentChoice, __instance) || !Object.op_Implicit((Object)(object)currentChoice.prompt) || (Object)(object)currentChoice.prompt.currentParticipantMaster != (Object)(object)currentChoice.ownerMaster || !OwnerConnected(currentChoice.ownerMaster)) { return true; } return !Object.op_Implicit((Object)(object)currentChoice.ownerMaster.GetBody()); } } [HarmonyPatch(typeof(PickupPickerController), "OnDisplayBegin")] private static class BindChoicePanelPatch { private static void Postfix(PickupPickerController __instance, PickupPickerPanel ___panelInstanceController) { if ((Object)(object)___panelInstanceController != (Object)null) { BindLocalPanel(___panelInstanceController); } } } [HarmonyPatch(typeof(PickupPickerPanel), "DestroyIt")] private static class PreserveChoicePanelPatch { private static bool Prefix(PickupPickerPanel __instance) { ActiveChoice uIChoice = UIChoice; if (!OwnsPicker(uIChoice, __instance.pickerController) || uIChoice.panelState == null || (Object)(object)uIChoice.panelState.panel != (Object)(object)__instance || !IsChoiceScoreboardOpen(uIChoice)) { return true; } uIChoice.panelState.SetHidden(value: true); return false; } } [HarmonyPatch(typeof(HUD), "ActivateScoreboard")] private static class ScoreboardOpenedPatch { private static void Postfix(HUD __instance) { if ((Object)(object)GetChoiceHud(UIChoice) == (Object)(object)__instance) { SyncChoicePanel(UIChoice); } } } [HarmonyPatch(typeof(HUD), "DeactivateScoreboard")] private static class ScoreboardClosedPatch { private static void Postfix(HUD __instance) { if ((Object)(object)GetChoiceHud(UIChoice) == (Object)(object)__instance) { SyncChoicePanel(UIChoice); } } } [HarmonyPatch(typeof(PickupPickerController), "SubmitChoice")] private static class GuardHiddenChoiceInputPatch { private static bool Prefix(PickupPickerController __instance) { ActiveChoice uIChoice = UIChoice; if (OwnsPicker(uIChoice, __instance)) { ChoicePanelState panelState = uIChoice.panelState; if (panelState == null || !panelState.hidden) { return !IsChoiceScoreboardOpen(uIChoice); } return false; } return true; } } [HarmonyPatch(typeof(PickupPickerController), "GetInspectInfoProvider")] private static class HideOwnedCommandInspectionPatch { private static void Postfix(PickupPickerController __instance, ref IInspectInfoProvider __result) { ActiveChoice uIChoice = UIChoice; if (OwnsPicker(uIChoice, __instance) && IsChoiceScoreboardOpen(uIChoice) && (Object)(object)uIChoice.prompt != (Object)null && (Object)(object)uIChoice.ownerMaster != (Object)null && (Object)(object)uIChoice.prompt.currentParticipantMaster == (Object)(object)uIChoice.ownerMaster) { __result = null; } } } [HarmonyPatch] private static class CreatePickupDropletPatch { private static MethodBase TargetMethod() { return typeof(PickupDropletController).GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault(delegate(MethodInfo method) { if (method.Name != "CreatePickupDroplet") { return false; } ParameterInfo[] parameters = method.GetParameters(); return parameters.Length == 3 && parameters[0].ParameterType == typeof(CreatePickupInfo) && parameters[1].ParameterType == typeof(Vector3) && parameters[2].ParameterType == typeof(Vector3); }); } private static bool Prefix(ref CreatePickupInfo __0, Vector3 __1, Vector3 __2) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) return !TryCreateThreeChoicePicker(ref __0, __1); } } [HarmonyPatch(typeof(PickupPickerController), "HandlePickupSelected")] private static class ValidateOwnedSelectionPatch { private static bool Prefix(PickupPickerController __instance, int __0) { ActiveChoice currentChoice = ThreeChoiceChestsPlugin.currentChoice; if (currentChoice == null || (Object)(object)currentChoice.picker != (Object)(object)__instance) { return true; } CharacterBody val = (Object.op_Implicit((Object)(object)currentChoice.ownerMaster) ? currentChoice.ownerMaster.GetBody() : null); if (!NetworkServer.active || currentChoice.completed || currentChoice.awarding || currentChoice.pending.extensionReward.Terminal || !Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val.healthComponent) || !val.healthComponent.alive || !Object.op_Implicit((Object)(object)val.inventory) || (Object)(object)currentChoice.prompt.currentParticipantMaster != (Object)(object)currentChoice.ownerMaster || __0 < 0 || __0 >= currentChoice.pending.options.Length || !currentChoice.pending.options[__0].available) { return false; } currentChoice.selectedIndex = __0; currentChoice.awarding = true; return true; } } [CompilerGenerated] private static class <>O { public static hook_OnInteractionBegin <0>__PurchaseInteraction_OnInteractionBegin; public static Action<Run> <1>__RunStarted; public static Action<Run> <2>__RunDestroyed; public static Action <3>__NetworkStopped; } public const string PluginGUID = "com.local.threechoicechests"; public const string PluginName = "ThreeChoiceChests"; public const string PluginVersion = "1.3.2"; private Harmony harmony; private static GameObject commandCubePrefab; private static readonly Queue<PendingChoice> pendingChoices = new Queue<PendingChoice>(); private static bool pickerActive; private static long rewardEnqueueOrder; private static ActiveChoice currentChoice; private static ActiveChoice localChoice; private static ThreeChoiceChestsPlugin instance; private static ActiveChoice UIChoice => localChoice ?? currentChoice; internal static void WriteLog(string message) { ThreeChoiceChestsPlugin threeChoiceChestsPlugin = instance; if (threeChoiceChestsPlugin != null) { ((BaseUnityPlugin)threeChoiceChestsPlugin).Logger.LogInfo((object)message); } } private void Awake() { //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Expected O, but got Unknown //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Expected O, but got Unknown instance = this; OwnedPickupGrant.Validate(); SelectionProtection.Install(); MarkChest("RoR2/Base/Chest1/Chest1.prefab", ThreeChoiceChestCategory.General); MarkChest("RoR2/Base/CategoryChest/CategoryChestDamage.prefab", ThreeChoiceChestCategory.Damage); MarkChest("RoR2/Base/CategoryChest/CategoryChestHealing.prefab", ThreeChoiceChestCategory.Healing); MarkChest("RoR2/Base/CategoryChest/CategoryChestUtility.prefab", ThreeChoiceChestCategory.Utility); MarkChest("RoR2/DLC1/CategoryChest2/CategoryChest2Damage Variant.prefab", ThreeChoiceChestCategory.Damage); MarkChest("RoR2/DLC1/CategoryChest2/CategoryChest2Healing Variant.prefab", ThreeChoiceChestCategory.Healing); MarkChest("RoR2/DLC1/CategoryChest2/CategoryChest2Utility Variant.prefab", ThreeChoiceChestCategory.Utility); MarkChest("RoR2/Base/Chest2/Chest2.prefab", ThreeChoiceChestCategory.General); MarkChest("RoR2/Base/GoldChest/GoldChest.prefab", ThreeChoiceChestCategory.General); MarkChest("RoR2/Base/Chest1StealthedVariant/Chest1StealthedVariant.prefab", ThreeChoiceChestCategory.General); MarkChest("RoR2/Base/EquipmentBarrel/EquipmentBarrel.prefab", ThreeChoiceChestCategory.General); GameObject val = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Command/CommandCube.prefab").WaitForCompletion(); if ((Object)(object)val == (Object)null) { ((BaseUnityPlugin)this).Logger.LogError((object)"Could not load CommandCube prefab."); return; } commandCubePrefab = PrefabAPI.InstantiateClone(val, "ThreeChoiceFrozenRollPicker", false); commandCubePrefab.AddComponent<OwnedChoiceMarker>(); HideCommandCubePrefab(commandCubePrefab); PrefabAPI.RegisterNetworkPrefab(commandCubePrefab); object obj = <>O.<0>__PurchaseInteraction_OnInteractionBegin; if (obj == null) { hook_OnInteractionBegin val2 = PurchaseInteraction_OnInteractionBegin; <>O.<0>__PurchaseInteraction_OnInteractionBegin = val2; obj = (object)val2; } PurchaseInteraction.OnInteractionBegin += (hook_OnInteractionBegin)obj; harmony = new Harmony("com.local.threechoicechests"); harmony.PatchAll(typeof(CreatePickupDropletPatch)); harmony.PatchAll(typeof(ChestRewardCapture)); harmony.PatchAll(typeof(OwnedPickerDistancePatch)); harmony.PatchAll(typeof(PreserveChoicePanelPatch)); harmony.PatchAll(typeof(BindChoicePanelPatch)); harmony.PatchAll(typeof(ScoreboardOpenedPatch)); harmony.PatchAll(typeof(ScoreboardClosedPatch)); harmony.PatchAll(typeof(GuardHiddenChoiceInputPatch)); harmony.PatchAll(typeof(HideOwnedCommandInspectionPatch)); harmony.PatchAll(typeof(ValidateOwnedSelectionPatch)); harmony.PatchAll(typeof(AttachChoiceTooltipPanelPatch)); harmony.PatchAll(typeof(RecordChoiceButtonIndexPatch)); harmony.PatchAll(typeof(GuardOwnedInteractionPatch)); Run.onRunStartGlobal += RunStarted; Run.onRunDestroyGlobal += RunDestroyed; NetworkManagerSystem.onStopClientGlobal += NetworkStopped; NetworkManagerSystem.onStopServerGlobal += NetworkStopped; if (NetworkServer.active && Object.op_Implicit((Object)(object)Run.instance)) { ChoiceExtensionRuntime.BeginRun(Run.instance); } ((BaseUnityPlugin)this).Logger.LogInfo((object)"ThreeChoiceChests 1.3.2 loaded."); } private void OnDestroy() { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown object obj = <>O.<0>__PurchaseInteraction_OnInteractionBegin; if (obj == null) { hook_OnInteractionBegin val = PurchaseInteraction_OnInteractionBegin; <>O.<0>__PurchaseInteraction_OnInteractionBegin = val; obj = (object)val; } PurchaseInteraction.OnInteractionBegin -= (hook_OnInteractionBegin)obj; Harmony obj2 = harmony; if (obj2 != null) { obj2.UnpatchSelf(); } Run.onRunStartGlobal -= RunStarted; Run.onRunDestroyGlobal -= RunDestroyed; NetworkManagerSystem.onStopClientGlobal -= NetworkStopped; NetworkManagerSystem.onStopServerGlobal -= NetworkStopped; SelectionProtection.Uninstall(); ChoiceExtensionRuntime.CloseScope(ChoiceCancellationReason.PluginUnloaded); if (currentChoice != null) { currentChoice.completed = true; } UIChoice?.panelState?.SetHidden(value: false); if (NetworkServer.active && (Object)(object)currentChoice?.picker != (Object)null) { NetworkServer.Destroy(((Component)currentChoice.picker).gameObject); } pendingChoices.Clear(); pickerActive = false; currentChoice = null; localChoice = null; ChoiceExtensionRuntime.Flush(); instance = null; } private static void ResetChoiceState(ChoiceCancellationReason reason, Run newRun = null) { ChoiceExtensionRuntime.CloseScope(reason); if (currentChoice != null) { currentChoice.completed = true; } UIChoice?.panelState?.SetHidden(value: false); if (NetworkServer.active && (Object)(object)currentChoice?.picker != (Object)null) { NetworkServer.Destroy(((Component)currentChoice.picker).gameObject); } pendingChoices.Clear(); pickerActive = false; currentChoice = null; localChoice = null; SelectionProtection.Clear(); if (Object.op_Implicit((Object)(object)newRun)) { ChoiceExtensionRuntime.BeginRun(newRun); } ChoiceExtensionRuntime.Flush(); } private static void RunStarted(Run run) { ResetChoiceState(ChoiceCancellationReason.NewRun, run); } private static void RunDestroyed(Run run) { ResetChoiceState(ChoiceCancellationReason.RunDestroyed); } private static void NetworkStopped() { ResetChoiceState(ChoiceCancellationReason.NetworkStopped); } private void Update() { SyncChoicePanel(UIChoice); if (localChoice != null && !Object.op_Implicit((Object)(object)localChoice.picker)) { LocalPanelEnded(localChoice.panelState?.panel); } if (NetworkServer.active) { ServerWatchdog(); SelectionProtection.Tick(); } } private void LateUpdate() { SelectionProtection.LateTick(); } internal static void BindLocalPanel(PickupPickerPanel panel) { if (!Object.op_Implicit((Object)(object)panel) || !Object.op_Implicit((Object)(object)panel.pickerController) || !Object.op_Implicit((Object)(object)((Component)panel.pickerController).GetComponent<OwnedChoiceMarker>())) { return; } PickupPickerController pickerController = panel.pickerController; NetworkUIPromptController component = ((Component)pickerController).GetComponent<NetworkUIPromptController>(); if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.currentParticipantMaster)) { ActiveChoice activeChoice = (localChoice = (OwnsPicker(localChoice, pickerController) ? localChoice : (OwnsPicker(currentChoice, pickerController) ? currentChoice : new ActiveChoice { picker = pickerController, prompt = component, ownerMaster = component.currentParticipantMaster }))); if (activeChoice.panelState == null || (Object)(object)activeChoice.panelState.panel != (Object)(object)panel) { activeChoice.panelState = new ChoicePanelState(panel); } SelectionProtection.SetLocalSelecting(activeChoice.ownerMaster, value: true); SyncChoicePanel(activeChoice); } } internal static void LocalPanelEnded(PickupPickerPanel panel) { if (localChoice == null || !((Object)(object)localChoice.panelState?.panel != (Object)(object)panel)) { localChoice = null; SelectionProtection.SetLocalSelecting(null, value: false); } } private static bool OwnerConnected(CharacterMaster master) { if ((Object)(object)master != (Object)null) { return NetworkUser.readOnlyInstancesList.Any((NetworkUser user) => Object.op_Implicit((Object)(object)user) && (Object)(object)user.master == (Object)(object)master); } return false; } private static void ServerWatchdog() { ActiveChoice activeChoice = currentChoice; if (activeChoice != null && activeChoice.awarding) { return; } if (activeChoice != null && !activeChoice.completed) { CharacterBody val = (Object.op_Implicit((Object)(object)activeChoice.ownerMaster) ? activeChoice.ownerMaster.GetBody() : null); if (!OwnerConnected(activeChoice.ownerMaster) || !Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val.healthComponent) || !val.healthComponent.alive || !Object.op_Implicit((Object)(object)activeChoice.picker) || !Object.op_Implicit((Object)(object)activeChoice.prompt)) { activeChoice.completed = true; SelectionProtection.SetServerSelecting(activeChoice.ownerMaster, value: false); if (Object.op_Implicit((Object)(object)activeChoice.prompt)) { activeChoice.prompt.SetParticipantMaster((CharacterMaster)null); } if (Object.op_Implicit((Object)(object)activeChoice.picker)) { NetworkServer.Destroy(((Component)activeChoice.picker).gameObject); } ChoiceExtensionRuntime.ReleaseDisplay(activeChoice.pending.extensionReward); if (OwnerConnected(activeChoice.ownerMaster)) { pendingChoices.Enqueue(activeChoice.pending); } else { ChoiceExtensionRuntime.Cancel(activeChoice.pending.extensionReward, ChoiceCancellationReason.OwnerDisconnected); } currentChoice = null; pickerActive = false; ChoiceExtensionRuntime.Flush(); return; } bool flag = (Object)(object)activeChoice.prompt.currentParticipantMaster == (Object)(object)activeChoice.ownerMaster; SelectionProtection.SetServerSelecting(activeChoice.ownerMaster, flag); if (!flag && !activeChoice.restoring && (Object)(object)instance != (Object)null) { activeChoice.restoring = true; ((MonoBehaviour)instance).StartCoroutine(RestoreChoiceAfterDisplayEnd(activeChoice)); } } if (!pickerActive) { OpenNextPendingChoice(); } } private static bool OwnsPicker(ActiveChoice choice, PickupPickerController picker) { if (choice != null && !choice.completed && (Object)(object)choice.picker != (Object)null) { return (Object)(object)choice.picker == (Object)(object)picker; } return false; } private static HUD GetChoiceHud(ActiveChoice choice) { LocalUser? obj = (((Object)(object)choice?.prompt != (Object)null) ? ((IEnumerable<LocalUser>)LocalUserManager.readOnlyLocalUsersList).FirstOrDefault((Func<LocalUser, bool>)((LocalUser user) => Object.op_Implicit((Object)(object)((user != null) ? user.cachedBody : null)) && (Object)(object)user.cachedBody.master == (Object)(object)choice.prompt.currentParticipantMaster)) : null); CameraRigController val = ((obj != null) ? obj.cameraRigController : null); if (!((Object)(object)val != (Object)null)) { return null; } return val.hud; } private static bool IsChoiceScoreboardOpen(ActiveChoice choice) { HUD choiceHud = GetChoiceHud(choice); if ((Object)(object)choiceHud != (Object)null && (Object)(object)choiceHud.scoreboardPanel != (Object)null) { return choiceHud.scoreboardPanel.activeInHierarchy; } return false; } private static void SyncChoicePanel(ActiveChoice choice) { if (choice != null && !choice.completed && choice == UIChoice) { choice.panelState?.SetHidden(IsChoiceScoreboardOpen(choice)); } } private void MarkChest(string address, ThreeChoiceChestCategory category) { //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) GameObject val = Addressables.LoadAssetAsync<GameObject>((object)address).WaitForCompletion(); if ((Object)(object)val == (Object)null) { ((BaseUnityPlugin)this).Logger.LogError((object)("Could not load chest prefab: " + address)); return; } ThreeChoiceChestMarker threeChoiceChestMarker = val.GetComponent<ThreeChoiceChestMarker>(); if ((Object)(object)threeChoiceChestMarker == (Object)null) { threeChoiceChestMarker = val.AddComponent<ThreeChoiceChestMarker>(); } threeChoiceChestMarker.category = category; } private static void PurchaseInteraction_OnInteractionBegin(orig_OnInteractionBegin orig, PurchaseInteraction self, Interactor activator) { ThreeChoiceChestMarker component = ((Component)self).GetComponent<ThreeChoiceChestMarker>(); if ((Object)(object)component != (Object)null && self.CanBeAffordedByInteractor(activator)) { component.lastInteractor = activator; } orig.Invoke(self, activator); } private static bool TryCreateThreeChoicePicker(ref CreatePickupInfo pickupInfo, Vector3 position) { //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_0063: 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_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Unknown result type (might be due to invalid IL or missing references) //IL_0198: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_01b9: Unknown result type (might be due to invalid IL or missing references) if (!NetworkServer.active) { return false; } ChestBehavior chest = pickupInfo.chest; if ((Object)(object)chest == (Object)null) { return false; } ThreeChoiceChestMarker component = ((Component)chest).GetComponent<ThreeChoiceChestMarker>(); if ((Object)(object)component == (Object)null) { return false; } ChestRewardCapture.Batch rewardBatch = component.rewardBatch; Interactor val = ((rewardBatch != null) ? rewardBatch.activator : component.lastInteractor); if (!Object.op_Implicit((Object)(object)val)) { return false; } UniquePickup pickup = ((CreatePickupInfo)(ref pickupInfo)).pickup; if (!((UniquePickup)(ref pickup)).isValid) { return false; } Option[] array = BuildThreeOptions(pickup, component.category); if (array == null || array.Length == 0) { return false; } CharacterBody component2 = ((Component)val).GetComponent<CharacterBody>(); CharacterMaster val2 = ((rewardBatch != null) ? rewardBatch.ownerMaster : (Object.op_Implicit((Object)(object)component2) ? component2.master : null)); if (!Object.op_Implicit((Object)(object)val2) || !OwnerConnected(val2)) { return false; } if (rewardBatch == null) { component.lastInteractor = null; } ChoiceRewardRecord choiceRewardRecord = ChoiceExtensionRuntime.CreateReward(val2, pickup, array); if (choiceRewardRecord == null) { return false; } PendingChoice item = new PendingChoice { firstPickup = pickup, options = array, activator = val, position = position, rotation = pickupInfo.rotation, ownerMaster = val2, extensionReward = choiceRewardRecord }; pendingChoices.Enqueue(item); int num = ((rewardBatch == null) ? 1 : (++rewardBatch.captured)); PickupDef pickupDef = PickupCatalog.GetPickupDef(pickup.pickupIndex); WriteLog(string.Format("[ThreeChoice RewardCapture] source={0}/{1} owner={2} ownerSource={3} rewardIndex={4} tier={5} saleStar=unknown rewardOrdinal={6} enqueueOrder={7}", ((Object)chest).name, ((Object)chest).GetInstanceID(), ((NetworkBehaviour)val2).netId, rewardBatch?.ownerSource ?? "purchase-hook", pickup.pickupIndex, pickupDef?.itemTier, num, ++rewardEnqueueOrder)); ChoiceExtensionRuntime.NotifyQueued(choiceRewardRecord); if (!pickerActive) { OpenNextPendingChoice(); } return true; } private static void OpenNextPendingChoice() { //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Unknown result type (might be due to invalid IL or missing references) //IL_0257: Unknown result type (might be due to invalid IL or missing references) //IL_026d: Unknown result type (might be due to invalid IL or missing references) //IL_0277: Expected O, but got Unknown //IL_0279: Unknown result type (might be due to invalid IL or missing references) //IL_0283: Expected O, but got Unknown //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) if (!NetworkServer.active || pickerActive || pendingChoices.Count == 0) { return; } PendingChoice pendingChoice = null; int count = pendingChoices.Count; while (count-- > 0) { PendingChoice candidate = pendingChoices.Dequeue(); if (candidate.extensionReward.Terminal) { continue; } if (!OwnerConnected(candidate.ownerMaster)) { ChoiceExtensionRuntime.Cancel(candidate.extensionReward, ChoiceCancellationReason.OwnerDisconnected); continue; } CharacterBody body = candidate.ownerMaster.GetBody(); if (!NetworkUser.readOnlyInstancesList.Any((NetworkUser user) => Object.op_Implicit((Object)(object)user) && (Object)(object)user.master == (Object)(object)candidate.ownerMaster && user.serverIsClientLoaded) || !Object.op_Implicit((Object)(object)body) || !Object.op_Implicit((Object)(object)body.healthComponent) || !body.healthComponent.alive) { pendingChoices.Enqueue(candidate); continue; } candidate.activator = ((Component)body).GetComponent<Interactor>(); if (!Object.op_Implicit((Object)(object)candidate.activator)) { pendingChoices.Enqueue(candidate); continue; } candidate.position = ((Component)body).transform.position; pendingChoice = candidate; break; } if (pendingChoice == null) { ChoiceExtensionRuntime.Flush(); return; } GameObject val = Object.Instantiate<GameObject>(commandCubePrefab, pendingChoice.position, pendingChoice.rotation); HideCommandCubePrefab(val); PickupPickerController component = val.GetComponent<PickupPickerController>(); PickupIndexNetworker component2 = val.GetComponent<PickupIndexNetworker>(); NetworkUIPromptController component3 = val.GetComponent<NetworkUIPromptController>(); if ((Object)(object)component == (Object)null || (Object)(object)component2 == (Object)null || (Object)(object)component3 == (Object)null) { Object.Destroy((Object)(object)val); ChoiceExtensionRuntime.Cancel(pendingChoice.extensionReward, ChoiceCancellationReason.InvalidPickerPrefab); OpenNextPendingChoice(); ChoiceExtensionRuntime.Flush(); return; } component2.NetworkpickupState = pendingChoice.firstPickup; pickerActive = true; NetworkServer.Spawn(val); CharacterBody component4 = ((Component)pendingChoice.activator).GetComponent<CharacterBody>(); ActiveChoice choice = new ActiveChoice { picker = component, prompt = component3, pending = pendingChoice, ownerMaster = (((Object)(object)component4 != (Object)null) ? component4.master : null) }; currentChoice = choice; WriteLog($"[ThreeChoice PickerDistance] pickerId={((Object)component).GetInstanceID()} owner={((NetworkBehaviour)choice.ownerMaster).netId} distanceCheckBypassed=true"); component.onPickupSelected = new PickupIndexUnityEvent(); component.onUniquePickupSelected = new UniquePickupUnityEvent(); ((UnityEvent<UniquePickup>)(object)component.onUniquePickupSelected).AddListener((UnityAction<UniquePickup>)delegate(UniquePickup selectedPickup) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) GrantSelected(choice, selectedPickup); }); component3.onDisplayEnd += delegate { if (!choice.completed && !choice.restoring && (Object)(object)instance != (Object)null && NetworkServer.active) { choice.restoring = true; ((MonoBehaviour)instance).StartCoroutine(RestoreChoiceAfterDisplayEnd(choice)); } }; component.SetOptionsServer(pendingChoice.options); if ((Object)(object)instance != (Object)null) { ((MonoBehaviour)instance).StartCoroutine(OpenPickerAfterSpawn(component, pendingChoice.activator)); } ChoiceExtensionRuntime.Bind(pendingChoice.extensionReward, component); } private static void CompleteChoice(ActiveChoice choice) { if (!choice.completed && currentChoice == choice && NetworkServer.active) { choice.completed = true; SelectionProtection.SetServerSelecting(choice.ownerMaster, value: false); if ((Object)(object)choice.prompt != (Object)null) { choice.prompt.SetParticipantMaster((CharacterMaster)null); } if ((Object)(object)choice.picker != (Object)null) { NetworkServer.Destroy(((Component)choice.picker).gameObject); } currentChoice = null; pickerActive = false; if ((Object)(object)instance != (Object)null) { ((MonoBehaviour)instance).StartCoroutine(OpenNextChoiceNextFrame()); } } } private static void GrantSelected(ActiveChoice choice, UniquePickup pickup) { //IL_0112: 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_0088: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) bool flag = false; bool flag2 = false; try { if (choice.completed || currentChoice != choice || !NetworkServer.active) { return; } CharacterBody val = (Object.op_Implicit((Object)(object)choice.ownerMaster) ? choice.ownerMaster.GetBody() : null); if (Object.op_Implicit((Object)(object)val) && choice.selectedIndex >= 0 && ChoiceExtensionRuntime.BeginGrant(choice.pending.extensionReward)) { flag = true; flag2 = OwnedPickupGrant.Grant(val, pickup); if (flag2) { ChoiceExtensionRuntime.FinishGrant(choice.pending.extensionReward, granted: true, choice.selectedIndex, pickup); WriteLog($"[Choice Selected] owner={((NetworkBehaviour)choice.ownerMaster).netId} pickup={pickup.pickupIndex} candidate={choice.selectedIndex}"); CompleteChoice(choice); } } } catch (Exception ex) { ThreeChoiceChestsPlugin threeChoiceChestsPlugin = instance; if (threeChoiceChestsPlugin != null) { ((BaseUnityPlugin)threeChoiceChestsPlugin).Logger.LogError((object)("[Choice Grant] " + ex)); } } finally { if (flag && !flag2) { ChoiceExtensionRuntime.FinishGrant(choice.pending.extensionReward, granted: false, choice.selectedIndex, pickup); } choice.awarding = false; ChoiceExtensionRuntime.Flush(); } } private static IEnumerator RestoreChoiceAfterDisplayEnd(ActiveChoice choice) { try { yield return (object)new WaitForSecondsRealtime(0.1f); while (!choice.completed && currentChoice == choice && (Object)(object)choice.picker != (Object)null && (Object)(object)choice.prompt != (Object)null && (Object)(object)choice.pending.activator != (Object)null && NetworkServer.active) { if (PauseManager.PauseScreenIsOpen() || IsChoiceScoreboardOpen(choice)) { yield return null; continue; } if ((Object)(object)choice.prompt.currentParticipantMaster != (Object)(object)choice.ownerMaster) { choice.prompt.SetParticipantMasterFromInteractor(choice.pending.activator); } yield return (object)new WaitForSecondsRealtime(0.1f); if (!((Object)(object)choice.prompt != (Object)null) || !((Object)(object)choice.prompt.currentParticipantMaster == (Object)(object)choice.ownerMaster)) { continue; } break; } } finally { choice.restoring = false; } } private static IEnumerator OpenNextChoiceNextFrame() { yield return null; OpenNextPendingChoice(); } private static IEnumerator OpenPickerAfterSpawn(PickupPickerController picker, Interactor activator) { yield return (object)new WaitForSecondsRealtime(0.1f); if (!((Object)(object)picker == (Object)null) && !((Object)(object)activator == (Object)null)) { picker.OnInteractionBegin(activator); } } private static Option[] BuildThreeOptions(UniquePickup firstPickup, ThreeChoiceChestCategory category) { //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_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Invalid comparison between Unknown and I4 //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: 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_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: 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_00f8: Unknown result type (might be due to invalid IL or missing references) PickupIndex pickupIndex = firstPickup.pickupIndex; PickupDef pickupDef = PickupCatalog.GetPickupDef(pickupIndex); if (pickupDef == null || (Object)(object)Run.instance == (Object)null) { return MakeOptions(new List<UniquePickup> { firstPickup }); } List<PickupIndex> list = new List<PickupIndex>(); if ((int)pickupDef.equipmentIndex != -1) { AddMatchingPickups(Run.instance.availableEquipmentDropList, pickupDef, category, equipmentMode: true, list); } else { AddMatchingPickups(Run.instance.availableTier1DropList, pickupDef, category, equipmentMode: false, list); AddMatchingPickups(Run.instance.availableTier2DropList, pickupDef, category, equipmentMode: false, list); AddMatchingPickups(Run.instance.availableTier3DropList, pickupDef, category, equipmentMode: false, list); } List<UniquePickup> list2 = new List<UniquePickup>(); list2.Add(firstPickup); for (int num = list.Count - 1; num >= 0; num--) { if (list[num].value == pickupIndex.value) { list.RemoveAt(num); } } while (list2.Count < 3 && list.Count > 0) { int index = Random.Range(0, list.Count); PickupIndex val = list[index]; list.RemoveAt(index); list2.Add(new UniquePickup(val)); } return MakeOptions(list2); } private static void AddMatchingPickups(List<PickupIndex> source, PickupDef firstDef, ThreeChoiceChestCategory category, bool equipmentMode, List<PickupIndex> destination) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Invalid comparison between Unknown and I4 //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Invalid comparison between Unknown and I4 //IL_003a: 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_005f: 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_0093: Unknown result type (might be due to invalid IL or missing references) if (source == null) { return; } foreach (PickupIndex item in source) { PickupDef pickupDef = PickupCatalog.GetPickupDef(item); if (pickupDef == null) { continue; } if (equipmentMode) { if ((int)pickupDef.equipmentIndex == -1) { continue; } } else if ((int)pickupDef.itemIndex == -1 || pickupDef.itemTier != firstDef.itemTier || !MatchesCategory(pickupDef, category)) { continue; } bool flag = false; foreach (PickupIndex item2 in destination) { if (item2.value == item.value) { flag = true; break; } } if (!flag) { destination.Add(item); } } } private static bool MatchesCategory(PickupDef pickupDef, ThreeChoiceChestCategory category) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Invalid comparison between Unknown and I4 //IL_0011: Unknown result type (might be due to invalid IL or missing references) if (category == ThreeChoiceChestCategory.General) { return true; } if ((int)pickupDef.itemIndex == -1) { return false; } ItemDef itemDef = ItemCatalog.GetItemDef(pickupDef.itemIndex); if ((Object)(object)itemDef == (Object)null) { return false; } return category switch { ThreeChoiceChestCategory.Damage => itemDef.ContainsTag((ItemTag)1), ThreeChoiceChestCategory.Healing => itemDef.ContainsTag((ItemTag)2), ThreeChoiceChestCategory.Utility => itemDef.ContainsTag((ItemTag)3), _ => true, }; } private static Option[] MakeOptions(List<UniquePickup> pickups) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001e: 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: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) Option[] array = (Option[])(object)new Option[pickups.Count]; for (int i = 0; i < pickups.Count; i++) { array[i] = new Option { pickup = pickups[i], available = true }; } return array; } private static void HideCommandCubePrefab(GameObject prefab) { //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) Renderer[] componentsInChildren = prefab.GetComponentsInChildren<Renderer>(true); for (int i = 0; i < componentsInChildren.Length; i++) { componentsInChildren[i].enabled = false; } Light[] componentsInChildren2 = prefab.GetComponentsInChildren<Light>(true); for (int i = 0; i < componentsInChildren2.Length; i++) { ((Behaviour)componentsInChildren2[i]).enabled = false; } ParticleSystem[] componentsInChildren3 = prefab.GetComponentsInChildren<ParticleSystem>(true); foreach (ParticleSystem obj in componentsInChildren3) { EmissionModule emission = obj.emission; ((EmissionModule)(ref emission)).enabled = false; obj.Stop(true, (ParticleSystemStopBehavior)0); } AudioSource[] componentsInChildren4 = prefab.GetComponentsInChildren<AudioSource>(true); foreach (AudioSource obj2 in componentsInChildren4) { obj2.playOnAwake = false; ((Behaviour)obj2).enabled = false; } } } public class PendingChoice { internal ChoiceRewardRecord extensionReward; public UniquePickup firstPickup; public Option[] options; public Interactor activator; public Vector3 position; public Quaternion rotation; public CharacterMaster ownerMaster; } public enum ThreeChoiceChestCategory { General, Damage, Healing, Utility } public class ThreeChoiceChestMarker : MonoBehaviour { public ThreeChoiceChestCategory category; public Interactor lastInteractor; internal ChestRewardCapture.Batch rewardBatch; } internal sealed class OwnedChoiceMarker : MonoBehaviour { } internal static class OwnedPickupGrant { private static readonly MethodInfo attempt = typeof(GenericPickupController).GetMethod("AttemptGrant", BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[1] { typeof(CharacterBody) }, null); private static readonly FieldInfo consumed = typeof(GenericPickupController).GetField("consumed", BindingFlags.Instance | BindingFlags.NonPublic); internal static void Validate() { if (attempt == null || attempt.ReturnType != typeof(void) || consumed?.FieldType != typeof(bool)) { throw new MissingMemberException("Native GenericPickupController grant API changed."); } } internal static bool Grant(CharacterBody owner, UniquePickup pickup) { //IL_003a: 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_004d: 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_0066: 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_0092: 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_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Invalid comparison between Unknown and I4 //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) if (!NetworkServer.active || !Object.op_Implicit((Object)(object)owner) || !Object.op_Implicit((Object)(object)owner.inventory) || !Object.op_Implicit((Object)(object)owner.healthComponent) || !owner.healthComponent.alive) { return false; } CreatePickupInfo val = new CreatePickupInfo { position = ((Component)owner).transform.position, rotation = Quaternion.identity }; ((CreatePickupInfo)(ref val)).pickup = pickup; CreatePickupInfo val2 = val; GenericPickupController val3 = GenericPickupController.CreatePickup(ref val2); if (!Object.op_Implicit((Object)(object)val3)) { return false; } bool flag = false; try { attempt.Invoke(val3, new object[1] { owner }); PickupDef pickupDef = PickupCatalog.GetPickupDef(pickup.pickupIndex); flag = (bool)consumed.GetValue(val3) || (pickupDef != null && (int)pickupDef.equipmentIndex != -1 && owner.inventory.GetEquipmentIndex() == pickupDef.equipmentIndex); return flag; } finally { if (Object.op_Implicit((Object)(object)val3) && !flag) { NetworkServer.Destroy(((Component)val3).gameObject); } } } } internal static class SelectionTiming { public const float ExitProtectionSeconds = 0.85f; public const float ProtectionLeaseSeconds = 0.35f; } internal sealed class SelectionLease { private double until; public bool Selecting { get; private set; } public void Begin() { Selecting = true; until = 0.0; } public void End(double now) { if (Selecting) { Selecting = false; until = now + 0.8500000238418579; } } public bool Protected(double now) { if (!Selecting) { return now < until; } return true; } public void Clear() { Selecting = false; until = 0.0; } } internal static class SelectionProtection { [CompilerGenerated] private static class <>O { public static hook_TakeDamageProcess <0>__Damage; public static hook_Heal <1>__Heal; public static hook_PreMove <2>__Move; public static Action<CharacterBody> <3>__BodyDestroyed; } private static readonly Dictionary<CharacterMaster, SelectionLease> leases = new Dictionary<CharacterMaster, SelectionLease>(); private static float nextRefresh; private static bool localSelecting; private static bool ownsPause; private static bool externalPause; private static bool pauseProbeComplete; private static CharacterMaster localOwner; private static float priorScale = 1f; internal static void Install() { //IL_0072: 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_007d: Expected O, but got Unknown //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Expected O, but got Unknown //IL_00b2: 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_00bd: Expected O, but got Unknown foreach (PluginInfo value in Chainloader.PluginInfos.Values) { if (Object.op_Implicit((Object)(object)value.Instance) && ((object)value.Instance).GetType().FullName == "RoR2UniversalPause.UniversalItemPause") { externalPause = true; } } object obj = <>O.<0>__Damage; if (obj == null) { hook_TakeDamageProcess val = Damage; <>O.<0>__Damage = val; obj = (object)val; } HealthComponent.TakeDamageProcess += (hook_TakeDamageProcess)obj; object obj2 = <>O.<1>__Heal; if (obj2 == null) { hook_Heal val2 = Heal; <>O.<1>__Heal = val2; obj2 = (object)val2; } HealthComponent.Heal += (hook_Heal)obj2; object obj3 = <>O.<2>__Move; if (obj3 == null) { hook_PreMove val3 = Move; <>O.<2>__Move = val3; obj3 = (object)val3; } CharacterMotor.PreMove += (hook_PreMove)obj3; CharacterBody.onBodyDestroyGlobal += BodyDestroyed; } internal static void SetLocalSelecting(CharacterMaster owner, bool value) { localOwner = (value ? owner : null); localSelecting = value; } internal static void SetServerSelecting(CharacterMaster owner, bool value) { //IL_0055: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)owner)) { return; } if (!leases.TryGetValue(owner, out var value2)) { if (!value) { return; } value2 = (leases[owner] = new SelectionLease()); } if (value2.Selecting != value) { if (value) { value2.Begin(); } else { value2.End(Time.unscaledTime); } ThreeChoiceChestsPlugin.WriteLog(string.Format("[Selection Protection] owner={0} {1}", ((NetworkBehaviour)owner).netId, value ? "enter" : ("exit; move/heal restored; invulnerability/untargetable tail=" + 0.85f + "s"))); if (value) { RefreshBuffs(owner, 0.35f); } else { RefreshBuffs(owner, 0.85f); } } } private static bool Selecting(CharacterBody body) { if (Object.op_Implicit((Object)(object)body) && Object.op_Implicit((Object)(object)body.master)) { if (!leases.TryGetValue(body.master, out var value) || !value.Selecting) { if (body.hasEffectiveAuthority && localSelecting) { return (Object)(object)body.master == (Object)(object)localOwner; } return false; } return true; } return false; } private static bool Protected(CharacterBody body) { if (Object.op_Implicit((Object)(object)body) && Object.op_Implicit((Object)(object)body.master) && leases.TryGetValue(body.master, out var value)) { return value.Protected(Time.unscaledTime); } return false; } private static void RefreshBuffs(CharacterMaster owner, float duration) { if (!RoR2Application.isInSinglePlayer) { CharacterBody val = (Object.op_Implicit((Object)(object)owner) ? owner.GetBody() : null); if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.healthComponent) && val.healthComponent.alive) { val.AddTimedBuff(Buffs.HiddenInvincibility, duration); val.AddTimedBuff(Buffs.Untargetable, duration); } } } internal static void Tick() { //IL_00b2: Unknown result type (might be due to invalid IL or missing references) if (Time.unscaledTime < nextRefresh) { return; } nextRefresh = Time.unscaledTime + 0.1f; foreach (KeyValuePair<CharacterMaster, SelectionLease> item in new List<KeyValuePair<CharacterMaster, SelectionLease>>(leases)) { CharacterMaster key = item.Key; CharacterBody val = (Object.op_Implicit((Object)(object)key) ? key.GetBody() : null); if (!Object.op_Implicit((Object)(object)key) || !Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val.healthComponent) || !val.healthComponent.alive) { item.Value.Clear(); leases.Remove(key); } else if (!item.Value.Protected(Time.unscaledTime)) { ThreeChoiceChestsPlugin.WriteLog($"[Selection Protection] owner={((NetworkBehaviour)key).netId} released"); leases.Remove(key); } else if (item.Value.Selecting) { RefreshBuffs(key, 0.35f); } } } internal static void LateTick() { if (Object.op_Implicit((Object)(object)Run.instance) && !pauseProbeComplete) { foreach (PluginInfo value in Chainloader.PluginInfos.Values) { if (Object.op_Implicit((Object)(object)value.Instance) && ((object)value.Instance).GetType().FullName == "RoR2UniversalPause.UniversalItemPause") { externalPause = true; } } pauseProbeComplete = true; } if (!Object.op_Implicit((Object)(object)Run.instance) || !RoR2Application.isInSinglePlayer || externalPause) { ReleasePause(); } else if (localSelecting) { if (!ownsPause && Time.timeScale > 0f) { priorScale = Time.timeScale; ownsPause = true; } if (ownsPause) { Time.timeScale = 0f; } } else { ReleasePause(); } } private static void ReleasePause() { if (ownsPause) { ownsPause = false; if (!PauseManager.PauseScreenIsOpen() && Time.timeScale == 0f) { Time.timeScale = priorScale; } } } private static void Damage(orig_TakeDamageProcess orig, HealthComponent self, DamageInfo info) { if (!RoR2Application.isInSinglePlayer && Protected(self.body)) { info.rejected = true; } else { orig.Invoke(self, info); } } private static float Heal(orig_Heal orig, HealthComponent self, float amount, ProcChainMask mask, bool nonRegen) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) if (RoR2Application.isInSinglePlayer || !Selecting(self.body)) { return orig.Invoke(self, amount, mask, nonRegen); } return 0f; } private static void Move(orig_PreMove orig, CharacterMotor self, float deltaTime) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002d: 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) CharacterBody component = ((Component)self).GetComponent<CharacterBody>(); if (!RoR2Application.isInSinglePlayer && Selecting(component)) { self.moveDirection = Vector3.zero; self.velocity = Vector3.zero; self.rootMotion = Vector3.zero; } else { orig.Invoke(self, deltaTime); } } private static void BodyDestroyed(CharacterBody body) { if (Object.op_Implicit((Object)(object)body) && Object.op_Implicit((Object)(object)body.master) && leases.TryGetValue(body.master, out var value)) { value.Clear(); leases.Remove(body.master); } } internal static void Clear() { leases.Clear(); localSelecting = false; localOwner = null; ReleasePause(); } internal static void Uninstall() { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown //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_003b: Expected O, but got Unknown //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_005b: Expected O, but got Unknown object obj = <>O.<0>__Damage; if (obj == null) { hook_TakeDamageProcess val = Damage; <>O.<0>__Damage = val; obj = (object)val; } HealthComponent.TakeDamageProcess -= (hook_TakeDamageProcess)obj; object obj2 = <>O.<1>__Heal; if (obj2 == null) { hook_Heal val2 = Heal; <>O.<1>__Heal = val2; obj2 = (object)val2; } HealthComponent.Heal -= (hook_Heal)obj2; object obj3 = <>O.<2>__Move; if (obj3 == null) { hook_PreMove val3 = Move; <>O.<2>__Move = val3; obj3 = (object)val3; } CharacterMotor.PreMove -= (hook_PreMove)obj3; CharacterBody.onBodyDestroyGlobal -= BodyDestroyed; Clear(); } } internal static class ThreeChoiceShortTextCatalog { private static readonly IReadOnlyDictionary<string, string> ItemTexts = new ReadOnlyDictionary<string, string>(CreateItemTexts()); private static readonly IReadOnlyDictionary<string, string> EquipmentTexts = new ReadOnlyDictionary<string, string>(CreateEquipmentTexts()); internal static string GetEffect(ItemDef item, EquipmentDef equipment) { if (Language.currentLanguageName == "zh-CN") { if (Object.op_Implicit((Object)(object)item) && item.nameToken != null && ItemTexts.TryGetValue(item.nameToken, out var value)) { return value; } if (!Object.op_Implicit((Object)(object)item) && Object.op_Implicit((Object)(object)equipment) && equipment.nameToken != null && EquipmentTexts.TryGetValue(equipment.nameToken, out var value2)) { return value2; } } if (!Object.op_Implicit((Object)(object)item)) { if (!Object.op_Implicit((Object)(object)equipment)) { return ""; } return Language.GetString(equipment.pickupToken); } return Language.GetString(item.pickupToken); } private static Dictionary<string, string> CreateItemTexts() { return new Dictionary<string, string>(StringComparer.Ordinal) { { "ITEM_SYRINGE_NAME", "<style=cIsDamage>攻击速度</style>提高<style=cIsDamage>15%</style><style=cStack>(每层+15%)</style>。" }, { "ITEM_CRITGLASSES_NAME", "获得<style=cIsDamage>暴击概率</style>,暴击造成<color=#EF8434>双倍伤害</color>。" }, { "ITEM_INCREASEDAMAGEONMULTIKILL_NAME", "<style=cIsDamage>击杀特效</style>,连续击杀会不断提高伤害;持续战斗可以维持效果。" }, { "ITEM_CRITATLOWERELEVATION_NAME", "<style=cIsDamage>攻击特效</style>,从高处攻击敌人时,提高<style=cIsDamage>暴击概率</style>和<color=#EF8434>暴击伤害</color>。" }, { "ITEM_MEDKIT_NAME", "受到伤害后,延迟回复生命值。" }, { "ITEM_FLATHEALTH_NAME", "<style=cIsHealing>最大生命值</style>增加<style=cIsHealing>25点</style><style=cStack>(每层+25点)</style>。" }, { "ITEM_PERSONALSHIELD_NAME", "获得基于最大生命值的护盾,<style=cIsUtility>脱离危险后重新充能。</style>" }, { "ITEM_STUNCHANCEONHIT_NAME", "<style=cIsDamage>攻击特效</style>,攻击有概率使敌人<style=cIsDamage>眩晕</style>。" }, { "ITEM_SPRINTBONUS_NAME", "<style=cIsDamage>奔跑时</style>大幅提高移动速度。" }, { "ITEM_SECONDARYSKILLMAGAZINE_NAME", "<style=cIsDamage>次要技能</style>获得额外充能。" }, { "ITEM_REPULSIONARMORPLATE_NAME", "受到伤害时获得<style=cIsHealing>固定伤害减免</style>。" }, { "ITEM_NEARBYDAMAGEBONUS_NAME", "对<style=cIsDamage>近距离敌人</style>造成额外伤害。" }, { "ITEM_ATTACKSPEEDPERNEARBYALLYORENEMY_NAME", "附近的敌人和盟友越多,<style=cIsDamage>攻击速度</style>越高。" }, { "ITEM_TOOTH_NAME", "<style=cIsDamage>击杀特效</style>,击杀敌人会掉落<style=cIsHealing>治疗球</style>。" }, { "ITEM_MUSHROOM_NAME", "<style=cIsDamage>站立不动</style><style=cIsDamage>1秒</style>后生成治疗区域。" }, { "ITEM_HEALWHILESAFE_NAME", "脱离危险时,大幅提高<style=cIsHealing>生命再生速度</style>。" }, { "ITEM_BARRIERONKILL_NAME", "<style=cIsDamage>击杀特效</style>,击杀敌人获得<style=cIsHealing>临时屏障</style>。" }, { "ITEM_BARRIERONCOOLDOWN_NAME", "技能冷却结束时获得<style=cIsHealing>临时屏障</style>;基础冷却越长,获得的屏障越多。" }, { "ITEM_HOOF_NAME", "提高<style=cIsDamage>移动速度</style>。" }, { "ITEM_WARDONLEVEL_NAME", "<style=cIsDamage>升级</style>或<style=cIsDamage>开启传送器</style>时放置战旗,提高范围内友方的攻击速度和移动速度。" }, { "ITEM_OUTOFCOMBATARMOR_NAME", "脱离危险时,大幅提高<style=cIsDamage>护甲</style>。" }, { "ITEM_SPEEDBOOSTPICKUP_NAME", "周期性生成<style=cIsDamage>能量球体</style>,拾取后叠加提高移动速度。" }, { "ITEM_DELAYEDDAMAGE_NAME", "周期性降低下一次受到的伤害,并将其<style=cIsHealing>分段结算</style>。" }, { "ITEM_FIREWORK_NAME", "<style=cIsDamage>交互</style>时发射烟花,造成<color=#EF8434>基础伤害</color>。" }, { "ITEM_ATTACKSPEEDANDMOVESPEED_NAME", "同时提高<style=cIsDamage>攻击速度</style>和<style=cIsDamage>移动速度</style>。" }, { "ITEM_TREASURECACHE_NAME", "每关生成一个上锁宝箱,可获得<style=cIsHealing>绿色物品</style>或<color=#CE2929>红色物品</color>;开启时消耗钥匙。" }, { "ITEM_GOLDONHURT_NAME", "受到敌人伤害时获得金币,<style=cIsUtility>数量随游戏进程增加。</style>" }, { "ITEM_CROWBAR_NAME", "对<style=cIsDamage>高生命值敌人</style>造成大量额外伤害。" }, { "ITEM_BLEEDONHIT_NAME", "<style=cIsDamage>攻击特效</style>,攻击有概率使敌人<style=cIsDamage>流血</style>,流血总计造成<color=#EF8434>240%基础伤害</color>。" }, { "ITEM_IGNITEONKILL_NAME", "<style=cIsDamage>击杀特效</style>,引爆并燃烧附近敌人,造成<color=#EF8434>基础伤害</color>。" }, { "ITEM_STICKYBOMB_NAME", "<style=cIsDamage>攻击特效</style>,攻击有概率附着粘弹,爆炸造成<color=#EF8434>180%总伤害</color>。" }, { "ITEM_BOSSDAMAGEBONUS_NAME", "对<style=cIsDamage>首领</style>造成额外伤害。" }, { "ITEM_FRAGILEDAMAGEBONUS_NAME", "提高伤害;生命值降得过低时<color=#CE2929>损坏</color>。" }, { "ITEM_HEALINGPOTION_NAME", "生命值降得过低时,<style=cIsDamage>消耗此物品</style>并立即恢复大量生命值。" }, { "ITEM_BEAR_NAME", "有概率<style=cIsHealing>完全格挡一次伤害</style>。<style=cIsUtility>不受运气影响。</style>" }, { "ITEM_MISSILE_NAME", "<style=cIsDamage>攻击特效</style>,攻击有概率发射追踪导