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 
 
First Attempt - Hooking Pause Event

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



Joined: 02 Sep 2007
Posts: 830

PostPosted: Tue Jun 22, 2010 21:32    Post subject: First Attempt - Hooking Pause Event Reply with quote

Rargh!! - I was going to post to say that I was very well on my way to making my first addition to nwnx_events for windows.

But now vs2006 has crashed......

Anyway, what I was planning on introducing to it, was the following code information.

0x462410 - This seems to be the 'Toggle Pause State' function.

I had just added this data, as well as starting the hook function when it crashed.


K, I just fixed it up again.

Got all my code ready to go, but it wont compile... due to something I never touched.

Its saying
mov eax, oTarget -
NWNXEvents.cpp(62) : error C2420: 'oTarget' : illegal symbol in second operand

This source code isnt from nwnx.org, its from nwnvault, where someone added the dev crit hook, I assumed it would be the more recent and working code.

Anyone know what I should replace this with? Where do I get oTarget?

Code:

unsigned long CNWNXEvents::OnRequestObject (char *gameObject, char* Request){

   if (!scriptRun) return OBJECT_INVALID;

   dword oTarget_a = 0;
   
   //Learning by doing as the asembly teacher said
   _asm{

      push eax
      mov eax, oTarget
      mov eax, [eax-0x4]
      mov oTarget_a, eax
      pop eax

   }

   if( !oTarget_a )
      oTarget_a = OBJECT_INVALID;

   if (strncmp(Request, "TARGET", 6) == 0)
      return oTarget_a;

   else return OBJECT_INVALID;
}
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Tue Jun 22, 2010 22:24    Post subject: YAY - Pause Hooked Reply with quote

Code:

//The All important Pause Toggle memory location is
DWORD org_Pause            = 0x462410;



void PauseHookProc()
{
//  _asm { int 3 }
  _asm { pushad }
   if (!scriptRun)
   {
      _asm { add ebx, 4 }
      _asm { mov oPC, ebx }
      _asm { sub ebx, 4 }
      events.FireEvent(*(dword *)oPC, EVENT_TOGGLE_PAUSE);
      
   }
  _asm { popad }
  _asm { leave }

  _asm { jmp PauseNextHook }
}




I had no idea it was sooooo easy to hook.
I didnt even need to understand the assembly, I just copied the method used by the other hooks, changed the locations of where to hook to match the functions, and made sure there was new CONST ints etc for the new event data to be sent to nwnx/nwn.

I programmed this particular event.dll to use event number 10.

The only event src I could get to build, was the one from the svn, the one which is supposed to be more recent with the dev crit hit hook in it, I couldnt get it to build because of the oTarget issue. It wouldnt build straight from download.

Im gonna have a look at the source for dmactions now,
I wana learn more about hooking, hooking seems to be one of the easier things to do.
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Tue Jun 22, 2010 23:51    Post subject: Improved Reply with quote

Code:






void PauseHookProc()
{
//  _asm { int 3 }
  _asm { pushad }
   if (!scriptRun)
   {
      _asm { add ebx, 4 }
      _asm { mov oPC, ebx }
      _asm { sub ebx, 4 }
      events.FireEvent(*(dword *)oPC, EVENT_TOGGLE_PAUSE);
      
   }
 
  _asm { popad }
  _asm { leave }
  if( events.nBypass == 1 ){
       _asm{ retn 4 }
  }
  else
  {

  }
  _asm { jmp PauseNextHook }
 
}



The following needs added to the ONRequest method too.

Code:

else if (strncmp(Request, "SETBYPASS", 10) == 0)
   {
      if (strlen(Parameters) > 1)
      {
         nBypass = 1;   
         //fprintf( m_fFile, "! GETEVENTID: %d\n", nEventID );
      }
      return NULL;
   }



This allows server admins to bypass the Pause event on windows.
Eg - Prevent Pause for those people who dont have access to it.
Eg - New DM's etc.

Alternativly, you can enable PlayerPausing
Then set up your event script to only allow people whos player account is in the admin list, to actually pause.
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