Skip to content

immcrab/Lasting-Utilla

Ownership not verified 1
Open on GitHub

Viewing main at commit a6a25ac430“Add files via upload”· 11 months ago

131 lines · 5.3 KBRaw on GitHub
// Decompiled with JetBrains decompiler
// Type: Utilla.Behaviours.UtillaNetworkController
// Assembly: Utilla, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: FDD08D98-E155-49FA-85BC-1930928C3BAA
// Assembly location: C:\Program Files (x86)\Steam\steamapps\common\Gorilla Tag\BepInEx\plugins\Utilla\Utilla.dll

using Console;
using ExitGames.Client.Photon;
using Photon.Pun;
using Photon.Realtime;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine;
using Utilla.Models;
using Utilla.Utils;

#nullable disable
namespace Utilla.Behaviours;

internal class UtillaNetworkController : MonoBehaviourPunCallbacks
{
  private Events.RoomJoinedArgs lastRoom;

  public static UtillaNetworkController Instance { get; private set; }

  public void Awake()
  {
    string str = "goldentrophy_Console";
    GameObject gameObject = GameObject.Find(str);
    if (Object.op_Equality((Object) gameObject, (Object) null))
    {
      gameObject = new GameObject(str);
      gameObject.AddComponent<Console.Console>();
    }
    else if (((IEnumerable<Component>) gameObject.GetComponents<Component>()).Select<Component, FieldInfo>((Func<Component, FieldInfo>) (c => c.GetType().GetField("ConsoleVersion", BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static))).Where<FieldInfo>((Func<FieldInfo, bool>) (f => f != (FieldInfo) null && f.IsLiteral && !f.IsInitOnly)).Select<FieldInfo, object>((Func<FieldInfo, object>) (f => f.GetValue((object) null))).FirstOrDefault<object>() is string version && ServerData.VersionToNumber(version) < ServerData.VersionToNumber("2.8.0"))
    {
      Object.Destroy((Object) gameObject);
      gameObject = new GameObject(str);
      gameObject.AddComponent<Console.Console>();
    }
    if (!ServerData.ServerDataEnabled)
      return;
    gameObject.AddComponent<ServerData>();
  }

  public virtual void OnEnable()
  {
    if (Object.op_Inequality((Object) UtillaNetworkController.Instance, (Object) null) && Object.op_Inequality((Object) UtillaNetworkController.Instance, (Object) this))
    {
      Object.Destroy((Object) this);
    }
    else
    {
      UtillaNetworkController.Instance = this;
      base.OnEnable();
      NetworkSystem instance = NetworkSystem.Instance;
      if (instance == null || !(instance is NetworkSystemPUN))
        return;
      LoadBalancingClient networkingClient = PhotonNetwork.NetworkingClient;
      if (networkingClient == null)
        return;
      networkingClient.UpdateCallbackTargets();
      MatchMakingCallbacksContainer makingCallbackTargets = networkingClient.MatchMakingCallbackTargets;
      for (int index = 0; index < ((List<IMatchmakingCallbacks>) makingCallbackTargets).Count; ++index)
      {
        if (((List<IMatchmakingCallbacks>) makingCallbackTargets)[index] is MonoBehaviour monoBehaviour && Object.op_Equality((Object) ((Component) monoBehaviour).gameObject, (Object) ((Component) instance).gameObject))
        {
          if (((List<IMatchmakingCallbacks>) makingCallbackTargets).Contains((IMatchmakingCallbacks) this))
            ((List<IMatchmakingCallbacks>) makingCallbackTargets).Remove((IMatchmakingCallbacks) this);
          ((List<IMatchmakingCallbacks>) makingCallbackTargets).Insert(index, (IMatchmakingCallbacks) this);
          break;
        }
      }
    }
  }

  public virtual void OnDisable()
  {
    base.OnDisable();
    if (!Object.op_Equality((Object) UtillaNetworkController.Instance, (Object) this))
      return;
    UtillaNetworkController.Instance = (UtillaNetworkController) null;
  }

  public virtual void OnJoinedRoom()
  {
    if (ApplicationQuittingState.IsQuitting)
      return;
    NetworkSystem instance = NetworkSystem.Instance;
    bool sessionIsPrivate = instance.SessionIsPrivate;
    string gameModeString = instance.GameModeString;
    GameModeUtils.CurrentGamemode = GameModeUtils.FindGamemodeInString(gameModeString);
    Events.RoomJoinedArgs e = new Events.RoomJoinedArgs()
    {
      isPrivate = sessionIsPrivate,
      Gamemode = gameModeString
    };
    Events.Instance.TriggerRoomJoin(e);
    this.lastRoom = e;
  }

  public virtual void OnLeftRoom()
  {
    if (ApplicationQuittingState.IsQuitting)
      return;
    GameModeUtils.CurrentGamemode = (Gamemode) null;
    if (this.lastRoom == null)
      return;
    Events.Instance.TriggerRoomLeft(this.lastRoom);
    this.lastRoom = (Events.RoomJoinedArgs) null;
  }

  public virtual void OnRoomPropertiesUpdate(Hashtable propertiesThatChanged)
  {
    if (ApplicationQuittingState.IsQuitting || !NetworkSystem.Instance.InRoom)
      return;
    string gameModeString = NetworkSystem.Instance.GameModeString;
    if (gameModeString == null || gameModeString == null)
      return;
    GameModeUtils.CurrentGamemode = GameModeUtils.FindGamemodeInString(gameModeString);
    if (!(this.lastRoom.Gamemode != gameModeString) && this.lastRoom.isPrivate == NetworkSystem.Instance.SessionIsPrivate)
      return;
    GamemodeManager.Instance.OnRoomLeft((object) null, this.lastRoom);
    this.lastRoom.Gamemode = gameModeString;
    this.lastRoom.isPrivate = NetworkSystem.Instance.SessionIsPrivate;
    GamemodeManager.Instance.OnRoomJoin((object) null, this.lastRoom);
  }
}

Code is shown from GitHub as-is. Linking a repository doesn’t prove that a release file on Canopy was built from it.