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 
 
RetrieveResEntry/DemandRes?

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



Joined: 23 Aug 2006
Posts: 37

PostPosted: Fri Sep 08, 2006 17:41    Post subject: RetrieveResEntry/DemandRes? Reply with quote

I'm trying to create a way to pull resources externally from the nwnserver's resource mananger. Currently I have my own application which runs along side the nwnserver, emulating the resource manager as defined by the bioware docs, but that requires significant additional memory.

I thought that I would be able to use RetrieveResEntry and DemandRes, using a mutex so the server and the external client do not both access at the same time, but I don't quite understand their behavior. The server will call RetrieveResEntry for every resource, but it only seems to call DemandRes on those that RetrieveResEntry returns '1' (and fills some output arguments). The arguments to DemandRes don't appear to contain the necessary information to identify the resource demanded.

Does anyone know how to craft calls to these functions in order to obtain any arbitrary resource? I'm starting to think I should be looking for another function.
Back to top
View user's profile Send private message
Papillon
x-man


Joined: 28 Dec 2004
Posts: 1060
Location: Germany

PostPosted: Wed Sep 13, 2006 9:02    Post subject: Reply with quote

It's been a while since I looked at those functions. IIRC, a resource either has already been loaded and is known to the resource manager, or has never been in use and yet needs to be loaded from disk.

Hmm... the retrieve function probably searches for instances of the resref and returns the result of this search. If it's not already there, DemandRes is called.

Maybe someone with more recent experience with these functions could comment in greater detail. My recollection on this is very vague...
_________________
Papillon
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
chaoslink



Joined: 23 Aug 2006
Posts: 37

PostPosted: Fri Dec 22, 2006 1:25    Post subject: Reply with quote

bump - anyone with this information about?
Back to top
View user's profile Send private message
chaoslink



Joined: 23 Aug 2006
Posts: 37

PostPosted: Fri Dec 29, 2006 20:36    Post subject: Reply with quote

I've finally had a chance to look at this further, and I better understand the arguments to the function calls. There are still a couple of fields in the resource struct which elude me, but I'm making some progress.
Back to top
View user's profile Send private message
chaoslink



Joined: 23 Aug 2006
Posts: 37

PostPosted: Sat Dec 30, 2006 1:02    Post subject: Reply with quote

Sweet. This is going much better now.

I'm able to snag a resource from a separate thread spawned in the plug-in. Looks like I need to map resource types to "classes", which are function pointers to code executed when a resource is demanded. Just testing with a 2da file and hard-coding the "class" to the value used for 2das works!
Back to top
View user's profile Send private message
chaoslink



Joined: 23 Aug 2006
Posts: 37

PostPosted: Sat Dec 30, 2006 1:08    Post subject: Reply with quote

so far I've gathered the following "classes"...
.2da: 0x832d3c0
.are: 0x832a580
.fac: 0x832d1e0
.git: 0x832d1e0
.ifo: 0x832acc0
.ncs: 0x832b7c0
.pwk: 0x832b740
.set: 0x8329ec0
.wok: 0x8329ee0
.dwk: 0x832b720
.uti: 0x832d1e0
.utp: 0x832d1e0

interesing that the .fac, .git, .uti and .utp are the same... that would lead me to believe that the same handler is used for all GFFs, but then .are throws me a curve ball Smile
Back to top
View user's profile Send private message
chaoslink



Joined: 23 Aug 2006
Posts: 37

PostPosted: Sat Dec 30, 2006 6:24    Post subject: Reply with quote

hmm.. I should have paid closer attention to the reply I was getting... looks like I still need to dig some more on what the other resource struct fields are
Back to top
View user's profile Send private message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Tue Mar 20, 2007 13:20    Post subject: Reply with quote

CResGFF class:
1.67 (Linux) - 0x0832B7E0
1.68 (Linux) - 0x0832D1E0
This class is the base class for all CRes* classes.

LoadGFFResource function:
1.67 (Linux) - 0x082B25E8
1.68 (Linux) - 0x082B33D8
arguments:
- pThis: pointer to 0xAC allocated bytes for CResGFF class
- Unknown argument: example - 0x7EB (for Creature)
- ResType: first 4 bytes of the resource ("UTC " for Creature)
- ResName: resref
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
chaoslink



Joined: 23 Aug 2006
Posts: 37

PostPosted: Tue Mar 20, 2007 17:54    Post subject: Reply with quote

Woah. Thanks. I had to put the project aside since my cat peed in my computer, but this should help quite a bit.
Back to top
View user's profile Send private message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Thu Mar 29, 2007 7:43    Post subject: Reply with quote

The second parameter is ResType from this list:
Code:
enum erf_resource_type {
    ERF_RESOURCE_TYPE_BMP = 0x0001,
    ERF_RESOURCE_TYPE_TGA = 0x0003,
    ERF_RESOURCE_TYPE_WAV = 0x0004,
    ERF_RESOURCE_TYPE_PLT = 0x0006,
    ERF_RESOURCE_TYPE_INI = 0x0007,
    ERF_RESOURCE_TYPE_BMU = 0x0008,
    ERF_RESOURCE_TYPE_TXT = 0x000a,
    ERF_RESOURCE_TYPE_MDL = 0x07d2,
    ERF_RESOURCE_TYPE_NSS = 0x07d9,
    ERF_RESOURCE_TYPE_NCS = 0x07da,
    ERF_RESOURCE_TYPE_MOD = 0x07db,
    ERF_RESOURCE_TYPE_ARE = 0x07dc,
    ERF_RESOURCE_TYPE_SET = 0x07dd,
    ERF_RESOURCE_TYPE_IFO = 0x07de,
    ERF_RESOURCE_TYPE_BIC = 0x07df,
    ERF_RESOURCE_TYPE_WOK = 0x07e0,
    ERF_RESOURCE_TYPE_2DA = 0x07e1,
    ERF_RESOURCE_TYPE_TXI = 0x07e6,
    ERF_RESOURCE_TYPE_GIT = 0x07e7,
    ERF_RESOURCE_TYPE_UTI = 0x07e9,
    ERF_RESOURCE_TYPE_UTC = 0x07eb,
    ERF_RESOURCE_TYPE_DLG = 0x07ed,
    ERF_RESOURCE_TYPE_ITP = 0x07ee,
    ERF_RESOURCE_TYPE_UTT = 0x07f0,
    ERF_RESOURCE_TYPE_DDS = 0x07f1,
    ERF_RESOURCE_TYPE_UTS = 0x07f3,
    ERF_RESOURCE_TYPE_LTR = 0x07f4,
    ERF_RESOURCE_TYPE_GFF = 0x07f5,
    ERF_RESOURCE_TYPE_FAC = 0x07f6,
    ERF_RESOURCE_TYPE_UTE = 0x07f8,
    ERF_RESOURCE_TYPE_UTD = 0x07fa,
    ERF_RESOURCE_TYPE_UTP = 0x07fc,
    ERF_RESOURCE_TYPE_DFT = 0x07fd,
    ERF_RESOURCE_TYPE_GIC = 0x07fe,
    ERF_RESOURCE_TYPE_GUI = 0x07ff,
    ERF_RESOURCE_TYPE_UTM = 0x0803,
    ERF_RESOURCE_TYPE_DWK = 0x0804,
    ERF_RESOURCE_TYPE_PWK = 0x0805,
    ERF_RESOURCE_TYPE_JRL = 0x0808,
    ERF_RESOURCE_TYPE_SAV = 0x0809,
    ERF_RESOURCE_TYPE_UTW = 0x080a,
    ERF_RESOURCE_TYPE_SSF = 0x080c,
    ERF_RESOURCE_TYPE_HAK = 0x080d,
    ERF_RESOURCE_TYPE_NWM = 0x080e,
    ERF_RESOURCE_TYPE_PTM = 0x0811,
    ERF_RESOURCE_TYPE_PTT = 0x0812,
    ERF_RESOURCE_TYPE_ERF = 0x270d,
    ERF_RESOURCE_TYPE_BIF = 0x270e,
    ERF_RESOURCE_TYPE_KEY = 0x270f,
    ERF_RESOURCE_TYPE_UNKNOWN = 0xffff,
};
From ERF Utility (c) roboius
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
chaoslink



Joined: 23 Aug 2006
Posts: 37

PostPosted: Thu May 31, 2007 0:15    Post subject: Reply with quote

Nice.

cat pee shorted mobo replaced, lost three of my 4 ram dims, but I'm limping along and I'll be looking at this again soon
Back to top
View user's profile Send private message
chaoslink



Joined: 23 Aug 2006
Posts: 37

PostPosted: Fri Feb 22, 2008 8:58    Post subject: Reply with quote

I've pretty much given up on using Detours to create an cross-platform nwnx . Ironically enough it works fine under linux, but I keep getting access violations under windows (looks like I'm stomping on ebp for some reason, maybe I need to hook a different location for SetString than what is used with MadCodeHook?).

Anyway, I'm working on retrieving resources under linux. LoadGFFResource looks great, I hooked it and I can see it being called. Of course, like the name suggests, this is only for GFF resources. I'd like to be able to get any.

I'm going to try to look up in the stack to see what is calling this and go from there.
Back to top
View user's profile Send private message
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Sat Feb 23, 2008 0:17    Post subject: Reply with quote

A More Complete DLL Injection Solution Using CreateRemoteThread

Have a look at the above link.
(I know it works with windows, you may be able to adapt it for Linux)

No MadChook, no Detours (although it works similarly)

Drew Benton (the author) has a series on 'CodeCaves' (code hooking) on the same site.

Cheers
Gryphyn
Back to top
View user's profile Send private message
nova82



Joined: 27 Jun 2006
Posts: 3

PostPosted: Fri Mar 28, 2008 20:10    Post subject: Reply with quote

are you certain the access violation is bad enough that you can not ignore it using SEH and try/except to catch & ignore the hardware exception ?

Or perhaps you are getting the same access violation I was getting. (i run winXP)
Unhandled exception at 0x079b2b93 (nwnx_resman.dll) in nwserver.exe: 0xC0000005: Access violation reading location 0x00000014.

If so, here is the fix:

Code:

NWNXResMan.cpp
........
   if (!cRes)
   {
      static int nMaxFails = 0;
      nMaxFails++;
      
      fprintf(m_fFile, ">> nMaxFails has incremented to %i. Max limit is currently set at 12. \n", nMaxFails );
      assert(nMaxFails <= 12);//If hit, then bad stuff might be happening, but if not just up the limit.

      // nothing for us to do
      return NULL;
   }
   if (cRes->pResName)
   {
      if (m_LogLevel == logAll)
.............


cRes was null for me exactly 2 times, probably because of some invisible door in one of the area files in our mod or similar.
So this code addition basically makes ResMan more resilient to this specific problem. If cRes is null for you much much more, then find out if the same problem happens with another mod.

nova
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 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