using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GuysNight.LethalCompanyMod.BalancedItems.Containers;
using GuysNight.LethalCompanyMod.BalancedItems.Models.Items;
using GuysNight.LethalCompanyMod.BalancedItems.Models.Moons;
using GuysNight.LethalCompanyMod.BalancedItems.Models.Terminal;
using GuysNight.LethalCompanyMod.BalancedItems.Utilities;
using HarmonyLib;
using TMPro;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("GuysNight.LethalCompanyMod.BalancedItems")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.6.0.0")]
[assembly: AssemblyInformationalVersion("1.6.0+14dd9d7cd93005afa09f87f9a93bd845346a4499")]
[assembly: AssemblyProduct("GuysNight.LethalCompanyMod.BalancedItems")]
[assembly: AssemblyTitle("GuysNight.LethalCompanyMod.BalancedItems")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.6.0.0")]
[module: UnverifiableCode]
namespace GuysNight.LethalCompanyMod.BalancedItems
{
internal static class Constants
{
internal const string ConfigSectionHeaderToggles = "Feature Toggles";
internal const string ConfigKeyToggleAverageSellValues = "EnableAverageSellValueOverrides";
internal const string ConfigKeyToggleSellableEquipment = "EnableSellingEquipment";
internal const string ConfigKeyToggleMoonRarity = "EnableMoonRarityOverrides";
internal const string ConfigKeyToggleTerminalPurchasePrice = "EnableTerminalPurchasePriceOverrides";
internal const string ConfigKeyToggleWeights = "EnableWeightOverrides";
internal const string ConfigSectionHeaderAverageSellValues = "Average Sell Values";
internal const string ConfigSectionHeaderMoonRarity = "Rarities for {0}";
internal const string ConfigSectionHeaderTerminalPurchasePrice = "Terminal Item Purchase Prices";
internal const string ConfigSectionHeaderWeight = "Weight";
internal const string ConfigDescriptionAverageSellValues = "The average sell value for the '{0}' item. The default vanilla value is '{1}'.";
internal const string ConfigDescriptionMoonRarity = "The rarity for the '{0}' item. The default vanilla value is '{1}'.";
internal const string ConfigDescriptionTerminalPurchasePrice = "The purchase price for the '{0}' item in the terminal. The default vanilla value is '{1}'.";
internal const string ConfigDescriptionWeight = "The weight for the '{0}' item. The default vanilla value is '{1}'.";
internal const double SellValueVariance = 0.2;
}
[BepInPlugin("GuysNight.LethalCompanyMod.BalancedItems", "GuysNight.LethalCompanyMod.BalancedItems", "1.6.0")]
public class Plugin : BaseUnityPlugin
{
private void Awake()
{
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Expected O, but got Unknown
SharedComponents.Logger = ((BaseUnityPlugin)this).Logger;
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
SharedComponents.Logger.LogInfo((object)"Plugin GuysNight.LethalCompanyMod.BalancedItems is loaded!");
SharedComponents.ConfigFile = new ConfigFile(Path.Combine(Paths.ConfigPath, "GuysNight.LethalCompanyMod.BalancedItems.cfg"), true)
{
SaveOnConfigSet = false
};
SharedComponents.ConfigFile.Bind<bool>("Feature Toggles", "EnableAverageSellValueOverrides", true, "Whether or not your specified average sell value overrides should be applied. If set to false, vanilla values will be used. Changes to this value are reflected only when new items are spawned.");
SharedComponents.ConfigFile.Bind<bool>("Feature Toggles", "EnableSellingEquipment", true, "Whether or not you want your equipment to sell for the average value of the item. If set to false, equipment will sell for 0 credits. Changes to this value are reflected every time you sell items to the company.");
SharedComponents.ConfigFile.Bind<bool>("Feature Toggles", "EnableMoonRarityOverrides", true, "Whether or not your specified moon rarity overrides should be applied. If set to false, vanilla values will be used. Changes to this value are reflected at the start of each day.");
SharedComponents.ConfigFile.Bind<bool>("Feature Toggles", "EnableTerminalPurchasePriceOverrides", true, "Whether or not your specified terminal item price overrides should be applied. If set to false, vanilla values will be used. Changes to this value are reflected every time you begin using the terminal.");
SharedComponents.ConfigFile.Bind<bool>("Feature Toggles", "EnableWeightOverrides", true, "Whether or not your specified weight overrides should be applied. If set to false, vanilla values will be used. Changes to this value are reflected only when new items are spawned, or when restarting your session.");
SharedComponents.ConfigFile.Save();
}
}
internal static class SharedComponents
{
internal static ManualLogSource Logger { get; set; }
internal static ConfigFile ConfigFile { get; set; }
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "GuysNight.LethalCompanyMod.BalancedItems";
public const string PLUGIN_NAME = "GuysNight.LethalCompanyMod.BalancedItems";
public const string PLUGIN_VERSION = "1.6.0";
}
}
namespace GuysNight.LethalCompanyMod.BalancedItems.Utilities
{
public static class ConfigUtilities
{
private static readonly char[] InvalidConfigChars = new char[8] { '=', '\n', '\t', '\\', '"', '\'', '[', ']' };
private static readonly string Pattern = "[" + Regex.Escape(new string(InvalidConfigChars)).Replace("]", "\\]") + "]";
private static readonly Regex InvalidConfigCharsRegex = new Regex(Pattern, RegexOptions.IgnoreCase | RegexOptions.Compiled);
public static string SanitizeConfigEntry(string rawEntry)
{
return InvalidConfigCharsRegex.Replace(rawEntry, "_");
}
internal static ItemProperties SyncConfigForItemOverrides(Item gameItem)
{
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Expected O, but got Unknown
//IL_0167: Unknown result type (might be due to invalid IL or missing references)
//IL_0171: Expected O, but got Unknown
ItemProperties itemProperties = ItemsContainer.Items[((Object)gameItem).name];
ItemProperties itemProperties2 = itemProperties;
if (itemProperties2.VanillaItemValues == null)
{
VanillaItemValues vanillaItemValues2 = (itemProperties2.VanillaItemValues = new VanillaItemValues(gameItem.minValue, gameItem.maxValue, gameItem.weight));
}
itemProperties.OverrideItemValues.Weight = SharedComponents.ConfigFile.Bind<float>(SanitizeConfigEntry("Weight"), SanitizeConfigEntry(((Object)gameItem).name), NumericUtilities.DenormalizeWeight((Math.Abs(itemProperties.OverrideItemValues.Weight - 0f) > 0f) ? itemProperties.OverrideItemValues.Weight : itemProperties.VanillaItemValues.Weight), new ConfigDescription($"The weight for the '{gameItem.itemName}' item. The default vanilla value is '{NumericUtilities.DenormalizeWeight(itemProperties.VanillaItemValues.Weight)}'.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1000f), Array.Empty<object>())).Value;
ushort num = (ushort)Math.Round(new int[2] { gameItem.minValue, gameItem.maxValue }.Average(), MidpointRounding.AwayFromZero);
itemProperties.OverrideItemValues.AverageValue = SharedComponents.ConfigFile.Bind<ushort>(SanitizeConfigEntry("Average Sell Values"), SanitizeConfigEntry(((Object)gameItem).name), (itemProperties.OverrideItemValues.AverageValue != 0) ? itemProperties.OverrideItemValues.AverageValue : num, new ConfigDescription($"The average sell value for the '{gameItem.itemName}' item. The default vanilla value is '{num}'.", (AcceptableValueBase)(object)new AcceptableValueRange<ushort>((ushort)0, ushort.MaxValue), Array.Empty<object>())).Value;
SharedComponents.Logger.LogDebug((object)("Finish adding config entries and setting override values for '" + ((Object)gameItem).name + "' to have " + $"average sell value = '{itemProperties.OverrideItemValues.AverageValue}', " + $"weight = '{NumericUtilities.DenormalizeWeight(itemProperties.OverrideItemValues.Weight)}'"));
ItemsContainer.Items[((Object)gameItem).name] = itemProperties;
return new ItemProperties(itemProperties.VanillaItemValues, itemProperties.OverrideItemValues);
}
internal static TerminalItemProperties SyncConfigForTerminalItemOverrides(Item gameItem)
{
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: Expected O, but got Unknown
TerminalItemProperties terminalItemProperties = TerminalItemsContainer.TerminalItems[((Object)gameItem).name];
TerminalItemProperties terminalItemProperties2 = terminalItemProperties;
if (terminalItemProperties2.VanillaTerminalItemValues == null)
{
VanillaTerminalItemValues vanillaTerminalItemValues2 = (terminalItemProperties2.VanillaTerminalItemValues = new VanillaTerminalItemValues(gameItem.creditsWorth));
}
terminalItemProperties.OverrideTerminalItemValues.PurchasePrice = SharedComponents.ConfigFile.Bind<int>(SanitizeConfigEntry("Terminal Item Purchase Prices"), SanitizeConfigEntry(((Object)gameItem).name), (terminalItemProperties.OverrideTerminalItemValues.PurchasePrice != 0) ? terminalItemProperties.OverrideTerminalItemValues.PurchasePrice : terminalItemProperties.VanillaTerminalItemValues.PurchasePrice, new ConfigDescription($"The purchase price for the '{gameItem.itemName}' item in the terminal. The default vanilla value is '{terminalItemProperties.VanillaTerminalItemValues.PurchasePrice}'.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 65535), Array.Empty<object>())).Value;
return new TerminalItemProperties(terminalItemProperties.VanillaTerminalItemValues, terminalItemProperties.OverrideTerminalItemValues);
}
internal static int SyncConfigForMoonItemRarity(SelectableLevel moon, SpawnableItemWithRarity gameItemWithRarity)
{
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Expected O, but got Unknown
string text = SanitizeConfigEntry($"Rarities for {moon.PlanetName}");
string text2 = SanitizeConfigEntry(((Object)gameItemWithRarity.spawnableItem).name);
ConfigEntry<int> val = default(ConfigEntry<int>);
if (SharedComponents.ConfigFile.TryGetEntry<int>(text, text2, ref val))
{
return val.Value;
}
int rarity = gameItemWithRarity.rarity;
SharedComponents.ConfigFile.Bind<int>(text, text2, rarity, new ConfigDescription($"The rarity for the '{gameItemWithRarity.spawnableItem.itemName}' item. The default vanilla value is '{rarity}'.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
SharedComponents.Logger.LogDebug((object)$"Finish adding config entry for '{((Object)gameItemWithRarity.spawnableItem).name}' to have rarity '{rarity}' on moon '{moon.PlanetName}'");
return rarity;
}
internal static int? GetItemRarityForMoon(SelectableLevel moon, SpawnableItemWithRarity gameItemWithRarity)
{
string text = SanitizeConfigEntry($"Rarities for {moon.PlanetName}");
string text2 = SanitizeConfigEntry(((Object)gameItemWithRarity.spawnableItem).name);
ConfigEntry<int> val = default(ConfigEntry<int>);
if (SharedComponents.ConfigFile.TryGetEntry<int>(text, text2, ref val))
{
return val.Value;
}
return null;
}
}
public static class NumericUtilities
{
public static float NormalizeWeight(float denormalizedWeight)
{
return (float)Math.Round(denormalizedWeight / 100f + 1f, 3, MidpointRounding.AwayFromZero);
}
public static float DenormalizeWeight(float normalizedWeight)
{
return (float)Math.Round((normalizedWeight - 1f) * 100f, 1, MidpointRounding.AwayFromZero);
}
}
}
namespace GuysNight.LethalCompanyMod.BalancedItems.Patches
{
[HarmonyPatch(typeof(DepositItemsDesk))]
public class DepositItemsDeskPatches
{
[HarmonyPatch("SellItemsOnServer")]
[HarmonyPrefix]
public static void MakeEquipmentOnDeskSellable(DepositItemsDesk __instance)
{
SharedComponents.ConfigFile.Reload();
bool flag = true;
ConfigEntry<bool> val = default(ConfigEntry<bool>);
if (SharedComponents.ConfigFile.TryGetEntry<bool>("Feature Toggles", "EnableSellingEquipment", ref val))
{
flag = val.Value;
SharedComponents.Logger.LogDebug((object)$"Successfully retrieved sellable equipment feature toggle. Value is '{flag}'");
}
else
{
SharedComponents.Logger.LogWarning((object)"Could not retrieve sellable equipment feature toggle from config. Assuming it was set to true.");
}
if (!flag)
{
return;
}
foreach (GrabbableObject item in __instance.itemsOnCounter)
{
if (!ItemsContainer.Items.TryGetValue(((Object)item.itemProperties).name, out var value))
{
SharedComponents.Logger.LogWarning((object)("Could not retrieve any item entries for '" + ((Object)item.itemProperties).name + "' Unable to make that equipment item sellable."));
}
else if (!item.itemProperties.isScrap)
{
SharedComponents.Logger.LogInfo((object)$"Setting '{((Object)item.itemProperties).name}' to be sellable equipment for '{value.OverrideItemValues.AverageValue}' credits.");
item.itemProperties.isScrap = true;
item.scrapValue = value.OverrideItemValues.AverageValue;
}
}
}
}
[HarmonyPatch(typeof(GrabbableObject))]
public class GrabbableObjectPatches
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
public static void ChangeItemWeight(GrabbableObject __instance)
{
if (__instance == null)
{
SharedComponents.Logger.LogWarning((object)"__instance is null in 'ChangeItemWeight'. Aborting.");
return;
}
SharedComponents.Logger.LogDebug((object)("item.itemProperties.name is '" + ((Object)__instance.itemProperties).name + "'"));
SharedComponents.Logger.LogDebug((object)$"item.itemProperties.weight is '{NumericUtilities.DenormalizeWeight(__instance.itemProperties.weight)}'");
SharedComponents.Logger.LogDebug((object)$"item.itemProperties.minValue is '{__instance.itemProperties.minValue}'");
SharedComponents.Logger.LogDebug((object)$"item.itemProperties.maxValue is '{__instance.itemProperties.maxValue}'");
if (!ItemsContainer.Items.TryGetValue(((Object)__instance.itemProperties).name, out var value))
{
SharedComponents.Logger.LogWarning((object)("No item entry exists for item '" + ((Object)__instance.itemProperties).name + "'. Making no changes to item weight."));
return;
}
bool flag = true;
ConfigEntry<bool> val = default(ConfigEntry<bool>);
if (SharedComponents.ConfigFile.TryGetEntry<bool>("Feature Toggles", "EnableWeightOverrides", ref val))
{
flag = val.Value;
SharedComponents.Logger.LogDebug((object)$"Successfully retrieved weight override feature toggle. Value is '{flag}'");
}
else
{
SharedComponents.Logger.LogWarning((object)"Could not retrieve weight override feature toggle from config. Assuming it was set to true.");
}
if (flag)
{
SharedComponents.ConfigFile.Reload();
SharedComponents.Logger.LogDebug((object)("Begin adding config entries and setting override values for '" + ((Object)__instance.itemProperties).name + "'"));
value = ConfigUtilities.SyncConfigForItemOverrides(__instance.itemProperties);
UpdateItemWeight(__instance, value.OverrideItemValues.Weight);
}
else
{
if (value.VanillaItemValues == null)
{
SharedComponents.Logger.LogWarning((object)("Vanilla values for item '" + ((Object)__instance.itemProperties).name + "' is null. Assuming current values are vanilla."));
ItemsContainer.SetVanillaValuesForItem(((Object)__instance.itemProperties).name, new VanillaItemValues(__instance.itemProperties.minValue, __instance.itemProperties.maxValue, __instance.itemProperties.weight));
value = ItemsContainer.Items[((Object)__instance.itemProperties).name];
}
UpdateItemWeight(__instance, value.VanillaItemValues.Weight);
}
SharedComponents.ConfigFile.Save();
}
private static void UpdateItemWeight(GrabbableObject item, float weight)
{
item.itemProperties.weight = weight;
SharedComponents.Logger.LogInfo((object)$"Successfully set weight for '{((Object)item.itemProperties).name}' to be '{NumericUtilities.DenormalizeWeight(weight)}'");
}
}
[HarmonyPatch(typeof(HUDManager))]
public class HUDManagerPatches
{
private static float? _originalFontSize;
[HarmonyPatch("Update")]
[HarmonyPostfix]
public static void DisplayCorrectCarryWeight(HUDManager __instance)
{
if (__instance == null)
{
SharedComponents.Logger.LogWarning((object)"__instance is null in 'DisplayCorrectCarryWeight'. Aborting.");
return;
}
if (GameNetworkManager.Instance?.localPlayerController == null)
{
SharedComponents.Logger.LogWarning((object)"Instance or localPlayerController is null in 'DisplayCorrectCarryWeight'. Aborting.");
return;
}
float num = (float)Math.Round(Math.Clamp(GameNetworkManager.Instance.localPlayerController.carryWeight - 1f, 0f, 100f) * 100f);
((TMP_Text)__instance.weightCounter).text = $"{num} lb";
}
[HarmonyPatch("Update")]
[HarmonyPrefix]
public static void StoreVariablesBeforeUpdateChanges(HUDManager __instance)
{
if (!_originalFontSize.HasValue)
{
SharedComponents.Logger.LogDebug((object)$"Original totalValueText.fontSize was '{((TMP_Text)__instance.totalValueText).fontSize}'");
_originalFontSize = ((TMP_Text)__instance.totalValueText).fontSize;
}
}
[HarmonyPatch("Update")]
[HarmonyPostfix]
public static void DisplayFormattedTotalScrapValue(HUDManager __instance)
{
if (__instance.totalScrapScanned >= 1000000)
{
((TMP_Text)__instance.totalValueText).fontSize = 12f;
}
else if (__instance.totalScrapScanned >= 100000)
{
((TMP_Text)__instance.totalValueText).fontSize = 14f;
}
else if (__instance.totalScrapScanned >= 10000)
{
((TMP_Text)__instance.totalValueText).fontSize = 16f;
}
else if (__instance.totalScrapScanned >= 1000)
{
((TMP_Text)__instance.totalValueText).fontSize = 18f;
}
else
{
((TMP_Text)__instance.totalValueText).fontSize = _originalFontSize.Value;
}
((TMP_Text)__instance.totalValueText).text = $"${__instance.totalScrapScanned:N0}";
}
}
[HarmonyPatch(typeof(LungProp))]
public class LungPropPatches
{
private static readonly Random RandomGenerator = new Random();
[HarmonyPatch("DisconnectFromMachinery")]
[HarmonyPrefix]
public static void SetApparatusValue(LungProp __instance)
{
if (!ItemsContainer.Items.TryGetValue(((Object)((GrabbableObject)__instance).itemProperties).name, out var value))
{
SharedComponents.Logger.LogWarning((object)("No item entry exists for item '" + ((Object)((GrabbableObject)__instance).itemProperties).name + "'. Making no changes to item value."));
return;
}
bool flag = true;
ConfigEntry<bool> val = default(ConfigEntry<bool>);
if (SharedComponents.ConfigFile.TryGetEntry<bool>("Feature Toggles", "EnableAverageSellValueOverrides", ref val))
{
flag = val.Value;
SharedComponents.Logger.LogDebug((object)$"Successfully retrieved sell value override feature toggle. Value is '{flag}'");
}
else
{
SharedComponents.Logger.LogWarning((object)"Could not retrieve sell value override feature toggle from config. Assuming it was set to true.");
}
if (flag)
{
int scrapValue = RandomGenerator.Next(value.OverrideItemValues.MinValue, value.OverrideItemValues.MaxValue + 1);
((GrabbableObject)__instance).SetScrapValue(scrapValue);
}
}
}
[HarmonyPatch(typeof(RoundManager))]
public class RoundManagerPatches
{
[HarmonyPrefix]
[HarmonyPatch("SpawnScrapInLevel")]
public static void SpawnScrapInLevelPrefix(RoundManager __instance)
{
if (__instance == null)
{
SharedComponents.Logger.LogWarning((object)"__instance is null in 'SpawnScrapInLevelPrefix'. Aborting.");
return;
}
SharedComponents.ConfigFile.Reload();
foreach (SpawnableItemWithRarity item in __instance.currentLevel.spawnableScrap)
{
SharedComponents.Logger.LogDebug((object)("spawnableScrap.name is '" + ((Object)item.spawnableItem).name + "'"));
SharedComponents.Logger.LogDebug((object)("spawnableScrap.itemName is '" + item.spawnableItem.itemName + "'"));
SharedComponents.Logger.LogDebug((object)$"spawnableScrap.minValue is '{item.spawnableItem.minValue}'");
SharedComponents.Logger.LogDebug((object)$"spawnableScrap.maxValue is '{item.spawnableItem.maxValue}'");
ChangeScrapRarity(__instance.currentLevel, item);
ChangeScrapValue(item.spawnableItem);
}
SharedComponents.ConfigFile.Save();
}
private static void ChangeScrapRarity(SelectableLevel level, SpawnableItemWithRarity spawnableScrap)
{
if (!MoonsContainer.Moons.TryGetValue(((Object)level).name, out var value))
{
SharedComponents.Logger.LogWarning((object)("No moon entry exists for moon '" + ((Object)level).name + "'. Making no changes to item rarity."));
return;
}
bool flag = true;
ConfigEntry<bool> val = default(ConfigEntry<bool>);
if (SharedComponents.ConfigFile.TryGetEntry<bool>("Feature Toggles", "EnableMoonRarityOverrides", ref val))
{
flag = val.Value;
SharedComponents.Logger.LogDebug((object)$"Successfully retrieved moon rarity override feature toggle. Value is '{flag}'");
}
else
{
SharedComponents.Logger.LogWarning((object)"Could not retrieve moon rarity override feature toggle from config. Assuming it was set to true.");
}
if (flag)
{
int? itemRarityForMoon = ConfigUtilities.GetItemRarityForMoon(level, spawnableScrap);
if (itemRarityForMoon.HasValue)
{
value.OverrideMoonRarities.MoonRarityValues[((Object)spawnableScrap.spawnableItem).name] = itemRarityForMoon.Value;
MoonsContainer.Moons[((Object)level).name] = value;
UpdateItemRarityOnMoon(((Object)level).name, spawnableScrap, value.OverrideMoonRarities.MoonRarityValues[((Object)spawnableScrap.spawnableItem).name]);
}
}
else
{
UpdateItemRarityOnMoon(((Object)level).name, spawnableScrap, value.VanillaMoonRarities.MoonRarityValues[((Object)spawnableScrap.spawnableItem).name]);
}
}
private static void UpdateItemRarityOnMoon(string moonName, SpawnableItemWithRarity item, int rarity)
{
item.rarity = rarity;
SharedComponents.Logger.LogInfo((object)$"Successfully set rarity to be '{rarity}' for item '{((Object)item.spawnableItem).name}' on '{moonName}'.");
}
private static void ChangeScrapValue(Item spawnableScrap)
{
if (!ItemsContainer.Items.TryGetValue(((Object)spawnableScrap).name, out var value))
{
SharedComponents.Logger.LogWarning((object)("No item entry exists for item '" + ((Object)spawnableScrap).name + "'. Making no changes to item value."));
return;
}
bool flag = true;
ConfigEntry<bool> val = default(ConfigEntry<bool>);
if (SharedComponents.ConfigFile.TryGetEntry<bool>("Feature Toggles", "EnableAverageSellValueOverrides", ref val))
{
flag = val.Value;
SharedComponents.Logger.LogDebug((object)$"Successfully retrieved sell value override feature toggle. Value is '{flag}'");
}
else
{
SharedComponents.Logger.LogWarning((object)"Could not retrieve sell value override feature toggle from config. Assuming it was set to true.");
}
if (flag)
{
value = ConfigUtilities.SyncConfigForItemOverrides(spawnableScrap);
UpdateItemValue(spawnableScrap, value.OverrideItemValues.MinValue, value.OverrideItemValues.MaxValue);
}
else
{
UpdateItemValue(spawnableScrap, value.VanillaItemValues.MinValue, value.VanillaItemValues.MaxValue);
}
}
private static void UpdateItemValue(Item item, int minValue, int maxValue)
{
item.minValue = minValue;
item.maxValue = maxValue;
SharedComponents.Logger.LogInfo((object)$"Successfully set sell value range for '{((Object)item).name}' to be '{minValue}' - '{maxValue}'");
}
}
[HarmonyPatch(typeof(StartOfRound))]
public class StartOfRoundPatches
{
[HarmonyPrefix]
[HarmonyPatch("Start")]
public static void InitializeAllLevelsAndSpawnableScrap(StartOfRound __instance)
{
if (__instance == null)
{
SharedComponents.Logger.LogWarning((object)"__instance is null in 'InitializeAllLevelsAndSpawnableScrap'. Aborting.");
return;
}
SharedComponents.ConfigFile.Reload();
InitializeAllItems(__instance);
InitializeAllLevels(__instance);
SharedComponents.ConfigFile.Save();
}
private static void InitializeAllItems(StartOfRound startOfRoundInstance)
{
SharedComponents.Logger.LogDebug((object)$"Found {startOfRoundInstance.allItemsList.itemsList.Count} items in allItemsList.");
foreach (Item item in startOfRoundInstance.allItemsList.itemsList.OrderBy((Item i) => i.itemName))
{
SharedComponents.Logger.LogDebug((object)("allItemsListEntry: name = '" + ((Object)item).name + "', itemName = '" + item.itemName + "', " + $"weight = '{item.weight}', " + $"minValue = '{item.minValue}', " + $"maxValue = '{item.maxValue}', " + $"isScrap = '{item.isScrap}'"));
ItemsContainer.SetVanillaValuesForItem(((Object)item).name, new VanillaItemValues(item.minValue, item.maxValue, item.weight));
ConfigUtilities.SyncConfigForItemOverrides(item);
if (((Object)item).name == "Key")
{
item.isScrap = true;
}
}
}
private static void InitializeAllLevels(StartOfRound startOfRoundInstance)
{
SelectableLevel[] levels = startOfRoundInstance.levels;
foreach (SelectableLevel val in levels)
{
VanillaMoonRarities vanillaMoonRarities = new VanillaMoonRarities(((Object)val).name);
OverrideMoonRarities overrideMoonRarities = new OverrideMoonRarities(((Object)val).name);
foreach (SpawnableItemWithRarity item in val.spawnableScrap.OrderBy((SpawnableItemWithRarity s) => s.spawnableItem.itemName))
{
vanillaMoonRarities.MoonRarityValues.TryAdd(((Object)item.spawnableItem).name, item.rarity);
int value = ConfigUtilities.SyncConfigForMoonItemRarity(val, item);
overrideMoonRarities.MoonRarityValues.TryAdd(((Object)item.spawnableItem).name, value);
SharedComponents.Logger.LogDebug((object)$"On level '{((Object)val).name}' we found a spawnable scrap item with name '{((Object)item.spawnableItem).name}', itemName '{item.spawnableItem.itemName}', weight '{NumericUtilities.DenormalizeWeight(item.spawnableItem.weight)}' pounds, rarity '{item.rarity}', min value '{item.spawnableItem.minValue}', and max value '{item.spawnableItem.maxValue}'");
}
MoonsContainer.Moons.TryAdd(((Object)val).name, new MoonProperties(vanillaMoonRarities, overrideMoonRarities));
}
}
}
[HarmonyPatch(typeof(Terminal))]
public class TerminalPatches
{
[HarmonyPatch("Start")]
[HarmonyPrefix]
public static void InitializeTerminalItems(Terminal __instance)
{
Item[] buyableItemsList = __instance.buyableItemsList;
foreach (Item val in buyableItemsList)
{
TerminalItemsContainer.SetVanillaValuesForTerminalItem(((Object)val).name, new VanillaTerminalItemValues(val.creditsWorth));
}
}
[HarmonyPatch("BeginUsingTerminal")]
[HarmonyPrefix]
public static void SetPricesInTerminal(Terminal __instance)
{
SharedComponents.ConfigFile.Reload();
bool flag = true;
ConfigEntry<bool> val = default(ConfigEntry<bool>);
if (SharedComponents.ConfigFile.TryGetEntry<bool>("Feature Toggles", "EnableTerminalPurchasePriceOverrides", ref val))
{
flag = val.Value;
SharedComponents.Logger.LogDebug((object)$"Successfully retrieved terminal purchase price override feature toggle. Value is '{flag}'");
}
else
{
SharedComponents.Logger.LogWarning((object)"Could not retrieve terminal purchase price override feature toggle from config. Assuming it was set to true.");
}
Item[] buyableItemsList = __instance.buyableItemsList;
foreach (Item val2 in buyableItemsList)
{
TerminalItemsContainer.TerminalItems[((Object)val2).name] = ConfigUtilities.SyncConfigForTerminalItemOverrides(val2);
int purchasePrice = TerminalItemsContainer.TerminalItems[((Object)val2).name].OverrideTerminalItemValues.PurchasePrice;
int purchasePrice2 = TerminalItemsContainer.TerminalItems[((Object)val2).name].VanillaTerminalItemValues.PurchasePrice;
SharedComponents.Logger.LogDebug((object)$"For terminal item '{((Object)val2).name}' the override sell price is '{purchasePrice}' and the vanilla sell price is '{purchasePrice2}'");
if (flag)
{
UpdateItemPriceInShop(val2, purchasePrice);
}
else
{
UpdateItemPriceInShop(val2, purchasePrice2);
}
}
SharedComponents.ConfigFile.Save();
}
private static void UpdateItemPriceInShop(Item item, int price)
{
item.creditsWorth = price;
SharedComponents.Logger.LogInfo((object)$"Successfully set purchase price for '{item.itemName}' to be '{price}'");
}
}
}
namespace GuysNight.LethalCompanyMod.BalancedItems.Models.Terminal
{
internal sealed class OverrideTerminalItemValues
{
internal int PurchasePrice { get; set; }
internal OverrideTerminalItemValues()
{
}
internal OverrideTerminalItemValues(int purchasePrice)
{
PurchasePrice = purchasePrice;
}
public override string ToString()
{
return $"PurchasePrice: '{PurchasePrice}'";
}
}
internal sealed class TerminalItemProperties
{
internal OverrideTerminalItemValues OverrideTerminalItemValues { get; } = new OverrideTerminalItemValues();
internal VanillaTerminalItemValues VanillaTerminalItemValues { get; set; }
internal TerminalItemProperties()
{
}
internal TerminalItemProperties(OverrideTerminalItemValues overrideTerminalItemValues)
{
OverrideTerminalItemValues = overrideTerminalItemValues;
}
internal TerminalItemProperties(VanillaTerminalItemValues vanillaTerminalItemValues)
{
VanillaTerminalItemValues = vanillaTerminalItemValues;
}
internal TerminalItemProperties(VanillaTerminalItemValues vanillaTerminalItemValues, OverrideTerminalItemValues overrideTerminalItemValues)
{
VanillaTerminalItemValues = vanillaTerminalItemValues;
OverrideTerminalItemValues = overrideTerminalItemValues;
}
}
internal sealed class VanillaTerminalItemValues
{
internal int PurchasePrice { get; }
internal VanillaTerminalItemValues(int purchasePrice)
{
PurchasePrice = purchasePrice;
}
public override string ToString()
{
return $"PurchasePrice: '{PurchasePrice}'";
}
}
}
namespace GuysNight.LethalCompanyMod.BalancedItems.Models.Moons
{
public interface IMoonRarities
{
string MoonName { get; }
Dictionary<string, int> MoonRarityValues { get; }
}
internal class MoonProperties
{
internal OverrideMoonRarities OverrideMoonRarities { get; set; }
internal VanillaMoonRarities VanillaMoonRarities { get; set; }
internal MoonProperties()
{
}
internal MoonProperties(OverrideMoonRarities overrideMoonRarities)
{
OverrideMoonRarities = overrideMoonRarities;
}
internal MoonProperties(VanillaMoonRarities vanillaMoonRarities)
{
VanillaMoonRarities = vanillaMoonRarities;
}
internal MoonProperties(VanillaMoonRarities vanillaMoonRarities, OverrideMoonRarities overrideMoonRarities)
{
VanillaMoonRarities = vanillaMoonRarities;
OverrideMoonRarities = overrideMoonRarities;
}
}
internal sealed class OverrideMoonRarities : IMoonRarities
{
public string MoonName { get; }
public Dictionary<string, int> MoonRarityValues { get; } = new Dictionary<string, int>();
internal OverrideMoonRarities(string moonName)
{
MoonName = moonName;
}
}
internal sealed class VanillaMoonRarities : IMoonRarities
{
public string MoonName { get; }
public Dictionary<string, int> MoonRarityValues { get; } = new Dictionary<string, int>();
internal VanillaMoonRarities(string moonName)
{
MoonName = moonName;
}
}
}
namespace GuysNight.LethalCompanyMod.BalancedItems.Models.Items
{
internal sealed class ItemProperties
{
internal OverrideItemValues OverrideItemValues { get; } = new OverrideItemValues();
internal VanillaItemValues VanillaItemValues { get; set; }
internal ItemProperties()
{
}
internal ItemProperties(OverrideItemValues overrideItemValues)
{
OverrideItemValues = overrideItemValues;
}
internal ItemProperties(VanillaItemValues vanillaItemValues)
{
VanillaItemValues = vanillaItemValues;
}
internal ItemProperties(VanillaItemValues vanillaItemValues, OverrideItemValues overrideItemValues)
{
VanillaItemValues = vanillaItemValues;
OverrideItemValues = overrideItemValues;
}
}
internal sealed class OverrideItemValues
{
private float _weight;
internal ushort AverageValue { get; set; }
internal int MinValue => (int)Math.Round((double)(int)AverageValue - (double)(int)AverageValue * 0.2, MidpointRounding.AwayFromZero);
internal int MaxValue => (int)Math.Round((double)(int)AverageValue + (double)(int)AverageValue * 0.2, MidpointRounding.AwayFromZero);
internal float Weight
{
get
{
return _weight;
}
set
{
if (value < 0f)
{
throw new ArgumentOutOfRangeException("value", "You cannot set a negative weight.");
}
_weight = NumericUtilities.NormalizeWeight(value);
}
}
internal OverrideItemValues()
{
}
internal OverrideItemValues(float weight)
{
Weight = weight;
}
public override string ToString()
{
return $"MinValue: '{MinValue}' AvgValue: '{AverageValue}' MaxValue: '{MaxValue}' Weight:'{Weight}'";
}
}
internal sealed class VanillaItemValues
{
internal int MinValue { get; }
internal int MaxValue { get; }
internal float Weight { get; }
internal VanillaItemValues(int minValue, int maxValue, float weight)
{
MinValue = minValue;
MaxValue = maxValue;
Weight = weight;
}
public override string ToString()
{
return $"MinValue: '{MinValue}' MaxValue: '{MaxValue}' Weight:'{Weight}'";
}
}
}
namespace GuysNight.LethalCompanyMod.BalancedItems.Containers
{
internal static class ItemsContainer
{
internal static Dictionary<string, ItemProperties> Items { get; } = new Dictionary<string, ItemProperties>
{
{
"7Ball",
new ItemProperties(new OverrideItemValues(0.5f))
},
{
"Airhorn",
new ItemProperties(new OverrideItemValues(1.5f))
},
{
"Bell",
new ItemProperties(new OverrideItemValues(5f))
},
{
"BigBolt",
new ItemProperties(new OverrideItemValues(7f))
},
{
"BottleBin",
new ItemProperties()
},
{
"Brush",
new ItemProperties(new OverrideItemValues(1f))
},
{
"Candy",
new ItemProperties(new OverrideItemValues(1f))
},
{
"CashRegister",
new ItemProperties(new OverrideItemValues(20f))
},
{
"ChemicalJug",
new ItemProperties(new OverrideItemValues(20f))
},
{
"ClownHorn",
new ItemProperties(new OverrideItemValues(1f))
},
{
"Cog1",
new ItemProperties(new OverrideItemValues(25f))
},
{
"ComedyMask",
new ItemProperties(new OverrideItemValues(2f))
},
{
"Dentures",
new ItemProperties(new OverrideItemValues(1.5f))
},
{
"DiyFlashbang",
new ItemProperties(new OverrideItemValues(1.5f))
},
{
"DustPan",
new ItemProperties(new OverrideItemValues(1f))
},
{
"EggBeater",
new ItemProperties(new OverrideItemValues(0.5f))
},
{
"EnginePart1",
new ItemProperties(new OverrideItemValues(30f))
},
{
"FancyCup",
new ItemProperties(new OverrideItemValues(4f))
},
{
"FancyLamp",
new ItemProperties(new OverrideItemValues(10f))
},
{
"FancyPainting",
new ItemProperties()
},
{
"FishTestProp",
new ItemProperties(new OverrideItemValues(0.5f))
},
{
"FlashLaserPointer",
new ItemProperties(new OverrideItemValues(1f))
},
{
"Flask",
new ItemProperties(new OverrideItemValues(2f))
},
{
"GiftBox",
new ItemProperties()
},
{
"GoldBar",
new ItemProperties(new OverrideItemValues(27.5f))
},
{
"Hairdryer",
new ItemProperties()
},
{
"LungApparatus",
new ItemProperties(new OverrideItemValues(50f))
},
{
"MagnifyingGlass",
new ItemProperties(new OverrideItemValues(4f))
},
{
"MetalSheet",
new ItemProperties(new OverrideItemValues(7f))
},
{
"MoldPan",
new ItemProperties(new OverrideItemValues(3f))
},
{
"Mug",
new ItemProperties(new OverrideItemValues(2f))
},
{
"PerfumeBottle",
new ItemProperties(new OverrideItemValues(0.5f))
},
{
"Phone",
new ItemProperties()
},
{
"PickleJar",
new ItemProperties(new OverrideItemValues(3f))
},
{
"PillBottle",
new ItemProperties(new OverrideItemValues(1f))
},
{
"Remote",
new ItemProperties(new OverrideItemValues(1f))
},
{
"Ring",
new ItemProperties(new OverrideItemValues(0.2f))
},
{
"RobotToy",
new ItemProperties(new OverrideItemValues(5f))
},
{
"RubberDuck",
new ItemProperties(new OverrideItemValues(0.5f))
},
{
"SodaCanRed",
new ItemProperties(new OverrideItemValues(0.5f))
},
{
"SteeringWheel",
new ItemProperties(new OverrideItemValues(5f))
},
{
"StopSign",
new ItemProperties(new OverrideItemValues(6f))
},
{
"TeaKettle",
new ItemProperties(new OverrideItemValues(5f))
},
{
"Toothpaste",
new ItemProperties(new OverrideItemValues(1f))
},
{
"ToyCube",
new ItemProperties(new OverrideItemValues(1f))
},
{
"TragedyMask",
new ItemProperties(new OverrideItemValues(2f))
},
{
"WhoopieCushion",
new ItemProperties(new OverrideItemValues(0.5f))
},
{
"YieldSign",
new ItemProperties(new OverrideItemValues(6f))
},
{
"Clipboard",
new ItemProperties(new OverrideItemValues(0.1f))
},
{
"Key",
new ItemProperties(new OverrideItemValues(0.1f))
},
{
"Ragdoll",
new ItemProperties(new OverrideItemValues(100f))
},
{
"RedLocustHive",
new ItemProperties(new OverrideItemValues(0.5f))
},
{
"Shotgun",
new ItemProperties(new OverrideItemValues(15f))
},
{
"StickyNote",
new ItemProperties(new OverrideItemValues(0.1f))
},
{
"Boombox",
new ItemProperties(new OverrideItemValues(10f))
},
{
"ExtensionLadder",
new ItemProperties(new OverrideItemValues(10f))
},
{
"Flashlight",
new ItemProperties(new OverrideItemValues(2f))
},
{
"Jetpack",
new ItemProperties()
},
{
"LockPicker",
new ItemProperties(new OverrideItemValues(10f))
},
{
"ProFlashlight",
new ItemProperties(new OverrideItemValues(2f))
},
{
"RadarBooster",
new ItemProperties()
},
{
"Shovel",
new ItemProperties(new OverrideItemValues(5f))
},
{
"SprayPaint",
new ItemProperties(new OverrideItemValues(1f))
},
{
"StunGrenade",
new ItemProperties(new OverrideItemValues(2f))
},
{
"TZPInhalant",
new ItemProperties(new OverrideItemValues(1f))
},
{
"WalkieTalkie",
new ItemProperties(new OverrideItemValues(2f))
},
{
"ZapGun",
new ItemProperties(new OverrideItemValues(7f))
}
};
internal static bool SetVanillaValuesForItem(string itemName, VanillaItemValues vanillaItemValues)
{
if (Items.TryGetValue(itemName, out var value))
{
if (value.VanillaItemValues == null)
{
value.VanillaItemValues = vanillaItemValues;
Items[itemName] = value;
SharedComponents.Logger.LogDebug((object)$"Vanilla values have been set for item '{itemName}' to be '{vanillaItemValues}'.");
return true;
}
SharedComponents.Logger.LogDebug((object)$"Vanilla values were already set for item '{itemName}' to be '{value.VanillaItemValues}'.");
return false;
}
Items.Add(itemName, new ItemProperties(vanillaItemValues));
SharedComponents.Logger.LogDebug((object)$"Created new items container entry and set vanilla values for item '{itemName}' to be '{vanillaItemValues}'.");
return true;
}
}
internal static class MoonsContainer
{
internal static Dictionary<string, MoonProperties> Moons { get; } = new Dictionary<string, MoonProperties>();
}
internal static class TerminalItemsContainer
{
internal static Dictionary<string, TerminalItemProperties> TerminalItems { get; } = new Dictionary<string, TerminalItemProperties>();
internal static bool SetVanillaValuesForTerminalItem(string itemName, VanillaTerminalItemValues vanillaTerminalItemValues)
{
if (TerminalItems.TryGetValue(itemName, out var value))
{
if (value.VanillaTerminalItemValues == null)
{
value.VanillaTerminalItemValues = vanillaTerminalItemValues;
TerminalItems[itemName] = value;
SharedComponents.Logger.LogDebug((object)$"Vanilla values have been set for terminal item '{itemName}' to be '{vanillaTerminalItemValues}'.");
return true;
}
SharedComponents.Logger.LogDebug((object)$"Vanilla values were already set for terminal item '{itemName}' to be '{value.VanillaTerminalItemValues}'.");
return false;
}
TerminalItems.Add(itemName, new TerminalItemProperties(vanillaTerminalItemValues));
SharedComponents.Logger.LogDebug((object)$"Created new terminal items container entry and set vanilla values for terminal item '{itemName}' to be '{vanillaTerminalItemValues}'.");
return true;
}
}
}