Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/xAstroBoy/lc-hax
Browse files Browse the repository at this point in the history
  • Loading branch information
xAstroBoy committed Feb 4, 2024
2 parents 4fec919 + 061b6ef commit 65a2555
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ The complete feature set includes the following.
| Turn invisible to players | `/invis` |
| Clear the chat for everyone | `/clear` |
| Toggle ship lights | `/light` |
| Copy lobby ID to clipboard | `/lobby` |

## Privileged Commands

Expand Down Expand Up @@ -178,6 +179,7 @@ These commands are only available when the user is in superuser mode.
| Toggle possession NoClip | <kbd> N </kbd> |
| Toggle Anti-Kick | <kbd> \ </kbd> |
| Disconnect from server | <kbd> Shift </kbd> + <kbd> F4 </kbd> |
| Connect to server | <kbd> Shift </kbd> + <kbd> F5 </kbd> |

### TriggerMod

Expand Down
10 changes: 10 additions & 0 deletions lc-hax/Scripts/Commands/LobbyCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Hax;
using UnityEngine;

[Command("/lobby")]
public class LobbyCommand : ICommand {
public void Execute(StringArray _) {
Chat.Print($"The lobby ID {Setting.ConnectedLobbyId} has been copied!");
GUIUtility.systemCopyBuffer = Setting.ConnectedLobbyId.ToString();
}
}
28 changes: 27 additions & 1 deletion lc-hax/Scripts/Modules/DisconnectMod.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,51 @@
using Hax;
using System.Text.RegularExpressions;
using UnityEngine;
using Steamworks;
using Hax;

public sealed class DisconnectMod : MonoBehaviour {
bool IsShiftHeld { get; set; } = false;

void OnEnable() {
InputListener.onShiftButtonHold += this.HoldShift;
InputListener.onF4Press += this.TryToDisconnect;
InputListener.onF5Press += this.TryToConnect;
}

void OnDisable() {
InputListener.onShiftButtonHold -= this.HoldShift;
InputListener.onF4Press -= this.TryToDisconnect;
InputListener.onF5Press -= this.TryToConnect;
}

void HoldShift(bool isHeld) => this.IsShiftHeld = isHeld;

SteamId? GetSteamIdFromClipboard() {
string clipboardText = GUIUtility.systemCopyBuffer;

return !string.IsNullOrWhiteSpace(clipboardText) && Regex.IsMatch(clipboardText, @"^\d{17}$")
? new SteamId { Value = ulong.Parse(clipboardText) }
: null;
}

void TryToDisconnect() {
if (!this.IsShiftHeld) return;
if (Helper.LocalPlayer is null) return;

GameNetworkManager.Instance.Disconnect();
Setting.DisconnectedVoluntarily = true;
}

void TryToConnect() {
if (!this.IsShiftHeld) return;

SteamId? steamId = this.GetSteamIdFromClipboard() ?? Setting.ConnectedLobbyId;

if (steamId is not SteamId lobbyId) {
return;
}

GameNetworkManager.Instance.StartClient(lobbyId);
GUIUtility.systemCopyBuffer = "";
}
}

0 comments on commit 65a2555

Please sign in to comment.