Skip to content

Commit

Permalink
single celled organism
Browse files Browse the repository at this point in the history
  • Loading branch information
nyakowint committed Dec 28, 2023
1 parent f97081f commit c6d1273
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 15 deletions.
40 changes: 35 additions & 5 deletions KeyboardOSC/Patches.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using HarmonyLib;
using UnityEngine;
using WindowsInput;
Expand All @@ -11,7 +12,8 @@ namespace KeyboardOSC;
public static class Patches
{
private static Harmony Harmony;
private static bool HasSettingsBeenOpenedOnce = false;
private static WindowAttachementManager.DeviceToAttachTo kbAttachedTo;
private static bool HasSettingsBeenOpenedOnce;

public static void PatchAll()
{
Expand All @@ -29,11 +31,11 @@ public static void PatchAll()

// stop inputs being sent to overlays
var keyPress = AccessTools.Method(typeof(KeyboardSimulator), nameof(KeyboardSimulator.KeyPress),
new[] {typeof(VirtualKeyCode)});
new[] { typeof(VirtualKeyCode) });
var keyDown = AccessTools.Method(typeof(KeyboardSimulator), nameof(KeyboardSimulator.KeyDown),
new[] {typeof(VirtualKeyCode)});
new[] { typeof(VirtualKeyCode) });
var keyUp = AccessTools.Method(typeof(KeyboardSimulator), nameof(KeyboardSimulator.KeyUp),
new[] {typeof(VirtualKeyCode)});
new[] { typeof(VirtualKeyCode) });
var blockInputPatch = new HarmonyMethod(typeof(Patches).GetMethod(nameof(BlockInput)));

Harmony.Patch(keyPress, prefix: blockInputPatch);
Expand All @@ -42,12 +44,18 @@ public static void PatchAll()

#endregion


// Scale bar with keyboard
var scaleMethod =
AccessTools.Method(typeof(WindowMovementManager), nameof(WindowMovementManager.DoScaleWindowFixed));
var scalePatch = new HarmonyMethod(typeof(Patches).GetMethod(nameof(ScalePatch)));
Harmony.Patch(scaleMethod, null, scalePatch);

// gosh i love enumerators (fix for a problem i created lol)
var attachMethod = AccessTools.Method(typeof(WindowMovementManager), "DelayedTransformSetToTarget");
var attachPatch = new HarmonyMethod(typeof(Patches).GetMethod(nameof(AttachedMovePatch)));
Harmony.Patch(attachMethod, null, attachPatch);

// Disable analytics by default (Xiexe loves seeing my plugin errors im sure XD)
// can be turned back on after launching if you want to send him stuff for some reason
var initAnalytics = AccessTools.Method(typeof(AnalyticsManager), "Initialize");
Expand Down Expand Up @@ -85,6 +93,14 @@ public static void AnalyticsPatch()
XSettingsManager.Instance.Settings.SendAnalytics = false;
}

public static void AttachedMovePatch(Unity_Overlay overlay, Transform target, Overlay_TrackDevice deviceTracker,
Unity_Overlay.OverlayTrackedDevice device, Vector3 pos, Quaternion rot, float originalScale,
float originalOpacity)
{
var chatBar = Plugin.Instance.oscBarWindowObj.GetComponent<Unity_Overlay>();
Plugin.Instance.RepositionBar(chatBar, overlay);
}

public static void ScalePatch(float dist, Unity_Overlay activeOverlay, float StartingWidth)
{
if (!Plugin.ChatModeActive || activeOverlay.overlayKey != "xso.overlay.keyboard") return;
Expand All @@ -107,9 +123,10 @@ public static void RequestSettingsPatch(string sender, string data)
// create new UiSettings instance
var settings = new UiSettings
{
KBVersion = Plugin.AssemblyVersion,
KBCheckForUpdates = PluginSettings.GetSetting<bool>("CheckForUpdates").Value,
KBLiveSend = PluginSettings.GetSetting<bool>("LiveSend").Value,
KBTypingIndicator = PluginSettings.GetSetting<bool>("TypingIndicator").Value
KBTypingIndicator = PluginSettings.GetSetting<bool>("TypingIndicator").Value,
};
var data2 = JsonUtility.ToJson(settings, true);
ServerBridge.Instance.SendMessage("UpdateSettings", data2, null, sender);
Expand Down Expand Up @@ -138,6 +155,19 @@ public static bool SetSettingPatch(string name, string value, string value1, boo
Application.OpenURL("https://github.com/nyakowint/xsoverlay-keyboard-osc");
Tools.SendBread("KeyboardOSC Github link opened in browser!");
break;
case "KBAttachmentIndex":
kbAttachedTo = (WindowAttachementManager.DeviceToAttachTo)int.Parse(value);
Plugin.Instance.AttachKeyboard(int.Parse(value));
break;
case "KBVersion":
Plugin.PluginLogger.LogWarning("bro what are you doing this is literally text");
break;
case "KBVersionCheck":
Task.Run(Tools.CheckVersion);
break;
default:
Plugin.PluginLogger.LogWarning($"Unknown setting {name}. Looks like you need to update the plugin!");
break;
}

return true;
Expand Down
14 changes: 10 additions & 4 deletions KeyboardOSC/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ namespace KeyboardOSC
[BepInPlugin("nwnt.keyboardosc", "KeyboardOSC", AssemblyVersion)]
public class Plugin : BaseUnityPlugin
{
public const string AssemblyVersion = "1.2.0.0";
public const string AssemblyVersion = "1.2.1.0";
public static Plugin Instance;
public static ManualLogSource PluginLogger;

public static bool isDebugConfig;
public static bool IsDebugConfig;
public static bool ChatModeActive;
public static bool ModifiedUiSuccess;

Expand All @@ -38,17 +38,18 @@ public class Plugin : BaseUnityPlugin
private void Awake()
{
#if DEBUG
isDebugConfig = true;
IsDebugConfig = true;
#endif
PluginLogger = Logger;
if (Instance != null) Destroy(this);
PluginSettings.ConfigFile = Config;
PluginSettings.Init();

// Download modified settings code

ModifiedUiSuccess = Tools.DownloadModifiedUi();

if (!Environment.CommandLine.Contains("-batchmode") || isDebugConfig) return;
if (!Environment.CommandLine.Contains("-batchmode") || IsDebugConfig) return;
Logger.LogWarning("XSOverlay runs in batchmode normally (headless, without a window).");
Logger.LogWarning("To see extended logs launch XSOverlay directly.");
}
Expand Down Expand Up @@ -219,6 +220,11 @@ public void RepositionBar(Unity_Overlay barOverlay, Unity_Overlay keebOverlay)
Vector3.Distance(keebOverlay.transform.position, barOverlay.transform.position) * 0.05f, 0f, 1);
}

public void AttachKeyboard(int anchor)
{
WindowMovementManager.WMM_Inst.AttachWindowToDeviceIndex(anchor, overlayManager.Keyboard_Overlay);
}

public void ToggleChatMode()
{
ReleaseStickyKeys.Invoke(inputHandler, null);
Expand Down
2 changes: 2 additions & 0 deletions KeyboardOSC/PluginSettings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BepInEx.Configuration;
using XSOverlay;

// ReSharper disable InconsistentNaming

Expand Down Expand Up @@ -32,6 +33,7 @@ public static void SetSetting<T>(string settingName, string value)

public class UiSettings
{
public string KBVersion = Plugin.AssemblyVersion;
public bool KBCheckForUpdates = false;
public bool KBLiveSend = false;
public bool KBTypingIndicator = true;
Expand Down
8 changes: 3 additions & 5 deletions KeyboardOSC/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ public static async Task CheckVersion()
{
logger.LogInfo("No updates available.");
}

client.Dispose();

}

public static bool DownloadModifiedUi()
{
var logger = Plugin.PluginLogger;
if (Plugin.IsDebugConfig) return true;
using var client = new WebClient();
try
{
Expand All @@ -150,11 +150,9 @@ public static bool DownloadModifiedUi()
catch (Exception exception)
{
Plugin.PluginLogger.LogError($"Exception downloading modified ui: {exception}");
client.Dispose();
return false;
}

client.Dispose();

return true;
}

Expand Down
5 changes: 4 additions & 1 deletion settingsKO.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ const SettingsLayout = {
KBCheckForUpdates: new SettingsElements.Setting(SettingsElements.UIComponents.Toggle, 'Notify about updates', "The plugin will notify you if there's an update available :D", false),
KBLiveSend: new SettingsElements.Setting(SettingsElements.UIComponents.Toggle, 'Live send mode', "Messages will be sent to the chatbox as you type.", false),
KBTypingIndicator: new SettingsElements.Setting(SettingsElements.UIComponents.Toggle, 'Send typing indicator', "Some people prefer to not let people know when they are typing for some reason lol", true),
KBOpenRepo: new SettingsElements.Setting(SettingsElements.UIComponents.Button, 'Plugin Repo', "View this plugin's repo on GitHub", '', '', '')
KBAttachmentIndex: new SettingsElements.Setting(SettingsElements.UIComponents.Dropdown, 'Keyboard Attachment', "put the keyboard on ur head idk", 'Disabled', ['Disabled', 'So no head?', 'Left hand', 'Right hand']),
KBOpenRepo: new SettingsElements.Setting(SettingsElements.UIComponents.Button, 'Plugin Repo', "View this plugin's repo on GitHub", '', '', ''),
KBVersionCheck: new SettingsElements.Setting(SettingsElements.UIComponents.Button, 'Check for updates', "Check for updates rn!!!!!", '', '', ''),
KBVersion: new SettingsElements.Setting(SettingsElements.UIComponents.Text, 'KBVersion'),
},
},
General: {
Expand Down

0 comments on commit c6d1273

Please sign in to comment.