private static void SetupBP()
        {
            bpClient = new ButtplugClient("VRCVibratorController");
            bpClient.ConnectAsync(new ButtplugEmbeddedConnectorOptions());
            bpClient.DeviceAdded += async(object aObj, DeviceAddedEventArgs args) => {
                await AsyncUtils.YieldToMainThread();

                new Toy(args.Device, TabButton.SubMenu);
            };

            bpClient.DeviceRemoved += async(object aObj, DeviceRemovedEventArgs args) => {
                await AsyncUtils.YieldToMainThread();

                if (Toy.myToys.ContainsKey(args.Device.Index))
                {
                    Toy.myToys[args.Device.Index].disable();
                }
            };

            bpClient.ErrorReceived += async(object aObj, ButtplugExceptionEventArgs args) =>
            {
                MelonLogger.Msg($"B******g Client recieved error: {args.Exception.Message}");
                await AsyncUtils.YieldToMainThread();

                buttplugError.SubtitleText = "Error occured";
            };
        }
예제 #2
0
        public static async void OnUserInfoOpen()
        {
            await AsyncUtils.YieldToMainThread();

            foreach (ModuleBase module in modules)
            {
                module.OnUserInfoOpen();
            }
        }
예제 #3
0
        public override async void OnPreferencesSaved()
        {
            await AsyncUtils.YieldToMainThread();

            foreach (ModuleBase module in modules)
            {
                module.OnPreferencesSaved();
            }
        }
예제 #4
0
        public static async void FromSocial()
        {
            UserInfoExtensionsMod.HideAllPopups();

            if (!canGet)
            {
                VRCUtils.OpenPopupV2("Slow down!", "Please wait a little in between button presses", "Close", new Action(VRCUtils.ClosePopup));
                return;
            }

            if (avatarLink == null)
            {
                VRCUtils.OpenPopupV2("Error!", "Something went wrong and the avatar author could not be retreived. Please try again", "Close", new Action(VRCUtils.ClosePopup));
                return;
            }

            MelonCoroutines.Start(StartTimer());

            HttpWebRequest request = WebRequest.CreateHttp(avatarLink.OriginalString);

            try
            {
                request.UserAgent = "Mozilla/5.0";
                WebResponse response = await request.GetResponseAsync();

                isFromSocialPage = true;

                StreamReader streamReader  = new StreamReader(response.GetResponseStream());
                JObject      jsonData      = JObject.Parse(streamReader.ReadToEnd());
                JsonData     requestedData = jsonData.ToObject <JsonData>();

                await AsyncUtils.YieldToMainThread();

                OpenUserInSocialMenu(requestedData.ownerId);

                response.Close();
                streamReader.Close();
            }
            catch (WebException)
            {
                await AsyncUtils.YieldToMainThread();

                VRCUtils.OpenPopupV2("Error!", "Something went wrong and the avatar author could not be retreived. Please try again", "Close", new Action(VRCUtils.ClosePopup));
                return;
            }
        }
예제 #5
0
        public static async void FromSocial()
        {
            UserInfoExtensionsMod.HideAllPopups();

            if (avatarLink == null)
            {
                UiManager.OpenErrorPopup("Something went wrong and the avatar author could not be retreived. Please try again");
                return;
            }

            if (!Utils.StartRequestTimer())
            {
                return;
            }

            HttpWebRequest request = WebRequest.CreateHttp(avatarLink.OriginalString);

            try
            {
                request.UserAgent = "Mozilla/5.0";
                WebResponse response = await request.GetResponseAsync();

                isFromSocialPage = true;

                StreamReader streamReader  = new StreamReader(response.GetResponseStream());
                JObject      jsonData      = JObject.Parse(streamReader.ReadToEnd());
                JsonData     requestedData = jsonData.ToObject <JsonData>();

                await AsyncUtils.YieldToMainThread();

                OpenUserInSocialMenu(requestedData.ownerId);

                response.Close();
                streamReader.Close();
            }
            catch (WebException)
            {
                await AsyncUtils.YieldToMainThread();

                UiManager.OpenErrorPopup("Something went wrong and the avatar author could not be retreived. Please try again");
                return;
            }
        }
        //message from server
        internal static async void message(VibratorControllerMessage msg, string userID)
        {
            await AsyncUtils.YieldToMainThread();

            switch (msg.Command)
            {
            case Commands.GetToys:
                handleGetToys(userID);
                break;

            case Commands.ToyUpdate:
                handleToyUpdate(msg, userID);
                break;

            case Commands.SetSpeeds:
                handleSetSpeeds(msg);
                break;
            }
        }
        internal static void createMenu()
        {
            MelonLogger.Msg("Creating BP client");
            SetupBP();

            MelonLogger.Msg("Creating Menu");
            search = new ToggleButton((state) =>
            {
                if (state)
                {
                    search.Text = "Scanning...";
                    bpClient.StartScanningAsync();
                }
                else
                {
                    search.Text = "Scan for toys";
                    bpClient.StopScanningAsync();
                }
            },
                                      CreateSpriteFromTexture2D(logo), null, "Scan for toys", "BPToggle", "Scan for connected toys", "Scaning for connected toys");
            networkStatus = new Label("Network", Client.ClientAvailable() ? "Connected" : "Not\nConnected", "networkstatus");
            networkStatus.TextComponent.fontSize = 24;
            buttplugError = new Label("B******g", "No Error", "status");
            buttplugError.TextComponent.fontSize = 24;
            Client.GetClient().ConnectRecieved += async() => {
                await AsyncUtils.YieldToMainThread();

                networkStatus.SubtitleText = Client.ClientAvailable() ? "Connected" : "Not\nConnected";
            };
            TabButton = new TabButton(CreateSpriteFromTexture2D(logo), "Vibrator Controller", "VibratorControllerMenu", "Vibrator Controller", "Vibrator Controller Menu");
            TabButton.SubMenu
            .AddButtonGroup(new ButtonGroup("ControlsGrp", "Controls", new List <IButtonGroupElement>()
            {
                search, networkStatus, buttplugError
            }));

            //Control all toys (vibrate only)
            new Toy("All Toys", 1000, "all", 20, 0, 0, false, TabButton.SubMenu);

            //activate scroll
            TabButton.SubMenu.ToggleScrollbar(true);
        }
예제 #8
0
        internal async void UpdateBattery()
        {
            try
            {
                while (isActive)
                {
                    battery = await device.SendBatteryLevelCmd();

                    await AsyncUtils.YieldToMainThread();

                    if (label != null)
                    {
                        label.SubtitleText = $"Battery: {battery * 100}";
                    }
                    await Task.Delay(1000 * 10);
                }
            }
            catch (Exception)
            {
                //maybe device dissconnected during cmd
            }
        }
예제 #9
0
        public override void OnApplicationStart()
        {
            VRCUtils.Init();

            Harmony.Patch(AccessTools.Method(typeof(MenuController), "Method_Public_Void_APIUser_0"), postfix: new HarmonyMethod(typeof(UserInfoExtensionsMod).GetMethod("OnUserInfoOpen", BindingFlags.Static | BindingFlags.Public)));
            Harmony.Patch(AccessTools.Method(typeof(PageUserInfo), "Back"), postfix: new HarmonyMethod(typeof(UserInfoExtensionsMod).GetMethod("OnUserInfoClose", BindingFlags.Static | BindingFlags.Public)));
            UIExpansionKit.API.LayoutDescription popupLayout = new UIExpansionKit.API.LayoutDescription
            {
                RowHeight  = 80,
                NumColumns = 3,
                NumRows    = 5
            };
            menu            = UIExpansionKit.API.ExpansionKitApi.CreateCustomFullMenuPopup(popupLayout);
            userDetailsMenu = UIExpansionKit.API.ExpansionKitApi.GetExpandedMenu(UIExpansionKit.API.ExpandedMenu.UserDetailsMenu);

            menu.AddLabel("General Things");
            menu.AddSpacer();
            menu.AddSimpleButton("Back", () => menu.Hide());
            userDetailsMenu.AddSimpleButton("UserInfoExtensions", async() =>
            {
                await AsyncUtils.YieldToMainThread();
                HideAllPopups();
                menu.Show();
                foreach (ModuleBase module in modules)
                {
                    module.OnUIEMenuOpen();
                }
            });

            AddModule(new QuickMenuFromSocial());
            AddModule(new GetAvatarAuthor());
            AddModule(new OpenInWorldMenu());
            AddModule(new BioButtons());
            AddModule(new OpenInBrowser());
            AddModule(new UserInformation());

            MelonLogger.Msg("Initialized!");
        }
예제 #10
0
        public async void DownloadTexture(int index)
        {
            MemoryStream stream;

            try
            {
                linkTexts[index].text = BioButtons.bioLinks[index].OriginalString.Length >= 43 ? BioButtons.bioLinks[index].OriginalString.Substring(0, 43) : BioButtons.bioLinks[index].OriginalString;
                WebRequest iconRequest = WebRequest.Create($"http://www.google.com/s2/favicons?domain_url={BioButtons.bioLinks[index].Host}&sz=64");

                WebResponse response = await iconRequest.GetResponseAsync();

                stream = new MemoryStream();
                response.GetResponseStream().CopyTo(stream);
            }
            finally
            {
                await AsyncUtils.YieldToMainThread();
            }

            Texture2D tex = new Texture2D(2, 2);

            ImageConversion.LoadImage(tex, stream.ToArray());
            icons[index].texture = tex;
        }