Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ddopreload.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- //#pragma optimize( "", off )
- unsigned char __declspec(noinline) readMapFile( void * k, DWORD i )
- {
- return *((unsigned char *)k+i);
- }
- //#pragma optimize( "", on )
- void cleanupMemory() {
- _tprintf_s(_T("Allocating space for cache...\n"));
- HANDLE hmap = CreateFileMapping(0,0,PAGE_READWRITE,0,1280*1024*1024,0);
- void *p = MapViewOfFile(hmap,FILE_MAP_ALL_ACCESS,0,0,0);
- for (DWORD i = 0; i < 1280*1024*1024; i+=1024) {
- *((unsigned char *)p+i) = 1;
- }
- UnmapViewOfFile(p);
- CloseHandle(hmap);
- }
- void preloadFile(LPCTSTR fname) {
- HANDLE h = CreateFile(fname,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0);
- if (h == 0 || h == INVALID_HANDLE_VALUE) {
- _ftprintf_s(stderr,_T("Can't open file '%s'\n"),fname);
- return;
- }
- HANDLE hmap = CreateFileMapping(h,0,PAGE_READONLY ,0,0,0);
- CloseHandle(h);
- if (hmap == 0 || hmap == INVALID_HANDLE_VALUE)
- {
- _ftprintf_s(stderr,_T("Can't open mapping for file '%s'\n"),fname);
- return;
- }
- void *k = MapViewOfFile(hmap,FILE_MAP_READ ,0,0,0);
- if (k == 0) {
- _ftprintf_s(stderr,_T("Can't map file '%s'\n"),fname);
- CloseHandle(hmap);
- return;
- }
- MEMORY_BASIC_INFORMATION inf;
- VirtualQuery(k,&inf,sizeof(inf));
- _tprintf_s(_T("Preloading file: '%s' (%u KiB)\n"),fname,inf.RegionSize/1024);
- byte b = 0;
- for (DWORD i = 0; i < inf.RegionSize; i+=1024) {
- b = b ^ readMapFile(k,i);
- }
- CloseHandle(hmap);
- printf("Done: %d\n",b);
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- STARTUPINFO nfo;
- ZeroMemory(&nfo,sizeof(nfo));
- PROCESS_INFORMATION pi;
- nfo.cb = sizeof(nfo);
- CreateProcess(_T("TurbineLauncher.exe"),_T("TurbineLauncher.exe -invoker"),0,0,0,0,0,0,&nfo,&pi);
- WaitForInputIdle(pi.hProcess,INFINITE);
- cleanupMemory();
- preloadFile(_T("dndclient.exe"));
- // preloadFile(_T("client_surface.dat"));
- // preloadFile(_T("client_local_English.dat"));
- // preloadFile(_T("client_general.dat"));
- preloadFile(_T("client_gamelogic.dat"));
- /* preloadFile(_T("client_map_1.dat"));
- preloadFile(_T("client_map_2.dat"));
- preloadFile(_T("client_mesh.dat"));
- preloadFile(_T("client_cell_2.dat"));
- preloadFile(_T("client_cell_1.dat"));*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement