using System;
using System.Diagnostics;
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 Microsoft.CodeAnalysis;
using MonoMod.RuntimeDetour;
using RiskOfOptions;
using RiskOfOptions.Options;
using RoR2;
[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("ForcePlayerCount")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+562b8f68a6eb77560800cc30a42f698a869c9f81")]
[assembly: AssemblyProduct("ForcePlayerCount")]
[assembly: AssemblyTitle("ForcePlayerCount")]
[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.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace ForcePlayerCount
{
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("iDeathHD.ForcePlayerCount", "ForcePlayerCount", "1.0.0")]
public class ForcePlayerCount : BaseUnityPlugin
{
public const string PluginGUID = "iDeathHD.ForcePlayerCount";
public const string PluginAuthor = "iDeathHD";
public const string PluginName = "ForcePlayerCount";
public const string PluginVersion = "1.0.0";
private Hook _hook;
private Hook _hook2;
public static ForcePlayerCount Instance { get; private set; }
public ConfigEntry<int> PlayerCount { get; private set; }
public void Awake()
{
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Expected O, but got Unknown
//IL_005f: 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_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Expected O, but got Unknown
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
//IL_00f3: Expected O, but got Unknown
Log.Init(((BaseUnityPlugin)this).Logger);
Instance = this;
int num = 4;
PlayerCount = ((BaseUnityPlugin)this).Config.Bind<int>("Gameplay Tweaks", "PlayerCount", num, "Overrides the game's player count with a fixed value.");
PlayerCount.SettingChanged += PlayerCountOnSettingChanged;
ModSettingsManager.AddOption((BaseOption)new IntFieldOption(PlayerCount));
BindingFlags bindingAttr = (BindingFlags)(-1);
HookConfig val = default(HookConfig);
val.ManualApply = true;
HookConfig val2 = val;
_hook = new Hook((MethodBase)typeof(Run).GetProperty("participatingPlayerCount", bindingAttr).GetGetMethod(nonPublic: true), (Delegate)new Func<Func<Run, int>, Run, int>(OverrideParticipatingPlayerCount), val2);
_hook2 = new Hook((MethodBase)typeof(Run).GetProperty("livingPlayerCount", bindingAttr).GetGetMethod(nonPublic: true), (Delegate)new Func<Func<Run, int>, Run, int>(OverrideLivingPlayerCount), val2);
}
private void PlayerCountOnSettingChanged(object sender, EventArgs e)
{
LogPlayerCount();
}
private static int OverrideParticipatingPlayerCount(Func<Run, int> orig, Run self)
{
return Instance.PlayerCount.Value;
}
private static int OverrideLivingPlayerCount(Func<Run, int> orig, Run self)
{
int num = orig(self);
int value = Instance.PlayerCount.Value;
if (num > 0 && value > 0 && value < num)
{
return value;
}
return num;
}
public void OnEnable()
{
Hook hook = _hook;
if (hook != null)
{
hook.Apply();
}
Hook hook2 = _hook2;
if (hook2 != null)
{
hook2.Apply();
}
}
public void OnDisable()
{
Hook hook = _hook;
if (hook != null)
{
hook.Undo();
}
Hook hook2 = _hook2;
if (hook2 != null)
{
hook2.Undo();
}
}
private static void LogPlayerCount()
{
Log.Info("New PlayerCount: " + Instance.PlayerCount.Value, "C:\\Users\\Quentin\\source\\repos\\ForcePlayerCount\\ForcePlayerCount.cs", "LogPlayerCount", 83);
}
}
internal static class Log
{
private static ManualLogSource _logSource;
internal static void Init(ManualLogSource logSource)
{
_logSource = logSource;
}
private static string Format(object data, string file, string member, int line)
{
return $"[{file}:{line} ({member})] {data}";
}
internal static void Debug(object data, [CallerFilePath] string file = "", [CallerMemberName] string member = "", [CallerLineNumber] int line = 0)
{
_logSource.LogDebug((object)Format(data, file, member, line));
}
internal static void Error(object data, [CallerFilePath] string file = "", [CallerMemberName] string member = "", [CallerLineNumber] int line = 0)
{
_logSource.LogError((object)Format(data, file, member, line));
}
internal static void Fatal(object data, [CallerFilePath] string file = "", [CallerMemberName] string member = "", [CallerLineNumber] int line = 0)
{
_logSource.LogFatal((object)Format(data, file, member, line));
}
internal static void Info(object data, [CallerFilePath] string file = "", [CallerMemberName] string member = "", [CallerLineNumber] int line = 0)
{
_logSource.LogInfo((object)Format(data, file, member, line));
}
internal static void Message(object data, [CallerFilePath] string file = "", [CallerMemberName] string member = "", [CallerLineNumber] int line = 0)
{
_logSource.LogMessage((object)Format(data, file, member, line));
}
internal static void Warning(object data, [CallerFilePath] string file = "", [CallerMemberName] string member = "", [CallerLineNumber] int line = 0)
{
_logSource.LogWarning((object)Format(data, file, member, line));
}
}
}