Skip to content

Commit

Permalink
Push beta to main
Browse files Browse the repository at this point in the history
random update at 9pm be like
  • Loading branch information
nyakowint committed Apr 12, 2024
2 parents 1ffa713 + e430ba0 commit 8ae3d83
Show file tree
Hide file tree
Showing 21 changed files with 978 additions and 289 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ko_fi: nyakonyan
ko_fi: nyakonyan
64 changes: 44 additions & 20 deletions KeyboardOSC/ChatMode.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Timers;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using KeyboardOSC.Twitch;
using TMPro;
using UnityEngine;
using WindowsInput.Native;
Expand All @@ -28,12 +30,12 @@ public static class ChatMode
public static void HandleKey(KeyboardKey.VirtualKeyEventData eventData)
{
var scanCode = eventData.Sender.UsingRawVirtualKeyCode
? (uint) eventData.KeyCode[0]
? (uint)eventData.KeyCode[0]
: eventData.Sender.ScanCode[0];
var shiftedField = AccessTools.Field(typeof(KeyboardKey), "IsShifted");
var altedField = AccessTools.Field(typeof(KeyboardKey), "IsAlted");
var isShifted = (bool) shiftedField.GetValue(eventData.Sender);
var isAlted = (bool) altedField.GetValue(eventData.Sender); // altGr
var isShifted = (bool)shiftedField.GetValue(eventData.Sender);
var isAlted = (bool)altedField.GetValue(eventData.Sender); // altGr

foreach (var key in eventData.KeyCode)
{
Expand Down Expand Up @@ -108,16 +110,29 @@ private static void ProcessKey(VirtualKeyCode key, KeyboardKey.VirtualKeyEventDa
case VirtualKeyCode.RETURN:
if (liveSendMode)
{
Logger.LogInfo($"Sending message: {_currentText.ReplaceShortcodes()} [^-^]");
Logger.LogInfo($"Sending message: {_currentText.ReplaceShortcodes()} [ls]");
_lastMsg = _currentText;
SendMessage(true);
ClearInput();
if (Core.IsTwitchSendingEnabled && !_isSilentMsg)
{
var affixes = Core.GetAffixes();
var currentText = _currentText.ReplaceShortcodes();
SendMessage(true);
Task.Run(() =>
{
Helix.SendTwitchMessage($"{affixes.Item1} {currentText} {affixes.Item2}");
ThreadingHelper.Instance.StartSyncInvoke(ClearInput);
});
}
else
{
SendMessage(true);
ClearInput();
}
}
else
{
Logger.LogInfo($"Sending message: {_currentText.ReplaceShortcodes()}");
SendMessage();
ClearInput();
}

return;
Expand Down Expand Up @@ -156,14 +171,22 @@ private static void SendMessage(bool liveSend = false)
if (liveSend)
{
_eventsTimer.Stop();
Tools.SendOsc("/chatbox/input", _currentText.ReplaceShortcodes(), true, !_isSilentMsg || _isFirstMsg);
Tools.SendOsc("/chatbox/input", _currentText.ReplaceShortcodes(), true, !_isSilentMsg);
SendTyping(false);
_isFirstMsg = false;
}
else
{
Tools.SendOsc("/chatbox/input", _currentText.ReplaceShortcodes(), true, !_isSilentMsg);
SendTyping(false);
if (Core.IsTwitchSendingEnabled && !_isSilentMsg)
{
var affixes = Core.GetAffixes();
var currentText = _currentText.ReplaceShortcodes();
Task.Run(() =>
Helix.SendTwitchMessage($"{affixes.Item1} {currentText} {affixes.Item2}"));
}

_lastMsg = _currentText;
ClearInput();
}
Expand All @@ -190,7 +213,7 @@ public static void Setup(TextMeshProUGUI barText, TextMeshProUGUI charCounter)
_charCounter = charCounter;
_eventsTimer.Elapsed += TimerElapsed;
var stickyKeysField = AccessTools.Field(typeof(KeyboardInputHandler), "CurrentlyDownStickyKeys");
_currentlyDownStickyKeys = (List<KeyboardKey>) stickyKeysField.GetValue(Plugin.Instance.inputHandler);
_currentlyDownStickyKeys = (List<KeyboardKey>)stickyKeysField.GetValue(Plugin.Instance.inputHandler);
}

private static void UpdateChatColor()
Expand All @@ -207,7 +230,7 @@ private static void UpdateChatColor()

private static void UpdateChatText(string text)
{
if (text.Length > 144)
if (text.Length > 144 && !Core.IsTwitchSendingEnabled)
{
text = text.Substring(0, 144);
}
Expand All @@ -222,16 +245,17 @@ private static string ReplaceShortcodes(this string input)
{
var shortcodes = new Dictionary<string, string>
{
{"//shrug", "¯\\_(ツ)_/¯"},
{"//happy", "(¬‿¬)"},
{"//table", "┬─┬"},
{"//music", "🎵"},
{"//cookie", "🍪"},
{"//star", ""},
{"//hrt", "💗"},
{"//2hrt", "💕"},
{"//skull", "💀"},
{"//skull2", ""},
{ "//shrug", "¯\\_(ツ)_/¯" },
{ "//happy", "(¬‿¬)" },
{ "//tflip", "┬─┬" },
{ "//music", "🎵" },
{ "//cookie", "🍪" },
{ "//star", "" },
{ "//hrt", "💗" },
{ "//hrt2", "💕" },
{ "//skull", "💀" },
{ "//skull2", "" },
{ "//rx3", "rawr x3" }
};

foreach (var shortcode in shortcodes)
Expand Down
55 changes: 30 additions & 25 deletions KeyboardOSC/KeyboardOSC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
</PropertyGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition=" '$(Configuration)' == 'Debug' ">
<Exec Command="taskkill /f /im XSOverlay.exe" IgnoreExitCode="true" IgnoreStandardErrorWarningFormat="true" ContinueOnError="true"/>
<Exec Command="taskkill /f /im &quot;XSOverlay Media Manager.exe&quot;" IgnoreExitCode="true" IgnoreStandardErrorWarningFormat="true" ContinueOnError="true"/>
<Exec Command="taskkill /f /im &quot;Vuplex WebView.vuplex&quot;" IgnoreExitCode="true" IgnoreStandardErrorWarningFormat="true" ContinueOnError="true"/>
<Exec Command="sleep 0.5"/>
<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>
Expand All @@ -31,33 +33,36 @@
</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>
<Reference Include="UnityEngine.CoreModule">
<HintPath>$(SolutionDir)refs\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.IMGUIModule">
<HintPath>$(SolutionDir)refs\UnityEngine.IMGUIModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>$(SolutionDir)refs\UnityEngine.UI.dll</HintPath>
</Reference>
<Reference Include="uOSC.Runtime">
<HintPath>$(SolutionDir)refs\uOSC.Runtime.dll</HintPath>
</Reference>
<EmbeddedResource Include="chat.png"/>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="chat.png"/>
<Reference Include="Assembly-CSharp">
<HintPath>..\refs\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Facepunch.Steamworks.Win64">
<HintPath>..\refs\Facepunch.Steamworks.Win64.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\refs\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http">
<HintPath>..\refs\System.Net.Http.dll</HintPath>
</Reference>
<Reference Include="Unity.TextMeshPro">
<HintPath>..\refs\Unity.TextMeshPro.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>..\refs\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.IMGUIModule">
<HintPath>..\refs\UnityEngine.IMGUIModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>..\refs\UnityEngine.UI.dll</HintPath>
</Reference>
<Reference Include="uOSC.Runtime">
<HintPath>..\refs\uOSC.Runtime.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
25 changes: 0 additions & 25 deletions KeyboardOSC/KeyboardOSC.sln

This file was deleted.

52 changes: 32 additions & 20 deletions KeyboardOSC/Patches.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using HarmonyLib;
using KeyboardOSC.Twitch;
using Steamworks;
using UnityEngine;
using WindowsInput;
using WindowsInput.Native;
using XSOverlay;
using XSOverlay.WebApp;
using XSOverlay.Websockets.API;

namespace KeyboardOSC;

Expand All @@ -13,9 +17,6 @@ public static class Patches
{
private static Harmony Harmony;

private static WindowAttachementManager.DeviceToAttachTo kbAttachedTo =
WindowAttachementManager.DeviceToAttachTo.None;

private static bool HasSettingsBeenOpenedOnce;

public static void PatchAll()
Expand Down Expand Up @@ -75,7 +76,7 @@ public static void PatchAll()
var setSettings = AccessTools.Method(typeof(XSettingsManager), nameof(XSettingsManager.SetSetting));
var setSettingsPatch = new HarmonyMethod(typeof(Patches).GetMethod(nameof(SetSettingPatch)));

var reqSettings = AccessTools.Method(typeof(ServerBridge), "OnRequestCurrentSettings");
var reqSettings = AccessTools.Method(typeof(ApiHandler), "OnRequestCurrentSettings");
var reqSettingsPatch = new HarmonyMethod(typeof(Patches).GetMethod(nameof(RequestSettingsPatch)));

Harmony.Patch(toggleAppSettings, postfix: settingsOverlayPatch);
Expand Down Expand Up @@ -115,25 +116,37 @@ public static void ScalePatch(float dist, Unity_Overlay activeOverlay, float Sta
public static void SettingsOverlayPatch()
{
if (!Plugin.ModifiedUiSuccess || HasSettingsBeenOpenedOnce) return;
Plugin.PluginLogger.LogInfo("Replacing settings page url!");
var globalSettings = Overlay_Manager.Instance.GlobalSettingsMenuOverlay;
var loadString =
$"http://localhost:{ExternalMessageHandler.Instance.Config.WebSocketPort + 1}/ui/SettingsKO.html";
Overlay_Manager.Instance.GlobalSettingsMenuOverlay.OverlayWebView._webView.WebView.LoadUrl(loadString);
$"http://localhost:{ExternalMessageHandler.Instance.Config.WebSocketPort + 1}/apps/_UI/Default/Settings/SettingsKO.html";
globalSettings.OverlayWebView._webView.WebView.LoadUrl(loadString);
HasSettingsBeenOpenedOnce = true;
}

public static void RequestSettingsPatch(string sender, string data)
{
// create new UiSettings instance
var pluginVersion = Plugin.AssemblyVersion;
if (SteamClient.IsValid && SteamApps.CurrentBetaName != null)
{
pluginVersion += $" — you're on the <strong>{SteamApps.CurrentBetaName}</strong> branch of XSOverlay! Check the plugin repo releases tab for beta plugin updates/fixes";
} else if (Tools.UpdateCheckResult.Key)
{
pluginVersion += $" — A newer version {Tools.UpdateCheckResult.Value} is available!";
}

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,
KBAttachmentIndex = (int)kbAttachedTo
KBTwitchSending = PluginSettings.GetSetting<bool>("TwitchSending").Value,
KBDisableAffixes = PluginSettings.GetSetting<bool>("DisableAffixes").Value,
KBVersion = pluginVersion,
};
var data2 = JsonUtility.ToJson(settings, true);
ServerBridge.Instance.SendMessage("UpdateSettings", data2, null, sender);
var data2 = JsonUtility.ToJson(settings, false);
ServerClientBridge.Instance.Api.SendMessage("UpdateSettings", data2, null, sender);
}

public static bool SetSettingPatch(string name, string value, string value1, bool sendAnalytics = false)
Expand All @@ -155,24 +168,23 @@ public static bool SetSettingPatch(string name, string value, string value1, boo
case "KBTypingIndicator":
PluginSettings.SetSetting<bool>("TypingIndicator", value);
break;
case "KBTwitchSending":
PluginSettings.SetSetting<bool>("TwitchSending", value);
break;
case "KBDisableAffixes":
PluginSettings.SetSetting<bool>("DisableAffixes", value);
break;
case "KBOpenRepo":
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;
}

if (name.StartsWith("Twitch"))
Core.SettingsCallback(name, value);

return true;
}
Expand Down
Loading

0 comments on commit 8ae3d83

Please sign in to comment.