fix build
This commit is contained in:
		
							parent
							
								
									7a9e0c973d
								
							
						
					
					
						commit
						cc15c3479f
					
				
							
								
								
									
										90
									
								
								vhook.cpp
									
									
									
									
									
								
							
							
						
						
									
										90
									
								
								vhook.cpp
									
									
									
									
									
								
							| @ -7,6 +7,7 @@ SourceHook::IHookManagerAutoGen *g_pHookManager = NULL; | |||||||
| ke::Vector<DHooksManager *> g_pHooks; | ke::Vector<DHooksManager *> g_pHooks; | ||||||
| 
 | 
 | ||||||
| using namespace SourceHook; | using namespace SourceHook; | ||||||
|  | using namespace sp; | ||||||
| 
 | 
 | ||||||
| #ifdef  WIN32 | #ifdef  WIN32 | ||||||
| #define OBJECT_OFFSET sizeof(void *) | #define OBJECT_OFFSET sizeof(void *) | ||||||
| @ -14,6 +15,95 @@ using namespace SourceHook; | |||||||
| #define OBJECT_OFFSET (sizeof(void *)*2) | #define OBJECT_OFFSET (sizeof(void *)*2) | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
|  | #ifndef  WIN32 | ||||||
|  | void *GenerateThunk(ReturnType type) | ||||||
|  | { | ||||||
|  | 	sp::MacroAssembler masm; | ||||||
|  | 	static const size_t kStackNeeded = (2) * 4; // 2 args max
 | ||||||
|  | 	static const size_t kReserve = ke::Align(kStackNeeded+8, 16)-8; | ||||||
|  | 
 | ||||||
|  | 	masm.push(ebp); | ||||||
|  | 	masm.movl(ebp, esp); | ||||||
|  | 	masm.subl(esp, kReserve); | ||||||
|  | 	if(type != ReturnType_String && type != ReturnType_Vector) | ||||||
|  | 	{ | ||||||
|  | 		masm.lea(eax, Operand(ebp, 12)); // grab the incoming caller argument vector
 | ||||||
|  | 		masm.movl(Operand(esp, 1 * 4), eax); // set that as the 2nd argument
 | ||||||
|  | 		masm.movl(eax, Operand(ebp, 8)); // grab the |this|
 | ||||||
|  | 		masm.movl(Operand(esp, 0 * 4), eax); // set |this| as the 1st argument*/
 | ||||||
|  | 	} | ||||||
|  | 	else | ||||||
|  | 	{ | ||||||
|  | 		masm.lea(eax, Operand(ebp, 8)); // grab the incoming caller argument vector
 | ||||||
|  | 		masm.movl(Operand(esp, 1 * 4), eax); // set that as the 2nd argument
 | ||||||
|  | 		masm.movl(eax, Operand(ebp, 12)); // grab the |this|
 | ||||||
|  | 		masm.movl(Operand(esp, 0 * 4), eax); // set |this| as the 1st argument*/
 | ||||||
|  | 	} | ||||||
|  | 	if(type == ReturnType_Float) | ||||||
|  | 	{ | ||||||
|  | 		masm.call(ExternalAddress((void *)Callback_float)); | ||||||
|  | 	} | ||||||
|  | 	else if(type == ReturnType_Vector) | ||||||
|  | 	{ | ||||||
|  | 		masm.call(ExternalAddress((void *)Callback_vector)); | ||||||
|  | 	} | ||||||
|  | 	else if(type == ReturnType_String) | ||||||
|  | 	{ | ||||||
|  | 		masm.call(ExternalAddress((void *)Callback_stringt)); | ||||||
|  | 	} | ||||||
|  | 	else | ||||||
|  | 	{ | ||||||
|  | 		masm.call(ExternalAddress((void *)Callback)); | ||||||
|  | 	} | ||||||
|  | 	masm.addl(esp, kReserve); | ||||||
|  | 	masm.pop(ebp); // restore ebp
 | ||||||
|  | 	masm.ret(); | ||||||
|  | 
 | ||||||
|  | 	void *base =  g_pSM->GetScriptingEngine()->AllocatePageMemory(masm.length()); | ||||||
|  | 	masm.emitToExecutableMemory(base); | ||||||
|  | 	return base; | ||||||
|  | } | ||||||
|  | #else | ||||||
|  | // HUGE THANKS TO BAILOPAN (dvander)!
 | ||||||
|  | void *GenerateThunk(ReturnType type) | ||||||
|  | { | ||||||
|  | 	sp::MacroAssembler masm; | ||||||
|  | 	static const size_t kStackNeeded = (3 + 1) * 4; // 3 args max, 1 locals max
 | ||||||
|  | 	static const size_t kReserve = ke::Align(kStackNeeded+8, 16)-8; | ||||||
|  | 
 | ||||||
|  | 	masm.push(ebp); | ||||||
|  | 	masm.movl(ebp, esp); | ||||||
|  | 	masm.subl(esp, kReserve); | ||||||
|  | 	masm.lea(eax, Operand(esp, 3 * 4)); // ptr to 2nd var after argument space
 | ||||||
|  | 	masm.movl(Operand(esp, 2 * 4), eax); // set the ptr as the third argument
 | ||||||
|  | 	masm.lea(eax, Operand(ebp, 8)); // grab the incoming caller argument vector
 | ||||||
|  | 	masm.movl(Operand(esp, 1 * 4), eax); // set that as the 2nd argument
 | ||||||
|  | 	masm.movl(Operand(esp, 0 * 4), ecx); // set |this| as the 1st argument
 | ||||||
|  | 	if(type == ReturnType_Float) | ||||||
|  | 	{ | ||||||
|  | 		masm.call(ExternalAddress(Callback_float)); | ||||||
|  | 	} | ||||||
|  | 	else if(type == ReturnType_Vector) | ||||||
|  | 	{ | ||||||
|  | 		masm.call(ExternalAddress(Callback_vector)); | ||||||
|  | 	} | ||||||
|  | 	else | ||||||
|  | 	{ | ||||||
|  | 		masm.call(ExternalAddress(Callback)); | ||||||
|  | 	} | ||||||
|  | 	masm.movl(ecx, Operand(esp, 3*4)); | ||||||
|  | 	masm.addl(esp, kReserve); | ||||||
|  | 	masm.pop(ebp); // restore ebp
 | ||||||
|  | 	masm.pop(edx); // grab return address in edx
 | ||||||
|  | 	masm.addl(esp, ecx); // remove arguments
 | ||||||
|  | 	masm.jmp(edx); // return to caller
 | ||||||
|  |   | ||||||
|  | 	void *base =  g_pSM->GetScriptingEngine()->AllocatePageMemory(masm.length()); | ||||||
|  | 	masm.emitToExecutableMemory(base); | ||||||
|  | 	return base; | ||||||
|  | } | ||||||
|  | #endif | ||||||
|  | 
 | ||||||
| DHooksManager::DHooksManager(HookSetup *setup, void *iface, IPluginFunction *remove_callback, IPluginFunction *plugincb, bool post) | DHooksManager::DHooksManager(HookSetup *setup, void *iface, IPluginFunction *remove_callback, IPluginFunction *plugincb, bool post) | ||||||
| { | { | ||||||
| 	this->callback = MakeHandler(setup->returnType); | 	this->callback = MakeHandler(setup->returnType); | ||||||
|  | |||||||
							
								
								
									
										90
									
								
								vhook.h
									
									
									
									
									
								
							
							
						
						
									
										90
									
								
								vhook.h
									
									
									
									
									
								
							| @ -162,95 +162,7 @@ bool SetupHookManager(ISmmAPI *ismm); | |||||||
| void CleanupHooks(IPluginContext *pContext = NULL); | void CleanupHooks(IPluginContext *pContext = NULL); | ||||||
| size_t GetParamTypeSize(HookParamType type); | size_t GetParamTypeSize(HookParamType type); | ||||||
| SourceHook::PassInfo::PassType GetParamTypePassType(HookParamType type); | SourceHook::PassInfo::PassType GetParamTypePassType(HookParamType type); | ||||||
| 
 | void *GenerateThunk(ReturnType type); | ||||||
| #ifndef  WIN32 |  | ||||||
| static void *GenerateThunk(ReturnType type) |  | ||||||
| { |  | ||||||
| 	sp::MacroAssemblerX86 masm; |  | ||||||
| 	static const size_t kStackNeeded = (2) * 4; // 2 args max
 |  | ||||||
| 	static const size_t kReserve = ke::Align(kStackNeeded+8, 16)-8; |  | ||||||
| 
 |  | ||||||
| 	masm.push(ebp); |  | ||||||
| 	masm.movl(ebp, esp); |  | ||||||
| 	masm.subl(esp, kReserve); |  | ||||||
| 	if(type != ReturnType_String && type != ReturnType_Vector) |  | ||||||
| 	{ |  | ||||||
| 		masm.lea(eax, Operand(ebp, 12)); // grab the incoming caller argument vector
 |  | ||||||
| 		masm.movl(Operand(esp, 1 * 4), eax); // set that as the 2nd argument
 |  | ||||||
| 		masm.movl(eax, Operand(ebp, 8)); // grab the |this|
 |  | ||||||
| 		masm.movl(Operand(esp, 0 * 4), eax); // set |this| as the 1st argument*/
 |  | ||||||
| 	} |  | ||||||
| 	else |  | ||||||
| 	{ |  | ||||||
| 		masm.lea(eax, Operand(ebp, 8)); // grab the incoming caller argument vector
 |  | ||||||
| 		masm.movl(Operand(esp, 1 * 4), eax); // set that as the 2nd argument
 |  | ||||||
| 		masm.movl(eax, Operand(ebp, 12)); // grab the |this|
 |  | ||||||
| 		masm.movl(Operand(esp, 0 * 4), eax); // set |this| as the 1st argument*/
 |  | ||||||
| 	} |  | ||||||
| 	if(type == ReturnType_Float) |  | ||||||
| 	{ |  | ||||||
| 		masm.call(ExternalAddress((void *)Callback_float)); |  | ||||||
| 	} |  | ||||||
| 	else if(type == ReturnType_Vector) |  | ||||||
| 	{ |  | ||||||
| 		masm.call(ExternalAddress((void *)Callback_vector)); |  | ||||||
| 	} |  | ||||||
| 	else if(type == ReturnType_String) |  | ||||||
| 	{ |  | ||||||
| 		masm.call(ExternalAddress((void *)Callback_stringt)); |  | ||||||
| 	} |  | ||||||
| 	else |  | ||||||
| 	{ |  | ||||||
| 		masm.call(ExternalAddress((void *)Callback)); |  | ||||||
| 	} |  | ||||||
| 	masm.addl(esp, kReserve); |  | ||||||
| 	masm.pop(ebp); // restore ebp
 |  | ||||||
| 	masm.ret(); |  | ||||||
| 
 |  | ||||||
| 	void *base =  g_pSM->GetScriptingEngine()->AllocatePageMemory(masm.length()); |  | ||||||
| 	masm.emitToExecutableMemory(base); |  | ||||||
| 	return base; |  | ||||||
| } |  | ||||||
| #else |  | ||||||
| // HUGE THANKS TO BAILOPAN (dvander)!
 |  | ||||||
| static void *GenerateThunk(ReturnType type) |  | ||||||
| { |  | ||||||
| 	sp::MacroAssemblerX86 masm; |  | ||||||
| 	static const size_t kStackNeeded = (3 + 1) * 4; // 3 args max, 1 locals max
 |  | ||||||
| 	static const size_t kReserve = ke::Align(kStackNeeded+8, 16)-8; |  | ||||||
| 
 |  | ||||||
| 	masm.push(ebp); |  | ||||||
| 	masm.movl(ebp, esp); |  | ||||||
| 	masm.subl(esp, kReserve); |  | ||||||
| 	masm.lea(eax, Operand(esp, 3 * 4)); // ptr to 2nd var after argument space
 |  | ||||||
| 	masm.movl(Operand(esp, 2 * 4), eax); // set the ptr as the third argument
 |  | ||||||
| 	masm.lea(eax, Operand(ebp, 8)); // grab the incoming caller argument vector
 |  | ||||||
| 	masm.movl(Operand(esp, 1 * 4), eax); // set that as the 2nd argument
 |  | ||||||
| 	masm.movl(Operand(esp, 0 * 4), ecx); // set |this| as the 1st argument
 |  | ||||||
| 	if(type == ReturnType_Float) |  | ||||||
| 	{ |  | ||||||
| 		masm.call(ExternalAddress(Callback_float)); |  | ||||||
| 	} |  | ||||||
| 	else if(type == ReturnType_Vector) |  | ||||||
| 	{ |  | ||||||
| 		masm.call(ExternalAddress(Callback_vector)); |  | ||||||
| 	} |  | ||||||
| 	else |  | ||||||
| 	{ |  | ||||||
| 		masm.call(ExternalAddress(Callback)); |  | ||||||
| 	} |  | ||||||
| 	masm.movl(ecx, Operand(esp, 3*4)); |  | ||||||
| 	masm.addl(esp, kReserve); |  | ||||||
| 	masm.pop(ebp); // restore ebp
 |  | ||||||
| 	masm.pop(edx); // grab return address in edx
 |  | ||||||
| 	masm.addl(esp, ecx); // remove arguments
 |  | ||||||
| 	masm.jmp(edx); // return to caller
 |  | ||||||
|   |  | ||||||
| 	void *base =  g_pSM->GetScriptingEngine()->AllocatePageMemory(masm.length()); |  | ||||||
| 	masm.emitToExecutableMemory(base); |  | ||||||
| 	return base; |  | ||||||
| } |  | ||||||
| #endif |  | ||||||
| 
 | 
 | ||||||
| static DHooksCallback *MakeHandler(ReturnType type) | static DHooksCallback *MakeHandler(ReturnType type) | ||||||
| { | { | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user