Compare commits
20 Commits
v4.0.3
...
feat/trans
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a0d1386712 | ||
|
|
ab960fc38b | ||
|
|
a40a605c37 | ||
|
|
b19f906216 | ||
|
|
3ecb7fb78b | ||
|
|
4e8931caba | ||
|
|
3adcdc46ba | ||
|
|
b6edc70594 | ||
| 9e7fb4d443 | |||
| 6ab8c38109 | |||
| 9a5d149241 | |||
|
|
f193d8a805 | ||
|
|
00960eb3f7 | ||
|
|
bc2d44f5cd | ||
|
|
c065b14f9d | ||
|
|
46f05b5489 | ||
|
|
3a9e903044 | ||
|
|
ca331d4ac8 | ||
|
|
692fc25d42 | ||
|
|
bec55e4ecc |
@@ -21,6 +21,11 @@ jobs:
|
||||
|
||||
- name: Restore dependencies
|
||||
run: dotnet restore
|
||||
# 直接加代理得了
|
||||
env:
|
||||
http_proxy: "http://172.17.0.1:7890"
|
||||
https_proxy: "http://172.17.0.1:7890"
|
||||
no_proxy: "localhost,127.0.0.1,*.lan"
|
||||
|
||||
- name: Build
|
||||
run: dotnet build --no-restore --configuration Release
|
||||
|
||||
@@ -41,7 +41,12 @@ public static class DefaultWidgets
|
||||
if (PlayerManager.ShowNameToggleButton.Value)
|
||||
RegisterManager.RegisterPlayerRow(InternalWidgets.NameToggleButton.Create());
|
||||
|
||||
if (PlayerManager.ShowTransButton.Value)
|
||||
RegisterManager.RegisterPlayerRow(InternalWidgets.TransButton.Create());
|
||||
|
||||
if (PlayerManager.ShowMuteButton.Value)
|
||||
RegisterManager.RegisterPlayerRow(InternalWidgets.MuteButton.Create());
|
||||
if (PlayerManager.ShowAddFriendButton.Value)
|
||||
RegisterManager.RegisterPlayerRow(InternalWidgets.AddFriendButton.Create());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,9 @@ public static class GUIStyles
|
||||
/// <summary>普通按钮样式(fontSize=22, richText=false)</summary>
|
||||
public static GUIStyle Button;
|
||||
|
||||
/// <summary>被按过的按钮样式,用于标识已经进入过的房间(fontSize=22)</summary>
|
||||
public static GUIStyle ButtonPressed;
|
||||
|
||||
/// <summary>黄色按钮样式(已记录玩家)</summary>
|
||||
public static GUIStyle YellowButton;
|
||||
|
||||
@@ -35,6 +38,8 @@ public static class GUIStyles
|
||||
|
||||
Label = new GUIStyle(GUI.skin.label) { fontSize = 22 };
|
||||
Button = new GUIStyle(GUI.skin.button) { fontSize = 22, richText = false };
|
||||
ButtonPressed = new GUIStyle(GUI.skin.button) { fontSize = 22, richText = false };
|
||||
ButtonPressed.normal.textColor = Color.grey;
|
||||
|
||||
YellowButton = new GUIStyle(GUI.skin.button) { fontSize = 22, richText = false };
|
||||
YellowButton.normal.textColor = Color.yellow;
|
||||
|
||||
26
Gui/InternalWidgets/AddFriendButton.cs
Normal file
26
Gui/InternalWidgets/AddFriendButton.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using Steamworks;
|
||||
using UnityEngine;
|
||||
using stick.plugins.playermanager.Recorder;
|
||||
|
||||
namespace stick.plugins.playermanager.Gui.InternalWidgets;
|
||||
|
||||
public static class AddFriendButton
|
||||
{
|
||||
public static IPlayerRowWidget Create()
|
||||
{
|
||||
return new PlayerRowButtonWidget
|
||||
{
|
||||
Name = "Add Friend",
|
||||
GetText = player => "加好友",
|
||||
Condition = player =>
|
||||
!PlayerManager.IsLocalPlayer(player)
|
||||
&& !player.IsFriend,
|
||||
OnClick = player =>
|
||||
{
|
||||
GUIUtility.systemCopyBuffer = player.ToString();
|
||||
SteamFriends.ActivateGameOverlayToUser("friendadd", player.SteamId);
|
||||
},
|
||||
Width = 100f,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -9,11 +9,9 @@ public static class MuteButton
|
||||
return new PlayerRowButtonWidget
|
||||
{
|
||||
Name = "mute",
|
||||
Condition = player =>
|
||||
!PlayerManager.IsHost(player)
|
||||
&& !PlayerManager.IsLocalPlayer(player),
|
||||
Condition = player => !PlayerManager.IsLocalPlayer(player),
|
||||
GetText = player =>
|
||||
PlayerManager.IsMuted(player) ? "取消禁音" : "禁音",
|
||||
PlayerManager.IsMuted(player) ? "取消静音" : "静音",
|
||||
OnClick = player =>
|
||||
{
|
||||
if (PlayerManager.IsMuted(player))
|
||||
|
||||
21
Gui/InternalWidgets/TransButton.cs
Normal file
21
Gui/InternalWidgets/TransButton.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using MultiplayerBasicExample;
|
||||
|
||||
namespace stick.plugins.playermanager.Gui.InternalWidgets;
|
||||
|
||||
public static class TransButton
|
||||
{
|
||||
public static IPlayerRowWidget Create()
|
||||
{
|
||||
return new PlayerRowButtonWidget
|
||||
{
|
||||
Name = "Trans Host",
|
||||
Condition = player =>
|
||||
PlayerManager.IsHost(PlayerManager.LocalPlayer)
|
||||
&& !PlayerManager.IsLocalPlayer(player),
|
||||
GetText = _ => "转让",
|
||||
OnClick = player =>
|
||||
PlayerManager.TransferLobbyOwnership(player),
|
||||
Width = 100f,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,7 @@ public static class PlayerManagerGUI
|
||||
if (PlayerManager.MatchmakingHandler.IsInsideLobby)
|
||||
{
|
||||
DrawCurrentLobbyInfo();
|
||||
DrawLobbySearchInfo();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -99,6 +100,8 @@ public static class PlayerManagerGUI
|
||||
{
|
||||
if (widget.ShouldDraw(member))
|
||||
widget.Draw(Cursor.NextColumn(widget.Width, 40f), member);
|
||||
else
|
||||
Cursor.NextColumn(widget.Width, 40f); // 占位推进列位置
|
||||
}
|
||||
Cursor.EndRow();
|
||||
}
|
||||
@@ -187,15 +190,23 @@ public static class PlayerManagerGUI
|
||||
for (int i = 0; i < PlayerManager.lobbyDataList.Count; i++)
|
||||
{
|
||||
CSteamID lobbyId = PlayerManager.lobbyDataList[i];
|
||||
var style = PlayerManager.enteredLobbyList.Contains(lobbyId) ? GUIStyles.ButtonPressed : GUIStyles.Button;
|
||||
|
||||
if (GUI.Button(
|
||||
new Rect(Cursor.OffsetX, Cursor.LineHeight * i, 500f, 40f),
|
||||
$"{lobbyId} 人数{SteamMatchmaking.GetNumLobbyMembers(lobbyId)}",
|
||||
GUIStyles.Button
|
||||
style
|
||||
))
|
||||
{
|
||||
// 在大厅中则不加入
|
||||
if (!PlayerManager.MatchmakingHandler.IsInsideLobby)
|
||||
{
|
||||
// 记录一下加入过的状态
|
||||
PlayerManager.enteredLobbyList.Add(lobbyId);
|
||||
PlayerManager.JoinSpecificServer(lobbyId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GUI.EndScrollView();
|
||||
}
|
||||
|
||||
22
Patches/DistanceFilterPatch.cs
Normal file
22
Patches/DistanceFilterPatch.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System.Reflection.Emit;
|
||||
using System.Collections.Generic;
|
||||
using HarmonyLib;
|
||||
using stick.plugins.playermanager;
|
||||
|
||||
[HarmonyPatch(typeof(MatchmakingHandler), "OnRandomServerJoinFailed")]
|
||||
class DistanceFilterPatch
|
||||
{
|
||||
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
|
||||
{
|
||||
return new CodeMatcher(instructions)
|
||||
.MatchForward(false,
|
||||
new CodeMatch(OpCodes.Ldc_I4_1),
|
||||
new CodeMatch(OpCodes.Stloc_0)
|
||||
)
|
||||
.SetInstruction(
|
||||
new CodeInstruction(OpCodes.Ldsfld,
|
||||
AccessTools.Field(typeof(PlayerManager), nameof(PlayerManager.lobbyDistanceFilter))))
|
||||
.InstructionEnumeration();
|
||||
}
|
||||
}
|
||||
|
||||
15
Patches/MutePatch.cs
Normal file
15
Patches/MutePatch.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using HarmonyLib;
|
||||
using stick.plugins.playermanager;
|
||||
|
||||
[HarmonyPatch(typeof(NetworkPlayer), "SyncClientChat")]
|
||||
class MutePatch
|
||||
{
|
||||
public static bool Prefix(NetworkPlayer __instance)
|
||||
{
|
||||
if (PlayerManager.MutedPlayers.Contains(__instance.NetworkSpawnID))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
80
Plugin.cs
80
Plugin.cs
@@ -39,6 +39,11 @@ public class PlayerManager : BaseUnityPlugin
|
||||
/// </summary>
|
||||
internal static ConfigEntry<bool> ShowKickButton;
|
||||
|
||||
/// <summary>
|
||||
/// 是否显示转让按钮
|
||||
/// </summary>
|
||||
internal static ConfigEntry<bool> ShowTransButton;
|
||||
|
||||
/// <summary>
|
||||
/// 是否显示记录/拉黑按钮
|
||||
/// </summary>
|
||||
@@ -64,6 +69,11 @@ public class PlayerManager : BaseUnityPlugin
|
||||
/// </summary>
|
||||
internal static ConfigEntry<bool> ShowMuteButton;
|
||||
|
||||
/// <summary>
|
||||
/// 是否显示加好友按钮
|
||||
/// </summary>
|
||||
internal static ConfigEntry<bool> ShowAddFriendButton;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Steam回调
|
||||
@@ -97,6 +107,11 @@ public class PlayerManager : BaseUnityPlugin
|
||||
/// </summary>
|
||||
public static List<CSteamID> lobbyDataList = [];
|
||||
|
||||
/// <summary>
|
||||
/// 进入过的大厅列表
|
||||
/// </summary>
|
||||
public static HashSet<CSteamID> enteredLobbyList = [];
|
||||
|
||||
/// <summary>
|
||||
/// 大厅距离过滤设置
|
||||
/// </summary>
|
||||
@@ -111,6 +126,11 @@ public class PlayerManager : BaseUnityPlugin
|
||||
|
||||
#region 快捷访问属性
|
||||
|
||||
/// <summary>
|
||||
/// 多人管理器实例
|
||||
/// </summary>
|
||||
public static MultiplayerManager MultiplayerManager => FindObjectOfType<MultiplayerManager>();
|
||||
|
||||
/// <summary>
|
||||
/// 大厅管理器实例
|
||||
/// </summary>
|
||||
@@ -164,7 +184,7 @@ public class PlayerManager : BaseUnityPlugin
|
||||
/// <summary>
|
||||
/// 禁音玩家列表
|
||||
/// </summary>
|
||||
public static HashSet<PlayerInfo> MutedPlayers = [];
|
||||
public static HashSet<ushort> MutedPlayers = [];
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -185,7 +205,7 @@ public class PlayerManager : BaseUnityPlugin
|
||||
private void Update()
|
||||
{
|
||||
HandleInput();
|
||||
if (SteamManager.Initialized)
|
||||
if (SteamManager.Initialized && LocalPlayer is null)
|
||||
{
|
||||
LocalPlayer = new(SteamUser.GetSteamID());
|
||||
}
|
||||
@@ -229,6 +249,13 @@ public class PlayerManager : BaseUnityPlugin
|
||||
"是否显示踢人按钮"
|
||||
);
|
||||
|
||||
ShowTransButton = Config.Bind(
|
||||
"GUI",
|
||||
"ShowTransButton",
|
||||
true,
|
||||
"是否显示转让按钮"
|
||||
);
|
||||
|
||||
ShowRecordButton = Config.Bind(
|
||||
"GUI",
|
||||
"ShowRecordButton",
|
||||
@@ -263,6 +290,13 @@ public class PlayerManager : BaseUnityPlugin
|
||||
true,
|
||||
"是否显示切换公开性按钮"
|
||||
);
|
||||
|
||||
ShowAddFriendButton = Config.Bind(
|
||||
"GUI",
|
||||
"ShowAddFriendButton",
|
||||
true,
|
||||
"是否显示加好友按钮"
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -276,6 +310,8 @@ public class PlayerManager : BaseUnityPlugin
|
||||
}
|
||||
Harmony.CreateAndPatchAll(typeof(ApplyBlacklist));
|
||||
Harmony.CreateAndPatchAll(typeof(ListenForChange));
|
||||
Harmony.CreateAndPatchAll(typeof(MutePatch));
|
||||
Harmony.CreateAndPatchAll(typeof(DistanceFilterPatch));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -310,6 +346,37 @@ public class PlayerManager : BaseUnityPlugin
|
||||
|
||||
#region 公共方法
|
||||
|
||||
/// <summary>
|
||||
/// 转让房主
|
||||
/// </summary>
|
||||
/// <param name="targetPlayer">目标玩家</param>
|
||||
/// <returns></returns>
|
||||
public static void TransferLobbyOwnership(PlayerInfo targetPlayer)
|
||||
{
|
||||
if (targetPlayer != null && targetPlayer != LocalPlayer)
|
||||
{
|
||||
SteamMatchmaking.SetLobbyOwner(CurrentLobbyID, targetPlayer.SteamId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过SteamID获取NetworkSpawnID
|
||||
/// </summary>
|
||||
/// <param name="targetSteamID"></param>
|
||||
/// <returns></returns>
|
||||
public static ushort GetNetworkSpawnIDBySteamID(CSteamID targetSteamID)
|
||||
{
|
||||
ConnectedClientData[] clients = MultiplayerManager.ConnectedClients;
|
||||
for (ushort i = 0; i < clients.Length; i++)
|
||||
{
|
||||
if (clients[i] != null && clients[i].ClientID == targetSteamID)
|
||||
{
|
||||
return i; // i 就是 NetworkSpawnID
|
||||
}
|
||||
}
|
||||
return 65535; // ushort.MaxValue,表示未找到(与默认值一致)
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断指定玩家是否被静音
|
||||
/// </summary>
|
||||
@@ -317,7 +384,7 @@ public class PlayerManager : BaseUnityPlugin
|
||||
/// <returns>如果被静音返回true</returns>
|
||||
public static bool IsMuted(PlayerInfo player)
|
||||
{
|
||||
return player != null && MutedPlayers.Contains(player);
|
||||
return player != null && MutedPlayers.Contains(player.NetworkSpawnID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -328,7 +395,7 @@ public class PlayerManager : BaseUnityPlugin
|
||||
{
|
||||
if (player != null)
|
||||
{
|
||||
MutedPlayers.Add(player);
|
||||
MutedPlayers.Add(player.NetworkSpawnID);
|
||||
Debug.Log($"玩家 {player} 已被静音");
|
||||
}
|
||||
}
|
||||
@@ -339,9 +406,9 @@ public class PlayerManager : BaseUnityPlugin
|
||||
/// <param name="player">要取消静音的玩家</param>
|
||||
public static void UnmutePlayer(PlayerInfo player)
|
||||
{
|
||||
if (player != null && MutedPlayers.Contains(player))
|
||||
if (player != null && MutedPlayers.Contains(player.NetworkSpawnID))
|
||||
{
|
||||
MutedPlayers.Remove(player);
|
||||
MutedPlayers.Remove(player.NetworkSpawnID);
|
||||
Debug.Log($"玩家 {player} 已被取消静音");
|
||||
}
|
||||
}
|
||||
@@ -397,6 +464,7 @@ public class PlayerManager : BaseUnityPlugin
|
||||
{
|
||||
Debug.Log("大厅列表请求完成: " + result.m_nLobbiesMatching + " 个大厅");
|
||||
lobbyDataList = [];
|
||||
enteredLobbyList = [];
|
||||
uint lobbyCount = result.m_nLobbiesMatching;
|
||||
|
||||
for (uint i = 0; i < lobbyCount; i++)
|
||||
|
||||
@@ -43,6 +43,12 @@ public class PlayerInfo : IEquatable<PlayerInfo>
|
||||
/// </summary>
|
||||
public PlayerRecordStatus RecordStatus { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 柴自己的NetworkSpawnID
|
||||
/// </summary>
|
||||
public ushort NetworkSpawnID => PlayerManager.GetNetworkSpawnIDBySteamID(SteamId);
|
||||
|
||||
/// <summary>
|
||||
/// 当前玩家名称(实时获取)
|
||||
/// </summary>
|
||||
|
||||
34
readme.md
34
readme.md
@@ -6,7 +6,6 @@
|
||||
|
||||
- 房间查找
|
||||
- 玩家记录
|
||||
|
||||
- 被记录的玩家显示为黄名
|
||||
- 是steam好友的玩家显示为绿名(优先级更高)
|
||||
- 被拉黑的玩家显示为红名(优先级最高)
|
||||
@@ -16,16 +15,41 @@
|
||||
- 可配置的界面开启按键,默认为F2
|
||||
- 可以随时切换房间的公开性
|
||||
- 静音单个玩家
|
||||
- 一键加好友
|
||||
|
||||
## 作者
|
||||
|
||||
老狼老狼几点钟、Moncak、z7572
|
||||
|
||||
## 更新日志
|
||||
|
||||
### v4.0.7
|
||||
|
||||
1. 现在点击大厅列表中的按钮进入大厅会在列表中将该大厅用灰色样式标识,标记已进入过
|
||||
2. 现在不会在每帧都初始化一遍LocalPlayer *难道他真的是猪??*
|
||||
|
||||
### v4.0.6
|
||||
|
||||
1. 大厅搜索范围按钮现在可同步修改快速匹配的搜索范围
|
||||
2. 修复了禁音功能 *难道他真的是猪??*
|
||||
|
||||
### v4.0.5
|
||||
|
||||
1. 修复了加好友按钮始终不显示的问题 *难道他真的是猪??*
|
||||
|
||||
### v4.0.4
|
||||
|
||||
1. 房间列表现在在房间内也显示,但是点击无效
|
||||
2. 添加了加好友按钮
|
||||
3. 修复了禁音功能 *难道他真的是猪??*
|
||||
|
||||
### v4.0.3
|
||||
|
||||
1. 静音单个玩家
|
||||
1. 性能优化
|
||||
1. 提供了更多可选是否开启功能显示的配置项
|
||||
1. 提供按钮组件注册入口
|
||||
1. 更好的房间公开性切换
|
||||
2. 性能优化
|
||||
3. 提供了更多可选是否开启功能显示的配置项
|
||||
4. 提供按钮组件注册入口
|
||||
5. 更好的房间公开性切换
|
||||
|
||||
### v3.1.1
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<TargetFramework>net35</TargetFramework>
|
||||
<AssemblyName>stick.plugins.playermanager</AssemblyName>
|
||||
<Product>PlayerManager</Product>
|
||||
<Version>4.0.3</Version>
|
||||
<Version>4.0.7</Version>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<RestoreAdditionalProjectSources>
|
||||
|
||||
Reference in New Issue
Block a user