-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/xAstroBoy/lc-hax
- Loading branch information
Showing
3 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = ""; | ||
} | ||
} |