long MissionBriefingScreen::getMissionTGA(const char* missionName) { if (!missionName) return 0; // do I need to open the file? I guess so, if this proves too slow, // it could be done when a stage is completed FullPathFileName path; path.init(missionPath, missionName, ".pak"); if ( 1 == fileExists( path ) ) { // big hack here for some reason we can open files while they're being transferred. HANDLE hFile = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0); // MCHD TODO: What is this all about? if ( hFile == INVALID_HANDLE_VALUE ) return 0; CloseHandle( hFile ); } // read the tga out of the pak file PacketFile file; if ( NO_ERR == file.open( path ) ) // in case file has just been created { if ( file.getNumPackets() > 3 ) { file.seekPacket(3); long size = file.getPacketSize( ); BYTE* mem = new BYTE[size]; file.readPacket( 3, mem ); TGAFileHeader* pHeader = (TGAFileHeader*)mem; long bmpWidth = pHeader->width; long bmpHeight = pHeader->height; flipTopToBottom( (BYTE*)(pHeader + 1), pHeader->pixel_depth, bmpWidth, bmpHeight ); // set up the texture long tmpMapTextureHandle = mcTextureManager->textureFromMemory( (unsigned long*)(pHeader+1), gos_Texture_Solid, 0, bmpWidth ); delete mem; return tmpMapTextureHandle; } } return 0; }
int32_t MissionBriefingScreen::getMissionTGA(PCSTR missionName) { if (!missionName) return 0; // do I need to open the file? I guess so, if this proves too slow, // it could be done when a stage is completed FullPathFileName path; path.init(missionPath, missionName, ".pak"); if (1 == fileExists(path)) { // big hack here for some reason we can open files while they're being // transferred. HANDLE hFile = CreateFile(path, GENERIC_READ, 0, nullptr, OPEN_EXISTING, 0, 0); int32_t error = GetLastError(); if (hFile == INVALID_HANDLE_VALUE) return 0; CloseHandle(hFile); } // read the tga out of the pak file PacketFile file; if (NO_ERROR == file.open(path)) // in case file has just been created { if (file.getNumPackets() > 3) { file.seekPacket(3); int32_t size = file.getPacketSize(); puint8_t mem = new uint8_t[size]; file.readPacket(3, mem); TGAFileHeader* pHeader = (TGAFileHeader*)mem; int32_t bmpWidth = pHeader->width; int32_t bmpHeight = pHeader->height; flipTopToBottom((puint8_t)(pHeader + 1), pHeader->pixel_depth, bmpWidth, bmpHeight); // set up the texture int32_t tmpMapTextureHandle = mcTextureManager->textureFromMemory( (uint32_t*)(pHeader + 1), gos_Texture_Solid, 0, bmpWidth); delete mem; return tmpMapTextureHandle; } } return 0; }
//--------------------------------------------------------------------------- int32_t PacketFile::insertPacket(int32_t packet, puint8_t buffer, int32_t nbytes, uint8_t pType) { //-------------------------------------------------------- // This function writes the packet to the current end // of file and stores the packet address in the seek // table. Originally, replace was a NONO. No, we check // for the size and, if it is different, insert the new // packet into a new file and basically spend many timeparts doing it. // Necessary for the teditor. // I Love it. int32_t result = 0; if(packet < 0) { return result; } //--------------------------------------------------------------- // Only used here, so OK if regular WINDOWS(tm) malloc! puint8_t workBuffer = (puint8_t)malloc(DEFAULT_MAX_PACKET); //------------------------------------------------------------- // All new code here. Basically, open a new packet file, // write each of the old packets and this new one. Close all // and copy the new one over the old one. Open the new one and // set pointers accordingly. PacketFile tmpFile; result = tmpFile.create("AF3456AF.788"); if(packet >= numPackets) { numPackets++; } tmpFile.reserve(numPackets); for(size_t i = 0; i < numPackets; i++) { if(i == packet) { if(nbytes >= DEFAULT_MAX_PACKET) { //---------------------------------------------------- // Not sure what to do here. We'll try reallocating ::free(workBuffer); workBuffer = (puint8_t)malloc(packetSize); } tmpFile.writePacket(i, buffer, nbytes, pType); } else { seekPacket(i); int32_t storageType = getStorageType(); int32_t packetSize = getPacketSize(); if(packetSize >= DEFAULT_MAX_PACKET) { //---------------------------------------------------- // Not sure what to do here. We'll try reallocating ::free(workBuffer); workBuffer = (puint8_t)malloc(packetSize); } readPacket(i, workBuffer); tmpFile.writePacket(i, workBuffer, packetSize, storageType); } } //------------------------------------ // Now close and reassign everything. char ourFileName[250]; int32_t ourFileMode = 0; strcpy(ourFileName, fileName); ourFileMode = fileMode; tmpFile.close(); close(); remove(ourFileName); rename("AF3456AF.788", ourFileName); remove("AF3456AF.788"); open(ourFileName, (FileMode)ourFileMode); seekPacket(packet); return result; }