logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Visibility Hook
Goto page 1, 2  Next
 
Post new topic   Reply to topic    nwnx.org Forum Index -> Windows technical support
View previous topic :: View next topic  
Author Message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Sun Apr 27, 2014 20:46    Post subject: Visibility Hook Reply with quote

Hi Virusman,
I was wondering if you might be able to shed some light on the TestVisibility hook from github?

I noticed this code in the windows version, and for some reason, only the Override section is working - (this code matches the linux one too)

Eg: I can set an object to be visible with everything, or nothing.
Not against specific objects though.

This line however,
Log(2, "Found object-object entry!");
nResult = objects[oObject1].vismap[oObject2];
return 1;

Should this not be return nResult?
It occurs to me that nResult is never used, if you just return 1 regardless of what came out of the hashmap.

Any assistance would be appreciated.
In the mean time, I am trying return nResult, to see if it makes it work on windows.

Code:

//Returns 1 if override is active
//nResult contains the return value: 1 if visible, 0 if no
int CNWNXVisibility::TestVisibility(dword oObject1, dword oObject2, int &nResult)
{
   if(objects.find(oObject1) != objects.end()){
      Log(2, "Found object entry!");
      if(objects[oObject1].vismap.find(oObject2) != objects[oObject1].vismap.end()){
         Log(2, "Found object-object entry!");
         nResult = objects[oObject1].vismap[oObject2];
         return 1;
      }
      else {
         switch(objects[oObject1].eOverrideType){
            case AlwaysVisible:
               nResult = 1;
               return 1;
               break;

            case AlwaysInvisible:
               nResult = 0;
               return 1;
               break;

            case Default:
            default:
               return 0;
         }
      }
   }
   return 0;
}
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Sun Apr 27, 2014 21:01    Post subject: Reply with quote

correction, I now see that nResult is being passed in byRef - i think?
Back to top
View user's profile Send private message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Sun Apr 27, 2014 23:43    Post subject: Reply with quote

Yes, the return value is 1 when we handle the visibility, ignoring the built-in check (0 means that we return the control back to the original visibility check). If the return value is 1, nResult contains 0 for invisible or 1 for visible object. Since nResult is passed by reference, it acts as a second return value.
_________________
In Soviet Russia, NWN plays you!
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Mon Apr 28, 2014 2:03    Post subject: Reply with quote

Not entirely sure what the issue is then.

The code appears to be the same in linux and windows, but the windows version from maxrocks branch in the svn doesnt seem to give visibility per object.


I remember trying the linux branch when I was experimenting with moving to linux, and it worked on per pc basis, but the same code in windows is misbehaving...

Sad
Back to top
View user's profile Send private message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Wed Apr 30, 2014 0:02    Post subject: Reply with quote

Yes, the code looks the same.. Try adding more logging to see what really happens there.
_________________
In Soviet Russia, NWN plays you!
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Wed Apr 30, 2014 14:30    Post subject: Reply with quote

When I added logging into the SetVisibility method, I could see that it was indeed firing the set visibility method, however I think I may have had the wrong % parameters for adding string arguments to the _log method.

When I did

"object1 = %x" it did indeed post what looked like an ObjectToString offset,
however, object2 = %x seemed to come back as just a single digit? like "d" or something


Odd

The logging from the hook, kept returning 0.
Suggesting that the objects aren't being added to the visibility map correctly?

Am I correct that unsigned int's such as offsets should be added to strings using the %x string type argument?

I tried to add the int value for the value for the visibility mode, but it ended up coming up as something like 3 million etc.
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Wed Apr 30, 2014 19:38    Post subject: Reply with quote

Quote:

[04/30/2014 18:31:04] - StrReq: "SET_VISIBILITY" Params: "12d51 2"
[04/30/2014 18:31:04] o Set Visible = End 7ffffffd object 1, and c object 2, 4294967295 nValue
[04/30/2014 18:31:04] o Set Visible 7ffffffd object 1, and c object 2, -1 nValue
[04/30/2014 18:31:04] - StrReq: "SET_VISIBILITY" Params: "12d52 2"
[04/30/2014 18:31:04] o Set Visible 7ffffffd object 1, and c object 2, -1 nValue





These statements were wrote to the logs with this c++ code
Code:

void CVisibility::SetVisibility(nwn_objid_t oObject1, nwn_objid_t oObject2, unsigned int nValue)
{
   if(objects.find(oObject1) == objects.end()){
      _log(3, "o Set Visible = End %x object 1, and %x object 2, %u nValue\n",oObject1,oObject2, nValue );
      objects[oObject1];
      objects[oObject1].eOverrideType = Default;
   }
   objects[oObject1].vismap[oObject2] = nValue;
   _log(3, "o Set Visible  %x object 1, and %x object 2, %d nValue\n",oObject1,oObject2, objects[oObject1].vismap[oObject2] );
}


via this nss script

Code:

void VisibleToFaeOnly(object oDoor)
{
    object oPC = GetFirstPC();
    //NWNXFuncs_SetVisibilityOverride(oDoor,VISIBILITY_TYPE_INVISIBLE);
    while(oPC != OBJECT_INVALID)
    {
        int iID = GetPlayerSubraceID(oPC);

        if(iID == 47)
        {
            NWNXFuncs_SetVisibility(oPC,oDoor, VISIBILITY_TYPE_INVISIBLE);
        }else
        {
           NWNXFuncs_SetVisibility(oPC,oDoor, VISIBILITY_TYPE_INVISIBLE);
        }
        oPC = GetNextPC();
    }
}


Yes - I realise that both statements set it to invisible, but I just did that for testing.
End result is that it remains visible (the placeable)


I also see that the object args are the wrong way round above - I did that to test both combinations, with the arguments swapped, I get

Quote:

[04/30/2014 18:35:42] - StrReq: "SET_VISIBILITY" Params: "7ffffffd 2"
[04/30/2014 18:35:42] o Set Visible = End 12d65 object 1, and 7 object 2, 4294967295 nValue
[04/30/2014 18:35:42] o Set Visible 12d65 object 1, and 7 object 2, -1 nValue
[04/30/2014 18:35:42] - StrReq: "SET_VISIBILITY" Params: "7ffffffd 2"
[04/30/2014 18:35:42] o Set Visible = End 12d66 object 1, and 7 object 2, 4294967295 nValue
[04/30/2014 18:35:42] o Set Visible 12d66 object 1, and 7 object 2, -1 nValue



This line
_log(3, "Visibility check: %x - %x: %d\n", pObject1->obj_id, pObject2->obj_id, nResult);
doesnt seem to be firing, suggesting that 0 is being returned from the test visibility function

Code:

int CVisibility::TestVisibility(nwn_objid_t oObject1, nwn_objid_t oObject2, int &nResult)
{
   CNWSObject *Obj1 = (CNWSObject*)(*NWN_AppManager)->app_server->GetGameObject(oObject1);
   CNWSObject *Obj2 = (CNWSObject*)(*NWN_AppManager)->app_server->GetGameObject(oObject2);
   if (Obj1 && Obj2) {
      if (Obj2->obj_type2 == OBJECT_TYPE2_CREATURE && ((CNWSCreature*)Obj2)->cre_stats->cs_is_dm) {
         nResult = 1;
         return 1;
      }

      int LocalVarOverride = Obj1->obj_vartable.GetInt(CExoString("NWNXFUNCS_VIS"));
      if (LocalVarOverride) {
         if (LocalVarOverride == Obj2->obj_vartable.GetInt(CExoString("NWNXFUNCS_VIS"))) {
            nResult = 1;
            return 1;
         }
      }

      if(objects.find(oObject1) != objects.end()){
         //__log(2, "Found object entry!");
         if(objects[oObject1].vismap.find(oObject2) != objects[oObject1].vismap.end()){
            //__log(2, "Found object-object entry!");
            nResult = objects[oObject1].vismap[oObject2];
            return 1;
         }
         else {
            switch(objects[oObject1].eOverrideType){
               case AlwaysVisible:
                  nResult = 1;
                  return 1;
                  break;
                  
               case AlwaysInvisible:
                  nResult = 0;
                  return 1;
                  break;

               case Default:
               default:
                  return 0;
            }
         }
      }
   }
   return 0;
}


Must be something wrong with the vismap?
Any ideas?

Im just wondering - could it be an incompatibility with the ExtractP2 method that Maxrock uses to extract arguments?
Its weird that argument 2 for object 2 comes out a different format than object 1?

Code:

int CVisibility::NssSetVisibility(CGameObject *oObject, char *Params) {
   nwn_objid_t oObject2 = OBJECT_INVALID;
   int nValue = -1;

   CParams::ExtractP2(Params, oObject2, nValue);

   SetVisibility(oObject->obj_id, oObject2, nValue);
   return 1;
}


and

Code:

static void ExtractP2(const char *Params, T &P1, N &P2, char delim = ' ') {
      stringstream ss;
      string s(Params);
      s += delim;
      int start=0, ip=0;
      ip = s.find(delim);
      ss << s.substr(start, ip-start);
      if (!HandleCHAR(ss, P1)) {
         ss >> P1;
      }
      ss.clear();

      start = ip+1; ip = s.find(delim, start);
      ss << s.substr(start, ip-start);
      if (!HandleCHAR(ss, P2)) {
         ss >> P2;
      }
   }
Back to top
View user's profile Send private message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Mon May 05, 2014 15:09    Post subject: Reply with quote

Yeah, looks like the params parser isn't working right here - it returns -1 as invisibility type (second param) instead of 2.
Try specifying the types explicitly: CParams::ExtractP2<nwn_objid_t, unsigned int>(...); Not sure if it'll work, but it's worth a try.
It looks like HandleCHAR is using typeid (RTTI), which afaik is not very reliable, especially with built-in C types.
_________________
In Soviet Russia, NWN plays you!
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Mon May 05, 2014 21:31    Post subject: Reply with quote

Code:

int CVisibility::NssSetVisibility(CGameObject *oObject, char *Params) {
   nwn_objid_t oObject2 = OBJECT_INVALID;
   unsigned int nValue = -1;

   CParams::ExtractP2<nwn_objid_t, unsigned int>(Params, oObject2, nValue);
   _log(3, "o Set Visible Params  %x object 2, and %d nValue\n",oObject2,nValue );
   SetVisibility(oObject->obj_id, oObject2, nValue);
   return 1;
}


Still getting -1, and the object2 is coming back as 7

Quote:

[05/05/2014 19:53:09] - StrReq: "SET_VISIBILITY" Params: "7ffffffc 2"
[05/05/2014 19:53:09] o Set Visible Params 7 object 2, and -1 nValue


I havent got a clue how that ExtractP2 Method works, so don't know how to fix.

:-\
Back to top
View user's profile Send private message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Mon May 05, 2014 22:00    Post subject: Reply with quote

You can always use good old sscanf: https://github.com/NWNX/nwnx2-linux/blob/master/plugins/visibility/NWNXVisibility.cpp#L121
_________________
In Soviet Russia, NWN plays you!
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Mon May 05, 2014 22:04    Post subject: Reply with quote

I have used sscanf before, but does it allow you to parse 2 parameters from the same char array?
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Mon May 05, 2014 22:06    Post subject: Reply with quote

Ah..
Ok I will try that
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Mon May 05, 2014 22:16    Post subject: Reply with quote

Making progress

Code:

int CVisibility::NssSetVisibility(CGameObject *oObject, char *Params) {
   nwn_objid_t oObject2 = OBJECT_INVALID;
   int nValue = -1;
   sscanf(Params, "%lx¬%d", &oObject2, &nValue);
   //CParams::ExtractP2<nwn_objid_t, int>(Params, oObject2, nValue);
   _log(3, "o Set Visible Params  %x object 2, and %d nValue\n",oObject2,nValue );
   SetVisibility(oObject->obj_id, oObject2, nValue);
   return 1;
}


This does give me a valid object id now,
however the value is still coming back as -1.

Does the ¬ need to be changed to be the delimiter used?
currently it is a space.
Or does the nValue need to be unset beforehand?


---
Edit
Added in the sscanf with a space a the delimiter - seems to be working.
Thanks Virusman
Back to top
View user's profile Send private message
Valgav



Joined: 28 Aug 2010
Posts: 53

PostPosted: Thu Feb 19, 2015 15:40    Post subject: Reply with quote

I'm looking for working version compiled or sources of nwnx_funcs. The only version I found is not compatible with nwnx 2.70beta4 and crashes server.

The version I found is this one: https://github.com/addicted2rpg/NWNX2-windows
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Thu Feb 19, 2015 15:52    Post subject: Reply with quote

I can give you my compiled version, but I cannot say for sure if I have the sources to go with it - as the visibility issue I had was solved last year and I havent needed to recompile for a while.

http://asmodei.net/Downloads/nwnx_funcs.rar

This one has the functional visibility hook
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Windows technical support All times are GMT + 2 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group