[Feat] (...): Add mojangInterfaceColor option, used in glClearColor.

This commit is contained in:
BZLZHH 2025-04-20 00:35:06 +08:00
parent 3f1bb9395f
commit 2bcb847b7c
8 changed files with 100 additions and 30 deletions

View File

@ -16,7 +16,7 @@ char* config_file_path;
char* log_file_path;
char* glsl_cache_file_path;
static cJSON *config_json = NULL;
static cJSON *config_json = nullptr;
int initialized = 0;
@ -27,6 +27,32 @@ char* concatenate(char* str1, char* str2) {
return result;
}
float* config_get_float_array(char* name, int* size) {
if (config_json == nullptr) {
*size = 0;
return nullptr;
}
cJSON *item = cJSON_GetObjectItem(config_json, name);
if (item == nullptr || !cJSON_IsArray(item)) {
LOG_D("Config item '%s' not found or not an array.\n", name);
*size = 0;
return nullptr;
}
int array_size = cJSON_GetArraySize(item);
auto *float_array = (float*)malloc(sizeof(float) * array_size);
*size = array_size;
for (int i = 0; i < array_size; i++) {
cJSON *element = cJSON_GetArrayItem(item, i);
if (element != nullptr && cJSON_IsNumber(element)) {
float_array[i] = (float)element->valuedouble;
}
}
return float_array;
}
int check_path() {
char* var = getenv("MG_DIR_PATH");
mg_directory_path = var ? var : DEFAULT_MG_DIRECTORY_PATH;
@ -48,7 +74,7 @@ int config_refresh() {
LOG_D("GLSL_CACHE_FILE_PATH=%s", glsl_cache_file_path)
FILE *file = fopen(config_file_path, "r");
if (file == NULL) {
if (file == nullptr) {
LOG_E("Unable to open config file %s", config_file_path);
return 0;
}
@ -58,7 +84,7 @@ int config_refresh() {
fseek(file, 0, SEEK_SET);
char *file_content = (char *)malloc(file_size + 1);
if (file_content == NULL) {
if (file_content == nullptr) {
LOG_E("Unable to allocate memory for file content");
fclose(file);
return 0;
@ -71,7 +97,7 @@ int config_refresh() {
config_json = cJSON_Parse(file_content);
free(file_content);
if (config_json == NULL) {
if (config_json == nullptr) {
LOG_E("Error parsing config JSON: %s\n", cJSON_GetErrorPtr());
return 0;
}
@ -81,12 +107,12 @@ int config_refresh() {
}
int config_get_int(char* name) {
if (config_json == NULL) {
if (config_json == nullptr) {
return -1;
}
cJSON *item = cJSON_GetObjectItem(config_json, name);
if (item == NULL || !cJSON_IsNumber(item)) {
if (item == nullptr || !cJSON_IsNumber(item)) {
LOG_D("Config item '%s' not found or not an integer.\n", name);
return -1;
}
@ -95,12 +121,12 @@ int config_get_int(char* name) {
}
char* config_get_string(char* name) {
if (config_json == NULL) {
return NULL;
if (config_json == nullptr) {
return nullptr;
}
cJSON *item = cJSON_GetObjectItem(config_json, name);
if (item == NULL || !cJSON_IsString(item)) {
if (item == nullptr || !cJSON_IsString(item)) {
LOG_D("Config item '%s' not found or not a string.\n", name);
return "";
}
@ -109,8 +135,8 @@ char* config_get_string(char* name) {
}
void config_cleanup() {
if (config_json != NULL) {
if (config_json != nullptr) {
cJSON_Delete(config_json);
config_json = NULL;
config_json = nullptr;
}
}

View File

@ -19,6 +19,7 @@ int check_path();
int config_refresh();
int config_get_int(char* name);
char* config_get_string(char* name);
float* config_get_float_array(char* name, int* size);
void config_cleanup();
#ifdef __cplusplus

View File

@ -27,7 +27,9 @@ void init_settings() {
int enableExtComputeShader = success ? config_get_int("enableExtComputeShader") : 0;
int enableCompatibleMode = success ? config_get_int("enableCompatibleMode") : 0;
multidraw_mode_t multidrawMode = success ? (multidraw_mode_t)config_get_int("multidrawMode") : multidraw_mode_t::Auto;
// multidraw_mode_t multidrawMode = multidraw_mode_t::PreferUnroll;
int size = 0;
float* mojangInterfaceColor = success ? config_get_float_array("mojangInterfaceColor", &size) : nullptr;
size_t maxGlslCacheSize = 0;
if (config_get_int("maxGlslCacheSize") > 0)
maxGlslCacheSize = success ? config_get_int("maxGlslCacheSize") * 1024 * 1024 : 0;
@ -44,7 +46,14 @@ void init_settings() {
enableCompatibleMode = 0;
if ((int)multidrawMode < 0 || (int)multidrawMode > 4)
multidrawMode = multidraw_mode_t::Auto;
if (mojangInterfaceColor == nullptr || size != 4) {
mojangInterfaceColor = new float[4];
mojangInterfaceColor[0] == 0.937255;
mojangInterfaceColor[1] == 0.196078;
mojangInterfaceColor[2] == 0.239216;
mojangInterfaceColor[3] == 1.000000;
}
// 1205
int fclVersion = 0;
GetEnvVarInt("FCL_VERSION_CODE", &fclVersion, 0);
@ -65,6 +74,12 @@ void init_settings() {
enableExtComputeShader = 0;
maxGlslCacheSize = 0;
enableCompatibleMode = 0;
multidrawMode = multidraw_mode_t::Auto;
mojangInterfaceColor = new float[4];
mojangInterfaceColor[0] == 0.937255;
mojangInterfaceColor[1] == 0.196078;
mojangInterfaceColor[2] == 0.239216;
mojangInterfaceColor[3] == 1.000000;
}
// Determining actual ANGLE mode
@ -77,16 +92,12 @@ void init_settings() {
} else {
int isQcom = isAdreno(gpuString);
int is740 = isAdreno740(gpuString);
//int is830 = isAdreno830(gpuString);
int hasVk13 = hasVulkan13();
LOG_D("Is Adreno? = %s", isQcom ? "true" : "false")
//LOG_D("Is Adreno 830? = %s", is830 ? "true" : "false")
LOG_D("Is Adreno 740? = %s", is740 ? "true" : "false")
LOG_D("Has Vulkan 1.3? = %s", hasVk13 ? "true" : "false")
//if (is830)
// global_settings.angle = 1;
if (is740)
global_settings.angle = 0;
else
@ -95,17 +106,6 @@ void init_settings() {
LOG_D("enableANGLE = %d", enableANGLE)
LOG_D("global_settings.angle = %d", global_settings.angle)
// if (enableANGLE == 1) {
// global_settings.angle = (isAdreno740(gpuString) || !hasVulkan13()) ? 0 : 1;
// } else if (enableANGLE == 2 || enableANGLE == 3) {
// global_settings.angle = enableANGLE - 2;
// } else {
// int is830 = isAdreno830(gpuString);
// LOG_D("Is Adreno 830? = %s", is830 ? "true" : "false")
// global_settings.angle = is830 ? 1 : 0;
// }
if (global_settings.angle) {
setenv("LIBGL_GLES", "libGLESv2_angle.so", 1);
setenv("LIBGL_EGL", "libEGL_angle.so", 1);
@ -149,6 +149,9 @@ void init_settings() {
global_settings.multidraw_mode = multidraw_mode_t::Auto;
break;
}
for (int i = 0; i < 4; i++)
global_settings.mojang_interface_color[i] = mojangInterfaceColor[i];
LOG_V("[MobileGlues] Setting: enableAngle = %s", global_settings.angle ? "true" : "false")
LOG_V("[MobileGlues] Setting: ignoreError = %i", global_settings.ignore_error)
@ -157,6 +160,7 @@ void init_settings() {
LOG_V("[MobileGlues] Setting: maxGlslCacheSize = %i", global_settings.max_glsl_cache_size / 1024 / 1024)
LOG_V("[MobileGlues] Setting: enableCompatibleMode = %s", global_settings.enable_compatible_mode ? "true" : "false")
LOG_V("[MobileGlues] Setting: multidrawMode = %s", draw_mode_str.c_str())
LOG_V("[MobileGlues] Setting: mojangInterfaceColor = %s", printFloatArray(global_settings.mojang_interface_color, 4).c_str())
}
void init_settings_post() {

View File

@ -27,6 +27,7 @@ struct global_settings_t {
size_t max_glsl_cache_size; // 0~
int enable_compatible_mode; // 0, 1
multidraw_mode_t multidraw_mode; // 0, 1, 2, 3, 4
float mojang_interface_color[4]; // 0~1, [4]
};
extern struct global_settings_t global_settings;

View File

@ -8,6 +8,7 @@
#include "log.h"
#include "../gles/loader.h"
#include "mg.h"
#include "../config/settings.h"
#define DEBUG 0
@ -20,4 +21,25 @@ void glClearDepth(GLclampd depth) {
void glHint(GLenum target, GLenum mode) {
LOG()
LOG_D("glHint, target = %s, mode = %s", glEnumToString(target), glEnumToString(mode))
CHECK_GL_ERROR
}
void glClearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) {
LOG()
LOG_D("glClearColor, red = %f, green = %f, blue = %f, alpha = %f", red, green, blue, alpha)
// Hook Mojang interface background color
if (fabsf(red - 0.937255f) < 0.01f &&
fabsf(green - 0.196078f) < 0.01f &&
fabsf(blue - 0.239216f) < 0.01f &&
fabsf(alpha - 1.000000f) < 0.01f) {
red = global_settings.mojang_interface_color[0];
green = global_settings.mojang_interface_color[1];
blue = global_settings.mojang_interface_color[2];
alpha = global_settings.mojang_interface_color[3];
LOG_D(" Hook! %f %f %f %f", red, green, blue, alpha)
}
GLES.glClearColor(red, green, blue, alpha);
CHECK_GL_ERROR
}

View File

@ -28,7 +28,7 @@ NATIVE_FUNCTION_HEAD(void, glBlendFuncSeparate, GLenum sfactorRGB, GLenum dfacto
NATIVE_FUNCTION_HEAD(void, glBufferSubData, GLenum target, GLintptr offset, GLsizeiptr size, const void *data) NATIVE_FUNCTION_END_NO_RETURN(void, glBufferSubData, target,offset,size,data)
//NATIVE_FUNCTION_HEAD(GLenum, glCheckFramebufferStatus, GLenum target) NATIVE_FUNCTION_END(GLenum, glCheckFramebufferStatus, target)
NATIVE_FUNCTION_HEAD(void, glClear, GLbitfield mask) NATIVE_FUNCTION_END_NO_RETURN(void, glClear, mask)
NATIVE_FUNCTION_HEAD(void, glClearColor, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) NATIVE_FUNCTION_END_NO_RETURN(void, glClearColor, red,green,blue,alpha)
//NATIVE_FUNCTION_HEAD(void, glClearColor, GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) NATIVE_FUNCTION_END_NO_RETURN(void, glClearColor, red,green,blue,alpha)
NATIVE_FUNCTION_HEAD(void, glClearDepthf, GLfloat d) NATIVE_FUNCTION_END_NO_RETURN(void, glClearDepthf, d)
NATIVE_FUNCTION_HEAD(void, glClearStencil, GLint s) NATIVE_FUNCTION_END_NO_RETURN(void, glClearStencil, s)
NATIVE_FUNCTION_HEAD(void, glColorMask, GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) NATIVE_FUNCTION_END_NO_RETURN(void, glColorMask, red,green,blue,alpha)

View File

@ -70,4 +70,17 @@ GLenum map_tex_target(GLenum target) {
default:
return target;
}
}
}
std::string printFloatArray(float* arr, int size) {
std::string result = "[";
for (int i = 0; i < size; ++i) {
result += std::to_string(arr[i]);
if (i < size - 1) {
result += ", ";
}
}
result += "]";
return result;
}

View File

@ -5,6 +5,7 @@
#ifndef MOBILEGLUES_MG_H
#define MOBILEGLUES_MG_H
#include <string>
#include <cstring>
#include <malloc.h>
#include <cstdlib>
@ -69,4 +70,6 @@ void clear_log();
}
#endif
std::string printFloatArray(float* arr, int size);
#endif //MOBILEGLUES_MG_H