From 5e5088e3eff516ec4640fb29c5697272ca179d7c Mon Sep 17 00:00:00 2001 From: Bigjango13 Date: Sun, 10 Mar 2024 22:46:34 -0400 Subject: [PATCH] Move chat history into chat - `get_death_message` is no longer static - Fix ItemInHandRenderer_instance symbol --- .../mods/text-input-box/TextInputBox.h | 6 +-- mods/src/chat/ui.cpp | 26 ++++++++++++- mods/src/death/death.cpp | 2 +- mods/src/text-input-box/TextInputBox.cpp | 38 +++---------------- symbols/src/item/ItemInHandRenderer.def | 2 +- symbols/src/misc/Tesselator.def | 1 + symbols/src/tile/Tile.def | 8 ++++ symbols/src/tile/TileRenderer.def | 4 ++ 8 files changed, 48 insertions(+), 39 deletions(-) diff --git a/mods/include/mods/text-input-box/TextInputBox.h b/mods/include/mods/text-input-box/TextInputBox.h index 9fcaf18..3a582b1 100644 --- a/mods/include/mods/text-input-box/TextInputBox.h +++ b/mods/include/mods/text-input-box/TextInputBox.h @@ -3,7 +3,7 @@ #include struct TextInputBox { - static TextInputBox *create(const std::string &placeholder = "", const std::string &text = "", const std::vector *history = NULL); + static TextInputBox *create(const std::string &placeholder = "", const std::string &text = ""); GuiComponent super; @@ -18,11 +18,10 @@ struct TextInputBox { void onClick(int x, int y); bool clicked(int x, int y); std::string getText(); + void setText(std::string text); bool isFocused(); void setMaxLength(int max_length); - int history_pos; - private: void recalculateScroll(); @@ -40,5 +39,4 @@ private: Font *m_pFont; int m_maxLength; int m_scrollPos; - const std::vector *history; }; diff --git a/mods/src/chat/ui.cpp b/mods/src/chat/ui.cpp index 12157b7..b0fa8a0 100644 --- a/mods/src/chat/ui.cpp +++ b/mods/src/chat/ui.cpp @@ -15,11 +15,16 @@ static std::vector &get_history() { return history; } +static std::string index_vec(const std::vector &vec, int pos) { + return pos == int(vec.size()) ? "" : vec.at(pos); +} + // Structure struct ChatScreen { TextInputScreen super; TextInputBox *chat; Button *send; + int history_pos; }; CUSTOM_VTABLE(chat_screen, Screen) { TextInputScreen::setup(vtable); @@ -29,10 +34,11 @@ CUSTOM_VTABLE(chat_screen, Screen) { original_init(super); ChatScreen *self = (ChatScreen *) super; // Text Input - self->chat = TextInputBox::create("", "", &get_history()); + self->chat = TextInputBox::create(); self->super.m_textInputs->push_back(self->chat); self->chat->init(super->font); self->chat->setFocused(true); + self->history_pos = get_history().size(); // Determine Max Length std::string prefix = _chat_get_prefix(Strings_default_username); int max_length = MAX_CHAT_MESSAGE_LENGTH - prefix.length(); @@ -91,6 +97,24 @@ CUSTOM_VTABLE(chat_screen, Screen) { _chat_queue_message(text.c_str()); } Minecraft_setScreen(super->minecraft, NULL); + } else if (key == 0x26 && self->chat->isFocused()) { + // Up + int old_pos = self->history_pos; + self->history_pos -= 1; + if (self->history_pos < 0) self->history_pos = get_history().size(); + if (old_pos != self->history_pos) { + self->chat->setText(index_vec(get_history(), self->history_pos)); + } + return; + } else if (key == 0x28 && self->chat->isFocused()) { + // Down + int old_pos = self->history_pos; + self->history_pos += 1; + if (self->history_pos > int(get_history().size())) self->history_pos = 0; + if (old_pos != self->history_pos) { + self->chat->setText(index_vec(get_history(), self->history_pos)); + } + return; } // Call Original Method original_keyPressed(super, key); diff --git a/mods/src/death/death.cpp b/mods/src/death/death.cpp index 2b88ba6..487faba 100644 --- a/mods/src/death/death.cpp +++ b/mods/src/death/death.cpp @@ -8,7 +8,7 @@ // Death Messages static const char *monster_names[] = {"Zombie", "Creeper", "Skeleton", "Spider", "Zombie Pigman"}; -static std::string get_death_message(Player *player, Entity *cause, bool was_shot = false) { +std::string get_death_message(Player *player, Entity *cause, bool was_shot = false) { // Prepare Death Message std::string message = player->username; if (cause) { diff --git a/mods/src/text-input-box/TextInputBox.cpp b/mods/src/text-input-box/TextInputBox.cpp index cfbda59..3ec57ce 100644 --- a/mods/src/text-input-box/TextInputBox.cpp +++ b/mods/src/text-input-box/TextInputBox.cpp @@ -2,16 +2,7 @@ #include -static int get_vec_size(const std::vector *vec) { - return vec ? vec->size() : 0; -} - -static std::string index_vec(const std::vector *vec, int pos) { - if (vec == NULL || pos == get_vec_size(vec)) return ""; - return vec->at(pos); -} - -TextInputBox *TextInputBox::create(const std::string &placeholder, const std::string &text, const std::vector *history) { +TextInputBox *TextInputBox::create(const std::string &placeholder, const std::string &text) { // Construct TextInputBox *self = new TextInputBox; GuiComponent_constructor(&self->super); @@ -31,8 +22,6 @@ TextInputBox *TextInputBox::create(const std::string &placeholder, const std::st self->m_pFont = nullptr; self->m_maxLength = -1; self->m_scrollPos = 0; - self->history = history; - self->history_pos = get_vec_size(history); // Return return self; @@ -99,16 +88,6 @@ void TextInputBox::keyPressed(int key) { recalculateScroll(); break; } - case 0x26: { - // Up - int old_pos = history_pos; - history_pos -= 1; - if (history_pos < 0) history_pos = get_vec_size(history); - if (old_pos == history_pos) break; - m_text = index_vec(history, history_pos); - m_insertHead = int(m_text.size()); - break; - } case 0x27: { // Right m_insertHead++; @@ -122,16 +101,6 @@ void TextInputBox::keyPressed(int key) { recalculateScroll(); break; } - case 0x28: { - // Down - int old_pos = history_pos; - history_pos += 1; - if (history_pos > get_vec_size(history)) history_pos = 0; - if (old_pos == history_pos) break; - m_text = index_vec(history, history_pos); - m_insertHead = int(m_text.size()); - break; - } case 0x0d: { // Enter m_bFocused = false; @@ -316,6 +285,11 @@ std::string TextInputBox::getText() { return m_text; } +void TextInputBox::setText(std::string str) { + m_text = str; + m_insertHead = int(m_text.size()); +} + bool TextInputBox::isFocused() { return m_bFocused; } diff --git a/symbols/src/item/ItemInHandRenderer.def b/symbols/src/item/ItemInHandRenderer.def index e6cbe76..1c239b9 100644 --- a/symbols/src/item/ItemInHandRenderer.def +++ b/symbols/src/item/ItemInHandRenderer.def @@ -6,4 +6,4 @@ property Minecraft *mc = 0x18; method void renderItem(Mob *mob, ItemInstance *item) = 0x4b824; method void render(float param_1) = 0x4bfcc; -static-property ItemInHandRenderer *instance = 0x137bc0; \ No newline at end of file +static-property ItemInHandRenderer **instance = 0x137bc0; \ No newline at end of file diff --git a/symbols/src/misc/Tesselator.def b/symbols/src/misc/Tesselator.def index c9c1e5e..92ea2e3 100644 --- a/symbols/src/misc/Tesselator.def +++ b/symbols/src/misc/Tesselator.def @@ -4,5 +4,6 @@ method void colorABGR(int color) = 0x52b54; method void color(int r, int g, int b, int a) = 0x52a48; method void vertex(float x, float y, float z) = 052bc0; method void vertexUV(float x, float y, float z, float u, float v) = 0x52d40; +method void addOffset(float x, float y, float z) = 0x52d90; static-property Tesselator instance = 0x137538; diff --git a/symbols/src/tile/Tile.def b/symbols/src/tile/Tile.def index 18c0ebd..7d7471c 100644 --- a/symbols/src/tile/Tile.def +++ b/symbols/src/tile/Tile.def @@ -23,6 +23,8 @@ virtual-method void tick(Level *level, int x, int y, int z) = 0x58; virtual-method void neighborChanged(Level *level, int x, int y, int z, int neighborId) = 0x64; virtual-method void onPlace(Level *level, int x, int y, int z) = 0x68; virtual-method void onRemove(Level *level, int x, int y, int z) = 0x6c; +virtual-method int getResource(int data, Random *random) = 0x70; +virtual-method int getResourceCount(Random *random) = 0x74; virtual-method int getRenderLayer() = 0x94; virtual-method int use(Level *level, int x, int y, int z, Player *player) = 0x98; virtual-method void setPlacedBy(Level *level, int x, int y, int z, Mob *placer) = 0xa8; @@ -38,6 +40,12 @@ virtual-method Tile *setDestroyTime(float destroy_time) = 0xf8; property int texture = 0x4; property int id = 0x8; +property float x1 = 0xc; +property float y1 = 0x10; +property float z1 = 0x14; +property float x2 = 0x18; +property float y2 = 0x1c; +property float z2 = 0x20; property int category = 0x3c; property AABB aabb = 0x40; diff --git a/symbols/src/tile/TileRenderer.def b/symbols/src/tile/TileRenderer.def index 23a3d3d..2ba223c 100644 --- a/symbols/src/tile/TileRenderer.def +++ b/symbols/src/tile/TileRenderer.def @@ -2,7 +2,11 @@ size 0xb8; constructor (Minecraft *minecraft, LevelSource *level) = 0x53e58; +static-method bool canRender(int shape) = 0x5accc; + method bool tesselateBlockInWorld(Tile *tile, int x, int y, int z) = 0x59e30; 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; property LevelSource *level = 0x0;