Added plugin for Descent game data files

This commit is contained in:
Michael Becker 2014-05-13 21:08:18 -04:00
parent 8a93f3f3ca
commit 856c9c45c3
4 changed files with 175 additions and 0 deletions

View File

@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UniversalEditor.ObjectModels.FileSystem;
namespace UniversalEditor.DataFormats.FileSystem.Descent
{
public class DescentHOGDataFormat : DataFormat
{
private static DataFormatReference _dfr = null;
public override DataFormatReference MakeReference()
{
if (_dfr == null)
{
_dfr = base.MakeReference();
_dfr.Capabilities.Add(typeof(FileSystemObjectModel), DataFormatCapabilities.All);
_dfr.Filters.Add("Descent HOG archive", new byte?[][] { new byte?[] { (byte)'D', (byte)'H', (byte)'F' } }, new string[] { "*.hog" });
}
return _dfr;
}
protected override void LoadInternal(ref ObjectModel objectModel)
{
FileSystemObjectModel fsom = (objectModel as FileSystemObjectModel);
IO.Reader br = base.Accessor.Reader;
string DHF = br.ReadFixedLengthString(3);
if (DHF != "DHF") throw new InvalidDataFormatException("File does not begin with \"DHF\"");
while (!br.EndOfStream)
{
string FileName = br.ReadFixedLengthString(13);
int length = br.ReadInt32();
long offset = br.Accessor.Position;
File file = new File();
file.Name = FileName;
file.Size = length;
file.Properties.Add("reader", br);
file.Properties.Add("offset", offset);
file.DataRequest += file_DataRequest;
fsom.Files.Add(file);
br.Accessor.Seek(length, IO.SeekOrigin.Current);
}
}
private void file_DataRequest(object sender, DataRequestEventArgs e)
{
File file = (sender as File);
long offset = (long)file.Properties["offset"];
IO.Reader reader = (IO.Reader)file.Properties["reader"];
reader.Accessor.Seek(offset, IO.SeekOrigin.Begin);
e.Data = reader.ReadBytes(file.Size);
}
protected override void SaveInternal(ObjectModel objectModel)
{
FileSystemObjectModel fsom = (objectModel as FileSystemObjectModel);
IO.Writer bw = base.Accessor.Writer;
bw.WriteFixedLengthString("DHF");
foreach (File file in fsom.Files)
{
bw.WriteFixedLengthString(file.Name, 13);
bw.WriteInt32((int)file.Size);
bw.WriteBytes(file.GetDataAsByteArray());
}
bw.Flush();
}
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("UniversalEditor.Plugins.Descent")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("UniversalEditor.Plugins.Descent")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("38142617-455a-4623-bcc6-2780711e6b72")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{3DC2C1F6-F332-4E55-BF6A-AED78A7C3FD2}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>UniversalEditor</RootNamespace>
<AssemblyName>UniversalEditor.Plugins.Descent</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\Output\Debug\Plugins\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\Output\Release\Plugins\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="DataFormats\FileSystem\Descent\DescentHOGDataFormat.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Libraries\UniversalEditor.Core\UniversalEditor.Core.csproj">
<Project>{2d4737e6-6d95-408a-90db-8dff38147e85}</Project>
<Name>UniversalEditor.Core</Name>
</ProjectReference>
<ProjectReference Include="..\UniversalEditor.Essential\UniversalEditor.Essential.csproj">
<Project>{30467e5c-05bc-4856-aadc-13906ef4cadd}</Project>
<Name>UniversalEditor.Essential</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -35,6 +35,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.Plugins.Mul
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.Plugins.ChaosWorks", "Plugins\UniversalEditor.Plugins.ChaosWorks\UniversalEditor.Plugins.ChaosWorks.csproj", "{30A2F772-8EC1-425A-8D5D-36A0BE4D6B66}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniversalEditor.Plugins.Descent", "Plugins\UniversalEditor.Plugins.Descent\UniversalEditor.Plugins.Descent.csproj", "{3DC2C1F6-F332-4E55-BF6A-AED78A7C3FD2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -123,6 +125,12 @@ Global
{30A2F772-8EC1-425A-8D5D-36A0BE4D6B66}.Release|Any CPU.ActiveCfg = Release|Any CPU
{30A2F772-8EC1-425A-8D5D-36A0BE4D6B66}.Release|Any CPU.Build.0 = Release|Any CPU
{30A2F772-8EC1-425A-8D5D-36A0BE4D6B66}.Release|x86.ActiveCfg = Release|Any CPU
{3DC2C1F6-F332-4E55-BF6A-AED78A7C3FD2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3DC2C1F6-F332-4E55-BF6A-AED78A7C3FD2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3DC2C1F6-F332-4E55-BF6A-AED78A7C3FD2}.Debug|x86.ActiveCfg = Debug|Any CPU
{3DC2C1F6-F332-4E55-BF6A-AED78A7C3FD2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3DC2C1F6-F332-4E55-BF6A-AED78A7C3FD2}.Release|Any CPU.Build.0 = Release|Any CPU
{3DC2C1F6-F332-4E55-BF6A-AED78A7C3FD2}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -139,6 +147,7 @@ Global
{BE4D0BA3-0888-42A5-9C09-FC308A4509D2} = {71CFF024-26F7-4626-A526-B435FDF8D64E}
{369CFD53-3E65-4A9E-8BDD-4CCD78BF3E33} = {71CFF024-26F7-4626-A526-B435FDF8D64E}
{30A2F772-8EC1-425A-8D5D-36A0BE4D6B66} = {71CFF024-26F7-4626-A526-B435FDF8D64E}
{3DC2C1F6-F332-4E55-BF6A-AED78A7C3FD2} = {71CFF024-26F7-4626-A526-B435FDF8D64E}
{617D9EB5-CA93-45D6-AA6B-5A012B7698AC} = {46041F27-7C1C-4209-B72B-251EDB5D4C61}
{FE016EA3-DC31-4A92-8B0A-8C746EC117E1} = {46041F27-7C1C-4209-B72B-251EDB5D4C61}
EndGlobalSection