Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reveal: Fix Reveal plugin always revealing PCs when the plugin is enabled, regardless of usage. #1695

Merged
merged 3 commits into from
Aug 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ https://github.com/nwnxee/unified/compare/build8193.35.40...HEAD

### Fixed
- Experimental: PlayerHitpointsAsPercentage: added the new argument nMessageLimit to SendServerToPlayerGameObjUpdate hook
- Reveal: Fixed Reveal plugin always revealing all PCs regardless of plugin usage.

## 8193.35.40
https://github.com/nwnxee/unified/compare/build8193.35.37...build8193.35.40
Expand Down
32 changes: 20 additions & 12 deletions Plugins/Reveal/Reveal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,37 +46,45 @@ Reveal::Reveal(Services::ProxyServiceList* services)
Reveal::~Reveal()
{
}
int32_t Reveal::HookStealthDetection(CNWSCreature* pObserverCreature, CNWSCreature* pHidingCreature, int32_t bClearLOS, int32_t* bSeen, int32_t* bHeard, int32_t bTargetInvisible)
BOOL Reveal::HookStealthDetection(CNWSCreature* pObserverCreature, CNWSCreature* pHidingCreature, BOOL bClearLOS, BOOL* bSeen, BOOL* bHeard, BOOL bTargetHiding)
{
if (pObserverCreature->m_bPlayerCharacter && pHidingCreature->m_bPlayerCharacter && pHidingCreature->m_nStealthMode)
{
if (pObserverCreature->GetArea() == pHidingCreature->GetArea())
{
if (*pHidingCreature->nwnxGet<int>(revealKey + "PARTY"))
auto partyReveal = pHidingCreature->nwnxGet<int>(revealKey + "PARTY");
if (partyReveal && *partyReveal)
{
if (pObserverCreature->GetFaction()->GetLeader() == pHidingCreature->GetFaction()->GetLeader())
{
if(*pHidingCreature->nwnxGet<int>(detectionKey + "PARTY"))
{
*bSeen = true;
}
auto detectionVector = pHidingCreature->nwnxGet<int>(detectionKey + "PARTY");
if (detectionVector && *detectionVector)
*bSeen = *detectionVector;
Comment on lines +61 to +62
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs a

else
    *bSeen = false;

the variables that bSeen/bHeard are pointing to aren't initialized, so they should always be set to something

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah; done

else
*bSeen = false;

*bHeard = true;
return true;
}
}
if (*pHidingCreature->nwnxGet<int>(revealKey + Utils::ObjectIDToString(pObserverCreature->m_idSelf)))

auto reveal = pHidingCreature->nwnxGet<int>(revealKey + Utils::ObjectIDToString(pObserverCreature->m_idSelf));
if (reveal && *reveal)
{
pHidingCreature->nwnxRemove(revealKey + Utils::ObjectIDToString(pObserverCreature->m_idSelf)); //remove mapping after first check
if (*pHidingCreature->nwnxGet<int>(detectionKey + Utils::ObjectIDToString(pObserverCreature->m_idSelf)))
{
*bSeen = true;
}

auto detectionVector = pHidingCreature->nwnxGet<int>(detectionKey + Utils::ObjectIDToString(pObserverCreature->m_idSelf));
if (detectionVector && *detectionVector)
*bSeen = *detectionVector;
else
*bSeen = false;

*bHeard = true;
return true;
}
}
}
return g_plugin->m_DoStealthDetection->CallOriginal<int32_t>(pObserverCreature, pHidingCreature, bClearLOS, bSeen, bHeard, bTargetInvisible);
return g_plugin->m_DoStealthDetection->CallOriginal<BOOL>(pObserverCreature, pHidingCreature, bClearLOS, bSeen, bHeard, bTargetHiding);
}


Expand Down
2 changes: 1 addition & 1 deletion Plugins/Reveal/Reveal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Reveal : public NWNXLib::Plugin
private:
NWNXLib::Hooks::Hook m_DoStealthDetection;

static int32_t HookStealthDetection(CNWSCreature* thisCreature, CNWSCreature* pHidingCreature, int32_t bClearLOS, int32_t* bSeen, int32_t* bHeard, int32_t bTargetInvisible);
static BOOL HookStealthDetection(CNWSCreature* thisCreature, CNWSCreature* pHidingCreature, BOOL bClearLOS, BOOL* bSeen, BOOL* bHeard, BOOL bTargetHiding);

ArgumentStack RevealTo(ArgumentStack&& args);
ArgumentStack SetRevealToParty(ArgumentStack&& args);
Expand Down