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 
 
FindObjectByTagOrdinal

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Windows development
View previous topic :: View next topic  
Author Message
MaxRock



Joined: 24 Jan 2008
Posts: 196

PostPosted: Thu Apr 07, 2011 18:57    Post subject: FindObjectByTagOrdinal Reply with quote

Can anybody figure out how the FindObjectByTagOrdinal function works?

I know it's the "internal" version of GetObjectByTag and it loops through the object LookupTable array but the way it does it gives me a headache.

My issue is with SetTag from nwnx_funcs. I'm able to change the tag in the lookuptable and the item, but afterwards GetObjectByTag cannot find it anymore. Yet when I override FindObjectByTagOrdinal with my own loop it finds the tab and object just fine.

Since I don't know all the members of CLookupTableObject, I suppose the secret is somewhere in those unknown members.
Here's what I have:
Code:

struct CLookupTableObject_s {
   char Tag[32];
   char fill[4]; //FF FF FF FF
   uint32_t unknown_1;
   uint32_t unknown_2;
   uint32_t tag_len1; //includes the terminator
   uint32_t unknown_4;
   uint32_t tag_len2; //not sure why there is a second length
   uint32_t unknown_6;
   uint32_t unknown_7;
   CGenericObject *pObject;
   uint32_t obj_oid;
};


Some insight would be greatly appreaciated
Back to top
View user's profile Send private message Send e-mail MSN Messenger
motu99



Joined: 24 Sep 2007
Posts: 16

PostPosted: Thu Apr 07, 2011 21:22    Post subject: Re: FindObjectByTagOrdinal Reply with quote

IMO CLookupTableObject is much simpler than what you posted:

Code:

struct CLookupTableObject_s {
   char        sTag[64];
    uint32_t   NotKnownToMe; (could be: CGenericObject *pObject;)
   nwn_objid_t  oID;
};


By looking at the disassembly in IDA, I am quite sure that
Code:

FindObjectByTagOrdinal(CExoString& TagToSearchFor, unsigned long nthOccurenceOfTag)


i) first does a

Code:

StringLeft(TagToSearchFor, 64)


on the supplied tag

ii) then does (I believe) a binary search within the the sorted Array of CLookupTableObject entries, returning the address of the first CLookupTableObject entry that matches TagToSearchFor

iii) then adds nthOccurenceOfTag (times 72) to the address, checks if the respective entry is within the array-bounds and that the selected entry still refers to the correct tag

iv) if all conditions in iii) are met it returns oID of the selected entry, otherwise 0x7F000000.
Back to top
View user's profile Send private message
MaxRock



Joined: 24 Jan 2008
Posts: 196

PostPosted: Thu Apr 07, 2011 22:13    Post subject: Reply with quote

Ah, thank you! I didn't take into account the array is sorted. Embarassed

Of course I can probably get around the whole issue by simply calling RemoveObjectFromLookupTable and AddObjectToLookupTable with the new tag.
Back to top
View user's profile Send private message Send e-mail MSN Messenger
MaxRock



Joined: 24 Jan 2008
Posts: 196

PostPosted: Thu Apr 07, 2011 22:27    Post subject: Reply with quote

Yup, that did it. And my instance dungeons' area transitions are working Very Happy
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Windows development All times are GMT + 2 Hours
Page 1 of 1

 
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