Decompiled source of StageSwapper v1.0.6

LLB-StageSwapper.dll

Decompiled 7 months ago
using System;
using System.Collections;
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 System.Xml;
using System.Xml.Serialization;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using LLBML.Utils;
using LLHandlers;
using StageBackground;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
namespace LLB_StageSwapper;

[HarmonyPatch(typeof(BG), "StartUp")]
public class StartPatch
{
	public static void Postfix()
	{
		Plugin.Log.LogInfo((object)QualitySettings.shadowDistance);
		Plugin.Log.LogInfo((object)BG.instance.fixedCamPosY);
		StageSwapper component = ((Component)BG.instance).gameObject.GetComponent<StageSwapper>();
		if ((Object)(object)component != (Object)null)
		{
			Object.DestroyImmediate((Object)(object)component);
		}
		((Component)BG.instance).gameObject.AddComponent<StageSwapper>();
	}
}
[HarmonyPatch(typeof(BG), "StartMatchIntro")]
public class IntroCamPatch
{
	public static void Prefix()
	{
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		Plugin.Log.LogInfo((object)"Start match intro called!");
		string text = ((object)(Stage)(ref JOMBNFKIHIC.GIGAKBJGFDI.OOEPDFABFIP)).ToString().ToLower();
		string path = Path.Combine(Plugin.PluginDir.ToString(), text + ".xml");
		StageSettings stageSettings = Plugin.LoadXML(path);
		if (stageSettings != null)
		{
			List<IntroCamShot> list = new List<IntroCamShot>();
			CamShot[] shots = stageSettings.shots;
			foreach (CamShot camShot in shots)
			{
				IntroCamShot item = default(IntroCamShot);
				item.StartPoint = Plugin.FromCamTransform(camShot.StartCam);
				item.EndPoint = Plugin.FromCamTransform(camShot.EndCam);
				item.Duration = camShot.Duration;
				item.isConstantSpeed = !camShot.Smooth;
				list.Add(item);
			}
			BG.instance.introCamShots = Enumerable.ToArray(list).ToArray();
		}
	}
}
[BepInPlugin("com.github.andylobjois.llb-stageswapper", "Stage Swapper", "1.0.6")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
	public static Plugin instance;

	private static IDictionary<string, AssetBundle> StageBundles = new Dictionary<string, AssetBundle>();

	public static DirectoryInfo PluginDir => ModdingFolder.GetModSubFolder(((BaseUnityPlugin)instance).Info);

	internal static ManualLogSource Log { get; private set; }

	private void Awake()
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Expected O, but got Unknown
		instance = this;
		Log = ((BaseUnityPlugin)this).Logger;
		Harmony val = new Harmony("Stage Swapper");
		val.PatchAll();
		Log.LogInfo((object)PluginDir);
	}

	private void Start()
	{
		((MonoBehaviour)this).StartCoroutine(LoadSwaps());
	}

	private IEnumerator LoadSwaps()
	{
		yield return (object)new WaitForSeconds(4f);
		if (StageHandler.stagesAll == null)
		{
			Log.LogError((object)"Stage handler wasn't loaded yet - please report this bug");
		}
		foreach (Stage item in StageHandler.stagesAll)
		{
			Stage stage = item;
			string stagePath = Path.Combine(PluginDir.ToString(), ((object)(Stage)(ref stage)).ToString().ToLower());
			if (File.Exists(stagePath))
			{
				Log.LogInfo((object)("Loading assetbundle: " + stagePath));
				AssetBundle bund = AssetBundle.LoadFromFile(stagePath);
				StageBundles[((object)(Stage)(ref stage)).ToString()] = bund;
			}
		}
	}

	public static AssetBundle GetBundle(string name)
	{
		if (StageBundles.ContainsKey(name))
		{
			return StageBundles[name];
		}
		return null;
	}

	public static bool HasSwap(string name)
	{
		return StageBundles.ContainsKey(name);
	}

	public static StageSettings LoadXML(string path)
	{
		if (File.Exists(path))
		{
			XmlSerializer xmlSerializer = new XmlSerializer(typeof(StageSettings));
			using XmlReader xmlReader = XmlReader.Create(path);
			return (StageSettings)xmlSerializer.Deserialize(xmlReader);
		}
		return null;
	}

	public static Transform FromCamTransform(CamTransform cam)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		Log.LogInfo((object)cam.ToString());
		Transform transform = new GameObject().transform;
		transform.localPosition = new Vector3(cam.x, cam.y, cam.z);
		transform.localEulerAngles = new Vector3(cam.rotX, cam.rotY, cam.rotZ);
		return transform;
	}
}
public static class PluginInfos
{
	public const string PLUGIN_ID = "com.github.andylobjois.llb-stageswapper";

	public const string PLUGIN_NAME = "Stage Swapper";

	public const string PLUGIN_VERSION = "1.0.6";
}
[Serializable]
public class StageSettings
{
	public int ShadowDistance;

	public float CameraPositionY;

	[XmlArray("NormalObjects")]
	[XmlArrayItem("string")]
	public string[] normal;

	[XmlArray("EclipseObjects")]
	[XmlArrayItem("string")]
	public string[] eclipse;

	[XmlArray("IntroCamShots")]
	[XmlArrayItem("CamShot")]
	public CamShot[] shots;
}
[Serializable]
public class CamShot
{
	public CamTransform StartCam;

	public CamTransform EndCam;

	public float Duration;

	public bool Smooth;
}
[Serializable]
public class CamTransform
{
	public float x;

	public float y;

	public float z;

	public float rotX;

	public float rotY;

	public float rotZ;

	public override string ToString()
	{
		return $"Pos({x},{y},{z}), Rot({rotX},{rotY},{rotZ})";
	}
}
public class StageSwapper : MonoBehaviour
{
	public AssetBundle sceneBundle;

	public string[] normalNames;

	public string[] eclipseNames;

	public CamShot[] camShots;

	public bool active = false;

	private void Start()
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Invalid comparison between Unknown and I4
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		if ((int)DNPFJHMAIBP.HHMOGKIMBNM() == 21)
		{
			return;
		}
		Scene activeScene = SceneManager.GetActiveScene();
		if (((Scene)(ref activeScene)).name == "title")
		{
			return;
		}
		ManualLogSource log = Plugin.Log;
		activeScene = SceneManager.GetActiveScene();
		log.LogInfo((object)((Scene)(ref activeScene)).name);
		string text = ((object)(Stage)(ref JOMBNFKIHIC.GIGAKBJGFDI.OOEPDFABFIP)).ToString();
		sceneBundle = Plugin.GetBundle(text);
		if ((Object)(object)sceneBundle != (Object)null)
		{
			active = true;
			string path = Path.Combine(Plugin.PluginDir.ToString(), text + ".xml");
			StageSettings stageSettings = Plugin.LoadXML(path);
			if (stageSettings != null)
			{
				QualitySettings.shadowDistance = stageSettings.ShadowDistance;
				BG.instance.fixedCamPosY = stageSettings.CameraPositionY;
				BG.instance.maxPosY = BG.instance.fixedCamPosY + 0.5f;
				normalNames = stageSettings.normal;
				eclipseNames = stageSettings.eclipse;
				camShots = stageSettings.shots;
			}
			else
			{
				normalNames = new string[1] { "StageSwapperNormal" };
				eclipseNames = new string[1] { "StageSwapperEclipse" };
			}
			((MonoBehaviour)this).StartCoroutine(ReplaceStage());
		}
		else
		{
			QualitySettings.shadowDistance = 40f;
		}
	}

	private IEnumerator ReplaceStage()
	{
		yield return (object)new WaitForEndOfFrame();
		BG.instance.obsEclipse = null;
		BG.instance.obsNormal = null;
		BG.instance.eclipseMaterials = null;
		BG.instance.replaceMaterials = null;
		BG.instance.eclipseColorRenderers = null;
		BG.instance.introCamShots = null;
		((UnityEventBase)BG.instance.eclipseEvents).RemoveAllListeners();
		ClearStage(GameObject.Find("Background"));
		ClearStage(GameObject.Find("Eclipse"));
		ClearStage(GameObject.Find("BGLayer2_Animated"));
		ClearStage(GameObject.Find("PedestriansLayer"));
		ClearStage(GameObject.Find("Blimp_Animated 1"));
		ClearStage(GameObject.Find("Blimp_Animated 2"));
		ClearStage(GameObject.Find("Blimp_Animated 3"));
		((MonoBehaviour)this).StartCoroutine("ChangeShadowsPlane");
		Plugin.Log.LogInfo((object)"Cleared stage objects");
		string[] scenePath = sceneBundle.GetAllScenePaths();
		SceneManager.LoadScene(scenePath[0], (LoadSceneMode)1);
		((MonoBehaviour)this).StartCoroutine(SetupScene());
	}

	private IEnumerator SetupScene()
	{
		yield return (object)new WaitForEndOfFrame();
		List<GameObject> normal = new List<GameObject>();
		List<GameObject> eclipse = new List<GameObject>();
		string[] array = normalNames;
		foreach (string objName in array)
		{
			GameObject obj = GameObject.Find(objName);
			if ((Object)(object)obj == (Object)null)
			{
				Plugin.Log.LogWarning((object)("Could not find obj with name '" + objName + "' for normal objects"));
			}
			else
			{
				normal.Add(obj);
			}
		}
		string[] array2 = eclipseNames;
		foreach (string objName2 in array2)
		{
			GameObject obj2 = GameObject.Find(objName2);
			if ((Object)(object)obj2 == (Object)null)
			{
				Plugin.Log.LogWarning((object)("Could not find obj with name '" + objName2 + "' for eclipse objects"));
			}
			else
			{
				eclipse.Add(obj2);
			}
		}
		BG.instance.obsNormal = Enumerable.ToArray(normal);
		BG.instance.obsEclipse = Enumerable.ToArray(eclipse);
		Plugin.Log.LogInfo((object)(BG.instance.obsNormal.Length + " elements in normal"));
		Plugin.Log.LogInfo((object)(BG.instance.obsEclipse.Length + " elements in eclipse"));
		GameObject[] obsEclipse = BG.instance.obsEclipse;
		foreach (GameObject ele in obsEclipse)
		{
			ele.SetActive(false);
		}
		GameObject light = GameObject.Find("shadowCastLight");
		light.GetComponent<Light>().shadows = (LightShadows)0;
		GameObject[] obsEclipse2 = BG.instance.obsEclipse;
		foreach (GameObject obj3 in obsEclipse2)
		{
			obj3.SetActive(false);
		}
	}

	private static void ClearStage(GameObject gameObject)
	{
		if (!((Object)(object)gameObject != (Object)null))
		{
			return;
		}
		for (int i = 0; i < gameObject.transform.childCount; i++)
		{
			bool flag = ((Object)gameObject.transform.GetChild(i)).name.Contains("Positions");
			bool flag2 = ((Object)gameObject.transform.GetChild(i)).name.Contains("Light");
			if (!flag && !flag2)
			{
				((Component)gameObject.transform.GetChild(i)).gameObject.SetActive(false);
			}
		}
	}

	private IEnumerator ChangeShadowsPlane()
	{
		yield return (object)new WaitForSeconds(0.1f);
		if (Object.op_Implicit((Object)(object)GameObject.Find("CustomReceiveShadowsPlane")))
		{
			GameObject originalPlane = GameObject.Find("receiveShadowsPlane");
			GameObject customPlane = GameObject.Find("CustomReceiveShadowsPlane");
			originalPlane.GetComponent<MeshFilter>().mesh = customPlane.GetComponent<MeshFilter>().mesh;
			originalPlane.transform.position = customPlane.transform.position;
			originalPlane.transform.rotation = customPlane.transform.rotation;
			originalPlane.transform.localScale = customPlane.transform.localScale;
			customPlane.SetActive(false);
		}
		else
		{
			Plugin.Log.LogMessage((object)"There is no 'CustomReceiveShadowsPlane' gameObject in the scene, if it's intentional, ignore this message.\nIf you want to create a custom ReceiveShadowsPlane, please create a gameObject with the exact name 'CustomReceiveShadowsPlane'.\nAdd a MeshFilter Component on this gameObject and assign your mesh.\nMake sure to let this gameObject active before building your stage bundle.");
		}
	}
}