From 973b410f3371e1d3a807e6384ed68748d11e7523 Mon Sep 17 00:00:00 2001 From: Nyako <24845294+nyakowint@users.noreply.github.com> Date: Thu, 30 Nov 2023 06:56:41 -0500 Subject: [PATCH] feat: optional update checker (default off, change in config) why do i only sometimes follow this goofy convention standard im so inconsistent also its off by default so ppl dont angy lol --- KeyboardOSC/KeyboardOSC.csproj | 18 ++++++++++---- KeyboardOSC/Plugin.cs | 27 ++++++++++++++------- KeyboardOSC/PluginSettings.cs | 1 + KeyboardOSC/Tools.cs | 29 ++++++++++++++++++++++ README.md | 44 ++++++++++++++++++---------------- install.ps1 | 2 +- 6 files changed, 85 insertions(+), 36 deletions(-) diff --git a/KeyboardOSC/KeyboardOSC.csproj b/KeyboardOSC/KeyboardOSC.csproj index 633110d..d841362 100644 --- a/KeyboardOSC/KeyboardOSC.csproj +++ b/KeyboardOSC/KeyboardOSC.csproj @@ -8,6 +8,8 @@ true latest $(SolutionDir)\builds\$(Configuration) + false + false Full @@ -18,20 +20,26 @@ - - - + + + - + - + $(SolutionDir)refs\Assembly-CSharp.dll + + $(SolutionDir)refs\Newtonsoft.Json.dll + + + $(SolutionDir)refs\System.Net.Http.dll + $(SolutionDir)refs\Unity.TextMeshPro.dll diff --git a/KeyboardOSC/Plugin.cs b/KeyboardOSC/Plugin.cs index 3b4d577..6ec2447 100644 --- a/KeyboardOSC/Plugin.cs +++ b/KeyboardOSC/Plugin.cs @@ -1,30 +1,32 @@ using System; -using System.IO; using System.Reflection; -using System.Threading; +using System.Threading.Tasks; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; +using KeyboardOSC; using KeyboardOSC.XScripts; using TMPro; using UnityEngine; -using UnityEngine.Serialization; using UnityEngine.UI; using XSOverlay; +[assembly: AssemblyVersion(Plugin.AssemblyVersion)] + namespace KeyboardOSC { - [BepInPlugin("nwnt.keyboardosc", "KeyboardOSC", "1.1.0.0")] + [BepInPlugin("nwnt.keyboardosc", "KeyboardOSC", AssemblyVersion)] public class Plugin : BaseUnityPlugin { + public const string AssemblyVersion = "1.1.1.0"; public static Plugin Instance; public static ManualLogSource PluginLogger; private static bool _isDebugConfig; public static bool IsChatModeActive; public Overlay_Manager overlayManager; public KeyboardInputHandler inputHandler; - + public GameObject toggleBarObj; public GameObject oscBarWindowObj; @@ -54,7 +56,7 @@ private void Start() ReleaseStickyKeys = AccessTools.Method(typeof(KeyboardInputHandler), "ReleaseStickyKeys"); Patches.PatchAll(); - + ServerBridge.Instance.CommandMap["Keyboard"] = delegate { InitializeKeyboard(); @@ -73,6 +75,8 @@ public void InitializeKeyboard() SetupBar(); ServerBridge.Instance.CommandMap["Keyboard"] = delegate { Overlay_Manager.Instance.EnableKeyboard(); }; + Config.TryGetEntry(PluginSettings.sectionId, "CheckForUpdates", out var checkUpdates); + if (checkUpdates.Value) Task.Run(Tools.CheckVersion); } private void SetupToggleButton() @@ -156,6 +160,10 @@ private void SetupBar() obwTransform.position = keyboardPos.TransformDirection(0, 0.01f, 0); obwTransform.rotation = new Quaternion(0, 0, 0, 0); + var kbOpacity = (Slider) AccessTools.Field(typeof(XSettingsManager), "KeyboardOpacity") + .GetValue(XSettingsManager.Instance); + kbOpacity.onValueChanged.AddListener(value => { oscBarWindow.opacity = value; }); + XSOEventSystem.OnGrabbedOrDroppedOverlay += (targetOverlay, _, grabbed) => { if (targetOverlay.overlayKey != "xso.overlay.keyboard" || grabbed) return; @@ -173,16 +181,16 @@ private void SetupBar() .gameObject, kbBackground.transform); Destroy(oscBarCanvas.transform.Find("Keyboard Background/KeyboardSettings").gameObject); oscBarTextObj.Rename("KeyboardOSC Bar Text"); - + var oscbarText = oscBarTextObj.GetComponent(); XSTools.SetTMPUIText(oscbarText, "type something silly!"); - + oscbarText.fontSize = 250f; oscbarText.fontSizeMax = 250f; oscbarText.horizontalAlignment = HorizontalAlignmentOptions.Center; oscbarText.verticalAlignment = VerticalAlignmentOptions.Middle; - + ChatMode.Setup(oscbarText); oscBarRoot.SetActive(true); keyboardWindowObj.SetActive(true); @@ -192,6 +200,7 @@ private void SetupBar() public void RepositionBar(Unity_Overlay barOverlay, Unity_Overlay keebOverlay) { + barOverlay.opacity = keebOverlay.opacity; WindowMovementManager.ScaleOverlayToScale(keebOverlay.widthInMeters - 0.1f, 0.1f, barOverlay); WindowMovementManager.MoveToEdgeOfWindowAndInheritRotation(barOverlay, keebOverlay, Vector3.Distance(keebOverlay.transform.position, barOverlay.transform.position) * 0.05f, 0f, 1); diff --git a/KeyboardOSC/PluginSettings.cs b/KeyboardOSC/PluginSettings.cs index e605404..e01bd64 100644 --- a/KeyboardOSC/PluginSettings.cs +++ b/KeyboardOSC/PluginSettings.cs @@ -10,5 +10,6 @@ public class PluginSettings internal static void Init() { ConfigFile.Bind(sectionId, "HasSeenHint", false, "Has user seen osc hint"); + ConfigFile.Bind(sectionId, "CheckForUpdates", false, "Notify user of updates on init?"); } } \ No newline at end of file diff --git a/KeyboardOSC/Tools.cs b/KeyboardOSC/Tools.cs index 72bdbd2..bb73763 100644 --- a/KeyboardOSC/Tools.cs +++ b/KeyboardOSC/Tools.cs @@ -1,10 +1,15 @@ using System; using System.Diagnostics; using System.IO; +using System.Linq; +using System.Net.Http; using System.Reflection; using System.Runtime.InteropServices; using System.Text; using System.Threading; +using System.Threading.Tasks; +using BepInEx; +using Newtonsoft.Json.Linq; using UnityEngine; using WindowsInput.Native; using XSOverlay; @@ -121,6 +126,30 @@ public static Texture2D GetTexture(string resName) return texture; } + private const string ReleaseUrl = "https://api.github.com/repos/nyakowint/xsoverlay-keyboard-osc/releases/latest"; + + public static async Task CheckVersion() + { + using var client = new HttpClient(); + client.DefaultRequestHeaders.Add("User-Agent", "xso-kbosc"); + + var response = await client.GetStringAsync(ReleaseUrl); + var json = JObject.Parse(response); + if (json["assets"] == null) throw new Exception("No assets found in release."); + var latestReleaseAssetUrl = json["assets"].First(b => b["name"].Value() == "KeyboardOSC.dll"); + if (latestReleaseAssetUrl == null) throw new Exception("Could not find the mod in release."); + + var release = + Assembly.Load( + await client.GetByteArrayAsync(latestReleaseAssetUrl["browser_download_url"]!.Value())); + + if (release.GetName().Version > Version.Parse(Plugin.AssemblyVersion)) + { + ThreadingHelper.Instance.StartSyncInvoke(() => SendBread("Plugin Update Available", + "A new version of KeyboardOSC is available. It's recommended to install it :D")); + } + } + [DllImport("user32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)] private static extern int ToUnicodeEx(uint wVirtKey, uint wScanCode, byte[] lpKeyState, StringBuilder pwszBuff, int cchBuff, uint wFlags, IntPtr dwhkl); diff --git a/README.md b/README.md index 9101fee..d67bf77 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,8 @@ A extension for XSOverlay to make text communication in VRChat easier. > [!NOTE] -> This is a third-party modification to [XSOverlay](https://store.steampowered.com/app/1173510/XSOverlay/). Use at your own discretion\ +> This is a third-party modification to [XSOverlay](https://store.steampowered.com/app/1173510/XSOverlay/). Use at your +> own discretion\ > Last tested with build 649. It should work on any recent version. ## Auto Install @@ -16,10 +17,12 @@ Open a PowerShell window, navigate to your XSOverlay folder and paste the follow Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/nyakowint/xsoverlay-keyboard-osc/main/install.ps1" | Invoke-Expression ``` -If you have any issues try manually installing with the instructions below. +Open XSOverlay, and hit that shiny new button on the right side of the keyboard! +If you're having trouble, try manually installing with the instructions below. ## Manual Installation + 1. [Follow the BepInEx install guide](https://docs.bepinex.dev/articles/user_guide/installation/index.html) into XSOverlay. 2. Download both the plugin DLL **and** `BepInEx.cfg` from [Releases](../../releases/latest) @@ -29,10 +32,11 @@ If you have any issues try manually installing with the instructions below. - or set it yourself: `HideManagerGameObject = true` 4. Start XSOverlay 5. If you did everything right you should have a message icon on the keyboard toolbar (right). \ -Click it. A bar should pop up above the keyboard. If not, move the + Click it. A bar should pop up above the keyboard. If not, move the keyboard around and it should pop up. -1. congration you done it - - You may also want to disable XSO analytics while using the plugin, but that's up to you, i'm not the one getting error logs XD +6. congration you done it + - You may also want to disable XSO analytics while using the plugin, but that's up to you, i'm not the one getting + error logs XD ### Removing the plugin @@ -45,29 +49,26 @@ Send messages to the chatbox just like in OVR Toolkit! Use the following shortcut keys: | Shortcut Key | Function | ---------------- | -------- -| TAB | Toggle silent msg (orange text, disables typing indicator and chatbox noise) -| ESC | Clear current text -| Backspace or Delete | Delete last character from right (bksp) or left (del) | ESC | Clear current text | END | Clear last sent message (equivalent to pressing "Clear Chatbox" in radial menu) -| F6 | Toggle "partial send" mode (Send messages as you're typing them) +| TAB | Toggle silent msg (orange text, disables typing indicator and chatbox noise) | INSERT | Replace current text with your last message +| F6 | Send partial messages as you're typing (experimental) +|   | +| Backspace or Delete | Delete last character from right or left respectively | CTRL + C | Copy current text to clipboard | CTRL + V | Paste text from your clipboard -| CTRL + Backspace | Delete last word (this one is weird as holding ctrl doesnt actually mean holding ctrl) | +| CTRL + Backspace | Delete last word (experimental) | ENTER | Send message to the chatbox! -I cannot guarantee full functionality with the CVR chatbox mod, as this is built with VRChat's OSC routes in mind. They were identical last I checked. - -## Unplanned features - -- Any type of "now playing" feature. It's out of scope for the plugin lol -- Text-to-Speech, STT & STTS. If someone wants to implement this PRs are welcome but it's not in my interest. +I cannot guarantee full functionality with the CVR chatbox mod, as this is built with VRChat's OSC routes in mind. They +were identical last I checked. ## Known Issues -- The bar will be positioned significantly higher than intended until moved/scaled. I consider this a non-issue - +- The bar will be positioned significantly higher than intended until you move it for the first time. I consider this a + non-issue + If you find any, create an issue so i can remember to try and fix it when i feel like it If you still need help you can find me in my dev server [discord](https://discord.gg/BrUacrw4cy) @@ -79,7 +80,8 @@ Check the .csproj or actions workflow but if you wanna build this just drop the dlls from `XSOverlay_Data/Managed` into `refs`, restore and build w/ Release config. dll will be in `builds` folder -## Why a mod for a vr overlay? +### Motivation -* I like the control scheme of XSOverlay better than OVRTK. No, you _dont_ have to agree with me. -* Why wait for it to be added when you can do it yourself? lol +- vrchat's keyboard is so gosh darn buggy. I wasn't even able to type a full sentence before it malfunctioned. this bug is probably buried on their swamped canny page lol +- i like that ovr toolkit had this feature already, but i dont want to switch back to it +- u nerd lol diff --git a/install.ps1 b/install.ps1 index 8bdf41a..4e979f1 100644 --- a/install.ps1 +++ b/install.ps1 @@ -10,7 +10,7 @@ Invoke-WebRequest -Uri $bepInExUrl -OutFile "./BepInEx.zip" Write-Host "Extracting into current directory..." Expand-Archive -Path "./BepInEx.zip" -DestinationPath "./" -Force -Remove-Item -Path "./BepInEx.zip" +Remove-Item -Path "./BepInEx.zip" -Force New-Item -ItemType Directory -Path "./BepInEx/config" -Force New-Item -ItemType Directory -Path "./BepInEx/plugins" -Force