Print Error Message If RakNet Fails To Start

This commit is contained in:
TheBrokenRail 2021-07-18 21:08:51 -04:00
parent a9830c3bba
commit a925463fdf
7 changed files with 63 additions and 6 deletions

View File

@ -1 +1 @@
2.1.4 2.1.5

View File

@ -1,5 +1,8 @@
# Changelog # Changelog
**2.1.5**
* Print Error Message If RakNet Fails To Start
**2.1.4** **2.1.4**
* Fix RakNet::RakString Security Bug * Fix RakNet::RakString Security Bug

View File

@ -23,7 +23,7 @@ void _overwrite_calls(const char *file, int line, void *start, void *target);
void _overwrite(const char *file, int line, void *start, void *target); void _overwrite(const char *file, int line, void *start, void *target);
#define overwrite(start, target) _overwrite(__FILE__, __LINE__, start, target); #define overwrite(start, target) _overwrite(__FILE__, __LINE__, start, target);
void _patch(const char *file, int line, void *start, unsigned char patch[]); void _patch(const char *file, int line, void *start, unsigned char patch[4]);
#define patch(start, patch) _patch(__FILE__, __LINE__, start, patch); #define patch(start, patch) _patch(__FILE__, __LINE__, start, patch);
void _patch_address(const char *file, int line, void *start, void *target); void _patch_address(const char *file, int line, void *start, void *target);

View File

@ -389,6 +389,24 @@ static uint32_t RakNetInstance_peer_property_offset = 0x4; // RakNet::RakPeer *
// RakNet::RakPeer // RakNet::RakPeer
typedef enum {
RAKNET_STARTED = 0,
RAKNET_ALREADY_STARTED,
INVALID_SOCKET_DESCRIPTORS,
INVALID_MAX_CONNECTIONS,
SOCKET_FAMILY_NOT_SUPPORTED,
SOCKET_PORT_ALREADY_IN_USE,
SOCKET_FAILED_TO_BIND,
SOCKET_FAILED_TEST_SEND,
PORT_CANNOT_BE_ZERO,
FAILED_TO_CREATE_NETWORK_THREAD,
COULD_NOT_GENERATE_GUID,
STARTUP_OTHER_FAILURE
} RakNet_StartupResult;
typedef RakNet_StartupResult (*RakNet_RakPeer_Startup_t)(unsigned char *rak_peer, unsigned short maxConnections, unsigned char *socketDescriptors, uint32_t socketDescriptorCount, int32_t threadPriority);
static RakNet_RakPeer_Startup_t RakNet_RakPeer_Startup = (RakNet_RakPeer_Startup_t) 0xe1654;
static void *RakNet_RakPeer_Startup_vtable_addr = (void *) 0x135438;
typedef struct RakNet_SystemAddress (*RakNet_RakPeer_GetSystemAddressFromGuid_t)(unsigned char *rak_peer, struct RakNet_RakNetGUID guid); typedef struct RakNet_SystemAddress (*RakNet_RakPeer_GetSystemAddressFromGuid_t)(unsigned char *rak_peer, struct RakNet_RakNetGUID guid);
static uint32_t RakNet_RakPeer_GetSystemAddressFromGuid_vtable_offset = 0xd0; static uint32_t RakNet_RakPeer_GetSystemAddressFromGuid_vtable_offset = 0xd0;

View File

@ -142,7 +142,7 @@ void _overwrite(const char *file, int line, void *start, void *target) {
#endif #endif
// Patch Instruction // Patch Instruction
void _patch(const char *file, int line, void *start, unsigned char patch[]) { void _patch(const char *file, int line, void *start, unsigned char patch[4]) {
if (((uint32_t) start) % 4 != 0) { if (((uint32_t) start) % 4 != 0) {
ERR("%s", "Invalid Address"); ERR("%s", "Invalid Address");
} }
@ -171,6 +171,6 @@ void _patch(const char *file, int line, void *start, unsigned char patch[]) {
// Patch Address // Patch Address
void _patch_address(const char *file, int line, void *start, void *target) { void _patch_address(const char *file, int line, void *start, void *target) {
uint32_t addr = (uint32_t) target; uint32_t addr = (uint32_t) target;
unsigned char patch_data[4] = {addr & 0xff, (addr >> 8) & 0xff, (addr >> 16) & 0xff, (addr >> 24) & 0xff}; unsigned char *patch_data = (unsigned char *) &addr;
_patch(file, line, start, patch_data); _patch(file, line, start, patch_data);
} }

View File

@ -74,6 +74,39 @@ static unsigned char *RakNet_RakString_injection(unsigned char *rak_string, cons
return (*RakNet_RakString)(rak_string, "%s", format); return (*RakNet_RakString)(rak_string, "%s", format);
} }
// Print Error Message If RakNet Startup Fails
static char *RAKNET_ERROR_NAMES[] = {
"Success",
"Already Started",
"Invalid Socket Descriptors",
"Invalid Max Connections",
"Socket Family Not Supported",
"Part Already In Use",
"Failed To Bind Port",
"Failed Test Send",
"Port Cannot Be 0",
"Failed To Create Network Thread",
"Couldn't Generate GUID",
"Unknown"
};
#ifdef MCPI_SERVER_MODE
#define PRINT_RAKNET_STARTUP_FAILURE ERR
#else
#define PRINT_RAKNET_STARTUP_FAILURE WARN
#endif
static RakNet_StartupResult RakNetInstance_host_RakNet_RakPeer_Startup_injection(unsigned char *rak_peer, unsigned short maxConnections, unsigned char *socketDescriptors, uint32_t socketDescriptorCount, int32_t threadPriority) {
// Call Original Method
RakNet_StartupResult result = (*RakNet_RakPeer_Startup)(rak_peer, maxConnections, socketDescriptors, socketDescriptorCount, threadPriority);
// Print Error
if (result != RAKNET_STARTED) {
PRINT_RAKNET_STARTUP_FAILURE("Failed To Start RakNet: %s", RAKNET_ERROR_NAMES[result]);
}
// Return
return result;
}
// Init // Init
void init_misc() { void init_misc() {
if (feature_has("Remove Invalid Item Background", 0)) { if (feature_has("Remove Invalid Item Background", 0)) {
@ -93,7 +126,10 @@ void init_misc() {
patch_address(LoginPacket_read_vtable_addr, (void *) LoginPacket_read_injection); patch_address(LoginPacket_read_vtable_addr, (void *) LoginPacket_read_injection);
// Fix RakNet::RakString Security Bug // Fix RakNet::RakString Security Bug
overwrite_calls((void *) RakNet_RakString, RakNet_RakString_injection); overwrite_calls((void *) RakNet_RakString, (void *) RakNet_RakString_injection);
// Print Error Message If RakNet Startup Fails
overwrite_call((void *) 0x73778, (void *) RakNetInstance_host_RakNet_RakPeer_Startup_injection);
// Init C++ // Init C++
_init_misc_cpp(); _init_misc_cpp();

View File

@ -83,8 +83,8 @@ static void start_world(unsigned char *minecraft) {
if (!only_generate) { if (!only_generate) {
// Open Port // Open Port
int port = get_server_properties().get_int("port", DEFAULT_PORT); int port = get_server_properties().get_int("port", DEFAULT_PORT);
(*Minecraft_hostMultiplayer)(minecraft, port);
INFO("Listening On: %i", port); INFO("Listening On: %i", port);
(*Minecraft_hostMultiplayer)(minecraft, port);
} }
// Open ProgressScreen // Open ProgressScreen