Decompiled source of Blahaj v1.3.0

plugins/4902-shark.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Steamworks;
using Steamworks.Data;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace shark;

[BepInPlugin("4902.Shark", "Shark", "1.0.0")]
public class gura : BaseUnityPlugin
{
	public static readonly Harmony harmony = new Harmony("4902.Shark");

	public static ManualLogSource mls;

	public static ConfigEntry<bool> cfg_saveseeds;

	public static ConfigEntry<int> cfg_millisecond;

	public static ConfigEntry<bool> cfg_synced_percentages;

	public static ConfigEntry<int> blue_percentage;

	public static ConfigEntry<int> pink_percentage;

	private void Awake()
	{
		cfg_saveseeds = ((BaseUnityPlugin)this).Config.Bind<bool>("#", "save/load", true, "[Save/load seeds]\nwhether the large axle/blahaj item types should be saved to the save file. this saves the seed that determines the items type, so it will be the same when rejoining.\nloading a save file that has saved seeds without having this enabled or while in lan isn't recommended as the saved seeds can be reset if the number of items is changed.\nsaved item types are synced with other players if the synced percentages config is enabled");
		cfg_millisecond = ((BaseUnityPlugin)this).Config.Bind<int>("#", "timer", 100, "[Client wait_timer]\nwhen joining a lobby as non-host if save/load is enabled then blahaj items will wait to set their item type until the seeds sent by the host have been received or the time spent waiting reached the maximum amount set by this config.\nthere will be a log message specifying if the seeds were received first or the timer ended first. if the timer is often ending before the message from the host is being received then this should be increased. if the host doesn't have this mod then save/load can be disabled since there won't be a received message from the host so the items would always wait the full timer.\nmin is 20, max is 4000. 100 is before the player spawn animation ends, 500 is about 10 seconds, 1000 is about 15 seconds");
		cfg_synced_percentages = ((BaseUnityPlugin)this).Config.Bind<bool>("#", "sync", true, "[Synced percentages]\nautomatically sync config item percentages with the host. only disable if you're aware that disabling this can cause the item types to not be the same as other players if playing with others that have this mod");
		blue_percentage = ((BaseUnityPlugin)this).Config.Bind<int>("#", "blahaj_percent", 50, "percentage that blahaj will replace axle\ninput = percentage, 50 is 50% etc");
		pink_percentage = ((BaseUnityPlugin)this).Config.Bind<int>("#", "pink_variant_percent", 10, "percentage that blahaj will be pink\ninput = percentage");
		mls = Logger.CreateLogSource("Shark");
		mls.LogInfo((object)"Blahaj is in your walls");
		harmony.PatchAll(typeof(blahaj));
	}
}
public class blahaj
{
	private static string[] item = new string[2];

	private static Mesh[] fish = (Mesh[])(object)new Mesh[2];

	private static Material[][] cats = new Material[3][];

	private static AudioClip[] take = (AudioClip[])(object)new AudioClip[2];

	private static AudioClip[] give = (AudioClip[])(object)new AudioClip[2];

	private static bool dots = false;

	private static ulong lobbyid = 0uL;

	private static bool[] first_item = new bool[3] { true, true, true };

	private static bool sync = false;

	private static string seeds = "nil";

	private static bool[] disconnected;

	private static int[] synced_percents;

	private static string saved_axle;

	private static List<string> loaded_axle;

	[HarmonyPostfix]
	[HarmonyPatch(typeof(GrabbableObject), "Start")]
	private static void pst1(GrabbableObject __instance)
	{
		pst1async(__instance);
	}

	private static async void pst1async(GrabbableObject __instance)
	{
		if (!(((Object)__instance.itemProperties).name == "Cog1"))
		{
			return;
		}
		if (first_item[0])
		{
			Item val = StartOfRound.Instance.allItemsList.itemsList.First((Item _) => ((Object)_).name == "Cog1");
			val.restingRotation = new Vector3(7f, 0f, 0f);
			val.verticalOffset = 0.5f;
		}
		if (gura.cfg_saveseeds.Value && !GameNetworkManager.Instance.disableSteam && seeds == "nil")
		{
			if (!GameNetworkManager.Instance.isHostingGame)
			{
				if (first_item[0])
				{
					gura.mls.LogInfo((object)"await wait_timer");
					first_item[0] = false;
				}
				await wait_timer((gura.cfg_millisecond.Value >= 20 && gura.cfg_millisecond.Value <= 4000) ? gura.cfg_millisecond.Value : 100);
				if (disconnected[0])
				{
					return;
				}
			}
			if (seeds == "nil")
			{
				seeds = "?";
			}
		}
		if (item[0] == null)
		{
			string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "4902-shark").Replace("\\", "/");
			gura.mls.LogMessage((object)("Searching this filepath:" + text));
			AssetBundle assetBundle = AssetBundle.LoadFromFileAsync(text).assetBundle;
			item[0] = "Large axle";
			fish[0] = ((Component)__instance).GetComponent<MeshFilter>().mesh;
			cats[0] = ((Renderer)((Component)__instance).GetComponent<MeshRenderer>()).materials;
			take[0] = __instance.itemProperties.grabSFX;
			give[0] = __instance.itemProperties.dropSFX;
			item[1] = "Shark plushie";
			fish[1] = assetBundle.LoadAsset<Mesh>("blahaj.fbx");
			cats[1] = (Material[])(object)new Material[1] { assetBundle.LoadAsset<Material>("blahaj.mat") };
			cats[2] = (Material[])(object)new Material[1] { assetBundle.LoadAsset<Material>("beyoublahaj.mat") };
			take[1] = assetBundle.LoadAsset<AudioClip>("blahajgrab.mp3");
			give[1] = assetBundle.LoadAsset<AudioClip>("blahajdrop.mp3");
		}
		if (item[0] == null)
		{
			return;
		}
		Shion shion;
		if (!GameNetworkManager.Instance.disableSteam && lobbyid != 0 && (Object)(object)((Component)__instance).GetComponent<NetworkObject>() != (Object)null)
		{
			ulong seed;
			if (gura.cfg_saveseeds.Value && seeds != "nil" && seeds != "?" && seeds.Contains(((Component)__instance).GetComponent<NetworkObject>().NetworkObjectId + "."))
			{
				if (first_item[2])
				{
					gura.mls.LogInfo((object)"custom_random = new Shion(saved seed)");
				}
				int num = seeds.IndexOf(((Component)__instance).GetComponent<NetworkObject>().NetworkObjectId + ".");
				int num2 = ((Component)__instance).GetComponent<NetworkObject>().NetworkObjectId.ToString().Length + 1;
				seed = ulong.Parse(seeds.Substring(num + num2, seeds.IndexOf("/", num) - (num + num2)));
			}
			else
			{
				if (first_item[2])
				{
					gura.mls.LogInfo((object)"custom_random = new Shion(lobbyid+networkobjectid)");
				}
				seed = lobbyid + ((Component)__instance).GetComponent<NetworkObject>().NetworkObjectId;
			}
			shion = new Shion(seed);
			if (gura.cfg_saveseeds.Value)
			{
				((Component)__instance).gameObject.AddComponent<ItemTypeSeed>();
				((Component)__instance).gameObject.GetComponent<ItemTypeSeed>().seed = seed.ToString();
			}
		}
		else
		{
			if (first_item[2])
			{
				gura.mls.LogInfo((object)"custom_random = new Shion()");
			}
			shion = new Shion();
		}
		if (first_item[2])
		{
			gura.mls.LogInfo((object)((gura.cfg_synced_percentages.Value && synced_percents[0] != -1) ? "host config" : "local config"));
		}
		first_item[2] = false;
		int[] array = ((gura.cfg_synced_percentages.Value && synced_percents[0] != -1) ? synced_percents : new int[2]
		{
			gura.blue_percentage.Value,
			gura.pink_percentage.Value
		});
		int num3 = ((shion.next32mm(0, 100) < array[0]) ? 1 : 0);
		if (num3 == 1)
		{
			if (!dots)
			{
				Vector3[] vertices = fish[1].vertices;
				Vector3[] normals = fish[1].normals;
				Bounds bounds = fish[1].bounds;
				Vector3 center = ((Bounds)(ref bounds)).center;
				for (int num2 = 0; num2 < vertices.Length; num2++)
				{
					ref Vector3 reference = ref vertices[num2];
					reference = vertices[num2] - center;
					ref Vector3 reference2 = ref vertices[num2];
					reference2 = vertices[num2] * 48f;
					float x = vertices[num2].x;
					float z = vertices[num2].z;
					float x2 = normals[num2].x;
					float z2 = normals[num2].z;
					vertices[num2].x = z;
					vertices[num2].z = 0f - x;
					normals[num2].x = z2;
					normals[num2].z = 0f - x2;
					ref Vector3 reference3 = ref vertices[num2];
					reference3 = vertices[num2] + center;
				}
				fish[1].vertices = vertices;
				fish[1].normals = normals;
				fish[1].RecalculateBounds();
				fish[1].RecalculateNormals();
				dots = true;
			}
			((Renderer)((Component)__instance).GetComponent<MeshRenderer>()).materials = ((shion.next32mm(0, 100) < array[1]) ? cats[2] : cats[1]);
		}
		else
		{
			((Renderer)((Component)__instance).GetComponent<MeshRenderer>()).materials = cats[0];
		}
		__instance.itemProperties.itemName = item[num3];
		((Component)__instance).GetComponentInChildren<ScanNodeProperties>().headerText = item[num3];
		((Component)__instance).GetComponent<MeshFilter>().mesh = fish[num3];
	}

	private static async Task wait_timer(int maxwell)
	{
		int i = 0;
		while (seeds == "nil" && i < maxwell && !disconnected[0])
		{
			i++;
			await Task.Delay(4);
		}
		if (disconnected[0])
		{
			if (!disconnected[1])
			{
				gura.mls.LogMessage((object)"disconnected before wait_timer ended");
				disconnected[1] = true;
			}
		}
		else if (first_item[1])
		{
			gura.mls.LogMessage((object)((seeds == "nil") ? ("timer ended before receiving seeds (" + i + "/" + gura.cfg_millisecond.Value + ")") : ("received seeds before timer ended (" + i + "/" + gura.cfg_millisecond.Value + ")")));
			first_item[1] = false;
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(GrabbableObject), "PlayDropSFX")]
	private static void pre1(ref GrabbableObject __instance)
	{
		if (item[0] != null && (Object)(object)__instance != (Object)null && ((Object)__instance.itemProperties).name == "Cog1" && (Object)(object)((Component)__instance).GetComponentInChildren<ScanNodeProperties>() != (Object)null)
		{
			__instance.itemProperties.dropSFX = ((((Component)__instance).GetComponentInChildren<ScanNodeProperties>().headerText == item[1]) ? give[1] : give[0]);
		}
	}

	[HarmonyPatch(typeof(PlayerControllerB), "BeginGrabObject")]
	[HarmonyTranspiler]
	private static IEnumerable<CodeInstruction> trn1(IEnumerable<CodeInstruction> Instrs)
	{
		List<CodeInstruction> i = new List<CodeInstruction>(Instrs);
		for (int j = 0; j < i.Count; j++)
		{
			yield return i[j];
			if (j > 0 && ((object)i[j - 1]).ToString() == "call static float UnityEngine.Mathf::Clamp(float value, float min, float max)" && ((object)i[j]).ToString() == "stfld float GameNetcodeStuff.PlayerControllerB::carryWeight")
			{
				yield return new CodeInstruction(OpCodes.Ldarg_0, (object)null);
				yield return new CodeInstruction(OpCodes.Ldfld, (object)typeof(PlayerControllerB).GetField("currentlyGrabbingObject", BindingFlags.Instance | BindingFlags.NonPublic));
				yield return new CodeInstruction(OpCodes.Call, (object)typeof(blahaj).GetMethod("grab_item"));
			}
		}
	}

	public static void grab_item(GrabbableObject currentlyGrabbingObject)
	{
		if (item[0] != null && (Object)(object)currentlyGrabbingObject != (Object)null && ((Object)currentlyGrabbingObject.itemProperties).name == "Cog1" && (Object)(object)((Component)currentlyGrabbingObject).GetComponentInChildren<ScanNodeProperties>() != (Object)null)
		{
			currentlyGrabbingObject.itemProperties.grabSFX = ((((Component)currentlyGrabbingObject).GetComponentInChildren<ScanNodeProperties>().headerText == item[1]) ? take[1] : take[0]);
			currentlyGrabbingObject.itemProperties.itemName = ((Component)currentlyGrabbingObject).GetComponentInChildren<ScanNodeProperties>().headerText;
		}
	}

	[HarmonyPatch(typeof(PlayerControllerB), "SwitchToItemSlot")]
	[HarmonyTranspiler]
	private static IEnumerable<CodeInstruction> trn2(IEnumerable<CodeInstruction> Instrs)
	{
		List<CodeInstruction> i = new List<CodeInstruction>(Instrs);
		for (int j = 0; j < i.Count; j++)
		{
			yield return i[j];
			if (j < i.Count - 4 && ((object)i[j + 4]).ToString() == "callvirt virtual void GrabbableObject::EquipItem()")
			{
				yield return new CodeInstruction(OpCodes.Ldarg_0, (object)null);
				yield return new CodeInstruction(OpCodes.Call, (object)typeof(blahaj).GetMethod("hold_item"));
			}
		}
	}

	public static void hold_item(PlayerControllerB player)
	{
		GrabbableObject val = player.ItemSlots[player.currentItemSlot];
		if (item[0] != null && (Object)(object)val != (Object)null && ((Object)val.itemProperties).name == "Cog1" && (Object)(object)((Component)val).GetComponentInChildren<ScanNodeProperties>() != (Object)null)
		{
			val.itemProperties.grabSFX = ((((Component)val).GetComponentInChildren<ScanNodeProperties>().headerText == item[1]) ? take[1] : take[0]);
			PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
			if ((Object)(object)player == (Object)(object)localPlayerController || (Object)(object)localPlayerController.ItemSlots[localPlayerController.currentItemSlot] == (Object)null || ((Object)localPlayerController.ItemSlots[localPlayerController.currentItemSlot].itemProperties).name != "MagnifyingGlass" || localPlayerController.isPlayerDead)
			{
				val.itemProperties.itemName = ((Component)val).GetComponentInChildren<ScanNodeProperties>().headerText;
			}
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(HUDManager), "DisplayNewScrapFound")]
	private static void pre2(ref List<GrabbableObject> ___itemsToBeDisplayed)
	{
		if (item[0] != null && (Object)(object)___itemsToBeDisplayed[0] != (Object)null && ((Object)___itemsToBeDisplayed[0].itemProperties).name == "Cog1" && (Object)(object)((Component)___itemsToBeDisplayed[0]).GetComponentInChildren<ScanNodeProperties>() != (Object)null)
		{
			___itemsToBeDisplayed[0].itemProperties.itemName = (___itemsToBeDisplayed[0].itemProperties.spawnPrefab.GetComponentInChildren<ScanNodeProperties>().headerText = ((Component)___itemsToBeDisplayed[0]).GetComponentInChildren<ScanNodeProperties>().headerText);
		}
	}

	[HarmonyPatch(typeof(HUDManager), "DisplayNewScrapFound")]
	[HarmonyTranspiler]
	private static IEnumerable<CodeInstruction> trn3(IEnumerable<CodeInstruction> Instrs)
	{
		List<CodeInstruction> i = new List<CodeInstruction>(Instrs);
		for (int j = 0; j < i.Count; j++)
		{
			if (j < i.Count - 1 && ((object)i[j + 1]).ToString() == "callvirt UnityEngine.Renderer[] UnityEngine.GameObject::GetComponentsInChildren()")
			{
				yield return new CodeInstruction(OpCodes.Ldloc_0, (object)null);
				yield return new CodeInstruction(OpCodes.Call, (object)typeof(blahaj).GetMethod("display_items"));
			}
			yield return i[j];
		}
	}

	public static void display_items(GameObject displayingObject)
	{
		if (item[0] != null && ((Object)displayingObject).name == "Cog(Clone)" && (Object)(object)displayingObject.GetComponentInChildren<ScanNodeProperties>() != (Object)null)
		{
			displayingObject.GetComponent<MeshFilter>().mesh = ((displayingObject.GetComponentInChildren<ScanNodeProperties>().headerText == item[1]) ? fish[1] : fish[0]);
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(StartOfRound), "Awake")]
	private static void pst2()
	{
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		if (!GameNetworkManager.Instance.disableSteam)
		{
			bool[] array = new bool[2];
			disconnected = array;
			synced_percents[0] = -1;
			if (GameNetworkManager.Instance.currentLobby.HasValue)
			{
				Lobby value = GameNetworkManager.Instance.currentLobby.Value;
				lobbyid = SteamId.op_Implicit(((Lobby)(ref value)).Id) % 1000000000;
				gura.mls.LogInfo((object)lobbyid);
			}
			else
			{
				gura.mls.LogError((object)"current lobby id is null");
			}
		}
	}

	[HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")]
	[HarmonyPostfix]
	private static void pst3()
	{
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Expected O, but got Unknown
		//IL_0092: 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_0040: Expected O, but got Unknown
		if (!sync)
		{
			if (NetworkManager.Singleton.IsHost)
			{
				NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler("4902.Blahaj-Host", new HandleNamedMessageDelegate(host_receive));
			}
			else
			{
				gura.mls.LogInfo((object)"requesting message from host");
				NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler("4902.Blahaj-Client", new HandleNamedMessageDelegate(client_receive));
				FastBufferWriter val = default(FastBufferWriter);
				((FastBufferWriter)(ref val))..ctor(0, (Allocator)2, -1);
				NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("4902.Blahaj-Host", 0uL, val, (NetworkDelivery)3);
				((FastBufferWriter)(ref val)).Dispose();
			}
			sync = true;
		}
	}

	private static void host_receive(ulong id, FastBufferReader r)
	{
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		if (NetworkManager.Singleton.IsHost)
		{
			try
			{
				gura.mls.LogInfo((object)"received request from client");
				string text = gura.blue_percentage.Value + "," + gura.pink_percentage.Value + "^" + seeds;
				gura.mls.LogInfo((object)("sending message " + text));
				FastBufferWriter val = default(FastBufferWriter);
				((FastBufferWriter)(ref val))..ctor(FastBufferWriter.GetWriteSize(text, false), (Allocator)2, -1);
				((FastBufferWriter)(ref val)).WriteValueSafe(text, false);
				NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("4902.Blahaj-Client", id, val, (NetworkDelivery)4);
				((FastBufferWriter)(ref val)).Dispose();
			}
			catch (Exception ex)
			{
				gura.mls.LogError((object)("Error writing strings while syncing: " + ex));
			}
		}
	}

	private static void client_receive(ulong id, FastBufferReader r)
	{
		if (!NetworkManager.Singleton.IsClient)
		{
			return;
		}
		try
		{
			string text = default(string);
			((FastBufferReader)(ref r)).ReadValueSafe(ref text, false);
			gura.mls.LogInfo((object)("client received message " + text));
			int num = 1;
			if (text.Length - text.Replace("^", "").Length == num)
			{
				string[] array = text.Split(new char[1] { '^' }, num + 1);
				synced_percents = Array.ConvertAll(array[0].Split(new char[1] { ',' }), Convert.ToInt32);
				seeds = array[1];
			}
			else
			{
				gura.mls.LogError((object)"received message was not what was expected. wasn't able to sync variables with host. (are the mod versions not the same?)");
				gura.mls.LogError((object)("found " + (text.Length - text.Replace("^", "").Length) + "/" + num + " ^ in message " + text));
			}
		}
		catch (Exception ex)
		{
			gura.mls.LogError((object)("Error reading strings while syncing: " + ex));
		}
	}

	[HarmonyPatch(typeof(GameNetworkManager), "Disconnect")]
	[HarmonyPrefix]
	private static void pre3()
	{
		disconnected[0] = true;
	}

	[HarmonyPatch(typeof(GameNetworkManager), "Disconnect")]
	[HarmonyPostfix]
	private static void pst4()
	{
		sync = false;
		seeds = "nil";
		lobbyid = 0uL;
		first_item = new bool[3] { true, true, true };
		saved_axle = "";
		loaded_axle = new List<string>();
		synced_percents = new int[2];
		synced_percents[0] = -1;
		if ((Object)(object)StartOfRound.Instance != (Object)null)
		{
			NetworkManager.Singleton.CustomMessagingManager.UnregisterNamedMessageHandler("4902.Blahaj-Host");
			NetworkManager.Singleton.CustomMessagingManager.UnregisterNamedMessageHandler("4902.Blahaj-Client");
		}
	}

	[HarmonyPatch(typeof(GameNetworkManager), "SaveItemsInShip")]
	[HarmonyTranspiler]
	private static IEnumerable<CodeInstruction> trn4(IEnumerable<CodeInstruction> Instrs)
	{
		List<CodeInstruction> i = new List<CodeInstruction>(Instrs);
		for (int j = 0; j < i.Count; j++)
		{
			yield return i[j];
			if (((object)i[j]).ToString() == "callvirt virtual void System.Collections.Generic.List<UnityEngine.Vector3>::Add(UnityEngine.Vector3 item)")
			{
				yield return new CodeInstruction(OpCodes.Ldloc_0, (object)null);
				yield return new CodeInstruction(OpCodes.Ldloc, (object)6);
				yield return new CodeInstruction(OpCodes.Call, (object)typeof(blahaj).GetMethod("save_axle"));
			}
		}
	}

	public static void save_axle(GrabbableObject[] _items, int index)
	{
		if (gura.cfg_saveseeds.Value && GameNetworkManager.Instance.isHostingGame && !GameNetworkManager.Instance.disableSteam && lobbyid != 0 && ((Object)_items[index].itemProperties).name == "Cog1")
		{
			if ((Object)(object)((Component)_items[index]).GetComponent<ItemTypeSeed>() != (Object)null)
			{
				ItemTypeSeed component = ((Component)_items[index]).GetComponent<ItemTypeSeed>();
				saved_axle = saved_axle + component.seed + "/";
			}
			else if ((Object)(object)((Component)_items[index]).GetComponent<NetworkObject>() != (Object)null)
			{
				saved_axle = saved_axle + (lobbyid + ((Component)_items[index]).GetComponent<NetworkObject>().NetworkObjectId) + "/";
				gura.mls.LogInfo((object)"ItemTypeSeed is null! saving seed for this item as lobbyid+networkobjectid");
			}
			else
			{
				saved_axle = saved_axle + new Shion().next32mm(1, 101) + "/";
				gura.mls.LogInfo((object)"ItemTypeSeed and NetworkObject are null! saving seed for this item as a random number from 1 to 100");
			}
		}
	}

	[HarmonyPatch(typeof(GameNetworkManager), "SaveGame")]
	[HarmonyPostfix]
	private static void pst5()
	{
		if (!gura.cfg_saveseeds.Value || !GameNetworkManager.Instance.isHostingGame || GameNetworkManager.Instance.disableSteam || !StartOfRound.Instance.inShipPhase || StartOfRound.Instance.isChallengeFile)
		{
			return;
		}
		try
		{
			if (saved_axle != "" && saved_axle.EndsWith("/"))
			{
				saved_axle = saved_axle.Substring(0, saved_axle.Length - 1);
			}
			gura.mls.LogInfo((object)("saving " + saved_axle));
			ES3.Save<string>("4902.Blahaj-1", saved_axle, GameNetworkManager.Instance.currentSaveFileName);
			saved_axle = "";
		}
		catch (Exception ex)
		{
			gura.mls.LogError((object)("Error saving item types: " + ex));
		}
	}

	[HarmonyTranspiler]
	[HarmonyPatch(typeof(StartOfRound), "LoadShipGrabbableItems")]
	private static IEnumerable<CodeInstruction> trn5(IEnumerable<CodeInstruction> Instrs)
	{
		List<CodeInstruction> i = new List<CodeInstruction>(Instrs);
		for (int j = 0; j < i.Count; j++)
		{
			yield return i[j];
			if (((object)i[j]).ToString() == "callvirt void Unity.Netcode.NetworkObject::Spawn(bool destroyWithScene)")
			{
				yield return new CodeInstruction(OpCodes.Ldloc_0, (object)null);
				yield return new CodeInstruction(OpCodes.Call, (object)typeof(blahaj).GetMethod("load_axle"));
			}
		}
	}

	public static void load_axle(GrabbableObject _item)
	{
		if (gura.cfg_saveseeds.Value && GameNetworkManager.Instance.isHostingGame && !GameNetworkManager.Instance.disableSteam && lobbyid != 0 && ((Object)_item.itemProperties).name == "Cog1")
		{
			if ((Object)(object)((Component)_item).GetComponent<NetworkObject>() != (Object)null)
			{
				loaded_axle.Add(((Component)_item).GetComponent<NetworkObject>().NetworkObjectId.ToString());
				return;
			}
			loaded_axle.Add("nil");
			gura.mls.LogInfo((object)"NetworkObject is null! the seed can't be loaded for this item");
		}
	}

	[HarmonyPatch(typeof(StartOfRound), "Start")]
	[HarmonyPostfix]
	private static void pst6()
	{
		if (!gura.cfg_saveseeds.Value || !GameNetworkManager.Instance.isHostingGame || GameNetworkManager.Instance.disableSteam)
		{
			return;
		}
		try
		{
			string text = ES3.Load<string>("4902.Blahaj-1", GameNetworkManager.Instance.currentSaveFileName, "nil");
			gura.mls.LogInfo((object)("loaded " + text));
			string[] array = text.Split(new char[1] { '/' });
			if (array[0] != "nil" && array[0] != "" && array.Length == loaded_axle.Count)
			{
				seeds = "";
				for (int i = 0; i < loaded_axle.Count; i++)
				{
					seeds = seeds + loaded_axle[i] + "." + array[i] + "/";
				}
				gura.mls.LogInfo((object)("current networkobjectids + saved seeds " + seeds));
			}
			loaded_axle = new List<string>();
		}
		catch (Exception ex)
		{
			gura.mls.LogError((object)("Error loading item types: " + ex));
		}
	}

	static blahaj()
	{
		bool[] array = new bool[2];
		disconnected = array;
		synced_percents = new int[2];
		saved_axle = "";
		loaded_axle = new List<string>();
	}
}
public class ItemTypeSeed : MonoBehaviour
{
	public string guid = gura.harmony.Id;

	public string seed;
}
public class Shion
{
	private ulong[] state;

	public Shion()
	{
		RandomNumberGenerator randomNumberGenerator = RandomNumberGenerator.Create();
		byte[] array = new byte[8];
		randomNumberGenerator.GetBytes(array, 0, 8);
		ulong seed = BitConverter.ToUInt64(array, 0);
		xorshift256_init(seed);
	}

	public Shion(ulong seed)
	{
		xorshift256_init(seed);
	}

	public int next32mm(int min, int max)
	{
		uint num = next32();
		double num2 = (double)(max - min) / 4294967295.0;
		return (int)((double)min + (double)num * num2);
	}

	public byte[] next8()
	{
		ulong value = xoshiro256ss();
		return BitConverter.GetBytes(value);
	}

	public uint next32()
	{
		byte[] value = next8();
		return BitConverter.ToUInt32(value, 0);
	}

	public ulong next64()
	{
		return xoshiro256ss();
	}

	public double next01()
	{
		ulong num = xoshiro256ss();
		return (double)num / 1.8446744073709552E+19;
	}

	private ulong splitmix64(ulong partialstate)
	{
		partialstate += 11400714819323198485uL;
		partialstate = (partialstate ^ (partialstate >> 30)) * 13787848793156543929uL;
		partialstate = (partialstate ^ (partialstate >> 27)) * 10723151780598845931uL;
		return partialstate ^ (partialstate >> 31);
	}

	private void xorshift256_init(ulong seed)
	{
		ulong[] array = new ulong[4];
		array[0] = splitmix64(seed);
		array[1] = splitmix64(array[0]);
		array[2] = splitmix64(array[1]);
		array[3] = splitmix64(array[2]);
		state = array;
	}

	private ulong rotl64(ulong x, int k)
	{
		return (x << k) | (x >> 64 - k);
	}

	private ulong xoshiro256ss()
	{
		ulong result = rotl64(state[1] * 5, 7) * 9;
		ulong num = state[1] << 17;
		state[2] ^= state[0];
		state[3] ^= state[1];
		state[1] ^= state[2];
		state[0] ^= state[3];
		state[2] ^= num;
		state[3] = rotl64(state[3], 45);
		return result;
	}
}