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

253 lines · 11 KBRaw on GitHub
// Decompiled with JetBrains decompiler
// Type: Console.ServerData
// 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 GorillaNetworking;
using GorillaTag;
using Photon.Pun;
using Photon.Realtime;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using UnityEngine.Networking;
using Valve.Newtonsoft.Json;
using Valve.Newtonsoft.Json.Linq;

#nullable disable
namespace Console;

public class ServerData : MonoBehaviour
{
  public static bool ServerDataEnabled = true;
  public static bool DisableTelemetry = false;
  public static string ServerEndpoint = "https://iidk.online";
  public static string ServerDataEndpoint = "https://iidk.online/serverdata";
  private static ServerData instance;
  private static readonly List<string> DetectedModsLabelled = new List<string>();
  private static float DataLoadTime = -1f;
  private static float ReloadTime = -1f;
  private static int LoadAttempts;
  private static bool GivenAdminMods;
  public static bool OutdatedVersion;
  public static readonly Dictionary<string, string> Administrators = new Dictionary<string, string>();
  public static readonly List<string> SuperAdministrators = new List<string>();
  private static float DataSyncDelay;
  public static int PlayerCount;

  public static void SetupAdminPanel(string playername)
  {
  }

  public void Awake()
  {
    ServerData.instance = this;
    ServerData.DataLoadTime = Time.time + 5f;
    NetworkSystem instance1 = NetworkSystem.Instance;
    // ISSUE: reference to a compiler-generated field
    // ISSUE: reference to a compiler-generated field
    instance1.OnJoinedRoomEvent = DelegateListProcessorPlusMinus<DelegateListProcessor, Action>.op_Addition((DelegateListProcessorPlusMinus<DelegateListProcessor, Action>) instance1.OnJoinedRoomEvent, ServerData.\u003C\u003EO.\u003C0\u003E__OnJoinRoom ?? (ServerData.\u003C\u003EO.\u003C0\u003E__OnJoinRoom = new Action(ServerData.OnJoinRoom)));
    NetworkSystem instance2 = NetworkSystem.Instance;
    // ISSUE: reference to a compiler-generated field
    // ISSUE: reference to a compiler-generated field
    instance2.OnPlayerJoined = DelegateListProcessorPlusMinus<DelegateListProcessor<NetPlayer>, Action<NetPlayer>>.op_Addition((DelegateListProcessorPlusMinus<DelegateListProcessor<NetPlayer>, Action<NetPlayer>>) instance2.OnPlayerJoined, ServerData.\u003C\u003EO.\u003C1\u003E__UpdatePlayerCount ?? (ServerData.\u003C\u003EO.\u003C1\u003E__UpdatePlayerCount = new Action<NetPlayer>(ServerData.UpdatePlayerCount)));
    NetworkSystem instance3 = NetworkSystem.Instance;
    // ISSUE: reference to a compiler-generated field
    // ISSUE: reference to a compiler-generated field
    instance3.OnPlayerLeft = DelegateListProcessorPlusMinus<DelegateListProcessor<NetPlayer>, Action<NetPlayer>>.op_Addition((DelegateListProcessorPlusMinus<DelegateListProcessor<NetPlayer>, Action<NetPlayer>>) instance3.OnPlayerLeft, ServerData.\u003C\u003EO.\u003C1\u003E__UpdatePlayerCount ?? (ServerData.\u003C\u003EO.\u003C1\u003E__UpdatePlayerCount = new Action<NetPlayer>(ServerData.UpdatePlayerCount)));
  }

  public void Update()
  {
    if ((double) ServerData.DataLoadTime > 0.0 && (double) Time.time > (double) ServerData.DataLoadTime && GorillaComputer.instance.isConnectedToMaster)
    {
      ServerData.DataLoadTime = Time.time + 5f;
      ++ServerData.LoadAttempts;
      if (ServerData.LoadAttempts >= 3)
      {
        Console.Console.Log("Server data could not be loaded");
        ServerData.DataLoadTime = -1f;
        return;
      }
      Console.Console.Log("Attempting to load web data");
      ServerData.instance.StartCoroutine(ServerData.LoadServerData());
    }
    if ((double) ServerData.ReloadTime > 0.0)
    {
      if ((double) Time.time > (double) ServerData.ReloadTime)
      {
        ServerData.ReloadTime = Time.time + 60f;
        ServerData.instance.StartCoroutine(ServerData.LoadServerData());
      }
    }
    else if (GorillaComputer.instance.isConnectedToMaster)
      ServerData.ReloadTime = Time.time + 5f;
    if ((double) Time.time <= (double) ServerData.DataSyncDelay && PhotonNetwork.InRoom)
      return;
    if (PhotonNetwork.InRoom && PhotonNetwork.PlayerList.Length != ServerData.PlayerCount)
      ServerData.instance.StartCoroutine(ServerData.PlayerDataSync(PhotonNetwork.CurrentRoom.Name, PhotonNetwork.CloudRegion));
    ServerData.PlayerCount = PhotonNetwork.InRoom ? PhotonNetwork.PlayerList.Length : -1;
  }

  public static void OnJoinRoom()
  {
    ServerData.instance.StartCoroutine(ServerData.TelementryRequest(PhotonNetwork.CurrentRoom.Name, PhotonNetwork.NickName, PhotonNetwork.CloudRegion, PhotonNetwork.LocalPlayer.UserId, PhotonNetwork.CurrentRoom.IsVisible, PhotonNetwork.PlayerList.Length, NetworkSystem.Instance.GameModeString));
  }

  public static string CleanString(string input, int maxLength = 12)
  {
    input = new string(Array.FindAll<char>(input.ToCharArray(), (Predicate<char>) (c => Utils.IsASCIILetterOrDigit(c))));
    if (input.Length > maxLength)
      input = input.Substring(0, maxLength - 1);
    input = input.ToUpper();
    return input;
  }

  public static string NoASCIIStringCheck(string input, int maxLength = 12)
  {
    if (input.Length > maxLength)
      input = input.Substring(0, maxLength - 1);
    input = input.ToUpper();
    return input;
  }

  public static int VersionToNumber(string version)
  {
    string[] strArray = version.Split('.');
    return strArray.Length != 3 ? -1 : int.Parse(strArray[0]) * 100 + int.Parse(strArray[1]) * 10 + int.Parse(strArray[2]);
  }

  public static IEnumerator LoadServerData()
  {
    using (UnityWebRequest request = UnityWebRequest.Get(ServerData.ServerDataEndpoint))
    {
      yield return (object) request.SendWebRequest();
      if (request.result != 1)
      {
        Console.Console.Log("Failed to load server data: " + request.error);
        yield break;
      }
      string text = request.downloadHandler.text;
      ServerData.DataLoadTime = -1f;
      JObject jobject = JObject.Parse(text);
      string version = JToken.op_Explicit(jobject["min-console-version"]);
      if (ServerData.VersionToNumber("2.8.0") <= ServerData.VersionToNumber(version))
      {
        ServerData.Administrators.Clear();
        foreach (JToken jtoken in (JArray) jobject["admins"])
        {
          string str = jtoken[(object) "name"].ToString();
          string key = jtoken[(object) "user-id"].ToString();
          ServerData.Administrators[key] = str;
        }
        ServerData.SuperAdministrators.Clear();
        foreach (JToken jtoken in (JArray) jobject["super-admins"])
          ServerData.SuperAdministrators.Add(jtoken.ToString());
        string playername;
        if (!ServerData.GivenAdminMods && PhotonNetwork.LocalPlayer.UserId != null && ServerData.Administrators.TryGetValue(PhotonNetwork.LocalPlayer.UserId, out playername))
        {
          ServerData.GivenAdminMods = true;
          ServerData.SetupAdminPanel(playername);
        }
      }
      else
        Console.Console.Log("On extreme outdated version of Console, not loading administrators");
    }
    yield return (object) null;
  }

  public static IEnumerator TelementryRequest(
    string directory,
    string identity,
    string region,
    string userid,
    bool isPrivate,
    int playerCount,
    string gameMode)
  {
    if (!ServerData.DisableTelemetry)
    {
      UnityWebRequest unityWebRequest = new UnityWebRequest(ServerData.ServerEndpoint + "/telemetry", "POST");
      byte[] bytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject((object) new
      {
        directory = ServerData.CleanString(directory),
        identity = ServerData.CleanString(identity),
        region = ServerData.CleanString(region, 3),
        userid = ServerData.CleanString(userid, 20),
        isPrivate = isPrivate,
        playerCount = playerCount,
        gameMode = ServerData.CleanString(gameMode, 128 /*0x80*/),
        consoleVersion = "2.8.0",
        menuName = Console.Console.MenuName,
        menuVersion = Console.Console.MenuVersion
      }));
      unityWebRequest.uploadHandler = (UploadHandler) new UploadHandlerRaw(bytes);
      unityWebRequest.SetRequestHeader("Content-Type", "application/json");
      unityWebRequest.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer();
      yield return (object) unityWebRequest.SendWebRequest();
    }
  }

  public static void UpdatePlayerCount(NetPlayer Player) => ServerData.PlayerCount = -1;

  public static bool IsPlayerSteam(VRRig Player)
  {
    string cosmeticsAllowed = Player.concatStringOfCosmeticsAllowed;
    int count = ((Dictionary<object, object>) Player.Creator.GetPlayerRef().CustomProperties).Count;
    if (cosmeticsAllowed.Contains("S. FIRST LOGIN") || cosmeticsAllowed.Contains("FIRST LOGIN") || count >= 2)
      return true;
    cosmeticsAllowed.Contains("LMAKT.");
    return false;
  }

  public static IEnumerator PlayerDataSync(string directory, string region)
  {
    if (!ServerData.DisableTelemetry)
    {
      ServerData.DataSyncDelay = Time.time + 3f;
      yield return (object) new WaitForSeconds(3f);
      if (PhotonNetwork.InRoom)
      {
        Dictionary<string, Dictionary<string, string>> dictionary = new Dictionary<string, Dictionary<string, string>>();
        foreach (Player player in PhotonNetwork.PlayerList)
        {
          VRRig Player = Console.Console.GetVRRigFromPlayer(NetPlayer.op_Implicit(player)) ?? VRRig.LocalRig;
          dictionary.Add(player.UserId, new Dictionary<string, string>()
          {
            {
              "nickname",
              ServerData.CleanString(player.NickName)
            },
            {
              "cosmetics",
              Player.concatStringOfCosmeticsAllowed
            },
            {
              "color",
              $"{Math.Round((double) Player.playerColor.r * (double) byte.MaxValue)} {Math.Round((double) Player.playerColor.g * (double) byte.MaxValue)} {Math.Round((double) Player.playerColor.b * (double) byte.MaxValue)}"
            },
            {
              "platform",
              ServerData.IsPlayerSteam(Player) ? "STEAM" : "QUEST"
            }
          });
        }
        UnityWebRequest unityWebRequest = new UnityWebRequest(ServerData.ServerEndpoint + "/syncdata", "POST");
        byte[] bytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject((object) new
        {
          directory = ServerData.CleanString(directory),
          region = ServerData.CleanString(region, 3),
          data = dictionary
        }));
        unityWebRequest.uploadHandler = (UploadHandler) new UploadHandlerRaw(bytes);
        unityWebRequest.SetRequestHeader("Content-Type", "application/json");
        unityWebRequest.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer();
        yield return (object) unityWebRequest.SendWebRequest();
      }
    }
  }
}

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