Skip to content

Commit

Permalink
tfw whatever broke wasnt even ur fault
Browse files Browse the repository at this point in the history
  • Loading branch information
nyakowint committed Oct 20, 2023
1 parent 7ec125c commit 214b4aa
Show file tree
Hide file tree
Showing 8 changed files with 262 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ jobs:
- name: Create Release
run: |
$short_sha="${{ github.sha }}".Substring(0,7)
gh release create ${{ steps.tag_version.outputs.new_tag }}-$short_sha ./builds/Release/net472/KeyboardOSC.dll --title "KeyboardOSC Build $short_sha" --prerelease --notes "${{ steps.tag_version.outputs.changelog }}"
gh release create ${{ steps.tag_version.outputs.new_tag }}-$short_sha --title "KeyboardOSC Build $short_sha" --prerelease --notes "${{ steps.tag_version.outputs.changelog }} ./builds/Release/net472/KeyboardOSC.dll ./BepInEx.cfg"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
151 changes: 151 additions & 0 deletions BepInEx.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
[Caching]

## Enable/disable assembly metadata cache
## Enabling this will speed up discovery of plugins and patchers by caching the metadata of all types BepInEx discovers.
# Setting type: Boolean
# Default value: true
EnableAssemblyCache = true

[Chainloader]

## If enabled, hides BepInEx Manager GameObject from Unity.
## This can fix loading issues in some games that attempt to prevent BepInEx from being loaded.
## Use this only if you know what this option means, as it can affect functionality of some older plugins.
##
# Setting type: Boolean
# Default value: false
HideManagerGameObject = true

[Harmony.Logger]

## Specifies which Harmony log channels to listen to.
## NOTE: IL channel dumps the whole patch methods, use only when needed!
# Setting type: LogChannel
# Default value: Warn, Error
# Acceptable values: None, Info, IL, Warn, Error, Debug, All
# Multiple values can be set at the same time by separating them with , (e.g. Debug, Warning)
LogChannels = Warn, Error

[Logging]

## Enables showing unity log messages in the BepInEx logging system.
# Setting type: Boolean
# Default value: true
UnityLogListening = true

## If enabled, writes Standard Output messages to Unity log
## NOTE: By default, Unity does so automatically. Only use this option if no console messages are visible in Unity log
##
# Setting type: Boolean
# Default value: false
LogConsoleToUnityLog = false

[Logging.Console]

## Enables showing a console for log output.
# Setting type: Boolean
# Default value: false
Enabled = false

## If enabled, will prevent closing the console (either by deleting the close button or in other platform-specific way).
# Setting type: Boolean
# Default value: false
PreventClose = false

## If true, console is set to the Shift-JIS encoding, otherwise UTF-8 encoding.
# Setting type: Boolean
# Default value: false
ShiftJisEncoding = false

## Hints console manager on what handle to assign as StandardOut. Possible values:
## Auto - lets BepInEx decide how to redirect console output
## ConsoleOut - prefer redirecting to console output; if possible, closes original standard output
## StandardOut - prefer redirecting to standard output; if possible, closes console out
##
# Setting type: ConsoleOutRedirectType
# Default value: Auto
# Acceptable values: Auto, ConsoleOut, StandardOut
StandardOutType = Auto

## Which log levels to show in the console output.
# Setting type: LogLevel
# Default value: Fatal, Error, Warning, Message, Info
# Acceptable values: None, Fatal, Error, Warning, Message, Info, Debug, All
# Multiple values can be set at the same time by separating them with , (e.g. Debug, Warning)
LogLevels = Fatal, Error, Warning, Message, Info

[Logging.Disk]

## Include unity log messages in log file output.
# Setting type: Boolean
# Default value: false
WriteUnityLog = false

## Appends to the log file instead of overwriting, on game startup.
# Setting type: Boolean
# Default value: false
AppendLog = false

## Enables writing log messages to disk.
# Setting type: Boolean
# Default value: true
Enabled = true

## Which log leves are saved to the disk log output.
# Setting type: LogLevel
# Default value: Fatal, Error, Warning, Message, Info
# Acceptable values: None, Fatal, Error, Warning, Message, Info, Debug, All
# Multiple values can be set at the same time by separating them with , (e.g. Debug, Warning)
LogLevels = Fatal, Error, Warning, Message, Info

[Preloader]

## Enables or disables runtime patches.
## This should always be true, unless you cannot start the game due to a Harmony related issue (such as running .NET Standard runtime) or you know what you're doing.
# Setting type: Boolean
# Default value: true
ApplyRuntimePatches = true

## Specifies which MonoMod backend to use for Harmony patches. Auto uses the best available backend.
## This setting should only be used for development purposes (e.g. debugging in dnSpy). Other code might override this setting.
# Setting type: MonoModBackend
# Default value: auto
# Acceptable values: auto, dynamicmethod, methodbuilder, cecil
HarmonyBackend = auto

## If enabled, BepInEx will save patched assemblies into BepInEx/DumpedAssemblies.
## This can be used by developers to inspect and debug preloader patchers.
# Setting type: Boolean
# Default value: false
DumpAssemblies = false

## If enabled, BepInEx will load patched assemblies from BepInEx/DumpedAssemblies instead of memory.
## This can be used to be able to load patched assemblies into debuggers like dnSpy.
## If set to true, will override DumpAssemblies.
# Setting type: Boolean
# Default value: false
LoadDumpedAssemblies = false

## If enabled, BepInEx will call Debugger.Break() once before loading patched assemblies.
## This can be used with debuggers like dnSpy to install breakpoints into patched assemblies before they are loaded.
# Setting type: Boolean
# Default value: false
BreakBeforeLoadAssemblies = false

[Preloader.Entrypoint]

## The local filename of the assembly to target.
# Setting type: String
# Default value: UnityEngine.CoreModule.dll
Assembly = UnityEngine.CoreModule.dll

## The name of the type in the entrypoint assembly to search for the entrypoint method.
# Setting type: String
# Default value: Application
Type = Application

## The name of the method in the specified entrypoint assembly and type to hook and load Chainloader from.
# Setting type: String
# Default value: .cctor
Method = .cctor

2 changes: 1 addition & 1 deletion KeyboardOSC/Patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static class Patches
private static readonly ManualLogSource Logger = Plugin.PluginLogger;
public static Harmony Harmony;

public static void DoPatches()
public static void PatchAll()
{
Harmony = new Harmony("nwnt.keyboardosc");
// patch key presses
Expand Down
42 changes: 28 additions & 14 deletions KeyboardOSC/Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using System.IO;
using System.Reflection;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using KeyboardOSC.XScripts;
Expand All @@ -11,13 +14,13 @@

namespace KeyboardOSC
{
[BepInPlugin("nwnt.keyboardosc", "KeyboardOSC", "1.0.0.0")]
[BepInPlugin("nwnt.keyboardosc", "KeyboardOSC", "1.0.1.1")]
public class Plugin : BaseUnityPlugin
{
public static Plugin Instance;
public static ManualLogSource PluginLogger;
public static bool IsFirstOpen = true;
public static bool IsChatModeActive = false;
private static bool _isDebugConfig;

Check warning on line 22 in KeyboardOSC/Plugin.cs

View workflow job for this annotation

GitHub Actions / build

Field 'Plugin._isDebugConfig' is never assigned to, and will always have its default value false

Check warning on line 22 in KeyboardOSC/Plugin.cs

View workflow job for this annotation

GitHub Actions / build

Field 'Plugin._isDebugConfig' is never assigned to, and will always have its default value false
public static bool IsChatModeActive;
public Overlay_Manager overlayManager;
public KeyboardInputHandler inputHandler;
public GameObject chatButtonObj;
Expand All @@ -26,18 +29,29 @@ public class Plugin : BaseUnityPlugin

public static MethodInfo ReleaseStickyKeys;

private void Start()
private void Awake()
{
#if DEBUG
_isDebugConfig = true;
#endif
PluginLogger = Logger;
Logger.LogWarning("Starting Pre-setup");
if (Instance != null) Destroy(this);
PluginSettings.ConfigFile = Config;
PluginSettings.Init();
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.");
}

private void Start()
{
Logger.LogWarning("It works! Starting Pre-setup");
Instance = this;
Console.Title = "XSO BepInEx Console";

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


Patches.PatchAll();

ServerBridge.Instance.CommandMap["Keyboard"] = delegate
{
InitializeKeyboard();
Expand Down Expand Up @@ -71,13 +85,13 @@ private void SetupAdditionalGameObjects()
chatButtonObj.transform.Find("Image").GetComponent<Image>().sprite = "chat".GetSprite();
chatButtonObj.Rename("OSC Keyboard Mode");


// Create typing bar
var oscBarRoot = new GameObject("TypingBarOverlay");
oscBarRoot.SetActive(false);
keyboardWindowObj.SetActive(false);
oscBarRoot.AddComponent<OverlayTopLevelObject>();

oscBarWindowObj = Instantiate(keyboardWindow.gameObject, oscBarRoot.transform);
oscBarWindowObj.Rename("TypingBar Overlay");
oscBarWindowObj.DestroyComponent<KeyboardGlobalManager>();
Expand All @@ -88,7 +102,7 @@ private void SetupAdditionalGameObjects()
oscBarWindowObj.GetComponent<OverlayIdentifier>().OverlayTopLevelObject = oscBarRoot;
oscBarWindow.overlayName = "chatbar";
oscBarWindow.overlayKey = "chatbar";

oscBarWindow.isMoveable = false;


Expand Down Expand Up @@ -142,12 +156,12 @@ private void SetupAdditionalGameObjects()
var newTrans = overlay.transform;
var newPos = newTrans.position;
const float offset = 0.155f;
obwTransform.position = newPos + newTrans.up * offset ;
obwTransform.position = newPos + newTrans.up * offset;
obwTransform.rotation = newTrans.rotation;
};

kbBackground.transform.localPosition = Vector3.zero;

kbBackground.GetComponent<RectTransform>().sizeDelta = new Vector2(4130, 475);

camTrans.position = canvasTrans.position;
Expand Down Expand Up @@ -176,7 +190,7 @@ public void ToggleChatMode()
{
var chatButton = chatButtonObj.GetComponent<Button>();
var buttonColors = chatButton.colors;

ReleaseStickyKeys.Invoke(inputHandler, null);

IsChatModeActive = !IsChatModeActive;
Expand Down
14 changes: 14 additions & 0 deletions KeyboardOSC/PluginSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using BepInEx.Configuration;

namespace KeyboardOSC;

public class PluginSettings
{
public static ConfigFile ConfigFile;
public static string sectionId = "KBOSC";

internal static void Init()
{
ConfigFile.Bind(sectionId, "HasSeenHint", false, "Has user seen osc hint");
}
}
8 changes: 5 additions & 3 deletions KeyboardOSC/ToggleChatButton.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UnityEngine;
using BepInEx.Configuration;
using UnityEngine;
using UnityEngine.UI;

namespace KeyboardOSC;
Expand All @@ -18,10 +19,11 @@ private void OnDisable()

private static void ToggleChatMode()
{
if (Plugin.IsFirstOpen)
PluginSettings.ConfigFile.TryGetEntry(PluginSettings.sectionId, "HasSeenHint", out ConfigEntry<bool> hasSeenHint);
if (!hasSeenHint.Value)
{
Tools.SendBread("HOLD UP!", "Make sure OSC is enabled in VRChat or this will do nothing! lol");
Plugin.IsFirstOpen = false;
hasSeenHint.SetSerializedValue("true");
}
Plugin.Instance.ToggleChatMode();
}
Expand Down
23 changes: 15 additions & 8 deletions KeyboardOSC/Tools.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using UnityEngine;
using WindowsInput.Native;
using XSOverlay;
Expand Down Expand Up @@ -35,20 +37,21 @@ public static void SendBread(string title, string content)
content = content,
messageType = 1,
timeout = 5f,
height = calculateHeight(content),
height = CalculateHeight(content),
sourceApp = "KeyboardOSC Plugin",
volume = 0.5f
};
NotificationHandler.Instance.PrepareToast(notif);
}


public static string ConvertVirtualKeyToUnicode(VirtualKeyCode keyCode, uint scanCode, bool shift, bool altGr)
{
return GetCharsFromKeys(keyCode, scanCode, shift, altGr);
}

private static int calculateHeight(string content) {

private static int CalculateHeight(string content)
{
return content.Length switch
{
<= 100 => 100,
Expand Down Expand Up @@ -121,8 +124,8 @@ public static Texture2D GetTexture(string resName)
[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);


// REEEEEEE
private static string GetCharsFromKeys(VirtualKeyCode key, uint scanCode, bool shift, bool altGr)
{
Expand All @@ -132,24 +135,28 @@ private static string GetCharsFromKeys(VirtualKeyCode key, uint scanCode, bool s
{
array[16] = byte.MaxValue;
}

if (altGr)
{
array[17] = byte.MaxValue;
array[18] = byte.MaxValue;
}
int num = ToUnicodeEx((uint)key, scanCode, array, stringBuilder, stringBuilder.Capacity, 0u, _currentHkl);

int num = ToUnicodeEx((uint) key, scanCode, array, stringBuilder, stringBuilder.Capacity, 0u, _currentHkl);
if (num == k_SUCCESS)
{
return stringBuilder.ToString();
}

if (num == k_NOTRANSLATION)
{
return "";
}

_ = k_DEADCHAR;
return stringBuilder[stringBuilder.Length - 1].ToString();
}

public static int k_DEADCHAR;
public static int k_NOTRANSLATION;
public static int k_SUCCESS;
Expand Down
Loading

0 comments on commit 214b4aa

Please sign in to comment.