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 NajCosmaticShare v0.2.5
plugins/NajCosmaticShare.dll
Decompiled a day agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text.RegularExpressions; using System.Threading.Tasks; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using ExitGames.Client.Photon; using HarmonyLib; using MenuLib; using MenuLib.MonoBehaviors; using Microsoft.CodeAnalysis; using Photon.Pun; using Photon.Realtime; using UnityEngine; using UnityEngine.AddressableAssets; using UnityEngine.Localization; using UnityEngine.Localization.Settings; using UnityEngine.ResourceManagement.AsyncOperations; 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("NajCosmaticShare")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.2.5.0")] [assembly: AssemblyInformationalVersion("0.2.5+53e16dcc64966babca7d092c38aafbe7231fcfc7")] [assembly: AssemblyProduct("NajCosmaticShare")] [assembly: AssemblyTitle("NajCosmaticShare")] [assembly: AssemblyVersion("0.2.5.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [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 NajCosmaticShare { [RequireComponent(typeof(Image))] internal sealed class CosmeticIcon : MonoBehaviour { private static readonly FieldRef<CosmeticAsset, Sprite> CachedIcon = AccessTools.FieldRefAccess<CosmeticAsset, Sprite>("icon"); private static readonly Func<string, string, Object, Action<Sprite>, Task> LoadBaked = AccessTools.MethodDelegate<Func<string, string, Object, Action<Sprite>, Task>>(AccessTools.Method(typeof(SemiIconMaker), "LoadBakedIcon", (Type[])null, (Type[])null), (object)null, true); private static readonly Func<CosmeticAsset, Object, Task<Sprite>> Generate = AccessTools.MethodDelegate<Func<CosmeticAsset, Object, Task<Sprite>>>(AccessTools.Method(typeof(CosmeticAsset), "GenerateIconAsync", (Type[])null, (Type[])null), (object)null, true); private Image image; private Sprite? temporarySprite; private AsyncOperationHandle<Sprite>? addressable; private int revision; internal static Image AddImage(Transform parent, string name, float size, Color color) { //IL_002e: 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_0058: Unknown result type (might be due to invalid IL or missing references) Image component = new GameObject(name, new Type[3] { typeof(RectTransform), typeof(CanvasRenderer), typeof(Image) }).GetComponent<Image>(); ((Transform)((Graphic)component).rectTransform).SetParent(parent, false); ((Graphic)component).rectTransform.sizeDelta = new Vector2(size, size); ((Graphic)component).color = color; ((Graphic)component).raycastTarget = false; return component; } private void Awake() { image = ((Component)this).GetComponent<Image>(); image.preserveAspect = true; ((Behaviour)image).enabled = false; } internal void SetAsset(CosmeticAsset? asset) { int generation = ++revision; image.sprite = null; ((Behaviour)image).enabled = false; ReleaseIcon(); if (Object.op_Implicit((Object)(object)asset)) { Load(asset, generation); } } private async Task Load(CosmeticAsset asset, int generation) { Sprite bakedOrGenerated = null; AsyncOperationHandle<Sprite>? handle = null; try { Sprite sprite = CachedIcon.Invoke(asset); if (!Object.op_Implicit((Object)(object)sprite)) { await LoadBaked("Cosmetics", ((Object)asset).name, (Object)(object)this, delegate(Sprite result) { bakedOrGenerated = result; }); if (!Object.op_Implicit((Object)(object)this) || revision != generation) { return; } sprite = bakedOrGenerated; } if (!Object.op_Implicit((Object)(object)sprite) && asset.iconRef != null && ((AssetReference)asset.iconRef).RuntimeKeyIsValid()) { handle = Addressables.LoadAssetAsync<Sprite>((object)asset.iconRef); try { sprite = await handle.Value.Task; } catch (Exception) { Addressables.Release<Sprite>(handle.Value); handle = null; } } if (Object.op_Implicit((Object)(object)this) && revision == generation) { if (!Object.op_Implicit((Object)(object)sprite)) { sprite = (bakedOrGenerated = await Generate(asset, (Object)(object)this)); } if (Object.op_Implicit((Object)(object)this) && revision == generation && Object.op_Implicit((Object)(object)sprite)) { temporarySprite = bakedOrGenerated; addressable = handle; bakedOrGenerated = null; handle = null; image.sprite = sprite; ((Behaviour)image).enabled = true; } } } catch (Exception ex2) { Plugin.Log.LogWarning((object)("Could not render the cosmetic icon for " + ((Object)asset).name + ": " + ex2.Message)); } finally { DestroyIcon(bakedOrGenerated); if (handle.HasValue) { Addressables.Release<Sprite>(handle.Value); } } } private void ReleaseIcon() { //IL_0025: Unknown result type (might be due to invalid IL or missing references) DestroyIcon(temporarySprite); temporarySprite = null; if (addressable.HasValue) { Addressables.Release<Sprite>(addressable.Value); } addressable = null; } private static void DestroyIcon(Sprite? sprite) { if (Object.op_Implicit((Object)(object)sprite)) { Object.Destroy((Object)(object)sprite.texture); Object.Destroy((Object)(object)sprite); } } private void OnDestroy() { ReleaseIcon(); } } internal static class CosmeticInventory { private static readonly FieldRef<CosmeticAsset, string> AssetId = AccessTools.FieldRefAccess<CosmeticAsset, string>("assetId"); private static readonly FieldRef<MetaManager, bool> SaveReady = AccessTools.FieldRefAccess<MetaManager, bool>("saveReady"); private static readonly FieldRef<MetaManager, bool> SaveAllowed = AccessTools.FieldRefAccess<MetaManager, bool>("saveAllowed"); private static readonly FieldRef<MetaManager, List<int>> Unlocks = AccessTools.FieldRefAccess<MetaManager, List<int>>("cosmeticUnlocks"); private static readonly FieldRef<MetaManager, List<int>> Equipped = AccessTools.FieldRefAccess<MetaManager, List<int>>("cosmeticEquipped"); private static readonly FieldRef<MetaManager, List<int>> Preview = AccessTools.FieldRefAccess<MetaManager, List<int>>("cosmeticEquippedPreview"); internal static bool CanSave { get { if (Object.op_Implicit((Object)(object)MetaManager.instance) && SaveReady.Invoke(MetaManager.instance) && SaveAllowed.Invoke(MetaManager.instance)) { return SemiFunc.IsMainEditor(); } return false; } } internal static string Id(CosmeticAsset asset) { return AssetId.Invoke(asset); } internal static string Name(CosmeticAsset asset) { if (!string.IsNullOrWhiteSpace(asset.assetName)) { return asset.assetName; } return ((Object)asset).name; } internal static CosmeticAsset? Find(string id) { if (!Object.op_Implicit((Object)(object)MetaManager.instance)) { return null; } return MetaManager.instance.cosmeticAssets.Find((CosmeticAsset asset) => Object.op_Implicit((Object)(object)asset) && Id(asset) == id); } internal static bool Owned(CosmeticAsset asset) { if (Object.op_Implicit((Object)(object)MetaManager.instance)) { return Unlocks.Invoke(MetaManager.instance).Contains(MetaManager.instance.cosmeticAssets.IndexOf(asset)); } return false; } internal static IEnumerable<CosmeticAsset> ListOwned() { MetaManager instance = MetaManager.instance; if (!Object.op_Implicit((Object)(object)instance) || !SaveReady.Invoke(instance)) { return Array.Empty<CosmeticAsset>(); } List<CosmeticAsset> assets = instance.cosmeticAssets; return (from index in Unlocks.Invoke(instance).Distinct() where index >= 0 && index < assets.Count select assets[index]).Where(IsGiftable).OrderBy<CosmeticAsset, string>(Name, StringComparer.CurrentCultureIgnoreCase); } internal static bool IsGiftable(CosmeticAsset? asset) { if (Object.op_Implicit((Object)(object)asset) && asset.prefab != null && ((PrefabRef<GameObject>)(object)asset.prefab).IsValid()) { return !string.IsNullOrEmpty(Id(asset)); } return false; } internal static bool ApplyTransfer(string id, bool receive) { CosmeticAsset val = Find(id); if (!Object.op_Implicit((Object)(object)val) || !CanSave) { return false; } if (Owned(val) == receive) { return true; } MetaManager instance = MetaManager.instance; if (receive) { return instance.CosmeticUnlock(val); } int item = instance.cosmeticAssets.IndexOf(val); bool flag = Equipped.Invoke(instance).Contains(item); if (flag) { instance.CosmeticUnequip(val, false, true); } if (Preview.Invoke(instance).Contains(item)) { instance.CosmeticUnequip(val, true, true); } if (!instance.CosmeticLock(val)) { return false; } if (flag) { instance.CosmeticPlayerUpdateLocal(true, true); } return true; } } internal sealed class GiftDisplay : MonoBehaviour { private Image icon; private CosmeticIcon loader; private string assetId = ""; internal static GiftDisplay Create(Transform parent, Vector3 front) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004f: 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_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_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_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("NajCosmaticShare Gift Frame", new Type[2] { typeof(RectTransform), typeof(Canvas) }); RectTransform val2 = (RectTransform)val.transform; ((Transform)val2).SetParent(parent, false); ((Transform)val2).SetPositionAndRotation(parent.position + Vector3.up * 2.45f + front * 0.58f, Quaternion.LookRotation(-front)); ((Transform)val2).localScale = Vector3.one * 0.004f; val2.sizeDelta = new Vector2(164f, 164f); val.GetComponent<Canvas>().renderMode = (RenderMode)2; CosmeticIcon.AddImage((Transform)(object)val2, "Frame", 164f, Color32.op_Implicit(new Color32((byte)196, (byte)155, (byte)83, byte.MaxValue))); CosmeticIcon.AddImage((Transform)(object)val2, "Inset", 152f, Color32.op_Implicit(new Color32((byte)24, (byte)20, (byte)18, byte.MaxValue))); GiftDisplay giftDisplay = val.AddComponent<GiftDisplay>(); giftDisplay.icon = CosmeticIcon.AddImage((Transform)(object)val2, "Cosmetic", 136f, Color.white); giftDisplay.loader = ((Component)giftDisplay.icon).gameObject.AddComponent<CosmeticIcon>(); return giftDisplay; } internal void Show(string id) { if (!(assetId == id)) { assetId = id; ((Component)this).gameObject.SetActive(id.Length > 0); loader.SetAsset((id.Length > 0) ? CosmeticInventory.Find(id) : null); } } } internal sealed class GiftExchange : MonoBehaviourPunCallbacks, IOnEventCallback { private enum Request : byte { Offer, Withdraw, Claim, Vote, Acknowledge } internal sealed class Slot { internal string Session { get; } internal int View { get; } internal string Id { get; } internal string Asset { get; } internal int Donor { get; } internal string Name { get; } internal int Recipient { get; } internal string Attempt { get; } internal bool Committed { get; } internal bool HasGift => Id.Length != 0; internal Slot(string session, int view, string id = "", string asset = "", int donor = 0, string name = "", int recipient = 0, string attempt = "", bool committed = false) { Session = session; View = view; Id = id; Asset = asset; Donor = donor; Name = name; Recipient = recipient; Attempt = attempt; Committed = committed; } internal Slot Empty() { return new Slot(Session, View); } internal Slot WithRecipient(int actor) { return new Slot(Session, View, Id, Asset, Donor, Name, actor, (actor > 0) ? Guid.NewGuid().ToString("N") : ""); } internal Slot Commit() { return new Slot(Session, View, Id, Asset, Donor, Name, Recipient, Attempt, committed: true); } internal object[] Encode() { return new object[9] { Session, View, Id, Asset, Donor, Name, Recipient, Attempt, Committed }; } internal static Slot? Decode(object value) { if (!(value is object[] array) || array.Length != 9 || !(array[0] is string text) || !Guid.TryParseExact(text, "N", out var result) || !(array[1] is int view) || !(array[2] is string text2) || !(array[3] is string text3) || !(array[4] is int num) || !(array[5] is string name) || !(array[6] is int num2) || !(array[7] is string text4) || !(array[8] is bool flag)) { return null; } if (text2.Length == 0) { return new Slot(text, view); } bool flag2 = !Guid.TryParseExact(text2, "N", out result); if (!flag2) { int length = text3.Length; bool flag3 = ((length > 512 || length == 0) ? true : false); flag2 = flag3; } if (flag2 || num <= 0 || num2 < 0 || num2 == num || (flag && num2 == 0) || (num2 > 0 && !Guid.TryParseExact(text4, "N", out result))) { return null; } return new Slot(text, view, text2, text3, num, CleanName(name, num), num2, text4, flag); } } private const byte EventCode = 193; private const string Protocol = "NajCosmaticShare.2"; private const string PresentationMessage = "show"; private const string SlotKey = "NajCosmaticShare.2.slot"; private const string TransferPrefix = "NajCosmaticShare.2.transfer."; private const float PrepareTimeout = 8f; private static readonly FieldRef<PlayerAvatar, string> AvatarName = AccessTools.FieldRefAccess<PlayerAvatar, string>("playerName"); private GiftTerminal? terminal; private Slot? hostSlot; private float prepareDeadline; private bool donorReady; private bool recipientReady; private float nextVote; private float nextSettlement; private string localOffer = ""; private string localClaim = ""; private readonly Dictionary<string, Slot> prepared = new Dictionary<string, Slot>(StringComparer.Ordinal); private readonly HashSet<string> applied = new HashSet<string>(StringComparer.Ordinal); private readonly Dictionary<string, HashSet<int>> acknowledgements = new Dictionary<string, HashSet<int>>(StringComparer.Ordinal); internal static GiftExchange? Instance { get; private set; } internal static int LocalActor { get { if (!PhotonNetwork.InRoom) { return 1; } return PhotonNetwork.LocalPlayer.ActorNumber; } } private static bool IsHost { get { if (!PhotonNetwork.InRoom) { if (Object.op_Implicit((Object)(object)GameManager.instance)) { return !GameManager.Multiplayer(); } return false; } return PhotonNetwork.IsMasterClient; } } private static Room? Room { get { if (!PhotonNetwork.InRoom) { return null; } return PhotonNetwork.CurrentRoom; } } internal Slot? Current { get { if (!Object.op_Implicit((Object)(object)terminal) || !terminal.ShopActive) { return null; } Slot slot = (IsHost ? hostSlot : ReadRoomSlot()); if (slot?.View != terminal.ViewId) { return null; } return slot; } } private void Awake() { Instance = this; } private void OnDestroy() { if ((Object)(object)Instance == (Object)(object)this) { Instance = null; } } internal void Bind(GiftTerminal next) { terminal = next; hostSlot = null; localOffer = ""; localClaim = ""; } internal void Unbind(GiftTerminal previous) { if (!((Object)(object)terminal != (Object)(object)previous)) { CloseShop(); terminal = null; } } internal bool IsReserved(CosmeticAsset asset) { Slot current = Current; if (current != null && current.HasGift && current.Id == localOffer && current.Donor == LocalActor) { return current.Asset == CosmeticInventory.Id(asset); } return false; } internal void Offer(CosmeticAsset asset) { Slot current = Current; if (current == null || current.HasGift || !CosmeticInventory.CanSave || !CosmeticInventory.IsGiftable(asset) || !CosmeticInventory.Owned(asset)) { return; } if (Room != null) { SettleTransfers(); if (!CosmeticInventory.Owned(asset)) { return; } } localOffer = Guid.NewGuid().ToString("N"); Send(Request.Offer, current.Session, localOffer, CosmeticInventory.Id(asset)); } internal void Interact(Slot slot) { if (slot.Recipient == 0) { if (slot.Donor == LocalActor) { Send(Request.Withdraw, slot.Session, slot.Id, ""); return; } localClaim = slot.Id; Send(Request.Claim, slot.Session, slot.Id, ""); } } private void Update() { UpdateShop(); Slot current = Current; if (current != null && current.Recipient > 0 && !current.Committed && Time.unscaledTime >= nextVote) { nextVote = Time.unscaledTime + 0.6f; Vote(current); } if (Room != null && Time.unscaledTime >= nextSettlement) { nextSettlement = Time.unscaledTime + 0.8f; SettleTransfers(); } } private void UpdateShop() { if (!IsHost) { return; } if (!Object.op_Implicit((Object)(object)terminal) || !terminal.ShopActive) { CloseShop(); } else if (hostSlot?.View != terminal.ViewId) { if (!GameManager.Multiplayer() || terminal.ViewId > 0) { Publish(new Slot(Guid.NewGuid().ToString("N"), terminal.ViewId)); } } else if (hostSlot.Committed) { if (!ActorPresent(hostSlot.Recipient) || Time.unscaledTime >= prepareDeadline) { Publish(hostSlot.Empty()); } } else if (hostSlot.HasGift && !ActorPresent(hostSlot.Donor)) { Publish(hostSlot.Empty()); } else if (hostSlot.Recipient != 0 && (!ActorPresent(hostSlot.Recipient) || Time.unscaledTime >= prepareDeadline)) { Publish(hostSlot.WithRecipient(0)); } } private void CloseShop() { //IL_001b: 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_0035: Expected O, but got Unknown if (hostSlot != null && IsHost) { Room? room = Room; if (room != null) { room.SetCustomProperties(new Hashtable { [(object)"NajCosmaticShare.2.slot"] = null }, (Hashtable)null, (WebFlags)null); } hostSlot = null; } } private static Slot? ReadRoomSlot() { Room? room = Room; if (room == null || !((Dictionary<object, object>)(object)((RoomInfo)room).CustomProperties).TryGetValue((object)"NajCosmaticShare.2.slot", out object value)) { return null; } return Slot.Decode(value); } private bool Publish(Slot slot, Slot? transfer = null) { //IL_0009: 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_0022: Expected O, but got Unknown Room room = Room; if (room != null) { Hashtable val = new Hashtable { [(object)"NajCosmaticShare.2.slot"] = slot.Encode() }; if (transfer != null) { val[(object)("NajCosmaticShare.2.transfer." + transfer.Id)] = transfer.Encode(); } if (!room.SetCustomProperties(val, (Hashtable)null, (WebFlags)null)) { return false; } } hostSlot = slot; return true; } private void Send(Request request, string session, string id, string value) { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_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_0057: Expected O, but got Unknown if (IsHost) { Receive(LocalActor, request, session, id, value); return; } PhotonNetwork.RaiseEvent((byte)193, (object)new object[5] { "NajCosmaticShare.2", (byte)request, session, id, value }, new RaiseEventOptions { Receivers = (ReceiverGroup)2 }, SendOptions.SendReliable); } public void OnEvent(EventData message) { if (message.Code != 193 || Room == null || !(message.CustomData is object[] array) || array.Length < 2 || !object.Equals(array[0], "NajCosmaticShare.2")) { return; } Guid result; if (object.Equals(array[1], "show")) { int sender = message.Sender; Player masterClient = PhotonNetwork.MasterClient; if (sender != ((masterClient != null) ? new int?(masterClient.ActorNumber) : ((int?)null)) || array.Length != 6 || !(array[2] is string text) || !(array[3] is int num) || !(array[4] is int num2) || !(array[5] is string { Length: var length } text2) || length <= 0 || length > 512) { return; } Slot current = Current; if (current == null || !(current.Session == text) || current.View != num) { return; } PhotonView val = PhotonView.Find(num2); if (val != null) { PlayerAvatar component = ((Component)val).GetComponent<PlayerAvatar>(); if (Object.op_Implicit((Object)(object)component)) { terminal.ShowGift(component, text2); } } } else if (IsHost && array.Length == 5 && array[1] is byte request && array[2] is string session && array[3] is string text3 && array[4] is string { Length: <=512 } text4 && Guid.TryParseExact(text3, "N", out result) && ActorPresent(message.Sender)) { Receive(message.Sender, (Request)request, session, text3, text4); } } private void Receive(int sender, Request request, string session, string id, string value) { if (request == Request.Acknowledge) { Acknowledge(sender, session, id); return; } Slot current = Current; if (current == null || current.Committed || current.Session != session || !terminal.CanUse) { return; } if (request == Request.Offer && !current.HasGift && GiftTerminal.Side.Rear == SenderSide(sender, out PlayerAvatar player) && CosmeticInventory.IsGiftable(CosmeticInventory.Find(value))) { Publish(new Slot(current.Session, current.View, id, value, sender, PlayerName(sender, player))); } else { if (!current.HasGift || current.Id != id) { return; } PlayerAvatar player2; switch (request) { case Request.Withdraw: if (current.Donor == sender && current.Recipient == 0 && SenderSide(sender, out player2) != GiftTerminal.Side.None) { Publish(current.Empty()); } break; case Request.Claim: if (current.Donor != sender && current.Recipient == 0 && ActorPresent(current.Donor) && SenderSide(sender, out player2) == GiftTerminal.Side.Front && Publish(current.WithRecipient(sender))) { donorReady = (recipientReady = false); prepareDeadline = Time.unscaledTime + 8f; nextVote = 0f; } break; case Request.Vote: if (current.Recipient != 0 && Time.unscaledTime < prepareDeadline && (current.Donor == sender || current.Recipient == sender)) { RecordVote(current, sender, value); } break; } } } private void Vote(Slot slot) { bool flag = slot.Donor == LocalActor; if (flag || slot.Recipient == LocalActor) { CosmeticAsset asset = CosmeticInventory.Find(slot.Asset); bool flag2 = (flag ? localOffer : localClaim) == slot.Id && CosmeticInventory.CanSave && CosmeticInventory.IsGiftable(asset) && CosmeticInventory.Owned(asset) == flag; if (flag2) { prepared[slot.Attempt] = slot; } Send(Request.Vote, slot.Session, slot.Id, (flag2 ? "+" : "-") + slot.Attempt); } } private void RecordVote(Slot slot, int sender, string value) { if (value == "-" + slot.Attempt) { Publish(slot.WithRecipient(0)); } else { if (value != "+" + slot.Attempt) { return; } if (sender == slot.Donor) { donorReady = true; } else { recipientReady = true; } if (donorReady && recipientReady && ActorPresent(slot.Donor) && ActorPresent(slot.Recipient)) { Slot slot2 = slot.Commit(); if (Publish(slot2, slot2)) { prepareDeadline = Time.unscaledTime + 8f; } } } } private void SettleTransfers() { Room room = Room; if (room == null) { return; } string[] array = (from key in ((Dictionary<object, object>)(object)((RoomInfo)room).CustomProperties).Keys.OfType<string>() where key.StartsWith("NajCosmaticShare.2.transfer.", StringComparison.Ordinal) select key).ToArray(); foreach (string text in array) { if (!((Dictionary<object, object>)(object)((RoomInfo)room).CustomProperties).TryGetValue((object)text, out object value)) { continue; } Slot slot = Slot.Decode(value); if (slot == null || !slot.Committed || text != "NajCosmaticShare.2.transfer." + slot.Id || (slot.Donor != LocalActor && slot.Recipient != LocalActor) || !prepared.TryGetValue(slot.Attempt, out Slot value2) || slot.Id != value2.Id || slot.Session != value2.Session || slot.Asset != value2.Asset || slot.Donor != value2.Donor || slot.Recipient != value2.Recipient) { continue; } try { bool flag = slot.Recipient == LocalActor; if (applied.Contains(slot.Id)) { goto IL_01a4; } if (!CosmeticInventory.ApplyTransfer(slot.Asset, flag)) { continue; } applied.Add(slot.Id); terminal?.TransferFinished(flag, slot.Name); goto IL_01a4; IL_01a4: Send(Request.Acknowledge, slot.Session, slot.Id, ""); } catch (Exception arg) { Plugin.Log.LogError((object)$"Could not settle cosmetic transfer {slot.Id}: {arg}"); } } } private void Acknowledge(int sender, string session, string id) { //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Expected O, but got Unknown string text = "NajCosmaticShare.2.transfer." + id; Room room = Room; if (room == null || !((Dictionary<object, object>)(object)((RoomInfo)room).CustomProperties).TryGetValue((object)text, out object value)) { return; } Slot slot = Slot.Decode(value); if (slot == null || !slot.Committed || slot.Session != session || (sender != slot.Donor && sender != slot.Recipient)) { return; } if (!acknowledgements.TryGetValue(id, out HashSet<int> value2)) { acknowledgements.Add(id, value2 = new HashSet<int>()); } if (value2.Add(sender) && sender == slot.Recipient) { Slot current = Current; if (current != null && current.Committed && current.Id == slot.Id) { StartPresentation(slot); Publish(current.Empty()); } } if ((value2.Contains(slot.Donor) || !ActorPresent(slot.Donor)) && (value2.Contains(slot.Recipient) || !ActorPresent(slot.Recipient)) && room.SetCustomProperties(new Hashtable { [(object)text] = null }, (Hashtable)null, (WebFlags)null)) { acknowledgements.Remove(id); } } private void StartPresentation(Slot transfer) { //IL_0083: 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_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Expected O, but got Unknown if (Object.op_Implicit((Object)(object)terminal) && terminal.CanUse) { PlayerAvatar val = FindAvatar(transfer.Recipient); if (Object.op_Implicit((Object)(object)val) && PhotonNetwork.RaiseEvent((byte)193, (object)new object[6] { "NajCosmaticShare.2", "show", transfer.Session, terminal.ViewId, val.photonView.ViewID, transfer.Asset }, new RaiseEventOptions { Receivers = (ReceiverGroup)0 }, SendOptions.SendReliable)) { terminal.ShowGift(val, transfer.Asset); } } } private GiftTerminal.Side SenderSide(int actor, out PlayerAvatar? player) { player = ((Room == null) ? GiftTerminal.LocalPlayer : FindAvatar(actor)); return terminal.GetSide(player); } private static PlayerAvatar? FindAvatar(int actor) { return SemiFunc.PlayerGetAll().Find((PlayerAvatar avatar) => Object.op_Implicit((Object)(object)avatar) && Object.op_Implicit((Object)(object)avatar.photonView) && avatar.photonView.OwnerActorNr == actor); } private static string PlayerName(int actor, PlayerAvatar? avatar) { Room? room = Room; object obj; if (room == null) { obj = null; } else { Player player = room.GetPlayer(actor, false); obj = ((player != null) ? player.NickName : null); } if (obj == null) { obj = ""; } string text = (string)obj; if (string.IsNullOrWhiteSpace(text) && Object.op_Implicit((Object)(object)avatar)) { text = AvatarName.Invoke(avatar); } return CleanName(text, actor); } private static string CleanName(string name, int actor) { string text = new string(name.Where(delegate(char c) { bool flag = !char.IsControl(c); if (flag) { bool flag2; switch (c) { case '<': case '>': case '[': case ']': flag2 = true; break; default: flag2 = false; break; } flag = !flag2; } return flag; }).Take(40).ToArray()).Trim(); if (text.Length != 0) { return text; } return $"#{actor}"; } private static bool ActorPresent(int actor) { Room room = Room; if (room == null) { return actor == LocalActor; } Player player = room.GetPlayer(actor, false); if (player != null) { return !player.IsInactive; } return false; } public override void OnRoomPropertiesUpdate(Hashtable propertiesThatChanged) { if (((Dictionary<object, object>)(object)propertiesThatChanged).ContainsKey((object)"NajCosmaticShare.2.slot")) { nextVote = 0f; } if (((Dictionary<object, object>)(object)propertiesThatChanged).Keys.OfType<string>().Any((string key) => key.StartsWith("NajCosmaticShare.2.transfer.", StringComparison.Ordinal))) { nextSettlement = 0f; SettleTransfers(); } } public override void OnMasterClientSwitched(Player newMasterClient) { if (IsHost) { hostSlot = ReadRoomSlot(); donorReady = (recipientReady = false); prepareDeadline = Time.unscaledTime + 8f; nextVote = (nextSettlement = 0f); } } public override void OnJoinedRoom() { ResetRoom(); } public override void OnLeftRoom() { ResetRoom(); } private void ResetRoom() { hostSlot = null; localOffer = (localClaim = ""); prepared.Clear(); applied.Clear(); acknowledgements.Clear(); nextVote = (nextSettlement = 0f); } } internal sealed class GiftPicker : MonoBehaviour { private enum BodyPart { Head, Face, Neck, Torso, Arms, Legs, Footwear, Other } private sealed class Tile { internal CosmeticAsset Asset { get; } internal REPOButton Button { get; } internal CosmeticIcon Icon { get; } internal bool IconRequested { get; set; } internal Tile(CosmeticAsset asset, REPOButton button, CosmeticIcon icon) { Asset = asset; Button = button; Icon = icon; } } private const int Columns = 3; private const float Gap = 8f; private static readonly Regex Neckwear = new Regex("\\b(?:scarf|neckwear|necklace|choker|collar|bow[ -]?tie|necktie|tie|lanyard)\\b", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); private static readonly Func<CosmeticAsset, Color> RarityColor = AccessTools.MethodDelegate<Func<CosmeticAsset, Color>>(AccessTools.Method(typeof(CosmeticAsset), "GetRarityColor", (Type[])null, (Type[])null), (object)null, true); private static readonly FieldRef<MenuButton, bool> Hovering = AccessTools.FieldRefAccess<MenuButton, bool>("hovering"); private static readonly FieldRef<PlayerCosmetics, bool> FirstSetup = AccessTools.FieldRefAccess<PlayerCosmetics, bool>("firstSetup"); private readonly List<Tile> tiles = new List<Tile>(); private REPOPopupPage page; private REPOAvatarPreview preview; private CosmeticAsset? previewAsset; internal static REPOPopupPage Open(CosmeticAsset[] assets, Action<CosmeticAsset> select, Action cancel) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) REPOPopupPage val = MenuAPI.CreateREPOPopupPage(ModLanguage.Text("Choose a gift", "Выберите подарок"), false, true, 7f, (Vector2?)new Vector2(-142f, 0f)); GiftPicker giftPicker = ((Component)val).gameObject.AddComponent<GiftPicker>(); giftPicker.page = val; giftPicker.Build(assets, select, cancel); val.OpenPage(false); return val; } private void Build(CosmeticAsset[] assets, Action<CosmeticAsset> select, Action cancel) { //IL_0018: 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_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Expected O, but got Unknown //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Expected O, but got Unknown //IL_01b1: Unknown result type (might be due to invalid IL or missing references) //IL_01b6: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01f3: Unknown result type (might be due to invalid IL or missing references) //IL_0209: Unknown result type (might be due to invalid IL or missing references) //IL_020e: Unknown result type (might be due to invalid IL or missing references) //IL_020f: Unknown result type (might be due to invalid IL or missing references) //IL_0210: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Unknown result type (might be due to invalid IL or missing references) //IL_0212: Unknown result type (might be due to invalid IL or missing references) //IL_0213: Unknown result type (might be due to invalid IL or missing references) //IL_021a: Unknown result type (might be due to invalid IL or missing references) //IL_021c: Unknown result type (might be due to invalid IL or missing references) //IL_021d: Unknown result type (might be due to invalid IL or missing references) //IL_0224: Unknown result type (might be due to invalid IL or missing references) //IL_022b: Unknown result type (might be due to invalid IL or missing references) //IL_024c: Unknown result type (might be due to invalid IL or missing references) //IL_0251: Unknown result type (might be due to invalid IL or missing references) //IL_026f: Unknown result type (might be due to invalid IL or missing references) //IL_0274: Unknown result type (might be due to invalid IL or missing references) //IL_0287: Unknown result type (might be due to invalid IL or missing references) //IL_028c: Unknown result type (might be due to invalid IL or missing references) //IL_0290: Unknown result type (might be due to invalid IL or missing references) //IL_029f: Unknown result type (might be due to invalid IL or missing references) Rect rect = page.maskRectTransform.rect; float num = Mathf.Clamp((((Rect)(ref rect)).width - 32f) / 3f, 46f, 77f); float gridWidth = num * 3f + 16f; page.AddElementToScrollView((ScrollViewBuilderDelegate)((Transform parent) => ((REPOElement)MenuAPI.CreateREPOButton(ModLanguage.Text("Cancel", "Отмена"), cancel, parent, default(Vector2))).rectTransform), 0f, 0f); foreach (IGrouping<BodyPart, CosmeticAsset> item in from @group in assets.GroupBy(PartOf) orderby @group.Key select @group) { string name = PartName(item.Key); page.AddElementToScrollView((ScrollViewBuilderDelegate)delegate(Transform parent) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) REPOLabel obj = MenuAPI.CreateREPOLabel(name, parent, default(Vector2)); ((REPOElement)obj).rectTransform.sizeDelta = new Vector2(gridWidth, 23f); return ((REPOElement)obj).rectTransform; }, 5f, 0f); CosmeticAsset[] array = item.OrderByDescending((CosmeticAsset asset) => asset.rarity).ToArray(); for (int num2 = 0; num2 < array.Length; num2 += 3) { AddRow(new ArraySegment<CosmeticAsset>(array, num2, Math.Min(3, array.Length - num2)), select, num, gridWidth); } } Transform transform = ((Component)page).transform; Color? val = Color32.op_Implicit(new Color32((byte)21, (byte)20, (byte)18, (byte)210)); preview = MenuAPI.CreateREPOAvatarPreview(transform, default(Vector2), true, val); Vector2 val2 = default(Vector2); ((Vector2)(ref val2))..ctor(0.5f, 0.5f); ((REPOElement)preview).rectTransform.pivot = val2; RectTransform val3 = (RectTransform)((Component)((Component)preview).GetComponentInChildren<PlayerAvatarMenuHover>()).transform; Vector2 val4 = (val3.pivot = val2); Vector2 anchorMin = (val3.anchorMax = val4); val3.anchorMin = anchorMin; val3.anchoredPosition = Vector2.zero; RectTransform maskRectTransform = page.maskRectTransform; rect = ((REPOElement)preview).rectTransform.rect; float num3 = ((Rect)(ref rect)).width * 0.5f; RectTransform rectTransform = ((REPOElement)preview).rectTransform; rect = maskRectTransform.rect; float num4 = ((Rect)(ref rect)).xMax + num3 + 34f; rect = maskRectTransform.rect; ((Transform)rectTransform).position = ((Transform)maskRectTransform).TransformPoint(num4, ((Rect)(ref rect)).center.y, 0f); } private static BodyPart PartOf(CosmeticAsset asset) { //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_000a: Invalid comparison between Unknown and I4 //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Invalid comparison between Unknown and I4 //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Invalid comparison between Unknown and I4 //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Invalid comparison between Unknown and I4 //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Invalid comparison between Unknown and I4 //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Invalid comparison between Unknown and I4 //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Invalid comparison between Unknown and I4 //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Expected I4, but got Unknown CosmeticType type = asset.type; if ((int)type <= 20) { if (type - 6 <= 1 || (int)type == 16 || (int)type == 20) { goto IL_002d; } } else if ((int)type == 25 || (int)type == 30 || (int)type == 32) { goto IL_002d; } bool flag = false; goto IL_0033; IL_002d: flag = true; goto IL_0033; IL_0033: if (flag && Neckwear.IsMatch(CosmeticInventory.Name(asset))) { return BodyPart.Neck; } type = asset.type; switch ((int)type) { case 0: case 5: case 17: case 24: return BodyPart.Head; case 6: case 14: case 15: case 18: case 25: case 30: case 31: case 32: return BodyPart.Face; case 7: case 8: case 16: case 20: case 21: case 23: return BodyPart.Torso; case 1: case 2: case 9: case 10: case 13: case 26: case 27: return BodyPart.Arms; case 3: case 4: case 11: case 12: case 28: case 29: return BodyPart.Legs; case 19: case 22: return BodyPart.Footwear; default: return BodyPart.Other; } } private static string PartName(BodyPart part) { return part switch { BodyPart.Head => ModLanguage.Text("Head", "Голова"), BodyPart.Face => ModLanguage.Text("Face", "Лицо"), BodyPart.Neck => ModLanguage.Text("Neck", "Шея"), BodyPart.Torso => ModLanguage.Text("Torso", "Туловище"), BodyPart.Arms => ModLanguage.Text("Arms", "Руки"), BodyPart.Legs => ModLanguage.Text("Legs", "Ноги"), BodyPart.Footwear => ModLanguage.Text("Footwear", "Обувь"), _ => ModLanguage.Text("Other", "Другое"), }; } private void AddRow(ArraySegment<CosmeticAsset> assets, Action<CosmeticAsset> select, float tileSize, float gridWidth) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Expected O, but got Unknown page.AddElementToScrollView((ScrollViewBuilderDelegate)delegate(Transform parent) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0038: 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_005b: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_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_006d: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_0190: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_01c3: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) RectTransform component = new GameObject("Cosmetic tiles", new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>(); ((Transform)component).SetParent(parent, false); component.sizeDelta = new Vector2(gridWidth, tileSize); RectTransform maskRectTransform = page.maskRectTransform; Rect rect = maskRectTransform.rect; float x = parent.InverseTransformPoint(((Transform)maskRectTransform).TransformPoint(Vector2.op_Implicit(((Rect)(ref rect)).center))).x; ((Transform)component).localPosition = new Vector3(x, 0f); for (int i = 0; i < assets.Count; i++) { CosmeticAsset asset = assets[i]; REPOButton val = MenuAPI.CreateREPOButton("", (Action)delegate { select(asset); }, (Transform)(object)component, new Vector2(((float)i - 1f) * (tileSize + 8f), 0f)); ((Object)((Component)val).gameObject).name = "Gift - " + CosmeticInventory.Id(asset); ((REPOElement)val).rectTransform.pivot = new Vector2(0.5f, ((REPOElement)val).rectTransform.pivot.y); val.overrideButtonSize = new Vector2(tileSize, tileSize); ((REPOElement)val).rectTransform.sizeDelta = val.overrideButtonSize.Value; CosmeticIcon.AddImage(((Component)val).transform, "Rarity", tileSize - 4f, RarityColor(asset)); CosmeticIcon.AddImage(((Component)val).transform, "Inset", tileSize - 8f, Color32.op_Implicit(new Color32((byte)28, (byte)25, (byte)23, byte.MaxValue))); Image val2 = CosmeticIcon.AddImage(((Component)val).transform, "Cosmetic", tileSize - 15f, Color.white); tiles.Add(new Tile(asset, val, ((Component)val2).gameObject.AddComponent<CosmeticIcon>())); } return component; }, 0f, 0f); } private void LateUpdate() { int num = 0; CosmeticAsset val = null; foreach (Tile tile in tiles) { if (Hovering.Invoke(tile.Button.menuButton)) { val = tile.Asset; } if (!tile.IconRequested && num < 2 && ((Component)tile.Button).gameObject.activeInHierarchy) { tile.IconRequested = true; tile.Icon.SetAsset(tile.Asset); num++; } } if (Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)previewAsset)) { UpdatePreview((CosmeticAsset)(Object.op_Implicit((Object)(object)val) ? ((object)val) : ((object)tiles[0].Asset))); } } private void UpdatePreview(CosmeticAsset asset) { //IL_0078: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)asset == (Object)(object)previewAsset) && Object.op_Implicit((Object)(object)preview) && Object.op_Implicit((Object)(object)preview.playerAvatarVisuals)) { PlayerCosmetics playerCosmetics = preview.playerAvatarVisuals.playerCosmetics; if (Object.op_Implicit((Object)(object)playerCosmetics) && !FirstSetup.Invoke(playerCosmetics)) { MetaManager instance = MetaManager.instance; int[] array = new int[Enum.GetValues(typeof(CosmeticType)).Length]; array[asset.type] = (Object.op_Implicit((Object)(object)asset.defaultColor) ? Mathf.Max(0, instance.colors.IndexOf(asset.defaultColor)) : 0); playerCosmetics.SetupCosmetics(false, true, new List<int> { instance.cosmeticAssets.IndexOf(asset) }); playerCosmetics.SetupColors(false, array); previewAsset = asset; } } } } internal static class GiftPresentation { private static readonly FieldRef<CosmeticShopMachine, State> State = AccessTools.FieldRefAccess<CosmeticShopMachine, State>("stateCurrent"); private static readonly FieldRef<CosmeticShopMachine, PlayerAvatar> InteractingPlayer = AccessTools.FieldRefAccess<CosmeticShopMachine, PlayerAvatar>("interactingPlayer"); private static readonly FieldRef<CosmeticShopMachine, int> Reward = AccessTools.FieldRefAccess<CosmeticShopMachine, int>("interactingReward"); private static readonly FieldRef<CosmeticShopMachine, bool> StateImpulse = AccessTools.FieldRefAccess<CosmeticShopMachine, bool>("stateImpulse"); private static readonly FieldRef<CosmeticShopMachine, float> StateTimer = AccessTools.FieldRefAccess<CosmeticShopMachine, float>("stateTimer"); private static readonly FieldRef<CosmeticShopMachineAnimator, bool> TokenImpact = AccessTools.FieldRefAccess<CosmeticShopMachineAnimator, bool>("tokenImpactDone"); private static readonly Action<CosmeticShopMachine> RunState = AccessTools.MethodDelegate<Action<CosmeticShopMachine>>(AccessTools.Method(typeof(CosmeticShopMachine), "StateMachine", (Type[])null, (Type[])null), (object)null, true); internal static bool Begin(GiftTerminal terminal, CosmeticShopMachine machine, PlayerAvatar recipient, string assetId) { if (!terminal.CanUse || !Object.op_Implicit((Object)(object)recipient) || !Object.op_Implicit((Object)(object)MetaManager.instance)) { return false; } terminal.PresentingGift = true; InteractingPlayer.Invoke(machine) = recipient; Reward.Invoke(machine) = MetaManager.instance.cosmeticAssets.IndexOf(CosmeticInventory.Find(assetId)); TokenImpact.Invoke(machine.animator) = true; State.Invoke(machine) = (State)8; StateImpulse.Invoke(machine) = true; StateTimer.Invoke(machine) = 0f; RunState(machine); return true; } internal static void End(GiftTerminal terminal, CosmeticShopMachine machine) { terminal.PresentingGift = false; TokenImpact.Invoke(machine.animator) = false; } } [HarmonyPatch(typeof(CosmeticShopMachine), "RewardSet")] internal static class GiftRewardPatch { private static bool Prefix(CosmeticShopMachine __instance) { GiftTerminal giftTerminal = default(GiftTerminal); if (((Component)__instance).TryGetComponent<GiftTerminal>(ref giftTerminal)) { return !giftTerminal.PresentingGift; } return true; } } [HarmonyPatch(typeof(CosmeticShopMachine), "StateIdle")] internal static class GiftPresentationEndPatch { private static void Prefix(CosmeticShopMachine __instance) { GiftTerminal giftTerminal = default(GiftTerminal); if (((Component)__instance).TryGetComponent<GiftTerminal>(ref giftTerminal) && giftTerminal.PresentingGift) { GiftPresentation.End(giftTerminal, __instance); } } } internal sealed class GiftTerminal : MonoBehaviour { internal enum Side { None, Front, Rear } private static readonly FieldRef<CosmeticShopMachine, State> State = AccessTools.FieldRefAccess<CosmeticShopMachine, State>("stateCurrent"); private static readonly FieldRef<PlayerAvatar, bool> Disabled = AccessTools.FieldRefAccess<PlayerAvatar, bool>("isDisabled"); private static readonly FieldRef<MenuManager, MenuPage> CurrentPage = AccessTools.FieldRefAccess<MenuManager, MenuPage>("currentMenuPage"); private CosmeticShopMachine machine; private PhotonView? view; private REPOPopupPage? picker; private GiftDisplay? display; private Vector3 front; private float frontReach; private float statusUntil; private string status = ""; internal static PlayerAvatar? LocalPlayer { get { if (!Object.op_Implicit((Object)(object)PlayerController.instance)) { return null; } return SemiFunc.PlayerGetLocal(); } } internal int ViewId { get { if (!Object.op_Implicit((Object)(object)view)) { return 0; } return view.ViewID; } } internal bool ShopActive { get { if (Object.op_Implicit((Object)(object)machine) && Object.op_Implicit((Object)(object)RunManager.instance)) { return SemiFunc.RunIsShop(); } return false; } } internal bool CanUse { get { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Invalid comparison between Unknown and I4 if (ShopActive && Object.op_Implicit((Object)(object)GameDirector.instance) && (int)GameDirector.instance.currentState == 2) { return (int)State.Invoke(machine) == 0; } return false; } } internal bool PresentingGift { get; set; } internal bool BlockHostToken { get { GiftExchange? instance = GiftExchange.Instance; if (instance == null) { return false; } return instance.Current?.HasGift == true; } } internal bool BlockLocalToken { get { if (!BlockHostToken) { if (ShopActive) { if (!Object.op_Implicit((Object)(object)picker)) { return GetSide(LocalPlayer) == Side.Rear; } return true; } return false; } return true; } } internal void Initialize(CosmeticShopMachine shopMachine, InfoTextTrigger trigger) { //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: 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_009e: 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_00a8: 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_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: 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_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) machine = shopMachine; view = ((Component)machine).GetComponent<PhotonView>(); Collider val = (Object.op_Implicit((Object)(object)trigger) ? ((Component)trigger).GetComponent<Collider>() : null); Vector3 val2; if (!Object.op_Implicit((Object)(object)val)) { val2 = ((Component)this).transform.position; } else { Bounds bounds = val.bounds; val2 = ((Bounds)(ref bounds)).center; } Vector3 val3 = Vector3.ProjectOnPlane(val2 - ((Component)this).transform.position, Vector3.up); if (((Vector3)(ref val3)).sqrMagnitude < 0.04f && Object.op_Implicit((Object)(object)machine.playerTumbleTarget)) { val3 = Vector3.ProjectOnPlane(machine.playerTumbleTarget.position - ((Component)this).transform.position, Vector3.up); } front = ((((Vector3)(ref val3)).sqrMagnitude > 0.04f) ? ((Vector3)(ref val3)).normalized : ((Component)this).transform.forward); float num = (Object.op_Implicit((Object)(object)machine.playerTumbleTarget) ? Vector3.Dot(machine.playerTumbleTarget.position - ((Component)this).transform.position, front) : ((Vector3)(ref val3)).magnitude); frontReach = Mathf.Clamp(num + 0.7f, 1.85f, 2.75f); GiftExchange.Instance?.Bind(this); } internal Side GetSide(PlayerAvatar? player) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0034: 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_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0058: 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_005a: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)player) || Disabled.Invoke(player)) { return Side.None; } Vector3 val = ((Component)player).transform.position - ((Component)this).transform.position; if (Mathf.Abs(val.y) > 2.1f) { return Side.None; } Vector3 val2 = Vector3.Cross(Vector3.up, front); if (Mathf.Abs(Vector3.Dot(val, val2)) > 1.02f) { return Side.None; } float num = Vector3.Dot(val, front); if (num > 0.35f && num < frontReach) { return Side.Front; } if (!(num < -0.35f) || !(num > -1.95f)) { return Side.None; } return Side.Rear; } private void Update() { GiftExchange instance = GiftExchange.Instance; GiftExchange.Slot slot = instance?.Current; UpdateDisplay(slot); if (slot == null || !CanUse) { ClosePicker(); return; } Side side = GetSide(LocalPlayer); if (Object.op_Implicit((Object)(object)picker) && (side != Side.Rear || slot.HasGift)) { ClosePicker(); } if (side == Side.None || (Object.op_Implicit((Object)(object)MenuManager.instance) && Object.op_Implicit((Object)(object)CurrentPage.Invoke(MenuManager.instance))) || !SemiFunc.NoTextInputsActive() || !Object.op_Implicit((Object)(object)ItemInfoUI.instance) || !Object.op_Implicit((Object)(object)PhysGrabber.instance)) { return; } var (text, flag) = GetPrompt(side, slot); if (Time.unscaledTime < statusUntil) { text = status; } if (text.Length > 0) { SemiFunc.UIItemInfoText((ItemAttributes)null, SemiFunc.InputDisplayReplaceTags(text, "<u><b>", "</b></u>")); } if (flag && SemiFunc.InputDown((InputKey)2)) { if (slot.HasGift) { instance.Interact(slot); } else { OpenPicker(); } } } private static (string Text, bool CanUse) GetPrompt(Side side, GiftExchange.Slot slot) { if (!slot.HasGift) { if (side != Side.Rear) { return (Text: "", CanUse: false); } return (Text: ModLanguage.Text("Press [interact] to leave a cosmetic gift", "Нажмите [interact], чтобы подарить скин"), CanUse: true); } if (slot.Recipient != 0) { return (Text: ModLanguage.Text("Transferring the cosmetic…", "Передаём скин…"), CanUse: false); } if (slot.Donor == GiftExchange.LocalActor) { return (Text: (side == Side.Rear) ? ModLanguage.Text("Press [interact] to cancel the gift", "Нажмите [interact], чтобы отменить подарок") : ModLanguage.Text("Press [interact] to take back your cosmetic", "Нажмите [interact], чтобы забрать свой скин"), CanUse: true); } if (side == Side.Rear) { return (Text: ModLanguage.Text("There is already a gift in the machine", "В автомате уже есть подарок"), CanUse: false); } CosmeticAsset asset = CosmeticInventory.Find(slot.Asset); if (!CosmeticInventory.IsGiftable(asset)) { return (Text: ModLanguage.Text("Install the cosmetic pack to claim the gift from " + slot.Name, "Нужен набор косметики для подарка от " + slot.Name), CanUse: false); } if (CosmeticInventory.Owned(asset)) { return (Text: ModLanguage.Text("You already own the gift from " + slot.Name, "У вас уже есть скин от " + slot.Name), CanUse: false); } return (Text: ModLanguage.Text("Press [interact] to claim a cosmetic from " + slot.Name, "Нажмите [interact], чтобы забрать косметику от " + slot.Name), CanUse: CosmeticInventory.CanSave); } private void OpenPicker() { if (Object.op_Implicit((Object)(object)picker)) { return; } if (!CosmeticInventory.CanSave) { ShowStatus(ModLanguage.Text("Cosmetic saving is unavailable", "Сохранение косметики недоступно")); return; } CosmeticAsset[] array = CosmeticInventory.ListOwned().ToArray(); if (array.Length == 0) { ShowStatus(ModLanguage.Text("You have no cosmetics to gift", "У вас нет скинов для подарка")); return; } picker = GiftPicker.Open(array, delegate(CosmeticAsset asset) { ClosePicker(); if (CanUse && GetSide(LocalPlayer) == Side.Rear) { GiftExchange.Instance?.Offer(asset); } }, ClosePicker); } private void ClosePicker() { if (Object.op_Implicit((Object)(object)picker) && Object.op_Implicit((Object)(object)MenuManager.instance)) { picker.ClosePage(false); } picker = null; } private void UpdateDisplay(GiftExchange.Slot? slot) { //IL_0054: Unknown result type (might be due to invalid IL or missing references) if (slot == null || !slot.HasGift || slot.Committed || PresentingGift) { if (Object.op_Implicit((Object)(object)display)) { display.Show(""); } return; } if (!Object.op_Implicit((Object)(object)display)) { display = GiftDisplay.Create(((Component)this).transform, front); } display.Show(slot.Asset); } internal void ShowGift(PlayerAvatar recipient, string assetId) { GiftPresentation.Begin(this, machine, recipient, assetId); } internal void TransferFinished(bool received, string donor) { ShowStatus(received ? ModLanguage.Text("Received a cosmetic from " + donor, "Получен скин от " + donor) : ModLanguage.Text("Cosmetic gift delivered", "Скин подарен")); } private void ShowStatus(string message) { status = message; statusUntil = Time.unscaledTime + 2f; } private void OnDestroy() { ClosePicker(); GiftExchange.Instance?.Unbind(this); } } internal static class ModLanguage { private const string Game = "Game"; private const string English = "English"; private const string Russian = "Russian"; private static ConfigEntry<string>? preference; private static bool IsRussian { get { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) string text = preference?.Value; if (!(text == "Russian")) { if (text == "English") { return false; } Locale selectedLocale = LocalizationSettings.SelectedLocale; int result; if (selectedLocale == null) { result = 0; } else { LocaleIdentifier identifier = selectedLocale.Identifier; result = (((LocaleIdentifier)(ref identifier)).Code.StartsWith("ru", StringComparison.OrdinalIgnoreCase) ? 1 : 0); } return (byte)result != 0; } return true; } } internal static void Initialize(ConfigFile config) { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Expected O, but got Unknown preference = config.Bind<string>("General", "Language", "Game", new ConfigDescription("Language of NajCosmaticShare. Game follows the game language and uses English when no translation is available.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[3] { "Game", "English", "Russian" }), Array.Empty<object>())); } internal static string Text(string english, string russian) { if (!IsRussian) { return english; } return russian; } } [BepInPlugin("com.najvlad.najcosmaticshare", "NajCosmaticShare", "0.2.5")] [BepInDependency("nickklmao.menulib", "2.6.2")] [BepInDependency(/*Could not decode attribute arguments.*/)] public sealed class Plugin : BaseUnityPlugin { public const string Id = "com.najvlad.najcosmaticshare"; private Harmony? harmony; private GiftExchange? exchange; internal static ManualLogSource Log { get; private set; } private void Awake() { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; ModLanguage.Initialize(((BaseUnityPlugin)this).Config); exchange = ((Component)this).gameObject.AddComponent<GiftExchange>(); harmony = new Harmony("com.najvlad.najcosmaticshare"); harmony.PatchAll(typeof(Plugin).Assembly); } private void OnDestroy() { Harmony? obj = harmony; if (obj != null) { obj.UnpatchSelf(); } if (Object.op_Implicit((Object)(object)exchange)) { Object.Destroy((Object)(object)exchange); } } } [HarmonyPatch(typeof(CosmeticShopMachine), "Awake")] internal static class MachineAwakePatch { private static void Postfix(CosmeticShopMachine __instance, InfoTextTrigger ___infoTextTrigger) { ((Component)__instance).gameObject.AddComponent<GiftTerminal>().Initialize(__instance, ___infoTextTrigger); } } [HarmonyPatch(typeof(CosmeticShopMachine), "Interact")] internal static class MachineInteractPatch { private static bool Prefix(CosmeticShopMachine __instance) { GiftTerminal giftTerminal = default(GiftTerminal); if (((Component)__instance).TryGetComponent<GiftTerminal>(ref giftTerminal)) { return !giftTerminal.BlockLocalToken; } return true; } } [HarmonyPatch(typeof(CosmeticShopMachine), "InteractSet")] internal static class MachineHostInteractPatch { private static bool Prefix(CosmeticShopMachine __instance) { GiftTerminal giftTerminal = default(GiftTerminal); if (((Component)__instance).TryGetComponent<GiftTerminal>(ref giftTerminal)) { return !giftTerminal.BlockHostToken; } return true; } } [HarmonyPatch(typeof(CosmeticShopMachine), "InfoTextTriggerLogic")] internal static class MachinePromptPatch { private static void Postfix(CosmeticShopMachine __instance, InfoTextTrigger ___infoTextTrigger) { GiftTerminal giftTerminal = default(GiftTerminal); if (((Component)__instance).TryGetComponent<GiftTerminal>(ref giftTerminal) && giftTerminal.BlockLocalToken && Object.op_Implicit((Object)(object)___infoTextTrigger)) { ___infoTextTrigger.Disable(0.1f); } } } [HarmonyPatch(typeof(MetaManager), "CosmeticEquip")] internal static class ReservedCosmeticPatch { private static bool Prefix(CosmeticAsset _cosmeticAssetNew, ref bool __result) { if (Object.op_Implicit((Object)(object)_cosmeticAssetNew)) { GiftExchange? instance = GiftExchange.Instance; if (instance != null && instance.IsReserved(_cosmeticAssetNew)) { __result = false; return false; } } return true; } } }