Decompiled source of Koyuki v1.1.0

plugins/4902-koyuki.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Kurosaki.Patches;
using Steamworks;
using Steamworks.Data;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace Kurosaki
{
	[BepInPlugin("4902.Koyuki", "Koyuki", "1.0.0")]
	public class koyu : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("4902.Koyuki");

		public static ManualLogSource mls;

		public static ConfigEntry<int> percentage;

		private void Awake()
		{
			percentage = ((BaseUnityPlugin)this).Config.Bind<int>("", "koyuki_percent", 50, "percentage that koyuki will replace fish\ninput = percentage, 50 is 50% etc");
			mls = Logger.CreateLogSource("Koyuki");
			mls.LogInfo((object)"yaata");
			harmony.PatchAll(typeof(go));
			harmony.PatchAll(typeof(pcb));
			harmony.PatchAll(typeof(hm));
		}
	}
}
namespace Kurosaki.Patches
{
	[HarmonyPatch(typeof(GrabbableObject))]
	internal class go
	{
		public static string[] item = new string[2];

		public static Mesh[] fish = (Mesh[])(object)new Mesh[7];

		public static AudioClip[] take = (AudioClip[])(object)new AudioClip[3];

		public static AudioClip[] give = (AudioClip[])(object)new AudioClip[3];

		public static Vector3[] position = (Vector3[])(object)new Vector3[2];

		public static Vector3[] rotation = (Vector3[])(object)new Vector3[2];

		public static bool[] z = new bool[2];

		public static Transform[] sequel = (Transform[])(object)new Transform[6];

		[HarmonyPatch("Start")]
		private static void Postfix(GrabbableObject __instance, ref MeshRenderer ___mainObjectRenderer)
		{
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02de: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0349: Unknown result type (might be due to invalid IL or missing references)
			//IL_036e: Unknown result type (might be due to invalid IL or missing references)
			//IL_038e: Unknown result type (might be due to invalid IL or missing references)
			//IL_04da: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_051c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0649: Unknown result type (might be due to invalid IL or missing references)
			//IL_064e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0665: Unknown result type (might be due to invalid IL or missing references)
			//IL_066a: Unknown result type (might be due to invalid IL or missing references)
			if (!(((Object)__instance.itemProperties).name == "FishTestProp"))
			{
				return;
			}
			if (item[0] == null)
			{
				string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "4902-koyuki").Replace("\\", "/");
				koyu.mls.LogMessage((object)("Searching this filepath:" + text));
				AssetBundle assetBundle = AssetBundle.LoadFromFileAsync(text).assetBundle;
				item[0] = "Fish";
				fish[0] = ((Component)___mainObjectRenderer).GetComponent<MeshFilter>().mesh;
				take[0] = __instance.itemProperties.grabSFX;
				give[0] = __instance.itemProperties.dropSFX;
				ref Vector3 reference = ref position[0];
				reference = __instance.itemProperties.positionOffset;
				ref Vector3 reference2 = ref rotation[0];
				reference2 = __instance.itemProperties.rotationOffset;
				z[0] = false;
				item[1] = "Koyuki";
				Transform[] componentsInChildren = Object.Instantiate<GameObject>(assetBundle.LoadAsset<GameObject>("koyuki_merged_90x.obj")).GetComponentsInChildren<Transform>();
				for (int i = 1; i <= 6; i++)
				{
					((Component)componentsInChildren[i]).GetComponent<MeshFilter>().mesh = fish1.fish2(((Component)componentsInChildren[i]).GetComponent<MeshFilter>().mesh);
					Object.Instantiate<Transform>(componentsInChildren[i]).SetParent(((Component)___mainObjectRenderer).transform);
					componentsInChildren[i].SetParent(__instance.itemProperties.spawnPrefab.transform);
					Transform[] componentsInChildren2 = ((Component)___mainObjectRenderer).GetComponentsInChildren<Transform>();
					Transform obj = componentsInChildren2[i + 1];
					Vector3 localPosition = (componentsInChildren[i].localPosition = new Vector3(-7.5f, 0f, 0f));
					obj.localPosition = localPosition;
					Transform obj2 = componentsInChildren2[i + 1];
					Quaternion localRotation = (componentsInChildren[i].localRotation = new Quaternion(0f, 0.7071f, 0f, 0.7071f));
					obj2.localRotation = localRotation;
					Transform obj3 = componentsInChildren2[i + 1];
					localPosition = (componentsInChildren[i].localScale = new Vector3(10f, 10f, 32.65306f));
					obj3.localScale = localPosition;
					fish[i] = Object.Instantiate<Mesh>(((Component)componentsInChildren2[i + 1]).GetComponent<MeshFilter>().mesh);
					sequel[i - 1] = componentsInChildren[i];
				}
				take[1] = assetBundle.LoadAsset<AudioClip>("koyuki_commonskill");
				take[2] = assetBundle.LoadAsset<AudioClip>("koyuki_formation_in_1");
				give[1] = assetBundle.LoadAsset<AudioClip>("koyuki_battle_damage_1");
				give[2] = assetBundle.LoadAsset<AudioClip>("koyuki_formation_select");
				ref Vector3 reference3 = ref position[1];
				reference3 = new Vector3(-0.12f, 0.09f, -0.08f);
				ref Vector3 reference4 = ref rotation[1];
				reference4 = new Vector3(23f, 0f, 0f);
				z[1] = true;
			}
			else if (((Component)___mainObjectRenderer).GetComponentsInChildren<Transform>().Length < 6)
			{
				for (int i = 0; i < 6; i++)
				{
					Object.Instantiate<Transform>(sequel[i]).SetParent(((Component)___mainObjectRenderer).transform);
					Transform[] componentsInChildren2 = ((Component)___mainObjectRenderer).GetComponentsInChildren<Transform>();
					componentsInChildren2[i + 2].localPosition = new Vector3(-7.5f, 0f, 0f);
					componentsInChildren2[i + 2].localRotation = new Quaternion(0f, 0.7071f, 0f, 0.7071f);
					componentsInChildren2[i + 2].localScale = new Vector3(10f, 10f, 32.65306f);
				}
			}
			if (item[0] == null)
			{
				return;
			}
			int num;
			if (GameNetworkManager.Instance.disableSteam)
			{
				num = ((Random.Range(0, 100) < koyu.percentage.Value) ? 1 : 0);
			}
			else
			{
				Lobby value = GameNetworkManager.Instance.currentLobby.Value;
				num = ((new Random((int)((SteamId.op_Implicit(((Lobby)(ref value)).Id) + ((Component)__instance).GetComponent<NetworkObject>().NetworkObjectId) % 1000000000)).Next(0, 100) < koyu.percentage.Value) ? 1 : 0);
			}
			int num2 = num;
			if (num2 == 1)
			{
				for (int i = 1; i <= 6; i++)
				{
					((Component)__instance.itemProperties.spawnPrefab.GetComponentsInChildren<Transform>()[i + 1]).GetComponent<MeshFilter>().mesh = fish[i];
					((Component)((Component)___mainObjectRenderer).GetComponentsInChildren<Transform>()[i + 1]).GetComponent<MeshFilter>().mesh = fish[i];
				}
				__instance.itemProperties.spawnPrefab.GetComponent<MeshFilter>().mesh = null;
				BoxCollider component = ((Component)___mainObjectRenderer).GetComponent<BoxCollider>();
				component.center = new Vector3(8f, 0.3f, 0f);
				component.size = new Vector3(31f, 3.3f, 3.3f);
				((Component)((Component)___mainObjectRenderer).GetComponentInChildren<ScanNodeProperties>()).transform.localPosition = new Vector3(8f, 0.3f, 0f);
				((Component)___mainObjectRenderer).GetComponent<MeshFilter>().mesh = null;
				__instance.itemProperties.grabSFX = take[Random.Range(1, 3)];
				__instance.itemProperties.dropSFX = give[Random.Range(1, 3)];
			}
			else
			{
				for (int i = 1; i <= 6; i++)
				{
					((Component)__instance.itemProperties.spawnPrefab.GetComponentsInChildren<Transform>()[i + 1]).GetComponent<MeshFilter>().mesh = null;
					((Component)((Component)___mainObjectRenderer).GetComponentsInChildren<Transform>()[i + 1]).GetComponent<MeshFilter>().mesh = null;
				}
				__instance.itemProperties.spawnPrefab.GetComponent<MeshFilter>().mesh = fish[0];
				((Component)___mainObjectRenderer).GetComponent<MeshFilter>().mesh = fish[0];
				__instance.itemProperties.grabSFX = take[0];
				__instance.itemProperties.dropSFX = give[0];
			}
			__instance.itemProperties.itemName = item[num2];
			((Component)___mainObjectRenderer).GetComponentInChildren<ScanNodeProperties>().headerText = item[num2];
			__instance.itemProperties.positionOffset = position[num2];
			__instance.itemProperties.rotationOffset = rotation[num2];
			__instance.itemProperties.canBeInspected = z[num2];
		}

		[HarmonyPatch("PlayDropSFX")]
		private static void Prefix(ref GrabbableObject __instance)
		{
			if (item[0] != null && (Object)(object)__instance != (Object)null && ((Object)__instance.itemProperties).name == "FishTestProp" && (Object)(object)__instance.mainObjectRenderer != (Object)null && (Object)(object)((Component)__instance.mainObjectRenderer).GetComponentInChildren<ScanNodeProperties>() != (Object)null)
			{
				if (((Component)__instance.mainObjectRenderer).GetComponentInChildren<ScanNodeProperties>().headerText == item[1])
				{
					__instance.itemProperties.dropSFX = give[Random.Range(1, 3)];
				}
				else
				{
					__instance.itemProperties.dropSFX = give[0];
				}
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class pcb
	{
		[HarmonyPatch("BeginGrabObject")]
		private static void Postfix(ref GrabbableObject ___currentlyGrabbingObject)
		{
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			if (go.item[0] != null && (Object)(object)___currentlyGrabbingObject != (Object)null && ((Object)___currentlyGrabbingObject.itemProperties).name == "FishTestProp" && (Object)(object)___currentlyGrabbingObject.mainObjectRenderer != (Object)null && (Object)(object)((Component)___currentlyGrabbingObject.mainObjectRenderer).GetComponentInChildren<ScanNodeProperties>() != (Object)null)
			{
				if (((Component)___currentlyGrabbingObject.mainObjectRenderer).GetComponentInChildren<ScanNodeProperties>().headerText == go.item[1])
				{
					___currentlyGrabbingObject.itemProperties.grabSFX = go.take[Random.Range(1, 3)];
					___currentlyGrabbingObject.itemProperties.positionOffset = go.position[1];
					___currentlyGrabbingObject.itemProperties.rotationOffset = go.rotation[1];
					___currentlyGrabbingObject.itemProperties.canBeInspected = go.z[1];
				}
				else
				{
					___currentlyGrabbingObject.itemProperties.grabSFX = go.take[0];
					___currentlyGrabbingObject.itemProperties.positionOffset = go.position[0];
					___currentlyGrabbingObject.itemProperties.rotationOffset = go.rotation[0];
					___currentlyGrabbingObject.itemProperties.canBeInspected = go.z[0];
				}
				___currentlyGrabbingObject.itemProperties.itemName = ((Component)___currentlyGrabbingObject.mainObjectRenderer).GetComponentInChildren<ScanNodeProperties>().headerText;
			}
		}

		[HarmonyPatch("ScrollMouse_performed")]
		private static void Prefix(ref CallbackContext context, ref int ___currentItemSlot, ref GrabbableObject[] ___ItemSlots)
		{
			if (go.item[0] == null)
			{
				return;
			}
			bool flag = false;
			if (((CallbackContext)(ref context)).ReadValue<float>() > 0f)
			{
				flag = true;
			}
			int num = ___currentItemSlot - 1;
			if (flag)
			{
				num = (___currentItemSlot + 1) % ___ItemSlots.Length;
			}
			else if (___currentItemSlot == 0)
			{
				num = ___ItemSlots.Length - 1;
			}
			if (num >= 0 && num < ___ItemSlots.Length && (Object)(object)___ItemSlots[num] != (Object)null && ((Object)___ItemSlots[num].itemProperties).name == "FishTestProp" && (Object)(object)___ItemSlots[num].mainObjectRenderer != (Object)null && (Object)(object)((Component)___ItemSlots[num].mainObjectRenderer).GetComponentInChildren<ScanNodeProperties>() != (Object)null)
			{
				if (((Component)___ItemSlots[num].mainObjectRenderer).GetComponentInChildren<ScanNodeProperties>().headerText == go.item[1])
				{
					___ItemSlots[num].itemProperties.grabSFX = go.take[Random.Range(1, 3)];
					___ItemSlots[num].itemProperties.canBeInspected = go.z[1];
				}
				else
				{
					___ItemSlots[num].itemProperties.grabSFX = go.take[0];
					___ItemSlots[num].itemProperties.canBeInspected = go.z[0];
				}
				___ItemSlots[num].itemProperties.itemName = ((Component)___ItemSlots[num].mainObjectRenderer).GetComponentInChildren<ScanNodeProperties>().headerText;
			}
		}

		[HarmonyPatch("ScrollMouse_performed")]
		[HarmonyPostfix]
		private static void scroll(ref int ___currentItemSlot, ref GrabbableObject[] ___ItemSlots)
		{
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			if (go.item[0] == null || !((Object)(object)___ItemSlots[___currentItemSlot] != (Object)null) || !(((Object)___ItemSlots[___currentItemSlot].itemProperties).name == "FishTestProp") || !((Object)(object)___ItemSlots[___currentItemSlot].mainObjectRenderer != (Object)null) || !((Object)(object)((Component)___ItemSlots[___currentItemSlot]).GetComponentInChildren<ScanNodeProperties>() != (Object)null))
			{
				return;
			}
			for (int i = 0; i < go.item.Length; i++)
			{
				if (((Component)___ItemSlots[___currentItemSlot].mainObjectRenderer).GetComponentInChildren<ScanNodeProperties>().headerText == go.item[i])
				{
					___ItemSlots[___currentItemSlot].itemProperties.positionOffset = go.position[i];
					___ItemSlots[___currentItemSlot].itemProperties.rotationOffset = go.rotation[i];
					break;
				}
			}
		}
	}
	[HarmonyPatch(typeof(HUDManager))]
	internal class hm
	{
		[HarmonyPatch("DisplayNewScrapFound")]
		[HarmonyPrefix]
		private static void Prefix1(ref List<GrabbableObject> ___itemsToBeDisplayed)
		{
			if (go.item[0] != null && (Object)(object)___itemsToBeDisplayed[0] != (Object)null && ((Object)___itemsToBeDisplayed[0].itemProperties).name == "FishTestProp" && (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);
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("displayScrapTimer")]
		private static void Prefix2(ref GameObject displayingObject)
		{
			if (go.item[0] == null || !(((Object)displayingObject).name == "FishTestProp(Clone)") || !((Object)(object)displayingObject.GetComponentInChildren<ScanNodeProperties>() != (Object)null))
			{
				return;
			}
			if (displayingObject.GetComponentInChildren<ScanNodeProperties>().headerText == go.item[1])
			{
				for (int i = 1; i <= 6; i++)
				{
					((Component)displayingObject.GetComponentsInChildren<Transform>()[i + 1]).GetComponent<MeshFilter>().mesh = go.fish[i];
				}
				displayingObject.GetComponent<MeshFilter>().mesh = null;
			}
			else
			{
				for (int i = 1; i <= 6; i++)
				{
					((Component)displayingObject.GetComponentsInChildren<Transform>()[i + 1]).GetComponent<MeshFilter>().mesh = null;
				}
				displayingObject.GetComponent<MeshFilter>().mesh = go.fish[0];
			}
		}
	}
	internal class fish1
	{
		public static Mesh fish2(Mesh nonReadableMesh)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			Mesh val = new Mesh();
			val.indexFormat = nonReadableMesh.indexFormat;
			GraphicsBuffer vertexBuffer = nonReadableMesh.GetVertexBuffer(0);
			int num = vertexBuffer.stride * vertexBuffer.count;
			byte[] array = new byte[num];
			vertexBuffer.GetData((Array)array);
			val.SetVertexBufferParams(nonReadableMesh.vertexCount, nonReadableMesh.GetVertexAttributes());
			val.SetVertexBufferData<byte>(array, 0, 0, num, 0, (MeshUpdateFlags)0);
			vertexBuffer.Release();
			val.subMeshCount = nonReadableMesh.subMeshCount;
			GraphicsBuffer indexBuffer = nonReadableMesh.GetIndexBuffer();
			int num2 = indexBuffer.stride * indexBuffer.count;
			byte[] array2 = new byte[num2];
			indexBuffer.GetData((Array)array2);
			val.SetIndexBufferParams(indexBuffer.count, nonReadableMesh.indexFormat);
			val.SetIndexBufferData<byte>(array2, 0, 0, num2, (MeshUpdateFlags)0);
			indexBuffer.Release();
			uint num3 = 0u;
			for (int i = 0; i < val.subMeshCount; i++)
			{
				uint indexCount = nonReadableMesh.GetIndexCount(i);
				val.SetSubMesh(i, new SubMeshDescriptor((int)num3, (int)indexCount, (MeshTopology)0), (MeshUpdateFlags)0);
				num3 += indexCount;
			}
			val.RecalculateNormals();
			val.RecalculateBounds();
			return val;
		}
	}
}