Add chat history

- More symbols too
- Made CUSTOM_VTABLE not static, for modders
This commit is contained in:
Bigjango13 2024-03-08 18:03:19 -05:00
parent d74d1501ce
commit 3ff24c2a92
18 changed files with 102 additions and 11 deletions

View File

@ -52,7 +52,7 @@ int reborn_is_server();
// Customize VTable
#define CUSTOM_VTABLE(name, parent) \
static void _setup_##name##_vtable(parent##_vtable *vtable); \
void _setup_##name##_vtable(parent##_vtable *vtable); \
static parent##_vtable *get_##name##_vtable() { \
static parent##_vtable *vtable = NULL; \
/* Allocate VTable */ \
@ -67,7 +67,7 @@ int reborn_is_server();
return vtable; \
} \
/* User-Defined Setup Code */ \
static void _setup_##name##_vtable(parent##_vtable *vtable)
void _setup_##name##_vtable(parent##_vtable *vtable)
#ifdef __cplusplus
}

View File

@ -3,7 +3,7 @@
#include <symbols/minecraft.h>
struct TextInputBox {
static TextInputBox *create(const std::string &placeholder = "", const std::string &text = "");
static TextInputBox *create(const std::string &placeholder = "", const std::string &text = "", const std::vector<std::string> *history = NULL);
GuiComponent super;
@ -21,6 +21,8 @@ struct TextInputBox {
bool isFocused();
void setMaxLength(int max_length);
int history_pos;
private:
void recalculateScroll();
@ -38,4 +40,5 @@ private:
Font *m_pFont;
int m_maxLength;
int m_scrollPos;
const std::vector<std::string> *history;
};

View File

@ -10,6 +10,8 @@
#include <mods/misc/misc.h>
#include <mods/touch/touch.h>
std::vector<std::string> history;
// Structure
struct ChatScreen {
TextInputScreen super;
@ -24,7 +26,7 @@ CUSTOM_VTABLE(chat_screen, Screen) {
original_init(super);
ChatScreen *self = (ChatScreen *) super;
// Text Input
self->chat = TextInputBox::create();
self->chat = TextInputBox::create("", "", &history);
self->super.m_textInputs->push_back(self->chat);
self->chat->init(super->font);
self->chat->setFocused(true);
@ -78,7 +80,11 @@ CUSTOM_VTABLE(chat_screen, Screen) {
ChatScreen *self = (ChatScreen *) super;
if (key == 0x0d && self->chat->isFocused()) {
if (self->chat->getText().length() > 0) {
_chat_queue_message(self->chat->getText().c_str());
std::string text = self->chat->getText();
if (self->chat->history_pos != int(history.size() - 1)) {
history.push_back(text);
}
_chat_queue_message(text.c_str());
}
Minecraft_setScreen(super->minecraft, NULL);
}
@ -113,6 +119,7 @@ static Screen *create_chat_screen() {
// Init
void _init_chat_ui() {
history = {};
misc_run_on_game_key_press([](Minecraft *minecraft, int key) {
if (key == 0x54) {
if (Minecraft_isLevelGenerated(minecraft) && minecraft->screen == NULL) {

View File

@ -2,7 +2,16 @@
#include <mods/text-input-box/TextInputBox.h>
TextInputBox *TextInputBox::create(const std::string &placeholder, const std::string &text) {
static int get_vec_size(const std::vector<std::string> *vec) {
return vec ? vec->size() : 0;
}
static std::string index_vec(const std::vector<std::string> *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<std::string> *history) {
// Construct
TextInputBox *self = new TextInputBox;
GuiComponent_constructor(&self->super);
@ -22,6 +31,8 @@ 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;
@ -88,6 +99,16 @@ 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++;
@ -101,6 +122,16 @@ 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;

View File

@ -66,6 +66,7 @@ set(SRC
src/level/container/Container.def
src/level/container/ContainerMenu.def
src/level/container/Inventory.def
src/level/feature/Feature.def
src/level/feature/LargeFeature.def
src/level/feature/LargeCaveFeature.def
src/level/Material.def
@ -97,6 +98,7 @@ set(SRC
src/item/ArmorItem.def
src/item/TileItem.def
src/item/FoodItem.def
src/item/DiggerItem.def
src/api/OffsetPosTranslator.def
src/api/CommandServer.def
src/api/ConnectedClient.def

View File

@ -1,5 +1,6 @@
virtual-method void remove() = 0x10;
virtual-method void tick() = 0x34;
virtual-method float getBrightness(float param_1) = 0x64;
virtual-method bool interact(Player *with) = 0x6c;
virtual-method void playerTouch(Player *player) = 0x70;
virtual-method bool isPlayer() = 0x94;
@ -37,3 +38,4 @@ property int fire_timer = 0xa0;
property int renderer_id = 0xa8;
property bool on_ground = 0xb2;
property bool freeze_physics = 0xb9;
property float fall_distance = 0xac;

View File

@ -1,3 +1,4 @@
method void tick(int tick, int max_ticks) = 0x495bc;
method void render(float param_1) = 0x4a338;
method void setupCamera(float param_1, int param_2) = 0x489f8;

View File

@ -4,7 +4,7 @@ method void tickInput() = 0x15ffc;
method void setIsCreativeMode(int is_creative) = 0x16ec4;
method int isTouchscreen() = 0x1639c;
method void setScreen(Screen *screen) = 0x15d6c;
method void tick(int param_1, int param_2) = 0x16934;
method void tick(int tick, int max_ticks) = 0x16934;
method void hostMultiplayer(int port) = 0x16664;
method char *getProgressMessage() = 0x16e58;
method uint isLevelGenerated() = 0x16e6c;
@ -27,21 +27,24 @@ property int screen_width = 0x20;
property int screen_height = 0x24;
property Options options = 0x3c;
property LevelRenderer *levelrenderer = 0x150;
property GameRenderer *gamerenderer = 0x154;
property GameMode *game_mode = 0x160;
property Textures *textures = 0x164;
property ScreenChooser screen_chooser = 0x168;
property Font *font = 0x16c;
property RakNetInstance *rak_net_instance = 0x170;
property NetEventCallback *network_handler = 0x174;
property Level *level = 0x188;
property LocalPlayer *player = 0x18c;
property Mob *camera = 0x194;
property Gui gui = 0x198;
property LocalPlayer *player = 0x18c;
property Screen *screen = 0xc10;
property HitResult hit_result = 0xc38;
property int progress = 0xc60;
property int ticks_per_update = 0xc70;
property bool is_creative_mode = 0xcb5;
property PerfRenderer *perf_renderer = 0xcbc;
property CommandServer *command_server = 0xcc0;
property Font *font = 0x16c;
property ScreenChooser screen_chooser = 0x168;
// Smooth Lighting
static-property bool useAmbientOcclusion = 0x136b90;

View File

@ -0,0 +1,3 @@
extends Item;
property float speed = 0x24;

View File

@ -1,2 +1,20 @@
vtable 0x110180;
vtable-size 0x24;
static-method void initBiomes() = 0xae320;
static-method void recalc() = 0xae010;
static-method Biome *_getBiome(float temp, float humidity) = 0xadf04;
virtual-method Feature *getTreeFeature(Random *random) = 0x8;
virtual-method Feature *getGrassFeature(Random *random) = 0xc;
virtual-method float adjustScale(float scale) = 0x10;
virtual-method float adjustDepth(float depth) = 0x14;
virtual-method uint getSkyColor(float temp) = 0x18;
//virtual-method ??? *getMobs(MobCategory *category) = 0x1c;
virtual-method float getCreatureProbability() = 0x20;
property int color = 0x2c;
property int leaf_color = 0x34;
// 64x64, Temp x humidity
static-property-array Biome *map = 0x17c970;

View File

@ -11,17 +11,21 @@ method Entity *getEntity(int id) = 0xa45a4;
method bool addEntity(Entity *entity) = 0xa7cbc;
method int getBrightness2(LightLayer *layer, int x, int y, int z) = 0xa3c70;
method void playSound(Entity *entity, std::string *name, float volume, float pitch) = 0xa42a8;
// Searches aabb for entities, ignores the entity "ignore", overwrites the same vector each time
method std::vector<Entity*> *getEntities(Entity *ignore, AABB *aabb) = 0xa5a4c;
// Searches aabb for entities of type type_id, adds then to buff, returns the number of entities added
method int getEntitiesOfType(int type_id, AABB *aabb, std::vector<Entity*> *buff) = 0xa612c;
// Searches aabb for entities of base type base_type, adds then to buff, returns the number of entities added
method int getEntitiesOfClass(int base_type, AABB *aabb, std::vector<Entity*> *buff) = 0xa6240;
// This will implicitly make the tile entity if the tile at x, y, z doesn't have one and is an EntityTile
method TileEntity *getTileEntity(int x, int y, int z) = 0xa55d4;
method void animateTick(int x, int y, int z) = 0xa5920;
virtual-method void tick() = 0x28;
virtual-method void updateSleepingPlayerList() = 0x2c;
virtual-method ChunkCache *createChunkSource() = 0x30;
property bool done_generating = 0x12;
property std::vector<Entity *> entities = 0x20;
property std::vector<TileEntity *> tileentities = 0x50;
property std::vector<Player *> players = 0x60;

View File

@ -1,3 +1,4 @@
method void tick() = 0x4da1c;
method void render(Mob *mob, int param_1, float delta) = 0x4f710;
method void renderDebug(AABB *aabb, float delta) = 0x4d310;
method void generateSky() = 0x4d0d4;

View File

@ -5,4 +5,5 @@ vtable 0x110598;
method void buildSurface(int chunk_x, int chunk_y, uchar *chunk_data, Biome **biomes) = 0xb32ec;
property LargeCaveFeature cave_feature = 0x8;
property Random random = 0x19f8;
property Level *level = 0x72c8;

View File

@ -6,5 +6,7 @@ method ItemInstance *getSelected() = 0x8d134;
// It's just FillingContainer_linkSlot with selectedSlot as linked_slot
method bool moveToSelectedSlot(int unlinked_slot, bool push_aside) = 0x8d148;
method void setupDefault() = 0x8d164;
method void clearInventoryWithDefault() = 0x8e7c8;
method void clearInventory() = 0x92b84;
property int selectedSlot = 0x28;

View File

@ -0,0 +1,7 @@
vtable 0x10e530;
vtable-size 0x10;
// Pure virtual
virtual-method bool place(Level *level, Random *random, int x, int y, int z) = 0x8;
// Not sure about args, it doesn't seem to be used at all
virtual-method void init(float x, float y, float z) = 0xc;

View File

@ -5,3 +5,4 @@ static-method float sin(float x) = 0x7775c;
static-method float cos(float x) = 0x77728;
static-method float abs(float x) = 0x7781c;
static-method float min(float a, float b) = 0x7782c;
static-method float invSqrt(float a) = 0x776d4;

View File

@ -73,3 +73,4 @@ static-property Tile *grass_carried = 0x181dd4;
// Sounds
static-property Tile_SoundType SOUND_STONE = 0x181c80;
static-property Tile_SoundType SOUND_WOOD = 0x181cb4;

View File

@ -1,4 +1,8 @@
size 0xb8;
constructor (Minecraft *minecraft, LevelSource *level) = 0x53e58;
method bool tesselateBlockInWorld(Tile *tile, int x, int y, int z) = 0x59e30;
method bool tesselateInWorld(Tile *tile, int x, int y, int z) = 0x5e80c;
property Level *level = 0x0;
property LevelSource *level = 0x0;