SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 14/02/2016, 08:48 AM   #161
maddinat0r
Gangsta
 
maddinat0r's Avatar
 
Join Date: Jun 2010
Location: Germany
Posts: 892
Reputation: 467
Default Re: Plugin development guide

Dan once made a function to push PAWN references/addresses:
Code:
int AMXAPI amx_PushAddress(AMX *amx, cell *address) 
{
	AMX_HEADER *hdr;
	unsigned char *data;
	cell xaddr;
	/* reverse relocate the address */
	assert(amx != NULL);
	hdr = (AMX_HEADER *) amx->base;
	assert(hdr != NULL);
	assert(hdr->magic == AMX_MAGIC);
	data = (amx->data != NULL) ? amx->data : amx->base + (int) hdr->dat;
	xaddr = (cell) ((unsigned char*) address-data);
	if ((ucell) xaddr >= (ucell) amx->stp) 
	{
		return AMX_ERR_MEMACCESS;
	}
	return amx_Push(amx,xaddr);
}
maddinat0r is offline   Reply With Quote
Old 14/02/2016, 12:28 PM   #162
kurta999
High-roller
 
kurta999's Avatar
 
Join Date: Apr 2009
Location: Slovakia (HU)
Posts: 1,423
Reputation: 626
Default Re: Plugin development guide

Yashas, Zeex: Thanks for help, it worked. U will see the result in next version of YSF xD

Quote:
Originally Posted by maddinat0r View Post
Dan once made a function to push PAWN references/addresses:
Code:
int AMXAPI amx_PushAddress(AMX *amx, cell *address) 
{
	AMX_HEADER *hdr;
	unsigned char *data;
	cell xaddr;
	/* reverse relocate the address */
	assert(amx != NULL);
	hdr = (AMX_HEADER *) amx->base;
	assert(hdr != NULL);
	assert(hdr->magic == AMX_MAGIC);
	data = (amx->data != NULL) ? amx->data : amx->base + (int) hdr->dat;
	xaddr = (cell) ((unsigned char*) address-data);
	if ((ucell) xaddr >= (ucell) amx->stp) 
	{
		return AMX_ERR_MEMACCESS;
	}
	return amx_Push(amx,xaddr);
}
Thanks, but function crashed for me.
__________________
I don't play and have ANY interest in SA:MP anymore! Please do not ask for help, because I'm not going to reply.
kurta999 is offline   Reply With Quote
Old 14/02/2016, 02:28 PM   #163
kurta999
High-roller
 
kurta999's Avatar
 
Join Date: Apr 2009
Location: Slovakia (HU)
Posts: 1,423
Reputation: 626
Default Re: Plugin development guide

E:

Thanks for help, result: https://github.com/kurta999/YSF/comm...d34b8ef3bda2e5
__________________
I don't play and have ANY interest in SA:MP anymore! Please do not ask for help, because I'm not going to reply.

Last edited by kurta999; 23/02/2016 at 10:20 PM.
kurta999 is offline   Reply With Quote
Old 16/03/2016, 06:59 AM   #164
DRIFT_HUNTER
High-roller
 
Join Date: Oct 2009
Posts: 2,147
Reputation: 169
Default Re: Plugin development guide

Guys could someone share snippet for calling native from C++? I would like to avoid GDK or Invoke ( i just need to call one native on plugin load and that's it )

Oh and i need to read returned data (its integer)
__________________
Путин here,
Путин there,
Путин просто everywhere.


Any PM's that include question about any kind of help will be ignored.
Use appropriate boards for that
DRIFT_HUNTER is offline   Reply With Quote
Old 16/03/2016, 07:28 AM   #165
codectile
Huge Clucker
 
codectile's Avatar
 
Join Date: Jul 2014
Posts: 306
Reputation: 116
Default Re: Plugin development guide

Here you go.

Code:
typedef cell(*AMX_NATIVE_CALL pfn_SetPlayerHealth)(AMX*, cell*);
cell AMX_NATIVE_CALL Test(AMX* amx, cell* params)
{
	pfn_SetPlayerHealth SetPlayerHealth_t = (pfn_SetPlayerHealth)0x47A6D0; //address of SetPlayerHealth native
	SetPlayerHealth_t(amx, params);
	return 1;
}
codectile is offline   Reply With Quote
Old 16/03/2016, 01:09 PM   #166
DRIFT_HUNTER
High-roller
 
Join Date: Oct 2009
Posts: 2,147
Reputation: 169
Default Re: Plugin development guide

Quote:
Originally Posted by codectile View Post
Here you go.

Code:
typedef cell(*AMX_NATIVE_CALL pfn_SetPlayerHealth)(AMX*, cell*);
cell AMX_NATIVE_CALL Test(AMX* amx, cell* params)
{
	pfn_SetPlayerHealth SetPlayerHealth_t = (pfn_SetPlayerHealth)0x47A6D0; //address of SetPlayerHealth native
	SetPlayerHealth_t(amx, params);
	return 1;
}
Oh hell no! No memory addresses, whole idea is to automatize hooking process...Guess i will have to make public inside include and call it instead of native itself...
__________________
Путин here,
Путин there,
Путин просто everywhere.


Any PM's that include question about any kind of help will be ignored.
Use appropriate boards for that
DRIFT_HUNTER is offline   Reply With Quote
Old 21/06/2016, 01:23 PM   #167
Yashas
Gangsta
 
Join Date: Jun 2012
Location: India
Posts: 866
Reputation: 295
Default Re: Plugin development guide

Code:
new str2[] = "test string two, STRING TWO_2 !TWO!";
new str3[35];
strncpy(str3, str2, 10);
print(str3);
Code:
cell AMX_NATIVE_CALL string_strncpy(AMX amx, cell params)
 {
  cell* dest = NULL;
		cell* source = NULL;

		amx_GetAddr(amx, params[1], &dest);
		amx_GetAddr(amx, params[2], &source);

		int num = static_cast<int>(params[3]);
		unsigned int size_dest = static_cast<unsigned int>(params[4]);
		unsigned int size_src = static_cast<unsigned int>(params[5]);

		while (num-- && size_dest-- && size_src--) {
			logprintf("%c", *(source));
			*dest++ = *source++;
		}
		*dest = 0;
		return 0;
 }
Code:
[18:40:19]  <------- NOTHING HERE wtf?
[18:40:19] e
[18:40:19] s
[18:40:19] t
[18:40:19]  
[18:40:19] s
[18:40:19] t
[18:40:19] r
[18:40:19] i
[18:40:19] n
[18:40:19] (null)
If I increase the str3 size to 36 (or more than 36), I get
Code:
[18:40:00] t
[18:40:00] e
[18:40:00] s
[18:40:00] t
[18:40:00]  
[18:40:00] s
[18:40:00] t
[18:40:00] r
[18:40:00] i
[18:40:00] n
[18:40:00] test strin
Code:
native strncpy(destination[], const source[], num, sizedest = sizeof(destination),  sizesrc = sizeof(source));
What does the array size got to do here? -_-
Yashas is offline   Reply With Quote
Old 21/06/2016, 01:59 PM   #168
vannesenn
Gangsta
 
vannesenn's Avatar
 
Join Date: Feb 2011
Posts: 662
Reputation: 15
Default Re: Plugin development guide

Is possible to make gamemode as plugin(s) ?
vannesenn is offline   Reply With Quote
Old 21/06/2016, 02:05 PM   #169
codectile
Huge Clucker
 
codectile's Avatar
 
Join Date: Jul 2014
Posts: 306
Reputation: 116
Default Re: Plugin development guide

Yashas, convert the strings from pawn to C/++ format.
vannesenn, see sampGDK by Zeex.
codectile is offline   Reply With Quote
Old 21/06/2016, 02:34 PM   #170
Yashas
Gangsta
 
Join Date: Jun 2012
Location: India
Posts: 866
Reputation: 295
Default Re: Plugin development guide

Quote:
Originally Posted by codectile View Post
Yashas, convert the strings from pawn to C/++ format.
vannesenn, see sampGDK by Zeex.
Why is it needed? PAWN cell is 4 bytes and only the first byte stores the character. So copying characters should be same as copying cells?
Yashas is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SA-MP 0.3c in development Kalcor News and Updates 889 19/09/2014 04:39 PM
0.3b Development bar gone WackoX General 94 02/08/2010 10:17 PM
A guide to install Jacob's IRC plugin? Celson Server Support 5 09/06/2009 07:06 AM


All times are GMT. The time now is 01:58 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.