using System;
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 GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using Unity.Collections;
using Unity.Netcode;
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(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("BuyableDramaMask")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyCopyright("Copyright © 2023 MegaPiggy")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+de03bd2735d14ec5e61f253b6602806c4ce89ece")]
[assembly: AssemblyProduct("BuyableDramaMask")]
[assembly: AssemblyTitle("BuyableDramaMask")]
[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 BuyableDramaMask
{
[BepInDependency("evaisa.lethallib", "0.13.0")]
[BepInDependency("DramaMask", "1.0.0")]
[BepInPlugin("MegaPiggy.BuyableDramaMask", "Buyable Drama Mask", "1.1.0")]
public class BuyableDramaMask : BaseUnityPlugin
{
internal class Unflagger : MonoBehaviour
{
public void Awake()
{
((Object)((Component)this).gameObject).hideFlags = (HideFlags)0;
}
}
[HarmonyPatch]
internal static class Patches
{
[CompilerGenerated]
private static class <>O
{
public static HandleNamedMessageDelegate <0>__OnRequestSync;
public static HandleNamedMessageDelegate <1>__OnReceiveSync;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")]
public static void ServerConnect()
{
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Expected O, but got Unknown
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Expected O, but got Unknown
if (IsHost)
{
LoggerInstance.LogInfo((object)"Started hosting, using local settings");
CustomMessagingManager customMessagingManager = NetworkManager.Singleton.CustomMessagingManager;
object obj = <>O.<0>__OnRequestSync;
if (obj == null)
{
HandleNamedMessageDelegate val = OnRequestSync;
<>O.<0>__OnRequestSync = val;
obj = (object)val;
}
customMessagingManager.RegisterNamedMessageHandler("BuyableDramaMask_OnRequestConfigSync", (HandleNamedMessageDelegate)obj);
return;
}
LoggerInstance.LogInfo((object)"Connected to server, requesting settings");
CustomMessagingManager customMessagingManager2 = NetworkManager.Singleton.CustomMessagingManager;
object obj2 = <>O.<1>__OnReceiveSync;
if (obj2 == null)
{
HandleNamedMessageDelegate val2 = OnReceiveSync;
<>O.<1>__OnReceiveSync = val2;
obj2 = (object)val2;
}
customMessagingManager2.RegisterNamedMessageHandler("BuyableDramaMask_OnReceiveConfigSync", (HandleNamedMessageDelegate)obj2);
NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("BuyableDramaMask_OnRequestConfigSync", 0uL, new FastBufferWriter(0, (Allocator)2, -1), (NetworkDelivery)2);
}
[HarmonyPostfix]
[HarmonyPatch(typeof(GameNetworkManager), "StartDisconnect")]
public static void ServerDisconnect()
{
LoggerInstance.LogInfo((object)"Server disconnect");
DramaMaskPriceRemote = -1;
}
}
private const string modGUID = "MegaPiggy.BuyableDramaMask";
private const string modName = "Buyable Drama Mask";
private const string modVersion = "1.1.0";
private readonly Harmony harmony = new Harmony("MegaPiggy.BuyableDramaMask");
private static BuyableDramaMask Instance;
private static ConfigEntry<int> DramaMaskPriceConfig;
internal static int DramaMaskPriceRemote = -1;
public static byte CurrentVersionByte = 1;
private static ManualLogSource LoggerInstance => ((BaseUnityPlugin)Instance).Logger;
public static List<Item> AllItems => Resources.FindObjectsOfTypeAll<Item>().Concat(Object.FindObjectsByType<Item>((FindObjectsInactive)1, (FindObjectsSortMode)1)).ToList();
public static Item Drama => ((IEnumerable<Item>)AllItems).FirstOrDefault((Func<Item, bool>)((Item item) => ((Object)item).name.Equals("DramaMask")));
public static Item DramaClone { get; private set; }
public static int DramaMaskPriceLocal => DramaMaskPriceConfig.Value;
public static int DramaMaskPrice => (DramaMaskPriceRemote > -1) ? DramaMaskPriceRemote : DramaMaskPriceLocal;
private static bool IsHost => NetworkManager.Singleton.IsHost;
private static ulong LocalClientId => NetworkManager.Singleton.LocalClientId;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
harmony.PatchAll();
DramaMaskPriceConfig = ((BaseUnityPlugin)this).Config.Bind<int>("Prices", "DramaMaskPrice", 30, "Credits needed to buy drama mask");
DramaClone = MakeNonScrap(Drama, DramaMaskPrice);
AddToShop();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin Buyable Drama Mask is loaded with version 1.1.0!");
}
private static Item MakeNonScrap(Item original, int price)
{
Item val = Object.Instantiate<Item>(original);
Object.DontDestroyOnLoad((Object)(object)val);
((Object)val).name = "Buyable" + ((Object)original).name;
val.isScrap = false;
val.creditsWorth = price;
return val;
}
private static TerminalNode CreateInfoNode(string name, string description)
{
TerminalNode val = ScriptableObject.CreateInstance<TerminalNode>();
val.clearPreviousText = true;
((Object)val).name = name + "InfoNode";
val.displayText = description + "\n\n";
return val;
}
private static void AddToShop()
{
Item dramaClone = DramaClone;
int dramaMaskPrice = DramaMaskPrice;
Items.RegisterShopItem(dramaClone, (TerminalNode)null, (TerminalNode)null, CreateInfoNode("DramaMask", "A mask that is not haunted unlike its Tragedy and Comedy counterparts. Wearing it will make other Masked enemies ignore you!"), dramaMaskPrice);
LoggerInstance.LogInfo((object)$"Drama Mask added to Shop for {DramaMaskPrice} credits");
}
private static void UpdateShopItemPrice()
{
DramaClone.creditsWorth = DramaMaskPrice;
Items.UpdateShopItemPrice(DramaClone, DramaMaskPrice);
LoggerInstance.LogInfo((object)$"Drama Mask price updated to {DramaMaskPrice} credits");
}
public static void WriteData(FastBufferWriter writer)
{
((FastBufferWriter)(ref writer)).WriteByte(CurrentVersionByte);
((FastBufferWriter)(ref writer)).WriteBytes(BitConverter.GetBytes(DramaMaskPriceLocal), -1, 0);
}
public static void ReadData(FastBufferReader reader)
{
byte b = default(byte);
((FastBufferReader)(ref reader)).ReadByte(ref b);
if (b == CurrentVersionByte)
{
byte[] value = new byte[4];
((FastBufferReader)(ref reader)).ReadBytes(ref value, 4, 0);
DramaMaskPriceRemote = BitConverter.ToInt32(value, 0);
UpdateShopItemPrice();
LoggerInstance.LogInfo((object)"Host config set successfully");
return;
}
throw new Exception("Invalid version byte");
}
public static void OnRequestSync(ulong clientID, FastBufferReader reader)
{
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
if (!IsHost)
{
return;
}
LoggerInstance.LogInfo((object)("Sending config to client " + clientID));
FastBufferWriter val = default(FastBufferWriter);
((FastBufferWriter)(ref val))..ctor(5, (Allocator)2, 5);
try
{
WriteData(val);
NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("BuyableDramaMask_OnReceiveConfigSync", clientID, val, (NetworkDelivery)2);
}
catch (Exception arg)
{
LoggerInstance.LogError((object)$"Failed to send config: {arg}");
}
finally
{
((FastBufferWriter)(ref val)).Dispose();
}
}
public static void OnReceiveSync(ulong clientID, FastBufferReader reader)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
LoggerInstance.LogInfo((object)"Received config from host");
try
{
ReadData(reader);
}
catch (Exception arg)
{
LoggerInstance.LogError((object)$"Failed to receive config: {arg}");
DramaMaskPriceRemote = -1;
}
}
}
}