Advertisement
Guest User

Untitled

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