Advertisement
Guest User

Importer

a guest
Apr 16th, 2016
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 13.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <float.h>
  3. #include <math.h>
  4. #include <fstream>
  5. #include <conio.h>
  6. #include <stdlib.h>
  7. #include <time.h>
  8.  
  9. using namespace std;
  10.  
  11. int hasIPLsameIDEID (int iplID);
  12. int GetTotalLinesFromAFile (string _file);
  13.  
  14. struct InternalIDEData
  15. {
  16.     int ID;
  17.     int oID;
  18.     char DFF[256];
  19.     char TXD[256];
  20.     int idk;
  21.     int idk_2;
  22. };
  23.  
  24. struct InternalIPLData
  25. {
  26.     bool assigned = false;
  27.     int ID;
  28.     char Object[256];
  29.     float x;
  30.     float y;
  31.     float z;
  32.     float rx;
  33.     float ry;
  34.     float rz;
  35.     int idk;
  36.     float idk_2;
  37.     int idk_3;
  38. };
  39.  
  40. struct MapData
  41. {
  42.     string IDE_name;
  43.     string IPL_name;
  44.  
  45.     string IDE_temp;
  46.     string IPL_temp;
  47.  
  48.     int ModelStart = 0;
  49.  
  50.     InternalIDEData IDE_data[1024];
  51.     InternalIPLData IPL_data[1024];
  52.  
  53.     ifstream IDE;
  54.     ifstream IPL;
  55.  
  56.     FILE* replaceFile;
  57.     FILE* mapFile;
  58.     FILE* unassignedIPL;
  59.     FILE* meta;
  60. };
  61.  
  62. MapData mapFiles[10];
  63.  
  64. int IDEF = 0;
  65. int IPLF = 0;
  66. FILE* logfile;
  67.  
  68. int main()
  69. {
  70.     srand(time(0));
  71.     system ("color A");
  72.  
  73.     cout<<"Type IDE name: ";
  74.     getline (cin, mapFiles[0].IDE_name);
  75.  
  76.     cout<<"Type IPL name: ";
  77.     getline (cin, mapFiles[0].IPL_name);
  78.  
  79.     mapFiles[0].IDE.open ((mapFiles[0].IDE_name+".ide").c_str());
  80.     mapFiles[0].IPL.open ((mapFiles[0].IPL_name+".ipl").c_str());
  81.  
  82.     cout<<"Choose a model to start counting: ";
  83.     cin>>mapFiles[0].ModelStart;
  84.  
  85.     logfile = fopen ("log.txt", "w");
  86.  
  87.     //int IDELines = GetTotalLinesFromAFile(mapFiles[0].IDE_name+".ide");
  88.     //int IPLLines = GetTotalLinesFromAFile(mapFiles[0].IPL_name+".ipl");
  89.  
  90.     printf ("Getting IDE data...\n");
  91.  
  92.     while (getline(mapFiles[0].IDE, mapFiles[0].IDE_temp))
  93.     {
  94.         if (sscanf (mapFiles[0].IDE_temp.c_str(), "%i , %s , %s , %i , %i",
  95.                    &mapFiles[0].IDE_data[IDEF].oID,
  96.                    &mapFiles[0].IDE_data[IDEF].DFF,
  97.                    &mapFiles[0].IDE_data[IDEF].TXD,
  98.                    &mapFiles[0].IDE_data[IDEF].idk,
  99.                    &mapFiles[0].IDE_data[IDEF].idk_2))
  100.         {
  101.             mapFiles[0].IDE_data[IDEF].ID = mapFiles[0].ModelStart;
  102.  
  103.             fprintf (logfile, "Getting IDE Data... Original ID: %i - Modified ID: %i - Model Name: %s - Texture name: %s\n", mapFiles[0].IDE_data[IDEF].oID,
  104.                                                                                                                              mapFiles[0].IDE_data[IDEF].ID,
  105.                                                                                                                              mapFiles[0].IDE_data[IDEF].DFF,
  106.                                                                                                                              mapFiles[0].IDE_data[IDEF].TXD);
  107.             IDEF ++;
  108.             mapFiles[0].ModelStart++;
  109.             Sleep (rand() % 10 + 5);
  110.         }
  111.     }
  112.     printf ("IDE Data Successfully Acquired!...\n\n");
  113.  
  114.     printf ("Getting IPL data...\n");
  115.     while (getline(mapFiles[0].IPL, mapFiles[0].IPL_temp))
  116.     {
  117.         if (sscanf (mapFiles[0].IPL_temp.c_str(), "%i , %s , %i , %f , %f , %f , %f , %f , %f , %f , %i",
  118.                    &mapFiles[0].IPL_data[IPLF].ID,
  119.                    &mapFiles[0].IPL_data[IPLF].Object,
  120.                    &mapFiles[0].IPL_data[IPLF].idk,
  121.                    &mapFiles[0].IPL_data[IPLF].x,
  122.                    &mapFiles[0].IPL_data[IPLF].y,
  123.                    &mapFiles[0].IPL_data[IPLF].z,
  124.                    &mapFiles[0].IPL_data[IPLF].rx,
  125.                    &mapFiles[0].IPL_data[IPLF].ry,
  126.                    &mapFiles[0].IPL_data[IPLF].rz,
  127.                    &mapFiles[0].IPL_data[IPLF].idk_2,
  128.                    &mapFiles[0].IPL_data[IPLF].idk_3))
  129.         {
  130.             int iplIDFix = hasIPLsameIDEID(mapFiles[0].IPL_data[IPLF].ID);
  131.             if (iplIDFix > 0)
  132.             {
  133.                 mapFiles[0].IPL_data[IPLF].ID = iplIDFix;
  134.                 mapFiles[0].IPL_data[IPLF].assigned = true;
  135.             }
  136.             fprintf (logfile, "Getting IPL Data... ID: %i - Object Name: %s - Assigned: %i\n", mapFiles[0].IPL_data[IPLF].ID,
  137.                                                                                                mapFiles[0].IPL_data[IPLF].Object,
  138.                                                                                                mapFiles[0].IPL_data[IPLF].assigned);
  139.             IPLF ++;
  140.         }
  141.         Sleep (rand() % 10 + 5);
  142.     }
  143.     printf ("IPL Data Successfully Acquired!...\n\n");
  144.  
  145.     mapFiles[0].IDE.close ();
  146.     mapFiles[0].IPL.close ();
  147.  
  148.     /// CREATE NEW FILES
  149.     /// CREATE NEW FILES
  150.  
  151.     mapFiles[0].replaceFile = fopen ("engine.lua", "w");
  152.     mapFiles[0].mapFile = fopen ("map.lua", "w");
  153.     mapFiles[0].unassignedIPL = fopen ("IPLObjects_Unassigned.lua", "w");
  154.     mapFiles[0].meta = fopen ("meta.xml", "w");
  155.  
  156.     ///REPLACING FILE
  157.     ///REPLACING FILE
  158.  
  159.     printf ("Creating file (engine.lua)...\n");
  160.     fprintf (logfile, "Creating files (engine.lua)...\n");
  161.     fprintf (mapFiles[0].replaceFile, "data = \n");
  162.     fprintf (mapFiles[0].replaceFile, "{\n");
  163.     for (int a = 0; a < IDEF; a++)
  164.     {
  165.             fprintf (mapFiles[0].replaceFile, "\t{id=%i, name='%s', texture='%s', useCol=%s, lod=%i},\n", mapFiles[0].IDE_data[a].ID,
  166.                                                                                                           mapFiles[0].IDE_data[a].DFF,
  167.                                                                                                           mapFiles[0].IDE_data[a].TXD,
  168.                                                                                                           "true",
  169.                                                                                                           mapFiles[0].IDE_data[a].ID);
  170.         Sleep (rand() % 10 + 5);
  171.     }
  172.     fprintf (mapFiles[0].replaceFile, "}\n\n");    fprintf (mapFiles[0].replaceFile, "function %s ()\n", mapFiles[0].IDE_name.c_str());
  173.     fprintf (mapFiles[0].replaceFile, "\tfor key, v in ipairs (data) do\n");
  174.     fprintf (mapFiles[0].replaceFile, "\t\tif engineImportTXD ( engineLoadTXD (':Graphics/txd/'..(v.texture)..'.txd'), v.id ) then\n");
  175.     fprintf (mapFiles[0].replaceFile, "\t\t\tengineReplaceModel ( engineLoadDFF (':Graphics/dff/'..(v.name)..'.dff', v.id ), v.id )\n");
  176.     fprintf (mapFiles[0].replaceFile, "\t\t\tif v.useCol == true then\n");
  177.     fprintf (mapFiles[0].replaceFile, "\t\t\t\tengineReplaceCOL ( engineLoadCOL (':Graphics/col/'..(v.name)..'.col', v.id ), v.id )\n");
  178.     fprintf (mapFiles[0].replaceFile, "\t\t\tend\n");
  179.     fprintf (mapFiles[0].replaceFile, "\t\telse\n");
  180.     fprintf (mapFiles[0].replaceFile, "\t\t\tengineImportTXD ( engineLoadTXD (':Graphics/txd/'..(v.texture)..'.txd'), v.id )\n");
  181.     fprintf (mapFiles[0].replaceFile, "\t\t\tengineReplaceModel ( engineLoadDFF (':Graphics/dff/'..(v.name)..'.dff', v.id ), v.id )\n");
  182.     fprintf (mapFiles[0].replaceFile, "\t\t\tif v.useCol == true then\n");
  183.     fprintf (mapFiles[0].replaceFile, "\t\t\t\tengineReplaceCOL ( engineLoadCOL (':Graphics/col/'..(v.name)..'.col', v.id ), v.id )\n");
  184.     fprintf (mapFiles[0].replaceFile, "\t\t\tend\n");
  185.     fprintf (mapFiles[0].replaceFile, "\t\tend\n");
  186.     fprintf (mapFiles[0].replaceFile, "\tend\n");
  187.     fprintf (mapFiles[0].replaceFile, "\tsetLOD ()\n");
  188.     fprintf (mapFiles[0].replaceFile, "end\n");
  189.     fprintf (mapFiles[0].replaceFile, "addEventHandler('onClientResourceStart', getResourceRootElement(getThisResource()), %s)\n\n", mapFiles[0].IDE_name.c_str());
  190.     fprintf (mapFiles[0].replaceFile, "function setLOD ()\n");
  191.     fprintf (mapFiles[0].replaceFile, "\tfor _, v in ipairs (data) do\n");
  192.     fprintf (mapFiles[0].replaceFile, "\t\tfor _, object in ipairs (getElementsByType('object')) do\n");
  193.     fprintf (mapFiles[0].replaceFile, "\t\t\tif not v.lod == false then\n");
  194.     fprintf (mapFiles[0].replaceFile, "\t\t\t\tlocal mdl = getElementModel(object)\n");
  195.     fprintf (mapFiles[0].replaceFile, "\t\t\t\tif mdl == v.id then\n");
  196.     fprintf (mapFiles[0].replaceFile, "\t\t\t\t\tlocal lod = getLODModelFromID (v.lod)\n");
  197.     fprintf (mapFiles[0].replaceFile, "\t\t\t\t\tif lod then\n");
  198.     fprintf (mapFiles[0].replaceFile, "\t\t\t\t\t\tsetLowLODElement ( object, lod )\n");
  199.     fprintf (mapFiles[0].replaceFile, "\t\t\t\t\t\tengineSetModelLODDistance ( mdl, 1000 )\n");
  200.     fprintf (mapFiles[0].replaceFile, "\t\t\t\t\t\toutputDebugString('LOD '..(v.lod)..' applied to '..mdl..' successfully')\n");
  201.     fprintf (mapFiles[0].replaceFile, "\t\t\t\t\tend\n");
  202.     fprintf (mapFiles[0].replaceFile, "\t\t\t\tend\n");
  203.     fprintf (mapFiles[0].replaceFile, "\t\t\tend\n");
  204.     fprintf (mapFiles[0].replaceFile, "\t\tend\n");
  205.     fprintf (mapFiles[0].replaceFile, "\tend\n");
  206.     fprintf (mapFiles[0].replaceFile, "end\n\n");
  207.     fprintf (mapFiles[0].replaceFile, "function getLODModelFromID (lod)\n");
  208.     fprintf (mapFiles[0].replaceFile, "\tfor _, object in ipairs (getElementsByType('object')) do\n");
  209.     fprintf (mapFiles[0].replaceFile, "\t\tlocal mdl = getElementModel(object)\n");
  210.     fprintf (mapFiles[0].replaceFile, "\t\tif mdl == lod then\n");
  211.     fprintf (mapFiles[0].replaceFile, "\t\t\treturn object\n");
  212.     fprintf (mapFiles[0].replaceFile, "\t\tend\n");
  213.     fprintf (mapFiles[0].replaceFile, "\tend\n");
  214.     fprintf (mapFiles[0].replaceFile, "\treturn false\n");
  215.     fprintf (mapFiles[0].replaceFile, "end");
  216.     fprintf (logfile, "engine.lua created successfully!\n");
  217.     printf ("Engine.lua successfully created!\n\n");
  218.  
  219.     ///MAPS FILES
  220.     ///MAPS FILES
  221.     fprintf (logfile, "Creating map files...\n");
  222.     printf ("Creating map files (map.lua, Unassigned_IPLObjects.lua)...\n");
  223.     fprintf (mapFiles[0].unassignedIPL, "Objects no assigned on the IDE file\n");
  224.     for (int b = 0; b < IPLF; b++)
  225.     {
  226.         if (mapFiles[0].IPL_data[b].assigned)
  227.             fprintf (mapFiles[0].mapFile, "createObject (%i, %f, %f, %f, %f, %f, %f)\n",     mapFiles[0].IPL_data[b].ID,
  228.                                                                                              mapFiles[0].IPL_data[b].x,
  229.                                                                                              mapFiles[0].IPL_data[b].y,
  230.                                                                                              mapFiles[0].IPL_data[b].z,
  231.                                                                                              mapFiles[0].IPL_data[b].rx,
  232.                                                                                              mapFiles[0].IPL_data[b].ry,
  233.                                                                                              mapFiles[0].IPL_data[b].rz);
  234.         else
  235.  
  236.             fprintf (mapFiles[0].unassignedIPL, "createObject (%i, %f, %f, %f, %f, %f, %f)\n", mapFiles[0].IPL_data[b].ID,
  237.                                                                                                mapFiles[0].IPL_data[b].x,
  238.                                                                                                mapFiles[0].IPL_data[b].y,
  239.                                                                                                mapFiles[0].IPL_data[b].z,
  240.                                                                                                mapFiles[0].IPL_data[b].rx,
  241.                                                                                                mapFiles[0].IPL_data[b].ry,
  242.                                                                                                mapFiles[0].IPL_data[b].rz);
  243.  
  244.         Sleep (rand() % 10 + 5);
  245.     }
  246.     fprintf (logfile, "Map files created successfully!\n");
  247.     printf ("Map files created successfully!\n\n");
  248.  
  249.  
  250.     fprintf (logfile, "Creating file (meta.xml)...\n");
  251.     printf ("Creating file (meta.xml)...\n");
  252.  
  253.     fprintf (mapFiles[0].meta, "<meta>\n");
  254.     fprintf (mapFiles[0].meta, "\t<script src='map.lua' type='server'/>\n");
  255.     fprintf (mapFiles[0].meta, "\t<script src='engine.lua' type='client'/>\n");
  256.     fprintf (mapFiles[0].meta, "\t<script src='IPLObjects_Unassigned.lua' type='server'/>\n\n");
  257.     for (int d = 0; d < IDEF; d++)
  258.     {
  259.         fprintf (mapFiles[0].meta, "\t<file src='dff/%s.dff' type='client'/>\n",   mapFiles[0].IDE_data[d].DFF);
  260.         fprintf (mapFiles[0].meta, "\t<file src='col/%s.col' type='client'/>\n",   mapFiles[0].IDE_data[d].DFF);
  261.         fprintf (mapFiles[0].meta, "\t<file src='txd/%s.txd' type='client'/>\n\n", mapFiles[0].IDE_data[d].TXD);
  262.  
  263.         Sleep (rand() % 10 + 5);
  264.     }
  265.     fprintf (mapFiles[0].meta, "</meta>");
  266.     fprintf (logfile, "meta.xml created successfully!\n");
  267.     printf ("meta.xml created successfully!\n\n");
  268.  
  269.     fclose (mapFiles[0].replaceFile);
  270.     fclose (mapFiles[0].mapFile);
  271.     fclose (mapFiles[0].unassignedIPL);
  272.     fclose (mapFiles[0].meta);
  273.     fclose (logfile);
  274.  
  275.     cout<<"PROCESS COMPLETED! Press any key to close."<<endl;
  276.     getch ();
  277.  
  278.     return 0;
  279. }
  280.  
  281. int GetTotalLinesFromAFile (string _file)
  282. {
  283.     int lines = 0;
  284.     string line;
  285.     ifstream tempFile;
  286.     tempFile.open (_file.c_str());
  287.     while (getline(tempFile, line))
  288.     {
  289.         lines++;
  290.     }
  291.     tempFile.close ();
  292.     return lines;
  293. }
  294.  
  295. int hasIPLsameIDEID (int iplID)
  296. {
  297.     for (int i = 0; i < IDEF; i++)
  298.     {
  299.         if (mapFiles[0].IDE_data[i].oID == iplID)
  300.         {
  301.             return mapFiles[0].IDE_data[i].ID;
  302.         }
  303.     }
  304.     return -1;
  305. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement