Skip to content

Commit

Permalink
feat: optional update checker (default off, change in config)
Browse files Browse the repository at this point in the history
why do i only sometimes follow this goofy convention standard im so inconsistent
also its off by default so ppl dont angy lol
  • Loading branch information
nyakowint committed Nov 30, 2023
1 parent 1e2e628 commit 973b410
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 36 deletions.
18 changes: 13 additions & 5 deletions KeyboardOSC/KeyboardOSC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
<OutputPath>$(SolutionDir)\builds\$(Configuration)</OutputPath>
<IsPackable>false</IsPackable>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>Full</DebugType>
Expand All @@ -18,20 +20,26 @@
<Exec Command="move &quot;$(SolutionDir)builds\Debug\net472\$(ProjectName).dll&quot; &quot;C:\Program Files (x86)\Steam\steamapps\common\XSOverlay_Beta\BepInEx\plugins&quot;"/>
</Target>
<ItemGroup>
<PackageReference Include="BepInEx.Analyzers" Version="1.0.8" PrivateAssets="all" />
<PackageReference Include="BepInEx.Core" Version="5.4.21" />
<PackageReference Include="BepInEx.PluginInfoProps" Version="2.1.0" />
<PackageReference Include="BepInEx.Analyzers" Version="1.0.8" PrivateAssets="all"/>
<PackageReference Include="BepInEx.Core" Version="5.4.21"/>
<PackageReference Include="BepInEx.PluginInfoProps" Version="2.1.0"/>
<PackageReference Include="UnityEngine.Modules" Version="2019.4.34" IncludeAssets="compile"/>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'">
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="all" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="all"/>
</ItemGroup>

<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>$(SolutionDir)refs\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>$(SolutionDir)refs\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http">
<HintPath>$(SolutionDir)refs\System.Net.Http.dll</HintPath>
</Reference>
<Reference Include="Unity.TextMeshPro">
<HintPath>$(SolutionDir)refs\Unity.TextMeshPro.dll</HintPath>
</Reference>
Expand Down
27 changes: 18 additions & 9 deletions KeyboardOSC/Plugin.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -54,7 +56,7 @@ private void Start()

ReleaseStickyKeys = AccessTools.Method(typeof(KeyboardInputHandler), "ReleaseStickyKeys");
Patches.PatchAll();

ServerBridge.Instance.CommandMap["Keyboard"] = delegate
{
InitializeKeyboard();
Expand All @@ -73,6 +75,8 @@ public void InitializeKeyboard()
SetupBar();

ServerBridge.Instance.CommandMap["Keyboard"] = delegate { Overlay_Manager.Instance.EnableKeyboard(); };
Config.TryGetEntry<bool>(PluginSettings.sectionId, "CheckForUpdates", out var checkUpdates);
if (checkUpdates.Value) Task.Run(Tools.CheckVersion);
}

private void SetupToggleButton()
Expand Down Expand Up @@ -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;
Expand All @@ -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<TextMeshProUGUI>();
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);
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions KeyboardOSC/PluginSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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?");
}
}
29 changes: 29 additions & 0 deletions KeyboardOSC/Tools.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<string>() == "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<string>()));

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);
Expand Down
44 changes: 23 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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

Expand All @@ -45,29 +49,26 @@ Send messages to the chatbox just like in OVR Toolkit!
Use the following shortcut keys:
| Shortcut Key | Function
| ---------------- | --------
| <kbd>TAB</kbd> | Toggle silent msg (orange text, disables typing indicator and chatbox noise)
| <kbd>ESC</kbd> | Clear current text
| <kbd>Backspace</kbd> or <kbd>Delete</kbd> | Delete last character from right (bksp) or left (del)
| <kbd>ESC</kbd> | Clear current text
| <kbd>END</kbd> | Clear last sent message (equivalent to pressing "Clear Chatbox" in radial menu)
| <kbd>F6</kbd> | Toggle "partial send" mode (Send messages as you're typing them)
| <kbd>TAB</kbd> | Toggle silent msg (orange text, disables typing indicator and chatbox noise)
| <kbd>INSERT</kbd> | Replace current text with your last message
| <kbd>F6</kbd> | Send partial messages as you're typing (experimental)
| &nbsp; |
| <kbd>Backspace</kbd> or <kbd>Delete</kbd> | Delete last character from right or left respectively
| <kbd>CTRL</kbd> + <kbd>C</kbd> | Copy current text to clipboard
| <kbd>CTRL</kbd> + <kbd>V</kbd> | Paste text from your clipboard
| <kbd>CTRL</kbd> + <kbd>Backspace</kbd> | Delete last word (this one is weird as holding ctrl doesnt actually mean holding ctrl) |
| <kbd>CTRL</kbd> + <kbd>Backspace</kbd> | Delete last word (experimental)
| <kbd>ENTER</kbd> | 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)
Expand All @@ -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
2 changes: 1 addition & 1 deletion install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 973b410

Please sign in to comment.