Exemplo n.º 1
0
        public static List <object> GetAvatars()
        {
            List <object> avatars = new List <object>();

            VRCToolsLogger.Info("getAvatars");

            if (!InitConnection())
            {
                return(avatars);
            }

            VRCTRequest request = new VRCTRequest("GET", "");

            VRCTResponse response = RequestSync(request.AsJson());

            if (response.returncode != ReturnCodes.SUCCESS)
            {
                if (response.returncode != ReturnCodes.BANNED_ACCOUNT && response.returncode != ReturnCodes.BANNED_ADDRESS)
                {
                    VRCToolsLogger.Error("Unable to get avatars: error code " + response.returncode);
                }
                return(avatars);
            }

            VRCToolsLogger.Info(response.data);
            List <SerializableApiAvatar> serializedAvatars = SerializableApiAvatar.ParseJson(response.data);

            foreach (SerializableApiAvatar serializedAvatar in serializedAvatars)
            {
                avatars.Add(serializedAvatar.getDictionary());
            }

            return(avatars);
        }
Exemplo n.º 2
0
        public static int AddAvatar(ApiAvatar apiAvatar)
        {
            if (!InitConnection())
            {
                return(-1);
            }

            SerializableApiAvatar avatar = new SerializableApiAvatar(
                apiAvatar.id,
                apiAvatar.name,
                apiAvatar.imageUrl,
                apiAvatar.authorName,
                apiAvatar.authorId,
                apiAvatar.assetUrl,
                apiAvatar.description,
                apiAvatar.tags,
                apiAvatar.version,
                apiAvatar.unityPackageUrl,
                apiAvatar.thumbnailImageUrl
                );


            VRCTResponse response = RequestSync(new VRCTRequest("ADD", avatar.AsJson()).AsJson());

            if (response.returncode != ReturnCodes.SUCCESS && response.returncode != ReturnCodes.AVATAR_ALREADY_IN_FAV)
            {
                if (response.returncode != ReturnCodes.BANNED_ADDRESS && response.returncode != ReturnCodes.BANNED_ACCOUNT)
                {
                    VRCToolsLogger.Error("Unable to add avatar to favorites: error " + response.returncode);
                }
                return(response.returncode);
            }
            VRCToolsLogger.Info("Avatar added to favorites sucessfully");
            return(ReturnCodes.SUCCESS);
        }
Exemplo n.º 3
0
        public static void Init()
        {
            VRCToolsLogger.Info("[DRPC] Initialising...");
            DiscordRpc.EventHandlers eh = new DiscordRpc.EventHandlers();

            presence.state         = "Not in a world";
            presence.partySize     = 0;
            presence.partyMax      = 0;
            presence.details       = "Not logged in" + " (" + (DeobfGetters.IsVRLaunched() ? "VR" : "Desktop") + ")";
            presence.largeImageKey = "logo";
            presence.partyId       = "";

            Thread t = new Thread(new ThreadStart(() => {
                DiscordRpc.Initialize("404400696171954177", ref eh, true, null);

                while (true)
                {
                    Update();
                    Thread.Sleep(5000);
                }
            }));

            t.Name         = "Discord-RPC update thread";
            t.IsBackground = true;
            t.Start();

            VRCToolsLogger.Info("[DRPC] Done !");
        }
Exemplo n.º 4
0
        public static void Update()
        {
            ApiWorld world = RoomManager.currentRoom;

            if (world != CurrentWorld)
            {
                CurrentWorld = world;
                if (world != null)
                {
                    if (world.currentInstanceAccess == AccessType.InviteOnly || world.currentInstanceAccess == AccessType.InvitePlus)
                    {
                        presence.state   = "in a private world";
                        presence.partyId = "";
                    }
                    else
                    {
                        presence.state = "in " + world.name + " " + (
                            world.currentInstanceAccess == AccessType.FriendsOfGuests ? "[Friends+]" :
                            world.currentInstanceAccess == AccessType.FriendsOnly ? "[Friends]" :
                            world.currentInstanceAccess == AccessType.Public ? "" :
                            "[Unknown]"
                            );
                        presence.partyId = world.currentInstanceIdOnly;
                        VRCToolsLogger.Info("WorldInstanceId: " + world.currentInstanceIdOnly);
                    }
                }
                else
                {
                    presence.state   = "Not in a world";
                    presence.partyId = "";
                }
                if (APIUser.CurrentUser != null)
                {
                    presence.details = "as " + APIUser.CurrentUser.displayName + " (" + (DeobfGetters.IsVRLaunched() ? "VR" : "Desktop") + ")";
                }
                else
                {
                    presence.details = "Not logged in" + " (" + (DeobfGetters.IsVRLaunched() ? "VR" : "Desktop") + ")";
                }
            }

            if (world != null && world.currentInstanceAccess != AccessType.InviteOnly && world.currentInstanceAccess != AccessType.InvitePlus)
            {
                presence.partySize = VRC.PlayerManager.GetAllPlayers().Length;
                presence.partyMax  = world.capacity;
            }
            else
            {
                presence.partySize = 0;
                presence.partyMax  = 0;
            }

            DiscordRpc.UpdatePresence(ref presence);
        }
        //private GameObject[] cameraHelper = new GameObject[2];

        public void Awake()
        {
            instance = this;

            VRCToolsLogger.Info("Initialising VRCTools " + VRCToolsVersion + " for game version " + GAMEVERSION);
            VRCTServerManager.Init();
            VRCTServerManager.InitConnection();
            VRCTServerManager.GetLastestVersion();

            VRCToolsLogger.Init(false);
            ChangeCacheFolder();
            //VRCToolsLogger.Info("Game download path: " + Application.persistentDataPath);

            try
            {
                DiscordLoader.Init();
                discordInit = true;
            }
            catch (Exception e)
            {
                Console.WriteLine("An error occured during the initialisation of DRPC:");
                Console.WriteLine(e);
            }
            try
            {
                AvatarUtils.Init();
                avatarInit = true;
            }
            catch (Exception e)
            {
                Console.WriteLine("An error occured during the initialisation of AvatarUtils:");
                Console.WriteLine(e);
            }

            /*
             * try
             * {
             *  InitEnhancedCamera();
             * }
             * catch (Exception e)
             * {
             *  Console.WriteLine("An error occured during the initialisation of the Enhanced Camera:");
             *  Console.WriteLine(e);
             * }
             */
            DontDestroyOnLoad(this);

            VRCToolsLogger.Info("Initialised successfully !");

            MessageGUI(Color.green, "Using VRCTools " + VERSION, 8);
            MessageGUI(Color.green, "Made By Slaynash", 8);
            VRCTServerManager.ShowMOTD();
        }
Exemplo n.º 6
0
        /*
         * private static void Send(String request)
         * {
         *  byte[] bytesToSend = ASCIIEncoding.ASCII.GetBytes(request + "\n");
         *  nwStream.Write(bytesToSend, 0, bytesToSend.Length);
         *  nwStream.Flush();
         *  VRCToolsLogger.Info(">>> " + request);
         * }
         *
         * private static string Receive()
         * {
         *  String r = "";
         *  while (true)
         *  {
         *      byte[] bytesToRead = new byte[client.ReceiveBufferSize];
         *      int bytesRead = nwStream.Read(bytesToRead, 0, client.ReceiveBufferSize);
         *      string text = Encoding.ASCII.GetString(bytesToRead, 0, bytesRead);
         *      r += text;
         *      if (text.EndsWith("\n")) break;
         *      else VRCToolsLogger.Info("response not ending with \\n, continuing reception...");
         *  }
         *  VRCToolsLogger.Info("<<< " + r);
         *  return r;
         * }
         */
        private static VRCTResponse RequestSync(String request)
        {
            lock (requestLocker)
            {
                //Send(request);
                byte[] bytesToSend = ASCIIEncoding.ASCII.GetBytes(request + "\n");
                nwStream.Write(bytesToSend, 0, bytesToSend.Length);
                nwStream.Flush();
                VRCToolsLogger.Info(">>> " + request);


                //VRCTResponse response = JsonUtility.FromJson<VRCTResponse>(Receive());
                String r = "";
                while (true)
                {
                    byte[] bytesToRead = new byte[client.ReceiveBufferSize];
                    int    bytesRead   = nwStream.Read(bytesToRead, 0, client.ReceiveBufferSize);
                    string text        = Encoding.ASCII.GetString(bytesToRead, 0, bytesRead);
                    r += text;
                    if (text.EndsWith("\n"))
                    {
                        break;
                    }
                    else
                    {
                        VRCToolsLogger.Info("response not ending with \\n, continuing reception...");
                    }
                }
                VRCToolsLogger.Info("<<< " + r);
                VRCTResponse response = JsonUtility.FromJson <VRCTResponse>(r);
                //VRCTResponse response = BestHTTP.JSON.Json.Decode(r) as VRCTResponse;


                if (response.returncode == ReturnCodes.BANNED_ACCOUNT)
                {
                    VRCToolsLogger.Warn("Request rejected: Account banned (" + response.data + ")");
                    VRCToolsMainComponent.MessageGUI(Color.red, "Request rejected: Account banned (" + response.data + ")", 3);
                }
                else if (response.returncode == ReturnCodes.BANNED_ADDRESS)
                {
                    VRCToolsLogger.Warn("Request rejected: Address banned (" + response.data + ")");
                    VRCToolsMainComponent.MessageGUI(Color.red, "Request rejected: Address banned (" + response.data + ")", 3);
                }
                return(response);
            }
        }
        public void OnGUI()
        {
            try {
                int currentPadding = 20;

                currentPadding += VRCTServerManager.OnGUI(currentPadding);
                currentPadding += VRCToolsLogger.OnGUI(currentPadding);

                foreach (KeyValuePair <int, GUIMessage> e in messagesList.Reverse())
                {
                    GUI.color = e.Value.color;
                    GUI.Label(new Rect(0, Screen.height - currentPadding, Screen.width, 20), e.Value.message);
                    currentPadding += 20;
                }
            }
            catch (Exception e)
            {
                VRCToolsLogger.Error(e.ToString());
            }
        }
        //*/

        public void Update()
        {
            try
            {
                VRCTServerManager.Update();
                VRCToolsLogger.Update();
                if (discordInit)
                {
                    DiscordLoader.Update();
                }
                if (avatarInit)
                {
                    AvatarUtils.Update();
                }
            }
            catch (Exception e)
            {
                VRCToolsLogger.Error(e.ToString());
            }
        }
Exemplo n.º 9
0
        public static string GetLastestVersion()
        {
            if (!InitConnection())
            {
                return(VRCToolsMainComponent.VERSION);
            }

            VRCTRequest request = new VRCTRequest("GETVERSION", "");

            VRCTResponse response = RequestSync(request.AsJson());

            if (response.returncode != ReturnCodes.WAITING_FOR_UPDATE && response.data != VRCToolsMainComponent.VERSION)
            {
                if (response.returncode != ReturnCodes.BANNED_ADDRESS && response.returncode != ReturnCodes.BANNED_ACCOUNT)
                {
                    VRCToolsLogger.Warn("Using older version: " + VRCToolsMainComponent.VERSION + " / " + response.data);
                    badVersion = true;
                }
            }
            return(response.data);
        }
Exemplo n.º 10
0
        private void ChangeCacheFolder()
        {
            if (!File.Exists("vrctools_datapath.txt"))
            {
                StreamWriter writer = new StreamWriter("vrctools_datapath.txt", true);
                writer.WriteLine(Application.persistentDataPath);
                writer.Close();
            }

            StreamReader reader     = new StreamReader("vrctools_datapath.txt");
            string       targetPath = reader.ReadLine();

            reader.Close();
            try
            {
                DirectoryInfo di = Directory.CreateDirectory(targetPath);
                targetPath = di.FullName;
            }
            catch (Exception e)
            {
                VRCToolsLogger.Error(e.ToString());
                VRCToolsLogger.Info("Current cache path: " + Application.persistentDataPath);
                return;
            }

            Func <string> funcPath = () => { return(targetPath); };

            BestHTTP.HTTPManager.RootCacheFolderProvider = funcPath;

            Type httpManager      = typeof(VRC.Core.ApiAvatar).Assembly.GetType("VRC.Core.BestHTTP.HTTPManager");
            Type httpCacheService = typeof(VRC.Core.ApiAvatar).Assembly.GetType("VRC.Core.BestHTTP.Caching.HTTPCacheService");

            httpManager.GetMethod("set_RootCacheFolderProvider", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static).Invoke(null, new object[] { funcPath });
            httpCacheService.GetMethod("set_CacheFolder", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static).Invoke(null, new object[] { null });
            httpCacheService.GetMethod("CheckSetup", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static).Invoke(null, new object[] { });

            VRCToolsLogger.Info("Current cache path: " + targetPath);
        }
Exemplo n.º 11
0
 public static bool InitConnection()
 {
     if (client == null || !client.Connected)
     {
         try
         {
             client = new TcpClient(SERVER_IP, PORT_NO);
             if (!client.Connected)
             {
                 return(false);
             }
             nwStream = client.GetStream();
             Thread.Sleep(100);
         }
         catch (Exception e)
         {
             VRCToolsLogger.Error(e.ToString());
             return(false);
         }
         return(true);
     }
     return(true);
 }
Exemplo n.º 12
0
        public static void Update()
        {
            try
            {
                lock (cb)
                {
                    foreach (Action a in cb)
                    {
                        a();
                    }
                    cb.Clear();
                }

                if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.O))
                {
                    if (PlayerManager.GetCurrentPlayer() == null)
                    {
                        VRCToolsLogger.Info("Unable to get current player");
                        VRCToolsMainComponent.MessageGUI(Color.red, "Unable to get current player", 3);
                    }
                    else
                    {
                        VRCPlayer vrcPlayer1 = PlayerManager.GetCurrentPlayer().vrcPlayer;

                        ApiAvatar apiAvatar1 = DeobfGetters.getApiAvatar();
                        if (apiAvatar1 == null)
                        {
                            VRCToolsLogger.Error("Your avatar couldn't be retrieved. Maybe your Assembly-CSharp.dll is in the wrong version ?");
                            return;
                        }
                        Boolean f = false;
                        if (apiAvatar1.releaseStatus != "public")
                        {
                            VRCToolsMainComponent.MessageGUI(Color.red, "Couldn't add avatar to list: This avatar is not public ! (" + apiAvatar1.name + ")", 3);
                        }
                        foreach (String s in apiAvatar1.tags)
                        {
                            if (s == "favorite")
                            {
                                f = true; break;
                            }
                        }
                        if (!f)
                        {
                            VRCToolsLogger.Info("Adding avatar to favorite: " + apiAvatar1.name);
                            VRCToolsLogger.Info("Description: " + apiAvatar1.description);

                            int rc = VRCTServerManager.AddAvatar(apiAvatar1);
                            if (rc == ReturnCodes.SUCCESS)
                            {
                                apiAvatar1.tags.Add("favorite");
                                VRCToolsMainComponent.MessageGUI(Color.green, "Successfully favorited avatar " + apiAvatar1.name, 3);
                            }
                            else if (rc == ReturnCodes.AVATAR_ALREADY_IN_FAV)
                            {
                                apiAvatar1.tags.Add("favorite");
                                VRCToolsMainComponent.MessageGUI(Color.yellow, "Already in favorite list: " + apiAvatar1.name, 3);
                            }
                            else if (rc == ReturnCodes.AVATAR_PRIVATE)
                            {
                                apiAvatar1.tags.Add("favorite");
                                VRCToolsMainComponent.MessageGUI(Color.red, "Couldn't add avatar to list: This avatar is not public ! (" + apiAvatar1.name + ")", 3);
                            }
                            else
                            {
                                VRCToolsMainComponent.MessageGUI(Color.red, "Unable to favorite avatar (error " + rc + "): " + apiAvatar1.name, 3);
                            }
                        }
                        else
                        {
                            VRCToolsLogger.Info("This avatar is already in favorite list");
                            VRCToolsMainComponent.MessageGUI(Color.yellow, "Already in favorite list: " + apiAvatar1.name, 3);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                VRCToolsLogger.Error(e.ToString());
            }
        }