From b8ad3f0b358201ba1387c6ee3081ac953a3195ee Mon Sep 17 00:00:00 2001 From: Mr-Auto <36127424+Mr-Auto@users.noreply.github.com> Date: Mon, 30 Oct 2023 20:21:31 +0100 Subject: [PATCH] fix ui flags --- src/game_api/flags.hpp | 61 ++++++++++++------------- src/game_api/render_api.cpp | 6 +-- src/injected/ui.cpp | 88 +++++++++++++------------------------ 3 files changed, 64 insertions(+), 91 deletions(-) diff --git a/src/game_api/flags.hpp b/src/game_api/flags.hpp index 6b830568a..954e91c2d 100644 --- a/src/game_api/flags.hpp +++ b/src/game_api/flags.hpp @@ -1,4 +1,5 @@ -const char* themes[]{ + +std::array themes{ "1: Dwelling", "2: Jungle", "2: Volcana", @@ -18,7 +19,7 @@ const char* themes[]{ "0: Base camp", }; -const char* themes_short[]{ +std::array themes_short{ "Dwelling", "Jungle", "Volcana", @@ -38,7 +39,7 @@ const char* themes_short[]{ "Base camp", }; -const char* entity_flags[]{ +std::array entity_flags{ "1: Invisible", "2: Indestructable/special floor", "3: Solid (wall)", @@ -73,7 +74,7 @@ const char* entity_flags[]{ "32: Use overlay draw depth", }; -const char* more_flags[]{ +std::array more_flags{ "1: Take damage on collision after throw", "2: Revived (HH)", "3: Blocks shield", @@ -108,7 +109,7 @@ const char* more_flags[]{ "32: ", }; -const char* entity_type_properties_flags[]{ +std::array entity_type_properties_flags{ "1: Apply solid block beautification", "2: Treat as FLOORSTYLED", "3: ", @@ -143,7 +144,7 @@ const char* entity_type_properties_flags[]{ "32: Unused", }; -const char* level_flags[]{ +std::array level_flags{ "1: Upbeat dwelling intro music played", "2: ", "3: Running tutorial speedrun", @@ -178,7 +179,7 @@ const char* level_flags[]{ "32: ", }; -const char* journal_flags[]{ +std::array journal_flags{ "1: I was a pacifist", "2: I was a vegan", "3: I was a vegetarian", @@ -213,7 +214,7 @@ const char* journal_flags[]{ "32: ", }; -const char* quest_flags[]{ +std::array quest_flags{ "1: Reset", "2: Dark level spawned in world", "3: Vault spawned in world", @@ -248,7 +249,7 @@ const char* quest_flags[]{ "32: ", }; -const char* presence_flags[]{ +std::array presence_flags{ "1: Udjat eye", "2: Black market", "3: Vlad's castle/drill", @@ -283,7 +284,7 @@ const char* presence_flags[]{ "32: ", }; -const char* illumination_flags[]{ +std::array illumination_flags{ "1: Disable light1", "2: Enable light2", "3: Enable light3", @@ -294,7 +295,7 @@ const char* illumination_flags[]{ "8: Unknown", }; -const char* special_visibility_flags[]{ +std::array special_visibility_flags{ "1: Crust embedded items shown", "2: Crust embedded items shown (level transition)", "3: ", @@ -321,7 +322,7 @@ const char* special_visibility_flags[]{ "24: ", }; -const char* basecamp_dialogue_win_flags[]{ +std::array basecamp_dialogue_win_flags{ "1: Ana Spelunky saved", "2: Margaret Tunnel saved", "3: Colin Northward saved", @@ -356,7 +357,7 @@ const char* basecamp_dialogue_win_flags[]{ "32: ", }; -const char* places_flags[]{ +std::array places_flags{ "Dwelling", "Jungle", "Volcana", @@ -375,7 +376,7 @@ const char* places_flags[]{ "Cosmic Ocean", }; -const char* people_flags[]{ +std::array people_flags{ "Ana Spelunky", "Margaret Tunnel", "Colin Northward", @@ -416,7 +417,7 @@ const char* people_flags[]{ "Eggplant King", }; -const char* bestiary_flags[]{ +std::array bestiary_flags{ "Snake", "Spider", "Bat", @@ -497,7 +498,7 @@ const char* bestiary_flags[]{ "Mech Rider", }; -const char* items_flags[]{ +std::array items_flags{ "Rope Pile", "Bomb Bag", "Bomb Box", @@ -554,7 +555,7 @@ const char* items_flags[]{ "Four-Leaf Clover", }; -const char* traps_flags[]{ +std::array traps_flags{ "Spikes", "Arrow Trap", "Totem Trap", @@ -581,7 +582,7 @@ const char* traps_flags[]{ "Egg Sac", }; -const char* shortcut_flags[]{ +std::array shortcut_flags{ "None", "Met Terra", "1-4: $2,000", @@ -595,7 +596,7 @@ const char* shortcut_flags[]{ "5-1: Golden Key (Unlocked)", }; -/*const char *empty_flags[]{ +/*std::array empty_flags{ "1: ", "2: ", "3: ", @@ -629,7 +630,7 @@ const char* shortcut_flags[]{ "31: ", "32: ",};*/ -const char* button_flags[]{ +std::array button_flags{ "Jp", "Wp", "Bm", @@ -637,14 +638,14 @@ const char* button_flags[]{ "Rn", "Dr", }; -const char* direction_flags[]{ +std::array direction_flags{ "Left", "Down", "Up", "Right", }; -const char* liquid_pool_names[]{ +std::array liquid_pool_names{ "Water", "Coarse Water", "Lava", @@ -652,7 +653,7 @@ const char* liquid_pool_names[]{ "Stagnant Lava", }; -const char* mask_names[]{ +std::array mask_names{ "Player", "Mount", "Monster", @@ -670,7 +671,7 @@ const char* mask_names[]{ "Lava", }; -const char* char_states[]{ +std::array char_states{ "Flailing", "Standing", "Sitting", @@ -696,7 +697,7 @@ const char* char_states[]{ "Dying", }; -const char* screen_names[]{ +std::array screen_names{ "Logo", "Intro", "Prologue", @@ -729,7 +730,7 @@ const char* screen_names[]{ "Online Lobby", }; -const char* pause_types[]{ +std::array pause_types{ "1: Menu", "2: Fade (janky camera, default)", "4: Cutscene", @@ -739,7 +740,7 @@ const char* pause_types[]{ "Freeze on PRE_UPDATE", // this is not a real state.pause flag, it's only used by ui.cpp for magic }; -const char* levelgen_flags[]{ +std::array levelgen_flags{ "1: Should generate path", "2: Can spawn vault", "3: Can spawn shops", @@ -750,7 +751,7 @@ const char* levelgen_flags[]{ "8: unknown", }; -const char* levelgen_flags2[]{ +std::array levelgen_flags2{ "1: Spawns background decorations on ground (ceiling if false)", "2: Spawns fake ladder/chain midbg?", "3: Spawn entrance door background (Ignored in 7-1 to 7-2 transition)", @@ -761,7 +762,7 @@ const char* levelgen_flags2[]{ "8: Has ghost", }; -const char* levelgen_flags3[]{ +std::array levelgen_flags3{ "1: Can spawn angry NPCs", "2: Can echo", "3: Can spawn Dead are Restless", @@ -772,7 +773,7 @@ const char* levelgen_flags3[]{ "8: unknown", }; -const char* level_chances[]{ +std::array level_chances{ "backroom", "backroom interconnect", "backroom hidden door", diff --git a/src/game_api/render_api.cpp b/src/game_api/render_api.cpp index 011694831..407e357e2 100644 --- a/src/game_api/render_api.cpp +++ b/src/game_api/render_api.cpp @@ -64,7 +64,7 @@ void render_loading(size_t param_1) } std::optional g_forced_lut_textures[2]{}; -float g_layer_zoom_offset[2]; +float g_layer_zoom_offset[2]{0}; using RenderLayer = void(const std::vector&, uint8_t, const Camera&, const char**, const char**); RenderLayer* g_render_layer_trampoline{nullptr}; @@ -110,9 +110,9 @@ void render_game(StateMemory* state) trigger_vanilla_render_callbacks(ON::RENDER_POST_GAME); } -float get_layer_transition_zoom_offset(uint8_t l) +float get_layer_transition_zoom_offset(uint8_t layer) { - return g_layer_zoom_offset[l]; + return g_layer_zoom_offset[layer]; } void RenderAPI::set_lut(TEXTURE texture_id, uint8_t layer) diff --git a/src/injected/ui.cpp b/src/injected/ui.cpp index e07fb8711..eae247ca0 100644 --- a/src/injected/ui.cpp +++ b/src/injected/ui.cpp @@ -3480,6 +3480,23 @@ void render_light(const char* name, LightParams* light) ImGui::PopID(); } +template +void render_flags(const std::array names_array, T* flag_field) +{ + for (int idx{0}; idx < SIZE && idx < sizeof(T) * 8; ++idx) + { + // just simplified version of CheckboxFlagsT + + T value = (T)std::pow(2, idx); + bool on = (*flag_field & value) == value; + + if (ImGui::Checkbox(names_array[idx], &on)) + { + *flag_field ^= value; + } + } +} + void render_illumination(Illumination* light, const char* sect = "") { ImGui::PushID(sect); @@ -3498,10 +3515,7 @@ void render_illumination(Illumination* light, const char* sect = "") ImGui::InputFloat("Offset X##LightPosX", &light->offset_x); ImGui::InputFloat("Offset Y##LightPosY", &light->offset_y); ImGui::DragFloat("Distortion##LightDistortion", &light->distortion, 0.01f); - for (int i = 0; i < 11; i++) - { - ImGui::CheckboxFlags(illumination_flags[i], &light->flags, (int)std::pow(2, i)); - } + render_flags(illumination_flags, &light->flags); ImGui::PopID(); } @@ -5792,10 +5806,7 @@ void render_options() if (submenu("Frame advance / Engine pause type")) { ImGui::PushID("PauseType"); - for (int i = 1; i < 7; i++) - { - ImGui::CheckboxFlags(pause_types[i], &g_pause_type, (int)std::pow(2, i)); - } + render_flags(pause_types, &g_pause_type); ImGui::PopID(); endmenu(); } @@ -7119,10 +7130,7 @@ void render_entity_props(int uid, bool detached = false) ImGui::InputScalar("Search flags##SearchFlags", ImGuiDataType_U32, &entity->type->search_flags, 0, 0, "%p", ImGuiInputTextFlags_ReadOnly); if (submenu("Properties flags")) { - for (int i = 0; i < 32; i++) - { - ImGui::CheckboxFlags(entity_type_properties_flags[i], &entity->type->properties_flags, (int)std::pow(2, i)); - } + render_flags(entity_type_properties_flags, &entity->type->properties_flags); endmenu(); } endmenu(); @@ -7316,18 +7324,12 @@ void render_entity_props(int uid, bool detached = false) } if (submenu("Flags")) { - for (int i = 0; i < 32; i++) - { - ImGui::CheckboxFlags(entity_flags[i], &entity->flags, (int)std::pow(2, i)); - } + render_flags(entity_flags, &entity->flags); endmenu(); } if (submenu("More Flags")) { - for (int i = 0; i < 32; i++) - { - ImGui::CheckboxFlags(more_flags[i], &entity->more_flags, (int)std::pow(2, i)); - } + render_flags(more_flags, &entity->more_flags); endmenu(); } if (is_movable && submenu("Input Display")) @@ -8083,67 +8085,37 @@ void render_game_props() } if (submenu("Level flags")) { - for (int i = 0; i < 32; i++) - { - ImGui::CheckboxFlags(level_flags[i], &g_state->level_flags, (int)std::pow(2, i)); - } + render_flags(level_flags, &g_state->level_flags); endmenu(); } if (submenu("Quest flags")) { - for (int i = 0; i < 32; i++) - { - ImGui::CheckboxFlags(quest_flags[i], &g_state->quest_flags, (int)std::pow(2, i)); - } + render_flags(quest_flags, &g_state->quest_flags); endmenu(); } if (submenu("Journal flags")) { - for (int i = 0; i < 21; i++) - { - ImGui::CheckboxFlags(journal_flags[i], &g_state->journal_flags, (int)std::pow(2, i)); - } + render_flags(journal_flags, &g_state->journal_flags); endmenu(); } if (submenu("Presence flags")) { - for (int i = 0; i < 11; i++) - { - ImGui::CheckboxFlags(presence_flags[i], &g_state->presence_flags, (int)std::pow(2, i)); - } + render_flags(presence_flags, &g_state->presence_flags); endmenu(); } if (submenu("Special visibility flags")) { - for (int i = 0; i < 32; i++) - { - ImGui::CheckboxFlags(special_visibility_flags[i], &g_state->special_visibility_flags, (int)std::pow(2, i)); - } + render_flags(special_visibility_flags, &g_state->special_visibility_flags); endmenu(); } if (submenu("Level generation flags")) { - auto flags = (int)g_state->level_gen->flags; - auto flags2 = (int)g_state->level_gen->flags2; - auto flags3 = (int)g_state->level_gen->flags3; ImGui::SeparatorText("Flags 1"); - for (int i = 0; i < 8; i++) - { - ImGui::CheckboxFlags(levelgen_flags[i], &flags, (int)std::pow(2, i)); - } + render_flags(levelgen_flags, &g_state->level_gen->flags); ImGui::SeparatorText("Flags 2"); - for (int i = 0; i < 8; i++) - { - ImGui::CheckboxFlags(levelgen_flags2[i], &flags2, (int)std::pow(2, i)); - } + render_flags(levelgen_flags2, &g_state->level_gen->flags2); ImGui::SeparatorText("Flags 3"); - for (int i = 0; i < 8; i++) - { - ImGui::CheckboxFlags(levelgen_flags3[i], &flags3, (int)std::pow(2, i)); - } - g_state->level_gen->flags = (uint8_t)flags; - g_state->level_gen->flags2 = (uint8_t)flags2; - g_state->level_gen->flags3 = (uint8_t)flags3; + render_flags(levelgen_flags3, &g_state->level_gen->flags3); if (g_state->current_theme) { ImGui::SeparatorText("Theme flags");