Skip to content

Commit 24e7e4d

Browse files
committed
Tweaks: add NWNX_TWEAKS_FIX_DM_FACTION_BUG
1 parent d6ac145 commit 24e7e4d

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ https://github.com/nwnxee/unified/compare/build8193.33...HEAD
1010
### Added
1111
- Tweaks: added `NWNX_TWEAKS_HIDE_HARDCODED_ITEM_VFX` to hide various hardcoded item vfx.
1212
- Tweaks: added `NWNX_TWEAKS_FIX_RESMAN_MEMLEAK` that fixes a memory leak in Resman / CResGFF.
13+
- Tweaks: added `NWNX_TWEAKS_FIX_DM_FACTION_BUG` that fixes a DM faction bug when using a non-DMClient BIC file.
1314

1415
##### New Plugins
1516
- N/A

Plugins/Tweaks/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ add_plugin(Tweaks
1111
"DisplayNumAttacksOverrideInCharacterSheet.cpp"
1212
"FixArmorDexBonusUnderOne.cpp"
1313
"FixDispelEffectLevels.cpp"
14+
"FixDMFactionBug.cpp"
1415
"FixGreaterSanctuaryBug.cpp"
1516
"FixItemNullptrInCItemRepository.cpp"
1617
"FixResmanMemleak.cpp"

Plugins/Tweaks/FixDMFactionBug.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "nwnx.hpp"
2+
3+
#include "API/CNWSCreature.hpp"
4+
#include "API/CNWSCreatureStats.hpp"
5+
6+
7+
namespace Tweaks {
8+
9+
using namespace NWNXLib;
10+
using namespace NWNXLib::API;
11+
12+
13+
void FixDMFactionBug() __attribute__((constructor));
14+
void FixDMFactionBug()
15+
{
16+
if (!Config::Get<bool>("FIX_DM_FACTION_BUG", false))
17+
return;
18+
19+
LOG_INFO("Fixing a DM faction bug when using a non-DMClient BIC file.");
20+
21+
static Hooks::Hook s_PostProcessHook = Hooks::HookFunction(Functions::_ZN12CNWSCreature11PostProcessEv,
22+
(void*)+[](CNWSCreature *thisPtr) -> void
23+
{
24+
thisPtr->m_bPlayerCharacter = thisPtr->m_pStats->m_bIsPC;
25+
s_PostProcessHook->CallOriginal<void>(thisPtr);
26+
}, Hooks::Order::Early);
27+
}
28+
29+
}

Plugins/Tweaks/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ Tweaks stuff. See below.
4141
| `NWNX_TWEAKS_MATERIAL_NAME_NULL_IS_ALL` | true or false | Makes SetMaterialShaderParamXxx() functions take `sMaterial=""` to mean all materials. |
4242
| `NWNX_TWEAKS_SUMMON_ASSOCIATE_USE_COMPUTE_SAFE_LOCATION` | true or false | CNWSCreature::SummonAssociate() will use ComputeSafeLocation() instead of ComputeNonVisibleLocation() |
4343
| `NWNX_TWEAKS_HIDE_HARDCODED_ITEM_VFX` | int | See [here](https://github.com/nwnxee/unified/tree/master/Plugins/Tweaks#nwnx_tweaks_hide_hardcoded_item_vfx). |
44-
| `NWNX_TWEAKS_FIX_RESMAN_MEMLEAK` | true or false | Fix a memory leak in Resman / CResGFF |
44+
| `NWNX_TWEAKS_FIX_RESMAN_MEMLEAK` | true or false | Fixes a memory leak in Resman / CResGFF |
45+
| `NWNX_TWEAKS_FIX_DM_FACTION_BUG` | true or false | Fixes a DM faction bug when using a non-DMClient BIC file. |
4546

4647
## Environment variable values
4748

0 commit comments

Comments
 (0)