Tweaks & Fixes

This commit is contained in:
TheBrokenRail 2022-09-20 18:25:27 -04:00
parent 35cafec1ee
commit d03a1a96ff
13 changed files with 92 additions and 49 deletions

View File

@ -6,12 +6,12 @@ if(MCPI_HEADLESS_MODE)
set(GLES_SRC src/stubs.c)
elseif(MCPI_USE_GLES1_COMPATIBILITY_LAYER)
# GLESv1_CM Compatibility Layer
set(GLES_SRC src/compatibility-layer/state.c src/compatibility-layer/passthrough.c src/compatibility-layer/matrix.c src/compatibility-layer/draw.c src/compatibility-layer/buffer.cpp)
set(GLES_SRC src/compatibility-layer/state.c src/compatibility-layer/passthrough.c src/compatibility-layer/matrix.c src/compatibility-layer/draw.c)
else()
# Passthrough To glfwGetProcAddress()
set(GLES_SRC src/passthrough.c)
endif()
add_library(GLESv1_CM SHARED ${GLES_SRC})
add_library(GLESv1_CM OBJECT ${GLES_SRC})
if(NOT MCPI_HEADLESS_MODE)
target_link_libraries(GLESv1_CM PRIVATE glfw PUBLIC reborn-util PRIVATE dl PRIVATE m)
# Shaders

View File

@ -1,35 +0,0 @@
#include <unordered_map>
#include <GLES/gl.h>
#include "../passthrough.h"
// Store Buffers
static std::unordered_map<GLuint, GLuint> buffers_map;
// Get Buffer
GL_FUNC(glGenBuffers, void, (GLsizei n, GLuint *buffers));
static GLuint get_real_buffer(GLuint fake_buffer) {
if (buffers_map.count(fake_buffer) > 0) {
return buffers_map[fake_buffer];
} else {
GLuint new_buffer;
real_glGenBuffers()(1, &new_buffer);
buffers_map[fake_buffer] = new_buffer;
return get_real_buffer(fake_buffer);
}
}
// Convert Fake Buffers To Real Buffers When Calling GL
GL_FUNC(glBindBuffer, void, (GLenum target, GLuint buffer));
void glBindBuffer(GLenum target, GLuint buffer) {
real_glBindBuffer()(target, get_real_buffer(buffer));
}
GL_FUNC(glDeleteBuffers, void, (GLsizei n, const GLuint *buffers));
void glDeleteBuffers(GLsizei n, const GLuint *buffers) {
for (int i = 0; i < n; i++) {
if (buffers_map.count(buffers[i]) > 0) {
real_glDeleteBuffers()(1, &buffers_map[i]);
buffers_map.erase(buffers[i]);
}
}
}

View File

@ -39,6 +39,10 @@ GL_FUNC(glDepthRangef, void, (GLclampf near, GLclampf far));
void glDepthRangef(GLclampf near, GLclampf far) {
real_glDepthRangef()(near, far);
}
GL_FUNC(glBindBuffer, void, (GLenum target, GLuint buffer));
void glBindBuffer(GLenum target, GLuint buffer) {
real_glBindBuffer()(target, buffer);
}
GL_FUNC(glDepthFunc, void, (GLenum func));
void glDepthFunc(GLenum func) {
real_glDepthFunc()(func);
@ -57,6 +61,10 @@ void glHint(GLenum target, GLenum mode) {
real_glHint()(target, mode);
}
}
GL_FUNC(glDeleteBuffers, void, (GLsizei n, const GLuint *buffers));
void glDeleteBuffers(GLsizei n, const GLuint *buffers) {
real_glDeleteBuffers()(n, buffers);
}
GL_FUNC(glColorMask, void, (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha));
void glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) {
real_glColorMask()(red, green, blue, alpha);
@ -103,3 +111,7 @@ void glShadeModel(__attribute__((unused)) GLenum mode) {
void glNormal3f(__attribute__((unused)) GLfloat nx, __attribute__((unused)) GLfloat ny, __attribute__((unused)) GLfloat nz) {
// Do Nothing
}
GL_FUNC(glGenBuffers, void, (GLsizei n, GLuint *buffers));
void glGenBuffers(GLsizei n, GLuint *buffers) {
real_glGenBuffers()(n, buffers);
}

View File

@ -202,3 +202,7 @@ GL_FUNC(glReadPixels, void, (GLint x, GLint y, GLsizei width, GLsizei height, GL
void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *data) {
real_glReadPixels()(x, y, width, height, format, type, data);
}
GL_FUNC(glGenBuffers, void, (GLsizei n, GLuint *buffers));
void glGenBuffers(GLsizei n, GLuint *buffers) {
real_glGenBuffers()(n, buffers);
}

View File

@ -76,7 +76,7 @@ void glColorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha
void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels) {
}
void glGenTextures(GLsizei n, GLuint *textures) {
static int i = 0;
static int i = 1;
for (int j = 0; j < n; j++) {
textures[j] = i++;
}
@ -160,5 +160,11 @@ void glGetIntegerv(GLenum pname, GLint *data) {
}
void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *data) {
}
void glGenBuffers(GLsizei n, GLuint *buffers) {
static int i = 1;
for (int j = 0; j < n; j++) {
buffers[j] = i++;
}
}
#pragma GCC diagnostic pop

View File

@ -1,5 +1,8 @@
#pragma once
#include <stdio.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
@ -41,9 +44,6 @@ extern "C" {
#define GL_FOG_COLOR 0xb66
#define GL_BLEND 0xbe2
#include <stdio.h>
#include <stdint.h>
typedef float GLfloat;
typedef float GLclampf;
typedef int GLint;
@ -107,6 +107,7 @@ void glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz);
GLboolean glIsEnabled(GLenum cap);
void glGetIntegerv(GLenum pname, GLint *data);
void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *data);
void glGenBuffers(GLsizei n, GLuint *buffers);
#ifdef __cplusplus
}

View File

@ -168,6 +168,7 @@ CALL(15, glDrawArrays, void, (GLenum mode, GLint first, GLsizei count)) {
// Release Proxy
end_proxy_call();
flush_write_cache();
#else
GLenum mode = (GLenum) read_int();
GLint first = (GLint) read_int();
@ -1242,3 +1243,30 @@ CALL(65, glReadPixels, void, (GLint x, GLint y, GLsizei width, GLsizei height, G
free(pixels);
#endif
}
CALL(67, glGenBuffers, void, (GLsizei n, GLuint *buffers)) {
#if defined(MEDIA_LAYER_PROXY_SERVER)
// Lock Proxy
start_proxy_call();
// Arguments
write_int((uint32_t) n);
// Get Return Value
for (GLsizei i = 0; i < n; i++) {
buffers[i] = (GLuint) read_int();
}
// Release Proxy
end_proxy_call();
#else
GLsizei n = (GLsizei) read_int();
GLuint buffers[n];
// Run
glGenBuffers(n, buffers);
// Return Value
for (GLsizei i = 0; i < n; i++) {
write_int((uint32_t) buffers[i]);
}
#endif
}

View File

@ -182,6 +182,7 @@ CALL(8, media_swap_buffers, void, ()) {
start_proxy_call();
// Release Proxy
end_proxy_call();
flush_write_cache();
#else
// Run
media_swap_buffers();

View File

@ -164,6 +164,4 @@ void _start_proxy_call(unsigned char call_id) {
write_byte(call_id);
}
void end_proxy_call() {
// Flush Write Cache
flush_write_cache();
}

View File

@ -197,9 +197,9 @@ static void Inventory_setupDefault_FillingContainer_addItem_call_injection(unsig
// Make Liquids Selectable
static bool is_holding_bucket = false;
static void Mob_pick_Level_clip_injection(unsigned char *level, unsigned char *param_1, unsigned char *param_2, bool param_3, __attribute__((unused)) bool clip_liquids) {
static HitResult Mob_pick_Level_clip_injection(unsigned char *level, unsigned char *param_1, unsigned char *param_2, __attribute__((unused)) bool clip_liquids, bool param_3) {
// Call Original Method
(*Level_clip)(level, param_1, param_2, param_3, is_holding_bucket);
return (*Level_clip)(level, param_1, param_2, is_holding_bucket, param_3);
}
static void handle_tick(unsigned char *minecraft) {
unsigned char *player = *(unsigned char **) (minecraft + Minecraft_player_property_offset);

View File

@ -22,8 +22,8 @@ static int32_t MouseBuildInput_tickBuild_injection(unsigned char *mouse_build_in
if (ret != 0 && is_left_click == 1 && *build_action_intention_return == 0xa) {
// Get Target HitResult
unsigned char *minecraft = *(unsigned char **) (local_player + LocalPlayer_minecraft_property_offset);
unsigned char *hit_result = minecraft + Minecraft_hit_result_property_offset;
int32_t hit_result_type = *(int32_t *) (hit_result + HitResult_type_property_offset);
HitResult *hit_result = (HitResult *) (minecraft + Minecraft_hit_result_property_offset);
int32_t hit_result_type = hit_result->type;
// Check if The Target Is An Entity Using HitResult
if (hit_result_type == 1) {
// Change BuildActionIntention To Attack/Place Mode (Place Will Not Happen Because The HitResult Is An Entity)

View File

@ -297,6 +297,11 @@ int32_t misc_get_real_selected_slot(unsigned char *player) {
return selected_slot;
}
// Properly Generate Buffers
static void anGenBuffers_injection(int32_t count, uint32_t *buffers) {
glGenBuffers(count, buffers);
}
// Init
static void nop() {
}
@ -379,6 +384,9 @@ void init_misc() {
overwrite_calls((void *) sleepMs, (void *) nop);
}
// Properly Generate Buffers
overwrite((void *) anGenBuffers, (void *) anGenBuffers_injection);
// Init C++ And Logging
_init_misc_cpp();
_init_misc_logging();

View File

@ -21,6 +21,9 @@ static sleepMs_t sleepMs = (sleepMs_t) 0x13cf4;
typedef int32_t (*sdl_key_to_minecraft_key_t)(int32_t sdl_key);
static sdl_key_to_minecraft_key_t sdl_key_to_minecraft_key = (sdl_key_to_minecraft_key_t) 0x1243c;
typedef void (*anGenBuffers_t)(int32_t count, uint32_t *buffers);
static anGenBuffers_t anGenBuffers = (anGenBuffers_t) 0x5f28c;
static char **default_path = (char **) 0xe264; // /.minecraft/
static char **default_username = (char **) 0x18fd4; // StevePi
static char **minecraft_pi_version = (char **) 0x39d94; // v0.1.1 alpha
@ -261,9 +264,26 @@ static uint32_t StartGamePacket_game_mode_property_offset = 0x14; // int32_t
static uint32_t ChatPacket_message_property_offset = 0xc; // char *
// Vec3
typedef struct {
float x;
float y;
float z;
} Vec3;
// HitResult
static uint32_t HitResult_type_property_offset = 0x0;
typedef struct {
int32_t type;
int32_t x;
int32_t y;
int32_t z;
int32_t side;
Vec3 exact;
unsigned char *entity;
unsigned char unknown;
} HitResult;
// Options
@ -470,7 +490,7 @@ static Level_getTile_t Level_getTile = (Level_getTile_t) 0xa3380;
typedef unsigned char *(*Level_getMaterial_t)(unsigned char *level, int32_t x, int32_t y, int32_t z);
static Level_getMaterial_t Level_getMaterial = (Level_getMaterial_t) 0xa27f8;
typedef void (*Level_clip_t)(unsigned char *level, unsigned char *param_1, unsigned char *param_2, bool param_3, bool clip_liquids);
typedef HitResult (*Level_clip_t)(unsigned char *level, unsigned char *param_1, unsigned char *param_2, bool clip_liquids, bool param_3);
static Level_clip_t Level_clip = (Level_clip_t) 0xa3db0;
static uint32_t Level_players_property_offset = 0x60; // std::vector<ServerPlayer *>