mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 14:29:25 +00:00
[ChatBoxExtensions] Updated for the latest API.
This commit is contained in:
parent
62eb612d73
commit
37ad5a8f9c
9 changed files with 88 additions and 40 deletions
|
@ -1,2 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project Sdk="Microsoft.NET.Sdk"/>
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<!-- Didn't put in the Directory.Build.props because it spams funny warnings... -->
|
||||
<ItemGroup>
|
||||
<Reference Include="ml_prm">
|
||||
<HintPath>$(MsBuildThisFileDirectory)\..\_ManagedLibs\ml_prm.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -10,22 +10,22 @@ internal class ChatBoxCommands : CommandBase
|
|||
DateTime pingTime = DateTime.MinValue; // store the time when "ping" command was sent
|
||||
|
||||
Commands.RegisterCommand("ping",
|
||||
onCommandSent: (message, sound) =>
|
||||
onCommandSent: (message, sound, displayMsg) =>
|
||||
{
|
||||
pingTime = DateTime.Now;
|
||||
awaitingPing = true;
|
||||
},
|
||||
onCommandReceived: (sender, message, sound) =>
|
||||
onCommandReceived: (sender, message, sound, displayMsg) =>
|
||||
{
|
||||
RemoteCommandListenForSelf(message, args =>
|
||||
{
|
||||
ChatBox.SendMessage("/pong " + GetPlayerUsername(sender), false);
|
||||
API.SendMessage("/pong " + GetPlayerUsername(sender), false, true);
|
||||
});
|
||||
});
|
||||
|
||||
Commands.RegisterCommand("pong",
|
||||
onCommandSent: null,
|
||||
onCommandReceived: (sender, message, sound) =>
|
||||
onCommandReceived: (sender, message, sound, displayMsg) =>
|
||||
{
|
||||
RemoteCommandListenForSelf(message, args =>
|
||||
{
|
||||
|
@ -33,11 +33,11 @@ internal class ChatBoxCommands : CommandBase
|
|||
{
|
||||
awaitingPing = false;
|
||||
TimeSpan timeSincePing = DateTime.Now - pingTime; // calculate the time difference
|
||||
ChatBox.SendMessage($"Time since ping: {timeSincePing.TotalMilliseconds}ms", false);
|
||||
API.SendMessage($"Time since ping: {timeSincePing.TotalMilliseconds}ms", false, true);
|
||||
return;
|
||||
}
|
||||
ChatBox.SendMessage($"You have to ping first, {GetPlayerUsername(sender)}!", false);
|
||||
API.SendMessage($"You have to ping first, {GetPlayerUsername(sender)}!", false, true);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,14 +9,14 @@ internal class ChilloutVRBaseCommands : CommandBase
|
|||
public static void RegisterCommands()
|
||||
{
|
||||
Commands.RegisterCommand("respawn",
|
||||
onCommandSent: (message, sound) =>
|
||||
onCommandSent: (message, sound, displayMsg) =>
|
||||
{
|
||||
LocalCommandIgnoreOthers(message, args =>
|
||||
{
|
||||
RootLogic.Instance.Respawn();
|
||||
});
|
||||
},
|
||||
onCommandReceived: (sender, message, sound) =>
|
||||
onCommandReceived: (sender, message, sound, displayMsg) =>
|
||||
{
|
||||
RemoteCommandListenForAll(message, (args) =>
|
||||
{
|
||||
|
@ -25,14 +25,14 @@ internal class ChilloutVRBaseCommands : CommandBase
|
|||
});
|
||||
|
||||
Commands.RegisterCommand("mute",
|
||||
onCommandSent: (message, sound) =>
|
||||
onCommandSent: (message, sound, displayMsg) =>
|
||||
{
|
||||
LocalCommandIgnoreOthers(message, args =>
|
||||
{
|
||||
Audio.SetMicrophoneActive(true);
|
||||
});
|
||||
},
|
||||
onCommandReceived: (sender, message, sound) =>
|
||||
onCommandReceived: (sender, message, sound, displayMsg) =>
|
||||
{
|
||||
RemoteCommandListenForAll(message, args =>
|
||||
{
|
||||
|
@ -40,4 +40,4 @@ internal class ChilloutVRBaseCommands : CommandBase
|
|||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,11 @@
|
|||
using ABI_RC.Core;
|
||||
using ABI_RC.Core.Base;
|
||||
using ABI_RC.Core.Savior;
|
||||
using Kafe.ChatBox;
|
||||
|
||||
namespace NAK.Melons.ChatBoxExtensions.Integrations;
|
||||
namespace NAK.Melons.ChatBoxExtensions.Integrations;
|
||||
|
||||
internal class ChilloutVRInputCommands : CommandBase
|
||||
{
|
||||
public static void RegisterCommands()
|
||||
{
|
||||
Commands.RegisterCommand("emote",
|
||||
onCommandSent: (message, sound) =>
|
||||
onCommandSent: (message, sound, displayMsg) =>
|
||||
{
|
||||
LocalCommandIgnoreOthers(message, args =>
|
||||
{
|
||||
|
@ -20,7 +15,7 @@ internal class ChilloutVRInputCommands : CommandBase
|
|||
}
|
||||
});
|
||||
},
|
||||
onCommandReceived: (sender, message, sound) =>
|
||||
onCommandReceived: (sender, message, sound, displayMsg) =>
|
||||
{
|
||||
RemoteCommandListenForAll(message, args =>
|
||||
{
|
||||
|
@ -32,7 +27,7 @@ internal class ChilloutVRInputCommands : CommandBase
|
|||
});
|
||||
|
||||
Commands.RegisterCommand("jump",
|
||||
onCommandSent: (message, sound) =>
|
||||
onCommandSent: (message, sound, displayMsg) =>
|
||||
{
|
||||
LocalCommandIgnoreOthers(message, args =>
|
||||
{
|
||||
|
@ -44,7 +39,7 @@ internal class ChilloutVRInputCommands : CommandBase
|
|||
ChatBoxExtensions.InputModule.jump = true;
|
||||
});
|
||||
},
|
||||
onCommandReceived: (sender, message, sound) =>
|
||||
onCommandReceived: (sender, message, sound, displayMsg) =>
|
||||
{
|
||||
RemoteCommandListenForAll(message, args =>
|
||||
{
|
||||
|
@ -55,4 +50,4 @@ internal class ChilloutVRInputCommands : CommandBase
|
|||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
46
ChatBoxExtensions/Integrations/Commands.cs
Normal file
46
ChatBoxExtensions/Integrations/Commands.cs
Normal file
|
@ -0,0 +1,46 @@
|
|||
namespace NAK.Melons.ChatBoxExtensions.Integrations;
|
||||
|
||||
public static class Commands {
|
||||
|
||||
private const string Character = "/";
|
||||
private static readonly List<Command> CommandList = new();
|
||||
|
||||
internal static void InitializeCommandHandlers() {
|
||||
Kafe.ChatBox.API.OnMessageSent += (source, msg, notification, displayMsg) => HandleSentCommand(msg, notification, displayMsg);
|
||||
Kafe.ChatBox.API.OnMessageReceived += (source, sender, msg, notification, displayMsg) => HandleReceivedCommand(sender, msg, notification, displayMsg);
|
||||
}
|
||||
|
||||
internal static void RegisterCommand(string prefix, Action<string, bool, bool> onCommandSent = null, Action<string, string, bool, bool> onCommandReceived = null) {
|
||||
var cmd = new Command { Prefix = prefix, OnCommandSent = onCommandSent, OnCommandReceived = onCommandReceived };
|
||||
CommandList.Add(cmd);
|
||||
}
|
||||
|
||||
internal static void UnregisterCommand(string prefix) {
|
||||
CommandList.RemoveAll(cmd => cmd.Prefix == prefix);
|
||||
}
|
||||
|
||||
private class Command {
|
||||
|
||||
internal string Prefix;
|
||||
|
||||
// Command Sent (message)
|
||||
internal Action<string, bool, bool> OnCommandSent;
|
||||
|
||||
// Command Sent (sender guid, message)
|
||||
internal Action<string, string, bool, bool> OnCommandReceived;
|
||||
}
|
||||
|
||||
private static void HandleSentCommand(string message, bool notification, bool displayMsg) {
|
||||
if (!message.StartsWith(Character)) return;
|
||||
foreach (var command in CommandList.Where(command => message.StartsWith(Character + command.Prefix))) {
|
||||
command.OnCommandSent?.Invoke(message, notification, displayMsg);
|
||||
}
|
||||
}
|
||||
|
||||
private static void HandleReceivedCommand(string sender, string message, bool notification, bool displayMsg) {
|
||||
if (!message.StartsWith(Character)) return;
|
||||
foreach (var command in CommandList.Where(command => message.StartsWith(Character + command.Prefix))) {
|
||||
command.OnCommandReceived?.Invoke(sender, message, notification, displayMsg);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
using Kafe.ChatBox;
|
||||
using ml_prm;
|
||||
using ml_prm;
|
||||
|
||||
namespace NAK.Melons.ChatBoxExtensions.Integrations;
|
||||
|
||||
|
@ -8,7 +7,7 @@ internal class PlayerRagdollModCommands : CommandBase
|
|||
public static void RegisterCommands()
|
||||
{
|
||||
Commands.RegisterCommand("unragdoll",
|
||||
onCommandSent: (message, sound) =>
|
||||
onCommandSent: (message, sound, displayMsg) =>
|
||||
{
|
||||
LocalCommandIgnoreOthers(message, (args) =>
|
||||
{
|
||||
|
@ -18,7 +17,7 @@ internal class PlayerRagdollModCommands : CommandBase
|
|||
}
|
||||
});
|
||||
},
|
||||
onCommandReceived: (sender, message, sound) =>
|
||||
onCommandReceived: (sender, message, sound, displayMsg) =>
|
||||
{
|
||||
RemoteCommandListenForAll(message, (args) =>
|
||||
{
|
||||
|
@ -30,7 +29,7 @@ internal class PlayerRagdollModCommands : CommandBase
|
|||
});
|
||||
|
||||
Commands.RegisterCommand("ragdoll",
|
||||
onCommandSent: (message, sound) =>
|
||||
onCommandSent: (message, sound, displayMsg) =>
|
||||
{
|
||||
LocalCommandIgnoreOthers(message, (args) =>
|
||||
{
|
||||
|
@ -47,7 +46,7 @@ internal class PlayerRagdollModCommands : CommandBase
|
|||
}
|
||||
});
|
||||
},
|
||||
onCommandReceived: (sender, message, sound) =>
|
||||
onCommandReceived: (sender, message, sound, displayMsg) =>
|
||||
{
|
||||
RemoteCommandListenForAll(message, (args) =>
|
||||
{
|
||||
|
@ -66,7 +65,7 @@ internal class PlayerRagdollModCommands : CommandBase
|
|||
});
|
||||
|
||||
Commands.RegisterCommand("kill",
|
||||
onCommandSent: (message, sound) =>
|
||||
onCommandSent: (message, sound, displayMsg) =>
|
||||
{
|
||||
LocalCommandIgnoreOthers(message, (args) =>
|
||||
{
|
||||
|
@ -76,7 +75,7 @@ internal class PlayerRagdollModCommands : CommandBase
|
|||
}
|
||||
});
|
||||
},
|
||||
onCommandReceived: (sender, message, sound) =>
|
||||
onCommandReceived: (sender, message, sound, displayMsg) =>
|
||||
{
|
||||
RemoteCommandListenForAll(message, (args) =>
|
||||
{
|
||||
|
|
|
@ -23,6 +23,7 @@ public class ChatBoxExtensions : MelonMod
|
|||
|
||||
void ApplyIntegrations()
|
||||
{
|
||||
Integrations.Commands.InitializeCommandHandlers();
|
||||
Integrations.ChatBoxCommands.RegisterCommands();
|
||||
Integrations.ChilloutVRBaseCommands.RegisterCommands();
|
||||
ApplyPatches(typeof(HarmonyPatches.CVRInputManagerPatches));
|
||||
|
@ -45,4 +46,4 @@ public class ChatBoxExtensions : MelonMod
|
|||
Logger.Error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,12 +21,13 @@ using System.Reflection;
|
|||
[assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")]
|
||||
[assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
|
||||
[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)]
|
||||
[assembly: MelonOptionalDependencies("ChatBox", "PlayerRagdollMod")]
|
||||
[assembly: MelonAdditionalDependencies("ChatBox")]
|
||||
[assembly: MelonOptionalDependencies("PlayerRagdollMod")]
|
||||
[assembly: HarmonyDontPatchAll]
|
||||
|
||||
namespace ChatBoxExtensions.Properties;
|
||||
internal static class AssemblyInfoParams
|
||||
{
|
||||
public const string Version = "1.0.0";
|
||||
public const string Version = "1.0.1";
|
||||
public const string Author = "NotAKidoS";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue