42 lines
1.4 KiB
C++
Raw Normal View History

2022-06-26 21:17:52 -04:00
// Headers
#include <libreborn/libreborn.h>
#include <symbols/minecraft.h>
#include <mods/chat/chat.h>
#include <mods/misc/misc.h>
2024-09-21 02:30:06 -04:00
#include <mods/server/server.h>
2022-06-26 21:17:52 -04:00
// The Actual Mod
2024-09-21 01:49:47 -04:00
HOOK(chat_handle_packet_send, void, (const Minecraft *minecraft, ChatPacket *packet)) {
2022-06-26 21:17:52 -04:00
// Get Message
2024-03-19 00:25:50 -04:00
const char *message = packet->message.c_str();
2022-06-26 21:17:52 -04:00
if (message[0] == '/') {
// API Command
2024-09-21 01:49:47 -04:00
Minecraft *mc = (Minecraft *) minecraft;
Gui *gui = &mc->gui;
std::string out = chat_send_api_command(mc, (char *) &message[1]);
2022-06-26 21:17:52 -04:00
if (out.length() > 0 && out[out.length() - 1] == '\n') {
out[out.length() - 1] = '\0';
}
2024-11-18 20:15:15 -05:00
std::string cp437_out = to_cp437(out);
2024-11-03 01:41:28 -04:00
gui->addMessage(cp437_out);
2022-06-26 21:17:52 -04:00
} else {
// Call Original Method
2024-10-07 10:18:16 -04:00
real_chat_handle_packet_send()(minecraft, packet);
2022-06-26 21:17:52 -04:00
}
}
2024-09-21 02:30:06 -04:00
// Add Server Command
HOOK(server_get_commands, std::vector<ServerCommand> *, (Minecraft *minecraft, ServerSideNetworkHandler *server_side_network_handler)) {
// Call Original Method
2024-10-07 10:18:16 -04:00
std::vector<ServerCommand> *commands = real_server_get_commands()(minecraft, server_side_network_handler);
2024-09-21 02:30:06 -04:00
// Add Command
commands->push_back({
.name = "greet",
.comment = "Example Custom Command",
.callback = [](__attribute__((unused)) const std::string &cmd) {
INFO("Hello World!");
}
});
// Return
return commands;
}