using System;
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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Mirror;
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("SharedUpgrades")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[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]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace SharedUpgrades
{
[BepInPlugin("com.uki.crashoutcrew.sharedupgrades", "SharedUpgrades", "1.0.2")]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Log;
private readonly Harmony _harmony = new Harmony("com.uki.crashoutcrew.sharedupgrades");
internal static Type PlayerUpgradesType;
internal static Type PlayerUpgradeEnumType;
internal static MethodInfo ServerSetUpgradeMethod;
internal static MethodInfo HasUpgradeMethod;
internal static MethodInfo CmdAddUpgradeMethod;
private static bool _isSharing;
private void Awake()
{
//IL_0181: Unknown result type (might be due to invalid IL or missing references)
//IL_018e: Expected O, but got Unknown
//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
//IL_01df: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
PlayerUpgradesType = AccessTools.TypeByName("PlayerUpgrades") ?? AppDomain.CurrentDomain.GetAssemblies().SelectMany(delegate(Assembly a)
{
try
{
return a.GetTypes();
}
catch
{
return Type.EmptyTypes;
}
}).FirstOrDefault((Type t) => t.Name == "PlayerUpgrades");
PlayerUpgradeEnumType = AccessTools.TypeByName("PlayerUpgrade") ?? AppDomain.CurrentDomain.GetAssemblies().SelectMany(delegate(Assembly a)
{
try
{
return a.GetTypes();
}
catch
{
return Type.EmptyTypes;
}
}).FirstOrDefault((Type t) => t.Name == "PlayerUpgrade");
if (PlayerUpgradesType == null || PlayerUpgradeEnumType == null)
{
Log.LogError((object)"No se encontraron las clases PlayerUpgrades o PlayerUpgrade.");
return;
}
ServerSetUpgradeMethod = AccessTools.Method(PlayerUpgradesType, "ServerSetUpgrade", (Type[])null, (Type[])null);
HasUpgradeMethod = AccessTools.Method(PlayerUpgradesType, "HasUpgrade", (Type[])null, (Type[])null);
CmdAddUpgradeMethod = AccessTools.Method(PlayerUpgradesType, "CmdAddUpgrade", (Type[])null, (Type[])null);
if (ServerSetUpgradeMethod != null)
{
MethodInfo methodInfo = AccessTools.Method(typeof(Plugin), "ServerSetUpgrade_Postfix", (Type[])null, (Type[])null);
_harmony.Patch((MethodBase)ServerSetUpgradeMethod, (HarmonyMethod)null, new HarmonyMethod(methodInfo), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
MethodInfo methodInfo2 = AccessTools.Method(PlayerUpgradesType, "DeserializeSyncVars", (Type[])null, (Type[])null);
if (methodInfo2 != null)
{
MethodInfo methodInfo3 = AccessTools.Method(typeof(Plugin), "DeserializeSyncVars_Postfix", (Type[])null, (Type[])null);
_harmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(methodInfo3), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
Log.LogInfo((object)"Mod SharedUpgrades cargado correctamente.");
}
public static void ServerSetUpgrade_Postfix(Object __instance, object[] __args)
{
if (!NetworkServer.active || _isSharing || __args == null || __args.Length == 0)
{
return;
}
object obj = __args[0];
try
{
_isSharing = true;
Object[] array = Object.FindObjectsOfType(PlayerUpgradesType);
Object[] array2 = array;
foreach (Object val in array2)
{
if (!(val == (Object)null) && !(val == __instance) && !(bool)HasUpgradeMethod.Invoke(val, new object[1] { obj }))
{
Log.LogInfo((object)$"[Host] Compartiendo mejora '{obj}' con {val.name}");
ServerSetUpgradeMethod.Invoke(val, new object[1] { obj });
}
}
}
catch (Exception arg)
{
Log.LogError((object)$"Error al compartir mejora en el servidor: {arg}");
}
finally
{
_isSharing = false;
}
}
public static void DeserializeSyncVars_Postfix(Object __instance)
{
if (NetworkServer.active || CmdAddUpgradeMethod == null)
{
return;
}
try
{
Object[] array = Object.FindObjectsOfType(PlayerUpgradesType);
Object val = null;
Object[] array2 = array;
foreach (Object val2 in array2)
{
NetworkBehaviour val3 = (NetworkBehaviour)(object)((val2 is NetworkBehaviour) ? val2 : null);
if (val3 != null && (val3.isLocalPlayer || val3.isOwned))
{
val = val2;
break;
}
}
if (val == (Object)null || val == __instance)
{
return;
}
foreach (object value in Enum.GetValues(PlayerUpgradeEnumType))
{
bool flag = (bool)HasUpgradeMethod.Invoke(__instance, new object[1] { value });
bool flag2 = (bool)HasUpgradeMethod.Invoke(val, new object[1] { value });
if (flag && !flag2)
{
Log.LogInfo((object)$"[Cliente] Sincronizando mejora '{value}' comprada por otro jugador.");
CmdAddUpgradeMethod.Invoke(val, new object[1] { value });
}
}
}
catch (Exception arg)
{
Log.LogError((object)$"Error al sincronizar mejora en el cliente: {arg}");
}
}
}
}