Skip to content

Commit

Permalink
feat: Misc update.
Browse files Browse the repository at this point in the history
  • Loading branch information
FlenarnTemp committed Sep 25, 2024
1 parent 9d1782f commit 68b48b4
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 80 deletions.
62 changes: 62 additions & 0 deletions Plugin/src/Events/TESHitEvent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#pragma once

namespace RE
{
namespace Cascadia
{
class TESHitEventWatcher :
public BSTEventSink<TESHitEvent>
{
virtual BSEventNotifyControl ProcessEvent(const TESHitEvent& a_event, BSTEventSource<TESHitEvent>*) override
{
TESObjectREFR* target = a_event.target.get();

// Return early on invalid events.
// Note: Unsure about the logic RE; Power Armor here.
if (!target || !a_event.usesHitData || target->extraList->GetByType(kPowerArmor) != nullptr)
{
return BSEventNotifyControl::kContinue;
}

Actor* actor = static_cast<Actor*>(target);

// We're only interested in the player.
if (target != PlayerCharacter::GetSingleton())
{
return BSEventNotifyControl::kContinue;
}

TESObjectREFR* sourceREFR = a_event.hitData.sourceRef.get().get();

BGSBodyPartData* bodyPartData = actor->GetBodyPartData();

// If sourceREFR is 'nullptr', most likely a melee attack.
if (sourceREFR)
{
if (sourceREFR->IsExplosion())
{
DEBUG("Explosion!");
}
else
{

}
}
else
{
auto test = a_event.hitData.weapon.object->GetFormEditorID();
DEBUG("WEAPON USED: {}", test);
}

return BSEventNotifyControl::kContinue;
}
};

void RegisterTESHitEventSink()
{
TESHitEventWatcher* tesHitEvent = new TESHitEventWatcher();
TESHitEvent::GetEventSource()->RegisterSink(tesHitEvent);
INFO("Registed 'TESHitEvent' sink.");
}
}
}
27 changes: 22 additions & 5 deletions Plugin/src/Shared/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ namespace RE
{
void Install(F4SE::Trampoline& trampoline)
{
// GetInfoForPlayerDialogueOptionHook - 2196817 ID + 0x40A offset
// GetInfoForPlayerDialogueOptionHook - { ID 2196817 + Offset-0x40A }
typedef TESTopicInfo(GetCurrentTopicInfo_Player_Sig)(BGSSceneActionPlayerDialogue* apPlayerDialogue, BGSScene* apParentScene, TESObjectREFR* apTarget, std::uint32_t aeType);
REL::Relocation<GetCurrentTopicInfo_Player_Sig> GetCurrentTopicInfo_Player_Location{ REL::ID(2196817), 0x40A };
trampoline.write_call<5>(GetCurrentTopicInfo_Player_Location.address(), &RE::GetCurrentTopicInfo_Player_Hook);

// GetInfoForNPCResponseDialogOptionHook - 2196817 ID + 0x78E offset
// GetInfoForNPCResponseDialogOptionHook - { ID 2196817 + 0x78E-offset }
typedef TESTopicInfo(GetCurrentTopicInfo_NPC_Sig)(BGSSceneActionPlayerDialogue* apPlayerDialogue, BGSScene* apParentScene, TESObjectREFR* apTarget, std::uint32_t aeType);
REL::Relocation<GetCurrentTopicInfo_NPC_Sig> GetCurrentTopicInfo_NPC_Location{ REL::ID(2196817), 0x7A1 };
trampoline.write_call<5>(GetCurrentTopicInfo_NPC_Location.address(), &RE::GetCurrentTopicInfo_NPC_Hook);
Expand Down Expand Up @@ -50,7 +50,22 @@ namespace RE
RE::RepairFailureCallback* repairFailureCallback = new RE::RepairFailureCallback(examineMenu.get());
RE::ExamineConfirmMenu::InitDataRepairFailure* initDataRepair = new RE::ExamineConfirmMenu::InitDataRepairFailure(requiredItems);

// TODO - list available components.
BSTHashMap<TESBoundObject*, std::uint32_t> availableComponents;

std::uint32_t size = requiredItems->size();
if (size)
{
auto tester = examineMenu->sharedContainerRef.get();
if (tester)
{

}

initDataRepair->availableComponents = availableComponents;

// TODO - list available components.
}


examineMenu->ShowConfirmMenu(initDataRepair, repairFailureCallback);
}
Expand Down Expand Up @@ -395,11 +410,13 @@ namespace RE
{
conditionReduction = it->second;
}
else

if (conditionReduction == 0.01f)
{
DEBUG("TESObjectWEAP::Fire - Ammo type '{}' is not declared in 'ammoDegradationMap'.", ammoInstance->GetFormEditorID())
WARN("TESObjectWEAP::Fire - Ammo type '{}' is not declared in 'ammoDegradationMap'.", ammoInstance->GetFormEditorID())
}

// TODO: Rework these numbers after gameplay tests.
std::uint32_t flags = data->flags.underlying();
if (flags & std::uint32_t(WEAPON_FLAGS::kAutomatic))
{
Expand Down
85 changes: 12 additions & 73 deletions Plugin/src/Systems/ItemDegradation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,6 @@ namespace RE
{
namespace Cascadia
{
// Weapon Condition - Manual Settings
float fDamageSkillMult;
float fDamageSkillBase;
float fAVDMeleeDamageStrengthMult;
float fAVDMeleeDamageStrengthOffset;

// Weapon Condition - Rate of Fire Game Settings
Setting* fWeaponConditionRateOfFire1;
Setting* fWeaponConditionRateOfFire2;
Setting* fWeaponConditionRateOfFire3;
Setting* fWeaponConditionRateOfFire4;
Setting* fWeaponConditionRateOfFire5;
Setting* fWeaponConditionRateOfFire6;
Setting* fWeaponConditionRateOfFire7;
Setting* fWeaponConditionRateOfFire8;
Setting* fWeaponConditionRateOfFire9;
Setting* fWeaponConditionRateOfFire10;

// Power Armor Keyword
BGSKeyword* furnitureTypePowerArmor;

Expand All @@ -41,23 +23,6 @@ namespace RE
{
INFO("Item Degradation: Linking degradation forms.");

fDamageSkillBase = 0.5f;
fDamageSkillMult = 0.5f;
fAVDMeleeDamageStrengthMult = 0.5f;
fAVDMeleeDamageStrengthOffset = 0.0f;

GameSettingCollection* gameSettings = GameSettingCollection::GetSingleton();

fWeaponConditionRateOfFire1 = gameSettings->GetSetting("fWeaponConditionRateOfFire1");
fWeaponConditionRateOfFire2 = gameSettings->GetSetting("fWeaponConditionRateOfFire2");
fWeaponConditionRateOfFire3 = gameSettings->GetSetting("fWeaponConditionRateOfFire3");
fWeaponConditionRateOfFire4 = gameSettings->GetSetting("fWeaponConditionRateOfFire4");
fWeaponConditionRateOfFire5 = gameSettings->GetSetting("fWeaponConditionRateOfFire5");
fWeaponConditionRateOfFire6 = gameSettings->GetSetting("fWeaponConditionRateOfFire6");
fWeaponConditionRateOfFire7 = gameSettings->GetSetting("fWeaponConditionRateOfFire7");
fWeaponConditionRateOfFire8 = gameSettings->GetSetting("fWeaponConditionRateOfFire8");
fWeaponConditionRateOfFire9 = gameSettings->GetSetting("fWeaponConditionRateOfFire9");
fWeaponConditionRateOfFire10 = gameSettings->GetSetting("fWeaponConditionRateOfFire10");

TESDataHandler* dataHandler = TESDataHandler::GetSingleton();

Expand All @@ -70,52 +35,26 @@ namespace RE
armorBodyPartLeftLeg = dataHandler->LookupForm<BGSKeyword>(0x211D07, "FalloutCascadia.esm");
armorBodyPartRightLeg = dataHandler->LookupForm<BGSKeyword>(0x211D09, "FalloutCascadia.esm");

TESAmmo* ammo45 = dataHandler->LookupForm<TESAmmo>(0x01F66A, "Fallout4.esm");
// Ammo types with respective degradation values
TESAmmo* ammo10mm = dataHandler->LookupForm<TESAmmo>(0x01F276, "Fallout4.esm");
TESAmmo* ammo2mmEC = dataHandler->LookupForm<TESAmmo>(0x18ABDF, "Fallout4.esm");
TESAmmo* ammo308 = dataHandler->LookupForm<TESAmmo>(0x01F66B, "Fallout4.esm");
TESAmmo* ammo38 = dataHandler->LookupForm<TESAmmo>(0x04CE87, "Fallout4.esm");
TESAmmo* ammo44 = dataHandler->LookupForm<TESAmmo>(0x09221C, "Fallout4.esm");
TESAmmo* ammo45 = dataHandler->LookupForm<TESAmmo>(0x01F66A, "Fallout4.esm");

ammoDegradationMap[ammo45] = 0.0035;
ammoDegradationMap[ammo10mm] = 0.005f;
ammoDegradationMap[ammo2mmEC] = 0.04f;
ammoDegradationMap[ammo308] = 0.0133f;
ammoDegradationMap[ammo38] = 0.003f;
ammoDegradationMap[ammo44] = 0.011f;
ammoDegradationMap[ammo45] = 0.0035f;


// No Degradation Keyword
noDegradation = dataHandler->LookupForm<BGSKeyword>(0x2BD72E, "FalloutCascadia.esm");

INFO("Item Degradation: Finished linking degradation forms.");
}


float CalculateSkillBonusFromActor(TESObjectWEAP* myWeapon)
{
float actorSkillValue = 1.0f;

if (myWeapon->weaponData.skill != nullptr)
{
actorSkillValue = (PlayerCharacter::GetSingleton()->GetActorValue(*myWeapon->weaponData.skill) / 100);
}

float result = (fDamageSkillBase + fDamageSkillMult * actorSkillValue);

return result;
}

void ModWeaponCondition()
{
PlayerCharacter* playerCharacter = PlayerCharacter::GetSingleton();

if (playerCharacter->IsGodMode())
{
DEBUG("ModWeaponCondition: God Mod enabled, ignoring weapon degradation.");
return;
}

EquippedItem& equippedWeapon = playerCharacter->currentProcess->middleHigh->equippedItems[0];
TESObjectWEAP* playerWeapon = (TESObjectWEAP*)equippedWeapon.item.object;
auto instanceData = equippedWeapon.item.instanceData.get();
DEBUG("Bound object: {}", playerWeapon->IsBoundObject());
}

void ModWeaponCondition(TESObjectREFR* myWeapon, float a_value)
{

}
}
}
1 change: 0 additions & 1 deletion Plugin/src/Systems/ItemDegradation.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace RE
{
namespace Cascadia
{
void ModWeaponCondition();
void DefineItemDegradationFormsFromGame();

std::map<TESAmmo*, float> ammoDegradationMap;
Expand Down
4 changes: 3 additions & 1 deletion Plugin/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Events/MenuOpenCloseEvent.h"
#include "Events/TESInitScriptEvent.h"
#include "Events/TESHarvestEvent.h"
#include "Events/TESHitEvent.h"
#include "Menus/ExamineConfirmMenu.h"
#include "Menus/PipboyMenu.h"
#include "Patches/Patches.h"
Expand Down Expand Up @@ -43,6 +44,7 @@ namespace
RE::Cascadia::DefineItemDegradationFormsFromGame();
RE::Cascadia::InputEventReceiverOverride::Install();
RE::Cascadia::BSAnimationGraphEventWatcher::Install();
RE::Cascadia::RegisterTESHitEventSink();
RE::Cascadia::RegisterTESInitScriptEventSink();
//RE::Cascadia::RegisterTESHarvestEventEventSink();
break;
Expand Down Expand Up @@ -182,7 +184,7 @@ DLLEXPORT bool F4SEAPI F4SEPlugin_Load(const F4SE::LoadInterface* a_F4SE)
RE::Cascadia::Hooks::RegisterExamineMenuBuildConfirmed();
RE::Cascadia::Hooks::RegisterTESObjectWEAPFire();
RE::Cascadia::Hooks::RegisterCombatFormulasCalcWeaponDamage();
RE::Cascadia::Hooks::RegisterGetEquippedArmorDamageResistance();
//RE::Cascadia::Hooks::RegisterGetEquippedArmorDamageResistance();
RE::Cascadia::Patches::Install();
ObScript::Install();

Expand Down

0 comments on commit 68b48b4

Please sign in to comment.