Decompiled source of Scrambled Seas v6.0.2

ScrambledSeas/ScrambledSeas.dll

Decompiled 8 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Xml.Serialization;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace ScrambledSeas;

public static class Extensions
{
	public static object GetPrivateField(this object obj, string field)
	{
		return Traverse.Create(obj).Field(field).GetValue();
	}

	public static T GetPrivateField<T>(this object obj, string field)
	{
		return (T)obj.GetPrivateField(field);
	}

	public static object GetPrivateField<T>(string field)
	{
		return Traverse.Create(typeof(T)).Field(field).GetValue();
	}

	public static T GetPrivateField<T, E>(string field)
	{
		return (T)GetPrivateField<E>(field);
	}

	public static void SetPrivateField(this object obj, string field, object value)
	{
		Traverse.Create(obj).Field(field).SetValue(value);
	}

	public static void SetPrivateField<T>(string field, object value)
	{
		Traverse.Create(typeof(T)).Field(field).SetValue(value);
	}

	public static object InvokePrivateMethod(this object obj, string method, params object[] parameters)
	{
		return AccessTools.Method(obj.GetType(), method, (Type[])null, (Type[])null).Invoke(obj, parameters);
	}

	public static T InvokePrivateMethod<T>(this object obj, string method, params object[] parameters)
	{
		return (T)obj.InvokePrivateMethod(method, parameters);
	}

	public static object InvokePrivateMethod<T>(string method, params object[] parameters)
	{
		return AccessTools.Method(typeof(T), method, (Type[])null, (Type[])null).Invoke(null, parameters);
	}

	public static T InvokePrivateMethod<T, E>(string method, params object[] parameters)
	{
		return (T)InvokePrivateMethod<E>(method, parameters);
	}

	public static T GetCopyOf<T>(this Component comp, T other) where T : Component
	{
		Type type = ((object)comp).GetType();
		if (type != ((object)other).GetType())
		{
			return default(T);
		}
		BindingFlags bindingAttr = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
		PropertyInfo[] properties = type.GetProperties(bindingAttr);
		foreach (PropertyInfo propertyInfo in properties)
		{
			if (propertyInfo.CanWrite)
			{
				try
				{
					propertyInfo.SetValue(comp, propertyInfo.GetValue(other, null), null);
				}
				catch
				{
				}
			}
		}
		FieldInfo[] fields = type.GetFields(bindingAttr);
		foreach (FieldInfo fieldInfo in fields)
		{
			fieldInfo.SetValue(comp, fieldInfo.GetValue(other));
		}
		return (T)(object)((comp is T) ? comp : null);
	}

	public static T AddComponent<T>(this GameObject go, T toAdd) where T : Component
	{
		return ((Component)(object)go.AddComponent<T>()).GetCopyOf(toAdd);
	}

	public static Transform GetChildByName(this Transform transform, string childName)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Expected O, but got Unknown
		foreach (Transform item in transform)
		{
			Transform val = item;
			if (((Object)val).name == childName)
			{
				return val;
			}
		}
		return null;
	}
}
[BepInPlugin("com.app24.scrambledseas", "Scrambled Seas", "6.0.1")]
public class Main : BaseUnityPlugin
{
	public const string GUID = "com.app24.scrambledseas";

	public const string NAME = "Scrambled Seas";

	public const string VERSION = "6.0.1";

	public static readonly bool pluginEnabled = true;

	public ScrambledSeasSaveContainer _saveContainer = new ScrambledSeasSaveContainer();

	public static Main instance;

	internal static ManualLogSource logSource;

	public static ScrambledSeasSaveContainer saveContainer
	{
		get
		{
			return instance._saveContainer;
		}
		set
		{
			instance._saveContainer = value;
		}
	}

	private void Awake()
	{
		instance = this;
		Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "com.app24.scrambledseas");
		logSource = ((BaseUnityPlugin)this).Logger;
	}
}
public static class Patches
{
	[HarmonyPatch(typeof(IslandHorizon), "Start")]
	private static class IslandPatch
	{
		private static void Prefix(IslandHorizon __instance)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			if (Main.pluginEnabled && __instance.islandIndex > 0)
			{
				WorldScrambler.islandNames[__instance.islandIndex - 1] = ((Object)((Component)__instance).gameObject).name;
				WorldScrambler.islandOrigins[__instance.islandIndex - 1] = ((Component)__instance).gameObject.transform.localPosition;
			}
		}
	}

	[HarmonyPatch(typeof(SaveLoadManager), "SaveModData")]
	private static class SavePatch
	{
		private static void Postfix()
		{
			if (Main.pluginEnabled)
			{
				Main.saveContainer.version = 60;
				Main.saveContainer.Save("ScrambledSeas");
			}
		}
	}

	[HarmonyPatch(typeof(SaveLoadManager), "LoadModData")]
	private static class LoadGamePatch
	{
		private static void Postfix()
		{
			if (Main.pluginEnabled)
			{
				Main.saveContainer = "ScrambledSeas".Load<ScrambledSeasSaveContainer>();
				if (Main.saveContainer.version < 60)
				{
					NotificationUi.instance.ShowNotification("ERROR: This save is not\ncompatiblewith this version\nof Scrambled Seas");
					throw new InvalidOperationException("ERROR: This save is not compatible with this version of Scrambled Seas");
				}
				WorldScrambler.Scramble();
			}
		}
	}

	[HarmonyPatch(typeof(StartMenu), "StartNewGame")]
	private static class StartNewGamePatch
	{
		private static bool Prefix(StartMenu __instance, ref bool ___fPressed, ref Transform ___playerObserver, ref GameObject ___playerController, ref int ___animsPlaying, ref int ___currentRegion, ref Transform ___startApos, ref Transform ___startEpos, ref Transform ___startMpos)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			if (Main.pluginEnabled)
			{
				Main.saveContainer.worldScramblerSeed = (int)DateTime.Now.Ticks;
				WorldScrambler.Scramble();
				Transform obj = ___startApos;
				obj.position += WorldScrambler.islandDisplacements[2];
				Transform obj2 = ___startEpos;
				obj2.position += WorldScrambler.islandDisplacements[10];
				Transform obj3 = ___startMpos;
				obj3.position += WorldScrambler.islandDisplacements[20];
				___animsPlaying++;
				Transform val = null;
				if (___currentRegion == 0)
				{
					val = ___startApos;
					GameState.newGameRegion = (PortRegion)0;
				}
				else if (___currentRegion == 1)
				{
					val = ___startEpos;
					GameState.newGameRegion = (PortRegion)1;
				}
				else
				{
					val = ___startMpos;
					GameState.newGameRegion = (PortRegion)2;
				}
				__instance.InvokePrivateMethod("DisableIslandMenu");
				((MonoBehaviour)__instance).StartCoroutine(MovePlayerToStartPos(__instance, val, ___playerObserver, ___playerController));
				return false;
			}
			return true;
		}

		public static IEnumerator MovePlayerToStartPos(StartMenu instance, Transform startPos, Transform playerObserver, GameObject playerController)
		{
			((Component)playerObserver).transform.parent = ((Component)instance).gameObject.transform.parent;
			playerObserver.position = startPos.position;
			playerController.transform.position = startPos.position;
			instance.GetPrivateField<GameObject>("logo").SetActive(false);
			((Component)instance.GetPrivateField<Transform>("playerObserver")).transform.parent = ((Component)instance).transform.parent;
			float animTime = 0f;
			Juicebox.juice.TweenPosition(((Component)instance.GetPrivateField<Transform>("playerObserver")).gameObject, startPos.position, animTime, (JuiceboxTween)4);
			for (float t = 0f; t < animTime; t += Time.deltaTime)
			{
				instance.GetPrivateField<Transform>("playerObserver").rotation = Quaternion.Lerp(instance.GetPrivateField<Transform>("playerObserver").rotation, startPos.rotation, Time.deltaTime * 0.35f);
				yield return (object)new WaitForEndOfFrame();
			}
			instance.GetPrivateField<Transform>("playerObserver").rotation = startPos.rotation;
			instance.GetPrivateField<GameObject>("playerController").transform.position = instance.GetPrivateField<Transform>("playerObserver").position;
			instance.GetPrivateField<GameObject>("playerController").transform.rotation = instance.GetPrivateField<Transform>("playerObserver").rotation;
			yield return (object)new WaitForEndOfFrame();
			((Collider)instance.GetPrivateField<GameObject>("playerController").GetComponent<CharacterController>()).enabled = true;
			((Behaviour)instance.GetPrivateField<GameObject>("playerController").GetComponent<OVRPlayerController>()).enabled = true;
			((Behaviour)((Component)instance.GetPrivateField<Transform>("playerObserver")).gameObject.GetComponent<PlayerControllerMirror>()).enabled = true;
			MouseLook.ToggleMouseLookAndCursor(true);
			instance.GetPrivateField<PurchasableBoat[]>("startingBoats")[instance.GetPrivateField<int>("currentRegion")].LoadAsPurchased();
			((MonoBehaviour)instance).StartCoroutine(Blackout.FadeTo(1f, 0.2f));
			yield return (object)new WaitForSeconds(0.2f);
			yield return (object)new WaitForEndOfFrame();
			instance.GetPrivateField<GameObject>("disclaimer").SetActive(true);
			instance.SetPrivateField("waitingForFInput", true);
			while (!instance.GetPrivateField<bool>("fPressed"))
			{
				yield return (object)new WaitForEndOfFrame();
			}
			instance.GetPrivateField<GameObject>("disclaimer").SetActive(false);
			((MonoBehaviour)instance).StartCoroutine(Blackout.FadeTo(0f, 0.3f));
			yield return (object)new WaitForEndOfFrame();
			SaveLoadManager.readyToSave = true;
			GameState.playing = true;
			GameState.justStarted = true;
			MouseLook.ToggleMouseLook(true);
			int num = (int)Traverse.Create((object)instance).Field("animsPlaying").GetValue();
			Traverse.Create((object)instance).Field("animsPlaying").SetValue((object)(num - 1));
			yield return (object)new WaitForSeconds(1f);
			GameState.justStarted = false;
		}
	}

	[HarmonyPatch(typeof(StartMenu), "MovePlayerToStartPos")]
	private static class MovePlayerPatch
	{
		private static void Prefix(Transform startPos, StartMenu __instance, ref Transform ___playerObserver, ref GameObject ___playerController)
		{
			//IL_0026: 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)
			if (Main.pluginEnabled)
			{
				((Component)___playerObserver).transform.parent = ((Component)__instance).gameObject.transform.parent;
				___playerObserver.position = startPos.position;
				___playerController.transform.position = startPos.position;
			}
		}
	}

	[HarmonyPatch(typeof(Juicebox), "TweenPosition", new Type[]
	{
		typeof(GameObject),
		typeof(Vector3),
		typeof(float),
		typeof(JuiceboxTween)
	})]
	private static class TweenPatch
	{
		private static bool Prefix()
		{
			if (Main.pluginEnabled)
			{
				return false;
			}
			return true;
		}
	}

	[HarmonyPatch(typeof(StarterSet), "InitiateStarterSet")]
	private static class StarterSetPatch
	{
		private static void Prefix(StarterSet __instance)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: 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_003e: Invalid comparison between Unknown and I4
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Invalid comparison between Unknown and I4
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			if (!Main.pluginEnabled)
			{
				return;
			}
			Vector3 val = default(Vector3);
			if ((int)__instance.region == 0)
			{
				val = WorldScrambler.islandDisplacements[2];
				PlayerGold.currency[0] += 48;
			}
			if ((int)__instance.region == 1)
			{
				val = WorldScrambler.islandDisplacements[10];
				PlayerGold.currency[1] += 48;
			}
			if ((int)__instance.region == 2)
			{
				val = WorldScrambler.islandDisplacements[20];
				PlayerGold.currency[2] += 48;
			}
			GameObject val2 = null;
			foreach (Transform item in ((Component)__instance).gameObject.transform)
			{
				Transform val3 = item;
				val3.Translate(val, (Space)0);
				if (((Object)val3).name.ToLower().Contains("map"))
				{
					val2 = ((Component)val3).gameObject;
				}
			}
			if (Object.op_Implicit((Object)(object)val2))
			{
				Object.Destroy((Object)(object)val2);
			}
		}
	}

	[HarmonyPatch(typeof(PlayerReputation), "GetMaxDistance")]
	private static class ReputationPatch
	{
		private static void Postfix(ref float __result)
		{
			if (Main.pluginEnabled && __result < 300f)
			{
				__result = 300f;
			}
		}
	}

	[HarmonyPatch(typeof(MissionDetailsUI), "UpdateMap")]
	private static class MissionMapPatch
	{
		private static void Postfix(ref Renderer ___mapRenderer, ref TextMesh ___locationText)
		{
			if (Main.pluginEnabled)
			{
				((Component)___mapRenderer).gameObject.SetActive(false);
				___locationText.text = "Map Unavailable\n\nWelcome to ScrambledSeas :)";
			}
		}
	}

	[HarmonyPatch(typeof(RegionBlender), "Update")]
	private static class RegionBlenderPatch
	{
		private static float regionUpdateCooldown;

		private static void Prefix(ref Region ___currentTargetRegion, ref Transform ___player)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			if (!Main.pluginEnabled)
			{
				return;
			}
			if (regionUpdateCooldown <= 0f)
			{
				regionUpdateCooldown = 100f;
				float num = 100000000f;
				Region val = null;
				foreach (Region region in WorldScrambler.regions)
				{
					float num2 = Vector3.Distance(___player.position, ((Component)region).transform.position);
					if (num2 < num)
					{
						num = num2;
						val = region;
					}
				}
				if ((Object)(object)val != (Object)null)
				{
					___currentTargetRegion = val;
				}
			}
			else
			{
				regionUpdateCooldown -= Time.deltaTime;
			}
		}
	}
}
public static class SaveFileHelper
{
	public static T Load<T>(this string modName) where T : new()
	{
		if (GameState.modData != null && GameState.modData.TryGetValue(modName, out var value))
		{
			Debug.Log((object)("Proceeding to parse save data for " + modName));
			XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
			using StringReader textReader = new StringReader(value);
			return (T)xmlSerializer.Deserialize(textReader);
		}
		Debug.Log((object)("Cannot load data from save file. Using defaults for " + modName));
		return new T();
	}

	public static void Save<T>(this T toSerialize, string modName)
	{
		XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
		using StringWriter stringWriter = new StringWriter();
		xmlSerializer.Serialize(stringWriter, toSerialize);
		GameState.modData[modName] = stringWriter.ToString();
		Debug.Log((object)("Packed save data for " + modName));
	}
}
public class ScrambledSeasSaveContainer
{
	public int version { get; set; }

	public int worldScramblerSeed { get; set; }

	public int islandSpread { get; set; } = 10000;


	public int minArchipelagoSeparation { get; set; } = 30000;


	public int minIslandSeparation { get; set; } = 2000;


	public int worldLonMin { get; set; } = -12;


	public int worldLonMax { get; set; } = 32;


	public int worldLatMin { get; set; } = 26;


	public int worldLatMax { get; set; } = 46;

}
internal static class WorldScrambler
{
	public const int version = 60;

	public const int nArchipelagos = 15;

	public const int nIslandsPer = 15;

	public static Vector3[] islandDisplacements = (Vector3[])(object)new Vector3[225];

	public static Vector3[] islandOrigins = (Vector3[])(object)new Vector3[225];

	public static string[] islandNames = new string[225];

	public static List<Region> regions = new List<Region>();

	public static void Scramble()
	{
		//IL_029b: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0302: Unknown result type (might be due to invalid IL or missing references)
		//IL_0307: Unknown result type (might be due to invalid IL or missing references)
		//IL_030c: Unknown result type (might be due to invalid IL or missing references)
		//IL_038d: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_043b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0450: Unknown result type (might be due to invalid IL or missing references)
		//IL_0455: Unknown result type (might be due to invalid IL or missing references)
		//IL_045a: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0529: Unknown result type (might be due to invalid IL or missing references)
		//IL_0572: Unknown result type (might be due to invalid IL or missing references)
		//IL_05c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_05de: Unknown result type (might be due to invalid IL or missing references)
		//IL_062e: Unknown result type (might be due to invalid IL or missing references)
		//IL_064d: Unknown result type (might be due to invalid IL or missing references)
		Dictionary<int, string> dictionary = new Dictionary<int, string>();
		Dictionary<int, List<int>> dictionary2 = new Dictionary<int, List<int>>();
		Dictionary<string, int> dictionary3 = new Dictionary<string, int>();
		dictionary.Add(0, "Region Al'ankh");
		dictionary2.Add(0, new List<int> { 1, 2, 3, 4, 5, 6, 7, 8 });
		dictionary3.Add("bottom plane A", 0);
		dictionary.Add(1, "Region Emerald (new smaller)");
		dictionary2.Add(1, new List<int> { 9, 10, 11, 12, 13, 22 });
		dictionary3.Add("bottom plane E", 1);
		dictionary.Add(2, "Region Medi");
		dictionary2.Add(2, new List<int> { 15, 16, 17, 19, 21, 23 });
		dictionary3.Add("bottom plane M", 2);
		dictionary2.Add(3, new List<int> { 20 });
		dictionary2.Add(4, new List<int> { 18 });
		dictionary2.Add(5, new List<int> { 25 });
		dictionary.Add(6, "Region Emerald Lagoon");
		dictionary2.Add(6, new List<int> { 26, 27, 28, 29, 30, 31 });
		dictionary3.Add("bottom plane chronos", 5);
		float num = Main.saveContainer.islandSpread;
		float minDist = Main.saveContainer.minArchipelagoSeparation;
		float minDist2 = Main.saveContainer.minIslandSeparation;
		float num2 = (float)Main.saveContainer.worldLonMin * 9000f + 27000f;
		float num3 = (float)Main.saveContainer.worldLonMax * 9000f - 27000f;
		float num4 = ((float)Main.saveContainer.worldLatMin - 36f) * 9000f + 27000f;
		float num5 = ((float)Main.saveContainer.worldLatMax - 36f) * 9000f - 27000f;
		Main.logSource.LogInfo((object)("Scrambler Seed:" + Main.saveContainer.worldScramblerSeed));
		Random.InitState(Main.saveContainer.worldScramblerSeed);
		Vector3[] array;
		do
		{
			array = (Vector3[])(object)new Vector3[15];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = new Vector3(Random.Range(num2, num3), 0f, Random.Range(num4, num5));
			}
		}
		while (!CheckScramble(array, minDist));
		Vector3[][] array2 = new Vector3[15][];
		int num6 = 0;
		while (num6 < 15)
		{
			array2[num6] = (Vector3[])(object)new Vector3[15];
			for (int j = 0; j < 15; j++)
			{
				array2[num6][j] = new Vector3(Random.Range(0f - num, num), 0f, Random.Range(0f - num, num)) + array[num6];
			}
			if (CheckScramble(array2[num6], minDist2))
			{
				num6++;
			}
		}
		int num7 = Random.Range(0, 1000000);
		Main.logSource.LogInfo((object)("Scrambler completion value:" + num7));
		Vector3[] array3 = (Vector3[])(object)new Vector3[15];
		foreach (KeyValuePair<int, string> item in dictionary)
		{
			array3[item.Key] = array[item.Key] - FloatingOriginManager.instance.ShiftingPosToRealPos(GameObject.Find(item.Value).transform.localPosition);
			array3[item.Key].y = 0f;
		}
		foreach (KeyValuePair<int, List<int>> item2 in dictionary2)
		{
			int key = item2.Key;
			List<int> value = item2.Value;
			_ = ref array3[key];
			for (int k = 0; k < value.Count; k++)
			{
				islandDisplacements[value[k] - 1] = array2[key][k] - islandOrigins[value[k] - 1];
				islandDisplacements[value[k] - 1].y = 0f;
			}
		}
		foreach (KeyValuePair<int, string> item3 in dictionary)
		{
			GameObject.Find(item3.Value).transform.Translate(array3[item3.Key], (Space)0);
		}
		for (int l = 0; l < islandDisplacements.Length; l++)
		{
			if (!string.IsNullOrEmpty(islandNames[l]))
			{
				GameObject.Find(islandNames[l]).transform.Translate(islandDisplacements[l], (Space)0);
			}
		}
		foreach (KeyValuePair<string, int> item4 in dictionary3)
		{
			GameObject.Find(item4.Key).transform.Translate(array3[item4.Value], (Space)0);
		}
		RecoveryPort[] array4 = Object.FindObjectsOfType(typeof(RecoveryPort)) as RecoveryPort[];
		foreach (RecoveryPort obj in array4)
		{
			int num8 = ClosestIsland(((Component)obj).gameObject.transform.position);
			((Component)obj).gameObject.transform.Translate(islandDisplacements[num8], (Space)0);
		}
		PurchasableBoat[] array5 = Object.FindObjectsOfType(typeof(PurchasableBoat)) as PurchasableBoat[];
		foreach (PurchasableBoat val in array5)
		{
			if (!val.isPurchased())
			{
				int num9 = ClosestIsland(((Component)val).gameObject.transform.position);
				((Component)val).gameObject.transform.Translate(islandDisplacements[num9], (Space)0);
			}
		}
		Random.InitState((int)DateTime.Now.Ticks);
		regions = new List<Region>();
		foreach (KeyValuePair<int, string> item5 in dictionary)
		{
			regions.Add(GameObject.Find(item5.Value).GetComponent<Region>());
		}
	}

	private static bool CheckScramble(Vector3[] locations, float minDist)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < locations.Length; i++)
		{
			for (int j = 0; j < locations.Length; j++)
			{
				if (i != j && Vector3.Distance(locations[i], locations[j]) < minDist)
				{
					return false;
				}
			}
		}
		return true;
	}

	private static float FlatDistance(Vector3 a, Vector3 b)
	{
		//IL_0000: 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_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		return Vector2.Distance(new Vector2(a.x, a.z), new Vector2(b.x, b.z));
	}

	private static int ClosestIsland(Vector3 pos)
	{
		//IL_0005: 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_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		Vector3 a = FloatingOriginManager.instance.ShiftingPosToRealPos(pos);
		float num = 999999f;
		int result = -1;
		for (int i = 0; i < islandOrigins.Length; i++)
		{
			if (!string.IsNullOrEmpty(islandNames[i]))
			{
				float num2 = FlatDistance(a, islandOrigins[i]);
				if (num2 < num)
				{
					num = num2;
					result = i;
				}
			}
		}
		return result;
	}
}