Skip to content

Commit

Permalink
Move OffensiveSpellAI to Tweaks, made it optional
Browse files Browse the repository at this point in the history
  • Loading branch information
powerof3 committed Sep 27, 2023
1 parent 8c34fda commit 0e129ba
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 97 deletions.
133 changes: 77 additions & 56 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -1,94 +1,115 @@
{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 21,
"patch": 0
},
"configurePresets": [
{
"binaryDir": "${sourceDir}/build",
"name": "cmake-dev",
"hidden": true,
"cacheVariables": {
"CMAKE_BUILD_TYPE": {
"type": "STRING",
"value": "Release"
}
"CMAKE_CONFIGURATION_TYPES": "Debug;Release",
"CMAKE_CXX_FLAGS": "/EHsc /MP /W4 /external:anglebrackets /external:W0 $penv{CXXFLAGS}"
},
"errors": {
"deprecated": true
},
"hidden": true,
"name": "cmake-dev",
"warnings": {
"deprecated": true,
"dev": true
}
},
{
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": {
"type": "STRING",
"value": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
},
"VCPKG_OVERLAY_PORTS": {
"type": "STRING",
"value": "${sourceDir}/cmake/ports/"
}
},
"name": "vcpkg",
"hidden": true,
"name": "vcpkg"
"toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"cacheVariables": {
"VCPKG_OVERLAY_PORTS": "${sourceDir}/cmake/ports/"
}
},
{
"cacheVariables": {
"CMAKE_MSVC_RUNTIME_LIBRARY": {
"type": "STRING",
"value": "MultiThreaded$<$<CONFIG:Debug>:Debug>"
},
"VCPKG_TARGET_TRIPLET": {
"type": "STRING",
"value": "x64-windows-static"
}
},
"name": "windows",
"hidden": true,
"name": "windows"
"cacheVariables": {
"CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreaded$<$<CONFIG:Debug>:Debug>",
"VCPKG_TARGET_TRIPLET": "x64-windows-static"
}
},
{
"cacheVariables": {
"CMAKE_CXX_FLAGS": "/EHsc /MP /W4 /WX /external:W0 $penv{CXXFLAGS}"
},
"name": "vs2022",
"hidden": true,
"generator": "Visual Studio 17 2022",
"inherits": [
"cmake-dev",
"vcpkg",
"windows"
],
"name": "vs2022-windows-vcpkg-se",
"toolset": "v143"
},
{
"name": "se",
"hidden": true,
"binaryDir": "${sourceDir}/build"
},
{
"name": "ae",
"hidden": true,
"binaryDir": "${sourceDir}/buildae",
"cacheVariables": {
"BUILD_SKYRIMAE": true
}
},
{
"name": "vr",
"hidden": true,
"binaryDir": "${sourceDir}/buildvr",
"cacheVariables": {
"CMAKE_CXX_FLAGS": "/EHsc /MP /W4 /WX /external:W0 $penv{CXXFLAGS}",
"BUILD_SKYRIMVR": true
},
"generator": "Visual Studio 17 2022",
}
},
{
"name": "vs2022-windows-vcpkg-se",
"inherits": [
"cmake-dev",
"vcpkg",
"windows"
],
"name": "vs2022-windows-vcpkg-vr",
"toolset": "v143"
"windows",
"vs2022",
"se"
]
},
{
"binaryDir": "${sourceDir}/buildae",
"cacheVariables": {
"CMAKE_CXX_FLAGS": "/EHsc /MP /W4 /WX /external:W0 $penv{CXXFLAGS}",
"BUILD_SKYRIMAE": true
},
"generator": "Visual Studio 17 2022",
"name": "vs2022-windows-vcpkg-ae",
"inherits": [
"cmake-dev",
"vcpkg",
"windows"
],
"name": "vs2022-windows-vcpkg-ae",
"toolset": "v143"
"windows",
"vs2022",
"ae"
]
},
{
"name": "vs2022-windows-vcpkg-vr",
"inherits": [
"cmake-dev",
"vcpkg",
"windows",
"vs2022",
"vr"
]
}
],
"version": 3
"buildPresets": [
{
"name": "vs2022-windows-vcpkg-ae",
"configurePreset": "vs2022-windows-vcpkg-ae",
"configuration": "Release"
},
{
"name": "vs2022-windows-vcpkg-se",
"configurePreset": "vs2022-windows-vcpkg-se",
"configuration": "Release"
},
{
"name": "vs2022-windows-vcpkg-vr",
"configurePreset": "vs2022-windows-vcpkg-vr",
"configuration": "Release"
}
]
}
2 changes: 1 addition & 1 deletion cmake/sourcelist.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ set(sources ${sources}
src/Fixes/FlagSpellsAsNoAbsorb.cpp
src/Fixes/IsFurnitureAnimTypeForFurniture.cpp
src/Fixes/MapMarkerPlacement.cpp
src/Fixes/OffensiveSpellAI.cpp
src/Fixes/ProjectileRange.cpp
src/Fixes/ReapplySpellsOnLoad.cpp
src/Fixes/RestoreCantTakeBook.cpp
Expand All @@ -40,6 +39,7 @@ set(sources ${sources}
src/Tweaks/NoCritSneakMessages.cpp
src/Tweaks/NoPoisonPrompt.cpp
src/Tweaks/NoRipplesOnHover.cpp
src/Tweaks/OffensiveSpellAI.cpp
src/Tweaks/RememberLockPickAngleVR.cpp
src/Tweaks/ScreenshotToConsole.cpp
src/Tweaks/SilentSneakPowerAttacks.cpp
Expand Down
3 changes: 0 additions & 3 deletions src/Fixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ void Fixes::PostLoad::Install()
if (fixes.useFurnitureInCombat != 0) {
UseFurnitureInCombat::Install();
}
if (fixes.offensiveSpellAI) {
OffensiveSpellAI::Install();
}
if (fixes.loadEditorIDs) {
CacheFormEditorIDs::Install();
}
Expand Down
31 changes: 0 additions & 31 deletions src/Fixes.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,37 +77,6 @@ namespace Fixes
void Install();
}

namespace OffensiveSpellAI
{
template <class T>
class CheckShouldEquip
{
public:
static void Install(REL::ID a_vtable_id)
{
REL::Relocation<std::uintptr_t> vtbl{ a_vtable_id };
func = vtbl.write_vfunc(0xF, thunk);
}

private:
static bool thunk(RE::CombatInventoryItemMagicT<T, RE::CombatMagicCasterOffensive>* a_this, RE::CombatController* a_controller)
{
auto result = func(a_this, a_controller);
if (result) {
const auto target = a_controller->handleCount ?
a_controller->cachedTarget :
a_controller->targetHandle.get();

return target && RE::CombatMagicCaster::CheckTargetValid(a_controller, target.get(), a_this);
}
return result;
}
static inline REL::Relocation<decltype(thunk)> func;
};

void Install();
}

namespace ProjectileRange
{
void Install();
Expand Down
8 changes: 6 additions & 2 deletions src/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ void Settings::Fixes::Load(CSimpleIniA& a_ini)
//1.7.6 - delete Flag Stolen Produce
a_ini.Delete(section, "Flag Stolen Produce", true);

//1.8.1 - move Offensive Spell AI over to Tweaks
a_ini.Delete(section, "Offensive Spell AI", true);

get_value(a_ini, distantRefLoadCrash, section, "Distant Ref Load Crash", ";Fixes loading crash caused by missing 3D on distant references.");
get_value(a_ini, mapMarker, section, "Map Marker Placement Fix", ";Allows placing map markers near fast travel destinations when fast travel is disabled");
get_value(a_ini, dontTakeBookFlag, section, "Restore 'Can't Be Taken Book' Flag", ";Enables 'Can't be taken' book flag functionality.");
Expand All @@ -61,7 +64,6 @@ void Settings::Fixes::Load(CSimpleIniA& a_ini)
get_value(a_ini, jumpingBonusFix, section, "Jumping Bonus Fix", ";Jump height is multiplied by 1% per point of JumpingBonus actor value");
get_value(a_ini, toggleGlobalAIFix, section, "Toggle Global AI Fix", ";TAI console command/Debug.ToggleAI() now toggles all loaded NPC AI");
get_value(a_ini, useFurnitureInCombat, section, "Use Furniture In Combat", ";Use furniture in combat and prevent getting forced out of furniture when attacked.\n;0 - off, 1 - player only, 2 - player and NPCs");
get_value(a_ini, offensiveSpellAI, section, "Offensive Spell AI", ";Check spell condition validity before NPCs equip offensive spells");
get_value(a_ini, breathingSounds, section, "Breathing Sounds", ";Fix creature breathing sounds persisting after cell change");
get_value(a_ini, loadEditorIDs, section, "Load EditorIDs", ";Loads editorIDs for skipped forms at runtime");
#ifdef SKYRIMVR
Expand Down Expand Up @@ -96,7 +98,9 @@ void Settings::Tweaks::Load(CSimpleIniA& a_ini, bool a_clearOld)
#ifdef SKYRIMVR
get_value(a_ini, rememberLockPickAngle, section, "Remember Lock Pick Angle", ";Angle is preserved after break");
#endif
if (a_clearOld) {
get_value(a_ini, offensiveSpellAI, section, "Offensive Spell AI", ";Check spell condition validity before NPCs equip offensive spells");

if (a_clearOld) {
logger::info("Replacing old Patches section with Tweaks");
a_ini.Delete("Patches", nullptr, true);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class Settings : public ISingleton<Settings>
bool skinnedDecalDelete{ true };
bool jumpingBonusFix{ true };
bool toggleGlobalAIFix{ true };
bool offensiveSpellAI{ true };
bool breathingSounds{ true };
std::uint32_t useFurnitureInCombat{ 1 };
bool loadEditorIDs{ true };
Expand Down Expand Up @@ -67,6 +66,7 @@ class Settings : public ISingleton<Settings>
LoadDoorPrompt loadDoorPrompt{};
std::uint32_t noPoisonPrompt{ 0 };
bool silentSneakPowerAttack{ false };
bool offensiveSpellAI{ false };
};

class Experimental
Expand Down
3 changes: 3 additions & 0 deletions src/Tweaks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ void Tweaks::PostLoad::Install()
if (tweaks.silentSneakPowerAttack) {
SilentSneakPowerAttacks::Install();
}
if (tweaks.offensiveSpellAI) {
OffensiveSpellAI::Install();
}
#ifdef SKYRIMVR
if (tweaks.rememberLockPickAngle) {
RememberLockPickAngleVR::Install();
Expand Down
31 changes: 31 additions & 0 deletions src/Tweaks.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,37 @@ namespace Tweaks
void Install();
}

namespace OffensiveSpellAI
{
template <class T>
class CheckShouldEquip
{
public:
static void Install(REL::ID a_vtable_id)
{
REL::Relocation<std::uintptr_t> vtbl{ a_vtable_id };
func = vtbl.write_vfunc(0xF, thunk);
}

private:
static bool thunk(RE::CombatInventoryItemMagicT<T, RE::CombatMagicCasterOffensive>* a_this, RE::CombatController* a_controller)
{
auto result = func(a_this, a_controller);
if (result) {
const auto target = a_controller->handleCount ?
a_controller->cachedTarget :
a_controller->targetHandle.get();

return target && RE::CombatMagicCaster::CheckTargetValid(a_controller, target.get(), a_this);
}
return result;
}
static inline REL::Relocation<decltype(thunk)> func;
};

void Install();
}

#ifdef SKYRIMVR
namespace RememberLockPickAngleVR
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "Fixes.h"
#include "Tweaks.h"

//check spell condition validity before equipping offensive magic
namespace Fixes::OffensiveSpellAI
namespace Tweaks::OffensiveSpellAI
{
namespace CombatMagicCaster
{
Expand Down Expand Up @@ -43,6 +43,6 @@ namespace Fixes::OffensiveSpellAI
CombatInventoryMagic::Install();
CombatMagicCaster::Install();

logger::info("\t\tInstalled offensive spell AI fix"sv);
logger::info("\t\tInstalled offensive spell AI tweak"sv);
}
}

0 comments on commit 0e129ba

Please sign in to comment.