Skip to content

Commit

Permalink
Implement chat command prefix config
Browse files Browse the repository at this point in the history
  • Loading branch information
MrBlue committed Dec 5, 2023
1 parent f5eaa19 commit ec02440
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 33 deletions.
34 changes: 5 additions & 29 deletions resources/Rust.opj
Original file line number Diff line number Diff line change
Expand Up @@ -19014,30 +19014,7 @@
{
"Type": "Simple",
"Hook": {
"InjectionIndex": 86,
"ReturnBehavior": 0,
"ArgumentBehavior": 4,
"ArgumentString": "this.player, this.message",
"HookTypeName": "Simple",
"Name": "IOnPlayerCommand",
"HookName": "IOnPlayerCommand",
"AssemblyName": "Assembly-CSharp.dll",
"TypeName": "ConVar.Chat/<sayAs>d__18",
"Flagged": false,
"Signature": {
"Exposure": 0,
"Name": "MoveNext",
"ReturnType": "System.Void",
"Parameters": []
},
"MSILHash": "iYnKlc55a6+MPJFdD5TPPrlc3MCC9S8TqbfO9DTb0xQ=",
"HookCategory": "Player"
}
},
{
"Type": "Simple",
"Hook": {
"InjectionIndex": 101,
"InjectionIndex": 76,
"ReturnBehavior": 3,
"ArgumentBehavior": 4,
"ArgumentString": "this.userId, this.username, this.<strChatText>5__2, this.targetChannel, this.player => l1",
Expand All @@ -19054,20 +19031,19 @@
"Parameters": []
},
"MSILHash": "iYnKlc55a6+MPJFdD5TPPrlc3MCC9S8TqbfO9DTb0xQ=",
"BaseHookName": "IOnPlayerCommand",
"HookCategory": "Player"
}
},
{
"Type": "Modify",
"Hook": {
"InjectionIndex": 123,
"InjectionIndex": 98,
"RemoveCount": 0,
"Instructions": [
{
"OpCode": "leave",
"OpType": "Instruction",
"Operand": 810
"Operand": 803
}
],
"HookTypeName": "Modify",
Expand All @@ -19090,13 +19066,13 @@
{
"Type": "Modify",
"Hook": {
"InjectionIndex": 119,
"InjectionIndex": 94,
"RemoveCount": 1,
"Instructions": [
{
"OpCode": "beq_s",
"OpType": "Instruction",
"Operand": 124
"Operand": 99
}
],
"HookTypeName": "Modify",
Expand Down
17 changes: 13 additions & 4 deletions src/RustHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,16 @@ private object IOnPlayerChat(ulong playerId, string playerName, string message,
return true;
}

// Check if chat command
string chatCommandPrefix = CommandHandler.GetChatCommandPrefix(message);
if ( chatCommandPrefix != null )
{
TryRunPlayerCommand( basePlayer, message.Substring( chatCommandPrefix.Length ) );
return false;
}

message = message.EscapeRichText();

// Check if using Rust+ app
if (basePlayer == null || !basePlayer.IsConnected)
{
Expand All @@ -305,8 +315,7 @@ private object IOnPlayerChat(ulong playerId, string playerName, string message,
/// <param name="basePlayer"></param>
/// <param name="message"></param>
/// <returns></returns>
[HookMethod("IOnPlayerCommand")]
private void IOnPlayerCommand(BasePlayer basePlayer, string message)
private void TryRunPlayerCommand(BasePlayer basePlayer, string message)
{
if (basePlayer == null)
{
Expand All @@ -316,13 +325,13 @@ private void IOnPlayerCommand(BasePlayer basePlayer, string message)
string str = message.Replace("\n", "").Replace("\r", "").Trim();

// Check if it is a chat command
if (string.IsNullOrEmpty(str) || str[0] != '/' || str.Length <= 1)
if (string.IsNullOrEmpty(str))
{
return;
}

// Parse the command
ParseCommand(str.TrimStart('/'), out string cmd, out string[] args);
ParseCommand(str, out string cmd, out string[] args);
if (cmd == null)
{
return;
Expand Down

0 comments on commit ec02440

Please sign in to comment.