Skip to content

Commit

Permalink
cleanup (#30)
Browse files Browse the repository at this point in the history
* adjusted: poison dose is now calculated from the perks, so it would be
the same as using it form the inventory. Tested with the Vanilla Perks,
Adamant, Ordinator, Vokrii. If there is somewhere a special
implementation that was missed there is a setting to overwrite it (Misc
Settings>Behavior Settings>Overwrite Poison Dose and Poison Dose) there
it can be set manually.
  • Loading branch information
mlthelama authored Mar 27, 2023
2 parents 498e9bf + 6b7c255 commit 03212db
Show file tree
Hide file tree
Showing 15 changed files with 128 additions and 40 deletions.
2 changes: 2 additions & 0 deletions cmake/sourcelist.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ set(sources ${sources}
src/util/helper.cpp
src/util/helper.h
src/util/offset.h
src/util/player/perk_visitor.cpp
src/util/player/perk_visitor.h
src/util/player/player.cpp
src/util/player/player.h
src/util/string_util.h
Expand Down
27 changes: 23 additions & 4 deletions mcm/Config/LamasTinyHUD/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,14 @@
"propertyName": "bGroupPotions"
}
},
{
"type": "hiddenToggle",
"groupControl": 10,
"valueOptions": {
"sourceType": "PropertyValueBool",
"propertyName": "bPoisonDose"
}
},
{
"id": "bHideOutsideCombat:MiscSetting",
"text": "$LamasTinyHUD_MiscSetting_HideOutsideCombat_OptionText",
Expand Down Expand Up @@ -1451,13 +1459,24 @@
}
},
{
"id": "uApplyPoisonCharges:MiscSetting",
"text": "$LamasTinyHUD_MiscSetting_ApplyPoisonCharges_OptionText",
"id": "bPoisonDoseOverwrite:MiscSetting",
"text": "$LamasTinyHUD_MiscSetting_PoisonDoseOverwrite_OptionText",
"type": "toggle",
"help": "$LamasTinyHUD_MiscSetting_PoisonDoseOverwrite_InfoText",
"valueOptions": {
"sourceType": "ModSettingBool"
}
},
{
"id": "uApplyPoisonDose:MiscSetting",
"text": "$LamasTinyHUD_MiscSetting_ApplyPoisonDose_OptionText",
"type": "slider",
"help": "$LamasTinyHUD_MiscSetting_ApplyPoisonCharges_InfoText",
"help": "$LamasTinyHUD_MiscSetting_ApplyPoisonDose_InfoText",
"groupCondition": 10,
"groupBehavior": "disable",
"valueOptions": {
"min": 1,
"max": 20,
"max": 30,
"step": 1,
"formatString": "{0}",
"sourceType": "ModSettingInt"
Expand Down
3 changes: 2 additions & 1 deletion mcm/Config/LamasTinyHUD/settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ fPotionMinPerfect = 0.7
fPotionMaxPerfect = 1.2
bDisableReEquipOfActives = 0
bSortArrowByQuantity = 0
uApplyPoisonCharges = 5
bPoisonDoseOverwrite = 0
uApplyPoisonDose = 5
bTryDualCastTopSpell = 0

[CleanupSetting]
Expand Down
Binary file modified mcm/Interface/Translations/LamasTinyHUD_english.txt
Binary file not shown.
Binary file modified mcm/scripts/LamasTinyHUD_MCM.pex
Binary file not shown.
5 changes: 5 additions & 0 deletions mcm/source/Scripts/LamasTinyHUD_MCM.psc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ bool property bUnarmed Auto
bool property bGroupPotions Auto
bool property bEditKey Auto
bool property bCleanup Auto
bool property bPoisonDose Auto

Event OnConfigClose() native
string function GetResolutionWidth() native
Expand Down Expand Up @@ -142,6 +143,9 @@ Event OnSettingChange(String a_ID)
elseif (a_ID == "bAutoCleanup:CleanupSetting")
bCleanup = GetModSettingBool(a_ID)
RefreshMenu()
elseif (a_ID == "bPoisonDoseOverwrite:MiscSetting")
bPoisonDose = GetModSettingBool(a_ID)
RefreshMenu()
endif
EndEvent

Expand Down Expand Up @@ -169,4 +173,5 @@ Event OnConfigOpen()
bSpellLeft = false
bEditKey = GetModSettingBool("bKeyPressToEnterEdit:Controls")
bCleanup = GetModSettingBool("bAutoCleanup:CleanupSetting")
bPoisonDose = GetModSettingBool("bPoisonDoseOverwrite:MiscSetting")
EndEvent
45 changes: 26 additions & 19 deletions src/equip/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "setting/mcm_setting.h"
#include "util/constant.h"
#include "util/helper.h"
#include "util/player/perk_visitor.h"
#include "util/player/player.h"
#include "util/string_util.h"

Expand Down Expand Up @@ -92,20 +93,6 @@ namespace equip {
}
}

//if (!extra_vector.empty()) {
//extra = extra_vector.back();
/*if (left) {
REL::Relocation<std::uintptr_t> extra_worn_left_vtbl{ RE::VTABLE_ExtraWornLeft[0] };
auto* worn_left =
(RE::ExtraWornLeft*)RE::BSExtraData::Create(sizeof(RE::ExtraWornLeft), extra_worn_left_vtbl.get());
extra->Add(worn_left);
} else {
REL::Relocation<std::uintptr_t> extra_worn_vtbl{ RE::VTABLE_ExtraWorn[0] };
auto* worn = (RE::ExtraWorn*)RE::BSExtraData::Create(sizeof(RE::ExtraWorn), extra_worn_vtbl.get());
extra->Add(worn);
}*/
//}

const auto obj_right = a_player->GetActorRuntimeData().currentProcess->GetEquippedRightHand();
const auto obj_left = a_player->GetActorRuntimeData().currentProcess->GetEquippedLeftHand();
if (left && obj_left && obj_left->formID == obj->formID) {
Expand Down Expand Up @@ -155,7 +142,7 @@ namespace equip {
auto item_count = 0;
for (const auto& [item, inv_data] : util::player::get_inventory(a_player, RE::FormType::Armor)) {
if (const auto& [num_items, entry] = inv_data; entry->object->formID == a_form->formID) {
obj = inv_data.second->object;
obj = entry->object;
item_count = num_items;
break;
}
Expand Down Expand Up @@ -211,14 +198,34 @@ namespace equip {
auto alchemy_item = obj->As<RE::AlchemyItem>();
if (alchemy_item->IsPoison()) {
logger::trace("try to apply poison to weapon, count left {}"sv, left);
uint32_t potion_doses = 1;
/* it works for vanilla and adamant
* vanilla does a basic set value to 3
* adamant does 2 times a add value 2
* ordinator we could handle it "dirty" because the Information we need needs to be RE, but if perk xy Is set
we could calculate it ourself. It is basically AV multiply base + "alchemy level" * 0.1 * 3 = dose count
* vokrii should be fine as well
* other add av multiply implementations need to be handled by getting the data from the game
* the MCM setting will be left for overwrite handling */
if (config::mcm_setting::get_overwrite_poison_dose()) {
potion_doses = config::mcm_setting::get_apply_poison_dose();
} else {
if (a_player->HasPerkEntries(RE::BGSEntryPoint::ENTRY_POINTS::kModPoisonDoseCount)) {
auto perk_visit = util::perk_visitor(a_player, static_cast<float>(potion_doses));
a_player->ForEachPerkEntry(RE::BGSEntryPoint::ENTRY_POINTS::kModPoisonDoseCount, perk_visit);
potion_doses = static_cast<int>(perk_visit.get_result());
}
}
logger::trace("Poison dose set value is {}"sv, potion_doses);

//check if there is a weapon to apply it to
//check count here as well, since we need 2
//check count here as well, since we need max 2
auto equipped_object = a_player->GetEquippedEntryData(false);
if (equipped_object && equipped_object->object->IsWeapon() && !equipped_object->IsPoisoned()) {
logger::trace("try to add poison {} to right {}"sv,
alchemy_item->GetName(),
equipped_object->GetDisplayName());
equipped_object->PoisonObject(alchemy_item, config::mcm_setting::get_apply_poison_charges());
equipped_object->PoisonObject(alchemy_item, potion_doses);
a_player->RemoveItem(alchemy_item, 1, RE::ITEM_REMOVE_REASON::kRemove, nullptr, nullptr);
left--;
}
Expand All @@ -229,7 +236,7 @@ namespace equip {
logger::trace("try to add poison {} to left {}"sv,
alchemy_item->GetName(),
equipped_object_left->GetDisplayName());
equipped_object_left->PoisonObject(alchemy_item, config::mcm_setting::get_apply_poison_charges());
equipped_object_left->PoisonObject(alchemy_item, potion_doses);
a_player->RemoveItem(alchemy_item, 1, RE::ITEM_REMOVE_REASON::kRemove, nullptr, nullptr);
}
logger::trace("Is a poison, I am done here. return.");
Expand All @@ -252,7 +259,7 @@ namespace equip {
const auto& [item, inv_data] : potential_items) {
if (const auto& [num_items, entry] = inv_data; entry->object->formID == a_form->formID) {
obj = item;
left = inv_data.first;
left = num_items;
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/equip/magic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ namespace equip {
}

RE::TESBoundObject* obj = nullptr;
uint32_t left = 0;
auto left = 0;
for (auto potential_items = util::player::get_inventory(a_player, RE::FormType::Scroll);
const auto& [item, inv_data] : potential_items) {
if (const auto& [num_items, entry] = inv_data; entry->object->formID == a_form->formID) {
obj = item;
left = inv_data.first;
left = num_items;
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/event/equip_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ namespace event {
}

const auto ui = RE::UI::GetSingleton();
if (!ui || (ui->IsMenuOpen(RE::InventoryMenu::MENU_NAME) || ui->IsMenuOpen(RE::MagicMenu::MENU_NAME) ||
/*if (!ui || (ui->IsMenuOpen(RE::InventoryMenu::MENU_NAME) || ui->IsMenuOpen(RE::MagicMenu::MENU_NAME) ||
ui->IsMenuOpen(RE::FavoritesMenu::MENU_NAME))) {
return event_result::kContinue;
}
}*/

//add check if we need to block left
if (!ui->GameIsPaused() && config::mcm_setting::get_elden_demon_souls() && util::helper::is_two_handed(form)) {
Expand Down
1 change: 0 additions & 1 deletion src/handle/extra_data_holder.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "extra_data_holder.h"
#include "util/string_util.h"

namespace handle {
extra_data_holder* extra_data_holder::get_singleton() {
Expand Down
9 changes: 6 additions & 3 deletions src/setting/mcm_setting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ namespace config {
static float potion_max_perfect;
static bool disable_re_equip_of_actives;
static bool sort_arrow_by_quantity;
static uint32_t apply_poison_charges;
static bool overwrite_poison_dose;
static uint32_t apply_poison_dose;
static bool try_dual_cast_top_spell;

static bool auto_cleanup;
Expand Down Expand Up @@ -221,7 +222,8 @@ namespace config {
potion_max_perfect = static_cast<float>(mcm.GetDoubleValue("MiscSetting", "fPotionMaxPerfect", 1.2));
disable_re_equip_of_actives = mcm.GetBoolValue("MiscSetting", "bDisableReEquipOfActives", false);
sort_arrow_by_quantity = mcm.GetBoolValue("MiscSetting", "bSortArrowByQuantity", false);
apply_poison_charges = static_cast<uint32_t>(mcm.GetLongValue("MiscSetting", "uApplyPoisonCharges", 5));
overwrite_poison_dose = mcm.GetBoolValue("MiscSetting", "bPoisonDoseOverwrite", false);
apply_poison_dose = static_cast<uint32_t>(mcm.GetLongValue("MiscSetting", "uApplyPoisonDose", 5));
try_dual_cast_top_spell = mcm.GetBoolValue("MiscSetting", "bTryDualCastTopSpell", false);

auto_cleanup = mcm.GetBoolValue("CleanupSetting", "bAutoCleanup", false);
Expand Down Expand Up @@ -336,7 +338,8 @@ namespace config {
float mcm_setting::get_potion_max_perfect() { return potion_max_perfect; }
bool mcm_setting::get_disable_re_equip_of_actives() { return disable_re_equip_of_actives; }
bool mcm_setting::get_sort_arrow_by_quantity() { return sort_arrow_by_quantity; }
uint32_t mcm_setting::get_apply_poison_charges() { return apply_poison_charges; }
bool mcm_setting::get_overwrite_poison_dose() { return overwrite_poison_dose; }
uint32_t mcm_setting::get_apply_poison_dose() { return apply_poison_dose; }
bool mcm_setting::get_try_dual_cast_top_spell() { return try_dual_cast_top_spell; }

bool mcm_setting::get_auto_cleanup() { return auto_cleanup; }
Expand Down
3 changes: 2 additions & 1 deletion src/setting/mcm_setting.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ namespace config {
static float get_potion_max_perfect();
static bool get_disable_re_equip_of_actives();
static bool get_sort_arrow_by_quantity();
static uint32_t get_apply_poison_charges();
static bool get_overwrite_poison_dose();
static uint32_t get_apply_poison_dose();
static bool get_try_dual_cast_top_spell();

static bool get_auto_cleanup();
Expand Down
10 changes: 3 additions & 7 deletions src/ui/ui_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,13 @@ namespace ui {
render_manager->GetRuntimeData();

// Load from disk into a raw RGBA buffer
int image_width = 0;
int image_height = 0;
unsigned char* image_data;

auto* svg = nsvgParseFromFile(filename, "px", 96.0f);
auto* rast = nsvgCreateRasterizer();

image_width = static_cast<int32_t>(svg->width);
image_height = static_cast<int32_t>(svg->height);
auto image_width = static_cast<int>(svg->width);
auto image_height = static_cast<int>(svg->height);

image_data = (unsigned char*)malloc(image_width * image_height * 4);
auto image_data = (unsigned char*)malloc(image_width * image_height * 4);
nsvgRasterize(rast, svg, 0, 0, 1, image_data, image_width, image_height, image_width * 4);
nsvgDelete(svg);
nsvgDeleteRasterizer(rast);
Expand Down
36 changes: 36 additions & 0 deletions src/util/player/perk_visitor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "perk_visitor.h"
#include "util/string_util.h"

namespace util {

RE::PerkEntryVisitor::ReturnType perk_visitor::Visit(RE::BGSPerkEntry* perk_entry) {
const auto* entry_point = static_cast<RE::BGSEntryPointPerkEntry*>(perk_entry);
const auto* perk = entry_point->perk;

logger::trace("form id {}, name {}"sv, string_util::int_to_hex(perk->formID), perk->GetName());

if (entry_point->functionData) {
const RE::BGSEntryPointFunctionDataOneValue* value =
static_cast<RE::BGSEntryPointFunctionDataOneValue*>(entry_point->functionData);
if (entry_point->entryData.function == RE::BGSEntryPointPerkEntry::EntryData::Function::kSetValue) {
result_ = value->data;
} else if (entry_point->entryData.function == RE::BGSEntryPointPerkEntry::EntryData::Function::kAddValue) {
result_ += value->data;
} else if (entry_point->entryData.function ==
RE::BGSEntryPointPerkEntry::EntryData::Function::kMultiplyValue) {
result_ *= value->data;
} else if (entry_point->entryData.function ==
RE::BGSEntryPointPerkEntry::EntryData::Function::kAddActorValueMult) {
if (perk_entry->GetFunction() == RE::BGSPerkEntry::EntryPoint::kModPoisonDoseCount) {
auto av = actor_->AsActorValueOwner()->GetActorValue(RE::ActorValue::kAlchemy);
result_ += static_cast<float>(av * 0.1 * 3);
}
}
logger::trace("Got value {} for Perk, total now is {}"sv, value->data, result_);
}

return ReturnType::kContinue;
}

float perk_visitor::get_result() const { return result_; }
} // util
19 changes: 19 additions & 0 deletions src/util/player/perk_visitor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

namespace util {
class perk_visitor : public RE::PerkEntryVisitor {
public:
explicit perk_visitor(RE::Actor* a_actor, float a_base) {
actor_ = a_actor;
result_ = a_base;
}

ReturnType Visit(RE::BGSPerkEntry* perk_entry) override;

[[nodiscard]] float get_result() const;

protected:
RE::Actor* actor_;
float result_;
};
} // util

0 comments on commit 03212db

Please sign in to comment.