using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CustomOutsideObjects.Patches;
using HarmonyLib;
using LethalLevelLoader;
using LethalLib.Extras;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Custom Outside Objects")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Custom Outside Objects")]
[assembly: AssemblyCopyright("Copyright Spookybuddy 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("28f2f16b-6471-4c7e-b0a4-007e3a2450d4")]
[assembly: AssemblyFileVersion("1.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.1.0.0")]
namespace CustomOutsideObjects
{
public class BreakObject : MonoBehaviour
{
public List<GameObject> prefabs = new List<GameObject>();
private void OnTriggerEnter(Collider other)
{
//IL_0126: Unknown result type (might be due to invalid IL or missing references)
//IL_0131: Unknown result type (might be due to invalid IL or missing references)
//IL_0136: Unknown result type (might be due to invalid IL or missing references)
//IL_013b: Unknown result type (might be due to invalid IL or missing references)
//IL_013f: Unknown result type (might be due to invalid IL or missing references)
//IL_014a: Unknown result type (might be due to invalid IL or missing references)
//IL_014f: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: 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)
VehicleController val = default(VehicleController);
if (!((Component)other).TryGetComponent<VehicleController>(ref val) || !(((Vector3)(ref val.averageVelocity)).magnitude > 5f))
{
return;
}
if (prefabs.Count > 0)
{
int num = ((prefabs.Count > 1) ? ((int)(100f * Mathf.Abs(((Component)this).transform.position.y)) % prefabs.Count) : 0);
if ((Object)(object)prefabs[num] != (Object)null && num < prefabs.Count && num > -1)
{
Object.Instantiate<GameObject>(prefabs[num], ((Component)this).transform.parent.position, default(Quaternion), RoundManager.Instance.mapPropsContainer.transform);
}
else
{
CustomOutsideModBase.mls.LogError((object)$"{num} was either out of range or null!");
}
}
Object.Destroy((Object)(object)((Component)((Component)this).transform.parent).gameObject);
VehicleController obj = val;
Vector3 val2 = val.mainRigidbody.position - ((Component)this).transform.position;
obj.CarReactToObstacle(((Vector3)(ref val2)).normalized, ((Component)this).transform.position, Vector3.zero, (CarObstacleType)2, 1f, (EnemyAI)null, true);
}
}
internal class ConfigControl : SyncedInstance<ConfigControl>
{
public struct PerObjectConfig
{
public ConfigEntry<bool> cfgEnabled;
public ConfigEntry<bool> cfgExp;
public ConfigEntry<bool> cfgAss;
public ConfigEntry<bool> cfgVow;
public ConfigEntry<bool> cfgOff;
public ConfigEntry<bool> cfgMar;
public ConfigEntry<bool> cfgAda;
public ConfigEntry<bool> cfgRen;
public ConfigEntry<bool> cfgDin;
public ConfigEntry<bool> cfgTit;
public ConfigEntry<bool> cfgEmb;
public ConfigEntry<bool> cfgArt;
public CustomMoonConfig[] cfgCustomMoons;
internal bool Enabled
{
get
{
if (cfgEnabled.Value)
{
return true;
}
return false;
}
set
{
cfgEnabled.Value = value;
}
}
internal bool Exp
{
get
{
if (cfgExp != null)
{
return cfgExp.Value;
}
return false;
}
set
{
if (cfgExp != null)
{
cfgExp.Value = value;
}
}
}
internal bool Ass
{
get
{
if (cfgAss != null)
{
return cfgAss.Value;
}
return false;
}
set
{
if (cfgAss != null)
{
cfgAss.Value = value;
}
}
}
internal bool Vow
{
get
{
if (cfgVow != null)
{
return cfgVow.Value;
}
return false;
}
set
{
if (cfgVow != null)
{
cfgVow.Value = value;
}
}
}
internal bool Off
{
get
{
if (cfgOff != null)
{
return cfgOff.Value;
}
return false;
}
set
{
if (cfgOff != null)
{
cfgOff.Value = value;
}
}
}
internal bool Mar
{
get
{
if (cfgMar != null)
{
return cfgMar.Value;
}
return false;
}
set
{
if (cfgMar != null)
{
cfgMar.Value = value;
}
}
}
internal bool Ada
{
get
{
if (cfgAda != null)
{
return cfgAda.Value;
}
return false;
}
set
{
if (cfgAda != null)
{
cfgAda.Value = value;
}
}
}
internal bool Ren
{
get
{
if (cfgRen != null)
{
return cfgRen.Value;
}
return false;
}
set
{
if (cfgRen != null)
{
cfgRen.Value = value;
}
}
}
internal bool Din
{
get
{
if (cfgDin != null)
{
return cfgDin.Value;
}
return false;
}
set
{
if (cfgDin != null)
{
cfgDin.Value = value;
}
}
}
internal bool Tit
{
get
{
if (cfgTit != null)
{
return cfgTit.Value;
}
return false;
}
set
{
if (cfgTit != null)
{
cfgTit.Value = value;
}
}
}
internal bool Emb
{
get
{
if (cfgEmb != null)
{
return cfgEmb.Value;
}
return false;
}
set
{
if (cfgEmb != null)
{
cfgEmb.Value = value;
}
}
}
internal bool Art
{
get
{
if (cfgArt != null)
{
return cfgArt.Value;
}
return false;
}
set
{
if (cfgArt != null)
{
cfgArt.Value = value;
}
}
}
}
public struct CustomMoonConfig
{
public string MoonName;
public ConfigEntry<bool> cfgCustom;
internal bool Custom
{
get
{
if (cfgCustom != null)
{
return cfgCustom.Value;
}
return false;
}
set
{
if (cfgCustom != null)
{
cfgCustom.Value = value;
}
}
}
}
public struct Tagged
{
internal bool[] valid;
}
private readonly bool usingCustomMoons;
public PerObjectConfig[] allObjects;
public ConfigControl(ConfigFile cfg)
{
Tagged tagged = new Tagged
{
valid = new bool[CustomOutsideModBase.tags.Length]
};
if (CustomOutsideModBase.customMoonList != null || CustomOutsideModBase.customMoonList.Count > 0)
{
usingCustomMoons = true;
CustomOutsideModBase.mls.LogInfo((object)"Added custom moons to configs.");
}
else
{
usingCustomMoons = false;
CustomOutsideModBase.mls.LogInfo((object)"No custom moons were added to the config.");
}
allObjects = new PerObjectConfig[CustomOutsideModBase.loadedInjectableOutsideObjects.Count];
for (int i = 0; i < CustomOutsideModBase.loadedInjectableOutsideObjects.Count; i++)
{
for (int j = 0; j < tagged.valid.Length; j++)
{
tagged.valid[j] = false;
}
for (int k = 0; k < CustomOutsideModBase.loadedInjectableOutsideObjects[i].spawnableObject.spawnableFloorTags.Length; k++)
{
for (int l = 0; l < CustomOutsideModBase.tags.Length; l++)
{
if (CustomOutsideModBase.loadedInjectableOutsideObjects[i].spawnableObject.spawnableFloorTags[k].Equals(CustomOutsideModBase.tags[l]))
{
tagged.valid[l] = true;
break;
}
}
}
string name = ((Object)CustomOutsideModBase.loadedInjectableOutsideObjects[i].spawnableObject).name;
allObjects[i].cfgEnabled = cfg.Bind<bool>(name, "Enabled", true, "Prevent " + name + " from spawning entirely.");
if (tagged.valid[0])
{
allObjects[i].cfgExp = cfg.Bind<bool>(name, "Spawn on Experimentation", true, "Can spawn on Experimentation.");
}
if (tagged.valid[0])
{
allObjects[i].cfgAss = cfg.Bind<bool>(name, "Spawn on Assurance", true, "Can spawn on Assurance.");
}
if (tagged.valid[1] || tagged.valid[4])
{
allObjects[i].cfgVow = cfg.Bind<bool>(name, "Spawn on Vow", true, "Can spawn on Vow.");
}
if (tagged.valid[0])
{
allObjects[i].cfgOff = cfg.Bind<bool>(name, "Spawn on Offense", true, "Can spawn on Offense.");
}
if (tagged.valid[1])
{
allObjects[i].cfgMar = cfg.Bind<bool>(name, "Spawn on March", true, "Can spawn on March.");
}
if (tagged.valid[1] || tagged.valid[3])
{
allObjects[i].cfgAda = cfg.Bind<bool>(name, "Spawn on Adamance", true, "Can spawn on Adamance.");
}
if (tagged.valid[2])
{
allObjects[i].cfgRen = cfg.Bind<bool>(name, "Spawn on Rend", true, "Can spawn on Rend.");
}
if (tagged.valid[2])
{
allObjects[i].cfgDin = cfg.Bind<bool>(name, "Spawn on Dine", true, "Can spawn on Dine.");
}
if (tagged.valid[2] || tagged.valid[4] || tagged.valid[5])
{
allObjects[i].cfgTit = cfg.Bind<bool>(name, "Spawn on Titan", true, "Can spawn on Titan.");
}
if (tagged.valid[3] || tagged.valid[4])
{
allObjects[i].cfgEmb = cfg.Bind<bool>(name, "Spawn on Embrion", true, "Can spawn on Embrion.");
}
if (tagged.valid[1] || tagged.valid[4] || tagged.valid[5] || tagged.valid[6])
{
allObjects[i].cfgArt = cfg.Bind<bool>(name, "Spawn on Artifice", true, "Can spawn on Artifice.");
}
if (usingCustomMoons)
{
allObjects[i].cfgCustomMoons = new CustomMoonConfig[CustomOutsideModBase.customMoonList.Count];
for (int m = 0; m < CustomOutsideModBase.customMoonList.Count; m++)
{
string text = CustomOutsideModBase.customMoonList[m];
text = char.ToUpper(text[0]) + text.Substring(1);
allObjects[i].cfgCustomMoons[m].MoonName = text;
allObjects[i].cfgCustomMoons[m].cfgCustom = cfg.Bind<bool>(name, "Spawn on " + text, true, "Can spawn on " + text + ". \n\nNOTE!\nThis does not mean the Object will be able spawn, as the Object's tags may not match the environment's.");
}
}
}
}
}
[BepInPlugin("CustomOutsideObjects", "CustomOutsideObjects", "1.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class CustomOutsideModBase : BaseUnityPlugin
{
public const string modGUID = "CustomOutsideObjects";
private const string modName = "CustomOutsideObjects";
private const string modVersion = "1.1.0";
private readonly Harmony harmony = new Harmony("CustomOutsideObjects");
internal static CustomOutsideModBase Instance;
internal static ManualLogSource mls;
internal ConfigControl Configuration;
internal static string[] foundOutsideAssetFiles;
internal static AssetBundle currentAsset;
internal static SpawnableOutsideObjectDef[] currentAssetObjects;
internal static List<SpawnableOutsideObjectWithRarity> loadedInjectableOutsideObjects = new List<SpawnableOutsideObjectWithRarity>();
internal static List<string> customMoonList = new List<string>();
internal static readonly string[] tags = new string[7] { "Gravel", "Grass", "Snow", "Rock", "Concrete", "Catwalk", "Wood" };
internal static bool Set_Experimentation;
internal static bool Set_Assurance;
internal static bool Set_Vow;
internal static bool Set_Offense;
internal static bool Set_March;
internal static bool Set_Adamance;
internal static bool Set_Rend;
internal static bool Set_Dine;
internal static bool Set_Titan;
internal static bool Set_Embrion;
internal static bool Set_Artifice;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
mls = Logger.CreateLogSource("CustomOutsideObjects");
foundOutsideAssetFiles = Directory.GetFiles(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "*.coo");
if (foundOutsideAssetFiles != null && foundOutsideAssetFiles.Length != 0)
{
for (int i = 0; i < foundOutsideAssetFiles.Length; i++)
{
currentAsset = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), foundOutsideAssetFiles[i]));
if ((Object)(object)currentAsset != (Object)null)
{
currentAssetObjects = currentAsset.LoadAllAssets<SpawnableOutsideObjectDef>();
if (currentAssetObjects != null && currentAssetObjects.Length != 0)
{
GameObject[] array = currentAsset.LoadAllAssets<GameObject>();
for (int j = 0; j < currentAssetObjects.Length; j++)
{
if (currentAssetObjects[j].spawnableMapObject != null)
{
if (currentAssetObjects[j].spawnableMapObject.spawnableObject.prefabToSpawn.layer.Equals(25))
{
if (((Object)currentAssetObjects[j].spawnableMapObject.spawnableObject.prefabToSpawn.transform.GetChild(0)).name.Equals("BreakTrigger"))
{
((Component)currentAssetObjects[j].spawnableMapObject.spawnableObject.prefabToSpawn.transform.GetChild(0)).gameObject.AddComponent<TerrainObstacleTrigger>();
string name = ((Object)currentAssetObjects[j].spawnableMapObject.spawnableObject.prefabToSpawn).name;
if ((Object)(object)currentAssetObjects[j].spawnableMapObject.spawnableObject.prefabToSpawn.GetComponentInChildren<TerrainObstacleTrigger>() != (Object)null)
{
mls.LogInfo((object)("Added generic break trigger script to " + name + "!"));
}
else
{
mls.LogError((object)("Add generic break to " + name + " failed!"));
}
}
else
{
BreakObject breakObject = ((Component)currentAssetObjects[j].spawnableMapObject.spawnableObject.prefabToSpawn.transform.GetChild(0)).gameObject.AddComponent<BreakObject>();
string name2 = ((Object)currentAssetObjects[j].spawnableMapObject.spawnableObject.prefabToSpawn).name;
for (int k = 0; k < array.Length; k++)
{
if (((Object)array[k]).name.Contains(name2) && ((Object)array[k]).name.Contains("Break"))
{
breakObject.prefabs.Add(array[k]);
}
}
if ((Object)(object)currentAssetObjects[j].spawnableMapObject.spawnableObject.prefabToSpawn.GetComponentInChildren<BreakObject>() != (Object)null)
{
mls.LogInfo((object)("Added custom break trigger script to " + name2 + "!"));
}
else
{
mls.LogError((object)("Add custom break to " + name2 + " failed!"));
}
}
}
loadedInjectableOutsideObjects.Add(currentAssetObjects[j].spawnableMapObject);
mls.LogInfo((object)("Custom Outside Object added: " + ((Object)currentAssetObjects[j].spawnableMapObject.spawnableObject).name));
}
else
{
mls.LogWarning((object)$"Spawnable Rarity {currentAssetObjects[j]} found, but no Spawnable Map Object is attached.");
}
}
}
else
{
mls.LogWarning((object)("No Spawnable Map Object found in " + foundOutsideAssetFiles[i] + ".coo."));
}
}
else
{
mls.LogError((object)("Failed to load " + foundOutsideAssetFiles[i] + ".coo."));
}
}
if (loadedInjectableOutsideObjects.Count < 1 || loadedInjectableOutsideObjects == null)
{
mls.LogWarning((object)"No Custom Outside Objects were added.");
return;
}
string text = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location).ToString();
string[] array2 = text.Split(new char[1] { '\\' });
for (int num = array2.Length - 1; num > 0; num--)
{
if (array2[num].Equals("plugins"))
{
for (int l = 0; l < array2.Length - num - 1; l++)
{
text = Directory.GetParent(text).ToString();
}
array2 = Directory.GetFiles(text, "*.lethalbundle", SearchOption.AllDirectories);
string[] array3 = new string[array2.Length];
for (int m = 0; m < array2.Length; m++)
{
array3[m] = array2[m];
array2[m] = Path.GetFileNameWithoutExtension(array2[m]);
}
for (int n = 0; n < array2.Length - 1; n++)
{
for (int num2 = n + 1; num2 < array2.Length; num2++)
{
if (array2[num2].Contains(array2[n]))
{
if (array2[num2].Replace(array2[n], "").Equals("scene"))
{
customMoonList.Add(array2[n]);
}
else if (array2[num2].Replace(array2[n], "").Equals(" scene"))
{
customMoonList.Add(array2[n]);
}
else if (array2[num2].Replace(array2[n], "").Equals("scenes"))
{
AssetBundle val = AssetBundle.LoadFromFile(array3[n]);
ExtendedMod[] array4 = val.LoadAllAssets<ExtendedMod>();
List<ExtendedLevel> extendedLevels = array4[0].ExtendedLevels;
for (int num3 = 0; num3 < extendedLevels.Count; num3++)
{
string[] array5 = ((Object)extendedLevels[num3].SelectableLevel).name.Split(new string[4] { "level", "selectable", "Level", "Selectable" }, StringSplitOptions.RemoveEmptyEntries);
customMoonList.Add(array5[0]);
}
val.Unload(true);
}
continue;
}
if (array2[num2].Replace(array2[n].Replace("moon", ""), "").Equals("scene"))
{
customMoonList.Add(array2[n]);
}
if (array2[num2].Replace(array2[n].Replace("assets", ""), "").Equals("mod"))
{
AssetBundle val2 = AssetBundle.LoadFromFile(array3[num2]);
ExtendedMod[] array6 = val2.LoadAllAssets<ExtendedMod>();
List<ExtendedLevel> extendedLevels2 = array6[0].ExtendedLevels;
for (int num4 = 0; num4 < extendedLevels2.Count; num4++)
{
string[] array7 = ((Object)extendedLevels2[num4].SelectableLevel).name.Split(new string[4] { "level", "selectable", "Level", "Selectable" }, StringSplitOptions.RemoveEmptyEntries);
customMoonList.Add(array7[0]);
}
val2.Unload(true);
}
}
}
break;
}
}
for (int num5 = 0; num5 < customMoonList.Count; num5++)
{
mls.LogInfo((object)("Found custom moon " + customMoonList[num5] + "."));
}
Configuration = new ConfigControl(((BaseUnityPlugin)this).Config);
mls.LogInfo((object)"Generated Config file for all loaded objects.");
harmony.PatchAll(typeof(CustomOutsideModBase));
harmony.PatchAll(typeof(StartOfRoundPatch));
harmony.PatchAll(typeof(RoundManagerPatch));
mls.LogInfo((object)"Outside Objects loaded.");
}
else
{
mls.LogWarning((object)"No Custom Outside Objects were found.");
}
}
}
[Serializable]
public class SyncedInstance<T>
{
[NonSerialized]
protected static int IntSize = 4;
internal static CustomMessagingManager MessageManager => NetworkManager.Singleton.CustomMessagingManager;
internal static bool IsClient => NetworkManager.Singleton.IsClient;
internal static bool IsHost => NetworkManager.Singleton.IsHost;
public static T Default { get; private set; }
public static T Instance { get; private set; }
public static bool Synced { get; internal set; }
protected void InitInstance(T instance)
{
Default = instance;
Instance = instance;
IntSize = 4;
}
internal static void SyncInstance(byte[] data)
{
Instance = DeserializeFromBytes(data);
Synced = true;
}
internal static void RevertSync()
{
Instance = Default;
Synced = false;
}
public static byte[] SerializeToBytes(T val)
{
BinaryFormatter binaryFormatter = new BinaryFormatter();
MemoryStream memoryStream = new MemoryStream();
try
{
binaryFormatter.Serialize(memoryStream, val);
return memoryStream.ToArray();
}
catch (Exception arg)
{
CustomOutsideModBase.mls.LogError((object)$"Error serializing instance: {arg}");
return null;
}
}
public static T DeserializeFromBytes(byte[] data)
{
BinaryFormatter binaryFormatter = new BinaryFormatter();
MemoryStream serializationStream = new MemoryStream(data);
try
{
return (T)binaryFormatter.Deserialize(serializationStream);
}
catch (Exception arg)
{
CustomOutsideModBase.mls.LogError((object)$"Error deserializing instance: {arg}");
return default(T);
}
}
public static void RequestSync()
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
if (IsClient)
{
FastBufferWriter val = default(FastBufferWriter);
((FastBufferWriter)(ref val))..ctor(IntSize, (Allocator)2, -1);
MessageManager.SendNamedMessage("CustomOutsideObjects_OnRequestConfigSync", 0uL, val, (NetworkDelivery)3);
}
}
public static void OnRequestSync(ulong clientId, FastBufferReader _)
{
//IL_0053: 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_0077: Unknown result type (might be due to invalid IL or missing references)
if (!IsHost)
{
return;
}
CustomOutsideModBase.mls.LogInfo((object)$"Config sync request received from client: {clientId}");
byte[] array = SerializeToBytes(Instance);
int num = array.Length;
FastBufferWriter val = default(FastBufferWriter);
((FastBufferWriter)(ref val))..ctor(num + IntSize, (Allocator)2, -1);
try
{
((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num, default(ForPrimitives));
((FastBufferWriter)(ref val)).WriteBytesSafe(array, -1, 0);
MessageManager.SendNamedMessage("CustomOutsideObjects_OnReceiveConfigSync", clientId, val, (NetworkDelivery)3);
}
catch (Exception arg)
{
CustomOutsideModBase.mls.LogInfo((object)$"Error occurred syncing config with client: {clientId}\n{arg}");
}
}
public static void OnReceiveSync(ulong _, FastBufferReader reader)
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
if (!((FastBufferReader)(ref reader)).TryBeginRead(IntSize))
{
CustomOutsideModBase.mls.LogError((object)"Config sync error: Could not begin reading buffer.");
return;
}
int num = default(int);
((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num, default(ForPrimitives));
if (!((FastBufferReader)(ref reader)).TryBeginRead(num))
{
CustomOutsideModBase.mls.LogError((object)"Config sync error: Host could not sync.");
return;
}
byte[] data = new byte[num];
((FastBufferReader)(ref reader)).ReadBytesSafe(ref data, num, 0);
SyncInstance(data);
CustomOutsideModBase.mls.LogInfo((object)"Successfully synced config with host.");
}
[HarmonyPostfix]
[HarmonyPatch(typeof(GameNetworkManager), "SteamMatchmaking_OnLobbyMemberJoined")]
public static void InitializeLocalPlayer()
{
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Expected O, but got Unknown
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Expected O, but got Unknown
if (IsHost)
{
MessageManager.RegisterNamedMessageHandler("CustomOutsideObjects_OnRequestConfigSync", new HandleNamedMessageDelegate(OnRequestSync));
Synced = true;
}
else
{
Synced = false;
MessageManager.RegisterNamedMessageHandler("CustomOutsideObjects_OnReceiveConfigSync", new HandleNamedMessageDelegate(OnReceiveSync));
RequestSync();
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(GameNetworkManager), "StartDisconnect")]
public static void PlayerLeave()
{
SyncedInstance<ConfigControl>.RevertSync();
}
}
}
namespace CustomOutsideObjects.Patches
{
[HarmonyPatch(typeof(RoundManager))]
internal class RoundManagerPatch
{
[HarmonyPatch("SpawnOutsideHazards")]
[HarmonyPrefix]
private static void OutsideHazardPatch(ref SelectableLevel ___currentLevel)
{
string text = ___currentLevel.PlanetName.ToLower().Trim();
string text2 = ((Object)___currentLevel).name.ToLower().Trim();
string[] array = text.Split(new char[1] { ' ' });
string[] array2 = text2.Split(new string[2] { "level", "selectable" }, StringSplitOptions.RemoveEmptyEntries);
switch (array2[0])
{
case "experimentation":
if (CustomOutsideModBase.Set_Experimentation)
{
CustomOutsideModBase.mls.LogInfo((object)("Planet " + array2[0] + " was pre-loaded."));
return;
}
break;
case "assurance":
if (CustomOutsideModBase.Set_Assurance)
{
CustomOutsideModBase.mls.LogInfo((object)("Planet " + array2[0] + " was pre-loaded."));
return;
}
break;
case "vow":
if (CustomOutsideModBase.Set_Vow)
{
CustomOutsideModBase.mls.LogInfo((object)("Planet " + array2[0] + " was pre-loaded."));
return;
}
break;
case "offense":
if (CustomOutsideModBase.Set_Offense)
{
CustomOutsideModBase.mls.LogInfo((object)("Planet " + array2[0] + " was pre-loaded."));
return;
}
break;
case "march":
if (CustomOutsideModBase.Set_March)
{
CustomOutsideModBase.mls.LogInfo((object)("Planet " + array2[0] + " was pre-loaded."));
return;
}
break;
case "adamance":
if (CustomOutsideModBase.Set_Adamance)
{
CustomOutsideModBase.mls.LogInfo((object)("Planet " + array2[0] + " was pre-loaded."));
return;
}
break;
case "rend":
if (CustomOutsideModBase.Set_Rend)
{
CustomOutsideModBase.mls.LogInfo((object)("Planet " + array2[0] + " was pre-loaded."));
return;
}
break;
case "dine":
if (CustomOutsideModBase.Set_Dine)
{
CustomOutsideModBase.mls.LogInfo((object)("Planet " + array2[0] + " was pre-loaded."));
return;
}
break;
case "titan":
if (CustomOutsideModBase.Set_Titan)
{
CustomOutsideModBase.mls.LogInfo((object)("Planet " + array2[0] + " was pre-loaded."));
return;
}
break;
case "embrion":
if (CustomOutsideModBase.Set_Embrion)
{
CustomOutsideModBase.mls.LogInfo((object)("Planet " + array2[0] + " was pre-loaded."));
return;
}
break;
case "artifice":
if (CustomOutsideModBase.Set_Artifice)
{
CustomOutsideModBase.mls.LogInfo((object)("Planet " + array2[0] + " was pre-loaded."));
return;
}
break;
case "companybuilding":
return;
}
CustomOutsideModBase.mls.LogWarning((object)("Planet " + array2[0] + " was not pre-loaded. Adding assets now."));
List<SpawnableOutsideObjectWithRarity> list = new List<SpawnableOutsideObjectWithRarity>();
for (int i = 0; i < CustomOutsideModBase.loadedInjectableOutsideObjects.Count; i++)
{
if (!CustomOutsideModBase.Instance.Configuration.allObjects[i].Enabled)
{
continue;
}
switch (array2[0])
{
case "experimentation":
if (!CustomOutsideModBase.Instance.Configuration.allObjects[i].Exp)
{
continue;
}
break;
case "assurance":
if (!CustomOutsideModBase.Instance.Configuration.allObjects[i].Ass)
{
continue;
}
break;
case "vow":
if (!CustomOutsideModBase.Instance.Configuration.allObjects[i].Vow)
{
continue;
}
break;
case "offense":
if (!CustomOutsideModBase.Instance.Configuration.allObjects[i].Off)
{
continue;
}
break;
case "march":
if (!CustomOutsideModBase.Instance.Configuration.allObjects[i].Mar)
{
continue;
}
break;
case "adamance":
if (!CustomOutsideModBase.Instance.Configuration.allObjects[i].Ada)
{
continue;
}
break;
case "rend":
if (!CustomOutsideModBase.Instance.Configuration.allObjects[i].Ren)
{
continue;
}
break;
case "dine":
if (!CustomOutsideModBase.Instance.Configuration.allObjects[i].Din)
{
continue;
}
break;
case "titan":
if (!CustomOutsideModBase.Instance.Configuration.allObjects[i].Tit)
{
continue;
}
break;
case "embrion":
if (!CustomOutsideModBase.Instance.Configuration.allObjects[i].Emb)
{
continue;
}
break;
case "artifice":
if (!CustomOutsideModBase.Instance.Configuration.allObjects[i].Art)
{
continue;
}
break;
case "companybuilding":
return;
default:
{
for (int num = 0; num < CustomOutsideModBase.Instance.Configuration.allObjects[i].cfgCustomMoons.Length; num++)
{
for (int num2 = 0; num2 < array.Length; num2++)
{
if (CustomOutsideModBase.Instance.Configuration.allObjects[i].cfgCustomMoons[num].MoonName.ToLower().Equals(array[num2]) && !CustomOutsideModBase.Instance.Configuration.allObjects[i].cfgCustomMoons[num].Custom)
{
goto IL_0acc;
}
}
if (CustomOutsideModBase.Instance.Configuration.allObjects[i].cfgCustomMoons[num].MoonName.ToLower().Equals(array2[0]) && !CustomOutsideModBase.Instance.Configuration.allObjects[i].cfgCustomMoons[num].Custom)
{
goto IL_0acc;
}
}
break;
}
}
if (list.Contains(CustomOutsideModBase.loadedInjectableOutsideObjects[i]))
{
continue;
}
int num3 = 0;
while (true)
{
if (num3 < ___currentLevel.spawnableOutsideObjects.Length)
{
if (((object)___currentLevel.spawnableOutsideObjects[num3]).Equals((object?)CustomOutsideModBase.loadedInjectableOutsideObjects[i]) || ((Object)___currentLevel.spawnableOutsideObjects[num3].spawnableObject).name.ToLower().Equals(((Object)CustomOutsideModBase.loadedInjectableOutsideObjects[i].spawnableObject).name.ToLower()))
{
break;
}
num3++;
continue;
}
list.Add(CustomOutsideModBase.loadedInjectableOutsideObjects[i]);
CustomOutsideModBase.mls.LogInfo((object)("Added " + ((Object)CustomOutsideModBase.loadedInjectableOutsideObjects[i].spawnableObject).name + " as potential spawns."));
break;
}
IL_0acc:;
}
SpawnableOutsideObjectWithRarity[] spawnableOutsideObjects = ___currentLevel.spawnableOutsideObjects;
for (int j = 0; j < spawnableOutsideObjects.Length; j++)
{
list.Add(spawnableOutsideObjects[j]);
}
___currentLevel.spawnableOutsideObjects = list.ToArray();
for (int k = 0; k < ___currentLevel.spawnableOutsideObjects.Length; k++)
{
CustomOutsideModBase.mls.LogInfo((object)$"#{k}: {((Object)___currentLevel.spawnableOutsideObjects[k].spawnableObject).name}");
}
}
}
[HarmonyPatch(typeof(StartOfRound))]
internal class StartOfRoundPatch
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void StartPatch(StartOfRound __instance)
{
CustomOutsideModBase.mls.LogWarning((object)"Finding all levels...");
for (int i = 0; i < __instance.levels.Length; i++)
{
SelectableLevel val = __instance.levels[i];
string text = val.PlanetName.ToLower().Trim();
string text2 = ((Object)val).name.ToLower().Trim();
string[] array = text.Split(new char[1] { ' ' });
string[] array2 = text2.Split(new string[1] { "level" }, StringSplitOptions.RemoveEmptyEntries);
List<SpawnableOutsideObjectWithRarity> list = new List<SpawnableOutsideObjectWithRarity>();
for (int j = 0; j < CustomOutsideModBase.loadedInjectableOutsideObjects.Count; j++)
{
if (!CustomOutsideModBase.Instance.Configuration.allObjects[j].Enabled)
{
continue;
}
switch (array2[0])
{
case "experimentation":
if (!CustomOutsideModBase.Instance.Configuration.allObjects[j].Exp)
{
continue;
}
break;
case "assurance":
if (!CustomOutsideModBase.Instance.Configuration.allObjects[j].Ass)
{
continue;
}
break;
case "vow":
if (!CustomOutsideModBase.Instance.Configuration.allObjects[j].Vow)
{
continue;
}
break;
case "offense":
if (!CustomOutsideModBase.Instance.Configuration.allObjects[j].Off)
{
continue;
}
break;
case "march":
if (!CustomOutsideModBase.Instance.Configuration.allObjects[j].Mar)
{
continue;
}
break;
case "adamance":
if (!CustomOutsideModBase.Instance.Configuration.allObjects[j].Ada)
{
continue;
}
break;
case "rend":
if (!CustomOutsideModBase.Instance.Configuration.allObjects[j].Ren)
{
continue;
}
break;
case "dine":
if (!CustomOutsideModBase.Instance.Configuration.allObjects[j].Din)
{
continue;
}
break;
case "titan":
if (!CustomOutsideModBase.Instance.Configuration.allObjects[j].Tit)
{
continue;
}
break;
case "embrion":
if (!CustomOutsideModBase.Instance.Configuration.allObjects[j].Emb)
{
continue;
}
break;
case "artifice":
if (!CustomOutsideModBase.Instance.Configuration.allObjects[j].Art)
{
continue;
}
break;
default:
{
for (int num = 0; num < CustomOutsideModBase.Instance.Configuration.allObjects[j].cfgCustomMoons.Length; num++)
{
for (int num2 = 0; num2 < array.Length; num2++)
{
if (CustomOutsideModBase.Instance.Configuration.allObjects[j].cfgCustomMoons[num].MoonName.ToLower().Equals(array[num2]) && !CustomOutsideModBase.Instance.Configuration.allObjects[j].cfgCustomMoons[num].Custom)
{
goto IL_06b4;
}
}
if (CustomOutsideModBase.Instance.Configuration.allObjects[j].cfgCustomMoons[num].MoonName.ToLower().Equals(array2[0]) && !CustomOutsideModBase.Instance.Configuration.allObjects[j].cfgCustomMoons[num].Custom)
{
goto IL_06b4;
}
}
break;
}
case "companybuilding":
continue;
}
if (list.Contains(CustomOutsideModBase.loadedInjectableOutsideObjects[j]))
{
continue;
}
int num3 = 0;
while (true)
{
if (num3 < val.spawnableOutsideObjects.Length)
{
if (((object)val.spawnableOutsideObjects[num3]).Equals((object?)CustomOutsideModBase.loadedInjectableOutsideObjects[j]) || ((Object)val.spawnableOutsideObjects[num3].spawnableObject).name.ToLower().Equals(((Object)CustomOutsideModBase.loadedInjectableOutsideObjects[j].spawnableObject).name.ToLower()))
{
break;
}
num3++;
continue;
}
list.Add(CustomOutsideModBase.loadedInjectableOutsideObjects[j]);
CustomOutsideModBase.mls.LogInfo((object)("Added " + ((Object)CustomOutsideModBase.loadedInjectableOutsideObjects[j].spawnableObject).name + " as potential spawns."));
break;
}
IL_06b4:;
}
SpawnableOutsideObjectWithRarity[] spawnableOutsideObjects = val.spawnableOutsideObjects;
for (int k = 0; k < spawnableOutsideObjects.Length; k++)
{
list.Add(spawnableOutsideObjects[k]);
}
val.spawnableOutsideObjects = list.ToArray();
__instance.levels[i] = val;
switch (array2[0])
{
case "experimentation":
CustomOutsideModBase.Set_Experimentation = true;
break;
case "assurance":
CustomOutsideModBase.Set_Assurance = true;
break;
case "vow":
CustomOutsideModBase.Set_Vow = true;
break;
case "offense":
CustomOutsideModBase.Set_Offense = true;
break;
case "march":
CustomOutsideModBase.Set_March = true;
break;
case "adamance":
CustomOutsideModBase.Set_Adamance = true;
break;
case "rend":
CustomOutsideModBase.Set_Rend = true;
break;
case "dine":
CustomOutsideModBase.Set_Dine = true;
break;
case "titan":
CustomOutsideModBase.Set_Titan = true;
break;
case "embrion":
CustomOutsideModBase.Set_Embrion = true;
break;
case "artifice":
CustomOutsideModBase.Set_Artifice = true;
break;
}
}
}
}
}