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 BepInEx;
using DM;
using HarmonyLib;
using Landfall.TABS;
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("PirateSpookified")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PirateSpookified")]
[assembly: AssemblyTitle("PirateSpookified")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PirateSpookified;
public sealed class GhostlyBob : MonoBehaviour
{
[Header("Bobbing")]
[Min(0f)]
public float height = 0.25f;
[Min(0f)]
public float speed = 1.2f;
[Header("Randomization")]
[Min(0f)]
public float randomHeightOffset = 0.15f;
[Min(0f)]
public float randomSpeedVariation = 0.2f;
private Vector3 startLocalPosition;
private float phaseOffset;
private float actualSpeed;
private void Awake()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
startLocalPosition = ((Component)this).transform.localPosition;
startLocalPosition.y += Random.Range(0f - randomHeightOffset, randomHeightOffset);
phaseOffset = Random.Range(0f, MathF.PI * 2f);
actualSpeed = speed * Random.Range(Mathf.Max(0f, 1f - randomSpeedVariation), 1f + randomSpeedVariation);
}
private void Update()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
Vector3 localPosition = startLocalPosition;
localPosition.y += Mathf.Sin(Time.time * actualSpeed + phaseOffset) * height;
((Component)this).transform.localPosition = localPosition;
}
}
[BepInPlugin("org.bepinex.plugins.PirateSpookified", "PirateSpookified", "1.0.0")]
internal class Loader : BaseUnityPlugin
{
private void Awake()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Expected O, but got Unknown
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
new Harmony("PirateSpookified").PatchAll();
GameObject val = new GameObject("PirateSpookified");
Object.DontDestroyOnLoad((Object)val);
val.AddComponent<LoadStuff>();
val.AddComponent<Main>();
}
}
public static class SceneLoadHandler
{
public static void Init()
{
SceneManager.sceneLoaded += OnSceneLoaded;
}
private static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: 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)
string name = ((Scene)(ref scene)).name;
if (!(name == "PirateSpookyAG") && !(name == "AsiaNight"))
{
return;
}
Scene activeScene = SceneManager.GetActiveScene();
if (!(((Scene)(ref activeScene)).name == "PirateSpookyAG"))
{
activeScene = SceneManager.GetActiveScene();
if (!(((Scene)(ref activeScene)).name.ToLower() == "AsiaNight".ToLower()))
{
return;
}
}
GameObject[] rootGameObjects = ((Scene)(ref scene)).GetRootGameObjects();
foreach (GameObject val in rootGameObjects)
{
Renderer[] componentsInChildren = val.GetComponentsInChildren<Renderer>(true);
if ((Object)(object)val.GetComponent<PirateWaterManager>() != (Object)null)
{
val.GetComponent<PirateWaterManager>().WaterMaterial.shader = Shader.Find(((Object)val.GetComponent<PirateWaterManager>().WaterMaterial.shader).name);
}
Renderer[] array = componentsInChildren;
foreach (Renderer val2 in array)
{
Material[] sharedMaterials = val2.sharedMaterials;
foreach (Material val3 in sharedMaterials)
{
if (!((Object)(object)val3 == (Object)null))
{
val3.shader = Shader.Find(((Object)val3.shader).name) ?? val3.shader;
}
}
if (Object.op_Implicit((Object)(object)((Component)val2).GetComponent<PiratePlacementTransparency>()))
{
((Component)val2).GetComponent<PiratePlacementTransparency>().Materials[0].m_oldMaterial.shader = Shader.Find(((Object)((Component)val2).GetComponent<PiratePlacementTransparency>().Materials[0].m_oldMaterial.shader).name) ?? ((Component)val2).GetComponent<PiratePlacementTransparency>().Materials[0].m_oldMaterial.shader;
}
}
}
}
}
public class LoadStuff : MonoBehaviour
{
public static void LoadAssets(bool reload)
{
//IL_017b: Unknown result type (might be due to invalid IL or missing references)
LandfallContentDatabase landfallContentDatabase = ContentDatabase.Instance().LandfallContentDatabase;
string[] files = Directory.GetFiles(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "*.ab", SearchOption.TopDirectoryOnly);
if (files.Length == 0)
{
Debug.LogError((object)"No .ab files found in current directory!");
return;
}
string[] array = files;
foreach (string obj in array)
{
AssetBundle val = AssetBundle.LoadFromFile(obj);
string text = Path.GetFileNameWithoutExtension(obj).ToLower();
if (text == "piratespooky" || text == "asianight")
{
continue;
}
List<MapAsset> list = val.LoadAllAssets<MapAsset>().ToList();
_ = (Dictionary<DatabaseID, Object>)typeof(AssetLoader).GetField("m_nonStreamableAssets", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(ContentDatabase.Instance().AssetLoader);
if (list.Count <= 0)
{
continue;
}
MapAsset[] array2 = (MapAsset[])typeof(LandfallContentDatabase).GetField("m_orderedMapAssets", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(landfallContentDatabase);
Dictionary<DatabaseID, int> dictionary = new Dictionary<DatabaseID, int>();
List<MapAsset> list2 = new List<MapAsset>();
for (int j = 0; j < array2.Count(); j++)
{
list2.Add(array2[j]);
}
foreach (MapAsset item in list)
{
if ((Object)(object)item != (Object)null)
{
list2.Add(item);
item.m_mapIndex = list2.Count();
}
}
foreach (MapAsset item2 in list2)
{
dictionary.Add(item2.Entity.GUID, list2.IndexOf(item2));
}
typeof(LandfallContentDatabase).GetField("m_orderedMapAssets", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(landfallContentDatabase, list2.ToArray());
typeof(LandfallContentDatabase).GetField("m_mapAssetIndexLookup", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(landfallContentDatabase, dictionary);
}
}
}
public class Main : MonoBehaviour
{
public void Awake()
{
Debug.Log((object)"Loaded PirateSpookified Successfully!");
LoadStuff.LoadAssets(reload: false);
SceneLoadHandler.Init();
}
}