Skip to content

Commit

Permalink
[fix]
Browse files Browse the repository at this point in the history
* add some checks if the form does not match configured type
* some checks to prevent a few crashes
* added updated sample images
  • Loading branch information
mlthelama committed Jan 11, 2023
1 parent 9f8f696 commit e969f49
Show file tree
Hide file tree
Showing 19 changed files with 43 additions and 4 deletions.
Binary file modified mcm/scripts/LamasTinyHUD_MCM.pex
Binary file not shown.
Binary file modified sample/default.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/default_test.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sample/default_test_2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/mcm_bottom.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/mcm_controls.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/mcm_left.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/mcm_right.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sample/mcm_right_one.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/mcm_settings.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample/mcm_top.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sample/mcm_top_one.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions src/equip/item/potion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ namespace item {
void potion::consume_potion(handle::slot_setting*& a_slot, RE::PlayerCharacter*& a_player) {
logger::trace("try to consume {}"sv, a_slot->form->GetName());


RE::TESBoundObject* obj = nullptr;
RE::InventoryEntryData inv_data;
uint32_t left;
for (auto potential_items = inventory::get_inventory_magic_items(a_player);
const auto& [item, invData] : potential_items) {
if (invData.second->object->formID == a_slot->form->formID) {
obj = item;
inv_data = *invData.second;
left = invData.first;
break;
}
Expand All @@ -25,6 +24,11 @@ namespace item {
return;
}

if (!obj->Is(RE::FormType::AlchemyItem)) {
logger::warn("object {} is not an alchemy item. return."sv, obj->GetName());
return;
}

logger::trace("calling drink/eat potion/food {}, count left {}"sv, obj->GetName(), left);

const auto equip_manager = RE::ActorEquipManager::GetSingleton();
Expand Down
8 changes: 8 additions & 0 deletions src/equip/item/weapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,16 @@ namespace item {
RE::ExtraDataList* extra = nullptr;
std::map<RE::TESBoundObject*, std::pair<int, std::unique_ptr<RE::InventoryEntryData>>> potential_items;
if (a_weapon) {
if (!a_form->Is(RE::FormType::Weapon)) {
logger::warn("object {} is not a weapon. return."sv, a_form->GetName());
return;
}
potential_items = inventory::get_inventory_weapon_items(a_player);
} else {
if (!a_form->Is(RE::FormType::Armor)) {
logger::warn("object {} is not an armor. return."sv, a_form->GetName());
return;
}
potential_items = inventory::get_inventory_armor_items(a_player);
}

Expand Down
4 changes: 4 additions & 0 deletions src/equip/magic/power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ namespace magic {
void power::equip_or_cast_power(RE::TESForm* a_form, action_type a_action, RE::PlayerCharacter*& a_player) {
logger::trace("try to work power {}, action {}"sv, a_form->GetName(), static_cast<uint32_t>(a_action));

if (!a_form->Is(RE::FormType::Spell)) {
logger::warn("object {} is not a spell. return."sv, a_form->GetName());
return;
}

if (const auto selected_power = a_player->GetActorRuntimeData().selectedPower;
selected_power != nullptr && a_action != handle::slot_setting::acton_type::instant) {
Expand Down
5 changes: 5 additions & 0 deletions src/equip/magic/shout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ namespace magic {
void shout::equip_shout(RE::TESForm* a_form, RE::PlayerCharacter*& a_player) {
logger::trace("try to equip shout {}"sv, a_form->GetName());

if (!a_form->Is(RE::FormType::Shout)) {
logger::warn("object {} is not a shout. return."sv, a_form->GetName());
return;
}

if (const auto selected_power = a_player->GetActorRuntimeData().selectedPower;
selected_power != nullptr) {
logger::trace("current selected power is {}, is shout {}, is spell {}"sv,
Expand Down
6 changes: 6 additions & 0 deletions src/equip/magic/spell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ namespace magic {
a_form->GetName(),
static_cast<uint32_t>(a_action),
left);

if (!a_form->Is(RE::FormType::Spell)) {
logger::warn("object {} is not a spell. return."sv, a_form->GetName());
return;
}

const auto spell = a_form->As<RE::SpellItem>();

//spell->avEffectSetting->data.dualCastScale
Expand Down
14 changes: 13 additions & 1 deletion src/handle/page_handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ namespace handle {
}

void page_handle::get_icon_for_weapon_type(RE::TESForm*& a_form, ui::icon_image_type& a_icon) {
if (!a_form->IsWeapon()) {
return;
}
switch (const auto weapon = a_form->As<RE::TESObjectWEAP>(); weapon->GetWeaponType()) {
case RE::WEAPON_TYPE::kHandToHandMelee:
break;
Expand Down Expand Up @@ -246,6 +249,9 @@ namespace handle {
}

void page_handle::get_icon_for_spell(RE::TESForm*& a_form, ui::icon_image_type& a_icon) {
if (!a_form->Is(RE::FormType::Spell)) {
return;
}
const auto spell = a_form->As<RE::SpellItem>();
const auto effect = spell->GetCostliestEffectItem()->baseEffect;
auto actor_value = effect->GetMagickSkill();
Expand Down Expand Up @@ -284,6 +290,9 @@ namespace handle {
}

void page_handle::get_icon_for_consumable(RE::TESForm*& a_form, ui::icon_image_type& a_icon) {
if (!a_form->Is(RE::FormType::AlchemyItem)) {
return;
}
const auto alchemy_potion = a_form->As<RE::AlchemyItem>();

if (alchemy_potion->IsFood()) {
Expand Down Expand Up @@ -330,7 +339,10 @@ namespace handle {
}

void page_handle::get_icon_for_item(RE::TESForm*& a_form, ui::icon_image_type& a_icon) {
switch (const auto weapon = a_form->As<RE::TESObjectARMO>(); weapon->GetArmorType()) {
if (!a_form->IsArmor()) {
return;
}
switch (const auto armor = a_form->As<RE::TESObjectARMO>(); armor->GetArmorType()) {
case RE::BIPED_MODEL::ArmorType::kLightArmor:
a_icon = ui::icon_image_type::armor_light;
break;
Expand Down
2 changes: 1 addition & 1 deletion src/papyrus/papyrus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace papyrus {
logger::info("Got refresh for id {}, both hands {}, instant {}"sv, a_id, a_both, a_instant_cast);
std::vector<RE::BSFixedString> empty_string_vec = { util::empty_enum_string };
const auto display_string_list = new std::vector<RE::BSFixedString>;
//clear_list();
clear_list();
//let the list be valid until it is refreshed again, might be an issue with magic and weapon

index_ = static_cast<util::selection_type>(a_id);
Expand Down

0 comments on commit e969f49

Please sign in to comment.