Skip to content

Commit

Permalink
fix (#46)
Browse files Browse the repository at this point in the history
* added minor fixes to cleanup and requip
* added fix to possible ctd
  • Loading branch information
mlthelama authored Sep 3, 2023
2 parents d3a1ba7 + 797cfb8 commit 208ac43
Show file tree
Hide file tree
Showing 15 changed files with 431 additions and 303 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "extern/resources"]
path = extern/resources
url = https://github.com/mlthelama/ResourcesForLamasTinyHUD.git
[submodule "extern/stb"]
path = extern/stb
url = https://github.com/nothings/stb.git
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.20)

set(NAME "LamasTinyHUD")
set(VERSION 1.4.4.0)
set(VERSION 1.5.0.0)

# ---- Options ----

Expand Down Expand Up @@ -96,6 +96,8 @@ find_package(CommonLibSSE CONFIG REQUIRED)

find_package(spdlog REQUIRED CONFIG)

include_directories(extern/stb)

find_package(imgui REQUIRED)

find_package(unofficial-nanosvg CONFIG REQUIRED)
Expand Down Expand Up @@ -154,6 +156,8 @@ target_link_libraries(
unofficial::nanosvg::nanosvg
)

link_directories(extern/stb)

if (MSVC)
target_compile_options(
${PROJECT_NAME}
Expand Down
4 changes: 4 additions & 0 deletions LamasTinyHUD.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ bIsDebug = false

[Image]
bDrawKeyBackground = 0
sFileEnding = .svg

[Key]
sFileEnding = .svg

[Font]
bLoad = true
Expand Down
1 change: 1 addition & 0 deletions extern/stb
Submodule stb added at 5736b1
1 change: 1 addition & 0 deletions src/PCH.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#define STB_IMAGE_IMPLEMENTATION
#define IMGUI_DEFINE_MATH_OPERATORS
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
Expand Down
4 changes: 3 additions & 1 deletion src/handle/page_handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ namespace handle {
page->slot_settings = *slots;

//for now the right hand or the first setting defines the icon, works well for elden.
page->icon_type = get_icon_type(slots->front()->type, slots->front()->form);
if (slots->front() && slots->front()->form) {
page->icon_type = get_icon_type(slots->front()->type, slots->front()->form);
}
if (slots->size() == 2 && page->icon_type == icon_type::icon_default) {
logger::debug("Could not find an Icon with first setting, try next");
page->icon_type = get_icon_type(slots->at(1)->type, slots->at(1)->form);
Expand Down
51 changes: 45 additions & 6 deletions src/processing/set_setting_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ namespace processing {

handle::key_position_handle::get_singleton()->init_key_position_map();

handle::name_handle::get_singleton()->init_names(util::player::get_hand_assignment());
auto hand_assignment = util::player::get_hand_assignment();
handle::name_handle::get_singleton()->init_names(hand_assignment);

write_empty_config_and_init_active();

logger::trace("continue with overwriting data from configuration ..."sv);

process_config_data();

//check_block(hand_assignment);

logger::trace("done executing. return."sv);
}

Expand Down Expand Up @@ -58,7 +61,7 @@ namespace processing {

std::vector<data_helper*> data;
if (a_data.empty()) {
const auto item = new data_helper();
auto* const item = new data_helper();
item->form = nullptr;
item->action_type = handle::slot_setting::action_type::default_action;
item->type = slot_type::empty;
Expand Down Expand Up @@ -112,7 +115,7 @@ namespace processing {
void set_setting_data::set_empty_slot(const int a_page, int a_pos, handle::key_position_handle*& a_key_pos) {
logger::trace("setting empty config for page {}, position {}"sv, a_page, a_pos);
std::vector<data_helper*> data;
const auto item = new data_helper();
auto* const item = new data_helper();
item->form = nullptr;
item->action_type = handle::slot_setting::action_type::default_action;
item->type = slot_type::empty;
Expand Down Expand Up @@ -162,7 +165,7 @@ namespace processing {
action_check);

handle::slot_setting::action_type action;
if (action_check) {
if (action_check && !mcm::get_elden_demon_souls()) {
if (a_action == a_action_left) {
action = static_cast<handle::slot_setting::action_type>(a_action);
} else {
Expand Down Expand Up @@ -207,7 +210,7 @@ namespace processing {
}
}

const auto item = new data_helper();
auto* const item = new data_helper();
item->form = form ? form : nullptr;
item->type = type;
item->action_type = action;
Expand Down Expand Up @@ -240,7 +243,7 @@ namespace processing {
}
}

const auto item_left = new data_helper();
auto* const item_left = new data_helper();
item_left->form = form_left ? form_left : nullptr;
item_left->type = type_left;
item_left->action_type = action;
Expand Down Expand Up @@ -539,6 +542,12 @@ namespace processing {

void set_setting_data::do_cleanup(handle::position_setting*& a_position_setting,
handle::slot_setting*& a_slot_setting) {
if (a_slot_setting->form && a_slot_setting->form->formID == util::unarmed) {
logger::trace("skipping cleanup for form {}, because of unarmed"sv,
util::string_util::int_to_hex(a_slot_setting->form->formID));
return;
}

auto log_string = fmt::format("doing cleanup at page {}, position {}, form {}"sv,
a_position_setting->page,
static_cast<uint32_t>(a_position_setting->position),
Expand Down Expand Up @@ -687,4 +696,34 @@ namespace processing {
}
return allowed;
}

[[maybe_unused]] void set_setting_data::check_block(const std::vector<data_helper*>& data_helpers) {
if (mcm::get_elden_demon_souls() && !mcm::get_disable_re_equip_of_actives() &&
!RE::UI::GetSingleton()->GameIsPaused()) {
logger::trace("continue with if location needs block, because reequip is {} and elden is {}"sv,
mcm::get_elden_demon_souls(),
mcm::get_disable_re_equip_of_actives());
RE::TESForm* two_handed_form = nullptr;
if (!data_helpers.empty() && data_helpers.size() == 1 && data_helpers.front() &&
data_helpers.front()->form && util::helper::is_two_handed(data_helpers.front()->form)) {
two_handed_form = data_helpers.front()->form;
}

if (!two_handed_form) {
return;
}
logger::trace("form is {} in right hand"sv, util::string_util::int_to_hex(two_handed_form));

auto* page_handle = handle::page_handle::get_singleton();
auto page = page_handle->get_active_page_id_position(position_type::right);
auto* setting = page_handle->get_page_setting(page, position_type::right);
if (!setting->slot_settings.empty() && setting->slot_settings.front() &&
setting->slot_settings.front()->form) {
if (setting->slot_settings.front()->form == two_handed_form) {
processing::set_setting_data::check_if_location_needs_block(two_handed_form, true);
}
}
logger::trace("done checking if location needs block. return.");
}
}
}
1 change: 1 addition & 0 deletions src/processing/set_setting_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ namespace processing {
//easier to have both, first only needed to get the page, position. the second, so it is easier to have the form
static void do_cleanup(handle::position_setting*& a_position_setting, handle::slot_setting*& a_slot_setting);
static bool clean_type_allowed(slot_type a_type);
[[maybe_unused]] static void check_block(const std::vector<data_helper*>& data_helpers);
};
}
8 changes: 6 additions & 2 deletions src/setting/file_setting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ namespace config {

static bool is_debug;
static bool draw_key_background;

static std::string image_file_ending;
static std::string key_file_ending;
static bool font_load;
static std::string font_file_name;
static float font_size;
Expand All @@ -35,6 +36,8 @@ namespace config {
is_debug = ini.GetBoolValue("General", "bIsDebug", false);

draw_key_background = ini.GetBoolValue("Image", "bDrawKeyBackground", false);
image_file_ending = ini.GetValue("Image", "sFileEnding", ".svg");
key_file_ending = ini.GetValue("Key", "sFileEnding", ".svg");

font_load = ini.GetBoolValue("Font", "bLoad", true);
font_file_name = ini.GetValue("Font", "sName", "");
Expand All @@ -57,7 +60,8 @@ namespace config {

bool file_setting::get_is_debug() { return is_debug; }
bool file_setting::get_draw_key_background() { return draw_key_background; }

std::string file_setting::get_image_file_ending() { return image_file_ending; }
std::string file_setting::get_key_file_ending() { return key_file_ending; }
bool file_setting::get_font_load() { return font_load; }
std::string file_setting::get_font_file_name() { return font_file_name; }
float file_setting::get_font_size() { return font_size; }
Expand Down
3 changes: 3 additions & 0 deletions src/setting/file_setting.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ namespace config {
static void load_setting();

static bool get_is_debug();

static bool get_draw_key_background();
static std::string get_image_file_ending();
static std::string get_key_file_ending();

static bool get_font_load();
static std::string get_font_file_name();
Expand Down
102 changes: 51 additions & 51 deletions src/ui/image_path.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ namespace ui {

enum class image_type { hud, round, key, total };

inline static std::map<std::string, image_type> image_type_name_map = { { R"(hud.svg)", image_type::hud },
{ R"(round.svg)", image_type::round },
{ R"(key.svg)", image_type::key } };
inline static std::map<std::string, image_type> image_type_name_map = { { R"(hud)", image_type::hud },
{ R"(round)", image_type::round },
{ R"(key)", image_type::key } };

enum class icon_image_type {
potion_health,
Expand Down Expand Up @@ -67,53 +67,53 @@ namespace ui {
};


inline static std::map<std::string, icon_image_type> icon_type_name_map = { { R"(potion_health.svg)",
inline static std::map<std::string, icon_image_type> icon_type_name_map = { { R"(potion_health)",
icon_image_type::potion_health },
{ R"(potion_default.svg)", icon_image_type::potion_default },
{ R"(sword_one_handed.svg)", icon_image_type::sword_one_handed },
{ R"(axe_one_handed.svg)", icon_image_type::axe_one_handed },
{ R"(mace.svg)", icon_image_type::mace },
{ R"(dagger.svg)", icon_image_type::dagger },
{ R"(sword_two_handed.svg)", icon_image_type::sword_two_handed },
{ R"(axe_two_handed.svg)", icon_image_type::axe_two_handed },
{ R"(staff.svg)", icon_image_type::staff },
{ R"(bow.svg)", icon_image_type::bow },
{ R"(crossbow.svg)", icon_image_type::crossbow },
{ R"(spell_default.svg)", icon_image_type::spell_default },
{ R"(destruction.svg)", icon_image_type::destruction },
{ R"(shout.svg)", icon_image_type::shout },
{ R"(power.svg)", icon_image_type::power },
{ R"(food.svg)", icon_image_type::food },
{ R"(shield.svg)", icon_image_type::shield },
{ R"(icon_default.svg)", icon_image_type::icon_default },
{ R"(destruction_fire.svg)", icon_image_type::destruction_fire },
{ R"(destruction_frost.svg)", icon_image_type::destruction_frost },
{ R"(destruction_shock.svg)", icon_image_type::destruction_shock },
{ R"(restoration.svg)", icon_image_type::restoration },
{ R"(poison_default.svg)", icon_image_type::poison_default },
{ R"(armor_light.svg)", icon_image_type::armor_light },
{ R"(armor_heavy.svg)", icon_image_type::armor_heavy },
{ R"(armor_clothing.svg)", icon_image_type::armor_clothing },
{ R"(scroll.svg)", icon_image_type::scroll },
{ R"(arrow.svg)", icon_image_type::arrow },
{ R"(hand_to_hand.svg)", icon_image_type::hand_to_hand },
{ R"(katana.svg)", icon_image_type::katana },
{ R"(halberd.svg)", icon_image_type::halberd },
{ R"(whip.svg)", icon_image_type::whip },
{ R"(claw.svg)", icon_image_type::claw },
{ R"(rapier.svg)", icon_image_type::rapier },
{ R"(quarter_staff.svg)", icon_image_type::quarter_staff },
{ R"(pike.svg)", icon_image_type::pike },
{ R"(potion_stamina.svg)", icon_image_type::potion_stamina },
{ R"(potion_magicka.svg)", icon_image_type::potion_magicka },
{ R"(potion_fire_resist.svg)", icon_image_type::potion_fire_resist },
{ R"(potion_shock_resist.svg)", icon_image_type::potion_shock_resist },
{ R"(potion_frost_resist.svg)", icon_image_type::potion_frost_resist },
{ R"(potion_magic_resist.svg)", icon_image_type::potion_magic_resist },
{ R"(alteration.svg)", icon_image_type::alteration },
{ R"(conjuration.svg)", icon_image_type::conjuration },
{ R"(illusion.svg)", icon_image_type::illusion },
{ R"(torch.svg)", icon_image_type::torch },
{ R"(lantern.svg)", icon_image_type::lantern },
{ R"(mask.svg)", icon_image_type::mask } };
{ R"(potion_default)", icon_image_type::potion_default },
{ R"(sword_one_handed)", icon_image_type::sword_one_handed },
{ R"(axe_one_handed)", icon_image_type::axe_one_handed },
{ R"(mace)", icon_image_type::mace },
{ R"(dagger)", icon_image_type::dagger },
{ R"(sword_two_handed)", icon_image_type::sword_two_handed },
{ R"(axe_two_handed)", icon_image_type::axe_two_handed },
{ R"(staff)", icon_image_type::staff },
{ R"(bow)", icon_image_type::bow },
{ R"(crossbow)", icon_image_type::crossbow },
{ R"(spell_default)", icon_image_type::spell_default },
{ R"(destruction)", icon_image_type::destruction },
{ R"(shout)", icon_image_type::shout },
{ R"(power)", icon_image_type::power },
{ R"(food)", icon_image_type::food },
{ R"(shield)", icon_image_type::shield },
{ R"(icon_default)", icon_image_type::icon_default },
{ R"(destruction_fire)", icon_image_type::destruction_fire },
{ R"(destruction_frost)", icon_image_type::destruction_frost },
{ R"(destruction_shock)", icon_image_type::destruction_shock },
{ R"(restoration)", icon_image_type::restoration },
{ R"(poison_default)", icon_image_type::poison_default },
{ R"(armor_light)", icon_image_type::armor_light },
{ R"(armor_heavy)", icon_image_type::armor_heavy },
{ R"(armor_clothing)", icon_image_type::armor_clothing },
{ R"(scroll)", icon_image_type::scroll },
{ R"(arrow)", icon_image_type::arrow },
{ R"(hand_to_hand)", icon_image_type::hand_to_hand },
{ R"(katana)", icon_image_type::katana },
{ R"(halberd)", icon_image_type::halberd },
{ R"(whip)", icon_image_type::whip },
{ R"(claw)", icon_image_type::claw },
{ R"(rapier)", icon_image_type::rapier },
{ R"(quarter_staff)", icon_image_type::quarter_staff },
{ R"(pike)", icon_image_type::pike },
{ R"(potion_stamina)", icon_image_type::potion_stamina },
{ R"(potion_magicka)", icon_image_type::potion_magicka },
{ R"(potion_fire_resist)", icon_image_type::potion_fire_resist },
{ R"(potion_shock_resist)", icon_image_type::potion_shock_resist },
{ R"(potion_frost_resist)", icon_image_type::potion_frost_resist },
{ R"(potion_magic_resist)", icon_image_type::potion_magic_resist },
{ R"(alteration)", icon_image_type::alteration },
{ R"(conjuration)", icon_image_type::conjuration },
{ R"(illusion)", icon_image_type::illusion },
{ R"(torch)", icon_image_type::torch },
{ R"(lantern)", icon_image_type::lantern },
{ R"(mask)", icon_image_type::mask } };
}
Loading

0 comments on commit 208ac43

Please sign in to comment.