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 - Fastcall RunScript version?
Goto page Previous  1, 2
 
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: Thu Mar 31, 2011 14:18    Post subject: Reply with quote

Hi MaxRock.
I've had the CVirtualMachine.cpp listed in Solution Explorer the whole time.

Still no build success.

I think I am gonna give up on nwnx_events, at least this distribution of it in any case.

It occurs to me, it might be easier to use nwnx_funcs for events hooking.
I mean, after all, your project already has access to all the include files, and nwn_internals, and you provide examples of hooking already.

Im thinking of trying to make another section in nwnx_funcs specifically for hooking, the frame work is pretty much there, it shouldnt be too hard to use it.

Have to compliment you MaxRock - Your nwnx_funcs win32 project is the most detailed, easy to understand and might as well be classed as a framework for future nwnx2 plugin developers, all the functions that anyone may need to use, are already freely available by your project.


anyway...
In order to add my own custom hooks to nwnx_funcs, am I right in that I only need to do the following?

HookFunc.cpp - Define the new memory locations to hook onto here.
Code:

CHookFunctions::CHookFunctions(int debugLevel) {
   this->debugLevel = debugLevel;

   org_CreateNewGeometry = 0x005A9250;
   org_ExecuteCommandEffectAppear = 0x00585110;
   CNWVirtualMachineCommands__ExecuteCommandGetItemPropertyTypeORG = 0x0058EA00;
   CNWVirtualMachineCommands__ExecuteCommandItemPropertyEffectORG = 0x0058EBD0;
   CNWSMessage__TestObjectVisibleORG = 0x004409F0;
   CNWSCreatureStats__GetEffectImmunityORG = 0x0048B770;
   CServerExoAppInternal__RemovePCFromWorldORG = 0x0045B990;

   HookFunctions();
}



HookFunctions(); - Change this function, to actually apply the hook
(I was just wondering - is it possible for you to refactor this function, in such a way, that it loops through hooks that we add? (eg - Minimizes locations in the cpp file that require editing.
I was thinking that each hook that we make, could be added to an array or a list of hooks, and then each hook is hooked onto via a for each loop or something.

Code:

//Just an edit of the onPlayerLeaving code.
//Ideally, I would change this function into a generic one.
int __fastcall CHookFunctions::ClassName__TheOriginalFunction(ClassType *pTHIS, void *pVOID, ArgumentType *a2) {
   _log(3, "o OurHook is running\n");
   (*NWN_VirtualMachine)->Runscript(&CExoString(NWNFuncs.TheNameOfOurEventScript), a2->obj_id);  //a2 being whatever object the script is to run on?
   return ClassName__TheOriginalFunctionNEXT(pTHIS, NULL, a2);
}



Now, what im not entirely sure about,
Is how do we set an event type inside nwnx_funcs, and then have nwnscript query this event number.

This is basically how nwnx_events did it.
Detect the event
Fire the script
Script queries nwnx_events plugin for the event number
returns to the script
enters a case statement, and goes to the appropriate section of code.

Im thinking the way it works, is
1. EventScript gets fired.
2. nwnx would then set a local variable in its own memory equal to whatever the event number is
3. nwn makes a request via SetLocal ( NWNX!FUNCS!EVENTNUMBER
4. nwnx funcs would then receive the request in CNWNXFuncs::OnRequest
5. nwnscript is then requesting this variable via GetLocal
6. nwn then receives the local variable from nwnx


I would love it if someone created an event hooking wizard for nwnx.

eg

void CreateHook(HookName,originalHookLocation,FunctionToRun,ScriptToFire);

and then calling it, would register your hook for you, and would make it that much easier to create new hooks.
Back to top
View user's profile Send private message
MaxRock



Joined: 24 Jan 2008
Posts: 196

PostPosted: Thu Mar 31, 2011 17:50    Post subject: Reply with quote

Quote:
I've had the CVirtualMachine.cpp listed in Solution Explorer the whole time.

Still no build success.


My bad, I just realized that
Code:
1>HookFunc.obj : error LNK2001: unresolved external symbol "struct CVirtualMachine_s * * NWN_VirtualMachine" (?NWN_VirtualMachine@@3PAPAUCVirtualMachine_s@@A)

is the original VM location... Add nwn_internal.cpp to the project (as long as you have types.h included, it will include nwn_internal.h too, but you must add the cpp file)

Quote:
Have to compliment you MaxRock - Your nwnx_funcs win32 project is the most detailed, easy to understand and might as well be classed as a framework for future nwnx2 plugin developers, all the functions that anyone may need to use, are already freely available by your project.

Except that apparently it's rather hard to use. I hate starting a new plugin (e.g. to test something real quick) and having to try and figure out what settings to change and what to include. That's why nwnw_funcs has/had a lot of code that never got used. It was just easier adding it there.
I do have an empty "template" project but I still have to go through and replace class/project/solution names. Have to figure out visual studios template wizard one of these days...
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
Goto page Previous  1, 2
Page 2 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