Guest User

Untitled

a guest
Oct 20th, 2017
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #ifdef _WIN32
  2. #pragma comment(lib,"OpenGL32.lib")
  3. #pragma comment(lib,"glu32.lib")
  4. #pragma comment(lib,"SDL.lib")
  5. #pragma comment(lib,"SDLmain.lib")
  6.  
  7. #define NOMINMAX
  8. #define _CRT_SECURE_NO_DEPRECATE
  9. #include <windows.h>
  10. #include <winerror.h>
  11. #endif
  12.  
  13. #include <ctime>
  14. #include <cstdlib>
  15. #include <iostream>
  16. #include <fstream>
  17.  
  18. #include "Config.h"
  19.  
  20. #include "MPQ.h"
  21. #include "Video.h"
  22. #include "Appstate.h"
  23.  
  24. #include "Test.h"
  25. #include "Menu.h"
  26. #include "Areadb.h"
  27.  
  28. #include "Shaders.h"
  29.  
  30. using namespace std;
  31.  
  32. int fullscreen = 0;
  33.  
  34. // ##################
  35. // ## CHECK CONFIG ##
  36. // ##################
  37. #define CONFIG_FILE "Editor.conf"
  38. int checkConfig()
  39. {
  40.     FILE *EditorPTR;
  41.  
  42.     EditorPTR = fopen(CONFIG_FILE, "r");
  43.  
  44.     if(EditorPTR) // If open Editor
  45.     {
  46.         gLog("[World of Warcraft Studio - Editor] - Config exist\n##############################################################\n");
  47.  
  48.         if(EditorPTR == NULL) // If conf is empty
  49.         {
  50.             gLog("[World of Warcraft Studio - Editor] - Config is empty\n##############################################################\n");
  51.             exit(1);
  52.         }
  53.         else
  54.         {
  55.             gLog("[World of Warcraft Studio - Editor] - Config have content\n##############################################################\n"); // Config isn't empty
  56.         }
  57.     }
  58.     else
  59.     {
  60.         gLog("[World of Warcraft Studio - Editor] - Config doesn't exist\n##############################################################\n"); // Config doesn't exist
  61.         exit(1);
  62.     }
  63.  
  64.     return 0;
  65. }
  66.  
  67. // ######################
  68. // ## EXPANSION SELECT ##
  69. // ######################
  70. int loadExpansion()
  71. {
  72.     ConfigFile conf(CONFIG_FILE);
  73.  
  74.     return (int)conf.Value("expansion_option", "Expansion");
  75. }
  76.  
  77. // ######################
  78. // ## GAMEPATH  SELECT ##
  79. // ######################
  80. bool loadPath()
  81. {
  82.     ConfigFile conf(CONFIG_FILE);
  83.  
  84.     (char)conf.Value("game_option", "Path");
  85.  
  86.     return true;
  87. }
  88.  
  89. // ######################
  90. // ## GAMEVER - SELECT ##
  91. // ######################
  92. int loadGameVersion()
  93. {
  94.     ConfigFile conf(CONFIG_FILE);
  95.  
  96.     return (int)conf.Value("game_option", "GameVersion");
  97. }
  98.  
  99. // ######################
  100. // ## LANGUAGE  SELECT ##
  101. // ######################
  102. int loadLanguage()
  103. {
  104.     ConfigFile conf(CONFIG_FILE);
  105.  
  106.     return (int)conf.Value("language_option", "Language");
  107. }
  108.  
  109. // ##################
  110. // ## CHECKCONFIG2 ##
  111. // ##################
  112. int checkConfig2()
  113. {
  114.     FILE *EditorPTR;
  115.  
  116.     EditorPTR = fopen(CONFIG_FILE, "r");
  117.  
  118.     if(EditorPTR)
  119.     {
  120.         if(loadExpansion() != 1 || 2 || 3)
  121.         {
  122.             gLog("[World of Warcraft Studio - Editor] - Expansion isn't selected\n");
  123.             exit(1);
  124.         }
  125.         else
  126.         {
  127.             gLog("[World of Warcraft Studio - Editor] - Expansion is selected - %s\n", loadExpansion());
  128.         }
  129.  
  130.         if(!loadPath())
  131.         {
  132.             gLog("[World of Warcraft Studio - Editor] - Path is selected from Registry\n");
  133.         }
  134.         else
  135.         {
  136.             gLog("[World of Warcraft Studio - Editor] - Path is selected from Config - %s\n", loadPath());
  137.         }
  138.  
  139.         if(loadLanguage())
  140.         {
  141.             gLog("[World of Warcraft Studio - Editor] - Language isn't selected\n");
  142.             exit(1);
  143.         }
  144.         else
  145.         {
  146.             gLog("[World of Warcraft Studio - Editor] - Language is selected - %s\n", loadLanguage());
  147.         }
  148.     }
  149.  
  150.     return 0;
  151. }
  152.  
  153. // ##################
  154. // ## GRAPHIC CARD ##
  155. // ##################
  156. void GraphicCard()
  157. {
  158.     gLog("[World of Warcraft Studio - Editor] - %s\n", glGetString(GL_VENDOR));
  159.     gLog("[World of Warcraft Studio - Editor] - %s\n", glGetString(GL_RENDERER));
  160.     gLog("[World of Warcraft Studio - Editor] - %s\n", glGetString(GL_VERSION));
  161. }
  162.  
  163. std::vector<AppState*> gStates;
  164. bool gPop = false;
  165.  
  166. char gamepath[1024];
  167. char wowpath[1024];
  168.  
  169.  
  170. float gFPS;
  171.  
  172. GLuint ftex;
  173. Font *f16, *f24, *f32;
  174. freetype::font_data arialn13,arial12,arial14,arial16,morpheus40;   
  175. AreaDB gAreaDB;
  176.  
  177.  
  178. void initFonts()
  179. {
  180.     ftex = loadTGA("arial.tga",false);
  181.  
  182.  
  183.     f16 = new Font(ftex, 256, 256, 16, "arial.info");
  184.     f24 = new Font(ftex, 256, 256, 24, "arial.info");
  185.     f32 = new Font(ftex, 256, 256, 32, "arial.info");
  186.  
  187.    
  188.     morpheus40.initMPQ("fonts\\MORPHEUS.TTF",40);
  189.     arialn13.initMPQ("fonts\\arialn.TTF",13);
  190.    
  191.     arial12.init("arial.ttf",12);
  192.     arial14.init("arial.ttf",14);
  193.     arial16.init("arial.ttf",16);
  194.    
  195. }
  196.  
  197. void deleteFonts()
  198. {
  199.     glDeleteTextures(1, &ftex);
  200.  
  201.     delete f16;
  202.     delete f24;
  203.     delete f32;
  204. }
  205.  
  206.  
  207.  
  208. FILE *flog;
  209. bool glogfirst = true;
  210.  
  211.  
  212. void gLog(char *str, ...)
  213. {
  214.     if (glogfirst) {
  215.         flog = fopen("log.txt","w");
  216.         fclose(flog);
  217.         glogfirst = false;
  218.     }
  219.  
  220.     flog = fopen("log.txt","a");
  221.  
  222.     va_list ap;
  223.  
  224.     va_start (ap, str);
  225.     vfprintf (flog, str, ap);
  226.     va_end (ap);
  227.  
  228.     fclose(flog);
  229. }
  230.  
  231.  
  232. void getGamePath()
  233. {
  234. #ifdef _WIN32
  235.     HKEY key;
  236.     DWORD t,s;
  237.     LONG l;
  238.     s = 1024;
  239.     memset(gamepath,0,s);
  240.     l = RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Blizzard Entertainment\\World of Warcraft",0,KEY_QUERY_VALUE,&key);
  241.     l = RegQueryValueEx(key,"InstallPath",0,&t,(LPBYTE)gamepath,&s);
  242.     l = RegQueryValueEx(key,"InstallPath",0,&t,(LPBYTE)wowpath,&s);
  243.     RegCloseKey(key);
  244.     strcat_s(gamepath,"Data\\");
  245. #else
  246.     strcpy(gamepath,"data/");
  247. #endif
  248. }
  249.  
  250. void CreateStrips();
  251. void InitGroundEffects();
  252. int main(int argc, char *argv[])
  253. {
  254.     srand((unsigned int)time(0));
  255.  
  256.     int xres = 1024;
  257.     int yres = 768;
  258.     //int xres = 1152;
  259.     //int yres = 864;
  260.  
  261.     bool usePatch = true;
  262.  
  263.     for (int i=1; i<argc; i++) {
  264.         if (!strcmp(argv[i],"-f")) fullscreen = 1;
  265.         else if (!strcmp(argv[i],"-w")) fullscreen = 0;
  266.         else if (!strcmp(argv[i],"-1024") || !strcmp(argv[i],"-1024x768")) {
  267.             xres = 1024;
  268.             yres = 768;
  269.         }
  270.         else if (!strcmp(argv[i],"-1280") || !strcmp(argv[i],"-1280x1024")) {
  271.             xres = 1280;
  272.             yres = 1024;
  273.         }
  274.         else if (!strcmp(argv[i],"-1280x960")) {
  275.             xres = 1280;
  276.             yres = 960;
  277.         }
  278.         else if (!strcmp(argv[i],"-1400") || !strcmp(argv[i],"-1400x1050")) {
  279.             xres = 1400;
  280.             yres = 1050;
  281.         }
  282.         else if (!strcmp(argv[i],"-1280x800")) {
  283.             xres = 1280;
  284.             yres = 800;
  285.         }
  286.         else if (!strcmp(argv[i],"-1600") || !strcmp(argv[i],"-1600x1200")) {
  287.             xres = 1600;
  288.             yres = 1200;
  289.         }
  290.         else if (!strcmp(argv[i],"-1920") || !strcmp(argv[i],"-1920x1200")) {
  291.             xres = 1920;
  292.             yres = 1200;
  293.         }
  294.         else if (!strcmp(argv[i],"-2048") || !strcmp(argv[i],"-2048x1536")) {
  295.             xres = 2048;
  296.             yres = 1536;
  297.         }
  298.         else if (!strcmp(argv[i],"-p")) usePatch = true;
  299.         else if (!strcmp(argv[i],"-np")) usePatch = false;
  300.     }
  301.  
  302.     checkConfig();
  303.  
  304.     /*if(!loadPath())
  305.     {
  306.         getGamePath();
  307.     }
  308.     else
  309.     {
  310.         getGamePath() = loadPath();
  311.     }*/
  312.  
  313.     gLog("[World of Warcraft Studio - Editor] - " APP_TITLE " - " APP_VERSION "\n[World of Warcraft Studio - Editor] - Game path: %s\n[World of Warcraft Studio - Editor] - Game Version: %s\n", gamepath, loadGameVersion());
  314.     GraphicCard(); // Send to Log info about Graphic Card
  315.  
  316.     CreateStrips();
  317.  
  318.     checkConfig2();
  319.  
  320.     std::vector<MPQArchive*> archives;
  321.     bool archiveNames[] = {""};
  322.     if(loadExpansion() == 1) // TBC
  323.     {
  324.         bool archiveNames[] = {"common.MPQ", "common-2.MPQ", "expansion.MPQ", "lichking.MPQ", "patch.MPQ", "patch-2.MPQ", "patch-3.MPQ"};
  325.     }
  326.     else if(loadExpansion() == 2) // WotLK
  327.     {
  328.         if(loadGameVersion() == 1) // enGB
  329.         {
  330.             bool archiveNames[] = {"common.MPQ", "common-2.MPQ", "expansion.MPQ", "lichking.MPQ", "patch.MPQ", "patch-2.MPQ",
  331.             "enGB/locale-enGB.MPQ", "enGB/expansion-locale-enGB.MPQ", "enGB/lichking-locale-enGB.MPQ", "enGB/patch-enGB.MPQ", "enGB/patch-enGB-2.MPQ"};
  332.         }
  333.         else if(loadGameVersion() == 2) // enUS
  334.         {
  335.             bool archiveNames[] = {"common.MPQ", "common-2.MPQ", "expansion.MPQ", "lichking.MPQ", "patch.MPQ", "patch-2.MPQ",
  336.             "enUS/locale-enUS.MPQ", "enUS/expansion-locale-enUS.MPQ", "enUS/lichking-locale-enUS.MPQ", "enUS/patch-enUS.MPQ", "enUS/patch-enUS-2.MPQ"};
  337.         }
  338.         else if(loadGameVersion() == 3) // deDE
  339.         {
  340.             bool archiveNames[] = {"common.MPQ", "common-2.MPQ", "expansion.MPQ", "lichking.MPQ", "patch.MPQ", "patch-2.MPQ",
  341.             "deDE/locale-deDE.MPQ", "deDE/expansion-locale-deDE.MPQ", "deDE/lichking-locale-deDE.MPQ", "deDE/patch-deDE.MPQ", "deDE/patch-deDE-2.MPQ"};
  342.         }
  343.         else if(loadGameVersion() == 4) // esES
  344.         {
  345.             bool archiveNames[] = {"common.MPQ", "common-2.MPQ", "expansion.MPQ", "lichking.MPQ", "patch.MPQ", "patch-2.MPQ",
  346.             "esES/locale-esES.MPQ", "esES/expansion-locale-esES.MPQ", "esES/lichking-locale-esES.MPQ", "esES/patch-esES.MPQ", "esES/patch-esES-2.MPQ"};
  347.         }
  348.         else if(loadGameVersion() == 5) // frFR
  349.         {
  350.             bool archiveNames[] = {"common.MPQ", "common-2.MPQ", "expansion.MPQ", "lichking.MPQ", "patch.MPQ", "patch-2.MPQ",
  351.             "frFR/locale-frFR.MPQ", "frFR/expansion-locale-frFR.MPQ", "frFR/lichking-locale-frFR.MPQ", "frFR/patch-frFR.MPQ", "frFR/patch-frFR-2.MPQ"};
  352.         }
  353.         else if(loadGameVersion() == 6) // ruRU
  354.         {
  355.             bool archiveNames[] = {"common.MPQ", "common-2.MPQ", "expansion.MPQ", "lichking.MPQ", "patch.MPQ", "patch-2.MPQ",
  356.             "ruRU/locale-ruRU.MPQ", "ruRU/expansion-locale-ruRU.MPQ", "ruRU/lichking-locale-ruRU.MPQ", "ruRU/patch-ruRU.MPQ", "ruRU/patch-ruRU-2.MPQ"};
  357.         }
  358.         else
  359.         {
  360.             gLog("[World of Warcraft Studio - Editor] - Can't load GameVersion.");
  361.             exit(1);
  362.         }
  363.  
  364.         if(loadGameVersion())
  365.         {
  366.             gLog("[World of Warcraft Studio - Editor] - GameVersion is selected - %s\n", loadGameVersion());
  367.         }
  368.     }
  369.     else if(loadExpansion() == 3) // Cataclysm
  370.     {
  371.         bool archiveNames[] = {"art.MPQ", "expansion1.MPQ", "expansion2.MPQ", "expansion3.MPQ", "sound.MPQ", "world.MPQ"};
  372.     }
  373.     else
  374.     {
  375.         gLog("Expansion isn't - The Burning Crusade or Wrath of the Lich King or Cataclysm. Select one of third expansion.");
  376.         exit(1);
  377.     }
  378.  
  379.     char path[512];
  380.  
  381.     //Patches
  382.     /*
  383.     if (usePatch) {
  384.         // patch goes first -> fake priority handling
  385.         sprintf(path, "%s%s", gamepath, "patch-9.MPQ");
  386.         archives.push_back(new MPQArchive(path));
  387.         sprintf(path, "%s%s", gamepath, "patch-8.MPQ");
  388.         archives.push_back(new MPQArchive(path));
  389.         sprintf(path, "%s%s", gamepath, "patch-7.MPQ");
  390.         archives.push_back(new MPQArchive(path));
  391.         sprintf(path, "%s%s", gamepath, "patch-6.MPQ");
  392.         archives.push_back(new MPQArchive(path));
  393.         sprintf(path, "%s%s", gamepath, "patch-5.MPQ");
  394.         archives.push_back(new MPQArchive(path));
  395.         sprintf(path, "%s%s", gamepath, "patch-4.MPQ");
  396.         archives.push_back(new MPQArchive(path));
  397.     }*/
  398.  
  399.     for (size_t i=0; i<7; i++) {
  400.         sprintf_s(path, "%s%s", gamepath, archiveNames[i]);
  401.         archives.push_back(new MPQArchive(path));
  402.     }
  403.  
  404.     gAreaDB.open();
  405.  
  406.     video.init(xres,yres,fullscreen!=0);
  407.     SDL_WM_SetCaption(APP_TITLE,NULL);
  408.  
  409.  
  410.     gLog("[World of Warcraft Studio - Editor] - Initializing Ground Effects\n");
  411.     InitGroundEffects();
  412.     gLog("[World of Warcraft Studio - Editor] - Initializing Fonts\n");
  413.     initFonts();
  414.  
  415.     float ftime;
  416.     Uint32 t, last_t, frames = 0, time = 0, fcount = 0, ft = 0;
  417.     AppState *as;
  418.     gFPS = 0;
  419.  
  420.     gLog("[World of Warcraft Studio - Editor] - Creating Menu\n");
  421.     Menu *m = new Menu();
  422.     as = m;
  423.  
  424.     gStates.push_back(as);
  425.  
  426.     if(glExtGetGLProcs_VertexProgram_1_0_ARB()==0)
  427.     {
  428.         gLog("[World of Warcraft Studio - Editor] - Unable to load ARB Vertex Program Code\n");
  429.         return 0;
  430.     }
  431.     loadWaterShader();
  432.  
  433.     bool done = false;
  434.     t = SDL_GetTicks();
  435.     gLog("[World of Warcraft Studio - Editor] - Entering Main Loop\n");
  436.     while(gStates.size()>0 && !done) {
  437.         last_t = t;
  438.         t = SDL_GetTicks();
  439.         Uint32 dt = t - last_t;
  440.         time += dt;
  441.         ftime = time / 1000.0f;
  442.  
  443.         as = gStates[gStates.size()-1];
  444.  
  445.         SDL_Event event;
  446.         while ( SDL_PollEvent(&event) ) {
  447.             if ( event.type == SDL_QUIT ) {
  448.                 done = true;
  449.             }
  450.             else if ( event.type == SDL_MOUSEMOTION) {
  451.                 if(SDL_GetAppState()&SDL_APPMOUSEFOCUS)
  452.                     as->mousemove(&event.motion);
  453.             }
  454.             else if ( (event.type == SDL_MOUSEBUTTONDOWN || event.type == SDL_MOUSEBUTTONUP)&&(SDL_GetAppState()&SDL_APPINPUTFOCUS)) {
  455.                
  456.                 if(event.button.type == SDL_MOUSEBUTTONUP)
  457.                     as->mouseclick(&event.button);
  458.                 else if(SDL_GetAppState()&SDL_APPMOUSEFOCUS)
  459.                     as->mouseclick(&event.button);
  460.             }
  461.             else if ( (event.type == SDL_KEYDOWN || event.type == SDL_KEYUP)) {
  462.                 if(SDL_GetAppState()&SDL_APPINPUTFOCUS)
  463.                     as->keypressed(&event.key);
  464.             }
  465.             else if( event.type == SDL_VIDEORESIZE)
  466.             {
  467.                 video.resize(event.resize.w,event.resize.h);
  468.             }
  469.         }
  470.  
  471.  
  472.  
  473.         if(SDL_GetAppState()&SDL_APPACTIVE)
  474.         {
  475.             as->tick(ftime, dt/1000.0f);
  476.  
  477.             as->display(ftime, dt/1000.0f);
  478.         }
  479.  
  480.         if (gPop) {
  481.             gPop = false;
  482.             gStates.pop_back();
  483.             delete as;
  484.         }
  485.  
  486.         frames++;
  487.         fcount++;
  488.         ft += dt;
  489.         if (ft >= 1000) {
  490.             float fps = (float)fcount / (float)ft * 1000.0f;
  491.             gFPS = fps;
  492.             char buf[32];
  493.             sprintf_s(buf, APP_TITLE " - %.2f fps",fps);
  494.             SDL_WM_SetCaption(buf,NULL);
  495.             ft = 0;
  496.             fcount = 0;
  497.         }
  498.  
  499.         video.flip();
  500.  
  501.     }
  502.     gLog("[World of Warcraft Studio - Editor] - Exited Main Loop\n");
  503.  
  504.     deleteFonts();
  505.    
  506.     video.close();
  507.  
  508.     for (std::vector<MPQArchive*>::iterator it = archives.begin(); it != archives.end(); ++it) {
  509.         (*it)->close();
  510.     }
  511.     archives.clear();
  512.  
  513.     gLog("\n[World of Warcraft Studio - Editor] - Exiting.\n");
  514.  
  515.     return 0;
  516. }
  517.  
  518. float frand()
  519. {
  520.     return rand()/(float)RAND_MAX;
  521. }
  522.  
  523. float randfloat(float lower, float upper)
  524. {
  525.     return lower + (upper-lower)*(rand()/(float)RAND_MAX);
  526. }
  527.  
  528. int randint(int lower, int upper)
  529. {
  530.     return lower + (int)((upper+1-lower)*frand());
  531. }
  532.  
  533. void fixnamen(char *name, size_t len)
  534. {
  535.     for (size_t i=0; i<len; i++) {
  536.         if (i>0 && name[i]>='A' && name[i]<='Z' && isalpha(name[i-1])) {
  537.             name[i] |= 0x20;
  538.         } else if ((i==0 || !isalpha(name[i-1])) && name[i]>='a' && name[i]<='z') {
  539.             name[i] &= ~0x20;
  540.         }
  541.     }
  542. }
  543.  
  544. void fixname(std::string &name)
  545. {
  546.     for (size_t i=0; i<name.length(); i++) {
  547.         if (i>0 && name[i]>='A' && name[i]<='Z' && isalpha(name[i-1])) {
  548.             name[i] |= 0x20;
  549.         } else if ((i==0 || !isalpha(name[i-1])) && name[i]>='a' && name[i]<='z') {
  550.             name[i] &= ~0x20;
  551.         }
  552.     }
  553. }
Add Comment
Please, Sign In to add comment