using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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 HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
using Microsoft.CodeAnalysis;
using Unity.AI.Navigation;
using UnityEngine;
using UnityEngine.AI;
using com.github.zehsteam.HalloweenTheme.Data;
using com.github.zehsteam.HalloweenTheme.Dependencies;
using com.github.zehsteam.HalloweenTheme.Patches;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.zehsteam.HalloweenTheme")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Reskin mod for vanilla moons and scrap.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("HalloweenTheme")]
[assembly: AssemblyTitle("com.github.zehsteam.HalloweenTheme")]
[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 com.github.zehsteam.HalloweenTheme
{
internal static class ConfigHelper
{
public static void SetModIcon(Sprite sprite)
{
if (LethalConfigProxy.Enabled)
{
LethalConfigProxy.SetModIcon(sprite);
}
}
public static void SetModDescription(string description)
{
if (LethalConfigProxy.Enabled)
{
LethalConfigProxy.SetModDescription(description);
}
}
public static void SkipAutoGen()
{
if (LethalConfigProxy.Enabled)
{
LethalConfigProxy.SkipAutoGen();
}
}
public static ConfigEntry<T> Bind<T>(string section, string key, T defaultValue, bool requiresRestart, string description, AcceptableValueBase acceptableValues = null, Action<T> settingChanged = null, ConfigFile configFile = null)
{
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Expected O, but got Unknown
if (configFile == null)
{
configFile = ((BaseUnityPlugin)Plugin.Instance).Config;
}
ConfigEntry<T> configEntry = ((acceptableValues == null) ? configFile.Bind<T>(section, key, defaultValue, description) : configFile.Bind<T>(section, key, defaultValue, new ConfigDescription(description, acceptableValues, Array.Empty<object>())));
if (settingChanged != null)
{
configEntry.SettingChanged += delegate
{
settingChanged?.Invoke(configEntry.Value);
};
}
if (LethalConfigProxy.Enabled)
{
if (acceptableValues == null)
{
LethalConfigProxy.AddConfig<T>(configEntry, requiresRestart);
}
else
{
LethalConfigProxy.AddConfigSlider<T>(configEntry, requiresRestart);
}
}
return configEntry;
}
public static void AddButton(string section, string name, string description, string buttonText, Action callback)
{
if (LethalConfigProxy.Enabled)
{
LethalConfigProxy.AddButton(section, name, description, buttonText, callback);
}
}
}
internal class ConfigManager
{
public ConfigEntry<bool> ExtendedLogging;
public ConfigManager()
{
BindConfigs();
ClearUnusedEntries();
}
private void BindConfigs()
{
ConfigHelper.SkipAutoGen();
ExtendedLogging = ConfigHelper.Bind("General Settings", "ExtendedLogging", defaultValue: false, requiresRestart: false, "Enable extended logging.");
}
private void ClearUnusedEntries()
{
ConfigFile config = ((BaseUnityPlugin)Plugin.Instance).Config;
PropertyInfo property = ((object)config).GetType().GetProperty("OrphanedEntries", BindingFlags.Instance | BindingFlags.NonPublic);
Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)property.GetValue(config, null);
dictionary.Clear();
config.Save();
}
}
internal static class Content
{
public static HalloweenAssets HalloweenAssets;
public static void Load()
{
LoadAssetsFromAssetBundle();
}
private static void LoadAssetsFromAssetBundle()
{
try
{
string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)Plugin.Instance).Info.Location);
string text = Path.Combine(directoryName, "halloweentheme_assets");
AssetBundle val = AssetBundle.LoadFromFile(text);
HalloweenAssets = val.LoadAsset<HalloweenAssets>("HalloweenAssets");
if ((Object)(object)HalloweenAssets == (Object)null)
{
throw new NullReferenceException();
}
Plugin.logger.LogInfo((object)"Successfully loaded assets from AssetBundle!");
}
catch (Exception arg)
{
Plugin.logger.LogError((object)$"Failed to load assets from AssetBundle.\n\n{arg}");
}
}
}
internal static class LevelHelper
{
private static bool _spawnedHalloweenLevelPrefab;
public static string PlanetName => StartOfRound.Instance.currentLevel.PlanetName;
public static void Reset()
{
_spawnedHalloweenLevelPrefab = false;
}
public static void OnLevelLoaded()
{
if (!_spawnedHalloweenLevelPrefab)
{
_spawnedHalloweenLevelPrefab = true;
SpawnHalloweenLevelPrefab();
}
}
private static void SpawnHalloweenLevelPrefab()
{
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
LevelData levelData = GetLevelData();
if (levelData != null && !((Object)(object)levelData.LevelPrefab == (Object)null))
{
GameObject val = Object.Instantiate<GameObject>(levelData.LevelPrefab);
val.transform.SetPositionAndRotation(Vector3.zero, Quaternion.identity);
Plugin.Instance.LogInfoExtended("Spawned halloween level prefab \"" + ((Object)levelData.LevelPrefab).name + "\".");
}
}
public static LevelData GetLevelData()
{
foreach (LevelData levelData in Content.HalloweenAssets.LevelDataList)
{
if (levelData.PlanetName == PlanetName)
{
return levelData;
}
}
return null;
}
public static EntranceTeleport GetEntranceTeleport(int entranceId, bool isEntranceToBuilding = true)
{
EntranceTeleport[] array = Object.FindObjectsByType<EntranceTeleport>((FindObjectsSortMode)0);
foreach (EntranceTeleport val in array)
{
if ((!isEntranceToBuilding || val.isEntranceToBuilding) && val.entranceId == entranceId)
{
return val;
}
}
return null;
}
}
[BepInPlugin("com.github.zehsteam.HalloweenTheme", "HalloweenTheme", "1.0.0")]
internal class Plugin : BaseUnityPlugin
{
private readonly Harmony harmony = new Harmony("com.github.zehsteam.HalloweenTheme");
internal static Plugin Instance;
internal static ManualLogSource logger;
internal static ConfigManager ConfigManager;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
logger = Logger.CreateLogSource("com.github.zehsteam.HalloweenTheme");
logger.LogInfo((object)"HalloweenTheme has awoken!");
harmony.PatchAll(typeof(StartOfRoundPatch));
harmony.PatchAll(typeof(RoundManagerPatch));
ConfigManager = new ConfigManager();
Content.Load();
}
public void OnLevelLoaded()
{
LevelHelper.OnLevelLoaded();
}
public void OnShipHasLeft()
{
LevelHelper.Reset();
}
public void OnLocalDisconnect()
{
LevelHelper.Reset();
}
public void LogInfoExtended(object data)
{
if (ConfigManager.ExtendedLogging.Value)
{
logger.LogInfo(data);
}
}
}
internal static class Utils
{
public static void DisableGameObject(string name)
{
GameObject val = GameObject.Find(name);
if ((Object)(object)val == (Object)null)
{
Plugin.logger.LogWarning((object)("Failed to disable GameObject \"" + name + "\". GameObject could not be found."));
}
else
{
val.SetActive(false);
}
}
public static void HideGameObject(string name, bool disableColliders = true)
{
GameObject val = GameObject.Find(name);
if ((Object)(object)val == (Object)null)
{
Plugin.logger.LogWarning((object)("Failed to hide GameObject \"" + name + "\". GameObject could not be found."));
}
else
{
HideGameObject(val, disableColliders);
}
}
public static void HideGameObject(GameObject gameObject, bool disableColliders = true)
{
if ((Object)(object)gameObject == (Object)null)
{
Plugin.logger.LogWarning((object)"Failed to hide GameObject. GameObject could not be found.");
return;
}
Renderer[] componentsInChildren = gameObject.GetComponentsInChildren<Renderer>();
foreach (Renderer val in componentsInChildren)
{
val.enabled = false;
}
if (disableColliders)
{
DisableColliders(gameObject);
}
}
public static void DisableColliders(string name)
{
GameObject val = GameObject.Find(name);
if ((Object)(object)val == (Object)null)
{
Plugin.logger.LogWarning((object)("Failed to disable colliders on GameObject \"" + name + "\". GameObject could not be found."));
}
else
{
DisableColliders(val);
}
}
public static void DisableColliders(GameObject gameObject)
{
if ((Object)(object)gameObject == (Object)null)
{
Plugin.logger.LogWarning((object)"Failed to disable colliders on GameObject. GameObject is null.");
return;
}
Collider[] componentsInChildren = gameObject.GetComponentsInChildren<Collider>();
foreach (Collider val in componentsInChildren)
{
if (!IgnoreCollider(val))
{
val.enabled = false;
}
}
}
public static bool IgnoreCollider(Collider collider)
{
if (collider.isTrigger)
{
return true;
}
if (((Component)collider).gameObject.CompareTag("InteractTrigger"))
{
return true;
}
if (((Component)collider).gameObject.layer == LayerMask.GetMask(new string[1] { "InteractableObject" }))
{
return true;
}
if (((Component)collider).gameObject.layer == LayerMask.GetMask(new string[1] { "Trigger" }))
{
return true;
}
return false;
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "com.github.zehsteam.HalloweenTheme";
public const string PLUGIN_NAME = "HalloweenTheme";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace com.github.zehsteam.HalloweenTheme.Patches
{
[HarmonyPatch(typeof(RoundManager))]
internal static class RoundManagerPatch
{
[HarmonyPatch("FinishGeneratingNewLevelClientRpc")]
[HarmonyPostfix]
private static void FinishGeneratingNewLevelClientRpcPatch()
{
Plugin.Instance.OnLevelLoaded();
}
}
[HarmonyPatch(typeof(StartOfRound))]
internal static class StartOfRoundPatch
{
private static bool _replacedSpawnableOutsideObjects;
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void StartPatch()
{
ReplaceSpawnableOutsideObjects();
}
private static void ReplaceSpawnableOutsideObjects()
{
if (!_replacedSpawnableOutsideObjects)
{
_replacedSpawnableOutsideObjects = true;
SelectableLevel[] levels = StartOfRound.Instance.levels;
foreach (SelectableLevel selectableLevel in levels)
{
ReplaceSpawnableOutsideObjectsForLevel(selectableLevel);
}
}
}
private static void ReplaceSpawnableOutsideObjectsForLevel(SelectableLevel selectableLevel)
{
List<SpawnableOutsideObjectWithRarity> list = Content.HalloweenAssets.DefaultSpawnableOutsideObjects;
LevelData levelData = LevelHelper.GetLevelData();
if (levelData != null)
{
list = levelData.SpawnableOutsideObjects;
}
foreach (SpawnableOutsideObjectWithRarity item in list)
{
bool flag = false;
for (int i = 0; i < selectableLevel.spawnableOutsideObjects.Length; i++)
{
if (((Object)selectableLevel.spawnableOutsideObjects[i].spawnableObject).name == ((Object)item.spawnableObject).name)
{
flag = true;
selectableLevel.spawnableOutsideObjects[i] = item;
break;
}
}
if (!flag)
{
CollectionExtensions.AddItem<SpawnableOutsideObjectWithRarity>((IEnumerable<SpawnableOutsideObjectWithRarity>)selectableLevel.spawnableOutsideObjects, item);
Plugin.Instance.LogInfoExtended("Added missing SpawnableOutsideObject \"" + ((Object)item.spawnableObject).name + "\" to level \"" + selectableLevel.PlanetName + "\".");
}
}
Plugin.Instance.LogInfoExtended("Replaced SpawnableOutsideObjects for level \"" + selectableLevel.PlanetName + "\".");
}
[HarmonyPatch("ShipHasLeft")]
[HarmonyPostfix]
private static void ShipHasLeftPatch()
{
Plugin.Instance.OnShipHasLeft();
}
[HarmonyPatch("OnLocalDisconnect")]
[HarmonyPostfix]
private static void OnLocalDisconnectPatch()
{
Plugin.Instance.OnLocalDisconnect();
}
}
}
namespace com.github.zehsteam.HalloweenTheme.MonoBehaviours
{
public class CustomEntranceTeleport : MonoBehaviour
{
public bool IsEntranceToBuilding = true;
public int EntranceId;
public Transform EntrancePoint;
private void Start()
{
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
EntranceTeleport entranceTeleport = LevelHelper.GetEntranceTeleport(EntranceId, IsEntranceToBuilding);
if ((Object)(object)entranceTeleport == (Object)null)
{
Plugin.logger.LogError((object)$"Failed to set custom entrance teleport. EntranceTeleport is null. (EntranceId: {EntranceId}, IsEntranceToBuilding: {IsEntranceToBuilding})");
return;
}
((Component)entranceTeleport).transform.SetPositionAndRotation(((Component)this).transform.position, ((Component)this).transform.rotation);
((Component)entranceTeleport).transform.localScale = ((Component)this).transform.localScale;
entranceTeleport.entrancePoint.SetPositionAndRotation(EntrancePoint.position, EntrancePoint.rotation);
Utils.HideGameObject(((Component)this).gameObject);
Plugin.Instance.LogInfoExtended($"Successfully set custom entrance teleport. (EntranceId: {EntranceId}, IsEntranceToBuilding: {IsEntranceToBuilding})");
}
}
public class LevelManager : MonoBehaviour
{
public static LevelManager Instance;
public NavMeshData NavMeshData;
public GameObject BrightDayPrefab;
public string[] ObjectsToDisable = Array.Empty<string>();
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
}
private void Start()
{
DisableObjects();
SetNavMeshData();
SetBrightDay();
}
private void SetNavMeshData()
{
if (!((Object)(object)NavMeshData == (Object)null))
{
NavMeshSurface navMeshSurface = GetNavMeshSurface();
if ((Object)(object)navMeshSurface == (Object)null)
{
Plugin.logger.LogError((object)"Failed to set NavMeshData. NavMeshSurface is null.");
return;
}
navMeshSurface.navMeshData = NavMeshData;
navMeshSurface.BuildNavMesh();
Plugin.Instance.LogInfoExtended("Successfully set NavMeshData.");
}
}
private void DisableObjects()
{
if (ObjectsToDisable.Length != 0)
{
string[] objectsToDisable = ObjectsToDisable;
foreach (string name in objectsToDisable)
{
Utils.DisableGameObject(name);
}
}
}
private void SetBrightDay()
{
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)BrightDayPrefab == (Object)null)
{
return;
}
GameObject val = GameObject.Find("Environment/Lighting");
if ((Object)(object)val == (Object)null)
{
Plugin.logger.LogError((object)"Failed to set bright day prefab. Lighting GameObject could not be found.");
return;
}
GameObject gameObject = ((Component)val.transform.Find("BrightDay")).gameObject;
if ((Object)(object)gameObject == (Object)null)
{
Plugin.logger.LogError((object)"Failed to set bright day prefab. BrightDay GameObject could not be found.");
return;
}
gameObject.SetActive(false);
GameObject val2 = Object.Instantiate<GameObject>(BrightDayPrefab, val.transform);
val2.transform.SetPositionAndRotation(Vector3.zero, Quaternion.identity);
Plugin.Instance.LogInfoExtended("Set BrightDay from prefab.");
}
private static NavMeshSurface GetNavMeshSurface()
{
try
{
return GameObject.Find("Environment").GetComponentInChildren<NavMeshSurface>();
}
catch (Exception arg)
{
Plugin.logger.LogError((object)$"Failed to get NavMeshSurface.\n\n{arg}");
}
return null;
}
}
}
namespace com.github.zehsteam.HalloweenTheme.Dependencies
{
internal static class LethalConfigProxy
{
public const string PLUGIN_GUID = "ainavt.lc.lethalconfig";
public static bool Enabled => Chainloader.PluginInfos.ContainsKey("ainavt.lc.lethalconfig");
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void SetModIcon(Sprite sprite)
{
LethalConfigManager.SetModIcon(sprite);
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void SetModDescription(string description)
{
LethalConfigManager.SetModDescription(description);
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void SkipAutoGen()
{
LethalConfigManager.SkipAutoGen();
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void AddConfig<T>(ConfigEntry<T> configEntry, bool requiresRestart = false)
{
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Expected O, but got Unknown
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Expected O, but got Unknown
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Expected O, but got Unknown
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Expected O, but got Unknown
if (!(configEntry is ConfigEntry<string> val))
{
if (!(configEntry is ConfigEntry<bool> val2))
{
if (!(configEntry is ConfigEntry<float> val3))
{
if (!(configEntry is ConfigEntry<int> val4))
{
throw new NotSupportedException($"Unsupported type: {typeof(T)}");
}
LethalConfigManager.AddConfigItem((BaseConfigItem)new IntInputFieldConfigItem(val4, requiresRestart));
}
else
{
LethalConfigManager.AddConfigItem((BaseConfigItem)new FloatInputFieldConfigItem(val3, requiresRestart));
}
}
else
{
LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(val2, requiresRestart));
}
}
else
{
LethalConfigManager.AddConfigItem((BaseConfigItem)new TextInputFieldConfigItem(val, requiresRestart));
}
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void AddConfigSlider<T>(ConfigEntry<T> configEntry, bool requiresRestart = false)
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Expected O, but got Unknown
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Expected O, but got Unknown
if (!(configEntry is ConfigEntry<float> val))
{
if (!(configEntry is ConfigEntry<int> val2))
{
throw new NotSupportedException($"Slider not supported for type: {typeof(T)}");
}
LethalConfigManager.AddConfigItem((BaseConfigItem)new IntSliderConfigItem(val2, requiresRestart));
}
else
{
LethalConfigManager.AddConfigItem((BaseConfigItem)new FloatSliderConfigItem(val, requiresRestart));
}
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void AddButton(string section, string name, string description, string buttonText, Action callback)
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Expected O, but got Unknown
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Expected O, but got Unknown
LethalConfigManager.AddConfigItem((BaseConfigItem)new GenericButtonConfigItem(section, name, description, buttonText, (GenericButtonHandler)delegate
{
callback?.Invoke();
}));
}
}
}
namespace com.github.zehsteam.HalloweenTheme.Data
{
[CreateAssetMenu(fileName = "HalloweenAssets", menuName = "HalloweenTheme/HalloweenAssets")]
public class HalloweenAssets : ScriptableObject
{
public List<LevelData> LevelDataList = new List<LevelData>();
public List<SpawnableOutsideObjectWithRarity> DefaultSpawnableOutsideObjects = new List<SpawnableOutsideObjectWithRarity>();
}
[Serializable]
public class LevelData
{
public string PlanetName;
public GameObject LevelPrefab;
public List<SpawnableOutsideObjectWithRarity> SpawnableOutsideObjects = new List<SpawnableOutsideObjectWithRarity>();
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}