From d9d57f01a27f1c4fe389b3fb97c7c99a3ee18c38 Mon Sep 17 00:00:00 2001 From: Dregu Date: Sun, 24 Sep 2023 01:10:13 +0300 Subject: [PATCH 01/10] some more vtable hooks --- src/game_api/entity.hpp | 76 ++++++------ src/game_api/movable.hpp | 110 +++++++++--------- src/game_api/script/usertypes/vtables_lua.cpp | 42 ++++++- 3 files changed, 132 insertions(+), 96 deletions(-) diff --git a/src/game_api/entity.hpp b/src/game_api/entity.hpp index 00b33ab06..8d7f0dacb 100644 --- a/src/game_api/entity.hpp +++ b/src/game_api/entity.hpp @@ -226,57 +226,57 @@ class Entity inline static std::function)> hook_dtor_impl{}; inline static std::function clear_dtor_impl{}; - virtual ~Entity() = 0; // vritual 0 - virtual void create_rendering_info() = 0; - virtual void handle_state_machine() = 0; + virtual ~Entity() = 0; // vritual 0 + virtual void create_rendering_info() = 0; // 1 + virtual void handle_state_machine() = 0; // 2 /// Kills the entity, you can set responsible to `nil` to ignore it - virtual void kill(bool destroy_corpse, Entity* responsible) = 0; + virtual void kill(bool destroy_corpse, Entity* responsible) = 0; // 3 - virtual void on_collision1(Entity* other_entity) = 0; // triggers on collision between whip and hit object + virtual void on_collision1(Entity* other_entity) = 0; // 4, triggers on collision between whip and hit object /// Completely removes the entity from existence - virtual void destroy() = 0; - - virtual void apply_texture(Texture*) = 0; - virtual void format_shopitem_name(char16_t*) = 0; - virtual void generate_stomp_damage_particles(Entity* victim) = 0; // particles when jumping on top of enemy - virtual float get_type_field_a8() = 0; - virtual bool can_be_pushed() = 0; // (runs only for activefloors?) checks if entity type is pushblock, for chained push block checks ChainedPushBlock.is_chained, is only a check that allows for the pushing animation - virtual bool v11() = 0; // for arrows: returns true if it's moving (for y possibily checks for some speed as well?) + virtual void destroy() = 0; // 5 + + virtual void apply_texture(Texture*) = 0; // 6 + virtual void format_shopitem_name(char16_t*) = 0; // 7 + virtual void generate_stomp_damage_particles(Entity* victim) = 0; // 8, particles when jumping on top of enemy + virtual float get_type_field_a8() = 0; // 9 + virtual bool can_be_pushed() = 0; // 10, (runs only for activefloors?) checks if entity type is pushblock, for chained push block checks ChainedPushBlock.is_chained, is only a check that allows for the pushing animation + virtual bool v11() = 0; // 11, for arrows: returns true if it's moving (for y possibily checks for some speed as well?) /// Returns true if entity is in water/lava - virtual bool is_in_liquid() = 0; - virtual bool check_type_properties_flags_19() = 0; // checks (properties_flags >> 0x12) & 1; for hermitcrab checks if he's invisible; can't get it to trigger - virtual uint32_t get_type_field_60() = 0; - virtual void set_invisible(bool value) = 0; - virtual void handle_turning_left(bool apply) = 0; // if disabled, monsters don't turn left and keep walking in the wall (and other right-left issues) - virtual void set_draw_depth(uint8_t draw_depth) = 0; - virtual void resume_ai() = 0; // works on entities with ai_func != 0; runs when companions are let go from being held. AI resumes anyway in 1.23.3 - virtual float friction() = 0; - virtual void set_as_sound_source(SoundMeta*) = 0; // update sound position to entity position? - virtual void remove_item_ptr(Entity*) = 0; - virtual Entity* get_held_entity() = 0; - virtual void v23(Entity* logical_trigger, Entity* who_triggered_it) = 0; // spawns LASERTRAP_SHOT from LASERTRAP, also some trigger entities use this, seam to be called right after "on_collision2", tiggers use self as the first parameter + virtual bool is_in_liquid() = 0; // 12 + virtual bool check_type_properties_flags_19() = 0; // 13, checks (properties_flags >> 0x12) & 1; for hermitcrab checks if he's invisible; can't get it to trigger + virtual uint32_t get_type_field_60() = 0; // 14 + virtual void set_invisible(bool value) = 0; // 15 + virtual void handle_turning_left(bool apply) = 0; // 16, if disabled, monsters don't turn left and keep walking in the wall (and other right-left issues) + virtual void set_draw_depth(uint8_t draw_depth) = 0; // 17 + virtual void resume_ai() = 0; // 18, works on entities with ai_func != 0; runs when companions are let go from being held. AI resumes anyway in 1.23.3 + virtual float friction() = 0; // 19 + virtual void set_as_sound_source(SoundMeta*) = 0; // 20, update sound position to entity position? + virtual void remove_item_ptr(Entity*) = 0; // 21 + virtual Entity* get_held_entity() = 0; // 22 + virtual void v23(Entity* logical_trigger, Entity* who_triggered_it) = 0; // 23, spawns LASERTRAP_SHOT from LASERTRAP, also some trigger entities use this, seam to be called right after "on_collision2", tiggers use self as the first parameter /// Triggers weapons and other held items like teleportter, mattock etc. You can check the [virtual-availability.md](https://github.com/spelunky-fyi/overlunky/blob/main/docs/virtual-availability.md), if entity has `open` in the `on_open` you can use this function, otherwise it does nothing. Returns false if action could not be performed (cooldown is not 0, no arrow loaded in etc. the animation could still be played thou) - virtual bool trigger_action(Entity* user) = 0; + virtual bool trigger_action(Entity* user) = 0; // 24 /// Activates a button prompt (with the Use door/Buy button), e.g. buy shop item, activate drill, read sign, interact in camp, ... `get_entity():activate(players[1])` (make sure player 1 has the udjat eye though) - virtual void activate(Entity* activator) = 0; + virtual void activate(Entity* activator) = 0; // 25 - virtual void on_collision2(Entity* other_entity) = 0; // needs investigating, difference between this and on_collision1, maybe this is on_hitbox_overlap as it works for logical tiggers + virtual void on_collision2(Entity* other_entity) = 0; // 26, needs investigating, difference between this and on_collision1, maybe this is on_hitbox_overlap as it works for logical tiggers /// e.g. for turkey: stores health, poison/curse state, for mattock: remaining swings (returned value is transferred) - virtual uint16_t get_metadata() = 0; - virtual void apply_metadata(uint16_t metadata) = 0; - virtual void on_walked_on_by(Entity* walker) = 0; // hits when monster/player walks on a floor, does something when walker.velocityy<-0.21 (falling onto) and walker.hitboxy * hitboxx > 0.09 - virtual void on_walked_off_by(Entity* walker) = 0; // appears to be disabled in 1.23.3? hits when monster/player walks off a floor, it checks whether the walker has floor as overlay, and if so, removes walker from floor's items by calling virtual remove_item_ptr - virtual void on_ledge_grab(Entity* who) = 0; // only ACTIVEFLOOR_FALLING_PLATFORM, does something with game menager - virtual void on_stood_on_by(Entity* entity) = 0; // e.g. pots, skulls, pushblocks, ... standing on floors - virtual void toggle_backlayer_illumination() = 0; // only for CHAR_*: when going to the backlayer, turns on player emitted light - virtual void v34() = 0; // only ITEM_TORCH, calls Torch.light_up(false), can't get it to trigger - virtual void liberate_from_shop() = 0; // can also be seen as event: when you anger the shopkeeper, this function gets called for each item; can be called on shopitems individually as well and they become 'purchased' + virtual uint16_t get_metadata() = 0; // 27 + virtual void apply_metadata(uint16_t metadata) = 0; // 28 + virtual void on_walked_on_by(Entity* walker) = 0; // 29, hits when monster/player walks on a floor, does something when walker.velocityy<-0.21 (falling onto) and walker.hitboxy * hitboxx > 0.09 + virtual void on_walked_off_by(Entity* walker) = 0; // 30, appears to be disabled in 1.23.3? hits when monster/player walks off a floor, it checks whether the walker has floor as overlay, and if so, removes walker from floor's items by calling virtual remove_item_ptr + virtual void on_ledge_grab(Entity* who) = 0; // 31, only ACTIVEFLOOR_FALLING_PLATFORM, does something with game menager + virtual void on_stood_on_by(Entity* entity) = 0; // 32, e.g. pots, skulls, pushblocks, ... standing on floors + virtual void toggle_backlayer_illumination() = 0; // 33, only for CHAR_*: when going to the backlayer, turns on player emitted light + virtual void v34() = 0; // 34, only ITEM_TORCH, calls Torch.light_up(false), can't get it to trigger + virtual void liberate_from_shop() = 0; // 35, can also be seen as event: when you anger the shopkeeper, this function gets called for each item; can be called on shopitems individually as well and they become 'purchased' /// Applies changes made in `entity.type` - virtual void apply_db() = 0; // This is actually just an initialize call that is happening once after the entity is created + virtual void apply_db() = 0; // 36, This is actually just an initialize call that is happening once after the entity is created }; std::tuple get_position(uint32_t uid); diff --git a/src/game_api/movable.hpp b/src/game_api/movable.hpp index ae8a70d24..77ef8c09c 100644 --- a/src/game_api/movable.hpp +++ b/src/game_api/movable.hpp @@ -119,65 +119,65 @@ class Movable : public Entity /// Set the absolute position of an entity and offset all rendering related things accordingly to teleport without any interpolation or graphical glitches. If the camera is focused on the entity, it is also moved. void set_position(float to_x, float to_y); - virtual bool can_jump() = 0; - virtual void get_collision_info(CollisionInfo*) = 0; - virtual float sprint_factor() = 0; - virtual void calculate_jump_height() = 0; // when disabled, jump height is very high - virtual std::unordered_map& get_animation_map() = 0; - virtual void apply_velocity(float* velocities) = 0; // param is pointer to an array of two floats: velocity x and y - virtual int8_t stomp_damage() = 0; // calculates the amount of stomp damage applied (checks spike shoes, movable.state and stand_counter resulting in different damage values) - virtual int8_t stomp_damage_trampoline() = 0; // simply jumps to the 43rd virtual function, aka stomp_damage... - virtual bool is_on_fire() = 0; - virtual void v46() = 0; - virtual void v47() = 0; - virtual bool on_damage(Entity* damage_dealer, int8_t damage_amount, DAMAGE_TYPE damage_flags, Vec2* velocity, uint8_t unknown_damage_phase, uint16_t stun_amount, uint8_t iframes, bool unknown_is_final) = 0; + virtual bool can_jump() = 0; // 37 + virtual void get_collision_info(CollisionInfo*) = 0; // 38 + virtual float sprint_factor() = 0; // 39 + virtual void calculate_jump_height() = 0; // 40, when disabled, jump height is very high + virtual std::unordered_map& get_animation_map() = 0; // 41 + virtual void apply_velocity(Vec2* velocities) = 0; // 42, param is pointer to an array of two floats: velocity x and y + virtual int8_t stomp_damage() = 0; // 43, calculates the amount of stomp damage applied (checks spike shoes, movable.state and stand_counter resulting in different damage values) + virtual int8_t stomp_damage_trampoline() = 0; // 44, simply jumps to the 43rd virtual function, aka stomp_damage... + virtual bool is_on_fire() = 0; // 45 + virtual void v46() = 0; // 46 + virtual void v47() = 0; // 47 + virtual bool on_damage(Entity* damage_dealer, int8_t damage_amount, DAMAGE_TYPE damage_flags, Vec2* velocity, uint8_t unknown_damage_phase, uint16_t stun_amount, uint8_t iframes, bool unknown_is_final) = 0; // 48 /// Hit by broken arrows etc that don't deal damage, calls on_damage with 0 damage. - virtual void on_hit(Entity* damage_dealer) = 0; - virtual void v50() = 0; - virtual void stun(uint16_t framecount) = 0; - virtual void freeze(uint8_t framecount) = 0; + virtual void on_hit(Entity* damage_dealer) = 0; // 49 + virtual void v50() = 0; // 50 + virtual void stun(uint16_t framecount) = 0; // 51 + virtual void freeze(uint8_t framecount) = 0; // 52 /// Does not damage entity - virtual void light_on_fire(uint8_t time) = 0; - virtual void set_cursed(bool b) = 0; - virtual void on_spiderweb_collision() = 0; - virtual void set_last_owner_uid_b127(Entity* owner) = 0; // assigns player as last_owner_uid and also manipulates movable.b127 - virtual uint32_t get_last_owner_uid() = 0; // for players, it checks !stunned && !frozen && !cursed && !has_overlay; for others: just returns last_owner_uid - virtual void check_out_of_bounds() = 0; // kills with the 'still falling' death cause, is called for any item/fx/mount/monster/player but not for liquid :( - virtual void v59() = 0; - virtual Entity* standing_on() = 0; // looks up movable.standing_on_uid in state.instance_id_to_pointer - virtual void on_stomped_on_by(Entity* stomper) = 0; - virtual void on_thrown_by(Entity* thrower) = 0; // implemented for special cases like hired hand (player with ai_func), horned lizard... - virtual void on_clonegunshot_hit(Entity* clone) = 0; // implemented for player/hired hand: copies health to clone etc - virtual uint32_t get_type_id() = 0; - virtual bool doesnt_have_spikeshoes() = 0; - virtual bool is_player_mount_or_monster() = 0; - virtual void pick_up(Entity* entity_to_pick_up) = 0; - virtual void on_picked_up_by(Entity* entity_picking_up) = 0; - virtual void drop(Entity* entity_to_drop) = 0; // also used when throwing + virtual void light_on_fire(uint8_t time) = 0; // 53 + virtual void set_cursed(bool b) = 0; // 54 + virtual void on_spiderweb_collision() = 0; // 55 + virtual void set_last_owner_uid_b127(Entity* owner) = 0; // 56, assigns player as last_owner_uid and also manipulates movable.b127 + virtual uint32_t get_last_owner_uid() = 0; // 57, for players, it checks !stunned && !frozen && !cursed && !has_overlay; for others: just returns last_owner_uid + virtual void check_out_of_bounds() = 0; // 58, kills with the 'still falling' death cause, is called for any item/fx/mount/monster/player but not for liquid :( + virtual void v59() = 0; // 59 + virtual Entity* standing_on() = 0; // 60, looks up movable.standing_on_uid in state.instance_id_to_pointer + virtual void on_stomped_on_by(Entity* stomper) = 0; // 61 + virtual void on_thrown_by(Entity* thrower) = 0; // 62, implemented for special cases like hired hand (player with ai_func), horned lizard... + virtual void on_clonegunshot_hit(Entity* clone) = 0; // 63, implemented for player/hired hand: copies health to clone etc + virtual uint32_t get_type_id() = 0; // 64 + virtual bool doesnt_have_spikeshoes() = 0; // 65 + virtual bool is_player_mount_or_monster() = 0; // 66 + virtual void pick_up(Entity* entity_to_pick_up) = 0; // 67 + virtual void on_picked_up_by(Entity* entity_picking_up) = 0; // 68 + virtual void drop(Entity* entity_to_drop) = 0; // 69, also used when throwing /// Adds or subtracts the specified amount of money to the movable's (player's) inventory. Shows the calculation animation in the HUD. - virtual void add_money(uint32_t money) = 0; + virtual void add_money(uint32_t money) = 0; // 70 - virtual void apply_movement() = 0; // disable this function and things can't move, some spin in place - virtual void damage_entity(Entity* victim) = 0; // can't trigger, maybe extra params are needed - virtual bool is_monster_or_player() = 0; - virtual void initialize() = 0; // e.g. cobra: set random spit_timer; bat: set random stand_counter; emerald: set price - virtual void check_is_falling() = 0; // sets more_flags.falling by comparing velocityy to 0 - virtual void handle_stun_transition_animation() = 0; // e.g. the wiggle the dog does when waking up from being stunned - virtual void process_input() = 0; // unsure of params - virtual void post_collision_damage_related() = 0; // used for enemies attacks as well? - virtual void on_picked_up() = 0; // gets called after on_picked_up_by - virtual void hired_hand_related() = 0; // checks ai_func, gets triggered just after throwing hired hand - virtual void generate_fall_poof_particles() = 0; // entity.velocityy must be < -0.12 to generate a poof, might do other stuff regarding falling/landing - virtual void handle_fall_logic() = 0; // adjusts entity.velocityy when falling - virtual void apply_friction() = 0; // applies entity.type.friction to entity.velocityx - virtual void boss_related() = 0; // when disabled, quillback keeps stomping through the level, including border tiles - virtual void v85() = 0; // triggers when tusk is angered, calls get_last_owner_uid - virtual void gravity_related() = 0; - virtual void v87() = 0; - virtual void v88() = 0; - virtual void stack_plus_28_is_0() = 0; // unknown; triggers on item_rubble - virtual void on_crushed_by(Entity*) = 0; // e.g. crushed by elevator, punishball, pushblock, crushtrap (not quillback or boulder) + virtual void apply_movement() = 0; // 71, disable this function and things can't move, some spin in place + virtual void damage_entity(Entity* victim) = 0; // 72, can't trigger, maybe extra params are needed + virtual void v73() = 0; // 73 + virtual bool is_monster_or_player() = 0; // 74 + virtual void initialize() = 0; // 75, e.g. cobra: set random spit_timer; bat: set random stand_counter; emerald: set price + virtual void check_is_falling() = 0; // 76, sets more_flags.falling by comparing velocityy to 0 + virtual void handle_stun_transition_animation() = 0; // 77, e.g. the wiggle the dog does when waking up from being stunned + virtual void process_input() = 0; // 78, unsure of params + virtual void post_collision_damage_related() = 0; // 79, used for enemies attacks as well? + virtual void on_picked_up() = 0; // 80, gets called after on_picked_up_by + virtual void hired_hand_related() = 0; // 81, checks ai_func, gets triggered just after throwing hired hand + virtual void generate_fall_poof_particles() = 0; // 82, entity.velocityy must be < -0.12 to generate a poof, might do other stuff regarding falling/landing + virtual void handle_fall_logic() = 0; // 83, adjusts entity.velocityy when falling + virtual void apply_friction() = 0; // 84, applies entity.type.friction to entity.velocityx + virtual void boss_related() = 0; // 85, when disabled, quillback keeps stomping through the level, including border tiles + virtual void v86() = 0; // 86, triggers when tusk is angered, calls get_last_owner_uid + virtual void gravity_related() = 0; // 87 + virtual void v88() = 0; // 88 + virtual void stack_plus_28_is_0() = 0; // 89, unknown; triggers on item_rubble + virtual void on_crushed_by(Entity*) = 0; // 90, e.g. crushed by elevator, punishball, pushblock, crushtrap (not quillback or boulder) virtual void on_fall_onto(uint32_t unknown, Entity* fell_on_entity) = 0; - virtual void on_instakill_death() = 0; // seems to only trigger for enemies that die in one hit, // virtual 92 + virtual void on_instakill_death() = 0; // 92, seems to only trigger for enemies that die in one hit }; diff --git a/src/game_api/script/usertypes/vtables_lua.cpp b/src/game_api/script/usertypes/vtables_lua.cpp index cede17658..8f275b0fd 100644 --- a/src/game_api/script/usertypes/vtables_lua.cpp +++ b/src/game_api/script/usertypes/vtables_lua.cpp @@ -43,10 +43,46 @@ void register_usertypes(sol::state& lua) Entity, CallbackType::Entity, EntityVTable, - VTableEntry<"damage", 0x30, bool(Entity*, int8_t, uint16_t, Vec2*, uint8_t, uint16_t, uint8_t, bool)>, + VTableEntry<"can_jump", 37, bool()>, + VTableEntry<"get_collision_info", 38, void(CollisionInfo*)>, + VTableEntry<"sprint_factor", 39, float()>, + VTableEntry<"calculate_jump_height", 40, void()>, + VTableEntry<"apply_velocity", 42, void(Vec2*)>, + VTableEntry<"stomp_damage", 43, int8_t()>, + VTableEntry<"is_on_fire", 45, bool()>, + VTableEntry<"damage", 48, bool(Entity*, int8_t, uint16_t, Vec2*, uint8_t, uint16_t, uint8_t, bool)>, + VTableEntry<"on_hit", 49, void(Entity*)>, + VTableEntry<"stun", 51, void(uint16_t)>, + VTableEntry<"freeze", 52, void(uint8_t)>, + VTableEntry<"light_on_fire", 53, void(uint8_t)>, + VTableEntry<"set_cursed", 54, void(bool)>, + VTableEntry<"web_collision", 55, void()>, + VTableEntry<"set_owner", 56, void(Entity*)>, + VTableEntry<"get_owner", 57, uint32_t()>, + VTableEntry<"check_out_of_bounds", 58, void()>, + VTableEntry<"standing_on", 60, Entity*()>, + VTableEntry<"stomped_by", 61, void(Entity*)>, + VTableEntry<"thrown_by", 62, void(Entity*)>, + VTableEntry<"cloned_to", 63, void(Entity*)>, + VTableEntry<"get_type", 64, uint32_t()>, + VTableEntry<"pick_up", 67, void(Entity*)>, + VTableEntry<"picked_up_by", 68, void(Entity*)>, + VTableEntry<"drop", 69, void(Entity*)>, + VTableEntry<"add_money", 70, void(uint32_t)>, VTableEntry<"apply_movement", 71, void()>, - VTableEntry<"check_is_falling", 75, void()>, - VTableEntry<"process_input", 77, void()>>; + VTableEntry<"damage_entity", 72, void(Entity*)>, + VTableEntry<"initialize", 75, void()>, + VTableEntry<"check_is_falling", 76, void()>, + VTableEntry<"stun_animation", 77, void()>, + VTableEntry<"process_input", 78, void()>, + VTableEntry<"collision_damage", 79, void()>, + VTableEntry<"picked_up", 80, void()>, + VTableEntry<"poof_particles", 82, void()>, + VTableEntry<"fall_logic", 83, void()>, + VTableEntry<"apply_friction", 84, void()>, + VTableEntry<"crush", 90, void()>, + VTableEntry<"fall_on", 91, void()>, + VTableEntry<"instakill", 92, void()>>; static MovableVTable movable_vtable(lua, lua["Movable"], "ENTITY_OVERRIDE"); using FloorVTable = HookableVTable< From a1c92e9e044d247ce568138109bf32b85277a88d Mon Sep 17 00:00:00 2001 From: Dregu Date: Sun, 24 Sep 2023 03:15:26 +0300 Subject: [PATCH 02/10] forgot a sig --- src/game_api/movable.hpp | 108 +++++++++--------- src/game_api/script/usertypes/vtables_lua.cpp | 2 +- 2 files changed, 56 insertions(+), 54 deletions(-) diff --git a/src/game_api/movable.hpp b/src/game_api/movable.hpp index 77ef8c09c..8ed509a1b 100644 --- a/src/game_api/movable.hpp +++ b/src/game_api/movable.hpp @@ -119,65 +119,67 @@ class Movable : public Entity /// Set the absolute position of an entity and offset all rendering related things accordingly to teleport without any interpolation or graphical glitches. If the camera is focused on the entity, it is also moved. void set_position(float to_x, float to_y); - virtual bool can_jump() = 0; // 37 - virtual void get_collision_info(CollisionInfo*) = 0; // 38 - virtual float sprint_factor() = 0; // 39 - virtual void calculate_jump_height() = 0; // 40, when disabled, jump height is very high + virtual bool can_jump() = 0; // 37 + virtual void get_collision_info(CollisionInfo*) = 0; // 38 + virtual float sprint_factor() = 0; // 39 + virtual void calculate_jump_height() = 0; // 40, when disabled, jump height is very high virtual std::unordered_map& get_animation_map() = 0; // 41 - virtual void apply_velocity(Vec2* velocities) = 0; // 42, param is pointer to an array of two floats: velocity x and y - virtual int8_t stomp_damage() = 0; // 43, calculates the amount of stomp damage applied (checks spike shoes, movable.state and stand_counter resulting in different damage values) - virtual int8_t stomp_damage_trampoline() = 0; // 44, simply jumps to the 43rd virtual function, aka stomp_damage... - virtual bool is_on_fire() = 0; // 45 - virtual void v46() = 0; // 46 - virtual void v47() = 0; // 47 + virtual void apply_velocity(Vec2* velocities) = 0; // 42, param is pointer to an array of two floats: velocity x and y + virtual int8_t stomp_damage() = 0; // 43, calculates the amount of stomp damage applied (checks spike shoes, movable.state and stand_counter resulting in different damage values) + virtual int8_t stomp_damage_trampoline() = 0; // 44, simply jumps to the 43rd virtual function, aka stomp_damage... + virtual bool is_on_fire() = 0; // 45 + virtual void v46() = 0; // 46 + virtual void v47() = 0; // 47 + virtual bool on_damage(Entity* damage_dealer, int8_t damage_amount, DAMAGE_TYPE damage_flags, Vec2* velocity, uint8_t unknown_damage_phase, uint16_t stun_amount, uint8_t iframes, bool unknown_is_final) = 0; // 48 + /// Hit by broken arrows etc that don't deal damage, calls on_damage with 0 damage. virtual void on_hit(Entity* damage_dealer) = 0; // 49 - virtual void v50() = 0; // 50 - virtual void stun(uint16_t framecount) = 0; // 51 - virtual void freeze(uint8_t framecount) = 0; // 52 + virtual void v50() = 0; // 50 + virtual void stun(uint16_t framecount) = 0; // 51 + virtual void freeze(uint8_t framecount) = 0; // 52 + /// Does not damage entity - virtual void light_on_fire(uint8_t time) = 0; // 53 - virtual void set_cursed(bool b) = 0; // 54 - virtual void on_spiderweb_collision() = 0; // 55 - virtual void set_last_owner_uid_b127(Entity* owner) = 0; // 56, assigns player as last_owner_uid and also manipulates movable.b127 - virtual uint32_t get_last_owner_uid() = 0; // 57, for players, it checks !stunned && !frozen && !cursed && !has_overlay; for others: just returns last_owner_uid - virtual void check_out_of_bounds() = 0; // 58, kills with the 'still falling' death cause, is called for any item/fx/mount/monster/player but not for liquid :( - virtual void v59() = 0; // 59 - virtual Entity* standing_on() = 0; // 60, looks up movable.standing_on_uid in state.instance_id_to_pointer - virtual void on_stomped_on_by(Entity* stomper) = 0; // 61 - virtual void on_thrown_by(Entity* thrower) = 0; // 62, implemented for special cases like hired hand (player with ai_func), horned lizard... - virtual void on_clonegunshot_hit(Entity* clone) = 0; // 63, implemented for player/hired hand: copies health to clone etc - virtual uint32_t get_type_id() = 0; // 64 - virtual bool doesnt_have_spikeshoes() = 0; // 65 - virtual bool is_player_mount_or_monster() = 0; // 66 - virtual void pick_up(Entity* entity_to_pick_up) = 0; // 67 + virtual void light_on_fire(uint8_t time) = 0; // 53 + virtual void set_cursed(bool b) = 0; // 54 + virtual void on_spiderweb_collision() = 0; // 55 + virtual void set_last_owner_uid_b127(Entity* owner) = 0; // 56, assigns player as last_owner_uid and also manipulates movable.b127 + virtual uint32_t get_last_owner_uid() = 0; // 57, for players, it checks !stunned && !frozen && !cursed && !has_overlay; for others: just returns last_owner_uid + virtual void check_out_of_bounds() = 0; // 58, kills with the 'still falling' death cause, is called for any item/fx/mount/monster/player but not for liquid :( + virtual void v59() = 0; // 59 + virtual Entity* standing_on() = 0; // 60, looks up movable.standing_on_uid in state.instance_id_to_pointer + virtual void on_stomped_on_by(Entity* stomper) = 0; // 61 + virtual void on_thrown_by(Entity* thrower) = 0; // 62, implemented for special cases like hired hand (player with ai_func), horned lizard... + virtual void on_clonegunshot_hit(Entity* clone) = 0; // 63, implemented for player/hired hand: copies health to clone etc + virtual uint32_t get_type_id() = 0; // 64 + virtual bool doesnt_have_spikeshoes() = 0; // 65 + virtual bool is_player_mount_or_monster() = 0; // 66 + virtual void pick_up(Entity* entity_to_pick_up) = 0; // 67 virtual void on_picked_up_by(Entity* entity_picking_up) = 0; // 68 - virtual void drop(Entity* entity_to_drop) = 0; // 69, also used when throwing + virtual void drop(Entity* entity_to_drop) = 0; // 69, also used when throwing /// Adds or subtracts the specified amount of money to the movable's (player's) inventory. Shows the calculation animation in the HUD. - virtual void add_money(uint32_t money) = 0; // 70 - - virtual void apply_movement() = 0; // 71, disable this function and things can't move, some spin in place - virtual void damage_entity(Entity* victim) = 0; // 72, can't trigger, maybe extra params are needed - virtual void v73() = 0; // 73 - virtual bool is_monster_or_player() = 0; // 74 - virtual void initialize() = 0; // 75, e.g. cobra: set random spit_timer; bat: set random stand_counter; emerald: set price - virtual void check_is_falling() = 0; // 76, sets more_flags.falling by comparing velocityy to 0 - virtual void handle_stun_transition_animation() = 0; // 77, e.g. the wiggle the dog does when waking up from being stunned - virtual void process_input() = 0; // 78, unsure of params - virtual void post_collision_damage_related() = 0; // 79, used for enemies attacks as well? - virtual void on_picked_up() = 0; // 80, gets called after on_picked_up_by - virtual void hired_hand_related() = 0; // 81, checks ai_func, gets triggered just after throwing hired hand - virtual void generate_fall_poof_particles() = 0; // 82, entity.velocityy must be < -0.12 to generate a poof, might do other stuff regarding falling/landing - virtual void handle_fall_logic() = 0; // 83, adjusts entity.velocityy when falling - virtual void apply_friction() = 0; // 84, applies entity.type.friction to entity.velocityx - virtual void boss_related() = 0; // 85, when disabled, quillback keeps stomping through the level, including border tiles - virtual void v86() = 0; // 86, triggers when tusk is angered, calls get_last_owner_uid - virtual void gravity_related() = 0; // 87 - virtual void v88() = 0; // 88 - virtual void stack_plus_28_is_0() = 0; // 89, unknown; triggers on item_rubble - virtual void on_crushed_by(Entity*) = 0; // 90, e.g. crushed by elevator, punishball, pushblock, crushtrap (not quillback or boulder) - virtual void on_fall_onto(uint32_t unknown, Entity* fell_on_entity) = 0; - virtual void on_instakill_death() = 0; // 92, seems to only trigger for enemies that die in one hit + virtual void add_money(uint32_t money) = 0; // 70 + virtual void apply_movement() = 0; // 71, disable this function and things can't move, some spin in place + virtual void damage_entity(Entity* victim) = 0; // 72, can't trigger, maybe extra params are needed + virtual void v73() = 0; // 73 + virtual bool is_monster_or_player() = 0; // 74 + virtual void initialize() = 0; // 75, e.g. cobra: set random spit_timer; bat: set random stand_counter; emerald: set price + virtual void check_is_falling() = 0; // 76, sets more_flags.falling by comparing velocityy to 0 + virtual void handle_stun_transition_animation() = 0; // 77, e.g. the wiggle the dog does when waking up from being stunned + virtual void process_input() = 0; // 78, unsure of params + virtual void post_collision_damage_related() = 0; // 79, used for enemies attacks as well? + virtual void on_picked_up() = 0; // 80, gets called after on_picked_up_by + virtual void hired_hand_related() = 0; // 81, checks ai_func, gets triggered just after throwing hired hand + virtual void generate_fall_poof_particles() = 0; // 82, entity.velocityy must be < -0.12 to generate a poof, might do other stuff regarding falling/landing + virtual void handle_fall_logic() = 0; // 83, adjusts entity.velocityy when falling + virtual void apply_friction() = 0; // 84, applies entity.type.friction to entity.velocityx + virtual void boss_related() = 0; // 85, when disabled, quillback keeps stomping through the level, including border tiles + virtual void v86() = 0; // 86, triggers when tusk is angered, calls get_last_owner_uid + virtual void gravity_related() = 0; // 87 + virtual void v88() = 0; // 88 + virtual void stack_plus_28_is_0() = 0; // 89, unknown; triggers on item_rubble + virtual void on_crushed_by(Entity*) = 0; // 90, e.g. crushed by elevator, punishball, pushblock, crushtrap (not quillback or boulder) + virtual void on_fall_onto(uint32_t unknown, Entity* fell_on_entity) = 0; // 91 + virtual void on_instakill_death() = 0; // 92, seems to only trigger for enemies that die in one hit }; diff --git a/src/game_api/script/usertypes/vtables_lua.cpp b/src/game_api/script/usertypes/vtables_lua.cpp index 8f275b0fd..a854b9775 100644 --- a/src/game_api/script/usertypes/vtables_lua.cpp +++ b/src/game_api/script/usertypes/vtables_lua.cpp @@ -81,7 +81,7 @@ void register_usertypes(sol::state& lua) VTableEntry<"fall_logic", 83, void()>, VTableEntry<"apply_friction", 84, void()>, VTableEntry<"crush", 90, void()>, - VTableEntry<"fall_on", 91, void()>, + VTableEntry<"fall_on", 91, void(uint32_t, Entity*)>, VTableEntry<"instakill", 92, void()>>; static MovableVTable movable_vtable(lua, lua["Movable"], "ENTITY_OVERRIDE"); From 7a1fd50c56b2906a73513528d8891c8cbfafbd43 Mon Sep 17 00:00:00 2001 From: Dregu Date: Sun, 24 Sep 2023 03:17:45 +0300 Subject: [PATCH 03/10] forgot a sig --- src/game_api/script/usertypes/vtables_lua.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game_api/script/usertypes/vtables_lua.cpp b/src/game_api/script/usertypes/vtables_lua.cpp index a854b9775..23bf55a27 100644 --- a/src/game_api/script/usertypes/vtables_lua.cpp +++ b/src/game_api/script/usertypes/vtables_lua.cpp @@ -80,7 +80,7 @@ void register_usertypes(sol::state& lua) VTableEntry<"poof_particles", 82, void()>, VTableEntry<"fall_logic", 83, void()>, VTableEntry<"apply_friction", 84, void()>, - VTableEntry<"crush", 90, void()>, + VTableEntry<"crush", 90, void(Entity*)>, VTableEntry<"fall_on", 91, void(uint32_t, Entity*)>, VTableEntry<"instakill", 92, void()>>; static MovableVTable movable_vtable(lua, lua["Movable"], "ENTITY_OVERRIDE"); From 16e3205b866120d86af1bc67a03ecd3449050543 Mon Sep 17 00:00:00 2001 From: Dregu Date: Thu, 5 Oct 2023 18:05:17 +0300 Subject: [PATCH 04/10] fix add_money --- src/game_api/movable.hpp | 2 +- src/game_api/script/usertypes/entity_lua.cpp | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/game_api/movable.hpp b/src/game_api/movable.hpp index 5de9a00c7..7ebafbaaf 100644 --- a/src/game_api/movable.hpp +++ b/src/game_api/movable.hpp @@ -167,7 +167,7 @@ class Movable : public Entity virtual void drop(Entity* entity_to_drop) = 0; // 69, also used when throwing /// Adds or subtracts the specified amount of money to the movable's (player's) inventory. Shows the calculation animation in the HUD. - virtual void add_money(uint32_t money) = 0; // 70 + virtual void add_money(uint32_t money, ENT_TYPE money_type) = 0; // 70 virtual void apply_movement() = 0; // 71, disable this function and things can't move, some spin in place virtual void damage_entity(Entity* victim) = 0; // 72, can't trigger, maybe extra params are needed virtual void v73() = 0; // 73 diff --git a/src/game_api/script/usertypes/entity_lua.cpp b/src/game_api/script/usertypes/entity_lua.cpp index 7cccdb145..27b1b34b4 100644 --- a/src/game_api/script/usertypes/entity_lua.cpp +++ b/src/game_api/script/usertypes/entity_lua.cpp @@ -14,7 +14,9 @@ #include "color.hpp" // for Color, Color::a, Color::b, Color::g #include "custom_types.hpp" // for get_custom_types_map +#include "entities_chars.hpp" // for Player #include "entity.hpp" // for Entity, EntityDB, Animation, Rect +#include "items.hpp" // for Inventory #include "math.hpp" // for Quad, AABB #include "movable.hpp" // for Movable, Movable::falling_timer #include "render_api.hpp" // for RenderInfo, RenderInfo::flip_horiz... @@ -283,7 +285,13 @@ void register_usertypes(sol::state& lua) auto light_on_fire = sol::overload( static_cast(&Movable::light_on_fire_broken), static_cast(&Movable::light_on_fire)); - + auto add_money = sol::overload( + [](Player& ent, uint32_t money) + { + ent.add_money(money, 0); + ent.inventory_ptr->collected_money_count--; + }, + &Movable::add_money); auto movable_type = lua.new_usertype("Movable", sol::base_classes, sol::bases()); movable_type["move"] = &Movable::move; movable_type["movex"] = &Movable::movex; @@ -332,7 +340,7 @@ void register_usertypes(sol::state& lua) movable_type["pick_up"] = &Movable::pick_up; movable_type["can_jump"] = &Movable::can_jump; movable_type["standing_on"] = &Movable::standing_on; - movable_type["add_money"] = &Movable::add_money; + movable_type["add_money"] = add_money; movable_type["is_on_fire"] = &Movable::is_on_fire; movable_type["damage"] = damage; movable_type["get_all_behaviors"] = &Movable::get_all_behaviors; From 2e051ff6f4962bc64e930d6ec66ca38305759b6e Mon Sep 17 00:00:00 2001 From: Dregu Date: Sun, 8 Oct 2023 03:54:59 +0300 Subject: [PATCH 05/10] door virtuals --- src/game_api/entities_floors.hpp | 10 ++++++---- .../script/usertypes/entities_floors_lua.cpp | 4 ++++ src/game_api/script/usertypes/vtables_lua.cpp | 12 ++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/game_api/entities_floors.hpp b/src/game_api/entities_floors.hpp index a97a48683..396a1068e 100644 --- a/src/game_api/entities_floors.hpp +++ b/src/game_api/entities_floors.hpp @@ -97,10 +97,12 @@ class Door : public Floor // returns 0.0 except for eggship doors // for example: FLOOR_DOOR_EGGSHIP_ROOM returns 0.75 when entering the room, and 1.0 when exiting, runs every frame while entering/exiting - virtual float v44() = 0; - /// Will alwyas return `true` for exits, layers and others that the game never locks, even if you lock it with `unlock` function - virtual bool is_unlocked() = 0; - virtual bool v46() = 0; // dunno, runs every frame when player overlays door + /// Returns the darkest light level used to fade the entity when entering or exiting. 0 = black, 1 = no change + virtual float light_level() = 0; + /// Should we display the button prompt when collided by player. Will always return `true` for exits, layers and others that the game never locks, even if you lock it with `unlock` function + virtual bool is_unlocked(Entity* player) = 0; + /// Can the door actually be entered by player. Overrides the button prompt too if false. + virtual bool can_enter(Entity* player) = 0; }; class ExitDoor : public Door diff --git a/src/game_api/script/usertypes/entities_floors_lua.cpp b/src/game_api/script/usertypes/entities_floors_lua.cpp index 28ba92c95..b7da6cdcc 100644 --- a/src/game_api/script/usertypes/entities_floors_lua.cpp +++ b/src/game_api/script/usertypes/entities_floors_lua.cpp @@ -90,8 +90,12 @@ void register_usertypes(sol::state& lua) &Door::fx_button, "enter", &Door::enter, + "light_level", + &Door::light_level, "is_unlocked", &Door::is_unlocked, + "can_enter", + &Door::can_enter, "unlock", &Door::unlock, sol::base_classes, diff --git a/src/game_api/script/usertypes/vtables_lua.cpp b/src/game_api/script/usertypes/vtables_lua.cpp index 23bf55a27..e85feda3b 100644 --- a/src/game_api/script/usertypes/vtables_lua.cpp +++ b/src/game_api/script/usertypes/vtables_lua.cpp @@ -92,6 +92,18 @@ void register_usertypes(sol::state& lua) VTableEntry<"floor_update", 0x26, void()>>; static FloorVTable floor_vtable(lua, lua["Floor"], "ENTITY_OVERRIDE"); + using DoorVTable = HookableVTable< + Entity, + CallbackType::Entity, + EntityVTable, + VTableEntry<"enter_attempt", 40, float(Entity*)>, + VTableEntry<"hide_ui", 41, float(Entity*)>, + VTableEntry<"enter", 42, uint8_t(Entity*)>, + VTableEntry<"light_level", 44, float()>, + VTableEntry<"is_unlocked", 45, bool(Entity*)>, + VTableEntry<"can_enter", 46, bool(Entity*)>>; + static DoorVTable door_vtable(lua, lua["Door"], "ENTITY_OVERRIDE"); + using RenderInfoVTable = HookableVTable< RenderInfo, CallbackType::Entity, From 6e96eae8643a9858a6b45d399592dd9058016ca5 Mon Sep 17 00:00:00 2001 From: Dregu Date: Sun, 8 Oct 2023 06:10:46 +0300 Subject: [PATCH 06/10] comment Door::enter --- src/game_api/entities_floors.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/game_api/entities_floors.hpp b/src/game_api/entities_floors.hpp index 396a1068e..7cc98f85a 100644 --- a/src/game_api/entities_floors.hpp +++ b/src/game_api/entities_floors.hpp @@ -90,6 +90,8 @@ class Door : public Floor // check if it's CHAR_*, then sets State.level_flags -> 21 (Hide hud, transition) virtual void hide_ui(Entity* who) = 0; + + /// Returns the entity state / behavior id to set the entity to after the entering animation. virtual uint8_t enter(Entity* who) = 0; // checks layer of the Entity entering, except for FLOOR_DOOR_EGGSHIP_ROOM which gets the overlay (BG_EGGSHIP_ROOM) and returns BGEggshipRoom.player_in From 05797762f565424292195675feddc851222d648f Mon Sep 17 00:00:00 2001 From: Dregu Date: Sun, 8 Oct 2023 15:25:00 +0300 Subject: [PATCH 07/10] fix bad virtual --- src/game_api/entities_floors.hpp | 2 +- src/game_api/script/usertypes/vtables_lua.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/game_api/entities_floors.hpp b/src/game_api/entities_floors.hpp index 7cc98f85a..01ce8b3d9 100644 --- a/src/game_api/entities_floors.hpp +++ b/src/game_api/entities_floors.hpp @@ -102,7 +102,7 @@ class Door : public Floor /// Returns the darkest light level used to fade the entity when entering or exiting. 0 = black, 1 = no change virtual float light_level() = 0; /// Should we display the button prompt when collided by player. Will always return `true` for exits, layers and others that the game never locks, even if you lock it with `unlock` function - virtual bool is_unlocked(Entity* player) = 0; + virtual bool is_unlocked() = 0; /// Can the door actually be entered by player. Overrides the button prompt too if false. virtual bool can_enter(Entity* player) = 0; }; diff --git a/src/game_api/script/usertypes/vtables_lua.cpp b/src/game_api/script/usertypes/vtables_lua.cpp index e85feda3b..c131d40e8 100644 --- a/src/game_api/script/usertypes/vtables_lua.cpp +++ b/src/game_api/script/usertypes/vtables_lua.cpp @@ -100,7 +100,7 @@ void register_usertypes(sol::state& lua) VTableEntry<"hide_ui", 41, float(Entity*)>, VTableEntry<"enter", 42, uint8_t(Entity*)>, VTableEntry<"light_level", 44, float()>, - VTableEntry<"is_unlocked", 45, bool(Entity*)>, + VTableEntry<"is_unlocked", 45, bool()>, VTableEntry<"can_enter", 46, bool(Entity*)>>; static DoorVTable door_vtable(lua, lua["Door"], "ENTITY_OVERRIDE"); From 3a2d0809ff9fd4d0abbd1d7f1d2dd33f13be8b4f Mon Sep 17 00:00:00 2001 From: Dregu Date: Sun, 8 Oct 2023 16:01:33 +0300 Subject: [PATCH 08/10] fix add_money fix --- src/game_api/movable.hpp | 12 ++++++++++-- src/game_api/script/usertypes/entity_lua.cpp | 10 ++++------ src/game_api/script/usertypes/vtables_lua.cpp | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/game_api/movable.hpp b/src/game_api/movable.hpp index 7ebafbaaf..487d63661 100644 --- a/src/game_api/movable.hpp +++ b/src/game_api/movable.hpp @@ -127,6 +127,14 @@ class Movable : public Entity /// Set the absolute position of an entity and offset all rendering related things accordingly to teleport without any interpolation or graphical glitches. If the camera is focused on the entity, it is also moved. void set_position(float to_x, float to_y); + // for backwards compatibility + // adds a coin to the table cause the collected_money_count is expected to increase + void add_money_broken(int amount) + { + static const auto coin = to_id("ENT_TYPE_ITEM_GOLDCOIN"); + this->collect_treasure(amount, coin); + } + virtual bool can_jump() = 0; // 37 virtual void get_collision_info(CollisionInfo*) = 0; // 38 virtual float sprint_factor() = 0; // 39 @@ -166,8 +174,8 @@ class Movable : public Entity virtual void on_picked_up_by(Entity* entity_picking_up) = 0; // 68 virtual void drop(Entity* entity_to_drop) = 0; // 69, also used when throwing - /// Adds or subtracts the specified amount of money to the movable's (player's) inventory. Shows the calculation animation in the HUD. - virtual void add_money(uint32_t money, ENT_TYPE money_type) = 0; // 70 + /// Adds or subtracts the specified amount of money to the movable's (player's) inventory. Shows the calculation animation in the HUD. Adds treasure to the inventory list shown on transition. Use the global add_money to add money without adding specific treasure. + virtual void collect_treasure(int32_t value, ENT_TYPE treasure) = 0; // 70 virtual void apply_movement() = 0; // 71, disable this function and things can't move, some spin in place virtual void damage_entity(Entity* victim) = 0; // 72, can't trigger, maybe extra params are needed virtual void v73() = 0; // 73 diff --git a/src/game_api/script/usertypes/entity_lua.cpp b/src/game_api/script/usertypes/entity_lua.cpp index 27b1b34b4..daa7a3d4f 100644 --- a/src/game_api/script/usertypes/entity_lua.cpp +++ b/src/game_api/script/usertypes/entity_lua.cpp @@ -286,12 +286,8 @@ void register_usertypes(sol::state& lua) static_cast(&Movable::light_on_fire_broken), static_cast(&Movable::light_on_fire)); auto add_money = sol::overload( - [](Player& ent, uint32_t money) - { - ent.add_money(money, 0); - ent.inventory_ptr->collected_money_count--; - }, - &Movable::add_money); + static_cast(&Movable::add_money_broken), + static_cast(&Movable::collect_treasure)); auto movable_type = lua.new_usertype("Movable", sol::base_classes, sol::bases()); movable_type["move"] = &Movable::move; movable_type["movex"] = &Movable::movex; @@ -340,7 +336,9 @@ void register_usertypes(sol::state& lua) movable_type["pick_up"] = &Movable::pick_up; movable_type["can_jump"] = &Movable::can_jump; movable_type["standing_on"] = &Movable::standing_on; + /// NoDoc movable_type["add_money"] = add_money; + movable_type["collect_treasure"] = &Movable::collect_treasure; movable_type["is_on_fire"] = &Movable::is_on_fire; movable_type["damage"] = damage; movable_type["get_all_behaviors"] = &Movable::get_all_behaviors; diff --git a/src/game_api/script/usertypes/vtables_lua.cpp b/src/game_api/script/usertypes/vtables_lua.cpp index c131d40e8..215074934 100644 --- a/src/game_api/script/usertypes/vtables_lua.cpp +++ b/src/game_api/script/usertypes/vtables_lua.cpp @@ -68,7 +68,7 @@ void register_usertypes(sol::state& lua) VTableEntry<"pick_up", 67, void(Entity*)>, VTableEntry<"picked_up_by", 68, void(Entity*)>, VTableEntry<"drop", 69, void(Entity*)>, - VTableEntry<"add_money", 70, void(uint32_t)>, + VTableEntry<"collect_treasure", 70, void(int32_t, uint32_t)>, VTableEntry<"apply_movement", 71, void()>, VTableEntry<"damage_entity", 72, void(Entity*)>, VTableEntry<"initialize", 75, void()>, From deac8fd84badf3d2988fdca368b33e2b49fea230 Mon Sep 17 00:00:00 2001 From: Dregu Date: Thu, 12 Oct 2023 12:57:16 +0300 Subject: [PATCH 09/10] remove weird movable hooks --- src/game_api/script/usertypes/vtables_lua.cpp | 21 +++---------------- 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/src/game_api/script/usertypes/vtables_lua.cpp b/src/game_api/script/usertypes/vtables_lua.cpp index 215074934..21fdb59c6 100644 --- a/src/game_api/script/usertypes/vtables_lua.cpp +++ b/src/game_api/script/usertypes/vtables_lua.cpp @@ -44,10 +44,6 @@ void register_usertypes(sol::state& lua) CallbackType::Entity, EntityVTable, VTableEntry<"can_jump", 37, bool()>, - VTableEntry<"get_collision_info", 38, void(CollisionInfo*)>, - VTableEntry<"sprint_factor", 39, float()>, - VTableEntry<"calculate_jump_height", 40, void()>, - VTableEntry<"apply_velocity", 42, void(Vec2*)>, VTableEntry<"stomp_damage", 43, int8_t()>, VTableEntry<"is_on_fire", 45, bool()>, VTableEntry<"damage", 48, bool(Entity*, int8_t, uint16_t, Vec2*, uint8_t, uint16_t, uint8_t, bool)>, @@ -57,32 +53,21 @@ void register_usertypes(sol::state& lua) VTableEntry<"light_on_fire", 53, void(uint8_t)>, VTableEntry<"set_cursed", 54, void(bool)>, VTableEntry<"web_collision", 55, void()>, - VTableEntry<"set_owner", 56, void(Entity*)>, - VTableEntry<"get_owner", 57, uint32_t()>, VTableEntry<"check_out_of_bounds", 58, void()>, VTableEntry<"standing_on", 60, Entity*()>, VTableEntry<"stomped_by", 61, void(Entity*)>, VTableEntry<"thrown_by", 62, void(Entity*)>, VTableEntry<"cloned_to", 63, void(Entity*)>, - VTableEntry<"get_type", 64, uint32_t()>, VTableEntry<"pick_up", 67, void(Entity*)>, VTableEntry<"picked_up_by", 68, void(Entity*)>, VTableEntry<"drop", 69, void(Entity*)>, VTableEntry<"collect_treasure", 70, void(int32_t, uint32_t)>, - VTableEntry<"apply_movement", 71, void()>, - VTableEntry<"damage_entity", 72, void(Entity*)>, VTableEntry<"initialize", 75, void()>, - VTableEntry<"check_is_falling", 76, void()>, - VTableEntry<"stun_animation", 77, void()>, VTableEntry<"process_input", 78, void()>, - VTableEntry<"collision_damage", 79, void()>, VTableEntry<"picked_up", 80, void()>, - VTableEntry<"poof_particles", 82, void()>, - VTableEntry<"fall_logic", 83, void()>, + VTableEntry<"fall", 83, void()>, VTableEntry<"apply_friction", 84, void()>, - VTableEntry<"crush", 90, void(Entity*)>, - VTableEntry<"fall_on", 91, void(uint32_t, Entity*)>, - VTableEntry<"instakill", 92, void()>>; + VTableEntry<"crush", 90, void(Entity*)>>; static MovableVTable movable_vtable(lua, lua["Movable"], "ENTITY_OVERRIDE"); using FloorVTable = HookableVTable< @@ -97,7 +82,7 @@ void register_usertypes(sol::state& lua) CallbackType::Entity, EntityVTable, VTableEntry<"enter_attempt", 40, float(Entity*)>, - VTableEntry<"hide_ui", 41, float(Entity*)>, + VTableEntry<"hide_hud", 41, float(Entity*)>, VTableEntry<"enter", 42, uint8_t(Entity*)>, VTableEntry<"light_level", 44, float()>, VTableEntry<"is_unlocked", 45, bool()>, From 36092e4a970bbc87ad04e78f2d021baab8e3f8f9 Mon Sep 17 00:00:00 2001 From: Dregu Date: Thu, 12 Oct 2023 13:15:19 +0300 Subject: [PATCH 10/10] document a few weirder virtuals --- src/game_api/movable.hpp | 53 ++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/src/game_api/movable.hpp b/src/game_api/movable.hpp index 487d63661..06b8d257a 100644 --- a/src/game_api/movable.hpp +++ b/src/game_api/movable.hpp @@ -135,17 +135,19 @@ class Movable : public Entity this->collect_treasure(amount, coin); } + /// Return true if the entity is allowed to jump, even midair. Return false and can't jump, except from ladders apparently. virtual bool can_jump() = 0; // 37 virtual void get_collision_info(CollisionInfo*) = 0; // 38 virtual float sprint_factor() = 0; // 39 virtual void calculate_jump_height() = 0; // 40, when disabled, jump height is very high virtual std::unordered_map& get_animation_map() = 0; // 41 virtual void apply_velocity(Vec2* velocities) = 0; // 42, param is pointer to an array of two floats: velocity x and y - virtual int8_t stomp_damage() = 0; // 43, calculates the amount of stomp damage applied (checks spike shoes, movable.state and stand_counter resulting in different damage values) - virtual int8_t stomp_damage_trampoline() = 0; // 44, simply jumps to the 43rd virtual function, aka stomp_damage... - virtual bool is_on_fire() = 0; // 45 - virtual void v46() = 0; // 46 - virtual void v47() = 0; // 47 + /// Returns stomp damage based on shoes and fall time + virtual int8_t stomp_damage() = 0; // 43, calculates the amount of stomp damage applied (checks spike shoes, movable.state and stand_counter resulting in different damage values) + virtual int8_t stomp_damage_trampoline() = 0; // 44, simply jumps to the 43rd virtual function, aka stomp_damage... + virtual bool is_on_fire() = 0; // 45 + virtual void v46() = 0; // 46 + virtual void v47() = 0; // 47 virtual bool on_damage(Entity* damage_dealer, int8_t damage_amount, DAMAGE_TYPE damage_flags, Vec2* velocity, uint8_t unknown_damage_phase, uint16_t stun_amount, uint8_t iframes, bool unknown_is_final) = 0; // 48 @@ -156,11 +158,12 @@ class Movable : public Entity virtual void freeze(uint8_t framecount) = 0; // 52 /// Does not damage entity - virtual void light_on_fire(uint8_t time) = 0; // 53 - virtual void set_cursed(bool b) = 0; // 54 - virtual void on_spiderweb_collision() = 0; // 55 - virtual void set_last_owner_uid_b127(Entity* owner) = 0; // 56, assigns player as last_owner_uid and also manipulates movable.b127 - virtual uint32_t get_last_owner_uid() = 0; // 57, for players, it checks !stunned && !frozen && !cursed && !has_overlay; for others: just returns last_owner_uid + virtual void light_on_fire(uint8_t time) = 0; // 53 + virtual void set_cursed(bool b) = 0; // 54 + virtual void on_spiderweb_collision() = 0; // 55 + virtual void set_last_owner_uid_b127(Entity* owner) = 0; // 56, assigns player as last_owner_uid and also manipulates movable.b127 + virtual uint32_t get_last_owner_uid() = 0; // 57, for players, it checks !stunned && !frozen && !cursed && !has_overlay; for others: just returns last_owner_uid + /// Disable to not get killed outside level bounds. virtual void check_out_of_bounds() = 0; // 58, kills with the 'still falling' death cause, is called for any item/fx/mount/monster/player but not for liquid :( virtual void v59() = 0; // 59 virtual Entity* standing_on() = 0; // 60, looks up movable.standing_on_uid in state.instance_id_to_pointer @@ -172,22 +175,24 @@ class Movable : public Entity virtual bool is_player_mount_or_monster() = 0; // 66 virtual void pick_up(Entity* entity_to_pick_up) = 0; // 67 virtual void on_picked_up_by(Entity* entity_picking_up) = 0; // 68 - virtual void drop(Entity* entity_to_drop) = 0; // 69, also used when throwing + /// Called when dropping or throwing + virtual void drop(Entity* entity_to_drop) = 0; // 69, also used when throwing /// Adds or subtracts the specified amount of money to the movable's (player's) inventory. Shows the calculation animation in the HUD. Adds treasure to the inventory list shown on transition. Use the global add_money to add money without adding specific treasure. - virtual void collect_treasure(int32_t value, ENT_TYPE treasure) = 0; // 70 - virtual void apply_movement() = 0; // 71, disable this function and things can't move, some spin in place - virtual void damage_entity(Entity* victim) = 0; // 72, can't trigger, maybe extra params are needed - virtual void v73() = 0; // 73 - virtual bool is_monster_or_player() = 0; // 74 - virtual void initialize() = 0; // 75, e.g. cobra: set random spit_timer; bat: set random stand_counter; emerald: set price - virtual void check_is_falling() = 0; // 76, sets more_flags.falling by comparing velocityy to 0 - virtual void handle_stun_transition_animation() = 0; // 77, e.g. the wiggle the dog does when waking up from being stunned - virtual void process_input() = 0; // 78, unsure of params - virtual void post_collision_damage_related() = 0; // 79, used for enemies attacks as well? - virtual void on_picked_up() = 0; // 80, gets called after on_picked_up_by - virtual void hired_hand_related() = 0; // 81, checks ai_func, gets triggered just after throwing hired hand - virtual void generate_fall_poof_particles() = 0; // 82, entity.velocityy must be < -0.12 to generate a poof, might do other stuff regarding falling/landing + virtual void collect_treasure(int32_t value, ENT_TYPE treasure) = 0; // 70 + virtual void apply_movement() = 0; // 71, disable this function and things can't move, some spin in place + virtual void damage_entity(Entity* victim) = 0; // 72, can't trigger, maybe extra params are needed + virtual void v73() = 0; // 73 + virtual bool is_monster_or_player() = 0; // 74 + virtual void initialize() = 0; // 75, e.g. cobra: set random spit_timer; bat: set random stand_counter; emerald: set price + virtual void check_is_falling() = 0; // 76, sets more_flags.falling by comparing velocityy to 0 + virtual void handle_stun_transition_animation() = 0; // 77, e.g. the wiggle the dog does when waking up from being stunned + virtual void process_input() = 0; // 78, unsure of params + virtual void post_collision_damage_related() = 0; // 79, used for enemies attacks as well? + virtual void on_picked_up() = 0; // 80, gets called after on_picked_up_by + virtual void hired_hand_related() = 0; // 81, checks ai_func, gets triggered just after throwing hired hand + virtual void generate_fall_poof_particles() = 0; // 82, entity.velocityy must be < -0.12 to generate a poof, might do other stuff regarding falling/landing + /// Applies gravity to entity. Disable to float like on hoverpack. virtual void handle_fall_logic() = 0; // 83, adjusts entity.velocityy when falling virtual void apply_friction() = 0; // 84, applies entity.type.friction to entity.velocityx virtual void boss_related() = 0; // 85, when disabled, quillback keeps stomping through the level, including border tiles