using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
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.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using SharedUpgrades__.Configuration;
using SharedUpgrades__.Models;
using SharedUpgrades__.Services;
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: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("Vippy")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+dcada6b259ce9338bc5c323ecc7513fdb5c1cce6")]
[assembly: AssemblyProduct("SharedUpgrades++")]
[assembly: AssemblyTitle("SharedUpgrades++")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.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;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace SharedUpgrades__
{
[BepInPlugin("Vippy.SharedUpgradesPlus", "SharedUpgradesPlus", "1.0.0")]
public class SharedUpgrades__ : BaseUnityPlugin
{
internal static SharedUpgrades__ Instance { get; private set; }
internal static ManualLogSource Logger => Instance._logger;
private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;
internal Harmony? Harmony { get; set; }
private void Awake()
{
Instance = this;
((Component)this).gameObject.transform.parent = null;
((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
PluginConfig.Init(((BaseUnityPlugin)this).Config);
Patch();
Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
}
internal void Patch()
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected O, but got Unknown
//IL_0026: Expected O, but got Unknown
if (Harmony == null)
{
Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
Harmony val2 = val;
Harmony = val;
}
Harmony.PatchAll();
}
internal void Unpatch()
{
Harmony? harmony = Harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
}
}
namespace SharedUpgrades__.Services
{
public static class ConfigService
{
public static bool IsSharedUpgradesEnabled()
{
return PluginConfig.EnableSharedUpgrades.Value;
}
public static bool IsModdedUpgradesEnabled()
{
return PluginConfig.EnableModdedUpgrades.Value;
}
public static bool IsLateJoinSyncEnabled()
{
return PluginConfig.EnableLateJoinSync.Value;
}
public static bool RollSharedUpgradesChance()
{
return Roll(PluginConfig.SharedUpgradeChance.Value);
}
public static bool RollLateJoinSyncChance()
{
return Roll(PluginConfig.LateJoinSyncChance.Value);
}
private static bool Roll(int chance)
{
return Random.Range(0, 100) < chance;
}
}
public static class DiscoveryService
{
public static DiscoveredUpgradesResult DiscoveredUpgrades(StatsManager statsManager)
{
HashSet<string> hashSet = new HashSet<string>();
HashSet<string> hashSet2 = new HashSet<string>();
foreach (string item in statsManager.dictionaryOfDictionaries.Keys.Where((string key) => key.StartsWith("playerUpgrade")))
{
if (AccessTools.Field(typeof(StatsManager), item) != null)
{
hashSet.Add(item);
}
else
{
hashSet2.Add(item);
}
}
return new DiscoveredUpgradesResult(hashSet, hashSet2);
}
}
public static class DistributionService
{
private static readonly FieldInfo _steamID = AccessTools.Field(typeof(PlayerAvatar), "steamID");
public static void DistributeUpgrade(UpgradeContext context, string upgradeKey, int difference, int currentValue)
{
PhotonView component = ((Component)PunManager.instance).GetComponent<PhotonView>();
if ((Object)(object)component == (Object)null)
{
SharedUpgrades__.Logger.LogWarning((object)"SharedUpgrades: PhotonView not found on PunManager.");
return;
}
bool flag = RegistryService.Instance.IsVanilla(upgradeKey);
if (!flag && !ConfigService.IsModdedUpgradesEnabled())
{
return;
}
object obj;
if (!flag)
{
obj = null;
}
else
{
int length = "playerUpgrade".Length;
obj = upgradeKey.Substring(length, upgradeKey.Length - length);
}
string text = (string)obj;
foreach (PlayerAvatar item in SemiFunc.PlayerGetAll())
{
if ((Object)(object)item == (Object)null || (Object)(object)item.photonView == (Object)null || item.photonView.ViewID == context.ViewID)
{
continue;
}
string text2 = (string)_steamID.GetValue(item);
if (!string.IsNullOrEmpty(text2) && ConfigService.RollSharedUpgradesChance())
{
if (flag)
{
component.RPC("TesterUpgradeCommandRPC", (RpcTarget)0, new object[3] { text2, text, difference });
SharedUpgrades__.Logger.LogInfo((object)$"SharedUpgrades: Distributed {upgradeKey} (+{difference}) to {text2}.");
}
else
{
component.RPC("UpdateStatRPC", (RpcTarget)0, new object[3] { upgradeKey, text2, currentValue });
SharedUpgrades__.Logger.LogInfo((object)$"SharedUpgrades: Distributed modded {upgradeKey} (={currentValue}) to {text2}.");
}
}
}
}
}
public class NetworkCallbackService : MonoBehaviourPunCallbacks
{
[CompilerGenerated]
private sealed class <>c__DisplayClass4_0
{
public Player joiningPlayer;
internal bool <WaitAndSync>b__0(PlayerAvatar p)
{
int result;
if ((Object)(object)p.photonView != (Object)null)
{
Player owner = p.photonView.Owner;
result = ((((owner != null) ? new int?(owner.ActorNumber) : null) == joiningPlayer.ActorNumber) ? 1 : 0);
}
else
{
result = 0;
}
return (byte)result != 0;
}
}
[CompilerGenerated]
private sealed class <WaitAndSync>d__4 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public Player joiningPlayer;
public Dictionary<string, int> teamSnapshot;
public NetworkCallbackService <>4__this;
private <>c__DisplayClass4_0 <>8__1;
private float <elapsed>5__2;
private PlayerAvatar <avatar>5__3;
private string <steamID>5__4;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <WaitAndSync>d__4(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>8__1 = null;
<avatar>5__3 = null;
<steamID>5__4 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>8__1 = new <>c__DisplayClass4_0();
<>8__1.joiningPlayer = joiningPlayer;
<elapsed>5__2 = 0f;
<avatar>5__3 = null;
<steamID>5__4 = string.Empty;
goto IL_0108;
case 1:
<>1__state = -1;
<elapsed>5__2 += 0.3f;
if (<avatar>5__3 == null)
{
<avatar>5__3 = ((IEnumerable<PlayerAvatar>)SemiFunc.PlayerGetAll()).FirstOrDefault((Func<PlayerAvatar, bool>)delegate(PlayerAvatar p)
{
int result;
if ((Object)(object)p.photonView != (Object)null)
{
Player owner = p.photonView.Owner;
result = ((((owner != null) ? new int?(owner.ActorNumber) : null) == <>8__1.joiningPlayer.ActorNumber) ? 1 : 0);
}
else
{
result = 0;
}
return (byte)result != 0;
});
}
if ((Object)(object)<avatar>5__3 != (Object)null)
{
<steamID>5__4 = (string)_steamID.GetValue(<avatar>5__3);
}
if (string.IsNullOrEmpty(<steamID>5__4))
{
goto IL_0108;
}
goto IL_011c;
case 2:
{
<>1__state = -1;
return false;
}
IL_0108:
if (<elapsed>5__2 < 12f)
{
<>2__current = (object)new WaitForSeconds(0.3f);
<>1__state = 1;
return true;
}
goto IL_011c;
IL_011c:
if ((Object)(object)<avatar>5__3 == (Object)null || string.IsNullOrEmpty(<steamID>5__4))
{
SharedUpgrades__.Logger.LogWarning((object)("Late Join: Timed out waiting for " + <>8__1.joiningPlayer.NickName + ". Skipping."));
return false;
}
<>2__current = SyncService.ApplyTeamSnapshot(<avatar>5__3, <steamID>5__4, teamSnapshot);
<>1__state = 2;
return true;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
private static readonly FieldInfo _steamID = AccessTools.Field(typeof(PlayerAvatar), "steamID");
public override void OnJoinedRoom()
{
//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_0026: Expected O, but got Unknown
//IL_0028: Expected O, but got Unknown
try
{
if (SemiFunc.IsMasterClientOrSingleplayer())
{
Hashtable val = new Hashtable();
((Dictionary<object, object>)val).Add((object)"su__v1", (object)true);
Hashtable val2 = val;
PhotonNetwork.CurrentRoom.SetCustomProperties(val2, (Hashtable)null, (WebFlags)null);
}
}
catch
{
}
}
public override void OnPlayerEnteredRoom(Player newPlayer)
{
if (ConfigService.IsLateJoinSyncEnabled() && ConfigService.IsSharedUpgradesEnabled() && SemiFunc.IsMasterClientOrSingleplayer() && IsActiveRun())
{
Dictionary<string, int> teamSnapshot = SnapshotService.SnapshotTeamMaxLevels();
((MonoBehaviour)this).StartCoroutine(WaitAndSync(newPlayer, teamSnapshot));
}
}
private static bool IsActiveRun()
{
if ((Object)(object)RunManager.instance == (Object)null)
{
return false;
}
Level levelCurrent = RunManager.instance.levelCurrent;
return (Object)(object)levelCurrent != (Object)(object)RunManager.instance.levelMainMenu && (Object)(object)levelCurrent != (Object)(object)RunManager.instance.levelLobbyMenu && (Object)(object)levelCurrent != (Object)(object)RunManager.instance.levelRecording && (Object)(object)levelCurrent != (Object)(object)RunManager.instance.levelSplashScreen;
}
[IteratorStateMachine(typeof(<WaitAndSync>d__4))]
private IEnumerator WaitAndSync(Player joiningPlayer, Dictionary<string, int> teamSnapshot)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <WaitAndSync>d__4(0)
{
<>4__this = this,
joiningPlayer = joiningPlayer,
teamSnapshot = teamSnapshot
};
}
}
public sealed class RegistryService
{
private static HashSet<string> vanillaKeys = null;
private static HashSet<string> moddedKeys = null;
private static readonly RegistryService instance = new RegistryService();
public static RegistryService Instance => instance;
private RegistryService()
{
vanillaKeys = new HashSet<string>();
moddedKeys = new HashSet<string>();
}
public void RegisterAll(DiscoveredUpgradesResult result)
{
vanillaKeys.UnionWith(result.Vanilla);
moddedKeys.UnionWith(result.Modded);
SharedUpgrades__.Logger.LogInfo((object)$"Discovered {vanillaKeys.Count} vanilla upgrades and {moddedKeys.Count} modded upgrades.");
}
public void Clear()
{
vanillaKeys.Clear();
moddedKeys.Clear();
}
public bool IsVanilla(string key)
{
return vanillaKeys.Contains(key);
}
}
public static class SnapshotService
{
public static Dictionary<string, int> SnapshotPlayerStats(string steamID)
{
string steamID2 = steamID;
if (string.IsNullOrEmpty(steamID2) || StatsManager.instance == null)
{
return new Dictionary<string, int>();
}
return StatsManager.instance.dictionaryOfDictionaries.Where((KeyValuePair<string, Dictionary<string, int>> kvp) => kvp.Key.StartsWith("playerUpgrade")).ToDictionary((KeyValuePair<string, Dictionary<string, int>> kvp) => kvp.Key, (KeyValuePair<string, Dictionary<string, int>> kvp) => kvp.Value.GetValueOrDefault(steamID2, 0));
}
public static Dictionary<string, int> SnapshotTeamMaxLevels()
{
Dictionary<string, int> dictionary = new Dictionary<string, int>();
if (StatsManager.instance == null)
{
return dictionary;
}
foreach (KeyValuePair<string, Dictionary<string, int>> item in StatsManager.instance.dictionaryOfDictionaries.Where((KeyValuePair<string, Dictionary<string, int>> k) => k.Key.StartsWith("playerUpgrade")))
{
dictionary[item.Key] = item.Value.Values.DefaultIfEmpty(0).Max();
}
return dictionary;
}
}
public static class SyncService
{
[CompilerGenerated]
private sealed class <ApplyTeamSnapshot>d__1 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public PlayerAvatar player;
public string steamID;
public Dictionary<string, int> teamSnapshot;
private PhotonView <photonView>5__1;
private string <playerName>5__2;
private Dictionary<string, int>.Enumerator <>s__3;
private KeyValuePair<string, int> <kvp>5__4;
private bool <isVanilla>5__5;
private int <playerLevel>5__6;
private Dictionary<string, int> <upgradeDict>5__7;
private int <difference>5__8;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <ApplyTeamSnapshot>d__1(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<photonView>5__1 = null;
<playerName>5__2 = null;
<>s__3 = default(Dictionary<string, int>.Enumerator);
<kvp>5__4 = default(KeyValuePair<string, int>);
<upgradeDict>5__7 = null;
<>1__state = -2;
}
private bool MoveNext()
{
if (<>1__state != 0)
{
return false;
}
<>1__state = -1;
if ((Object)(object)StatsManager.instance == (Object)null || (Object)(object)PunManager.instance == (Object)null)
{
return false;
}
<photonView>5__1 = ((Component)PunManager.instance).GetComponent<PhotonView>();
if ((Object)(object)<photonView>5__1 == (Object)null)
{
SharedUpgrades__.Logger.LogWarning((object)"Late Join: PhotonView not found on PunManager.");
return false;
}
<playerName>5__2 = (string)_playerName.GetValue(player);
SharedUpgrades__.Logger.LogInfo((object)("Late Join: Starting sync for " + <playerName>5__2 + " (" + steamID + ")."));
<>s__3 = teamSnapshot.GetEnumerator();
try
{
while (<>s__3.MoveNext())
{
<kvp>5__4 = <>s__3.Current;
<isVanilla>5__5 = RegistryService.Instance.IsVanilla(<kvp>5__4.Key);
if (!<isVanilla>5__5 && !ConfigService.IsModdedUpgradesEnabled())
{
continue;
}
<playerLevel>5__6 = (StatsManager.instance.dictionaryOfDictionaries.TryGetValue(<kvp>5__4.Key, out <upgradeDict>5__7) ? <upgradeDict>5__7.GetValueOrDefault(steamID, 0) : 0);
<difference>5__8 = <kvp>5__4.Value - <playerLevel>5__6;
if (<difference>5__8 <= 0)
{
continue;
}
if (!ConfigService.RollLateJoinSyncChance())
{
SharedUpgrades__.Logger.LogInfo((object)("Late Join: Roll failed for " + <kvp>5__4.Key + " (" + steamID + "), skipping."));
continue;
}
if (<isVanilla>5__5)
{
PhotonView obj = <photonView>5__1;
object[] obj2 = new object[3] { steamID, null, null };
string key = <kvp>5__4.Key;
int length = "playerUpgrade".Length;
obj2[1] = key.Substring(length, key.Length - length);
obj2[2] = <difference>5__8;
obj.RPC("TesterUpgradeCommandRPC", (RpcTarget)1, obj2);
}
else
{
<photonView>5__1.RPC("UpdateStatRPC", (RpcTarget)1, new object[3] { <kvp>5__4.Key, steamID, <kvp>5__4.Value });
}
<upgradeDict>5__7 = null;
<kvp>5__4 = default(KeyValuePair<string, int>);
}
}
finally
{
((IDisposable)<>s__3).Dispose();
}
<>s__3 = default(Dictionary<string, int>.Enumerator);
SharedUpgrades__.Logger.LogInfo((object)("Late Join: Sync complete for " + <playerName>5__2 + "."));
return false;
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
private static readonly FieldInfo _playerName = AccessTools.Field(typeof(PlayerAvatar), "playerName");
[IteratorStateMachine(typeof(<ApplyTeamSnapshot>d__1))]
public static IEnumerator ApplyTeamSnapshot(PlayerAvatar player, string steamID, Dictionary<string, int> teamSnapshot)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <ApplyTeamSnapshot>d__1(0)
{
player = player,
steamID = steamID,
teamSnapshot = teamSnapshot
};
}
}
public class WatermarkService : MonoBehaviour
{
[CompilerGenerated]
private sealed class <Poll>d__6 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public WatermarkService <>4__this;
private bool <isOwner>5__1;
private bool <modPresent>5__2;
private List<PlayerAvatar>.Enumerator <>s__3;
private PlayerAvatar <p>5__4;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <Poll>d__6(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>s__3 = default(List<PlayerAvatar>.Enumerator);
<p>5__4 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_012f: Unknown result type (might be due to invalid IL or missing references)
//IL_0139: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
break;
case 1:
<>1__state = -1;
break;
}
try
{
<isOwner>5__1 = false;
<>s__3 = SemiFunc.PlayerGetAll().GetEnumerator();
try
{
while (<>s__3.MoveNext())
{
<p>5__4 = <>s__3.Current;
if ((Object)(object)<p>5__4?.photonView != (Object)null && <p>5__4.photonView.IsMine)
{
<isOwner>5__1 = (string)_steamID.GetValue(<p>5__4) == "76561198032409969";
break;
}
<p>5__4 = null;
}
}
finally
{
((IDisposable)<>s__3).Dispose();
}
<>s__3 = default(List<PlayerAvatar>.Enumerator);
<modPresent>5__2 = PhotonNetwork.InRoom && ((Dictionary<object, object>)(object)((RoomInfo)PhotonNetwork.CurrentRoom).CustomProperties).ContainsKey((object)"su__v1");
<>4__this.show = <isOwner>5__1 & <modPresent>5__2;
}
catch
{
}
<>2__current = (object)new WaitForSeconds(3f);
<>1__state = 1;
return true;
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
internal const string RoomKey = "su__v1";
private const string OwnerID = "76561198032409969";
private static readonly FieldInfo _steamID = AccessTools.Field(typeof(PlayerAvatar), "steamID");
private bool show = false;
private GUIStyle? style;
private void Start()
{
((MonoBehaviour)this).StartCoroutine(Poll());
}
[IteratorStateMachine(typeof(<Poll>d__6))]
private IEnumerator Poll()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <Poll>d__6(0)
{
<>4__this = this
};
}
private void OnGUI()
{
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: 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_0060: Expected O, but got Unknown
if (!show)
{
return;
}
try
{
if (style == null)
{
GUIStyle val = new GUIStyle(GUI.skin.label)
{
fontSize = 9
};
val.normal.textColor = new Color(1f, 1f, 1f, 0.15f);
style = val;
}
GUI.Label(new Rect(6f, (float)(Screen.height - 18), 40f, 14f), "S++", style);
}
catch
{
}
}
}
}
namespace SharedUpgrades__.Patches
{
[HarmonyPatch(typeof(ItemUpgrade), "PlayerUpgrade")]
public class SharedUpgradesPatch
{
private static readonly FieldInfo _itemToggle = AccessTools.Field(typeof(ItemUpgrade), "itemToggle");
private static readonly FieldInfo _playerTogglePhotonId = AccessTools.Field(typeof(ItemToggle), "playerTogglePhotonID");
private static readonly FieldInfo _steamID = AccessTools.Field(typeof(PlayerAvatar), "steamID");
private static readonly FieldInfo _playerName = AccessTools.Field(typeof(PlayerAvatar), "playerName");
private static PlayerAvatar? GetUpgradePlayer(ItemUpgrade instance, out int viewID)
{
viewID = 0;
object? value = _itemToggle.GetValue(instance);
ItemToggle val = (ItemToggle)((value is ItemToggle) ? value : null);
if (val == null || !val.toggleState)
{
return null;
}
viewID = (int)_playerTogglePhotonId.GetValue(val);
return SemiFunc.PlayerAvatarGetFromPhotonID(viewID);
}
[HarmonyPrefix]
public static void Prefix(ItemUpgrade __instance, out UpgradeContext? __state)
{
__state = null;
if (!ConfigService.IsSharedUpgradesEnabled() || !SemiFunc.IsMasterClientOrSingleplayer())
{
return;
}
int viewID;
PlayerAvatar upgradePlayer = GetUpgradePlayer(__instance, out viewID);
if (upgradePlayer != null)
{
string text = (string)_steamID.GetValue(upgradePlayer);
if (!string.IsNullOrEmpty(text))
{
__state = new UpgradeContext(text, playerName: (string)_playerName.GetValue(upgradePlayer), viewID: viewID, levelsBefore: SnapshotService.SnapshotPlayerStats(text));
}
}
}
[HarmonyPostfix]
public static void Postfix(UpgradeContext? __state)
{
if (!SemiFunc.IsMasterClientOrSingleplayer() || __state == null)
{
return;
}
IEnumerable<KeyValuePair<string, Dictionary<string, int>>> enumerable = StatsManager.instance.dictionaryOfDictionaries.Where((KeyValuePair<string, Dictionary<string, int>> key) => key.Key.StartsWith("playerUpgrade"));
foreach (KeyValuePair<string, Dictionary<string, int>> item in enumerable)
{
item.Value.TryGetValue(__state.SteamID, out var value);
__state.LevelsBefore.TryGetValue(item.Key, out var value2);
if (value > value2)
{
SharedUpgrades__.Logger.LogInfo((object)$"SharedUpgrades: {__state.PlayerName} purchased {item.Key} (+{value - value2}), distributing...");
DistributionService.DistributeUpgrade(__state, item.Key, value - value2, value);
}
}
}
}
[HarmonyPatch(typeof(StatsManager), "Start")]
public class StatsManagerPatch
{
private static NetworkCallbackService? _callbackService;
[HarmonyPostfix]
public static void Postfix(StatsManager __instance)
{
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Expected O, but got Unknown
DiscoveredUpgradesResult result = DiscoveryService.DiscoveredUpgrades(__instance);
RegistryService.Instance.Clear();
RegistryService.Instance.RegisterAll(result);
if ((Object)(object)_callbackService == (Object)null)
{
GameObject val = new GameObject("NetworkCallbackService");
_callbackService = val.AddComponent<NetworkCallbackService>();
val.AddComponent<WatermarkService>();
Object.DontDestroyOnLoad((Object)(object)val);
}
}
}
}
namespace SharedUpgrades__.Models
{
public sealed class DiscoveredUpgradesResult
{
public HashSet<string> Vanilla { get; }
public HashSet<string> Modded { get; }
public DiscoveredUpgradesResult(HashSet<string> vanilla, HashSet<string> modded)
{
Vanilla = vanilla;
Modded = modded;
}
}
public sealed class UpgradeContext
{
public string SteamID { get; }
public int ViewID { get; }
public string PlayerName { get; }
public Dictionary<string, int> LevelsBefore { get; }
public UpgradeContext(string steamID, int viewID, string playerName, Dictionary<string, int> levelsBefore)
{
SteamID = steamID;
ViewID = viewID;
PlayerName = playerName;
LevelsBefore = levelsBefore;
}
}
}
namespace SharedUpgrades__.Configuration
{
internal static class PluginConfig
{
public static ConfigEntry<bool> EnableSharedUpgrades;
public static ConfigEntry<int> SharedUpgradeChance;
public static ConfigEntry<bool> EnableLateJoinSync;
public static ConfigEntry<int> LateJoinSyncChance;
public static ConfigEntry<bool> EnableModdedUpgrades;
public static void Init(ConfigFile config)
{
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Expected O, but got Unknown
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Expected O, but got Unknown
EnableSharedUpgrades = config.Bind<bool>("Shared Upgrades", "EnableSharedUpgrades", true, "Toggle for Shared Upgrades");
SharedUpgradeChance = config.Bind<int>("Shared Upgrades Chance", "SharedUpgradesChance", 100, new ConfigDescription("0-100% chance the upgrade will be applied to other players", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
EnableLateJoinSync = config.Bind<bool>("Late Join Sync", "LateJoinSync", true, "If players join late, should the previous upgrades be applied?");
LateJoinSyncChance = config.Bind<int>("Late Join Sync Chance", "LateJoinSyncChance", 100, new ConfigDescription("0-100% chance for previously applied upgrades to apply to players who join late", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
EnableModdedUpgrades = config.Bind<bool>("Modded Upgrade Sync", "EnableModdedUpgrades", true, "This feature will sync upgrades introduced by mods.");
}
}
}