using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using LethalLib;
using LethalLib.Modules;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("bkleach01BuyableShotgun")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("bkleach01BuyableShotgun")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b993f56b-85df-4083-ac88-bb20f338992c")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace bkleach01BuyableShotgun;
public class ChatCommandPatch : BaseUnityPlugin
{
private static Plugin chatClass = new Plugin();
public static Plugin getChatClass()
{
return chatClass;
}
}
[HarmonyPatch(typeof(Items))]
[BepInPlugin("bkleach01.bkleach01BuyableShotgun", "bkleach01BuyableShotgun", "1.0.1")]
public class BuyableShotgunBase : BaseUnityPlugin
{
private const string modGUID = "bkleach01.bkleach01BuyableShotgun";
private const string modName = "bkleach01BuyableShotgun";
private const string modVersion = "1.0.1";
private readonly Harmony harmony = new Harmony("bkleach01.bkleach01BuyableShotgun");
private static BuyableShotgunBase Instance;
public int ShotgunPrice;
public static int NewShotgunPrice;
public int AmmoPrice;
public bool added;
internal static bool isHost;
internal static ManualLogSource mls;
public List<Item> AllItems => Resources.FindObjectsOfTypeAll<Item>().Concat(Object.FindObjectsByType<Item>((FindObjectsInactive)1, (FindObjectsSortMode)1)).ToList();
public Item Shotgun => ((IEnumerable<Item>)AllItems).FirstOrDefault((Func<Item, bool>)((Item item) => ((Object)item).name == "Shotgun"));
public static List<Item> AllItemsStatic => Resources.FindObjectsOfTypeAll<Item>().Concat(Object.FindObjectsByType<Item>((FindObjectsInactive)1, (FindObjectsSortMode)1)).ToList();
public static Item ShotgunStatic => ((IEnumerable<Item>)AllItemsStatic).FirstOrDefault((Func<Item, bool>)((Item item) => ((Object)item).name == "Shotgun"));
public Item Ammo => ((IEnumerable<Item>)AllItems).FirstOrDefault((Func<Item, bool>)((Item item) => ((Object)item).name == "GunAmmo"));
private void Awake()
{
if (Instance == null)
{
Instance = this;
}
mls = Logger.CreateLogSource("bkleach01.bkleach01BuyableShotgun");
harmony.PatchAll(typeof(BuyableShotgunBase));
ShotgunPrice = ((BaseUnityPlugin)this).Config.Bind<int>("Prices", "ShotgunPrice", 600, "Credits needed to buy shotgun").Value;
AmmoPrice = ((BaseUnityPlugin)this).Config.Bind<int>("Prices", "AmmoPrice", 20, "Credits needed to buy shotgun ammo").Value;
SceneManager.sceneLoaded += OnSceneLoaded;
mls.LogInfo((object)"Plugin bkleach01BuyableShotgun is loaded with version 1.0.1!");
}
[HarmonyPatch(typeof(HUDManager), "SubmitChat_performed")]
[HarmonyPrefix]
private static void ChatCommands(HUDManager __instance)
{
isHost = ((NetworkBehaviour)RoundManager.Instance).NetworkManager.IsHost;
string text = __instance.chatTextField.text;
string text2 = "/";
mls.LogInfo((object)text);
if (!text.ToLower().StartsWith(text2.ToLower()))
{
return;
}
string text3 = "Default Title";
string text4 = "Default Body";
if (!isHost)
{
text3 = "Command";
text4 = "Unable to send command since you are not host.";
HUDManager.Instance.DisplayTip(text3, text4, false, false, "LC_Tip1");
return;
}
if (text.ToLower().StartsWith(text2 + "setprice"))
{
text3 = "Price change";
string[] array = text.Split(new char[1] { ' ' });
if (array.Length > 1)
{
try
{
int num = int.Parse(array[1]);
mls.LogInfo((object)("user tried to enter '" + array[1] + "' and passed."));
Items.UpdateShopItemPrice(ShotgunStatic, num);
__instance.chatTextField.text = $"Shotgun price successfully set to {num}.";
return;
}
catch (FormatException)
{
mls.LogInfo((object)("user tried to enter '" + array[1] + "', which is not an int."));
}
}
}
__instance.chatTextField.text = "";
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
if (added)
{
return;
}
Scene val = scene;
if (((Scene)(ref val)).name == "MainMenu")
{
added = true;
try
{
Items.RemoveShopItem(Shotgun);
}
catch (FormatException)
{
mls.LogInfo((object)"Shotgun was not in the store");
}
Items.RegisterShopItem(Shotgun, ShotgunPrice);
Items.UpdateShopItemPrice(Shotgun, 600);
Items.RegisterShopItem(Ammo, AmmoPrice);
Items.UpdateShopItemPrice(Ammo, 20);
}
}
}