From 82b3ca3a9e55864f1103e9f76ab19c3f0d0b6156 Mon Sep 17 00:00:00 2001 From: Mr-Auto <36127424+Mr-Auto@users.noreply.github.com> Date: Sun, 24 Nov 2024 17:22:15 +0100 Subject: [PATCH 1/7] add QuestLogic and JournalData stuff --- src/game_api/game_manager.hpp | 65 +++++++++++++++++++++++++++++++--- src/game_api/screen.hpp | 8 ++--- src/game_api/state_structs.hpp | 35 ++++++++++++++---- 3 files changed, 94 insertions(+), 14 deletions(-) diff --git a/src/game_api/game_manager.hpp b/src/game_api/game_manager.hpp index 0ac64c11b..704d31068 100644 --- a/src/game_api/game_manager.hpp +++ b/src/game_api/game_manager.hpp @@ -3,10 +3,11 @@ #include // for size_t #include // for uint32_t, uint8_t, int8_t -#include "aliases.hpp" // for MAX_PLAYERS -#include "render_api.hpp" // for TextureRenderingInfo -#include "sound_manager.hpp" -#include "thread_utils.hpp" // for OnHeapPointer +#include "aliases.hpp" // for MAX_PLAYERS +#include "containers/game_unordered_map.hpp" // for game_unordered_map +#include "render_api.hpp" // for TextureRenderingInfo +#include "sound_manager.hpp" // for BackgroundSound +#include "thread_utils.hpp" // for OnHeapPointer struct SaveData; class ScreenCamp; @@ -35,12 +36,68 @@ struct JournalPopupUI uint32_t timer; float slide_position; uint8_t unknown; + // uint8_t padding[3]; // probably? +}; + +class JournalData +{ + uint32_t page_nr; + uint32_t sprite_id; + STRINGID name; + STRINGID description; + float scale; + float offset_x; + float offset_y; +}; + +class JournalBestiaryData : public JournalData +{ + TEXTURE texture; + uint32_t background_sprite_id; + bool killed_by_NA; + bool defeated_NA; +}; + +class JournalPeopleData : public JournalData +{ + TEXTURE texture; + uint32_t background_sprite_id; + bool killed_by_NA; + bool defeated_NA; + // uint16_t padding; + TEXTURE portret_texture; +}; + +class JournalTrapData : public JournalData +{ + TEXTURE texture; + uint32_t background_sprite_id; +}; + +struct StickersData +{ + uint32_t sprite_id; + TEXTURE texture; }; struct SaveRelated { OnHeapPointer savedata; JournalPopupUI journal_popup_ui; + + ENT_TYPE player_entity; // for the journal stuff, probably the leader? + ENT_TYPE progress_stickers_powerups[29]; // pre-journal progress setup, maybe gathering from all players or something? + + /// Scale and offset not used + game_unordered_map places_data; + game_unordered_map bestiary_data; + game_unordered_map monster_part_to_main; // used to map stuff like Osiris_Hand -> Osiris_Head, Hundun limbs -> Hundun etc. + game_unordered_map people_info; + game_unordered_map people_part_to_main; // used to map shopkeeper clone to shopkeeper only + game_unordered_map item_info; + game_unordered_map trap_info; + game_unordered_map trap_part_to_main; // used for stuff like upsidedown_spikes -> spikes, skulldrop skulls -> skulldrop trap etc. + game_unordered_map stickers_data; }; struct BGMUnknown diff --git a/src/game_api/screen.hpp b/src/game_api/screen.hpp index d8517594a..6307b76b6 100644 --- a/src/game_api/screen.hpp +++ b/src/game_api/screen.hpp @@ -505,10 +505,10 @@ class ScreenCharacterSelect : public Screen // ID: 9 float topleft_woodpanel_esc_slidein; float start_panel_slidein; float action_buttons_keycap_size; - bool unknown64a; - bool unknown64b; - bool unknown64c; - bool unknown64d; + bool screen_loading; // locks the inputs? + bool unknown64b; // sets the state.ingame + bool seeded_run; + bool daily_challenge; uint32_t next_screen_to_load; bool not_ready_to_start_yet; uint8_t available_mine_entrances; // The rest are boarded off diff --git a/src/game_api/state_structs.hpp b/src/game_api/state_structs.hpp index dfccf900e..9cccdd475 100644 --- a/src/game_api/state_structs.hpp +++ b/src/game_api/state_structs.hpp @@ -91,14 +91,37 @@ struct PlayerInputs }; }; +struct QuestLogic +{ + // used to access flags in QuestsInfo + uint32_t id; + + // called during layer loading by the state update, sets the level generation flags etc. + virtual void pre_level_gen() = 0; + + // Gets called on every non-CO level by 18 virtual in current theme. Function checks whether the quest needs to be initialized. + // Yang: checks whether his quest status = 1 -> makes his pen work + // Sisters: make them appear on Olmec + // Horsing: makes him appear in Vlad's castle + // Sparrow: nop + // Tusk: populates pleasure palace with other characters depending on their quest state + // Beg: nop + virtual void post_level_gen() = 0; + + // Only implemented for Beg quest, called by the 24 virtual in current theme + virtual void post_level_gen2() = 0; + + virtual ~QuestLogic() = delete; +}; + struct QuestsInfo { - size_t unknown1; // the first six are pointers to small similar objects - size_t unknown2; // that don't appear to change at all - size_t unknown3; - size_t unknown4; - size_t unknown5; - size_t unknown6; + QuestLogic* yang; + QuestLogic* jungle_sisters; + QuestLogic* van_horsing; + QuestLogic* sparrow; + QuestLogic* madame_tusk; + QuestLogic* beg; int8_t yang_state; int8_t jungle_sisters_flags; // flags! not state ; -1 = sisters angry int8_t van_horsing_state; From 27f65b8e4c59d24a55083254ef792a1ddcd0fb8f Mon Sep 17 00:00:00 2001 From: Mr-Auto <36127424+Mr-Auto@users.noreply.github.com> Date: Sat, 30 Nov 2024 18:31:14 +0100 Subject: [PATCH 2/7] expose all of the JournalPageData stuff --- docs/game_data/spel2.lua | 40 ++++++++ docs/src/includes/_types.md | 73 ++++++++++++++ src/game_api/game_manager.hpp | 35 ++++--- src/game_api/screen.hpp | 2 +- .../script/usertypes/game_manager_lua.cpp | 95 ++++++++++++++++++- 5 files changed, 231 insertions(+), 14 deletions(-) diff --git a/docs/game_data/spel2.lua b/docs/game_data/spel2.lua index 915759e34..0724d29f4 100644 --- a/docs/game_data/spel2.lua +++ b/docs/game_data/spel2.lua @@ -2356,6 +2356,46 @@ do ---@class SaveRelated ---@field journal_popup_ui JournalPopupUI + ---@field places_data table @Scale and offset not used in those pages. Can't add more + ---@field bestiary_data table + ---@field monster_part_to_main table @used to map stuff like Osiris_Hand -> Osiris_Head, Hundun limbs -> Hundun etc. + ---@field people_info table + ---@field people_part_to_main table @used to map shopkeeper clone to shopkeeper only + ---@field item_info table + ---@field trap_info table + ---@field trap_part_to_main table @used for stuff like upsidedown_spikes -> spikes, skulldrop skulls -> skulldrop trap etc. + ---@field stickers_data table + ---@field get_SaveData fun(self): SaveData @Gets local version of the SaveData + +---@class JournalPageData + ---@field page_nr integer + ---@field sprite_id integer + ---@field name STRINGID + ---@field description STRINGID + ---@field scale number + ---@field offset_x number + ---@field offset_y number + +---@class JournalBestiaryData : JournalPageData + ---@field texture TEXTURE + ---@field background_sprite_id integer + ---@field killed_by_NA boolean + ---@field defeated_NA boolean + +---@class JournalPeopleData : JournalPageData + ---@field texture TEXTURE + ---@field background_sprite_id integer + ---@field killed_by_NA boolean + ---@field defeated_NA boolean + ---@field portret_texture TEXTURE + +---@class JournalTrapData : JournalPageData + ---@field texture TEXTURE + ---@field background_sprite_id integer + +---@class StickersData + ---@field sprite_id integer + ---@field texture TEXTURE ---@class JournalPopupUI ---@field wiggling_page_icon TextureRenderingInfo diff --git a/docs/src/includes/_types.md b/docs/src/includes/_types.md index 30a4ae45e..6d2d8d18f 100644 --- a/docs/src/includes/_types.md +++ b/docs/src/includes/_types.md @@ -779,6 +779,20 @@ Type | Name | Description [ENT_TYPE](#ENT_TYPE) | [owner_type](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=owner_type) | int | [owner_uid](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=owner_uid) | +### JournalPageData + +Used in [SaveRelated](#SaveRelated) + +Type | Name | Description +---- | ---- | ----------- +int | [page_nr](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=page_nr) | +int | [sprite_id](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=sprite_id) | +[STRINGID](#Aliases) | [name](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=name) | +[STRINGID](#Aliases) | [description](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=description) | +float | [scale](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=scale) | +float | [offset_x](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=offset_x) | +float | [offset_y](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=offset_y) | + ### KeyboardKey @@ -1028,6 +1042,15 @@ Type | Name | Description int | [column](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=column) | int | [row](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=row) | +### StickersData + +Used in [SaveRelated](#SaveRelated) + +Type | Name | Description +---- | ---- | ----------- +int | [sprite_id](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=sprite_id) | +[TEXTURE](#TEXTURE) | [texture](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=texture) | + ### Triangle @@ -1188,6 +1211,19 @@ array<[ControllerInput](#ControllerInput), 12> | [controller](https://gith ## Journal types +### JournalBestiaryData + +Used in [SaveRelated](#SaveRelated) +Derived from [JournalPageData](#JournalPageData) + + +Type | Name | Description +---- | ---- | ----------- +[TEXTURE](#TEXTURE) | [texture](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=texture) | +int | [background_sprite_id](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=background_sprite_id) | +bool | [killed_by_NA](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=killed_by_NA) | +bool | [defeated_NA](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=defeated_NA) | + ### JournalPage Used in [set_callback](#set_callback) with [ON](#ON).RENDER_POST_JOURNAL_PAGE @@ -1368,6 +1404,31 @@ Type | Name | Description [TextureRenderingInfo](#TextureRenderingInfo) | [trap_icon](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=trap_icon) | [TextureRenderingInfo](#TextureRenderingInfo) | [trap_background](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=trap_background) | +### JournalPeopleData + +Used in [SaveRelated](#SaveRelated) +Derived from [JournalPageData](#JournalPageData) + + +Type | Name | Description +---- | ---- | ----------- +[TEXTURE](#TEXTURE) | [texture](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=texture) | +int | [background_sprite_id](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=background_sprite_id) | +bool | [killed_by_NA](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=killed_by_NA) | +bool | [defeated_NA](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=defeated_NA) | +[TEXTURE](#TEXTURE) | [portret_texture](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=portret_texture) | + +### JournalTrapData + +Used in [SaveRelated](#SaveRelated) +Derived from [JournalPageData](#JournalPageData) + + +Type | Name | Description +---- | ---- | ----------- +[TEXTURE](#TEXTURE) | [texture](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=texture) | +int | [background_sprite_id](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=background_sprite_id) | + ## Levelgen types @@ -1966,6 +2027,7 @@ float | [sinewave_angle](https://github.com/spelunky-fyi/overlunky/search?l=Lua& ### JournalPopupUI +Used in [SaveRelated](#SaveRelated) Type | Name | Description ---- | ---- | ----------- @@ -2052,10 +2114,21 @@ int | [visibility](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=visi ### SaveRelated +Used in [GameManager](#GameManager) Type | Name | Description ---- | ---- | ----------- [JournalPopupUI](#JournalPopupUI) | [journal_popup_ui](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=journal_popup_ui) | +map<int, [JournalPageData](#JournalPageData)> | [places_data](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=places_data) | Scale and offset not used in those pages. Can't add more +map<[ENT_TYPE](#ENT_TYPE), [JournalBestiaryData](#JournalBestiaryData)> | [bestiary_data](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=bestiary_data) | +map<[ENT_TYPE](#ENT_TYPE), [ENT_TYPE](#ENT_TYPE)> | [monster_part_to_main](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=monster_part_to_main) | used to map stuff like Osiris_Hand -> Osiris_Head, [Hundun](#Hundun) limbs -> [Hundun](#Hundun) etc. +map<[ENT_TYPE](#ENT_TYPE), [JournalPeopleData](#JournalPeopleData)> | [people_info](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=people_info) | +map<[ENT_TYPE](#ENT_TYPE), [ENT_TYPE](#ENT_TYPE)> | [people_part_to_main](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=people_part_to_main) | used to map shopkeeper clone to shopkeeper only +map<[ENT_TYPE](#ENT_TYPE), [JournalPageData](#JournalPageData)> | [item_info](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=item_info) | +map<[ENT_TYPE](#ENT_TYPE), [JournalPageData](#JournalPageData)> | [trap_info](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=trap_info) | +map<[ENT_TYPE](#ENT_TYPE), [ENT_TYPE](#ENT_TYPE)> | [trap_part_to_main](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=trap_part_to_main) | used for stuff like upsidedown_spikes -> spikes, skulldrop skulls -> skulldrop trap etc. +map<[ENT_TYPE](#ENT_TYPE), [StickersData](#StickersData)> | [stickers_data](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=stickers_data) | +[SaveData](#SaveData) | [get_SaveData()](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=get_SaveData) | Gets local version of the [SaveData](#SaveData) ### Screen diff --git a/src/game_api/game_manager.hpp b/src/game_api/game_manager.hpp index 704d31068..f4f582940 100644 --- a/src/game_api/game_manager.hpp +++ b/src/game_api/game_manager.hpp @@ -39,8 +39,9 @@ struct JournalPopupUI // uint8_t padding[3]; // probably? }; -class JournalData +class JournalPageData { + public: uint32_t page_nr; uint32_t sprite_id; STRINGID name; @@ -50,16 +51,18 @@ class JournalData float offset_y; }; -class JournalBestiaryData : public JournalData +class JournalBestiaryData : public JournalPageData { + public: TEXTURE texture; uint32_t background_sprite_id; bool killed_by_NA; bool defeated_NA; }; -class JournalPeopleData : public JournalData +class JournalPeopleData : public JournalPageData { + public: TEXTURE texture; uint32_t background_sprite_id; bool killed_by_NA; @@ -68,8 +71,9 @@ class JournalPeopleData : public JournalData TEXTURE portret_texture; }; -class JournalTrapData : public JournalData +class JournalTrapData : public JournalPageData { + public: TEXTURE texture; uint32_t background_sprite_id; }; @@ -88,16 +92,25 @@ struct SaveRelated ENT_TYPE player_entity; // for the journal stuff, probably the leader? ENT_TYPE progress_stickers_powerups[29]; // pre-journal progress setup, maybe gathering from all players or something? - /// Scale and offset not used - game_unordered_map places_data; + /// Scale and offset not used in those pages. Can't add more + game_unordered_map places_data; game_unordered_map bestiary_data; - game_unordered_map monster_part_to_main; // used to map stuff like Osiris_Hand -> Osiris_Head, Hundun limbs -> Hundun etc. + /// used to map stuff like Osiris_Hand -> Osiris_Head, Hundun limbs -> Hundun etc. + game_unordered_map monster_part_to_main; game_unordered_map people_info; - game_unordered_map people_part_to_main; // used to map shopkeeper clone to shopkeeper only - game_unordered_map item_info; - game_unordered_map trap_info; - game_unordered_map trap_part_to_main; // used for stuff like upsidedown_spikes -> spikes, skulldrop skulls -> skulldrop trap etc. + /// used to map shopkeeper clone to shopkeeper only + game_unordered_map people_part_to_main; + game_unordered_map item_info; + game_unordered_map trap_info; + /// used for stuff like upsidedown_spikes -> spikes, skulldrop skulls -> skulldrop trap etc. + game_unordered_map trap_part_to_main; game_unordered_map stickers_data; + + /// Gets local version of the SaveData + SaveData* get_SaveData() + { + return savedata.decode_local(); + } }; struct BGMUnknown diff --git a/src/game_api/screen.hpp b/src/game_api/screen.hpp index 6307b76b6..5bb626e31 100644 --- a/src/game_api/screen.hpp +++ b/src/game_api/screen.hpp @@ -506,7 +506,7 @@ class ScreenCharacterSelect : public Screen // ID: 9 float start_panel_slidein; float action_buttons_keycap_size; bool screen_loading; // locks the inputs? - bool unknown64b; // sets the state.ingame + bool unknown64b; // sets the state.ingame bool seeded_run; bool daily_challenge; uint32_t next_screen_to_load; diff --git a/src/game_api/script/usertypes/game_manager_lua.cpp b/src/game_api/script/usertypes/game_manager_lua.cpp index ebfd36923..2d1ec85e3 100644 --- a/src/game_api/script/usertypes/game_manager_lua.cpp +++ b/src/game_api/script/usertypes/game_manager_lua.cpp @@ -10,8 +10,9 @@ #include "game_manager.hpp" // for GameManager, JournalPopupUI, GameProps #include "memory.hpp" // for memory_read TODO:temp +#include "savedata.hpp" // for SaveData #include "screen.hpp" // IWYU pragma: keep -#include "script/sol_helper.hpp" // +#include "script/sol_helper.hpp" // for ZeroIndexArray namespace NGM { @@ -78,10 +79,99 @@ void register_usertypes(sol::state& lua) gamemanager_type["buttons_controls"] = &GameManager::buttons_controls; gamemanager_type["buttons_movement"] = &GameManager::buttons_movement; + /// Used in GameManager lua.new_usertype( "SaveRelated", "journal_popup_ui", - &SaveRelated::journal_popup_ui); + &SaveRelated::journal_popup_ui, + "places_data", + &SaveRelated::places_data, + "bestiary_data", + &SaveRelated::bestiary_data, + "monster_part_to_main", + &SaveRelated::monster_part_to_main, + "people_info", + &SaveRelated::people_info, + "people_part_to_main", + &SaveRelated::people_part_to_main, + "item_info", + &SaveRelated::item_info, + "trap_info", + &SaveRelated::trap_info, + "trap_part_to_main", + &SaveRelated::trap_part_to_main, + "stickers_data", + &SaveRelated::stickers_data, + "get_SaveData", + &SaveRelated::get_SaveData); + + /// Used in SaveRelated + lua.new_usertype( + "JournalPageData", + "page_nr", + &JournalPageData::page_nr, + "sprite_id", + &JournalPageData::sprite_id, + "name", + &JournalPageData::name, + "description", + &JournalPageData::description, + "scale", + &JournalPageData::scale, + "offset_x", + &JournalPageData::offset_x, + "offset_y", + &JournalPageData::offset_y); + + /// Used in SaveRelated + lua.new_usertype( + "JournalBestiaryData", + "texture", + &JournalBestiaryData::texture, + "background_sprite_id", + &JournalBestiaryData::background_sprite_id, + "killed_by_NA", + &JournalBestiaryData::killed_by_NA, + "defeated_NA", + &JournalBestiaryData::defeated_NA, + sol::base_classes, + sol::bases()); + + /// Used in SaveRelated + lua.new_usertype( + "JournalPeopleData", + "texture", + &JournalPeopleData::texture, + "background_sprite_id", + &JournalPeopleData::background_sprite_id, + "killed_by_NA", + &JournalPeopleData::killed_by_NA, + "defeated_NA", + &JournalPeopleData::defeated_NA, + "portret_texture", + &JournalPeopleData::portret_texture, + sol::base_classes, + sol::bases()); + + /// Used in SaveRelated + lua.new_usertype( + "JournalTrapData", + "texture", + &JournalTrapData::texture, + "background_sprite_id", + &JournalTrapData::background_sprite_id, + sol::base_classes, + sol::bases()); + + /// Used in SaveRelated + lua.new_usertype( + "StickersData", + "sprite_id", + &StickersData::sprite_id, + "texture", + &StickersData::texture); + + /// Used in SaveRelated lua.new_usertype( "JournalPopupUI", "wiggling_page_icon", @@ -100,6 +190,7 @@ void register_usertypes(sol::state& lua) &JournalPopupUI::timer, "slide_position", &JournalPopupUI::slide_position); + auto gameprops_type = lua.new_usertype("GameProps"); /// NoDoc gameprops_type["buttons"] = sol::property([](GameProps& gp) -> uint32_t From 1a81adfffa41adc224f047c23a805d0de36e2be1 Mon Sep 17 00:00:00 2001 From: Mr-Auto <36127424+Mr-Auto@users.noreply.github.com> Date: Sun, 1 Dec 2024 21:03:32 +0100 Subject: [PATCH 3/7] exposed few values in ScreenCharacterSelect, some extra comments --- src/game_api/game_manager.hpp | 10 ++++++---- src/game_api/script/usertypes/level_lua.cpp | 2 +- src/game_api/script/usertypes/screen_lua.cpp | 6 ++++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/game_api/game_manager.hpp b/src/game_api/game_manager.hpp index f4f582940..9c8808230 100644 --- a/src/game_api/game_manager.hpp +++ b/src/game_api/game_manager.hpp @@ -51,26 +51,28 @@ class JournalPageData float offset_y; }; -class JournalBestiaryData : public JournalPageData +class JournalPeopleData : public JournalPageData { public: TEXTURE texture; uint32_t background_sprite_id; bool killed_by_NA; bool defeated_NA; + // uint16_t padding; + TEXTURE portret_texture; }; -class JournalPeopleData : public JournalPageData +// probably same as JournalPeopleData, just not using portret_texture +class JournalBestiaryData : public JournalPageData { public: TEXTURE texture; uint32_t background_sprite_id; bool killed_by_NA; bool defeated_NA; - // uint16_t padding; - TEXTURE portret_texture; }; +// this is probably part of JournalPageData, just only used for bestiary, people and trap class JournalTrapData : public JournalPageData { public: diff --git a/src/game_api/script/usertypes/level_lua.cpp b/src/game_api/script/usertypes/level_lua.cpp index 9ade948b6..7c1cecf21 100644 --- a/src/game_api/script/usertypes/level_lua.cpp +++ b/src/game_api/script/usertypes/level_lua.cpp @@ -1246,7 +1246,7 @@ void register_usertypes(sol::state& lua) auto customtheme_type = lua.new_usertype("CustomTheme", sol::constructors(), sol::base_classes, sol::bases()); customtheme_type["level_file"] = &CustomTheme::level_file; customtheme_type["theme"] = &CustomTheme::theme; - // NoDoc + /// NoDoc customtheme_type["base_theme"] = sol::property([](CustomTheme& ct) -> uint8_t { if (ct.base_theme < UINT8_MAX) diff --git a/src/game_api/script/usertypes/screen_lua.cpp b/src/game_api/script/usertypes/screen_lua.cpp index c5532f310..484a27393 100644 --- a/src/game_api/script/usertypes/screen_lua.cpp +++ b/src/game_api/script/usertypes/screen_lua.cpp @@ -348,6 +348,12 @@ void register_usertypes(sol::state& lua) screencharacterselect_type["topleft_woodpanel_esc_slidein"] = &ScreenCharacterSelect::topleft_woodpanel_esc_slidein; screencharacterselect_type["start_panel_slidein"] = &ScreenCharacterSelect::start_panel_slidein; screencharacterselect_type["action_buttons_keycap_size"] = &ScreenCharacterSelect::action_buttons_keycap_size; + screencharacterselect_type["screen_loading"] = &ScreenCharacterSelect::screen_loading; + screencharacterselect_type["seeded_run"] = &ScreenCharacterSelect::seeded_run; + screencharacterselect_type["daily_challenge"] = sol::readonly(&ScreenCharacterSelect::daily_challenge); + /// Short for `screen->next_screen_to_load == SCREEN.TEAM_SELECT and not screen->seeded_run and not screen->daily_challenge` + screencharacterselect_type["arena"] = sol::property([](ScreenCharacterSelect* screen) -> bool + { return screen->next_screen_to_load == 10 && !screen->seeded_run && !screen->daily_challenge; }); screencharacterselect_type["next_screen_to_load"] = &ScreenCharacterSelect::next_screen_to_load; screencharacterselect_type["not_ready_to_start_yet"] = &ScreenCharacterSelect::not_ready_to_start_yet; screencharacterselect_type["available_mine_entrances"] = &ScreenCharacterSelect::available_mine_entrances; From 7e172e5bf06bafa37232b1c833700c4a84da069b Mon Sep 17 00:00:00 2001 From: Mr-Auto <36127424+Mr-Auto@users.noreply.github.com> Date: Sun, 1 Dec 2024 21:05:39 +0100 Subject: [PATCH 4/7] Add ability for adding comments in the lua type definition files for the runtime type creation --- docs/game_data/spel2.lua | 4 ++++ docs/generate.py | 2 +- docs/parse_source.py | 25 +++++++++++++++++-------- docs/src/includes/_types.md | 4 ++++ 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/docs/game_data/spel2.lua b/docs/game_data/spel2.lua index 0724d29f4..349311f9e 100644 --- a/docs/game_data/spel2.lua +++ b/docs/game_data/spel2.lua @@ -5919,6 +5919,10 @@ function Quad:is_point_inside(x, y, epsilon) end ---@field topleft_woodpanel_esc_slidein number ---@field start_panel_slidein number ---@field action_buttons_keycap_size number + ---@field screen_loading boolean + ---@field seeded_run boolean + ---@field daily_challenge boolean + ---@field arena boolean @Short for `screen->next_screen_to_load == SCREEN.TEAM_SELECT and not screen->seeded_run and not screen->daily_challenge` ---@field next_screen_to_load integer ---@field not_ready_to_start_yet boolean ---@field available_mine_entrances integer diff --git a/docs/generate.py b/docs/generate.py index fbc2fdc73..9a89e6b1a 100644 --- a/docs/generate.py +++ b/docs/generate.py @@ -697,7 +697,7 @@ def print_lf(lf): [] if type_name not in ps.constructors else ps.constructors[type_name] ) for var in ctors + type["vars"]: - if "comment" in var and "NoDoc" in var["comment"]: + if "comment" in var and var["comment"] and "NoDoc" in var["comment"]: continue var_name = var["name"] search_link = ( diff --git a/docs/parse_source.py b/docs/parse_source.py index cc8698c76..1c6756d43 100644 --- a/docs/parse_source.py +++ b/docs/parse_source.py @@ -647,13 +647,18 @@ def run_parse(): cpp_type = type[2] name = type[3] attr = type[4] + extra_comments = {} if container: extra = [] n = re.findall( - r"(?.,`"\'=]*?)?' + container + r'\[([\w":]+)\] = ([^;]+);', data ) for var in n: - extra.append(",".join(var)) + if var[0].startswith("/// NoDoc"): + continue + if var[0]: + extra_comments[var[1].replace('"', '')] = var[0][4:] + extra.append(",".join(var[1:3])) extra = ",".join(extra) if attr: attr = attr + "," + extra @@ -711,9 +716,9 @@ def run_parse(): var[1] = var[1][:-1] var_name = var[0] - cpp = replace_fun(var[1]) # should probably be done later, so the regex doesn't have to relay on some of the changes, also generate_emmylua.py uses some unique formats replacements + cpp = replace_fun(var[1]) #TODO: should probably be done later, so the regex doesn't have to relay on some of the changes, also generate_emmylua.py uses some unique formats replacements - if var[1].startswith("sol::property"): + if var[1].startswith("sol::property"): # fix for sol::property param_match = re.match( rf"property\(\[\]\({underlying_cpp_type['name']}&(\w+)\)", cpp, @@ -745,7 +750,7 @@ def run_parse(): "comment": fun["comment"], } ) - elif cpp.startswith("[]("): + elif cpp.startswith("[]("): # lambdas param_match = re.match(r"\[\]\(([\w &*:,]+)?\) -> ([\w.*&<>\?\[\]:]+)?(?: )?{", cpp) if param_match: ret = param_match.group(2) @@ -764,7 +769,7 @@ def run_parse(): "name": var_name, "type": cpp, "signature": f"{ret} {var_name}({sig})", - "comment": "", + "comment": [extra_comments[var_name]] if var_name in extra_comments else [], "function": True, "cb_signature": "", } @@ -783,6 +788,8 @@ def run_parse(): if fun["comment"] else None ) + if var_name in extra_comments: + fun["comment"].append(extra_comments[var_name]) vars.append( { @@ -817,6 +824,8 @@ def run_parse(): sig += underlying_cpp_var["name"][ underlying_cpp_var["name"].find("[") : ] + if var_name in extra_comments: + underlying_cpp_var["comment"].append(extra_comments[var_name]) vars.append( { "name": var_name, @@ -833,10 +842,10 @@ def run_parse(): type = replace_fun(m_return_type[1]) sig = f"{type} {var_name}" vars.append( - {"name": var_name, "type": cpp, "signature": sig} + {"name": var_name, "type": cpp, "signature": sig, "comment": [extra_comments[var_name]] if var_name in extra_comments else []} ) else: - vars.append({"name": var_name, "type": cpp}) + vars.append({"name": var_name, "type": cpp, "comment": [extra_comments[var_name]] if var_name in extra_comments else []}) if name in vtables_by_usertype: vtable = vtables_by_usertype[name] diff --git a/docs/src/includes/_types.md b/docs/src/includes/_types.md index 6d2d8d18f..4dbbe8d8a 100644 --- a/docs/src/includes/_types.md +++ b/docs/src/includes/_types.md @@ -2379,6 +2379,10 @@ array<float, MAX_PLAYERS> | [player_quickselect_wiggle_angle](https://gith float | [topleft_woodpanel_esc_slidein](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=topleft_woodpanel_esc_slidein) | float | [start_panel_slidein](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=start_panel_slidein) | float | [action_buttons_keycap_size](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=action_buttons_keycap_size) | +bool | [screen_loading](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=screen_loading) | +bool | [seeded_run](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=seeded_run) | +bool | [daily_challenge](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=daily_challenge) | +bool | [arena](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=arena) | Short for `screen->next_screen_to_load == SCREEN.TEAM_SELECT and not screen->seeded_run and not screen->daily_challenge` int | [next_screen_to_load](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=next_screen_to_load) | bool | [not_ready_to_start_yet](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=not_ready_to_start_yet) | int | [available_mine_entrances](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=available_mine_entrances) | From 68cf5c9dd8d914ab5b5e0d61388f73e86890571a Mon Sep 17 00:00:00 2001 From: Mr-Auto <36127424+Mr-Auto@users.noreply.github.com> Date: Sun, 1 Dec 2024 21:48:54 +0100 Subject: [PATCH 5/7] add `DOOR_COG_SCEPTER` to `replace_drop` --- src/game_api/drops.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/game_api/drops.cpp b/src/game_api/drops.cpp index 2085fead0..b7ebed55e 100644 --- a/src/game_api/drops.cpp +++ b/src/game_api/drops.cpp @@ -294,6 +294,8 @@ std::vector drop_entries{ /// Special: /// + /// Change item used to open the door (still requires hedjet, crown or eggplant crown) + {"DOOR_COG_SCEPTER", "\x81\x78\x14\x4C\x02\x00\x00"sv, VTABLE_OFFSET::FLOOR_DOOR_COG, 25, 3, 2}, // is not the exact virtual, but function that the virtual uses /// It's not ENT_TYPE but amount of health, with elixir it will be this value * 2 {"MOTHERSTATUE_HEALTH", "\xBD\x04\x00\x00\x00\xD3"sv, VTABLE_OFFSET::FLOOR_MOTHER_STATUE, 2, 1}, /// It's not ENT_TYPE but amount of health, with elixir it will be this value * 2 From 55bba79a240ad0b49ed06c1d32d814b5f33916e2 Mon Sep 17 00:00:00 2001 From: Mr-Auto <36127424+Mr-Auto@users.noreply.github.com> Date: Sat, 14 Dec 2024 20:47:21 +0100 Subject: [PATCH 6/7] rename get_savegame, fix typo --- src/game_api/game_manager.hpp | 6 +++--- .../script/usertypes/game_manager_lua.cpp | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/game_api/game_manager.hpp b/src/game_api/game_manager.hpp index 9c8808230..de856cd2d 100644 --- a/src/game_api/game_manager.hpp +++ b/src/game_api/game_manager.hpp @@ -59,10 +59,10 @@ class JournalPeopleData : public JournalPageData bool killed_by_NA; bool defeated_NA; // uint16_t padding; - TEXTURE portret_texture; + TEXTURE portrait_texture; }; -// probably same as JournalPeopleData, just not using portret_texture +// probably same as JournalPeopleData, just not using portrait_texture class JournalBestiaryData : public JournalPageData { public: @@ -109,7 +109,7 @@ struct SaveRelated game_unordered_map stickers_data; /// Gets local version of the SaveData - SaveData* get_SaveData() + SaveData* get_savegame() { return savedata.decode_local(); } diff --git a/src/game_api/script/usertypes/game_manager_lua.cpp b/src/game_api/script/usertypes/game_manager_lua.cpp index 2d1ec85e3..54aed50cc 100644 --- a/src/game_api/script/usertypes/game_manager_lua.cpp +++ b/src/game_api/script/usertypes/game_manager_lua.cpp @@ -8,11 +8,12 @@ #include // for move, declval #include // for min, max -#include "game_manager.hpp" // for GameManager, JournalPopupUI, GameProps -#include "memory.hpp" // for memory_read TODO:temp -#include "savedata.hpp" // for SaveData -#include "screen.hpp" // IWYU pragma: keep -#include "script/sol_helper.hpp" // for ZeroIndexArray +#include "containers/game_allocator.hpp" // for game_allocator +#include "game_manager.hpp" // for GameManager, JournalPopupUI, GameProps +#include "memory.hpp" // for memory_read TODO:temp +#include "savedata.hpp" // for SaveData +#include "screen.hpp" // IWYU pragma: keep +#include "script/sol_helper.hpp" // for ZeroIndexArray namespace NGM { @@ -102,8 +103,8 @@ void register_usertypes(sol::state& lua) &SaveRelated::trap_part_to_main, "stickers_data", &SaveRelated::stickers_data, - "get_SaveData", - &SaveRelated::get_SaveData); + "get_savegame", + &SaveRelated::get_savegame); /// Used in SaveRelated lua.new_usertype( @@ -148,8 +149,8 @@ void register_usertypes(sol::state& lua) &JournalPeopleData::killed_by_NA, "defeated_NA", &JournalPeopleData::defeated_NA, - "portret_texture", - &JournalPeopleData::portret_texture, + "portrait_texture", + &JournalPeopleData::portrait_texture, sol::base_classes, sol::bases()); From 8518c50c1911f3e7eb7e05df4501aa80529fa15a Mon Sep 17 00:00:00 2001 From: Mr-Auto <36127424+Mr-Auto@users.noreply.github.com> Date: Sat, 14 Dec 2024 21:10:32 +0100 Subject: [PATCH 7/7] fix the `unordered_map` not being correctly readable from lua, update doc --- docs/game_data/spel2.lua | 4 ++-- docs/src/includes/_types.md | 4 ++-- src/game_api/game_manager.hpp | 19 ++++++++++--------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/docs/game_data/spel2.lua b/docs/game_data/spel2.lua index 349311f9e..3a06946ed 100644 --- a/docs/game_data/spel2.lua +++ b/docs/game_data/spel2.lua @@ -2365,7 +2365,7 @@ do ---@field trap_info table ---@field trap_part_to_main table @used for stuff like upsidedown_spikes -> spikes, skulldrop skulls -> skulldrop trap etc. ---@field stickers_data table - ---@field get_SaveData fun(self): SaveData @Gets local version of the SaveData + ---@field get_savegame fun(self): SaveData @Gets local version of the SaveData ---@class JournalPageData ---@field page_nr integer @@ -2387,7 +2387,7 @@ do ---@field background_sprite_id integer ---@field killed_by_NA boolean ---@field defeated_NA boolean - ---@field portret_texture TEXTURE + ---@field portrait_texture TEXTURE ---@class JournalTrapData : JournalPageData ---@field texture TEXTURE diff --git a/docs/src/includes/_types.md b/docs/src/includes/_types.md index 4dbbe8d8a..71f8989d3 100644 --- a/docs/src/includes/_types.md +++ b/docs/src/includes/_types.md @@ -1416,7 +1416,7 @@ Type | Name | Description int | [background_sprite_id](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=background_sprite_id) | bool | [killed_by_NA](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=killed_by_NA) | bool | [defeated_NA](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=defeated_NA) | -[TEXTURE](#TEXTURE) | [portret_texture](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=portret_texture) | +[TEXTURE](#TEXTURE) | [portrait_texture](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=portrait_texture) | ### JournalTrapData @@ -2128,7 +2128,7 @@ map<[ENT_TYPE](#ENT_TYPE), [JournalPageData](#JournalPageData)> | [item_in map<[ENT_TYPE](#ENT_TYPE), [JournalPageData](#JournalPageData)> | [trap_info](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=trap_info) | map<[ENT_TYPE](#ENT_TYPE), [ENT_TYPE](#ENT_TYPE)> | [trap_part_to_main](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=trap_part_to_main) | used for stuff like upsidedown_spikes -> spikes, skulldrop skulls -> skulldrop trap etc. map<[ENT_TYPE](#ENT_TYPE), [StickersData](#StickersData)> | [stickers_data](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=stickers_data) | -[SaveData](#SaveData) | [get_SaveData()](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=get_SaveData) | Gets local version of the [SaveData](#SaveData) +[SaveData](#SaveData) | [get_savegame()](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=get_savegame) | Gets local version of the [SaveData](#SaveData) ### Screen diff --git a/src/game_api/game_manager.hpp b/src/game_api/game_manager.hpp index de856cd2d..373747dc2 100644 --- a/src/game_api/game_manager.hpp +++ b/src/game_api/game_manager.hpp @@ -5,6 +5,7 @@ #include "aliases.hpp" // for MAX_PLAYERS #include "containers/game_unordered_map.hpp" // for game_unordered_map +#include "containers/identity_hasher.hpp" // for identity_hasher #include "render_api.hpp" // for TextureRenderingInfo #include "sound_manager.hpp" // for BackgroundSound #include "thread_utils.hpp" // for OnHeapPointer @@ -95,18 +96,18 @@ struct SaveRelated ENT_TYPE progress_stickers_powerups[29]; // pre-journal progress setup, maybe gathering from all players or something? /// Scale and offset not used in those pages. Can't add more - game_unordered_map places_data; - game_unordered_map bestiary_data; + game_unordered_map> places_data; + game_unordered_map> bestiary_data; /// used to map stuff like Osiris_Hand -> Osiris_Head, Hundun limbs -> Hundun etc. - game_unordered_map monster_part_to_main; - game_unordered_map people_info; + game_unordered_map> monster_part_to_main; + game_unordered_map> people_info; /// used to map shopkeeper clone to shopkeeper only - game_unordered_map people_part_to_main; - game_unordered_map item_info; - game_unordered_map trap_info; + game_unordered_map> people_part_to_main; + game_unordered_map> item_info; + game_unordered_map> trap_info; /// used for stuff like upsidedown_spikes -> spikes, skulldrop skulls -> skulldrop trap etc. - game_unordered_map trap_part_to_main; - game_unordered_map stickers_data; + game_unordered_map> trap_part_to_main; + game_unordered_map> stickers_data; /// Gets local version of the SaveData SaveData* get_savegame()