Merge pull request 'master' (#2) from TheBrokenRail/minecraft-pi-reborn:master into master

Reviewed-on: RaspberryPiNews/minecraft-pi-reborn#2
This commit is contained in:
RaspberryPiNews 2021-11-12 16:07:00 +00:00
commit f6cbd22f3f
49 changed files with 625 additions and 379 deletions

10
.gitignore vendored
View File

@ -1,6 +1,6 @@
/out
/debian/tmp
/.vscode
/build
/CMakeLists.txt.user
out
debian/tmp
.vscode
build
CMakeLists.txt.user
*.autosave

8
.gitmodules vendored Normal file
View File

@ -0,0 +1,8 @@
[submodule "dependencies/libpng/src"]
path = dependencies/libpng/src
url = https://github.com/glennrp/libpng.git
shallow = true
[submodule "dependencies/zlib/src"]
path = dependencies/zlib/src
url = https://github.com/madler/zlib.git
shallow = true

View File

@ -34,7 +34,7 @@ endif()
# Setup ARM Cross Compilation
if(USE_ARM32_TOOLCHAIN)
include(cmake/arm-toolchain.cmake)
include(cmake/armhf-toolchain.cmake)
endif()
# Utility Functions
@ -72,6 +72,14 @@ if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "/" CACHE PATH "" FORCE)
endif()
# Use LLD When Using Clang
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
add_link_options("-fuse-ld=lld")
endif()
# PIC
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
# Buld LibPNG + ZLib + Download Minecraft: Pi Edition
if(BUILD_ARM_COMPONENTS)
add_subdirectory(dependencies)
@ -84,11 +92,6 @@ add_definitions(-D_GNU_SOURCE)
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 11)
# Use LLD When Using Clang
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
add_link_options("-fuse-ld=lld")
endif()
# Specify Constants
if(MCPI_SERVER_MODE)
add_definitions(-DMCPI_SERVER_MODE)

View File

@ -1 +1 @@
2.2.4
2.2.7

View File

@ -0,0 +1,7 @@
# Compile For x86_64
include("${CMAKE_CURRENT_LIST_DIR}/base-toolchain.cmake")
# Use x86_64 Cross-Compiler
setup_toolchain("x86_64-linux-gnu")
# Details
set(CMAKE_SYSTEM_NAME "Linux")
set(CMAKE_SYSTEM_PROCESSOR "x86_64")

View File

@ -1,11 +0,0 @@
# Compile For ARM
if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "aarch64_be" OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "armv8b" OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "armv8l")
# Force 32-Bit Compile
add_compile_options("-m32")
elseif(NOT CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "arm")
# Use ARM Cross-Compiler
include("${CMAKE_CURRENT_LIST_DIR}/base-toolchain.cmake")
setup_toolchain("arm-linux-gnueabihf")
endif()
set(CMAKE_SYSTEM_NAME "Linux")
set(CMAKE_SYSTEM_PROCESSOR "arm")

View File

@ -1,8 +1,7 @@
# Compile For ARM64
if(NOT (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "aarch64_be" OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "armv8b" OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "armv8l"))
# Use ARM64 Cross-Compiler
include("${CMAKE_CURRENT_LIST_DIR}/base-toolchain.cmake")
setup_toolchain("aarch64-linux-gnu")
endif()
include("${CMAKE_CURRENT_LIST_DIR}/base-toolchain.cmake")
# Use ARM64 Cross-Compiler
setup_toolchain("aarch64-linux-gnu")
# Details
set(CMAKE_SYSTEM_NAME "Linux")
set(CMAKE_SYSTEM_PROCESSOR "aarch64")

View File

@ -0,0 +1,7 @@
# Compile For ARM
include("${CMAKE_CURRENT_LIST_DIR}/base-toolchain.cmake")
# Use ARM Cross-Compiler
setup_toolchain("arm-linux-gnueabihf")
# Details
set(CMAKE_SYSTEM_NAME "Linux")
set(CMAKE_SYSTEM_PROCESSOR "arm")

View File

@ -1,16 +1,102 @@
# Pick GCC Version
macro(pick_gcc_version gcc_root gcc_version)
file(GLOB children RELATIVE "${gcc_root}" "${gcc_root}/*")
set("${gcc_version}" "")
foreach(child IN LISTS children)
if(IS_DIRECTORY "${gcc_root}/${child}" AND ("${${gcc_version}}" STREQUAL "" OR "${child}" GREATER_EQUAL "${${gcc_version}}"))
set("${gcc_version}" "${child}")
# Sanity Check Return
function(sanity_check_return ret)
if(NOT ret EQUAL "0")
message(FATAL_ERROR "Process Failed")
endif()
endfunction()
# Get Host Architecture
find_program(UNAME uname /bin /usr/bin /usr/local/bin REQUIRED)
execute_process(
COMMAND "${UNAME}" "-m"
OUTPUT_VARIABLE HOST_ARCHITECTURE
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE ret
)
sanity_check_return("${ret}")
# Get Include Directories
function(get_include_dirs target compiler result)
# Get Tool Name
set(tool "cc1")
if(compiler MATCHES "^.*g\\+\\+$")
set(tool "cc1plus")
endif()
# Get Tool Path
execute_process(
COMMAND "${compiler}" "-print-prog-name=${tool}"
ERROR_QUIET
OUTPUT_VARIABLE tool
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE ret
)
sanity_check_return("${ret}")
# Run Tool To Get Include Path
set(tool_output "")
execute_process(
COMMAND "${tool}" "-quiet" "-v" "-imultiarch" "${target}"
OUTPUT_QUIET
ERROR_VARIABLE tool_output
ERROR_STRIP_TRAILING_WHITESPACE
INPUT_FILE "/dev/null"
RESULT_VARIABLE ret
)
sanity_check_return("${ret}")
string(REPLACE "\n" ";" tool_output "${tool_output}")
# Loop
set(parsing_include_section FALSE)
foreach(line IN LISTS tool_output)
# Check Include Section Status
if(parsing_include_section)
# Check If Include Section Is Over
if(line MATCHES "^End of search list.$")
# Starting Include Section
set(parsing_include_section FALSE)
break()
else()
# Parsing Include Section
if(line MATCHES "^ .*$")
# Strip Line
string(STRIP "${line}" line)
# Add To List
list(APPEND "${result}" "${line}")
endif()
endif()
else()
# Check If Include Section Is Starting
if(line MATCHES "^#include <\\.\\.\\.> search starts here:$")
# Starting Include Section
set(parsing_include_section TRUE)
endif()
endif()
endforeach()
if("${${gcc_version}}" STREQUAL "")
message(FATAL_ERROR "Unable To Pick GCC Version")
endif()
endmacro()
# Return
set("${result}" "${${result}}" PARENT_SCOPE)
endfunction()
# Setup Include Directories
function(setup_include_dirs compiler target result)
# Get Full Compiler
set(full_compiler "${target}-${compiler}")
# Get Include Directories
set(include_dirs "")
get_include_dirs("${target}" "${full_compiler}" include_dirs)
# Loop
set(flags "")
foreach(include_dir IN LISTS include_dirs)
set(flags "${flags} -isystem ${include_dir}")
endforeach()
# Return
set("${result}" "${${result}} ${flags}" PARENT_SCOPE)
endfunction()
# Setup Toolchain
macro(setup_toolchain target)
@ -20,20 +106,17 @@ macro(setup_toolchain target)
set(CMAKE_CXX_COMPILER "clang++")
set(CMAKE_CXX_COMPILER_TARGET "${target}")
set(CMAKE_FIND_ROOT_PATH "/usr/${target}" "/usr/lib/${target}")
# Include Directories
pick_gcc_version("/usr/lib/gcc-cross/${target}" GCC_VERSION)
# Flags
string(CONCAT NEW_FLAGS
"-nostdinc -nostdinc++ -Wno-unused-command-line-argument "
"-isystem /usr/${target}/include/c++/${GCC_VERSION} "
"-isystem /usr/${target}/include/c++/${GCC_VERSION}/${target} "
"-isystem /usr/${target}/include/c++/${GCC_VERSION}/backward "
"-isystem /usr/lib/gcc-cross/${target}/${GCC_VERSION}/include "
"-isystem /usr/lib/gcc-cross/${target}/${GCC_VERSION}/include-fixed "
"-isystem /usr/${target}/include "
"-isystem /usr/include"
"-nostdinc "
"-nostdinc++ "
"-Wno-unused-command-line-argument"
)
set(CMAKE_C_FLAGS_INIT "${CMAKE_C_FLAGS_INIT} ${NEW_FLAGS}")
set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} ${NEW_FLAGS}")
# Include Directories
setup_include_dirs("gcc" "${target}" CMAKE_C_FLAGS_INIT)
setup_include_dirs("g++" "${target}" CMAKE_CXX_FLAGS_INIT)
# Extra
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
endmacro()

View File

@ -0,0 +1,9 @@
# Warning
message(WARNING "i686 Builds Are Unsupported, Proceed At Your Own Risk")
# Compile For i686
include("${CMAKE_CURRENT_LIST_DIR}/base-toolchain.cmake")
# Use i686 Cross-Compiler
setup_toolchain("i686-linux-gnu")
# Details
set(CMAKE_SYSTEM_NAME "Linux")
set(CMAKE_SYSTEM_PROCESSOR "i686")

View File

@ -1,8 +0,0 @@
# Compile For x86_64
if(NOT CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64")
# Use x86_64 Cross-Compiler
include("${CMAKE_CURRENT_LIST_DIR}/base-toolchain.cmake")
setup_toolchain("x86_64-linux-gnu")
endif()
set(CMAKE_SYSTEM_NAME "Linux")
set(CMAKE_SYSTEM_PROCESSOR "x86_64")

View File

@ -1,28 +1,20 @@
project(libpng)
include(FetchContent)
# Silence Warnings
add_compile_options(-w)
## LibPNG
# Download
set(SKIP_INSTALL_ALL TRUE) # Skip Default LibPNG Installation
FetchContent_Declare(
libpng
GIT_REPOSITORY "https://github.com/glennrp/libpng.git"
GIT_TAG "v1.2.59"
)
FetchContent_Populate(libpng)
set(ZLIB_LIBRARY zlib)
set(ZLIB_INCLUDE_DIR "${zlib_SOURCE_DIR}" "${zlib_BINARY_DIR}")
set(ZLIB_LIBRARY zlibstatic)
set(ZLIB_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../zlib/src" "${CMAKE_CURRENT_BINARY_DIR}/../zlib/src")
set(CMAKE_POLICY_DEFAULT_CMP0054 OLD) # Silence Warning
add_subdirectory("${libpng_SOURCE_DIR}" "${libpng_BINARY_DIR}")
add_subdirectory(src EXCLUDE_FROM_ALL)
set(CMAKE_POLICY_DEFAULT_CMP0054 NEW) # Re-Enable New Behavior
set_target_properties(png12 PROPERTIES LINK_FLAGS "-Wl,--version-script='${CMAKE_CURRENT_SOURCE_DIR}/libpng.vers'") # Use Symbol Versioning
set_target_properties(png12 PROPERTIES LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/libpng.vers") # Use Symbol Versioning
set_target_properties(png12 PROPERTIES DEBUG_POSTFIX "") # Fix LibPNG Suffix In Debug Mode
# Ensure Build
add_custom_target(png12-build ALL DEPENDS png12)
# Install
install(TARGETS png12 DESTINATION "${MCPI_LIB_DIR}")

1
dependencies/libpng/src vendored Submodule

@ -0,0 +1 @@
Subproject commit 5bb5bf345aef1e62adcfe30791f4364730a2aede

View File

@ -13,4 +13,3 @@ FetchContent_Populate(minecraft-pi)
# Install
install(DIRECTORY "${minecraft-pi_SOURCE_DIR}/" DESTINATION "${MCPI_INSTALL_DIR}" USE_SOURCE_PERMISSIONS)

View File

@ -1,23 +1,12 @@
project(zlib)
include(FetchContent)
# Silence Warnings
add_compile_options(-w)
## zlib
# Download
set(SKIP_INSTALL_ALL TRUE) # Skip Default ZLib Installation
FetchContent_Declare(
zlib
GIT_REPOSITORY "https://github.com/madler/zlib.git"
GIT_TAG "v1.2.11"
)
FetchContent_Populate(zlib)
include_directories("${zlib_SOURCE_DIR}" "${zlib_BINARY_DIR}") # Fix ZLib Build
add_subdirectory("${zlib_SOURCE_DIR}" "${zlib_BINARY_DIR}")
# Install
install(TARGETS zlib DESTINATION "${MCPI_LIB_DIR}")
add_subdirectory(src EXCLUDE_FROM_ALL)
# Ensure Build
add_custom_target(zlib-build ALL DEPENDS zlibstatic)

1
dependencies/zlib/src vendored Submodule

@ -0,0 +1 @@
Subproject commit cacf7f1d4e3d44d871b605da3b647f07d718623f

View File

@ -1,5 +1,18 @@
# Changelog
**2.2.7**
* Fix Crash When OpenAL Is Unavailable
* Fix Command Input In Server
**2.2.5**
* Fix Bug In Texture Scaling Code
**2.2.5**
* Scale Animated Textures
* Add More Blocks To Expanded Creative Inventory
* Reduce Unnecessary Logging
* Log IPs In Server Mode
**2.2.4**
* Instead Of Crashing, Disable Polling Block Hits In Survival Mode Using The API
@ -11,7 +24,7 @@
* Make Missing Sound Event Cause Warning Rather Than Crash
**2.2.1**
* Prevent `random.burp` Sound From Crashing Game
* Prevent ``random.burp`` Sound From Crashing Game
* Always Cleanup Media Layer, Even On Crash
* Resolve All Sounds On Startup
@ -19,7 +32,7 @@
* Sound Support
* Split Off "Allow Joining Survival Servers" From Game-Mode Mod
* Separate Headless Code From Server Code
* Fix Bug Where `RakNetInstance` Starts Pinging Potential Servers Before The "Join Game" Screen Is Opened
* Fix Bug Where ``RakNetInstance`` Starts Pinging Potential Servers Before The "Join Game" Screen Is Opened
* Clean-Up Code
* Remove Support For Debian Buster
@ -36,7 +49,7 @@
* Print Error Message If RakNet Fails To Start
**2.1.4**
* Fix RakNet::RakString Security Bug
* Fix ``RakNet::RakString`` Security Bug
**2.1.3**
* Workaround Broken Library Search Path On Some ARM 32-Bit Systems
@ -74,7 +87,7 @@
* Optimize Media Layer Proxy
**2.0.3**
* Make "kill" Admin Command Print Death Message
* Make ``kill`` Admin Command Print Death Message
**2.0.2**
* Fix Mouse Cursor Bugs

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 31 KiB

View File

@ -25,90 +25,96 @@ static std::vector<ALuint> &get_sources() {
// Update Listener
void media_audio_update(float volume, float x, float y, float z, float yaw) {
// Update Listener Volume
alListenerf(AL_GAIN, volume);
AL_ERROR_CHECK();
// Check
if (_media_audio_is_loaded()) {
// Update Listener Volume
alListenerf(AL_GAIN, volume);
AL_ERROR_CHECK();
// Update Listener Position
alListener3f(AL_POSITION, x, y, z);
AL_ERROR_CHECK();
// Update Listener Position
alListener3f(AL_POSITION, x, y, z);
AL_ERROR_CHECK();
// Update Listener Orientation
float radian_yaw = yaw * (M_PI / 180);
ALfloat orientation[] = {-sinf(radian_yaw), 0.0f, cosf(radian_yaw), 0.0f, 1.0f, 0.0f};
alListenerfv(AL_ORIENTATION, orientation);
AL_ERROR_CHECK();
// Update Listener Orientation
float radian_yaw = yaw * (M_PI / 180);
ALfloat orientation[] = {-sinf(radian_yaw), 0.0f, cosf(radian_yaw), 0.0f, 1.0f, 0.0f};
alListenerfv(AL_ORIENTATION, orientation);
AL_ERROR_CHECK();
// Clear Finished Sources
std::vector<ALuint>::iterator it = get_sources().begin();
while (it != get_sources().end()) {
ALuint source = *it;
bool remove = false;
// Check
if (source && alIsSource(source)) {
// Is Valid Source
ALint source_state;
alGetSourcei(source, AL_SOURCE_STATE, &source_state);
AL_ERROR_CHECK();
if (source_state != AL_PLAYING) {
// Finished Playing
remove = true;
alDeleteSources(1, &source);
// Clear Finished Sources
std::vector<ALuint>::iterator it = get_sources().begin();
while (it != get_sources().end()) {
ALuint source = *it;
bool remove = false;
// Check
if (source && alIsSource(source)) {
// Is Valid Source
ALint source_state;
alGetSourcei(source, AL_SOURCE_STATE, &source_state);
AL_ERROR_CHECK();
if (source_state != AL_PLAYING) {
// Finished Playing
remove = true;
alDeleteSources(1, &source);
AL_ERROR_CHECK();
}
} else {
// Not A Source
remove = true;
}
// Remove If Needed
if (remove) {
it = get_sources().erase(it);
} else {
++it;
}
} else {
// Not A Source
remove = true;
}
// Remove If Needed
if (remove) {
it = get_sources().erase(it);
} else {
++it;
}
}
}
void media_audio_play(const char *source, const char *name, float x, float y, float z, float pitch, float volume, int is_ui) {
// Load Sound
ALuint buffer = _media_audio_get_buffer(source, name);
if (volume > 0.0f && buffer) {
// Create Source
ALuint al_source;
alGenSources(1, &al_source);
AL_ERROR_CHECK();
// Check
if (_media_audio_is_loaded()) {
// Load Sound
ALuint buffer = _media_audio_get_buffer(source, name);
if (volume > 0.0f && buffer) {
// Create Source
ALuint al_source;
alGenSources(1, &al_source);
AL_ERROR_CHECK();
// Set Properties
alSourcef(al_source, AL_PITCH, pitch);
AL_ERROR_CHECK();
alSourcef(al_source, AL_GAIN, volume);
AL_ERROR_CHECK();
alSource3f(al_source, AL_POSITION, x, y, z);
AL_ERROR_CHECK();
alSource3f(al_source, AL_VELOCITY, 0, 0, 0);
AL_ERROR_CHECK();
alSourcei(al_source, AL_LOOPING, AL_FALSE);
AL_ERROR_CHECK();
alSourcei(al_source, AL_SOURCE_RELATIVE, is_ui ? AL_TRUE : AL_FALSE);
AL_ERROR_CHECK();
// Set Properties
alSourcef(al_source, AL_PITCH, pitch);
AL_ERROR_CHECK();
alSourcef(al_source, AL_GAIN, volume);
AL_ERROR_CHECK();
alSource3f(al_source, AL_POSITION, x, y, z);
AL_ERROR_CHECK();
alSource3f(al_source, AL_VELOCITY, 0, 0, 0);
AL_ERROR_CHECK();
alSourcei(al_source, AL_LOOPING, AL_FALSE);
AL_ERROR_CHECK();
alSourcei(al_source, AL_SOURCE_RELATIVE, is_ui ? AL_TRUE : AL_FALSE);
AL_ERROR_CHECK();
// Set Attenuation
alSourcei(al_source, AL_DISTANCE_MODEL, AL_LINEAR_DISTANCE);
AL_ERROR_CHECK();
alSourcef(al_source, AL_MAX_DISTANCE, 16.0f);
AL_ERROR_CHECK();
alSourcef(al_source, AL_ROLLOFF_FACTOR, 1.0f);
AL_ERROR_CHECK();
alSourcef(al_source, AL_REFERENCE_DISTANCE, 0.0f);
AL_ERROR_CHECK();
// Set Attenuation
alSourcei(al_source, AL_DISTANCE_MODEL, AL_LINEAR_DISTANCE);
AL_ERROR_CHECK();
alSourcef(al_source, AL_MAX_DISTANCE, 16.0f);
AL_ERROR_CHECK();
alSourcef(al_source, AL_ROLLOFF_FACTOR, 1.0f);
AL_ERROR_CHECK();
alSourcef(al_source, AL_REFERENCE_DISTANCE, 0.0f);
AL_ERROR_CHECK();
// Set Buffer
alSourcei(al_source, AL_BUFFER, buffer);
AL_ERROR_CHECK();
// Set Buffer
alSourcei(al_source, AL_BUFFER, buffer);
AL_ERROR_CHECK();
// Play
alSourcePlay(al_source);
AL_ERROR_CHECK();
get_sources().push_back(al_source);
// Play
alSourcePlay(al_source);
AL_ERROR_CHECK();
get_sources().push_back(al_source);
}
}
}

View File

@ -76,6 +76,10 @@ static SDLKey glfw_key_to_sdl_key(int key) {
return SDLK_7;
case GLFW_KEY_8:
return SDLK_8;
case GLFW_KEY_9:
return SDLK_9;
case GLFW_KEY_0:
return SDLK_0;
// UI Control
case GLFW_KEY_ESCAPE:
return SDLK_ESCAPE;

View File

@ -7,6 +7,7 @@ extern "C" {
#define GL_FALSE 0
#define GL_FOG_COLOR 0xb66
#define GL_ARRAY_BUFFER_BINDING 0x8894
#define GL_TEXTURE_BINDING_2D 0x8069
#define GL_UNSIGNED_BYTE 0x1401
#define GL_RGB 0x1907
#define GL_RGBA 0x1908

View File

@ -114,8 +114,8 @@ typedef struct SDL_JoyButtonEvent {
typedef struct SDL_ResizeEvent {
uint8_t type;
int w;
int h;
int32_t w;
int32_t h;
} SDL_ResizeEvent;
typedef struct SDL_ExposeEvent {
@ -128,14 +128,14 @@ typedef struct SDL_QuitEvent {
typedef struct SDL_UserEvent {
uint8_t type;
int code;
void *data1;
void *data2;
int32_t code;
uint32_t data1;
uint32_t data2;
} SDL_UserEvent;
typedef struct SDL_SysWMEvent {
uint8_t type;
void *msg;
uint32_t msg;
} SDL_SysWMEvent;
typedef union SDL_Event {

View File

@ -1099,6 +1099,7 @@ CALL(58, glIsEnabled, GLboolean, (GLenum cap)) {
static int get_glGetIntegerv_params_size(GLenum pname) {
switch (pname) {
case GL_TEXTURE_BINDING_2D:
case GL_UNPACK_ALIGNMENT: {
return 1;
}

View File

@ -9,116 +9,6 @@
#include "common/common.h"
// Read/Write SDL Events
static void write_SDL_Event(SDL_Event event) {
// Write EVent Type
write_int(event.type);
// Write Event Details
switch (event.type) {
// Focus Event
case SDL_ACTIVEEVENT: {
write_int(event.active.gain);
write_int(event.active.state);
break;
}
// Key Press Events
case SDL_KEYDOWN:
case SDL_KEYUP: {
write_int(event.key.state);
write_int(event.key.keysym.scancode);
write_int(event.key.keysym.sym);
write_int(event.key.keysym.mod);
write_int(event.key.keysym.unicode);
break;
}
// Mouse Motion Event
case SDL_MOUSEMOTION: {
write_int(event.motion.state);
write_int(event.motion.x);
write_int(event.motion.y);
write_int(event.motion.xrel);
write_int(event.motion.yrel);
break;
}
// Mouse Press Events
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP: {
write_int(event.button.button);
write_int(event.button.state);
write_int(event.button.x);
write_int(event.button.y);
break;
}
// User-Specified Event (Repurposed As Unicode Character Event)
case SDL_USEREVENT: {
write_int(event.user.code);
break;
}
}
}
static SDL_Event read_SDL_Event() {
// Create Event
SDL_Event event;
event.type = read_int();
// Read Event Details
switch (event.type) {
// Focus Event
case SDL_ACTIVEEVENT: {
event.active.gain = read_int();
event.active.state = read_int();
break;
}
// Key Press Events
case SDL_KEYDOWN:
case SDL_KEYUP: {
event.key.state = read_int();
event.key.keysym.scancode = read_int();
event.key.keysym.sym = read_int();
event.key.keysym.mod = read_int();
event.key.keysym.unicode = read_int();
break;
}
// Mouse Motion Event
case SDL_MOUSEMOTION: {
event.motion.state = read_int();
event.motion.x = read_int();
event.motion.y = read_int();
event.motion.xrel = read_int();
event.motion.yrel = read_int();
break;
}
// Mouse Press Events
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP: {
event.button.button = read_int();
event.button.state = read_int();
event.button.x = read_int();
event.button.y = read_int();
break;
}
// Quit Event
case SDL_QUIT: {
break;
}
// User-Specified Event (Repurposed As Unicode Character Event)
case SDL_USEREVENT: {
event.user.code = read_int();
break;
}
// Unsupported Event
default: {
INFO("Unsupported SDL Event: %u", event.type);
}
}
// Return
#pragma GCC diagnostic push
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
return event;
#pragma GCC diagnostic pop
}
// SDL Functions
CALL(0, SDL_Init, int, (uint32_t flags)) {
@ -156,7 +46,7 @@ CALL(1, SDL_PollEvent, int, (SDL_Event *event)) {
// Get Return Value
int32_t ret = (int32_t) read_int();
if (ret) {
*event = read_SDL_Event();
safe_read((void *) event, sizeof (SDL_Event));
}
// Release Proxy
@ -171,7 +61,7 @@ CALL(1, SDL_PollEvent, int, (SDL_Event *event)) {
// Return Values
write_int(ret);
if (ret) {
write_SDL_Event(event);
safe_write((void *) &event, sizeof (SDL_Event));
}
#endif
}
@ -182,7 +72,7 @@ CALL(2, SDL_PushEvent, int, (SDL_Event *event)) {
start_proxy_call();
// Arguments
write_SDL_Event(*event);
safe_write((void *) event, sizeof (SDL_Event));
// Get Return Value
int32_t ret = (int32_t) read_int();
@ -193,7 +83,8 @@ CALL(2, SDL_PushEvent, int, (SDL_Event *event)) {
// Return Value
return ret;
#else
SDL_Event event = read_SDL_Event();
SDL_Event event;
safe_read((void *) &event, sizeof (SDL_Event));
// Run
int ret = SDL_PushEvent(&event);
// Return Value

View File

@ -54,7 +54,7 @@ else()
target_link_libraries(override reborn symbols dl home)
add_library(textures SHARED src/textures/textures.cpp)
target_link_libraries(textures reborn symbols feature)
target_link_libraries(textures reborn symbols media-layer-core feature)
add_library(atlas SHARED src/atlas/atlas.cpp)
target_link_libraries(atlas reborn symbols feature GLESv1_CM)

View File

@ -15,10 +15,10 @@ static float ItemRenderer_renderGuiItemCorrect_injection(unsigned char *font, un
bool use_carried = false;
if (item_instance != NULL) {
if (item_instance->id == leaves_id) {
(*ItemInstance_constructor_tile_extra)(&carried_item_instance, *Tile_leaves_carried, item_instance->count, item_instance->auxilary);
(*ItemInstance_constructor_tile_extra)(&carried_item_instance, *Tile_leaves_carried, item_instance->count, item_instance->auxiliary);
use_carried = true;
} else if (item_instance->id == grass_id) {
(*ItemInstance_constructor_tile_extra)(&carried_item_instance, *Tile_grass_carried, item_instance->count, item_instance->auxilary);
(*ItemInstance_constructor_tile_extra)(&carried_item_instance, *Tile_grass_carried, item_instance->count, item_instance->auxiliary);
use_carried = true;
}
}

View File

@ -71,7 +71,7 @@ static void CommandServer_parse_CommandServer_dispatchPacket_injection(unsigned
}
// Handle ChatPacket Server-Side
static void ServerSideNetworkHandler_handle_ChatPacket_injection(unsigned char *server_side_network_handler, unsigned char *rak_net_guid, unsigned char *chat_packet) {
static void ServerSideNetworkHandler_handle_ChatPacket_injection(unsigned char *server_side_network_handler, RakNet_RakNetGUID *rak_net_guid, unsigned char *chat_packet) {
unsigned char *player = (*ServerSideNetworkHandler_getPlayer)(server_side_network_handler, rak_net_guid);
if (player != NULL) {
char *username = *(char **) (player + Player_username_property_offset);

View File

@ -44,6 +44,9 @@ static int32_t Inventory_setupDefault_FillingContainer_addItem_call_injection(un
inventory_add_item(filling_container, *Tile_topSnow, true);
inventory_add_item(filling_container, *Tile_ice, true);
inventory_add_item(filling_container, *Tile_invisible_bedrock, true);
inventory_add_item(filling_container, *Tile_bedrock, true);
inventory_add_item(filling_container, *Tile_info_updateGame1, true);
inventory_add_item(filling_container, *Tile_info_updateGame2, true);
return ret;
}

View File

@ -29,7 +29,7 @@ int feature_has(const char *name, int server_default) {
tok = strtok(NULL, "|");
}
free(features);
#ifndef MCPI_SERVER_MODE
#ifdef DEBUG
INFO("Feature: %s: %s", name, ret ? "Enabled" : "Disabled");
#endif
return ret;

View File

@ -13,16 +13,13 @@
#define NEW_PATH ""
// Store Launch Directory
static char *get_launch_directory() {
__attribute__((constructor)) static char *get_launch_directory() {
static char *launch_directory = NULL;
if (launch_directory == NULL) {
launch_directory = getcwd(NULL, 0);
}
return launch_directory;
}
__attribute__((constructor)) static void init_launch_directory() {
get_launch_directory();
}
__attribute__((destructor)) static void free_launch_directory() {
free(get_launch_directory());
}

View File

@ -33,6 +33,7 @@ static int32_t MouseBuildInput_tickBuild_injection(unsigned char *mouse_build_in
is_left_click = 2;
}
// Return
return ret;
}

View File

@ -14,7 +14,7 @@ void input_set_is_right_click(int val) {
static int fix_bow = 0;
// Handle Bow & Arrow
void _handle_bow(unsigned char *minecraft) {
static void _handle_bow(unsigned char *minecraft) {
if (fix_bow && !is_right_click) {
// GameMode Is Offset From minecraft By 0x160
// Player Is Offset From minecraft By 0x18c
@ -32,4 +32,5 @@ void _handle_bow(unsigned char *minecraft) {
void _init_bow() {
// Enable Bow & Arrow Fix
fix_bow = feature_has("Fix Bow & Arrow", 0);
input_run_on_tick(_handle_bow);
}

View File

@ -21,7 +21,7 @@ void input_drop(int drop_slot) {
}
// Handle Drop Item Presses
void _handle_drop(unsigned char *minecraft) {
static void _handle_drop(unsigned char *minecraft) {
if (!(*Minecraft_isCreativeMode)(minecraft) && (drop_item_presses > 0 || drop_slot_pressed)) {
// Get Player
unsigned char *player = *(unsigned char **) (minecraft + Minecraft_player_property_offset);
@ -85,4 +85,5 @@ void _handle_drop(unsigned char *minecraft) {
// Init
void _init_drop() {
enable_drop = feature_has("Bind \"Q\" Key To Item Dropping", 0);
input_run_on_tick(_handle_drop);
}

View File

@ -21,21 +21,6 @@ static void Minecraft_tickInput_injection(unsigned char *minecraft) {
// Call Original Method
(*Minecraft_tickInput)(minecraft);
// Handle Bow
_handle_bow(minecraft);
// Handle Toggle Options
_handle_toggle_options(minecraft);
// Set Mouse Grab State
_handle_mouse_grab(minecraft);
// Handle Back Button
_handle_back(minecraft);
// Handle Item Drops
_handle_drop(minecraft);
// Run Input Tick Functions
for (input_tick_function_t function : get_input_tick_functions()) {
(*function)(minecraft);

View File

@ -19,14 +19,9 @@ void input_set_mouse_grab_state(int state);
__attribute__((visibility("internal"))) void _init_attack();
__attribute__((visibility("internal"))) void _init_bow();
__attribute__((visibility("internal"))) void _handle_bow(unsigned char *minecraft);
__attribute__((visibility("internal"))) void _handle_toggle_options(unsigned char *minecraft);
__attribute__((visibility("internal"))) void _init_misc();
__attribute__((visibility("internal"))) void _init_toggle();
__attribute__((visibility("internal"))) void _handle_mouse_grab(unsigned char *minecraft);
__attribute__((visibility("internal"))) void _handle_back(unsigned char *minecraft);
__attribute__((visibility("internal"))) void _init_drop();
__attribute__((visibility("internal"))) void _handle_drop(unsigned char *minecraft);
#ifdef __cplusplus
}

View File

@ -19,7 +19,7 @@ int input_back() {
}
// Handle Back Button Presses
void _handle_back(unsigned char *minecraft) {
static void _handle_back(unsigned char *minecraft) {
unsigned char *minecraft_vtable = *(unsigned char **) minecraft;
Minecraft_handleBack_t Minecraft_handleBack = *(Minecraft_handleBack_t *) (minecraft_vtable + Minecraft_handleBack_vtable_offset);
for (int i = 0; i < back_button_presses; i++) {
@ -44,7 +44,7 @@ void input_set_mouse_grab_state(int state) {
}
// Grab/Un-Grab Mouse
void _handle_mouse_grab(unsigned char *minecraft) {
static void _handle_mouse_grab(unsigned char *minecraft) {
if (mouse_grab_state == -1) {
// Grab
(*Minecraft_grabMouse)(minecraft);
@ -88,4 +88,6 @@ void _init_misc() {
// Disable Opening Inventory Using The Cursor When Cursor Is Hidden
overwrite_calls((void *) Gui_handleClick, (void *) Gui_handleClick_injection);
}
input_run_on_tick(_handle_back);
input_run_on_tick(_handle_mouse_grab);
}

View File

@ -18,7 +18,7 @@ void input_third_person() {
}
// Handle Toggle Options
void _handle_toggle_options(unsigned char *minecraft) {
static void _handle_toggle_options(unsigned char *minecraft) {
if (enable_toggles) {
// Handle Functions
unsigned char *options = minecraft + Minecraft_options_property_offset;
@ -38,4 +38,5 @@ void _handle_toggle_options(unsigned char *minecraft) {
// Init
void _init_toggle() {
enable_toggles = feature_has("Bind Common Toggleable Options To Function Keys", 0);
input_run_on_tick(_handle_toggle_options);
}

View File

@ -100,20 +100,22 @@ void init_options() {
}
patch_address((void *) default_username, (void *) username);
// Disable Autojump By Default
if (feature_has("Disable Autojump By Default", 0)) {
// Disable Autojump By Default
unsigned char autojump_patch[4] = {0x00, 0x30, 0xa0, 0xe3}; // "mov r3, #0x0"
patch((void *) 0x44b90, autojump_patch);
}
// Display Nametags By Default
if (feature_has("Display Nametags By Default", 0)) {
// Display Nametags By Default
// r6 = 0x1
// r5 = 0x0
unsigned char display_nametags_patch[4] = {0x1d, 0x60, 0xc0, 0xe5}; // "strb r6, [r0, #0x1d]"
patch((void *) 0xa6628, display_nametags_patch);
}
// Enable Smooth Lighting
smooth_lighting = feature_has("Smooth Lighting", 0);
if (smooth_lighting) {
// Enable Smooth Lighting
unsigned char smooth_lighting_patch[4] = {0x01, 0x00, 0x53, 0xe3}; // "cmp r3, #0x1"
patch((void *) 0x59ea4, smooth_lighting_patch);
}

View File

@ -198,16 +198,20 @@ static unsigned char *get_rak_peer(unsigned char *minecraft) {
unsigned char *rak_net_instance = *(unsigned char **) (minecraft + Minecraft_rak_net_instance_property_offset);
return *(unsigned char **) (rak_net_instance + RakNetInstance_peer_property_offset);
}
// Get IP From Player
static char *get_player_ip(unsigned char *minecraft, unsigned char *player) {
RakNet_RakNetGUID guid = get_rak_net_guid(player);
unsigned char *rak_peer = get_rak_peer(minecraft);
static char *get_rak_net_guid_ip(unsigned char *rak_peer, RakNet_RakNetGUID guid) {
RakNet_SystemAddress address = get_system_address(rak_peer, guid);
// Get IP
return (*RakNet_SystemAddress_ToString)(&address, false, '|');
}
// Get IP From Player
static char *get_player_ip(unsigned char *minecraft, unsigned char *player) {
unsigned char *rak_peer = get_rak_peer(minecraft);
RakNet_RakNetGUID guid = get_rak_net_guid(player);
// Return
return get_rak_net_guid_ip(rak_peer,guid);
}
// Ban Player
static void ban_callback(unsigned char *minecraft, std::string username, unsigned char *player) {
// Get IP
@ -275,25 +279,33 @@ static unsigned char *get_server_side_network_handler(unsigned char *minecraft)
static volatile bool stdin_buffer_complete = false;
static volatile char *stdin_buffer = NULL;
static void *read_stdin_thread(__attribute__((unused)) void *data) {
while (1) {
if (!stdin_buffer_complete) {
int x = getchar();
if (x != EOF) {
if (x == '\n') {
if (stdin_buffer == NULL) {
stdin_buffer = strdup("");
// Check If STDIN Is A TTY
if (isatty(fileno(stdin))) {
// Loop
while (1) {
if (!stdin_buffer_complete) {
// Read Data
int x = fgetc(stdin);
if (x != EOF) {
if (x == '\n') {
if (stdin_buffer == NULL) {
stdin_buffer = strdup("");
}
stdin_buffer_complete = true;
} else {
string_append((char **) &stdin_buffer, "%c", (char) x);
}
stdin_buffer_complete = true;
} else {
string_append((char **) &stdin_buffer, "%c", (char) x);
}
}
}
}
return NULL;
}
__attribute__((destructor)) static void _free_stdin_buffer() {
free((void *) stdin_buffer);
stdin_buffer = NULL;
if (stdin_buffer != NULL) {
free((void *) stdin_buffer);
stdin_buffer = NULL;
}
}
// Handle Commands
@ -385,6 +397,7 @@ static void Minecraft_update_injection(unsigned char *minecraft) {
handle_server_stop(minecraft);
}
// Ban Players
static bool RakNet_RakPeer_IsBanned_injection(__attribute__((unused)) unsigned char *rakpeer, const char *ip) {
// Check banned-ips.txt
std::string blacklist_file_path = get_blacklist_file();
@ -420,6 +433,27 @@ static bool RakNet_RakPeer_IsBanned_injection(__attribute__((unused)) unsigned c
}
}
// Log IPs
static unsigned char *ServerSideNetworkHandler_onReady_ClientGeneration_ServerSideNetworkHandler_popPendingPlayer_injection(unsigned char *server_side_network_handler, RakNet_RakNetGUID *guid) {
// Call Original Method
unsigned char *player = (*ServerSideNetworkHandler_popPendingPlayer)(server_side_network_handler, guid);
// Check If Player Is Null
if (player != NULL) {
// Get Data
char *username = (char *) *(unsigned char **) (player + Player_username_property_offset);
unsigned char *minecraft = *(unsigned char **) (server_side_network_handler + ServerSideNetworkHandler_minecraft_property_offset);
unsigned char *rak_peer = get_rak_peer(minecraft);
char *ip = get_rak_net_guid_ip(rak_peer, *guid);
// Log
INFO("%s Has Joined (IP: %s)", username, ip);
}
// Return
return player;
}
// Get MOTD
static std::string get_motd() {
std::string motd(get_server_properties().get_string("motd", DEFAULT_MOTD));
@ -532,6 +566,9 @@ static void server_init() {
patch((void *) 0x737e4, minecon_badge_patch);
}
// Log IPs
overwrite_call((void *) 0x75e54, (void *) ServerSideNetworkHandler_onReady_ClientGeneration_ServerSideNetworkHandler_popPendingPlayer_injection);
// Start Reading STDIN
pthread_t read_stdin_thread_obj;
pthread_create(&read_stdin_thread_obj, NULL, read_stdin_thread, NULL);

View File

@ -1,3 +1,9 @@
#include <vector>
#include <assert.h>
#include <cstdint>
#include <GLES/gl.h>
#include <libreborn/libreborn.h>
#include <symbols/minecraft.h>
@ -16,10 +22,154 @@ static void Minecraft_tick_injection(unsigned char *minecraft, int32_t param_1,
}
}
// Store Texture Sizes
struct texture_data {
GLint id;
GLsizei width;
GLsizei height;
};
static std::vector<texture_data> &get_texture_data() {
static std::vector<texture_data> data;
return data;
}
HOOK(glTexImage2D, void, (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels)) {
// Store
texture_data data;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &data.id);
data.width = width;
data.height = height;
get_texture_data().push_back(data);
// Call Original Method
ensure_glTexImage2D();
(*real_glTexImage2D)(target, level, internalformat, width, height, border, format, type, pixels);
}
HOOK(glDeleteTextures, void, (GLsizei n, const GLuint *textures)) {