Get Lighting Working!

This commit is contained in:
TheBrokenRail 2024-10-19 05:19:08 -04:00
parent 18f7d64405
commit fbb3152a70
14 changed files with 175 additions and 5 deletions

View File

@ -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`

View File

@ -71,7 +71,7 @@ static bool Mob_hurt_injection(Mob_hurt_t original, Mob *mob, Entity *source, co
// Death Message Logic
template <typename Self, typename ParentSelf>
static void Player_die_injection(std::function<void(ParentSelf *, Entity *)> original, Self *player, Entity *cause) {
static void Player_die_injection(const std::function<void(ParentSelf *, Entity *)> &original, Self *player, Entity *cause) {
// Call Original Method
original((ParentSelf *) player, cause);
@ -88,7 +88,7 @@ static void Player_die_injection(std::function<void(ParentSelf *, Entity *)> ori
}
}
template <typename OriginalSelf, typename Self>
static void Player_actuallyHurt_injection(std::function<void(OriginalSelf *, int)> original, Self *player, int32_t damage) {
static void Player_actuallyHurt_injection(const std::function<void(OriginalSelf *, int)> &original, Self *player, int32_t damage) {
// Store Old Health
int32_t old_health = player->health;

View File

@ -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);
}
}
}

View File

@ -406,7 +406,7 @@ static void set_on_fire(Mob *mob, const int seconds) {
}
}
template <typename Self>
static void Monster_aiStep_injection(__attribute__((unused)) std::function<void(Self *)> original, Self *self) {
static void Monster_aiStep_injection(__attribute__((unused)) const std::function<void(Self *)> &original, Self *self) {
// Fire!
Level *level = self->level;
if (level->isDay() && !level->is_client_side) {

View File

@ -48,7 +48,7 @@ static int32_t TallGrass_getColor_injection(TallGrass_getColor_t original, TallG
// No Block Tinting
template <typename T>
static int32_t Tile_getColor_injection(__attribute__((unused)) std::function<int(T *, LevelSource *, int, int, int)> 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<int(T *, LevelSource *, int, int, int)> &original, __attribute__((unused)) T *self, __attribute__((unused)) LevelSource *level_source, __attribute__((unused)) int x, __attribute__((unused)) int y, __attribute__((unused)) int z) {
return 0xffffff;
}

View File

@ -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 <typename Self>
static void EntityRenderer_render_injection(const std::function<void(Self *, Entity *, float, float, float, float, float)> &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<ItemRenderer>);
overwrite_calls(ArrowRenderer_render, EntityRenderer_render_injection<ArrowRenderer>);
overwrite_calls(ItemSpriteRenderer_render, EntityRenderer_render_injection<ItemSpriteRenderer>);
overwrite_calls(PaintingRenderer_render, EntityRenderer_render_injection<PaintingRenderer>);
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);
}

View File

@ -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 <float nx, float ny, float nz> \
static decltype(auto) type##_##name##_injection(type *self, auto... args) { \
Tesselator::instance.normal(nx, ny, nz); \
return self->name(std::forward<decltype(args)>(args)...); \
} \
template <float nx, float ny, float nz> \
static void add_normal_before_##name(uint32_t addr) { \
std::remove_pointer_t<decltype(type##_##name)>::ptr_type func = type##_##name##_injection<nx, ny, nz>; \
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);
}

View File

@ -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

View File

@ -0,0 +1,3 @@
extends EntityRenderer;
vtable 0x1075e0;

View File

@ -1,5 +1,7 @@
extends EntityRenderer;
vtable 0x107e18;
size 0x10;
constructor (int texture) = 0x64078;

View File

@ -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;

View File

@ -0,0 +1,3 @@
extends EntityRenderer;
vtable 0x107eb8;

View File

@ -0,0 +1,3 @@
extends Screen;
method void renderPlayer(float param_1, float param_2) = 0x29cd0;

View File

@ -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;