using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using GameEvent;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Networking;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("PlayerPlacementsLimiterPlugin")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PlayerPlacementsLimiterPlugin")]
[assembly: AssemblyTitle("PlayerPlacementsLimiterPlugin")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PlayerPlacementsLimiter
{
[BepInPlugin("FaNim.PlayerPlacementsLimiter", "PlayerPlacementsLimiter", "0.1.0.0")]
public class PlayerPlacementsLimiterPlugin : BaseUnityPlugin
{
private readonly Harmony harmony = new Harmony("FaNim.PlayerPlacementsLimiter");
public static ConfigEntry<int> placeableLimit;
private void Awake()
{
placeableLimit = ((BaseUnityPlugin)this).Config.Bind<int>("General", "placeableLimit", 4, "Limit of placeable blocks per rounc");
Debug.Log((object)"[PlayerPlacementsLimiter] started.");
harmony.PatchAll();
}
}
public static class Logger
{
private const string logPrefix = "[PlayerPlacementsLimiter] ";
private const string errorPrefix = "[ERROR] ";
private const string warningPrefix = "[WARNING] ";
public static void Log(object message)
{
Debug.Log((object)string.Format("{0} {1}", "[PlayerPlacementsLimiter] ", message));
}
public static void Warning(object message)
{
Debug.LogWarning((object)string.Format("{0} {1} {2}", "[PlayerPlacementsLimiter] ", "[WARNING] ", message));
}
public static void Error(object message)
{
Debug.LogError((object)string.Format("{0} {1} {2}", "[PlayerPlacementsLimiter] ", "[ERROR] ", message));
}
}
}
namespace PlayerPlacementsLimiter.Patches
{
internal static class PartyBoxFields
{
public static readonly FieldRef<PartyBox, int> RemainingPickingCursor = AccessTools.FieldRefAccess<PartyBox, int>("remainingPickingCursor");
public static readonly FieldRef<PartyBox, PartyPickCursor[]> Cursors = AccessTools.FieldRefAccess<PartyBox, PartyPickCursor[]>("cursors");
}
[HarmonyPatch(typeof(PartyBox), "handleEvent")]
public static class PartyBoxHandleEventPatch
{
private static void Prefix(PartyBox __instance, GameEvent e)
{
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Invalid comparison between Unknown and I4
if (e == null)
{
return;
}
Type type = ((object)e).GetType();
if (type == typeof(ScoreboardEvent))
{
Logger.Log("Scoreboard event");
}
if (type == typeof(PickBlockEvent) && __instance.HasAuthority && (int)GameSettings.GetInstance().partyBoxMode == 0)
{
Logger.Log($"remainingPickingCursor on PickBlockEvent: {PartyBoxFields.RemainingPickingCursor.Invoke(__instance)}");
}
if (type == typeof(GamePlayerRemovedEvent))
{
GamePlayerRemovedEvent val = (GamePlayerRemovedEvent)(object)((e is GamePlayerRemovedEvent) ? e : null);
Logger.Log($"[GamePlayerRemovedEvent] Player network number: {val.PlayerNetworkNumber}");
}
if (type == typeof(NetworkMessageReceivedEvent))
{
NetworkMessageReceivedEvent val2 = (NetworkMessageReceivedEvent)(object)((e is NetworkMessageReceivedEvent) ? e : null);
if (val2.Message.msgType == NetMsgTypes.PiecePicked)
{
MessageBase readMessage = val2.ReadMessage;
MsgPiecePicked val3 = (MsgPiecePicked)(object)((readMessage is MsgPiecePicked) ? readMessage : null);
Logger.Log($"[PiecePicked] player number: {val3.PlayerNumber}, piece id: {val3.PieceID}, pickeable net id: {val3.PickableNetID}");
}
}
}
}
[HarmonyPatch(typeof(PartyBox), "ShowBox")]
public static class PartyBoxShowBoxPatch
{
private static void Postfix(PartyBox __instance, bool extraBox)
{
int num = PartyBoxFields.Cursors.Invoke(__instance).Length;
int value = PlayerPlacementsLimiterPlugin.placeableLimit.Value;
if (num > value)
{
num = value;
}
PartyBoxFields.RemainingPickingCursor.Invoke(__instance) = num;
}
}
[HarmonyPatch(typeof(PartyBox), "ChoosePieces")]
public static class PartyBoxChoosePiecesPathc
{
private static void Prefix(PartyBox __instance, int amount, List<Placeable> forceBlocks)
{
Logger.Log($"[ChoosePieces] amount: {amount}");
for (int i = 0; i < forceBlocks.Count; i++)
{
Placeable val = forceBlocks[i];
Logger.Log($"[ChoosePieces] force block [{i}]: {((Object)val).name}");
}
}
}
[HarmonyPatch(typeof(PartyBox), "OnPiecePicked")]
public static class PartyBoxOnPiecePickedPatch
{
private static void Postfix(PartyBox __instance, MsgPiecePicked pickMsg)
{
Logger.Log($"[OnPiecePicked] piece id: {pickMsg.PieceID}, player number: {pickMsg.PlayerNumber}, pickeable net id: {pickMsg.PickableNetID}");
}
}
[HarmonyPatch(typeof(PiecePlacementCursor), "handleEvent")]
public static class PiecePlacementCursorHandleEventPatch
{
private static void Prefix(PiecePlacementCursor __instance, GameEvent e)
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Expected O, but got Unknown
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Invalid comparison between Unknown and I4
Type type = ((object)e).GetType();
if (!(type == typeof(PickBlockEvent)))
{
return;
}
PickBlockEvent val = (PickBlockEvent)e;
if (val.PlayerNumber == ((Cursor)__instance).networkNumber && !((Object)(object)val.PickablePiece != (Object)null))
{
if ((int)GameSettings.GetInstance().GameMode != 2)
{
Logger.Warning("Wrong game mode");
}
else
{
Logger.Warning($"Should disable cursor with network number: {val.PlayerNumber}");
}
}
}
}
[HarmonyPatch(typeof(VersusControl), "SetupPlacementCursors")]
public static class VersusControlSetupPlacementCursorsPatch
{
private static void Postfix(VersusControl __instance)
{
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
//IL_00e2: Expected O, but got Unknown
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Expected O, but got Unknown
foreach (uint allGameNetID in LobbyManager.instance.PlayerTracker.GetAllGameNetIDs())
{
if (allGameNetID == 0)
{
continue;
}
GameObject val = ClientScene.FindLocalObject(new NetworkInstanceId(allGameNetID));
if ((Object)(object)val == (Object)null)
{
continue;
}
GamePlayer component = val.GetComponent<GamePlayer>();
if (!((Object)(object)component == (Object)null) && !((Object)(object)component.CursorInstance == (Object)null))
{
PiecePlacementCursor component2 = ((Component)component.CursorInstance).GetComponent<PiecePlacementCursor>();
if (!((Object)(object)component2.Piece != (Object)null) && component.IsLocalPlayer)
{
Logger.Warning($"Placement Cursor has no piece; skipping for network number: {component.CursorInstance.networkNumber}");
GameEventManager.SendEvent((GameEvent)new PickBlockEvent(component.CursorInstance.networkNumber, (PickableBlock)null, (Placeable)null));
GameEventManager.SendEvent((GameEvent)new PlacementTimerDoneEvent());
}
}
}
}
}
}