Decompiled source of Nekogiri v1.0.6

BepInEx/plugins/Nekogiri.dll

Decompiled a month ago
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.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using HarmonyLib;
using Photon.Pun;
using Photon.Realtime;
using Steamworks;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Nekogiri")]
[assembly: AssemblyDescription("Allow REPO to work with custom photon servers")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Kirigiri")]
[assembly: AssemblyProduct("Nekogiri")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("be8d4052-15e4-4cc0-8481-034b8dd0e20d")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.5")]
namespace NekogiriMod;

[BepInPlugin("kirigiri.repo.nekogiri", "Nekogiri", "1.0.4.0")]
public class NekogiriMod : BaseUnityPlugin
{
	[HarmonyPatch(typeof(NetworkConnect), "Start")]
	public class NetworkConnectPatch
	{
		[HarmonyPrefix]
		public static bool Prefix()
		{
			Debug.Log((object)"Patching NetworkConnect.Start method.");
			new NekogiriMod().CustomStart();
			return true;
		}
	}

	[HarmonyPatch(typeof(MenuPageMain), "Start")]
	public class MenuPageMainPatch
	{
		[HarmonyPrefix]
		public static bool Prefix()
		{
			Debug.Log((object)"Patching MenuPageMain.Start method.");
			new NekogiriMod().WelcomeMessage();
			return true;
		}
	}

	[HarmonyPatch(typeof(SteamManager), "Awake")]
	public class SteamManagerPatch
	{
		[HarmonyPrefix]
		public static bool Prefix()
		{
			Debug.Log((object)"Patching SteamManager.Awake method.");
			new NekogiriMod().CustomSteamAppID();
			return true;
		}
	}

	[HarmonyPatch(typeof(SteamManager), "SendSteamAuthTicket")]
	public class SendSteamAuthTicketPatch
	{
		[HarmonyPrefix]
		public static bool Prefix()
		{
			Debug.Log((object)"Patching SteamManager.SendSteamAuthTicket method.");
			new NekogiriMod().CustomAuth();
			return false;
		}
	}

	[Serializable]
	public class PhotonAppSettings
	{
		public string AppIdRealtime = "";

		public string AppIdChat = "";

		public string AppIdVoice = "";

		public string AppIdFusion = "";

		public string FixedRegion = "";
	}

	internal AuthTicket steamAuthTicket;

	private void Awake()
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Nekogiri has loaded!");
		new Harmony("kirigiri.repo.nekogiri").PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Made with <3 By Kirigiri \nhttps://discord.gg/zn2a2A65My");
	}

	private void CustomStart()
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Custom Start method executed!");
		ServerSettings val = Resources.Load<ServerSettings>("PhotonServerSettings");
		try
		{
			string text = Path.Combine(Path.GetDirectoryName(Application.dataPath), "Kirigiri.ini");
			if (File.Exists(text))
			{
				Dictionary<string, string> dictionary = (from line in File.ReadAllLines(text)
					where !string.IsNullOrWhiteSpace(line) && !line.StartsWith(";")
					select line.Split(new char[1] { '=' }) into parts
					where parts.Length == 2
					select parts).ToDictionary((string[] parts) => parts[0].Trim(), (string[] parts) => parts[1].Trim());
				if (dictionary.ContainsKey("AppIdRealtime"))
				{
					val.AppSettings.AppIdRealtime = dictionary["AppIdRealtime"];
				}
				if (dictionary.ContainsKey("AppIdChat"))
				{
					val.AppSettings.AppIdChat = dictionary["AppIdChat"];
				}
				if (dictionary.ContainsKey("AppIdVoice"))
				{
					val.AppSettings.AppIdVoice = dictionary["AppIdVoice"];
				}
				if (dictionary.ContainsKey("AppIdFusion"))
				{
					val.AppSettings.AppIdFusion = dictionary["AppIdFusion"];
				}
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Address read are " + val.AppSettings.AppIdRealtime + " & " + val.AppSettings.AppIdVoice));
				if (dictionary.ContainsKey("FixedRegion"))
				{
					PhotonNetwork.PhotonServerSettings.AppSettings.FixedRegion = dictionary["FixedRegion"];
				}
				else
				{
					PhotonNetwork.PhotonServerSettings.AppSettings.FixedRegion = "";
				}
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Photon settings loaded from " + text));
			}
			else
			{
				PhotonNetwork.PhotonServerSettings.AppSettings.FixedRegion = "";
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Settings file not found at " + text + ". Using default values."));
			}
		}
		catch (Exception ex)
		{
			PhotonNetwork.PhotonServerSettings.AppSettings.FixedRegion = "";
			((BaseUnityPlugin)this).Logger.LogError((object)("Error loading Photon settings: " + ex.Message + ". Using default values."));
		}
	}

	private void CustomSteamAppID()
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Custom Steam AppID method executed!");
		string text = Path.Combine(Path.GetDirectoryName(Application.dataPath), "Kirigiri.ini");
		uint num = 480u;
		try
		{
			if (File.Exists(text))
			{
				Dictionary<string, string> dictionary = (from line in File.ReadAllLines(text)
					where !string.IsNullOrWhiteSpace(line) && !line.StartsWith(";")
					select line.Split(new char[1] { '=' }) into parts
					where parts.Length == 2
					select parts).ToDictionary((string[] parts) => parts[0].Trim(), (string[] parts) => parts[1].Trim());
				if (dictionary.ContainsKey("SteamAppId"))
				{
					if (uint.TryParse(dictionary["SteamAppId"], out var result))
					{
						num = result;
					}
					else
					{
						((BaseUnityPlugin)this).Logger.LogWarning((object)"Invalid SteamAppId in the INI file, defaulting to 480.");
					}
				}
				else
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"SteamAppId not found in the INI file, defaulting to 480.");
				}
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Settings file not found at " + text + ". Using default App ID 480."));
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("Error reading SteamAppId from INI: " + ex.Message + ". Defaulting to App ID 480."));
		}
		SteamClient.Init(num, true);
		((BaseUnityPlugin)this).Logger.LogInfo((object)$"Steam client initialized with AppId {num}");
	}

	public void CustomAuth()
	{
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Expected O, but got Unknown
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0373: Unknown result type (might be due to invalid IL or missing references)
		//IL_0366: Unknown result type (might be due to invalid IL or missing references)
		//IL_0346: Unknown result type (might be due to invalid IL or missing references)
		//IL_0342: Unknown result type (might be due to invalid IL or missing references)
		//IL_0379: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_036b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0361: Unknown result type (might be due to invalid IL or missing references)
		//IL_035c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0357: Unknown result type (might be due to invalid IL or missing references)
		//IL_034a: Unknown result type (might be due to invalid IL or missing references)
		//IL_034e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0352: Unknown result type (might be due to invalid IL or missing references)
		//IL_033e: Unknown result type (might be due to invalid IL or missing references)
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Custom Auth method executed!");
		string text = Path.Combine(Path.GetDirectoryName(Application.dataPath), "Kirigiri.ini");
		string text2 = "None";
		try
		{
			if (File.Exists(text))
			{
				Dictionary<string, string> dictionary = (from line in File.ReadAllLines(text)
					where !string.IsNullOrWhiteSpace(line) && !line.StartsWith(";")
					select line.Split(new char[1] { '=' }) into parts
					where parts.Length == 2
					select parts).ToDictionary((string[] parts) => parts[0].Trim(), (string[] parts) => parts[1].Trim());
				if (dictionary.ContainsKey("Auth"))
				{
					text2 = dictionary["Auth"];
				}
				else
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"Auth setting not found in the INI file, defaulting to 'None'.");
				}
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Settings file not found at " + text + ". Using default Auth value 'None'."));
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("Error reading Auth setting from INI: " + ex.Message + ". Defaulting to 'None'."));
		}
		PhotonNetwork.AuthValues = new AuthenticationValues();
		AuthenticationValues authValues = PhotonNetwork.AuthValues;
		SteamId steamId = SteamClient.SteamId;
		authValues.UserId = ((object)(SteamId)(ref steamId)).ToString();
		CustomAuthenticationType val = (CustomAuthenticationType)255;
		val = (CustomAuthenticationType)(text2.ToLower() switch
		{
			"custom" => 0, 
			"steam" => 1, 
			"facebook" => 2, 
			"oculus" => 3, 
			"playstation4" => 4, 
			"xbox" => 5, 
			"viveport" => 10, 
			"nintendoswitch" => 11, 
			"playstation5" => 12, 
			"epic" => 13, 
			"facebookgaming" => 15, 
			_ => 255, 
		});
		PhotonNetwork.AuthValues.AuthType = val;
		string text3 = GetSteamAuthTicket(out steamAuthTicket);
		PhotonNetwork.AuthValues.AddAuthParameter("ticket", text3);
		((BaseUnityPlugin)this).Logger.LogInfo((object)$"Patched Auth to {PhotonNetwork.AuthValues.AuthType}!");
	}

	private void WelcomeMessage()
	{
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		string path = Path.Combine(Path.GetDirectoryName(Application.dataPath), "Kirigiri.ini");
		try
		{
			if (!File.Exists(path))
			{
				return;
			}
			List<string> list = File.ReadAllLines(path).ToList();
			bool flag = false;
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].StartsWith("FirstLaunch"))
				{
					if (list[i].Contains("FirstLaunch=1"))
					{
						MenuManager.instance.PagePopUp("Nekogiri", Color.magenta, "<size=20>This mod has been made by Kirigiri.\nMake sure to create an account on <color=#808080>https://www.photonengine.com/</color> and to fill the values inside the <color=#34ebde>Kirigiri.ini</color> file !\nThis message will appear only once, Have fun !", "OK");
						Application.OpenURL("https://www.photonengine.com/");
						list[i] = "FirstLaunch=0";
						flag = true;
						((BaseUnityPlugin)this).Logger.LogInfo((object)"Welcome message displayed and FirstLaunch updated.");
					}
					break;
				}
			}
			if (flag)
			{
				File.WriteAllLines(path, list);
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("Error reading or updating Kirigiri.ini: " + ex.Message));
		}
	}

	private string GetSteamAuthTicket(out AuthTicket ticket)
	{
		Debug.Log((object)"Getting Steam Auth Ticket...");
		ticket = SteamUser.GetAuthSessionTicket();
		StringBuilder stringBuilder = new StringBuilder();
		for (int i = 0; i < ticket.Data.Length; i++)
		{
			stringBuilder.AppendFormat("{0:x2}", ticket.Data[i]);
		}
		return stringBuilder.ToString();
	}
}