using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("MissionLoader")]
[assembly: AssemblyConfiguration("Export")]
[assembly: AssemblyDescription("A BepInEx plugin that loads modded missions for House of the Dying Sun.")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1+217185a6bfbcbdc78eb0fbd7e2527f3422bea95b")]
[assembly: AssemblyProduct("MissionLoader")]
[assembly: AssemblyTitle("MissionLoader")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.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 MissionLoader
{
internal static class LinqSubstitute
{
public static int Count<T>(this IEnumerable<T> values)
{
return new List<T>(values).Count;
}
public static T FirstOf<T>(this IEnumerable<T> values, Func<T, bool> predicate)
{
foreach (T value in values)
{
if (predicate(value))
{
return value;
}
}
return default(T);
}
public static IEnumerable<U> Remap<T, U>(this IEnumerable<T> values, Func<T, U> remapper)
{
foreach (T value in values)
{
yield return remapper(value);
}
}
public static Dictionary<T, U> Zipper<T, U>(this IEnumerable<T> keys, IEnumerable<U> values)
{
List<T> list = new List<T>(keys);
List<U> list2 = new List<U>(values);
if (list.Count != list2.Count)
{
throw new ArgumentException("Keys and values are not the same length");
}
Dictionary<T, U> dictionary = new Dictionary<T, U>();
for (int i = 0; i < list.Count; i++)
{
dictionary.Add(list[i], list2[i]);
}
return dictionary;
}
public static T FirstByName<T>(this IEnumerable<Object> values, string name) where T : Object
{
Object obj = values.FirstOf((Object o) => o.name == name);
return (T)(object)((obj is T) ? obj : null);
}
}
public class NamedNodeDatum
{
public string sortieName;
public List<string> connections;
public string posName;
public NamedNodeDatum(string sortieName, List<string> connections, string posName = "")
{
this.sortieName = sortieName;
this.connections = connections;
if (posName == "")
{
this.posName = sortieName.Replace("MISSION_", "POS_");
}
else
{
this.posName = posName;
}
}
}
public static class NodeFactory
{
public static GameObject Create(NodeFactoryDatum nodeDatum, Transform parent = null)
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Expected O, but got Unknown
GameObject val = new GameObject(((Object)nodeDatum.sortieTemplate).name.Replace("MISSION_", "NODE_"));
val.transform.parent = parent;
OverworldNode obj = val.AddComponent<OverworldNode>();
obj.sortieTemplate = nodeDatum.sortieTemplate;
((Component)obj).transform.position = nodeDatum.position;
((HUDIcon)val.AddComponent<HUDIconOverworldNode>()).mesh = Resources.Load<Mesh>("ui/hudicons_landmarks_model_31");
return val;
}
public static List<GameObject> CreateMultiple(List<NodeFactoryDatum> nodeDatums, Transform parent = null)
{
List<GameObject> nodes = new List<GameObject>();
nodeDatums.ForEach(delegate(NodeFactoryDatum nd)
{
nodes.Add(Create(nd, parent));
});
return nodes;
}
}
public class NodeFactoryDatum
{
public SortieTemplate sortieTemplate;
public List<string> connectionNames;
public Vector3 position;
public NodeFactoryDatum(SortieTemplate sortieTemplate, List<string> connectionNames, Vector3 position)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
this.sortieTemplate = sortieTemplate;
this.connectionNames = connectionNames;
this.position = position;
}
}
public class NodeSpawner : MonoBehaviour
{
public delegate void SceneReadyDelegate();
private static string type = "NodeSpawner";
private static GameObject instance;
private static List<NodeFactoryDatum> data = new List<NodeFactoryDatum>();
public static GameObject Instance => instance;
public static event SceneReadyDelegate SceneReady;
public static void Spawn()
{
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Expected O, but got Unknown
if (!((Object)(object)instance != (Object)null))
{
NodeSpawner.SceneReady?.Invoke();
instance = new GameObject("NodeSpawner", new Type[1] { typeof(NodeSpawner) });
}
}
public static void ReadyNodes(List<NodeFactoryDatum> newNodes)
{
data.AddRange(newNodes);
if ((Object)(object)instance != (Object)null)
{
instance.GetComponent<NodeSpawner>().SpawnNodes();
}
}
public static void FindAndReadyNodes(List<NamedNodeDatum> namedNodeData, List<Object> objects)
{
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
List<NodeFactoryDatum> list = new List<NodeFactoryDatum>();
foreach (NamedNodeDatum namedNodeDatum in namedNodeData)
{
SortieTemplate val = ((IEnumerable<Object>)objects).FirstByName<SortieTemplate>(namedNodeDatum.sortieName);
Transform transform = ((IEnumerable<Object>)objects).FirstByName<GameObject>(namedNodeDatum.posName).transform;
if ((Object)(object)val == (Object)null || (Object)(object)transform == (Object)null)
{
string text = (((Object)(object)val == (Object)null) ? namedNodeDatum.sortieName : namedNodeDatum.posName);
Debug.LogError((object)(type + ": Couldn't find " + text));
}
else
{
list.Add(new NodeFactoryDatum(val, namedNodeDatum.connections, transform.position));
}
}
ReadyNodes(list);
}
private void Awake()
{
SpawnNodes();
}
private void AssignConnections(KeyValuePair<OverworldNode, string[]> node, Transform root)
{
string[] value = node.Value;
foreach (string text in value)
{
Transform val = root.FindChild(text);
if ((Object)(object)val != (Object)null)
{
node.Key.ConnectTo(((Component)val).GetComponent<OverworldNode>());
}
}
}
private void SpawnNodes()
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
Debug.Log((object)$"{type}: Spawning {data.Count} nodes");
Scene activeScene = SceneManager.GetActiveScene();
Transform val = ((Scene)(ref activeScene)).GetRootGameObjects().FirstOf((GameObject r) => ((Object)r).name == "#GALAXY_ROOT").transform.FindChild("GALAXY_ROTATOR/ROOT_Overworld");
IEnumerable<OverworldNode> enumerable = NodeFactory.CreateMultiple(data, val).Remap((GameObject g) => g.GetComponent<OverworldNode>());
Debug.Log((object)$"{type}: Spawned {enumerable.Count()} nodes");
IEnumerable<string[]> values = data.Remap((NodeFactoryDatum d) => d.connectionNames.ToArray());
foreach (KeyValuePair<OverworldNode, string[]> item in enumerable.Zipper(values))
{
AssignConnections(item, val);
}
Debug.Log((object)(type + ": Connection process done"));
data.Clear();
}
}
[BepInProcess("dyingsun.exe")]
[BepInPlugin("MissionLoader", "MissionLoader", "1.1.1")]
public class Plugin : BaseUnityPlugin
{
private void Awake()
{
SceneManager.sceneLoaded += OnSceneLoaded;
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin awake done, waiting for scene to load");
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
SceneManager.sceneLoaded -= OnSceneLoaded;
((MonoBehaviour)this).StartCoroutine(InitAfterFrame());
}
private IEnumerator InitAfterFrame()
{
yield return null;
NodeSpawner.Spawn();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Created node spawner instance, initialization all done");
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "MissionLoader";
public const string PLUGIN_NAME = "MissionLoader";
public const string PLUGIN_VERSION = "1.1.1";
}
}