diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 9fd580722b..5c58d95d2b 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -50,6 +50,7 @@ * `Render Entity Shadows` (Enabled By Default) * `Render Vignette` (Enabled By Default) * `Increase Render Chunk Size` (Enabled By Default) + * `Proper Entity Shading` (Enabled By Default) * Existing Functionality (All Enabled By Default) * `Fix Screen Rendering When Hiding HUD` * `Sanitize Usernames` diff --git a/mods/src/death/death.cpp b/mods/src/death/death.cpp index 2c80478369..913a1a849e 100644 --- a/mods/src/death/death.cpp +++ b/mods/src/death/death.cpp @@ -71,7 +71,7 @@ static bool Mob_hurt_injection(Mob_hurt_t original, Mob *mob, Entity *source, co // Death Message Logic template -static void Player_die_injection(std::function original, Self *player, Entity *cause) { +static void Player_die_injection(const std::function &original, Self *player, Entity *cause) { // Call Original Method original((ParentSelf *) player, cause); @@ -88,7 +88,7 @@ static void Player_die_injection(std::function ori } } template -static void Player_actuallyHurt_injection(std::function original, Self *player, int32_t damage) { +static void Player_actuallyHurt_injection(const std::function &original, Self *player, int32_t damage) { // Store Old Health int32_t old_health = player->health; diff --git a/mods/src/misc/graphics.cpp b/mods/src/misc/graphics.cpp index a61b20a6e0..42e2ff9458 100644 --- a/mods/src/misc/graphics.cpp +++ b/mods/src/misc/graphics.cpp @@ -276,7 +276,12 @@ static void EntityRenderDispatcher_render_EntityRenderer_render_injection(Entity } // Render Fire if (should_render_fire) { + const bool was_lighting_enabled = glIsEnabled(GL_LIGHTING); + glDisable(GL_LIGHTING); render_fire(self, entity, x, y, z); + if (was_lighting_enabled) { + glEnable(GL_LIGHTING); + } } } diff --git a/mods/src/misc/misc.cpp b/mods/src/misc/misc.cpp index 516027ea89..31d57d5498 100644 --- a/mods/src/misc/misc.cpp +++ b/mods/src/misc/misc.cpp @@ -406,7 +406,7 @@ static void set_on_fire(Mob *mob, const int seconds) { } } template -static void Monster_aiStep_injection(__attribute__((unused)) std::function original, Self *self) { +static void Monster_aiStep_injection(__attribute__((unused)) const std::function &original, Self *self) { // Fire! Level *level = self->level; if (level->isDay() && !level->is_client_side) { diff --git a/mods/src/misc/tinting.cpp b/mods/src/misc/tinting.cpp index 75926d6822..3f8762ae28 100644 --- a/mods/src/misc/tinting.cpp +++ b/mods/src/misc/tinting.cpp @@ -48,7 +48,7 @@ static int32_t TallGrass_getColor_injection(TallGrass_getColor_t original, TallG // No Block Tinting template -static int32_t Tile_getColor_injection(__attribute__((unused)) std::function original, __attribute__((unused)) T *self, __attribute__((unused)) LevelSource *level_source, __attribute__((unused)) int x, __attribute__((unused)) int y, __attribute__((unused)) int z) { +static int32_t Tile_getColor_injection(__attribute__((unused)) const std::function &original, __attribute__((unused)) T *self, __attribute__((unused)) LevelSource *level_source, __attribute__((unused)) int x, __attribute__((unused)) int y, __attribute__((unused)) int z) { return 0xffffff; } diff --git a/mods/src/shading/lighting.cpp b/mods/src/shading/lighting.cpp index b8da6aa8a2..ecff315de9 100644 --- a/mods/src/shading/lighting.cpp +++ b/mods/src/shading/lighting.cpp @@ -49,7 +49,75 @@ static void LevelRenderer_renderEntities_injection(LevelRenderer_renderEntities_ lighting_turn_off(); } +// Held Items +static void ItemInHandRenderer_render_glPopMatrix_injection() { + lighting_turn_on(); + glPopMatrix(); + glEnable(GL_RESCALE_NORMAL); +} +static void ItemInHandRenderer_render_injection(ItemInHandRenderer_render_t original, ItemInHandRenderer *self, float a) { + original(self, a); + lighting_turn_off(); + glDisable(GL_RESCALE_NORMAL); +} + +// GL_RESCALE_NORMAL +static void enable_rescale_normal() { + glPushMatrix(); + glEnable(GL_RESCALE_NORMAL); +} +static void disable_rescale_normal() { + glPopMatrix(); + glDisable(GL_RESCALE_NORMAL); +} +template +static void EntityRenderer_render_injection(const std::function &original, Self *self, Entity *entity, float x, float y, float z, float rot, float a) { + glEnable(GL_RESCALE_NORMAL); + original(self, entity, x, y, z, rot, a); + glDisable(GL_RESCALE_NORMAL); +} + +// Fix Falling Tile Rendering +static void FallingTileRenderer_render_TileRenderer_renderBlock_injection(TileRenderer *self, Tile *tile, LevelSource *level, int x, int y, int z) { + glDisable(GL_LIGHTING); + self->renderBlock(tile, level, x, y, z); + glEnable(GL_LIGHTING); +} +static void TntRenderer_render_TileRenderer_renderTile_injection(TileRenderer *self, Tile *tile, int data) { + glDisable(GL_LIGHTING); + self->renderTile(tile, data); + glEnable(GL_LIGHTING); +} + +// Fix Names +static void MobRenderer_renderNameTag_injection(MobRenderer_renderNameTag_t original, MobRenderer *self, Mob *mob, const std::string &name, const float x, const float y, const float z, const int param_1) { + glDisable(GL_LIGHTING); + original(self, mob, name, x, y, z, param_1); + glEnable(GL_LIGHTING); +} + +// Armor Screen +static void ArmorScreen_renderPlayer_injection(ArmorScreen_renderPlayer_t original, ArmorScreen *self, float param_1, float param_2) { + lighting_turn_on(); + original(self, param_1, param_2); + lighting_turn_off(); +} + // Init void _init_lighting() { overwrite_calls(LevelRenderer_renderEntities, LevelRenderer_renderEntities_injection); + overwrite_call((void *) 0x4c04c, (void *) ItemInHandRenderer_render_glPopMatrix_injection); + overwrite_calls(ItemInHandRenderer_render, ItemInHandRenderer_render_injection); + overwrite_call((void *) 0x4bedc, (void *) enable_rescale_normal); + overwrite_call((void *) 0x4bf70, (void *) disable_rescale_normal); + overwrite_calls(ItemRenderer_render, EntityRenderer_render_injection); + overwrite_calls(ArrowRenderer_render, EntityRenderer_render_injection); + overwrite_calls(ItemSpriteRenderer_render, EntityRenderer_render_injection); + overwrite_calls(PaintingRenderer_render, EntityRenderer_render_injection); + overwrite_call((void *) 0x641ec, (void *) enable_rescale_normal); + overwrite_call((void *) 0x647a0, (void *) disable_rescale_normal); + overwrite_call((void *) 0x62b08, (void *) FallingTileRenderer_render_TileRenderer_renderBlock_injection); + overwrite_call((void *) 0x65754, (void *) TntRenderer_render_TileRenderer_renderTile_injection); + overwrite_calls(MobRenderer_renderNameTag, MobRenderer_renderNameTag_injection); + overwrite_calls(ArmorScreen_renderPlayer, ArmorScreen_renderPlayer_injection); } \ No newline at end of file diff --git a/mods/src/shading/normals.cpp b/mods/src/shading/normals.cpp index 168fd99b74..c86aba036c 100644 --- a/mods/src/shading/normals.cpp +++ b/mods/src/shading/normals.cpp @@ -10,7 +10,7 @@ Vec3 vector_to(const Vec3 &a, const Vec3 &b) { Vec3 vector_cross(const Vec3 &a, const Vec3 &b) { return Vec3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x); } -static void PolygonQuad_render_injection(PolygonQuad_render_t original, PolygonQuad *self, Tesselator &t, float scale, int buffer) { +static void PolygonQuad_render_injection(PolygonQuad_render_t original, PolygonQuad *self, Tesselator &t, const float scale, const int buffer) { // Set Normal const Vec3 v0 = vector_to(self->vertices[1].pos, self->vertices[0].pos); const Vec3 v1 = vector_to(self->vertices[1].pos, self->vertices[2].pos); @@ -20,7 +20,83 @@ static void PolygonQuad_render_injection(PolygonQuad_render_t original, PolygonQ original(self, t, scale, buffer); } +// Specify Normal Before Vertex +#define add_normal_before(type, name) \ + template \ + static decltype(auto) type##_##name##_injection(type *self, auto... args) { \ + Tesselator::instance.normal(nx, ny, nz); \ + return self->name(std::forward(args)...); \ + } \ + template \ + static void add_normal_before_##name(uint32_t addr) { \ + std::remove_pointer_t::ptr_type func = type##_##name##_injection; \ + overwrite_call((void *) addr, (void *) func); \ + } +add_normal_before(Tesselator, vertexUV) +add_normal_before(Tesselator, vertex) +add_normal_before(Tile, getTexture2) +add_normal_before(TileRenderer, tesselateCrossTexture) +add_normal_before(Tile, updateDefaultShape) + // Init void _init_normals() { + // PolygonQuad::render overwrite_calls(PolygonQuad_render, PolygonQuad_render_injection); + // ItemInHandRenderer::renderItem + add_normal_before_vertexUV<0.0f, 0.0f, 1.0f>(0x4bb4c); + add_normal_before_vertexUV<0.0f, 0.0f, -1.0f>(0x4bbbc); + add_normal_before_vertexUV<-1.0f, 0.0f, 0.0f>(0x4bc50); + add_normal_before_vertexUV<1.0f, 0.0f, 0.0f>(0x4bcf0); + add_normal_before_vertexUV<0.0f, 1.0f, 0.0f>(0x4bd90); + add_normal_before_vertexUV<0.0f, -1.0f, 0.0f>(0x4be28); + // TileRenderer::renderTile + add_normal_before_getTexture2<0.0f, -1.0f, 0.0f>(0x5dd2c); + add_normal_before_getTexture2<0.0f, 1.0f, 0.0f>(0x5dd60); + add_normal_before_getTexture2<0.0f, 0.0f, -1.0f>(0x5dd94); + add_normal_before_getTexture2<0.0f, 0.0f, 1.0f>(0x5ddc8); + add_normal_before_getTexture2<-1.0f, 0.0f, 0.0f>(0x5ddfc); + add_normal_before_getTexture2<1.0f, 0.0f, 0.0f>(0x5de30); + add_normal_before_tesselateCrossTexture<0.0f, -1.0f, 0.0f>(0x5de7c); + add_normal_before_updateDefaultShape<0.0f, -1.0f, 0.0f>(0x5dea0); + add_normal_before_getTexture2<0.0f, -1.0f, 0.0f>(0x5df38); + add_normal_before_getTexture2<0.0f, 1.0f, 0.0f>(0x5df68); + add_normal_before_getTexture2<0.0f, 0.0f, -1.0f>(0x5dfac); + add_normal_before_getTexture2<0.0f, 0.0f, 1.0f>(0x5e004); + add_normal_before_getTexture2<-1.0f, 0.0f, 0.0f>(0x5e05c); + add_normal_before_getTexture2<1.0f, 0.0f, 0.0f>(0x5e0b4); + add_normal_before_getTexture2<0.0f, -1.0f, 0.0f>(0x5e1e4); + add_normal_before_getTexture2<0.0f, 1.0f, 0.0f>(0x5e218); + add_normal_before_getTexture2<0.0f, 0.0f, -1.0f>(0x5e248); + add_normal_before_getTexture2<0.0f, 0.0f, 1.0f>(0x5e278); + add_normal_before_getTexture2<-1.0f, 0.0f, 0.0f>(0x5e2a8); + add_normal_before_getTexture2<1.0f, 0.0f, 0.0f>(0x5e2d8); + add_normal_before_getTexture2<0.0f, -1.0f, 0.0f>(0x5e408); + add_normal_before_getTexture2<0.0f, 1.0f, 0.0f>(0x5e43c); + add_normal_before_getTexture2<0.0f, 0.0f, -1.0f>(0x5e46c); + add_normal_before_getTexture2<0.0f, 0.0f, 1.0f>(0x5e49c); + add_normal_before_getTexture2<-1.0f, 0.0f, 0.0f>(0x5e4cc); + add_normal_before_getTexture2<1.0f, 0.0f, 0.0f>(0x5e4fc); + add_normal_before_getTexture2<0.0f, -1.0f, 0.0f>(0x5e60c); + add_normal_before_getTexture2<0.0f, 1.0f, 0.0f>(0x5e640); + add_normal_before_getTexture2<0.0f, 0.0f, -1.0f>(0x5e670); + add_normal_before_getTexture2<0.0f, 0.0f, 1.0f>(0x5e6a0); + add_normal_before_getTexture2<-1.0f, 0.0f, 0.0f>(0x5e6d0); + add_normal_before_getTexture2<1.0f, 0.0f, 0.0f>(0x5e700); + // ArrowRenderer::render + add_normal_before_vertexUV<1.0f, 0.0f, 0.0f>(0x60184); + add_normal_before_vertexUV<-1.0f, 0.0f, 0.0f>(0x601f4); + add_normal_before_vertexUV<0.0f, 0.0f, 1.0f>(0x60288); + // ItemRenderer::render + add_normal_before_vertexUV<0.0f, 1.0f, 0.0f>(0x63394); + // ItemSpriteRenderer::render + add_normal_before_vertexUV<0.0f, 1.0f, 0.0f>(0x63fd0); + // MobRenderer::renderNameTag + add_normal_before_vertex<0.0f, 1.0f, 0.0f>(0x64918); + // PaintingRenderer::renderPainting + add_normal_before_vertexUV<0.0f, 0.0f, -1.0f>(0x64c94); + add_normal_before_vertexUV<0.0f, 0.0f, 1.0f>(0x64d04); + add_normal_before_vertexUV<0.0f, 1.0f, 0.0f>(0x64d74); + add_normal_before_vertexUV<0.0f, -1.0f, 0.0f>(0x64de4); + add_normal_before_vertexUV<-1.0f, 0.0f, 0.0f>(0x64e54); + add_normal_before_vertexUV<1.0f, 0.0f, 0.0f>(0x64ec4); } \ No newline at end of file diff --git a/symbols/CMakeLists.txt b/symbols/CMakeLists.txt index ceae189e3f..995e416b21 100644 --- a/symbols/CMakeLists.txt +++ b/symbols/CMakeLists.txt @@ -63,6 +63,8 @@ set(SRC src/entity/Entity.def src/entity/ItemEntity.def src/entity/Arrow.def + src/entity/ArrowRenderer.def + src/entity/PaintingRenderer.def src/entity/Throwable.def src/level/container/FillingContainer.def src/level/container/Container.def @@ -125,6 +127,7 @@ set(SRC src/gui/screens/Touch_SelectWorldScreen.def src/gui/screens/PaneCraftingScreen.def src/gui/screens/ScreenChooser.def + src/gui/screens/ArmorScreen.def src/gui/Font.def src/gui/components/ImageButton.def src/gui/components/OptionButton.def diff --git a/symbols/src/entity/ArrowRenderer.def b/symbols/src/entity/ArrowRenderer.def new file mode 100644 index 0000000000..8e5585c028 --- /dev/null +++ b/symbols/src/entity/ArrowRenderer.def @@ -0,0 +1,3 @@ +extends EntityRenderer; + +vtable 0x1075e0; \ No newline at end of file diff --git a/symbols/src/entity/ItemSpriteRenderer.def b/symbols/src/entity/ItemSpriteRenderer.def index e01309b3d3..a15af08916 100644 --- a/symbols/src/entity/ItemSpriteRenderer.def +++ b/symbols/src/entity/ItemSpriteRenderer.def @@ -1,5 +1,7 @@ extends EntityRenderer; +vtable 0x107e18; + size 0x10; constructor (int texture) = 0x64078; diff --git a/symbols/src/entity/MobRenderer.def b/symbols/src/entity/MobRenderer.def index 7b7d1b95f0..1aaf71f3c5 100644 --- a/symbols/src/entity/MobRenderer.def +++ b/symbols/src/entity/MobRenderer.def @@ -1 +1,5 @@ extends EntityRenderer; + +vtable 0x107e58; + +virtual-method void renderNameTag(Mob *mob, const std::string &name, float x, float y, float z, int param_1) = 0x34; \ No newline at end of file diff --git a/symbols/src/entity/PaintingRenderer.def b/symbols/src/entity/PaintingRenderer.def new file mode 100644 index 0000000000..9c2b270577 --- /dev/null +++ b/symbols/src/entity/PaintingRenderer.def @@ -0,0 +1,3 @@ +extends EntityRenderer; + +vtable 0x107eb8; \ No newline at end of file diff --git a/symbols/src/gui/screens/ArmorScreen.def b/symbols/src/gui/screens/ArmorScreen.def new file mode 100644 index 0000000000..ac324c62e9 --- /dev/null +++ b/symbols/src/gui/screens/ArmorScreen.def @@ -0,0 +1,3 @@ +extends Screen; + +method void renderPlayer(float param_1, float param_2) = 0x29cd0; \ No newline at end of file diff --git a/symbols/src/tile/TileRenderer.def b/symbols/src/tile/TileRenderer.def index f2aacb2cb7..23eb276488 100644 --- a/symbols/src/tile/TileRenderer.def +++ b/symbols/src/tile/TileRenderer.def @@ -9,5 +9,7 @@ method bool tesselateInWorld(Tile *tile, int x, int y, int z) = 0x5e80c; method void renderGuiTile(Tile *tile, int aux) = 0x5ad0c; method void renderTile(Tile *tile, int data) = 0x5dcb0; method void tesselateTorch(Tile *tile, float x, float y, float z, float top_x, float top_z) = 0x54254; +method void tesselateCrossTexture(Tile *tile, int data, float x, float y, float z) = 0x547cc; +method void renderBlock(Tile *tile, LevelSource *level, int x, int y, int z) = 0x59540; property LevelSource *level = 0x0;