using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Photon.Pun;
using Photon.Realtime;
using Steamworks;
using UnityEngine;
using Zorro.Core;
using Zorro.UI.Modal;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("PeakCrossVersion")]
[assembly: AssemblyDescription("Join your friend without having the same game version.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Kirigiri")]
[assembly: AssemblyProduct("PeakCrossVersion")]
[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 PeakCrossVersion;
[BepInPlugin("kirigiri.peak.crossversion", "PeakCrossVersion", "1.0.0.0")]
public class PeakCrossVersion : BaseUnityPlugin
{
[HarmonyPatch(typeof(SteamLobbyHandler), "OnLobbyCreated")]
public class SteamLobbyHandler_OnLobbyCreated_Patch
{
private static readonly FieldRef<SteamLobbyHandler, bool> isHostingRef = AccessTools.FieldRefAccess<SteamLobbyHandler, bool>("m_isHosting");
private static readonly FieldRef<SteamLobbyHandler, CSteamID> currentLobbyRef = AccessTools.FieldRefAccess<SteamLobbyHandler, CSteamID>("m_currentLobby");
[HarmonyPrefix]
public static bool Prefix(ref LobbyCreated_t param, SteamLobbyHandler __instance)
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Invalid comparison between Unknown and I4
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Expected O, but got Unknown
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Expected O, but got Unknown
//IL_006a: Expected O, but got Unknown
Debug.Log((object)"[PeakCrossVersion] Intercepted OnLobbyCreated");
isHostingRef.Invoke(__instance) = true;
if ((int)param.m_eResult != 1)
{
Modal.OpenModal((HeaderModalOption)new DefaultHeaderModalOption(LocalizedText.GetText("MODAL_CANTCREATELOBBY_TITLE", true), $"{param.m_eResult}"), (ModalContentOption)new ModalButtonsOption((Option[])(object)new Option[1]
{
new Option(LocalizedText.GetText("OK", true), (Action)null)
}), (Action)null);
return false;
}
Debug.Log((object)$"Lobby Created: {param.m_ulSteamIDLobby}");
currentLobbyRef.Invoke(__instance) = new CSteamID(param.m_ulSteamIDLobby);
BuildVersion val = new BuildVersion("kirigiri.1.0.a");
string text = ((BuildVersion)(ref val)).ToMatchmaking();
if (!SteamMatchmaking.SetLobbyData(currentLobbyRef.Invoke(__instance), "PeakVersion", text))
{
Debug.LogError((object)"[PeakCrossVersion] Failed to assign game version to lobby");
}
HostState val2 = ((StateMachine<ConnectionState>)(object)GameHandler.GetService<ConnectionService>().StateMachine).SwitchState<HostState>(false);
PropertyInfo property = ((object)val2).GetType().GetProperty("RoomName");
if (property != null && property.CanWrite)
{
property.SetValue(val2, Guid.NewGuid().ToString());
}
LoadingScreenHandler instance = RetrievableResourceSingleton<LoadingScreenHandler>.Instance;
MethodInfo methodInfo = AccessTools.Method(typeof(LoadingScreenHandler), "LoadSceneProcess", (Type[])null, (Type[])null);
if (methodInfo == null)
{
Debug.LogError((object)"[PeakCrossVersion] Failed to find LoadSceneProcess method.");
return false;
}
IEnumerator enumerator = (IEnumerator)methodInfo.Invoke(instance, new object[4] { "Airport", false, true, 3f });
instance.Load((LoadingScreenType)0, (Action)null, new IEnumerator[1] { enumerator });
return false;
}
}
[HarmonyPatch(typeof(SteamLobbyHandler), "OnLobbyDataUpdate")]
public class SteamLobbyHandler_OnLobbyDataUpdate_Patch
{
private static readonly FieldRef<SteamLobbyHandler, Optionable<CSteamID>> fetchingVersionRef = AccessTools.FieldRefAccess<SteamLobbyHandler, Optionable<CSteamID>>("m_currentlyFetchingGameVersion");
[HarmonyPrefix]
public static bool Prefix(ref LobbyDataUpdate_t param, SteamLobbyHandler __instance)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_016b: Unknown result type (might be due to invalid IL or missing references)
//IL_0184: Unknown result type (might be due to invalid IL or missing references)
//IL_018a: Expected O, but got Unknown
//IL_018a: Unknown result type (might be due to invalid IL or missing references)
//IL_0195: Expected O, but got Unknown
//IL_0195: Expected O, but got Unknown
//IL_01a0: 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_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_011f: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: Expected O, but got Unknown
//IL_013e: Unknown result type (might be due to invalid IL or missing references)
//IL_0149: Expected O, but got Unknown
//IL_0149: Expected O, but got Unknown
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
Debug.Log((object)"[PeakCrossVersion] Intercepted OnLobbyDataUpdate.");
Optionable<CSteamID> val = fetchingVersionRef.Invoke(__instance);
if (param.m_bSuccess == 1)
{
if (val.IsSome && val.Value.m_SteamID == param.m_ulSteamIDLobby)
{
string lobbyData = SteamMatchmaking.GetLobbyData(val.Value, "PeakVersion");
BuildVersion val2 = new BuildVersion("kirigiri.1.0.a");
string text = ((BuildVersion)(ref val2)).ToMatchmaking();
if (lobbyData == text)
{
if (PhotonNetwork.InRoom)
{
Debug.LogError((object)"[PeakCrossVersion] Already in a room. Not joining invite.");
return false;
}
MethodInfo methodInfo = AccessTools.Method(typeof(SteamLobbyHandler), "JoinLobby", (Type[])null, (Type[])null);
if (methodInfo != null)
{
methodInfo.Invoke(__instance, new object[1] { val.Value });
}
else
{
Debug.LogError((object)"[PeakCrossVersion] Failed to find JoinLobby method via reflection.");
}
}
else
{
Debug.LogError((object)("[PeakCrossVersion] Game version mismatch: " + lobbyData));
string text2 = LocalizedText.GetText("MODAL_MISMATCH_BODY", true).Replace("#", lobbyData).Replace("&", text);
Modal.OpenModal((HeaderModalOption)new DefaultHeaderModalOption(LocalizedText.GetText("MODAL_MISMATCH_TITLE", true), text2), (ModalContentOption)new ModalButtonsOption((Option[])(object)new Option[1]
{
new Option(LocalizedText.GetText("OK", true), (Action)null)
}), (Action)null);
}
}
}
else
{
Debug.LogError((object)"[PeakCrossVersion] Failed to fetch lobby data.");
Modal.OpenModal((HeaderModalOption)new DefaultHeaderModalOption(LocalizedText.GetText("MODAL_CANTFINDLOBBY_TITLE", true), LocalizedText.GetText("MODAL_CANTFINDLOBBY_BODY", true)), (ModalContentOption)new ModalButtonsOption((Option[])(object)new Option[1]
{
new Option(LocalizedText.GetText("OK", true), (Action)null)
}), (Action)null);
}
fetchingVersionRef.Invoke(__instance) = Optionable<CSteamID>.None;
return false;
}
}
[HarmonyPatch(typeof(NetworkConnector), "ConnectToPhoton")]
public class NetworkConnectorPatch
{
[HarmonyPrefix]
public static bool Prefix()
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
Debug.Log((object)"[PeakCrossVersion] Intercepted ConnectToPhoton.");
BuildVersion version = new BuildVersion("kirigiri.1.0.a");
PhotonNetwork.AutomaticallySyncScene = true;
PhotonNetwork.GameVersion = ((object)(BuildVersion)(ref version)).ToString();
PhotonNetwork.PhotonServerSettings.AppSettings.AppVersion = ((BuildVersion)(ref version)).ToMatchmaking();
MethodInfo method = typeof(NetworkConnector).GetMethod("PrepareSteamAuthTicket", BindingFlags.Static | BindingFlags.NonPublic);
if (method == null)
{
Debug.LogError((object)"Failed to find PrepareSteamAuthTicket via reflection.");
return false;
}
method.Invoke(null, new object[1] { (Action)delegate
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
PhotonNetwork.ConnectUsingSettings();
ClientState networkClientState = PhotonNetwork.NetworkClientState;
Debug.Log((object)("Photon Start " + ((object)(ClientState)(ref networkClientState)).ToString() + " using app version: " + ((BuildVersion)(ref version)).ToMatchmaking()));
} });
return false;
}
}
private void Awake()
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
((BaseUnityPlugin)this).Logger.LogInfo((object)"PeakCrossVersion has loaded!");
new Harmony("kirigiri.peak.crossversion").PatchAll();
}
}