//--------------------------------------------------------------------------- // This function pulls the raw compressed data out of the file and sticks it in the buffer // passed in. This way, we can load the textures directly from file to RAM and not // have to decompress them!! long FastFile::readFastRAW (long fastFileHandle, void *bfr, long size) { size; long result = 0; if ((fastFileHandle >= 0) && (fastFileHandle < numFiles) && files[fastFileHandle].inuse) { logicalPosition = fseek(handle,files[fastFileHandle].pos + files[fastFileHandle].pfe->offset,SEEK_SET); if (size >= files[fastFileHandle].pfe->size) { result = fread(bfr,1,files[fastFileHandle].pfe->size,handle); logicalPosition += files[fastFileHandle].pfe->size; } if (result != files[fastFileHandle].pfe->size) { //READ Error. Maybe the CD is missing? bool openFailed = false; bool alreadyFullScreen = (Environment.fullScreen != 0); while (result != files[fastFileHandle].pfe->size) { openFailed = true; EnterWindowMode(); char data[2048]; sprintf(data,FileMissingString,fileName,CDMissingString); DWORD result1 = MessageBox(NULL,data,MissingTitleString,MB_OKCANCEL | MB_ICONWARNING); if (result1 == IDCANCEL) { ExitGameOS(); return (2); //File not found. Never returns though! } logicalPosition = fseek(handle,files[fastFileHandle].pos + files[fastFileHandle].pfe->offset,SEEK_SET); result = fread(bfr,1,files[fastFileHandle].pfe->size,handle); logicalPosition += files[fastFileHandle].pfe->size; } if (openFailed && (Environment.fullScreen == 0) && alreadyFullScreen) EnterFullScreenMode(); } return result; } return FILE_NOT_OPEN; }
LONG WINAPI DwExceptionFilter(LPEXCEPTION_POINTERS pep) { EXCEPTION_RECORD *per; HANDLE hFileMap; DWSharedMem *pdwsm; SECURITY_ATTRIBUTES sa; //------------------------------------------------------------------------------------------------------------ // we keep local copies of these in case another thread is trashing memory // it much more likely to trash the heap than our stack HANDLE hEventDone; // event DW signals when done HANDLE hEventAlive; // heartbeat event DW signals per EVENT_TIMEOUT HANDLE hMutex; // to protect the signaling of EventDone char szCommandLine[MAX_PATH * 2]; DWORD dw; BOOL fDwRunning; STARTUPINFO si; PROCESS_INFORMATION pi; //------------------------------------------------------------------------------------------------------------ // init - Check if we just hit a breakpoint. If so, continue execution. Debugger will take care of itself. per = pep->ExceptionRecord; if (EXCEPTION_BREAKPOINT == per->ExceptionCode) return 0; //------------------------------------------------------------------------------------------------------------ // create shared memory memset(&sa, 0, sizeof(SECURITY_ATTRIBUTES)); sa.nLength = sizeof(SECURITY_ATTRIBUTES); sa.bInheritHandle = TRUE; hFileMap = CreateFileMapping(INVALID_HANDLE_VALUE, &sa, PAGE_READWRITE, 0, sizeof(DWSharedMem), NULL); if (hFileMap == NULL) { //At this point, call the GameOS exception handler and convert the pep to the data they need! ProcessException(pep); return 1; } pdwsm = (DWSharedMem *) MapViewOfFile(hFileMap, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0); if (pdwsm == NULL) { //At this point, call the GameOS exception handler and convert the pep to the data they need! ProcessException(pep); return 1; } memset(pdwsm, 0, sizeof(DWSharedMem)); hEventAlive = CreateEvent(&sa, FALSE, FALSE, NULL); hEventDone = CreateEvent(&sa, FALSE, FALSE, NULL); hMutex = CreateMutex(&sa, FALSE, NULL); if (!DuplicateHandle(GetCurrentProcess(), GetCurrentProcess(), GetCurrentProcess(), &pdwsm->hProc, PROCESS_ALL_ACCESS, TRUE, 0)) { //At this point, call the GameOS exception handler and convert the pep to the data they need! ProcessException(pep); return 1; } if (hEventAlive == NULL || hEventDone == NULL || hMutex == NULL || pdwsm->hProc == NULL) { //At this point, call the GameOS exception handler and convert the pep to the data they need! ProcessException(pep); return 1; } //------------------------------------------------------------------------------------------------------------ // setup interface structure pdwsm->pid = GetCurrentProcessId(); pdwsm->tid = GetCurrentThreadId(); pdwsm->hEventAlive = hEventAlive; pdwsm->hEventDone = hEventDone; pdwsm->hMutex = hMutex; pdwsm->dwSize = sizeof(DWSharedMem); pdwsm->pep = pep; pdwsm->eip = (DWORD) pep->ExceptionRecord->ExceptionAddress; pdwsm->bfmsoctdsOffer = msoctdsQuit; pdwsm->bfmsoctdsLetRun = msoctdsQuit; pdwsm->bfDWBehaviorFlags = fDwCheckSig; strcpy(pdwsm->szFormalAppName, Environment.applicationName); strcpy(pdwsm->szInformalAppName, "MechCommander 2"); strcpy(pdwsm->szRegSubPath, "Software\\Microsoft\\Microsoft Games\\"); strcat(pdwsm->szRegSubPath, Environment.applicationName); // strcpy(pdwsm->szLCIDKeyValue, ""); // strcpy(pdwsm->szPIDRegKey, "HKLM\\Software\\Microsoft\\Internet Explorer\\Registration\\DigitalProductID"); #if defined(FINAL) || defined(EXTERNAL) strcpy(pdwsm->szServer, "watson.microsoft.com"); #else strcpy(pdwsm->szServer, "officewatson"); #endif wcscpy(pdwsm->wzErrorMessage, WatsonCrashMessageUnicode); //Leave this alone? No idea what it does. Not in Docs. // OK, I kinda know now. These are DLLs that Watson can check for goodness at crash time. // COOL, because the end user might have mucked with the EXE or data and this allows us to // report that information back to the server. memcpy(pdwsm->wzDotDataDlls, L"mc2res.dll\0editores.dll\0", 24 * sizeof(WCHAR)); GetModuleFileNameA(NULL, pdwsm->szModuleFileName, DW_MAX_PATH); //Additional Files for MechCommander? Should there be any? Log files, etc. // ok, now we don't want to accidently change this memset(&si, 0, sizeof(STARTUPINFO)); si.cb = sizeof(STARTUPINFO); memset(&pi, 0, sizeof(PROCESS_INFORMATION)); wsprintfA(szCommandLine, "dw -x -s %u", (DWORD) hFileMap); //Check if we are in fullScreen mode. If so, switch back to WindowMode to insure DW screen comes up. if(Environment.fullScreen && hWindow ) EnterWindowMode(); if (CreateProcessA(NULL, szCommandLine, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE | NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi)) { fDwRunning = TRUE; while (fDwRunning) { if (WaitForSingleObject(hEventAlive, DW_TIMEOUT_VALUE * 100) == WAIT_OBJECT_0) { if (WaitForSingleObject(hEventDone, 1) == WAIT_OBJECT_0) { fDwRunning = FALSE; } continue; } // we timed-out waiting for DW to respond, try to quit dw = WaitForSingleObject(hMutex, DW_TIMEOUT_VALUE); if (dw == WAIT_TIMEOUT) { fDwRunning = FALSE; // either DW's hung or crashed, we must carry on } else if (dw == WAIT_ABANDONED) { fDwRunning = FALSE; ReleaseMutex(hMutex); } else { // DW has not woken up? if (WaitForSingleObject(hEventAlive, 1) != WAIT_OBJECT_0) // tell DW we're through waiting for it's sorry self { SetEvent(hEventDone); fDwRunning = FALSE; } else { // are we done if (WaitForSingleObject(hEventDone, 1) == WAIT_OBJECT_0) fDwRunning = FALSE; } ReleaseMutex(hMutex); } } #if 0 // did we get attached? // Again, do NOT term the current APP. Late GameOS have its shot at the exception. if (WaitForSingleObject(hEventDBAttach, 1) == WAIT_OBJECT_0) { // yes, die MessageBox(NULL, "DB Attach ", "out", MB_OK); CloseHandle(hEventAlive); CloseHandle(hEventDone); CloseHandle(hMutex); TerminateProcess(GetCurrentProcess(), 0); } #endif // no, clean up CloseHandle(hEventAlive); CloseHandle(hEventDone); CloseHandle(hMutex); } // end if CreateProcess succeeded UnmapViewOfFile(pdwsm); CloseHandle(hFileMap); //At this point, call the GameOS exception handler and convert the pep to the data they need! ProcessException(pep); return 1; }
bool ForceGroupBar::setPilotVideo( const char* pVideo, MechWarrior* pPilot ) { if ( !pVideo ) { if ( ForceGroupIcon::bMovie ) { delete ForceGroupIcon::bMovie; ForceGroupIcon::bMovie = NULL; } else if ( ForceGroupIcon::pilotVideoTexture ) gos_DestroyTexture( ForceGroupIcon::pilotVideoTexture ); ForceGroupIcon::pilotVideoTexture = 0; ForceGroupIcon::pilotVideoPilot = 0; } else if (ForceGroupIcon::bMovie || ControlGui::instance->isMoviePlaying() || ForceGroupIcon::pilotVideoTexture || !prefs.pilotVideos) { // one already playing... // OR we don't want them playing. return 0; } else { for ( int i = 0; i < iconCount; i++ ) { if ( icons[i] && icons[i]->unit->getPilot() == pPilot ) { ForceGroupIcon::pilotVideoPilot = pPilot; FullPathFileName aviPath; aviPath.init( moviePath, pVideo, ".bik" ); if ( (frameRate > 15.0) && fileExists(aviPath) && prefs.pilotVideos) // This is about correct. Slower then this and movie has hard time keeping up! { //Update the RECT every frame. What if we shift Icons around cause someone died!! RECT vRect; vRect.left = icons[i]->bmpLocation[icons[i]->locationIndex][1].x; vRect.right = icons[i]->pilotLocation[icons[i]->locationIndex][2]; vRect.top = icons[i]->bmpLocation[icons[i]->locationIndex][3].y; vRect.bottom = icons[i]->bmpLocation[icons[i]->locationIndex][1].y; ForceGroupIcon::bMovie = new MC2Movie; ForceGroupIcon::bMovie->init(aviPath,vRect,true); } else // make a still texture { char realPilotName[9]; //Set everything to zero so the strncpy below doesn't go off into LALA land!! memset(realPilotName,0,9); strncpy(realPilotName,pPilot->getName(),8); FullPathFileName path; path.init( moviePath, realPilotName, ".tga" ); if (fileExists(path)) ForceGroupIcon::pilotVideoTexture = gos_NewTextureFromFile( gos_Texture_Solid, path, 0 ); else { char realMovieName[256]; char realMoviePath[1024]; _splitpath(path,NULL,realMoviePath,realMovieName,NULL); //Not in main installed directory and not in fastfile. Look on CD. char actualPath[2048]; strcpy(actualPath,CDInstallPath); strcat(actualPath,realMoviePath); strcat(actualPath,realMovieName); strcat(actualPath,".tga"); bool fileThere = fileExists(actualPath); if (fileThere) ForceGroupIcon::pilotVideoTexture = gos_NewTextureFromFile( gos_Texture_Solid, actualPath, 0 ); bool openFailed = false; while (!fileThere) { openFailed = true; EnterWindowMode(); char data[2048]; char msg[1024]; char msg1[512]; char title[256]; cLoadString(IDS_MC2_movieMISSING,msg1,511); cLoadString(IDS_MC2_CDMISSING,msg,1023); cLoadString(IDS_MC2_MISSING_TITLE,title,255); sprintf(data,msg1,path,msg); DWORD result = MessageBox(NULL,data,title,MB_OKCANCEL | MB_ICONWARNING); if (result == IDCANCEL) { ExitGameOS(); return 1; } fileThere = fileExists(actualPath); if (fileThere) ForceGroupIcon::pilotVideoTexture = gos_NewTextureFromFile( gos_Texture_Solid, actualPath, 0 ); } if (openFailed && (Environment.fullScreen == 0) && prefs.fullScreen) EnterFullScreenMode(); } } break; } } } return 1; }
//--------------------------------------------------------------------------- long FastFile::open (char* fName) { //------------------------------------------------------------- long fNameLength = strlen(fName); fileName = new char [fNameLength+1]; //fileName = (char *)gos_Malloc(fNameLength+1); //magic 26092011 if (!fileName) return(NO_RAM_FOR_FILENAME); strncpy(fileName,fName,fNameLength+1); handle = fopen(fileName,"r"); if (handle != NULL) { logicalPosition = 0; fileSize(); //Sets Length } else { //Check on CD. They may not have been installed. char actualPath[2048]; strcpy(actualPath,CDInstallPath); strcat(actualPath,fileName); handle = fopen(actualPath,"r"); if (handle == NULL) { //OPEN Error. Maybe the CD is missing? bool openFailed = false; bool alreadyFullScreen = (Environment.fullScreen != 0); while (handle == NULL) { openFailed = true; EnterWindowMode(); char data[2048]; sprintf(data,FileMissingString,fileName,CDMissingString); DWORD result1 = MessageBox(NULL,data,MissingTitleString,MB_OKCANCEL | MB_ICONWARNING); if (result1 == IDCANCEL) { ExitGameOS(); return (2); //File not found. Never returns though! } handle = fopen(actualPath,"r"); } if (openFailed && (Environment.fullScreen == 0) && alreadyFullScreen) EnterFullScreenMode(); } else { logicalPosition = 0; fileSize(); //Sets Length } } //--------------------------------------------- //-- Read in ALL of the file names and offsets logicalPosition = fseek(handle,0,SEEK_SET); //--------------------------------------------- //-- First Long is Version Number of FastFile unsigned long result = 0; unsigned long version = 0; result = fread((&version),1,sizeof(long),handle); logicalPosition += sizeof(long); if (result != sizeof(long)) { long lastError = errno; return lastError; } if (version != FASTFILE_VERSION && version != FASTFILE_VERSION_LZ) return FASTFILE_VERSION; if (version == FASTFILE_VERSION_LZ) useLZCompress = true; //--------------------------------------------- //-- Second Long is number of filenames present. result = fread((&numFiles),1,sizeof(long),handle); logicalPosition += sizeof(long); if (result != sizeof(long)) { long lastError = errno; return lastError; } files = (FILE_HANDLE*)malloc(sizeof(FILE_HANDLE) * numFiles); for (long i=0;i<numFiles;i++) { files[i].pfe = (FILEENTRY *)malloc(sizeof(FILEENTRY)); memset(files[i].pfe,0,sizeof(FILEENTRY)); unsigned long result = 0; result = fread(files[i].pfe,1,sizeof(FILEENTRY),handle); files[i].inuse = FALSE; files[i].pos = 0; } return (result); }
//--------------------------------------------------------------------------- long FastFile::readFast (long fastFileHandle, void *bfr, long size) { size; long result = 0; if ((fastFileHandle >= 0) && (fastFileHandle < numFiles) && files[fastFileHandle].inuse) { logicalPosition = fseek(handle,files[fastFileHandle].pos + files[fastFileHandle].pfe->offset,SEEK_SET); //ALL files in the fast file are now zLib compressed. NO EXCEPTIONS!! // This fixes a bug where the zLib Compressed version is the same length // as the raw version. Yikes but this is rare. Finally happened though! // -fs /* if (files[fastFileHandle].pfe->size == files[fastFileHandle].pfe->realSize) { result = fread(bfr,1,size,handle); logicalPosition += size; if (result != size) { long lastError = errno; return lastError; } } else //File is NOW zLib Compressed. Read In Appropriately */ { if (!LZPacketBuffer) { LZPacketBuffer = (MemoryPtr)malloc(LZPacketBufferSize); if (!LZPacketBuffer) return 0; } if ((long)LZPacketBufferSize < files[fastFileHandle].pfe->size) { LZPacketBufferSize = files[fastFileHandle].pfe->size; free(LZPacketBuffer); LZPacketBuffer = (MemoryPtr)malloc(LZPacketBufferSize); if (!LZPacketBuffer) return 0; } if (LZPacketBuffer) { result = fread(LZPacketBuffer,1,files[fastFileHandle].pfe->size,handle); logicalPosition += files[fastFileHandle].pfe->size; if (result != files[fastFileHandle].pfe->size) { //READ Error. Maybe the CD is missing? bool openFailed = false; bool alreadyFullScreen = (Environment.fullScreen != 0); while (result != files[fastFileHandle].pfe->size) { openFailed = true; EnterWindowMode(); char data[2048]; sprintf(data,FileMissingString,fileName,CDMissingString); DWORD result1 = MessageBox(NULL,data,MissingTitleString,MB_OKCANCEL | MB_ICONWARNING); if (result1 == IDCANCEL) { ExitGameOS(); return (2); //File not found. Never returns though! } logicalPosition = fseek(handle,files[fastFileHandle].pos + files[fastFileHandle].pfe->offset,SEEK_SET); result = fread(LZPacketBuffer,1,files[fastFileHandle].pfe->size,handle); logicalPosition += files[fastFileHandle].pfe->size; } if (openFailed && (Environment.fullScreen == 0) && alreadyFullScreen) EnterFullScreenMode(); } //-------------------------------------------------------- //USED to LZ Compress here. It is NOW zLib Compression. // We should not try to use old fastfiles becuase version check above should fail when trying to open!! unsigned long decompLength = 0; if (useLZCompress) { decompLength = LZDecomp((MemoryPtr)bfr,LZPacketBuffer,files[fastFileHandle].pfe->size); } else { decompLength = files[fastFileHandle].pfe->realSize; long error = uncompress((MemoryPtr)bfr,&decompLength,LZPacketBuffer,files[fastFileHandle].pfe->size); if (error != Z_OK) STOP(("Error %d UnCompressing File %s from FastFile %s",error,files[fastFileHandle].pfe->name,fileName)); } if ((long)decompLength != files[fastFileHandle].pfe->realSize) result = 0; else result = decompLength; } } return result; } return FILE_NOT_OPEN; }
//--------------------------------------------------------------------------- long File::open (const char* fName, FileMode _mode, long numChild) { gosASSERT( !isOpen() ); //------------------------------------------------------------- long fNameLength = strlen(fName); fileName = (char *)systemHeap->Malloc(fNameLength+1); gosASSERT(fileName != NULL); strncpy(fileName,fName,fNameLength+1); fileMode = _mode; _fmode = _O_BINARY; _strlwr(fileName); if (fileMode == CREATE) { handle = _creat(fileName,_S_IWRITE); if (handle == INVALID_HANDLE_VALUE) { lastError = errno; return lastError; } } else { //---------------------------------------------------------------- //-- First, see if file is in normal place. Useful for patches!! handle = _open(fileName,_O_RDONLY); //------------------------------------------ //-- Next, see if file is in fastFile. if (handle == INVALID_HANDLE_VALUE) { lastError = errno; fastFile = FastFileFind(fileName,fastFileHandle); if (!fastFile) { //Not in main installed directory and not in fastfile. Look on CD. char actualPath[2048]; strcpy(actualPath,CDInstallPath); strcat(actualPath,fileName); handle = _open(actualPath,_O_RDONLY); if (handle == INVALID_HANDLE_VALUE) { bool openFailed = false; bool alreadyFullScreen = (Environment.fullScreen != 0); while (handle == INVALID_HANDLE_VALUE) { openFailed = true; //OK, check to see if the CD is actually present. // Do this by checking for tgl.fst on the CD Path. // If its there, the CD is present BUT the file is missing. // MANY files in MechCommander 2 are LEGALLY missing! // Tell it to the art staff. char testCDPath[2048]; strcpy(testCDPath,CDInstallPath); strcat(testCDPath,"tgl.fst"); DWORD findCD = fileExists(testCDPath); if (findCD == 1) //File exists. CD is in drive. Return 2 to indicate file not found. return 2; EnterWindowMode(); char data[2048]; sprintf(data,FileMissingString,fileName,CDMissingString); DWORD result1 = MessageBox(NULL,data,MissingTitleString,MB_OKCANCEL | MB_ICONWARNING); if (result1 == IDCANCEL) { ExitGameOS(); return (2); //File not found. Never returns though! } handle = _open(actualPath,_O_RDONLY); } if (openFailed && (Environment.fullScreen == 0) && alreadyFullScreen) EnterFullScreenMode(); } else { if (logFileTraffic && (handle != INVALID_HANDLE_VALUE)) { if (!fileTrafficLog) { createTrafficLog(); } char msg[300]; sprintf(msg,"CFHandle Length: %010d File: %s",fileSize(),fileName); fileTrafficLog->writeLine(msg); } setup(); //------------------------------------------------------------ // NEW FUNCTIONALITY!!! // // Each file may have a number of files open as children which // use the parent's handle for reads and writes. This would // allow us to open a packet file and read a packet as a fitIni // or allow us to write a packet as a fit ini and so forth. // // It also allows us to use the packet file extensions as tree // files to avoid the ten thousand file syndrome. // // There is now an open which takes a FilePtr and a size. maxChildren = numChild; childList = (FilePtr *)systemHeap->Malloc(sizeof(FilePtr) * maxChildren); if (!childList) { return(NO_RAM_FOR_CHILD_LIST); } numChildren = 0; for (long i=0;i<(long)maxChildren;i++) { childList[i] = NULL; } return (NO_ERR); } } if (logFileTraffic) { if (!fileTrafficLog) { createTrafficLog(); } char msg[300]; sprintf(msg,"FASTF Length: %010d File: %s",fileSize(),fileName); fileTrafficLog->writeLine(msg); } //--------------------------------------------------------------------- //-- FastFiles are all compressed. Must read in entire chunk into RAM //-- Then close fastfile!!!!! inRAM = TRUE; fileImage = (unsigned char *)malloc(fileSize()); if (fileImage) { fastFile->readFast(fastFileHandle,fileImage,fileSize()); physicalLength = getLength(); //------------------------------------ //-- Image is in RAM. Shut the file. //fastFile->closeFast(fastFileHandle); //fastFile = NULL; //fastFileHandle = -1; logicalPosition = 0; } return NO_ERR; } else { if (logFileTraffic && (handle != INVALID_HANDLE_VALUE)) { if (!fileTrafficLog) { createTrafficLog(); } char msg[300]; sprintf(msg,"CFHandle Length: %010d File: %s",fileSize(),fileName); fileTrafficLog->writeLine(msg); } setup(); //------------------------------------------------------------ // NEW FUNCTIONALITY!!! // // Each file may have a number of files open as children which // use the parent's handle for reads and writes. This would // allow us to open a packet file and read a packet as a fitIni // or allow us to write a packet as a fit ini and so forth. // // It also allows us to use the packet file extensions as tree // files to avoid the ten thousand file syndrome. // // There is now an open which takes a FilePtr and a size. maxChildren = numChild; childList = (FilePtr *)systemHeap->Malloc(sizeof(FilePtr) * maxChildren); if (!childList) { return(NO_RAM_FOR_CHILD_LIST); } numChildren = 0; for (long i=0;i<(long)maxChildren;i++) { childList[i] = NULL; } return (NO_ERR); } } return(NO_ERR); }