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.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Chameleon.Info;
using DunGen;
using DunGen.Graph;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
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("Chameleon")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Changes visual elements of interiors for more variety")]
[assembly: AssemblyFileVersion("1.2.2.0")]
[assembly: AssemblyInformationalVersion("1.2.2+cd169417a348954a27473a28bfc189d4ff1524e3")]
[assembly: AssemblyProduct("Chameleon")]
[assembly: AssemblyTitle("Chameleon")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.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.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace Chameleon
{
internal class Configuration
{
internal enum GordionStorms
{
Never = -1,
Chance,
Always
}
internal struct MoonCavernMapping
{
internal string moon;
internal CavernType type;
internal int weight;
}
private static ConfigFile configFile;
internal static ConfigEntry<bool> fancyEntranceDoors;
internal static ConfigEntry<bool> recolorRandomRocks;
internal static ConfigEntry<bool> doorLightColors;
internal static ConfigEntry<bool> rainyMarch;
internal static ConfigEntry<bool> eclipsesBlockMusic;
internal static ConfigEntry<bool> autoAdaptSnow;
internal static ConfigEntry<bool> powerOffBreakerBox;
internal static ConfigEntry<bool> powerOffWindows;
internal static ConfigEntry<GordionStorms> stormyGordion;
internal static List<MoonCavernMapping> mappings = new List<MoonCavernMapping>();
internal static void Init(ConfigFile cfg)
{
configFile = cfg;
ExteriorConfig();
InteriorConfig();
MigrateLegacyConfigs();
}
private static void ExteriorConfig()
{
fancyEntranceDoors = configFile.Bind<bool>("Exterior", "FancyEntranceDoors", true, "Changes the front doors to match how they look on the inside when a manor interior generates. (Works for ONLY vanilla levels!)");
recolorRandomRocks = configFile.Bind<bool>("Exterior", "RecolorRandomRocks", true, "Recolors random boulders to be white on snowy moons so they blend in better.");
rainyMarch = configFile.Bind<bool>("Exterior", "RainyMarch", true, "March is constantly rainy, as described in its terminal page. This is purely visual and does not affect quicksand generation.");
stormyGordion = configFile.Bind<GordionStorms>("Exterior", "StormyGordion", GordionStorms.Chance, "Allows for storms on Gordion, as described in its terminal page. This is purely visual and lightning does not strike at The Company.");
eclipsesBlockMusic = configFile.Bind<bool>("Exterior", "EclipsesBlockMusic", true, "Prevents the morning/afternoon ambience music from playing during Eclipsed weather, which has its own ambient track.");
}
private static void InteriorConfig()
{
doorLightColors = configFile.Bind<bool>("Interior", "DoorLightColors", true, "Dynamically adjust the color of the light behind the entrance doors depending on where you land and the current weather.");
powerOffBreakerBox = configFile.Bind<bool>("Interior", "PowerOffBreakerBox", true, "When the apparatus is unplugged, the light on the breaker box will turn off to indicate it is inactive.");
InteriorManorConfig();
InteriorMineshaftConfig();
}
private static void InteriorManorConfig()
{
powerOffWindows = configFile.Bind<bool>("Interior.Manor", "PowerOffWindows", true, "When the breaker box is turned off, the \"fake window\" rooms will also turn off.");
}
private static void InteriorMineshaftConfig()
{
PopulateGlobalListWithCavernType(CavernType.Vanilla, "Vow:100,March:100,Adamance:100,Artifice:80");
PopulateGlobalListWithCavernType(CavernType.Mesa, "Experimentation:100,Titan:100");
PopulateGlobalListWithCavernType(CavernType.Desert, "Assurance:100,Offense:100");
PopulateGlobalListWithCavernType(CavernType.Ice, "Rend:100,Dine:100");
PopulateGlobalListWithCavernType(CavernType.Amethyst, "Embrion:100");
PopulateGlobalListWithCavernType(CavernType.Gravel, "Artifice:20");
autoAdaptSnow = configFile.Bind<bool>("Interior.Mineshaft", "AutoAdaptSnow", true, "Automatically enable ice caverns on modded levels that are snowy.\nIf you have Artifice Blizzard installed, this will also change the caverns to ice specifically when the blizzard is active.");
}
private static void PopulateGlobalListWithCavernType(CavernType type, string defaultList)
{
string text = $"{type}CavesList";
string value = configFile.Bind<string>("Interior.Mineshaft", text, defaultList, string.Format("A list of moons for which to assign \"{0}\" caves, with their respective weights.{1}\n", type, (type != CavernType.Vanilla) ? " Leave empty to disable." : string.Empty) + "Moon names are not case-sensitive, and can be left incomplete (ex. \"as\" will map to both Assurance and Asteroid-13.)" + ((type == CavernType.Vanilla) ? "\nUpon hosting a lobby, the full list of moon names will be printed in the debug log, which you can use as a guide." : string.Empty)).Value;
if (string.IsNullOrEmpty(value))
{
Plugin.Logger.LogDebug((object)("User has no " + text + " defined"));
return;
}
try
{
string[] array = value.Split(',');
foreach (string text2 in array)
{
string[] array2 = text2.Split(':');
int result = -1;
if (array2.Length == 2 && int.TryParse(array2[1], out result))
{
MoonCavernMapping moonCavernMapping = default(MoonCavernMapping);
moonCavernMapping.moon = array2[0].ToLower();
moonCavernMapping.type = type;
moonCavernMapping.weight = (int)Mathf.Clamp((float)result, 0f, 99999f);
MoonCavernMapping item = moonCavernMapping;
mappings.Add(item);
Plugin.Logger.LogDebug((object)$"Successfully added \"{item.moon}\" to \"{item.type}\" caves list with weight {item.weight}");
}
else
{
Plugin.Logger.LogWarning((object)("Encountered an error parsing entry \"" + text2 + "\" in the \"" + text + "\" setting. It has been skipped"));
}
}
}
catch
{
Plugin.Logger.LogError((object)("Encountered an error parsing the \"" + text + "\" setting. Please double check that your config follows proper syntax, then restart your game."));
}
}
private static void MigrateLegacyConfigs()
{
string[] array = new string[6] { "IceCaves", "AmethystCave", "DesertCave", "MesaCave", "IcyTitan", "AdaptiveArtifice" };
foreach (string text in array)
{
configFile.Bind<bool>("Interior", text, false, "Legacy setting, doesn't work");
configFile.Remove(configFile["Interior", text].Definition);
}
configFile.Save();
}
}
[BepInPlugin("butterystancakes.lethalcompany.chameleon", "Chameleon", "1.2.2")]
public class Plugin : BaseUnityPlugin
{
private const string PLUGIN_GUID = "butterystancakes.lethalcompany.chameleon";
private const string PLUGIN_NAME = "Chameleon";
private const string PLUGIN_VERSION = "1.2.2";
internal static ManualLogSource Logger;
private void Awake()
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
Logger = ((BaseUnityPlugin)this).Logger;
Configuration.Init(((BaseUnityPlugin)this).Config);
new Harmony("butterystancakes.lethalcompany.chameleon").PatchAll();
SceneManager.sceneUnloaded += delegate
{
SceneOverrides.done = false;
SceneOverrides.forceRainy = false;
SceneOverrides.forceStormy = false;
SceneOverrides.breakerBoxOff = false;
SceneOverrides.windowsInManor = false;
};
Logger.LogInfo((object)"Chameleon v1.2.2 loaded");
}
}
[HarmonyPatch]
internal class ChameleonPatches
{
[HarmonyPatch(typeof(RoundManager), "FinishGeneratingNewLevelClientRpc")]
[HarmonyPostfix]
private static void PostFinishGeneratingNewLevelClientRpc(RoundManager __instance)
{
if (!SceneOverrides.done)
{
SceneOverrides.done = true;
SceneOverrides.SetupCompatibility();
SceneOverrides.ExteriorOverrides();
if (((Object)StartOfRound.Instance.currentLevel).name != "CompanyBuildingLevel")
{
SceneOverrides.InteriorOverrides();
}
}
}
[HarmonyPatch(typeof(TimeOfDay), "Update")]
[HarmonyPostfix]
private static void TimeOfDayPostUpdate(TimeOfDay __instance)
{
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
if (SceneOverrides.forceRainy)
{
if ((!GameNetworkManager.Instance.localPlayerController.isInsideFactory && !GameNetworkManager.Instance.localPlayerController.isPlayerDead) || ((Object)(object)GameNetworkManager.Instance.localPlayerController.spectatedPlayerScript != (Object)null && !GameNetworkManager.Instance.localPlayerController.spectatedPlayerScript.isInsideFactory))
{
__instance.effects[1].effectEnabled = true;
}
}
else if (SceneOverrides.forceStormy)
{
GameObject effectObject = __instance.effects[2].effectObject;
Vector3 position = (GameNetworkManager.Instance.localPlayerController.isPlayerDead ? ((Component)StartOfRound.Instance.spectateCamera).transform : ((Component)GameNetworkManager.Instance.localPlayerController).transform).position;
position.y = Mathf.Max(position.y, -24f);
effectObject.transform.position = position;
effectObject.SetActive(true);
}
}
[HarmonyPatch(typeof(TimeOfDay), "PlayTimeMusicDelayed")]
[HarmonyPostfix]
private static void PostPlayTimeMusicDelayed(TimeOfDay __instance, AudioClip clip)
{
if ((Object)(object)clip == (Object)(object)StartOfRound.Instance.companyVisitMusic && SceneOverrides.forceStormy)
{
__instance.TimeOfDayMusic.volume = 1f;
}
}
[HarmonyPatch(typeof(SoundManager), "PlayRandomOutsideMusic")]
[HarmonyPrefix]
private static bool PrePlayRandomOutsideMusic(SoundManager __instance)
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Invalid comparison between Unknown and I4
if (Configuration.eclipsesBlockMusic.Value)
{
return (int)StartOfRound.Instance.currentLevel.currentWeather != 5;
}
return true;
}
[HarmonyPatch(typeof(HUDManager), "HelmetCondensationDrops")]
[HarmonyPostfix]
private static void PostHelmetCondensationDrops(HUDManager __instance)
{
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
if (!__instance.increaseHelmetCondensation && SceneOverrides.forceStormy && !TimeOfDay.Instance.insideLighting && ((Component)GameNetworkManager.Instance.localPlayerController).transform.position.y >= -5.5f && Vector3.Angle(((Component)GameNetworkManager.Instance.localPlayerController.gameplayCamera).transform.forward, Vector3.up) < 45f)
{
__instance.increaseHelmetCondensation = true;
}
}
[HarmonyPatch(typeof(StartOfRound), "Start")]
[HarmonyPostfix]
[HarmonyPriority(0)]
private static void StartOfRoundPostStart()
{
SceneOverrides.BuildWeightLists();
}
[HarmonyPatch(typeof(RoundManager), "Update")]
[HarmonyPostfix]
private static void RoundManagerPostUpdate(RoundManager __instance)
{
if (__instance.powerOffPermanently && !SceneOverrides.breakerBoxOff)
{
SceneOverrides.breakerBoxOff = true;
if (Configuration.powerOffBreakerBox.Value)
{
SceneOverrides.ShutdownBreakerBox();
}
}
}
[HarmonyPatch(typeof(RoundManager), "TurnOnAllLights")]
[HarmonyPostfix]
private static void RoundManagerPostTurnOnAllLights(RoundManager __instance, bool on)
{
if (SceneOverrides.windowsInManor)
{
SceneOverrides.ToggleAllWindows(on);
}
}
}
internal static class SceneOverrides
{
internal static bool done;
internal static bool forceRainy;
internal static bool forceStormy;
internal static bool breakerBoxOff;
internal static bool windowsInManor;
private static GameObject artificeBlizzard;
private static Dictionary<string, IntWithRarity[]> mineshaftWeightLists = new Dictionary<string, IntWithRarity[]>();
private static Material breakerLightOff;
private static Material fakeWindowOff;
private static Material fakeWindowOn;
private static List<(Renderer room, Light light)> windowTiles = new List<(Renderer, Light)>();
internal static void ExteriorOverrides()
{
//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
//IL_03ff: Invalid comparison between Unknown and I4
//IL_0421: Unknown result type (might be due to invalid IL or missing references)
//IL_0427: Invalid comparison between Unknown and I4
//IL_0433: Unknown result type (might be due to invalid IL or missing references)
//IL_0439: Invalid comparison between Unknown and I4
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Expected O, but got Unknown
if (Configuration.recolorRandomRocks.Value && IsSnowLevel())
{
if ((Object)(object)RoundManager.Instance.mapPropsContainer == (Object)null)
{
RoundManager.Instance.mapPropsContainer = GameObject.FindGameObjectWithTag("MapPropsContainer");
}
if ((Object)(object)RoundManager.Instance.mapPropsContainer != (Object)null)
{
foreach (Transform item in RoundManager.Instance.mapPropsContainer.transform)
{
Transform val = item;
if (((Object)val).name.StartsWith("LargeRock"))
{
Renderer[] componentsInChildren = ((Component)val).GetComponentsInChildren<Renderer>();
foreach (Renderer obj in componentsInChildren)
{
obj.material.SetTexture("_MainTex", (Texture)null);
obj.material.SetTexture("_BaseColorMap", (Texture)null);
}
}
}
}
}
if (((Object)StartOfRound.Instance.currentLevel).name == "CompanyBuildingLevel")
{
GameObject obj2 = GameObject.Find("/Environment/Map");
Transform val2 = ((obj2 != null) ? obj2.transform : null);
string[] array = new string[30]
{
"CompanyPlanet/Cube", "CompanyPlanet/Cube/Colliders/Cube", "CompanyPlanet/Cube/Colliders/Cube (2)", "CompanyPlanet/Cube/Colliders/Cube (3)", "CompanyPlanet/Elbow Joint.001", "CompanyPlanet/Cube.003", "ShippingContainers/ShippingContainer", "ShippingContainers/ShippingContainer (1)", "ShippingContainers/ShippingContainer (2)", "ShippingContainers/ShippingContainer (3)",
"ShippingContainers/ShippingContainer (4)", "ShippingContainers/ShippingContainer (5)", "ShippingContainers/ShippingContainer (6)", "ShippingContainers/ShippingContainer (7)", "ShippingContainers/ShippingContainer (8)", "ShippingContainers/ShippingContainer (9)", "ShippingContainers/ShippingContainer (10)", "CompanyPlanet/Cube.005", "CompanyPlanet/CatwalkChunk", "CompanyPlanet/CatwalkChunk.001",
"CompanyPlanet/CatwalkStairTile", "CompanyPlanet/Cylinder", "CompanyPlanet/Cylinder.001", "CompanyPlanet/LargePipeSupportBeam", "CompanyPlanet/LargePipeSupportBeam.001", "CompanyPlanet/LargePipeSupportBeam.002", "CompanyPlanet/LargePipeSupportBeam.003", "CompanyPlanet/Scaffolding", "CompanyPlanet/Scaffolding.001", "GiantDrill/DrillMainBody"
};
Renderer val4 = default(Renderer);
foreach (string text in array)
{
Transform val3 = val2.Find(text);
if ((Object)(object)val3 != (Object)null)
{
if (((Component)val3).gameObject.layer == 11 && ((Component)val3).TryGetComponent<Renderer>(ref val4))
{
val4.enabled = false;
}
((Component)val3).gameObject.layer = 8;
}
}
if (Configuration.stormyGordion.Value == Configuration.GordionStorms.Always)
{
forceStormy = true;
}
else
{
if (Configuration.stormyGordion.Value != 0 || TimeOfDay.Instance.profitQuota <= 130)
{
return;
}
float num = 0.7f;
int num2 = 0;
GrabbableObject[] array2 = Object.FindObjectsOfType<GrabbableObject>();
foreach (GrabbableObject val5 in array2)
{
if (val5.itemProperties.isScrap)
{
num2 += val5.scrapValue;
}
}
if (TimeOfDay.Instance.daysUntilDeadline < 1)
{
if (num2 < 1)
{
num = 0.98f;
}
else if (num2 < TimeOfDay.Instance.profitQuota)
{
num += 0.17f;
}
else if (Mathf.FloorToInt((float)(num2 - TimeOfDay.Instance.profitQuota - 75) * 1.2f) + TimeOfDay.Instance.profitQuota >= 1500)
{
num = 0.6f;
}
}
if (num2 > TimeOfDay.Instance.profitQuota - 75 && !StartOfRound.Instance.levels.Any((SelectableLevel level) => (int)level.currentWeather != -1))
{
num *= 0.55f;
}
if (new Random(StartOfRound.Instance.randomMapSeed).NextDouble() <= (double)num)
{
forceStormy = true;
}
}
}
else if (((Object)StartOfRound.Instance.currentLevel).name == "MarchLevel")
{
float num3 = 0.66f;
if ((int)StartOfRound.Instance.currentLevel.currentWeather == 3)
{
num3 *= 0.5f;
}
if (Configuration.rainyMarch.Value && (int)StartOfRound.Instance.currentLevel.currentWeather != 2 && (int)StartOfRound.Instance.currentLevel.currentWeather != 4 && new Random(StartOfRound.Instance.randomMapSeed).NextDouble() <= (double)num3)
{
forceRainy = true;
}
}
}
internal static void InteriorOverrides()
{
RoundManager instance = RoundManager.Instance;
object obj;
if (instance == null)
{
obj = null;
}
else
{
RuntimeDungeon dungeonGenerator = instance.dungeonGenerator;
if (dungeonGenerator == null)
{
obj = null;
}
else
{
DungeonGenerator generator = dungeonGenerator.Generator;
if (generator == null)
{
obj = null;
}
else
{
DungeonFlow dungeonFlow = generator.DungeonFlow;
obj = ((dungeonFlow != null) ? ((Object)dungeonFlow).name : null);
}
}
}
string text = (string)obj;
if (string.IsNullOrEmpty(text))
{
return;
}
VanillaLevelsInfo.predefinedLevels.TryGetValue(((Object)StartOfRound.Instance.currentLevel).name, out var value);
if ((Object)(object)breakerLightOff == (Object)null || (Object)(object)fakeWindowOff == (Object)null)
{
try
{
AssetBundle obj2 = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "lightmats"));
breakerLightOff = obj2.LoadAsset<Material>("LEDLightYellowOff");
fakeWindowOff = obj2.LoadAsset<Material>("FakeWindowViewOff");
obj2.Unload(false);
}
catch
{
Plugin.Logger.LogError((object)"Encountered some error loading assets from bundle \"lightmats\". Did you install the plugin correctly?");
return;
}
}
if (text == "Level2Flow" || text == "SDMLevel")
{
if (Configuration.fancyEntranceDoors.Value && value != null)
{
SetUpFancyEntranceDoors(value);
}
if (text == "Level2Flow" && Configuration.powerOffWindows.Value)
{
SetUpManorWindows();
}
return;
}
if (Configuration.doorLightColors.Value)
{
ColorDoorLight(value);
}
if (!(text == "Level3Flow"))
{
return;
}
IntWithRarity[] value2;
if (Configuration.autoAdaptSnow.Value && IsSnowLevel() && ((Object)(object)artificeBlizzard != (Object)null || !VanillaLevelsInfo.predefinedLevels.ContainsKey(((Object)StartOfRound.Instance.currentLevel).name)))
{
RetextureCaverns(CavernType.Ice);
Plugin.Logger.LogDebug((object)"Snow level detected, automatically enabling ice caverns");
}
else if (mineshaftWeightLists.TryGetValue(((Object)StartOfRound.Instance.currentLevel).name, out value2))
{
int randomWeightedIndex = RoundManager.Instance.GetRandomWeightedIndex(value2.Select((IntWithRarity x) => x.rarity).ToArray(), new Random(StartOfRound.Instance.randomMapSeed));
if (randomWeightedIndex >= 0 && randomWeightedIndex < value2.Length)
{
int id = value2[randomWeightedIndex].id;
if (Enum.IsDefined(typeof(CavernType), id))
{
if (id > -1)
{
RetextureCaverns((CavernType)id);
}
}
else
{
Plugin.Logger.LogWarning((object)"Tried to assign an unknown cavern type. This shouldn't happen! (Falling back to vanilla caverns)");
}
}
else
{
Plugin.Logger.LogWarning((object)"An error occurred indexing a random cavern type. This shouldn't happen! (Falling back to vanilla caverns)");
}
}
else
{
Plugin.Logger.LogDebug((object)"No custom cave weights were defined for the current moon. Falling back to vanilla caverns");
}
}
private static void SetUpFancyEntranceDoors(LevelCosmeticInfo levelCosmeticInfo)
{
//IL_0174: Unknown result type (might be due to invalid IL or missing references)
//IL_017a: Unknown result type (might be due to invalid IL or missing references)
//IL_019b: Unknown result type (might be due to invalid IL or missing references)
//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
//IL_01db: Unknown result type (might be due to invalid IL or missing references)
//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
//IL_020b: Unknown result type (might be due to invalid IL or missing references)
//IL_0211: Unknown result type (might be due to invalid IL or missing references)
//IL_0216: Unknown result type (might be due to invalid IL or missing references)
//IL_0222: Unknown result type (might be due to invalid IL or missing references)
//IL_0233: Unknown result type (might be due to invalid IL or missing references)
//IL_023e: Unknown result type (might be due to invalid IL or missing references)
//IL_024e: Unknown result type (might be due to invalid IL or missing references)
GameObject val = GameObject.Find(levelCosmeticInfo.fakeDoor1Path);
GameObject val2 = GameObject.Find(levelCosmeticInfo.fakeDoor2Path);
object obj2;
if (!string.IsNullOrEmpty(levelCosmeticInfo.planePath))
{
GameObject obj = GameObject.Find(levelCosmeticInfo.planePath);
obj2 = ((obj != null) ? obj.transform : null);
}
else
{
obj2 = null;
}
Transform val3 = (Transform)obj2;
object obj4;
if (!string.IsNullOrEmpty(levelCosmeticInfo.framePath))
{
GameObject obj3 = GameObject.Find(levelCosmeticInfo.framePath);
obj4 = ((obj3 != null) ? obj3.transform : null);
}
else
{
obj4 = null;
}
Transform val4 = (Transform)obj4;
if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || (!string.IsNullOrEmpty(levelCosmeticInfo.planePath) && (Object)(object)val3 == (Object)null) || (!string.IsNullOrEmpty(levelCosmeticInfo.framePath) && (Object)(object)val4 == (Object)null))
{
Plugin.Logger.LogWarning((object)"\"FancyEntranceDoors\" skipped because some GameObjects were missing.");
return;
}
GameObject val5 = null;
try
{
AssetBundle obj5 = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "fancyentrancedoors"));
val5 = obj5.LoadAsset<GameObject>("WideDoorFrame");
obj5.Unload(false);
}
catch
{
Plugin.Logger.LogError((object)"Encountered some error loading assets from bundle \"fancyentrancedoors\". Did you install the plugin correctly?");
return;
}
if ((Object)(object)val5 == (Object)null)
{
Plugin.Logger.LogWarning((object)"\"FancyEntranceDoors\" skipped because fancy door asset was missing.");
return;
}
if ((Object)(object)RoundManager.Instance.mapPropsContainer == (Object)null)
{
RoundManager.Instance.mapPropsContainer = GameObject.FindGameObjectWithTag("MapPropsContainer");
}
if ((Object)(object)RoundManager.Instance.mapPropsContainer == (Object)null)
{
Plugin.Logger.LogWarning((object)"\"FancyEntranceDoors\" skipped because disposable prop container did not exist in scene.");
return;
}
val.SetActive(false);
val2.SetActive(false);
Transform transform = Object.Instantiate<GameObject>(val5, levelCosmeticInfo.fancyDoorPos, levelCosmeticInfo.fancyDoorRot, RoundManager.Instance.mapPropsContainer.transform).transform;
if (levelCosmeticInfo.fancyDoorScalar != Vector3.one)
{
transform.localScale = Vector3.Scale(transform.localScale, levelCosmeticInfo.fancyDoorScalar);
}
if ((Object)(object)val4 != (Object)null)
{
val4.localScale = new Vector3(val4.localScale.x, val4.localScale.y + 0.05f, val4.localScale.z);
}
if ((Object)(object)val3 != (Object)null)
{
val3.localPosition += levelCosmeticInfo.planeOffset;
val3.localScale = new Vector3(val3.localScale.x + 0.047f, val3.localScale.y, val3.localScale.z + 0.237f);
}
}
private static void RetextureCaverns(CavernType type)
{
//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
//IL_01df: Unknown result type (might be due to invalid IL or missing references)
string text = type.ToString().ToLower() + "cave";
Material val = null;
Material val2 = null;
try
{
AssetBundle obj = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), text));
val = obj.LoadAsset<Material>("CaveRocks1");
val2 = obj.LoadAsset<Material>("CoalMat");
obj.Unload(false);
}
catch
{
Plugin.Logger.LogError((object)("Encountered some error loading assets from bundle \"" + text + "\". Did you install the plugin correctly?"));
}
if ((Object)(object)val == (Object)null)
{
Plugin.Logger.LogWarning((object)"Skipping mineshaft retexture because there was an error loading the replacement material.");
return;
}
GameObject val3 = GameObject.Find("/Systems/LevelGeneration/LevelGenerationRoot");
if ((Object)(object)val3 == (Object)null)
{
Plugin.Logger.LogWarning((object)"Skipping mineshaft retexture because there was an error finding the dungeon object tree.");
return;
}
VanillaLevelsInfo.predefinedCaverns.TryGetValue(type, out var value);
if (value == null)
{
Plugin.Logger.LogWarning((object)"Skipping mineshaft retexture because there was an error finding cavern specifications.");
return;
}
Renderer[] componentsInChildren = val3.GetComponentsInChildren<Renderer>();
foreach (Renderer val4 in componentsInChildren)
{
if (((Object)val4).name == "MineshaftStartTileMesh")
{
Material[] materials = val4.materials;
materials[3] = val;
val4.materials = materials;
}
else
{
if (!((Object)(object)val4.sharedMaterial != (Object)null))
{
continue;
}
if (((Object)val4.sharedMaterial).name.StartsWith(((Object)val).name))
{
val4.material = val;
if (((Component)val4).CompareTag("Rock") && !string.IsNullOrEmpty(value.tag))
{
((Component)val4).tag = value.tag;
}
}
else if (value.waterColor && ((Object)val4).name == "Water (1)" && ((Object)val4.sharedMaterial).name.StartsWith("CaveWater"))
{
val4.material.SetColor("Color_6a9a916e2c84442984edc20c082efe79", value.waterColor1);
val4.sharedMaterial.SetColor("Color_c9a840f2115c4802ba54d713194f761d", value.waterColor2);
}
else if ((Object)(object)val2 != (Object)null && ((Object)val4.sharedMaterial).name.StartsWith(((Object)val2).name))
{
val4.material = val2;
}
}
}
if (!value.noDrips)
{
return;
}
LocalPropSet[] componentsInChildren2 = val3.GetComponentsInChildren<LocalPropSet>();
foreach (LocalPropSet val5 in componentsInChildren2)
{
if (((Object)val5).name.StartsWith("WaterDrips"))
{
((Component)val5).gameObject.SetActive(false);
Plugin.Logger.LogDebug((object)"Disabled water drips");
}
}
}
internal static void SetupCompatibility()
{
if (((Object)StartOfRound.Instance.currentLevel).name == "ArtificeLevel" && Chainloader.PluginInfos.ContainsKey("butterystancakes.lethalcompany.artificeblizzard"))
{
artificeBlizzard = GameObject.Find("/Systems/Audio/BlizzardAmbience");
if ((Object)(object)artificeBlizzard != (Object)null)
{
Plugin.Logger.LogInfo((object)"Artifice Blizzard compatibility success");
}
}
}
private static bool IsSnowLevel()
{
if (StartOfRound.Instance.currentLevel.levelIncludesSnowFootprints)
{
if (!((Object)(object)artificeBlizzard == (Object)null))
{
return artificeBlizzard.activeSelf;
}
return true;
}
return false;
}
internal static void BuildWeightLists()
{
//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_010a: Unknown result type (might be due to invalid IL or missing references)
//IL_011c: Expected O, but got Unknown
mineshaftWeightLists.Clear();
Plugin.Logger.LogInfo((object)"List of all indexed moons (Use this to set up your config!):");
SelectableLevel[] levels = StartOfRound.Instance.levels;
foreach (SelectableLevel val in levels)
{
if (((Object)val).name != "CompanyBuildingLevel")
{
Plugin.Logger.LogInfo((object)("\"" + ((Object)val).name + "\""));
}
}
Plugin.Logger.LogDebug((object)"Now assembling final weighted lists");
levels = StartOfRound.Instance.levels;
foreach (SelectableLevel level in levels)
{
if (((Object)level).name == "CompanyBuildingLevel")
{
continue;
}
try
{
List<IntWithRarity> list = new List<IntWithRarity>();
foreach (Configuration.MoonCavernMapping item in Configuration.mappings.Where((Configuration.MoonCavernMapping x) => ((Object)level).name.ToLower().StartsWith(x.moon)))
{
list.Add(new IntWithRarity
{
id = (int)item.type,
rarity = item.weight
});
Plugin.Logger.LogDebug((object)$"{((Object)level).name} - {item.type} @ {item.weight}");
}
if (list.Count > 0)
{
mineshaftWeightLists.Add(((Object)level).name, list.ToArray());
}
}
catch
{
Plugin.Logger.LogError((object)"Failed to finish assembling weighted lists. If you are encountering this error, it's likely there is a problem with your config - look for warnings further up in your log!");
}
}
}
private static void ColorDoorLight(LevelCosmeticInfo levelCosmeticInfo)
{
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Invalid comparison between Unknown and I4
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
SpriteRenderer val = ((IEnumerable<SpriteRenderer>)Object.FindObjectsOfType<SpriteRenderer>()).FirstOrDefault((Func<SpriteRenderer, bool>)((SpriteRenderer spriteRenderer) => ((Object)spriteRenderer).name == "LightBehindDoor"));
if ((Object)(object)val != (Object)null)
{
if ((int)StartOfRound.Instance.currentLevel.currentWeather == 5)
{
val.color = DoorLightPalette.ECLIPSE_BACKGROUND;
}
else if (IsSnowLevel())
{
val.color = DoorLightPalette.BLIZZARD_BACKGROUND;
}
else if (levelCosmeticInfo != null)
{
val.color = levelCosmeticInfo.doorLightColor;
}
else
{
Plugin.Logger.LogDebug((object)"Could not recolor door light - No information exists for the current level (Are you playing a custom moon?)");
}
}
else
{
Plugin.Logger.LogDebug((object)"Could not recolor door light - GameObject \"LightBehindDoor\" was not found (Are you playing a custom interior?)");
}
}
internal static void ShutdownBreakerBox()
{
if ((Object)(object)breakerLightOff != (Object)null)
{
BreakerBox val = Object.FindObjectOfType<BreakerBox>();
if (!((Object)(object)val != (Object)null))
{
return;
}
Transform val2 = ((Component)val).transform.Find("Light");
Renderer component = ((Component)val2).GetComponent<Renderer>();
if ((Object)(object)component != (Object)null)
{
Material[] sharedMaterials = component.sharedMaterials;
if (sharedMaterials.Length != 2)
{
Plugin.Logger.LogWarning((object)"Breaker box materials are different than expected. Is this a custom interior?");
return;
}
sharedMaterials[1] = breakerLightOff;
component.sharedMaterials = sharedMaterials;
Transform obj = val2.Find("RedLight");
if (obj != null)
{
GameObject gameObject = ((Component)obj).gameObject;
if (gameObject != null)
{
gameObject.SetActive(false);
}
}
if ((Object)(object)val.breakerBoxHum != (Object)null)
{
val.breakerBoxHum.Stop();
val.breakerBoxHum.mute = true;
}
}
Plugin.Logger.LogDebug((object)"Breaker box light was turned off");
}
else
{
Plugin.Logger.LogWarning((object)"Can't disable breaker box light because material is missing. Asset bundle(s) were likely installed incorrectly");
}
}
private static void SetUpManorWindows()
{
windowTiles.Clear();
if ((Object)(object)fakeWindowOff == (Object)null)
{
Plugin.Logger.LogWarning((object)"Skipping window caching because the asset bundle materials failed to load.");
return;
}
GameObject val = GameObject.Find("/Systems/LevelGeneration/LevelGenerationRoot");
if ((Object)(object)val == (Object)null)
{
Plugin.Logger.LogWarning((object)"Skipping manor search because there was an error finding the dungeon object tree.");
return;
}
Renderer[] componentsInChildren = val.GetComponentsInChildren<Renderer>();
foreach (Renderer val2 in componentsInChildren)
{
if (!(((Object)val2).name == "mesh") || val2.sharedMaterials.Length <= 5)
{
continue;
}
Material obj = val2.sharedMaterials[5];
if (((obj != null) ? ((Object)obj).name : null) == "FakeWindowView")
{
if ((Object)(object)fakeWindowOn == (Object)null)
{
fakeWindowOn = val2.sharedMaterials[5];
fakeWindowOff.mainTexture = fakeWindowOn.GetTexture("_EmissiveColorMap");
}
Transform obj2 = ((Component)val2).transform.parent.Find("ScreenLight");
Light val3 = ((obj2 != null) ? ((Component)obj2).GetComponent<Light>() : null);
if ((Object)(object)val3 != (Object)null)
{
windowTiles.Add((val2, val3));
Plugin.Logger.LogDebug((object)"Cached window tile instance");
}
}
}
if (windowTiles.Count > 0)
{
windowsInManor = true;
BreakerBox val4 = Object.FindObjectOfType<BreakerBox>();
if ((Object)(object)val4 != (Object)null && val4.leversSwitchedOff > 0)
{
ToggleAllWindows(powered: false);
}
}
}
internal static void ToggleAllWindows(bool powered)
{
if (!windowsInManor || windowTiles.Count < 1 || (Object)(object)fakeWindowOn == (Object)null || (Object)(object)fakeWindowOff == (Object)null)
{
return;
}
foreach (var windowTile in windowTiles)
{
Material[] sharedMaterials = windowTile.room.sharedMaterials;
sharedMaterials[5] = (powered ? fakeWindowOn : fakeWindowOff);
windowTile.room.sharedMaterials = sharedMaterials;
((Behaviour)windowTile.light).enabled = powered;
}
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "Chameleon";
public const string PLUGIN_NAME = "Chameleon";
public const string PLUGIN_VERSION = "1.2.2";
}
}
namespace Chameleon.Info
{
internal enum CavernType
{
Vanilla = -1,
Ice,
Amethyst,
Desert,
Mesa,
Gravel
}
internal class CavernInfo
{
internal string tag = string.Empty;
internal bool waterColor;
internal Color waterColor1 = new Color(0.3018868f, 0.24540168f, 0.22926308f, 0.972549f);
internal Color waterColor2 = new Color(27f / 106f, 0.2132654f, 0.17181382f, 84f / 85f);
internal bool noDrips;
}
internal static class DoorLightPalette
{
internal static readonly Color WITCHES_BACKGROUND = new Color(0.4901961f, 0.4693464f, 32f / 85f);
internal static readonly Color BLIZZARD_BACKGROUND = new Color(0.4845f, 0.4986666f, 0.51f);
internal static readonly Color AMETHYST_BACKGROUND = new Color(0.4901961f, 0.3714178f, 0.3578431f);
internal static readonly Color ECLIPSE_BACKGROUND = new Color(0.4901961f, 0.3336095f, 23f / 102f);
}
internal class LevelCosmeticInfo
{
internal string fakeDoor1Path = "/Environment/SteelDoorFake";
internal string fakeDoor2Path = "/Environment/SteelDoorFake (1)";
internal string framePath = "/Environment/DoorFrame (1)";
internal string planePath = "/Environment/Plane";
internal Vector3 fancyDoorPos;
internal Quaternion fancyDoorRot;
internal Vector3 fancyDoorScalar = Vector3.one;
internal Vector3 planeOffset = new Vector3(0f, -1f, 0f);
internal Color doorLightColor = new Color(0.490566f, 0.4165709f, 0.3355286f);
}
internal static class VanillaLevelsInfo
{
internal static Dictionary<string, LevelCosmeticInfo> predefinedLevels = new Dictionary<string, LevelCosmeticInfo>
{
{
"ExperimentationLevel",
new LevelCosmeticInfo
{
fakeDoor1Path = "/Environment/SteelDoor (6)",
fakeDoor2Path = "/Environment/SteelDoor (5)",
framePath = string.Empty,
planePath = string.Empty,
fancyDoorPos = new Vector3(-113.911f, 2.895f, -17.67f),
fancyDoorRot = Quaternion.Euler(-90f, 0f, 0f),
fancyDoorScalar = new Vector3(1f, 1.07f, 1f)
}
},
{
"AssuranceLevel",
new LevelCosmeticInfo
{
fancyDoorPos = new Vector3(135.249f, 6.452f, 74.49f),
fancyDoorRot = Quaternion.Euler(-90f, 180f, 0f),
planeOffset = new Vector3(0.075f, -1f, 0f)
}
},
{
"VowLevel",
new LevelCosmeticInfo
{
fancyDoorPos = new Vector3(-29.279f, -1.176f, 151.069f),
fancyDoorRot = Quaternion.Euler(-90f, 90f, 0f),
planeOffset = new Vector3(0.075f, -1f, 0f)
}
},
{
"OffenseLevel",
new LevelCosmeticInfo
{
fancyDoorPos = new Vector3(128.936f, 16.35f, -53.713f),
fancyDoorRot = Quaternion.Euler(-90f, 180f, -73.621f),
planeOffset = new Vector3(0f, -1f, -0.075f)
}
},
{
"MarchLevel",
new LevelCosmeticInfo
{
fancyDoorPos = new Vector3(-158.18f, -3.953f, 21.708f),
fancyDoorRot = Quaternion.Euler(-90f, 0f, 0f),
planeOffset = new Vector3(0f, -1f, -0.075f)
}
},
{
"AdamanceLevel",
new LevelCosmeticInfo
{
fakeDoor1Path = "/Environment/Teleports/EntranceTeleportA/SteelDoorFake",
fakeDoor2Path = "/Environment/Teleports/EntranceTeleportA/SteelDoorFake (1)",
framePath = "/Environment/Teleports/EntranceTeleportA/DoorFrame (1)",
planePath = "/Environment/Teleports/EntranceTeleportA/Plane",
fancyDoorPos = new Vector3(-122.032f, 1.843f, -3.617f),
fancyDoorRot = Quaternion.Euler(-90f, 0f, 0f),
planeOffset = new Vector3(-0.0033637f, -0.069986f, -1.0246016f),
doorLightColor = DoorLightPalette.WITCHES_BACKGROUND
}
},
{
"EmbrionLevel",
new LevelCosmeticInfo
{
fancyDoorPos = new Vector3(-195.47f, 6.357f, -7.83f),
fancyDoorRot = Quaternion.Euler(-90f, 0f, 39.517f),
planeOffset = new Vector3(-0.045f, -1f, -0.05513f),
doorLightColor = DoorLightPalette.AMETHYST_BACKGROUND
}
},
{
"RendLevel",
new LevelCosmeticInfo
{
fancyDoorPos = new Vector3(50.545f, -16.822502f, -152.71658f),
fancyDoorRot = Quaternion.Euler(-90f, 180f, 64.342f),
doorLightColor = DoorLightPalette.BLIZZARD_BACKGROUND
}
},
{
"DineLevel",
new LevelCosmeticInfo
{
fancyDoorPos = new Vector3(-120.70987f, -16.337002f, -4.2681026f),
fancyDoorRot = Quaternion.Euler(-90f, 0f, 90.836f),
doorLightColor = DoorLightPalette.BLIZZARD_BACKGROUND
}
},
{
"TitanLevel",
new LevelCosmeticInfo
{
fancyDoorPos = new Vector3(-35.877f, 47.64f, 8.939f),
fancyDoorRot = Quaternion.Euler(-90f, 0f, 35.333f),
planeOffset = new Vector3(0.03f, -1f, 0.036f),
doorLightColor = DoorLightPalette.BLIZZARD_BACKGROUND
}
},
{
"ArtificeLevel",
new LevelCosmeticInfo
{
fakeDoor1Path = "/Environment/MainFactory/SteelDoorFake",
fakeDoor2Path = "/Environment/MainFactory/SteelDoorFake (1)",
framePath = "/Environment/MainFactory/DoorFrame (1)",
planePath = "/Environment/MainFactory/Plane",
fancyDoorPos = new Vector3(52.32f, -0.665f, -156.146f),
fancyDoorRot = Quaternion.Euler(-90f, -90f, 0f)
}
}
};
internal static Dictionary<CavernType, CavernInfo> predefinedCaverns = new Dictionary<CavernType, CavernInfo>
{
{
CavernType.Ice,
new CavernInfo
{
tag = "Snow",
waterColor = true,
waterColor1 = new Color(0f, 0.18982977f, 0.20754719f, 0.972549f),
waterColor2 = new Color(0.12259702f, 0.1792453f, 0.16491137f, 84f / 85f)
}
},
{
CavernType.Amethyst,
new CavernInfo
{
noDrips = true,
waterColor = true,
waterColor1 = new Color(0.2509804f, 0.2627451f, 0.2784314f, 0.972549f),
waterColor2 = new Color(14f / 85f, 0.14901961f, 0.17254902f, 84f / 85f)
}
},
{
CavernType.Desert,
new CavernInfo()
},
{
CavernType.Mesa,
new CavernInfo
{
tag = "Gravel"
}
},
{
CavernType.Gravel,
new CavernInfo
{
tag = "Gravel",
waterColor = true,
waterColor1 = new Color(0.2f, 0.2f, 0.2f, 0.972549f),
waterColor2 = new Color(0.15f, 0.15f, 0.15f, 84f / 85f)
}
}
};
}
}