added a Dune 2000 SOUND.RS parser
again @pchote via IRC
This commit is contained in:
109
OpenRA.FileFormats/Filesystem/D2kSoundResources.cs
Normal file
109
OpenRA.FileFormats/Filesystem/D2kSoundResources.cs
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
|
||||||
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
|
* available to you under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation. For more information,
|
||||||
|
* see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace OpenRA.FileFormats
|
||||||
|
{
|
||||||
|
public class D2kSoundResources : IFolder
|
||||||
|
{
|
||||||
|
readonly Stream s;
|
||||||
|
|
||||||
|
readonly string filename;
|
||||||
|
readonly List<string> filenames;
|
||||||
|
readonly int priority;
|
||||||
|
|
||||||
|
readonly Dictionary<uint, PackageEntry> index = new Dictionary<uint, PackageEntry>();
|
||||||
|
|
||||||
|
public D2kSoundResources(string filename, int priority)
|
||||||
|
{
|
||||||
|
this.filename = filename;
|
||||||
|
this.priority = priority;
|
||||||
|
|
||||||
|
s = FileSystem.Open(filename);
|
||||||
|
s.Seek(0, SeekOrigin.Begin);
|
||||||
|
|
||||||
|
filenames = new List<string>();
|
||||||
|
|
||||||
|
var headerLength = s.ReadUInt32();
|
||||||
|
while (s.Position < headerLength + 4)
|
||||||
|
{
|
||||||
|
var name = "";
|
||||||
|
var letter = s.ReadASCII(1);
|
||||||
|
while (letter != "\0")
|
||||||
|
{
|
||||||
|
name += letter;
|
||||||
|
letter = s.ReadASCII(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
var offset = s.ReadUInt32();
|
||||||
|
var length = s.ReadUInt32();
|
||||||
|
|
||||||
|
var hash = PackageEntry.HashFilename(name, PackageHashType.Classic);
|
||||||
|
if (!index.ContainsKey(hash))
|
||||||
|
index.Add(hash, new PackageEntry(hash, offset, length));
|
||||||
|
|
||||||
|
filenames.Add(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Stream GetContent(uint hash)
|
||||||
|
{
|
||||||
|
PackageEntry e;
|
||||||
|
if (!index.TryGetValue(hash, out e))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
s.Seek(e.Offset, SeekOrigin.Begin);
|
||||||
|
var data = new byte[e.Length];
|
||||||
|
s.Read(data, 0, (int)e.Length);
|
||||||
|
|
||||||
|
return new MemoryStream(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Stream GetContent(string filename)
|
||||||
|
{
|
||||||
|
return GetContent(PackageEntry.HashFilename(filename, PackageHashType.Classic));
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Exists(string filename)
|
||||||
|
{
|
||||||
|
return index.ContainsKey(PackageEntry.HashFilename(filename, PackageHashType.Classic));
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<string> AllFileNames()
|
||||||
|
{
|
||||||
|
return filenames;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name { get { return filename; } }
|
||||||
|
|
||||||
|
public int Priority { get { return 1000 + priority; }}
|
||||||
|
|
||||||
|
public IEnumerable<uint> ClassicHashes()
|
||||||
|
{
|
||||||
|
return index.Keys;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<uint> CrcHashes()
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Write(Dictionary<string, byte[]> contents)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException("Cannot save Dune 2000 Sound Resources.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -53,6 +53,8 @@ namespace OpenRA.FileFormats
|
|||||||
return new ZipFile(filename, order, content);
|
return new ZipFile(filename, order, content);
|
||||||
else if (filename.EndsWith(".oramap", StringComparison.InvariantCultureIgnoreCase))
|
else if (filename.EndsWith(".oramap", StringComparison.InvariantCultureIgnoreCase))
|
||||||
return new ZipFile(filename, order, content);
|
return new ZipFile(filename, order, content);
|
||||||
|
else if (filename.EndsWith(".RS", StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
throw new NotImplementedException("Creating .RS archives is unsupported");
|
||||||
else if (filename.EndsWith(".Z", StringComparison.InvariantCultureIgnoreCase))
|
else if (filename.EndsWith(".Z", StringComparison.InvariantCultureIgnoreCase))
|
||||||
throw new NotImplementedException("Creating .Z archives is unsupported");
|
throw new NotImplementedException("Creating .Z archives is unsupported");
|
||||||
else
|
else
|
||||||
@@ -71,6 +73,8 @@ namespace OpenRA.FileFormats
|
|||||||
return new ZipFile(filename, order);
|
return new ZipFile(filename, order);
|
||||||
else if (filename.EndsWith(".oramap", StringComparison.InvariantCultureIgnoreCase))
|
else if (filename.EndsWith(".oramap", StringComparison.InvariantCultureIgnoreCase))
|
||||||
return new ZipFile(filename, order);
|
return new ZipFile(filename, order);
|
||||||
|
else if (filename.EndsWith(".RS", StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
return new D2kSoundResources(filename, order);
|
||||||
else if (filename.EndsWith(".Z", StringComparison.InvariantCultureIgnoreCase))
|
else if (filename.EndsWith(".Z", StringComparison.InvariantCultureIgnoreCase))
|
||||||
return new InstallShieldPackage(filename, order);
|
return new InstallShieldPackage(filename, order);
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ namespace OpenRA.FileFormats
|
|||||||
var FileName = new String(reader.ReadChars(NameLength));
|
var FileName = new String(reader.ReadChars(NameLength));
|
||||||
|
|
||||||
var hash = PackageEntry.HashFilename(FileName, PackageHashType.Classic);
|
var hash = PackageEntry.HashFilename(FileName, PackageHashType.Classic);
|
||||||
if(!index.ContainsKey(hash))
|
if (!index.ContainsKey(hash))
|
||||||
index.Add(hash, new PackageEntry(hash,AccumulatedData, CompressedSize));
|
index.Add(hash, new PackageEntry(hash,AccumulatedData, CompressedSize));
|
||||||
filenames.Add(FileName);
|
filenames.Add(FileName);
|
||||||
AccumulatedData += CompressedSize;
|
AccumulatedData += CompressedSize;
|
||||||
@@ -102,9 +102,9 @@ namespace OpenRA.FileFormats
|
|||||||
if (!index.TryGetValue(hash, out e))
|
if (!index.TryGetValue(hash, out e))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
s.Seek( dataStart + e.Offset, SeekOrigin.Begin );
|
s.Seek(dataStart + e.Offset, SeekOrigin.Begin);
|
||||||
byte[] data = new byte[ e.Length ];
|
var data = new byte[e.Length];
|
||||||
s.Read( data, 0, (int)e.Length );
|
s.Read(data, 0, (int)e.Length);
|
||||||
|
|
||||||
return new MemoryStream(Blast.Decompress(data));
|
return new MemoryStream(Blast.Decompress(data));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -145,6 +145,7 @@
|
|||||||
<Compile Include="Graphics\HvaReader.cs" />
|
<Compile Include="Graphics\HvaReader.cs" />
|
||||||
<Compile Include="StreamExts.cs" />
|
<Compile Include="StreamExts.cs" />
|
||||||
<Compile Include="FileFormats\WavLoader.cs" />
|
<Compile Include="FileFormats\WavLoader.cs" />
|
||||||
|
<Compile Include="Filesystem\D2kSoundResources.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||||
|
|||||||
Reference in New Issue
Block a user