Decompiled source of Nekogiri v1.0.7

Nekogiri.dll

Decompiled 4 days 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.1.0.2")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.1.0.2")]
namespace NekogiriMod;

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

	[HarmonyPatch(typeof(MenuPageMain), "Start")]
	public class MenuPageMainPatch
	{
		[HarmonyPrefix]
		public static bool Prefix()
		{
			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;
		}
	}

	internal AuthTicket steamAuthTicket;

	private void Awake()
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		((BaseUnityPlugin)this).Logger.LogInfo((object)"\r\n ██ ▄█▀ ██▓ ██▀███   ██▓  ▄████  ██▓ ██▀███   ██▓\r\n ██▄█▒ ▓██▒▓██ ▒ ██▒▓██▒ ██▒ ▀█▒▓██▒▓██ ▒ ██▒▓██▒\r\n▓███▄░ ▒██▒▓██ ░▄█ ▒▒██▒▒██░▄▄▄░▒██▒▓██ ░▄█ ▒▒██▒\r\n▓██ █▄ ░██░▒██▀▀█▄  ░██░░▓█  ██▓░██░▒██▀▀█▄  ░██░\r\n▒██▒ █▄░██░░██▓ ▒██▒░██░░▒▓███▀▒░██░░██▓ ▒██▒░██░\r\n▒ ▒▒ ▓▒░▓  ░ ▒▓ ░▒▓░░▓   ░▒   ▒ ░▓  ░ ▒▓ ░▒▓░░▓  \r\n░ ░▒ ▒░ ▒ ░  ░▒ ░ ▒░ ▒ ░  ░   ░  ▒ ░  ░▒ ░ ▒░ ▒ ░\r\n░ ░░ ░  ▒ ░  ░░   ░  ▒ ░░ ░   ░  ▒ ░  ░░   ░  ▒ ░\r\n░  ░    ░     ░      ░        ░  ░     ░      ░  \r\n                                                 \r\n");
		((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!");
		string text = Path.Combine(Path.GetDirectoryName(Application.dataPath), "Kirigiri.ini");
		string text2 = "99515094-45b7-4c98-ab70-a448c548c83d";
		string text3 = "dfc40a01-c3a4-4395-9707-b71118816d2b";
		bool flag = false;
		if (File.Exists(text))
		{
			try
			{
				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.TryGetValue("UseDefaultRepoServers", out var value) && value == "1")
				{
					flag = true;
				}
				if (!flag)
				{
					if (dictionary.TryGetValue("AppIdRealtime", out var value2) && !string.IsNullOrWhiteSpace(value2))
					{
						text2 = value2;
						Debug.Log((object)("[Photon] AppIdRealtime from INI: " + text2));
					}
					if (dictionary.TryGetValue("AppIdVoice", out var value3) && !string.IsNullOrWhiteSpace(value3))
					{
						text3 = value3;
						Debug.Log((object)("[Photon] AppIdVoice from INI: " + text3));
					}
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Error reading INI file, using default App IDs. Details: " + ex.Message));
			}
		}
		else
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("INI file not found at " + text + ", using default App IDs."));
			flag = true;
		}
		SemiLogger.LogAxel((object)"PhotonSetAppId", (GameObject)null, (Color?)null);
		PhotonNetwork.PhotonServerSettings.AppSettings.AppIdRealtime = text2;
		PhotonNetwork.PhotonServerSettings.AppSettings.AppIdVoice = text3;
	}

	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 = 3241660u;
		bool flag = false;
		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.TryGetValue("UseDefaultRepoServers", out var value) && value == "1")
				{
					flag = true;
					((BaseUnityPlugin)this).Logger.LogInfo((object)"Using default R.E.P.O. servers !.");
				}
				if (!flag)
				{
					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 3241660.");
						}
					}
					else
					{
						((BaseUnityPlugin)this).Logger.LogWarning((object)"SteamAppId not found in the INI file, defaulting to 3241660.");
					}
				}
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Settings file not found at " + text + ". Using default App ID 3241660."));
				flag = true;
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("Error reading SteamAppId from INI: " + ex.Message + ". Defaulting to App ID 3241660."));
		}
		SteamClient.Init(num, true);
		((BaseUnityPlugin)this).Logger.LogInfo((object)$"Steam client initialized with AppId {num}");
	}

	public void CustomAuth()
	{
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Expected O, but got Unknown
		//IL_0194: Unknown result type (might be due to invalid IL or missing references)
		//IL_0199: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_0396: Unknown result type (might be due to invalid IL or missing references)
		//IL_0389: Unknown result type (might be due to invalid IL or missing references)
		//IL_0369: Unknown result type (might be due to invalid IL or missing references)
		//IL_0365: Unknown result type (might be due to invalid IL or missing references)
		//IL_039c: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d1: 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_0384: Unknown result type (might be due to invalid IL or missing references)
		//IL_037f: Unknown result type (might be due to invalid IL or missing references)
		//IL_037a: Unknown result type (might be due to invalid IL or missing references)
		//IL_036d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0371: Unknown result type (might be due to invalid IL or missing references)
		//IL_0375: 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)
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Custom Auth method executed!");
		string text = Path.Combine(Path.GetDirectoryName(Application.dataPath), "Kirigiri.ini");
		string text2 = "Steam";
		bool flag = false;
		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.TryGetValue("UseDefaultRepoServers", out var value) && value == "1")
				{
					flag = true;
				}
				if (!flag)
				{
					if (dictionary.ContainsKey("Auth"))
					{
						text2 = dictionary["Auth"];
					}
					else
					{
						((BaseUnityPlugin)this).Logger.LogWarning((object)"Auth setting not found in the INI file, defaulting to 'Steam'.");
					}
				}
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Settings file not found at " + text + ". Using default Auth value 'Steam'."));
				flag = true;
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("Error reading Auth setting from INI: " + ex.Message + ". Defaulting to 'Steam'."));
		}
		PhotonNetwork.AuthValues = new AuthenticationValues();
		AuthenticationValues authValues = PhotonNetwork.AuthValues;
		SteamId steamId = SteamClient.SteamId;
		authValues.UserId = ((object)(SteamId)(ref steamId)).ToString();
		CustomAuthenticationType val = (CustomAuthenticationType)1;
		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_005f: 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=#cc00ff>Kirigiri.ini</color> file !\nThis message will appear only once, Have fun !", "OK", true);
						list[i] = "FirstLaunch=0";
						flag = true;
					}
					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();
	}
}