sourcehook/sourcehook.cpp
changeset 179 3ade923f508b
parent 177 114eaa11dca2
child 181 50e55881d8c2
     1.1 --- a/sourcehook/sourcehook.cpp	Sat Feb 04 21:45:10 2006 +0000
     1.2 +++ b/sourcehook/sourcehook.cpp	Sun Feb 05 20:24:58 2006 +0000
     1.3 @@ -617,12 +617,19 @@
     1.4  		HookLoopInfo hli;
     1.5  		hli.pCurIface = pIface;
     1.6  		hli.shouldContinue = true;
     1.7 -		hli.recall = false;
     1.8 +		hli.recall = HookLoopInfo::Recall_No;
     1.9 +
    1.10 +		static_cast<CIface*>(pIface)->m_PreHooks.RQFlagReset();
    1.11 +		static_cast<CIface*>(pIface)->m_PostHooks.RQFlagReset();
    1.12 +
    1.13  		m_HLIStack.push(hli);
    1.14  	}
    1.15  
    1.16  	void CSourceHookImpl::HookLoopEnd()
    1.17  	{
    1.18 +		// When in a post recall... make sure status is high enough so that it returns the orig ret.
    1.19 +		if (m_HLIStack.size() > 1 && m_HLIStack.second().recall == HookLoopInfo::Recall_Post2)
    1.20 +			*m_HLIStack.front().pStatus = MRES_SUPERCEDE;			// THAT'LL TEACH THEM!
    1.21  		m_HLIStack.pop();
    1.22  	}
    1.23  
    1.24 @@ -643,6 +650,10 @@
    1.25  
    1.26  	const void *CSourceHookImpl::GetOrigRet()
    1.27  	{
    1.28 +		// When in a post recall... return the orig ret of the previous hookloop.
    1.29 +		if (m_HLIStack.size() > 1 && m_HLIStack.second().recall == HookLoopInfo::Recall_Post2)
    1.30 +			return m_HLIStack.second().pOrigRet;
    1.31 +
    1.32  		return m_HLIStack.front().pOrigRet;
    1.33  	}
    1.34  
    1.35 @@ -724,7 +735,13 @@
    1.36  			HookLoopInfo &other = m_HLIStack.second();
    1.37  			*statusPtr = *other.pStatus;
    1.38  			*prevResPtr = *other.pStatus;
    1.39 -			hli.pOverrideRet = other.pOverrideRet;
    1.40 +
    1.41 +			// When the status is low so there's no override return value and we're in a post recall,
    1.42 +			// give it the orig return value as override return value.
    1.43 +			if (*statusPtr < MRES_OVERRIDE && other.recall == HookLoopInfo::Recall_Post1)
    1.44 +				hli.pOverrideRet = const_cast<void*>(other.pOrigRet);
    1.45 +			else	// Otherwise, transfer override ret normally
    1.46 +				hli.pOverrideRet = other.pOverrideRet;
    1.47  		}
    1.48  		else
    1.49  			hli.pOverrideRet = overrideRetPtr;
    1.50 @@ -740,6 +757,27 @@
    1.51  		// actual recall is done and that we are back in the original handler which shall return
    1.52  		// immediately.
    1.53  
    1.54 +		// Post-recalls:
    1.55 +		//  The second element on the stack has recall set to Recall_Post1.
    1.56 +		//  This means that we want to skip this part and the original function calling thing, so
    1.57 +		//  we store the status mres value, set status to MRES_SUPERCEDE, and return false.
    1.58 +		//  We also set the recall flag to Recall_Post2, so the next time the thing calls us, we
    1.59 +		//  can return true (so that the thing goes into post hooks).
    1.60 +		if (m_HLIStack.size() > 1)
    1.61 +		{
    1.62 +			if (m_HLIStack.second().recall == HookLoopInfo::Recall_Post1)
    1.63 +			{
    1.64 +				m_HLIStack.front().temporaryStatus = *m_HLIStack.front().pStatus;
    1.65 +				*m_HLIStack.front().pStatus = MRES_SUPERCEDE;
    1.66 +				m_HLIStack.second().recall = HookLoopInfo::Recall_Post2;
    1.67 +				return false;
    1.68 +			}
    1.69 +			else if (m_HLIStack.second().recall == HookLoopInfo::Recall_Post2)
    1.70 +			{
    1.71 +				*m_HLIStack.front().pStatus = m_HLIStack.front().temporaryStatus;
    1.72 +				return m_HLIStack.front().shouldContinue;
    1.73 +			}
    1.74 +		}
    1.75  		return m_HLIStack.front().shouldContinue && !m_HLIStack.front().recall;
    1.76  	}
    1.77  
    1.78 @@ -747,11 +785,16 @@
    1.79  	{
    1.80  		if (!m_HLIStack.empty())
    1.81  		{
    1.82 -			m_HLIStack.front().recall = true;
    1.83 -			CHookList *mlist = static_cast<CHookList*>(m_HLIStack.front().pCurIface->GetPreHooks());
    1.84 +			// Also watch out for post recalls! Described at the beginning of sourcehook_impl.h
    1.85 +			m_HLIStack.front().recall =
    1.86 +				static_cast<CIface*>(m_HLIStack.front().pCurIface)->m_PostHooks.RQFlagGet() ?
    1.87 +				HookLoopInfo::Recall_Post1 : HookLoopInfo::Recall_Pre;
    1.88 +			
    1.89 +			CHookList *mlist = static_cast<CHookList*>(m_HLIStack.front().recall == HookLoopInfo::Recall_Pre ? 
    1.90 +				m_HLIStack.front().pCurIface->GetPreHooks() : m_HLIStack.front().pCurIface->GetPostHooks());
    1.91  			mlist->m_Recall = true;
    1.92  
    1.93 -			// The hookfunc usually do this, but it won't have a chance to see it, 
    1.94 +			// The hookfunc usually does this, but it won't have a chance to see it, 
    1.95  			// so for recalls, we update status here if it's required
    1.96  			if (*m_HLIStack.front().pCurRes > *m_HLIStack.front().pStatus) 
    1.97  				*m_HLIStack.front().pStatus = *m_HLIStack.front().pCurRes;
    1.98 @@ -931,6 +974,8 @@
    1.99  	}
   1.100  	IHookList::IIter *CSourceHookImpl::CHookList::GetIter()
   1.101  	{
   1.102 +		m_RQFlag = true;
   1.103 +
   1.104  		CIter *ret;
   1.105  		if (m_FreeIters)
   1.106  		{