Kazuhiri

Untitled

Jan 25th, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 34.81 KB | None | 0 0
  1. #include "StdAfx.h"
  2. #include "PythonApplication.h"
  3. #include "ProcessScanner.h"
  4. #include "PythonExceptionSender.h"
  5. #include "resource.h"
  6. #include "Version.h"
  7. #include <windowsx.h>
  8. #include <windows.h>
  9. #include <assert.h>
  10. #include <tlhelp32.h>
  11. #include <imagehlp.h>
  12. #include <psapi.h>
  13. #include <process.h>
  14. #include <stdlib.h>
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <commdlg.h>
  18. #include <iostream>
  19. #include <sstream>
  20. #include <string>
  21. #include <vector>
  22. #include <stdlib.h>
  23. #include <Aclapi.h>
  24.  
  25. #ifdef _DEBUG
  26. #include <crtdbg.h>
  27. #endif
  28.  
  29. #include "../eterPack/EterPackManager.h"
  30. #include "../eterLib/Util.h"
  31. #include "../CWebBrowser/CWebBrowser.h"
  32. #include "../eterBase/CPostIt.h"
  33.  
  34. #include "CheckLatestFiles.h"
  35.  
  36. #include "Hackshield.h"
  37. #include "NProtectGameGuard.h"
  38. #include "WiseLogicXTrap.h"
  39. extern "C" {
  40. extern int _fltused;
  41. volatile int _AVOID_FLOATING_POINT_LIBRARY_BUG = _fltused;
  42. };
  43.  
  44. #pragma comment(linker, "/NODEFAULTLIB:libci.lib")
  45.  
  46. #pragma comment( lib, "version.lib" )
  47.  
  48. // #ifdef _DEBUG
  49. // #pragma comment( lib, "python2_d.lib" )
  50. // #else
  51. #pragma comment( lib, "python27.lib" )
  52. // #endif
  53. #pragma comment( lib, "imagehlp.lib" )
  54. #pragma comment( lib, "devil.lib" )
  55.  
  56. #if GrannyProductMinorVersion==4
  57. #pragma comment( lib, "granny2.4.0.10.lib" )
  58. #elif GrannyProductMinorVersion==7
  59. #pragma comment( lib, "granny2.7.0.30.lib" )
  60. #elif GrannyProductMinorVersion==9
  61. #pragma comment( lib, "granny2.9.12.0.lib" )
  62. #else
  63. #error "unknown granny version"
  64. #endif
  65. #pragma comment( lib, "mss32.lib" )
  66. #pragma comment( lib, "winmm.lib" )
  67. #pragma comment( lib, "imm32.lib" )
  68. #pragma comment( lib, "oldnames.lib" )
  69. #pragma comment( lib, "SpeedTreeRT.lib" )
  70. #pragma comment( lib, "dinput8.lib" )
  71. #pragma comment( lib, "dxguid.lib" )
  72. #pragma comment( lib, "ws2_32.lib" )
  73. #pragma comment( lib, "strmiids.lib" )
  74. #pragma comment( lib, "ddraw.lib" )
  75. #pragma comment( lib, "psapi.lib")
  76. #pragma comment( lib, "imagehlp.lib")
  77. #pragma comment( lib, "comdlg32.lib")
  78. #pragma comment( lib, "dmoguids.lib" )
  79. //#pragma comment( lib, "wsock32.lib" )
  80. #ifdef USE_FOX_FS
  81. #pragma comment( lib, "lz4.lib" )
  82. #pragma comment( lib, "xxhash.lib" )
  83. #pragma comment( lib, "FoxFS.lib" )
  84. #endif
  85. #include <stdlib.h>
  86. #include <cryptopp/cryptoppLibLink.h>
  87. bool __IS_TEST_SERVER_MODE__=false;
  88.  
  89. // #define __USE_CYTHON__
  90. #ifdef __USE_CYTHON__
  91. #include "PythonrootlibManager.h"
  92. #endif
  93.  
  94. // #define __USE_EXTRA_CYTHON__
  95. #ifdef __USE_EXTRA_CYTHON__
  96. // don't include these two files .h .cpp if you're implementing cython via .pyd
  97. // #include "PythonuiscriptlibManager.h"
  98. // it would be better including such file in the project, but this is easier at this moment:
  99. // #include "PythonuiscriptlibManager.cpp"
  100. #endif
  101.  
  102. #include <stdlib.h>
  103. #include <cryptopp/cryptoppLibLink.h>
  104.  
  105. #define JUMP_TO_OFFSET(_BaseOffset, _TargetOffset) ((LONG)(_TargetOffset) - (LONG)(_BaseOffset) - 5)
  106. #define STATUS_SUCCESS ((NTSTATUS)0x00000000L)
  107. #define STATUS_INFO_LENGTH_MISMATCH ((NTSTATUS)0xC0000004L)
  108. #define STATUS_BUFFER_OVERFLOW ((NTSTATUS)0x80000005L)
  109. #define SystemHandleInformation 16
  110.  
  111. extern bool SetDefaultCodePage(DWORD codePage);
  112.  
  113. #ifdef USE_OPENID
  114. extern int openid_test;
  115. #endif
  116.  
  117. extern bool SetDefaultCodePage(DWORD codePage);
  118.  
  119. #ifdef USE_OPENID
  120. extern int openid_test;
  121. #endif
  122.  
  123. static const char * sc_apszPythonLibraryFilenames[] =
  124. {
  125.     "UserDict.pyc",
  126.     "__future__.pyc",
  127.     "copy_reg.pyc",
  128.     "linecache.pyc",
  129.     "ntpath.pyc",
  130.     "os.pyc",
  131.     "site.pyc",
  132.     "stat.pyc",
  133.     "string.pyc",
  134.     "traceback.pyc",
  135.     "types.pyc",
  136.     "\n",
  137. };
  138.  
  139.  
  140. #ifdef ENABLE_PYLIB_CHECK
  141. #define PRINT_LEVEL 0
  142. #define PRINTME(level, ...) if(PRINT_LEVEL>=level) TraceError(__VA_ARGS__);
  143. #define PYFOLD "./lib"
  144. // #define PYFORCE
  145.  
  146. typedef struct PyLibFiles_s
  147. {
  148.     std::string sFileName;
  149.     size_t stSize;
  150.     DWORD dwCRC32;
  151. } PyLibFiles_t;
  152.  
  153. PyLibFiles_t PyLibFilesTable[] =
  154. {
  155. #if PY_VERSION_HEX==0x020706f0
  156.     { PYFOLD"/UserDict.pyc", 9000, 1431875928},
  157.     { PYFOLD"/__future__.pyc", 4431, 2857792867},
  158.     { PYFOLD"/copy_reg.pyc", 5157, 536292604},
  159.     { PYFOLD"/linecache.pyc", 3235, 4048207604},
  160.     { PYFOLD"/ntpath.pyc", 11961, 2765879465},
  161.     { PYFOLD"/os.pyc", 25769, 911432770},
  162.     { PYFOLD"/site.pyc", 20019, 3897044925},
  163.     { PYFOLD"/stat.pyc", 2791, 1375966108},
  164.     { PYFOLD"/string.pyc", 13514, 648740690},
  165.     { PYFOLD"/traceback.pyc", 11703, 3768933732},
  166.     { PYFOLD"/types.pyc", 2530, 920695307},
  167. #elif PY_VERSION_HEX==0x020203f0
  168. #else
  169. #error "unknown python version"
  170. #endif
  171. };
  172.  
  173. bool checkPyLibDir(const string szDirName)
  174. {
  175.     bool HasHack = false;
  176.  
  177.     char szDirNamePath[MAX_PATH];
  178.     sprintf(szDirNamePath, "%s\\*", szDirName.c_str());
  179.  
  180.     WIN32_FIND_DATA f;
  181.     HANDLE h = FindFirstFile(szDirNamePath, &f);
  182.  
  183.     if (h == INVALID_HANDLE_VALUE) { return HasHack; }
  184.  
  185.     do
  186.     {
  187.         if (HasHack)
  188.             break;
  189.         const char * name = f.cFileName;
  190.  
  191.         if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0) { continue; }
  192.  
  193.         if (f.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
  194.         {
  195.             char filePath[MAX_PATH];
  196.             sprintf(filePath, "%s%s%s", szDirName.c_str(), "\\", name);
  197.             PRINTME(1, "sub %s", filePath);
  198.             checkPyLibDir(filePath);
  199.         }
  200.         else
  201.         {
  202.             // start processing file
  203.             PRINTME(1, "starting %s", name);
  204.             std::string sName(name);
  205.             std::string sPathName(szDirName+"/"+name);
  206.             // change \\ to /
  207.             std::replace(sPathName.begin(), sPathName.end(), '\\', '/');
  208.             PRINTME(1, "path %s", sPathName.c_str());
  209.             // lower file name
  210.             std::transform(sName.begin(), sName.end(), sName.begin(), ::tolower);
  211.             {
  212.                 PRINTME(1, "verify %s", sName.c_str());
  213.                 bool isPyLibFound = false;
  214.                 for (PyLibFiles_t *i1=std::begin(PyLibFilesTable), *e1=std::end(PyLibFilesTable); i1<e1; i1++)
  215.                 {
  216.                     if (!i1->sFileName.compare(sPathName))
  217.                     {
  218.                         PRINTME(1, "found %s==%s", i1->sFileName.c_str(), sName.c_str());
  219.                         DWORD dwCrc32 = GetFileCRC32(sPathName.c_str());
  220.                         // assert(dwCrc32);
  221.                         //DWORD dwFileSize = f.nFileSizeLow;
  222.                         //if (i1->stSize!=dwFileSize)
  223.                         //{
  224.                         //  PRINTME(1, "wrong size %u==%u", i1->stSize, dwFileSize);
  225.                         //  HasHack = true;
  226.                         //  PRINTME(0, "wrong size %u for %s", dwFileSize, sPathName.c_str());
  227.                         //  return HasHack;
  228.                         //}
  229.                         //else if (i1->dwCRC32 != dwCrc32)
  230.                         //{
  231.                         //  PRINTME(1, "wrong crc32 %u==%u", i1->dwCRC32, dwCrc32);
  232.                         //  HasHack = true;
  233.                         //  PRINTME(0, "wrong crc32 %u for %s", dwCrc32, sPathName.c_str());
  234.                         //  return HasHack;
  235.                         //}
  236.                     }
  237.                 }
  238.                 // block ambiguous pyc/d files
  239.                 if (!isPyLibFound)
  240.                 {
  241.                     PRINTME(1, "not found %s", sName.c_str());
  242. #ifdef PYFORCE
  243.                     HasHack = true;
  244.                     PRINTME(0, "ambiguous file for %s", sPathName.c_str());
  245.                     return HasHack;
  246. #endif
  247.                 }
  248.                 PRINTME(1, "skipping file(%s) hack(%u) found(%u)", sName.c_str(), HasHack, isPyLibFound);
  249.             }
  250.         }
  251.  
  252.     } while (FindNextFile(h, &f));
  253.     FindClose(h);
  254.     return HasHack;
  255. }
  256.  
  257. bool __CheckPyLibFiles()
  258. {
  259.     PRINTME(1, "__CheckPyLibFiles processing "PYFOLD);
  260.     if (checkPyLibDir(PYFOLD))
  261.         return false;
  262.     return true;
  263. }
  264. #endif
  265.  
  266. #ifdef ENABLE_MILES_CHECK
  267. #include <algorithm>
  268. #include "../EterBase/Filename.h"
  269. // #include "../EterBase/CRC32.h"
  270. #define PRINT_LEVEL 0
  271. #define PRINTME(level, ...) if(PRINT_LEVEL>=level) TraceError(__VA_ARGS__);
  272.  
  273. typedef struct MilesFiles_s
  274. {
  275.     std::string sFileName;
  276.     size_t stSize;
  277.     DWORD dwCRC32;
  278. } MilesFiles_t;
  279.  
  280. typedef struct MilesExten_s
  281. {
  282.     std::string ExtName;
  283.     bool IsUni;
  284. } MilesExten_t;
  285.  
  286. MilesExten_t MilesExtenTable[] = {
  287.     {"dll", false},
  288.     {"asi", true},
  289.     {"flt", true},
  290.     {"m3d", true},
  291.     {"mix", true},
  292. };
  293.  
  294. MilesFiles_t MilesFilesTable[] =
  295. {
  296.     {"mss32.dll", 349696, 1817711331},
  297.     {"mssa3d.m3d", 83456, 1812642892},
  298.     {"mssds3d.m3d", 70656, 2704596484},
  299.     {"mssdsp.flt", 93696, 3364819387},
  300.     {"mssdx7.m3d", 80896, 236402185},
  301.     {"msseax.m3d", 103424, 3195814903},
  302.     {"mssmp3.asi", 125952, 1219814613},
  303.     {"mssrsx.m3d", 354816, 550946743},
  304.     {"msssoft.m3d", 67072, 4284421368},
  305.     {"mssvoice.asi", 197120, 1407967464},
  306. };
  307.  
  308. bool checkMilesDir(const string szDirName)
  309. {
  310.     bool HasHack = false;
  311.  
  312.     char szDirNamePath[MAX_PATH];
  313.     sprintf(szDirNamePath, "%s\\*", szDirName.c_str());
  314.  
  315.     WIN32_FIND_DATA f;
  316.     HANDLE h = FindFirstFile(szDirNamePath, &f);
  317.  
  318.     if (h == INVALID_HANDLE_VALUE) { return HasHack; }
  319.  
  320.     do
  321.     {
  322.         if (HasHack)
  323.             break;
  324.         const char * name = f.cFileName;
  325.  
  326.         if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0) { continue; }
  327.  
  328.         if (f.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
  329.         {
  330.             // do nothing if it's a folder
  331.         }
  332.         else
  333.         {
  334.             // start processing file
  335.             PRINTME(1, "starting %s", name);
  336.             std::string sName(name);
  337.             std::string sPathName(szDirName+"/"+name);
  338.             PRINTME(1, "path %s", sPathName.c_str());
  339.             // lower file name
  340.             std::transform(sName.begin(), sName.end(), sName.begin(), ::tolower);
  341.             // file or symlink; check for asi flt m3d mix exploit
  342.             string sNameExt = CFileNameHelper::GetExtension(sName);
  343.             PRINTME(1, "ext %s", sNameExt.c_str());
  344.             // workaround instead of std::find
  345.             bool isMilesFile = false, isMilesUnique = false;
  346.             for (MilesExten_t *i1=std::begin(MilesExtenTable), *e1=std::end(MilesExtenTable); i1<e1; i1++)
  347.             {
  348.                 PRINTME(1, "is %s ? %s", i1->ExtName.c_str(), sNameExt.c_str());
  349.                 if (!sNameExt.compare(0, i1->ExtName.length(), i1->ExtName))
  350.                 {
  351.                     isMilesFile = true;
  352.                     isMilesUnique = i1->IsUni;
  353.                 }
  354.             }
  355.             if (isMilesFile)
  356.             {
  357.                 PRINTME(1, "verify %s -> %s", sName.c_str(), sNameExt.c_str());
  358.                 bool isMilesFound = false;
  359.                 for (MilesFiles_t *i1=std::begin(MilesFilesTable), *e1=std::end(MilesFilesTable); i1<e1; i1++)
  360.                 {
  361.                     if (!i1->sFileName.compare(sName))
  362.                     {
  363.                         PRINTME(1, "found %s==%s", i1->sFileName.c_str(), sName.c_str());
  364.                         DWORD dwCrc32 = GetFileCRC32(sPathName.c_str());
  365.                         // assert(dwCrc32);
  366.                         //DWORD dwFileSize = f.nFileSizeLow;
  367.                         //if (i1->stSize!=dwFileSize)
  368.                         //{
  369.                         //  PRINTME(1, "wrong size %u==%u", i1->stSize, dwFileSize);
  370.                         //  HasHack = true;
  371.                         //  PRINTME(0, "wrong size %u for %s", dwFileSize, sPathName.c_str());
  372.                         //  return HasHack;
  373.                         //}
  374.                         //if (i1->dwCRC32 != dwCrc32)
  375.                         //{
  376.                         //  PRINTME(1, "wrong crc32 %u==%u", i1->dwCRC32, dwCrc32);
  377.                         //  HasHack = true;
  378.                         //  PRINTME(0, "wrong crc32 %u for %s", dwCrc32, sPathName.c_str());
  379.                         //  return HasHack;
  380.                         //}
  381.                         //PRINTME(1, "right size %u==%u", i1->stSize, dwFileSize);
  382.                         PRINTME(1, "right crc32 %u==%u", i1->dwCRC32, dwCrc32);
  383.                         isMilesFound = true;
  384.                         break;
  385.                     }
  386.                 }
  387.                 // only mss32.dll is checked, and there's no need to check the others
  388.                 if (!isMilesFound && isMilesUnique)
  389.                 {
  390.                     PRINTME(1, "not found %s", sName.c_str());
  391.                     HasHack = true;
  392.                     PRINTME(0, "ambiguous file for %s", sPathName.c_str());
  393.                     return HasHack;
  394.                 }
  395.                 PRINTME(1, "skipping file(%s) hack(%u) found(%u) uni(%u)", sName.c_str(), HasHack, isMilesFound, isMilesUnique);
  396.             }
  397.         }
  398.  
  399.     } while (FindNextFile(h, &f));
  400.     FindClose(h);
  401.     return HasHack;
  402. }
  403.  
  404. bool __CheckMilesFiles()
  405. {
  406.     PRINTME(1, "__CheckMilesFiles processing . and .\\miles");
  407.     if (checkMilesDir(".") || checkMilesDir(".\\miles"))
  408.         return false;
  409.     return true;
  410. }
  411. #endif
  412.  
  413. char gs_szErrorString[512] = "";
  414.  
  415. void ApplicationSetErrorString(const char* szErrorString)
  416. {
  417.     strcpy(gs_szErrorString, szErrorString);
  418. }
  419.  
  420. bool CheckPythonLibraryFilenames()
  421. {
  422.     for (int i = 0; *sc_apszPythonLibraryFilenames[i] != '\n'; ++i)
  423.     {
  424.         std::string stFilename = "lib\\";
  425.         stFilename += sc_apszPythonLibraryFilenames[i];
  426.  
  427.         if (_access(stFilename.c_str(), 0) != 0)
  428.         {
  429.             return false;
  430.         }
  431.  
  432.         MoveFile(stFilename.c_str(), stFilename.c_str());
  433.     }
  434.  
  435.     return true;
  436. }
  437.  
  438. struct ApplicationStringTable
  439. {
  440.     HINSTANCE m_hInstance;
  441.     std::map<DWORD, std::string> m_kMap_dwID_stLocale;
  442. } gs_kAppStrTable;
  443.  
  444. void ApplicationStringTable_Initialize(HINSTANCE hInstance)
  445. {
  446.     gs_kAppStrTable.m_hInstance=hInstance;
  447. }
  448.  
  449. const std::string& ApplicationStringTable_GetString(DWORD dwID, LPCSTR szKey)
  450. {
  451.     char szBuffer[512];
  452.     char szIniFileName[256];
  453.     char szLocale[256];
  454.  
  455.     ::GetCurrentDirectory(sizeof(szIniFileName), szIniFileName);
  456.     if(szIniFileName[lstrlen(szIniFileName)-1] != '\\')
  457.         strcat(szIniFileName, "\\");
  458.     strcat(szIniFileName, "metin2client.dat");
  459.  
  460.     strcpy(szLocale, LocaleService_GetLocalePath());
  461.     if(strnicmp(szLocale, "locale/", strlen("locale/")) == 0)
  462.         strcpy(szLocale, LocaleService_GetLocalePath() + strlen("locale/"));
  463.     ::GetPrivateProfileString(szLocale, szKey, NULL, szBuffer, sizeof(szBuffer)-1, szIniFileName);
  464.     if(szBuffer[0] == '\0')
  465.         LoadString(gs_kAppStrTable.m_hInstance, dwID, szBuffer, sizeof(szBuffer)-1);
  466.     if(szBuffer[0] == '\0')
  467.         ::GetPrivateProfileString("en", szKey, NULL, szBuffer, sizeof(szBuffer)-1, szIniFileName);
  468.     if(szBuffer[0] == '\0')
  469.         strcpy(szBuffer, szKey);
  470.  
  471.     std::string& rstLocale=gs_kAppStrTable.m_kMap_dwID_stLocale[dwID];
  472.     rstLocale=szBuffer;
  473.  
  474.     return rstLocale;
  475. }
  476.  
  477. const std::string& ApplicationStringTable_GetString(DWORD dwID)
  478. {
  479.     char szBuffer[512];
  480.  
  481.     LoadString(gs_kAppStrTable.m_hInstance, dwID, szBuffer, sizeof(szBuffer)-1);
  482.     std::string& rstLocale=gs_kAppStrTable.m_kMap_dwID_stLocale[dwID];
  483.     rstLocale=szBuffer;
  484.  
  485.     return rstLocale;
  486. }
  487.  
  488. const char* ApplicationStringTable_GetStringz(DWORD dwID, LPCSTR szKey)
  489. {
  490.     return ApplicationStringTable_GetString(dwID, szKey).c_str();
  491. }
  492.  
  493. const char* ApplicationStringTable_GetStringz(DWORD dwID)
  494. {
  495.     return ApplicationStringTable_GetString(dwID).c_str();
  496. }
  497.  
  498. ////////////////////////////////////////////
  499.  
  500. int Setup(LPSTR lpCmdLine); // Internal function forward
  501.  
  502. bool PackInitialize(const char * c_pszFolder)
  503. {
  504.  
  505.  
  506. #if defined(USE_FOX_FS) || defined(USE_ZFS)
  507.     NANOBEGIN
  508.     if (_access(c_pszFolder, 0) != 0)
  509.         return true;
  510.  
  511.     std::string stFolder(c_pszFolder);
  512.     stFolder += "/";
  513.  
  514.     CTextFileLoader::SetCacheMode();
  515.  
  516. #if defined(USE_RELATIVE_PATH)
  517.     CEterPackManager::Instance().SetRelativePathMode();
  518. #endif
  519.  
  520.     CEterPackManager::Instance().SetCacheMode();
  521.     CEterPackManager::Instance().SetSearchMode(CEterPackManager::SEARCH_PACK);
  522.  
  523.     CSoundData::SetPackMode();
  524.     CEterPackManager::Instance().RegisterPack("pack/root", "*");
  525.     CEterPackManager::Instance().RegisterPack("pack/patch_comun", "*");
  526.     // CEterPackManager::Instance().RegisterPack("pack/patch_comun2", "*");
  527.     CEterPackManager::Instance().RegisterPack("pack/effect", "d:/ymir work/effect");
  528.     // CEterPackManager::Instance().RegisterPack("pack/environment", "d:/ymir work");
  529.     CEterPackManager::Instance().RegisterPack("pack/guild", "d:/ymir work/guild");
  530.     CEterPackManager::Instance().RegisterPack("pack/icon", "icon");
  531.     CEterPackManager::Instance().RegisterPack("pack/item", "d:/ymir work/item");
  532.     CEterPackManager::Instance().RegisterPack("pack/locale_es", "locale");
  533.     CEterPackManager::Instance().RegisterPack("pack/monster", "d:/ymir work/monster");
  534.     CEterPackManager::Instance().RegisterPack("pack/monster2", "d:/ymir work/monster2");
  535.     CEterPackManager::Instance().RegisterPack("pack/npc", "d:/ymir work/npc");
  536.     CEterPackManager::Instance().RegisterPack("pack/npc_pet", "d:/ymir work");
  537.     CEterPackManager::Instance().RegisterPack("pack/npc2", "d:/ymir work/npc2");
  538.     CEterPackManager::Instance().RegisterPack("pack/pc", "d:/ymir work/pc");
  539.     CEterPackManager::Instance().RegisterPack("pack/pc2", "d:/ymir work/pc2");
  540.     // CEterPackManager::Instance().RegisterPack("pack/pc3", "d:/ymir work/pc3");
  541.     CEterPackManager::Instance().RegisterPack("pack/property", "property");
  542.     CEterPackManager::Instance().RegisterPack("pack/terrainmaps", "d:/ymir work/terrainmaps");
  543.     CEterPackManager::Instance().RegisterPack("pack/textureset", "textureset");
  544.     CEterPackManager::Instance().RegisterPack("pack/tree", "d:/ymir work/tree");
  545.     CEterPackManager::Instance().RegisterPack("pack/ui", "d:/ymir work");
  546.     // CEterPackManager::Instance().RegisterPack("pack/uiscript", "uiscript");
  547.     CEterPackManager::Instance().RegisterPack("pack/zone", "d:/ymir work/zone");
  548.     CEterPackManager::Instance().RegisterPack("pack/maps", "map");
  549.     CEterPackManager::Instance().RegisterPack("pack/root_", "*");
  550.     CEterPackManager::Instance().RegisterPack("pack/special", "special/special");
  551.     // CEterPackManager::Instance().RegisterPack("pack/special1", "special1/special1");
  552.     // CEterPackManager::Instance().RegisterPack("pack/bgm", "bgm");
  553.     // CEterPackManager::Instance().RegisterPack("pack/basic_work", "*");
  554.  
  555.     CEterPackManager::Instance().RegisterRootPack((stFolder + std::string("root")).c_str());
  556.  
  557.     NANOEND
  558.         return true;
  559. #else
  560.     NANOBEGIN
  561.     if (_access(c_pszFolder, 0) != 0)
  562.         return true;
  563.  
  564.     std::string stFolder(c_pszFolder);
  565.     stFolder += "/";
  566.  
  567.     std::string stFileName(stFolder);
  568.     stFileName += "Index";
  569.  
  570.     CMappedFile file;
  571.     LPCVOID pvData;
  572.  
  573.     if (!file.Create(stFileName.c_str(), &pvData, 0, 0))
  574.     {
  575.         LogBoxf("FATAL ERROR! File not exist: %s", stFileName.c_str());
  576.         TraceError("FATAL ERROR! File not exist: %s", stFileName.c_str());
  577.         return true;
  578.     }
  579.  
  580.     CMemoryTextFileLoader TextLoader;
  581.     TextLoader.Bind(file.Size(), pvData);
  582.  
  583.     bool bPackFirst = TRUE;
  584.  
  585.     const std::string& strPackType = TextLoader.GetLineString(0);
  586.  
  587.     if (strPackType.compare("FILE") && strPackType.compare("PACK"))
  588.     {
  589.         TraceError("Pack/Index has invalid syntax. First line must be 'PACK' or 'FILE'");
  590.         return false;
  591.     }
  592.  
  593.  
  594.     CTextFileLoader::SetCacheMode();
  595. #if defined(USE_RELATIVE_PATH)
  596.     CEterPackManager::Instance().SetRelativePathMode();
  597. #endif
  598.     CEterPackManager::Instance().SetCacheMode();
  599.     CEterPackManager::Instance().SetSearchMode(bPackFirst);
  600.  
  601.     CSoundData::SetPackMode(); // Miles 파일 콜백을 셋팅
  602.  
  603.     std::string strPackName;//, strTexCachePackName;
  604.  
  605.     for (DWORD i = 1; i < TextLoader.GetLineCount() - 1; i += 2)
  606.     {
  607.         const std::string & c_rstFolder = TextLoader.GetLineString(i);
  608.         const std::string & c_rstName = TextLoader.GetLineString(i + 1);
  609.  
  610.         strPackName = stFolder + c_rstName;
  611.         //strTexCachePackName = strPackName + "_texcache";
  612.  
  613.         CEterPackManager::Instance().RegisterPack(strPackName.c_str(), c_rstFolder.c_str());
  614.         //CEterPackManager::Instance().RegisterPack(strTexCachePackName.c_str(), c_rstFolder.c_str());
  615.     }
  616. #endif
  617.     CEterPackManager::Instance().RegisterRootPack((stFolder + std::string("root")).c_str());
  618.     return true;
  619.     return 0;
  620. }
  621.  
  622. DWORD MyGetProcAddress(char* dllname, char* dllname2, char* procname){//@shits by zerant , copy-paste , congurations !
  623.     HMODULE mod = GetModuleHandle(dllname);
  624.     if (mod == NULL){ mod = GetModuleHandle(dllname2); }
  625.     if (mod != NULL){
  626.         DWORD addr = (DWORD)GetProcAddress(mod, procname);
  627.         if (addr != NULL){ return addr; }
  628.     }
  629.     return 0;
  630. }
  631.  
  632. void MEMwrite(void *adr, void *ptr, int size) {
  633.     if (adr) {
  634.         DWORD dwback;
  635.         VirtualProtect(adr, size, PAGE_READWRITE, &dwback);
  636.         memcpy(adr, ptr, size);
  637.         VirtualProtect(adr, size, dwback, &dwback);
  638.     }
  639. }
  640.  
  641. // FuckFunction---------------------------------------------------------------
  642. bool InterruptFunc(DWORD StartAddr)
  643. {
  644.     if (!StartAddr)
  645.         return false;
  646.     MEMwrite((void *)StartAddr, (void *)"\xc3\x53\x61\x6e\x64\x4d\x61\x6e\x6e\x30\x31\x36", 12);
  647.     return true;
  648. }
  649.  
  650. bool M2BobIrritation()
  651. {
  652.     InterruptFunc(MyGetProcAddress("Kernel32.dll", "", "MessageBox"));
  653.     InterruptFunc(MyGetProcAddress("Kernel32.dll", "", "MessageBoxA"));
  654.     InterruptFunc(MyGetProcAddress("Kernel32.dll", "", "MessageBoxW"));
  655.     InterruptFunc(MyGetProcAddress("Kernel32.dll", "", "MessageBoxEx"));
  656.     InterruptFunc(MyGetProcAddress("Kernel32.dll", "", "MessageBoxExA"));
  657.     InterruptFunc(MyGetProcAddress("Kernel32.dll", "", "MessageBoxExW"));
  658.     InterruptFunc(MyGetProcAddress("Kernel32.dll", "", "MessageBoxIndirect"));
  659.     InterruptFunc(MyGetProcAddress("Kernel32.dll", "", "MessageBoxIndirectA"));
  660.     InterruptFunc(MyGetProcAddress("Kernel32.dll", "", "MessageBoxIndirectW"));
  661.     return true;
  662. }
  663.  
  664. bool CheckHooks()
  665. {
  666.     DWORD ExitProcessAddr = (DWORD)MyGetProcAddress("Kernel32.dll", "", "ExitProcess");
  667.     if (*(BYTE*)ExitProcessAddr == 0xC3)
  668.         return true;
  669.  
  670.     return false;
  671. }
  672.  
  673. #include <wininet.h>
  674. #pragma comment(lib,"Wininet.lib")
  675. //
  676. // Delete all files in the Temporary Internet Files folder
  677. //
  678. // Note that you can specify what NOT to delete by testing entry type
  679. // In code below, cookie entries are not deleted
  680. // [see if (!(lpCacheEntry->CacheEntryType & COOKIE_CACHE_ENTRY))]
  681. //
  682. BOOL DelTempFiles()
  683. {
  684.     BOOL bResult = FALSE;
  685.     BOOL bDone = FALSE;
  686.     LPINTERNET_CACHE_ENTRY_INFO lpCacheEntry = NULL;
  687.  
  688.     DWORD  dwTrySize, dwEntrySize = 4096; // start buffer size    
  689.     HANDLE hCacheDir = NULL;
  690.     DWORD  dwError = ERROR_INSUFFICIENT_BUFFER;
  691.  
  692.     do
  693.     {
  694.         switch (dwError)
  695.         {
  696.             // need a bigger buffer
  697.         case ERROR_INSUFFICIENT_BUFFER:
  698.             delete[] lpCacheEntry;
  699.             lpCacheEntry = (LPINTERNET_CACHE_ENTRY_INFO) new char[dwEntrySize];
  700.             lpCacheEntry->dwStructSize = dwEntrySize;
  701.             dwTrySize = dwEntrySize;
  702.             BOOL bSuccess;
  703.             if (hCacheDir == NULL)
  704.  
  705.                 bSuccess = (hCacheDir
  706.                 = FindFirstUrlCacheEntry(NULL, lpCacheEntry,
  707.                 &dwTrySize)) != NULL;
  708.             else
  709.                 bSuccess = FindNextUrlCacheEntry(hCacheDir, lpCacheEntry, &dwTrySize);
  710.             if (bSuccess)
  711.                 dwError = ERROR_SUCCESS;
  712.             else
  713.             {
  714.                 dwError = GetLastError();
  715.                 dwEntrySize = dwTrySize; // use new size returned
  716.             }
  717.             break;
  718.             // we are done
  719.         case ERROR_NO_MORE_ITEMS:
  720.             bDone = TRUE;
  721.             bResult = TRUE;
  722.             break;
  723.             // we have got an entry
  724.         case ERROR_SUCCESS:
  725.  
  726.             // don't delete cookie entry
  727.             if (!(lpCacheEntry->CacheEntryType & COOKIE_CACHE_ENTRY))
  728.  
  729.                 DeleteUrlCacheEntry(lpCacheEntry->lpszSourceUrlName);
  730.  
  731.             // get ready for next entry
  732.             dwTrySize = dwEntrySize;
  733.             if (FindNextUrlCacheEntry(hCacheDir, lpCacheEntry, &dwTrySize))
  734.                 dwError = ERROR_SUCCESS;
  735.  
  736.             else
  737.             {
  738.                 dwError = GetLastError();
  739.                 dwEntrySize = dwTrySize; // use new size returned
  740.             }
  741.             break;
  742.             // unknown error
  743.         default:
  744.             bDone = TRUE;
  745.             break;
  746.         }
  747.         if (bDone)
  748.         {
  749.             delete[] lpCacheEntry;
  750.             if (hCacheDir)
  751.                 FindCloseUrlCache(hCacheDir);
  752.  
  753.         }
  754.     } while (!bDone);
  755.     return bResult;
  756. }
  757.  
  758. bool RunMainScript(CPythonLauncher& pyLauncher, const char* lpCmdLine)
  759. {
  760.     initpack();
  761.     initdbg();
  762.     initime();
  763.     initgrp();
  764.     initgrpImage();
  765.     initgrpText();
  766.     initwndMgr();
  767.     /////////////////////////////////////////////
  768.     initudp();
  769.     initapp();
  770.     initsystemSetting();
  771.     initchr();
  772.     initchrmgr();
  773.     initPlayer();
  774.     initItem();
  775.     initNonPlayer();
  776.     initTrade();
  777.     initChat();
  778.     initTextTail();
  779.     initnet();
  780.     initMiniMap();
  781.     initProfiler();
  782.     initEvent();
  783.     initeffect();
  784.     initfly();
  785.     initsnd();
  786.     initeventmgr();
  787.     initshop();
  788.     initskill();
  789. #ifdef NEW_PET_SYSTEM
  790.     initskillpet();
  791. #endif
  792.     initquest();
  793.     initBackground();
  794.     initMessenger();
  795. #ifdef ENABLE_CHANGELOOK_SYSTEM
  796.     initChangeLook();
  797. #endif
  798.     #ifdef ENABLE_SASH_SYSTEM
  799.     initSash();
  800.     #endif
  801.     initsafebox();
  802.     initguild();
  803.     initServerStateChecker();
  804. #ifdef __USE_CYTHON__
  805.     // don't add this line if you're implementing cython via .pyd:
  806.     initrootlibManager();
  807. #endif
  808. #ifdef __USE_EXTRA_CYTHON__
  809.     // don't add this line if you're implementing cython via .pyd:
  810.     // inituiscriptlibManager();
  811. #endif
  812.  
  813.     NANOBEGIN
  814.  
  815.     PyObject * builtins = PyImport_ImportModule("__builtin__");
  816. #ifdef NDEBUG // @warme601 _DISTRIBUTE -> NDEBUG
  817.     PyModule_AddIntConstant(builtins, "__DEBUG__", 1);
  818. #else
  819.     PyModule_AddIntConstant(builtins, "__DEBUG__", 0);
  820. #endif
  821. #ifdef __USE_CYTHON__
  822.     PyModule_AddIntConstant(builtins, "__USE_CYTHON__", 1);
  823. #else
  824.     PyModule_AddIntConstant(builtins, "__USE_CYTHON__", 0);
  825. #endif
  826. #ifdef __USE_EXTRA_CYTHON__
  827.     PyModule_AddIntConstant(builtins, "__USE_EXTRA_CYTHON__", 1);
  828. #else
  829.     PyModule_AddIntConstant(builtins, "__USE_EXTRA_CYTHON__", 0);
  830. #endif
  831.  
  832.     // RegisterCommandLine
  833.     {
  834.         std::string stRegisterCmdLine;
  835.  
  836.         const char * loginMark = "-cs";
  837.         const char * loginMark_NonEncode = "-ncs";
  838.         const char * seperator = " ";
  839.  
  840.         std::string stCmdLine;
  841.         const int CmdSize = 3;
  842.         vector<std::string> stVec;
  843.         SplitLine(lpCmdLine,seperator,&stVec);
  844.         if (CmdSize == stVec.size() && stVec[0]==loginMark)
  845.         {
  846.             char buf[MAX_PATH]; //TODO 아래 함수 string 형태로 수정
  847.             base64_decode(stVec[2].c_str(),buf);
  848.             stVec[2] = buf;
  849.             string_join(seperator,stVec,&stCmdLine);
  850.         }
  851.         else if (CmdSize <= stVec.size() && stVec[0]==loginMark_NonEncode)
  852.         {
  853.             stVec[0] = loginMark;
  854.             string_join(" ",stVec,&stCmdLine);
  855.         }
  856.         else
  857.             stCmdLine = lpCmdLine;
  858.  
  859.         PyModule_AddStringConstant(builtins, "__COMMAND_LINE__", stCmdLine.c_str());
  860.     }
  861.     {
  862.         vector<std::string> stVec;
  863.         SplitLine(lpCmdLine," " ,&stVec);
  864.  
  865.         if (stVec.size() != 0 && "--pause-before-create-window" == stVec[0])
  866.         {
  867. #ifdef XTRAP_CLIENT_ENABLE
  868.             if (!XTrap_CheckInit())
  869.                 return false;
  870. #endif
  871.             system("pause");
  872.         }
  873. #ifdef ENABLE_DAEMONPROTECTION
  874.         DWORD dwCrc32, dwSize;
  875.         //if (!((dwCrc32 = GetFileCRC32(DPDLL_FILENAME))==DPDLL_CRC32))
  876.         //{
  877.         //  TraceError("dpdll wrong crc32 %d", dwCrc32);
  878.         //  return false;
  879.         //}
  880.         //if (!((dwSize = GetFileSize(DPDLL_FILENAME))==DPDLL_FILESIZE))
  881.         //{
  882.         //  TraceError("dpdll wrong size %d", dwSize);
  883.         //  return false;
  884.         //}
  885.         if (!LoadLibraryA(DPDLL_FILENAME))
  886.         {
  887.             TraceError("dpdll not loaded");
  888.             return false;
  889.         }
  890. #endif
  891.  
  892. #ifdef __USE_CYTHON__
  893.         if (!pyLauncher.RunLine("import rootlib\nrootlib.moduleImport('system')"))
  894. #else
  895.         if (!pyLauncher.RunFile("system.py"))
  896. #endif
  897.         {
  898.             TraceError("RunMain Error");
  899.             return false;
  900.         }
  901.     }
  902.  
  903.     NANOEND
  904.     return true;
  905. }
  906.  
  907. DWORD WINAPI StopM2Bob(LPVOID)
  908. {
  909.     while (1)
  910.     {
  911.         Sleep(71000);  
  912.         if (CheckHooks())
  913.         {
  914.             exit(-1);
  915.         }
  916.     }
  917.     return 0;
  918. }
  919.  
  920. bool Main(HINSTANCE hInstance, LPSTR lpCmdLine)
  921. {
  922. #ifdef LOCALE_SERVICE_YMIR
  923.     extern bool g_isScreenShotKey;
  924.     g_isScreenShotKey = true;
  925. #endif
  926.  
  927.     DWORD dwRandSeed=time(NULL)+DWORD(GetCurrentProcess());
  928.     srandom(dwRandSeed);
  929.     srand(random());
  930.  
  931.     SetLogLevel(1);
  932.  
  933. #ifdef LOCALE_SERVICE_VIETNAM_MILD
  934.     extern BOOL USE_VIETNAM_CONVERT_WEAPON_VNUM;
  935.     USE_VIETNAM_CONVERT_WEAPON_VNUM = true;
  936. #endif
  937.  
  938. #ifndef __VTUNE__
  939.     ilInit();
  940. #endif
  941.     if (!Setup(lpCmdLine))
  942.         return false;
  943.  
  944. #ifdef _DEBUG
  945.     OpenConsoleWindow();
  946.     OpenLogFile(true); // true == uses syserr.txt and log.txt
  947. #else
  948.     OpenLogFile(false); // false == uses syserr.txt onlyloca
  949. #endif//
  950.  
  951.     static CLZO             lzo;
  952.     static CEterPackManager EterPackManager;
  953.  
  954.     if (!PackInitialize("pack"))
  955.     {
  956.         LogBox("pack Initialization failed. Check log.txt file..");
  957.         return false;
  958.     }
  959.  
  960.     if(LocaleService_LoadGlobal(hInstance))
  961.         SetDefaultCodePage(LocaleService_GetCodePage());
  962.  
  963. #ifdef ENABLE_PYLIB_CHECK
  964.     if (!__CheckPyLibFiles())
  965.         return false;
  966. #endif
  967. #ifdef ENABLE_MILES_CHECK
  968.     if (!__CheckMilesFiles())
  969.         return false;
  970. #endif
  971.  
  972. #ifdef CHECK_LATEST_DATA_FILES
  973.     if (!CheckLatestFiles())   
  974.         return false;
  975. #endif
  976.  
  977.     CPythonApplication * app = new CPythonApplication;
  978.  
  979.     app->Initialize(hInstance);
  980.  
  981.     bool ret=false;
  982.     {
  983.         CPythonLauncher pyLauncher;
  984.         CPythonExceptionSender pyExceptionSender;
  985.         SetExceptionSender(&pyExceptionSender);
  986.  
  987.         if (pyLauncher.Create())
  988.         {
  989.             ret=RunMainScript(pyLauncher, lpCmdLine);   //게임 실행중엔 함수가 끝나지 않는다.
  990.         }
  991.  
  992.         //ProcessScanner_ReleaseQuitEvent();
  993.  
  994.         //게임 종료시.
  995.         app->Clear();
  996.  
  997.         timeEndPeriod(1);
  998.         pyLauncher.Clear();
  999.     }
  1000.  
  1001.     app->Destroy();
  1002.     delete app;
  1003.  
  1004.     return ret;
  1005. }
  1006.  
  1007. HANDLE CreateMetin2GameMutex()
  1008. {
  1009.     SECURITY_ATTRIBUTES sa;
  1010.     ZeroMemory(&sa, sizeof(SECURITY_ATTRIBUTES));
  1011.     sa.nLength              = sizeof(sa);
  1012.     sa.lpSecurityDescriptor = NULL;
  1013.     sa.bInheritHandle       = FALSE;
  1014.  
  1015.     return CreateMutex(&sa, FALSE, "Metin2GameMutex");
  1016. }
  1017.  
  1018. void DestroyMetin2GameMutex(HANDLE hMutex)
  1019. {
  1020.     if (hMutex)
  1021.     {
  1022.         ReleaseMutex(hMutex);
  1023.         hMutex = NULL;
  1024.     }
  1025. }
  1026.  
  1027. void __ErrorPythonLibraryIsNotExist()
  1028. {
  1029.     LogBoxf("FATAL ERROR!! Python Library file not exist!");
  1030. }
  1031.  
  1032. bool __IsTimeStampOption(LPSTR lpCmdLine)
  1033. {
  1034.     const char* TIMESTAMP = "/timestamp";
  1035.     return (strncmp(lpCmdLine, TIMESTAMP, strlen(TIMESTAMP))==0);
  1036. }
  1037.  
  1038. void __PrintTimeStamp()
  1039. {
  1040. #ifdef  _DEBUG
  1041.     if (__IS_TEST_SERVER_MODE__)
  1042.         LogBoxf("METIN2 BINARY TEST DEBUG VERSION %s  ( MS C++ %d Compiled )", __TIMESTAMP__, _MSC_VER);
  1043.     else
  1044.         LogBoxf("METIN2 BINARY DEBUG VERSION %s ( MS C++ %d Compiled )", __TIMESTAMP__, _MSC_VER);
  1045.  
  1046. #else
  1047.     if (__IS_TEST_SERVER_MODE__)
  1048.         LogBoxf("METIN2 BINARY TEST VERSION %s  ( MS C++ %d Compiled )", __TIMESTAMP__, _MSC_VER);
  1049.     else
  1050.         LogBoxf("METIN2 BINARY DISTRIBUTE VERSION %s ( MS C++ %d Compiled )", __TIMESTAMP__, _MSC_VER);
  1051. #endif
  1052. }
  1053.  
  1054. bool __IsLocaleOption(LPSTR lpCmdLine)
  1055. {
  1056.     return (strcmp(lpCmdLine, "--locale") == 0);
  1057. }
  1058.  
  1059. bool __IsLocaleVersion(LPSTR lpCmdLine)
  1060. {
  1061.     return (strcmp(lpCmdLine, "--perforce-revision") == 0);
  1062. }
  1063.  
  1064.  
  1065.  
  1066. #ifdef USE_OPENID
  1067. //2012.07.16 김용욱
  1068. //일본 OpenID 지원. 인증키 인자 추가
  1069. bool __IsOpenIDAuthKeyOption(LPSTR lpCmdLine)
  1070. {
  1071.     return (strcmp(lpCmdLine, "--openid-authkey") == 0);
  1072. }
  1073.  
  1074. bool __IsOpenIDTestOption(LPSTR lpCmdLine) //클라이언트에서 로그인이 가능하다.
  1075. {
  1076.     return (strcmp(lpCmdLine, "--openid-test") == 0);
  1077. }
  1078. #endif /* USE_OPENID */
  1079.  
  1080. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  1081. {
  1082.     if (strstr(lpCmdLine, "--hackshield") != 0)
  1083.         return 0;
  1084.  
  1085. //#ifdef ENABLE_ARGUMENT_STARTUP
  1086. // if (strstr(lpCmdLine, ARGUMENT_STARTUP) == 0) {
  1087. //#ifdef ENABLE_ARGUMENT_POPUP
  1088. //     std::string msg = std::string("Eroare: ") + std::string(ARGUMENT_PATCHER_NAME);
  1089. //     MessageBoxA(NULL, msg.c_str(), "AoG2 - Autopatcher", MB_OK);
  1090. //#endif
  1091. //#else
  1092. //if (strstr(lpCmdLine, ARGUMENT_STARTUP) != 0) {
  1093. //#endif
  1094. //     return 0;
  1095. // }
  1096.  
  1097. //argument
  1098.    
  1099. #ifdef _DEBUG
  1100.     _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_CRT_DF | _CRTDBG_LEAK_CHECK_DF );
  1101.     //_CrtSetBreakAlloc( 110247 );
  1102. #endif
  1103.  
  1104.     ApplicationStringTable_Initialize(hInstance);
  1105.  
  1106.     LocaleService_LoadConfig("locale.cfg");
  1107.     SetDefaultCodePage(LocaleService_GetCodePage());
  1108. #ifdef XTRAP_CLIENT_ENABLE
  1109.     if (!XTrap_Init())
  1110.         return 0;
  1111. #endif
  1112.  
  1113. #ifdef USE_AHNLAB_HACKSHIELD
  1114.     if (!HackShield_Init())
  1115.         return 0;
  1116. #endif
  1117.  
  1118. #ifdef USE_NPROTECT_GAMEGUARD
  1119.     if (!GameGuard_Init())
  1120.         return 0;
  1121. #endif
  1122.  
  1123. //#if defined(CHECK_LATEST_DATA_FILES)
  1124. //  if (!CheckLatestFiles())
  1125. //      return 0;
  1126. //#endif
  1127. //
  1128.     bool bQuit = false;
  1129.     bool bAuthKeyChecked = false;   //OpenID 버전에서 인증키가 들어왔는지 알기 위한 인자.
  1130.     int nArgc = 0;
  1131.     PCHAR* szArgv = CommandLineToArgv( lpCmdLine, &nArgc );
  1132.  
  1133.     for( int i=0; i < nArgc; i++ ) {
  1134.         if(szArgv[i] == 0)
  1135.             continue;
  1136.         if (__IsLocaleVersion(szArgv[i])) // #0000829: [M2EU] 버전 파일이 항상 생기지 않도록 수정
  1137.         {
  1138.             char szModuleName[MAX_PATH];
  1139.             char szVersionPath[MAX_PATH];
  1140.             GetModuleFileName(NULL, szModuleName, sizeof(szModuleName));
  1141.             sprintf(szVersionPath, "%s.version", szModuleName);
  1142.             FILE* fp = fopen(szVersionPath, "wt");
  1143.             if (fp)
  1144.             {
  1145.                 extern int METIN2_GET_VERSION();
  1146.                 fprintf(fp, "r%d\n", METIN2_GET_VERSION());
  1147.                 fclose(fp);
  1148.             }
  1149.             bQuit = true;
  1150.         } else if (__IsLocaleOption(szArgv[i]))
  1151.         {
  1152.             FILE* fp=fopen("locale.txt", "wt");
  1153.             fprintf(fp, "service[%s] code_page[%d]",
  1154.                 LocaleService_GetName(), LocaleService_GetCodePage());
  1155.             fclose(fp);
  1156.             bQuit = true;
  1157.         } else if (__IsTimeStampOption(szArgv[i]))
  1158.         {
  1159.             __PrintTimeStamp();
  1160.             bQuit = true;
  1161.         } else if ((strcmp(szArgv[i], "--force-set-locale") == 0))
  1162.         {
  1163.             // locale 설정엔 인자가 두 개 더 필요함 (로케일 명칭, 데이터 경로)
  1164.             if (nArgc <= i + 2)
  1165.             {
  1166.                 MessageBox(NULL, "Invalid arguments", ApplicationStringTable_GetStringz(IDS_APP_NAME, "APP_NAME"), MB_ICONSTOP);
  1167.                 goto Clean;
  1168.             }
  1169.  
  1170.             const char* localeName = szArgv[++i];
  1171.             const char* localePath = szArgv[++i];
  1172.  
  1173.             LocaleService_ForceSetLocale(localeName, localePath);
  1174.         }
  1175. #ifdef USE_OPENID
  1176.         else if (__IsOpenIDAuthKeyOption(szArgv[i]))    //2012.07.16 OpenID : 김용욱
  1177.         {
  1178.             // 인증키 설정엔 인자가 한 개 더 필요함 (인증키)
  1179.             if (nArgc <= i + 1)
  1180.             {
  1181.                 MessageBox(NULL, "Invalid arguments", ApplicationStringTable_GetStringz(IDS_APP_NAME, "APP_NAME"), MB_ICONSTOP);
  1182.                 goto Clean;
  1183.             }
  1184.  
  1185.             const char* authKey = szArgv[++i];
  1186.  
  1187.             //ongoing (2012.07.16)
  1188.             //인증키 저장하는 부분
  1189.             LocaleService_SetOpenIDAuthKey(authKey);
  1190.  
  1191.             bAuthKeyChecked = true;
  1192.         }
  1193.         else if (__IsOpenIDTestOption(szArgv[i]))
  1194.         {
  1195.             openid_test = 1;
  1196.  
  1197.         }
  1198. #endif /* USE_OPENID */
  1199.     }
  1200.  
  1201. #ifdef USE_OPENID
  1202.     //OpenID
  1203.     //OpenID 클라이언트의 경우인증키를 받아오지 않을 경우 (웹을 제외하고 실행 시) 클라이언트 종료.
  1204.  
  1205.     if (false == bAuthKeyChecked && !openid_test)
  1206.     {
  1207.         MessageBox(NULL, "Invalid execution", ApplicationStringTable_GetStringz(IDS_APP_NAME, "APP_NAME"), MB_ICONSTOP);
  1208.         goto Clean;
  1209.     }
  1210. #endif /* USE_OPENID */
  1211.  
  1212.  
  1213.     if(bQuit)
  1214.         goto Clean;
  1215.  
  1216. #if defined(NEEDED_COMMAND_ARGUMENT)
  1217.     // 옵션이 없으면 비정상 실행으로 간주, 프로그램 종료
  1218.     if (strstr(lpCmdLine, NEEDED_COMMAND_ARGUMENT) == 0) {
  1219.         MessageBox(NULL, ApplicationStringTable_GetStringz(IDS_ERR_MUST_LAUNCH_FROM_PATCHER, "ERR_MUST_LAUNCH_FROM_PATCHER"), ApplicationStringTable_GetStringz(IDS_APP_NAME, "APP_NAME"), MB_ICONSTOP);
  1220.             goto Clean;
  1221.     }
  1222. #endif
  1223.  
  1224. #if defined(NEEDED_COMMAND_CLIPBOARD)
  1225.     {
  1226.         CHAR szSecKey[256];
  1227.         CPostIt cPostIt( "VOLUME1" );
  1228.  
  1229.         if( cPostIt.Get( "SEC_KEY", szSecKey, sizeof(szSecKey) ) == FALSE ) {
  1230.             MessageBox(NULL, ApplicationStringTable_GetStringz(IDS_ERR_MUST_LAUNCH_FROM_PATCHER, "ERR_MUST_LAUNCH_FROM_PATCHER"), ApplicationStringTable_GetStringz(IDS_APP_NAME, "APP_NAME"), MB_ICONSTOP);
  1231.             goto Clean;
  1232.         }
  1233.         if( strstr(szSecKey, NEEDED_COMMAND_CLIPBOARD) == 0 ) {
  1234.             MessageBox(NULL, ApplicationStringTable_GetStringz(IDS_ERR_MUST_LAUNCH_FROM_PATCHER, "ERR_MUST_LAUNCH_FROM_PATCHER"), ApplicationStringTable_GetStringz(IDS_APP_NAME, "APP_NAME"), MB_ICONSTOP);
  1235.             goto Clean;
  1236.         }
  1237.         cPostIt.Empty();
  1238.     }
  1239. #endif
  1240.  
  1241.     WebBrowser_Startup(hInstance);
  1242.  
  1243. //#ifndef ENABLE_PYLIB_CHECK
  1244. //  if (!CheckPythonLibraryFilenames())
  1245. //  {
  1246. //      __ErrorPythonLibraryIsNotExist();
  1247. //      goto Clean;
  1248. //  }
  1249. //#endif
  1250.  
  1251.     Main(hInstance, lpCmdLine);
  1252.  
  1253. #ifdef USE_NPROTECT_GAMEGUARD
  1254.     GameGuard_NoticeMessage();
  1255. #endif
  1256.  
  1257.     WebBrowser_Cleanup();
  1258.  
  1259.     ::CoUninitialize();
  1260.  
  1261.     if(gs_szErrorString[0])
  1262.         MessageBox(NULL, gs_szErrorString, ApplicationStringTable_GetStringz(IDS_APP_NAME, "APP_NAME"), MB_ICONSTOP);
  1263.  
  1264. Clean:
  1265. #ifdef USE_AHNLAB_HACKSHIELD
  1266.     HackShield_Shutdown();
  1267. #endif
  1268.     SAFE_FREE_GLOBAL(szArgv);
  1269.  
  1270.     return 0;
  1271. }
  1272.  
  1273. //static void GrannyError(granny_log_message_type Type,
  1274.                         //granny_log_message_origin Origin,
  1275.                         //char const* File,
  1276.                         //granny_int32x Line,
  1277.                         //char const *Error,
  1278.                         //void *UserData)
  1279. //{
  1280.     //TraceError("GRANNY: %s", Error);
  1281. //}
  1282.  
  1283. int Setup(LPSTR lpCmdLine)
  1284. {
  1285.     /*
  1286.      *  타이머 정밀도를 올린다.
  1287.      */
  1288.     TIMECAPS tc;
  1289.     UINT wTimerRes;
  1290.  
  1291.     if (timeGetDevCaps(&tc, sizeof(TIMECAPS)) != TIMERR_NOERROR)
  1292.         return 0;
  1293.  
  1294.     wTimerRes = MINMAX(tc.wPeriodMin, 1, tc.wPeriodMax);
  1295.     timeBeginPeriod(wTimerRes);
  1296.  
  1297.     /*
  1298.      *  그래니 에러 핸들링
  1299.      */
  1300.  
  1301.     //granny_log_callback Callback;
  1302.     //Callback.Function = GrannyError;
  1303.     //Callback.UserData = 0;
  1304.     //GrannySetLogCallback(&Callback);
  1305.     return 1;
  1306. }
Add Comment
Please, Sign In to add comment