//Loads the first bmp found in the pack, by default uses befallen.s3d void Start() { Debug.Log("Loading s3d"); var archive = EQArchive.Load(GamePath + ArchiveName); Debug.Log("File count: " + archive.Files.Count); string extension = ""; //Vector3[] newVertices; //Vector2[] newUV; //int[] newTriangles; //Mesh mesh = new Mesh(); cube.GetComponent <MeshFilter>().mesh = CreateMesh(1, 2); //mesh.vertices = newVertices; //mesh.uv = newUV; //mesh.triangles = newTriangles; foreach (var file in archive.Files) { // Debug.Log(file.Key); if (!LoadFirstMesh) { if (file.Key.ToLower() == MeshToLoad.ToLower()) { //byte[] contents = file.Value.GetContents(); return; } continue; } extension = System.IO.Path.GetExtension(file.Key); if (extension == ".wld") { Debug.Log("Loading " + file.Key); byte[] contents = file.Value.GetContents(); try { Wld wld = new Wld(contents); Debug.Log(wld); } catch (Exception e) { Debug.LogError("Failed to load World: " + e.Message); return; } return; } continue; } Debug.Log("Done"); }
//Loads the first bmp found in the pack, by default uses befallen.s3d void Start() { Debug.Log("Loading s3d"); var archive = EQArchive.Load(GamePath + ArchiveName); Debug.Log("File count: " + archive.Files.Count); string extension = ""; AudioSource asource = cube.GetComponent <AudioSource>(); foreach (var file in archive.Files) { if (!LoadFirstSound) { if (file.Key.ToLower() == SoundToLoad.ToLower()) { //byte[] contents = file.Value.GetContents(); /* * WAV wav = new WAV(contents); * //asource.clip.SetData(wav.LeftChannel, 0); * //asource.Play(); * //Debug.Log(audioClip); * AudioClip audioClip = AudioClip.Create(SoundToLoad, wav.SampleCount, 1, wav.Frequency, false); * audioClip.SetData(wav.LeftChannel, 0); * asource.clip = audioClip; */ asource.clip = WavUtility.ToAudioClip(@"D:\Documents\Desktop\boatbell.wav"); //asource.clip = WavUtility.ToAudioClip(contents,0, file.Key); Debug.Log("Playing sound " + SoundToLoad); return; } continue; } extension = System.IO.Path.GetExtension(file.Key); if (extension == ".wav") { byte[] contents = file.Value.GetContents(); WAV wav = new WAV(contents); //asource.clip.SetData(wav.LeftChannel, 0); //asource.Play(); //Debug.Log(audioClip); AudioClip audioClip = AudioClip.Create("testSound", wav.SampleCount, 1, wav.Frequency, false); audioClip.SetData(wav.LeftChannel, 0); asource.clip = audioClip; asource.Play(); return; } continue; //Debug.Log(file.Key); } Debug.Log("Done"); }
public static EQArchive Load(string Filename, byte[] Contents) { if (Filename.Length == 0 || Contents == null) { // We got a bad filename, or the file is zero length, and thus not a PFS archive. return(null); } Header _header = new Header(); using (BinaryReader _input = new BinaryReader(new MemoryStream(Contents))) { try { // // 1. Read the file header // _header.IndexPointer = _input.ReadUInt32(); _header.MagicNumber = _input.ReadUInt32(); _header.VersionNumber = _input.ReadUInt32(); } catch { // Too small to be a PFS archive return(null); } if (_header.MagicNumber != _MagicNumber) { // Not a PFS archive return(null); } EQArchive _archive = new EQArchive(); _archive.Filename = Filename; _archive.SizeOnDisk = (UInt32)Contents.Length; try { // // 2. Read Index of File Pointers and Sizes in Archive // _input.BaseStream.Seek(_header.IndexPointer, SeekOrigin.Begin); _header.EntryCount = _input.ReadUInt32(); if (_header.EntryCount == 0) { // Empty archive...? _archive.Files = new SortedList <string, EQArchiveFile>(); } else { _archive.Files = new SortedList <string, EQArchiveFile>((int)_header.EntryCount); } // Filename directory is the "file" at the end of the archive (with the highest FilePointer) EQArchiveFile _directory = null; // For verification later, which is optional, but will catch a malformed/corrupted archive. Dictionary <UInt32, UInt32> _filenameCRCs = new Dictionary <UInt32, UInt32>(); // Files in a PFS archive tend to be stored by ascending order of FilenameCRC. // However, the filename directory is sorted by FilePointer SortedList <UInt32, EQArchiveFile> _files = new SortedList <UInt32, EQArchiveFile>(); for (UInt32 _index = 0; _index < _header.EntryCount; _index++) { EQArchiveFile _file = new EQArchiveFile(); UInt32 _filenameCRC = _input.ReadUInt32(); _file.FilePointer = _input.ReadUInt32(); _file.Size.Uncompressed = _input.ReadUInt32(); _filenameCRCs.Add(_file.FilePointer, _filenameCRC); if ((_directory == null) || (_file.FilePointer > _directory.FilePointer)) { _directory = _file; } _files.Add(_file.FilePointer, _file); } if ((_input.BaseStream.Length - _input.BaseStream.Position) >= 9) { // PFS Footer char[] _token = _input.ReadChars(5); if (new String(_token).Equals("STEVE")) { // Valid Footer Token _header.DateStamp = _input.ReadUInt32(); } } // // 3. Read the compressed file entries (each split into compressed chunks) // foreach (EQArchiveFile _file in _files.Values) { // Seek to entry position in stream _input.BaseStream.Seek(_file.FilePointer, SeekOrigin.Begin); UInt32 _totalUncompressedBytes = _file.Size.Uncompressed; _file.Size.Uncompressed = 0; while ((_file.Size.Uncompressed < _totalUncompressedBytes) && (_input.BaseStream.Position < _input.BaseStream.Length)) { UInt32 _blockSizeCmp = _input.ReadUInt32(); UInt32 _blockSizeUnc = _input.ReadUInt32(); // Sanity Check 1: Uncompressed data larger than what we were told? if ((_blockSizeUnc + _file.Size.Uncompressed) > _totalUncompressedBytes) { throw new Exception(); } // Sanity Check 2: Compressed data goes past the end of the file? if ((_input.BaseStream.Position + _blockSizeCmp) > _input.BaseStream.Length) { throw new Exception(); } _file.AddChunk(new EQArchiveFile.Chunk(Contents, (UInt32)_input.BaseStream.Position, _blockSizeCmp, _blockSizeUnc, true)); _input.BaseStream.Position += _blockSizeCmp; } } // // 4. Unpack and parse the directory of filenames from the "file" at the end of the archive (highest FilePointer) // // Remove directory from file entries in archive. We'll have to rebuild it when saving the archive anyway. _files.Remove(_directory.FilePointer); _header.EntryCount--; // Load filenames from directory BinaryReader _dirStream = new BinaryReader(new MemoryStream(_directory.GetContents())); UInt32 _filenameCount = _dirStream.ReadUInt32(); if (_filenameCount > _header.EntryCount) { // If we somehow have more filenames than entries in the archive, ignore the glitched extras _filenameCount = _header.EntryCount; } _archive.Files = new SortedList <string, EQArchiveFile>(); foreach (EQArchiveFile _file in _files.Values) { Int32 _len = _dirStream.ReadInt32(); char[] _inputname = _dirStream.ReadChars(_len); UInt32 _crc = GetFilenameCRC(_inputname); if (_crc != _filenameCRCs[_file.FilePointer]) { // Filename doesn't match with what we were given in Step 2 // This happens in gequip.s3d. We are ignoring it. //throw new Exception(); } _file.Filename = new string(_inputname, 0, _len - 1); _archive.Files.Add(_file.Filename.ToLower(), _file); } // All entries loaded and filenames read from directory. _archive.Status = Result.OK; } catch { _archive.Status = Result.MalformedFile; } return(_archive); } }
//Loads the first bmp found in the pack, by default uses befallen.s3d void Start() { MeshRenderer mesh; if (cube == null) { Debug.Log("Cube not set"); return; } mesh = cube.GetComponent <MeshRenderer>(); if (mesh == null) { Debug.Log("No mesh set"); return; } Debug.Log("Loading s3d"); var archive = EQArchive.Load(GamePath + ArchiveName); Debug.Log("File count: " + archive.Files.Count); string extension = ""; foreach (var file in archive.Files) { if (!LoadFirstTexture) { if (file.Key.ToLower() == TextureToLoad.ToLower()) { byte[] contents = file.Value.GetContents(); Texture2D tex = new Texture2D(256, 256, TextureFormat.DXT1, false); tex.LoadRawTextureData(contents); tex.Apply(); mesh.material.mainTexture = tex; Debug.Log("Loaded " + TextureToLoad); return; } continue; } extension = System.IO.Path.GetExtension(file.Key); if (extension == ".bmp" || extension == ".dds") { Debug.Log("Bmp file: " + file.Key); byte[] contents = file.Value.GetContents(); //todo: identify dimensions etc so i don't hardcore to 256x256 //Debug.Log("Size: " + contents.Length); //Debug.Log("Size Header: "+ (contents[0] + contents[1] + contents[2] + contents[3])); //Debug.Log("Width: " + contents[4]+", Height: "+contents[5]); Texture2D tex = new Texture2D(256, 256, TextureFormat.DXT1, false); tex.LoadRawTextureData(contents); tex.Apply(); mesh.material.mainTexture = tex; return; } continue; //Debug.Log(file.Key); } Debug.Log("Done"); }