Esempio n. 1
0
cell Call_Void_Vector_Entvar_Entvar_Float_Int_Int(AMX *amx, cell *params)
{
	SETUP(6);

	Vector v3;

	float *fl3=(float *)MF_GetAmxAddr(amx, params[3]);
	v3.x=fl3[0];
	v3.y=fl3[1];
	v3.z=fl3[2];

	int id4=*MF_GetAmxAddr(amx, params[4]);
	int id5=*MF_GetAmxAddr(amx, params[5]);
	float f6=amx_ctof2(*MF_GetAmxAddr(amx, params[6]));
	int i7=*MF_GetAmxAddr(amx, params[7]);
	int i8=*MF_GetAmxAddr(amx, params[8]);

	CHECK_ENTITY(id4);
	CHECK_ENTITY(id5);

	entvars_t *ev4=&(INDEXENT_NEW(id4)->v);
	entvars_t *ev5=&(INDEXENT_NEW(id5)->v);

#if defined(_WIN32)
	reinterpret_cast<void (__fastcall *)(void *, int, Vector, entvars_t *, entvars_t *, float, int, int)>(__func)(pv, 0, v3, ev4, ev5, f6, i7, i8);
#elif defined(__linux__) || defined(__APPLE__)
	reinterpret_cast<void (*)(void *, Vector, entvars_t *, entvars_t *, float, int, int)>(__func)(pv, v3, ev4, ev5, f6, i7, i8);
#endif

	return 1;
}
Esempio n. 2
0
cell Call_Void_Entvar_Float_Vector_Trace_Int(AMX *amx, cell *params)
{
	SETUP(5);

	int id3=*MF_GetAmxAddr(amx, params[3]);
	float f4=amx_ctof2(*MF_GetAmxAddr(amx, params[4]));
	Vector v5;
	TraceResult *tr6=reinterpret_cast<TraceResult *>(*MF_GetAmxAddr(amx, params[6]));
	int i7=*MF_GetAmxAddr(amx, params[7]);

	float *fl5=(float *)MF_GetAmxAddr(amx, params[5]);
	v5.x=fl5[0];
	v5.y=fl5[1];
	v5.z=fl5[2];

	if (tr6==NULL)
	{
		MF_LogError(amx, AMX_ERR_NATIVE, "Null traceresult provided.");

		return 0;
	}

	CHECK_ENTITY(id3);

	entvars_t *ev3=&(INDEXENT_NEW(id3)->v);
#if defined(_WIN32)
	reinterpret_cast<void (__fastcall *)(void *, int, entvars_t *, float, Vector, TraceResult *, int)>(__func)(pv, 0, ev3, f4, v5, tr6, i7);
#elif defined(__linux__) || defined(__APPLE__)
	reinterpret_cast<void (*)(void *, entvars_t *, float, Vector, TraceResult *, int)>(__func)(pv, ev3, f4, v5, tr6, i7);
#endif

	return 1;
}
Esempio n. 3
0
cell Call_Int_Cbase_pVector(AMX *amx, cell *params)
{
	SETUP(2);

	int id3=*MF_GetAmxAddr(amx, params[3]);
	CHECK_ENTITY(id3);
	void *pv1=(INDEXENT_NEW(id3)->pvPrivateData);

	Vector v4;
	float *fl4=(float *)MF_GetAmxAddr(amx, params[4]);
	v4.x=fl4[0];
	v4.y=fl4[1];
	v4.z=fl4[2];

#if defined(_WIN32)
	int ret = reinterpret_cast<int (__fastcall *)(void*, int, void *, Vector *)>(__func)(pv, 0, pv1, &v4);
#elif defined(__linux__) || defined(__APPLE__)
	int ret = reinterpret_cast<int (*)(void *, void *, Vector *)>(__func)(pv, pv1, &v4);
#endif

	fl4[0]=v4.x;
	fl4[1]=v4.y;
	fl4[2]=v4.z;

	return ret;
}
Esempio n. 4
0
cell Call_Int_Entvar_Entvar_Float_Int(AMX *amx, cell *params)
{
	SETUP(4);

	int id3=*MF_GetAmxAddr(amx, params[3]);
	int id4=*MF_GetAmxAddr(amx, params[4]);
	float f5=amx_ctof2(*MF_GetAmxAddr(amx, params[5]));
	int i6=*MF_GetAmxAddr(amx, params[6]);

	CHECK_ENTITY(id3);
	CHECK_ENTITY(id4);

	entvars_t *ev3=&(INDEXENT_NEW(id3)->v);
	entvars_t *ev4=&(INDEXENT_NEW(id4)->v);

#if defined(_WIN32)
	return reinterpret_cast<int (__fastcall *)(void *, int, entvars_t *, entvars_t *, float, int)>(__func)(pv, 0, ev3, ev4, f5, i6);
#elif defined(__linux__) || defined(__APPLE__)
	return reinterpret_cast<int (*)(void *, entvars_t *, entvars_t *, float, int)>(__func)(pv, ev3, ev4, f5, i6);
#endif
}
Esempio n. 5
0
cell Call_Void_Entvar_Entvar_Int(AMX *amx, cell *params)
{
	SETUP(3);

	int id3=*MF_GetAmxAddr(amx, params[3]);
	int id4=*MF_GetAmxAddr(amx, params[4]);
	int i5=*MF_GetAmxAddr(amx, params[5]);

	CHECK_ENTITY(id3);
	CHECK_ENTITY(id4);

	entvars_t *ev3=&(INDEXENT_NEW(id3)->v);
	entvars_t *ev4=&(INDEXENT_NEW(id4)->v);

#if defined(_WIN32)
	reinterpret_cast<void (__fastcall *)(void*, int, entvars_t *, entvars_t *, int)>(__func)(pv, 0, ev3, ev4, i5);
#elif defined(__linux__) || defined(__APPLE__)
	reinterpret_cast<void (*)(void *, entvars_t *, entvars_t *, int)>(__func)(pv, ev3, ev4, i5);
#endif
	return 1;
}
Esempio n. 6
0
cell Call_Bool_Cbase(AMX *amx, cell *params)
{
	SETUP(1);

	int id3=*MF_GetAmxAddr(amx, params[3]);
	CHECK_ENTITY(id3);
	void *pv1=(INDEXENT_NEW(id3)->pvPrivateData);

#if defined(_WIN32)
	return reinterpret_cast<bool (__fastcall *)(void*, int, void*)>(__func)(pv, 0, pv1);
#elif defined(__linux__) || defined(__APPLE__)
	return reinterpret_cast<bool (*)(void *, void*)>(__func)(pv, pv1);
#endif
}
Esempio n. 7
0
cell Call_Int_Entvar(AMX *amx, cell *params)
{
	SETUP(1);

	int id3=*MF_GetAmxAddr(amx, params[3]);

	CHECK_ENTITY(id3);

	entvars_t *ev3=&(INDEXENT_NEW(id3)->v);

#if defined(_WIN32)
	return reinterpret_cast<int (__fastcall *)(void *, int, entvars_t *)>(__func)(pv, 0, ev3);
#elif defined(__linux__) || defined(__APPLE__)
	return reinterpret_cast<int (*)(void *, entvars_t *)>(__func)(pv, ev3);
#endif
}
Esempio n. 8
0
cell Call_Void_Edict(AMX *amx, cell *params)
{
	SETUP(1);

	int id3=*MF_GetAmxAddr(amx, params[3]);
	CHECK_ENTITY(id3);

	edict_t *ed3=INDEXENT_NEW(id3);

#if defined(_WIN32)
	reinterpret_cast<int (__fastcall *)(void*, int, edict_t *)>(__func)(pv, 0, ed3);
#elif defined(__linux__) || defined(__APPLE__)
	reinterpret_cast<int (*)(void *, edict_t *)>(__func)(pv, ed3);
#endif

	return 1;
}
Esempio n. 9
0
cell Call_Int_Cbase_Bool(AMX *amx, cell *params)
{
	SETUP(2);

	int id3=*MF_GetAmxAddr(amx, params[3]);

	CHECK_ENTITY(id3);

	void *pv1=(INDEXENT_NEW(id3)->pvPrivateData);

	bool b4=*MF_GetAmxAddr(amx, params[4]) ? true : false;

#if defined(_WIN32)
	return reinterpret_cast<int (__fastcall *)(void*, int, void *, bool)>(__func)(pv, 0, pv1, b4);
#elif defined(__linux__) || defined(__APPLE__)
	return reinterpret_cast<int (*)(void *, void *, bool)>(__func)(pv, pv1, b4);
#endif
}
Esempio n. 10
0
/**
 * Converts a log string (eg: "sawce<1><STEAM_0:1:4560311><marine1team>")
 * into a player index
 */
int UTIL_LogToIndex(const char *LogLine)
{
	char				 NameBuffer[33]	;	// Temporary buffer to store the CID String
	char				*StrLocation;		// Location in the LogLine pointer
	unsigned int		 Count=0;			// Count for how many <'s we've passed
	size_t				 Length;			// Length of LogLine

	Length=strlen(LogLine);
	StrLocation=const_cast<char *>(LogLine) + Length; // Should now point to the last >

	while (Length--)
	{
		if (*StrLocation--=='<')
		{
			if (++Count==3) // 3rd match is end of CID
			{
				break;
			}
		}
	}

	if (Count!=3) // Invalid name somehow??
	{
		return 0;
	}

	if (Length > 32) // The name is too long somehow? stop here...
	{
		return 0;
	}
	strncpy(NameBuffer,LogLine,Length);

	Count=0;

	while ((int)Count++<gpGlobals->maxClients)
	{
		if (strcmp(NameBuffer,STRING(INDEXENT_NEW(Count)->v.netname))==0)
		{
			return Count;
		}
	}

	return 0;
}
Esempio n. 11
0
cell Call_Void_Entvar_Float_Float(AMX *amx, cell *params)
{
	SETUP(3);

	int id3=*MF_GetAmxAddr(amx, params[3]);
	float f4=amx_ctof2(*MF_GetAmxAddr(amx, params[4]));
	float f5=amx_ctof2(*MF_GetAmxAddr(amx, params[5]));

	CHECK_ENTITY(id3);

	entvars_t *ev3=&(INDEXENT_NEW(id3)->v);

#if defined(_WIN32)
	reinterpret_cast<void (__fastcall *)(void *, int, entvars_t *, float, float)>(__func)(pv, 0, ev3, f4, f5);
#elif defined(__linux__) || defined(__APPLE__)
	reinterpret_cast<void (*)(void *, entvars_t *, float, float)>(__func)(pv, ev3, f4, f5);
#endif

	return 1;
}
// RegisterHamFromEntity(Ham:function, EntityId, const Callback[], Post=0);
static cell AMX_NATIVE_CALL RegisterHamFromEntity(AMX *amx, cell *params)
{
	// Make sure the function we're requesting is within bounds
	int func=params[1];
	int post=params[4];

	CHECK_FUNCTION(func);

	char *function=MF_GetAmxString(amx, params[3], 0, NULL);
	int entid=params[2];
	char classname[64];
	
	// Check the entity

	edict_t *Entity=INDEXENT_NEW(entid);


	if (Entity->pvPrivateData == NULL)
	{

		MF_LogError(amx, AMX_ERR_NATIVE,"Failed to retrieve classtype for entity id \"%d\", hook for \"%s\" not active.",entid,function);

		return 0;
	}
	void **vtable=GetVTable(Entity->pvPrivateData, Offsets.GetBase());


	if (vtable == NULL)
	{
		MF_LogError(amx, AMX_ERR_NATIVE,"Failed to retrieve vtable for entity id \"%d\", hook for \"%s\" not active.",entid,function);

		return 0;
	}

	// Verify that the function is valid
	// Don't fail the plugin if this fails, just emit a normal error
	int fwd=hooklist[func].makefunc(amx, function);

	if (fwd == -1)
	{
		MF_LogError(amx, AMX_ERR_NATIVE, "Function %s not found.", function);

		return 0;
	}

	// We've passed all tests...

	int **ivtable=(int **)vtable;

	void *vfunction=(void *)ivtable[hooklist[func].vtid];

	// Check the list of this function's hooks, see if the function we have is a hook

	CVector<Hook *>::iterator end=hooks[func].end();
	for (CVector<Hook *>::iterator i=hooks[func].begin();
		 i!=end;
		 ++i)
	{
		if ((*i)->tramp == vfunction)
		{
			// Yes, this function is hooked
			Forward *pfwd=new Forward(fwd);
			if (post)
			{
				(*i)->post.push_back(pfwd);
			}
			else
			{
				(*i)->pre.push_back(pfwd);
			}
			return reinterpret_cast<cell>(pfwd);
		}
	}

	// Note down the classname for the given class
	// It may very well be wrong (such as lots of TS weapons have the same classname)
	// but it's the best we can do, and better than nothing.
	// (only used for display)
	snprintf(classname, sizeof(classname) - 1, "%s", STRING(Entity->v.classname));

	// If we got here, the function is not hooked
	Hook *hook=new Hook(vtable, hooklist[func].vtid, hooklist[func].targetfunc, hooklist[func].isvoid, hooklist[func].paramcount, classname);
	hooks[func].push_back(hook);

	Forward *pfwd=new Forward(fwd);
	if (post)
	{
		hook->post.push_back(pfwd);
	}
	else
	{
		hook->pre.push_back(pfwd);
	}

	return reinterpret_cast<cell>(pfwd);
}
Esempio n. 13
0
// ns_find_weapon_offset(idPlayer,"primweapon","lastinvweapon")
static cell AMX_NATIVE_CALL ns_find_weapon_offset(AMX *amx, cell *params)
{
	char *SPrimWeapon=MF_GetAmxString(amx,params[2],0,NULL);
	char *SLastInv=MF_GetAmxString(amx,params[3],1,NULL);
	edict_t *ePlayer=INDEXENT_NEW(params[1]);

	// Locate entities by name
	edict_t *PrimWeapon=NULL;
	edict_t *LastInv=NULL;

	edict_t *Temp=NULL;

	while ((Temp=UTIL_FindEntityByString(Temp,"classname",SPrimWeapon))!=NULL)
	{
		if (Temp->v.owner==ePlayer)
		{
			PrimWeapon=Temp;
			break;
		}
	}
	Temp=NULL;
	while ((Temp=UTIL_FindEntityByString(Temp,"classname",SLastInv))!=NULL)
	{
		if (Temp->v.owner==ePlayer)
		{
			LastInv=Temp;
			break;
		}
	}

	if (LastInv == NULL || PrimWeapon == NULL)
	{
		if (LastInv==NULL)
		{
			MF_Log("LastInv==NULL");
		}
		if (PrimWeapon==NULL)
		{
			MF_Log("PrimWeapon=NULL");
		}
		return 0;
	}

	// now iterate through the client's private data until we find the pointer to PrimWeapon/LastInv's offset
	unsigned int *Ptr=(unsigned int*)ePlayer->pvPrivateData;

	int FoundLastInv=0;
	int FoundPrim=0;
	size_t count=0;
	unsigned int iPrim;
	unsigned int iLast;

	// so nasty D: this is basically horrible_cast
	union bleh
	{
		void *ptr;
		unsigned int ival;
	}blah;
	
	blah.ptr=PrimWeapon->pvPrivateData;
	iPrim=blah.ival;

	blah.ptr=LastInv->pvPrivateData;
	iLast=blah.ival;

	while (count<4000)
	{
		if (*Ptr==iLast)
		{
			MF_Log("Found LastInv: %d",count);
			FoundLastInv=1;
		}
		if (*Ptr==iPrim)
		{
			MF_Log("Found Primary: %d",count);
			FoundPrim=1;
		}

		if (FoundLastInv && FoundPrim)
		{
			//break;
		}
		count+=4;
		Ptr++;
	}
	return 1;
}
Esempio n. 14
0
entvars_t *IndexToEntvar(int index)
{
	return &(INDEXENT_NEW(index)->v);
};
Esempio n. 15
0
void *IndexToPrivate(int index)
{
	return INDEXENT_NEW(index)->pvPrivateData;
};