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 System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("MaxWasUnavailable")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Adds an air of uncertainty to Lethal Company... Are you prepared?")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("UncertainCompany")]
[assembly: AssemblyTitle("UncertainCompany")]
[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 UncertainCompany
{
[BepInPlugin("UncertainCompany", "UncertainCompany", "1.0.0")]
public class UncertainCompany : BaseUnityPlugin
{
private bool _isPatched;
private Harmony Harmony { get; set; }
private static ManualLogSource Logger { get; set; }
public static UncertainCompany Instance { get; private set; }
public ConfigEntry<bool> DoHideWeather { get; private set; }
public ConfigEntry<bool> DoRandomiseItemSales { get; private set; }
public ConfigEntry<bool> DoRandomiseSellPrice { get; private set; }
public ConfigEntry<bool> DoRandomiseTravelCost { get; private set; }
private void Awake()
{
Instance = this;
Logger = ((BaseUnityPlugin)this).Logger;
DoHideWeather = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "HideWeather", true, "Hide weather information.");
DoRandomiseItemSales = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "RandomiseItemSales", true, "Randomise item sales. (Can be cheaper *or* more expensive)");
DoRandomiseSellPrice = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "RandomiseSellPrice", true, "Randomise sell price. (Can sell for more *or* less)");
DoRandomiseTravelCost = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "RandomiseTravelCost", true, "Randomise travel cost. (Can also impact free moons)");
PatchAll();
Logger.LogInfo((object)"Plugin UncertainCompany is loaded!");
}
public void PatchAll()
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Expected O, but got Unknown
if (_isPatched)
{
Logger.LogWarning((object)"Already patched!");
return;
}
Logger.LogDebug((object)"Patching...");
Harmony = new Harmony("UncertainCompany");
Harmony.PatchAll();
_isPatched = true;
Logger.LogDebug((object)"Patched!");
}
public void UnpatchAll()
{
if (!_isPatched)
{
Logger.LogWarning((object)"Already unpatched!");
return;
}
Logger.LogDebug((object)"Unpatching...");
Harmony.UnpatchSelf();
_isPatched = false;
Logger.LogDebug((object)"Unpatched!");
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "UncertainCompany";
public const string PLUGIN_NAME = "UncertainCompany";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace UncertainCompany.Patches
{
[HarmonyPatch(typeof(StartOfRound))]
internal class StartOfRoundPatch
{
private const int TicksBetweenWeatherChanges = 10;
private static int _ticksSinceLastWeatherChange;
private static readonly Random _random = new Random();
[HarmonyPatch("SetMapScreenInfoToCurrentLevel")]
[HarmonyPostfix]
internal static void HideWeatherInfoFromDisplay(ref StartOfRound __instance)
{
if (UncertainCompany.Instance.DoHideWeather.Value)
{
UpdateScreenLevelDescription(ref __instance);
}
}
[HarmonyPatch("Update")]
[HarmonyPostfix]
internal static void ScrambleWeatherInfoOnUpdate(ref StartOfRound __instance)
{
if (UncertainCompany.Instance.DoHideWeather.Value)
{
if (_ticksSinceLastWeatherChange < 10 + _random.Next(0, 10))
{
_ticksSinceLastWeatherChange++;
return;
}
_ticksSinceLastWeatherChange = 0;
UpdateScreenLevelDescription(ref __instance);
}
}
private static void UpdateScreenLevelDescription(ref StartOfRound __instance)
{
if (((TMP_Text)__instance.screenLevelDescription).text.Contains("Weather:"))
{
((TMP_Text)__instance.screenLevelDescription).text = Regex.Replace(((TMP_Text)__instance.screenLevelDescription).text, "Weather.*", ScrambledWeatherText());
return;
}
if (!((TMP_Text)__instance.screenLevelDescription).text.EndsWith("\n"))
{
TextMeshProUGUI screenLevelDescription = __instance.screenLevelDescription;
((TMP_Text)screenLevelDescription).text = ((TMP_Text)screenLevelDescription).text + "\n";
}
TextMeshProUGUI screenLevelDescription2 = __instance.screenLevelDescription;
((TMP_Text)screenLevelDescription2).text = ((TMP_Text)screenLevelDescription2).text + ScrambledWeatherText();
}
private static string ScrambledWeatherText()
{
string text = "Weather: ";
string text2 = ((object)(LevelWeatherType)(ref Enum.GetValues(typeof(LevelWeatherType)).Cast<LevelWeatherType>().ToArray()[_random.Next(0, Enum.GetValues(typeof(LevelWeatherType)).Length)])).ToString();
int length = text2.Length;
for (int i = 0; i < length; i++)
{
text = _random.Next(0, 5) switch
{
0 => text + text2[i].ToString().ToUpper(),
1 => text + text2[i].ToString().ToLower(),
2 => text + text2[_random.Next(0, length)],
_ => text + (char)_random.Next(48, 122),
};
}
return text;
}
}
[HarmonyPatch(typeof(Terminal))]
internal class TerminalPatch
{
private const double MaxItemSaleAddition = 0.3;
private const double MaxItemSaleSubtraction = 0.1;
private const double MaxMoonCostAddition = 0.25;
private const double MaxMoonCostSubtraction = 0.25;
private const int MaxFreeMoonCost = 200;
private static readonly Dictionary<string, int> OriginalMoonCosts = new Dictionary<string, int>();
[HarmonyPatch("Awake")]
[HarmonyPostfix]
[HarmonyPriority(0)]
internal static void HideMoonWeatherInfoFromRouteCommand(ref Terminal __instance)
{
if (!UncertainCompany.Instance.DoHideWeather.Value)
{
return;
}
List<TerminalKeyword> list = __instance.terminalNodes.allKeywords.ToList();
CompatibleNoun[] compatibleNouns = list.Find((TerminalKeyword keyword) => keyword.word == "route").compatibleNouns;
foreach (CompatibleNoun val in compatibleNouns)
{
if (!val.result.displayText.ToLower().Contains("company"))
{
val.result.displayPlanetInfo = -1;
val.result.displayText = val.result.displayText.Replace("currently [currentPlanetTime]", "The conditions are uncertain").Replace("It is", "");
}
}
__instance.terminalNodes.allKeywords = list.ToArray();
}
[HarmonyPatch("Awake")]
[HarmonyPostfix]
[HarmonyPriority(0)]
internal static void HideMoonWeatherInfoFromMoonsCommand(ref Terminal __instance)
{
if (UncertainCompany.Instance.DoHideWeather.Value)
{
List<TerminalKeyword> list = __instance.terminalNodes.allKeywords.ToList();
TerminalKeyword val = list.Find((TerminalKeyword keyword) => keyword.word == "moons");
val.specialKeywordResult.displayText = val.specialKeywordResult.displayText.Replace("[planetTime]", "");
__instance.terminalNodes.allKeywords = list.ToArray();
}
}
[HarmonyPatch("SetItemSales")]
[HarmonyPostfix]
[HarmonyPriority(0)]
internal static void RandomiseItemSales(ref Terminal __instance)
{
if (!UncertainCompany.Instance.DoRandomiseItemSales.Value)
{
return;
}
Random random = new Random(StartOfRound.Instance.randomMapSeed);
for (int i = 0; i < __instance.itemSalesPercentages.Length; i++)
{
if (__instance.itemSalesPercentages[i] != 100)
{
__instance.itemSalesPercentages[i] += GetRandomItemSaleOffset(random);
}
}
}
private static int GetRandomItemSaleOffset(Random random)
{
double num = ((random.Next(0, 2) != 0) ? (random.NextDouble() * -0.1) : (random.NextDouble() * 0.3));
return (int)(num * 100.0);
}
[HarmonyPatch("SetItemSales")]
[HarmonyPostfix]
[HarmonyPriority(0)]
internal static void RandomiseMoonTravelPrices(ref Terminal __instance)
{
if (!UncertainCompany.Instance.DoRandomiseTravelCost.Value)
{
return;
}
Random random = new Random(StartOfRound.Instance.randomMapSeed);
List<TerminalKeyword> list = __instance.terminalNodes.allKeywords.ToList();
TerminalKeyword val = list.Find((TerminalKeyword keyword) => keyword.word == "route");
int num = ((OriginalMoonCosts.Values.Count > 0) ? OriginalMoonCosts.Values.Count((int moonCost) => moonCost == 0) : val.compatibleNouns.Count((CompatibleNoun compatibleNoun) => compatibleNoun.result.itemCost == 0));
CompatibleNoun[] compatibleNouns = val.compatibleNouns;
foreach (CompatibleNoun val2 in compatibleNouns)
{
if (val2.result.displayText.ToLower().Contains("company"))
{
continue;
}
if (!OriginalMoonCosts.ContainsKey(val2.noun.word))
{
OriginalMoonCosts.Add(val2.noun.word, val2.result.itemCost);
}
int num2 = OriginalMoonCosts[val2.noun.word];
if (num2 == 0 && random.Next(0, 4) == 0)
{
num2 = random.Next(0, 200);
}
if (OriginalMoonCosts[val2.noun.word] == 0 && num > 0)
{
if (random.Next(0, 2) == 0 || num == 1)
{
num = -1;
num2 = 0;
}
else
{
num--;
}
}
num2 = GetRandomisedMoonPrice(random, num2);
val2.result.itemCost = num2;
CompatibleNoun[] terminalOptions = val2.result.terminalOptions;
foreach (CompatibleNoun val3 in terminalOptions)
{
if (val3.noun.word.ToLower() == "confirm")
{
val3.result.itemCost = num2;
}
}
}
__instance.terminalNodes.allKeywords = list.ToArray();
}
private static int GetRandomisedMoonPrice(Random random, int originalPrice)
{
double num = ((random.Next(0, 2) != 0) ? (random.NextDouble() * -0.25) : (random.NextDouble() * 0.25));
double num2 = num;
return (int)((double)originalPrice * (1.0 + num2));
}
}
[HarmonyPatch(typeof(TimeOfDay))]
internal class TimeOfDayPatch
{
private const double MaxBuyingRateAddition = 0.15;
private const double MaxBuyingRateSubtraction = 0.2;
[HarmonyPatch("SetBuyingRateForDay")]
[HarmonyPostfix]
internal static void RandomiseBuyingRate(ref TimeOfDay __instance)
{
if (UncertainCompany.Instance.DoRandomiseSellPrice.Value)
{
Random random = new Random(StartOfRound.Instance.randomMapSeed);
double num = ((random.Next(0, 2) != 0) ? (random.NextDouble() * -0.2) : (random.NextDouble() * 0.15));
double num2 = num;
StartOfRound instance = StartOfRound.Instance;
instance.companyBuyingRate += (float)num2;
}
}
}
}