using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Networking;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("CloudAPI_Emulator")]
[assembly: AssemblyDescription("Emulate the PEAK CloudAPI to make custom servers")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Kirigiri")]
[assembly: AssemblyProduct("CloudAPI_Emulator")]
[assembly: AssemblyCopyright("Kirigiri © 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.0")]
namespace CloudAPI_Emulator;
[BepInPlugin("kirigiri.peak.cloudapiemulator", "CloudAPI_Emulator", "1.0.0.0")]
public class CloudAPI_Emulator : BaseUnityPlugin
{
[HarmonyPatch(typeof(CloudAPI), "CheckVersion")]
public class CloudAPICheckVersionPatch
{
private static readonly string emulatorFilePath = Path.Combine(Paths.ConfigPath, "CloudAPI_Emulator.txt");
private static readonly string defaultURL = "https://peaklogin.azurewebsites.net/api/VersionCheck?version=99.99";
[HarmonyPrefix]
public static bool Prefix(Action<LoginResponse> response)
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
GameHandler.AddStatus<QueryingGameTimeStatus>((GameStatus)new QueryingGameTimeStatus());
string emulatorURL = GetEmulatorURL();
Debug.Log((object)("Sending GET Request to: " + emulatorURL));
UnityWebRequest request = UnityWebRequest.Get(emulatorURL);
((AsyncOperation)request.SendWebRequest()).completed += delegate
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Invalid comparison between Unknown and I4
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Invalid comparison between Unknown and I4
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Expected O, but got Unknown
GameHandler.ClearStatus<QueryingGameTimeStatus>();
if ((int)request.result != 1)
{
Debug.Log((object)("Got error: " + request.error));
if ((int)request.result != 2)
{
response?.Invoke(new LoginResponse
{
VersionOkay = false
});
}
}
else
{
string text = request.downloadHandler.text;
LoginResponse obj = JsonUtility.FromJson<LoginResponse>(text);
Debug.Log((object)("Got message: " + text));
response?.Invoke(obj);
}
};
return false;
}
private static string GetEmulatorURL()
{
try
{
if (File.Exists(emulatorFilePath))
{
string text = File.ReadAllText(emulatorFilePath).Trim();
if (!string.IsNullOrEmpty(text))
{
return text;
}
Debug.LogWarning((object)"CloudAPI_Emulator.txt is empty. Using default URL.");
}
else
{
Debug.LogWarning((object)"CloudAPI_Emulator.txt not found. Using default URL.");
}
}
catch (Exception ex)
{
Debug.LogError((object)("Error reading CloudAPI_Emulator.txt: " + ex.Message));
}
return defaultURL;
}
}
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)"CloudAPI_Emulator has loaded!");
new Harmony("kirigiri.peak.cloudapiemulator").PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Made with <3 By Kirigiri");
}
}