From bc090cd8d1991615bfe29e0695c32b4220f04927 Mon Sep 17 00:00:00 2001 From: "1992414357@qq.com" <1992414357@qq.com> Date: Sun, 22 Jun 2025 03:26:55 +0800 Subject: Update Csharp Bindings --- .../NoGamepads_Core/Data/LoggerManagement.cs | 2 +- .../NoGamepads_Core/Runtime/ControllerRuntime.cs | 8 ++++++ .../NoGamepads_Core/Runtime/GameRuntime.cs | 18 ++++++++++--- .../NoGamepads_Core/Services/Tcp/PadTcpClient.cs | 7 +++-- .../NoGamepads_Core/Services/Tcp/PadTcpServer.cs | 7 +++-- .../NoGamepads_Example/Program.cs | 31 ++++++++++++++++++---- 6 files changed, 60 insertions(+), 13 deletions(-) diff --git a/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/LoggerManagement.cs b/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/LoggerManagement.cs index f1d2bd9..0d0ccc1 100644 --- a/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/LoggerManagement.cs +++ b/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Data/LoggerManagement.cs @@ -4,7 +4,7 @@ namespace NoGamepads_Core.Data; public static class LoggerManagement { - public static void EnableLogger(int level) + public static void EnableLogger(int level = 0) { nogamepads_data.EnableLogger((byte) level); } diff --git a/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Runtime/ControllerRuntime.cs b/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Runtime/ControllerRuntime.cs index da3a266..264ab73 100644 --- a/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Runtime/ControllerRuntime.cs +++ b/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Runtime/ControllerRuntime.cs @@ -18,6 +18,7 @@ public class ControllerRuntime : IRustDataBorrow, IRustDat { get { + if (IsUsed()) return GameMessage.End(); var result = nogamepads_data.ControllerRuntimePop(_ffi); return result == null ? GameMessage.Error() : GameMessage.From(result); } @@ -25,36 +26,43 @@ public class ControllerRuntime : IRustDataBorrow, IRustDat public void Close() { + if (IsUsed()) return; nogamepads_data.ControllerRuntimeClose(_ffi); } public void Press(int key) { + if (IsUsed()) return; nogamepads_data.ControllerRuntimePressAButton(_ffi, (byte)key); } public void Release(int key) { + if (IsUsed()) return; nogamepads_data.ControllerRuntimeReleaseAButton(_ffi, (byte)key); } public void ChangeAxis(int key, float axis) { + if (IsUsed()) return; nogamepads_data.ControllerRuntimeChangeAxis(_ffi, (byte)key, axis); } public void ChangeDirection(int key, float x, float y) { + if (IsUsed()) return; nogamepads_data.ControllerRuntimeChangeDirection(_ffi, (byte)key, x, y); } public void SendText(string message) { + if (IsUsed()) return; nogamepads_data.ControllerRuntimeSendTextMessage(_ffi, message); } public void Send(ControlMessage message) { + if (IsUsed()) return; nogamepads_data.ControllerRuntimeSendMessage(_ffi, message.Convert()); } diff --git a/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Runtime/GameRuntime.cs b/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Runtime/GameRuntime.cs index 5bef52a..986b4ab 100644 --- a/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Runtime/GameRuntime.cs +++ b/core/bindings/lang/csharp/NoGamepads_CharpBindings/NoGamepads_Core/Runtime/GameRuntime.cs @@ -44,34 +44,40 @@ public class GameRuntime : IRustDataBorrow, IRustDataUse, IRustDataUse, IRustDataUse OnlinePlayers => nogamepads_data.GameRuntimeGetOnlineList(_ffi).ToPlayerList(); + public List? OnlinePlayers => IsUsed() ? null : nogamepads_data.GameRuntimeGetOnlineList(_ffi).ToPlayerList(); - public List BannedPlayers => nogamepads_data.GameRuntimeGetBannedList(_ffi).ToPlayerList(); + public List? BannedPlayers => IsUsed() ? null : nogamepads_data.GameRuntimeGetBannedList(_ffi).ToPlayerList(); #endregion #region Message Management - public ControlEvent RecentEvent => new(nogamepads_data.GameRuntimePopControlEvent(_ffi)); + public ControlEvent? RecentEvent => IsUsed() ? null : new(nogamepads_data.GameRuntimePopControlEvent(_ffi)); public void SendText(string message, Player player, ServiceType type = ServiceType.Unknown) { + if (IsUsed()) return; var serviceType = type == ServiceType.Unknown ? GetServiceType(player) : type; nogamepads_data.GameRuntimeSendTextMessage(_ffi, player.Borrow(), serviceType.Convert(), message); } public void Send(GameMessage message, Player player, ServiceType type = ServiceType.Unknown) { + if (IsUsed()) return; var serviceType = type == ServiceType.Unknown ? GetServiceType(player) : type; nogamepads_data.GameRuntimeSendMessageTo(_ffi, player.Borrow(), message.Convert(), serviceType.Convert()); } @@ -118,6 +127,7 @@ public class GameRuntime : IRustDataBorrow, IRustDataUse, IRustDataUse, IRustDataUse + { + new PadTcpClient(runtime) + .SetAddressV4() + .Connect(); + }); + + var threadRuntime = new Thread(() => + { + while (true) + { + var recent = runtime.RecentMessage; + + if (recent.MessageTag == GameMessage.Tag.End) + break; + + if (recent.MessageTag != GameMessage.Tag.Error) + Console.WriteLine(recent); + } + Console.WriteLine("\nPress any key to continue..."); + }); + + threadService.Start(); + threadRuntime.Start(); } } \ No newline at end of file -- cgit From bc824a6209d72e6366b5c390c5b6cc68aad6e094 Mon Sep 17 00:00:00 2001 From: "1992414357@qq.com" <1992414357@qq.com> Date: Sun, 22 Jun 2025 03:27:54 +0800 Subject: Add some trace! macros to game_runtime.rs, controller_runtime.rs --- core/src/service/tcp_network/pad_client/pad_client_service.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/service/tcp_network/pad_client/pad_client_service.rs b/core/src/service/tcp_network/pad_client/pad_client_service.rs index 9b1826b..fe3da29 100644 --- a/core/src/service/tcp_network/pad_client/pad_client_service.rs +++ b/core/src/service/tcp_network/pad_client/pad_client_service.rs @@ -85,8 +85,6 @@ impl PadClientNetwork { pub fn connect(self) { let runtime = build_tokio_runtime("padclient_tcp".to_string()); - - info!("[TCP Client] Connecting to {}:{}", self.addr.ip().to_string(), self.addr.port()); runtime.block_on(self.build_entry()); } } @@ -94,6 +92,8 @@ impl PadClientNetwork { impl PadClientNetwork { async fn connection_thread(self: Arc) { + info!("[TCP Client] Connecting to {}:{}", self.addr.ip().to_string(), self.addr.port()); + let mut buffer = [0; 1024]; // Requests game infos -- cgit