using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using ExitGames.Client.Photon;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("PhotonCustomPropsUtils")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.0+7a6f1ee1f463947ca9cc507608f1f04cdcd9325e")]
[assembly: AssemblyProduct("PhotonCustomPropsUtils")]
[assembly: AssemblyTitle("PhotonCustomPropsUtils")]
[assembly: AssemblyVersion("1.1.0.0")]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.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]
[Microsoft.CodeAnalysis.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;
}
}
}
namespace PhotonCustomPropsUtils
{
[BepInPlugin("com.snosz.photoncustompropsutils", "PhotonCustomPropsUtils", "1.1.0")]
public class PhotonCustomPropsUtilsPlugin : BaseUnityPlugin
{
public static PhotonCustomPropsUtilsManager UtilsManager;
public static bool IsReady { get; private set; }
public static event Action OnReady;
private void Awake()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
GameObject val = new GameObject("PhotonCustomPropsUtilsManager");
Object.DontDestroyOnLoad((Object)(object)val);
UtilsManager = val.AddComponent<PhotonCustomPropsUtilsManager>();
IsReady = true;
PhotonCustomPropsUtilsPlugin.OnReady?.Invoke();
}
public static PhotonScopedManager GetManager(string modGUID)
{
return new PhotonScopedManager(modGUID, UtilsManager);
}
}
public class PhotonCustomPropsUtilsManager : MonoBehaviourPunCallbacks
{
private static readonly Dictionary<string, List<PhotonScopedManager>> scopedManagers = new Dictionary<string, List<PhotonScopedManager>>();
public static void RegisterScopedManager(string modGUID, PhotonScopedManager manager)
{
if (!scopedManagers.TryGetValue(modGUID, out List<PhotonScopedManager> value))
{
value = (scopedManagers[modGUID] = new List<PhotonScopedManager>());
}
value.Add(manager);
}
public override void OnJoinedRoom()
{
Room currentRoom = PhotonNetwork.CurrentRoom;
Hashtable val = ((currentRoom != null) ? ((RoomInfo)currentRoom).CustomProperties : null);
Player localPlayer = PhotonNetwork.LocalPlayer;
Hashtable val2 = ((localPlayer != null) ? localPlayer.CustomProperties : null);
foreach (List<PhotonScopedManager> value in scopedManagers.Values)
{
foreach (PhotonScopedManager item in value)
{
item.OnJoinedRoomLocalPlayer(localPlayer);
if (val != null)
{
item.OnRoomPropertiesChanged(RoomEventType.OnJoinedRoom, val);
}
if (val2 != null)
{
item.OnPlayerPropertiesChanged(PlayerEventType.OnJoinedRoom, localPlayer, val2);
}
}
}
}
public override void OnRoomPropertiesUpdate(Hashtable propertiesThatChanged)
{
foreach (List<PhotonScopedManager> value in scopedManagers.Values)
{
foreach (PhotonScopedManager item in value)
{
item.OnRoomPropertiesChanged(RoomEventType.OnRoomPropertyChanged, propertiesThatChanged);
}
}
}
public override void OnPlayerPropertiesUpdate(Player targetPlayer, Hashtable changedProps)
{
foreach (List<PhotonScopedManager> value in scopedManagers.Values)
{
foreach (PhotonScopedManager item in value)
{
item.OnPlayerPropertiesChanged(PlayerEventType.OnPlayerPropertyChanged, targetPlayer, changedProps);
}
}
}
}
public enum RoomEventType
{
OnJoinedRoom,
OnRoomPropertyChanged,
All
}
public enum PlayerEventType
{
OnJoinedRoom,
OnPlayerPropertyChanged,
All
}
public class PhotonScopedManager
{
private struct RoomListener
{
public RoomEventType Type;
public Action<object> Callback;
}
private struct PlayerListener
{
public PlayerEventType Type;
public Action<Player, object> Callback;
}
private readonly string modGUID;
private readonly PhotonCustomPropsUtilsManager eventManager;
private readonly Dictionary<string, List<RoomListener>> roomPropertyListeners = new Dictionary<string, List<RoomListener>>();
private readonly Dictionary<string, List<PlayerListener>> playerPropertyListeners = new Dictionary<string, List<PlayerListener>>();
private readonly List<Action<Player>> onJoinedRoomLocalPlayerCallbacks = new List<Action<Player>>();
public PhotonScopedManager(string modGUID, PhotonCustomPropsUtilsManager eventManager)
{
this.modGUID = modGUID;
this.eventManager = eventManager;
PhotonCustomPropsUtilsManager.RegisterScopedManager(modGUID, this);
}
public void RegisterOnJoinedRoom(Action<Player> callback)
{
if (callback != null)
{
onJoinedRoomLocalPlayerCallbacks.Add(callback);
}
}
public void OnJoinedRoomLocalPlayer(Player localPlayer)
{
foreach (Action<Player> onJoinedRoomLocalPlayerCallback in onJoinedRoomLocalPlayerCallbacks)
{
onJoinedRoomLocalPlayerCallback(localPlayer);
}
}
public void RegisterRoomProperty(string propertyKey, RoomEventType type, Action<object> callback)
{
if (!roomPropertyListeners.TryGetValue(propertyKey, out List<RoomListener> value))
{
value = new List<RoomListener>();
roomPropertyListeners[propertyKey] = value;
}
if (type == RoomEventType.All)
{
value.Add(new RoomListener
{
Type = RoomEventType.OnJoinedRoom,
Callback = callback
});
value.Add(new RoomListener
{
Type = RoomEventType.OnRoomPropertyChanged,
Callback = callback
});
}
else
{
value.Add(new RoomListener
{
Type = type,
Callback = callback
});
}
}
public Dictionary<Player, Hashtable> GetAllPlayerProperties()
{
Dictionary<Player, Hashtable> dictionary = new Dictionary<Player, Hashtable>();
Player[] playerList = PhotonNetwork.PlayerList;
foreach (Player val in playerList)
{
if (((val != null) ? val.CustomProperties : null) != null)
{
dictionary[val] = val.CustomProperties;
}
}
return dictionary;
}
public Dictionary<Player, T> GetAllPlayerProperties<T>(string propertyKey)
{
Dictionary<Player, T> dictionary = new Dictionary<Player, T>();
Player[] playerList = PhotonNetwork.PlayerList;
foreach (Player val in playerList)
{
if (((val != null) ? val.CustomProperties : null) != null && ((Dictionary<object, object>)(object)val.CustomProperties).ContainsKey((object)propertyKey))
{
if (val.CustomProperties[(object)propertyKey] is T value)
{
dictionary[val] = value;
continue;
}
Debug.LogWarning((object)("[PhotonCustomPropsUtils] Player " + val.NickName + " has property '" + propertyKey + "' but it's not of type " + typeof(T).Name + "."));
}
}
return dictionary;
}
public void RegisterRoomProperty<T>(string propertyKey, RoomEventType type, Action<T> callback)
{
Action<T> callback2 = callback;
string propertyKey2 = propertyKey;
RegisterRoomProperty(propertyKey2, type, delegate(object val)
{
if (val is T obj)
{
callback2(obj);
}
else
{
Debug.LogWarning((object)("[PhotonCustomPropsUtils] Expected type " + typeof(T).Name + " for key " + propertyKey2 + ", but got " + (val?.GetType().Name ?? "null")));
}
});
}
public void RegisterPlayerProperty(string propertyKey, PlayerEventType type, Action<Player, object> callback)
{
if (!playerPropertyListeners.TryGetValue(propertyKey, out List<PlayerListener> value))
{
value = new List<PlayerListener>();
playerPropertyListeners[propertyKey] = value;
}
if (type == PlayerEventType.All)
{
value.Add(new PlayerListener
{
Type = PlayerEventType.OnJoinedRoom,
Callback = callback
});
value.Add(new PlayerListener
{
Type = PlayerEventType.OnPlayerPropertyChanged,
Callback = callback
});
}
else
{
value.Add(new PlayerListener
{
Type = type,
Callback = callback
});
}
}
public void RegisterPlayerProperty<T>(string propertyKey, PlayerEventType type, Action<Player, T> callback)
{
Action<Player, T> callback2 = callback;
string propertyKey2 = propertyKey;
RegisterPlayerProperty(propertyKey2, type, delegate(Player player, object val)
{
if (val is T arg)
{
callback2(player, arg);
}
else
{
Debug.LogWarning((object)("[PhotonCustomPropsUtils] Expected type " + typeof(T).Name + " for key " + propertyKey2 + ", but got " + (val?.GetType().Name ?? "null")));
}
});
}
public void SetRoomProperty(string propertyKey, object value)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
Hashtable val = new Hashtable { [(object)propertyKey] = value };
Room currentRoom = PhotonNetwork.CurrentRoom;
if (currentRoom != null)
{
currentRoom.SetCustomProperties(val, (Hashtable)null, (WebFlags)null);
}
}
public void SetPlayerProperty(string propertyKey, object value)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
Hashtable val = new Hashtable { [(object)propertyKey] = value };
Player localPlayer = PhotonNetwork.LocalPlayer;
if (localPlayer != null)
{
localPlayer.SetCustomProperties(val, (Hashtable)null, (WebFlags)null);
}
}
public void OnRoomPropertiesChanged(RoomEventType firedType, Hashtable changedProps)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
DictionaryEntryEnumerator enumerator = changedProps.GetEnumerator();
try
{
while (((DictionaryEntryEnumerator)(ref enumerator)).MoveNext())
{
DictionaryEntry current = ((DictionaryEntryEnumerator)(ref enumerator)).Current;
string key = current.Key.ToString();
if (!roomPropertyListeners.TryGetValue(key, out List<RoomListener> value))
{
continue;
}
foreach (RoomListener item in value)
{
if (item.Type == firedType)
{
item.Callback(current.Value);
}
}
}
}
finally
{
((IDisposable)(DictionaryEntryEnumerator)(ref enumerator)).Dispose();
}
}
public void OnPlayerPropertiesChanged(PlayerEventType firedType, Player targetPlayer, Hashtable changedProps)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
DictionaryEntryEnumerator enumerator = changedProps.GetEnumerator();
try
{
while (((DictionaryEntryEnumerator)(ref enumerator)).MoveNext())
{
DictionaryEntry current = ((DictionaryEntryEnumerator)(ref enumerator)).Current;
string key = current.Key.ToString();
if (!playerPropertyListeners.TryGetValue(key, out List<PlayerListener> value))
{
continue;
}
foreach (PlayerListener item in value)
{
if (item.Type == firedType)
{
item.Callback(targetPlayer, current.Value);
}
}
}
}
finally
{
((IDisposable)(DictionaryEntryEnumerator)(ref enumerator)).Dispose();
}
}
}
}