From 3d8525a3218c7d3d7c58e89855ff2bd502787605 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Thu, 3 Oct 2024 05:17:12 -0400 Subject: [PATCH] 3D Items! --- docs/CHANGELOG.md | 1 + launcher/src/client/available-feature-flags | 3 +- mods/src/misc/graphics.cpp | 83 ++++++++++++++++++++ mods/src/textures/lava.cpp | 6 +- symbols/src/entity/EntityRenderer.def | 4 +- symbols/src/entity/ItemEntity.def | 1 + symbols/src/item/ItemRenderer.def | 6 ++ symbols/src/level/renderer/LevelRenderer.def | 1 + symbols/src/misc/Random.def | 3 + 9 files changed, 101 insertions(+), 7 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 1d983a1890..be9fdbfa8e 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -46,6 +46,7 @@ * `Hide Block Outline When GUI Is Hidden` (Enabled By Default) * `Fix Crash When Generating Certain Seeds` (Enabled By Default) * `Click Buttons On Mouse Down` (Enabled By Default) + * `3D Dropped Items` (Enabled By Default) * Existing Functionality (All Enabled By Default) * `Fix Screen Rendering When Hiding HUD` * `Sanitize Usernames` diff --git a/launcher/src/client/available-feature-flags b/launcher/src/client/available-feature-flags index 4e18eca529..3b371b81fe 100644 --- a/launcher/src/client/available-feature-flags +++ b/launcher/src/client/available-feature-flags @@ -108,4 +108,5 @@ TRUE Improved Classic Title Positioning TRUE Use Updated Title TRUE Hide Block Outline When GUI Is Hidden TRUE Fix Crash When Generating Certain Seeds -TRUE Click Buttons On Mouse Down \ No newline at end of file +TRUE Click Buttons On Mouse Down +TRUE 3D Dropped Items \ No newline at end of file diff --git a/mods/src/misc/graphics.cpp b/mods/src/misc/graphics.cpp index 918810b0d2..b584b21986 100644 --- a/mods/src/misc/graphics.cpp +++ b/mods/src/misc/graphics.cpp @@ -1,3 +1,5 @@ +#include + #include #include @@ -261,6 +263,81 @@ static ContainerMenu *ContainerMenu_destructor_injection(ContainerMenu_destructo return original(container_menu); } +// 3D Dropped Items +static bool disable_hand_positioning = false; +static void ItemInHandRenderer_renderItem_glTranslatef_injection(const float x, const float y, const float z) { + if (disable_hand_positioning) { + glPopMatrix(); + glPushMatrix(); + } else { + glTranslatef(x, y, z); + } +} +static void ItemRenderer_render_injection(ItemRenderer_render_t original, ItemRenderer *self, Entity *entity, const float x, const float y, const float z, const float a, const float b) { + // Get Item + const ItemEntity *item_entity = (ItemEntity *) entity; + ItemInstance item = item_entity->item; + // Check If Item Is Tile + if (item.id < 256 && TileRenderer::canRender(Tile::tiles[item.id]->getRenderShape())) { + // Call Original Method + original(self, entity, x, y, z, a, b); + } else { + // 3D Item + self->random.setSeed(187); + glPushMatrix(); + + // Count + int count; + if (item.count < 2) { + count = 1; + } else if (item.count < 16) { + count = 2; + } else if (item.count < 32) { + count = 3; + } else { + count = 4; + } + + // Bob + const float age = float(item_entity->age) + b; + const float bob = (Mth::sin((age / 10.0f) + item_entity->bob_offset) * 0.1f) + 0.1f; + glTranslatef(x, y + bob, z); + + // Scale + glScalef(0.5f, 0.5f, 0.5f); + + // Spin + const float spin = ((age / 20.0f) + item_entity->bob_offset) * float(180.0f / M_PI); + glRotatef(spin, 0, 1, 0); + + // Position + constexpr float xo = 0.5f; + constexpr float yo = 0.25f; + constexpr float width = 1 / 16.0f; + constexpr float margin = 0.35f / 16.0f; + constexpr float zo = width + margin; + glTranslatef(-xo, -yo, -((zo * float(count)) / 2)); + + // Draw + disable_hand_positioning = true; + for (int i = 0; i < count; i++) { + glTranslatef(0, 0, zo); + glPushMatrix(); + if (i > 0) { + const float c = (self->random.nextFloat() * 2 - 1) * 0.15f; + const float d = (self->random.nextFloat() * 2 - 1) * 0.15f; + glTranslatef(c, d, 0.0f); + } + EntityRenderer::entityRenderDispatcher->item_renderer->renderItem(nullptr, &item); + glPopMatrix(); + } + disable_hand_positioning = false; + + // Finish + glPopMatrix(); + } +} + // Init void _init_misc_graphics() { // Disable V-Sync @@ -351,6 +428,12 @@ void _init_misc_graphics() { overwrite_calls(ChestTileEntity_shouldSave, ChestTileEntity_shouldSave_injection); } + // 3D Dropped Items + if (feature_has("3D Dropped Items", server_disabled)) { + overwrite_calls(ItemRenderer_render, ItemRenderer_render_injection); + overwrite_call((void *) 0x4bf34, (void *) ItemInHandRenderer_renderItem_glTranslatef_injection); + } + // Don't Render Game In Headless Mode if (reborn_is_headless()) { overwrite_calls(GameRenderer_render, nop); diff --git a/mods/src/textures/lava.cpp b/mods/src/textures/lava.cpp index 4671f552c3..987f9fe05d 100644 --- a/mods/src/textures/lava.cpp +++ b/mods/src/textures/lava.cpp @@ -216,11 +216,7 @@ static DynamicTexture *create_fire_texture(const int a2) { texture->super()->vtable = get_fire_texture_vtable(); // Setup Random texture->data.m_random = Random::allocate(); - const int seed = Common::getTimeMs(); - texture->data.m_random->seed = seed; - texture->data.m_random->param_1 = 0x271; - texture->data.m_random->param_2 = false; - texture->data.m_random->param_3 = 0; + texture->data.m_random->constructor(); for (int i = 0; i < 320; i++) { texture->data.m_data1[i] = 0.0f; texture->data.m_data2[i] = 0.0f; diff --git a/symbols/src/entity/EntityRenderer.def b/symbols/src/entity/EntityRenderer.def index 79cea4d738..77973732b9 100644 --- a/symbols/src/entity/EntityRenderer.def +++ b/symbols/src/entity/EntityRenderer.def @@ -1,6 +1,8 @@ +vtable 0x1075a8; + virtual-method void render(Entity *entity, float param_2, float param_3, float param_4, float param_5, float param_6) = 0x8; -// Can be called without an EntityRenderer, just do EntityRenderer_bindTexture(NULL, &file); +// Can be called without an EntityRenderer, just do EntityRenderer_bindTexture->get(false)(NULL, &file); method void bindTexture(const std::string &file) = 0x62540; // Globals diff --git a/symbols/src/entity/ItemEntity.def b/symbols/src/entity/ItemEntity.def index 82463555b1..e800ff7dcd 100644 --- a/symbols/src/entity/ItemEntity.def +++ b/symbols/src/entity/ItemEntity.def @@ -5,3 +5,4 @@ constructor (Level *level, float x, float y, float z, const ItemInstance &item) property ItemInstance item = 0xd0; property int age = 0xdc; +property float bob_offset = 0xe4; \ No newline at end of file diff --git a/symbols/src/item/ItemRenderer.def b/symbols/src/item/ItemRenderer.def index f13f37c280..687c8ac3de 100644 --- a/symbols/src/item/ItemRenderer.def +++ b/symbols/src/item/ItemRenderer.def @@ -1,3 +1,7 @@ +extends EntityRenderer; + +vtable 0x107970; + static-method void renderGuiItem_one(Font *font, Textures *textures, const ItemInstance *item_instance, float x, float y, bool param_3) = 0x63e58; static-method void renderGuiItem_two(Font *font, Textures *textures, const ItemInstance *item_instance, float x, float y, float w, float h, bool param_5) = 0x63be0; static-method void renderGuiItemCorrect(Font *font, Textures *textures, const ItemInstance *item_instance, int x, int y) = 0x639a0; @@ -7,3 +11,5 @@ static-method void blit(float x, float y, float texture_x, float texture_y, floa // This doesn't include things that it doesn't need for item rendering (like the level) // So if you are (ab)using it for something else, be sure to set what you need static-property TileRenderer *tileRenderer = 0x137c18; + +property Random random = 0xc; diff --git a/symbols/src/level/renderer/LevelRenderer.def b/symbols/src/level/renderer/LevelRenderer.def index da76f2deaf..f66e4f9f7f 100644 --- a/symbols/src/level/renderer/LevelRenderer.def +++ b/symbols/src/level/renderer/LevelRenderer.def @@ -1,5 +1,6 @@ method void tick() = 0x4da1c; method int render(Mob *mob, int param_1, float delta) = 0x4f710; +method void render_AABB(const AABB &box) = 0x4d740; method void renderDebug(const AABB &aabb, float delta) = 0x4d310; method void generateSky() = 0x4d0d4; method void renderHitSelect(Player *player, const HitResult &hit_result, int i, void *vp, float f) = 0x4e318; diff --git a/symbols/src/misc/Random.def b/symbols/src/misc/Random.def index 1a6fdbcd26..59e4cbe7d1 100644 --- a/symbols/src/misc/Random.def +++ b/symbols/src/misc/Random.def @@ -1,8 +1,11 @@ size 0x9d0; +constructor () = 0xb7490; + method float nextFloat() = 0x42cf8; method uint genrand_int32() = 0x50e14; method void init_genrand(uint seed) = 0x27d38; +method void setSeed(int seed) = 0xaf884; property uint seed = 0x0; property int param_1 = 0x9c4; // Set To 0x271