Fix overriding functions with objects crashing.
This commit is contained in:
		
							parent
							
								
									47cf76c2e3
								
							
						
					
					
						commit
						71b840e70a
					
				| @ -84,8 +84,11 @@ enum MRESReturn | |||||||
| 
 | 
 | ||||||
| enum DHookPassFlag | enum DHookPassFlag | ||||||
| { | { | ||||||
| 	DHookPass_ByVal = (1<<0), | 	DHookPass_ByVal = 		(1<<0),		/**< Passing by value */ | ||||||
| 	DHookPass_ByRef = (1<<1) | 	DHookPass_ByRef = 		(1<<1),		/**< Passing by reference */ | ||||||
|  | 	DHookPass_ODTOR =		(1<<2),		/**< Object has a destructor */ | ||||||
|  | 	DHookPass_OCTOR =		(1<<3),		/**< Object has a constructor */ | ||||||
|  | 	DHookPass_OASSIGNOP	=	(1<<4),		/**< Object has an assignment operator */ | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| typeset ListenCB | typeset ListenCB | ||||||
|  | |||||||
							
								
								
									
										69
									
								
								vfunc_call.h
									
									
									
									
									
								
							
							
						
						
									
										69
									
								
								vfunc_call.h
									
									
									
									
									
								
							| @ -3,35 +3,30 @@ | |||||||
| 
 | 
 | ||||||
| #include "vhook.h" | #include "vhook.h" | ||||||
| #include "extension.h" | #include "extension.h" | ||||||
|  | #include "natives.h" | ||||||
| 
 | 
 | ||||||
| #define PARAMINFO_SWITCH(passType) \ | #define PARAMINFO_SWITCH(passType) \ | ||||||
| 		paramInfo[i].flags = dg->params.at(i).flag; \ | 		paramInfo[i].flags = dg->params.at(i).flags; \ | ||||||
| 		paramInfo[i].size = dg->params.at(i).size; \ | 		paramInfo[i].size = dg->params.at(i).size; \ | ||||||
| 		paramInfo[i].type = passType; | 		paramInfo[i].type = passType; | ||||||
| 
 | 
 | ||||||
| #define VSTK_PARAM_SWITCH(paramType) \ | #define VSTK_PARAM_SWITCH(paramType) \ | ||||||
| 		if(paramStruct->isChanged[i]) \ | 		if(paramStruct->isChanged[i]) \ | ||||||
| 		{ \ | 		{ \ | ||||||
| 			*(paramType *)vptr = (paramType)(paramStruct->newParams[i]); \ | 			*(paramType *)vptr = *(paramType *)newAddr; \ | ||||||
| 		} \ | 		} \ | ||||||
| 		else \ | 		else \ | ||||||
| 		{ \ | 		{ \ | ||||||
| 			*(paramType *)vptr = (paramType)(paramStruct->orgParams[i]); \ | 			*(paramType *)vptr = *(paramType *)orgAddr; \ | ||||||
| 		} \ | 		} \ | ||||||
| 		if(i + 1 != dg->params.size()) \ | 		if(i + 1 != dg->params.size()) \ | ||||||
| 		{ \ | 		{ \ | ||||||
| 			vptr += dg->params.at(i).size; \ | 			vptr += dg->params.at(i).size; \ | ||||||
| 		} \ | 		} \ | ||||||
| 		break; | 		break; | ||||||
| #define VSTK_PARAM_SWITCH_FLOAT() \ | 
 | ||||||
| 		if(paramStruct->isChanged[i]) \ | #define VSTK_PARAM_SWITCH_OBJECT() \ | ||||||
| 		{ \ | 		memcpy(vptr, objAddr, dg->params.at(i).size); \ | ||||||
| 			*(float *)vptr = *(float *)(paramStruct->newParams[i]); \ |  | ||||||
| 		} \ |  | ||||||
| 		else \ |  | ||||||
| 		{ \ |  | ||||||
| 			*(float *)vptr = *(float *)(paramStruct->orgParams[i]); \ |  | ||||||
| 		} \ |  | ||||||
| 		if(i + 1 != dg->params.size()) \ | 		if(i + 1 != dg->params.size()) \ | ||||||
| 		{ \ | 		{ \ | ||||||
| 			vptr += dg->params.at(i).size; \ | 			vptr += dg->params.at(i).size; \ | ||||||
| @ -71,8 +66,14 @@ T CallVFunction(DHooksCallback *dg, HookParamsStruct *paramStruct, void *iface) | |||||||
| 	{ | 	{ | ||||||
| 		vptr += sizeof(void *); | 		vptr += sizeof(void *); | ||||||
| 		paramInfo = (SourceMod::PassInfo *)malloc(sizeof(SourceMod::PassInfo) * dg->params.size()); | 		paramInfo = (SourceMod::PassInfo *)malloc(sizeof(SourceMod::PassInfo) * dg->params.size()); | ||||||
|  | 
 | ||||||
| 		for(int i = 0; i < (int)dg->params.size(); i++) | 		for(int i = 0; i < (int)dg->params.size(); i++) | ||||||
| 		{ | 		{ | ||||||
|  | 			size_t offset = GetParamOffset(paramStruct, i); | ||||||
|  | 
 | ||||||
|  | 			void *orgAddr = (void **)((intptr_t)paramStruct->orgParams + offset); | ||||||
|  | 			void *newAddr = (void **)((intptr_t)paramStruct->newParams + offset); | ||||||
|  | 
 | ||||||
| 			switch(dg->params.at(i).type) | 			switch(dg->params.at(i).type) | ||||||
| 			{ | 			{ | ||||||
| 				case HookParamType_Int: | 				case HookParamType_Int: | ||||||
| @ -83,10 +84,10 @@ T CallVFunction(DHooksCallback *dg, HookParamsStruct *paramStruct, void *iface) | |||||||
| 					VSTK_PARAM_SWITCH(cell_t); | 					VSTK_PARAM_SWITCH(cell_t); | ||||||
| 				case HookParamType_Float: | 				case HookParamType_Float: | ||||||
| 					PARAMINFO_SWITCH(PassType_Float); | 					PARAMINFO_SWITCH(PassType_Float); | ||||||
| 					VSTK_PARAM_SWITCH_FLOAT(); | 					VSTK_PARAM_SWITCH(float); | ||||||
| 				case HookParamType_String: | 				case HookParamType_String: | ||||||
| 					PARAMINFO_SWITCH(PassType_Object); | 					PARAMINFO_SWITCH(PassType_Object); | ||||||
| 					VSTK_PARAM_SWITCH(int); | 					VSTK_PARAM_SWITCH(string_t); | ||||||
| 				case HookParamType_StringPtr: | 				case HookParamType_StringPtr: | ||||||
| 					PARAMINFO_SWITCH(PassType_Basic); | 					PARAMINFO_SWITCH(PassType_Basic); | ||||||
| 					VSTK_PARAM_SWITCH(string_t *); | 					VSTK_PARAM_SWITCH(string_t *); | ||||||
| @ -102,6 +103,12 @@ T CallVFunction(DHooksCallback *dg, HookParamsStruct *paramStruct, void *iface) | |||||||
| 				case HookParamType_Edict: | 				case HookParamType_Edict: | ||||||
| 					PARAMINFO_SWITCH(PassType_Basic); | 					PARAMINFO_SWITCH(PassType_Basic); | ||||||
| 					VSTK_PARAM_SWITCH(edict_t *); | 					VSTK_PARAM_SWITCH(edict_t *); | ||||||
|  | 				case HookParamType_Object: | ||||||
|  | 				{ | ||||||
|  | 					void *objAddr = GetObjectAddr(HookParamType_Object, paramStruct->dg->params.at(i).flags, paramStruct->orgParams, offset); | ||||||
|  | 					PARAMINFO_SWITCH(PassType_Object); | ||||||
|  | 					VSTK_PARAM_SWITCH_OBJECT(); | ||||||
|  | 				} | ||||||
| 				default: | 				default: | ||||||
| 					PARAMINFO_SWITCH(PassType_Basic); | 					PARAMINFO_SWITCH(PassType_Basic); | ||||||
| 					VSTK_PARAM_SWITCH(void *); | 					VSTK_PARAM_SWITCH(void *); | ||||||
| @ -160,7 +167,12 @@ SDKVector CallVFunction<SDKVector>(DHooksCallback *dg, HookParamsStruct *paramSt | |||||||
| 		paramInfo = (SourceMod::PassInfo *)malloc(sizeof(SourceMod::PassInfo) * dg->params.size()); | 		paramInfo = (SourceMod::PassInfo *)malloc(sizeof(SourceMod::PassInfo) * dg->params.size()); | ||||||
| 		for(int i = 0; i < (int)dg->params.size(); i++) | 		for(int i = 0; i < (int)dg->params.size(); i++) | ||||||
| 		{ | 		{ | ||||||
| 			switch(dg->params.at(i).type) | 			size_t offset = GetParamOffset(paramStruct, i); | ||||||
|  | 
 | ||||||
|  | 			void *orgAddr = *(void **)((intptr_t)paramStruct->orgParams + offset); | ||||||
|  | 			void *newAddr = *(void **)((intptr_t)paramStruct->newParams + offset); | ||||||
|  | 
 | ||||||
|  | 			switch (dg->params.at(i).type) | ||||||
| 			{ | 			{ | ||||||
| 				case HookParamType_Int: | 				case HookParamType_Int: | ||||||
| 					PARAMINFO_SWITCH(PassType_Basic); | 					PARAMINFO_SWITCH(PassType_Basic); | ||||||
| @ -170,10 +182,10 @@ SDKVector CallVFunction<SDKVector>(DHooksCallback *dg, HookParamsStruct *paramSt | |||||||
| 					VSTK_PARAM_SWITCH(cell_t); | 					VSTK_PARAM_SWITCH(cell_t); | ||||||
| 				case HookParamType_Float: | 				case HookParamType_Float: | ||||||
| 					PARAMINFO_SWITCH(PassType_Float); | 					PARAMINFO_SWITCH(PassType_Float); | ||||||
| 					VSTK_PARAM_SWITCH_FLOAT(); | 					VSTK_PARAM_SWITCH(float); | ||||||
| 				case HookParamType_String: | 				case HookParamType_String: | ||||||
| 					PARAMINFO_SWITCH(PassType_Object); | 					PARAMINFO_SWITCH(PassType_Object); | ||||||
| 					VSTK_PARAM_SWITCH(int); | 					VSTK_PARAM_SWITCH(string_t); | ||||||
| 				case HookParamType_StringPtr: | 				case HookParamType_StringPtr: | ||||||
| 					PARAMINFO_SWITCH(PassType_Basic); | 					PARAMINFO_SWITCH(PassType_Basic); | ||||||
| 					VSTK_PARAM_SWITCH(string_t *); | 					VSTK_PARAM_SWITCH(string_t *); | ||||||
| @ -189,6 +201,12 @@ SDKVector CallVFunction<SDKVector>(DHooksCallback *dg, HookParamsStruct *paramSt | |||||||
| 				case HookParamType_Edict: | 				case HookParamType_Edict: | ||||||
| 					PARAMINFO_SWITCH(PassType_Basic); | 					PARAMINFO_SWITCH(PassType_Basic); | ||||||
| 					VSTK_PARAM_SWITCH(edict_t *); | 					VSTK_PARAM_SWITCH(edict_t *); | ||||||
|  | 				case HookParamType_Object: | ||||||
|  | 				{ | ||||||
|  | 					void *objAddr = GetObjectAddr(HookParamType_Object, paramStruct->dg->params.at(i).flags, paramStruct->orgParams, offset); | ||||||
|  | 					PARAMINFO_SWITCH(PassType_Object); | ||||||
|  | 					VSTK_PARAM_SWITCH_OBJECT(); | ||||||
|  | 				} | ||||||
| 				default: | 				default: | ||||||
| 					PARAMINFO_SWITCH(PassType_Basic); | 					PARAMINFO_SWITCH(PassType_Basic); | ||||||
| 					VSTK_PARAM_SWITCH(void *); | 					VSTK_PARAM_SWITCH(void *); | ||||||
| @ -240,7 +258,12 @@ string_t CallVFunction<string_t>(DHooksCallback *dg, HookParamsStruct *paramStru | |||||||
| 		paramInfo = (SourceMod::PassInfo *)malloc(sizeof(SourceMod::PassInfo) * dg->params.size()); | 		paramInfo = (SourceMod::PassInfo *)malloc(sizeof(SourceMod::PassInfo) * dg->params.size()); | ||||||
| 		for(int i = 0; i < dg->params.size(); i++) | 		for(int i = 0; i < dg->params.size(); i++) | ||||||
| 		{ | 		{ | ||||||
| 			switch(dg->params.at(i).type) | 			size_t offset = GetParamOffset(paramStruct, i); | ||||||
|  | 
 | ||||||
|  | 			void *orgAddr = *(void **)((intptr_t)paramStruct->orgParams + offset); | ||||||
|  | 			void *newAddr = *(void **)((intptr_t)paramStruct->newParams + offset); | ||||||
|  | 
 | ||||||
|  | 			switch (dg->params.at(i).type) | ||||||
| 			{ | 			{ | ||||||
| 				case HookParamType_Int: | 				case HookParamType_Int: | ||||||
| 					PARAMINFO_SWITCH(PassType_Basic); | 					PARAMINFO_SWITCH(PassType_Basic); | ||||||
| @ -250,10 +273,10 @@ string_t CallVFunction<string_t>(DHooksCallback *dg, HookParamsStruct *paramStru | |||||||
| 					VSTK_PARAM_SWITCH(cell_t); | 					VSTK_PARAM_SWITCH(cell_t); | ||||||
| 				case HookParamType_Float: | 				case HookParamType_Float: | ||||||
| 					PARAMINFO_SWITCH(PassType_Float); | 					PARAMINFO_SWITCH(PassType_Float); | ||||||
| 					VSTK_PARAM_SWITCH_FLOAT(); | 					VSTK_PARAM_SWITCH(float); | ||||||
| 				case HookParamType_String: | 				case HookParamType_String: | ||||||
| 					PARAMINFO_SWITCH(PassType_Object); | 					PARAMINFO_SWITCH(PassType_Object); | ||||||
| 					VSTK_PARAM_SWITCH(int); | 					VSTK_PARAM_SWITCH(string_t); | ||||||
| 				case HookParamType_StringPtr: | 				case HookParamType_StringPtr: | ||||||
| 					PARAMINFO_SWITCH(PassType_Basic); | 					PARAMINFO_SWITCH(PassType_Basic); | ||||||
| 					VSTK_PARAM_SWITCH(string_t *); | 					VSTK_PARAM_SWITCH(string_t *); | ||||||
| @ -269,6 +292,12 @@ string_t CallVFunction<string_t>(DHooksCallback *dg, HookParamsStruct *paramStru | |||||||
| 				case HookParamType_Edict: | 				case HookParamType_Edict: | ||||||
| 					PARAMINFO_SWITCH(PassType_Basic); | 					PARAMINFO_SWITCH(PassType_Basic); | ||||||
| 					VSTK_PARAM_SWITCH(edict_t *); | 					VSTK_PARAM_SWITCH(edict_t *); | ||||||
|  | 				case HookParamType_Object: | ||||||
|  | 				{ | ||||||
|  | 					void *objAddr = GetObjectAddr(HookParamType_Object, paramStruct->dg->params.at(i).flags, paramStruct->orgParams, offset); | ||||||
|  | 					PARAMINFO_SWITCH(PassType_Object); | ||||||
|  | 					VSTK_PARAM_SWITCH_OBJECT(); | ||||||
|  | 				} | ||||||
| 				default: | 				default: | ||||||
| 					PARAMINFO_SWITCH(PassType_Basic); | 					PARAMINFO_SWITCH(PassType_Basic); | ||||||
| 					VSTK_PARAM_SWITCH(void *); | 					VSTK_PARAM_SWITCH(void *); | ||||||
|  | |||||||
| @ -44,7 +44,7 @@ DHooksManager::DHooksManager(HookSetup *setup, void *iface, IPluginFunction *rem | |||||||
| 
 | 
 | ||||||
| 	for(int i = this->callback->params.size() -1; i >= 0; i--) | 	for(int i = this->callback->params.size() -1; i >= 0; i--) | ||||||
| 	{ | 	{ | ||||||
| 		protoInfo.AddParam(this->callback->params.at(i).size, this->callback->params.at(i).pass_type, this->callback->params.at(i).flag, NULL, NULL, NULL, NULL); | 		protoInfo.AddParam(this->callback->params.at(i).size, this->callback->params.at(i).pass_type, PASSFLAG_BYVAL, NULL, NULL, NULL, NULL);//This seems like we need to do something about it at some point...
 | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if(this->callback->returnType == ReturnType_Void) | 	if(this->callback->returnType == ReturnType_Void) | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user