sourcehook/sourcehook_impl.h
changeset 179 3ade923f508b
parent 163 377bdd31c28d
child 181 50e55881d8c2
     1.1 --- a/sourcehook/sourcehook_impl.h	Sat Feb 04 21:45:10 2006 +0000
     1.2 +++ b/sourcehook/sourcehook_impl.h	Sun Feb 05 20:24:58 2006 +0000
     1.3 @@ -116,6 +116,32 @@
     1.4  	When this recurisvely called hookfunc returns, the macro returns what it returned
     1.5  	(using MRES_SUPERCEDE). CSourceHookImpl returns false from ShouldContinue so the original hook loop
     1.6  	is abandonned.
     1.7 +
     1.8 +Post Recalls
     1.9 +	People wanted to be able to use META_RETURN_(VALUE_)NEWPARAMS from post hooks as well. Crazy people!
    1.10 +	Anyway, for this, we have to know where a hook handler is. Is it executing pre or post hooks at the moment?
    1.11 +	The only way we can know this is watching when it calls CHookList::GetIter(). So CHookList gets a new variable:
    1.12 +	m_RequestedFlag. It also gets two new functions: RQFlagReset() and RQFlagGet().
    1.13 +	HookLoopBegin() calls RQFlagReset on both hooklists of the iface; then DoRecall() checks whether the postlist's 
    1.14 +	RQ flag is set. if yes, the hook loop is in post mode.
    1.15 +
    1.16 +	So, what a about a recall in post mode? The first ShouldContinue returns false and sets Status to supercede. 
    1.17 +	This way the pre hooks and the function call will be skipped. Then, then next ShouldContinue returns true, so we get
    1.18 +	into the post hooks. HA!
    1.19 +
    1.20 +Return Values in Post Recalls
    1.21 +	The easy case is when we already have an override return value. In this case, the status register gets transferred,
    1.22 +	and so does the override return pointer. So, basically, everything is ok.
    1.23 +
    1.24 +	However, what happens if we don't? ie. the status register is on MRES_IGNORED? In this case we'd have to transfer the
    1.25 +	orig ret value. But we can't: There's no way to tell the hookfunc: "Use this as orig ret pointer". It uses its own.
    1.26 +	So, we emulate it. GetOrigRet will return the orig ret pointer from the old hook loop. If still no one overrides it,
    1.27 +	we'd have to return it. BUT! HOW TO DO THIS? Check out SH_RETURN(). First calls HookLoopEnd(), then decides whether
    1.28 +	to return the override retval or the orig retval. But it doesn't ask for a new override return. So we give the function
    1.29 +	the last orig return value as its new override return value; but leave status where it is so everything works, and in
    1.30 +	HookLoopEnd we make sure that status is high enough so that the override return will be returned. crazy.
    1.31 +
    1.32 +	All this stuff could be much less complicated if I didn't try to preserve binary compatibility :)
    1.33  */
    1.34  
    1.35  namespace SourceHook
    1.36 @@ -240,6 +266,7 @@
    1.37  
    1.38  			// For recalls
    1.39  			bool m_Recall;
    1.40 +			bool m_RQFlag;
    1.41  
    1.42  			void SetRecallState();	// Sets the list into a state where the next returned
    1.43  									// iterator (from GetIter) will be a copy of the last
    1.44 @@ -247,6 +274,8 @@
    1.45  									// The hook resets this state automatically on:
    1.46  									// GetIter, ReleaseIter
    1.47  
    1.48 +			void RQFlagReset() { m_RQFlag = false; }
    1.49 +			bool RQFlagGet() { return m_RQFlag; }
    1.50  			CHookList();
    1.51  			CHookList(const CHookList &other);
    1.52  			virtual ~CHookList();
    1.53 @@ -452,12 +481,21 @@
    1.54  
    1.55  		struct HookLoopInfo
    1.56  		{
    1.57 +			enum RecallType
    1.58 +			{
    1.59 +				Recall_No=0,
    1.60 +				Recall_Pre,
    1.61 +				Recall_Post1,
    1.62 +				Recall_Post2
    1.63 +			};
    1.64 +
    1.65  			META_RES *pStatus;
    1.66  			META_RES *pPrevRes;
    1.67  			META_RES *pCurRes;
    1.68  
    1.69 +			META_RES temporaryStatus;				//!< Stored during Post1 recall phase
    1.70  			bool shouldContinue;
    1.71 -			bool recall;							//!< True if we're in a recall, eh.
    1.72 +			RecallType recall;						//!< Specifies which kind of recall we're in.
    1.73  
    1.74  			IIface *pCurIface;
    1.75  			const void *pOrigRet;