Skip to content

Instantly share code, notes, and snippets.

@m0k1
Created June 24, 2015 12:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m0k1/8cd6cdc9b81f8e8c7dbe to your computer and use it in GitHub Desktop.
Save m0k1/8cd6cdc9b81f8e8c7dbe to your computer and use it in GitHub Desktop.
Test sa-mp functions ingame. (main.cpp)
#include <stdio.h>
#include <string.h>
using namespace std;
bool strEqual(char string[], char toComp[])
{
int len = strlen(toComp);
char oldchar = string[len];
string[len] = '\0';
if(strcmp(string,toComp) == 0)
{
string[len] = oldchar;
return true;
}
string[len] = oldchar;
return false;
}
int main()
{
char sLine[1024];
char RetMsg[512];
char ByRefArgs[128];
char ByRefParams[128];
char CmdList[5120];
char DefList[5120];
char sFormat[256];
char sInclude[9][64];
strcpy(sInclude[0],"a_players.inc");
strcpy(sInclude[1],"a_objects.inc");
strcpy(sInclude[2],"a_samp.inc");
strcpy(sInclude[3],"a_vehicles.inc");
strcpy(sInclude[4],"a_actor.inc");
strcpy(sInclude[5],"float.inc");
strcpy(sInclude[6],"string.inc");
strcpy(sInclude[7],"time.inc");
FILE *fileOUT;
sprintf(sFormat,"C:/Users/admin/Desktop/SAMP (0.3.7)/filterscripts/CmdsFS.pwn");
fileOUT = fopen(sFormat,"w");
fputs("#include <a_samp>\n\n#define SendFormatMsg(%0,%1) new strformatmsg[512]; format(strformatmsg, 512, %0, %1); SendText(playerid,strformatmsg)\n#define SendFormatMsgToAll(%0,%1) new strformatmsg[512]; format(strformatmsg, 512, %0, %1); SendClientMessageToAll(-1,strformatmsg)\n#define SendFormatMsgForPlayer(%0,%1,%2) new strformatmsg[512]; format(strformatmsg, 512, %1, %2); SendText(%0,strformatmsg)\n#define ifCMD(%0) if(!strcmp(cmd, %0, true))\n#define RetMsg(%0) new RetStrMsg[512] = %0\n#define GetInt(%0) cmd = GetParameter(cmdtext, idx); if(!strlen(cmd)) return SendText(playerid, RetStrMsg); new %0 = strval(cmd)\n#define GetFloat(%0) cmd = GetParameter(cmdtext, idx); if(!strlen(cmd)) return SendText(playerid, RetStrMsg); new Float:%0 = floatstr(cmd)\n#define GetText(%0) cmd = GetParameter(cmdtext, idx); if(!strlen(cmd)) return SendText(playerid, RetStrMsg); new Text:%0 = Text:strval(cmd)\n#define GetPlayerText(%0) cmd = GetParameter(cmdtext, idx); if(!strlen(cmd)) return SendText(playerid, RetStrMsg); new PlayerText:%0 = PlayerText:strval(cmd)\n#define GetMenu(%0) cmd = GetParameter(cmdtext, idx); if(!strlen(cmd)) return SendText(playerid, RetStrMsg); new Menu:%0 = Menu:strval(cmd)\n#define GetText3D(%0) cmd = GetParameter(cmdtext, idx); if(!strlen(cmd)) return SendText(playerid, RetStrMsg); new Text3D:%0 = Text3D:strval(cmd)\n#define GetPlayerText3D(%0) cmd = GetParameter(cmdtext, idx); if(!strlen(cmd)) return SendText(playerid, RetStrMsg); new PlayerText3D:%0 = PlayerText3D:strval(cmd)\n#define GetString(%0) cmd = GetParameter(cmdtext, idx); if(!strlen(cmd)) return SendText(playerid, RetStrMsg); new %0[128]=\"\"; strcat(%0,cmd)\n#define Getfloatround_method(%0) cmd = GetParameter(cmdtext, idx); if(!strlen(cmd)) return SendText(playerid, RetStrMsg); new floatround_method:%0 = floatround_method:strval(cmd)\n#define Getanglemode(%0) cmd = GetParameter(cmdtext, idx); if(!strlen(cmd)) return SendText(playerid, RetStrMsg); new anglemode:%0 = anglemode:strval(cmd)\n#define Getbool(%0) cmd = GetParameter(cmdtext, idx); if(!strlen(cmd)) return SendText(playerid, RetStrMsg); new bool:%0 = bool:strval(cmd)\n\n#define SetInt(%0) new %0\n#define SetFloat(%0) new Float:%0\n#define SetText(%0) new Text:%0\n#define SetPlayerText(%0) new PlayerText:%0\n#define SetMenu(%0) new Menu:%0\n#define SetText3D(%0) new Text3D:%0\n#define SetPlayerText3D(%0) new PlayerText3D:%0\n#define SetString(%0) new %0[512]\n\n#define ShowDialogFS(%0) SetPVarInt(playerid,\"dialogFsFlag\",1); ShowPlayerDialog(%0)\n\npublic OnFilterScriptInit()\n{\n print(\"******************************************\\n\");\n print(\"*************(Miguel Leopold)*************\\n\");\n print(\"****************[Commands]****************\\n\");\n print(\"******************************************\\n\");\n print(\"FilterScript Loading...\\n\");\n return 1;\n}\n\npublic OnFilterScriptExit()\n{\n print(\"******************************************\\n\");\n print(\"*************(Miguel Leopold)*************\\n\");\n print(\"****************[Commands]****************\\n\");\n print(\"******************************************\\n\");\n print(\"FilterScript Unloading...\\n\");\n return 1;\n}\n\nnew Float:letterSizes[127] = {0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,\n0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,1.000000,1.000000,1.500000,1.750000,1.750000,\n0.000000,2.250000,0.752000,1.000000,1.000000,1.250000,2.000000,1.000000,1.000000,1.000000,1.000000,1.750000,1.500000,1.750000,1.750000,1.750000,1.750000,1.750000,1.750000,1.750000,\n1.750000,1.000000,1.000000,2.000000,2.000000,2.000000,2.000000,3.256410,2.250000,2.250000,2.250000,2.250000,2.000000,2.000000,2.500000,2.250000,1.000000,1.750000,2.250000,2.000000,\n2.750000,2.250000,2.520000,2.250000,2.500000,2.250000,2.250000,2.000000,2.250000,2.250000,3.256410,2.250000,2.000000,1.750000,1.000000,1.000000,1.000000,2.000000,1.750000,0.000000,\n2.000000,2.000000,1.750000,2.000000,2.000000,1.000000,2.000000,2.000000,1.000000,1.000000,1.750000,1.000000,3.000000,2.000000,2.000000,2.000000,2.000000,1.247525,1.500000,1.000000,\n2.000000,1.750000,2.739130,2.000000,1.750000,1.750000,1.247525,0.752000,1.247525,2.000000};\n\nSendText(playerid,text[])\n{\n new message[256];\n new idx;\n new msglen=0;\n new len = strlen(text);\n new Float:sum;\n while(len < 512)\n {\n sum = 0.0;\n idx = 0;\n while(sum<156.0)\n {\n if(msglen >= len)\n {\n message[idx] = 0;\n SendClientMessage(playerid,-1,message);\n return 1;\n }\n message[idx] = text[msglen];\n sum+=letterSizes[text[msglen]];\n idx++;\n msglen++;\n }\n message[idx] = 0;\n SendClientMessage(playerid,-1,message);\n }\n return 1;\n}\n\nsHexTOsInt(string[])\n{\n new lenght = strlen(string);\n new result = 0;\n new idx = 0;\n while(!(string[idx-1]=='0' && string[idx]=='x')) if((idx++)>lenght) return 0;\n lenght = idx++;\n new startToDel = idx-2;\n while((string[idx]>='A'&&string[idx]<='F')||(string[idx]>='a'&&string[idx]<='f')||(string[idx]>='0'&&string[idx]<='9')) idx++;\n while((++lenght)<idx)\n {\n switch(string[lenght])\n {\n case 'A' .. 'F': result+=(string[lenght]-55)<<((idx-1-lenght)*4);\n case 'a' .. 'f': result+=(string[lenght]-87)<<((idx-1-lenght)*4);\n case '0' .. '9': result+=(string[lenght]-48)<<((idx-1-lenght)*4);\n default: return 0;\n }\n }\n strdel(string,startToDel,lenght);\n new sTemp[64];\n valstr(sTemp,result);\n strins(string,sTemp,startToDel,128);\n sHexTOsInt(string);\n return result;\n}\n\npublic OnPlayerCommandText(playerid, cmdtext[])\n{\n sHexTOsInt(cmdtext);\n for(new i = 0; i < strlen(cmdtext); i++) if(cmdtext[i] == ')') cmdtext[i] = '\\0';\n new cmd[128], params[128], idx;\n cmd = GetParameter(cmdtext, idx);\n strmid(params,cmdtext,idx,strlen(cmdtext));\n ifCMD(\"/includes\")\n {\n ShowDialogFS(playerid,1,DIALOG_STYLE_LIST,\"Includes\",\"/a_players.inc\\n/a_objects.inc\\n/a_samp.inc\\n/a_vehicles.inc\\n/float.inc\\n/string.inc\\n/time.inc\\n/[include].def //show #defines\",\"Select\",\"Close\");\n return 1;\n }\n ifCMD(\"/[include].def\")\n {\n ShowDialogFS(playerid,1,DIALOG_STYLE_LIST,\"Includes Defines\",\"/a_players.def\\n/a_objects.def\\n/a_samp.def\\n/a_vehicles.def\\n/float.def\\n/string.def\\n/time.def\",\"Select\",\"Close\");\n return 1;\n }\n",fileOUT);
for(int z = 0; z < 8; z++)
{
CmdList[0] = '\0';
DefList[0] = '\0';
FILE *fileIN;
sprintf(sFormat,"C:/Users/admin/Desktop/SAMP (0.3.7)/pawno/include/%s",sInclude[z]);
fileIN = fopen(sFormat,"r");
while(!feof(fileIN))
{
fgets(sLine,1024,fileIN);
if(feof(fileIN)) continue;
if(!strEqual(sLine,"native"))
{
if(strEqual(sLine,"#define"))
{
char *defPointer;
if((defPointer=strchr(sLine,'\n'))!=NULL) defPointer[0] = '\0';
if((defPointer=strchr(sLine,'/'))!=NULL) defPointer[0] = '\0';
defPointer = sLine + 8;
strcat(DefList,"\\n");
strcat(DefList,defPointer);
}
continue;
}
char *pch;
char *sFunctionName;
sFunctionName = sLine + 7;
RetMsg[0] = '\0';
strcat(RetMsg,sFunctionName);
if((pch=strchr(RetMsg,';'))!=NULL) pch[0] = '\0';
while((pch=strchr(RetMsg,'"'))!=NULL) pch[0] = '\'';
char *playeridException = sFunctionName;
while((pch=strchr(playeridException,'p'))!=NULL)
{
if(strEqual(pch,"playerid")) pch[1] = '1';
playeridException = pch+1;
}
pch=strchr(sFunctionName,')');
char *pRetMsg = strchr(RetMsg,'(');
if(pch!=NULL)
{
pch[0] = ',';
pch[1] = ' ';
pch[2] = '\0';
}
pch=strchr(sFunctionName,'(');
while(pch[1]==' ')
{
pch[0] = '\0';
pch++;
}
pch[0] = '\0';
while(sFunctionName[0]==' ') sFunctionName++;
char *sFunctionParams = pch+1;
if(strchr(sFunctionParams,'}')!=NULL)
{
fprintf(fileOUT,"//%s (Funcion [{Float,_}:...] no soportada)\n",sFunctionName);
continue;
}
if(sFunctionParams[2] == 0)
{
fprintf(fileOUT," ifCMD(\"/%s\")\n {\n %s();\n return 1;\n }\n",sFunctionName,sFunctionName);
strcat(CmdList,"\\n");
strcat(CmdList,sFunctionName);
continue;
}
ByRefArgs[0] = '\0';
ByRefParams[0] = '\0';
char *nextparam = sFunctionParams;
if((pch=strchr(sFunctionName,':'))!=NULL)
{
pch++;
while(pch[0]==' ') pch++;
if(strEqual(pch,"operator")) continue;
if(nextparam[0]!='&') fprintf(fileOUT," ifCMD(\"/%s\")\n {\n RetMsg(\"%s%s\");\n",pch,pch,pRetMsg);
else fprintf(fileOUT," ifCMD(\"/%s\")\n {\n",pch);
strcat(CmdList,"\\n");
strcat(CmdList,pch);
}
else
{
if(strEqual(sFunctionName,"operator")) continue;
if(nextparam[0]!='&') fprintf(fileOUT," ifCMD(\"/%s\")\n {\n RetMsg(\"%s%s\");\n",sFunctionName,sFunctionName,pRetMsg);
else fprintf(fileOUT," ifCMD(\"/%s\")\n {\n",sFunctionName);
strcat(CmdList,"\\n");
strcat(CmdList,sFunctionName);
}
RetMsg[0] = '\0';
while((pch=strchr(nextparam,','))!=NULL)
{
int toAdd = 2;
if(pch[1]!=' ') toAdd=1;
pch[0] = '\0';
bool flagConst = false;
if(strEqual(nextparam,"const "))
{
nextparam+=6;
flagConst = true;
}
char *checkType = strchr(nextparam,' ');
if(checkType!=NULL) checkType[0] = '\0';
if((checkType=strchr(nextparam,'='))!=NULL) checkType[0] = '\0';
checkType=strchr(nextparam,':');
char *isByRef=NULL;
if(checkType!=NULL)
{
checkType[0] = '\0';
checkType += 1;
if((isByRef=strchr(nextparam,'&'))!=NULL)
{
isByRef++;
fprintf(fileOUT," Set%s(%s);\n",isByRef,checkType);
strcat(RetMsg,checkType);
strcat(RetMsg,",");
strcat(ByRefArgs,", ");
strcat(ByRefArgs,checkType);
if(strEqual(isByRef,"Float"))
{
strcat(ByRefArgs,"(%f)");
}
else
{
strcat(ByRefArgs,"(%i)");
strcat(ByRefParams,"_:");
}
strcat(ByRefParams,checkType);
strcat(ByRefParams,",");
}
else
{
fprintf(fileOUT," Get%s(%s);\n",nextparam,checkType);
strcat(RetMsg,checkType);
strcat(RetMsg,",");
}
}
else
{
checkType=strchr(nextparam,'[');
if(checkType!=NULL)
{
checkType[0] = '\0';
if(flagConst == false)
{
fprintf(fileOUT," SetString(%s);\n",nextparam);
strcat(RetMsg,nextparam);
strcat(RetMsg,",");
strcat(ByRefArgs,", ");
strcat(ByRefArgs,nextparam);
strcat(ByRefArgs,"(%s)");
strcat(ByRefParams,nextparam);
strcat(ByRefParams,",");
}
else
{
fprintf(fileOUT," GetString(%s);\n",nextparam);
strcat(RetMsg,nextparam);
strcat(RetMsg,",");
}
}
else
{
if((isByRef=strchr(nextparam,'&'))!=NULL)
{
isByRef++;
fprintf(fileOUT," SetInt(%s);\n",isByRef);
strcat(RetMsg,isByRef);
strcat(RetMsg,",");
strcat(ByRefArgs,", ");
strcat(ByRefArgs,isByRef);
strcat(ByRefArgs,"(%i)");
strcat(ByRefParams,isByRef);
strcat(ByRefParams,",");
}
else
{
fprintf(fileOUT," GetInt(%s);\n",nextparam);
strcat(RetMsg,nextparam);
strcat(RetMsg,",");
}
}
}
nextparam = pch+toAdd;
}
int LenRet2Msg = strlen(RetMsg) - 1;
RetMsg[LenRet2Msg] = '\0';
if((pch=strchr(sFunctionName,':'))!=NULL)
{
pch[0] = '\0';
pch++;
if(strEqual(sFunctionName,"Float"))
{
fprintf(fileOUT," SendFormatMsg(\"%s(%%s)%s; Return %%f\",params,%s%s(%s));\n return 1;\n }\n",pch,ByRefArgs,ByRefParams,pch,RetMsg);
}
else if(strEqual(sFunctionName,"String"))
{
fprintf(fileOUT," SendFormatMsg(\"%s(%%s)%s; Return %%s\",params,%s%s(%s));\n return 1;\n }\n",pch,ByRefArgs,ByRefParams,pch,RetMsg);
}
else
{
fprintf(fileOUT," SendFormatMsg(\"%s(%%s)%s; Return %%i\",params,%s_:%s(%s));\n return 1;\n }\n",pch,ByRefArgs,ByRefParams,pch,RetMsg);
}
}
else fprintf(fileOUT," SendFormatMsg(\"%s(%%s)%s; Return %%i\",params,%s%s(%s));\n return 1;\n }\n",sFunctionName,ByRefArgs,ByRefParams,sFunctionName,RetMsg);
}
CmdList[0] = ' ';
char *PointerList=CmdList+2;
char *endofCmd = PointerList+strlen(CmdList);
fprintf(fileOUT," ifCMD(\"/%s\")\n {\n new CmdList[3120];\n",sInclude[z]);
char trunct[488];
do
{
strncpy(trunct,PointerList,488);
PointerList+=488;
trunct[488] = '\0';
fprintf(fileOUT," strcat(CmdList,\"%s\");\n",trunct);
}while(PointerList < endofCmd);
fprintf(fileOUT," ShowDialogFS(playerid,1,DIALOG_STYLE_LIST,\"%s\",CmdList,\"Select\",\"Close\");\n return 1;\n }\n",sInclude[z]);
DefList[0] = ' ';
PointerList=DefList+2;
if((endofCmd=strchr(sInclude[z],'.'))!=NULL) endofCmd[0] = '\0';
endofCmd = PointerList+strlen(DefList);
fprintf(fileOUT," ifCMD(\"/%s.def\")\n {\n new DefList[3120];\n",sInclude[z]);
do
{
strncpy(trunct,PointerList,488);
PointerList+=488;
trunct[488] = '\0';
fprintf(fileOUT," strcat(DefList,\"%s\");\n",trunct);
}while(PointerList < endofCmd);
fprintf(fileOUT," ShowDialogFS(playerid,1,DIALOG_STYLE_LIST,\"%s.defines\",DefList,\"Select\",\"Close\");\n return 1;\n }\n",sInclude[z]);
fclose(fileIN);
}
fputs(" return 0;\n}\n\nnew isFunction;\nGetParameter(const string[], &index)\n{\n new result[128] = \"\";\n new findChar = ' ';\n if(index==0)\n {\n isFunction = 0;\n for(new i = 0; i < strlen(string); i++) if(string[i] == '(') isFunction = 2;\n }\n if(isFunction==1) findChar = ',';\n else if(isFunction==2)\n {\n isFunction=1;\n findChar = '(';\n }\n new length = strlen(string);\n new startToFind = 0;\n while(string[index] != findChar)\n {\n if(index < length)\n {\n result[startToFind] = string[index];\n index++;\n startToFind++;\n }\n else\n {\n result[startToFind] = EOS;\n return result;\n }\n }\n index++;\n result[startToFind] = EOS;\n return result;\n}\n\npublic OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])\n{\n if(GetPVarInt(playerid,\"dialogFsFlag\") == 1)\n {\n SetPVarInt(playerid,\"dialogFsFlag\",0);\n if(response)\n {\n new sCmdResponse[128] = \"\";\n if(inputtext[0] != '/')\n {\n sCmdResponse[0] = '/';\n sCmdResponse[1] = 0;\n }\n strcat(sCmdResponse,inputtext);\n OnPlayerCommandText(playerid,sCmdResponse);\n }\n return 1;\n }\n return 0;\n}\n",fileOUT);
fclose(fileOUT);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment