using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using DiscountAlert;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("DiscountAlert")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A template for Lethal Company")]
[assembly: AssemblyFileVersion("2.3.0.0")]
[assembly: AssemblyInformationalVersion("2.3.0.0")]
[assembly: AssemblyProduct("DiscountAlert")]
[assembly: AssemblyTitle("DiscountAlert")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.3.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[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;
}
}
}
[HarmonyPatch(typeof(StartMatchLever))]
public class StartMatchLever_Patches
{
private static string priceUpColor = Plugin.Instance.PRICE_UP_COLOR;
private static string priceDownColor = Plugin.Instance.PRICE_DOWN_COLOR;
private static string noDiscountColor = Plugin.Instance.NO_DISCOUNT_COLOR;
private static string noDiscountText = Plugin.Instance.noDiscountText.Value;
private static string titleColor = Plugin.Instance.TITLE_COLOR;
private static string titleText = Plugin.Instance.titleText.Value;
private static int delayAfterLeverIsPulled = Plugin.Instance.delayAfterLeverIsPulled.Value;
private static bool colorsEnabled = Plugin.Instance.colorsEnabled.Value;
private static bool alertEnabledWhenNoDiscounts = Plugin.Instance.alertEnabledWhenNoDiscounts.Value;
public static bool playerAlerted = false;
public static int counter = 0;
[HarmonyPatch("PlayLeverPullEffectsClientRpc")]
[HarmonyPostfix]
public static void PlayLeverPullEffectsClientRpcPatch()
{
playerAlerted = false;
counter++;
if (StartOfRound.Instance.inShipPhase && !playerAlerted && counter == 1)
{
playerAlerted = true;
((MonoBehaviour)HUDManager.Instance).StartCoroutine(DisplayAlert());
}
else if (counter > 1)
{
counter = 0;
}
}
private static IEnumerator DisplayAlert()
{
yield return (object)new WaitForSeconds((float)delayAfterLeverIsPulled);
Debug.Log((object)"Displaying alert");
StringBuilder discount_list = new StringBuilder();
for (int i = 0; i < HUDManager.Instance.terminalScript.buyableItemsList.Length; i++)
{
if (HUDManager.Instance.terminalScript.itemSalesPercentages[i] != 100)
{
if (HUDManager.Instance.terminalScript.itemSalesPercentages[i] < 0)
{
discount_list.Append("\n" + ((priceUpColor != null) ? ("<color=" + priceUpColor + ">* ") : "* ") + HUDManager.Instance.terminalScript.buyableItemsList[i].itemName + $" ${(float)HUDManager.Instance.terminalScript.buyableItemsList[i].creditsWorth * (1f - (float)HUDManager.Instance.terminalScript.itemSalesPercentages[i] / 100f)} " + string.Format("({0}% UP!){1}", Math.Abs(HUDManager.Instance.terminalScript.itemSalesPercentages[i]), (priceUpColor != null) ? "</color>" : ""));
}
else if (HUDManager.Instance.terminalScript.itemSalesPercentages[i] > 0)
{
discount_list.Append("\n" + ((priceDownColor != null) ? ("<color=" + priceDownColor + ">* ") : "* ") + HUDManager.Instance.terminalScript.buyableItemsList[i].itemName + $" ${(float)HUDManager.Instance.terminalScript.buyableItemsList[i].creditsWorth * (float)HUDManager.Instance.terminalScript.itemSalesPercentages[i] / 100f} " + string.Format("({0}% OFF!){1}", 100 - HUDManager.Instance.terminalScript.itemSalesPercentages[i], (priceDownColor != null) ? "</color>" : ""));
}
}
}
if ((!(discount_list.ToString() == "") && discount_list != null) || alertEnabledWhenNoDiscounts)
{
if ((discount_list.ToString() == "" || discount_list == null) && alertEnabledWhenNoDiscounts)
{
discount_list.Append(((noDiscountColor != null) ? ("<color=" + noDiscountColor + "> ") : " ") + noDiscountText + ((noDiscountColor != null) ? "</color>" : ""));
}
HUDManager.Instance.DisplayTip(((titleColor != null) ? ("<color=" + titleColor + "> ") : " ") + titleText + ((titleColor != null) ? "</color>" : ""), discount_list.ToString(), false, false, "LC_Tip1");
}
}
}
namespace DiscountAlert
{
[BepInPlugin("discount.alert", "DiscountAlert", "2.3.0.0")]
public class Plugin : BaseUnityPlugin
{
private const string modGUID = "discount.alert";
private const string modName = "DiscountAlert";
private const string modVersion = "2.3.0.0";
public ConfigEntry<string> priceUpColor;
public ConfigEntry<string> priceDownColor;
public ConfigEntry<string> noDiscountColor;
public ConfigEntry<string> noDiscountText;
public ConfigEntry<string> titleColor;
public ConfigEntry<string> titleText;
public ConfigEntry<int> delayAfterLeverIsPulled;
public ConfigEntry<bool> colorsEnabled;
public ConfigEntry<bool> alertEnabledWhenNoDiscounts;
public string PRICE_UP_COLOR;
public string PRICE_DOWN_COLOR;
public string NO_DISCOUNT_COLOR;
public string TITLE_COLOR;
private readonly Harmony harmony = new Harmony("discount.alert");
public static Plugin? Instance;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
priceUpColor = ((BaseUnityPlugin)this).Config.Bind<string>("Colors", "PriceUpColor", "#990000", "Text color when the price goes up (currently only possible with other mods)");
priceDownColor = ((BaseUnityPlugin)this).Config.Bind<string>("Colors", "PriceDownColor", "#008000", "Text color when the price goes down");
delayAfterLeverIsPulled = ((BaseUnityPlugin)this).Config.Bind<int>("Alert", "DelayAfterLeverIsPulled", 4, "Number of seconds to wait after the \"Land ship\" or \"Start Game\" lever is pulled before showing the alert.");
colorsEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Alert", "ColorsEnabled", true, "Enable or disable text colors");
noDiscountColor = ((BaseUnityPlugin)this).Config.Bind<string>("Colors", "NoDiscountColor", "", "Text color when there are no discounts");
titleColor = ((BaseUnityPlugin)this).Config.Bind<string>("Colors", "TitleColor", "", "Text color for the alert's title");
titleText = ((BaseUnityPlugin)this).Config.Bind<string>("Alert", "TitleText", "Today's discounts", "Alert title text");
noDiscountText = ((BaseUnityPlugin)this).Config.Bind<string>("Alert", "NoDiscountText", "None :( \n Check back tomorrow!", "Alert text when there are no discounts");
alertEnabledWhenNoDiscounts = ((BaseUnityPlugin)this).Config.Bind<bool>("Alert", "AlertEnabledWhenNoDiscounts", true, "Show alert when there are no discounts");
if (!IsValidHexCode(priceUpColor.Value))
{
PRICE_UP_COLOR = null;
}
else
{
PRICE_UP_COLOR = priceUpColor.Value;
}
if (!IsValidHexCode(priceDownColor.Value))
{
PRICE_DOWN_COLOR = null;
}
else
{
PRICE_DOWN_COLOR = priceDownColor.Value;
}
if (!IsValidHexCode(noDiscountColor.Value))
{
NO_DISCOUNT_COLOR = null;
}
else
{
NO_DISCOUNT_COLOR = noDiscountColor.Value;
}
if (!IsValidHexCode(titleColor.Value))
{
TITLE_COLOR = null;
}
else
{
TITLE_COLOR = titleColor.Value;
}
if (!colorsEnabled.Value)
{
PRICE_UP_COLOR = null;
PRICE_DOWN_COLOR = null;
NO_DISCOUNT_COLOR = null;
TITLE_COLOR = null;
}
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin discount.alert is loaded!");
harmony.PatchAll();
}
public static bool IsValidHexCode(string hexCode)
{
string pattern = "^#?([0-9A-Fa-f]{3}){1,2}$";
return Regex.IsMatch(hexCode, pattern);
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}