bool Remove(ResourcePack& pack) { const auto result = pack.Uninstall(File::GetUserPath(D_USER_IDX)); if (!result) return false; auto pack_iterator = std::find(packs.begin(), packs.end(), pack); if (pack_iterator == packs.end()) return false; std::string filename; IniFile file = GetPackConfig(); auto* order = file.GetOrCreateSection("Order"); order->Delete(pack.GetManifest()->GetID()); int offset = pack_iterator - packs.begin(); for (int i = offset + 1; i < static_cast<int>(packs.size()); i++) order->Set(packs[i].GetManifest()->GetID(), i - 1); file.Save(packs_path); packs.erase(pack_iterator); return true; }
void operator()() { while (_flcPlayer->getFrameCount() >= introSoundTrack[trackPosition].frameNumber) { int command = introSoundTrack[trackPosition].sound; if (command & 0x200) { #ifndef __NO_MUSIC switch(command) { case 0x200: Log(LOG_DEBUG) << "Playing gmintro1"; m = rp->getMusic("GMINTRO1"); m->play(1); break; case 0x201: Log(LOG_DEBUG) << "Playing gmintro2"; m = rp->getMusic("GMINTRO2"); m->play(1); break; case 0x202: Log(LOG_DEBUG) << "Playing gmintro3"; m = rp->getMusic("GMINTRO3"); m->play(1); //Mix_HookMusicFinished(_FlcPlayer::stop); break; } #endif } else if (command & 0x400) { int newSpeed = (command & 0xff); _flcPlayer->setHeaderSpeed(newSpeed); Log(LOG_DEBUG) << "Frame delay now: " << newSpeed; } else if (command <= 0x19) { for (soundInFile **sounds = introSounds; *sounds; ++sounds) // try hybrid sound set, then intro.cat or sample3.cat alone { soundInFile *sf = (*sounds) + command; int channel = trackPosition % 4; // use at most four channels to play sound effects double ratio = (double)Options::soundVolume / MIX_MAX_VOLUME; Log(LOG_DEBUG) << "playing: " << sf->catFile << ":" << sf->sound << " for index " << command; s = rp->getSound(sf->catFile, sf->sound); if (s) { s->play(channel); Mix_Volume(channel, sf->volume * ratio); break; } else Log(LOG_DEBUG) << "Couldn't play " << sf->catFile << ":" << sf->sound; } } ++trackPosition; } }
void operator ()() { while (Flc::flc.FrameCount >= introSoundTrack[trackPosition].frameNumber) { int command = introSoundTrack[trackPosition].sound; if (command & 0x200) { #ifndef __NO_MUSIC switch(command) { case 0x200: Log(LOG_DEBUG) << "Playing gmintro1"; m = rp->getMusic("GMINTRO1"); m->play(1); break; case 0x201: Log(LOG_DEBUG) << "Playing gmintro2"; m = rp->getMusic("GMINTRO2"); m->play(1); break; case 0x202: Log(LOG_DEBUG) << "Playing gmintro3"; m = rp->getMusic("GMINTRO3"); m->play(1); Mix_HookMusicFinished(musicDone); break; } #endif } else if (command & 0x400) { Flc::flc.HeaderSpeed = (1000.0/70.0) * (command & 0xff); Log(LOG_DEBUG) << "Frame delay now: " << Flc::flc.HeaderSpeed; } else if (command <= 0x19) { for (soundInFile **sounds = introSounds; *sounds; ++sounds) // try hybrid sound set, then intro.cat or sample3.cat alone { soundInFile *sf = (*sounds) + command; int channel = trackPosition % 4; // use at most four channels to play sound effects Log(LOG_DEBUG) << "playing: " << sf->catFile << ":" << sf->sound << " for index " << command; s = rp->getSound(sf->catFile, sf->sound); if (s) { s->play(channel); Mix_Volume(channel, sf->volume); break; } else Log(LOG_DEBUG) << "Couldn't play " << sf->catFile << ":" << sf->sound; } } ++trackPosition; } }
void SetInstalled(const ResourcePack& pack, bool installed) { IniFile file = GetPackConfig(); auto* install = file.GetOrCreateSection("Installed"); if (installed) install->Set(pack.GetManifest()->GetID(), installed); else install->Delete(pack.GetManifest()->GetID()); file.Save(packs_path); }
//------------------------------------------------------------------------------------------------ // Name: obtainD3DTexture // Desc: Loads the image denoted by this class using the specified device //------------------------------------------------------------------------------------------------ bool PackImage::obtainD3DTexture(LPDIRECT3DDEVICE9 pd3dDevice, DWORD options, LPDIRECT3DTEXTURE9* ppd3dTexture) const { // Fail without a device or if something is wrong with the output pointer if (!pd3dDevice || !ppd3dTexture) return false; // Get the pack from which to load this image dc::dcTable<ResourcePack>::Element* packElement = ((PackImage*)this)->myResourcePack.getReferencedResource(); if (!packElement) return false; ResourcePack* pack = packElement->getImplementation(); if (!pack) return false; // Obtain the image in the pack dcBuffer buffer; if (APP_ERROR(!pack->openResource(myResourceIndex.getValue(), &buffer)) ("Failed to open image %i in pack file", myResourceIndex)) return false; // Obtain options flags bool managed = (options & D3DTEX_MANAGED) != 0; bool mipmap = (options & D3DTEX_MIPMAP) != 0; bool systemmem = (options & D3DTEX_SYSTEMMEM) != 0; D3DPOOL pool = systemmem ? D3DPOOL_SYSTEMMEM : (managed ? D3DPOOL_MANAGED : D3DPOOL_DEFAULT); // Holds return codes HRESULT hr; // Save a NULL first (just in case something goes wrong) *ppd3dTexture = NULL; // The destination for the texture interface LPDIRECT3DTEXTURE9 pd3dTexture; // Load the texture hr = D3DXCreateTextureFromFileInMemoryEx(pd3dDevice, buffer.getDataPointer(), buffer.getDataSize(), D3DX_DEFAULT, D3DX_DEFAULT, mipmap ? D3DX_DEFAULT : 1, 0, D3DFMT_UNKNOWN, pool, D3DX_DEFAULT, D3DX_FILTER_POINT, 0, NULL, NULL, &pd3dTexture); // TODO: // buffer.destroy(); // If there is a problem, there's not much more we can do if (APP_WARNING(FAILED(hr))("Couldn't load PackImage %i", myResourceIndex)) return false; // Assign the output texture *ppd3dTexture = pd3dTexture; // Success return true; }
// load animation from a data pack bool CharAnimation::load( const ResourcePack& pack, const std::string& filepath){ std::string fixedFn = makeUnixFilePath(filepath); ResourceFile rcf; if( !pack.getResource(fixedFn, rcf) ){ std::cerr << __FILE__ << ": " << __LINE__ << ": Requested file \"" << fixedFn << "\" not found in supplied pack" << std::endl; return false; } filename_ = fixedFn; // read file into packet inp::INFPacket packet; packet.readBuf( const_cast<unsigned char*>(&pack.getRawData()[rcf.start]), rcf.size ); return load(packet); }
bool IsInstalled(const ResourcePack& pack) { IniFile file = GetPackConfig(); auto* install = file.GetOrCreateSection("Installed"); bool installed; install->Get(pack.GetManifest()->GetID(), &installed, false); return installed; }
//------------------------------------------------------------------------------------------------ // Name: obtainSourceGeometry // Desc: Loads the geometry held by this class into the destination set //------------------------------------------------------------------------------------------------ bool PackMesh::obtainSourceGeometry(LPDIRECT3DDEVICE9 pd3dDevice, SubsetGeometry* subsetGeometry) const { // Fail without a device or if something is wrong with the output pointer if (APP_ERROR(!pd3dDevice || !subsetGeometry)("Invalid parameter to obtainSourceGeometry")) return false; // Get the pack from which to load this mesh dc::dcTable<ResourcePack>::Element* packElement = ((PackMesh*)this)->myResourcePack.getReferencedResource(); if (!packElement) return false; ResourcePack* pack = packElement->getImplementation(); if (!pack) return false; // Obtain the mesh in the pack dcBuffer buffer; if (APP_ERROR(!pack->openResource(myResourceIndex.getValue(), &buffer)) ("Failed to open image %i in pack file", myResourceIndex)) return false; // Set up a buffer reader to scan data from the returned information dcBuffer::Reader bufferReader(&buffer); // Get the number of subsets in this mesh size_t subsets; if (!bufferReader.read(&subsets, sizeof(subsets))) return false; // Whether or not loading failed bool failed = false; // Load each of the subsets for (size_t s = 0; s < subsets; ++s) { // Stores subset information while it is being loaded Geometry* geometry = NULL; SubsetIndex subset; DWORD vertices, indices; // Read the subset index information and the geometry data from the file if (APP_ERROR(!bufferReader.read(&subset, sizeof(subset)) || !bufferReader.read(&vertices, sizeof(vertices)) || !bufferReader.read(&indices, sizeof(indices))) ("Error while reading mesh data")) { // We were unable to load this mesh failed = true; // Exit the subset loop break; } // Create geometry for this mesh subset's data if (APP_FATAL(FAILED(AllocateGeometry(vertices, indices, &geometry))) ("Out of memory while allocating subset %i of %s (%i vertices/%i indices)", subset, getPathString().c_str(), vertices, indices)) { // Couldn't load the mesh failed = true; // Exit this loop break; } // Load the geometry buffers if (APP_ERROR(!bufferReader.read(geometry->pVertices, sizeof(GeometryVertex) * vertices) || !bufferReader.read(geometry->pIndices, sizeof(GeometryIndex) * indices)) ("Couldn't load geometry vertex/index data for subset %i of %s", subset, getPathString().c_str())) { // Unable to load failed = true; // Quit the loading process break; } // Add the data we just loaded as a mesh subset subsetGeometry->insert(SubsetGeometry::value_type(subset, geometry)); } // If we failed, get rid of anything that managed to be loaded if (failed) DeallocateGeometry(subsetGeometry); // Return whether or not this operation succeeded return !failed; }