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 
 
NWNX Events
Goto page 1, 2  Next
 
Post new topic   Reply to topic    nwnx.org Forum Index -> Windows development
View previous topic :: View next topic  
Author Message
Terra_777



Joined: 27 Jun 2008
Posts: 216
Location: Sweden

PostPosted: Fri Oct 09, 2009 2:46    Post subject: NWNX Events Reply with quote

First off, I actually managed to fix nwnx_events.dll which can be found here: http://nwvault.ign.com/View.php?view=Other.Detail&id=1429

I'm trying to learn how to find and hook events since the actual fault in the event mod was the object hook which I got rid off and getting target with matching object ID instead.

How do I hook events such as stealth mode, functions and such? I know how to read/write memory but not the hooking part.
_________________
I dun have any signature, I'm happy anyway.
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Zebranky



Joined: 04 Jun 2006
Posts: 415

PostPosted: Fri Oct 09, 2009 4:19    Post subject: Reply with quote

I really need to finish my "Anatomy of a NWNX Hook" blog post. Smile

Short version: find a function that looks interesting, then hook it.

Finding the function is done with the help of tools such as IDA Pro and Ollydbg (or Windbg or insert-your-choice-of-debugger-here). There are some tips and tricks, but much of the time it comes down to low-level digging, much like memory editing.

Most of my hooks are ugly patches to the code rather than full function hooks, but there are examples of both all over the plugins. nwnx_events (the version in SVN; haven't looked at yours yet) uses madCHook (note the calls to HookCode()). One of the most elegant examples of madCHook is in nwnx_fixes, with GetIsMergeableHookProc(). nwnx_chat is another good place to look.

Most/all of the Linux hooks are *way* more elegant, but I haven't found the time to port all of acaos's work to Win32. Those are nice to look at to get an idea of what can be done, though.
_________________
Win32 SVN builds: http://www.mercuric.net/nwn/nwnx/

<Fluffy-Kooshy> NWNx plugin is to this as nuclear warheads are to getting rid of fire ants.

<ThriWork> whenever I hear nwn extender, I think what does NWN need a penis extender for?
Back to top
View user's profile Send private message Visit poster's website
Sag



Joined: 24 Sep 2009
Posts: 8

PostPosted: Thu Sep 23, 2010 23:18    Post subject: Reply with quote

This is awesome!

Could you also add a hook for Animal Empathy as well as Open Lock?
Back to top
View user's profile Send private message
Zebranky



Joined: 04 Jun 2006
Posts: 415

PostPosted: Fri Sep 24, 2010 6:55    Post subject: Reply with quote

Sag wrote:
Could you also add a hook for Animal Empathy as well as Open Lock?

Done -- well, sort of. I added the UseSkill event, but it doesn't fire when people unlock an object using the radial menu. It does, however, seem to work great for Animal Empathy.

I updated the builds in my sig. Grab it there, and you'll need to make sure you have a current nwnx-module.dll as well (2.7b4 or thereabouts -- 2.6 won't do). Besides that, it should work much like the Linux version.
_________________
Win32 SVN builds: http://www.mercuric.net/nwn/nwnx/

<Fluffy-Kooshy> NWNx plugin is to this as nuclear warheads are to getting rid of fire ants.

<ThriWork> whenever I hear nwn extender, I think what does NWN need a penis extender for?
Back to top
View user's profile Send private message Visit poster's website
Zebranky



Joined: 04 Jun 2006
Posts: 415

PostPosted: Fri Sep 24, 2010 7:04    Post subject: Reply with quote

Hmm, might have broken compatibility with Terra's previous build there. Just reread the first post in the thread -- old nwnx-module.dll causes exactly that issue (object hook not working). I commented out GETTARGETID, since its use should be discouraged with the object hook working. I'll leave it that way for now.
_________________
Win32 SVN builds: http://www.mercuric.net/nwn/nwnx/

<Fluffy-Kooshy> NWNx plugin is to this as nuclear warheads are to getting rid of fire ants.

<ThriWork> whenever I hear nwn extender, I think what does NWN need a penis extender for?
Back to top
View user's profile Send private message Visit poster's website
Sag



Joined: 24 Sep 2009
Posts: 8

PostPosted: Fri Sep 24, 2010 15:13    Post subject: Reply with quote

This works as you said.

I did some testing:

Animal Empathy:
Radial Menu: Returns event correctly
Quick Slot: Returns event correctly

Disable Trap:
Examine: Returns event correctly
Flag: Returns event correctly
Recover: Returns event correctly
Disable: Returns event correctly

Open Lock:
Radial Menu: Does not return event (as you mentioned above)
Quick Slot: Returns event correctly

Pick pocket runs for both events 2 and 7.

GetNWNXEventTarget( ) is returning nothing and the object type is 0 thus making neither valid or invalid according to nwscript. (as you mentioned above)

If I might make a suggestion;
-Add a way to check which skill is being used
-please add the event for the radial menu for open lock (if you are able)

I hope the above information is helpful. Your and everyone's work on nwnx is much appreciated.
Back to top
View user's profile Send private message
Zebranky



Joined: 04 Jun 2006
Posts: 415

PostPosted: Fri Sep 24, 2010 17:23    Post subject: Reply with quote

There is a way to check the skill: "NWNX!EVENTS!GET_EVENT_SUBID" (returns the skill ID as in skills.2da).

I'll restore GETTARGETID.

What's your use case for an unlock hook? Nothing comes to mind that can't be accomplished with locks, keys, plot flags, and scripts, but I could be missing something. If you can describe in more detail what you want to achieve, that'll help in attacking the unlock event.
_________________
Win32 SVN builds: http://www.mercuric.net/nwn/nwnx/

<Fluffy-Kooshy> NWNx plugin is to this as nuclear warheads are to getting rid of fire ants.

<ThriWork> whenever I hear nwn extender, I think what does NWN need a penis extender for?
Back to top
View user's profile Send private message Visit poster's website
Sag



Joined: 24 Sep 2009
Posts: 8

PostPosted: Fri Sep 24, 2010 21:47    Post subject: Reply with quote

For open lock I was hoping to:
1) Require that players have (server custom) lockpicks in order to open a door. (I don't like the way NWN uses thieve's tools).
2) Allow bonuses on those lockpicks w/o the need for equipping which I could retrieve via a script
3) Not show the results of a door's DC

Thanks Z.
Back to top
View user's profile Send private message
Sag



Joined: 24 Sep 2009
Posts: 8

PostPosted: Mon Oct 04, 2010 1:29    Post subject: Reply with quote

I'm able to do some of those things via scripting but the ability to hook open lock makes for a more professional experience.
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Sat Nov 06, 2010 14:53    Post subject: onHit Reply with quote

Has anyone managed to hook onHit with any effective method.

Eg - I originally wanted to make an onHit effect for my Players Skin's, but apparently Skin's dont fire the onHit event.

So now im looking into hooking on the impact event of an attack.

Has this been done, or is it likely to be too laggy.
Back to top
View user's profile Send private message
ShaDoOoW



Joined: 20 Aug 2005
Posts: 584

PostPosted: Sat Nov 06, 2010 23:54    Post subject: Re: onHit Reply with quote

Baaleos wrote:
Has anyone managed to hook onHit with any effective method.

Eg - I originally wanted to make an onHit effect for my Players Skin's, but apparently Skin's dont fire the onHit event.

So now im looking into hooking on the impact event of an attack.

Has this been done, or is it likely to be too laggy.
Im using onhit on armor. If player unequip armor, scrip will give him rags that looks like if he would wear nothing. If he then equip armor, rags is destroyed.

Not totally pretty solution but nice.
_________________
Community Patch / NWNX Patch / NWNX Files / NWNX Connect
Back to top
View user's profile Send private message
motu99



Joined: 24 Sep 2007
Posts: 16

PostPosted: Sun Nov 07, 2010 12:16    Post subject: NWNX Events Reply with quote

Any chance that the SpellCastAt-event can be hooked in the Windows version? [Not the scripted event initiated by SignalEvent(), but the "real hardwired" event that's already hooked in the Linux-version of nwnw_events: in the Linux version the SpellCastAt-event fires whenever a spell from the Bioware spellbook is *selected* (and placed in the action queue) or when ActionCastSpellAtObject() or ActionCastSpellAtLocation() places the spellcast-action into the action queue]

I am working on a system that will allow multiple metamagics and that will allow one to add a (principally unlimited) number of new metamagics. In order that such a system works smoothly and fairly intuitively with queued spells (more than one spell in the action queue) it would be convenient to hook into the SpellCastAt event at the time the spellcast action is *inserted* into the action queue. Of course there are other ways to implement such a system. If one could examine the action queue (and remove or add events at specific positions in the action queue), that might help as well.
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Mon Nov 08, 2010 16:14    Post subject: tried replying Reply with quote

Tried replying earlier over the weekend, but the website wouldnt let me log in.


In the end I made it so that when my players equipe armor, which has no 'On-Hit' power, it will add one for them, and then I made a modification to the default onHit cast spell script, so that it will detect if the armor being hit, is the one intended, and then it fires the desired function I need, to simulate skin bashing.


Also - Disaster - I accidentally got the latest nwnx_win32 svn folder, overwriting my own copy which I had gone through all that work of creating the nwnx events of.

Eg - the Events pvp toggle disable, pause disabling etc, as well as the new ExecuteScript method call method...... Have to see if I can rebuild any of it.
Back to top
View user's profile Send private message
ShaDoOoW



Joined: 20 Aug 2005
Posts: 584

PostPosted: Sat Feb 19, 2011 23:08    Post subject: Reply with quote

Would be anyone able to add a new functionality to Bypass event at least into download character? Possibly with still running the script, but it would be useable even without it. source is at svn Idea
_________________
Community Patch / NWNX Patch / NWNX Files / NWNX Connect
Back to top
View user's profile Send private message
motu99



Joined: 24 Sep 2007
Posts: 16

PostPosted: Sun Mar 13, 2011 16:55    Post subject: Reply with quote

I finally found the CNWSCreature::AddCastSpellActions() function in the win32 executable of nwserver.exe (at 0x00491610). Wasn't too difficult (that is, after I learned 0x86 assembly language and read some stuff about the more common function calling conventions).

In hindsight, I did it the quite hard way:
- started nwserver.exe with OllyDbg
- searched for a RETN 44
- fortunately there was only one RETN 44 in the whole of nwserver.exe
- poking through the logic of the assembly code confirmed that it was the right function

[Why RETN 44?
I knew the Linux version of the function had 18 arguments; the Windows functions mostly use the __thiscall calling convention, with the this-pointer passed in ecx, so the Windows-functions would have 17 arguments. 17*4 is 0x44, so the function would have to end with RETN 44]

Given the already working code of the Linux version of the events plugin, it shouldn't be too difficult to modify the windows version of the events plugin (or MaxRocks funcs plugin, which is awesome due to its scope) to hook into that function.

Why am I writing this?

In the last few weeks I have been poking through the code of the Win32 executable. In the beginning this was quite painful, because nwserver.exe doesn't come with any symbol tables. I switched from OllyDbg to IDA Pro Free 5.0, when I realized that I couldn't read in the structure layout of the common NWN-structs (CGameObject_s, etc.) into OllyDbg. This, at least, is relatively straight forward in IDA. Furthermore, MaxRock has ported the more important structs to Windows, so I mostly just had to copy and paste (the struct layout of the Windows and Linux versions is slightly different in some cases, so the linux-structs don't always work).

Roughly 2 weeks ago I took a look at the core2.8 branch of the nwnx2-linux SVN and was amazed to find a rather extensive API (see the /api and /include sub-directories), with code to jump to (almost) any function running within nwserver. How could that be? So I decided to take a look at the linux executable of nwserver with IDA. And, amazingly, the Linux version includes the full symbol information for all nwserver-functions and the more important data segments. Wow, had I just known that earlier...

So within the last week I have been working heavily to reconstruct some of the more important symbolic information in the win32 disassembly of nwserver.exe. My final goal is to successively build up an api - similar to the Linux core-2.8 api - for windows. It will take a while, but it might be helpful for others too.

In the process I updated a few unknown fields in the some of the nwn-structures (I have practically complete versions of the CNWRules_s, CNWBaseItem_s, CNWSpell_s, CNWFeat_s) and I am working on others.

So here are my questions:
- Is there any interest in the nwnx2-win32 community to build a similar api framework as in nwnx2-linux/branches/core2.8 ?
- If so, would it be possible to get SVN access for a new core-2.8 branch in nwnx2-win32?
- Are there any symbol tables for the Win32 executables (notably nwserver.exe and nwmain.exe)?

Now the last point is pretty important: Although it is possible to reconstruct the symbolic content of nwserver.exe by comparing its disassembly with the linux disassembly, any symbolic information already available about nwserver.exe (either gathered per hand or made available through a "half official" symbol table from the devs) would greatly facilitate the project; tracing the functions calls in the Linux and Windows disassemblies by hand and copying the symbolic information from the Linux to the Windows disassembly is tedious, mostly because the windows compiler (Visual C++ 6) and the Linux compiler (gnu?) inline code slightly differently.

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