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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LethalLevelLoader;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
[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("RebalancedMoons")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Rebalances/reworks some of the vanilla moons.")]
[assembly: AssemblyFileVersion("1.4.8.0")]
[assembly: AssemblyInformationalVersion("1.4.8+92be3e4b74036f89109979a8f36324b7df4c502d")]
[assembly: AssemblyProduct("RebalancedMoons")]
[assembly: AssemblyTitle("RebalancedMoons")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.4.8.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 RebalancedMoons
{
[BepInPlugin("dopadream.lethalcompany.rebalancedmoons", "RebalancedMoons", "1.4.8")]
public class Plugin : BaseUnityPlugin
{
[HarmonyPatch]
private class RebalancedMoonsPatches
{
private static void InitMoons()
{
if (!Plugin.IsSetupComplete)
{
return;
}
foreach (ExtendedLevel vanillaExtendedLevel in PatchedContent.VanillaExtendedLevels)
{
RebalanceMoon(vanillaExtendedLevel);
}
}
private static void RebalanceMoon(ExtendedLevel extendedLevel)
{
if (new Dictionary<string, Action<ExtendedLevel>>
{
{
"Assurance",
delegate(ExtendedLevel level)
{
ApplyRebalance(level, reAssuranceExtended);
}
},
{
"Offense",
delegate(ExtendedLevel level)
{
ApplyRebalance(level, reOffenseExtended);
SetScene(level, "ReOffenseScene");
}
},
{
"March",
delegate(ExtendedLevel level)
{
ApplyRebalance(level, reMarchExtended);
SetScene(level, "ReMarchLevel");
}
},
{
"Adamance",
delegate(ExtendedLevel level)
{
ApplyRebalance(level, reAdamanceExtended);
SetScene(level, "ReAdamanceScene");
}
},
{
"Rend",
delegate(ExtendedLevel level)
{
ApplyRebalance(level, reRendExtended);
}
},
{
"Dine",
delegate(ExtendedLevel level)
{
ApplyRebalance(level, reDineExtended);
SetScene(level, "ReDineScene");
}
},
{
"Titan",
delegate(ExtendedLevel level)
{
ApplyRebalance(level, reTitanExtended);
SetScene(level, "ReTitanScene");
}
},
{
"Artifice",
delegate(ExtendedLevel level)
{
level.SelectableLevel.riskLevel = "S+";
}
},
{
"Embrion",
delegate(ExtendedLevel level)
{
ApplyRebalance(level, reEmbrionExtended);
}
}
}.TryGetValue(extendedLevel.NumberlessPlanetName, out var value))
{
value(extendedLevel);
}
}
private static void SetScene(ExtendedLevel extendedLevel, string sceneName)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Expected O, but got Unknown
extendedLevel.SceneSelections.Clear();
extendedLevel.SceneSelections.Add(new StringWithRarity(sceneName, 100));
}
[HarmonyPatch(typeof(StartOfRound), "Start")]
[HarmonyPostfix]
private static void StartOfRoundPostFix(StartOfRound __instance)
{
SelectableLevel[] levels = __instance.levels;
foreach (SelectableLevel val in levels)
{
string planetName = val.PlanetName;
if (planetName != null)
{
if (planetName.Contains("Titan"))
{
val.canSpawnMold = false;
}
else if (planetName.Contains("Embrion"))
{
val.canSpawnMold = false;
}
}
}
InitMoons();
__instance.screenLevelVideoReel.Play();
}
[HarmonyPatch(typeof(ExtendedLevel), "SetExtendedDungeonFlowMatches")]
[HarmonyPostfix]
[HarmonyPriority(800)]
private static void ExtendedLevelFlowsPostFix(ExtendedLevel __instance)
{
foreach (ExtendedDungeonFlow extendedDungeonFlow in PatchedContent.ExtendedDungeonFlows)
{
List<StringWithRarity> planetNames = extendedDungeonFlow.LevelMatchingProperties.planetNames;
switch (((Object)extendedDungeonFlow.DungeonFlow).name)
{
case "Level1Flow3Exits":
planetNames.RemoveAll((StringWithRarity p) => p.Name.Equals("March"));
break;
case "Level1Flow":
UpdateMoonInList(planetNames, "Titan", 140);
AddMoonIfNotInList(planetNames, "March", 300);
break;
case "Level2Flow":
UpdateMoonInList(planetNames, "Titan", 40);
AddMoonIfNotInList(planetNames, "March", 5);
break;
case "Level3Flow":
UpdateMoonInList(planetNames, "Dine", 50);
UpdateMoonInList(planetNames, "Titan", 300);
AddMoonIfNotInList(planetNames, "March", 190);
break;
}
}
}
private static void UpdateMoonInList(List<StringWithRarity> planetNames, string planetName, int newRarity)
{
foreach (StringWithRarity planetName2 in planetNames)
{
if (planetName2.Name.Equals(planetName))
{
planetName2.Rarity = newRarity;
}
}
}
private static void AddMoonIfNotInList(List<StringWithRarity> planetNames, string planetName, int rarity)
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Expected O, but got Unknown
if (!planetNames.Any((StringWithRarity p) => p.Name.Equals(planetName)))
{
planetNames.Add(new StringWithRarity(planetName, rarity));
}
}
[HarmonyPatch(typeof(RoundManager), "GenerateNewFloor")]
[HarmonyPriority(250)]
[HarmonyPrefix]
private static void onGenerateNewFloorPrefix(RoundManager __instance)
{
foreach (ExtendedLevel extendedLevel in PatchedContent.ExtendedLevels)
{
string numberlessPlanetName = extendedLevel.NumberlessPlanetName;
if (!(numberlessPlanetName == "March"))
{
if (numberlessPlanetName == "Titan")
{
extendedLevel.SelectableLevel.factorySizeMultiplier = reTitanExtended.SelectableLevel.factorySizeMultiplier;
}
}
else
{
extendedLevel.SelectableLevel.factorySizeMultiplier = reMarchExtended.SelectableLevel.factorySizeMultiplier;
}
}
}
[HarmonyPatch(typeof(TerminalManager), "GetExtendedLevelGroups")]
[HarmonyPostfix]
private static void onGetExtendedLevelGroupsPostfix(ref List<ExtendedLevelGroup> __result)
{
List<ExtendedLevelGroup> list = new List<ExtendedLevelGroup>();
foreach (ExtendedLevelGroup item in __result)
{
if (!item.extendedLevelsList.Any((ExtendedLevel x) => rebalancedMoonsMod.ExtendedLevels.Any((ExtendedLevel y) => (Object)(object)y == (Object)(object)x)))
{
list.Add(item);
}
}
__result = list;
}
}
private const string PLUGIN_GUID = "dopadream.lethalcompany.rebalancedmoons";
private const string PLUGIN_NAME = "RebalancedMoons";
private const string PLUGIN_VERSION = "1.4.8";
internal static ManualLogSource Logger;
internal static ExtendedLevel reRendExtended;
internal static ExtendedLevel reDineExtended;
internal static ExtendedLevel reMarchExtended;
internal static ExtendedLevel reOffenseExtended;
internal static ExtendedLevel reAssuranceExtended;
internal static ExtendedLevel reEmbrionExtended;
internal static ExtendedLevel reTitanExtended;
internal static ExtendedLevel reAdamanceExtended;
internal static ExtendedMod rebalancedMoonsMod;
internal static VolumeProfile snowyProfile;
internal static VolumeProfile embyProfile;
internal static ConfigEntry<bool> configHDRISkies;
private void Awake()
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Expected O, but got Unknown
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
Logger = ((BaseUnityPlugin)this).Logger;
configHDRISkies = ((BaseUnityPlugin)this).Config.Bind<bool>("Client", "New HDRI Skies", true, new ConfigDescription("Adds new HDRI sky volumes to Embrion and snowy moons.", (AcceptableValueBase)null, Array.Empty<object>()));
AssetBundleLoader.AddOnExtendedModLoadedListener((Action<ExtendedMod>)OnExtendedModRegistered, "dopadream", "RebalancedMoons");
new Harmony("dopadream.lethalcompany.rebalancedmoons").PatchAll();
SceneManager.sceneLoaded += delegate
{
ApplySky();
};
Logger.LogInfo((object)"RebalancedMoons v1.4.8 loaded");
}
internal static void OnExtendedModRegistered(ExtendedMod extendedMod)
{
if (!((Object)(object)extendedMod == (Object)null))
{
rebalancedMoonsMod = extendedMod;
reAdamanceExtended = rebalancedMoonsMod.ExtendedLevels[0];
reAssuranceExtended = rebalancedMoonsMod.ExtendedLevels[1];
reDineExtended = rebalancedMoonsMod.ExtendedLevels[2];
reEmbrionExtended = rebalancedMoonsMod.ExtendedLevels[3];
reMarchExtended = rebalancedMoonsMod.ExtendedLevels[4];
reOffenseExtended = rebalancedMoonsMod.ExtendedLevels[5];
reRendExtended = rebalancedMoonsMod.ExtendedLevels[6];
reTitanExtended = rebalancedMoonsMod.ExtendedLevels[7];
}
}
internal static void ApplyRebalance(ExtendedLevel input, ExtendedLevel output)
{
input.RoutePrice = output.RoutePrice;
input.SelectableLevel.Enemies = output.SelectableLevel.Enemies;
input.SelectableLevel.OutsideEnemies = output.SelectableLevel.OutsideEnemies;
input.SelectableLevel.DaytimeEnemies = output.SelectableLevel.DaytimeEnemies;
input.SelectableLevel.maxEnemyPowerCount = output.SelectableLevel.maxEnemyPowerCount;
input.SelectableLevel.maxOutsideEnemyPowerCount = output.SelectableLevel.maxOutsideEnemyPowerCount;
input.SelectableLevel.maxDaytimeEnemyPowerCount = output.SelectableLevel.maxDaytimeEnemyPowerCount;
input.SelectableLevel.spawnProbabilityRange = output.SelectableLevel.spawnProbabilityRange;
input.SelectableLevel.enemySpawnChanceThroughoutDay = output.SelectableLevel.enemySpawnChanceThroughoutDay;
input.SelectableLevel.daytimeEnemiesProbabilityRange = output.SelectableLevel.daytimeEnemiesProbabilityRange;
input.SelectableLevel.daytimeEnemySpawnChanceThroughDay = output.SelectableLevel.daytimeEnemySpawnChanceThroughDay;
input.SelectableLevel.daytimeEnemiesProbabilityRange = output.SelectableLevel.daytimeEnemiesProbabilityRange;
input.SelectableLevel.daytimeEnemySpawnChanceThroughDay = output.SelectableLevel.daytimeEnemySpawnChanceThroughDay;
input.SelectableLevel.outsideEnemySpawnChanceThroughDay = output.SelectableLevel.outsideEnemySpawnChanceThroughDay;
input.SelectableLevel.minScrap = output.SelectableLevel.minScrap;
input.SelectableLevel.maxScrap = output.SelectableLevel.maxScrap;
input.SelectableLevel.minTotalScrapValue = output.SelectableLevel.minTotalScrapValue;
input.SelectableLevel.maxTotalScrapValue = output.SelectableLevel.maxTotalScrapValue;
input.SelectableLevel.spawnableScrap.Clear();
input.SelectableLevel.spawnableScrap.AddRange(output.SelectableLevel.spawnableScrap);
input.SelectableLevel.spawnableMapObjects = output.SelectableLevel.spawnableMapObjects;
input.SelectableLevel.spawnableOutsideObjects = output.SelectableLevel.spawnableOutsideObjects;
input.SelectableLevel.riskLevel = output.SelectableLevel.riskLevel;
input.SelectableLevel.sceneName = output.SelectableLevel.sceneName;
input.SelectableLevel.videoReel = output.SelectableLevel.videoReel;
Logger.LogDebug((object)("Rebalances applied for " + ((object)input)?.ToString() + "!"));
}
internal static void ApplySky()
{
if (!configHDRISkies.Value)
{
return;
}
Volume[] array = Object.FindObjectsOfType<Volume>();
foreach (Volume val in array)
{
if ((Object)(object)snowyProfile == (Object)null || (Object)(object)embyProfile == (Object)null)
{
try
{
AssetBundle obj = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "hdri_skies"));
snowyProfile = obj.LoadAsset<VolumeProfile>("ReSnowyFog");
embyProfile = obj.LoadAsset<VolumeProfile>("EmbrionSky");
}
catch
{
Logger.LogError((object)"Encountered some error loading assets from bundle \"hdri_skies\". Did you install the plugin correctly?");
break;
}
}
if ((Object)(object)snowyProfile != (Object)null && ((Object)val.sharedProfile).name.Contains("SnowyFog") && !StartOfRound.Instance.currentLevel.PlanetName.Contains("Artifice"))
{
val.sharedProfile = snowyProfile;
}
if ((Object)(object)embyProfile != (Object)null && StartOfRound.Instance.currentLevel.PlanetName.Contains("Embrion") && ((Object)val.sharedProfile).name.Contains("Sky and Fog Settings Profile"))
{
val.sharedProfile = embyProfile;
}
}
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "RebalancedMoons";
public const string PLUGIN_NAME = "RebalancedMoons";
public const string PLUGIN_VERSION = "1.4.8";
}
}