Guest User

main.cpp

a guest
Jun 14th, 2015
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 15.66 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. bool strEqual(char string[], char toComp[])
  8. {
  9.     int len = strlen(toComp);
  10.     char oldchar = string[len];
  11.     string[len] = '\0';
  12.     if(strcmp(string,toComp) == 0)
  13.     {
  14.         string[len] = oldchar;
  15.         return true;
  16.     }
  17.     string[len] = oldchar;
  18.     return false;
  19. }
  20.  
  21. int main()
  22. {
  23.     char sLine[1024];
  24.     char RetMsg[512];
  25.     char ByRefArgs[128];
  26.     char ByRefParams[128];
  27.     char CmdList[5120];
  28.     char DefList[5120];
  29.     char sFormat[256];
  30.     char sInclude[9][64];
  31.     strcpy(sInclude[0],"a_players.inc");
  32.     strcpy(sInclude[1],"a_objects.inc");
  33.     strcpy(sInclude[2],"a_samp.inc");
  34.     strcpy(sInclude[3],"a_vehicles.inc");
  35.     strcpy(sInclude[4],"a_actor.inc");
  36.     strcpy(sInclude[5],"float.inc");
  37.     strcpy(sInclude[6],"string.inc");
  38.     strcpy(sInclude[7],"time.inc");
  39.     FILE *fileOUT;
  40.     sprintf(sFormat,"C:/Users/admin/Desktop/SAMP (0.3.7)/filterscripts/CmdsFS.pwn");
  41.     fileOUT = fopen(sFormat,"w");
  42.     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);
  43.     for(int z = 0; z < 8; z++)
  44.     {
  45.     CmdList[0] = '\0';
  46.     DefList[0] = '\0';
  47.     FILE *fileIN;
  48.     sprintf(sFormat,"C:/Users/admin/Desktop/SAMP (0.3.7)/pawno/include/%s",sInclude[z]);
  49.     fileIN = fopen(sFormat,"r");
  50.     while(!feof(fileIN))
  51.     {
  52.         fgets(sLine,1024,fileIN);
  53.         if(feof(fileIN)) continue;
  54.         if(!strEqual(sLine,"native"))
  55.         {
  56.             if(strEqual(sLine,"#define"))
  57.             {
  58.                 char *defPointer;
  59.                 if((defPointer=strchr(sLine,'\n'))!=NULL) defPointer[0] = '\0';
  60.                 if((defPointer=strchr(sLine,'/'))!=NULL) defPointer[0] = '\0';
  61.                 defPointer = sLine + 8;
  62.                 strcat(DefList,"\\n");
  63.                 strcat(DefList,defPointer);
  64.             }
  65.             continue;
  66.         }
  67.         char *pch;
  68.         char *sFunctionName;
  69.         sFunctionName = sLine + 7;
  70.         RetMsg[0] = '\0';
  71.         strcat(RetMsg,sFunctionName);
  72.         if((pch=strchr(RetMsg,';'))!=NULL) pch[0] = '\0';
  73.         while((pch=strchr(RetMsg,'"'))!=NULL) pch[0] = '\'';
  74.         char *playeridException = sFunctionName;
  75.         while((pch=strchr(playeridException,'p'))!=NULL)
  76.         {
  77.             if(strEqual(pch,"playerid")) pch[1] = '1';
  78.             playeridException = pch+1;
  79.         }
  80.         pch=strchr(sFunctionName,')');
  81.         char *pRetMsg = strchr(RetMsg,'(');
  82.         if(pch!=NULL)
  83.         {
  84.             pch[0] = ',';
  85.             pch[1] = ' ';
  86.             pch[2] = '\0';
  87.         }
  88.         pch=strchr(sFunctionName,'(');
  89.         while(pch[1]==' ')
  90.         {
  91.             pch[0] = '\0';
  92.             pch++;
  93.         }
  94.         pch[0] = '\0';
  95.         while(sFunctionName[0]==' ') sFunctionName++;
  96.         char *sFunctionParams = pch+1;
  97.         if(strchr(sFunctionParams,'}')!=NULL)
  98.         {
  99.             fprintf(fileOUT,"//%s   (Funcion [{Float,_}:...] no soportada)\n",sFunctionName);
  100.             continue;
  101.         }
  102.         if(sFunctionParams[2] == 0)
  103.         {
  104.             fprintf(fileOUT,"   ifCMD(\"/%s\")\n    {\n     %s();\n     return 1;\n }\n",sFunctionName,sFunctionName);
  105.             strcat(CmdList,"\\n");
  106.             strcat(CmdList,sFunctionName);
  107.             continue;
  108.         }
  109.         ByRefArgs[0] = '\0';
  110.         ByRefParams[0] = '\0';
  111.         char *nextparam = sFunctionParams;
  112.         if((pch=strchr(sFunctionName,':'))!=NULL)
  113.         {
  114.             pch++;
  115.             while(pch[0]==' ') pch++;
  116.             if(strEqual(pch,"operator")) continue;
  117.             if(nextparam[0]!='&') fprintf(fileOUT," ifCMD(\"/%s\")\n    {\n     RetMsg(\"%s%s\");\n",pch,pch,pRetMsg);
  118.             else fprintf(fileOUT,"  ifCMD(\"/%s\")\n    {\n",pch);
  119.             strcat(CmdList,"\\n");
  120.             strcat(CmdList,pch);
  121.         }
  122.         else
  123.         {
  124.             if(strEqual(sFunctionName,"operator")) continue;
  125.             if(nextparam[0]!='&') fprintf(fileOUT," ifCMD(\"/%s\")\n    {\n     RetMsg(\"%s%s\");\n",sFunctionName,sFunctionName,pRetMsg);
  126.             else fprintf(fileOUT,"  ifCMD(\"/%s\")\n    {\n",sFunctionName);
  127.             strcat(CmdList,"\\n");
  128.             strcat(CmdList,sFunctionName);
  129.         }
  130.         RetMsg[0] = '\0';
  131.         while((pch=strchr(nextparam,','))!=NULL)
  132.         {
  133.             int toAdd = 2;
  134.             if(pch[1]!=' ') toAdd=1;
  135.             pch[0] = '\0';
  136.             bool flagConst = false;
  137.             if(strEqual(nextparam,"const "))
  138.             {
  139.                 nextparam+=6;
  140.                 flagConst = true;
  141.             }
  142.             char *checkType = strchr(nextparam,' ');
  143.             if(checkType!=NULL) checkType[0] = '\0';
  144.             if((checkType=strchr(nextparam,'='))!=NULL) checkType[0] = '\0';
  145.             checkType=strchr(nextparam,':');
  146.             char *isByRef=NULL;
  147.             if(checkType!=NULL)
  148.             {
  149.                 checkType[0] = '\0';
  150.                 checkType += 1;
  151.                 if((isByRef=strchr(nextparam,'&'))!=NULL)
  152.                 {
  153.                     isByRef++;
  154.                     fprintf(fileOUT,"       Set%s(%s);\n",isByRef,checkType);
  155.                     strcat(RetMsg,checkType);
  156.                     strcat(RetMsg,",");
  157.                     strcat(ByRefArgs,", ");
  158.                     strcat(ByRefArgs,checkType);
  159.                     if(strEqual(isByRef,"Float"))
  160.                     {
  161.                         strcat(ByRefArgs,"(%f)");
  162.                     }
  163.                     else
  164.                     {
  165.                         strcat(ByRefArgs,"(%i)");
  166.                         strcat(ByRefParams,"_:");
  167.                     }
  168.                     strcat(ByRefParams,checkType);
  169.                     strcat(ByRefParams,",");
  170.                 }
  171.                 else
  172.                 {
  173.                     fprintf(fileOUT,"       Get%s(%s);\n",nextparam,checkType);
  174.                     strcat(RetMsg,checkType);
  175.                     strcat(RetMsg,",");
  176.                 }
  177.             }
  178.             else
  179.             {
  180.                 checkType=strchr(nextparam,'[');
  181.                 if(checkType!=NULL)
  182.                 {
  183.                     checkType[0] = '\0';
  184.                     if(flagConst == false)
  185.                     {
  186.                         fprintf(fileOUT,"       SetString(%s);\n",nextparam);
  187.                         strcat(RetMsg,nextparam);
  188.                         strcat(RetMsg,",");
  189.                         strcat(ByRefArgs,", ");
  190.                         strcat(ByRefArgs,nextparam);
  191.                         strcat(ByRefArgs,"(%s)");
  192.                         strcat(ByRefParams,nextparam);
  193.                         strcat(ByRefParams,",");
  194.                     }
  195.                     else
  196.                     {
  197.                         fprintf(fileOUT,"       GetString(%s);\n",nextparam);
  198.                         strcat(RetMsg,nextparam);
  199.                         strcat(RetMsg,",");
  200.                     }
  201.                 }
  202.                 else
  203.                 {
  204.                     if((isByRef=strchr(nextparam,'&'))!=NULL)
  205.                     {
  206.                         isByRef++;
  207.                         fprintf(fileOUT,"       SetInt(%s);\n",isByRef);
  208.                         strcat(RetMsg,isByRef);
  209.                         strcat(RetMsg,",");
  210.                         strcat(ByRefArgs,", ");
  211.                         strcat(ByRefArgs,isByRef);
  212.                         strcat(ByRefArgs,"(%i)");
  213.                         strcat(ByRefParams,isByRef);
  214.                         strcat(ByRefParams,",");
  215.                     }
  216.                     else
  217.                     {
  218.                         fprintf(fileOUT,"       GetInt(%s);\n",nextparam);
  219.                         strcat(RetMsg,nextparam);
  220.                         strcat(RetMsg,",");
  221.                     }
  222.                 }
  223.             }
  224.             nextparam = pch+toAdd;
  225.         }
  226.         int LenRet2Msg = strlen(RetMsg) - 1;
  227.         RetMsg[LenRet2Msg] = '\0';
  228.         if((pch=strchr(sFunctionName,':'))!=NULL)
  229.         {
  230.             pch[0] = '\0';
  231.             pch++;
  232.             if(strEqual(sFunctionName,"Float"))
  233.             {
  234.                 fprintf(fileOUT,"       SendFormatMsg(\"%s(%%s)%s; Return %%f\",params,%s%s(%s));\n     return 1;\n }\n",pch,ByRefArgs,ByRefParams,pch,RetMsg);
  235.             }
  236.             else if(strEqual(sFunctionName,"String"))
  237.             {
  238.                 fprintf(fileOUT,"       SendFormatMsg(\"%s(%%s)%s; Return %%s\",params,%s%s(%s));\n     return 1;\n }\n",pch,ByRefArgs,ByRefParams,pch,RetMsg);
  239.             }
  240.             else
  241.             {
  242.                 fprintf(fileOUT,"       SendFormatMsg(\"%s(%%s)%s; Return %%i\",params,%s_:%s(%s));\n       return 1;\n }\n",pch,ByRefArgs,ByRefParams,pch,RetMsg);
  243.             }
  244.         }
  245.         else fprintf(fileOUT,"      SendFormatMsg(\"%s(%%s)%s; Return %%i\",params,%s%s(%s));\n     return 1;\n }\n",sFunctionName,ByRefArgs,ByRefParams,sFunctionName,RetMsg);
  246.     }
  247.     CmdList[0] = ' ';
  248.     char *PointerList=CmdList+2;
  249.     char *endofCmd = PointerList+strlen(CmdList);
  250.     fprintf(fileOUT,"   ifCMD(\"/%s\")\n    {\n     new CmdList[3120];\n",sInclude[z]);
  251.     char trunct[488];
  252.     do
  253.     {
  254.         strncpy(trunct,PointerList,488);
  255.         PointerList+=488;
  256.         trunct[488] = '\0';
  257.         fprintf(fileOUT,"       strcat(CmdList,\"%s\");\n",trunct);
  258.     }while(PointerList < endofCmd);
  259.     fprintf(fileOUT,"       ShowDialogFS(playerid,1,DIALOG_STYLE_LIST,\"%s\",CmdList,\"Select\",\"Close\");\n       return 1;\n }\n",sInclude[z]);
  260.     DefList[0] = ' ';
  261.     PointerList=DefList+2;
  262.     if((endofCmd=strchr(sInclude[z],'.'))!=NULL) endofCmd[0] = '\0';
  263.     endofCmd = PointerList+strlen(DefList);
  264.     fprintf(fileOUT,"   ifCMD(\"/%s.def\")\n    {\n     new DefList[3120];\n",sInclude[z]);
  265.     do
  266.     {
  267.         strncpy(trunct,PointerList,488);
  268.         PointerList+=488;
  269.         trunct[488] = '\0';
  270.         fprintf(fileOUT,"       strcat(DefList,\"%s\");\n",trunct);
  271.     }while(PointerList < endofCmd);
  272.     fprintf(fileOUT,"       ShowDialogFS(playerid,1,DIALOG_STYLE_LIST,\"%s.defines\",DefList,\"Select\",\"Close\");\n       return 1;\n }\n",sInclude[z]);
  273.     fclose(fileIN);
  274.     }
  275.     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);
  276.     fclose(fileOUT);
  277.     return 0;
  278. }
Advertisement
Add Comment
Please, Sign In to add comment