2020-12-02 23:18:49 +00:00
|
|
|
#include <string>
|
|
|
|
#include <fstream>
|
|
|
|
#include <streambuf>
|
|
|
|
|
2020-12-04 17:17:51 +00:00
|
|
|
#include <cstring>
|
2020-12-02 23:18:49 +00:00
|
|
|
|
2021-01-27 21:26:19 +00:00
|
|
|
#include <libreborn/libreborn.h>
|
2021-09-12 03:18:12 +00:00
|
|
|
#include <symbols/minecraft.h>
|
2020-12-02 23:18:49 +00:00
|
|
|
|
2022-06-25 21:30:08 +00:00
|
|
|
#include <mods/feature/feature.h>
|
|
|
|
#include "misc-internal.h"
|
|
|
|
#include <mods/misc/misc.h>
|
2020-12-02 23:18:49 +00:00
|
|
|
|
|
|
|
// Read Asset File
|
2020-12-04 17:17:51 +00:00
|
|
|
static AppPlatform_readAssetFile_return_value AppPlatform_readAssetFile_injection(__attribute__((unused)) unsigned char *app_platform, std::string const& path) {
|
2023-11-11 05:44:26 +00:00
|
|
|
// Open File
|
2023-09-25 03:06:23 +00:00
|
|
|
std::ifstream stream("data/" + path, std::ios_base::binary | std::ios_base::ate);
|
2023-11-11 05:44:26 +00:00
|
|
|
if (!stream) {
|
|
|
|
// Does Not Exist
|
|
|
|
AppPlatform_readAssetFile_return_value ret;
|
|
|
|
ret.length = -1;
|
|
|
|
ret.data = NULL;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
// Read File
|
2023-09-25 03:06:23 +00:00
|
|
|
long len = stream.tellg();
|
|
|
|
char *buf = new char[len];
|
|
|
|
stream.seekg(0, stream.beg);
|
|
|
|
stream.read(buf, len);
|
2023-11-11 05:44:26 +00:00
|
|
|
stream.close();
|
2020-12-04 17:17:51 +00:00
|
|
|
// Return String
|
|
|
|
AppPlatform_readAssetFile_return_value ret;
|
2023-09-25 03:07:30 +00:00
|
|
|
ret.length = len;
|
|
|
|
ret.data = strdup(buf);
|
2020-12-04 17:17:51 +00:00
|
|
|
return ret;
|
2020-12-02 23:18:49 +00:00
|
|
|
}
|
|
|
|
|
2022-04-12 02:52:38 +00:00
|
|
|
// Add Missing Buttons To Pause Menu
|
|
|
|
static void PauseScreen_init_injection(unsigned char *screen) {
|
|
|
|
// Call Original Method
|
|
|
|
(*PauseScreen_init)(screen);
|
|
|
|
|
|
|
|
// Check If Server
|
|
|
|
unsigned char *minecraft = *(unsigned char **) (screen + Screen_minecraft_property_offset);
|
|
|
|
unsigned char *rak_net_instance = *(unsigned char **) (minecraft + Minecraft_rak_net_instance_property_offset);
|
|
|
|
if (rak_net_instance != NULL) {
|
|
|
|
unsigned char *rak_net_instance_vtable = *(unsigned char**) rak_net_instance;
|
|
|
|
RakNetInstance_isServer_t RakNetInstance_isServer = *(RakNetInstance_isServer_t *) (rak_net_instance_vtable + RakNetInstance_isServer_vtable_offset);
|
|
|
|
if ((*RakNetInstance_isServer)(rak_net_instance)) {
|
|
|
|
// Add Button
|
|
|
|
std::vector<unsigned char *> *rendered_buttons = (std::vector<unsigned char *> *) (screen + Screen_rendered_buttons_property_offset);
|
|
|
|
std::vector<unsigned char *> *selectable_buttons = (std::vector<unsigned char *> *) (screen + Screen_selectable_buttons_property_offset);
|
|
|
|
unsigned char *button = *(unsigned char **) (screen + PauseScreen_server_visibility_button_property_offset);
|
|
|
|
rendered_buttons->push_back(button);
|
|
|
|
selectable_buttons->push_back(button);
|
|
|
|
|
|
|
|
// Update Button Text
|
|
|
|
(*PauseScreen_updateServerVisibilityText)(screen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-22 01:50:26 +00:00
|
|
|
// Init
|
2021-06-17 21:32:24 +00:00
|
|
|
void _init_misc_cpp() {
|
2020-12-02 23:18:49 +00:00
|
|
|
// Implement AppPlatform::readAssetFile So Translations Work
|
2022-04-10 00:01:16 +00:00
|
|
|
if (feature_has("Load Language Files", server_enabled)) {
|
2021-07-04 23:02:45 +00:00
|
|
|
overwrite((void *) AppPlatform_readAssetFile, (void *) AppPlatform_readAssetFile_injection);
|
|
|
|
}
|
2020-12-02 23:18:49 +00:00
|
|
|
|
2022-04-12 02:52:38 +00:00
|
|
|
// Fix Pause Menu
|
|
|
|
if (feature_has("Fix Pause Menu", server_disabled)) {
|
|
|
|
// Add Missing Buttons To Pause Menu
|
|
|
|
patch_address(PauseScreen_init_vtable_addr, (void *) PauseScreen_init_injection);
|
|
|
|
}
|
2021-06-22 01:50:26 +00:00
|
|
|
}
|