Convert API Chat Posts To CP-437

This commit is contained in:
TheBrokenRail 2024-11-03 01:41:28 -04:00
parent 644e9e421b
commit 9ae6cd17cf
2 changed files with 12 additions and 3 deletions

View File

@ -17,7 +17,9 @@ HOOK(chat_handle_packet_send, void, (const Minecraft *minecraft, ChatPacket *pac
if (out.length() > 0 && out[out.length() - 1] == '\n') { if (out.length() > 0 && out[out.length() - 1] == '\n') {
out[out.length() - 1] = '\0'; out[out.length() - 1] = '\0';
} }
gui->addMessage(out); char *cp437_out = to_cp437(out.c_str());
gui->addMessage(cp437_out);
free(cp437_out);
} else { } else {
// Call Original Method // Call Original Method
real_chat_handle_packet_send()(minecraft, packet); real_chat_handle_packet_send()(minecraft, packet);

View File

@ -10,7 +10,7 @@
#include "chat-internal.h" #include "chat-internal.h"
#include <mods/chat/chat.h> #include <mods/chat/chat.h>
// Send API Command // Send UTF-8 API Command
std::string chat_send_api_command(const Minecraft *minecraft, const std::string &str) { std::string chat_send_api_command(const Minecraft *minecraft, const std::string &str) {
ConnectedClient client; ConnectedClient client;
client.sock = -1; client.sock = -1;
@ -26,7 +26,9 @@ std::string chat_send_api_command(const Minecraft *minecraft, const std::string
// Send API Chat Command // Send API Chat Command
static void send_api_chat_command(const Minecraft *minecraft, const char *str) { static void send_api_chat_command(const Minecraft *minecraft, const char *str) {
const std::string command = std::string("chat.post(") + str + ")\n"; char *utf_str = from_cp437(str);
const std::string command = std::string("chat.post(") + utf_str + ")\n";
free(utf_str);
chat_send_api_command(minecraft, command); chat_send_api_command(minecraft, command);
} }
@ -45,6 +47,11 @@ void chat_send_message_to_clients(ServerSideNetworkHandler *server_side_network_
} }
// Handle Chat packet Send // Handle Chat packet Send
void chat_handle_packet_send(const Minecraft *minecraft, ChatPacket *packet) { void chat_handle_packet_send(const Minecraft *minecraft, ChatPacket *packet) {
// Convert To CP-437
char *cp437_str = to_cp437(packet->message.c_str());
packet->message = cp437_str;
free(cp437_str);
// Send
RakNetInstance *rak_net_instance = minecraft->rak_net_instance; RakNetInstance *rak_net_instance = minecraft->rak_net_instance;
if (rak_net_instance->isServer()) { if (rak_net_instance->isServer()) {
// Hosting Multiplayer // Hosting Multiplayer