fork download
  1. //in some program
  2.  
  3. int AMXAPI amx_GetAddr(AMX *amx,cell amx_addr,cell **phys_addr)
  4. {
  5. AMX_HEADER *hdr;
  6. unsigned char *data;
  7.  
  8. assert(amx!=NULL);
  9. hdr=(AMX_HEADER *)amx->base;
  10. assert(hdr!=NULL);
  11. assert(hdr->magic==AMX_MAGIC);
  12. data=(amx->data!=NULL) ? amx->data : amx->base+(int)hdr->dat;
  13.  
  14. assert(phys_addr!=NULL);
  15. if (amx_addr>=amx->hea && amx_addr<amx->stk || amx_addr<0 || amx_addr>=amx->stp) {
  16. *phys_addr=NULL;
  17. return AMX_ERR_MEMACCESS;
  18. } /* if */
  19.  
  20. *phys_addr=(cell *)(data + (int)amx_addr);
  21. return AMX_ERR_NONE;
  22. }
  23.  
  24. // native GetPlayerPos(playerid, &Float:x, &Float:y, &Float:z)
  25. static cell AMX_NATIVE_CALL n_GetPlayerPos(AMX *amx, cell *params)
  26. {
  27. CHECK_PARAMS(4);//check if params[0] = 4*4 (4*sizeof(cell))
  28.  
  29. cell* cptr;//a pointer
  30. amx_GetAddr(amx, params[2], &cptr);//get address of params[2]
  31. *cptr = amx_ftoc(pPlayer->m_vecPos.X);//set params[2]
  32. amx_GetAddr(amx, params[3], &cptr);//etc
  33. *cptr = amx_ftoc(pPlayer->m_vecPos.Y);
  34. amx_GetAddr(amx, params[4], &cptr);
  35. *cptr = amx_ftoc(pPlayer->m_vecPos.Z);
  36. return 1;
  37. }
  38.  
  39. //My DLL:
  40.  
  41. ///////////////////////////////////////////////////////
  42. // From "amx.c", part of the PAWN language runtime:
  43. // http://code.google.com/p/pawnscript/source/browse/trunk/amx/amx.c
  44.  
  45. ucell GetPlayerPosAddress = NULL;
  46. cell GetPlayerPosPositionData[6] = {4*sizeof(cell),NULL,NULL,NULL,NULL,NULL};
  47. AMX FakeAMX;
  48.  
  49. #define USENAMETABLE(hdr) \
  50.   ((hdr)->defsize==sizeof(AMX_FUNCSTUBNT))
  51.  
  52. #define NUMENTRIES(hdr,field,nextfield) \
  53. (unsigned)(((hdr)->nextfield - (hdr)->field) / (hdr)->defsize)
  54.  
  55. #define GETENTRY(hdr,table,index) \
  56. (AMX_FUNCSTUB *)((unsigned char*)(hdr) + (unsigned)(hdr)->table + (unsigned)index*(hdr)->defsize)
  57.  
  58. #define GETENTRYNAME(hdr,entry) \
  59. (USENAMETABLE(hdr) ? \
  60. (char *)((unsigned char*)(hdr) + (unsigned)((AMX_FUNCSTUBNT*)(entry))->nameofs) : \
  61. ((AMX_FUNCSTUB*)(entry))->name)
  62.  
  63. typedef ucell AMX_NATIVE_CALL n_GetPlayerPos( AMX* amx, cell* params );//call to the function in program
  64. n_GetPlayerPos* func_GetPlayerPos = NULL;//the function call addr
  65.  
  66. int GetPlayerPos(int playerid,float *x,float *y,float *z)
  67. {
  68. GetPlayerPosPositionData[0] = 4*sizeof(cell);
  69. GetPlayerPosPositionData[1] = playerid;
  70. func_GetPlayerPos(&FakeAMX,GetPlayerPosPositionData);
  71. std::cout << (float)amx_ctof(GetPlayerPosPositionData[3]) << std::endl;
  72. std::cout << (float)amx_ctof(GetPlayerPosPositionData[4]) << std::endl;
  73. std::cout << (float)amx_ctof(GetPlayerPosPositionData[5]) << std::endl;
  74. *x = amx_ctof(GetPlayerPosPositionData[3]);
  75. *y = amx_ctof(GetPlayerPosPositionData[4]);
  76. *z = amx_ctof(GetPlayerPosPositionData[5]);
  77. return 1;
  78. }
  79. ///////////////////////////////////////////////////////
  80.  
  81. PLUGIN_EXPORT int PLUGIN_CALL AmxLoad( AMX *amx )
  82. {
  83. //Code from sscanf2.5, [PAWN]SSCANF Author: Y_Less
  84. int
  85. num,
  86. idx;
  87. // Operate on the raw AMX file, don't use the amx_ functions to avoid issues
  88. // with the fact that we've not actually finished initialisation yet. Based
  89. // VERY heavilly on code from "amx.c" in the PAWN runtime library.
  90. AMX_HEADER *
  91. hdr = (AMX_HEADER *)amx->base;
  92. AMX_FUNCSTUB *
  93. func;
  94. num = NUMENTRIES(hdr, natives, libraries);
  95. for (idx = 0; idx != num; ++idx)
  96. {
  97. func = GETENTRY(hdr, natives, idx);
  98. if (!strcmp("GetPlayerPos", GETENTRYNAME(hdr, func)))
  99. {
  100. GetPlayerPosAddress = func->address;//set adress
  101. FakeAMX = *amx;//create a copy of a valid AMX
  102. FakeAMX.data = (unsigned char*)sizeof(cell);//edit the AMX to point to our data
  103. func_GetPlayerPos = (n_GetPlayerPos*)GetPlayerPosAddress;//assign the function address
  104. break;
  105. }
  106. }
  107. //end sscanf cut
  108. return 1;
  109. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty