forked from nwnxee/unified
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #199 from nwnxee/master
Merge upstream
- Loading branch information
Showing
10 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
add_plugin(Experimental | ||
"Experimental.cpp" | ||
"Experimentals/SuppressPlayerLoginInfo.cpp" | ||
"Experimentals/AdjustReputationFix.cpp" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
Plugins/Experimental/Experimentals/AdjustReputationFix.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include "Experimentals/AdjustReputationFix.hpp" | ||
|
||
#include "Services/Hooks/Hooks.hpp" | ||
|
||
#include "API/CAppManager.hpp" | ||
#include "API/CFactionManager.hpp" | ||
#include "API/CNWSCreature.hpp" | ||
#include "API/CNWSCreatureStats.hpp" | ||
#include "API/CServerExoApp.hpp" | ||
#include "API/CServerExoAppInternal.hpp" | ||
#include "API/Functions.hpp" | ||
#include "API/Globals.hpp" | ||
|
||
namespace Experimental { | ||
|
||
using namespace NWNXLib; | ||
using namespace NWNXLib::API; | ||
|
||
AdjustReputationFix::AdjustReputationFix(Services::HooksProxy* hooker) | ||
{ | ||
hooker->RequestExclusiveHook<API::Functions::_ZN12CNWSCreature16AdjustReputationEii, void>(&CNWSCreature__AdjustReputation_Hook); | ||
} | ||
|
||
void AdjustReputationFix::CNWSCreature__AdjustReputation_Hook(CNWSCreature *pThis, int32_t nFactionId, int32_t nAdjustment) | ||
{ | ||
auto* pFactionManager = Globals::AppManager()->m_pServerExoApp->m_pcExoAppInternal->m_pFactionManager; | ||
|
||
if (!pFactionManager->GetIsNPCFaction(nFactionId)) | ||
return; | ||
|
||
if (pThis->m_bPlayerCharacter || pThis->GetIsPossessedFamiliar()) | ||
{ | ||
if (pThis->m_pReputation) | ||
{ | ||
int32_t index = nFactionId - 1; | ||
if (index >= 0 && index < pThis->m_pReputation->num) | ||
{ | ||
pThis->m_pReputation->element[index] += nAdjustment; | ||
pThis->m_pReputation->element[index] = std::clamp(pThis->m_pReputation->element[index], 0, 100); | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
if (pThis->m_pStats->m_nFactionId != nFactionId) | ||
{ | ||
int32_t rep = pFactionManager->GetNPCFactionReputation(pThis->m_pStats->m_nFactionId, nFactionId); | ||
pFactionManager->SetNPCFactionReputation(pThis->m_pStats->m_nFactionId, nFactionId, (rep + nAdjustment)); | ||
} | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
Plugins/Experimental/Experimentals/AdjustReputationFix.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
|
||
#include "Common.hpp" | ||
|
||
namespace Experimental { | ||
|
||
class AdjustReputationFix | ||
{ | ||
public: | ||
AdjustReputationFix(NWNXLib::Services::HooksProxy* hooker); | ||
|
||
private: | ||
static void CNWSCreature__AdjustReputation_Hook(CNWSCreature*, int32_t, int32_t); | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters