using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
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 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: AssemblyCompany("inoyu.MoreSales")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.5.2.0")]
[assembly: AssemblyInformationalVersion("0.5.2+33e1f812c1905615244beb9181fc64ced6aa7c7c")]
[assembly: AssemblyProduct("MoreSales")]
[assembly: AssemblyTitle("inoyu.MoreSales")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.5.2.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.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = 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;
}
}
}
namespace MoreSales
{
[BepInPlugin("inoyu.MoreSales", "MoreSales", "0.5.2")]
public class MoreSales : BaseUnityPlugin
{
internal static MoreSalesConfigs moreSalesConfigs;
public static MoreSales Instance { get; private set; }
internal static ManualLogSource mls { get; private set; }
internal static Harmony? Harmony { get; set; }
private void Awake()
{
mls = ((BaseUnityPlugin)this).Logger;
Instance = this;
moreSalesConfigs = new MoreSalesConfigs(((BaseUnityPlugin)this).Config);
Patch();
mls.LogInfo((object)"inoyu.MoreSales v0.5.2 has loaded!");
}
internal static void Patch()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Expected O, but got Unknown
if (Harmony == null)
{
Harmony = new Harmony("inoyu.MoreSales");
}
mls.LogDebug((object)"Patching...");
Harmony.PatchAll();
mls.LogDebug((object)"Finished patching!");
}
internal static void Unpatch()
{
mls.LogDebug((object)"Unpatching...");
Harmony? harmony = Harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
mls.LogDebug((object)"Finished unpatching!");
}
}
internal class MoreSalesConfigs
{
internal int numberOfItemsInSaleBaseValue = 10;
internal int minSalePercentageBaseValue = 20;
internal int maxSalePercentageBaseValue = 90;
internal ConfigEntry<bool> isAllItemsOnSale;
internal ConfigEntry<int> numberOfItemsInSale;
internal ConfigEntry<int> minSalePercentage;
internal ConfigEntry<int> maxSalePercentage;
internal ConfigEntry<string> header;
internal int actualOfItemsInSale = 10;
public MoreSalesConfigs(ConfigFile cfg)
{
header = cfg.Bind<string>("DiscountPercentageRange", "IMPORTANT", "(\uff3f \uff3f*) Z z z", "SOME ITEMS CAN'T BE ON SALE, THOSE WILL BE IGNORED AND WON'T GO ON SALE!" + Environment.NewLine + "All percentage values will be rounded (by the game) to the nearest ten.");
isAllItemsOnSale = cfg.Bind<bool>("Discounts", "setAllItemsOnSale", false, "[This does not work atm!] This sets all shop Items on sale.");
numberOfItemsInSale = cfg.Bind<int>("Discounts", "numberOfItemsInSale", numberOfItemsInSaleBaseValue, "This sets the number of items in sale.");
minSalePercentage = cfg.Bind<int>("DiscountPercentageRange", "minSalePercentage", minSalePercentageBaseValue, "This sets min discount-percentage of sales for all items that are on sale." + Environment.NewLine + "If min > max, minSalePercentage will be set to maxSalePercentage");
maxSalePercentage = cfg.Bind<int>("DiscountPercentageRange", "maxSalePercentage", maxSalePercentageBaseValue, "This sets max discount-percentage of sales for all items that are on sale.");
fixConfigs();
}
private void fixConfigs()
{
if (maxSalePercentage.Value < 0)
{
maxSalePercentage.Value = 0;
}
else if (maxSalePercentage.Value > 90)
{
maxSalePercentage.Value = 90;
}
if (minSalePercentage.Value < 0)
{
minSalePercentage.Value = 0;
}
else if (minSalePercentage.Value > 90)
{
minSalePercentage.Value = 90;
}
if (minSalePercentage.Value > maxSalePercentage.Value)
{
minSalePercentage.Value = maxSalePercentage.Value;
}
if (numberOfItemsInSale.Value < 0)
{
numberOfItemsInSale.Value = 0;
}
if (isAllItemsOnSale.Value)
{
actualOfItemsInSale = 10000;
}
else
{
actualOfItemsInSale = numberOfItemsInSale.Value;
}
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "inoyu.MoreSales";
public const string PLUGIN_NAME = "MoreSales";
public const string PLUGIN_VERSION = "0.5.2";
}
}
namespace MoreSales.Patches
{
[HarmonyPatch]
public class IncreaseSalesPatch
{
[HarmonyPatch(typeof(Terminal), "SetItemSales")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00dc: Expected O, but got Unknown
//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
//IL_00f1: Expected O, but got Unknown
//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0200: Expected O, but got Unknown
//IL_022a: Unknown result type (might be due to invalid IL or missing references)
//IL_0234: Expected O, but got Unknown
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
for (int i = 0; i < list.Count; i++)
{
if (list[i].opcode == OpCodes.Call && list[i].operand is MethodInfo methodInfo && methodInfo.Name == "Clamp" && methodInfo.DeclaringType == typeof(Mathf) && i > 2 && list[i - 1].opcode == OpCodes.Ldc_I4_5 && list[i - 2].opcode == OpCodes.Ldc_I4_0)
{
list.Insert(i + 2, new CodeInstruction(OpCodes.Ldc_I4_S, (object)MoreSales.moreSalesConfigs.actualOfItemsInSale));
list.Insert(i + 3, new CodeInstruction(OpCodes.Stloc_1, (object)null));
}
}
for (int j = 0; j < list.Count; j++)
{
if (list[j].opcode == OpCodes.Callvirt && list[j].operand is MethodInfo methodInfo2 && methodInfo2.Name == "Next" && methodInfo2.DeclaringType == typeof(Random) && j > 2 && list[j - 1].opcode == OpCodes.Ldloc_S && list[j - 2].opcode == OpCodes.Ldc_I4_0)
{
list.RemoveAt(j - 2);
list.Insert(j - 2, new CodeInstruction(OpCodes.Ldc_I4_S, (object)MoreSales.moreSalesConfigs.minSalePercentage.Value));
list.RemoveAt(j - 1);
list.Insert(j - 1, new CodeInstruction(OpCodes.Ldc_I4_S, (object)MoreSales.moreSalesConfigs.maxSalePercentage.Value));
break;
}
}
return list.AsEnumerable();
}
[HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")]
[HarmonyPostfix]
private static void updateItemSalesOnLobbyJoin()
{
Terminal val = Object.FindObjectOfType<Terminal>();
val.SetItemSales();
}
private static void Debug_LogILCodeAtIndex(List<CodeInstruction> codes, int index)
{
if (index >= 2)
{
MoreSales.mls.LogDebug((object)("i - 2: " + ((object)codes[index - 2]).ToString()));
MoreSales.mls.LogDebug((object)("i - 1: " + ((object)codes[index - 1]).ToString()));
}
MoreSales.mls.LogDebug((object)("i: " + ((object)codes[index]).ToString()));
MoreSales.mls.LogDebug((object)("i + 1: " + ((object)codes[index + 1]).ToString()));
MoreSales.mls.LogDebug((object)("i + 2: " + ((object)codes[index + 2]).ToString()));
MoreSales.mls.LogDebug((object)("i + 3: " + ((object)codes[index + 3]).ToString()));
MoreSales.mls.LogDebug((object)("i + 4: " + ((object)codes[index + 4]).ToString()));
}
private static void Debug_GenerateRandomSales(Terminal terminal)
{
Random random = new Random(StartOfRound.Instance.randomMapSeed + 90);
int num = 999999;
List<int> list = new List<int>();
for (int i = 0; i < terminal.buyableItemsList.Length; i++)
{
list.Add(i);
}
for (int j = 0; j < num; j++)
{
if (list.Count <= 0)
{
break;
}
int num2 = random.Next(0, list.Count);
int i2 = 100 - random.Next(MoreSales.moreSalesConfigs.minSalePercentage.Value, MoreSales.moreSalesConfigs.maxSalePercentage.Value);
i2 = RoundToNearestTen(i2);
MoreSales.mls.LogWarning((object)("num2: " + num2 + " number of list: " + list[num2] + " should be percentage: " + i2));
MoreSales.mls.LogWarning((object)("itemName: " + terminal.buyableItemsList[num2].itemName + " itemSaleP " + terminal.itemSalesPercentages[num2]));
list.RemoveAt(num2);
}
}
private static int RoundToNearestTen(int i)
{
return (int)Math.Round((double)i / 10.0) * 10;
}
}
}