Advertisement
Guest User

Wanesa's ddopreload.exe

a guest
Feb 14th, 2013
524
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.24 KB | None | 0 0
  1. // ddopreload.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5.  
  6.  
  7. //#pragma optimize( "", off )
  8. unsigned char __declspec(noinline) readMapFile( void * k, DWORD i )
  9. {
  10.     return *((unsigned char *)k+i);
  11. }
  12. //#pragma optimize( "", on )
  13.  
  14. void cleanupMemory() {
  15.     _tprintf_s(_T("Allocating space for cache...\n"));
  16.     HANDLE hmap = CreateFileMapping(0,0,PAGE_READWRITE,0,1280*1024*1024,0);
  17.     void *p = MapViewOfFile(hmap,FILE_MAP_ALL_ACCESS,0,0,0);
  18.     for (DWORD i = 0; i < 1280*1024*1024; i+=1024) {
  19.         *((unsigned char *)p+i) = 1;
  20.     }
  21.     UnmapViewOfFile(p);
  22.     CloseHandle(hmap);
  23. }
  24.  
  25. void preloadFile(LPCTSTR fname) {
  26.  
  27.     HANDLE h = CreateFile(fname,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0);
  28.     if (h == 0 || h == INVALID_HANDLE_VALUE) {
  29.         _ftprintf_s(stderr,_T("Can't open file '%s'\n"),fname);
  30.         return;
  31.     }
  32.     HANDLE hmap = CreateFileMapping(h,0,PAGE_READONLY ,0,0,0);
  33.     CloseHandle(h);
  34.     if (hmap == 0 || hmap == INVALID_HANDLE_VALUE)
  35.     {
  36.         _ftprintf_s(stderr,_T("Can't open mapping for file '%s'\n"),fname);
  37.         return;
  38.     }
  39.     void *k = MapViewOfFile(hmap,FILE_MAP_READ ,0,0,0);
  40.     if (k == 0) {
  41.         _ftprintf_s(stderr,_T("Can't map file '%s'\n"),fname);
  42.         CloseHandle(hmap);
  43.         return;
  44.     }
  45.    
  46.     MEMORY_BASIC_INFORMATION inf;
  47.     VirtualQuery(k,&inf,sizeof(inf));
  48.     _tprintf_s(_T("Preloading file: '%s' (%u KiB)\n"),fname,inf.RegionSize/1024);
  49.     byte b = 0;
  50.     for (DWORD i = 0; i < inf.RegionSize; i+=1024) {
  51.         b = b ^ readMapFile(k,i);
  52.        
  53.     }
  54.  
  55.     CloseHandle(hmap);
  56.     printf("Done: %d\n",b);
  57. }
  58.  
  59. int _tmain(int argc, _TCHAR* argv[])
  60. {
  61.     STARTUPINFO nfo;
  62.     ZeroMemory(&nfo,sizeof(nfo));
  63.     PROCESS_INFORMATION pi;
  64.     nfo.cb = sizeof(nfo);
  65.     CreateProcess(_T("TurbineLauncher.exe"),_T("TurbineLauncher.exe -invoker"),0,0,0,0,0,0,&nfo,&pi);
  66.     WaitForInputIdle(pi.hProcess,INFINITE);
  67.     cleanupMemory();
  68.     preloadFile(_T("dndclient.exe"));
  69. //  preloadFile(_T("client_surface.dat"));
  70. //  preloadFile(_T("client_local_English.dat"));
  71. //  preloadFile(_T("client_general.dat"));
  72.     preloadFile(_T("client_gamelogic.dat"));
  73. /*  preloadFile(_T("client_map_1.dat"));
  74.     preloadFile(_T("client_map_2.dat"));
  75.     preloadFile(_T("client_mesh.dat"));
  76.     preloadFile(_T("client_cell_2.dat"));
  77.     preloadFile(_T("client_cell_1.dat"));*/
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement