Initial Commit

This commit is contained in:
Gericom 2014-11-04 16:22:45 +01:00
commit 948fda4ac6
253 changed files with 46480 additions and 0 deletions

32
.gitignore vendored Normal file
View File

@ -0,0 +1,32 @@
Thumbs.db
*.vsp
*.psess
*.obj
*.exe
*.pdb
*.user
*.aps
*.pch
*.vspscc
*_i.c
*_p.c
*.ncb
*.suo
*.sln.docstates
*.tlb
*.tlh
*.bak
*.cache
*.ilk
*.log
[Bb]in
[Dd]ebug*/
*.lib
*.sbr
obj/
[Rr]elease*/
_ReSharper*/
[Tt]est[Rr]esult*
*.vssscc
$tf*/
TestPlugin*/

1
.tfignore Normal file
View File

@ -0,0 +1 @@
\.git

205
3DS/3DS.csproj Normal file
View File

@ -0,0 +1,205 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{F28E77C4-BB68-4513-9468-8EABDE8DC9CB}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>_3DS</RootNamespace>
<AssemblyName>3DS</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="Tao.DevIl, Version=1.6.8.3, Culture=neutral, PublicKeyToken=7ec4053013524957, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\MKDS Course Modifier\MKDS Course Modifier\bin\x86\Debug_new\Tao.DevIl.dll</HintPath>
</Reference>
<Reference Include="Tao.OpenGl, Version=2.1.0.12, Culture=neutral, PublicKeyToken=1ca010269a4501ef, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\MKDS Course Modifier\MKDS Course Modifier\bin\x86\Debug_new\Tao.OpenGl.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Tao.Platform.Windows, Version=1.0.0.5, Culture=neutral, PublicKeyToken=701104b2da67a104, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\MKDS Course Modifier\MKDS Course Modifier\bin\x86\Debug_new\Tao.Platform.Windows.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="NintendoWare\GFX\BoundingVolume.cs" />
<Compile Include="NintendoWare\GFX\CANM.cs" />
<Compile Include="NintendoWare\GFX\CGFX.cs" />
<Compile Include="NintendoWare\GFX\CGFXShader.cs" />
<Compile Include="NintendoWare\GFX\CGFXWriterContext.cs" />
<Compile Include="NintendoWare\GFX\CMDL.cs" />
<Compile Include="NintendoWare\GFX\DICT.cs" />
<Compile Include="NintendoWare\GFX\PatriciaTreeGenerator.cs" />
<Compile Include="NintendoWare\GFX\TXOB.cs" />
<Compile Include="NintendoWare\LYT\BasicShader.cs" />
<Compile Include="NintendoWare\LYT\bnd1.cs" />
<Compile Include="NintendoWare\LYT\CLIM.cs" />
<Compile Include="NintendoWare\LYT\CLYT.cs" />
<Compile Include="NintendoWare\LYT\CLAN.cs" />
<Compile Include="NintendoWare\LYT\CLYTShader.cs" />
<Compile Include="NintendoWare\LYT\mat1.cs" />
<Compile Include="NintendoWare\LYT\pan1.cs" />
<Compile Include="NintendoWare\LYT\pic1.cs" />
<Compile Include="NintendoWare\LYT\txt1.cs" />
<Compile Include="NintendoWare\LYT\wnd1.cs" />
<Compile Include="NintendoWare\SND\CSTM.cs" />
<Compile Include="DARC.cs" />
<Compile Include="DSP\ADPCM.cs" />
<Compile Include="DVLB.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="GPU\Textures.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Resource.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resource.resx</DependentUpon>
</Compile>
<Compile Include="SARC.cs" />
<Compile Include="SARCEFESFSFile.cs" />
<Compile Include="SMDH.cs" />
<Compile Include="UI\CGFXViewer.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="UI\CGFXViewer.designer.cs">
<DependentUpon>CGFXViewer.cs</DependentUpon>
</Compile>
<Compile Include="UI\CLIMViewer.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="UI\CLIMViewer.Designer.cs">
<DependentUpon>CLIMViewer.cs</DependentUpon>
</Compile>
<Compile Include="UI\CLYTViewer.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="UI\CLYTViewer.Designer.cs">
<DependentUpon>CLYTViewer.cs</DependentUpon>
</Compile>
<Compile Include="UI\DARCViewer.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="UI\DARCViewer.Designer.cs">
<DependentUpon>DARCViewer.cs</DependentUpon>
</Compile>
<Compile Include="UI\SARCViewer.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="UI\SARCViewer.Designer.cs">
<DependentUpon>SARCViewer.cs</DependentUpon>
</Compile>
<Compile Include="UI\SMDHViewer.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="UI\SMDHViewer.Designer.cs">
<DependentUpon>SMDHViewer.cs</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CommonFiles\CommonFiles.csproj">
<Project>{4D0F5EC8-4730-4D62-AFA5-80AD4AD14625}</Project>
<Name>CommonFiles</Name>
</ProjectReference>
<ProjectReference Include="..\LibEveryFileExplorer\LibEveryFileExplorer.csproj">
<Project>{39DBD12F-F7E3-4E9A-97A2-0722A4BA2A26}</Project>
<Name>LibEveryFileExplorer</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resource.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resource.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="UI\CGFXViewer.resx">
<DependentUpon>CGFXViewer.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="UI\CLIMViewer.resx">
<DependentUpon>CLIMViewer.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="UI\CLYTViewer.resx">
<DependentUpon>CLYTViewer.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="UI\DARCViewer.resx">
<DependentUpon>DARCViewer.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="UI\SARCViewer.resx">
<DependentUpon>SARCViewer.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="UI\SMDHViewer.resx">
<DependentUpon>SMDHViewer.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="Resources\leaf.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\image.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\zone.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\preview_background.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\zone16.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\image16.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\slide.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\edit.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\zones-stack.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy "$(TargetPath)" "$(SolutionDir)\EveryFileExplorer\bin\Debug\Plugins\$(TargetFileName)"</PostBuildEvent>
</PropertyGroup>
<!-- 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>

152
3DS/DARC.cs Normal file
View File

@ -0,0 +1,152 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LibEveryFileExplorer.Files;
using System.Drawing;
using System.IO;
using LibEveryFileExplorer.Files.SimpleFileSystem;
using _3DS.UI;
namespace _3DS
{
public class DARC : FileFormat<DARC.darcIdentifier>, IViewable
{
public DARC(byte[] Data)
{
EndianBinaryReader er = new EndianBinaryReader(new MemoryStream(Data), Endianness.LittleEndian);
try
{
Header = new darcHeader(er);
er.BaseStream.Position = Header.FileTableOffset;
FileTableEntry root = new FileTableEntry(er);
Entries = new FileTableEntry[root.DataLength];
Entries[0] = root;
for (int i = 1; i < root.DataLength; i++) Entries[i] = new FileTableEntry(er);
FileNameTable = new Dictionary<uint,string>();
uint offs = 0;
for (int i = 0; i < root.DataLength; i++)
{
String s = er.ReadStringNT(Encoding.Unicode);
FileNameTable.Add(offs, s);
offs += (uint)s.Length * 2 + 2;
}
er.BaseStream.Position = Header.FileDataOffset;
this.Data = er.ReadBytes((int)(Header.FileSize - Header.FileDataOffset));
}
finally
{
er.Close();
}
}
public System.Windows.Forms.Form GetDialog()
{
return new DARCViewer(this);
}
public darcHeader Header;
public class darcHeader
{
public darcHeader(EndianBinaryReader er)
{
Signature = er.ReadString(Encoding.ASCII, 4);
if (Signature != "darc") throw new SignatureNotCorrectException(Signature, "darc", er.BaseStream.Position - 4);
Endianness = er.ReadUInt16();
HeaderSize = er.ReadUInt16();
Unknown = er.ReadUInt32();
FileSize = er.ReadUInt32();
FileTableOffset = er.ReadUInt32();
FileTableLength = er.ReadUInt32();
FileDataOffset = er.ReadUInt32();
}
public String Signature;
public UInt16 Endianness;
public UInt16 HeaderSize;
public UInt32 Unknown;
public UInt32 FileSize;
public UInt32 FileTableOffset;
public UInt32 FileTableLength;
public UInt32 FileDataOffset;
}
public FileTableEntry[] Entries;
public class FileTableEntry
{
public FileTableEntry(EndianBinaryReader er)
{
NameOffset = er.ReadUInt32();
IsFolder = (NameOffset >> 24) == 1;
NameOffset &= 0xFFFFFF;
DataOffset = er.ReadUInt32();
DataLength = er.ReadUInt32();
}
public UInt32 NameOffset;
public Boolean IsFolder;
public UInt32 DataOffset;//Parent Entry Index if folder
public UInt32 DataLength;//Nr Files if folder
}
public Dictionary<UInt32, String> FileNameTable;
public byte[] Data;
public SFSDirectory ToFileSystem()
{
SFSDirectory[] dirs = new SFSDirectory[Entries.Length];
dirs[1] = new SFSDirectory("/", true);
var curdir = dirs[1];
for (int i = 2; i < Entries.Length; i++)
{
if (Entries[i].IsFolder)
{
var folder = new SFSDirectory(FileNameTable[Entries[i].NameOffset], false);
dirs[i] = folder;
folder.Parent = dirs[Entries[i].DataOffset];
dirs[Entries[i].DataOffset].SubDirectories.Add(folder);
curdir = folder;
}
else
{
var file = new SFSFile(-1, FileNameTable[Entries[i].NameOffset], curdir);
byte[] data = new byte[Entries[i].DataLength];
Array.Copy(Data, Entries[i].DataOffset - Header.FileDataOffset, data, 0, Entries[i].DataLength);
file.Data = data;
curdir.Files.Add(file);
}
}
return dirs[1];
}
public class darcIdentifier : FileFormatIdentifier
{
public override string GetCategory()
{
return Category_Archives;
}
public override string GetFileDescription()
{
return "Data Archive (darc)";
}
public override string GetFileFilter()
{
return "Data Archive (*.darc, *.arc)|*.darc;*.arc";
}
public override Bitmap GetIcon()
{
return null;
}
public override FormatMatch IsFormat(EFEFile File)
{
if (File.Data.Length > 4 && File.Data[0] == 'd' && File.Data[1] == 'a' && File.Data[2] == 'r' && File.Data[3] == 'c') return FormatMatch.Content;
return FormatMatch.No;
}
}
}
}

63
3DS/DSP/ADPCM.cs Normal file
View File

@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _3DS.DSP
{
public class ADPCM
{
Int16[] Table;
double Last1 = 0;
double Last2 = 0;
public ADPCM(Int16[] CoefTable)
{
Table = CoefTable;
}
public void UpdateLastSamples(short Prev1, short Prev2)
{
Last1 = Prev1;
Last2 = Prev2;
}
public Int16[] GetWaveData(byte[] Data, int Offset, int Length)
{
List<Int16> DataOut = new List<short>();
for (int i = Offset + 1; i < (Offset + Length); i += 8)
{
int Scale = 1 << (Data[i - 1] & 0xF);
int Coef = (Data[i - 1] >> 4) & 0xF;
double Coef1 = Table[Coef * 2];
double Coef2 = Table[Coef * 2 + 1];
for (int j = 0; j < 7; j++)
{
int high = Data[i + j] >> 4;
int low = Data[i + j] & 0xF;
if (high >= 8) high -= 16;
if (low >= 8) low -= 16;
double val = (((high * Scale) << 11) + 1024.0 + (Coef1 * Last1 + Coef2 * Last2)) / 2048.0; //>> 11;
short samp = Clamp((int)val, short.MinValue, short.MaxValue);
DataOut.Add(samp);
Last2 = Last1;
Last1 = val;
val = (((low * Scale) << 11) + 1024.0 + (Coef1 * Last1 + Coef2 * Last2)) / 2048.0;//>> 11;
samp = Clamp((int)val, short.MinValue, short.MaxValue);
DataOut.Add(samp);
Last2 = Last1;
Last1 = val;
}
}
return DataOut.ToArray();
}
private static short Clamp(int value, int min, int max)
{
if (value < min) value = min;
if (value > max) value = max;
return (short)value;
}
}
}

42
3DS/DVLB.cs Normal file
View File

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LibEveryFileExplorer.Files;
using System.Drawing;
namespace _3DS
{
public class DVLB : FileFormat<DVLB.DVLBIdentifier>
{
public class DVLBIdentifier : FileFormatIdentifier
{
public override string GetCategory()
{
return Category_Shaders;
}
public override string GetFileDescription()
{
return "DMP Vertex Linker Binary (DVLB)";
}
public override string GetFileFilter()
{
return "DMP Vertex Linker Binary (*.shbin)|*.shbin";
}
public override Bitmap GetIcon()
{
return null;
}
public override FormatMatch IsFormat(EFEFile File)
{
if (File.Data.Length > 4 && File.Data[0] == 'D' && File.Data[1] == 'V' && File.Data[2] == 'L' && File.Data[3] == 'B') return FormatMatch.Content;
return FormatMatch.No;
}
}
}
}

52
3DS/Extensions.cs Normal file
View File

@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Drawing;
namespace _3DS
{
public static class Extensions
{
public static Color ReadColor8(this EndianBinaryReader er)
{
int r = er.ReadByte();
int g = er.ReadByte();
int b = er.ReadByte();
int a = er.ReadByte();
return Color.FromArgb(a, r, g, b);
}
public static Color ReadColor4Singles(this EndianBinaryReader er)
{
float R = er.ReadSingle();
float G = er.ReadSingle();
float B = er.ReadSingle();
float A = er.ReadSingle();
int r = (int)(0.5f + (R * 255f));
int g = (int)(0.5f + (G * 255f));
int b = (int)(0.5f + (B * 255f));
int a = (int)(0.5f + (A * 255f));
return Color.FromArgb(a, r, g, b);
}
public static void WriteColor8(this EndianBinaryWriter er, Color Value)
{
er.Write((byte)Value.R);
er.Write((byte)Value.G);
er.Write((byte)Value.B);
er.Write((byte)Value.A);
}
public static void WriteColor4Singles(this EndianBinaryWriter er, Color Value)
{
er.Write((float)(Value.R / 255f));
er.Write((float)(Value.G / 255f));
er.Write((float)(Value.B / 255f));
er.Write((float)(Value.A / 255f));
}
}
}

744
3DS/GPU/Textures.cs Normal file
View File

@ -0,0 +1,744 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using LibEveryFileExplorer.IO;
using LibEveryFileExplorer.GFX;
namespace _3DS.GPU
{
public class Textures
{
public enum ImageFormat : uint
{
RGBA8 = 0,
RGB8 = 1,
RGBA5551 = 2,
RGB565 = 3,
RGBA4 = 4,
LA8 = 5,
HILO8 = 6,
L8 = 7,
A8 = 8,
LA4 = 9,
L4 = 10,
A4 = 11,
ETC1 = 12,
ETC1A4 = 13
}
private static readonly int[] Bpp = { 32, 24, 16, 16, 16, 16, 16, 8, 8, 8, 4, 4, 4, 8 };
private static readonly int[] TileOrder =
{
0, 1, 4, 5,
2, 3, 6, 7,
8, 9, 12, 13,
10, 11, 14, 15
};
private static readonly int[,] ETC1Modifiers =
{
{ 2, 8 },
{ 5, 17 },
{ 9, 29 },
{ 13, 42 },
{ 18, 60 },
{ 24, 80 },
{ 33, 106 },
{ 47, 183 }
};
public static int GetBpp(ImageFormat Format) { return Bpp[(uint)Format]; }
public static Bitmap ToBitmap(byte[] Data, int Width, int Height, ImageFormat Format, bool ExactSize = false)
{
return ToBitmap(Data, 0, Width, Height, Format, ExactSize);
}
public static unsafe Bitmap ToBitmap(byte[] Data, int Offset, int Width, int Height, ImageFormat Format, bool ExactSize = false)
{
if (Data == null || Data.Length < 1 || Offset < 0 || Offset >= Data.Length || Width < 1 || Height < 1) return null;
if (ExactSize && ((Width % 8) != 0 || (Height % 8) != 0)) return null;
int physicalwidth = Width;
int physicalheight = Height;
if (!ExactSize)
{
Width = 1 << (int)Math.Ceiling(Math.Log(Width, 2));
Height = 1 << (int)Math.Ceiling(Math.Log(Height, 2));
}
Bitmap bitm = new Bitmap(physicalwidth, physicalheight);
BitmapData d = bitm.LockBits(new Rectangle(0, 0, bitm.Width, bitm.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
uint* res = (uint*)d.Scan0;
int offs = Offset;//0;
int stride = d.Stride / 4;
switch (Format)
{
case ImageFormat.RGBA8:
for (int y = 0; y < Height; y += 8)
{
for (int x = 0; x < Width; x += 8)
{
for (int i = 0; i < 64; i++)
{
int x2 = i % 8;
if (x + x2 >= physicalwidth) continue;
int y2 = i / 8;
if (y + y2 >= physicalheight) continue;
int pos = TileOrder[x2 % 4 + y2 % 4 * 4] + 16 * (x2 / 4) + 32 * (y2 / 4);
res[(y + y2) * stride + x + x2] = GFXUtil.ToArgb(
Data[offs + pos * 4],
Data[offs + pos * 4 + 3],
Data[offs + pos * 4 + 2],
Data[offs + pos * 4 + 1]
);
}
offs += 64 * 4;
}
}
break;
case ImageFormat.RGB8:
for (int y = 0; y < Height; y += 8)
{
for (int x = 0; x < Width; x += 8)
{
for (int i = 0; i < 64; i++)
{
int x2 = i % 8;
if (x + x2 >= physicalwidth) continue;
int y2 = i / 8;
if (y + y2 >= physicalheight) continue;
int pos = TileOrder[x2 % 4 + y2 % 4 * 4] + 16 * (x2 / 4) + 32 * (y2 / 4);
res[(y + y2) * stride + x + x2] = GFXUtil.ToArgb(
Data[offs + pos * 3 + 2],
Data[offs + pos * 3 + 1],
Data[offs + pos * 3 + 0]
);
}
offs += 64 * 3;
}
}
break;
case ImageFormat.RGBA5551:
for (int y = 0; y < Height; y += 8)
{
for (int x = 0; x < Width; x += 8)
{
for (int i = 0; i < 64; i++)
{
int x2 = i % 8;
if (x + x2 >= physicalwidth) continue;
int y2 = i / 8;
if (y + y2 >= physicalheight) continue;
int pos = TileOrder[x2 % 4 + y2 % 4 * 4] + 16 * (x2 / 4) + 32 * (y2 / 4);
res[(y + y2) * stride + x + x2] =
GFXUtil.ARGB1555ToArgb(IOUtil.ReadU16LE(Data, offs + pos * 2));
}
offs += 64 * 2;
}
}
break;
case ImageFormat.RGB565:
for (int y = 0; y < Height; y += 8)
{
for (int x = 0; x < Width; x += 8)
{
for (int i = 0; i < 64; i++)
{
int x2 = i % 8;
if (x + x2 >= physicalwidth) continue;
int y2 = i / 8;
if (y + y2 >= physicalheight) continue;
int pos = TileOrder[x2 % 4 + y2 % 4 * 4] + 16 * (x2 / 4) + 32 * (y2 / 4);
res[(y + y2) * stride + x + x2] =
GFXUtil.RGB565ToArgb(IOUtil.ReadU16LE(Data, offs + pos * 2));
}
offs += 64 * 2;
}
}
break;
case ImageFormat.RGBA4:
for (int y = 0; y < Height; y += 8)
{
for (int x = 0; x < Width; x += 8)
{
for (int i = 0; i < 64; i++)
{
int x2 = i % 8;
if (x + x2 >= physicalwidth) continue;
int y2 = i / 8;
if (y + y2 >= physicalheight) continue;
int pos = TileOrder[x2 % 4 + y2 % 4 * 4] + 16 * (x2 / 4) + 32 * (y2 / 4);
res[(y + y2) * stride + x + x2] = GFXUtil.ToArgb(
(byte)((Data[offs + pos * 2] & 0xF) * 0x11),
(byte)((Data[offs + pos * 2 + 1] >> 4) * 0x11),
(byte)((Data[offs + pos * 2 + 1] & 0xF) * 0x11),
(byte)((Data[offs + pos * 2] >> 4) * 0x11)
);
}
offs += 64 * 2;
}
}
break;
case ImageFormat.LA8:
for (int y = 0; y < Height; y += 8)
{
for (int x = 0; x < Width; x += 8)
{
for (int i = 0; i < 64; i++)
{
int x2 = i % 8;
if (x + x2 >= physicalwidth) continue;
int y2 = i / 8;
if (y + y2 >= physicalheight) continue;
int pos = TileOrder[x2 % 4 + y2 % 4 * 4] + 16 * (x2 / 4) + 32 * (y2 / 4);
res[(y + y2) * stride + x + x2] = GFXUtil.ToArgb(
Data[offs + pos * 2],
Data[offs + pos * 2 + 1],
Data[offs + pos * 2 + 1],
Data[offs + pos * 2 + 1]
);
}
offs += 64 * 2;
}
}
break;
case ImageFormat.HILO8:
for (int y = 0; y < Height; y += 8)
{
for (int x = 0; x < Width; x += 8)
{
for (int i = 0; i < 64; i++)
{
int x2 = i % 8;
if (x + x2 >= physicalwidth) continue;
int y2 = i / 8;
if (y + y2 >= physicalheight) continue;
int pos = TileOrder[x2 % 4 + y2 % 4 * 4] + 16 * (x2 / 4) + 32 * (y2 / 4);
res[(y + y2) * stride + x + x2] = GFXUtil.ToArgb(
Data[offs + pos * 2],
Data[offs + pos * 2 + 1],
Data[offs + pos * 2 + 1],
Data[offs + pos * 2 + 1]
);
}
offs += 64 * 2;
}
}
break;
case ImageFormat.L8:
for (int y = 0; y < Height; y += 8)
{
for (int x = 0; x < Width; x += 8)
{
for (int i = 0; i < 64; i++)
{
int x2 = i % 8;
if (x + x2 >= physicalwidth) continue;
int y2 = i / 8;
if (y + y2 >= physicalheight) continue;
int pos = TileOrder[x2 % 4 + y2 % 4 * 4] + 16 * (x2 / 4) + 32 * (y2 / 4);
res[(y + y2) * stride + x + x2] = GFXUtil.ToArgb(
Data[offs + pos],
Data[offs + pos],
Data[offs + pos]
);
}
offs += 64;
}
}
break;
case ImageFormat.A8:
for (int y = 0; y < Height; y += 8)
{
for (int x = 0; x < Width; x += 8)
{
for (int i = 0; i < 64; i++)
{
int x2 = i % 8;
if (x + x2 >= physicalwidth) continue;
int y2 = i / 8;
if (y + y2 >= physicalheight) continue;
int pos = TileOrder[x2 % 4 + y2 % 4 * 4] + 16 * (x2 / 4) + 32 * (y2 / 4);
res[(y + y2) * stride + x + x2] = GFXUtil.ToArgb(
Data[offs + pos],
255,
255,
255
);
}
offs += 64;
}
}
break;
case ImageFormat.LA4:
for (int y = 0; y < Height; y += 8)
{
for (int x = 0; x < Width; x += 8)
{
for (int i = 0; i < 64; i++)
{
int x2 = i % 8;
if (x + x2 >= physicalwidth) continue;
int y2 = i / 8;
if (y + y2 >= physicalheight) continue;
int pos = TileOrder[x2 % 4 + y2 % 4 * 4] + 16 * (x2 / 4) + 32 * (y2 / 4);
res[(y + y2) * stride + x + x2] = GFXUtil.ToArgb(
(byte)((Data[offs + pos] & 0xF) * 0x11),
(byte)((Data[offs + pos] >> 4) * 0x11),
(byte)((Data[offs + pos] >> 4) * 0x11),
(byte)((Data[offs + pos] >> 4) * 0x11)
);
}
offs += 64;
}
}
break;
case ImageFormat.L4:
for (int y = 0; y < Height; y += 8)
{
for (int x = 0; x < Width; x += 8)
{
for (int i = 0; i < 64; i++)
{
int x2 = i % 8;
if (x + x2 >= physicalwidth) continue;
int y2 = i / 8;
if (y + y2 >= physicalheight) continue;
int pos = TileOrder[x2 % 4 + y2 % 4 * 4] + 16 * (x2 / 4) + 32 * (y2 / 4);
int shift = (pos & 1) * 4;
res[(y + y2) * stride + x + x2] = GFXUtil.ToArgb(
(byte)(((Data[offs + pos / 2] >> shift) & 0xF) * 0x11),
(byte)(((Data[offs + pos / 2] >> shift) & 0xF) * 0x11),
(byte)(((Data[offs + pos / 2] >> shift) & 0xF) * 0x11)
);
}
offs += 64 / 2;
}
}
break;
case ImageFormat.A4:
for (int y = 0; y < Height; y += 8)
{
for (int x = 0; x < Width; x += 8)
{
for (int i = 0; i < 64; i++)
{
int x2 = i % 8;
if (x + x2 >= physicalwidth) continue;
int y2 = i / 8;
if (y + y2 >= physicalheight) continue;
int pos = TileOrder[x2 % 4 + y2 % 4 * 4] + 16 * (x2 / 4) + 32 * (y2 / 4);
int shift = (pos & 1) * 4;
res[(y + y2) * stride + x + x2] = GFXUtil.ToArgb(
(byte)(((Data[offs + pos / 2] >> shift) & 0xF) * 0x11),
255,
255,
255
);
}
offs += 64 / 2;
}
}
break;
case ImageFormat.ETC1://Some reference: http://www.khronos.org/registry/gles/extensions/OES/OES_compressed_ETC1_RGB8_texture.txt
case ImageFormat.ETC1A4:
{
for (int y = 0; y < Height; y += 8)
{
for (int x = 0; x < Width; x += 8)
{
for (int i = 0; i < 8; i += 4)
{
for (int j = 0; j < 8; j += 4)
{
ulong alpha = 0xFFFFFFFFFFFFFFFF;
if (Format == ImageFormat.ETC1A4)
{
alpha = IOUtil.ReadU64LE(Data, offs);
offs += 8;
}
ulong data = IOUtil.ReadU64LE(Data, offs);
bool diffbit = ((data >> 33) & 1) == 1;
bool flipbit = ((data >> 32) & 1) == 1; //0: |||, 1: |-|
int r1, r2, g1, g2, b1, b2;
if (diffbit) //'differential' mode
{
int r = (int)((data >> 59) & 0x1F);
int g = (int)((data >> 51) & 0x1F);
int b = (int)((data >> 43) & 0x1F);
r1 = (r << 3) | ((r & 0x1C) >> 2);
g1 = (g << 3) | ((g & 0x1C) >> 2);
b1 = (b << 3) | ((b & 0x1C) >> 2);
r += (int)((data >> 56) & 0x7) << 29 >> 29;
g += (int)((data >> 48) & 0x7) << 29 >> 29;
b += (int)((data >> 40) & 0x7) << 29 >> 29;
r2 = (r << 3) | ((r & 0x1C) >> 2);
g2 = (g << 3) | ((g & 0x1C) >> 2);
b2 = (b << 3) | ((b & 0x1C) >> 2);
}
else //'individual' mode
{
r1 = (int)((data >> 60) & 0xF) * 0x11;
g1 = (int)((data >> 52) & 0xF) * 0x11;
b1 = (int)((data >> 44) & 0xF) * 0x11;
r2 = (int)((data >> 56) & 0xF) * 0x11;
g2 = (int)((data >> 48) & 0xF) * 0x11;
b2 = (int)((data >> 40) & 0xF) * 0x11;
}
int Table1 = (int)((data >> 37) & 0x7);
int Table2 = (int)((data >> 34) & 0x7);
for (int y3 = 0; y3 < 4; y3++)
{
for (int x3 = 0; x3 < 4; x3++)
{
if (x + j + x3 >= physicalwidth) continue;
if (y + i + y3 >= physicalheight) continue;
int val = (int)((data >> (x3 * 4 + y3)) & 0x1);
bool neg = ((data >> (x3 * 4 + y3 + 16)) & 0x1) == 1;
uint c;
if ((flipbit && y3 < 2) || (!flipbit && x3 < 2))
{
int add = ETC1Modifiers[Table1, val] * (neg ? -1 : 1);
c = GFXUtil.ToArgb((byte)(((alpha >> ((x3 * 4 + y3) * 4)) & 0xF) * 0x11), (byte)ColorClamp(r1 + add), (byte)ColorClamp(g1 + add), (byte)ColorClamp(b1 + add));
}
else
{
int add = ETC1Modifiers[Table2, val] * (neg ? -1 : 1);
c = GFXUtil.ToArgb((byte)(((alpha >> ((x3 * 4 + y3) * 4)) & 0xF) * 0x11), (byte)ColorClamp(r2 + add), (byte)ColorClamp(g2 + add), (byte)ColorClamp(b2 + add));
}
res[(i + y3) * stride + x + j + x3] = c;
}
}
offs += 8;
}
}
}
res += stride * 8;
}
}
break;
}
bitm.UnlockBits(d);
return bitm;
}
public static unsafe byte[] FromBitmap(Bitmap Picture, ImageFormat Format, bool ExactSize = false)
{
if (ExactSize && ((Picture.Width % 8) != 0 || (Picture.Height % 8) != 0)) return null;
int physicalwidth = Picture.Width;
int physicalheight = Picture.Height;
int ConvWidth = Picture.Width;
int ConvHeight = Picture.Height;
if (!ExactSize)
{
ConvWidth = 1 << (int)Math.Ceiling(Math.Log(Picture.Width, 2));
ConvHeight = 1 << (int)Math.Ceiling(Math.Log(Picture.Height, 2));
}
BitmapData d = Picture.LockBits(new Rectangle(0, 0, Picture.Width, Picture.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
uint* res = (uint*)d.Scan0;
byte[] result = new byte[ConvWidth * ConvHeight * GetBpp(Format) / 8];
int offs = 0;
switch (Format)
{
case ImageFormat.RGB565:
for (int y = 0; y < ConvHeight; y += 8)
{
for (int x = 0; x < ConvWidth; x += 8)
{
for (int i = 0; i < 64; i++)
{
int x2 = i % 8;
if (x + x2 >= physicalwidth) continue;
int y2 = i / 8;
if (y + y2 >= physicalheight) continue;
int pos = TileOrder[x2 % 4 + y2 % 4 * 4] + 16 * (x2 / 4) + 32 * (y2 / 4);
IOUtil.WriteU16LE(result, offs + pos * 2, GFXUtil.ArgbToRGB565(res[(y + y2) * d.Stride / 4 + x + x2]));
}
offs += 64 * 2;
}
}
break;
case ImageFormat.ETC1:
case ImageFormat.ETC1A4:
for (int y = 0; y < ConvHeight; y += 8)
{
for (int x = 0; x < ConvWidth; x += 8)
{
for (int i = 0; i < 8; i += 4)
{
for (int j = 0; j < 8; j += 4)
{
if (Format == ImageFormat.ETC1A4)
{
ulong alpha = 0;
int iiii = 0;
for (int xx = 0; xx < 4; xx++)
{
for (int yy = 0; yy < 4; yy++)
{
uint color = res[((y + i + yy) * (d.Stride / 4)) + x + j + xx];
uint a = color >> 24;
a >>= 4;
alpha |= (ulong)a << (iiii * 4);
iiii++;
}
}
IOUtil.WriteU64LE(result, offs, alpha);
offs += 8;
}
/*
ulong data = 0;
//TODO: Choose the best configuration
bool diffbit = false;//((data >> 33) & 1) == 1;
bool flipbit = false;// ((data >> 32) & 1) == 1;
data |= (flipbit ? 1ul : 0ul) << 32;
data |= (diffbit ? 1ul : 0ul) << 33;
//Get the colors for the left side:
uint[] Left = new uint[8];
uint avrgRL = 0;
uint avrgGL = 0;
uint avrgBL = 0;
int iii = 0;
for (int yy = 0; yy < 4; yy++)
{
for (int xx = 0; xx < 2; xx++)
{
uint color = res[((y + i + yy) * (d.Stride / 4)) + x + j + xx];
avrgRL += (color >> 16) & 0xFF;
avrgGL += (color >> 8) & 0xFF;
avrgBL += (color >> 0) & 0xFF;
Left[iii++] = color;
}
}
avrgRL /= 8;
avrgGL /= 8;
avrgBL /= 8;
ulong r1 = avrgRL / 0x11;
ulong g1 = avrgGL / 0x11;
ulong b1 = avrgBL / 0x11;
float[] LeftDeltas = new float[8];
//float LeftMax = int.MinValue;
//float LeftMin = int.MaxValue;
float deltamean = 0;
iii = 0;
foreach (uint c in Left)
{
uint r = (c >> 16) & 0xFF;
uint g = (c >> 8) & 0xFF;
uint b = (c >> 0) & 0xF;
LeftDeltas[iii] = ((int)(r - (r1 * 0x11)) + (int)(g - (g1 * 0x11)) + (int)(b - (b1 * 0x11))) / 3f;
deltamean += LeftDeltas[iii];
//if (Math.Abs(LeftDeltas[iii]) > LeftMax) LeftMax = Math.Abs(LeftDeltas[iii]);
//if (Math.Abs(LeftDeltas[iii]) < LeftMin) LeftMin = Math.Abs(LeftDeltas[iii]);
iii++;
}
deltamean /= 8;
/*avrgRL = (uint)((int)avrgRL + deltamean);
if ((int)avrgRL > 255) avrgRL = 255;
if ((int)avrgRL < 0) avrgRL = 0;
avrgGL = (uint)((int)avrgGL + deltamean);
if ((int)avrgGL > 255) avrgGL = 255;
if ((int)avrgGL < 0) avrgGL = 0;
avrgBL = (uint)((int)avrgBL + deltamean);
if ((int)avrgBL > 255) avrgBL = 255;
if ((int)avrgBL < 0) avrgBL = 0;*/
/*while (avrgRL > 183 && avrgGL > 183 && avrgBL > 183)
{
avrgRL--;
avrgGL--;
avrgBL--;
}/
r1 = avrgRL / 0x11;
g1 = avrgGL / 0x11;
b1 = avrgBL / 0x11;
data |= r1 << 60;
data |= g1 << 52;
data |= b1 << 44;
//Get the colors for the right side:
uint[] Right = new uint[8];
uint avrgRR = 0;
uint avrgGR = 0;
uint avrgBR = 0;
iii = 0;
for (int yy = 0; yy < 4; yy++)
{
for (int xx = 2; xx < 4; xx++)
{
uint color = res[((y + i + yy) * (d.Stride / 4)) + x + j + xx];
avrgRR += (color >> 16) & 0xFF;
avrgGR += (color >> 8) & 0xFF;
avrgBR += (color >> 0) & 0xFF;
Right[iii++] = color;
}
}
avrgRR /= 8;
avrgGR /= 8;
avrgBR /= 8;
ulong r2 = avrgRR / 0x11;
ulong g2 = avrgGR / 0x11;
ulong b2 = avrgBR / 0x11;
float[] RightDeltas = new float[8];
deltamean = 0;
iii = 0;
foreach (uint c in Right)
{
uint r = (c >> 16) & 0xFF;
uint g = (c >> 8) & 0xFF;
uint b = (c >> 0) & 0xF;
RightDeltas[iii] = ((int)(r - (r2 * 0x11)) + (int)(g - (g2 * 0x11)) + (int)(b - (b2 * 0x11))) / 3f;
deltamean += RightDeltas[iii];
iii++;
}
deltamean /= 8;
/* avrgRR = (uint)((int)avrgRR + deltamean);
if ((int)avrgRR > 255) avrgRR = 255;
if ((int)avrgRR < 0) avrgRR = 0;
avrgGR = (uint)((int)avrgGR + deltamean);
if ((int)avrgGR > 255) avrgGR = 255;
if ((int)avrgGR < 0) avrgGR = 0;
avrgBR = (uint)((int)avrgBR + deltamean);
if ((int)avrgBR > 255) avrgBR = 255;
if ((int)avrgBR < 0) avrgBR = 0;/
r2 = avrgRR / 0x11;
g2 = avrgGR / 0x11;
b2 = avrgBR / 0x11;
data |= r2 << 56;
data |= g2 << 48;
data |= b2 << 40;
//Calulate Deltas
LeftDeltas = new float[8];
float LeftMax = float.MinValue;
float LeftMin = float.MaxValue;
iii = 0;
foreach (uint c in Left)
{
uint r = (c >> 16) & 0xFF;
uint g = (c >> 8) & 0xFF;
uint b = (c >> 0) & 0xF;
LeftDeltas[iii] = ((int)(r - (r1 * 0x11)) + (int)(g - (g1 * 0x11)) + (int)(b - (b1 * 0x11))) / 3f;
if (Math.Abs(LeftDeltas[iii]) > LeftMax) LeftMax = Math.Abs(LeftDeltas[iii]);
if (Math.Abs(LeftDeltas[iii]) < LeftMin) LeftMin = Math.Abs(LeftDeltas[iii]);
iii++;
}
int tblidxmax = ClosestTable((int)LeftMax);
int tblidxmin = ClosestTable((int)LeftMin);
uint Table1 = (uint)tblidxmin;//(uint)((tblidxmax + tblidxmin) / 2);
RightDeltas = new float[8];
float RightMax = int.MinValue;
float RightMin = int.MaxValue;
iii = 0;
foreach (uint c in Right)
{
uint r = (c >> 16) & 0xFF;
uint g = (c >> 8) & 0xFF;
uint b = (c >> 0) & 0xF;
RightDeltas[iii] = ((int)(r - (r2 * 0x11)) + (int)(g - (g2 * 0x11)) + (int)(b - (b2 * 0x11))) / 3f;
if (Math.Abs(RightDeltas[iii]) > RightMax) RightMax = Math.Abs(RightDeltas[iii]);
if (Math.Abs(RightDeltas[iii]) < RightMin) RightMin = Math.Abs(RightDeltas[iii]);
iii++;
}
tblidxmax = ClosestTable((int)RightMax);
tblidxmin = ClosestTable((int)RightMin);
uint Table2 = (uint)tblidxmin;//(uint)((tblidxmax + tblidxmin) / 2);
//Set the tables
//uint Table1 = 0;
//uint Table2 = 0;
data |= (Table1 & 0x7) << 37;
data |= (Table2 & 0x7) << 34;
iii = 0;
for (int yy = 0; yy < 4; yy++)
{
for (int xx = 0; xx < 2; xx++)
{
if (LeftDeltas[iii] < 0) data |= 1ul << (xx * 4 + yy + 16);
float tbldiff1 = Math.Abs(LeftDeltas[iii]) - ETC1Modifiers[Table1, 0];
float tbldiff2 = Math.Abs(LeftDeltas[iii]) - ETC1Modifiers[Table1, 1];
if (Math.Abs(tbldiff2) < Math.Abs(tbldiff1)) data |= 1ul << (xx * 4 + yy);
iii++;
}
}
iii = 0;
for (int yy = 0; yy < 4; yy++)
{
for (int xx = 2; xx < 4; xx++)
{
if (RightDeltas[iii] < 0) data |= 1ul << (xx * 4 + yy + 16);
float tbldiff1 = Math.Abs(RightDeltas[iii]) - ETC1Modifiers[Table2, 0];
float tbldiff2 = Math.Abs(RightDeltas[iii]) - ETC1Modifiers[Table2, 1];
if (Math.Abs(tbldiff2) < Math.Abs(tbldiff1)) data |= 1ul << (xx * 4 + yy);
iii++;
}
}
//Write the data
IOUtil.WriteU64LE(result, offs, data);
offs += 8;*/
byte[] Data = new byte[4 * 4 * 3];
for (int yy = 0; yy < 4; yy++)
{
for (int xx = 0; xx < 4; xx++)
{
uint color = res[((y + i + yy) * (d.Stride / 4)) + x + j + xx];
Data[(yy * 4 + xx) * 3] = (byte)((color >> 16) & 0xFF);
Data[(yy * 4 + xx) * 3 + 1] = (byte)((color >> 8) & 0xFF);
Data[(yy * 4 + xx) * 3 + 2] = (byte)((color >> 0) & 0xFF);
}
}
IOUtil.WriteU64LE(result, offs, ETC1.etc1_encode_block(Data));
offs += 8;
}
}
}
}
break;
default:
throw new NotImplementedException("This format is not implemented yet.");
}
return result;
}
private static int ClosestTable(int Value)
{
int delta = int.MaxValue;
int curtable = -1;
for (int i = 0; i < 8; i++)
{
if (Math.Abs(Value - ETC1Modifiers[i, 0]) < delta)
{
delta = Math.Abs(Value - ETC1Modifiers[i, 0]);
curtable = i;
}
if (Math.Abs(Value - ETC1Modifiers[i, 1]) < delta)
{
delta = Math.Abs(Value - ETC1Modifiers[i, 1]);
curtable = i;
}
}
return curtable;
}
private static int ColorClamp(int Color)
{
if (Color > 255) Color = 255;
if (Color < 0) Color = 0;
return Color;
}
}
}

View File

@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using LibEveryFileExplorer.Collections;
namespace _3DS.NintendoWare.GFX
{
public class BoundingVolume
{
public BoundingVolume(EndianBinaryReader er)
{
Type = er.ReadUInt32();
}
public virtual void Write(EndianBinaryWriter er)
{
er.Write(Type);
}
public UInt32 Type;
public static BoundingVolume FromStream(EndianBinaryReader er)
{
uint type = er.ReadUInt32();
er.BaseStream.Position -= 4;
switch (type)
{
case 0x80000000:
return new OrientedBoundingBox(er);
}
return new BoundingVolume(er);
}
}
public class AxisAlignedBoundingBox : BoundingVolume
{
public AxisAlignedBoundingBox(EndianBinaryReader er)
: base(er)
{
CenterPosition = er.ReadVector3();
Size = er.ReadVector3();
}
public override void Write(EndianBinaryWriter er)
{
base.Write(er);
er.WriteVector3(CenterPosition);
er.WriteVector3(Size);
}
public Vector3 CenterPosition;
public Vector3 Size;
}
public class OrientedBoundingBox : BoundingVolume
{
public OrientedBoundingBox(EndianBinaryReader er)
: base(er)
{
CenterPosition = er.ReadVector3();
OrientationMatrix = er.ReadSingles(3 * 3);
Size = er.ReadVector3();
}
public override void Write(EndianBinaryWriter er)
{
base.Write(er);
er.WriteVector3(CenterPosition);
er.Write(OrientationMatrix, 0, 3 * 3);
er.WriteVector3(Size);
}
public Vector3 CenterPosition;
public Single[] OrientationMatrix;//3x3
public Vector3 Size;
}
}

View File

@ -0,0 +1,112 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using LibEveryFileExplorer.Files;
namespace _3DS.NintendoWare.GFX
{
public class CANM
{
public CANM(EndianBinaryReader er)
{
Signature = er.ReadString(Encoding.ASCII, 4);
if (Signature != "CANM") throw new SignatureNotCorrectException(Signature, "CANM", er.BaseStream.Position);
Revision = er.ReadUInt32();
NameOffset = (UInt32)er.BaseStream.Position + er.ReadUInt32();
TargetAnimationGroupNameOffset = (UInt32)er.BaseStream.Position + er.ReadUInt32();
LoopMode = er.ReadUInt32();
FrameSize = er.ReadSingle();
NrMemberAnimations = er.ReadUInt32();
MemberAnimationDictOffset = (UInt32)er.BaseStream.Position + er.ReadUInt32();
NrUserDataEntries = er.ReadUInt32();
UserDataOffset = er.ReadUInt32();
long curpos = er.BaseStream.Position;
er.BaseStream.Position = NameOffset;
Name = er.ReadStringNT(Encoding.ASCII);
er.BaseStream.Position = TargetAnimationGroupNameOffset;
TargetAnimationGroupName = er.ReadStringNT(Encoding.ASCII);
er.BaseStream.Position = MemberAnimationDictOffset;
MemberAnimationDictionary = new DICT(er);
MemberAnimations = new MemberAnimationData[NrMemberAnimations];
for (int i = 0; i < NrMemberAnimations; i++)
{
er.BaseStream.Position = MemberAnimationDictionary[i].DataOffset;
MemberAnimations[i] = new MemberAnimationData(er);
}
er.BaseStream.Position = curpos;
}
public String Signature;
public UInt32 Revision;
public UInt32 NameOffset;
public UInt32 TargetAnimationGroupNameOffset;
public UInt32 LoopMode;
public Single FrameSize;
public UInt32 NrMemberAnimations;
public UInt32 MemberAnimationDictOffset;
public UInt32 NrUserDataEntries;
public UInt32 UserDataOffset;
public String Name;
public String TargetAnimationGroupName;
public DICT MemberAnimationDictionary;
public MemberAnimationData[] MemberAnimations;
public class MemberAnimationData
{
public enum AnimationType
{
FloatAnimation,
IntAnimation,
BoolAnimation,
Vector2Animation,
Vector3Animation,
TransformAnimation,
RgbaColorAnimation,
TextureAnimation,
BakedTransformAnimation,
FullBakedAnimation
}
public MemberAnimationData(EndianBinaryReader er)
{
Flags = er.ReadUInt32();
PathOffset = (UInt32)er.BaseStream.Position + er.ReadUInt32();
PrimitiveType = (AnimationType)er.ReadUInt32();
/*switch (PrimitiveType)
{
case AnimationType.Vector2Animation:
var v = new Single[2][];
if ((Flags & 1) != 0) v[0] = new float[] { er.ReadSingle() };//constant
else if ((Flags & 4) != 0) er.ReadUInt32();//nothing = empty reference
Data = v;
break;
}*/
long curpos = er.BaseStream.Position;
er.BaseStream.Position = PathOffset;
Path = er.ReadStringNT(Encoding.ASCII);
er.BaseStream.Position = curpos;
}
public UInt32 Flags;
public UInt32 PathOffset;
public AnimationType PrimitiveType;
//public Array[] Data;
public String Path;
}
public override string ToString()
{
return Name;
}
}
}

View File

@ -0,0 +1,690 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LibEveryFileExplorer.Files;
using System.Drawing;
using System.IO;
using LibEveryFileExplorer.IO;
using System.Windows.Forms;
using LibEveryFileExplorer._3D;
using CommonFiles;
using Tao.OpenGl;
using LibEveryFileExplorer.Collections;
namespace _3DS.NintendoWare.GFX
{
public class CGFX : FileFormat<CGFX.CGFXIdentifier>, IConvertable, IViewable, IWriteable
{
public CGFX(byte[] Data)
{
EndianBinaryReader er = new EndianBinaryReader(new MemoryStream(Data), Endianness.LittleEndian);
try
{
Header = new CGFXHeader(er);
this.Data = new DATA(er);
}
finally
{
er.Close();
}
}
public Form GetDialog()
{
return new UI.CGFXViewer(this);
}
public string GetConversionFileFilters()
{
return "COLLADA DAE File (*.dae)|*.dae|Wavefront OBJ File (*.obj)|*.obj";
}
public bool Convert(int FilterIndex, String Path)
{
switch (FilterIndex)
{
case 0:
{
DAE o = ToDAE(0);
File.Create(Path).Close();
File.WriteAllBytes(Path, o.Write());
Directory.CreateDirectory(System.IO.Path.GetDirectoryName(Path) + "\\Tex");
foreach (var v in Data.Textures)
{
if (!(v is ImageTextureCtr)) continue;
((ImageTextureCtr)v).GetBitmap().Save(System.IO.Path.GetDirectoryName(Path) + "\\Tex\\" + v.Name + ".png");
}
return true;
}
case 1:
{
if (Data.Models.Length == 0) return false;
OBJ o = ToOBJ(0);
o.MTLPath = System.IO.Path.GetFileNameWithoutExtension(Path) + ".mtl";
MTL m = ToMTL(0);
byte[] d = o.Write();
byte[] d2 = m.Write();
File.Create(Path).Close();
File.WriteAllBytes(Path, d);
File.Create(System.IO.Path.ChangeExtension(Path, "mtl")).Close();
File.WriteAllBytes(System.IO.Path.ChangeExtension(Path, "mtl"), d2);
Directory.CreateDirectory(System.IO.Path.GetDirectoryName(Path) + "\\Tex");
foreach (var v in Data.Textures)
{
//if (v.NrLevels > 2) v.GetBitmap(2).Save(System.IO.Path.GetDirectoryName(Path) + "\\Tex\\" + v.Name + ".png");
//else if (v.NrLevels > 1) v.GetBitmap(1).Save(System.IO.Path.GetDirectoryName(Path) + "\\Tex\\" + v.Name + ".png");
//else v.GetBitmap(0).Save(System.IO.Path.GetDirectoryName(Path) + "\\Tex\\" + v.Name + ".png");
if (!(v is ImageTextureCtr)) continue;
((ImageTextureCtr)v).GetBitmap().Save(System.IO.Path.GetDirectoryName(Path) + "\\Tex\\" + v.Name + ".png");
}
return true;
}
default:
return false;
}
}
public string GetSaveDefaultFileFilter()
{
return "CTR Graphics Resource (*.bcres)|*.bcres";
}
public byte[] Write()
{
MemoryStream m = new MemoryStream();
EndianBinaryWriter er = new EndianBinaryWriter(m, Endianness.LittleEndian);
Header.NrBlocks = 1;
Header.Write(er);
CGFXWriterContext c = new CGFXWriterContext();
Data.Write(er, c);
if (c.DoWriteIMAGBlock())
{
long curpos = er.BaseStream.Position;
er.BaseStream.Position = 0x10;
er.Write((uint)2);
er.BaseStream.Position = curpos;
c.WriteIMAGBlock(er);
}
long curpos2 = er.BaseStream.Position;
er.BaseStream.Position = 0xC;
er.Write((uint)(curpos2));
er.BaseStream.Position = curpos2;
byte[] result = m.ToArray();
er.Close();
return result;
}
public CGFXHeader Header;
public class CGFXHeader
{
public CGFXHeader(EndianBinaryReader er)
{
Signature = er.ReadString(Encoding.ASCII, 4);
if (Signature != "CGFX") throw new SignatureNotCorrectException(Signature, "CGFX", er.BaseStream.Position - 4);
Endianness = er.ReadUInt16();
HeaderSize = er.ReadUInt16();
Version = er.ReadUInt32();
FileSize = er.ReadUInt32();
NrBlocks = er.ReadUInt32();
}
public void Write(EndianBinaryWriter er)
{
er.Write(Signature, Encoding.ASCII, false);
er.Write(Endianness);
er.Write(HeaderSize);
er.Write(Version);
er.Write((uint)0);
er.Write(NrBlocks);
}
public String Signature;
public UInt16 Endianness;
public UInt16 HeaderSize;
public UInt32 Version;
public UInt32 FileSize;
public UInt32 NrBlocks;
}
public DATA Data;
public class DATA
{
public DATA(EndianBinaryReader er)
{
Signature = er.ReadString(Encoding.ASCII, 4);
if (Signature != "DATA") throw new SignatureNotCorrectException(Signature, "DATA", er.BaseStream.Position - 4);
SectionSize = er.ReadUInt32();
DictionaryEntries = new DictionaryInfo[16];
for (int i = 0; i < 16; i++)
{
DictionaryEntries[i] = new DictionaryInfo(er);
}
Dictionaries = new DICT[16];
for (int i = 0; i < 16; i++)
{
if (i == 15 && DictionaryEntries[i].NrItems == 0x54434944)
{
DictionaryEntries[i].NrItems = 0;
DictionaryEntries[i].Offset = 0;
}
if (DictionaryEntries[i].Offset != 0)
{
long curpos = er.BaseStream.Position;
er.BaseStream.Position = DictionaryEntries[i].Offset;
Dictionaries[i] = new DICT(er);
er.BaseStream.Position = curpos;
}
else Dictionaries[i] = null;
}
if (Dictionaries[0] != null)
{
Models = new CMDL[Dictionaries[0].Count];
for (int i = 0; i < Dictionaries[0].Count; i++)
{
long curpos = er.BaseStream.Position;
er.BaseStream.Position = Dictionaries[0][i].DataOffset;
Models[i] = new CMDL(er);
er.BaseStream.Position = curpos;
}
}
if (Dictionaries[1] != null)
{
Textures = new TXOB[Dictionaries[1].Count];
for (int i = 0; i < Dictionaries[1].Count; i++)
{
long curpos = er.BaseStream.Position;
er.BaseStream.Position = Dictionaries[1][i].DataOffset;
Textures[i] = TXOB.FromStream(er);//new TXOB(er);
er.BaseStream.Position = curpos;
}
}
if (Dictionaries[9] != null)
{
SkeletonAnimations = new CANM[Dictionaries[9].Count];
for (int i = 0; i < Dictionaries[9].Count; i++)
{
long curpos = er.BaseStream.Position;
er.BaseStream.Position = Dictionaries[9][i].DataOffset;
SkeletonAnimations[i] = new CANM(er);
er.BaseStream.Position = curpos;
}
}
if (Dictionaries[10] != null)
{
MaterialAnimations = new CANM[Dictionaries[10].Count];
for (int i = 0; i < Dictionaries[10].Count; i++)
{
long curpos = er.BaseStream.Position;
er.BaseStream.Position = Dictionaries[10][i].DataOffset;
MaterialAnimations[i] = new CANM(er);
er.BaseStream.Position = curpos;
}
}
if (Dictionaries[11] != null)
{
VisibilityAnimations = new CANM[Dictionaries[11].Count];
for (int i = 0; i < Dictionaries[11].Count; i++)
{
long curpos = er.BaseStream.Position;
er.BaseStream.Position = Dictionaries[11][i].DataOffset;
VisibilityAnimations[i] = new CANM(er);
er.BaseStream.Position = curpos;
}
}
}
public void Write(EndianBinaryWriter er, CGFXWriterContext c)
{
long basepos = er.BaseStream.Position;
er.Write(Signature, Encoding.ASCII, false);
er.Write((uint)0);
for (int i = 0; i < 16; i++)
{
if (Dictionaries[i] != null)
{
if (i != 0 && i != 1) throw new NotImplementedException();
er.Write((uint)Dictionaries[i].Count);
er.Write((uint)0);//dictoffset
}
else
{
er.Write((uint)0);
er.Write((uint)0);
}
}
long[] dictoffsets = new long[16];
for (int i = 0; i < 16; i++)
{
if (Dictionaries[i] != null)
{
dictoffsets[i] = er.BaseStream.Position;
er.BaseStream.Position = basepos + 8 + i * 8 + 4;
er.Write((uint)(dictoffsets[i] - (basepos + 8 + i * 8 + 4)));
er.BaseStream.Position = dictoffsets[i];
Dictionaries[i].Write(er, c);
}
}
if (Dictionaries[0] != null)
{
for (int i = 0; i < Dictionaries[0].Count; i++)
{
long curpos = er.BaseStream.Position;
long bpos = er.BaseStream.Position = dictoffsets[0] + 0x1C + i * 0x10 + 0xC;
er.Write((uint)(curpos - bpos));
er.BaseStream.Position = curpos;
Models[i].Write(er, c);
}
}
if (Dictionaries[1] != null)
{
for (int i = 0; i < Dictionaries[1].Count; i++)
{
long curpos = er.BaseStream.Position;
long bpos = er.BaseStream.Position = dictoffsets[1] + 0x1C + i * 0x10 + 0xC;
er.Write((uint)(curpos - bpos));
er.BaseStream.Position = curpos;
Textures[i].Write(er, c);
}
}
c.WriteStringTable(er);
if (c.DoWriteIMAGBlock())
{
int length = c.GetIMAGBlockSize();
while (((er.BaseStream.Position + length) % 64) != 0) er.Write((byte)0);
}
long curpos2 = er.BaseStream.Position;
er.BaseStream.Position = basepos + 4;
er.Write((uint)(curpos2 - basepos));
er.BaseStream.Position = curpos2;
}
public String Signature;
public UInt32 SectionSize;
public DictionaryInfo[] DictionaryEntries;//x15
public class DictionaryInfo
{
public DictionaryInfo(EndianBinaryReader er)
{
NrItems = er.ReadUInt32();
long pos = er.BaseStream.Position;
Offset = er.ReadUInt32();
if (Offset != 0) Offset += (UInt32)pos;
}
public UInt32 NrItems;
public UInt32 Offset;
}
public DICT[] Dictionaries;
//0x0 - CMDL
//0x1 - TXOB
//0x9 - CANM (Skeleton Animation)
//0xA - CANM (Material Animation)
public CMDL[] Models;
public TXOB[] Textures;
public CANM[] SkeletonAnimations;
public CANM[] MaterialAnimations;
public CANM[] VisibilityAnimations;
}
public OBJ ToOBJ(int Model)
{
if (Data.Models.Length == 0 || Data.Models.Length <= Model) return null;
var o = new OBJ();
int v = 0;
int vn = 0;
int vt = 0;
//int vc = 0;
int ff = 0;
var m = Data.Models[Model];
//foreach (CMDL m in Models)
{
foreach (var vv in m.Shapes)
{
Polygon p = vv.GetVertexData(m);
var mat = m.Materials[m.Meshes[ff].MaterialIndex];
foreach (var q in vv.PrimitiveSets[0].Primitives[0].IndexStreams)
{
Vector3[] defs = q.GetFaceData();
foreach (Vector3 d in defs)
{
OBJ.OBJFace f = new OBJ.OBJFace();
f.Material = mat.Name;
o.Vertices.Add(p.Vertex[(int)d.X]);
o.Vertices.Add(p.Vertex[(int)d.Y]);
o.Vertices.Add(p.Vertex[(int)d.Z]);
f.VertexIndieces.Add(v);
f.VertexIndieces.Add(v + 1);
f.VertexIndieces.Add(v + 2);
v += 3;
if (p.Normals != null)
{
o.Normals.Add(p.Normals[(int)d.X]);
o.Normals.Add(p.Normals[(int)d.Y]);
o.Normals.Add(p.Normals[(int)d.Z]);
f.NormalIndieces.Add(vn);
f.NormalIndieces.Add(vn + 1);
f.NormalIndieces.Add(vn + 2);
vn += 3;
}
if (mat.NrActiveTextureCoordiators > 0 && mat.TextureCoordiators[0].MappingMethod == 0)// && mat.TextureCoordiators[0].SourceCoordinate == 0)
{
if (mat.TextureCoordiators[0].SourceCoordinate == 0)
{
o.TexCoords.Add(p.TexCoords[(int)d.X] * new Matrix34(mat.TextureCoordiators[0].Matrix));
o.TexCoords.Add(p.TexCoords[(int)d.Y] * new Matrix34(mat.TextureCoordiators[0].Matrix));
o.TexCoords.Add(p.TexCoords[(int)d.Z] * new Matrix34(mat.TextureCoordiators[0].Matrix));
}
else if (mat.TextureCoordiators[0].SourceCoordinate == 1)
{
o.TexCoords.Add(p.TexCoords2[(int)d.X] * new Matrix34(mat.TextureCoordiators[0].Matrix));
o.TexCoords.Add(p.TexCoords2[(int)d.Y] * new Matrix34(mat.TextureCoordiators[0].Matrix));
o.TexCoords.Add(p.TexCoords2[(int)d.Z] * new Matrix34(mat.TextureCoordiators[0].Matrix));
}
else
{
o.TexCoords.Add(p.TexCoords3[(int)d.X] * new Matrix34(mat.TextureCoordiators[0].Matrix));
o.TexCoords.Add(p.TexCoords3[(int)d.Y] * new Matrix34(mat.TextureCoordiators[0].Matrix));
o.TexCoords.Add(p.TexCoords3[(int)d.Z] * new Matrix34(mat.TextureCoordiators[0].Matrix));
}
}
/*else if (mat.NrActiveTextureCoordiators > 1 && mat.TextureCoordiators[1].MappingMethod == 0 && mat.TextureCoordiators[1].SourceCoordinate == 0)
{
o.TexCoords.Add(Vector2.Multiply(p.TexCoords[(int)d.X], mat.TextureCoordiators[1].Scale));
o.TexCoords.Add(Vector2.Multiply(p.TexCoords[(int)d.Y], mat.TextureCoordiators[1].Scale));
o.TexCoords.Add(Vector2.Multiply(p.TexCoords[(int)d.Z], mat.TextureCoordiators[1].Scale));
}
else if (mat.NrActiveTextureCoordiators > 2 && mat.TextureCoordiators[2].MappingMethod == 0 && mat.TextureCoordiators[2].SourceCoordinate == 0)
{
o.TexCoords.Add(Vector2.Multiply(p.TexCoords[(int)d.X], mat.TextureCoordiators[2].Scale));
o.TexCoords.Add(Vector2.Multiply(p.TexCoords[(int)d.Y], mat.TextureCoordiators[2].Scale));
o.TexCoords.Add(Vector2.Multiply(p.TexCoords[(int)d.Z], mat.TextureCoordiators[2].Scale));
}*/
else goto cont;
f.TexCoordIndieces.Add(vt);
f.TexCoordIndieces.Add(vt + 1);
f.TexCoordIndieces.Add(vt + 2);
vt += 3;
cont:
/*if (p.Colors != null)
{
o.VertexColors.Add(p.Colors[(int)d.X]);
o.VertexColors.Add(p.Colors[(int)d.Y]);
o.VertexColors.Add(p.Colors[(int)d.Z]);
f.VertexColorIndieces.Add(vc);
f.VertexColorIndieces.Add(vc + 1);
f.VertexColorIndieces.Add(vc + 2);
vc += 3;
}*/
o.Faces.Add(f);
}
}
ff++;
}
}
return o;
}
public DAE ToDAE(int Model)
{
if (Data.Models.Length == 0 || Data.Models.Length <= Model) return null;
var m = Data.Models[Model];
var o = new DAE();
o.Content.scene = new DAE.COLLADA._scene();
o.Content.scene.instance_visual_scene = new DAE.InstanceWithExtra();
o.Content.scene.instance_visual_scene.url = "#ID1";
o.Content.library_visual_scenes = new DAE.library_visual_scenes();
var scene = new DAE.visual_scene("ID1");
var rootnode = new DAE.node(m.Name);
scene.node.Add(rootnode);
o.Content.library_visual_scenes.visual_scene.Add(scene);
o.Content.library_geometries = new DAE.library_geometries();
o.Content.library_materials = new DAE.library_materials();
o.Content.library_effects = new DAE.library_effects();
if (Data.Textures != null && Data.Textures.Length > 0) o.Content.library_images = new DAE.library_images();
int id = 2;
int i = 0;
foreach (var matt in m.Materials)
{
var mat2 = new DAE.material();
mat2.id = "ID" + id++;
mat2.name = matt.Name;
var eff = new DAE.effect();
eff.id = "ID" + id++;
mat2.instance_effect = new DAE.instance_effect();
mat2.instance_effect.url = "#" + eff.id;
eff.profile_COMMON = new DAE.profile_COMMON();
eff.profile_COMMON.technique = new DAE.profile_COMMON._technique();
eff.profile_COMMON.technique.sid = "COMMON";
eff.profile_COMMON.technique.lambert = new DAE.profile_COMMON._technique._lambert();
eff.profile_COMMON.technique.lambert.diffuse = new DAE.common_color_or_texture_type();
if (matt.Tex0 != null && matt.Tex0.TextureObject is ReferenceTexture)
{
string texid = "ID" + id++;
o.Content.library_images.image.Add(new DAE.image() { id = texid, init_from = "Tex/" + ((ReferenceTexture)matt.Tex0.TextureObject).LinkedTextureName + ".png" });
var param1 = new DAE.common_newparam_type() { sid = "ID" + id++, choice = new DAE.fx_surface_common() { type = DAE.fx_surface_type_enum._2D } };
((DAE.fx_surface_common)param1.choice).init_from.Add(new DAE.fx_surface_init_from_common() { content = texid });
eff.profile_COMMON.newparam = new List<DAE.common_newparam_type>();
eff.profile_COMMON.newparam.Add(param1);
eff.profile_COMMON.newparam.Add(new DAE.common_newparam_type() { sid = "ID" + id++, choice = new DAE.fx_sampler2D_common() { source = param1.sid } });
eff.profile_COMMON.technique.lambert.diffuse.texture = new DAE.common_color_or_texture_type._texture() { texture = eff.profile_COMMON.newparam[1].sid, texcoord = "UVSET0" };
}
else
{
eff.profile_COMMON.technique.lambert.diffuse.color = new DAE.common_color_or_texture_type._color();
eff.profile_COMMON.technique.lambert.diffuse.color.content = Color.White;
}
o.Content.library_materials.material.Add(mat2);
o.Content.library_effects.effect.Add(eff);
}
int ff = 0;
//foreach (CMDL m in Models)
{
foreach (var vv in m.Shapes)
{
var geometry = new DAE.geometry();
geometry.id = "ID" + id++;
Polygon p = vv.GetVertexData(m);
var mat = m.Materials[m.Meshes[ff].MaterialIndex];
geometry.mesh = new DAE.mesh();
geometry.mesh.vertices = new DAE.vertices() { id = "ID" + id++ };
if (p.Vertex != null)
{
var src = new DAE.source() { id = "ID" + id++ };
src.float_array = new DAE.source._float_array() { id = "ID" + id++, count = (uint)p.Vertex.Length * 3 };
foreach (var v in p.Vertex)
{
src.float_array.content.Add(v.X);
src.float_array.content.Add(v.Y);
src.float_array.content.Add(v.Z);
}
src.technique_common = new DAE.source._technique_common();
src.technique_common.accessor = new DAE.accessor();
src.technique_common.accessor.count = (uint)p.Vertex.Length;
src.technique_common.accessor.source = "#" + src.float_array.id;
src.technique_common.accessor.stride = 3;
src.technique_common.accessor.param.Add(new DAE.param() { name = "X", type = "float" });
src.technique_common.accessor.param.Add(new DAE.param() { name = "Y", type = "float" });
src.technique_common.accessor.param.Add(new DAE.param() { name = "Z", type = "float" });
geometry.mesh.source.Add(src);
geometry.mesh.vertices.input.Add(new DAE.InputLocal() { semantic = "POSITION", source = "#" + src.id });
}
if (p.Normals != null)
{
var src = new DAE.source() { id = "ID" + id++ };
src.float_array = new DAE.source._float_array() { id = "ID" + id++, count = (uint)p.Normals.Length * 3 };
foreach (var v in p.Normals)
{
src.float_array.content.Add(v.X);
src.float_array.content.Add(v.Y);
src.float_array.content.Add(v.Z);
}
src.technique_common = new DAE.source._technique_common();
src.technique_common.accessor = new DAE.accessor();
src.technique_common.accessor.count = (uint)p.Normals.Length;
src.technique_common.accessor.source = "#" + src.float_array.id;
src.technique_common.accessor.stride = 3;
src.technique_common.accessor.param.Add(new DAE.param() { name = "X", type = "float" });
src.technique_common.accessor.param.Add(new DAE.param() { name = "Y", type = "float" });
src.technique_common.accessor.param.Add(new DAE.param() { name = "Z", type = "float" });
geometry.mesh.source.Add(src);
geometry.mesh.vertices.input.Add(new DAE.InputLocal() { semantic = "NORMAL", source = "#" + src.id });
}
DAE.source texcoordsrc = null;
if (p.TexCoords != null)
{
if (mat.NrActiveTextureCoordiators > 0 && mat.TextureCoordiators[0].MappingMethod == 0)
{
Vector2[] texc;
if (mat.TextureCoordiators[0].SourceCoordinate == 0)
{
texc = p.TexCoords.ToArray();
}
else if (mat.TextureCoordiators[0].SourceCoordinate == 1)
{
texc = p.TexCoords2.ToArray();
}
else
{
texc = p.TexCoords3.ToArray();
}
var src = texcoordsrc = new DAE.source() { id = "ID" + id++ };
src.float_array = new DAE.source._float_array() { id = "ID" + id++, count = (uint)texc.Length * 2 };
foreach (var v in texc)
{
Vector2 result = v * new Matrix34(mat.TextureCoordiators[0].Matrix);
src.float_array.content.Add(result.X);
src.float_array.content.Add(result.Y);
}
src.technique_common = new DAE.source._technique_common();
src.technique_common.accessor = new DAE.accessor();
src.technique_common.accessor.count = (uint)p.TexCoords.Length;
src.technique_common.accessor.source = "#" + src.float_array.id;
src.technique_common.accessor.stride = 2;
src.technique_common.accessor.param.Add(new DAE.param() { name = "S", type = "float" });
src.technique_common.accessor.param.Add(new DAE.param() { name = "T", type = "float" });
geometry.mesh.source.Add(src);
}
}
DAE.source colorsrc = null;
if (p.Colors != null)
{
var src = colorsrc = new DAE.source() { id = "ID" + id++ };
src.float_array = new DAE.source._float_array() { id = "ID" + id++, count = (uint)p.Colors.Length * 4 };
foreach (var v in p.Colors)
{
src.float_array.content.Add(v.R / 255f);
src.float_array.content.Add(v.G / 255f);
src.float_array.content.Add(v.B / 255f);
src.float_array.content.Add(v.A / 255f);
}
src.technique_common = new DAE.source._technique_common();
src.technique_common.accessor = new DAE.accessor();
src.technique_common.accessor.count = (uint)p.Colors.Length;
src.technique_common.accessor.source = "#" + src.float_array.id;
src.technique_common.accessor.stride = 4;
src.technique_common.accessor.param.Add(new DAE.param() { name = "R", type = "float" });
src.technique_common.accessor.param.Add(new DAE.param() { name = "G", type = "float" });
src.technique_common.accessor.param.Add(new DAE.param() { name = "B", type = "float" });
src.technique_common.accessor.param.Add(new DAE.param() { name = "A", type = "float" });
geometry.mesh.source.Add(src);
}
foreach (var q in vv.PrimitiveSets[0].Primitives[0].IndexStreams)
{
Vector3[] defs = q.GetFaceData();
var tri = new DAE.triangles() { count = (uint)defs.Length, material = mat.Name };
uint offs = 0;
tri.input.Add(new DAE.InputLocalOffset() { offset = offs++, semantic = "VERTEX", source = "#" + geometry.mesh.vertices.id });
if (texcoordsrc != null) tri.input.Add(new DAE.InputLocalOffset() { offset = offs++, semantic = "TEXCOORD", source = "#" + texcoordsrc.id });
if (colorsrc != null) tri.input.Add(new DAE.InputLocalOffset() { offset = offs++, semantic = "COLOR", source = "#" + colorsrc.id, set = 0 });
tri.p.Add(new DAE.p());
foreach (Vector3 d in defs)
{
tri.p[0].content.Add((ulong)d.X);
if (texcoordsrc != null) tri.p[0].content.Add((ulong)d.X);
if (colorsrc != null) tri.p[0].content.Add((ulong)d.X);
tri.p[0].content.Add((ulong)d.Y);
if (texcoordsrc != null) tri.p[0].content.Add((ulong)d.Y);
if (colorsrc != null) tri.p[0].content.Add((ulong)d.Y);
tri.p[0].content.Add((ulong)d.Z);
if (texcoordsrc != null) tri.p[0].content.Add((ulong)d.Z);
if (colorsrc != null) tri.p[0].content.Add((ulong)d.Z);
}
geometry.mesh.triangles.Add(tri);
}
o.Content.library_geometries.geometry.Add(geometry);
var instgem = new DAE.instance_geometry() { url = "#" + geometry.id };
instgem.bind_material = new DAE.bind_material();
instgem.bind_material.technique_common = new DAE.bind_material._technique_common();
var instmat = new DAE.instance_material();
instmat.symbol = mat.Name;
instmat.target = "#" + o.Content.library_materials.material[(int)m.Meshes[ff].MaterialIndex].id;
instmat.bind_vertex_input.Add(new DAE.instance_material._bind_vertex_input() { semantic = "UVSET0", input_semantic = "TEXCOORD", input_set = 0 });
instgem.bind_material.technique_common.instance_material.Add(instmat);
rootnode.instance_geometry.Add(instgem);
ff++;
}
}
return o;
}
public MTL ToMTL(int Model)
{
if (Data.Models.Length == 0 || Data.Models.Length <= Model) return null;
var o = new MTL();
var m = Data.Models[Model];
//foreach (CMDL m in Models)
{
foreach (var vv in m.Materials)
{
MTL.MTLMaterial mm = new MTL.MTLMaterial(vv.Name);
mm.DiffuseColor = vv.MaterialColor.DiffuseU32;
mm.AmbientColor = vv.MaterialColor.AmbientU32;
mm.Alpha = vv.MaterialColor.Diffuse.W;
mm.SpecularColor = vv.MaterialColor.Specular0U32;
if (vv.Tex0 != null && vv.Tex0.TextureObject is ReferenceTexture/* && vv.TextureCoordiators[0].SourceCoordinate == 0*/) mm.DiffuseMapPath = "Tex/" + ((ReferenceTexture)vv.Tex0.TextureObject).LinkedTextureName + ".png";
//else if (vv.Tex1 != null && vv.Tex1.TextureObject is ReferenceTexture && vv.TextureCoordiators[1].SourceCoordinate == 0) mm.DiffuseMapPath = "Tex/" + ((ReferenceTexture)vv.Tex1.TextureObject).LinkedTextureName + ".png";
//else if (vv.Tex2 != null && vv.Tex2.TextureObject is ReferenceTexture && vv.TextureCoordiators[2].SourceCoordinate == 0) mm.DiffuseMapPath = "Tex/" + ((ReferenceTexture)vv.Tex2.TextureObject).LinkedTextureName + ".png";
o.Materials.Add(mm);
}
}
return o;
}
public class CGFXIdentifier : FileFormatIdentifier
{
public override string GetCategory()
{
return Category_Models;
}
public override string GetFileDescription()
{
return "CTR Graphics (CGFX)";
}
public override string GetFileFilter()
{
return "CTR Graphics (*.bccam, *.bcfog, *.bclgt, *.bcmata, *.bcmcla, *.bcmdl, *.bcptl, *.bcres, *.bcsdr, *.bcskla)|*.bccam;*.bcfog;*.bclgt;*.bcmata;*.bcmcla;*.bcmdl;*.bcptl;*.bcres;*.bcsdr;*.bcskla";
}
public override Bitmap GetIcon()
{
return Resource.leaf;
}
public override FormatMatch IsFormat(EFEFile File)
{
if (File.Data.Length > 4 && File.Data[0] == 'C' && File.Data[1] == 'G' && File.Data[2] == 'F' && File.Data[3] == 'X') return FormatMatch.Content;
return FormatMatch.No;
}
}
}
}

View File

@ -0,0 +1,417 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tao.OpenGl;
using System.Drawing;
using LibEveryFileExplorer.Collections;
namespace _3DS.NintendoWare.GFX
{
public class CGFXShader
{
public int[] Textures;
private CMDL.MTOB Material;
public CGFXShader(CMDL.MTOB Material, int[] Textures)
{
this.Textures = Textures;
this.Material = Material;
}
public void Enable()
{
Gl.glUseProgram(program);
//setup uniforms
/*for (int i = 0; i < 3; i++)
{
String ss = "color_register" + i;
Gl.glUniform4f(Gl.glGetUniformLocation(program, ss), g_color_registers[i][0], g_color_registers[i][1], g_color_registers[i][2], g_color_registers[i][3]);
}
for (int i = 0; i < 1; i++)
{
String ss = "matColor";
Gl.glUniform4f(Gl.glGetUniformLocation(program, ss), MatColor[0], MatColor[1], MatColor[2], MatColor[3]);
}
for (int i = 0; i < 4; i++)
{
String ss = "color_const" + i;
Gl.glUniform4f(Gl.glGetUniformLocation(program, ss), g_color_consts[i][0], g_color_consts[i][1], g_color_consts[i][2], g_color_consts[i][3]);
}*/
// TODO: cache value of GetUniformLocation
//Gl.glUniform4fv(Gl.glGetUniformLocation(program, "registers"), 3, new float[] { g_color_registers[0][0], g_color_registers[0][1], g_color_registers[0][2], g_color_registers[0][3], g_color_registers[1][0], g_color_registers[1][1], g_color_registers[1][2], g_color_registers[1][3], g_color_registers[2][0], g_color_registers[2][1], g_color_registers[2][2], g_color_registers[2][3] });
}
public void Disable()
{
//Gl.glDeleteProgram(program);
//Gl.glDeleteShader(vertex_shader);
//Gl.glDeleteShader(fragment_shader);
// TODO: cache value of GetUniformLocation
//Gl.glUniform4fv(Gl.glGetUniformLocation(program, "registers"), 3, g_color_registers[0]);
}
//Fragment Lighting Primary Color:
//Color = SUM((dmp_FragmentLightSource[i].diffuse * dmp_FragmentMaterial.diffuse * DOT(dmp_FragmentLightSource[i].position, NormalVector) * SdwAttPr[i] + dmp_FragmentMaterial.ambient * dmp_FragmentLightSource[i].ambient) * Spot[i] * DistAtt[i]) + dmp_FragmentMaterial.emission + dmp_FragmentMaterial.ambient * dmp_FragmentLighting.ambient
//Color = SUM((vec3(1.0) * mDiff * DOT(
public void Compile()
{
// w.e good for now
uint sampler_count = (uint)Textures.Length;
//if (sampler_count == 0)
//{
// sampler_count = 1;
//}
// generate vertex/fragment shader code
//{
StringBuilder vert_ss = new StringBuilder();
//String vert_ss = "";
vert_ss.AppendFormat("vec4 diffuse = {0};\n", GetVec4(Material.MaterialColor.DiffuseU32));
vert_ss.AppendFormat("vec4 ambient = {0};\n", GetVec4(Material.MaterialColor.Ambient));
vert_ss.AppendFormat("vec4 spec1 = {0};\n", GetVec4(Material.MaterialColor.Specular0U32));
vert_ss.AppendFormat("vec4 spec2 = {0};\n", GetVec4(Material.MaterialColor.Specular1U32));
vert_ss.AppendLine("void main()");
vert_ss.AppendLine("{");
{
//if (Material.NrActiveTextureCoordiators != 0)
//{
vert_ss.AppendLine("gl_FrontColor = gl_Color * ambient;");
//vert_ss.AppendLine("gl_BackColor = gl_Color * ambient;");
//vert_ss.AppendLine("gl_FrontSecondaryColor = gl_Color * ambient;");
//vert_ss.AppendLine("gl_BackSecondaryColor = gl_Color * ambient;");
//}
//else
//{
// vert_ss.AppendLine("gl_FrontColor = diffuse * gl_Color * ambient;");
//vert_ss.AppendLine("gl_BackColor = diffuse * gl_Color * ambient;");
//vert_ss.AppendLine("gl_FrontSecondaryColor = diffuse * gl_Color * ambient;");
//vert_ss.AppendLine("gl_BackSecondaryColor = diffuse * gl_Color * ambient;");
//}
//vert_ss.AppendLine("gl_FrontColor = vec4(gl_Color.rgb, 1.0);");
if (Material.Tex0 != null) vert_ss.AppendFormat("gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord{0};\n", Material.TextureCoordiators[0].SourceCoordinate);
if (Material.Tex1 != null) vert_ss.AppendFormat("gl_TexCoord[1] = gl_TextureMatrix[1] * gl_MultiTexCoord{0};\n", Material.TextureCoordiators[1].SourceCoordinate);
if (Material.Tex2 != null) vert_ss.AppendFormat("gl_TexCoord[2] = gl_TextureMatrix[2] * gl_MultiTexCoord{0};\n", Material.TextureCoordiators[2].SourceCoordinate);
vert_ss.AppendLine("gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;");
}
vert_ss.AppendLine("}");
// create/compile vertex shader
vertex_shader = Gl.glCreateShader(Gl.GL_VERTEX_SHADER);
{
var vert_src_str = vert_ss.ToString();
//const GLchar* vert_src = vert_src_str.c_str();
Gl.glShaderSource(vertex_shader, 1, new string[] { vert_src_str }, new int[] { vert_src_str.Length });
}
//} // done generating vertex shader
Gl.glCompileShader(vertex_shader);
string[] constant =
{
"const0",
"const1",
"const2",
"const3",
"const4",
"const5",
"emission",
"ambient",
"diffuse",
"spec1",
"spec2"
};
/*
* Confirmed by intermediate file:
* 0x00 - PrimaryColor
* 0x01 - FragmentPrimaryColor
* 0x02 - FragmentSecondaryColor
* 0x03 - Texture0
*/
string[] p0 =
{
"gl_Color",
"vec4(0.5, 0.5, 0.5, 1.0)",
"vec4(0.5, 0.5, 0.5, 1.0)",
//"gl_Color",
//"gl_Color",
"texture2D(textures0, gl_TexCoord[0].st)",
"texture2D(textures1, gl_TexCoord[1].st)",
"texture2D(textures2, gl_TexCoord[2].st)",
"texture2D(textures3, gl_TexCoord[3].st)",
"const0",//?
"const1",//?
"const2",//?
"const3",//?
"const4",//?
"const5",//?
"bufin",
"{0}",
"previous"
};
string[] c_p1 =
{
"{0}.rgb",//0
"vec3(1.0) - {0}.rgb",//1
"{0}.aaa",//2
"vec3(1.0) - {0}.aaa",//3
"{0}.rrr",//4
"vec3(1.0) - {0}.rrr",//5
"{0}.rgb",//?
"{0}.rgb",//?
"{0}.ggg",//8
"vec3(1.0) - {0}.ggg",//9
"{0}.rgb",//?
"{0}.rgb",//?
"{0}.bbb",//c
"vec3(1.0) - {0}.bbb",//d
"{0}.rgb",//?
"{0}.rgb",//?
};
string[] a_p1 =
{
"{0}.a",
"1.0 - {0}.a",
"{0}.r",
"1.0 - {0}.r",
"{0}.g",
"1.0 - {0}.g",
"{0}.b",
"1.0 - {0}.b",
"{0}.a",//unknown 8
"{0}.a",//unknown 9
"{0}.a",//unknown A
"{0}.a",//unknown B
"{0}.a",//unknown C
"{0}.a",//unknown D
"{0}.a",//unknown E
"{0}.a"//unknown F
};
string[] c_p2 =
{
"j1.rgb",
"j1.rgb * j2.rgb",
"j1.rgb + j2.rgb",
"j1.rgb + j2.rgb - vec3(0.5)",
"j1.rgb * j3.rgb + j2.rgb * (vec3(1.0) - j3.rgb)",
"j1.rgb - j2.rgb",
"vec3(4 * ((j1.r - 0.5) * (j1.r - 0.5) + (j1.g - 0.5) * (j2.g - 0.5) + (j1.b - 0.5) * (j2.b - 0.5)))",
"vec4(4 * ((j1.r - 0.5) * (j1.r - 0.5) + (j1.g - 0.5) * (j2.g - 0.5) + (j1.b - 0.5) * (j2.b - 0.5)))",
"(j1.rgb * j2.rgb) + j3.rgb",//"j1.rgb * j2.aaa + j3.rgb" //"(vec3(1.0) - ((vec3(1.0) - j1.rgb) + (vec3(1.0) - j2.rgb))) + j3.rgb",//"j2.rgb * j1.rgb + j3.rgb * (vec3(1.0) - j1.rgb)",//"j1.rgb * j2.rgb + j3.rgb * (vec3(1.0) - j2.rgb)",//"j1.rgb * j2.rgb + j3.rgb * (vec3(1.0) - j2.rgb)"//"j2.rgb + j1.rgb - (vec3(1.0) - j3.rgb)",//Unknown 8
"clamp(j1.rgb + j2.rgb, 0.0, 1.0) * j3.rgb"//"j2.rgb + (j1.rgb * j3.rgb)"//"j3.rgb * j1.rgb + j2.rgb - vec3(0.1)"//"j2.rgb * j3.rgb + j1.rgb - vec3(0.5)"//"j1.rgb * j2.rgb + j3.rgb * (vec3(1.0) - j2.rgb)"//"j1.rgb + j3.rgb * j2.rgb"//"j3.rgb"//Unknown 9
};
string[] a_p2 =
{
"j1.a",
"j1.a * j2.a",
"j1.a + j2.a",
"j1.a + j2.a - 0.5",
"j1.a * j3.a + j2.a * (1.0 - j3.a)",
"j1.a - j2.a",
"j1.a",//unknown
"j1.a",//unknown
"(j1.a * j2.a) + j3.a",//"j2.a * j1.a + j3.a * (1.0 - j1.a)",//Unknown 8
"clamp(j1.a + j2.a, 0.0, 1.0) * j3.a"//"(1.0 - j2.a) + (j1.a * j3.a)"//"j2.a - (j1.a + j3.a)"//"j3.a * j1.a + j2.a - 0.1"//"j1.a * j2.a + j3.a * (1.0 - j2.a)"//Unknown 9
};
string[] scale =
{
//"1.0",
//"1.0",
//"1.0"
"1.0",
"2.0",
"4.0"
};
// generate fragment shader code
//{
StringBuilder frag_ss = new StringBuilder();
//frag_ss += "uniform sampler2D tex;";
// uniforms
for (uint i = 0; i != sampler_count; ++i)
frag_ss.AppendFormat("uniform sampler2D textures{0};\n", i);
frag_ss.AppendFormat("vec4 const0 = {0};\n", GetVec4(Material.MaterialColor.Constant0U32));
frag_ss.AppendFormat("vec4 const1 = {0};\n", GetVec4(Material.MaterialColor.Constant1U32));
frag_ss.AppendFormat("vec4 const2 = {0};\n", GetVec4(Material.MaterialColor.Constant2U32));
frag_ss.AppendFormat("vec4 const3 = {0};\n", GetVec4(Material.MaterialColor.Constant3U32));
frag_ss.AppendFormat("vec4 const4 = {0};\n", GetVec4(Material.MaterialColor.Constant4U32));
frag_ss.AppendFormat("vec4 const5 = {0};\n", GetVec4(Material.MaterialColor.Constant5U32));
frag_ss.AppendFormat("vec4 diffuse = {0};\n", GetVec4(Material.MaterialColor.DiffuseU32));
frag_ss.AppendFormat("vec4 ambient = {0};\n", GetVec4(Material.MaterialColor.Ambient));
frag_ss.AppendFormat("vec4 spec1 = {0};\n", GetVec4(Material.MaterialColor.Specular0U32));
frag_ss.AppendFormat("vec4 spec2 = {0};\n", GetVec4(Material.MaterialColor.Specular1U32));
frag_ss.AppendFormat("vec4 emission = {0};\n", GetVec4(Material.MaterialColor.EmissionU32));
frag_ss.AppendFormat("vec4 unk1 = vec4(1.0);\n");
frag_ss.AppendFormat("vec4 unk2 = vec4(0.0);\n");
frag_ss.AppendFormat("vec4 unk3 = {0};\n", GetVec4(Material.FragShader.BufferColor));
if (Material.MaterialColor.Constant0U32 ==Color.FromArgb(0, 0, 0, 0) && Material.MaterialColor.Constant1U32 ==Color.FromArgb(0, 0, 0, 0) && Material.MaterialColor.Constant2U32 ==Color.FromArgb(0, 0, 0, 0) && Material.MaterialColor.Constant3U32 ==Color.FromArgb(0, 0, 0, 0) && Material.MaterialColor.Constant4U32 ==Color.FromArgb(0, 0, 0, 0) && Material.MaterialColor.Constant5U32 == Color.FromArgb(0, 0, 0, 0))
{
frag_ss.AppendLine("const0 = const1 = const2 = const3 = const4 = const5 = vec4(0, 0, 0, 1);");
}
frag_ss.AppendFormat("vec4 buf0 = unk3;\n");
frag_ss.AppendFormat("vec4 buf1;\n");
frag_ss.AppendFormat("vec4 buf2;\n");
frag_ss.AppendFormat("vec4 buf3;\n");
frag_ss.AppendFormat("vec4 buf4;\n");
//frag_ss.AppendFormat("vec4 unk3 = gl_Color;\n");
//frag_ss.AppendFormat("vec4 unk3 = vec4(1.0);\n");
frag_ss.AppendLine("void main()");
frag_ss.AppendLine("{");
{
frag_ss.AppendLine("vec4 previous = vec4(1.0);");
frag_ss.AppendLine("vec4 i1c;");
frag_ss.AppendLine("vec4 i2c;");
frag_ss.AppendLine("vec4 i3c;");
frag_ss.AppendLine("vec4 i1a;");
frag_ss.AppendLine("vec4 i2a;");
frag_ss.AppendLine("vec4 i3a;");
frag_ss.AppendLine("vec4 j1;");
frag_ss.AppendLine("vec4 j2;");
frag_ss.AppendLine("vec4 j3;");
frag_ss.AppendLine("vec4 ConstRgba;");
frag_ss.AppendLine("vec4 bufin;");
for (int i = 0; i < 6; i++)
{
if (i > 0 && i < 5)
{
if (((Material.FragShader.BufferCommand3 >> (i + 7)) & 1) == 1)
frag_ss.AppendFormat("buf{0}.rgb = previous.rgb;\n", i);
else frag_ss.AppendFormat("buf{0}.rgb = buf{1}.rgb;\n", i, i - 1);
if (((Material.FragShader.BufferCommand3 >> (i + 11)) & 1) == 1)
frag_ss.AppendFormat("buf{0}.a = previous.a;\n", i);
else frag_ss.AppendFormat("buf{0}.a = buf{1}.a;\n", i, i - 1);
}
frag_ss.AppendFormat("ConstRgba = {0};\n", GetVec4(Material.FragShader.TextureCombiners[i].ConstRgba));
int c_input1 = (Material.FragShader.TextureCombiners[i].SrcRgb >> 0) & 0xF;
int c_input2 = (Material.FragShader.TextureCombiners[i].SrcRgb >> 4) & 0xF;
int c_input3 = (Material.FragShader.TextureCombiners[i].SrcRgb >> 8) & 0xF;
int a_input1 = (Material.FragShader.TextureCombiners[i].SrcAlpha >> 0) & 0xF;
int a_input2 = (Material.FragShader.TextureCombiners[i].SrcAlpha >> 4) & 0xF;
int a_input3 = (Material.FragShader.TextureCombiners[i].SrcAlpha >> 8) & 0xF;
//String cons;
///*if (Material.Shader.TexEnvSlotInfos[i].ConstRgba.ToArgb() == Color.Black.ToArgb())*/ cons = "const" + (Material.Shader.TexEnvSlotInfos[i].Unknown3 & 0xF);
//else cons = "ConstRgba";
if (i > 0) frag_ss.AppendFormat("bufin = buf{0};\n", i - 1);
frag_ss.AppendFormat("i1c = {0};\n", String.Format(p0[c_input1], constant[Material.FragShader.TextureCombiners[i].Constant]));
frag_ss.AppendFormat("i2c = {0};\n", String.Format(p0[c_input2], constant[Material.FragShader.TextureCombiners[i].Constant]));
frag_ss.AppendFormat("i3c = {0};\n", String.Format(p0[c_input3], constant[Material.FragShader.TextureCombiners[i].Constant]));
frag_ss.AppendFormat("i1a = {0};\n", String.Format(p0[a_input1], constant[Material.FragShader.TextureCombiners[i].Constant]));
frag_ss.AppendFormat("i2a = {0};\n", String.Format(p0[a_input2], constant[Material.FragShader.TextureCombiners[i].Constant]));
frag_ss.AppendFormat("i3a = {0};\n", String.Format(p0[a_input3], constant[Material.FragShader.TextureCombiners[i].Constant]));
//frag_ss.AppendFormat("i1 = vec4({0}.rgb, {1}.a);\n", String.Format(p0[c_input1], Material.FragShader.TextureCombiners[i].Unknown3 & 0xF), String.Format(p0[a_input1], Material.FragShader.TextureCombiners[i].Unknown3 & 0xF));
//frag_ss.AppendFormat("i2 = vec4({0}.rgb, {1}.a);\n", String.Format(p0[c_input2], Material.FragShader.TextureCombiners[i].Unknown3 & 0xF), String.Format(p0[a_input2], Material.FragShader.TextureCombiners[i].Unknown3 & 0xF));
//frag_ss.AppendFormat("i3 = vec4({0}.rgb, {1}.a);\n", String.Format(p0[c_input3], Material.FragShader.TextureCombiners[i].Unknown3 & 0xF), String.Format(p0[a_input3], Material.FragShader.TextureCombiners[i].Unknown3 & 0xF));
uint c_p1_1 = (Material.FragShader.TextureCombiners[i].Operands >> 0) & 0xF;
uint c_p1_2 = (Material.FragShader.TextureCombiners[i].Operands >> 4) & 0xF;
uint c_p1_3 = (Material.FragShader.TextureCombiners[i].Operands >> 8) & 0xF;
uint a_p1_1 = (Material.FragShader.TextureCombiners[i].Operands >> 12) & 0xF;
uint a_p1_2 = (Material.FragShader.TextureCombiners[i].Operands >> 16) & 0xF;
uint a_p1_3 = (Material.FragShader.TextureCombiners[i].Operands >> 20) & 0xF;
frag_ss.AppendFormat("j1 = vec4({0}, {1});\n", String.Format(c_p1[c_p1_1], "i1c"), String.Format(a_p1[a_p1_1], "i1a"));
frag_ss.AppendFormat("j2 = vec4({0}, {1});\n", String.Format(c_p1[c_p1_2], "i2c"), String.Format(a_p1[a_p1_2], "i2a"));
frag_ss.AppendFormat("j3 = vec4({0}, {1});\n", String.Format(c_p1[c_p1_3], "i3c"), String.Format(a_p1[a_p1_3], "i3a"));
if (Material.FragShader.TextureCombiners[i].CombineRgb == 7) frag_ss.AppendFormat("previous = {0};\n", c_p2[Material.FragShader.TextureCombiners[i].CombineRgb]);
else frag_ss.AppendFormat("previous = clamp(vec4(({0}) * vec3({2}, {2}, {2}), ({1}) * {3}), 0.0, 1.0);\n", c_p2[Material.FragShader.TextureCombiners[i].CombineRgb], a_p2[Material.FragShader.TextureCombiners[i].CombineAlpha], scale[Material.FragShader.TextureCombiners[i].ScaleRgb], scale[Material.FragShader.TextureCombiners[i].ScaleAlpha]);
//else frag_ss.AppendFormat("previous = clamp(vec4(({0}) * vec3({2}), ({1}) * {3}), 0.0, 1.0);\n", c_p2[Material.Shader.TexEnvSlotInfos[i].CombineRgb], a_p2[Material.Shader.TexEnvSlotInfos[i].CombineAlpha], Material.Shader.TexEnvSlotInfos[i].Unknown2Rgb + 1, Material.Shader.TexEnvSlotInfos[i].Unknown2Alpha + 1);
}
frag_ss.AppendLine("gl_FragColor = previous;");
//frag_ss.AppendLine("gl_FragColor = texture2D(textures0, gl_TexCoord[0].st) * vec4(gl_Color.rgb, 1.0);");
}
frag_ss.AppendLine("}");
//std::cout << frag_ss.str() << '\n';
// create/compile fragment shader
fragment_shader = Gl.glCreateShader(Gl.GL_FRAGMENT_SHADER);
{
var frag_src_str = frag_ss.ToString();
Gl.glShaderSource(fragment_shader, 1, new String[] { frag_src_str }, new int[] { frag_src_str.Length });
}
//} // done generating fragment shader
Gl.glCompileShader(fragment_shader);
// check compile status of both shaders
//{
int vert_compiled = 0;
int frag_compiled = 0;
Gl.glGetShaderiv(vertex_shader, Gl.GL_COMPILE_STATUS, out vert_compiled);
Gl.glGetShaderiv(fragment_shader, Gl.GL_COMPILE_STATUS, out frag_compiled);
if (vert_compiled == 0)
{
//std::cout << "Failed to compile vertex shader\n";
}
if (frag_compiled == 0)
{
//std::cout << "Failed to compile fragment shader\n";
}
// create program, attach shaders
program = Gl.glCreateProgram();
Gl.glAttachShader(program, vertex_shader);
Gl.glAttachShader(program, fragment_shader);
// link program, check link status
Gl.glLinkProgram(program);
int link_status;
Gl.glGetProgramiv(program, Gl.GL_LINK_STATUS, out link_status);
if (link_status == 0)
{
//std::cout << "Failed to link program!\n";
}
Gl.glUseProgram(program);
// set uniforms
for (uint i = 0; i != sampler_count; ++i)
{
String ss = "textures" + i;
Gl.glUniform1i(Gl.glGetUniformLocation(program, ss), (int)i);
}
}
private String GetVec4(Color c)
{
return String.Format("vec4({0}, {1}, {2}, {3})", (c.R / 255f).ToString().Replace(",", "."), (c.G / 255f).ToString().Replace(",", "."), (c.B / 255f).ToString().Replace(",", "."), (c.A / 255f).ToString().Replace(",", "."));
}
private String GetVec4(Vector4 c)
{
return String.Format("vec4({0}, {1}, {2}, {3})", (c.X).ToString().Replace(",", "."), (c.Y).ToString().Replace(",", "."), (c.Z).ToString().Replace(",", "."), (c.W).ToString().Replace(",", "."));
}
public int program = 0, fragment_shader = 0, vertex_shader = 0;
}
}

View File

@ -0,0 +1,116 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.IO;
using System.Drawing;
using LibEveryFileExplorer.IO;
using LibEveryFileExplorer.Collections;
namespace _3DS.NintendoWare.GFX
{
public class CGFXWriterContext
{
private Dictionary<long, byte[]> IMAGBlockEntries = new Dictionary<long, byte[]>();
private Dictionary<long, string> StringTableEntries = new Dictionary<long, string>();
public void WriteDataReference(byte[] Data, EndianBinaryWriter er)
{
IMAGBlockEntries.Add(er.BaseStream.Position, Data);
er.Write((uint)0);
}
public void WriteStringReference(String s, EndianBinaryWriter er)
{
StringTableEntries.Add(er.BaseStream.Position, s);
er.Write((uint)0);
}
public void WriteStringTable(EndianBinaryWriter er)
{
Dictionary<String, long> strings = new Dictionary<string,long>();
foreach (var v in StringTableEntries)
{
if (strings.ContainsKey(v.Value))
{
long curpos = er.BaseStream.Position;
er.BaseStream.Position = v.Key;
er.Write((uint)(strings[v.Value] - v.Key));
er.BaseStream.Position = curpos;
}
else
{
long curpos = er.BaseStream.Position;
er.BaseStream.Position = v.Key;
er.Write((uint)(curpos - v.Key));
er.BaseStream.Position = curpos;
strings.Add(v.Value, curpos);
er.Write(v.Value, Encoding.ASCII, true);
}
}
}
public bool DoWriteIMAGBlock()
{
return IMAGBlockEntries.Count > 0;
}
public int GetIMAGBlockSize()
{
int size = 0;//8;
foreach (var v in IMAGBlockEntries)
{
size += v.Value.Length;
while ((size % 128) != 0) size++;
}
while ((size % 8) != 0) size++;
return size + 8;
}
public void WriteIMAGBlock(EndianBinaryWriter er)
{
//long basepos = er.BaseStream.Position;
er.Write("IMAG", Encoding.ASCII, false);
er.Write((uint)GetIMAGBlockSize());
foreach (var v in IMAGBlockEntries)
{
long curpos = er.BaseStream.Position;
er.BaseStream.Position = v.Key;
er.Write((uint)(curpos - v.Key));
er.BaseStream.Position = curpos;
er.Write(v.Value, 0, v.Value.Length);
while ((er.BaseStream.Position % 128) != 0) er.Write((byte)0);
}
while ((er.BaseStream.Position % 64) != 0) er.Write((byte)0);
}
public static uint CalcHash(byte[] Data)
{
uint num = 0;
byte[] buffer = new MD5CryptoServiceProvider().ComputeHash(Data);
for (int i = 0; i < buffer.Length; i++)
{
num ^= (uint)(buffer[i] << ((i % 4) * 8));
}
if (num == 0) return 1;
return num;
}
public static void WriteFloatColorRGB(byte[] Data, int Offset, Vector4 Value)
{
IOUtil.WriteSingleLE(Data, Offset, Value.X);
IOUtil.WriteSingleLE(Data, Offset + 4, Value.Y);
IOUtil.WriteSingleLE(Data, Offset + 8, Value.Z);
}
public static void WriteFloatColorRGBA(byte[] Data, int Offset, Vector4 Value)
{
IOUtil.WriteSingleLE(Data, Offset, Value.X);
IOUtil.WriteSingleLE(Data, Offset + 4, Value.Y);
IOUtil.WriteSingleLE(Data, Offset + 8, Value.Z);
IOUtil.WriteSingleLE(Data, Offset + 12, Value.W);
}
}
}

3330
3DS/NintendoWare/GFX/CMDL.cs Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,170 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using LibEveryFileExplorer.Files;
namespace _3DS.NintendoWare.GFX
{
public class DICT
{
public DICT(EndianBinaryReader er)
{
Signature = er.ReadString(Encoding.ASCII, 4);
if (Signature != "DICT") throw new SignatureNotCorrectException(Signature, "DICT", er.BaseStream.Position);
SectionSize = er.ReadUInt32();
NrEntries = er.ReadUInt32();
RootNode = new Node(er);
Entries = new List<Node>();// new Node[NrEntries];
for (int i = 0; i < NrEntries; i++)
{
Entries.Add(new Node(er));
}
}
public void Write(EndianBinaryWriter er, CGFXWriterContext c)
{
long basepos = er.BaseStream.Position;
er.Write(Signature, Encoding.ASCII, false);
er.Write((uint)0);
er.Write((uint)Entries.Count);
RootNode.Write(er, c);
foreach (var v in Entries) v.Write(er, c);
long curpos = er.BaseStream.Position;
er.BaseStream.Position = basepos + 4;
er.Write((uint)(curpos - basepos));
er.BaseStream.Position = curpos;
}
private String Signature;
private UInt32 SectionSize;
private UInt32 NrEntries;
private Node RootNode;
private List<Node> Entries;
public class Node
{
public Node() { }
public Node(EndianBinaryReader er)
{
RefBit = er.ReadUInt32();
LeftIndex = er.ReadUInt16();
RightIndex = er.ReadUInt16();
NameOffset = er.ReadUInt32();
if (NameOffset != 0) NameOffset += (UInt32)er.BaseStream.Position - 4;
DataOffset = er.ReadUInt32();
if (DataOffset != 0) DataOffset += (UInt32)er.BaseStream.Position - 4;
if (NameOffset != 0)
{
long curpos = er.BaseStream.Position;
er.BaseStream.Position = NameOffset;
Name = er.ReadStringNT(Encoding.ASCII);
er.BaseStream.Position = curpos;
}
}
public void Write(EndianBinaryWriter er, CGFXWriterContext c)
{
er.Write(RefBit);
er.Write(LeftIndex);
er.Write(RightIndex);
if (Name != null) c.WriteStringReference(Name, er);
else er.Write((uint)0);
er.Write((uint)0);
}
public UInt32 RefBit;
public UInt16 LeftIndex;
public UInt16 RightIndex;
public UInt32 NameOffset;
public UInt32 DataOffset;
public String Name;
public override string ToString()
{
return Name;
}
}
public int Count { get { return Entries.Count; } }
public int IndexOf(uint Offset)
{
for (int i = 0; i < NrEntries; i++)
{
if (Entries[i].DataOffset == Offset) return i;
}
return -1;
}
public int IndexOf(String Name)
{
for (int i = 0; i < NrEntries; i++)
{
if (Entries[i].Name == Name) return i;
}
return -1;
}
public Node this[int index]
{
get { return Entries[index]; }
set { Entries[index] = value; RegenerateTree(); }
}
public Node this[String index]
{
get { return Entries[IndexOf(index)]; }
set { Entries[IndexOf(index)] = value; RegenerateTree(); }
}
public void Add(String Name)
{
Entries.Add(new Node() { Name = Name });
NrEntries = (uint)Entries.Count;
RegenerateTree();
}
public void Remove(Node Entry)
{
Entries.Remove(Entry);
NrEntries = (uint)Entries.Count;
RegenerateTree();
}
public void RemoveAt(int Index)
{
Entries.RemoveAt(Index);
RegenerateTree();
}
private void RegenerateTree()
{
List<String> names = new List<string>();
foreach (Node n in Entries)
{
names.Add(n.Name);
}
PatriciaTreeGenerator p = PatriciaTreeGenerator.Generate(names.ToArray());
bool first = true;
foreach (var v in p.TreeNodes)
{
if (first)
{
v.idxEntry = -1;
RootNode.LeftIndex = (ushort)(v.left.idxEntry + 1);
RootNode.RightIndex = (ushort)(v.right.idxEntry + 1);
RootNode.RefBit = 0xFFFFFFFF;
first = false;
continue;
}
Entries[v.idxEntry].LeftIndex = (ushort)(v.left.idxEntry + 1);
Entries[v.idxEntry].RightIndex = (ushort)(v.right.idxEntry + 1);
Entries[v.idxEntry].RefBit = (uint)v.refbit;
}
}
}
}

View File

@ -0,0 +1,125 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _3DS.NintendoWare.GFX
{
internal class PatriciaTreeGenerator
{
List<PatTreeNode> Nodes = new List<PatTreeNode>();
public PatTreeNode[] TreeNodes { get { return Nodes.ToArray(); } }
private int StringLength;
public PatriciaTreeGenerator(int StringLength)
{
this.StringLength = StringLength;
AddRootPatTreeNode();
}
private PatTreeNode AddRootPatTreeNode()
{
PatTreeNode p = new PatTreeNode();
p.refbit = (uint)(StringLength * 8) - 1;
p.left = p;
p.right = p;
p.idxEntry = 0;
p.name = new String('\0', StringLength);
Nodes.Add(p);
return p;
}
public PatTreeNode AddPatTreeNode(String Name, int Index)
{
Name = Name.PadRight(StringLength, '\0');
PatTreeNode n = new PatTreeNode();
n.name = Name;
PatTreeNode CurNode = Nodes[0];
PatTreeNode leftNode = CurNode.left;
uint bit = (uint)(StringLength * 8) - 1;
while (CurNode.refbit > leftNode.refbit)
{
CurNode = leftNode;
leftNode = GetBit(Name, leftNode.refbit) ? leftNode.right : leftNode.left;
}
while (GetBit(leftNode.name, bit) == GetBit(Name, bit)) bit--;
CurNode = Nodes[0];
leftNode = CurNode.left;
while ((CurNode.refbit > leftNode.refbit) && (leftNode.refbit > bit))
{
CurNode = leftNode;
leftNode = GetBit(Name, leftNode.refbit) ? leftNode.right : leftNode.left;
}
n.refbit = bit;
n.left = GetBit(Name, n.refbit) ? leftNode : n;
n.right = GetBit(Name, n.refbit) ? n : leftNode;
if (GetBit(Name, CurNode.refbit)) CurNode.right = n;
else CurNode.left = n;
n.idxEntry = Index;
Nodes.Add(n);
return n;
}
private static bool GetBit(string name, uint bit)
{
if (name == null || bit / 8 >= name.Length) throw new ArgumentException();
return (((int)name[(int)bit / 8] >> ((int)bit & 7)) & 1) == 1;
}
public void Sort()
{
SortedDictionary<String, PatTreeNode> alphabet = new SortedDictionary<string, PatTreeNode>();
foreach (PatTreeNode p in Nodes)
{
if (p.name.TrimEnd('\0') == "") continue;
alphabet.Add(p.name.TrimEnd('\0'), p);
}
List<PatTreeNode> AlphabetSortedNodes = new List<PatTreeNode>();
foreach (PatTreeNode p in alphabet.Values)
{
AlphabetSortedNodes.Add(p);
}
List<PatTreeNode> LengthSorted = new List<PatTreeNode>();
for (int j = 0; j < Nodes.Count - 1; j++)
{
int longest = -1;
int longestlength = -1;
for (int i = 0; i < AlphabetSortedNodes.Count; i++)
{
if (AlphabetSortedNodes[i].name.TrimEnd('\0').Length > longestlength)
{
longest = i;
longestlength = AlphabetSortedNodes[i].name.TrimEnd('\0').Length;
}
}
LengthSorted.Add(AlphabetSortedNodes[longest]);
AlphabetSortedNodes.RemoveAt(longest);
}
LengthSorted.Insert(0, Nodes[0]);
Nodes = LengthSorted;
}
public static PatriciaTreeGenerator Generate(string[] Names)
{
int length = 0;
foreach (String n in Names) if (n.Length > length) length = n.Length;
PatriciaTreeGenerator p = new PatriciaTreeGenerator(length);
for (int i = 0; i < Names.Length; i++)
{
p.AddPatTreeNode(Names[i], i);
}
p.Sort();
return p;
}
public class PatTreeNode
{
public UInt32 refbit;
public PatTreeNode left;
public PatTreeNode right;
public Int32 idxEntry;
public String name;
public override string ToString()
{
return name;
}
}
}
}

View File

@ -0,0 +1,305 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.IO;
using LibEveryFileExplorer.Files;
using _3DS.GPU;
namespace _3DS.NintendoWare.GFX
{
/*public class TXOB
{
public TXOB() { }
public TXOB(EndianBinaryReader er)
{
Flags = er.ReadUInt32();
Signature = er.ReadString(Encoding.ASCII, 4);
if (Signature != "TXOB") throw new SignatureNotCorrectException(Signature, "TXOB", er.BaseStream.Position);
Unknown1 = er.ReadUInt32();
NameOffset = (UInt32)er.BaseStream.Position + er.ReadUInt32();
Unknown2 = er.ReadUInt32();
Unknown3 = er.ReadUInt32();
Height = er.ReadUInt32();
Width = er.ReadUInt32();
GlFormat = er.ReadUInt32();
Type = er.ReadUInt32();
NrLevels = er.ReadUInt32();
Unknown7 = er.ReadUInt32();
Unknown8 = er.ReadUInt32();
Format = (GPU.Textures.ImageFormat)er.ReadUInt32();
Unknown9 = er.ReadUInt32();
Height2 = er.ReadUInt32();
Width2 = er.ReadUInt32();
DataSize = er.ReadUInt32();
DataOffset = (UInt32)er.BaseStream.Position + er.ReadUInt32();
Unknown10 = er.ReadUInt32();
BitsPerPixel = er.ReadUInt32();
Unknown12 = er.ReadUInt32();
long curpos = er.BaseStream.Position;
er.BaseStream.Position = NameOffset;
Name = er.ReadStringNT(Encoding.ASCII);
er.BaseStream.Position = DataOffset;
Data = er.ReadBytes((int)DataSize);
er.BaseStream.Position = curpos;
}
public UInt32 Flags;//?
public String Signature;
public UInt32 Unknown1;
public UInt32 NameOffset;
public UInt32 Unknown2;
public UInt32 Unknown3;
public UInt32 Height;
public UInt32 Width;
public UInt32 GlFormat;
public UInt32 Type;
public UInt32 NrLevels;
public UInt32 Unknown7;
public UInt32 Unknown8;
public GPU.Textures.ImageFormat Format;
public UInt32 Unknown9;
public UInt32 Height2;
public UInt32 Width2;
public UInt32 DataSize;
public UInt32 DataOffset;
public UInt32 Unknown10;
public UInt32 BitsPerPixel;
public UInt32 Unknown12;
public String Name;
public byte[] Data;
//The flags are like this:
//Image Texture = 0x20000011 (this structure)
//Cube Texture = 0x20000009
//Reference Texture = 0x20000004
//Procedural Texture = 0x20000002
//Shadow Texture = 0x20000021
public Bitmap GetBitmap(int Level = 0)
{
int l = Level;
uint w = Width;
uint h = Height;
int bpp = GPU.Textures.GetBpp(Format);
int offset = 0;
while (l > 0)
{
offset += (int)(w * h * bpp / 8);
w /= 2;
h /= 2;
l--;
}
return GPU.Textures.ToBitmap(Data, offset, (int)w, (int)h, Format);
}
public override string ToString()
{
return Name;
}
}*/
public class TXOB
{
public TXOB(EndianBinaryReader er)
{
Type = er.ReadUInt32();
Signature = er.ReadString(Encoding.ASCII, 4);
if (Signature != "TXOB") throw new SignatureNotCorrectException(Signature, "TXOB", er.BaseStream.Position);
Revision = er.ReadUInt32();
NameOffset = (UInt32)er.BaseStream.Position + er.ReadUInt32();
Unknown2 = er.ReadUInt32();
Unknown3 = er.ReadUInt32();
long curpos = er.BaseStream.Position;
er.BaseStream.Position = NameOffset;
Name = er.ReadStringNT(Encoding.ASCII);
er.BaseStream.Position = curpos;
}
public virtual void Write(EndianBinaryWriter er, CGFXWriterContext c)
{
er.Write(Type);
er.Write(Signature, Encoding.ASCII, false);
er.Write(Revision);
c.WriteStringReference(Name, er);
er.Write(Unknown2);
er.Write(Unknown3);
}
public UInt32 Type;
public String Signature;
public UInt32 Revision;
public UInt32 NameOffset;
public UInt32 Unknown2;
public UInt32 Unknown3;
public String Name;
public static TXOB FromStream(EndianBinaryReader er)
{
uint type = er.ReadUInt32();
er.BaseStream.Position -= 4;
//Image Texture = 0x20000011
//Cube Texture = 0x20000009
//Reference Texture = 0x20000004
//Procedural Texture = 0x20000002
//Shadow Texture = 0x20000021
switch (type)
{
case 0x20000004://reference texture
return new ReferenceTexture(er);
case 0x20000011:
return new ImageTextureCtr(er);
}
return new TXOB(er);
}
public override string ToString()
{
return Name;
}
}
public class ReferenceTexture : TXOB
{
public ReferenceTexture(EndianBinaryReader er)
: base(er)
{
LinkedTextureNameOffset = (UInt32)er.BaseStream.Position + er.ReadUInt32();
LinkedTextureOffset = er.ReadUInt32();
if (LinkedTextureOffset != 0) LinkedTextureOffset += (UInt32)er.BaseStream.Position - 4;
long curpos = er.BaseStream.Position;
er.BaseStream.Position = LinkedTextureNameOffset;
LinkedTextureName = er.ReadStringNT(Encoding.ASCII);
er.BaseStream.Position = curpos;
}
public override void Write(EndianBinaryWriter er, CGFXWriterContext c)
{
base.Write(er, c);
c.WriteStringReference(LinkedTextureName, er);
if (LinkedTextureOffset == 0) er.Write((uint)0);
else er.Write((uint)0);//TODO!
}
public UInt32 LinkedTextureNameOffset;
public UInt32 LinkedTextureOffset;
public String LinkedTextureName;
}
public class PixelBasedTexture : TXOB
{
public PixelBasedTexture(EndianBinaryReader er)
: base(er)
{
Height = er.ReadUInt32();
Width = er.ReadUInt32();
GLFormat = er.ReadUInt32();
Type = er.ReadUInt32();
NrLevels = er.ReadUInt32();
TextureObject = er.ReadUInt32();
LocationFlag = er.ReadUInt32();
HWFormat = (Textures.ImageFormat)er.ReadUInt32();
}
public override void Write(EndianBinaryWriter er, CGFXWriterContext c)
{
base.Write(er, c);
er.Write(Height);
er.Write(Width);
er.Write(GLFormat);
er.Write(Type);
er.Write(NrLevels);
er.Write(TextureObject);
er.Write(LocationFlag);
er.Write((uint)HWFormat);
}
public UInt32 Height;
public UInt32 Width;
public UInt32 GLFormat;
public UInt32 Type;
public UInt32 NrLevels;//mipmaps
public UInt32 TextureObject;
public UInt32 LocationFlag;
public Textures.ImageFormat HWFormat;
}
public class ImageTextureCtr : PixelBasedTexture
{
public ImageTextureCtr(EndianBinaryReader er)
: base(er)
{
TextureImageOffset = (UInt32)er.BaseStream.Position + er.ReadUInt32();
long curpos = er.BaseStream.Position;
er.BaseStream.Position = TextureImageOffset;
TextureImage = new PixelBasedImageCtr(er);
er.BaseStream.Position = curpos;
}
public override void Write(EndianBinaryWriter er, CGFXWriterContext c)
{
base.Write(er, c);
if (TextureImage != null) er.Write((uint)4);
else er.Write((uint)0);
if (TextureImage != null) TextureImage.Write(er, c);
}
public UInt32 TextureImageOffset;
public PixelBasedImageCtr TextureImage;
public class PixelBasedImageCtr
{
public PixelBasedImageCtr(EndianBinaryReader er)
{
Height = er.ReadUInt32();
Width = er.ReadUInt32();
DataSize = er.ReadUInt32();
DataOffset = (UInt32)er.BaseStream.Position + er.ReadUInt32();
DynamicAllocator = er.ReadUInt32();
BitsPerPixel = er.ReadUInt32();
LocationAddress = er.ReadUInt32();
MemoryAddress = er.ReadUInt32();
long curpos = er.BaseStream.Position;
er.BaseStream.Position = DataOffset;
Data = er.ReadBytes((int)DataSize);
er.BaseStream.Position = curpos;
}
public void Write(EndianBinaryWriter er, CGFXWriterContext c)
{
er.Write(Height);
er.Write(Width);
er.Write(DataSize);
c.WriteDataReference(Data, er);
er.Write(DynamicAllocator);
er.Write(BitsPerPixel);
er.Write(LocationAddress);
er.Write(MemoryAddress);
}
public UInt32 Height;
public UInt32 Width;
public UInt32 DataSize;
public UInt32 DataOffset;
public UInt32 DynamicAllocator;
public UInt32 BitsPerPixel;
public UInt32 LocationAddress;
public UInt32 MemoryAddress;
public byte[] Data;
}
public Bitmap GetBitmap(int Level = 0)
{
int l = Level;
uint w = Width;
uint h = Height;
int bpp = GPU.Textures.GetBpp(HWFormat);
int offset = 0;
while (l > 0)
{
offset += (int)(w * h * bpp / 8);
w /= 2;
h /= 2;
l--;
}
return GPU.Textures.ToBitmap(TextureImage.Data, offset, (int)w, (int)h, HWFormat);
}
}
}

View File

@ -0,0 +1,138 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tao.OpenGl;
namespace NintendoWare.LYT
{
public class BasicShader
{
public void Enable()
{
Gl.glUseProgram(program);
}
public void Compile(bool texture)
{
// w.e good for now
//uint sampler_count = 1;
//if (sampler_count == 0)
//{
// sampler_count = 1;
//}
// generate vertex/fragment shader code
//{
StringBuilder vert_ss = new StringBuilder();
//String vert_ss = "";
vert_ss.AppendLine("void main()");
vert_ss.AppendLine("{");
{
vert_ss.AppendLine("gl_FrontColor = gl_Color;");
vert_ss.AppendLine("gl_BackColor = gl_Color;");
//if (texture)
//{
//vert_ss.AppendLine("gl_TexCoord[0] = gl_TextureMatrix[0];");
//}
vert_ss.AppendLine("gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;");
}
vert_ss.AppendLine("}");
// create/compile vertex shader
vertex_shader = Gl.glCreateShader(Gl.GL_VERTEX_SHADER);
{
var vert_src_str = vert_ss.ToString();
//const GLchar* vert_src = vert_src_str.c_str();
Gl.glShaderSource(vertex_shader, 1, new string[] { vert_src_str }, new int[] { vert_src_str.Length });
}
//} // done generating vertex shader
Gl.glCompileShader(vertex_shader);
// generate fragment shader code
//{
StringBuilder frag_ss = new StringBuilder();
//frag_ss += "uniform sampler2D tex;";
// uniforms
frag_ss.AppendLine("void main()");
frag_ss.AppendLine("{");
{
if (!texture)
{
frag_ss.AppendLine("gl_FragColor = gl_Color;");
}
else
{
//frag_ss.AppendLine("gl_Color = vec4(1,1,1,1);");
//frag_ss.AppendLine("gl_FragColor = texture2D(0, gl_TexCoord[0].st);");
}
}
frag_ss.AppendLine("}");
//std::cout << frag_ss.str() << '\n';
// create/compile fragment shader
fragment_shader = Gl.glCreateShader(Gl.GL_FRAGMENT_SHADER);
{
var frag_src_str = frag_ss.ToString();
Gl.glShaderSource(fragment_shader, 1, new String[] { frag_src_str }, new int[] { frag_src_str.Length });
}
//} // done generating fragment shader
Gl.glCompileShader(fragment_shader);
// check compile status of both shaders
//{
int vert_compiled = 0;
int frag_compiled = 0;
Gl.glGetShaderiv(vertex_shader, Gl.GL_COMPILE_STATUS, out vert_compiled);
Gl.glGetShaderiv(fragment_shader, Gl.GL_COMPILE_STATUS, out frag_compiled);
if (vert_compiled == 0)
{
//std::cout << "Failed to compile vertex shader\n";
}
if (frag_compiled == 0)
{
//std::cout << "Failed to compile fragment shader\n";
}
// create program, attach shaders
program = Gl.glCreateProgram();
Gl.glAttachShader(program, vertex_shader);
Gl.glAttachShader(program, fragment_shader);
// link program, check link status
Gl.glLinkProgram(program);
int link_status;
Gl.glGetProgramiv(program, Gl.GL_LINK_STATUS, out link_status);
if (link_status == 0)
{
//std::cout << "Failed to link program!\n";
}
Gl.glUseProgram(program);
// print log
//{
StringBuilder infolog = new StringBuilder();
Gl.glGetProgramInfoLog(program, 10240, null, infolog);
//std::cout << infolog;
//}
// pause
//std::cin.get();
//}
}
public int program = 0, fragment_shader = 0, vertex_shader = 0;
}
}

View File

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LibEveryFileExplorer.Files;
using System.Drawing;
namespace _3DS.NintendoWare.LYT
{
public class CLAN : FileFormat<CLAN.CLANIdentifier>
{
public class CLANIdentifier : FileFormatIdentifier
{
public override string GetCategory()
{
return Category_Animations;
}
public override string GetFileDescription()
{
return "CTR Layout Animation (CLAN)";
}
public override string GetFileFilter()
{
return "CTR Layout Animation (*.bclan)|*.bclan";
}
public override Bitmap GetIcon()
{
return null;
}
public override FormatMatch IsFormat(EFEFile File)
{
if (File.Data.Length > 4 && File.Data[0] == 'C' && File.Data[1] == 'L' && File.Data[2] == 'A' && File.Data[3] == 'N') return FormatMatch.Content;
return FormatMatch.No;
}
}
}
}

View File

@ -0,0 +1,232 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LibEveryFileExplorer.Files;
using System.Drawing;
using System.IO;
using _3DS.UI;
using _3DS.GPU;
using LibEveryFileExplorer.IO;
namespace _3DS.NintendoWare.LYT
{
public class CLIM : FileFormat<CLIM.CLIMIdentifier>, IConvertable, IFileCreatable, IViewable, IWriteable
{
public CLIM()
{
Data = new byte[0];
Header = new CLIMHeader();
Image = new imag();
}
public CLIM(byte[] Data)
{
EndianBinaryReader er = new EndianBinaryReader(new MemoryStream(Data), Endianness.LittleEndian);
er.BaseStream.Position = Data.Length - 0x28;
try
{
Header = new CLIMHeader(er);
Image = new imag(er);
er.BaseStream.Position = 0;
this.Data = er.ReadBytes((int)Image.DataLength);
}
finally
{
er.Close();
}
}
public System.Windows.Forms.Form GetDialog()
{
return new CLIMViewer(this);
}
public string GetSaveDefaultFileFilter()
{
return "CTR Layout Images (*.bclim)|*.bclim";
}
public byte[] Write()
{
MemoryStream m = new MemoryStream();
EndianBinaryWriter er = new EndianBinaryWriter(m, Endianness.LittleEndian);
er.Write(Data, 0, Data.Length);
Header.Write(er);
Image.Write(er);
long curpos = er.BaseStream.Position;
er.BaseStream.Position = Data.Length + 0xC;
er.Write((uint)curpos);
er.BaseStream.Position = curpos;
byte[] result = m.ToArray();
er.Close();
return result;
}
public string GetConversionFileFilters()
{
return "Portable Network Graphics (*.png)|*.png";
}
public bool Convert(int FilterIndex, string Path)
{
switch (FilterIndex)
{
case 0:
File.Create(Path).Close();
ToBitmap().Save(Path, System.Drawing.Imaging.ImageFormat.Png);
return true;
}
return false;
}
public bool CreateFromFile()
{
System.Windows.Forms.OpenFileDialog f = new System.Windows.Forms.OpenFileDialog();
f.Filter = "PNG Files (*.png)|*.png";
if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK
&& f.FileName.Length > 0)
{
Bitmap b = new Bitmap(new MemoryStream(File.ReadAllBytes(f.FileName)));
Image.Width = (ushort)b.Width;
Image.Height = (ushort)b.Height;
Image.Format = 10;//5;
Data = Textures.FromBitmap(b, Textures.ImageFormat.ETC1);//.RGB565);
Image.DataLength = (uint)Data.Length;
return true;
}
return false;
}
public byte[] Data;
public CLIMHeader Header;
public class CLIMHeader
{
public CLIMHeader()
{
Signature = "CLIM";
Endianness = 0xFEFF;
HeaderSize = 0x14;
Version = 0x02020000;
NrBlocks = 1;
}
public CLIMHeader(EndianBinaryReader er)
{
Signature = er.ReadString(Encoding.ASCII, 4);
if (Signature != "CLIM") throw new SignatureNotCorrectException(Signature, "CLIM", er.BaseStream.Position - 4);
Endianness = er.ReadUInt16();
HeaderSize = er.ReadUInt16();
Version = er.ReadUInt32();
FileSize = er.ReadUInt32();
NrBlocks = er.ReadUInt32();
}
public void Write(EndianBinaryWriter er)
{
er.Write(Signature, Encoding.ASCII, false);
er.Write(Endianness);
er.Write(HeaderSize);
er.Write(Version);
er.Write((uint)0);
er.Write(NrBlocks);
}
public String Signature;
public UInt16 Endianness;
public UInt16 HeaderSize;
public UInt32 Version;
public UInt32 FileSize;
public UInt32 NrBlocks;
}
public imag Image;
public class imag
{
public imag()
{
Signature = "imag";
SectionSize = 0x10;
}
public imag(EndianBinaryReader er)
{
Signature = er.ReadString(Encoding.ASCII, 4);
if (Signature != "imag") throw new SignatureNotCorrectException(Signature, "imag", er.BaseStream.Position);
SectionSize = er.ReadUInt32();
Width = er.ReadUInt16();
Height = er.ReadUInt16();
Format = er.ReadUInt32();
DataLength = er.ReadUInt32();
}
public void Write(EndianBinaryWriter er)
{
er.Write(Signature, Encoding.ASCII, false);
er.Write(SectionSize);
er.Write(Width);
er.Write(Height);
er.Write(Format);
er.Write(DataLength);
}
public String Signature;
public UInt32 SectionSize;//Without signature
public UInt16 Width;
public UInt16 Height;
public UInt32 Format;
public UInt32 DataLength;
public Textures.ImageFormat GetGPUTextureFormat()
{
switch (Format)
{
case 0: return Textures.ImageFormat.L8;
case 1: return Textures.ImageFormat.A8;
case 2: return Textures.ImageFormat.LA4;
case 3: return Textures.ImageFormat.LA8;
case 4: return Textures.ImageFormat.HILO8;
case 5: return Textures.ImageFormat.RGB565;
case 6: return Textures.ImageFormat.RGB8;
case 7: return Textures.ImageFormat.RGBA5551;
case 8: return Textures.ImageFormat.RGBA4;
case 9: return Textures.ImageFormat.RGBA8;
case 10: return Textures.ImageFormat.ETC1;
case 11: return Textures.ImageFormat.ETC1A4;
case 12: return Textures.ImageFormat.L4;
case 13: return Textures.ImageFormat.A4;
case 19: return Textures.ImageFormat.ETC1;
}
throw new Exception("Unknown Image Format!");
}
}
public Bitmap ToBitmap()
{
return GPU.Textures.ToBitmap(Data, Image.Width, Image.Height, Image.GetGPUTextureFormat());
}
public class CLIMIdentifier : FileFormatIdentifier
{
public override string GetCategory()
{
return Category_Graphics;
}
public override string GetFileDescription()
{
return "CTR Layout Images (CLIM)";
}
public override string GetFileFilter()
{
return "CTR Layout Images (*.bclim)|*.bclim";
}
public override Bitmap GetIcon()
{
return Resource.image;
}
public override FormatMatch IsFormat(EFEFile File)
{
if (File.Data.Length > 0x28 && File.Data[File.Data.Length - 0x28] == 'C' && File.Data[File.Data.Length - 0x27] == 'L' && File.Data[File.Data.Length - 0x26] == 'I' && File.Data[File.Data.Length - 0x25] == 'M' && IOUtil.ReadU32LE(File.Data, File.Data.Length - 0x4) == (File.Data.Length - 0x28)) return FormatMatch.Content;
return FormatMatch.No;
}
}
}
}

View File

@ -0,0 +1,284 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LibEveryFileExplorer.Files;
using System.Drawing;
using LibEveryFileExplorer.Collections;
using System.IO;
using System.Windows.Forms;
using _3DS.UI;
namespace _3DS.NintendoWare.LYT
{
public class CLYT : FileFormat<CLYT.CLYTIdentifier>, IViewable
{
public CLYT(byte[] Data)
{
EndianBinaryReader er = new EndianBinaryReader(new MemoryStream(Data), Endianness.LittleEndian);
try
{
Header = new CLYTHeader(er);
pan1 ParentPan = new pan1("FakeDummyTopPane");
pan1 LastPan = null;
grp1 ParentGrp = new grp1("FakeDummyTopGroup");
grp1 LastGrp = null;
int blocknr = 0;
while (blocknr < Header.NrBlocks)
{
String sig = er.ReadString(Encoding.ASCII, 4);
UInt32 size = er.ReadUInt32();
er.BaseStream.Position -= 8;
switch (sig)
{
case "lyt1": Layout = new lyt1(er); break;
case "txl1": TextureList = new txl1(er); break;
case "fnl1": FontList = new fnl1(er); break;
case "mat1": Materials = new mat1(er); break;
case "pan1":
LastPan = new pan1(er);
LastPan.Parent = ParentPan;
ParentPan.Children.Add(LastPan);
break;
case "pic1":
LastPan = new pic1(er);
LastPan.Parent = ParentPan;
ParentPan.Children.Add(LastPan);
break;
case "txt1":
LastPan = new txt1(er);
LastPan.Parent = ParentPan;
ParentPan.Children.Add(LastPan);
break;
case "bnd1":
LastPan = new bnd1(er);
LastPan.Parent = ParentPan;
ParentPan.Children.Add(LastPan);
break;
case "wnd1":
LastPan = new wnd1(er);
LastPan.Parent = ParentPan;
ParentPan.Children.Add(LastPan);
break;
case "pas1":
ParentPan = LastPan;
er.BaseStream.Position += 8;
break;
case "pae1":
ParentPan = ParentPan.Parent;
er.BaseStream.Position += 8;
break;
case "grp1":
LastGrp = new grp1(er);
LastGrp.Parent = ParentGrp;
ParentGrp.Children.Add(LastGrp);
break;
case "grs1":
ParentGrp = LastGrp;
er.BaseStream.Position += 8;
break;
case "gre1":
ParentGrp = ParentGrp.Parent;
er.BaseStream.Position += 8;
break;
case "usd1"://userdata
er.BaseStream.Position += size;
break;
default:
er.BaseStream.Position += size;
break;
}
blocknr++;
}
RootPane = ParentPan.Children[0];
RootPane.Parent = null;
RootGroup = ParentGrp.Children[0];
RootGroup.Parent = null;
}
finally
{
er.Close();
}
}
public Form GetDialog()
{
return new CLYTViewer(this);
}
public CLYTHeader Header;
public class CLYTHeader
{
public CLYTHeader(EndianBinaryReader er)
{
Signature = er.ReadString(Encoding.ASCII, 4);
if (Signature != "CLYT") throw new SignatureNotCorrectException(Signature, "CLYT", er.BaseStream.Position - 4);
Endianness = er.ReadUInt16();
HeaderSize = er.ReadUInt16();
Version = er.ReadUInt32();
FileSize = er.ReadUInt32();
NrBlocks = er.ReadUInt32();
}
public String Signature;
public UInt16 Endianness;
public UInt16 HeaderSize;
public UInt32 Version;
public UInt32 FileSize;
public UInt32 NrBlocks;
}
public lyt1 Layout;
public class lyt1
{
public enum ScreenOriginType : uint
{
Classic = 0,
Normal = 1
}
public lyt1(EndianBinaryReader er)
{
Signature = er.ReadString(Encoding.ASCII, 4);
if (Signature != "lyt1") throw new SignatureNotCorrectException(Signature, "lyt1", er.BaseStream.Position - 4);
SectionSize = er.ReadUInt32();
ScreenOrigin = (ScreenOriginType)er.ReadUInt32();
LayoutSize = er.ReadVector2();
}
public String Signature;
public UInt32 SectionSize;
public ScreenOriginType ScreenOrigin;//u32
public Vector2 LayoutSize;
}
public txl1 TextureList;
public class txl1
{
public txl1(EndianBinaryReader er)
{
long startpos = er.BaseStream.Position;
Signature = er.ReadString(Encoding.ASCII, 4);
if (Signature != "txl1") throw new SignatureNotCorrectException(Signature, "txl1", er.BaseStream.Position - 4);
SectionSize = er.ReadUInt32();
NrTextures = er.ReadUInt32();
long baseoffset = er.BaseStream.Position;
TextureNameOffsets = er.ReadUInt32s((int)NrTextures);
TextureNames = new string[NrTextures];
for (int i = 0; i < NrTextures; i++)
{
er.BaseStream.Position = baseoffset + TextureNameOffsets[i];
TextureNames[i] = er.ReadStringNT(Encoding.ASCII);
}
//padding
er.BaseStream.Position = startpos + SectionSize;
}
public String Signature;
public UInt32 SectionSize;
public UInt32 NrTextures;
public UInt32[] TextureNameOffsets;
public String[] TextureNames;
}
public fnl1 FontList;
public class fnl1
{
public fnl1(EndianBinaryReader er)
{
long startpos = er.BaseStream.Position;
Signature = er.ReadString(Encoding.ASCII, 4);
if (Signature != "fnl1") throw new SignatureNotCorrectException(Signature, "fnl1", er.BaseStream.Position - 4);
SectionSize = er.ReadUInt32();
NrFonts = er.ReadUInt32();
long baseoffset = er.BaseStream.Position;
FontNameOffsets = er.ReadUInt32s((int)NrFonts);
FontNames = new string[NrFonts];
for (int i = 0; i < NrFonts; i++)
{
er.BaseStream.Position = baseoffset + FontNameOffsets[i];
FontNames[i] = er.ReadStringNT(Encoding.ASCII);
}
er.BaseStream.Position = startpos + SectionSize;
}
public String Signature;
public UInt32 SectionSize;
public UInt32 NrFonts;
public UInt32[] FontNameOffsets;
public String[] FontNames;
}
public mat1 Materials;
public pan1 RootPane;
public grp1 RootGroup;
public class grp1
{
public grp1(String Name) { this.Name = Name; }
public grp1(EndianBinaryReader er)
{
Signature = er.ReadString(Encoding.ASCII, 4);
if (Signature != "grp1") throw new SignatureNotCorrectException(Signature, "grp1", er.BaseStream.Position - 4);
SectionSize = er.ReadUInt32();
Name = er.ReadString(Encoding.ASCII, 0x10).Replace("\0", "");
NrPaneReferences = er.ReadUInt32();
PaneReferences = new string[NrPaneReferences];
for (int i = 0; i < NrPaneReferences; i++)
{
PaneReferences[i] = er.ReadString(Encoding.ASCII, 0x10).Replace("\0", "");
}
}
public String Signature;
public UInt32 SectionSize;
public String Name;
public UInt32 NrPaneReferences;
public String[] PaneReferences;
public grp1 Parent = null;
public List<grp1> Children = new List<grp1>();
public TreeNode GetTreeNodes()
{
TreeNode t = new TreeNode(Name);
t.ImageKey = t.SelectedImageKey = Signature;
foreach (var v in Children)
{
t.Nodes.Add(v.GetTreeNodes());
}
foreach (var v in PaneReferences)
{
t.Nodes.Add("pan1", v);
}
return t;
}
public override string ToString()
{
return Name;
}
}
public class CLYTIdentifier : FileFormatIdentifier
{
public override string GetCategory()
{
return Category_Layouts;
}
public override string GetFileDescription()
{
return "CTR Layout (CLYT)";
}
public override string GetFileFilter()
{
return "CTR Layout (*.bclyt)|*.bclyt";
}
public override Bitmap GetIcon()
{
return Resource.zone;
}
public override FormatMatch IsFormat(EFEFile File)
{
if (File.Data.Length > 4 && File.Data[0] == 'C' && File.Data[1] == 'L' && File.Data[2] == 'Y' && File.Data[3] == 'T') return FormatMatch.Content;
return FormatMatch.No;
}
}
}
}

View File

@ -0,0 +1,283 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using Tao.OpenGl;
namespace _3DS.NintendoWare.LYT
{
public class CLYTShader
{
public int[] Textures;
private mat1.MaterialEntry Material;
public CLYTShader(mat1.MaterialEntry Material, int[] Textures)
{
this.Textures = Textures;
this.Material = Material;
}
public void Enable()
{
Gl.glUseProgram(program);
//setup uniforms
Gl.glUniform4f(Gl.glGetUniformLocation(program, "colorreg"), Material.BufferColor.R / 255f, Material.BufferColor.G / 255f, Material.BufferColor.B / 255f, Material.BufferColor.A / 255f);
for (int i = 0; i < 6; i++)
{
Gl.glUniform4f(Gl.glGetUniformLocation(program, "const" + i), Material.ConstColors[i].R / 255f, Material.ConstColors[i].G / 255f, Material.ConstColors[i].B / 255f, Material.ConstColors[i].A / 255f);
}
}
public void Disable()
{
//Gl.glDeleteProgram(program);
//Gl.glDeleteShader(vertex_shader);
//Gl.glDeleteShader(fragment_shader);
// TODO: cache value of GetUniformLocation
//Gl.glUniform4fv(Gl.glGetUniformLocation(program, "registers"), 3, g_color_registers[0]);
}
//Fragment Lighting Primary Color:
//Color = SUM((dmp_FragmentLightSource[i].diffuse * dmp_FragmentMaterial.diffuse * DOT(dmp_FragmentLightSource[i].position, NormalVector) * SdwAttPr[i] + dmp_FragmentMaterial.ambient * dmp_FragmentLightSource[i].ambient) * Spot[i] * DistAtt[i]) + dmp_FragmentMaterial.emission + dmp_FragmentMaterial.ambient * dmp_FragmentLighting.ambient
//Color = SUM((vec3(1.0) * mDiff * DOT(
public void Compile()
{
// w.e good for now
uint sampler_count = (uint)Textures.Length;
//if (sampler_count == 0)
//{
// sampler_count = 1;
//}
// generate vertex/fragment shader code
//{
StringBuilder vert_ss = new StringBuilder();
//String vert_ss = "";
//vert_ss.AppendFormat("vec4 diffuse = {0};\n", GetVec4(Material.MaterialColor.DiffuseU32));
//vert_ss.AppendFormat("vec4 ambient = {0};\n", GetVec4(Material.MaterialColor.Ambient));
//vert_ss.AppendFormat("vec4 spec1 = {0};\n", GetVec4(Material.MaterialColor.Specular0U32));
//vert_ss.AppendFormat("vec4 spec2 = {0};\n", GetVec4(Material.MaterialColor.Specular1U32));
vert_ss.AppendLine("void main()");
vert_ss.AppendLine("{");
{
vert_ss.AppendLine("gl_FrontColor = gl_Color;");
//if (Material.Tex0 != null) vert_ss.AppendFormat("gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord{0};\n", Material.TextureCoordiators[0].SourceCoordinate);
//if (Material.Tex1 != null) vert_ss.AppendFormat("gl_TexCoord[1] = gl_TextureMatrix[1] * gl_MultiTexCoord{0};\n", Material.TextureCoordiators[1].SourceCoordinate);
//if (Material.Tex2 != null) vert_ss.AppendFormat("gl_TexCoord[2] = gl_TextureMatrix[2] * gl_MultiTexCoord{0};\n", Material.TextureCoordiators[2].SourceCoordinate);
int i = 0;
foreach (var v in Material.TexCoordGens)
{
if ((int)v.Source < 4)
{
vert_ss.AppendFormat("gl_TexCoord[{0}] = gl_TextureMatrix[{0}] * gl_MultiTexCoord{1};\n", i, (int)v.Source);
}
i++;
}
vert_ss.AppendLine("gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;");
}
vert_ss.AppendLine("}");
// create/compile vertex shader
vertex_shader = Gl.glCreateShader(Gl.GL_VERTEX_SHADER);
{
var vert_src_str = vert_ss.ToString();
//const GLchar* vert_src = vert_src_str.c_str();
Gl.glShaderSource(vertex_shader, 1, new string[] { vert_src_str }, new int[] { vert_src_str.Length });
}
//} // done generating vertex shader
Gl.glCompileShader(vertex_shader);
string[] p0 =
{
"texture2D(textures0, gl_TexCoord[0].st)",
"texture2D(textures1, gl_TexCoord[1].st)",
"texture2D(textures2, gl_TexCoord[2].st)",
"texture2D(textures3, gl_TexCoord[3].st)",
"{0}",
"gl_Color",
"previous",
"colorreg"
};
string[] oc =
{
"{0}.rgb",
"vec3(1.0) - {0}.rgb",
"{0}.aaa",
"vec3(1.0) - {0}.aaa",
"{0}.rrr",
"vec3(1.0) - {0}.rrr",
"{0}.ggg",
"vec3(1.0) - {0}.ggg",
"{0}.bbb",
"vec3(1.0) - {0}.bbb"
};
string[] oa =
{
"{0}.a",
"(1.0 - {0}.a)",
"{0}.r",
"(1.0 - {0}.r)",
"{0}.g",
"(1.0 - {0}.g)",
"{0}.b",
"(1.0 - {0}.b)"
};
string[] comb_c =
{
"j1.rgb",
"j1.rgb * j2.rgb",
"j1.rgb + j2.rgb",
"j1.rgb + j2.rgb - vec3(0.5)",
"j1.rgb * j3.rgb + j2.rgb * (vec3(1.0) - j3.rgb)",
"j1.rgb - j2.rgb",
"clamp(j1.rgb + j2.rgb, 0.0, 1.0) * j3.rgb",
"(j1.rgb * j2.rgb) + j3.rgb",
"j1.rgb",
"j1.rgb",
"j1.rgb",
"j1.rgb"
};
string[] comb_a =
{
"j1.a",
"j1.a * j2.a",
"j1.a + j2.a",
"j1.a + j2.a - vec3(0.5)",
"j1.a * j3.a + j2.a * (vec3(1.0) - j3.a)",
"j1.a - j2.a",
"clamp(j1.a + j2.a, 0.0, 1.0) * j3.a",
"(j1.a * j2.a) + j3.a",
"j1.a",
"j1.a",
"j1.a",
"j1.a"
};
// generate fragment shader code
//{
StringBuilder frag_ss = new StringBuilder();
//frag_ss += "uniform sampler2D tex;";
// uniforms
for (uint i = 0; i != sampler_count; ++i)
frag_ss.AppendFormat("uniform sampler2D textures{0};\n", i);
frag_ss.AppendLine("uniform vec4 colorreg;");
for (int i = 0; i < 6; i++) frag_ss.AppendFormat("uniform vec4 const{0};\n", i);
frag_ss.AppendLine("void main()");
frag_ss.AppendLine("{");
{
if (Material.TexMaps.Length == 0) frag_ss.AppendLine("gl_FragColor = gl_Color;");
else if (Material.TexMaps.Length == 1) frag_ss.AppendLine("gl_FragColor = texture2D(textures0, gl_TexCoord[0].st) * gl_Color;");
else
{
frag_ss.AppendLine("vec4 j1;");
frag_ss.AppendLine("vec4 j2;");
frag_ss.AppendLine("vec4 j3;");
frag_ss.AppendLine("vec4 previous;");
foreach (var tev in Material.TevStages)
{
uint colorconst = (tev.ConstColors & 0xF) - 1;
uint alphaconst = ((tev.ConstColors >> 4) & 0xF) - 1;
frag_ss.AppendFormat("j1 = vec4({0}, {1});\n",
string.Format(oc[(int)tev.ColorOperators[0]], string.Format(p0[(int)tev.ColorSources[0]], string.Format("const{0}", colorconst))),
string.Format(oa[(int)tev.AlphaOperators[0]], string.Format(p0[(int)tev.AlphaSources[0]], string.Format("const{0}", alphaconst))));
frag_ss.AppendFormat("j2 = vec4({0}, {1});\n",
string.Format(oc[(int)tev.ColorOperators[1]], string.Format(p0[(int)tev.ColorSources[1]], string.Format("const{0}", colorconst))),
string.Format(oa[(int)tev.AlphaOperators[1]], string.Format(p0[(int)tev.AlphaSources[1]], string.Format("const{0}", alphaconst))));
frag_ss.AppendFormat("j3 = vec4({0}, {1});\n",
string.Format(oc[(int)tev.ColorOperators[2]], string.Format(p0[(int)tev.ColorSources[2]], string.Format("const{0}", colorconst))),
string.Format(oa[(int)tev.AlphaOperators[2]], string.Format(p0[(int)tev.AlphaSources[2]], string.Format("const{0}", alphaconst))));
frag_ss.AppendFormat("previous = vec4({0},{1});\n", comb_c[(int)tev.ColorMode], comb_a[(int)tev.AlphaMode]);
}
frag_ss.AppendLine("gl_FragColor = previous;");
}
}
frag_ss.AppendLine("}");
//std::cout << frag_ss.str() << '\n';
// create/compile fragment shader
fragment_shader = Gl.glCreateShader(Gl.GL_FRAGMENT_SHADER);
{
var frag_src_str = frag_ss.ToString();
Gl.glShaderSource(fragment_shader, 1, new String[] { frag_src_str }, new int[] { frag_src_str.Length });
}
//} // done generating fragment shader
Gl.glCompileShader(fragment_shader);
// check compile status of both shaders
//{
int vert_compiled = 0;
int frag_compiled = 0;
Gl.glGetShaderiv(vertex_shader, Gl.GL_COMPILE_STATUS, out vert_compiled);
Gl.glGetShaderiv(fragment_shader, Gl.GL_COMPILE_STATUS, out frag_compiled);
if (vert_compiled == 0)
{
//std::cout << "Failed to compile vertex shader\n";
}
if (frag_compiled == 0)
{
//std::cout << "Failed to compile fragment shader\n";
}
// create program, attach shaders
program = Gl.glCreateProgram();
Gl.glAttachShader(program, vertex_shader);
Gl.glAttachShader(program, fragment_shader);
// link program, check link status
Gl.glLinkProgram(program);
int link_status;
Gl.glGetProgramiv(program, Gl.GL_LINK_STATUS, out link_status);
if (link_status == 0)
{
//std::cout << "Failed to link program!\n";
}
Gl.glUseProgram(program);
// set uniforms
for (uint i = 0; i != sampler_count; ++i)
{
String ss = "textures" + i;
Gl.glUniform1i(Gl.glGetUniformLocation(program, ss), (int)i);
}
Gl.glUniform4f(Gl.glGetUniformLocation(program, "colorreg"), Material.BufferColor.R / 255f, Material.BufferColor.G / 255f, Material.BufferColor.B / 255f, Material.BufferColor.A / 255f);
for (int i = 0; i < 6; i++)
{
Gl.glUniform4f(Gl.glGetUniformLocation(program, "const" + i), Material.ConstColors[i].R / 255f, Material.ConstColors[i].G / 255f, Material.ConstColors[i].B / 255f, Material.ConstColors[i].A / 255f);
}
}
private String GetVec4(Color c)
{
return String.Format("vec4({0}, {1}, {2}, {3})", (c.R / 255f).ToString().Replace(",", "."), (c.G / 255f).ToString().Replace(",", "."), (c.B / 255f).ToString().Replace(",", "."), (c.A / 255f).ToString().Replace(",", "."));
}
public int program = 0, fragment_shader = 0, vertex_shader = 0;
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace _3DS.NintendoWare.LYT
{
public class bnd1 : pan1
{
public bnd1(EndianBinaryReader er)
: base(er)
{
}
}
}

View File

@ -0,0 +1,441 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using LibEveryFileExplorer.Files;
using System.Drawing;
using LibEveryFileExplorer.Collections;
using Tao.OpenGl;
namespace _3DS.NintendoWare.LYT
{
public class mat1
{
public mat1(EndianBinaryReader er)
{
long startpos = er.BaseStream.Position;
Signature = er.ReadString(Encoding.ASCII, 4);
if (Signature != "mat1") throw new SignatureNotCorrectException(Signature, "mat1", er.BaseStream.Position - 4);
SectionSize = er.ReadUInt32();
NrMaterials = er.ReadUInt32();
MaterialEntryOffsets = er.ReadUInt32s((int)NrMaterials);
Materials = new MaterialEntry[NrMaterials];
for (int i = 0; i < NrMaterials; i++)
{
er.BaseStream.Position = startpos + MaterialEntryOffsets[i];
Materials[i] = new MaterialEntry(er);
}
er.BaseStream.Position = startpos + SectionSize;
}
public String Signature;
public UInt32 SectionSize;
public UInt32 NrMaterials;
public UInt32[] MaterialEntryOffsets;
public MaterialEntry[] Materials;
public class MaterialEntry
{
public MaterialEntry(EndianBinaryReader er)
{
Name = er.ReadString(Encoding.ASCII, 20).Replace("\0", "");
BufferColor = er.ReadColor8();
ConstColors = new Color[6];
ConstColors[0] = er.ReadColor8();
ConstColors[1] = er.ReadColor8();
ConstColors[2] = er.ReadColor8();
ConstColors[3] = er.ReadColor8();
ConstColors[4] = er.ReadColor8();
ConstColors[5] = er.ReadColor8();
Flags = er.ReadUInt32();
//Material Flag:
// 0-1: Nr texMap
// 2-3: Nr texMatrix
// 4-5: Nr texCoordGen
// 6-8: Nr tevStage
// 9: Has alphaCompare
// 10: Has blendMode
// 11: Use Texture Only
// 12: Separate Blend Mode
// 14: Has Indirect Parameter
//15-16: Nr projectionTexGenParameter
// 17: Has Font Shadow Parameter
TexMaps = new TexMap[Flags & 3];
for (int i = 0; i < (Flags & 3); i++)
{
TexMaps[i] = new TexMap(er);
}
TexMatrices = new TexMatrix[(Flags >> 2) & 3];
for (int i = 0; i < ((Flags >> 2) & 3); i++)
{
TexMatrices[i] = new TexMatrix(er);
}
TexCoordGens = new TexCoordGen[(Flags >> 4) & 3];
for (int i = 0; i < ((Flags >> 4) & 3); i++)
{
TexCoordGens[i] = new TexCoordGen(er);
}
TevStages = new TevStage[(Flags >> 6) & 7];
for (int i = 0; i < ((Flags >> 6) & 7); i++)
{
TevStages[i] = new TevStage(er);
}
if (((Flags >> 9) & 1) == 1) AlphaTest = new AlphaCompare(er);
if (((Flags >> 10) & 1) == 1) ColorBlendMode = new BlendMode(er);
if (((Flags >> 12) & 1) == 1) AlphaBlendMode = new BlendMode(er);
//Some more things
}
public String Name;
public Color BufferColor;//?
public Color[] ConstColors;
public UInt32 Flags;
public TexMap[] TexMaps;
public class TexMap
{
public enum WrapMode
{
Clamp = 0,
Repeat = 1,
Mirror = 2
}
public enum FilterMode
{
Near = 0,
Linear = 1
}
public TexMap(EndianBinaryReader er)
{
TexIndex = er.ReadUInt16();
byte tmp = er.ReadByte();
WrapS = (WrapMode)(tmp & 3);
MinFilter = (FilterMode)((tmp >> 2) & 3);
tmp = er.ReadByte();
WrapT = (WrapMode)(tmp & 3);
MagFilter = (FilterMode)((tmp >> 2) & 3);
}
public UInt16 TexIndex;
public WrapMode WrapS;
public FilterMode MinFilter;
public WrapMode WrapT;
public FilterMode MagFilter;
}
public TexMatrix[] TexMatrices;
public class TexMatrix
{
public TexMatrix(EndianBinaryReader er)
{
Translation = er.ReadVector2();
Rotation = er.ReadSingle();
Scale = er.ReadVector2();
}
public Vector2 Translation;
public Single Rotation;
public Vector2 Scale;
}
public TexCoordGen[] TexCoordGens;
public class TexCoordGen
{
public enum TexCoordSource
{
Tex0 = 0,
Tex1 = 1,
Tex2 = 2,
OrthogonalProjection = 3,
PaneBasedProjection = 4,
PerspectiveProjection = 5
}
public TexCoordGen(EndianBinaryReader er)
{
Unknown1 = er.ReadByte();
Source = (TexCoordSource)er.ReadByte();
Unknown2 = er.ReadUInt16();
}
public byte Unknown1;
public TexCoordSource Source;
public UInt16 Unknown2;
}
public TevStage[] TevStages;
public class TevStage
{
public enum TevSource
{
Tex0 = 0,
Tex1 = 1,
Tex2 = 2,
Tex3 = 3,
Constant = 4,
Primary = 5,
Previous = 6,
Register = 7
}
public enum TevColorOp
{
RGB = 0,
InvRGB = 1,
Alpha = 2,
InvAlpha = 3,
RRR = 4,
InvRRR = 5,
GGG = 6,
InvGGG = 7,
BBB = 8,
InvBBB = 9
}
public enum TevAlphaOp
{
Alpha = 0,
InvAlpha = 1,
R = 2,
InvR = 3,
G = 4,
InvG = 5,
B = 6,
InvB = 7
}
public enum TevMode
{
Replace = 0,
Modulate = 1,
Add = 2,
AddSigned = 3,
Interpolate = 4,
Subtract = 5,
AddMult = 6,
MultAdd = 7,
Overlay = 8,
Indirect = 9,
BlendIndirect = 10,
EachIndirect = 11
}
public enum TevScale
{
Scale1,
Scale2,
Scale4
}
public TevStage(EndianBinaryReader er)
{
uint tmp = er.ReadUInt32();
ColorSources = new TevSource[] { (TevSource)(tmp & 0xF), (TevSource)((tmp >> 4) & 0xF), (TevSource)((tmp >> 8) & 0xF) };
ColorOperators = new TevColorOp[] { (TevColorOp)((tmp >> 12) & 0xF), (TevColorOp)((tmp >> 16) & 0xF), (TevColorOp)((tmp >> 20) & 0xF) };
ColorMode = (TevMode)((tmp >> 24) & 0xF);
ColorScale = (TevScale)((tmp >> 28) & 0x3);
ColorSavePrevReg = ((tmp >> 30) & 0x1) == 1;
tmp = er.ReadUInt32();
AlphaSources = new TevSource[] { (TevSource)(tmp & 0xF), (TevSource)((tmp >> 4) & 0xF), (TevSource)((tmp >> 8) & 0xF) };
AlphaOperators = new TevAlphaOp[] { (TevAlphaOp)((tmp >> 12) & 0xF), (TevAlphaOp)((tmp >> 16) & 0xF), (TevAlphaOp)((tmp >> 20) & 0xF) };
AlphaMode = (TevMode)((tmp >> 24) & 0xF);
AlphaScale = (TevScale)((tmp >> 28) & 0x3);
AlphaSavePrevReg = ((tmp >> 30) & 0x1) == 1;
ConstColors = er.ReadUInt32();
}
public TevSource[] ColorSources;
public TevColorOp[] ColorOperators;
public TevMode ColorMode;
public TevScale ColorScale;
public Boolean ColorSavePrevReg;
public byte ColorUnknown;
public TevSource[] AlphaSources;
public TevAlphaOp[] AlphaOperators;
public TevMode AlphaMode;
public TevScale AlphaScale;
public Boolean AlphaSavePrevReg;
public UInt32 ConstColors;
}
public AlphaCompare AlphaTest;
public class AlphaCompare
{
public enum AlphaFunction
{
Never = 0,
Less = 1,
LEqual = 2,
Equal = 3,
NEqual = 4,
GEqual = 5,
Greater = 6,
Always = 7
}
public AlphaCompare(EndianBinaryReader er)
{
AlphaFunc = (AlphaFunction)er.ReadUInt32();
Reference = er.ReadSingle();
}
public AlphaFunction AlphaFunc;
public Single Reference;
private readonly int[] GlAlphaFunc =
{
Gl.GL_NEVER,
Gl.GL_LESS,
Gl.GL_LEQUAL,
Gl.GL_EQUAL,
Gl.GL_NOTEQUAL,
Gl.GL_GEQUAL,
Gl.GL_GREATER,
Gl.GL_ALWAYS
};
public void Apply()
{
Gl.glEnable(Gl.GL_ALPHA_TEST);
Gl.glAlphaFunc(GlAlphaFunc[(int)AlphaFunc], Reference);
Gl.glEnable(Gl.GL_ALPHA_TEST);
}
}
public BlendMode ColorBlendMode;
public BlendMode AlphaBlendMode;
public class BlendMode
{
public enum BlendOp
{
None = 0,
Add = 1,
Subtract = 2,
ReverseSubtract = 3,
SelectMin = 4,
SelectMax = 5
}
public enum BlendSource
{
V0 = 0,
V1_0 = 1,
DstClr = 2,
InvDstClr = 3,
SrcAlpha = 4,
InvSrcAlpha = 5,
DstAlpha = 6,
InvDstAlpha = 7
}
public enum BlendDestination
{
V0 = 0,
V1_0 = 1,
SrcClr = 2,
InvSrcClr = 3,
SrcAlpha = 4,
InvSrcAlpha = 5,
DstAlpha = 6,
InvDstAlpha = 7
}
public enum BlendLogicOp
{
None = 0,
NoOp = 1,
Clear = 2,
Set = 3,
Copy = 4,
InvCopy = 5,
Inv = 6,
And = 7,
Nand = 8,
Or = 9,
Nor = 10,
Xor = 11,
Equiv = 12,
RevAnd = 13,
InvAnd = 14,
RevOr = 15,
InvOr = 16
}
public BlendMode(EndianBinaryReader er)
{
BlendOperator = (BlendOp)er.ReadByte();
SourceFactor = (BlendSource)er.ReadByte();
DestinationFactor = (BlendDestination)er.ReadByte();
LogicOperator = (BlendLogicOp)er.ReadByte();
}
public BlendOp BlendOperator;
public BlendSource SourceFactor;
public BlendDestination DestinationFactor;
public BlendLogicOp LogicOperator;
private readonly int[] GlBlendEq =
{
0,
Gl.GL_FUNC_ADD,
Gl.GL_FUNC_SUBTRACT,
Gl.GL_FUNC_REVERSE_SUBTRACT,
Gl.GL_MIN,
Gl.GL_MAX
};
private readonly int[] GlBlendSrc =
{
Gl.GL_ZERO,
Gl.GL_ONE,
Gl.GL_DST_COLOR,
Gl.GL_ONE_MINUS_DST_COLOR,
Gl.GL_SRC_ALPHA,
Gl.GL_ONE_MINUS_SRC_ALPHA,
Gl.GL_DST_ALPHA,
Gl.GL_ONE_MINUS_DST_ALPHA
};
private readonly int[] GlBlendDst =
{
Gl.GL_ZERO,
Gl.GL_ONE,
Gl.GL_SRC_COLOR,
Gl.GL_ONE_MINUS_SRC_COLOR,
Gl.GL_SRC_ALPHA,
Gl.GL_ONE_MINUS_SRC_ALPHA,
Gl.GL_DST_ALPHA,
Gl.GL_ONE_MINUS_DST_ALPHA
};
public void Apply()
{
if (BlendOperator == BlendOp.None) Gl.glDisable(Gl.GL_BLEND);
else
{
Gl.glEnable(Gl.GL_BLEND);
Gl.glBlendEquation(GlBlendEq[(int)BlendOperator]);
Gl.glBlendFunc(GlBlendSrc[(int)SourceFactor], GlBlendDst[(int)DestinationFactor]);
Gl.glEnable(Gl.GL_BLEND);
}
}
}
public CLYTShader GlShader { get; private set; }
public void SetupShader()
{
GlShader = new CLYTShader(this, new int[TexMaps.Length]);
GlShader.Compile();
}
public void ApplyAlphaCompareBlendMode()
{
if (AlphaTest != null) AlphaTest.Apply();
else
{
Gl.glEnable(Gl.GL_ALPHA_TEST);
Gl.glAlphaFunc(Gl.GL_ALWAYS, 0);
Gl.glEnable(Gl.GL_ALPHA_TEST);
}
if (ColorBlendMode != null) ColorBlendMode.Apply();
else
{
Gl.glEnable(Gl.GL_BLEND);
Gl.glBlendEquation(Gl.GL_FUNC_ADD);
Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);
Gl.glEnable(Gl.GL_BLEND);
}
}
public override string ToString()
{
return Name;
}
}
}
}

View File

@ -0,0 +1,195 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LibEveryFileExplorer.Collections;
using System.IO;
using LibEveryFileExplorer.Files;
using Tao.OpenGl;
using System.Windows.Forms;
namespace _3DS.NintendoWare.LYT
{
public class pan1
{
[Flags]
public enum PaneFlags : byte
{
IsVisible = 1,
IsInfluencedAlpha = 2,
IsLocationAdjust = 4
}
[Flags]
public enum PaneMagnifyFlags : byte
{
IgnorePartsMagnify = 1,
AdjustToPartsBounds = 2
}
public pan1(String Name) { this.Name = Name; }
public pan1(EndianBinaryReader er)
{
Signature = er.ReadString(Encoding.ASCII, 4);
if (Signature != "pan1" && Signature != "pic1" && Signature != "txt1" && Signature != "bnd1" && Signature != "wnd1" && Signature != "prt1")
throw new SignatureNotCorrectException(Signature, "pan1, pic1, txt1, bnd1, wnd1, prt1", er.BaseStream.Position - 4);
SectionSize = er.ReadUInt32();
Flags = (PaneFlags)er.ReadByte();
Origin = er.ReadByte();
Alpha = er.ReadByte();
MagnifyFlags = (PaneMagnifyFlags)er.ReadByte();
Name = er.ReadString(Encoding.ASCII, 24).Replace("\0", "");
Translation = er.ReadVector3();
Rotation = er.ReadVector3();
Scale = er.ReadVector2();
Size = er.ReadVector2();
}
public String Signature;
public UInt32 SectionSize;
public PaneFlags Flags;
public Byte Origin;
public Byte Alpha;
public PaneMagnifyFlags MagnifyFlags;
public String Name;//24
public Vector3 Translation;
public Vector3 Rotation;
public Vector2 Scale;
public Vector2 Size;
public pan1 Parent = null;
public List<pan1> Children = new List<pan1>();
public enum XOrigin
{
Left = 0,
Center = 1,
Right = 2
}
public enum YOrigin
{
Top = 0,
Center = 1,
Bottom = 2
}
public XOrigin HAlignment { get { return (XOrigin)(Origin % 3); } }
public YOrigin VAlignment { get { return (YOrigin)(Origin / 3); } }
public Boolean InfluencedAlpha { get { return (Flags & PaneFlags.IsInfluencedAlpha) != 0; } }
public virtual void Render(CLYT Layout, CLIM[] Textures, int InfluenceAlpha)
{
Gl.glPushMatrix();
{
Gl.glTranslatef(Translation.X, Translation.Y, Translation.Z);
Gl.glRotatef(Rotation.X, 1, 0, 0);
Gl.glRotatef(Rotation.Y, 0, 1, 0);
Gl.glRotatef(Rotation.Z, 0, 0, 1);
Gl.glScalef(Scale.X, Scale.Y, 1);
foreach (pan1 p in Children)
{
p.Render(Layout, Textures, InfluencedAlpha ? (int)((float)(Alpha * InfluenceAlpha) / 255f) : Alpha);
}
}
Gl.glPopMatrix();
}
protected float[,] SetupRect()
{
/*float[,] Vertex2 = new float[4, 2];
Vertex2[0, 0] = 0;
Vertex2[1, 0] = Size.X;
Vertex2[2, 0] = Size.X;
Vertex2[3, 0] = 0;
Vertex2[0, 1] = 0;
Vertex2[1, 1] = 0;
Vertex2[2, 1] = -Size.Y;
Vertex2[3, 1] = -Size.Y;
return Vertex2;*/
return SetupRect(Size.X, Size.Y);
}
protected static float[,] SetupRect(float Width, float Height)
{
float[,] Vertex2 = new float[4, 2];
Vertex2[0, 0] = 0;
Vertex2[1, 0] = Width;
Vertex2[2, 0] = Width;
Vertex2[3, 0] = 0;
Vertex2[0, 1] = 0;
Vertex2[1, 1] = 0;
Vertex2[2, 1] = -Height;
Vertex2[3, 1] = -Height;
return Vertex2;
}
protected static void SetupMaterial(CLYT Layout, int MatId)
{
var mat = Layout.Materials.Materials[MatId];
mat.ApplyAlphaCompareBlendMode();
for (int o = 0; o < mat.TexMaps.Length; o++)
{
Gl.glActiveTexture(Gl.GL_TEXTURE0 + o);
Gl.glBindTexture(Gl.GL_TEXTURE_2D, MatId * 4 + o + 1);
Gl.glEnable(Gl.GL_TEXTURE_2D);
}
if (mat.TexMaps.Length == 0)
{
Gl.glActiveTexture(Gl.GL_TEXTURE0);
Gl.glColor4f(1, 1, 1, 1);
Gl.glBindTexture(Gl.GL_TEXTURE_2D, MatId * 4 + 1);
Gl.glEnable(Gl.GL_TEXTURE_2D);
}
Gl.glMatrixMode(Gl.GL_TEXTURE);
for (int o = 0; o < mat.TexCoordGens.Length; o++)
{
Gl.glActiveTexture(Gl.GL_TEXTURE0 + o);
Gl.glLoadIdentity();
//if ((int)mat.TexCoordGens[o].Source < 4)
//{
mat1.MaterialEntry.TexMatrix srt = mat.TexMatrices[o];//(int)mat.TexCoordGens[o].Source];
Gl.glTranslatef(0.5f, 0.5f, 0.0f);
Gl.glRotatef(srt.Rotation, 0.0f, 0.0f, 1.0f);
Gl.glScalef(srt.Scale.X, srt.Scale.Y, 1.0f);
Gl.glTranslatef(srt.Translation.X / srt.Scale.X - 0.5f, srt.Translation.Y / srt.Scale.Y - 0.5f, 0.0f);
//}
//else
//{
//}
}
Gl.glMatrixMode(Gl.GL_MODELVIEW);
mat.GlShader.Enable();
}
protected static float MixColors(params float[] c)
{
float a = c[0];
for (int i = 1; i < c.Length; i++)
{
a *= c[i];
}
for (int i = 1; i < c.Length; i++)
{
a /= 255f;
}
return a / 255f;
}
public TreeNode GetTreeNodes()
{
TreeNode t = new TreeNode(Name);
t.ImageKey = t.SelectedImageKey = Signature;
foreach (var v in Children)
{
t.Nodes.Add(v.GetTreeNodes());
}
return t;
}
public override string ToString()
{
return Signature + ": " + Name;
}
}
}

View File

@ -0,0 +1,149 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.IO;
using LibEveryFileExplorer.Collections;
using Tao.OpenGl;
namespace _3DS.NintendoWare.LYT
{
public class pic1 : pan1
{
public pic1(EndianBinaryReader er)
: base(er)
{
VertexColorLT = er.ReadColor8();
VertexColorRT = er.ReadColor8();
VertexColorLB = er.ReadColor8();
VertexColorRB = er.ReadColor8();
MaterialId = er.ReadUInt16();
NrTexCoordEntries = er.ReadUInt16();
TexCoordEntries = new TexCoord[NrTexCoordEntries];
for (int i = 0; i < NrTexCoordEntries; i++)
{
TexCoordEntries[i] = new TexCoord(er);
}
}
public Color VertexColorLT;
public Color VertexColorRT;
public Color VertexColorLB;
public Color VertexColorRB;
public UInt16 MaterialId;
public UInt16 NrTexCoordEntries;
public TexCoord[] TexCoordEntries;
public class TexCoord
{
public TexCoord(EndianBinaryReader er)
{
TexCoordLT = er.ReadVector2();
TexCoordRT = er.ReadVector2();
TexCoordLB = er.ReadVector2();
TexCoordRB = er.ReadVector2();
}
public Vector2 TexCoordLT;
public Vector2 TexCoordRT;
public Vector2 TexCoordLB;
public Vector2 TexCoordRB;
}
public override void Render(CLYT Layout, CLIM[] Textures, int InfluenceAlpha)
{
Gl.glPushMatrix();
{
SetupMaterial(Layout, MaterialId);
Gl.glMatrixMode(Gl.GL_MODELVIEW);
Gl.glTranslatef(Translation.X, Translation.Y, Translation.Z);
Gl.glRotatef(Rotation.X, 1, 0, 0);
Gl.glRotatef(Rotation.Y, 0, 1, 0);
Gl.glRotatef(Rotation.Z, 0, 0, 1);
Gl.glScalef(Scale.X, Scale.Y, 1);
Gl.glPushMatrix();
{
Gl.glTranslatef(-0.5f * Size.X * (float)HAlignment, -0.5f * Size.Y * (-(float)VAlignment), 0);
float[,] Vertex2 = SetupRect();
float[][] VtxColor = SetupVtxColors(InfluenceAlpha);
Gl.glBegin(Gl.GL_QUADS);
for (int o = 0; o < TexCoordEntries.Length; o++)
{
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0 + o,
TexCoordEntries[o].TexCoordLT.X, TexCoordEntries[o].TexCoordLT.Y);
}
if (TexCoordEntries.Length == 0) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 0, 0);
Gl.glColor4f(VtxColor[0][0], VtxColor[0][1], VtxColor[0][2], VtxColor[0][3]);
Gl.glVertex3f(Vertex2[0, 0], Vertex2[0, 1], 0);
for (int o = 0; o < TexCoordEntries.Length; o++)
{
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0 + o,
TexCoordEntries[o].TexCoordRT.X, TexCoordEntries[o].TexCoordRT.Y);
}
if (TexCoordEntries.Length == 0) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 1, 0);
Gl.glColor4f(VtxColor[1][0], VtxColor[1][1], VtxColor[1][2], VtxColor[1][3]);
Gl.glVertex3f(Vertex2[1, 0], Vertex2[1, 1], 0);
for (int o = 0; o < TexCoordEntries.Length; o++)
{
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0 + o,
TexCoordEntries[o].TexCoordRB.X, TexCoordEntries[o].TexCoordRB.Y);
}
if (TexCoordEntries.Length == 0) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 1, 1);
Gl.glColor4f(VtxColor[2][0], VtxColor[2][1], VtxColor[2][2], VtxColor[2][3]);
Gl.glVertex3f(Vertex2[2, 0], Vertex2[2, 1], 0);
for (int o = 0; o < TexCoordEntries.Length; o++)
{
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0 + o,
TexCoordEntries[o].TexCoordLB.X, TexCoordEntries[o].TexCoordLB.Y);
}
if (TexCoordEntries.Length == 0) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 0, 1);
Gl.glColor4f(VtxColor[3][0], VtxColor[3][1], VtxColor[3][2], VtxColor[3][3]);
Gl.glVertex3f(Vertex2[3, 0], Vertex2[3, 1], 0);
Gl.glEnd();
}
Gl.glPopMatrix();
foreach (pan1 p in Children)
{
p.Render(Layout, Textures, InfluencedAlpha ? (int)((float)(Alpha * InfluenceAlpha) / 255f) : Alpha);
}
}
Gl.glPopMatrix();
}
private float[][] SetupVtxColors(int InfluenceAlpha)
{
float[] TL2;
float[] TR2;
float[] BL2;
float[] BR2;
TL2 = new float[]
{
VertexColorLT.R / 255f,
VertexColorLT.G / 255f,
VertexColorLT.B / 255f,
MixColors(VertexColorLT.A, (InfluencedAlpha ? (byte)(((float)Alpha * (float)InfluenceAlpha) / 255f) : this.Alpha))
};
TR2 = new float[]
{
VertexColorRT.R / 255f,
VertexColorRT.G / 255f,
VertexColorRT.B / 255f,
MixColors(VertexColorRT.A, (InfluencedAlpha ? (byte)(((float)Alpha * (float)InfluenceAlpha) / 255f) : this.Alpha))
};
BR2 = new float[]
{
VertexColorRB.R / 255f,
VertexColorRB.G / 255f,
VertexColorRB.B / 255f,
MixColors(VertexColorRB.A,(InfluencedAlpha ? (byte)(((float)Alpha * (float)InfluenceAlpha) / 255f) : this.Alpha))
};
BL2 = new float[]
{
VertexColorLB.R / 255f,
VertexColorLB.G / 255f,
VertexColorLB.B / 255f,
MixColors(VertexColorLB.A, (InfluencedAlpha ? (byte)(((float)Alpha * (float)InfluenceAlpha) / 255f) : this.Alpha))
};
return new float[][] { TL2, TR2, BR2, BL2 };
}
}
}

View File

@ -0,0 +1,151 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using LibEveryFileExplorer.Collections;
using System.IO;
using Tao.OpenGl;
namespace _3DS.NintendoWare.LYT
{
public class txt1 : pan1
{
public txt1(EndianBinaryReader er)
: base(er)
{
long baseoffset = er.BaseStream.Position - 0x4C;
NrCharacters = er.ReadUInt16();
NrCharacters2 = er.ReadUInt16();
MaterialId = er.ReadUInt16();
FontId = er.ReadUInt16();
PositionType = er.ReadByte();
TextAlignment = er.ReadByte();
TextFlags = er.ReadByte();
Padding = er.ReadByte();
StringOffset = er.ReadUInt32();
TopColor = er.ReadColor8();
BottomColor = er.ReadColor8();
FontSize = er.ReadVector2();
CharSize = er.ReadSingle();
LineSize = er.ReadSingle();
er.BaseStream.Position = baseoffset + StringOffset;
Text = er.ReadStringNT(Encoding.Unicode);
er.BaseStream.Position = baseoffset + SectionSize;
}
public UInt16 NrCharacters;
public UInt16 NrCharacters2;//?
public UInt16 MaterialId;
public UInt16 FontId;
public Byte PositionType;
public Byte TextAlignment;
public Byte TextFlags;
public Byte Padding;
public UInt32 StringOffset;
public Color TopColor;
public Color BottomColor;
public Vector2 FontSize;
public Single CharSize;
public Single LineSize;
public String Text;
public override void Render(CLYT Layout, CLIM[] Textures, int InfluenceAlpha)
{
Gl.glPushMatrix();
{
SetupMaterial(Layout, MaterialId);
Gl.glMatrixMode(Gl.GL_MODELVIEW);
Gl.glTranslatef(Translation.X, Translation.Y, Translation.Z);
Gl.glRotatef(Rotation.X, 1, 0, 0);
Gl.glRotatef(Rotation.Y, 0, 1, 0);
Gl.glRotatef(Rotation.Z, 0, 0, 1);
Gl.glScalef(Scale.X, Scale.Y, 1);
Gl.glPushMatrix();
{
Gl.glTranslatef(-0.5f * Size.X * (float)HAlignment, -0.5f * Size.Y * (-(float)VAlignment), 0);
float[,] Vertex2 = SetupRect();
float[][] VtxColor = SetupVtxColors(InfluenceAlpha);
Gl.glBegin(Gl.GL_QUADS);
/*for (int o = 0; o < TexCoordEntries.Length; o++)
{
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0 + o,
TexCoordEntries[o].TexCoordLT.X, TexCoordEntries[o].TexCoordLT.Y);
}
if (TexCoordEntries.Length == 0)*/ Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 0, 0);
Gl.glColor4f(VtxColor[0][0], VtxColor[0][1], VtxColor[0][2], VtxColor[0][3]);
Gl.glVertex3f(Vertex2[0, 0], Vertex2[0, 1], 0);
/*for (int o = 0; o < TexCoordEntries.Length; o++)
{
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0 + o,
TexCoordEntries[o].TexCoordRT.X, TexCoordEntries[o].TexCoordRT.Y);
}
if (TexCoordEntries.Length == 0)*/ Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 1, 0);
Gl.glColor4f(VtxColor[1][0], VtxColor[1][1], VtxColor[1][2], VtxColor[1][3]);
Gl.glVertex3f(Vertex2[1, 0], Vertex2[1, 1], 0);
/*for (int o = 0; o < TexCoordEntries.Length; o++)
{
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0 + o,
TexCoordEntries[o].TexCoordRB.X, TexCoordEntries[o].TexCoordRB.Y);
}
if (TexCoordEntries.Length == 0)*/ Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 1, 1);
Gl.glColor4f(VtxColor[2][0], VtxColor[2][1], VtxColor[2][2], VtxColor[2][3]);
Gl.glVertex3f(Vertex2[2, 0], Vertex2[2, 1], 0);
/*for (int o = 0; o < TexCoordEntries.Length; o++)
{
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0 + o,
TexCoordEntries[o].TexCoordLB.X, TexCoordEntries[o].TexCoordLB.Y);
}
if (TexCoordEntries.Length == 0)*/Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 0, 1);
Gl.glColor4f(VtxColor[3][0], VtxColor[3][1], VtxColor[3][2], VtxColor[3][3]);
Gl.glVertex3f(Vertex2[3, 0], Vertex2[3, 1], 0);
Gl.glEnd();
}
Gl.glPopMatrix();
foreach (pan1 p in Children)
{
p.Render(Layout, Textures, InfluencedAlpha ? (int)((float)(Alpha * InfluenceAlpha) / 255f) : Alpha);
}
}
Gl.glPopMatrix();
}
private float[][] SetupVtxColors(int InfluenceAlpha)
{
float[] TL2;
float[] TR2;
float[] BL2;
float[] BR2;
TL2 = new float[]
{
TopColor.R / 255f,
TopColor.G / 255f,
TopColor.B / 255f,
MixColors(TopColor.A, (InfluencedAlpha ? (byte)(((float)Alpha * (float)InfluenceAlpha) / 255f) : this.Alpha))
};
TR2 = new float[]
{
TopColor.R / 255f,
TopColor.G / 255f,
TopColor.B / 255f,
MixColors(TopColor.A, (InfluencedAlpha ? (byte)(((float)Alpha * (float)InfluenceAlpha) / 255f) : this.Alpha))
};
BR2 = new float[]
{
BottomColor.R / 255f,
BottomColor.G / 255f,
BottomColor.B / 255f,
MixColors(BottomColor.A,(InfluencedAlpha ? (byte)(((float)Alpha * (float)InfluenceAlpha) / 255f) : this.Alpha))
};
BL2 = new float[]
{
BottomColor.R / 255f,
BottomColor.G / 255f,
BottomColor.B / 255f,
MixColors(BottomColor.A, (InfluencedAlpha ? (byte)(((float)Alpha * (float)InfluenceAlpha) / 255f) : this.Alpha))
};
return new float[][] { TL2, TR2, BR2, BL2 };
}
}
}

View File

@ -0,0 +1,468 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Drawing;
using LibEveryFileExplorer.Collections;
using Tao.OpenGl;
namespace _3DS.NintendoWare.LYT
{
public class wnd1 : pan1
{
public enum WindowKind
{
Around = 0,
Horizontal = 1,
HorizontalNoContent = 2
}
public wnd1(EndianBinaryReader er)
: base(er)
{
long basepos = er.BaseStream.Position - 0x4C;
InflationLeft = er.ReadUInt16() / 16f;
InflationRight = er.ReadUInt16() / 16f;
InflationTop = er.ReadUInt16() / 16f;
InflationBottom = er.ReadUInt16() / 16f;
FrameSizeLeft = er.ReadUInt16();
FrameSizeRight = er.ReadUInt16();
FrameSizeTop = er.ReadUInt16();
FrameSizeBottom = er.ReadUInt16();
NrFrames = er.ReadByte();
byte tmp = er.ReadByte();
UseLTMaterial = (tmp & 1) == 1;
UseVtxColorForAllWindow = (tmp & 2) == 2;
Kind = (WindowKind)((tmp >> 2) & 3);
DontDrawContent = (tmp & 8) == 16;
Padding = er.ReadUInt16();
ContentOffset = er.ReadUInt32();
FrameOffsetTableOffset = er.ReadUInt32();
er.BaseStream.Position = basepos + ContentOffset;
Content = new WindowContent(er);
er.BaseStream.Position = basepos + FrameOffsetTableOffset;
WindowFrameOffsets = er.ReadUInt32s(NrFrames);
WindowFrames = new WindowFrame[NrFrames];
for (int i = 0; i < NrFrames; i++)
{
er.BaseStream.Position = basepos + WindowFrameOffsets[i];
WindowFrames[i] = new WindowFrame(er);
}
er.BaseStream.Position = basepos + SectionSize;
}
public float InflationLeft;
public float InflationRight;
public float InflationTop;
public float InflationBottom;
public UInt16 FrameSizeLeft;
public UInt16 FrameSizeRight;
public UInt16 FrameSizeTop;
public UInt16 FrameSizeBottom;
public Byte NrFrames;
//Flags:
//0:
public Boolean UseLTMaterial;
//1:
public Boolean UseVtxColorForAllWindow;
//2-3:
public WindowKind Kind;
//4:
public Boolean DontDrawContent;
//End Flags;
public UInt16 Padding;
public UInt32 ContentOffset;
public UInt32 FrameOffsetTableOffset;
public WindowContent Content;
public class WindowContent
{
public WindowContent(EndianBinaryReader er)
{
VertexColorLT = er.ReadColor8();
VertexColorRT = er.ReadColor8();
VertexColorLB = er.ReadColor8();
VertexColorRB = er.ReadColor8();
MaterialId = er.ReadUInt16();
NrTexCoordEntries = er.ReadUInt16();
TexCoordEntries = new TexCoord[NrTexCoordEntries];
for (int i = 0; i < NrTexCoordEntries; i++)
{
TexCoordEntries[i] = new TexCoord(er);
}
}
public Color VertexColorLT;
public Color VertexColorRT;
public Color VertexColorLB;
public Color VertexColorRB;
public UInt16 MaterialId;
public UInt16 NrTexCoordEntries;
public TexCoord[] TexCoordEntries;
public class TexCoord
{
public TexCoord(EndianBinaryReader er)
{
TexCoordLT = er.ReadVector2();
TexCoordRT = er.ReadVector2();
TexCoordLB = er.ReadVector2();
TexCoordRB = er.ReadVector2();
}
public Vector2 TexCoordLT;
public Vector2 TexCoordRT;
public Vector2 TexCoordLB;
public Vector2 TexCoordRB;
}
}
public UInt32[] WindowFrameOffsets;
public WindowFrame[] WindowFrames;
public class WindowFrame
{
public enum TexFlip
{
None = 0,
FlipH = 1,
FlipV = 2,
Rotate90 = 3,
Rotate180 = 4,
Rotate270 = 5
}
public WindowFrame(EndianBinaryReader er)
{
MaterialId = er.ReadUInt16();
TextureFlip = (TexFlip)er.ReadByte();
Padding = er.ReadByte();
}
public UInt16 MaterialId;
public TexFlip TextureFlip;
public Byte Padding;
}
public override void Render(CLYT Layout, CLIM[] Textures, int InfluenceAlpha)
{
Gl.glPushMatrix();
{
Gl.glMatrixMode(Gl.GL_MODELVIEW);
Gl.glTranslatef(Translation.X, Translation.Y, Translation.Z);
Gl.glRotatef(Rotation.X, 1, 0, 0);
Gl.glRotatef(Rotation.Y, 0, 1, 0);
Gl.glRotatef(Rotation.Z, 0, 0, 1);
Gl.glScalef(Scale.X, Scale.Y, 1);
Gl.glPushMatrix();
{
//Translate to origin
Gl.glTranslatef(-0.5f * Size.X * (float)HAlignment, -0.5f * Size.Y * (-(float)VAlignment), 0);
switch (Kind)
{
case WindowKind.Around:
if (NrFrames == 1)//1 texture for all
{
mat1.MaterialEntry m = Layout.Materials.Materials[WindowFrames[0].MaterialId];
if (m.TexMaps.Length == 0) RenderContent(Layout, InfluenceAlpha, Size.X, Size.Y);
else
{
var t = Textures[m.TexMaps[0].TexIndex];
Gl.glPushMatrix();
{
Gl.glTranslatef(t.Image.Width, -t.Image.Height, 0);
RenderContent(Layout, InfluenceAlpha, Size.X - t.Image.Width * 2, Size.Y - t.Image.Height * 2);
}
Gl.glPopMatrix();
// _________
//|______| |
//| | | |
//| |___|__|
//|__|______|
//Top Left
SetupMaterial(Layout, WindowFrames[0].MaterialId);
float[,] Vertex2 = SetupRect(Size.X - t.Image.Width, t.Image.Height);
Gl.glBegin(Gl.GL_QUADS);
Gl.glColor4f(1, 1, 1, (InfluencedAlpha ? (byte)(((float)Alpha * (float)InfluenceAlpha) / 255f) : this.Alpha) / 255f);
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 0, 0);
Gl.glVertex3f(Vertex2[0, 0], Vertex2[0, 1], 0);
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, (Size.X - t.Image.Width) / t.Image.Width, 0);
Gl.glVertex3f(Vertex2[1, 0], Vertex2[1, 1], 0);
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, (Size.X - t.Image.Width) / t.Image.Width, 1);
Gl.glVertex3f(Vertex2[2, 0], Vertex2[2, 1], 0);
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 0, 1);
Gl.glVertex3f(Vertex2[3, 0], Vertex2[3, 1], 0);
Gl.glEnd();
//Top Right
Gl.glPushMatrix();
{
Gl.glTranslatef(Size.X - t.Image.Width, 0, 0);
Vertex2 = SetupRect(t.Image.Width, Size.Y - t.Image.Height);
Gl.glBegin(Gl.GL_QUADS);
Gl.glColor4f(1, 1, 1, (InfluencedAlpha ? (byte)(((float)Alpha * (float)InfluenceAlpha) / 255f) : this.Alpha) / 255f);
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 1, 0);
Gl.glVertex3f(Vertex2[0, 0], Vertex2[0, 1], 0);
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 0, 0);
Gl.glVertex3f(Vertex2[1, 0], Vertex2[1, 1], 0);
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 0, (Size.Y - t.Image.Height) / t.Image.Height);
Gl.glVertex3f(Vertex2[2, 0], Vertex2[2, 1], 0);
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 1, (Size.Y - t.Image.Height) / t.Image.Height);
Gl.glVertex3f(Vertex2[3, 0], Vertex2[3, 1], 0);
Gl.glEnd();
}
Gl.glPopMatrix();
//Bottom Right
Gl.glPushMatrix();
{
Gl.glTranslatef(t.Image.Width, -(Size.Y - t.Image.Height), 0);
Vertex2 = SetupRect(Size.X - t.Image.Width, t.Image.Height);
Gl.glBegin(Gl.GL_QUADS);
Gl.glColor4f(1, 1, 1, (InfluencedAlpha ? (byte)(((float)Alpha * (float)InfluenceAlpha) / 255f) : this.Alpha) / 255f);
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, (Size.X - t.Image.Width) / t.Image.Width, 1);
Gl.glVertex3f(Vertex2[0, 0], Vertex2[0, 1], 0);
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 0, 1);
Gl.glVertex3f(Vertex2[1, 0], Vertex2[1, 1], 0);
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 0, 0);
Gl.glVertex3f(Vertex2[2, 0], Vertex2[2, 1], 0);
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, (Size.X - t.Image.Width) / t.Image.Width, 0);
Gl.glVertex3f(Vertex2[3, 0], Vertex2[3, 1], 0);
Gl.glEnd();
}
Gl.glPopMatrix();
//Bottom Left
Gl.glPushMatrix();
{
Gl.glTranslatef(0, -t.Image.Height, 0);
Vertex2 = SetupRect(t.Image.Width, Size.Y - t.Image.Height);
Gl.glBegin(Gl.GL_QUADS);
Gl.glColor4f(1, 1, 1, (InfluencedAlpha ? (byte)(((float)Alpha * (float)InfluenceAlpha) / 255f) : this.Alpha) / 255f);
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 0, (Size.Y - t.Image.Height) / t.Image.Height);
Gl.glVertex3f(Vertex2[0, 0], Vertex2[0, 1], 0);
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 1, (Size.Y - t.Image.Height) / t.Image.Height);
Gl.glVertex3f(Vertex2[1, 0], Vertex2[1, 1], 0);
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 1, 0);
Gl.glVertex3f(Vertex2[2, 0], Vertex2[2, 1], 0);
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 0, 0);
Gl.glVertex3f(Vertex2[3, 0], Vertex2[3, 1], 0);
Gl.glEnd();
}
Gl.glPopMatrix();
}
}
else if (NrFrames == 4)//Corners
{
var t1 = Textures[Layout.Materials.Materials[WindowFrames[0].MaterialId].TexMaps[0].TexIndex];
var t2 = Textures[Layout.Materials.Materials[WindowFrames[1].MaterialId].TexMaps[0].TexIndex];
var t3 = Textures[Layout.Materials.Materials[WindowFrames[2].MaterialId].TexMaps[0].TexIndex];
var t4 = Textures[Layout.Materials.Materials[WindowFrames[3].MaterialId].TexMaps[0].TexIndex];
Gl.glPushMatrix();
{
Gl.glTranslatef(t4.Image.Width, -t1.Image.Height, 0);
RenderContent(Layout, InfluenceAlpha, Size.X - (t4.Image.Width + t2.Image.Width), Size.Y - (t1.Image.Height + t3.Image.Height));
}
Gl.glPopMatrix();
// _________
//|______| |
//| | | |
//| |___|__|
//|__|______|
//Top Left
SetupMaterial(Layout, WindowFrames[0].MaterialId);
float[,] Vertex2 = SetupRect(Size.X - t2.Image.Width, t1.Image.Height);
Gl.glBegin(Gl.GL_QUADS);
Gl.glColor4f(1, 1, 1, (InfluencedAlpha ? (byte)(((float)Alpha * (float)InfluenceAlpha) / 255f) : this.Alpha) / 255f);
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 0, 0);
Gl.glVertex3f(Vertex2[0, 0], Vertex2[0, 1], 0);
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, (Size.X - t2.Image.Width) / t1.Image.Width, 0);
Gl.glVertex3f(Vertex2[1, 0], Vertex2[1, 1], 0);
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, (Size.X - t2.Image.Width) / t1.Image.Width, 1);
Gl.glVertex3f(Vertex2[2, 0], Vertex2[2, 1], 0);
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 0, 1);
Gl.glVertex3f(Vertex2[3, 0], Vertex2[3, 1], 0);
Gl.glEnd();
//Top Right
Gl.glPushMatrix();
{
Gl.glTranslatef(Size.X - t2.Image.Width, 0, 0);
SetupMaterial(Layout, WindowFrames[1].MaterialId);
Vertex2 = SetupRect(t2.Image.Width, Size.Y - t3.Image.Height);
Gl.glBegin(Gl.GL_QUADS);
Gl.glColor4f(1, 1, 1, (InfluencedAlpha ? (byte)(((float)Alpha * (float)InfluenceAlpha) / 255f) : this.Alpha) / 255f);
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 0, 0);
Gl.glVertex3f(Vertex2[0, 0], Vertex2[0, 1], 0);
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 1, 0);
Gl.glVertex3f(Vertex2[1, 0], Vertex2[1, 1], 0);
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 1, (Size.Y - t3.Image.Height) / t2.Image.Height);
Gl.glVertex3f(Vertex2[2, 0], Vertex2[2, 1], 0);
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 0, (Size.Y - t3.Image.Height) / t2.Image.Height);
Gl.glVertex3f(Vertex2[3, 0], Vertex2[3, 1], 0);
Gl.glEnd();
}
Gl.glPopMatrix();
//Bottom Right
Gl.glPushMatrix();
{
Gl.glTranslatef(t4.Image.Width, -(Size.Y - t3.Image.Height), 0);
SetupMaterial(Layout, WindowFrames[2].MaterialId);
Vertex2 = SetupRect(Size.X - t4.Image.Width, t3.Image.Height);
Gl.glBegin(Gl.GL_QUADS);
Gl.glColor4f(1, 1, 1, (InfluencedAlpha ? (byte)(((float)Alpha * (float)InfluenceAlpha) / 255f) : this.Alpha) / 255f);
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, (Size.X - t2.Image.Width) / t3.Image.Width, 0);
Gl.glVertex3f(Vertex2[0, 0], Vertex2[0, 1], 0);
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 0, 0);
Gl.glVertex3f(Vertex2[1, 0], Vertex2[1, 1], 0);
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 0, 1);
Gl.glVertex3f(Vertex2[2, 0], Vertex2[2, 1], 0);
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, (Size.X - t2.Image.Width) / t3.Image.Width, 1);
Gl.glVertex3f(Vertex2[3, 0], Vertex2[3, 1], 0);
Gl.glEnd();
}
Gl.glPopMatrix();
//Bottom Left
Gl.glPushMatrix();
{
Gl.glTranslatef(0, -t1.Image.Height, 0);
SetupMaterial(Layout, WindowFrames[3].MaterialId);
Vertex2 = SetupRect(t4.Image.Width, Size.Y - t1.Image.Height);
Gl.glBegin(Gl.GL_QUADS);
Gl.glColor4f(1, 1, 1, (InfluencedAlpha ? (byte)(((float)Alpha * (float)InfluenceAlpha) / 255f) : this.Alpha) / 255f);
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 1, -(Size.Y - t1.Image.Height) / t4.Image.Height);
Gl.glVertex3f(Vertex2[0, 0], Vertex2[0, 1], 0);
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 0, -(Size.Y - t1.Image.Height) / t4.Image.Height);
Gl.glVertex3f(Vertex2[1, 0], Vertex2[1, 1], 0);
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 0, 1);
Gl.glVertex3f(Vertex2[2, 0], Vertex2[2, 1], 0);
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 1, 1);
Gl.glVertex3f(Vertex2[3, 0], Vertex2[3, 1], 0);
Gl.glEnd();
}
Gl.glPopMatrix();
}
else if (NrFrames == 8)//all
{
RenderContent(Layout, InfluenceAlpha, Size.X, Size.Y);
}
else
{
RenderContent(Layout, InfluenceAlpha, Size.X, Size.Y);
//not possible?
}
break;
default:
break;
}
}
Gl.glPopMatrix();
foreach (pan1 p in Children)
{
p.Render(Layout, Textures, InfluencedAlpha ? (int)((float)(Alpha * InfluenceAlpha) / 255f) : Alpha);
}
}
Gl.glPopMatrix();
}
private float[][] SetupVtxColors(int InfluenceAlpha)
{
float[] TL2;
float[] TR2;
float[] BL2;
float[] BR2;
TL2 = new float[]
{
Content.VertexColorLT.R / 255f,
Content.VertexColorLT.G / 255f,
Content.VertexColorLT.B / 255f,
MixColors(Content.VertexColorLT.A, (InfluencedAlpha ? (byte)(((float)Alpha * (float)InfluenceAlpha) / 255f) : this.Alpha))
};
TR2 = new float[]
{
Content.VertexColorRT.R / 255f,
Content.VertexColorRT.G / 255f,
Content.VertexColorRT.B / 255f,
MixColors(Content.VertexColorRT.A, (InfluencedAlpha ? (byte)(((float)Alpha * (float)InfluenceAlpha) / 255f) : this.Alpha))
};
BR2 = new float[]
{
Content.VertexColorRB.R / 255f,
Content.VertexColorRB.G / 255f,
Content.VertexColorRB.B / 255f,
MixColors(Content.VertexColorRB.A,(InfluencedAlpha ? (byte)(((float)Alpha * (float)InfluenceAlpha) / 255f) : this.Alpha))
};
BL2 = new float[]
{
Content.VertexColorLB.R / 255f,
Content.VertexColorLB.G / 255f,
Content.VertexColorLB.B / 255f,
MixColors(Content.VertexColorLB.A, (InfluencedAlpha ? (byte)(((float)Alpha * (float)InfluenceAlpha) / 255f) : this.Alpha))
};
return new float[][] { TL2, TR2, BR2, BL2 };
}
private void RenderContent(CLYT Layout, int InfluenceAlpha, float Width, float Height)
{
SetupMaterial(Layout, Content.MaterialId);
float[,] Vertex2 = SetupRect(Width, Height);
float[][] VtxColor = SetupVtxColors(InfluenceAlpha);
Gl.glBegin(Gl.GL_QUADS);
for (int o = 0; o < Content.TexCoordEntries.Length; o++)
{
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0 + o,
Content.TexCoordEntries[o].TexCoordLT.X, Content.TexCoordEntries[o].TexCoordLT.Y);
}
if (Content.TexCoordEntries.Length == 0) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 0, 0);
Gl.glColor4f(VtxColor[0][0], VtxColor[0][1], VtxColor[0][2], VtxColor[0][3]);
Gl.glVertex3f(Vertex2[0, 0], Vertex2[0, 1], 0);
for (int o = 0; o < Content.TexCoordEntries.Length; o++)
{
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0 + o,
Content.TexCoordEntries[o].TexCoordRT.X, Content.TexCoordEntries[o].TexCoordRT.Y);
}
if (Content.TexCoordEntries.Length == 0) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 1, 0);
Gl.glColor4f(VtxColor[1][0], VtxColor[1][1], VtxColor[1][2], VtxColor[1][3]);
Gl.glVertex3f(Vertex2[1, 0], Vertex2[1, 1], 0);
for (int o = 0; o < Content.TexCoordEntries.Length; o++)
{
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0 + o,
Content.TexCoordEntries[o].TexCoordRB.X, Content.TexCoordEntries[o].TexCoordRB.Y);
}
if (Content.TexCoordEntries.Length == 0) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 1, 1);
Gl.glColor4f(VtxColor[2][0], VtxColor[2][1], VtxColor[2][2], VtxColor[2][3]);
Gl.glVertex3f(Vertex2[2, 0], Vertex2[2, 1], 0);
for (int o = 0; o < Content.TexCoordEntries.Length; o++)
{
Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0 + o,
Content.TexCoordEntries[o].TexCoordLB.X, Content.TexCoordEntries[o].TexCoordLB.Y);
}
if (Content.TexCoordEntries.Length == 0) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, 0, 1);
Gl.glColor4f(VtxColor[3][0], VtxColor[3][1], VtxColor[3][2], VtxColor[3][3]);
Gl.glVertex3f(Vertex2[3, 0], Vertex2[3, 1], 0);
Gl.glEnd();
}
}
}

View File

@ -0,0 +1,772 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LibEveryFileExplorer.Files;
using System.Drawing;
using System.IO;
using _3DS.DSP;
using LibEveryFileExplorer.SND;
using CommonFiles;
using LibEveryFileExplorer.IO;
namespace _3DS.NintendoWare.SND
{
public class CSTM : FileFormat<CSTM.CSTMIdentifier>, IConvertable, IFileCreatable, IViewable, IWriteable
{
public CSTM()
{
Header = new CSTMHeader(false);
Info = new INFO(true);
Data = new DATA();
}
public CSTM(byte[] Data)
{
EndianBinaryReader er = new EndianBinaryReader(new MemoryStream(Data), Endianness.LittleEndian);
try
{
Header = new CSTMHeader(er);
er.BaseStream.Position = Header.Sections[0].Offset;
Info = new INFO(er);
if (Header.NrSections > 2 && Header.Sections[1].Id == 0x4001)
{
er.BaseStream.Position = Header.Sections[1].Offset;
Seek = new SEEK(er);
er.BaseStream.Position = Header.Sections[2].Offset;
this.Data = new DATA(er);
}
else
{
er.BaseStream.Position = Header.Sections[1].Offset;
this.Data = new DATA(er);
}
}
finally
{
er.Close();
}
}
public string GetSaveDefaultFileFilter()
{
return "CTR Stream (*.bcstm)|*.bcstm";
}
public byte[] Write()
{
MemoryStream m = new MemoryStream();
EndianBinaryWriter er = new EndianBinaryWriter(m, Endianness.LittleEndian);
Header.Write(er);
long curpos = er.BaseStream.Position;
er.BaseStream.Position = 0x18;
er.Write((uint)curpos);
er.BaseStream.Position = curpos;
Info.Write(er);
long length = er.BaseStream.Position - curpos;
curpos = er.BaseStream.Position;
er.BaseStream.Position = 0x1C;
er.Write((uint)length);
er.BaseStream.Position = 0x24;
er.Write((uint)curpos);
er.BaseStream.Position = curpos;
if (Seek != null)
{
Seek.Write(er);
length = er.BaseStream.Position - curpos;
curpos = er.BaseStream.Position;
er.BaseStream.Position = 0x28;
er.Write((uint)length);
er.BaseStream.Position = 0x30;
er.Write((uint)curpos);
er.BaseStream.Position = curpos;
Data.Write(er);
length = er.BaseStream.Position - curpos;
curpos = er.BaseStream.Position;
er.BaseStream.Position = 0x34;
er.Write((uint)length);
er.BaseStream.Position = curpos;
}
else
{
Data.Write(er);
length = er.BaseStream.Position - curpos;
curpos = er.BaseStream.Position;
er.BaseStream.Position = 0x28;
er.Write((uint)length);
er.BaseStream.Position = curpos;
}
curpos = er.BaseStream.Position;
er.BaseStream.Position = 0xC;
er.Write((uint)curpos);
byte[] result = m.ToArray();
er.Close();
return result;
}
public System.Windows.Forms.Form GetDialog()
{
return new CommonFiles.UI.WAVEPlayer(ToWave());
}
public string GetConversionFileFilters()
{
return "Wave File (*.wav)|*.wav";
}
public bool Convert(int FilterIndex, String Path)
{
switch (FilterIndex)
{
case 0:
byte[] Data = ToWave().Write();
File.Create(Path).Close();
File.WriteAllBytes(Path, Data);
return true;
default:
return false;
}
}
public bool CreateFromFile()
{
System.Windows.Forms.OpenFileDialog f = new System.Windows.Forms.OpenFileDialog();
f.Filter = WAV.Identifier.GetFileFilter();
if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK
&& f.FileName.Length > 0)
{
WAV w = new WAV(File.ReadAllBytes(f.FileName));
Header = new CSTMHeader(false);
Info = new INFO(true);
Data = new DATA();
Info.StreamInfo.SampleRate = w.Wave.FMT.SampleRate;
Info.StreamInfo.NrChannels = (byte)w.Wave.FMT.NrChannel;
if (w.Wave.FMT.AudioFormat == WAV.WaveData.FMTBlock.WaveFormat.WAVE_FORMAT_PCM && w.Wave.FMT.BitsPerSample == 16)
{
Info.StreamInfo.Format = 1;
Info.StreamInfo.SeekInterval = 0x1000;
Info.StreamInfo.LoopEnd = (uint)((w.Wave.DATA.Data.Length / w.Wave.FMT.NrChannel) / 2);
Info.StreamInfo.BlockSize = 0x2000;
Info.StreamInfo.BlockNrSamples = 0x2000 / 2;
Info.StreamInfo.NrBlocks = (uint)((w.Wave.DATA.Data.Length / w.Wave.FMT.NrChannel) / 0x2000) + 1;
Info.StreamInfo.LastBlockSize = (uint)((w.Wave.DATA.Data.Length / w.Wave.FMT.NrChannel) % 0x2000);
Info.StreamInfo.LastBlockPaddedSize = Info.StreamInfo.LastBlockSize;
while ((Info.StreamInfo.LastBlockPaddedSize % 4) != 0) Info.StreamInfo.LastBlockPaddedSize++;
Info.StreamInfo.LastBlockNrSamples = Info.StreamInfo.LastBlockSize / 2;
Info.TrackInfoReferenceTable.NrEntries = 1;
Info.TrackInfoReferenceTable.Entries = new INFO.SectionInfo[] { new INFO.SectionInfo(0x4101) };
Info.TrackInfos = new INFO.TrackInfo[] { new INFO.TrackInfo() };
Info.ChannelInfoReferenceTable.NrEntries = 2;
Info.ChannelInfoReferenceTable.Entries = new INFO.SectionInfo[] { new INFO.SectionInfo(0x4102), new INFO.SectionInfo(0x4102) };
Info.ChannelInfos = new INFO.ChannelInfo[] { new INFO.ChannelInfo(), new INFO.ChannelInfo() };
byte[][] channels = new byte[w.Wave.FMT.NrChannel][];
for (int i = 0; i < w.Wave.FMT.NrChannel; i++)
{
channels[i] = w.GetChannelData(i);
}
Data.Data = new byte[(Info.StreamInfo.NrBlocks - 1) * 0x2000 * w.Wave.FMT.NrChannel + Info.StreamInfo.LastBlockPaddedSize * w.Wave.FMT.NrChannel];
int offs = 0;
for (int i = 0; i < Info.StreamInfo.NrBlocks - 1; i++)
{
for (int j = 0; j < w.Wave.FMT.NrChannel; j++)
{
Array.Copy(channels[j], i * 0x2000, Data.Data, offs, 0x2000);
offs += 0x2000;
}
}
for (int j = 0; j < w.Wave.FMT.NrChannel; j++)
{
Array.Copy(channels[j], channels[j].Length - Info.StreamInfo.LastBlockSize, Data.Data, offs, Info.StreamInfo.LastBlockSize);
offs += (int)Info.StreamInfo.LastBlockSize;
while ((offs % 4) != 0) offs++;
}
return true;
}
else return false;
}
return false;
}
public CSTMHeader Header;
public class CSTMHeader
{
public CSTMHeader(bool HasSeek)
{
Signature = "CSTM";
Endianness = 0xFEFF;
HeaderSize = 0x40;
Version = 0x02000000;
NrSections = (uint)(HasSeek ? 3 : 2);
if (HasSeek) Sections = new SectionInfo[] { new SectionInfo(0x4000), new SectionInfo(0x4001), new SectionInfo(0x4002) };
else Sections = new SectionInfo[] { new SectionInfo(0x4000), new SectionInfo(0x4002) };
}
public CSTMHeader(EndianBinaryReader er)
{
Signature = er.ReadString(Encoding.ASCII, 4);
if (Signature != "CSTM") throw new SignatureNotCorrectException(Signature, "CSTM", er.BaseStream.Position - 4);
Endianness = er.ReadUInt16();
HeaderSize = er.ReadUInt16();
Version = er.ReadUInt32();
FileSize = er.ReadUInt32();
NrSections = er.ReadUInt32();
Sections = new SectionInfo[NrSections];
for (int i = 0; i < NrSections; i++) Sections[i] = new SectionInfo(er);
}
public void Write(EndianBinaryWriter er)
{
er.Write(Signature, Encoding.ASCII, false);
er.Write(Endianness);
er.Write(HeaderSize);
er.Write(Version);
er.Write((uint)0);
er.Write(NrSections);
foreach (var v in Sections) v.Write(er);
while ((er.BaseStream.Position % 32) != 0) er.Write((byte)0);
}
public String Signature;
public UInt16 Endianness;
public UInt16 HeaderSize;
public UInt32 Version;
public UInt32 FileSize;
public UInt32 NrSections;
public SectionInfo[] Sections;
public class SectionInfo
{
public SectionInfo(uint Id) { this.Id = Id; }
public SectionInfo(EndianBinaryReader er)
{
Id = er.ReadUInt32();
Offset = er.ReadUInt32();
Size = er.ReadUInt32();
}
public void Write(EndianBinaryWriter er)
{
er.Write(Id);
er.Write(Offset);
er.Write(Size);
}
public UInt32 Id;//0x4000 = INFO, 0x4001 = SEEK, 0x4002 = DATA
public UInt32 Offset;
public UInt32 Size;
}
}
public INFO Info;
public class INFO
{
public INFO(bool HasTracks)
{
Signature = "INFO";
StreamSoundInfoReference = new SectionInfo(0x4100);
TrackInfoReference = new SectionInfo((uint)(HasTracks ? 0x101 : 0));
ChannelInfoReference = new SectionInfo(0x101);
StreamInfo = new StreamSoundInfo();
if (HasTracks) TrackInfoReferenceTable = new ReferenceTable();
ChannelInfoReferenceTable = new ReferenceTable();
}
public INFO(EndianBinaryReader er)
{
Signature = er.ReadString(Encoding.ASCII, 4);
if (Signature != "INFO") throw new SignatureNotCorrectException(Signature, "INFO", er.BaseStream.Position - 4);
SectionSize = er.ReadUInt32();
long offs = er.BaseStream.Position;
StreamSoundInfoReference = new SectionInfo(er);
TrackInfoReference = new SectionInfo(er);
ChannelInfoReference = new SectionInfo(er);
er.BaseStream.Position = offs + StreamSoundInfoReference.Offset;
StreamInfo = new StreamSoundInfo(er);
if ((int)TrackInfoReference.Offset != -1)
{
er.BaseStream.Position = offs + TrackInfoReference.Offset;
TrackInfoReferenceTable = new ReferenceTable(er);
}
er.BaseStream.Position = offs + ChannelInfoReference.Offset;
ChannelInfoReferenceTable = new ReferenceTable(er);
int i;
if ((int)TrackInfoReference.Offset != -1)
{
TrackInfos = new TrackInfo[TrackInfoReferenceTable.NrEntries];
i = 0;
foreach (var v in TrackInfoReferenceTable.Entries)
{
er.BaseStream.Position = offs + TrackInfoReference.Offset + v.Offset;
TrackInfos[i] = new TrackInfo(er);
i++;
}
}
ChannelInfos = new ChannelInfo[ChannelInfoReferenceTable.NrEntries];
i = 0;
foreach (var v in ChannelInfoReferenceTable.Entries)
{
er.BaseStream.Position = offs + ChannelInfoReference.Offset + v.Offset;
ChannelInfos[i] = new ChannelInfo(er);
i++;
}
if (StreamInfo.Format == 2)
{
CodecInfos = new DSPADPCMCodecInfo[ChannelInfoReferenceTable.NrEntries];
i = 0;
foreach (var v in ChannelInfos)
{
if ((int)v.CodecInfoOffset == -1) { i++; continue; }
er.BaseStream.Position = offs + ChannelInfoReference.Offset + ChannelInfoReferenceTable.Entries[i].Offset + v.CodecInfoOffset;
CodecInfos[i] = new DSPADPCMCodecInfo(er);
i++;
}
}
else
{
}
}
public void Write(EndianBinaryWriter er)
{
long basepos = er.BaseStream.Position;
er.Write(Signature, Encoding.ASCII, false);
er.Write((uint)0);
StreamSoundInfoReference.Write(er);
TrackInfoReference.Write(er);
ChannelInfoReference.Write(er);
long curpos = er.BaseStream.Position;
er.BaseStream.Position = basepos + 8;
er.Write((uint)(0x4100));
er.Write((uint)(curpos - basepos - 8));
er.BaseStream.Position = curpos;
StreamInfo.Write(er);
long trackreftableoffs = -1;
if (TrackInfoReferenceTable != null)
{
trackreftableoffs = curpos = er.BaseStream.Position;
er.BaseStream.Position = basepos + 16;
er.Write((uint)(0x101));
er.Write((uint)(curpos - basepos - 8));
er.BaseStream.Position = curpos;
TrackInfoReferenceTable.Write(er);
}
else
{
curpos = er.BaseStream.Position;
er.BaseStream.Position = basepos + 16;
er.Write((uint)(0));
er.Write((uint)(0xFFFFFFFF));
er.BaseStream.Position = curpos;
er.Write((uint)0x100);
er.Write((uint)0);
er.Write((uint)0xFFFFFFFF);
}
long chanreftableoffs = curpos = er.BaseStream.Position;
er.BaseStream.Position = basepos + 24;
er.Write((uint)(0x101));
er.Write((uint)(curpos - basepos - 8));
er.BaseStream.Position = curpos;
ChannelInfoReferenceTable.Write(er);
if (TrackInfoReferenceTable != null)
{
for (int i = 0; i < TrackInfos.Length; i++)
{
curpos = er.BaseStream.Position;
er.BaseStream.Position = trackreftableoffs + 4 + 8 * i;
er.Write((uint)(0x4101));
er.Write((uint)(curpos - trackreftableoffs));
er.BaseStream.Position = curpos;
TrackInfos[i].Write(er);
}
}
long[] chaninfooffs = new long[ChannelInfos.Length];
for (int i = 0; i < ChannelInfos.Length; i++)
{
curpos = er.BaseStream.Position;
er.BaseStream.Position = chanreftableoffs + 4 + 8 * i;
er.Write((uint)(0x4102));
er.Write((uint)(curpos - chanreftableoffs));
chaninfooffs[i] = er.BaseStream.Position = curpos;
ChannelInfos[i].Write(er);
}
if (StreamInfo.Format == 2)
{
for (int i = 0; i < ChannelInfos.Length; i++)
{
curpos = er.BaseStream.Position;
er.BaseStream.Position = chaninfooffs[i];
er.Write((uint)(0x300));
er.Write((uint)(curpos - chaninfooffs[i]));
er.BaseStream.Position = curpos;
CodecInfos[i].Write(er);
}
}
while ((er.BaseStream.Position % 32) != 0) er.Write((byte)0);
curpos = er.BaseStream.Position;
er.BaseStream.Position = basepos + 4;
er.Write((uint)(curpos - basepos));
er.BaseStream.Position = curpos;
}
public String Signature;
public UInt32 SectionSize;
public SectionInfo StreamSoundInfoReference;
public class SectionInfo
{
public SectionInfo(uint Id) { this.Id = Id; }
public SectionInfo(EndianBinaryReader er)
{
Id = er.ReadUInt32();
Offset = er.ReadUInt32();
}
public void Write(EndianBinaryWriter er)
{
er.Write(Id);
er.Write(Offset);
}
public UInt32 Id;
public UInt32 Offset;//Relative to start of the whole block, eventually including the number of entries
}
public SectionInfo TrackInfoReference;
public SectionInfo ChannelInfoReference;
public StreamSoundInfo StreamInfo;
public class StreamSoundInfo
{
public StreamSoundInfo()
{
NrChannels = 1;
SampleRate = 44100;
BlockSize = 0x2000;
LastBlockSize = 0x2000;
SeekEntrySize = 4;
//SeekInterval = 0x2000;
ReferenceSignature = 0x1F00;
DataBlockDataOffset = 0x18;
}
public StreamSoundInfo(EndianBinaryReader er)
{
Format = er.ReadByte();
Loop = er.ReadByte() == 1;
NrChannels = er.ReadByte();
er.ReadByte();//padding
SampleRate = er.ReadUInt32();
LoopStart = er.ReadUInt32();
LoopEnd = er.ReadUInt32();
NrBlocks = er.ReadUInt32();
BlockSize = er.ReadUInt32();
BlockNrSamples = er.ReadUInt32();
LastBlockSize = er.ReadUInt32();
LastBlockNrSamples = er.ReadUInt32();
LastBlockPaddedSize = er.ReadUInt32();
SeekEntrySize = er.ReadUInt32();
SeekInterval = er.ReadUInt32();
ReferenceSignature = er.ReadUInt32();
DataBlockDataOffset = er.ReadUInt32();
}
public void Write(EndianBinaryWriter er)
{
er.Write(Format);
er.Write((byte)(Loop ? 1 : 0));
er.Write(NrChannels);
er.Write((byte)0);
er.Write(SampleRate);
er.Write(LoopStart);
er.Write(LoopEnd);
er.Write(NrBlocks);
er.Write(BlockSize);
er.Write(BlockNrSamples);
er.Write(LastBlockSize);
er.Write(LastBlockNrSamples);
er.Write(LastBlockPaddedSize);
er.Write(SeekEntrySize);
er.Write(SeekInterval);
er.Write(ReferenceSignature);
er.Write(DataBlockDataOffset);
}
public Byte Format;
public bool Loop;
public Byte NrChannels;
public UInt32 SampleRate;
public UInt32 LoopStart;
public UInt32 LoopEnd;
public UInt32 NrBlocks;
public UInt32 BlockSize;
public UInt32 BlockNrSamples;
public UInt32 LastBlockSize;
public UInt32 LastBlockNrSamples;
public UInt32 LastBlockPaddedSize;
public UInt32 SeekEntrySize;
public UInt32 SeekInterval;//nr of samples between a seek entry
public UInt32 ReferenceSignature;
public UInt32 DataBlockDataOffset;//Including padding
}
public class ReferenceTable
{
public ReferenceTable() { Entries = new SectionInfo[0]; }
public ReferenceTable(EndianBinaryReader er)
{
NrEntries = er.ReadUInt32();
Entries = new SectionInfo[NrEntries];
for (int i = 0; i < NrEntries; i++)
{
Entries[i] = new SectionInfo(er);
}
}
public void Write(EndianBinaryWriter er)
{
er.Write(NrEntries);
for (int i = 0; i < NrEntries; i++)
{
Entries[i].Write(er);
}
}
public UInt32 NrEntries;
public SectionInfo[] Entries;
}
public ReferenceTable TrackInfoReferenceTable;
public TrackInfo[] TrackInfos;
public class TrackInfo
{
public TrackInfo()
{
Volume = 0x7F;
Pan = 0x40;
ChannelIndexTableSignature = 0x100;
ChannelIndexTableDataOffset = 0xC;
ChannelIndexTableNrEntries = 2;
ChannelIndexTableData = new byte[] { 0, 1 };
}
public TrackInfo(EndianBinaryReader er)
{
Volume = er.ReadByte();
Pan = er.ReadByte();
er.ReadUInt16();//padding
long curpos = er.BaseStream.Position;
ChannelIndexTableSignature = er.ReadUInt32();
ChannelIndexTableDataOffset = er.ReadUInt32();
ChannelIndexTableNrEntries = er.ReadUInt32();
er.BaseStream.Position = curpos + ChannelIndexTableDataOffset;
ChannelIndexTableData = er.ReadBytes((int)ChannelIndexTableNrEntries);
while ((er.BaseStream.Position % 4) != 0) er.ReadByte();
}
public void Write(EndianBinaryWriter er)
{
ChannelIndexTableNrEntries = (uint)ChannelIndexTableData.Length;
er.Write(Volume);
er.Write(Pan);
er.Write((ushort)0);
er.Write((uint)0x100);
er.Write((uint)0xC);
er.Write(ChannelIndexTableNrEntries);
er.Write(ChannelIndexTableData, 0, ChannelIndexTableData.Length);
while ((er.BaseStream.Position % 4) != 0) er.Write((byte)0);
}
public Byte Volume;
public Byte Pan;
public UInt32 ChannelIndexTableSignature;//0x100
public UInt32 ChannelIndexTableDataOffset;
public UInt32 ChannelIndexTableNrEntries;
public byte[] ChannelIndexTableData;
}
public ReferenceTable ChannelInfoReferenceTable;
public ChannelInfo[] ChannelInfos;
public class ChannelInfo
{
public ChannelInfo()
{
CodecInfoOffset = 0xFFFFFFFF;
}
public ChannelInfo(EndianBinaryReader er)
{
CodecSignature = er.ReadUInt32();
CodecInfoOffset = er.ReadUInt32();
}
public void Write(EndianBinaryWriter er)
{
er.Write(CodecSignature);
er.Write(CodecInfoOffset);
}
public UInt32 CodecSignature;
public UInt32 CodecInfoOffset;//Relative to start of this block
}
public DSPADPCMCodecInfo[] CodecInfos;
public class DSPADPCMCodecInfo
{
public DSPADPCMCodecInfo(EndianBinaryReader er)
{
Table = er.ReadInt16s(16);
Scale = er.ReadUInt16();
Last1 = er.ReadInt16();
Last2 = er.ReadInt16();
LoopScale = er.ReadUInt16();
LoopLast1 = er.ReadInt16();
LoopLast2 = er.ReadInt16();
Unknown6 = er.ReadUInt16();
}
public void Write(EndianBinaryWriter er)
{
er.Write(Table, 0, 16);
er.Write(Scale);
er.Write(Last1);
er.Write(Last2);
er.Write(LoopScale);
er.Write(LoopLast1);
er.Write(LoopLast2);
er.Write(Unknown6);
}
public Int16[] Table;//[16];
public UInt16 Scale;
public Int16 Last1;
public Int16 Last2;
public UInt16 LoopScale;
public Int16 LoopLast1;
public Int16 LoopLast2;
public UInt16 Unknown6;
};
}
public SEEK Seek;
public class SEEK
{
public SEEK()
{
Signature = "SEEK";
Samples = new short[0];
}
public SEEK(EndianBinaryReader er)
{
Signature = er.ReadString(Encoding.ASCII, 4);
if (Signature != "SEEK") throw new SignatureNotCorrectException(Signature, "SEEK", er.BaseStream.Position - 4);
SectionSize = er.ReadUInt32();
Samples = er.ReadInt16s((int)((SectionSize - 8) / 2));
}
public void Write(EndianBinaryWriter er)
{
SectionSize = (uint)(Samples.Length * 2 + 8);
er.Write(Signature, Encoding.ASCII, false);
er.Write(SectionSize);
er.Write(Samples, 0, Samples.Length);
while ((er.BaseStream.Position % 32) != 0) er.Write((byte)0);
}
public String Signature;
public UInt32 SectionSize;
public Int16[] Samples;
}
public DATA Data;
public class DATA
{
public DATA()
{
Signature = "DATA";
Data = new byte[0];
}
public DATA(EndianBinaryReader er)
{
Signature = er.ReadString(Encoding.ASCII, 4);
if (Signature != "DATA") throw new SignatureNotCorrectException(Signature, "DATA", er.BaseStream.Position - 4);
SectionSize = er.ReadUInt32();
er.ReadBytes(0x18);//padding
Data = er.ReadBytes((int)(SectionSize - 0x20));
}
public void Write(EndianBinaryWriter er)
{
long basepos = er.BaseStream.Position;
er.Write(Signature, Encoding.ASCII, false);
er.Write((uint)0);
er.Write(new byte[0x18], 0, 0x18);
er.Write(Data, 0, Data.Length);
while ((er.BaseStream.Position % 32) != 0) er.Write((byte)0);
long curpos = er.BaseStream.Position;
er.BaseStream.Position = basepos + 4;
er.Write((uint)(curpos - basepos));
er.BaseStream.Position = curpos;
}
public String Signature;
public UInt32 SectionSize;
public byte[] Data;
}
public Int16[] GetChannelData(int Channel)
{
if (Channel >= Info.StreamInfo.NrChannels) return null;
if (Info.StreamInfo.Format == 2)
{
ADPCM worker = new ADPCM(Info.CodecInfos[Channel].Table);
List<short> Data = new List<short>();
for (int i = 0; i < this.Data.Data.Length; i += (int)Info.StreamInfo.BlockSize * Info.StreamInfo.NrChannels)
{
if (i != 0)
{
Data[Data.Count - 2] = Seek.Samples[(i / Info.StreamInfo.BlockSize) * 2 + Channel * 2 + 1];
Data[Data.Count - 1] = Seek.Samples[(i / Info.StreamInfo.BlockSize) * 2 + Channel * 2];
}
worker.UpdateLastSamples(Seek.Samples[(i / Info.StreamInfo.BlockSize) * 2 + Channel * 2], Seek.Samples[(i / Info.StreamInfo.BlockSize) * 2 + Channel * 2 + 1]);
if (i + Info.StreamInfo.BlockSize * Info.StreamInfo.NrChannels < this.Data.Data.Length) Data.AddRange(worker.GetWaveData(this.Data.Data, i + Channel * (int)Info.StreamInfo.BlockSize, (int)Info.StreamInfo.BlockSize));
else if (Info.StreamInfo.BlockSize != Info.StreamInfo.LastBlockPaddedSize) Data.AddRange(worker.GetWaveData(this.Data.Data, i + Channel * (int)Info.StreamInfo.LastBlockPaddedSize, (int)Info.StreamInfo.LastBlockPaddedSize));
else break;
}
return Data.ToArray();
}
else if (Info.StreamInfo.Format == 1)
{
List<short> Data = new List<short>();
for (int i = 0; i < this.Data.Data.Length; i += (int)Info.StreamInfo.BlockSize * Info.StreamInfo.NrChannels)
{
if (i + Info.StreamInfo.BlockSize * Info.StreamInfo.NrChannels < this.Data.Data.Length)
{
for (int q = 0; q < Info.StreamInfo.BlockSize; q += 2)
{
Data.Add(IOUtil.ReadS16LE(this.Data.Data, (int)(i + Channel * Info.StreamInfo.BlockSize + q)));
}
}
else if (Info.StreamInfo.BlockSize != Info.StreamInfo.LastBlockSize)
{
for (int q = 0; q < Info.StreamInfo.LastBlockSize; q += 2)
{
Data.Add(IOUtil.ReadS16LE(this.Data.Data, (int)(i + Channel * Info.StreamInfo.LastBlockPaddedSize + q)));
}
}
else break;
}
return Data.ToArray();
}
else
{
return new short[0];
}
}
public WAV ToWave()
{
Int16[][] Channels = new short[Info.StreamInfo.NrChannels][];
for (int i = 0; i < Info.StreamInfo.NrChannels; i++)
{
Channels[i] = GetChannelData(i);
}
return new CommonFiles.WAV(SNDUtil.InterleaveChannels(Channels), Info.StreamInfo.SampleRate, 16, Info.StreamInfo.NrChannels);
}
public class CSTMIdentifier : FileFormatIdentifier
{
public override string GetCategory()
{
return Category_Audio;
}
public override string GetFileDescription()
{
return "CTR Stream (CSTM)";
}
public override string GetFileFilter()
{
return "CTR Stream (*.bcstm)|*.bcstm";
}
public override Bitmap GetIcon()
{
return null;
}
public override FormatMatch IsFormat(EFEFile File)
{
if (File.Data.Length > 4 && File.Data[0] == 'C' && File.Data[1] == 'S' && File.Data[2] == 'T' && File.Data[3] == 'M') return FormatMatch.Content;
return FormatMatch.No;
}
}
}
}

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("Nintendo 3DS Plugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Every File Explorer")]
[assembly: AssemblyCopyright("Copyright © Florian Nouwt 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("52cc8500-db45-4569-85c7-8e7a382adbe9")]
// 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")]

153
3DS/Resource.Designer.cs generated Normal file
View File

@ -0,0 +1,153 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.18063
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace _3DS {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resource {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resource() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("_3DS.Resource", typeof(Resource).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap edit {
get {
object obj = ResourceManager.GetObject("edit", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap image {
get {
object obj = ResourceManager.GetObject("image", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap image16 {
get {
object obj = ResourceManager.GetObject("image16", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap leaf {
get {
object obj = ResourceManager.GetObject("leaf", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap preview_background {
get {
object obj = ResourceManager.GetObject("preview_background", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap slide {
get {
object obj = ResourceManager.GetObject("slide", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap zone {
get {
object obj = ResourceManager.GetObject("zone", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap zone16 {
get {
object obj = ResourceManager.GetObject("zone16", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap zones_stack {
get {
object obj = ResourceManager.GetObject("zones_stack", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}

148
3DS/Resource.resx Normal file
View File

@ -0,0 +1,148 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="edit" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\edit.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="image" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\image.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="image16" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\image16.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="leaf" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\leaf.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="preview_background" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\preview_background.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="slide" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\slide.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="zone" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\zone.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="zone16" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\zone16.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="zones_stack" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\zones-stack.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

BIN
3DS/Resources/edit.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 445 B

BIN
3DS/Resources/image.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
3DS/Resources/image16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 562 B

BIN
3DS/Resources/leaf.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 B

BIN
3DS/Resources/slide.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 544 B

BIN
3DS/Resources/zone.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 702 B

BIN
3DS/Resources/zone16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 434 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 512 B

305
3DS/SARC.cs Normal file
View File

@ -0,0 +1,305 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LibEveryFileExplorer.Files;
using System.Drawing;
using System.IO;
using LibEveryFileExplorer.Files.SimpleFileSystem;
using _3DS.UI;
namespace _3DS
{
public class SARC : FileFormat<SARC.SARCIdentifier>, IViewable, IWriteable
{
public SARC(byte[] Data)
{
EndianBinaryReader er = new EndianBinaryReader(new MemoryStream(Data), Endianness.LittleEndian);
try
{
Header = new SARCHeader(er);
SFat = new SFAT(er);
SFnt = new SFNT(er);
er.BaseStream.Position = Header.FileDataOffset;
this.Data = er.ReadBytes((int)(Header.FileSize - Header.FileDataOffset));
}
finally
{
er.Close();
}
}
public System.Windows.Forms.Form GetDialog()
{
return new SARCViewer(this);
}
public string GetSaveDefaultFileFilter()
{
return "Simple Archive (*.sarc)|*.sarc";
}
public byte[] Write()
{
MemoryStream m = new MemoryStream();
EndianBinaryWriter er = new EndianBinaryWriter(m, Endianness.LittleEndian);
Header.Write(er);
SFat.Write(er);
SFnt.Write(er);
while ((er.BaseStream.Position % 128) != 0) er.Write((byte)0);
er.Write(Data, 0, Data.Length);
er.BaseStream.Position = 8;
er.Write((UInt32)(er.BaseStream.Length));
byte[] result = m.ToArray();
er.Close();
return result;
}
public SARCHeader Header;
public class SARCHeader
{
public SARCHeader()
{
Signature = "SARC";
HeaderSize = 0x14;
Endianness = 0xFEFF;
FileSize = 0;
FileDataOffset = 0;
Unknown = 0x0100;
}
public SARCHeader(EndianBinaryReader er)
{
Signature = er.ReadString(Encoding.ASCII, 4);
if (Signature != "SARC") throw new SignatureNotCorrectException(Signature, "SARC", er.BaseStream.Position - 4);
HeaderSize = er.ReadUInt16();
Endianness = er.ReadUInt16();
FileSize = er.ReadUInt32();
FileDataOffset = er.ReadUInt32();
Unknown = er.ReadUInt32();
}
public void Write(EndianBinaryWriter er)
{
er.Write(Signature, Encoding.ASCII, false);
er.Write(HeaderSize);
er.Write(Endianness);
er.Write(FileSize);
er.Write(FileDataOffset);
er.Write(Unknown);
}
public String Signature;
public UInt16 HeaderSize;
public UInt16 Endianness;
public UInt32 FileSize;
public UInt32 FileDataOffset;
public UInt32 Unknown;
}
public SFAT SFat;
public class SFAT
{
public SFAT()
{
Signature = "SFAT";
HeaderSize = 0xC;
NrEntries = 0;
HashMultiplier = 0x65;
Entries = new List<SFATEntry>();
}
public SFAT(EndianBinaryReader er)
{
Signature = er.ReadString(Encoding.ASCII, 4);
if (Signature != "SFAT") throw new SignatureNotCorrectException(Signature, "SFAT", er.BaseStream.Position - 4);
HeaderSize = er.ReadUInt16();
NrEntries = er.ReadUInt16();
HashMultiplier = er.ReadUInt32();
Entries = new List<SFATEntry>();
for (int i = 0; i < NrEntries; i++)
{
Entries.Add(new SFATEntry(er));
}
}
public void Write(EndianBinaryWriter er)
{
NrEntries = (ushort)Entries.Count;
er.Write(Signature, Encoding.ASCII, false);
er.Write(HeaderSize);
er.Write(NrEntries);
er.Write(HashMultiplier);
foreach (var v in Entries) v.Write(er);
}
public String Signature;
public UInt16 HeaderSize;
public UInt16 NrEntries;
public UInt32 HashMultiplier;
public List<SFATEntry> Entries;
public class SFATEntry
{
public SFATEntry() { }
public SFATEntry(EndianBinaryReader er)
{
FileNameHash = er.ReadUInt32();
FileNameOffset = er.ReadUInt32();
FileDataStart = er.ReadUInt32();
FileDataEnd = er.ReadUInt32();
}
public void Write(EndianBinaryWriter er)
{
er.Write(FileNameHash);
er.Write(FileNameOffset);
er.Write(FileDataStart);
er.Write(FileDataEnd);
}
public UInt32 FileNameHash;
public UInt32 FileNameOffset;//If filenames are available
public UInt32 FileDataStart;
public UInt32 FileDataEnd;
}
}
public SFNT SFnt;
public class SFNT
{
public SFNT()
{
Signature = "SFNT";
HeaderSize = 8;
Unknown1 = 0;
}
public SFNT(EndianBinaryReader er)
{
Signature = er.ReadString(Encoding.ASCII, 4);
if (Signature != "SFNT") throw new SignatureNotCorrectException(Signature, "SFNT", er.BaseStream.Position - 4);
HeaderSize = er.ReadUInt16();
Unknown1 = er.ReadUInt16();
}
public void Write(EndianBinaryWriter er)
{
er.Write(Signature, Encoding.ASCII, false);
er.Write(HeaderSize);
er.Write(Unknown1);
}
public String Signature;
public UInt16 HeaderSize;
public UInt16 Unknown1;
}
public byte[] Data;
public byte[] GetFileDataByIndex(int Index)
{
if (SFat.Entries.Count <= Index) return null;
SFAT.SFATEntry v = SFat.Entries[Index];
uint start = v.FileDataStart;
uint length = v.FileDataEnd - start;
byte[] Result = new byte[length];
Array.Copy(Data, start, Result, 0, length);
return Result;
}
public byte[] GetFileDataByHash(UInt32 Hash)
{
foreach (SFAT.SFATEntry v in SFat.Entries)
{
if (v.FileNameHash == Hash)
{
uint start = v.FileDataStart;
uint length = v.FileDataEnd - start;
byte[] Result = new byte[length];
Array.Copy(Data, start, Result, 0, length);
return Result;
}
}
return null;
}
public UInt32 GetHashFromName(String Name)
{
return GetHashFromName(Name, SFat.HashMultiplier);
}
public static UInt32 GetHashFromName(String Name, UInt32 HashMultiplier)
{
uint res = 0;
for (int i = 0; i < Name.Length; i++)
{
res = Name[i] + res * HashMultiplier;
}
return res;
}
public SFSDirectory ToFileSystem()
{
SFSDirectory Root = new SFSDirectory("/", true);
foreach (var v in SFat.Entries)
{
var q = new SFSFile((int)v.FileNameHash, string.Format("0x{0:X8}", v.FileNameHash), Root);
q.Data = GetFileDataByHash(v.FileNameHash);
Root.Files.Add(q);
}
return Root;
}
public void FromFileSystem(SFSDirectory Root)
{
Header = new SARCHeader();
SFat = new SFAT();
SFat.NrEntries = (ushort)Root.Files.Count;
uint DataStart = 0;
foreach (var v in Root.Files)
{
while ((DataStart % 128) != 0) DataStart++;
uint hash;
if (v.FileName == string.Format("0x{0:X8}", v.FileID)) hash = (uint)v.FileID;
else hash = GetHashFromName(v.FileName);
SFat.Entries.Add(new SFAT.SFATEntry() { FileDataStart = DataStart, FileDataEnd = (uint)(DataStart + v.Data.Length), FileNameHash = hash, FileNameOffset = 0 });
DataStart += (uint)v.Data.Length;
}
Data = new byte[DataStart];
int i = 0;
foreach (var v in Root.Files)
{
Array.Copy(v.Data, 0, Data, SFat.Entries[i].FileDataStart, v.Data.Length);
i++;
}
SFnt = new SFNT();
Header.FileSize = (uint)(0x14 + 0xC + SFat.NrEntries * 0x10 + 0x8);
while ((Header.FileSize % 128) != 0) Header.FileSize++;
Header.FileDataOffset = Header.FileSize;
Header.FileSize += (uint)Data.Length;
}
public class SARCIdentifier : FileFormatIdentifier
{
public override string GetCategory()
{
return Category_Archives;
}
public override string GetFileDescription()
{
return "Simple Archive (SARC)";
}
public override string GetFileFilter()
{
return "Simple Archive (*.sarc, *.szs)|*.sarc;*.szs";
}
public override Bitmap GetIcon()
{
return null;
}
public override FormatMatch IsFormat(EFEFile File)
{
if (File.Data.Length > 20 && File.Data[0] == 'S' && File.Data[1] == 'A' && File.Data[2] == 'R' && File.Data[3] == 'C') return FormatMatch.Content;
return FormatMatch.No;
}
}
}
}

21
3DS/SARCEFESFSFile.cs Normal file
View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LibEveryFileExplorer.Files.SimpleFileSystem;
namespace _3DS
{
public class SARCEFESFSFile : EFESFSFile
{
public SARCEFESFSFile(SFSFile File)
: base(File) { }
public override byte[] FindFileRelative(string Path)
{
Path = Path.Replace("\\", "/");
if (Path.TrimStart('/').StartsWith("../")) return null;
return File.Parent.GetFileByID((int)SARC.GetHashFromName(Path, 0x65)).Data;
}
}
}

165
3DS/SMDH.cs Normal file
View File

@ -0,0 +1,165 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LibEveryFileExplorer.Files;
using System.Drawing;
using System.IO;
using _3DS.UI;
namespace _3DS
{
public class SMDH : FileFormat<SMDH.SMDHIdentifier>, IViewable
{
public SMDH(byte[] Data)
{
EndianBinaryReader er = new EndianBinaryReader(new MemoryStream(Data), Endianness.LittleEndian);
try
{
Header = new SMDHHeader(er);
AppTitles = new ApplicationTitle[16];
for (int i = 0; i < 16; i++) AppTitles[i] = new ApplicationTitle(er);
AppSettings = new ApplicationSettings(er);
Reserved = er.ReadBytes(8);
SmallIcon = er.ReadBytes(0x480);
LargeIcon = er.ReadBytes(0x1200);
}
finally
{
er.Close();
}
}
public System.Windows.Forms.Form GetDialog()
{
return new SMDHViewer(this);
}
public SMDHHeader Header;
public class SMDHHeader
{
public SMDHHeader(EndianBinaryReader er)
{
Signature = er.ReadString(Encoding.ASCII, 4);
if (Signature != "SMDH") throw new SignatureNotCorrectException(Signature, "SMDH", er.BaseStream.Position);
Version = er.ReadUInt16();
Reserved = er.ReadUInt16();
}
public String Signature;
public UInt16 Version;
public UInt16 Reserved;
}
public ApplicationTitle[] AppTitles;//16
public class ApplicationTitle
{
public ApplicationTitle(EndianBinaryReader er)
{
ShortDescription = er.ReadString(Encoding.Unicode, 64).TrimEnd('\0');
LongDescription = er.ReadString(Encoding.Unicode, 128).TrimEnd('\0');
Publisher = er.ReadString(Encoding.Unicode, 64).TrimEnd('\0');
}
public String ShortDescription;//0x80
public String LongDescription;//0x100
public String Publisher;//0x80
}
public ApplicationSettings AppSettings;
public class ApplicationSettings
{
[Flags]
public enum RegionLockoutFlags : uint
{
Japan = 0x01,
NorthAmerica = 0x02,
Europe = 0x04,
Australia = 0x08,
China = 0x10,
Korea = 0x20,
Taiwan = 0x40
}
[Flags]
public enum AppSettingsFlags : uint
{
Visible = 1,
AutoBoot = 2,
Allow3D = 4,
ReqAcceptEULA = 8,
AutoSaveOnExit = 16,
UsesExtendedBanner = 32,
ReqRegionGameRating = 64,
UsesSaveData = 128,
RecordUsage = 256,
DisableSDSaveBackup = 512
}
public ApplicationSettings(EndianBinaryReader er)
{
GameRatings = er.ReadBytes(0x10);
RegionLockout = (RegionLockoutFlags)er.ReadUInt32();
MatchMakerID = er.ReadUInt32();
MatchMakerBITID = er.ReadUInt64();
Flags = (AppSettingsFlags)er.ReadUInt32();
EULAVersion = er.ReadUInt16();
Reserved = er.ReadUInt16();
AnimationDefaultFrame = er.ReadSingle();
StreetPassID = er.ReadUInt32();
}
public byte[] GameRatings;//0x10
public RegionLockoutFlags RegionLockout;
public UInt32 MatchMakerID;
public UInt64 MatchMakerBITID;
public AppSettingsFlags Flags;
public UInt16 EULAVersion;
public UInt16 Reserved;
public Single AnimationDefaultFrame;
public UInt32 StreetPassID;
}
public byte[] Reserved;//8
public byte[] SmallIcon;//0x480
public byte[] LargeIcon;//0x1200
public Bitmap GetSmallIcon()
{
return GPU.Textures.ToBitmap(SmallIcon, 24, 24, GPU.Textures.ImageFormat.RGB565, true);
}
public Bitmap GetLargeIcon()
{
return GPU.Textures.ToBitmap(LargeIcon, 48, 48, GPU.Textures.ImageFormat.RGB565, true);
}
public class SMDHIdentifier : FileFormatIdentifier
{
public override string GetCategory()
{
return "3DS";
}
public override string GetFileDescription()
{
return "System Menu Data Header (SMDH)";
}
public override string GetFileFilter()
{
return "System Menu Data Header (*.icn, icon.bin)|*.icn;icon.bin";
}
public override Bitmap GetIcon()
{
return null;
}
public override FormatMatch IsFormat(EFEFile File)
{
if (File.Data.Length > 4 && File.Data[0] == 'S' && File.Data[1] == 'M' && File.Data[2] == 'D' && File.Data[3] == 'H') return FormatMatch.Content;
return FormatMatch.No;
}
}
}
}

474
3DS/UI/CGFXViewer.cs Normal file
View File

@ -0,0 +1,474 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Tao.OpenGl;
using LibEveryFileExplorer._3D;
using System.Drawing.Imaging;
using _3DS.NintendoWare.GFX;
using LibEveryFileExplorer.Collections;
namespace _3DS.UI
{
public partial class CGFXViewer : Form
{
bool init = false;
CGFX cgfx;
public CGFXViewer(CGFX cgfx)
{
this.cgfx = cgfx;
InitializeComponent();
simpleOpenGlControl1.MouseWheel += new MouseEventHandler(simpleOpenGlControl1_MouseWheel);
}
void simpleOpenGlControl1_MouseWheel(object sender, MouseEventArgs e)
{
if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift) { dist += ((float)e.Delta / 10); }// *file.modelSet.models[SelMdl].info.posScale; }
else { dist += ((float)e.Delta / 100); }// *file.modelSet.models[SelMdl].info.posScale; }
Render();
}
String glversion = null;
float X = 0.0f;
float Y = 0.0f;
float ang = 0.0f;
float dist = 0.0f;
float elev = 0.0f;
private void CGFX_Load(object sender, EventArgs e)
{
simpleOpenGlControl1.InitializeContexts();
Gl.ReloadFunctions();
//Gl.glEnable(Gl.GL_LIGHTING);
Gl.glEnable(Gl.GL_RESCALE_NORMAL);
Gl.glEnable(Gl.GL_COLOR_MATERIAL);
Gl.glEnable(Gl.GL_DEPTH_TEST);
Gl.glEnable(Gl.GL_NORMALIZE);
Gl.glDisable(Gl.GL_CULL_FACE);
Gl.glFrontFace(Gl.GL_CCW);
Gl.glEnable(Gl.GL_TEXTURE_2D);
Gl.glClearDepth(1);
Gl.glEnable(Gl.GL_ALPHA_TEST);
Gl.glAlphaFunc(Gl.GL_GREATER, 0f);
Gl.glEnable(Gl.GL_BLEND);
Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);
//Gl.glTexEnvf(Gl.GL_TEXTURE_ENV, Gl.GL_TEXTURE_ENV_MODE, Gl.GL_BLEND);
Gl.glShadeModel(Gl.GL_SMOOTH);
Gl.glDepthFunc(Gl.GL_LEQUAL);
Gl.glClearColor(51f / 255f, 51f / 255f, 51f / 255f, 0f);
if (cgfx.Data.Textures != null && cgfx.Data.Models != null)
{
//int i = 1;
/*foreach (_3DS.CGFX.DATA.TXOB t in cgfx.Data.Textures)
{
//int S = (int)((t.Unknown7 >> 8) & 0x3);
//int T = (int)((t.Unknown7 >> 12) & 0x3);
//if (S == 0) S = Gl.GL_REPEAT;
//else S = Gl.GL_MIRRORED_REPEAT;
//if (T == 0) T = Gl.GL_REPEAT;
//else T = Gl.GL_MIRRORED_REPEAT;
int S = Gl.GL_REPEAT;
int T = Gl.GL_REPEAT;
/*if ((t.Unknown4 & 0x7) == 0x3)
{
S = Gl.GL_MIRRORED_REPEAT;
T = Gl.GL_MIRRORED_REPEAT;
}*/
//if ((t.Unknown4 & 0x1) == 1) S = Gl.GL_MIRRORED_REPEAT;
//if (((t.Unknown4 >> 1) & 0x1) == 1) T = Gl.GL_MIRRORED_REPEAT;
/*uint _s = (t.Unknown8 >> 16) & 0xFF;
uint _t = (t.Unknown8 >> 24) & 0xFF;
if (_s == 2) S = Gl.GL_REPEAT;
else if (_s == 3) S = Gl.GL_MIRRORED_REPEAT;
else S = Gl.GL_CLAMP_TO_EDGE;
if (_t == 2) T = Gl.GL_REPEAT;
else if (_t == 3) T = Gl.GL_MIRRORED_REPEAT;
else T = Gl.GL_CLAMP_TO_EDGE;/
//GlNitro.glNitroTexImage2D(t.GetBitmap(), i, S, T, Gl.GL_LINEAR, Gl.GL_LINEAR);
Gl.glBindTexture(Gl.GL_TEXTURE_2D, i);
Gl.glColor3f(1, 1, 1);
Bitmap b = t.GetBitmap();
BitmapData d = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGBA8, b.Width, b.Height, 0, Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, d.Scan0);
b.UnlockBits(d);
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR);
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, S);
Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, T);
i++;
}*/
int i = 0;
foreach (var v in cgfx.Data.Models[0].Materials)
{
if (v.Tex0 != null) UploadTex(v.Tex0, i * 4 + 0 + 1);
if (v.Tex1 != null) UploadTex(v.Tex1, i * 4 + 1 + 1);
if (v.Tex2 != null) UploadTex(v.Tex2, i * 4 + 2 + 1);
//if (v.Tex3 != null) UploadTex(v.Tex3, i * 4 + 3 + 1);
i++;
}
}
if (cgfx.Data.Models != null) Shaders = new CGFXShader[cgfx.Data.Models[0].Materials.Length];
//GlNitro.glNitroBindTextures(file, 1);
glversion = Gl.glGetString(Gl.GL_VERSION);
init = true;
Render();
}
private void UploadTex(CMDL.MTOB.TexInfo TextureMapper, int Id)
{
if (!(TextureMapper.TextureObject is ReferenceTexture))
return;
var tex = cgfx.Data.Textures[cgfx.Data.Dictionaries[1].IndexOf(((ReferenceTexture)TextureMapper.TextureObject).LinkedTextureName)] as ImageTextureCtr;
if (tex == null)
return;
Gl.glBindTexture(Gl.GL_TEXTURE_2D, Id);
Gl.glColor3f(1, 1, 1);
Bitmap b = tex.GetBitmap();
b.RotateFlip(RotateFlipType.RotateNoneFlipY);
BitmapData d = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGBA8, b.Width, b.Height, 0, Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, d.Scan0);
b.UnlockBits(d);
if (((TextureMapper.Unknown12 >> 1) & 1) == 1) Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
else Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_NEAREST);
//if (((TextureMapper.Unknown12 >> 2) & 1) == 1) Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
//else Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_NEAREST);
//A bit confusing, so using this for now:
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR);
switch ((TextureMapper.Unknown12 >> 12) & 0xF)
{
case 0:
Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_CLAMP_TO_EDGE);
break;
case 1:
Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_CLAMP_TO_BORDER);
break;
case 2:
Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_REPEAT);
break;
case 3:
Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_MIRRORED_REPEAT);
break;
default:
Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_REPEAT);
break;
}
switch ((TextureMapper.Unknown12 >> 8) & 0xF)
{
case 0:
Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_CLAMP_TO_EDGE);
break;
case 1:
Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_CLAMP_TO_BORDER);
break;
case 2:
Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_REPEAT);
break;
case 3:
Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_MIRRORED_REPEAT);
break;
default:
Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_REPEAT);
break;
}
}
CGFXShader[] Shaders;
public void Render()
{
if (!init) return;
if (cgfx.Data.Models == null) return;
//G3D_Binary_File_Format.Shaders.Shader s = new G3D_Binary_File_Format.Shaders.Shader();
//s.Compile();
//s.Enable();
//Gl.glViewport(0, 0, simpleOpenGlControl1.Width, simpleOpenGlControl1.Height);
float aspect = (float)simpleOpenGlControl1.Width / (float)simpleOpenGlControl1.Height;
//float fov = 60.0f; // in degrees
//float znear = 0.02f;
//float zfar = 1000.0f * file.modelSet.models[SelMdl].info.posScale;
//Gl.glMatrixMode(Gl.GL_PROJECTION);
//Gl.glLoadMatrixf(BuildPerspProjMat(fov, aspect, znear, zfar));
Gl.glMatrixMode(Gl.GL_PROJECTION);
Gl.glLoadIdentity();
Gl.glViewport(0, 0, simpleOpenGlControl1.Width, simpleOpenGlControl1.Height);
//Gl.glOrtho(-simpleOpenGlControl1.Width / 2.0f, simpleOpenGlControl1.Width / 2.0f, -simpleOpenGlControl1.Height / 2.0f, simpleOpenGlControl1.Height / 2.0f, 0.02f, 1000f * file.modelSet.models[SelMdl].info.posScale);
//Gl.glMatrixMode(Gl.GL_PROJECTION);
//Gl.glLoadIdentity();
//Gl.glFrustum(-simpleOpenGlControl1.Width / 2f, simpleOpenGlControl1.Width / 2f, -simpleOpenGlControl1.Height / 2f, simpleOpenGlControl1.Height / 2f, 1000, -1000);
Glu.gluPerspective(30, aspect, 0.1f, 20480000f);//0.02f, 32.0f);
Gl.glMatrixMode(Gl.GL_MODELVIEW);
Gl.glLoadIdentity();
Gl.glBindTexture(Gl.GL_TEXTURE_2D, 0);
Gl.glColor3f(1.0f, 1.0f, 1.0f);
//Gl.glEnable(Gl.GL_DEPTH_TEST);
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
/*Gl.glRotatef(elev, 1, 0, 0);
Gl.glFogfv(Gl.GL_FOG_COLOR, new float[] { 0, 0, 0, 1 });
Gl.glFogf(Gl.GL_FOG_DENSITY, 1);
Gl.glRotatef(-elev, 1, 0, 0);*/
Gl.glTranslatef(X, Y, -dist);
Gl.glRotatef(elev, 1, 0, 0);
Gl.glRotatef(ang, 0, 1, 0);
Gl.glPushMatrix();
RenderModel();
Gl.glPopMatrix();
simpleOpenGlControl1.Refresh();
}
void RenderModel()
{
CMDL m = cgfx.Data.Models[0];
//foreach (_3DS.CGFX.DATA.CMDL m in cgfx.Data.Models)
//{
//int i = 0;
foreach (var mm in m.Meshes)
{
var vv = m.Shapes[mm.ShapeIndex];
Polygon p = vv.GetVertexData(m);
var mat = m.Materials[mm.MaterialIndex];
mat.FragShader.AlphaTest.GlApply();
mat.FragmentOperation.BlendOperation.GlApply();
Gl.glMatrixMode(Gl.GL_TEXTURE);
if (mat.Tex0 != null)
{
Gl.glActiveTexture(Gl.GL_TEXTURE0);
Gl.glBindTexture(Gl.GL_TEXTURE_2D, mm.MaterialIndex * 4 + 0 + 1);
Gl.glEnable(Gl.GL_TEXTURE_2D);
Gl.glLoadIdentity();
float[] mtx = new float[16];
Array.Copy(mat.TextureCoordiators[0].Matrix, mtx, 4 * 3);
mtx[15] = 1;
mtx[12] = mtx[3];
mtx[13] = mtx[7];
mtx[14] = mtx[11];
mtx[3] = 0;
mtx[7] = 0;
mtx[11] = 0;
Gl.glLoadMatrixf(mtx);
//if (mat.TextureCoordiators[0].MappingMethod == 2)
//{
// Gl.glTexGeni(Gl.GL_S, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_SPHERE_MAP);
// Gl.glTexGeni(Gl.GL_T, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_SPHERE_MAP);
//}
//Gl.glTranslatef(mat.TextureCoordiators[0].Scale.X / mat.TextureCoordiators[0].Translate.X, mat.TextureCoordiators[0].Translate.Y * mat.TextureCoordiators[0].Scale.Y, 0);
//Gl.glRotatef(mat.TextureCoordiators[0].Rotate, 0, 1, 0);
//Gl.glScalef(mat.TextureCoordiators[0].Scale.X, mat.TextureCoordiators[0].Scale.Y, 1);
}
if (mat.Tex1 != null)
{
Gl.glActiveTexture(Gl.GL_TEXTURE1);
Gl.glBindTexture(Gl.GL_TEXTURE_2D, mm.MaterialIndex * 4 + 1 + 1);
Gl.glEnable(Gl.GL_TEXTURE_2D);
Gl.glLoadIdentity();
float[] mtx = new float[16];
Array.Copy(mat.TextureCoordiators[1].Matrix, mtx, 4 * 3);
mtx[15] = 1;
mtx[12] = mtx[3];
mtx[13] = mtx[7];
mtx[14] = mtx[11];
mtx[3] = 0;
mtx[7] = 0;
mtx[11] = 0;
Gl.glLoadMatrixf(mtx);
//if (mat.TextureCoordiators[1].MappingMethod == 2)
//{
// Gl.glTexGeni(Gl.GL_S, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_SPHERE_MAP);
// Gl.glTexGeni(Gl.GL_T, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_SPHERE_MAP);
//}
}
if (mat.Tex2 != null)
{
Gl.glActiveTexture(Gl.GL_TEXTURE2);
Gl.glBindTexture(Gl.GL_TEXTURE_2D, mm.MaterialIndex * 4 + 2 + 1);
Gl.glEnable(Gl.GL_TEXTURE_2D);
Gl.glLoadIdentity();
float[] mtx = new float[16];
Array.Copy(mat.TextureCoordiators[2].Matrix, mtx, 4 * 3);
mtx[15] = 1;
mtx[12] = mtx[3];
mtx[13] = mtx[7];
mtx[14] = mtx[11];
mtx[3] = 0;
mtx[7] = 0;
mtx[11] = 0;
Gl.glLoadMatrixf(mtx);
//if (mat.TextureCoordiators[2].MappingMethod == 2)
//{
// Gl.glTexGeni(Gl.GL_S, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_SPHERE_MAP);
// Gl.glTexGeni(Gl.GL_T, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_SPHERE_MAP);
//}
}
/*if (mat.Tex3 != null)
{
MessageBox.Show("Tex3!!!!!!!!!!!");
Gl.glActiveTexture(Gl.GL_TEXTURE3);
Gl.glBindTexture(Gl.GL_TEXTURE_2D, mm.MaterialIndex * 4 + 3 + 1);
Gl.glEnable(Gl.GL_TEXTURE_2D);
Gl.glLoadIdentity();
}*/
Gl.glMatrixMode(Gl.GL_MODELVIEW);
if (glversion.StartsWith("2.") && Shaders[mm.MaterialIndex] == null)
{
List<int> tex = new List<int>();
if (mat.Tex0 != null) tex.Add((int)mm.MaterialIndex * 4 + 0 + 1);
else tex.Add(0);
if (mat.Tex1 != null) tex.Add((int)mm.MaterialIndex * 4 + 1 + 1);
else tex.Add(0);
if (mat.Tex2 != null) tex.Add((int)mm.MaterialIndex * 4 + 2 + 1);
else tex.Add(0);
//if (mat.Tex3 != null) tex.Add((int)mm.MaterialIndex * 4 + 3 + 1);
/*else */tex.Add(0);
Shaders[mm.MaterialIndex] = new CGFXShader(mat, tex.ToArray());
Shaders[mm.MaterialIndex].Compile();
}
if (glversion.StartsWith("2.")) Shaders[mm.MaterialIndex].Enable();
//Gl.glMaterialfv(Gl.GL_FRONT_AND_BACK, Gl.GL_EMISSION, new float[] { mat.Emission_2.R / 255f, mat.Emission_2.G / 255f, mat.Emission_2.B / 255f, mat.Emission_2.A / 255f });
//Gl.glMaterialfv(Gl.GL_FRONT_AND_BACK, Gl.GL_AMBIENT, new float[] { mat.Ambient_1.R / 255f, mat.Ambient_1.G / 255f, mat.Ambient_1.B / 255f, mat.Ambient_1.A / 255f });
//Gl.glMaterialfv(Gl.GL_FRONT_AND_BACK, Gl.GL_DIFFUSE, new float[] { mat.Diffuse_2.R / 255f, mat.Diffuse_2.G / 255f, mat.Diffuse_2.B / 255f, mat.Diffuse_2.A / 255f });
//Gl.glColorMaterial(Gl.GL_FRONT_AND_BACK, Gl.GL_DIFFUSE);
//Gl.glEnable(Gl.GL_COLOR_MATERIAL);
foreach (var q in vv.PrimitiveSets[0].Primitives[0].IndexStreams)
{
Vector3[] defs = q.GetFaceData();
Gl.glBegin(Gl.GL_TRIANGLES);
foreach (Vector3 d in defs)
{
if (p.Normals != null) Gl.glNormal3f(p.Normals[(int)d.X].X, p.Normals[(int)d.X].Y, p.Normals[(int)d.X].Z);
if (p.Colors != null) Gl.glColor4f(p.Colors[(int)d.X].R / 255f, p.Colors[(int)d.X].G / 255f, p.Colors[(int)d.X].B / 255f, p.Colors[(int)d.X].A / 255f);
else Gl.glColor4f(1, 1, 1, 1);
if (p.TexCoords != null) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, p.TexCoords[(int)d.X].X, p.TexCoords[(int)d.X].Y);
if (p.TexCoords2 != null) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE1, p.TexCoords2[(int)d.X].X, p.TexCoords2[(int)d.X].Y);
if (p.TexCoords3 != null) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE2, p.TexCoords3[(int)d.X].X, p.TexCoords3[(int)d.X].Y);
Gl.glVertex3f(p.Vertex[(int)d.X].X, p.Vertex[(int)d.X].Y, p.Vertex[(int)d.X].Z);
if (p.Normals != null) Gl.glNormal3f(p.Normals[(int)d.Y].X, p.Normals[(int)d.Y].Y, p.Normals[(int)d.Y].Z);
if (p.Colors != null) Gl.glColor4f(p.Colors[(int)d.Y].R / 255f, p.Colors[(int)d.Y].G / 255f, p.Colors[(int)d.Y].B / 255f, p.Colors[(int)d.Y].A / 255f);
else Gl.glColor4f(1, 1, 1, 1);
if (p.TexCoords != null) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, p.TexCoords[(int)d.Y].X, p.TexCoords[(int)d.Y].Y);
if (p.TexCoords2 != null) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE1, p.TexCoords2[(int)d.Y].X, p.TexCoords2[(int)d.Y].Y);
if (p.TexCoords3 != null) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE2, p.TexCoords3[(int)d.Y].X, p.TexCoords3[(int)d.Y].Y);
Gl.glVertex3f(p.Vertex[(int)d.Y].X, p.Vertex[(int)d.Y].Y, p.Vertex[(int)d.Y].Z);
if (p.Normals != null) Gl.glNormal3f(p.Normals[(int)d.Z].X, p.Normals[(int)d.Z].Y, p.Normals[(int)d.Z].Z);
if (p.Colors != null) Gl.glColor4f(p.Colors[(int)d.Z].R / 255f, p.Colors[(int)d.Z].G / 255f, p.Colors[(int)d.Z].B / 255f, p.Colors[(int)d.Z].A / 255f);
else Gl.glColor4f(1, 1, 1, 1);
if (p.TexCoords != null) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE0, p.TexCoords[(int)d.Z].X, p.TexCoords[(int)d.Z].Y);
if (p.TexCoords2 != null) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE1, p.TexCoords2[(int)d.Z].X, p.TexCoords2[(int)d.Z].Y);
if (p.TexCoords3 != null) Gl.glMultiTexCoord2f(Gl.GL_TEXTURE2, p.TexCoords3[(int)d.Z].X, p.TexCoords3[(int)d.Z].Y);
Gl.glVertex3f(p.Vertex[(int)d.Z].X, p.Vertex[(int)d.Z].Y, p.Vertex[(int)d.Z].Z);
}
Gl.glEnd();
}
}
}
bool wire = false;
bool licht = true;
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
switch (keyData)
{
case Keys.Right:
ang += 1;
Render();
return true;
case Keys.Left:
ang -= 1;
Render();
return true;
case Keys.Up:
elev += 1;
Render();
return true;
case Keys.Down:
elev -= 1;
Render();
return true;
case Keys.Z:
X -= 5f;// * file.modelSet.models[SelMdl].info.posScale;
Render();
return true;
case Keys.X:
X += 5f;// * file.modelSet.models[SelMdl].info.posScale;
Render();
return true;
case Keys.A:
Y -= 5f;// * file.modelSet.models[SelMdl].info.posScale;
Render();
return true;
case Keys.S:
Y += 5f;// * file.modelSet.models[SelMdl].info.posScale;
Render();
return true;
case Keys.W:
wire = !wire;
if (wire) { Gl.glPolygonMode(Gl.GL_FRONT_AND_BACK, Gl.GL_LINE); Render(); }
else { Gl.glPolygonMode(Gl.GL_FRONT_AND_BACK, Gl.GL_FILL); Render(); }
return true;
case Keys.Escape:
X = 0.0f;
Y = 0.0f;
ang = 0.0f;
dist = 0.0f;
elev = 0.0f;
Render();
return true;
case Keys.T:
elev = 90;
ang = 0;
Render();
return true;
case Keys.L:
licht = !licht;
Render();
return true;
default:
return base.ProcessCmdKey(ref msg, keyData);
}
}
private void CGFX_Resize(object sender, EventArgs e)
{
Render();
Render();
}
private void CGFX_Layout(object sender, LayoutEventArgs e)
{
Render();
}
private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e)
{
Render();
}
}
}

148
3DS/UI/CGFXViewer.designer.cs generated Normal file
View File

@ -0,0 +1,148 @@
namespace _3DS.UI
{
partial class CGFXViewer
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.simpleOpenGlControl1 = new Tao.Platform.Windows.SimpleOpenGlControl();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.treeView1 = new System.Windows.Forms.TreeView();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.tabPage2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.SuspendLayout();
this.SuspendLayout();
//
// simpleOpenGlControl1
//
this.simpleOpenGlControl1.AccumBits = ((byte)(0));
this.simpleOpenGlControl1.AutoCheckErrors = false;
this.simpleOpenGlControl1.AutoFinish = false;
this.simpleOpenGlControl1.AutoMakeCurrent = true;
this.simpleOpenGlControl1.AutoSwapBuffers = true;
this.simpleOpenGlControl1.BackColor = System.Drawing.Color.Black;
this.simpleOpenGlControl1.ColorBits = ((byte)(32));
this.simpleOpenGlControl1.DepthBits = ((byte)(32));
this.simpleOpenGlControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.simpleOpenGlControl1.Location = new System.Drawing.Point(3, 3);
this.simpleOpenGlControl1.Name = "simpleOpenGlControl1";
this.simpleOpenGlControl1.Size = new System.Drawing.Size(575, 353);
this.simpleOpenGlControl1.StencilBits = ((byte)(8));
this.simpleOpenGlControl1.TabIndex = 0;
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabControl1.Location = new System.Drawing.Point(0, 0);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(589, 385);
this.tabControl1.TabIndex = 1;
this.tabControl1.Selecting += new System.Windows.Forms.TabControlCancelEventHandler(this.tabControl1_Selecting);
//
// tabPage1
//
this.tabPage1.Controls.Add(this.simpleOpenGlControl1);
this.tabPage1.Location = new System.Drawing.Point(4, 22);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
this.tabPage1.Size = new System.Drawing.Size(581, 359);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "Render";
this.tabPage1.UseVisualStyleBackColor = true;
this.tabPage1.Layout += new System.Windows.Forms.LayoutEventHandler(this.CGFX_Layout);
//
// tabPage2
//
this.tabPage2.Controls.Add(this.splitContainer1);
this.tabPage2.Location = new System.Drawing.Point(4, 22);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
this.tabPage2.Size = new System.Drawing.Size(581, 359);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "Content";
this.tabPage2.UseVisualStyleBackColor = true;
//
// splitContainer1
//
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer1.Location = new System.Drawing.Point(3, 3);
this.splitContainer1.Name = "splitContainer1";
//
// splitContainer1.Panel1
//
this.splitContainer1.Panel1.Controls.Add(this.treeView1);
this.splitContainer1.Size = new System.Drawing.Size(575, 353);
this.splitContainer1.SplitterDistance = 191;
this.splitContainer1.TabIndex = 0;
//
// treeView1
//
this.treeView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.treeView1.Location = new System.Drawing.Point(0, 0);
this.treeView1.Name = "treeView1";
this.treeView1.Size = new System.Drawing.Size(191, 353);
this.treeView1.TabIndex = 0;
//
// CGFXViewer
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(589, 385);
this.Controls.Add(this.tabControl1);
this.Name = "CGFXViewer";
this.Text = "CGFX";
this.Load += new System.EventHandler(this.CGFX_Load);
this.Layout += new System.Windows.Forms.LayoutEventHandler(this.CGFX_Layout);
this.Resize += new System.EventHandler(this.CGFX_Resize);
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.tabPage2.ResumeLayout(false);
this.splitContainer1.Panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
this.splitContainer1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private Tao.Platform.Windows.SimpleOpenGlControl simpleOpenGlControl1;
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.SplitContainer splitContainer1;
private System.Windows.Forms.TreeView treeView1;
}
}

120
3DS/UI/CGFXViewer.resx Normal file
View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

66
3DS/UI/CLIMViewer.Designer.cs generated Normal file
View File

@ -0,0 +1,66 @@
namespace _3DS.UI
{
partial class CLIMViewer
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(CLIMViewer));
this.pictureBox1 = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.BackColor = System.Drawing.Color.White;
this.pictureBox1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("pictureBox1.BackgroundImage")));
this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(565, 386);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// CLIMViewer
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(565, 386);
this.Controls.Add(this.pictureBox1);
this.Name = "CLIMViewer";
this.Text = "CLIMViewer";
this.Load += new System.EventHandler(this.CLIMViewer_Load);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.PictureBox pictureBox1;
}
}

27
3DS/UI/CLIMViewer.cs Normal file
View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using _3DS.NintendoWare.LYT;
namespace _3DS.UI
{
public partial class CLIMViewer : Form
{
CLIM Image;
public CLIMViewer(CLIM Image)
{
this.Image = Image;
InitializeComponent();
}
private void CLIMViewer_Load(object sender, EventArgs e)
{
pictureBox1.Image = Image.ToBitmap();
}
}
}

173
3DS/UI/CLIMViewer.resx Normal file
View File

@ -0,0 +1,173 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="pictureBox1.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGOfPtRkwAAACBjSFJNAACH
DwAAjA8AAP1SAACBQAAAfXkAAOmLAAA85QAAGcxzPIV3AAAKOWlDQ1BQaG90b3Nob3AgSUNDIHByb2Zp
bGUAAEjHnZZ3VFTXFofPvXd6oc0wAlKG3rvAANJ7k15FYZgZYCgDDjM0sSGiAhFFRJoiSFDEgNFQJFZE
sRAUVLAHJAgoMRhFVCxvRtaLrqy89/Ly++Osb+2z97n77L3PWhcAkqcvl5cGSwGQyhPwgzyc6RGRUXTs
AIABHmCAKQBMVka6X7B7CBDJy82FniFyAl8EAfB6WLwCcNPQM4BOB/+fpFnpfIHomAARm7M5GSwRF4g4
JUuQLrbPipgalyxmGCVmvihBEcuJOWGRDT77LLKjmNmpPLaIxTmns1PZYu4V8bZMIUfEiK+ICzO5nCwR
3xKxRoowlSviN+LYVA4zAwAUSWwXcFiJIjYRMYkfEuQi4uUA4EgJX3HcVyzgZAvEl3JJS8/hcxMSBXQd
li7d1NqaQffkZKVwBALDACYrmcln013SUtOZvBwAFu/8WTLi2tJFRbY0tba0NDQzMv2qUP91829K3NtF
ehn4uWcQrf+L7a/80hoAYMyJarPziy2uCoDOLQDI3fti0zgAgKSobx3Xv7oPTTwviQJBuo2xcVZWlhGX
wzISF/QP/U+Hv6GvvmckPu6P8tBdOfFMYYqALq4bKy0lTcinZ6QzWRy64Z+H+B8H/nUeBkGceA6fwxNF
hImmjMtLELWbx+YKuGk8Opf3n5r4D8P+pMW5FonS+BFQY4yA1HUqQH7tBygKESDR+8Vd/6NvvvgwIH55
4SqTi3P/7zf9Z8Gl4iWDm/A5ziUohM4S8jMX98TPEqABAUgCKpAHykAd6ABDYAasgC1wBG7AG/iDEBAJ
VgMWSASpgA+yQB7YBApBMdgJ9oBqUAcaQTNoBcdBJzgFzoNL4Bq4AW6D+2AUTIBnYBa8BgsQBGEhMkSB
5CEVSBPSh8wgBmQPuUG+UBAUCcVCCRAPEkJ50GaoGCqDqqF6qBn6HjoJnYeuQIPQXWgMmoZ+h97BCEyC
qbASrAUbwwzYCfaBQ+BVcAK8Bs6FC+AdcCXcAB+FO+Dz8DX4NjwKP4PnEIAQERqiihgiDMQF8UeikHiE
j6xHipAKpAFpRbqRPuQmMorMIG9RGBQFRUcZomxRnqhQFAu1BrUeVYKqRh1GdaB6UTdRY6hZ1Ec0Ga2I
1kfboL3QEegEdBa6EF2BbkK3oy+ib6Mn0K8xGAwNo42xwnhiIjFJmLWYEsw+TBvmHGYQM46Zw2Kx8lh9
rB3WH8vECrCF2CrsUexZ7BB2AvsGR8Sp4Mxw7rgoHA+Xj6vAHcGdwQ3hJnELeCm8Jt4G749n43PwpfhG
fDf+On4Cv0CQJmgT7AghhCTCJkIloZVwkfCA8JJIJKoRrYmBRC5xI7GSeIx4mThGfEuSIemRXEjRJCFp
B+kQ6RzpLuklmUzWIjuSo8gC8g5yM/kC+RH5jQRFwkjCS4ItsUGiRqJDYkjiuSReUlPSSXK1ZK5kheQJ
yeuSM1J4KS0pFymm1HqpGqmTUiNSc9IUaVNpf+lU6RLpI9JXpKdksDJaMm4ybJkCmYMyF2TGKQhFneJC
YVE2UxopFykTVAxVm+pFTaIWU7+jDlBnZWVkl8mGyWbL1sielh2lITQtmhcthVZKO04bpr1borTEaQln
yfYlrUuGlszLLZVzlOPIFcm1yd2WeydPl3eTT5bfJd8p/1ABpaCnEKiQpbBf4aLCzFLqUtulrKVFS48v
vacIK+opBimuVTyo2K84p6Ss5KGUrlSldEFpRpmm7KicpFyufEZ5WoWiYq/CVSlXOavylC5Ld6Kn0Cvp
vfRZVUVVT1Whar3qgOqCmrZaqFq+WpvaQ3WCOkM9Xr1cvUd9VkNFw08jT6NF454mXpOhmai5V7NPc15L
Wytca6tWp9aUtpy2l3audov2Ax2yjoPOGp0GnVu6GF2GbrLuPt0berCehV6iXo3edX1Y31Kfq79Pf9AA
bWBtwDNoMBgxJBk6GWYathiOGdGMfI3yjTqNnhtrGEcZ7zLuM/5oYmGSYtJoct9UxtTbNN+02/R3Mz0z
llmN2S1zsrm7+QbzLvMXy/SXcZbtX3bHgmLhZ7HVosfig6WVJd+y1XLaSsMq1qrWaoRBZQQwShiXrdHW
ztYbrE9Zv7WxtBHYHLf5zdbQNtn2iO3Ucu3lnOWNy8ft1OyYdvV2o/Z0+1j7A/ajDqoOTIcGh8eO6o5s
xybHSSddpySno07PnU2c+c7tzvMuNi7rXM65Iq4erkWuA24ybqFu1W6P3NXcE9xb3Gc9LDzWepzzRHv6
eO7yHPFS8mJ5NXvNelt5r/Pu9SH5BPtU+zz21fPl+3b7wX7efrv9HqzQXMFb0ekP/L38d/s/DNAOWBPw
YyAmMCCwJvBJkGlQXlBfMCU4JvhI8OsQ55DSkPuhOqHC0J4wybDosOaw+XDX8LLw0QjjiHUR1yIVIrmR
XVHYqLCopqi5lW4r96yciLaILoweXqW9KnvVldUKq1NWn46RjGHGnIhFx4bHHol9z/RnNjDn4rziauNm
WS6svaxnbEd2OXuaY8cp40zG28WXxU8l2CXsTphOdEisSJzhunCruS+SPJPqkuaT/ZMPJX9KCU9pS8Wl
xqae5Mnwknm9acpp2WmD6frphemja2zW7Fkzy/fhN2VAGasyugRU0c9Uv1BHuEU4lmmfWZP5Jiss60S2
dDYvuz9HL2d7zmSue+63a1FrWWt78lTzNuWNrXNaV78eWh+3vmeD+oaCDRMbPTYe3kTYlLzpp3yT/LL8
V5vDN3cXKBVsLBjf4rGlpVCikF84stV2a9021DbutoHt5turtn8sYhddLTYprih+X8IqufqN6TeV33za
Eb9joNSydP9OzE7ezuFdDrsOl0mX5ZaN7/bb3VFOLy8qf7UnZs+VimUVdXsJe4V7Ryt9K7uqNKp2Vr2v
Tqy+XeNc01arWLu9dn4fe9/Qfsf9rXVKdcV17w5wD9yp96jvaNBqqDiIOZh58EljWGPft4xvm5sUmoqb
PhziHRo9HHS4t9mqufmI4pHSFrhF2DJ9NProje9cv+tqNWytb6O1FR8Dx4THnn4f+/3wcZ/jPScYJ1p/
0Pyhtp3SXtQBdeR0zHYmdo52RXYNnvQ+2dNt293+o9GPh06pnqo5LXu69AzhTMGZT2dzz86dSz83cz7h
/HhPTM/9CxEXbvUG9g5c9Ll4+ZL7pQt9Tn1nL9tdPnXF5srJq4yrndcsr3X0W/S3/2TxU/uA5UDHdavr
XTesb3QPLh88M+QwdP6m681Lt7xuXbu94vbgcOjwnZHokdE77DtTd1PuvriXeW/h/sYH6AdFD6UeVjxS
fNTws+7PbaOWo6fHXMf6Hwc/vj/OGn/2S8Yv7ycKnpCfVEyqTDZPmU2dmnafvvF05dOJZ+nPFmYKf5X+
tfa5zvMffnP8rX82YnbiBf/Fp99LXsq/PPRq2aueuYC5R69TXy/MF72Rf3P4LeNt37vwd5MLWe+x7ys/
6H7o/ujz8cGn1E+f/gUDmPP8usTo0wAAAAlwSFlzAAALEgAACxIB0t1+/AAAAERJREFUOE/tzLENADAM
w7D8f1t+clchENK96MDNciVZdXc2GpFFpBFZRBqRRaQRWUQakUWkEVlEGpFFdB3Mw+kfPHCQOn42MC4n
CVKmAAAAAElFTkSuQmCC
</value>
</data>
</root>

258
3DS/UI/CLYTViewer.Designer.cs generated Normal file
View File

@ -0,0 +1,258 @@
namespace _3DS.UI
{
partial class CLYTViewer
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.splitContainer2 = new System.Windows.Forms.SplitContainer();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.treeView1 = new System.Windows.Forms.TreeView();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.tabPage3 = new System.Windows.Forms.TabPage();
this.tabPage4 = new System.Windows.Forms.TabPage();
this.tabPage5 = new System.Windows.Forms.TabPage();
this.propertyGrid1 = new System.Windows.Forms.PropertyGrid();
this.simpleOpenGlControl1 = new Tao.Platform.Windows.SimpleOpenGlControl();
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
this.mainMenu1 = new LibEveryFileExplorer.UI.MainMenu(this.components);
this.treeView2 = new System.Windows.Forms.TreeView();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).BeginInit();
this.splitContainer2.Panel1.SuspendLayout();
this.splitContainer2.Panel2.SuspendLayout();
this.splitContainer2.SuspendLayout();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.tabPage2.SuspendLayout();
this.SuspendLayout();
//
// splitContainer1
//
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer1.FixedPanel = System.Windows.Forms.FixedPanel.Panel1;
this.splitContainer1.Location = new System.Drawing.Point(0, 0);
this.splitContainer1.Name = "splitContainer1";
//
// splitContainer1.Panel1
//
this.splitContainer1.Panel1.Controls.Add(this.splitContainer2);
//
// splitContainer1.Panel2
//
this.splitContainer1.Panel2.Controls.Add(this.simpleOpenGlControl1);
this.splitContainer1.Panel2.Controls.Add(this.toolStrip1);
this.splitContainer1.Size = new System.Drawing.Size(582, 387);
this.splitContainer1.SplitterDistance = 194;
this.splitContainer1.TabIndex = 0;
//
// splitContainer2
//
this.splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer2.FixedPanel = System.Windows.Forms.FixedPanel.Panel1;
this.splitContainer2.Location = new System.Drawing.Point(0, 0);
this.splitContainer2.Name = "splitContainer2";
this.splitContainer2.Orientation = System.Windows.Forms.Orientation.Horizontal;
//
// splitContainer2.Panel1
//
this.splitContainer2.Panel1.Controls.Add(this.tabControl1);
//
// splitContainer2.Panel2
//
this.splitContainer2.Panel2.Controls.Add(this.propertyGrid1);
this.splitContainer2.Size = new System.Drawing.Size(194, 387);
this.splitContainer2.SplitterDistance = 182;
this.splitContainer2.TabIndex = 0;
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Controls.Add(this.tabPage3);
this.tabControl1.Controls.Add(this.tabPage4);
this.tabControl1.Controls.Add(this.tabPage5);
this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabControl1.Location = new System.Drawing.Point(0, 0);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(194, 182);
this.tabControl1.TabIndex = 0;
//
// tabPage1
//
this.tabPage1.Controls.Add(this.treeView1);
this.tabPage1.Location = new System.Drawing.Point(4, 22);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Size = new System.Drawing.Size(186, 156);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "Hierarchy";
this.tabPage1.UseVisualStyleBackColor = true;
//
// treeView1
//
this.treeView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.treeView1.HideSelection = false;
this.treeView1.HotTracking = true;
this.treeView1.Location = new System.Drawing.Point(0, 0);
this.treeView1.Name = "treeView1";
this.treeView1.Size = new System.Drawing.Size(186, 156);
this.treeView1.TabIndex = 0;
//
// tabPage2
//
this.tabPage2.Controls.Add(this.treeView2);
this.tabPage2.Location = new System.Drawing.Point(4, 22);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Size = new System.Drawing.Size(186, 156);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "Groups";
this.tabPage2.UseVisualStyleBackColor = true;
//
// tabPage3
//
this.tabPage3.Location = new System.Drawing.Point(4, 22);
this.tabPage3.Name = "tabPage3";
this.tabPage3.Padding = new System.Windows.Forms.Padding(3);
this.tabPage3.Size = new System.Drawing.Size(186, 156);
this.tabPage3.TabIndex = 2;
this.tabPage3.Text = "Materials";
this.tabPage3.UseVisualStyleBackColor = true;
//
// tabPage4
//
this.tabPage4.Location = new System.Drawing.Point(4, 22);
this.tabPage4.Name = "tabPage4";
this.tabPage4.Padding = new System.Windows.Forms.Padding(3);
this.tabPage4.Size = new System.Drawing.Size(186, 156);
this.tabPage4.TabIndex = 3;
this.tabPage4.Text = "Textures";
this.tabPage4.UseVisualStyleBackColor = true;
//
// tabPage5
//
this.tabPage5.Location = new System.Drawing.Point(4, 22);
this.tabPage5.Name = "tabPage5";
this.tabPage5.Padding = new System.Windows.Forms.Padding(3);
this.tabPage5.Size = new System.Drawing.Size(186, 156);
this.tabPage5.TabIndex = 4;
this.tabPage5.Text = "Fonts";
this.tabPage5.UseVisualStyleBackColor = true;
//
// propertyGrid1
//
this.propertyGrid1.Dock = System.Windows.Forms.DockStyle.Fill;
this.propertyGrid1.Location = new System.Drawing.Point(0, 0);
this.propertyGrid1.Name = "propertyGrid1";
this.propertyGrid1.Size = new System.Drawing.Size(194, 201);
this.propertyGrid1.TabIndex = 0;
//
// simpleOpenGlControl1
//
this.simpleOpenGlControl1.AccumBits = ((byte)(0));
this.simpleOpenGlControl1.AutoCheckErrors = false;
this.simpleOpenGlControl1.AutoFinish = false;
this.simpleOpenGlControl1.AutoMakeCurrent = true;
this.simpleOpenGlControl1.AutoSwapBuffers = true;
this.simpleOpenGlControl1.BackColor = System.Drawing.Color.Black;
this.simpleOpenGlControl1.ColorBits = ((byte)(32));
this.simpleOpenGlControl1.DepthBits = ((byte)(16));
this.simpleOpenGlControl1.Location = new System.Drawing.Point(0, 25);
this.simpleOpenGlControl1.Name = "simpleOpenGlControl1";
this.simpleOpenGlControl1.Size = new System.Drawing.Size(384, 362);
this.simpleOpenGlControl1.StencilBits = ((byte)(0));
this.simpleOpenGlControl1.TabIndex = 1;
//
// toolStrip1
//
this.toolStrip1.Location = new System.Drawing.Point(0, 0);
this.toolStrip1.Name = "toolStrip1";
this.toolStrip1.Size = new System.Drawing.Size(384, 25);
this.toolStrip1.TabIndex = 0;
this.toolStrip1.Text = "toolStrip1";
//
// treeView2
//
this.treeView2.Dock = System.Windows.Forms.DockStyle.Fill;
this.treeView2.HideSelection = false;
this.treeView2.HotTracking = true;
this.treeView2.Location = new System.Drawing.Point(0, 0);
this.treeView2.Name = "treeView2";
this.treeView2.Size = new System.Drawing.Size(186, 156);
this.treeView2.TabIndex = 0;
//
// CLYTViewer
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(582, 387);
this.Controls.Add(this.splitContainer1);
this.Menu = this.mainMenu1;
this.Name = "CLYTViewer";
this.Text = "CLYTViewer";
this.Load += new System.EventHandler(this.CLYTViewer_Load);
this.Layout += new System.Windows.Forms.LayoutEventHandler(this.CLYTViewer_Layout);
this.Resize += new System.EventHandler(this.CLYTViewer_Resize);
this.splitContainer1.Panel1.ResumeLayout(false);
this.splitContainer1.Panel2.ResumeLayout(false);
this.splitContainer1.Panel2.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
this.splitContainer1.ResumeLayout(false);
this.splitContainer2.Panel1.ResumeLayout(false);
this.splitContainer2.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).EndInit();
this.splitContainer2.ResumeLayout(false);
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.tabPage2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.SplitContainer splitContainer1;
private System.Windows.Forms.SplitContainer splitContainer2;
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.PropertyGrid propertyGrid1;
private Tao.Platform.Windows.SimpleOpenGlControl simpleOpenGlControl1;
private System.Windows.Forms.ToolStrip toolStrip1;
private LibEveryFileExplorer.UI.MainMenu mainMenu1;
private System.Windows.Forms.TabPage tabPage3;
private System.Windows.Forms.TabPage tabPage4;
private System.Windows.Forms.TabPage tabPage5;
private System.Windows.Forms.TreeView treeView1;
private System.Windows.Forms.TreeView treeView2;
}
}

237
3DS/UI/CLYTViewer.cs Normal file
View File

@ -0,0 +1,237 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using _3DS.NintendoWare.LYT;
using Tao.OpenGl;
using LibEveryFileExplorer.Files;
using System.Drawing.Imaging;
using NintendoWare.LYT;
using System.Runtime.InteropServices;
namespace _3DS.UI
{
public partial class CLYTViewer : Form
{
bool init = false;
CLYT NWLayout;
CLIM[] Textures;
BasicShader BShader = new BasicShader();
ImageList ImageL;
[DllImport("uxtheme.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
private static extern int SetWindowTheme(IntPtr hWnd, string appName, string partList);
public CLYTViewer(CLYT Layout)
{
this.NWLayout = Layout;
InitializeComponent();
SetWindowTheme(treeView1.Handle, "explorer", null);
SetWindowTheme(treeView2.Handle, "explorer", null);
}
private void CLYTViewer_Load(object sender, EventArgs e)
{
simpleOpenGlControl1.InitializeContexts();
simpleOpenGlControl1.Width = (int)NWLayout.Layout.LayoutSize.X;
simpleOpenGlControl1.Height = (int)NWLayout.Layout.LayoutSize.Y;
Gl.ReloadFunctions();
Gl.glEnable(Gl.GL_COLOR_MATERIAL);
Gl.glDisable(Gl.GL_DEPTH_TEST);
//Gl.glDepthFunc(Gl.GL_ALWAYS);
Gl.glEnable(Gl.GL_LOGIC_OP);
Gl.glDisable(Gl.GL_CULL_FACE);
Gl.glEnable(Gl.GL_TEXTURE_2D);
//Gl.glEnable(Gl.GL_LINE_SMOOTH);
Gl.glEnable(Gl.GL_BLEND);
Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);
if (NWLayout.TextureList != null)
{
int i = 0;
Textures = new CLIM[NWLayout.TextureList.NrTextures];
foreach (String s in NWLayout.TextureList.TextureNames)
{
byte[] data = data = ((ViewableFile)Tag).File.FindFileRelative("../timg/" + s);
if (data == null) data = ((ViewableFile)Tag).File.FindFileRelative(s);
if (data != null) Textures[i] = new CLIM(data);
i++;
}
}
if (NWLayout.Materials != null)
{
int i = 0;
foreach (var v in NWLayout.Materials.Materials)
{
int j = 0;
foreach (var t in v.TexMaps)
{
if (Textures[t.TexIndex] != null) UploadTex(t, Textures[t.TexIndex], i * 4 + j + 1);
j++;
}
v.SetupShader();
i++;
}
}
BShader.Compile(false);
ImageL = new ImageList();
ImageL.ColorDepth = ColorDepth.Depth32Bit;
ImageL.ImageSize = new System.Drawing.Size(16, 16);
ImageL.Images.Add("pan1", Resource.zone16);
ImageL.Images.Add("pic1", Resource.image16);
ImageL.Images.Add("wnd1", Resource.slide);
ImageL.Images.Add("txt1", Resource.edit);
ImageL.Images.Add("grp1", Resource.zones_stack);
treeView1.ImageList = ImageL;
treeView2.ImageList = ImageL;
treeView1.BeginUpdate();
treeView1.Nodes.Clear();
treeView1.Nodes.Add(NWLayout.RootPane.GetTreeNodes());
treeView1.EndUpdate();
treeView2.BeginUpdate();
treeView2.Nodes.Clear();
treeView2.Nodes.Add(NWLayout.RootGroup.GetTreeNodes());
treeView2.EndUpdate();
init = true;
Render();
}
private void UploadTex(mat1.MaterialEntry.TexMap TexMap, CLIM Texture, int Id)
{
Gl.glBindTexture(Gl.GL_TEXTURE_2D, Id);
Gl.glColor3f(1, 1, 1);
Bitmap b = Texture.ToBitmap();
//b.RotateFlip(RotateFlipType.RotateNoneFlipY);
BitmapData d = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGBA8, b.Width, b.Height, 0, Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, d.Scan0);
b.UnlockBits(d);
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, (TexMap.MagFilter == mat1.MaterialEntry.TexMap.FilterMode.Linear) ? Gl.GL_LINEAR : Gl.GL_NEAREST);
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, (TexMap.MinFilter == mat1.MaterialEntry.TexMap.FilterMode.Linear) ? Gl.GL_LINEAR : Gl.GL_NEAREST);
switch (TexMap.WrapS)
{
case mat1.MaterialEntry.TexMap.WrapMode.Clamp:
Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_CLAMP_TO_EDGE);
break;
case mat1.MaterialEntry.TexMap.WrapMode.Repeat:
Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_REPEAT);
break;
case mat1.MaterialEntry.TexMap.WrapMode.Mirror:
Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_MIRRORED_REPEAT);
break;
default:
Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_REPEAT);
break;
}
switch (TexMap.WrapT)
{
case mat1.MaterialEntry.TexMap.WrapMode.Clamp:
Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_CLAMP_TO_EDGE);
break;
case mat1.MaterialEntry.TexMap.WrapMode.Repeat:
Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_REPEAT);
break;
case mat1.MaterialEntry.TexMap.WrapMode.Mirror:
Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_MIRRORED_REPEAT);
break;
default:
Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_REPEAT);
break;
}
}
public void Render()
{
if (!init) return;
Gl.glMatrixMode(Gl.GL_PROJECTION);
Gl.glLoadIdentity();
Gl.glViewport(0, 0, simpleOpenGlControl1.Width, simpleOpenGlControl1.Height);
Gl.glOrtho(-NWLayout.Layout.LayoutSize.X / 2.0f, NWLayout.Layout.LayoutSize.X / 2.0f, -NWLayout.Layout.LayoutSize.Y / 2.0f, NWLayout.Layout.LayoutSize.Y / 2.0f, -1000, 1000);
//Glu.gluPerspective(90, aspect, 0.02f, 1000.0f);//0.02f, 32.0f);
//Gl.glTranslatef(0, 0, -100);
Gl.glMatrixMode(Gl.GL_MODELVIEW);
Gl.glLoadIdentity();
/*if (!picking)*/
Gl.glClearColor(1, 1, 1, 1);//BGColor.R / 255f, BGColor.G / 255f, BGColor.B / 255f, 1f);
//else Gl.glClearColor(0, 0, 0, 1);
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
Gl.glColor4f(1, 1, 1, 1);
Gl.glEnable(Gl.GL_TEXTURE_2D);
Gl.glBindTexture(Gl.GL_TEXTURE_2D, 0);
Gl.glColor4f(1, 1, 1, 1);
Gl.glDisable(Gl.GL_CULL_FACE);
Gl.glEnable(Gl.GL_ALPHA_TEST);
Gl.glEnable(Gl.GL_BLEND);
Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);
Gl.glAlphaFunc(Gl.GL_ALWAYS, 0f);
Gl.glLoadIdentity();
//if (!picking)
{
Gl.glBindTexture(Gl.GL_TEXTURE_2D, 0);
BShader.Enable();
Gl.glBindTexture(Gl.GL_TEXTURE_2D, 0);
Gl.glColor4f(204 / 255f, 204 / 255f, 204 / 255f, 1);
int xbase = 0;
for (int y = 0; y < simpleOpenGlControl1.Height; y += 8)
{
for (int x = xbase; x < simpleOpenGlControl1.Width; x += 16)
{
Gl.glRectf(x - simpleOpenGlControl1.Width / 2f, y - simpleOpenGlControl1.Height / 2f, x - simpleOpenGlControl1.Width / 2f + 8, y - simpleOpenGlControl1.Height / 2f + 8);
}
if (xbase == 0) xbase = 8;
else xbase = 0;
}
}
/*if (picking)
{
BasicShaderb.Enable();
int idx = 0;
Layout.PAN1.Render(Layout, ref idx, 255, picking);
pic = new byte[4];
Bitmap b = IO.Util.ScreenShot(simpleOpenGlControl1);
Gl.glReadPixels(MousePoint.X, (int)simpleOpenGlControl1.Height - MousePoint.Y, 1, 1, Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, pic);
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
Render();
//simpleOpenGlControl1.Refresh();
//Render();
}
else
{*/
NWLayout.RootPane.Render(NWLayout, Textures, 255);
simpleOpenGlControl1.Refresh();
//}
}
private void CLYTViewer_Layout(object sender, LayoutEventArgs e)
{
Render();
}
private void CLYTViewer_Resize(object sender, EventArgs e)
{
Render();
Render();
}
}
}

126
3DS/UI/CLYTViewer.resx Normal file
View File

@ -0,0 +1,126 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="toolStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="mainMenu1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>122, 17</value>
</metadata>
</root>

151
3DS/UI/DARCViewer.Designer.cs generated Normal file
View File

@ -0,0 +1,151 @@
namespace _3DS.UI
{
partial class DARCViewer
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(DARCViewer));
this.mainMenu1 = new LibEveryFileExplorer.UI.MainMenu(this.components);
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuExport = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuExportDir = new System.Windows.Forms.MenuItem();
this.fileBrowser1 = new LibEveryFileExplorer.UI.FileBrowser();
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.contextMenu1 = new System.Windows.Forms.ContextMenu();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
this.SuspendLayout();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.menuItem2});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuExport});
this.menuItem1.MergeOrder = 1;
this.menuItem1.MergeType = System.Windows.Forms.MenuMerge.MergeItems;
this.menuItem1.Text = "Edit";
//
// menuExport
//
this.menuExport.Enabled = false;
this.menuExport.Index = 0;
this.menuExport.Text = "Export...";
this.menuExport.Click += new System.EventHandler(this.OnExport);
//
// menuItem2
//
this.menuItem2.Index = 1;
this.menuItem2.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem3,
this.menuExportDir});
this.menuItem2.MergeOrder = 2;
this.menuItem2.MergeType = System.Windows.Forms.MenuMerge.MergeItems;
this.menuItem2.Text = "Tools";
//
// menuItem3
//
this.menuItem3.Index = 0;
this.menuItem3.Text = "-";
//
// menuExportDir
//
this.menuExportDir.Index = 1;
this.menuExportDir.Text = "Export Directory Content...";
this.menuExportDir.Click += new System.EventHandler(this.menuExportDir_Click);
//
// fileBrowser1
//
this.fileBrowser1.DeleteEnabled = true;
this.fileBrowser1.Dock = System.Windows.Forms.DockStyle.Fill;
this.fileBrowser1.Location = new System.Drawing.Point(0, 0);
this.fileBrowser1.Name = "fileBrowser1";
this.fileBrowser1.RenameEnabled = true;
this.fileBrowser1.ShowAddDirectoryButton = false;
this.fileBrowser1.ShowAddFileButton = false;
this.fileBrowser1.ShowDeleteButton = false;
this.fileBrowser1.ShowRenameButton = false;
this.fileBrowser1.Size = new System.Drawing.Size(652, 338);
this.fileBrowser1.TabIndex = 0;
this.fileBrowser1.OnDirectoryChanged += new LibEveryFileExplorer.UI.FileBrowser.OnDirectoryChangedEventHandler(this.fileBrowser1_OnDirectoryChanged);
this.fileBrowser1.OnFileActivated += new LibEveryFileExplorer.UI.FileBrowser.OnFileActivatedEventHandler(this.fileBrowser1_OnFileActivated);
this.fileBrowser1.OnSelectionChanged += new System.EventHandler(this.fileBrowser1_OnSelectionChanged);
this.fileBrowser1.OnRightClick += new LibEveryFileExplorer.UI.FileBrowser.OnRightClickEventHandler(this.fileBrowser1_OnRightClick);
//
// contextMenu1
//
this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem4});
//
// menuItem4
//
this.menuItem4.Index = 0;
this.menuItem4.Text = "Export...";
this.menuItem4.Click += new System.EventHandler(this.OnExport);
//
// folderBrowserDialog1
//
this.folderBrowserDialog1.Description = "Select the directory to export the content of current directory to.";
//
// DARCViewer
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(652, 338);
this.Controls.Add(this.fileBrowser1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Menu = this.mainMenu1;
this.Name = "DARCViewer";
this.Text = "DARC Viewer";
this.Load += new System.EventHandler(this.SARCViewer_Load);
this.ResumeLayout(false);
}
#endregion
private LibEveryFileExplorer.UI.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private LibEveryFileExplorer.UI.FileBrowser fileBrowser1;
private System.Windows.Forms.MenuItem menuExport;
private System.Windows.Forms.SaveFileDialog saveFileDialog1;
private System.Windows.Forms.ContextMenu contextMenu1;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuExportDir;
private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1;
}
}

85
3DS/UI/DARCViewer.cs Normal file
View File

@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LibEveryFileExplorer.Files.SimpleFileSystem;
using LibEveryFileExplorer.Files;
using LibEveryFileExplorer;
namespace _3DS.UI
{
public partial class DARCViewer : Form
{
DARC Archive;
SFSDirectory Root;
public DARCViewer(DARC Archive)
{
Root = Archive.ToFileSystem();
InitializeComponent();
}
private void SARCViewer_Load(object sender, EventArgs e)
{
fileBrowser1.UpdateDirectories(Root.GetTreeNodes());
}
private void fileBrowser1_OnDirectoryChanged(string Path)
{
var d = Root.GetDirectoryByPath(Path);
fileBrowser1.UpdateContent(d.GetContent());
}
private void fileBrowser1_OnFileActivated(string Path)
{
var s = Root.GetFileByPath(Path);
EveryFileExplorerUtil.OpenFile(new EFESFSFile(s), ((ViewableFile)Tag).File);
}
private void OnExport(object sender, EventArgs e)
{
var file = Root.GetFileByPath(fileBrowser1.SelectedPath);
if (file == null) return;
saveFileDialog1.Filter = System.IO.Path.GetExtension(fileBrowser1.SelectedPath).Replace(".", "").ToUpper() + " Files (*" + System.IO.Path.GetExtension(fileBrowser1.SelectedPath).ToLower() + ")|*" + System.IO.Path.GetExtension(fileBrowser1.SelectedPath).ToLower() + "|All Files (*.*)|*.*";
saveFileDialog1.FileName = System.IO.Path.GetFileName(fileBrowser1.SelectedPath);
if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK
&& saveFileDialog1.FileName.Length > 0)
{
System.IO.File.Create(saveFileDialog1.FileName).Close();
System.IO.File.WriteAllBytes(saveFileDialog1.FileName, file.Data);
}
}
private void fileBrowser1_OnSelectionChanged(object sender, EventArgs e)
{
menuExport.Enabled = !(fileBrowser1.SelectedPath == fileBrowser1.SelectedFolderPath);
}
private void fileBrowser1_OnRightClick(Point Location)
{
var dir = Root.GetDirectoryByPath(fileBrowser1.SelectedPath);
if (dir != null)
{
}
else
{
//var file = Root.GetFileByPath(fileBrowser1.SelectedPath);
contextMenu1.Show(fileBrowser1, Location);
}
}
private void menuExportDir_Click(object sender, EventArgs e)
{
var dir = Root.GetDirectoryByPath(fileBrowser1.SelectedFolderPath);
if (folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK
&& folderBrowserDialog1.SelectedPath.Length > 0)
{
dir.Export(folderBrowserDialog1.SelectedPath);
}
}
}
}

157
3DS/UI/DARCViewer.resx Normal file
View File

@ -0,0 +1,157 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="mainMenu1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="saveFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>134, 17</value>
</metadata>
<metadata name="contextMenu1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>270, 17</value>
</metadata>
<metadata name="folderBrowserDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>400, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAQAQAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAADwAAABcAAAAaAAAAGgAAABoAAAAaAAAAGgAAABoAAAAaAAAAGgAAABoAAAAaAAAAGgAA
ABoAAAAXAAAADwAAAB4BM2aeAUSHxQFEh8UBRIfFAUSHxQFEh8UBRIfFAUSHxQFEh8UBRIfFAUSHxQFE
h8UBRIfFATNmngAAAB4AAAAAAUqUuHuu4P96rd//eq3f/3qt3/96rd//eq3f/3qt3/96rd//eq3f/3qt
3/96rd//e67g/wFKlLgAAAAAAAAAAAJRoKuBtOT/fbDh/32w4f99sOH/fbDh/2yf0P9ajb//Wo2//1qN
v/9ajb//Wo2//3Cj0/8CUaCrAAAAAAAAAAACVKSmiLvq/4K15f+CteX/grXl/4K15f9jlsf/4uLR/+Li
0f/i4tH/4uLR/+Li0f9pnMv/AlSkpgAAAAAAAAAAA1aoo4/C7v+Huun/h7rp/4e66f+Huun/cKPT/+zs
2/+6uqn/0NC//83NvP/s7Nv/eKvY/wNWqKMAAAAAAAAAAANYrJ+WyfL/jL/s/4y/7P+Mv+z/RHeq/0J1
qP/19eT/9fXk//X15P/19eT/9fXk/4i75f8DWKyfAAAAAAAAAAADWrCbm872/5HE8P+RxPD/kcTw/1WI
u/9Uh7r//8tD//zFPf/4vTX/87Ut//CuJv+WyfL/A1qwmwAAAAAAAAAAA1uzmJ/S+f+VyPP/lcjz/5XI
8/9ViLv/VYi7/1WIu/9NgLP/lcjz/5XI8/+VyPP/n9L5/wNbs5gAAAAAAAAAAANdtpWn2/79qt3//6rd
//+q3f//d6rd/3eq3f93qt3/ZpnM/6rd//+q3f//qt3//6fb/v0DXbaVAAAAAAAAAAAEX7lta6bf4ICz
5v+As+b/gLPm/06BtP9OgbT/ToG0/0h7rv+As+b/gLPm/4Cz5v9rpt/gBF+5bQAAAAAAAAAABGC8R02U
2cSJvO//iLvu/4i77v9BdKf/QXSn/0F0p/8+caT/iLvu/4i77v+JvO//TZTZxARgvEcAAAAAAAAAAARh
viMqfMylibzv/4i77v+Iu+7/NWib/zVom/81aJv/NWib/4i77v+Iu+7/ibzv/yp8zKUEYb4jAAAAAAAA
AAAEYr8EBGLAaARiwIsEYsCLBGLAiwBAgMwAQIDMAECAzABAgMwEYsCLBGLAiwRiwIsEYsBoBGK/BAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAA//8AAAAAAAAAAAAAgAEAAIABAACAAQAAgAEAAIABAACAAQAAgAEAAIABAACAAQAAgAEAAIAB
AACAAQAA//8AAA==
</value>
</data>
</root>

192
3DS/UI/SARCViewer.Designer.cs generated Normal file
View File

@ -0,0 +1,192 @@
namespace _3DS.UI
{
partial class SARCViewer
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SARCViewer));
this.mainMenu1 = new LibEveryFileExplorer.UI.MainMenu(this.components);
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuExport = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.menuReplace = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuExportDir = new System.Windows.Forms.MenuItem();
this.fileBrowser1 = new LibEveryFileExplorer.UI.FileBrowser();
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.contextMenu1 = new System.Windows.Forms.ContextMenu();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuItem7 = new System.Windows.Forms.MenuItem();
this.menuItem8 = new System.Windows.Forms.MenuItem();
this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.SuspendLayout();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.menuItem2});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuExport,
this.menuItem5,
this.menuReplace});
this.menuItem1.MergeOrder = 1;
this.menuItem1.MergeType = System.Windows.Forms.MenuMerge.MergeItems;
this.menuItem1.Text = "Edit";
//
// menuExport
//
this.menuExport.Enabled = false;
this.menuExport.Index = 0;
this.menuExport.Text = "Export...";
this.menuExport.Click += new System.EventHandler(this.OnExport);
//
// menuItem5
//
this.menuItem5.Index = 1;
this.menuItem5.Text = "-";
//
// menuReplace
//
this.menuReplace.Enabled = false;
this.menuReplace.Index = 2;
this.menuReplace.Text = "Replace...";
this.menuReplace.Click += new System.EventHandler(this.menuReplace_Click);
//
// menuItem2
//
this.menuItem2.Index = 1;
this.menuItem2.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem3,
this.menuExportDir});
this.menuItem2.MergeOrder = 2;
this.menuItem2.MergeType = System.Windows.Forms.MenuMerge.MergeItems;
this.menuItem2.Text = "Tools";
//
// menuItem3
//
this.menuItem3.Index = 0;
this.menuItem3.Text = "-";
//
// menuExportDir
//
this.menuExportDir.Index = 1;
this.menuExportDir.Text = "Export Directory Content...";
this.menuExportDir.Click += new System.EventHandler(this.menuExportDir_Click);
//
// fileBrowser1
//
this.fileBrowser1.DeleteEnabled = true;
this.fileBrowser1.Dock = System.Windows.Forms.DockStyle.Fill;
this.fileBrowser1.Location = new System.Drawing.Point(0, 0);
this.fileBrowser1.Name = "fileBrowser1";
this.fileBrowser1.RenameEnabled = true;
this.fileBrowser1.ShowAddDirectoryButton = false;
this.fileBrowser1.ShowAddFileButton = false;
this.fileBrowser1.ShowDeleteButton = false;
this.fileBrowser1.ShowRenameButton = false;
this.fileBrowser1.Size = new System.Drawing.Size(652, 338);
this.fileBrowser1.TabIndex = 0;
this.fileBrowser1.OnDirectoryChanged += new LibEveryFileExplorer.UI.FileBrowser.OnDirectoryChangedEventHandler(this.fileBrowser1_OnDirectoryChanged);
this.fileBrowser1.OnFileActivated += new LibEveryFileExplorer.UI.FileBrowser.OnFileActivatedEventHandler(this.fileBrowser1_OnFileActivated);
this.fileBrowser1.OnSelectionChanged += new System.EventHandler(this.fileBrowser1_OnSelectionChanged);
this.fileBrowser1.OnRightClick += new LibEveryFileExplorer.UI.FileBrowser.OnRightClickEventHandler(this.fileBrowser1_OnRightClick);
//
// contextMenu1
//
this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem4,
this.menuItem7,
this.menuItem8});
//
// menuItem4
//
this.menuItem4.Index = 0;
this.menuItem4.Text = "Export...";
this.menuItem4.Click += new System.EventHandler(this.OnExport);
//
// menuItem7
//
this.menuItem7.Index = 1;
this.menuItem7.Text = "-";
//
// menuItem8
//
this.menuItem8.Index = 2;
this.menuItem8.Text = "Replace...";
this.menuItem8.Click += new System.EventHandler(this.menuReplace_Click);
//
// folderBrowserDialog1
//
this.folderBrowserDialog1.Description = "Select the directory to export the content of current directory to.";
//
// openFileDialog1
//
this.openFileDialog1.FileName = "openFileDialog1";
//
// SARCViewer
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(652, 338);
this.Controls.Add(this.fileBrowser1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Menu = this.mainMenu1;
this.Name = "SARCViewer";
this.Text = "SARC Viewer";
this.Load += new System.EventHandler(this.SARCViewer_Load);
this.ResumeLayout(false);
}
#endregion
private LibEveryFileExplorer.UI.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private LibEveryFileExplorer.UI.FileBrowser fileBrowser1;
private System.Windows.Forms.MenuItem menuExport;
private System.Windows.Forms.SaveFileDialog saveFileDialog1;
private System.Windows.Forms.ContextMenu contextMenu1;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuExportDir;
private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.MenuItem menuReplace;
private System.Windows.Forms.MenuItem menuItem7;
private System.Windows.Forms.MenuItem menuItem8;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
}
}

105
3DS/UI/SARCViewer.cs Normal file
View File

@ -0,0 +1,105 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LibEveryFileExplorer.Files.SimpleFileSystem;
using LibEveryFileExplorer.Files;
using LibEveryFileExplorer;
namespace _3DS.UI
{
public partial class SARCViewer : Form, IChildReactive
{
SARC Archive;
SFSDirectory Root;
public SARCViewer(SARC Archive)
{
this.Archive = Archive;
Root = Archive.ToFileSystem();
InitializeComponent();
}
private void SARCViewer_Load(object sender, EventArgs e)
{
fileBrowser1.UpdateDirectories(Root.GetTreeNodes());
}
private void fileBrowser1_OnDirectoryChanged(string Path)
{
var d = Root.GetDirectoryByPath(Path);
fileBrowser1.UpdateContent(d.GetContent());
}
private void fileBrowser1_OnFileActivated(string Path)
{
var s = Root.GetFileByPath(Path);
EveryFileExplorerUtil.OpenFile(new SARCEFESFSFile(s), ((ViewableFile)Tag).File);
}
private void OnExport(object sender, EventArgs e)
{
var file = Root.GetFileByPath(fileBrowser1.SelectedPath);
if (file == null) return;
saveFileDialog1.Filter = "Binary File (*.bin)|*.bin|All Files (*.*)|*.*";//System.IO.Path.GetExtension(fileBrowser1.SelectedPath).Replace(".", "").ToUpper() + " Files (*" + System.IO.Path.GetExtension(fileBrowser1.SelectedPath).ToLower() + ")|*" + System.IO.Path.GetExtension(fileBrowser1.SelectedPath).ToLower() + "|All Files (*.*)|*.*";
saveFileDialog1.FileName = System.IO.Path.GetFileName(fileBrowser1.SelectedPath);
if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK
&& saveFileDialog1.FileName.Length > 0)
{
System.IO.File.Create(saveFileDialog1.FileName).Close();
System.IO.File.WriteAllBytes(saveFileDialog1.FileName, file.Data);
}
}
private void fileBrowser1_OnSelectionChanged(object sender, EventArgs e)
{
if (Root.GetDirectoryByPath(fileBrowser1.SelectedPath) == null) menuExport.Enabled = menuReplace.Enabled = true;
else menuExport.Enabled = menuReplace.Enabled = false;
}
private void fileBrowser1_OnRightClick(Point Location)
{
var dir = Root.GetDirectoryByPath(fileBrowser1.SelectedPath);
if (dir != null)
{
}
else
{
//var file = Root.GetFileByPath(fileBrowser1.SelectedPath);
contextMenu1.Show(fileBrowser1, Location);
}
}
private void menuExportDir_Click(object sender, EventArgs e)
{
var dir = Root.GetDirectoryByPath(fileBrowser1.SelectedFolderPath);
if (folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK
&& folderBrowserDialog1.SelectedPath.Length > 0)
{
dir.Export(folderBrowserDialog1.SelectedPath);
}
}
private void menuReplace_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK
&& openFileDialog1.FileName.Length > 0)
{
var file = Root.GetFileByPath(fileBrowser1.SelectedPath);
file.Data = System.IO.File.ReadAllBytes(openFileDialog1.FileName);
Archive.FromFileSystem(Root);
fileBrowser1.UpdateDirectories(Root.GetTreeNodes(), true);
}
}
public void OnChildSave(ViewableFile File)
{
Archive.FromFileSystem(Root);
fileBrowser1.UpdateDirectories(Root.GetTreeNodes(), true);
}
}
}

160
3DS/UI/SARCViewer.resx Normal file
View File

@ -0,0 +1,160 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="mainMenu1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="saveFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>134, 17</value>
</metadata>
<metadata name="contextMenu1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>270, 17</value>
</metadata>
<metadata name="folderBrowserDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>400, 17</value>
</metadata>
<metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>569, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAQAQAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAADwAAABcAAAAaAAAAGgAAABoAAAAaAAAAGgAAABoAAAAaAAAAGgAAABoAAAAaAAAAGgAA
ABoAAAAXAAAADwAAAB4BM2aeAUSHxQFEh8UBRIfFAUSHxQFEh8UBRIfFAUSHxQFEh8UBRIfFAUSHxQFE
h8UBRIfFATNmngAAAB4AAAAAAUqUuHuu4P96rd//eq3f/3qt3/96rd//eq3f/3qt3/96rd//eq3f/3qt
3/96rd//e67g/wFKlLgAAAAAAAAAAAJRoKuBtOT/fbDh/32w4f99sOH/fbDh/2yf0P9ajb//Wo2//1qN
v/9ajb//Wo2//3Cj0/8CUaCrAAAAAAAAAAACVKSmiLvq/4K15f+CteX/grXl/4K15f9jlsf/4uLR/+Li
0f/i4tH/4uLR/+Li0f9pnMv/AlSkpgAAAAAAAAAAA1aoo4/C7v+Huun/h7rp/4e66f+Huun/cKPT/+zs
2/+6uqn/0NC//83NvP/s7Nv/eKvY/wNWqKMAAAAAAAAAAANYrJ+WyfL/jL/s/4y/7P+Mv+z/RHeq/0J1
qP/19eT/9fXk//X15P/19eT/9fXk/4i75f8DWKyfAAAAAAAAAAADWrCbm872/5HE8P+RxPD/kcTw/1WI
u/9Uh7r//8tD//zFPf/4vTX/87Ut//CuJv+WyfL/A1qwmwAAAAAAAAAAA1uzmJ/S+f+VyPP/lcjz/5XI
8/9ViLv/VYi7/1WIu/9NgLP/lcjz/5XI8/+VyPP/n9L5/wNbs5gAAAAAAAAAAANdtpWn2/79qt3//6rd
//+q3f//d6rd/3eq3f93qt3/ZpnM/6rd//+q3f//qt3//6fb/v0DXbaVAAAAAAAAAAAEX7lta6bf4ICz
5v+As+b/gLPm/06BtP9OgbT/ToG0/0h7rv+As+b/gLPm/4Cz5v9rpt/gBF+5bQAAAAAAAAAABGC8R02U
2cSJvO//iLvu/4i77v9BdKf/QXSn/0F0p/8+caT/iLvu/4i77v+JvO//TZTZxARgvEcAAAAAAAAAAARh
viMqfMylibzv/4i77v+Iu+7/NWib/zVom/81aJv/NWib/4i77v+Iu+7/ibzv/yp8zKUEYb4jAAAAAAAA
AAAEYr8EBGLAaARiwIsEYsCLBGLAiwBAgMwAQIDMAECAzABAgMwEYsCLBGLAiwRiwIsEYsBoBGK/BAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAA//8AAAAAAAAAAAAAgAEAAIABAACAAQAAgAEAAIABAACAAQAAgAEAAIABAACAAQAAgAEAAIAB
AACAAQAA//8AAA==
</value>
</data>
</root>

317
3DS/UI/SMDHViewer.Designer.cs generated Normal file
View File

@ -0,0 +1,317 @@
namespace _3DS.UI
{
partial class SMDHViewer
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle12 = new System.Windows.Forms.DataGridViewCellStyle();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.tabPage3 = new System.Windows.Forms.TabPage();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.dataGridView1 = new System.Windows.Forms.DataGridView();
this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column5 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.tabPage3.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
this.SuspendLayout();
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Controls.Add(this.tabPage3);
this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabControl1.Location = new System.Drawing.Point(0, 0);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(704, 354);
this.tabControl1.TabIndex = 0;
//
// tabPage1
//
this.tabPage1.Controls.Add(this.dataGridView1);
this.tabPage1.Location = new System.Drawing.Point(4, 22);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
this.tabPage1.Size = new System.Drawing.Size(696, 328);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "Title";
this.tabPage1.UseVisualStyleBackColor = true;
//
// tabPage2
//
this.tabPage2.Location = new System.Drawing.Point(4, 22);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
this.tabPage2.Size = new System.Drawing.Size(696, 328);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "Settings";
this.tabPage2.UseVisualStyleBackColor = true;
//
// tabPage3
//
this.tabPage3.Controls.Add(this.button5);
this.tabPage3.Controls.Add(this.button4);
this.tabPage3.Controls.Add(this.button3);
this.tabPage3.Controls.Add(this.button2);
this.tabPage3.Controls.Add(this.button1);
this.tabPage3.Controls.Add(this.pictureBox1);
this.tabPage3.Controls.Add(this.pictureBox2);
this.tabPage3.Location = new System.Drawing.Point(4, 22);
this.tabPage3.Name = "tabPage3";
this.tabPage3.Padding = new System.Windows.Forms.Padding(3);
this.tabPage3.Size = new System.Drawing.Size(696, 328);
this.tabPage3.TabIndex = 2;
this.tabPage3.Text = "Icon";
this.tabPage3.UseVisualStyleBackColor = true;
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(60, 6);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(24, 24);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// pictureBox2
//
this.pictureBox2.Location = new System.Drawing.Point(6, 6);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(48, 48);
this.pictureBox2.TabIndex = 0;
this.pictureBox2.TabStop = false;
//
// dataGridView1
//
this.dataGridView1.AllowUserToAddRows = false;
this.dataGridView1.AllowUserToDeleteRows = false;
this.dataGridView1.AllowUserToResizeRows = false;
this.dataGridView1.BackgroundColor = System.Drawing.Color.White;
this.dataGridView1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.dataGridView1.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None;
this.dataGridView1.ColumnHeadersHeight = 25;
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.Column1,
this.Column2,
this.Column3,
this.Column4,
this.Column5});
dataGridViewCellStyle12.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle12.BackColor = System.Drawing.SystemColors.Window;
dataGridViewCellStyle12.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
dataGridViewCellStyle12.ForeColor = System.Drawing.SystemColors.ControlText;
dataGridViewCellStyle12.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle12.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle12.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.dataGridView1.DefaultCellStyle = dataGridViewCellStyle12;
this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.dataGridView1.GridColor = System.Drawing.SystemColors.Control;
this.dataGridView1.Location = new System.Drawing.Point(3, 3);
this.dataGridView1.MultiSelect = false;
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.RowHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None;
this.dataGridView1.RowHeadersVisible = false;
this.dataGridView1.RowTemplate.Height = 17;
this.dataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.dataGridView1.Size = new System.Drawing.Size(690, 322);
this.dataGridView1.TabIndex = 1;
//
// Column1
//
this.Column1.FillWeight = 36F;
this.Column1.Frozen = true;
this.Column1.HeaderText = "Lang";
this.Column1.MaxInputLength = 4;
this.Column1.MinimumWidth = 36;
this.Column1.Name = "Column1";
this.Column1.ReadOnly = true;
this.Column1.Resizable = System.Windows.Forms.DataGridViewTriState.False;
this.Column1.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
this.Column1.Width = 36;
//
// Column2
//
this.Column2.Frozen = true;
this.Column2.HeaderText = "Short Description";
this.Column2.MaxInputLength = 64;
this.Column2.Name = "Column2";
this.Column2.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
this.Column2.Width = 200;
//
// Column3
//
this.Column3.Frozen = true;
this.Column3.HeaderText = "Long Description";
this.Column3.MaxInputLength = 128;
this.Column3.Name = "Column3";
this.Column3.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
this.Column3.Width = 250;
//
// Column4
//
this.Column4.Frozen = true;
this.Column4.HeaderText = "Publisher";
this.Column4.MaxInputLength = 64;
this.Column4.Name = "Column4";
this.Column4.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
this.Column4.Width = 200;
//
// Column5
//
this.Column5.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.Column5.FillWeight = 1F;
this.Column5.HeaderText = "";
this.Column5.MinimumWidth = 2;
this.Column5.Name = "Column5";
this.Column5.ReadOnly = true;
this.Column5.Resizable = System.Windows.Forms.DataGridViewTriState.False;
this.Column5.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
//
// button1
//
this.button1.Location = new System.Drawing.Point(90, 31);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 1;
this.button1.Text = "Export Large";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(90, 6);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 2;
this.button2.Text = "Export Small";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(171, 6);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(75, 23);
this.button3.TabIndex = 3;
this.button3.Text = "Import Small";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button4
//
this.button4.Location = new System.Drawing.Point(171, 31);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(75, 23);
this.button4.TabIndex = 4;
this.button4.Text = "Import Large";
this.button4.UseVisualStyleBackColor = true;
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// button5
//
this.button5.Location = new System.Drawing.Point(252, 6);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(75, 23);
this.button5.TabIndex = 5;
this.button5.Text = "Import Both";
this.button5.UseVisualStyleBackColor = true;
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// saveFileDialog1
//
this.saveFileDialog1.DefaultExt = "png";
this.saveFileDialog1.Filter = "Portable Network Graphics (*.png)|*.png";
//
// openFileDialog1
//
this.openFileDialog1.DefaultExt = "png";
this.openFileDialog1.FileName = "openFileDialog1";
this.openFileDialog1.Filter = "Portable Network Graphics (*.png)|*.png";
//
// SMDHViewer
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(704, 354);
this.Controls.Add(this.tabControl1);
this.DoubleBuffered = true;
this.Name = "SMDHViewer";
this.Text = "SMDH Viewer";
this.Load += new System.EventHandler(this.SMDHViewer_Load);
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.tabPage3.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.TabPage tabPage3;
private System.Windows.Forms.PictureBox pictureBox2;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.DataGridView dataGridView1;
private System.Windows.Forms.DataGridViewTextBoxColumn Column1;
private System.Windows.Forms.DataGridViewTextBoxColumn Column2;
private System.Windows.Forms.DataGridViewTextBoxColumn Column3;
private System.Windows.Forms.DataGridViewTextBoxColumn Column4;
private System.Windows.Forms.DataGridViewTextBoxColumn Column5;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.SaveFileDialog saveFileDialog1;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
}
}

134
3DS/UI/SMDHViewer.cs Normal file
View File

@ -0,0 +1,134 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using System.IO;
using LibEveryFileExplorer.GFX;
namespace _3DS.UI
{
public partial class SMDHViewer : Form
{
private string[] Languages =
{
"JPN",
"ENG",
"FRE",
"GER",
"ITA",
"SPA",
"SCHI",
"KOR",
"DUT",
"POR",
"RUS",
"TCHI",
"UNK",
"UNK",
"UNK",
"UNK"
};
public SMDH icn;
public SMDHViewer(SMDH Icon)
{
this.icn = Icon;
InitializeComponent();
typeof(DataGridView).InvokeMember("DoubleBuffered", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty, null,
dataGridView1, new object[] { true });
typeof(TabControl).InvokeMember("DoubleBuffered", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty, null,
tabControl1, new object[] { true });
typeof(TabPage).InvokeMember("DoubleBuffered", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty, null,
tabPage1, new object[] { true });
typeof(TabPage).InvokeMember("DoubleBuffered", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty, null,
tabPage2, new object[] { true });
typeof(TabPage).InvokeMember("DoubleBuffered", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty, null,
tabPage3, new object[] { true });
}
private void SMDHViewer_Load(object sender, EventArgs e)
{
dataGridView1.SuspendLayout();
int i = 0;
foreach (var v in icn.AppTitles)
{
dataGridView1.Rows.Add(Languages[i++], v.ShortDescription, v.LongDescription, v.Publisher);
}
dataGridView1.ResumeLayout();
pictureBox1.Image = icn.GetSmallIcon();
pictureBox2.Image = icn.GetLargeIcon();
}
private void button2_Click(object sender, EventArgs e)
{
saveFileDialog1.Title = "Export Small Icon";
if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK
&& saveFileDialog1.FileName.Length > 0)
{
File.Create(saveFileDialog1.FileName).Close();
icn.GetSmallIcon().Save(saveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Png);
}
}
private void button1_Click(object sender, EventArgs e)
{
saveFileDialog1.Title = "Export Large Icon";
if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK
&& saveFileDialog1.FileName.Length > 0)
{
File.Create(saveFileDialog1.FileName).Close();
icn.GetLargeIcon().Save(saveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Png);
}
}
private void button3_Click(object sender, EventArgs e)
{
openFileDialog1.Title = "Import Small Icon";
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK
&& openFileDialog1.FileName.Length > 0)
{
Bitmap b = GFXUtil.Resize(new Bitmap(new MemoryStream(File.ReadAllBytes(openFileDialog1.FileName))), 24, 24);
icn.SmallIcon = GPU.Textures.FromBitmap(b, GPU.Textures.ImageFormat.RGB565, true);
b.Dispose();
pictureBox1.Image = icn.GetSmallIcon();
}
}
private void button4_Click(object sender, EventArgs e)
{
openFileDialog1.Title = "Import Large Icon";
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK
&& openFileDialog1.FileName.Length > 0)
{
Bitmap b = GFXUtil.Resize(new Bitmap(new MemoryStream(File.ReadAllBytes(openFileDialog1.FileName))), 48, 48);
icn.LargeIcon = GPU.Textures.FromBitmap(b, GPU.Textures.ImageFormat.RGB565, true);
b.Dispose();
pictureBox2.Image = icn.GetLargeIcon();
}
}
private void button5_Click(object sender, EventArgs e)
{
openFileDialog1.Title = "Import Both Icons";
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK
&& openFileDialog1.FileName.Length > 0)
{
Bitmap b = new Bitmap(new MemoryStream(File.ReadAllBytes(openFileDialog1.FileName)));
Bitmap Small = GFXUtil.Resize(b, 24, 24);
Bitmap Big = GFXUtil.Resize(b, 48, 48);
icn.SmallIcon = GPU.Textures.FromBitmap(Small, GPU.Textures.ImageFormat.RGB565, true);
icn.LargeIcon = GPU.Textures.FromBitmap(Big, GPU.Textures.ImageFormat.RGB565, true);
b.Dispose();
Small.Dispose();
Big.Dispose();
pictureBox1.Image = icn.GetSmallIcon();
pictureBox2.Image = icn.GetLargeIcon();
}
}
}
}

141
3DS/UI/SMDHViewer.resx Normal file
View File

@ -0,0 +1,141 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="Column1.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Column2.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Column3.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Column4.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Column5.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="saveFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>153, 17</value>
</metadata>
</root>

View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{CE7A5169-BB6E-4112-9E18-9836FF94FA4C}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CommonCompressors</RootNamespace>
<AssemblyName>CommonCompressors</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="LZ77.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="YAZ0.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LibEveryFileExplorer\LibEveryFileExplorer.csproj">
<Project>{39DBD12F-F7E3-4E9A-97A2-0722A4BA2A26}</Project>
<Name>LibEveryFileExplorer</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy "$(TargetPath)" "$(SolutionDir)\EveryFileExplorer\bin\Debug\Plugins\$(TargetFileName)"</PostBuildEvent>
</PropertyGroup>
<!-- 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>

175
CommonCompressors/LZ77.cs Normal file
View File

@ -0,0 +1,175 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LibEveryFileExplorer.Compression;
using System.Runtime.InteropServices;
namespace CommonCompressors
{
public unsafe class LZ77 : CompressionFormat<LZ77.LZ77Identifier>, ICompressable
{
public unsafe byte[] Compress(byte[] Data)
{
byte* dataptr = (byte*)Marshal.UnsafeAddrOfPinnedArrayElement(Data, 0);
byte[] result = new byte[Data.Length + Data.Length / 8 + 4];
byte* resultptr = (byte*)Marshal.UnsafeAddrOfPinnedArrayElement(result, 0);
*resultptr++ = 0x10;
*resultptr++ = (byte)(Data.Length & 0xFF);
*resultptr++ = (byte)((Data.Length >> 8) & 0xFF);
*resultptr++ = (byte)((Data.Length >> 16) & 0xFF);
int length = Data.Length;
int dstoffs = 4;
int Offs = 0;
while (true)
{
int headeroffs = dstoffs++;
resultptr++;
byte header = 0;
for (int i = 0; i < 8; i++)
{
int comp = 0;
int back = 1;
int nr = 2;
{
byte* ptr = dataptr - 1;
int maxnum = 18;
if (length - Offs < maxnum) maxnum = length - Offs;
int maxback = 0x1000;
if (Offs < maxback) maxback = Offs;
maxback = (int)dataptr - maxback;
int tmpnr;
while (maxback <= (int)ptr)
{
if (*(ushort*)ptr == *(ushort*)dataptr && ptr[2] == dataptr[2])
{
tmpnr = 3;
while (tmpnr < maxnum && ptr[tmpnr] == dataptr[tmpnr]) tmpnr++;
if (tmpnr > nr)
{
if (Offs + tmpnr > length)
{
nr = length - Offs;
back = (int)(dataptr - ptr);
break;
}
nr = tmpnr;
back = (int)(dataptr - ptr);
if (nr == maxnum) break;
}
}
--ptr;
}
}
if (nr > 2)
{
Offs += nr;
dataptr += nr;
*resultptr++ = (byte)((((back - 1) >> 8) & 0xF) | (((nr - 3) & 0xF) << 4));
*resultptr++ = (byte)((back - 1) & 0xFF);
dstoffs += 2;
comp = 1;
}
else
{
*resultptr++ = *dataptr++;
dstoffs++;
Offs++;
}
header = (byte)((header << 1) | (comp & 1));
if (Offs >= length)
{
header = (byte)(header << (7 - i));
break;
}
}
result[headeroffs] = header;
if (Offs >= length) break;
}
while ((dstoffs % 4) != 0) dstoffs++;
byte[] realresult = new byte[dstoffs];
Array.Copy(result, realresult, dstoffs);
return realresult;
}
public override byte[] Decompress(byte[] Data)
{
UInt32 leng = (uint)(Data[1] | (Data[2] << 8) | (Data[3] << 16));
byte[] Result = new byte[leng];
int Offs = 4;
int dstoffs = 0;
while (true)
{
byte header = Data[Offs++];
for (int i = 0; i < 8; i++)
{
if ((header & 0x80) == 0) Result[dstoffs++] = Data[Offs++];
else
{
byte a = Data[Offs++];
byte b = Data[Offs++];
int offs = (((a & 0xF) << 8) | b) + 1;
int length = (a >> 4) + 3;
for (int j = 0; j < length; j++)
{
Result[dstoffs] = Result[dstoffs - offs];
dstoffs++;
}
}
if (dstoffs >= leng) return Result;
header <<= 1;
}
}
}
public class LZ77Identifier : CompressionFormatIdentifier
{
public override string GetCompressionDescription()
{
return "LZ77";
}
public override bool IsFormat(byte[] Data)
{
return Data.Length > 4 && (Data[0] == 0x10 || Data[0] == 0x00);
}
}
}
public class LZ77Header : CompressionFormat<LZ77Header.LZ77HeaderIdentifier>, ICompressable
{
public byte[] Compress(byte[] Data)
{
byte[] Comp = new LZ77().Compress(Data);
byte[] Result = new byte[Comp.Length + 4];
Result[0] = 0x4C;
Result[1] = 0x5A;
Result[2] = 0x37;
Result[3] = 0x37;
Array.Copy(Comp, 0, Result, 4, Comp.Length);
return Result;
}
public override byte[] Decompress(byte[] Data)
{
if (!(Data[0] == 'L' && Data[1] == 'Z' && Data[2] == '7' && Data[3] == '7')) throw new ArgumentException("LZ77 Header Missing!");
byte[] Data2 = new byte[Data.Length - 4];
Array.Copy(Data, 4, Data2, 0, Data.Length - 4);
return new LZ77().Decompress(Data2);
}
public class LZ77HeaderIdentifier : CompressionFormatIdentifier
{
public override string GetCompressionDescription()
{
return "LZ77 (Header)";
}
public override bool IsFormat(byte[] Data)
{
return Data.Length > 8 && (Data[0] == 'L' && Data[1] == 'Z' && Data[2] == '7' && Data[3] == '7');
}
}
}
}

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("Common Compressors Plugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Every File Explorer")]
[assembly: AssemblyCopyright("Copyright © Florian Nouwt 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("287caaec-e539-44ce-8e11-bffcf4b45471")]
// 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")]

132
CommonCompressors/YAZ0.cs Normal file
View File

@ -0,0 +1,132 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LibEveryFileExplorer.Compression;
namespace CommonCompressors
{
public unsafe class YAZ0 : CompressionFormat<YAZ0.YAZ0Identifier>
{
/*public unsafe byte[] Compress(byte[] Data)
{
byte* dataptr = (byte*)Marshal.UnsafeAddrOfPinnedArrayElement(Data, 0);
byte[] result = new byte[Data.Length + Data.Length / 8 + 4];
byte* resultptr = (byte*)Marshal.UnsafeAddrOfPinnedArrayElement(result, 0);
*resultptr++ = 0x10;
*resultptr++ = (byte)(Data.Length & 0xFF);
*resultptr++ = (byte)((Data.Length >> 8) & 0xFF);
*resultptr++ = (byte)((Data.Length >> 16) & 0xFF);
int length = Data.Length;
int dstoffs = 4;
int Offs = 0;
while (true)
{
int headeroffs = dstoffs++;
resultptr++;
byte header = 0;
for (int i = 0; i < 8; i++)
{
int comp = 0;
int back = 1;
int nr = 2;
{
byte* ptr = dataptr - 1;
int maxnum = 18;
if (length - Offs < maxnum) maxnum = length - Offs;
int maxback = 0x1000;
if (Offs < maxback) maxback = Offs;
maxback = (int)dataptr - maxback;
int tmpnr;
while (maxback <= (int)ptr)
{
if (*(ushort*)ptr == *(ushort*)dataptr && ptr[2] == dataptr[2])
{
tmpnr = 3;
while (tmpnr < maxnum && ptr[tmpnr] == dataptr[tmpnr]) tmpnr++;
if (tmpnr > nr)
{
nr = tmpnr;
back = (int)(dataptr - ptr);
if (nr == maxnum) break;
}
}
--ptr;
}
}
if (nr > 2)
{
Offs += nr;
dataptr += nr;
*resultptr++ = (byte)((((back - 1) >> 8) & 0xF) | (((nr - 3) & 0xF) << 4));
*resultptr++ = (byte)((back - 1) & 0xFF);
dstoffs += 2;
comp = 1;
}
else
{
*resultptr++ = *dataptr++;
dstoffs++;
Offs++;
}
header = (byte)((header << 1) | (comp & 1));
if (Offs == length)
{
header = (byte)(header << (7 - i));
break;
}
}
result[headeroffs] = header;
if (Offs == length) break;
}
while ((dstoffs % 4) != 0) dstoffs++;
byte[] realresult = new byte[dstoffs];
Array.Copy(result, realresult, dstoffs);
return realresult;
}*/
public override byte[] Decompress(byte[] Data)
{
UInt32 leng = (uint)(Data[4] << 24 | Data[5] << 16 | Data[6] << 8 | Data[7]);
byte[] Result = new byte[leng];
int Offs = 16;
int dstoffs = 0;
while (true)
{
byte header = Data[Offs++];
for (int i = 0; i < 8; i++)
{
if ((header & 0x80) != 0) Result[dstoffs++] = Data[Offs++];
else
{
byte b = Data[Offs++];
int offs = ((b & 0xF) << 8 | Data[Offs++]) + 1;
int length = (b >> 4) + 2;
if (length == 2) length = Data[Offs++] + 0x12;
for (int j = 0; j < length; j++)
{
Result[dstoffs] = Result[dstoffs - offs];
dstoffs++;
}
}
if (dstoffs >= leng) return Result;
header <<= 1;
}
}
}
public class YAZ0Identifier : CompressionFormatIdentifier
{
public override string GetCompressionDescription()
{
return "YAZ0";
}
public override bool IsFormat(byte[] Data)
{
return Data.Length > 16 && (Data[0] == 'Y' && Data[1] == 'a' && Data[2] == 'z' && Data[3] == '0');
}
}
}
}

View File

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{4D0F5EC8-4730-4D62-AFA5-80AD4AD14625}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CommonFiles</RootNamespace>
<AssemblyName>CommonFiles</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</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>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DAE.cs" />
<Compile Include="MTL.cs" />
<Compile Include="OBJ.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UI\WAVEPlayer.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="UI\WAVEPlayer.Designer.cs">
<DependentUpon>WAVEPlayer.cs</DependentUpon>
</Compile>
<Compile Include="WAV.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LibEveryFileExplorer\LibEveryFileExplorer.csproj">
<Project>{39DBD12F-F7E3-4E9A-97A2-0722A4BA2A26}</Project>
<Name>LibEveryFileExplorer</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy "$(TargetPath)" "$(SolutionDir)\EveryFileExplorer\bin\Debug\Plugins\$(TargetFileName)"</PostBuildEvent>
</PropertyGroup>
<!-- 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>

1764
CommonFiles/DAE.cs Normal file

File diff suppressed because it is too large Load Diff

159
CommonFiles/MTL.cs Normal file
View File

@ -0,0 +1,159 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LibEveryFileExplorer.Files;
using System.Drawing;
using System.IO;
namespace CommonFiles
{
public class MTL : FileFormat<MTL.MTLIdentifier>, IWriteable
{
public MTL()
{
Materials = new List<MTLMaterial>();
}
public MTL(byte[] Data)
{
MTLMaterial CurrentMaterial = null;
TextReader tr = new StreamReader(new MemoryStream(Data));
String line;
while ((line = tr.ReadLine()) != null)
{
line = line.Trim();
if (line.Length < 1 || line.StartsWith("#")) continue;
string[] parts = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length < 1) continue;
switch (parts[0])
{
case "newmtl":
if (parts.Length < 2) continue;
if (CurrentMaterial != null) Materials.Add(CurrentMaterial);
CurrentMaterial = new MTLMaterial(parts[1]);
break;
case "Ka":
{
if (parts.Length < 4) continue;
float r = float.Parse(parts[1]);
float g = float.Parse(parts[2]);
float b = float.Parse(parts[3]);
CurrentMaterial.AmbientColor = Color.FromArgb((int)(r * 255f), (int)(g * 255f), (int)(b * 255f));
break;
}
case "Kd":
{
if (parts.Length < 4) continue;
float r = float.Parse(parts[1]);
float g = float.Parse(parts[2]);
float b = float.Parse(parts[3]);
CurrentMaterial.DiffuseColor = Color.FromArgb((int)(r * 255f), (int)(g * 255f), (int)(b * 255f));
break;
}
case "Ks":
{
if (parts.Length < 4) continue;
float r = float.Parse(parts[1]);
float g = float.Parse(parts[2]);
float b = float.Parse(parts[3]);
CurrentMaterial.SpecularColor = Color.FromArgb((int)(r * 255f), (int)(g * 255f), (int)(b * 255f));
break;
}
case "d":
if (parts.Length < 2) continue;
CurrentMaterial.Alpha = float.Parse(parts[1]);
break;
case "map_Kd":
CurrentMaterial.DiffuseMapPath = line.Substring(parts[0].Length + 1).Trim();
break;
}
}
tr.Close();
}
public string GetSaveDefaultFileFilter()
{
return "Material Library (*.mtl)|*.mtl";
}
public byte[] Write()
{
StringBuilder b = new StringBuilder();
b.AppendLine("# Created by Every File Explorer");
b.AppendLine();
foreach (MTLMaterial m in Materials)
{
b.AppendFormat("newmtl {0}\n", m.Name);
b.AppendFormat("Ka {0} {1} {2}\n", (m.AmbientColor.R / 255f).ToString().Replace(",", "."), (m.AmbientColor.G / 255f).ToString().Replace(",", "."), (m.AmbientColor.B / 255f).ToString().Replace(",", "."));
b.AppendFormat("Kd {0} {1} {2}\n", (m.DiffuseColor.R / 255f).ToString().Replace(",", "."), (m.DiffuseColor.G / 255f).ToString().Replace(",", "."), (m.DiffuseColor.B / 255f).ToString().Replace(",", "."));
b.AppendFormat("Ks {0} {1} {2}\n", (m.SpecularColor.R / 255f).ToString().Replace(",", "."), (m.SpecularColor.G / 255f).ToString().Replace(",", "."), (m.SpecularColor.B / 255f).ToString().Replace(",", "."));
b.AppendFormat("d {0}\n", m.Alpha.ToString().Replace(",", "."));
if (m.DiffuseMapPath != null) b.AppendFormat("map_Kd {0}\n", m.DiffuseMapPath);
b.AppendLine();
}
String s = b.ToString();
return Encoding.ASCII.GetBytes(s);
}
public List<MTLMaterial> Materials;
public MTLMaterial GetMaterialByName(String Name)
{
foreach (MTLMaterial m in Materials)
{
if (m.Name == Name) return m;
}
return null;
}
public class MTLMaterial
{
public MTLMaterial(String Name)
{
this.Name = Name;
}
public String Name;
public Color DiffuseColor;
public Color AmbientColor;
public Color SpecularColor;
public float Alpha = 1;
public String DiffuseMapPath;
public override string ToString()
{
return Name;
}
}
public class MTLIdentifier : FileFormatIdentifier
{
public override string GetCategory()
{
return Category_Textures;
}
public override string GetFileDescription()
{
return "Material Library (MTL)";
}
public override string GetFileFilter()
{
return "Material Library (*.mtl)|*.mtl";
}
public override Bitmap GetIcon()
{
return null;
}
public override FormatMatch IsFormat(EFEFile File)
{
if (File.Name.ToLower().EndsWith(".mtl")) return FormatMatch.Extension;
return FormatMatch.No;
}
}
}
}

207
CommonFiles/OBJ.cs Normal file
View File

@ -0,0 +1,207 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LibEveryFileExplorer.Files;
using System.Drawing;
using LibEveryFileExplorer.Collections;
using System.IO;
using System.Globalization;
namespace CommonFiles
{
public class OBJ : FileFormat<OBJ.OBJIdentifier>, IWriteable
{
public OBJ()
{
Vertices = new List<Vector3>();
Normals = new List<Vector3>();
TexCoords = new List<Vector2>();
Faces = new List<OBJFace>();
}
public OBJ(byte[] Data)
{
var enusculture = new CultureInfo("en-US");
string curmat = null;
Vertices = new List<Vector3>();
Normals = new List<Vector3>();
TexCoords = new List<Vector2>();
Faces = new List<OBJFace>();
TextReader tr = new StreamReader(new MemoryStream(Data));
String line;
while ((line = tr.ReadLine()) != null)
{
line = line.Trim();
if (line.Length < 1 || line.StartsWith("#")) continue;
string[] parts = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length < 1) continue;
switch (parts[0])
{
case "mtllib":
if (parts.Length < 2) continue;
MTLPath = line.Substring(parts[0].Length + 1).Trim();
break;
case "usemtl":
if (parts.Length < 2) continue;
curmat = parts[1];
break;
case "v":
{
if (parts.Length < 4) continue;
float x = float.Parse(parts[1], enusculture);
float y = float.Parse(parts[2], enusculture);
float z = float.Parse(parts[3], enusculture);
Vertices.Add(new Vector3(x, y, z));
break;
}
case "vn":
{
if (parts.Length < 4) continue;
float x = float.Parse(parts[1], enusculture);
float y = float.Parse(parts[2], enusculture);
float z = float.Parse(parts[3], enusculture);
Normals.Add(new Vector3(x, y, z));
break;
}
case "vt":
{
if (parts.Length < 3) continue;
float s = float.Parse(parts[1], enusculture);
float t = float.Parse(parts[2], enusculture);
TexCoords.Add(new Vector2(s, t));
break;
}
case "f":
{
if (parts.Length < 4) continue;
OBJFace f = new OBJFace();
f.Material = curmat;
for (int i = 0; i < parts.Length - 1; i++)
{
String[] Parts = parts[i + 1].Split('/');
f.VertexIndieces.Add(int.Parse(Parts[0]) - 1);
if (Parts.Length > 1)
{
if (Parts[1] != "") f.TexCoordIndieces.Add(int.Parse(Parts[1]) - 1);
if (Parts.Length > 2 && Parts[2] != "") f.NormalIndieces.Add(int.Parse(Parts[2]) - 1);
}
}
Faces.Add(f);
break;
}
}
}
tr.Close();
}
public string GetSaveDefaultFileFilter()
{
return "Wavefront OBJ File (*.obj)|*.obj";
}
public byte[] Write()
{
StringBuilder b = new StringBuilder();
b.AppendLine("# Created by Every File Explorer");
b.AppendLine();
if (MTLPath != null) b.AppendFormat("mtllib {0}\n", MTLPath);
b.AppendLine();
foreach (Vector3 Vertex in Vertices)
{
b.AppendFormat("v {0} {1} {2}\n", (Vertex.X).ToString().Replace(",", "."), (Vertex.Y).ToString().Replace(",", "."), (Vertex.Z).ToString().Replace(",", "."));
}
b.AppendLine();
foreach (Vector3 Normal in Normals)
{
b.AppendFormat("vn {0} {1} {2}\n", (Normal.X).ToString().Replace(",", "."), (Normal.Y).ToString().Replace(",", "."), (Normal.Z).ToString().Replace(",", "."));
}
b.AppendLine();
foreach (Vector2 TexCoord in TexCoords)
{
b.AppendFormat("vt {0} {1}\n", (TexCoord.X).ToString().Replace(",", "."), (TexCoord.Y).ToString().Replace(",", "."));
}
b.AppendLine();
String CurrentMat = null;
foreach (var c in Faces)
{
bool vertex = c.VertexIndieces.Count != 0;
bool normal = c.NormalIndieces.Count != 0 && c.NormalIndieces.Count == c.VertexIndieces.Count;
bool tex = c.TexCoordIndieces.Count != 0 && c.TexCoordIndieces.Count == c.VertexIndieces.Count;
if (!vertex) throw new Exception("Face has no vertex entries!");
if (CurrentMat != c.Material)
{
b.AppendFormat("usemtl {0}\n", c.Material);
b.AppendLine();
CurrentMat = c.Material;
}
b.Append("f");
int count = c.VertexIndieces.Count;
for (int i = 0; i < count; i++)
{
if (vertex && normal && tex) b.AppendFormat(" {0}/{1}/{2}", c.VertexIndieces[i] + 1, c.TexCoordIndieces[i] + 1, c.NormalIndieces[i] + 1);
else if (vertex && tex) b.AppendFormat(" {0}/{1}", c.VertexIndieces[i] + 1, c.TexCoordIndieces[i] + 1);
else if (vertex && normal) b.AppendFormat(" {0}//{1}", c.VertexIndieces[i] + 1, c.NormalIndieces[i] + 1);
else b.AppendFormat(" {0}", c.VertexIndieces[i] + 1);
}
b.AppendLine();
}
String s = b.ToString();
return Encoding.ASCII.GetBytes(s);
}
public String MTLPath;//Relative to this OBJ file
public List<Vector3> Vertices;
public List<Vector3> Normals;
public List<Vector2> TexCoords;
public List<OBJFace> Faces;
public class OBJFace
{
public OBJFace()
{
VertexIndieces = new List<int>();
NormalIndieces = new List<int>();
TexCoordIndieces = new List<int>();
}
public List<int> VertexIndieces;
public List<int> NormalIndieces;
public List<int> TexCoordIndieces;
public String Material;
}
public class OBJIdentifier : FileFormatIdentifier
{
public override string GetCategory()
{
return Category_Models;
}
public override string GetFileDescription()
{
return "Wavefront OBJ File (OBJ)";
}
public override string GetFileFilter()
{
return "Wavefront OBJ File (*.obj)|*.obj";
}
public override Bitmap GetIcon()
{
return null;
}
public override FormatMatch IsFormat(EFEFile File)
{
if (File.Name.ToLower().EndsWith(".obj")) return FormatMatch.Extension;
return FormatMatch.No;
}
}
}
}

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("Common Files Plugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Every File Explorer")]
[assembly: AssemblyCopyright("Copyright © Florian Nouwt 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("c993dbcd-fe83-4fdb-850d-710640b3fdd0")]
// 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")]

38
CommonFiles/UI/WAVEPlayer.Designer.cs generated Normal file
View File

@ -0,0 +1,38 @@
namespace CommonFiles.UI
{
partial class WAVEPlayer
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Text = "WAVEPlayer";
}
#endregion
}
}

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace CommonFiles.UI
{
public partial class WAVEPlayer : Form
{
WAV Wave;
public WAVEPlayer(WAV Wave)
{
this.Wave = Wave;
InitializeComponent();
}
}
}

237
CommonFiles/WAV.cs Normal file
View File

@ -0,0 +1,237 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LibEveryFileExplorer.Files;
using System.Drawing;
using System.IO;
namespace CommonFiles
{
public class WAV : FileFormat<WAV.WAVIdentifier>, IWriteable
{
/// <summary>
/// Generates a WAV file with the given <paramref name="Data"/> and params.
/// </summary>
/// <param name="Data">The raw sample Data.</param>
/// <param name="SampleRate">The SampleRate in Hz.</param>
/// <param name="BitsPerSample">The number of Bits per Sample.</param>
/// <param name="NrChannel">The number of Channels.</param>
public WAV(byte[] Data, UInt32 SampleRate, UInt16 BitsPerSample, UInt16 NrChannel)
{
Header = new RIFFHeader((uint)(4 + 8 + 16 + 8 + Data.Length + 8));
Wave = new WaveData(Data, SampleRate, BitsPerSample, NrChannel);
}
public WAV(byte[] Data)
{
EndianBinaryReader er = new EndianBinaryReader(new MemoryStream(Data), Endianness.LittleEndian);
try
{
Header = new RIFFHeader(er);
Wave = new WaveData(er);
}
finally
{
er.Close();
}
}
public string GetSaveDefaultFileFilter()
{
return "Wave Audio File (*.wav)|*.wav";
}
public byte[] Write()
{
MemoryStream m = new MemoryStream();
EndianBinaryWriter er = new EndianBinaryWriter(m, Endianness.LittleEndian);
Header.Write(er);
Wave.Write(er);
byte[] b = m.ToArray();
er.Close();
return b;
}
public RIFFHeader Header;
public class RIFFHeader
{
/// <summary>
/// Creates a new RIFF Header for the given <paramref name="FileSize"/>.
/// </summary>
/// <param name="FileSize">Size of the complete file.</param>
public RIFFHeader(UInt32 FileSize)
{
Signature = "RIFF";
this.FileSize = FileSize - 8;
}
public RIFFHeader(EndianBinaryReader er)
{
Signature = er.ReadString(Encoding.ASCII, 4);
if (Signature != "RIFF") throw new SignatureNotCorrectException(Signature, "RIFF", er.BaseStream.Position - 4);
FileSize = er.ReadUInt32();
}
public String Signature;
public UInt32 FileSize;//-8
public void Write(EndianBinaryWriter er)
{
er.Write(Signature, Encoding.ASCII, false);
er.Write(FileSize);
}
}
public WaveData Wave;
public class WaveData
{
public WaveData(byte[] Data, UInt32 SampleRate, UInt16 BitsPerSample, UInt16 NrChannel)
{
Signature = "WAVE";
FMT = new FMTBlock(SampleRate, BitsPerSample, NrChannel);
DATA = new DATABlock(Data);
}
public WaveData(EndianBinaryReader er)
{
Signature = er.ReadString(ASCIIEncoding.ASCII, 4);
if (Signature != "WAVE") throw new SignatureNotCorrectException(Signature, "WAVE", er.BaseStream.Position - 4);
FMT = new FMTBlock(er);
DATA = new DATABlock(er);
}
public void Write(EndianBinaryWriter er)
{
er.Write(Signature, Encoding.ASCII, false);
FMT.Write(er);
DATA.Write(er);
}
public String Signature;
public FMTBlock FMT;
public class FMTBlock
{
public FMTBlock(UInt32 SampleRate, UInt16 BitsPerSample, UInt16 NrChannel)
{
Signature = "fmt ";
SectionSize = 16;
AudioFormat = WaveFormat.WAVE_FORMAT_PCM;
this.NrChannel = NrChannel;
this.SampleRate = SampleRate;
this.BitsPerSample = BitsPerSample;
this.ByteRate = SampleRate * BitsPerSample * NrChannel / 8;
this.BlockAlign = (UInt16)(NrChannel * BitsPerSample / 8);
}
public FMTBlock(EndianBinaryReader er)
{
Signature = er.ReadString(Encoding.ASCII, 4);
if (Signature != "fmt ") throw new SignatureNotCorrectException(Signature, "fmt ", er.BaseStream.Position - 4);
SectionSize = er.ReadUInt32();
AudioFormat = (WaveFormat)er.ReadUInt16();
NrChannel = er.ReadUInt16();
SampleRate = er.ReadUInt32();
ByteRate = er.ReadUInt32();
BlockAlign = er.ReadUInt16();
BitsPerSample = er.ReadUInt16();
}
public void Write(EndianBinaryWriter er)
{
er.Write(Signature, Encoding.ASCII, false);
er.Write(SectionSize);
er.Write((ushort)AudioFormat);
er.Write(NrChannel);
er.Write(SampleRate);
er.Write(ByteRate);
er.Write(BlockAlign);
er.Write(BitsPerSample);
}
public String Signature;
public UInt32 SectionSize;
public WaveFormat AudioFormat;
public enum WaveFormat : ushort
{
WAVE_FORMAT_PCM = 0x0001,
IBM_FORMAT_ADPCM = 0x0002,
IBM_FORMAT_MULAW = 0x0007,
IBM_FORMAT_ALAW = 0x0006,
WAVE_FORMAT_EXTENSIBLE = 0xFFFE
}
public UInt16 NrChannel;
public UInt32 SampleRate;
public UInt32 ByteRate;
public UInt16 BlockAlign;
public UInt16 BitsPerSample;
}
public DATABlock DATA;
public class DATABlock
{
public DATABlock(byte[] Data)
{
Signature = "data";
SectionSize = (UInt32)Data.Length;
this.Data = Data;
}
public DATABlock(EndianBinaryReader er)
{
Signature = er.ReadString(Encoding.ASCII, 4);
if (Signature != "data") throw new SignatureNotCorrectException(Signature, "data", er.BaseStream.Position - 4);
SectionSize = er.ReadUInt32();
Data = er.ReadBytes((int)SectionSize);
}
public void Write(EndianBinaryWriter er)
{
er.Write(Signature, Encoding.ASCII, false);
er.Write(SectionSize);
er.Write(Data, 0, Data.Length);
}
public String Signature;
public UInt32 SectionSize;
public byte[] Data;
}
}
public byte[] GetChannelData(int Channel)
{
byte[] result = new byte[Wave.DATA.Data.Length / Wave.FMT.NrChannel];
int offs = 0;
for (int i = 0; i < Wave.DATA.Data.Length; i += Wave.FMT.NrChannel * Wave.FMT.BitsPerSample / 8)
{
for (int j = 0; j < Wave.FMT.BitsPerSample / 8; j++)
{
result[offs++] = Wave.DATA.Data[i + Channel * Wave.FMT.BitsPerSample / 8 + j];
}
}
return result;
}
public class WAVIdentifier : FileFormatIdentifier
{
public override string GetCategory()
{
return Category_Audio;
}
public override string GetFileDescription()
{
return "Wave Audio File (WAV)";
}
public override string GetFileFilter()
{
return "Wave Audio File (*.wav)|*.wav";
}
public override Bitmap GetIcon()
{
return null;
}
public override FormatMatch IsFormat(EFEFile File)
{
if (File.Data.Length > 16 && File.Data[0] == 'R' && File.Data[1] == 'I' && File.Data[2] == 'F' && File.Data[3] == 'F' && File.Data[8] == 'W' && File.Data[9] == 'A' && File.Data[10] == 'V' && File.Data[11] == 'E') return FormatMatch.Content;
return FormatMatch.No;
}
}
}
}

108
EveryFileExplorer.sln Normal file
View File

@ -0,0 +1,108 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EveryFileExplorer", "EveryFileExplorer\EveryFileExplorer.csproj", "{01A81192-97A9-4D92-BAD4-D5D4325B0F8E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibEveryFileExplorer", "LibEveryFileExplorer\LibEveryFileExplorer.csproj", "{39DBD12F-F7E3-4E9A-97A2-0722A4BA2A26}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NDS", "NDS\NDS.csproj", "{8BCF0C6C-FD8F-4446-BEA1-B8C1BE5C3389}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "3DS", "3DS\3DS.csproj", "{F28E77C4-BB68-4513-9468-8EABDE8DC9CB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommonCompressors", "CommonCompressors\CommonCompressors.csproj", "{CE7A5169-BB6E-4112-9E18-9836FF94FA4C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommonFiles", "CommonFiles\CommonFiles.csproj", "{4D0F5EC8-4730-4D62-AFA5-80AD4AD14625}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{69A9D75C-140C-4C8E-9F46-AADCA8B9CCC5}"
ProjectSection(SolutionItems) = preProject
Performance1.psess = Performance1.psess
README.md = README.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MarioKart", "MarioKart\MarioKart.csproj", "{8117CF39-0FD6-453D-AA7F-4B4AD85EBB3A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|Mixed Platforms = Debug|Mixed Platforms
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|Mixed Platforms = Release|Mixed Platforms
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{01A81192-97A9-4D92-BAD4-D5D4325B0F8E}.Debug|Any CPU.ActiveCfg = Debug|x86
{01A81192-97A9-4D92-BAD4-D5D4325B0F8E}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{01A81192-97A9-4D92-BAD4-D5D4325B0F8E}.Debug|Mixed Platforms.Build.0 = Debug|x86
{01A81192-97A9-4D92-BAD4-D5D4325B0F8E}.Debug|x86.ActiveCfg = Debug|x86
{01A81192-97A9-4D92-BAD4-D5D4325B0F8E}.Debug|x86.Build.0 = Debug|x86
{01A81192-97A9-4D92-BAD4-D5D4325B0F8E}.Release|Any CPU.ActiveCfg = Release|x86
{01A81192-97A9-4D92-BAD4-D5D4325B0F8E}.Release|Mixed Platforms.ActiveCfg = Release|x86
{01A81192-97A9-4D92-BAD4-D5D4325B0F8E}.Release|Mixed Platforms.Build.0 = Release|x86
{01A81192-97A9-4D92-BAD4-D5D4325B0F8E}.Release|x86.ActiveCfg = Release|x86
{01A81192-97A9-4D92-BAD4-D5D4325B0F8E}.Release|x86.Build.0 = Release|x86
{39DBD12F-F7E3-4E9A-97A2-0722A4BA2A26}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{39DBD12F-F7E3-4E9A-97A2-0722A4BA2A26}.Debug|Any CPU.Build.0 = Debug|Any CPU
{39DBD12F-F7E3-4E9A-97A2-0722A4BA2A26}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{39DBD12F-F7E3-4E9A-97A2-0722A4BA2A26}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{39DBD12F-F7E3-4E9A-97A2-0722A4BA2A26}.Debug|x86.ActiveCfg = Debug|Any CPU
{39DBD12F-F7E3-4E9A-97A2-0722A4BA2A26}.Release|Any CPU.ActiveCfg = Release|Any CPU
{39DBD12F-F7E3-4E9A-97A2-0722A4BA2A26}.Release|Any CPU.Build.0 = Release|Any CPU
{39DBD12F-F7E3-4E9A-97A2-0722A4BA2A26}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{39DBD12F-F7E3-4E9A-97A2-0722A4BA2A26}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{39DBD12F-F7E3-4E9A-97A2-0722A4BA2A26}.Release|x86.ActiveCfg = Release|Any CPU
{8BCF0C6C-FD8F-4446-BEA1-B8C1BE5C3389}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8BCF0C6C-FD8F-4446-BEA1-B8C1BE5C3389}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8BCF0C6C-FD8F-4446-BEA1-B8C1BE5C3389}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{8BCF0C6C-FD8F-4446-BEA1-B8C1BE5C3389}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{8BCF0C6C-FD8F-4446-BEA1-B8C1BE5C3389}.Debug|x86.ActiveCfg = Debug|Any CPU
{8BCF0C6C-FD8F-4446-BEA1-B8C1BE5C3389}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8BCF0C6C-FD8F-4446-BEA1-B8C1BE5C3389}.Release|Any CPU.Build.0 = Release|Any CPU
{8BCF0C6C-FD8F-4446-BEA1-B8C1BE5C3389}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{8BCF0C6C-FD8F-4446-BEA1-B8C1BE5C3389}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{8BCF0C6C-FD8F-4446-BEA1-B8C1BE5C3389}.Release|x86.ActiveCfg = Release|Any CPU
{F28E77C4-BB68-4513-9468-8EABDE8DC9CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F28E77C4-BB68-4513-9468-8EABDE8DC9CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F28E77C4-BB68-4513-9468-8EABDE8DC9CB}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{F28E77C4-BB68-4513-9468-8EABDE8DC9CB}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{F28E77C4-BB68-4513-9468-8EABDE8DC9CB}.Debug|x86.ActiveCfg = Debug|Any CPU
{F28E77C4-BB68-4513-9468-8EABDE8DC9CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F28E77C4-BB68-4513-9468-8EABDE8DC9CB}.Release|Any CPU.Build.0 = Release|Any CPU
{F28E77C4-BB68-4513-9468-8EABDE8DC9CB}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{F28E77C4-BB68-4513-9468-8EABDE8DC9CB}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{F28E77C4-BB68-4513-9468-8EABDE8DC9CB}.Release|x86.ActiveCfg = Release|Any CPU
{CE7A5169-BB6E-4112-9E18-9836FF94FA4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CE7A5169-BB6E-4112-9E18-9836FF94FA4C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CE7A5169-BB6E-4112-9E18-9836FF94FA4C}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{CE7A5169-BB6E-4112-9E18-9836FF94FA4C}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{CE7A5169-BB6E-4112-9E18-9836FF94FA4C}.Debug|x86.ActiveCfg = Debug|Any CPU
{CE7A5169-BB6E-4112-9E18-9836FF94FA4C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CE7A5169-BB6E-4112-9E18-9836FF94FA4C}.Release|Any CPU.Build.0 = Release|Any CPU
{CE7A5169-BB6E-4112-9E18-9836FF94FA4C}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{CE7A5169-BB6E-4112-9E18-9836FF94FA4C}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{CE7A5169-BB6E-4112-9E18-9836FF94FA4C}.Release|x86.ActiveCfg = Release|Any CPU
{4D0F5EC8-4730-4D62-AFA5-80AD4AD14625}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4D0F5EC8-4730-4D62-AFA5-80AD4AD14625}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4D0F5EC8-4730-4D62-AFA5-80AD4AD14625}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{4D0F5EC8-4730-4D62-AFA5-80AD4AD14625}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{4D0F5EC8-4730-4D62-AFA5-80AD4AD14625}.Debug|x86.ActiveCfg = Debug|Any CPU
{4D0F5EC8-4730-4D62-AFA5-80AD4AD14625}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4D0F5EC8-4730-4D62-AFA5-80AD4AD14625}.Release|Any CPU.Build.0 = Release|Any CPU
{4D0F5EC8-4730-4D62-AFA5-80AD4AD14625}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{4D0F5EC8-4730-4D62-AFA5-80AD4AD14625}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{4D0F5EC8-4730-4D62-AFA5-80AD4AD14625}.Release|x86.ActiveCfg = Release|Any CPU
{8117CF39-0FD6-453D-AA7F-4B4AD85EBB3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8117CF39-0FD6-453D-AA7F-4B4AD85EBB3A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8117CF39-0FD6-453D-AA7F-4B4AD85EBB3A}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{8117CF39-0FD6-453D-AA7F-4B4AD85EBB3A}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{8117CF39-0FD6-453D-AA7F-4B4AD85EBB3A}.Debug|x86.ActiveCfg = Debug|Any CPU
{8117CF39-0FD6-453D-AA7F-4B4AD85EBB3A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8117CF39-0FD6-453D-AA7F-4B4AD85EBB3A}.Release|Any CPU.Build.0 = Release|Any CPU
{8117CF39-0FD6-453D-AA7F-4B4AD85EBB3A}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{8117CF39-0FD6-453D-AA7F-4B4AD85EBB3A}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{8117CF39-0FD6-453D-AA7F-4B4AD85EBB3A}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,106 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{01A81192-97A9-4D92-BAD4-D5D4325B0F8E}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>EveryFileExplorer</RootNamespace>
<AssemblyName>EveryFileExplorer</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>Propeller_Box_Artwork_-_Super_Mario_3D_World.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Files\EFEDiskFile.cs" />
<Compile Include="Files\FileManager.cs" />
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="Plugins\Plugin.cs" />
<Compile Include="Plugins\PluginManager.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LibEveryFileExplorer\LibEveryFileExplorer.csproj">
<Project>{39DBD12F-F7E3-4E9A-97A2-0722A4BA2A26}</Project>
<Name>LibEveryFileExplorer</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="UI\" />
</ItemGroup>
<ItemGroup>
<Content Include="Propeller_Box_Artwork_-_Super_Mario_3D_World.ico" />
</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

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using LibEveryFileExplorer.Files;
namespace EveryFileExplorer.Files
{
public class EFEDiskFile : EFEFile
{
public EFEDiskFile()
{
Name = "Untitled";
Data = new byte[0];
}
public EFEDiskFile(String Path)
{
if (!File.Exists(Path)) throw new ArgumentException("File doesn't exist!");
this.Path = Path;
Name = System.IO.Path.GetFileName(Path);
PrepareDataForUse(File.ReadAllBytes(Path));
}
public String Path { get; set; }
public override void Save()
{
byte[] Data = GetDataForSave();
File.Create(Path).Close();
File.WriteAllBytes(Path, Data);
}
public override byte[] FindFileRelative(string Path)
{
Path = Path.Replace("/", "\\");
String NewPath = System.IO.Path.GetDirectoryName(this.Path) + "\\" + Path;
if (File.Exists(NewPath)) return File.ReadAllBytes(NewPath);
return null;
}
public override bool Equals(object obj)
{
if (!(obj is EFEDiskFile)) return false;
EFEDiskFile a = (EFEDiskFile)obj;
if (a.Path == Path) return true;
return false;
}
}
}

View File

@ -0,0 +1,193 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LibEveryFileExplorer.Files;
using EveryFileExplorer.Plugins;
using System.Windows.Forms;
using LibEveryFileExplorer;
namespace EveryFileExplorer.Files
{
public class FileManager
{
private List<ViewableFile> ViewedFiles = new List<ViewableFile>();
public bool OpenFile(EFEFile File, EFEFile Parent = null)
{
foreach (var v in ViewedFiles)
{
if (v.File.Equals(File))
{
MessageBox.Show("This file has already been opened!");
((Form1)Application.OpenForms[0]).BringMDIWindowToFront(v.Dialog);
return false;
}
}
Type[] formats = GetPossibleFormats(File);
if (formats.Length == 0) return false;
List<Type> Viewables = new List<Type>();
foreach (Type t in formats)
{
if (t.GetInterfaces().Contains(typeof(IViewable))) Viewables.Add(t);
}
Type tt;
if (Viewables.Count == 0) return false;
else if (Viewables.Count == 1) tt = Viewables[0];
else
{
MessageBox.Show("Multiple types match!");
return false;
}
ViewableFile vv = new ViewableFile(File, tt);
ViewedFiles.Add(vv);
vv.DialogClosing += new ViewableFile.DialogClosingEventHandler(v_DialogClosing);
vv.ShowDialog(Application.OpenForms[0]);
if (Parent != null)
{
File.Parent = Parent;
Parent.Children.Add(File);
}
foreach (var v in ViewedFiles)
{
if (vv != v && v.Dialog is IUseOtherFiles) ((IUseOtherFiles)v.Dialog).FileOpened(vv);
}
return true;
}
public bool CreateEmptyFileWithType(Type tt)
{
ViewableFile vv = new ViewableFile(new EFEDiskFile(), tt, true);
ViewedFiles.Add(vv);
vv.DialogClosing += new ViewableFile.DialogClosingEventHandler(v_DialogClosing);
vv.ShowDialog(Application.OpenForms[0]);
foreach (var v in ViewedFiles)
{
if (vv != v && v.Dialog is IUseOtherFiles) ((IUseOtherFiles)v.Dialog).FileOpened(vv);
}
return true;
}
public bool CreateFileFromFileWithType(Type tt)
{
ViewableFile vv = new ViewableFile(new EFEDiskFile(), tt, true);
if (!((IFileCreatable)vv.FileFormat).CreateFromFile()) return false;
ViewedFiles.Add(vv);
vv.DialogClosing += new ViewableFile.DialogClosingEventHandler(v_DialogClosing);
vv.ShowDialog(Application.OpenForms[0]);
foreach (var v in ViewedFiles)
{
if (vv != v && v.Dialog is IUseOtherFiles) ((IUseOtherFiles)v.Dialog).FileOpened(vv);
}
return true;
}
bool v_DialogClosing(ViewableFile VFile)
{
return CloseFile(VFile);
}
public ViewableFile GetViewableFileFromPath(String Path)
{
foreach (var v in ViewedFiles)
{
if (v.File is EFEDiskFile)
{
if (((EFEDiskFile)v.File).Path == Path) return v;
}
}
return null;
}
public ViewableFile GetViewableFileFromFile(EFEFile File)
{
foreach (var v in ViewedFiles)
{
if (v.File.Equals(File)) return v;
}
return null;
}
public ViewableFile GetViewableFileFromWindow(Form Window)
{
foreach (var v in ViewedFiles)
{
if (v.Dialog == Window) return v;
}
return null;
}
public void DisableFileDependencyDialog()
{
ClosingDepDisabled = Closing = true;
}
private bool Closing = false;
private bool ClosingDepDisabled = false;
public void DisableDependenceMessage()
{
Closing = true;
}
public bool CloseFile(ViewableFile File)
{
if (File.File.Children.Count != 0)
{
if (!Closing && MessageBox.Show("One or more files are part of this file. These files will be closed aswell.\nDo you still want to close this file?", "File Dependency", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) return false;
while (File.File.Children.Count > 0)
{
Closing = true;
GetViewableFileFromFile(File.File.Children[0]).Dialog.Close();
Closing = false;
}
}
if (File.File.Parent != null) File.File.Parent.Children.Remove(File.File);
ViewedFiles.Remove(File);
if (!ClosingDepDisabled)
{
foreach (var v in ViewedFiles)
{
if (v.Dialog is IUseOtherFiles) ((IUseOtherFiles)v.Dialog).FileClosed(File);
}
}
return true;
}
public Type[] GetPossibleFormats(EFEFile File)
{
Dictionary<Type, FormatMatch> Formats = new Dictionary<Type, FormatMatch>();
bool gotContent = false;
foreach (Plugin p in Program.PluginManager.Plugins)
{
foreach (Type t in p.FileFormatTypes)
{
dynamic d = new StaticDynamic(t);
FormatMatch m = d.Identifier.IsFormat(File);
if (m == FormatMatch.Content) gotContent = true;
if (m != FormatMatch.No && !(gotContent && m == FormatMatch.Extension)) Formats.Add(t, m);
}
}
if (gotContent)
{
foreach (Type t in Formats.Keys)
{
if (Formats[t] == FormatMatch.Extension) Formats.Remove(t);
}
}
return Formats.Keys.ToArray();
}
public ViewableFile[] GetOpenFilesOfType(Type FileType)
{
List<ViewableFile> f = new List<ViewableFile>();
foreach (var v in ViewedFiles)
{
if (v.FileFormat.GetType() == FileType) f.Add(v);
}
return f.ToArray();
}
}
}

312
EveryFileExplorer/Form1.Designer.cs generated Normal file
View File

@ -0,0 +1,312 @@
namespace EveryFileExplorer
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.mainMenu1 = new LibEveryFileExplorer.UI.MainMenu(this.components);
this.menuFile = new System.Windows.Forms.MenuItem();
this.menuNew = new System.Windows.Forms.MenuItem();
this.menuFileNew = new System.Windows.Forms.MenuItem();
this.menuOpen = new System.Windows.Forms.MenuItem();
this.menuClose = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.menuSave = new System.Windows.Forms.MenuItem();
this.menuSaveAs = new System.Windows.Forms.MenuItem();
this.menuItem7 = new System.Windows.Forms.MenuItem();
this.menuExit = new System.Windows.Forms.MenuItem();
this.menuEdit = new System.Windows.Forms.MenuItem();
this.menuTools = new System.Windows.Forms.MenuItem();
this.menuCompression = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItemOptions = new System.Windows.Forms.MenuItem();
this.menuWindow = new System.Windows.Forms.MenuItem();
this.menuTile = new System.Windows.Forms.MenuItem();
this.menuCascade = new System.Windows.Forms.MenuItem();
this.menuHelp = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.panel1 = new System.Windows.Forms.Panel();
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
this.buttonOpen = new System.Windows.Forms.ToolStripButton();
this.buttonSave = new System.Windows.Forms.ToolStripButton();
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.panel1.SuspendLayout();
this.toolStrip1.SuspendLayout();
this.SuspendLayout();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuFile,
this.menuEdit,
this.menuTools,
this.menuWindow,
this.menuHelp});
//
// menuFile
//
this.menuFile.Index = 0;
this.menuFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuNew,
this.menuFileNew,
this.menuOpen,
this.menuClose,
this.menuItem5,
this.menuSave,
this.menuSaveAs,
this.menuItem7,
this.menuExit});
this.menuFile.Text = "File";
//
// menuNew
//
this.menuNew.Index = 0;
this.menuNew.Text = "New";
//
// menuFileNew
//
this.menuFileNew.Index = 1;
this.menuFileNew.Text = "New from File";
//
// menuOpen
//
this.menuOpen.Index = 2;
this.menuOpen.Text = "Open...";
this.menuOpen.Click += new System.EventHandler(this.OpenFile);
//
// menuClose
//
this.menuClose.Enabled = false;
this.menuClose.Index = 3;
this.menuClose.Text = "Close";
this.menuClose.Click += new System.EventHandler(this.menuClose_Click);
//
// menuItem5
//
this.menuItem5.Index = 4;
this.menuItem5.Text = "-";
//
// menuSave
//
this.menuSave.Enabled = false;
this.menuSave.Index = 5;
this.menuSave.Text = "Save";
this.menuSave.Click += new System.EventHandler(this.SaveFile);
//
// menuSaveAs
//
this.menuSaveAs.Enabled = false;
this.menuSaveAs.Index = 6;
this.menuSaveAs.Text = "Save As...";
this.menuSaveAs.Click += new System.EventHandler(this.menuSaveAs_Click);
//
// menuItem7
//
this.menuItem7.Index = 7;
this.menuItem7.Text = "-";
//
// menuExit
//
this.menuExit.Index = 8;
this.menuExit.Text = "Exit";
this.menuExit.Click += new System.EventHandler(this.menuExit_Click);
//
// menuEdit
//
this.menuEdit.Index = 1;
this.menuEdit.MergeOrder = 1;
this.menuEdit.MergeType = System.Windows.Forms.MenuMerge.MergeItems;
this.menuEdit.Text = "Edit";
//
// menuTools
//
this.menuTools.Index = 2;
this.menuTools.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuCompression,
this.menuItem2,
this.menuItemOptions});
this.menuTools.MergeOrder = 2;
this.menuTools.MergeType = System.Windows.Forms.MenuMerge.MergeItems;
this.menuTools.Text = "Tools";
//
// menuCompression
//
this.menuCompression.Index = 0;
this.menuCompression.Text = "Compression";
//
// menuItem2
//
this.menuItem2.Index = 1;
this.menuItem2.Text = "-";
//
// menuItemOptions
//
this.menuItemOptions.Index = 2;
this.menuItemOptions.Text = "Options...";
//
// menuWindow
//
this.menuWindow.Index = 3;
this.menuWindow.MdiList = true;
this.menuWindow.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuTile,
this.menuCascade});
this.menuWindow.MergeOrder = 3;
this.menuWindow.Text = "Window";
//
// menuTile
//
this.menuTile.Index = 0;
this.menuTile.Text = "Tile";
this.menuTile.Click += new System.EventHandler(this.menuTile_Click);
//
// menuCascade
//
this.menuCascade.Index = 1;
this.menuCascade.Text = "Cascade";
this.menuCascade.Click += new System.EventHandler(this.menuCascade_Click);
//
// menuHelp
//
this.menuHelp.Index = 4;
this.menuHelp.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem4});
this.menuHelp.MergeOrder = 4;
this.menuHelp.Text = "Help";
//
// menuItem4
//
this.menuItem4.Index = 0;
this.menuItem4.Text = "About...";
//
// openFileDialog1
//
this.openFileDialog1.FileName = "openFileDialog1";
//
// panel1
//
this.panel1.AutoSize = true;
this.panel1.Controls.Add(this.toolStrip1);
this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(804, 25);
this.panel1.TabIndex = 3;
//
// toolStrip1
//
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.buttonOpen,
this.buttonSave});
this.toolStrip1.Location = new System.Drawing.Point(0, 0);
this.toolStrip1.Name = "toolStrip1";
this.toolStrip1.Size = new System.Drawing.Size(804, 25);
this.toolStrip1.TabIndex = 2;
this.toolStrip1.Text = "toolStrip1";
//
// buttonOpen
//
this.buttonOpen.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.buttonOpen.Image = ((System.Drawing.Image)(resources.GetObject("buttonOpen.Image")));
this.buttonOpen.ImageTransparentColor = System.Drawing.Color.Magenta;
this.buttonOpen.Name = "buttonOpen";
this.buttonOpen.Size = new System.Drawing.Size(23, 22);
this.buttonOpen.Text = "Open";
this.buttonOpen.Click += new System.EventHandler(this.OpenFile);
//
// buttonSave
//
this.buttonSave.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.buttonSave.Enabled = false;
this.buttonSave.Image = ((System.Drawing.Image)(resources.GetObject("buttonSave.Image")));
this.buttonSave.ImageTransparentColor = System.Drawing.Color.Magenta;
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(23, 22);
this.buttonSave.Text = "Save";
this.buttonSave.Click += new System.EventHandler(this.SaveFile);
//
// Form1
//
this.AllowDrop = true;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(804, 443);
this.Controls.Add(this.panel1);
this.DoubleBuffered = true;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.IsMdiContainer = true;
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "Every File Explorer";
this.Load += new System.EventHandler(this.Form1_Load);
this.MdiChildActivate += new System.EventHandler(this.Form1_MdiChildActivate);
this.DragDrop += new System.Windows.Forms.DragEventHandler(this.Form1_DragDrop);
this.DragEnter += new System.Windows.Forms.DragEventHandler(this.Form1_DragEnter);
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.toolStrip1.ResumeLayout(false);
this.toolStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private LibEveryFileExplorer.UI.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuFile;
private System.Windows.Forms.MenuItem menuEdit;
private System.Windows.Forms.MenuItem menuTools;
private System.Windows.Forms.MenuItem menuWindow;
private System.Windows.Forms.MenuItem menuHelp;
private System.Windows.Forms.MenuItem menuNew;
private System.Windows.Forms.MenuItem menuOpen;
private System.Windows.Forms.MenuItem menuItemOptions;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.ToolStrip toolStrip1;
private System.Windows.Forms.ToolStripButton buttonOpen;
private System.Windows.Forms.ToolStripButton buttonSave;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.MenuItem menuExit;
private System.Windows.Forms.MenuItem menuTile;
private System.Windows.Forms.MenuItem menuCascade;
private System.Windows.Forms.MenuItem menuClose;
private System.Windows.Forms.MenuItem menuSave;
private System.Windows.Forms.MenuItem menuSaveAs;
private System.Windows.Forms.MenuItem menuItem7;
private System.Windows.Forms.SaveFileDialog saveFileDialog1;
private System.Windows.Forms.MenuItem menuFileNew;
private System.Windows.Forms.MenuItem menuCompression;
private System.Windows.Forms.MenuItem menuItem2;
}
}

359
EveryFileExplorer/Form1.cs Normal file
View File

@ -0,0 +1,359 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LibEveryFileExplorer.Files;
using EveryFileExplorer.Plugins;
using EveryFileExplorer.Files;
using LibEveryFileExplorer;
using System.Runtime.InteropServices;
using System.Reflection;
using LibEveryFileExplorer.Compression;
namespace EveryFileExplorer
{
public partial class Form1 : Form
{
private const int GWL_STYLE = -16;
private const int GWL_EXSTYLE = -20;
private const int WS_BORDER = 0x00800000;
private const int WS_EX_CLIENTEDGE = 0x00000200;
private const uint SWP_NOSIZE = 0x0001;
private const uint SWP_NOMOVE = 0x0002;
private const uint SWP_NOZORDER = 0x0004;
private const uint SWP_NOREDRAW = 0x0008;
private const uint SWP_NOACTIVATE = 0x0010;
private const uint SWP_FRAMECHANGED = 0x0020;
private const uint SWP_SHOWWINDOW = 0x0040;
private const uint SWP_HIDEWINDOW = 0x0080;
private const uint SWP_NOCOPYBITS = 0x0100;
private const uint SWP_NOOWNERZORDER = 0x0200;
private const uint SWP_NOSENDCHANGING = 0x0400;
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int SetWindowLong(IntPtr hWnd, int Index, int Value);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int GetWindowLong(IntPtr hWnd, int Index);
[DllImport("user32.dll", ExactSpelling = true)]
private static extern int SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < this.Controls.Count; i++)
{
MdiClient mdiClient = this.Controls[i] as MdiClient;
if (mdiClient != null)
{
SetMDIBorderStyle(mdiClient, BorderStyle.None);
}
}
menuNew.MenuItems.Clear();
foreach (Plugin p in Program.PluginManager.Plugins)
{
List<Type> creatables = new List<Type>();
foreach (Type t in p.FileFormatTypes)
{
if (t.GetInterfaces().Contains(typeof(IEmptyCreatable))) creatables.Add(t);
}
if (creatables.Count > 0)
{
MenuItem m = menuNew.MenuItems.Add(p.Name);
foreach (Type t in creatables)
{
MenuItem ii = m.MenuItems.Add(((dynamic)new StaticDynamic(t)).Identifier.GetFileDescription());
ii.Click += new EventHandler(CreateNew_Click);
ii.Tag = t;
}
}
}
menuFileNew.MenuItems.Clear();
foreach (Plugin p in Program.PluginManager.Plugins)
{
List<Type> creatables = new List<Type>();
foreach (Type t in p.FileFormatTypes)
{
if (t.GetInterfaces().Contains(typeof(IFileCreatable))) creatables.Add(t);
}
if (creatables.Count > 0)
{
MenuItem m = menuFileNew.MenuItems.Add(p.Name);
foreach (Type t in creatables)
{
MenuItem ii = m.MenuItems.Add(((dynamic)new StaticDynamic(t)).Identifier.GetFileDescription());
ii.Click += new EventHandler(CreateFileNew_Click);
ii.Tag = t;
}
}
}
menuCompression.MenuItems.Clear();
foreach (Plugin p in Program.PluginManager.Plugins)
{
if (p.CompressionTypes.Length != 0)
{
MenuItem m = menuCompression.MenuItems.Add(p.Name);
foreach (Type t in p.CompressionTypes)
{
MenuItem ii = m.MenuItems.Add(((dynamic)new StaticDynamic(t)).Identifier.GetCompressionDescription());
ii.MenuItems.Add("Decompress...");
if (t.GetInterfaces().Contains(typeof(ICompressable))) ii.MenuItems.Add("Compress...");
//ii.Click += new EventHandler(CreateFileNew_Click);
//ii.Tag = t;
}
}
}
}
private void SetMDIBorderStyle(MdiClient mdiClient, BorderStyle value)
{
// Get styles using Win32 calls
int style = GetWindowLong(mdiClient.Handle, GWL_STYLE);
int exStyle = GetWindowLong(mdiClient.Handle, GWL_EXSTYLE);
// Add or remove style flags as necessary.
switch (value)
{
case BorderStyle.Fixed3D:
exStyle |= WS_EX_CLIENTEDGE;
style &= ~WS_BORDER;
break;
case BorderStyle.FixedSingle:
exStyle &= ~WS_EX_CLIENTEDGE;
style |= WS_BORDER;
break;
case BorderStyle.None:
style &= ~WS_BORDER;
exStyle &= ~WS_EX_CLIENTEDGE;
break;
}
// Set the styles using Win32 calls
SetWindowLong(mdiClient.Handle, GWL_STYLE, style);
SetWindowLong(mdiClient.Handle, GWL_EXSTYLE, exStyle);
// Update the non-client area.
SetWindowPos(mdiClient.Handle, IntPtr.Zero, 0, 0, 0, 0,
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER |
SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
}
public void BringMDIWindowToFront(Form Dialog)
{
ActivateMdiChild(Dialog);
Dialog.BringToFront();
}
bool opening = false;
private void OpenFile(object sender, EventArgs e)
{
if (opening) return;
opening = true;
String Filter = "";
List<String> Filters = new List<string>();
Filters.Add("all files (*.*)|*.*");
List<String> Extenstions = new List<string>();
String AllSupportedFilesA = "All Supported Files (";
String AllSupportedFilesB = "|";
foreach (Plugin p in Program.PluginManager.Plugins)
{
foreach (Type t in p.FileFormatTypes)
{
if (t.GetInterfaces().Contains(typeof(IViewable)))
{
dynamic d = new StaticDynamic(t);
String FilterString;
try
{
FilterString = d.Identifier.GetFileFilter();
}
catch (NotImplementedException)
{
continue;
}
if (FilterString == null || FilterString.Length == 0) continue;
if (!Filters.Contains(FilterString.ToLower()))
{
string[] strArray = FilterString.Split(new char[] { '|' });
if ((strArray == null) || ((strArray.Length % 2) != 0)) continue;
string[] q = FilterString.Split('|');
for (int i = 1; i < q.Length; i += 2)
{
foreach (string f in q[i].Split(';'))
{
if (!Extenstions.Contains(f.ToLower()))
{
Extenstions.Add(f.ToLower());
if (!AllSupportedFilesA.EndsWith("(")) AllSupportedFilesA += ", ";
AllSupportedFilesA += f.ToLower();
if (!AllSupportedFilesB.EndsWith("|")) AllSupportedFilesB += ";";
AllSupportedFilesB += f.ToLower();
}
}
}
Filters.Add(FilterString.ToLower());
if (Filter != "") Filter += "|";
Filter += FilterString;
}
}
}
}
if (Filter != "")
{
Filter = AllSupportedFilesA + ")" + AllSupportedFilesB + "|" + Filter;
Filter += "|";
}
Filter += "All Files (*.*)|*.*";
openFileDialog1.Filter = Filter;
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK
&& openFileDialog1.FileName.Length > 0)
{
Program.FileManager.OpenFile(new EFEDiskFile(openFileDialog1.FileName));
}
opening = false;
}
private void menuTile_Click(object sender, EventArgs e)
{
LayoutMdi(MdiLayout.TileVertical);
}
private void menuCascade_Click(object sender, EventArgs e)
{
LayoutMdi(MdiLayout.Cascade);
}
private void Form1_MdiChildActivate(object sender, EventArgs e)
{
if (ActiveMdiChild != null)
{
var v = Program.FileManager.GetViewableFileFromWindow(ActiveMdiChild);
dynamic FileFormat = v.FileFormat;
menuSave.Enabled = buttonSave.Enabled = FileFormat is IWriteable && (v.File.CompressionFormat == null || v.File.CompressionFormat is ICompressable);
menuSaveAs.Enabled = FileFormat is IWriteable | FileFormat is IConvertable;
menuClose.Enabled = true;
}
else
{
menuClose.Enabled = false;
menuSaveAs.Enabled = menuSave.Enabled = buttonSave.Enabled = false;
}
}
private void menuExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void SaveFile(object sender, EventArgs e)
{
ViewableFile file = Program.FileManager.GetViewableFileFromWindow(ActiveMdiChild);
if (!(file.FileFormat is IWriteable))
{
MessageBox.Show("This format is not saveable!");
return;
}
if (file.File is EFEDiskFile && ((EFEDiskFile)file.File).Path == null)
{
saveFileDialog1.Filter = file.FileFormat.GetSaveDefaultFileFilter();
saveFileDialog1.Title = "Save";
saveFileDialog1.FileName = file.File.Name;
if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK
&& saveFileDialog1.FileName.Length > 0)
{
((EFEDiskFile)file.File).Path = saveFileDialog1.FileName;
file.File.Name = System.IO.Path.GetFileName(saveFileDialog1.FileName);
file.Dialog.Text = file.File.Name;
}
else return;
}
try
{
byte[] data = file.FileFormat.Write();
file.File.Data = data;
file.File.Save();
}
catch
{
MessageBox.Show("An error occurred while trying to save!");
}
}
private void menuClose_Click(object sender, EventArgs e)
{
ActiveMdiChild.Close();
}
private void menuSaveAs_Click(object sender, EventArgs e)
{
String Filter = "";
ViewableFile file = Program.FileManager.GetViewableFileFromWindow(ActiveMdiChild);
if (file.FileFormat is IWriteable) Filter += file.FileFormat.GetSaveDefaultFileFilter();
if (file.FileFormat is IConvertable)
{
if (Filter.Length > 0) Filter += "|";
Filter += file.FileFormat.GetConversionFileFilters();
}
saveFileDialog1.Filter = Filter;
saveFileDialog1.Title = "Save As";
saveFileDialog1.FileName = file.File.Name;
if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK
&& saveFileDialog1.FileName.Length > 0)
{
if (file.FileFormat is IWriteable && saveFileDialog1.FilterIndex == 1)
{
try
{
byte[] data = file.FileFormat.Write();
if (data != null)
{
System.IO.File.Create(saveFileDialog1.FileName).Close();
System.IO.File.WriteAllBytes(saveFileDialog1.FileName, data);
}
}
catch { }
}
else
{
if (!file.FileFormat.Convert(saveFileDialog1.FilterIndex - (file.FileFormat is IWriteable ? 2 : 1), saveFileDialog1.FileName))
{
MessageBox.Show("An error occured while trying to convert!");
}
}
}
}
private void Form1_DragDrop(object sender, DragEventArgs e)
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
foreach (string file in files) Program.FileManager.OpenFile(new EFEDiskFile(file));
}
private void Form1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
}
void CreateNew_Click(object sender, EventArgs e)
{
Program.FileManager.CreateEmptyFileWithType((Type)(((MenuItem)sender).Tag));
}
void CreateFileNew_Click(object sender, EventArgs e)
{
Program.FileManager.CreateFileFromFileWithType((Type)(((MenuItem)sender).Tag));
}
}
}

7817
EveryFileExplorer/Form1.resx Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using LibEveryFileExplorer.Files;
using LibEveryFileExplorer.Compression;
namespace EveryFileExplorer.Plugins
{
public class Plugin
{
public String Name;
public String Description;
public String Version;
public Type[] CompressionTypes;
public Type[] FileFormatTypes;
public Plugin(Assembly Assembly)
{
Name = Assembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false).OfType<AssemblyTitleAttribute>().FirstOrDefault().Title;
Description = Assembly.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false).OfType<AssemblyDescriptionAttribute>().FirstOrDefault().Description;
try
{
Version = Assembly.GetCustomAttributes(typeof(AssemblyVersionAttribute), false).OfType<AssemblyVersionAttribute>().FirstOrDefault().Version;
}
catch
{
Version = null;
}
Type[] tt = Assembly.GetExportedTypes();
List<Type> fe = new List<Type>();
List<Type> ce = new List<Type>();
foreach (var t in tt)
{
if (!t.IsClass) continue;
var v = t.GetInterfaces();
if (v.Length != 0 && t.GetInterfaces()[0].Name == "FileFormatBase") fe.Add(t);
else if (v.Length != 0 && t.GetInterfaces()[0].Name == "CompressionFormatBase") ce.Add(t);
}
FileFormatTypes = fe.ToArray();
CompressionTypes = ce.ToArray();
}
public static bool IsPlugin(Assembly Assembly)
{
Type[] tt = Assembly.GetExportedTypes();
foreach (var t in tt)
{
if (!t.IsClass) continue;
var v = t.GetInterfaces();
if (v.Length != 0 && (t.GetInterfaces()[0].Name == "FileFormatBase" || t.GetInterfaces()[0].Name == "CompressionFormatBase")) return true;
}
return false;
}
}
}

View File

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Reflection;
namespace EveryFileExplorer.Plugins
{
public class PluginManager
{
public Plugin[] Plugins { get; private set; }
public PluginManager()
{
string[] d = Directory.GetFiles(Path.GetDirectoryName(Application.ExecutablePath) + "\\Plugins\\", "*.dll", SearchOption.TopDirectoryOnly);
List<Plugin> p = new List<Plugin>();
foreach (var s in d)
{
try
{
AssemblyName.GetAssemblyName(s);
}
catch (BadImageFormatException)
{
continue;//This is not a .net assembly
}
Assembly ass = Assembly.LoadFile(s);
if (Plugin.IsPlugin(ass)) p.Add(new Plugin(ass));
}
Plugins = p.ToArray();
}
}
}

View File

@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using EveryFileExplorer.Plugins;
using EveryFileExplorer.Files;
using System.Reflection;
using System.IO;
namespace EveryFileExplorer
{
static class Program
{
public static PluginManager PluginManager { get; private set; }
public static FileManager FileManager { get; private set; }
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
PluginManager = new PluginManager();
FileManager = new FileManager();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
string folderPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\Plugins\\";
string assemblyPath = Path.Combine(folderPath, new AssemblyName(args.Name).Name + ".dll");
if (File.Exists(assemblyPath) == false) return null;
Assembly assembly = Assembly.LoadFrom(assemblyPath);
return assembly;
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 448 KiB

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("Every File Explorer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Every File Explorer")]
[assembly: AssemblyCopyright("Copyright © Florian Nouwt 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("33556173-9816-4c7a-960f-b1fffa0c01f6")]
// 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,71 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.18063
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace EveryFileExplorer.Properties
{
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources
{
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources()
{
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager
{
get
{
if ((resourceMan == null))
{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("EveryFileExplorer.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
}
}

View File

@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,30 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.18063
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace EveryFileExplorer.Properties
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default
{
get
{
return defaultInstance;
}
}
}
}

View File

@ -0,0 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>

View File

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LibEveryFileExplorer.Collections;
using System.Drawing;
namespace LibEveryFileExplorer._3D
{
public class Polygon
{
public PolygonType PolyType;
public Vector3[] Normals;
public Vector2[] TexCoords;
public Vector2[] TexCoords2;
public Vector2[] TexCoords3;
public Vector3[] Vertex;
public Color[] Colors;
public Polygon() { }
public Polygon(PolygonType PolyType, Vector3[] Vertex, Vector3[] Normals, Vector2[] TexCoords, Color[] Colors = null)
{
this.PolyType = PolyType;
this.Normals = Normals;
this.TexCoords = TexCoords;
this.Vertex = Vertex;
this.Colors = Colors;
}
}
public enum PolygonType
{
Triangle,
Quad,
TriangleStrip,
QuadStrip
}
}

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LibEveryFileExplorer.Collections;
namespace LibEveryFileExplorer._3D
{
public class Triangle
{
public Triangle(Vector3 A, Vector3 B, Vector3 C)
{
PointA = A;
PointB = B;
PointC = C;
}
public Vector3 PointA { get; set; }
public Vector3 PointB { get; set; }
public Vector3 PointC { get; set; }
public Vector3 Normal
{
get
{
Vector3 a = (PointB - PointA).Cross(PointC - PointA);
return a / (float)Math.Sqrt(a.X * a.X + a.Y * a.Y + a.Z * a.Z);
}
}
}
}

View File

@ -0,0 +1,114 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LibEveryFileExplorer.Collections
{
public struct Matrix33
{
public static readonly Matrix33 Identity = new Matrix33(new float[] { 1, 0, 0, 0, 1, 0, 0, 0, 1 });
public Matrix33(params float[] Matrix)
{
if (Matrix == null || Matrix.Length != 9) throw new ArgumentException();
row0 = new Vector3();
row1 = new Vector3();
row2 = new Vector3();
for (int i = 0; i < 9; i++)
{
this[i / 3, i % 3] = Matrix[i];
}
}
private Vector3 row0;
private Vector3 row1;
private Vector3 row2;
public float this[int index]
{
get { return this[index / 3, index % 3]; }
set { this[index / 3, index % 3] = value; }
}
public float this[int row, int column]
{
get
{
switch (row)
{
case 0: return row0[column];
case 1: return row1[column];
case 2: return row2[column];
}
throw new IndexOutOfRangeException();
}
set
{
switch (row)
{
case 0: row0[column] = value; return;
case 1: row1[column] = value; return;
case 2: row2[column] = value; return;
}
throw new IndexOutOfRangeException();
}
}
public static Matrix33 operator *(Matrix33 Left, Matrix33 Right)
{
Matrix33 result = new Matrix33();
for (int row = 0; row < 3; row++)
{
for (int col = 0; col < 3; col++)
{
for (int inner = 0; inner < 3; inner++)
{
result[row, col] += Left[inner, col] * Right[row, inner];
}
}
}
return result;
}
public static Matrix33 operator *(Matrix33 Left, float Right)
{
for (int row = 0; row < 3; row++)
{
for (int col = 0; col < 3; col++)
{
Left[row, col] *= Right;
}
}
return Left;
}
public static Matrix33 operator *(float Left, Matrix33 Right)
{
for (int row = 0; row < 3; row++)
{
for (int col = 0; col < 3; col++)
{
Right[row, col] *= Left;
}
}
return Right;
}
public static Matrix33 CreateScale(Vector3 Scale)
{
Matrix33 result = Matrix33.Identity;
result[0, 0] = Scale.X;
result[1, 1] = Scale.Y;
result[2, 2] = Scale.X;
return result;
}
public static explicit operator float[](Matrix33 Matrix)
{
float[] result = new float[9];
for (int i = 0; i < 9; i++) result[i] = Matrix[i];
return result;
}
}
}

View File

@ -0,0 +1,119 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LibEveryFileExplorer.Collections
{
public struct Matrix34
{
public static readonly Matrix34 Identity = new Matrix34(new float[] { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0 });
public Matrix34(params float[] Matrix)
{
if (Matrix == null || Matrix.Length != 12) throw new ArgumentException();
row0 = new Vector4();
row1 = new Vector4();
row2 = new Vector4();
for (int i = 0; i < 12; i++)
{
this[i / 4, i % 4] = Matrix[i];
}
}
private Vector4 row0;
private Vector4 row1;
private Vector4 row2;
public Vector4 Row0 { get { return row0; } set { row0 = value; } }
public Vector4 Row1 { get { return row1; } set { row1 = value; } }
public Vector4 Row2 { get { return row2; } set { row2 = value; } }
public float this[int index]
{
get { return this[index / 4, index % 4]; }
set { this[index / 4, index % 4] = value; }
}
public float this[int row, int column]
{
get
{
switch (row)
{
case 0: return row0[column];
case 1: return row1[column];
case 2: return row2[column];
}
throw new IndexOutOfRangeException();
}
set
{
switch (row)
{
case 0: row0[column] = value; return;
case 1: row1[column] = value; return;
case 2: row2[column] = value; return;
}
throw new IndexOutOfRangeException();
}
}
public static Matrix34 operator *(Matrix34 Left, Matrix34 Right)
{
Matrix44 l = new Matrix44(Left, new Vector4(0, 0, 0, 1));
Matrix44 r = new Matrix44(Right, new Vector4(0, 0, 0, 1));
Matrix44 Result = l * r;
Matrix34 result2 = new Matrix34();
for (int i = 0; i < 12; i++)
{
result2[i] = Result[i];
}
return result2;
}
public static Vector3 operator *(Vector3 Vector, Matrix34 Matrix)
{
return new Vector3(((Matrix.Row0.X * Vector.X) + (Matrix.Row0.Y * Vector.Y)) + (Matrix.Row0.Z * Vector.Z), ((Matrix.Row1.X * Vector.X) + (Matrix.Row1.Y * Vector.Y)) + (Matrix.Row1.Z * Vector.Z), ((Matrix.Row2.X * Vector.X) + (Matrix.Row2.Y * Vector.Y)) + (Matrix.Row2.Z * Vector.Z)) + new Vector3(Matrix.Row0.W, Matrix.Row1.W, Matrix.Row2.W);
}
public static Vector3 operator *(Matrix34 Matrix, Vector3 Vector)
{
return Vector * Matrix;
}
public static Vector2 operator *(Vector2 Vector, Matrix34 Matrix)
{
return new Vector2(((Matrix.Row0.X * Vector.X) + (Matrix.Row0.Y * Vector.Y)) + Matrix.Row0.Z, ((Matrix.Row1.X * Vector.X) + (Matrix.Row1.Y * Vector.Y)) + Matrix.Row1.Z) + new Vector2(Matrix.Row0.W, Matrix.Row1.W);
}
public static Vector2 operator *(Matrix34 Matrix, Vector2 Vector)
{
return Vector * Matrix;
}
public static Matrix34 operator *(Matrix34 Left, float Right)
{
for (int row = 0; row < 3; row++)
{
for (int col = 0; col < 4; col++)
{
Left[row, col] *= Right;
}
}
return Left;
}
public static Matrix34 operator *(float Left, Matrix34 Right)
{
for (int row = 0; row < 3; row++)
{
for (int col = 0; col < 4; col++)
{
Right[row, col] *= Left;
}
}
return Right;
}
}
}

View File

@ -0,0 +1,102 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LibEveryFileExplorer.Collections
{
public struct Matrix43
{
public static readonly Matrix43 Identity = new Matrix43(new float[] { 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 });
public Matrix43(params float[] Matrix)
{
if (Matrix == null || Matrix.Length != 12) throw new ArgumentException();
row0 = new Vector3();
row1 = new Vector3();
row2 = new Vector3();
row3 = new Vector3();
for (int i = 0; i < 12; i++)
{
this[i / 3, i % 3] = Matrix[i];
}
}
private Vector3 row0;
private Vector3 row1;
private Vector3 row2;
private Vector3 row3;
public float this[int index]
{
get { return this[index / 3, index % 3]; }
set { this[index / 3, index % 3] = value; }
}
public float this[int row, int column]
{
get
{
switch (row)
{
case 0: return row0[column];
case 1: return row1[column];
case 2: return row2[column];
case 3: return row3[column];
}
throw new IndexOutOfRangeException();
}
set
{
switch (row)
{
case 0: row0[column] = value; return;
case 1: row1[column] = value; return;
case 2: row2[column] = value; return;
case 3: row3[column] = value; return;
}
throw new IndexOutOfRangeException();
}
}
public static Matrix43 operator *(Matrix43 Left, Matrix43 Right)
{
Matrix44 l = new Matrix44(Left, new Vector4(0, 0, 0, 1));
Matrix44 r = new Matrix44(Right, new Vector4(0, 0, 0, 1));
Matrix44 Result = l * r;
Matrix43 result2 = new Matrix43();
for (int row = 0; row < 4; row++)
{
for (int col = 0; col < 3; col++)
{
result2[row, col] = Result[row,col];
}
}
return result2;
}
public static Matrix43 operator *(Matrix43 Left, float Right)
{
for (int row = 0; row < 4; row++)
{
for (int col = 0; col < 3; col++)
{
Left[row, col] *= Right;
}
}
return Left;
}
public static Matrix43 operator *(float Left, Matrix43 Right)
{
for (int row = 0; row < 4; row++)
{
for (int col = 0; col < 3; col++)
{
Right[row, col] *= Left;
}
}
return Right;
}
}
}

View File

@ -0,0 +1,208 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LibEveryFileExplorer.Collections
{
public struct Matrix44
{
public static readonly Matrix44 Identity = new Matrix44(new float[] { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 });
public Matrix44(params float[] Matrix)
{
if (Matrix == null || Matrix.Length != 16) throw new ArgumentException();
row0 = new Vector4();
row1 = new Vector4();
row2 = new Vector4();
row3 = new Vector4();
for (int i = 0; i < 16; i++)
{
this[i / 4, i % 4] = Matrix[i];
}
}
public Matrix44(Matrix33 Matrix)
: this(Matrix, 0, 0, 0, new Vector4()) { }
public Matrix44(Matrix33 Matrix, float M14, float M24, float M34, Vector4 Row3)
{
row0 = new Vector4();
row1 = new Vector4();
row2 = new Vector4();
row3 = Row3;
for (int i = 0; i < 9; i++)
{
this[i / 3, i % 3] = Matrix[i];
}
row0.W = M14;
row1.W = M24;
row2.W = M34;
}
public Matrix44(Matrix34 Matrix)
: this(Matrix, new Vector4()) { }
public Matrix44(Matrix34 Matrix, Vector4 Row3)
{
row0 = new Vector4();
row1 = new Vector4();
row2 = new Vector4();
row3 = Row3;
for (int i = 0; i < 12; i++)
{
this[i / 4, i % 4] = Matrix[i];
}
}
public Matrix44(Matrix43 Matrix)
: this(Matrix, new Vector4()) { }
public Matrix44(Matrix43 Matrix, Vector4 Column3)
{
row0 = new Vector4();
row1 = new Vector4();
row2 = new Vector4();
row3 = new Vector4();
row0.W = Column3.X;
row1.W = Column3.Y;
row2.W = Column3.Z;
row3.W = Column3.W;
for (int i = 0; i < 12; i++)
{
this[i / 3, i % 3] = Matrix[i];
}
}
private Vector4 row0;
private Vector4 row1;
private Vector4 row2;
private Vector4 row3;
public Vector4 Row0 { get { return row0; } set { row0 = value; } }
public Vector4 Row1 { get { return row1; } set { row1 = value; } }
public Vector4 Row2 { get { return row2; } set { row2 = value; } }
public Vector4 Row3 { get { return row3; } set { row3 = value; } }
public float this[int index]
{
get { return this[index / 4, index % 4]; }
set { this[index / 4, index % 4] = value; }
}
public float this[int row, int column]
{
get
{
switch (row)
{
case 0: return row0[column];
case 1: return row1[column];
case 2: return row2[column];
case 3: return row3[column];
}
throw new IndexOutOfRangeException();
}
set
{
switch (row)
{
case 0: row0[column] = value; return;
case 1: row1[column] = value; return;
case 2: row2[column] = value; return;
case 3: row3[column] = value; return;
}
throw new IndexOutOfRangeException();
}
}
public static Matrix44 operator *(Matrix44 Left, Matrix44 Right)
{
Matrix44 tmpMatrix = new Matrix44();
tmpMatrix[0] = (Left[0] * Right[0]) + (Left[4] * Right[1]) + (Left[8] * Right[2]) + (Left[12] * Right[3]);
tmpMatrix[1] = (Left[1] * Right[0]) + (Left[5] * Right[1]) + (Left[9] * Right[2]) + (Left[13] * Right[3]);
tmpMatrix[2] = (Left[2] * Right[0]) + (Left[6] * Right[1]) + (Left[10] * Right[2]) + (Left[14] * Right[3]);
tmpMatrix[3] = (Left[3] * Right[0]) + (Left[7] * Right[1]) + (Left[11] * Right[2]) + (Left[15] * Right[3]);
tmpMatrix[4] = (Left[0] * Right[4]) + (Left[4] * Right[5]) + (Left[8] * Right[6]) + (Left[12] * Right[7]);
tmpMatrix[5] = (Left[1] * Right[4]) + (Left[5] * Right[5]) + (Left[9] * Right[6]) + (Left[13] * Right[7]);
tmpMatrix[6] = (Left[2] * Right[4]) + (Left[6] * Right[5]) + (Left[10] * Right[6]) + (Left[14] * Right[7]);
tmpMatrix[7] = (Left[3] * Right[4]) + (Left[7] * Right[5]) + (Left[11] * Right[6]) + (Left[15] * Right[7]);
tmpMatrix[8] = (Left[0] * Right[8]) + (Left[4] * Right[9]) + (Left[8] * Right[10]) + (Left[12] * Right[11]);
tmpMatrix[9] = (Left[1] * Right[8]) + (Left[5] * Right[9]) + (Left[9] * Right[10]) + (Left[13] * Right[11]);
tmpMatrix[10] = (Left[2] * Right[8]) + (Left[6] * Right[9]) + (Left[10] * Right[10]) + (Left[14] * Right[11]);
tmpMatrix[11] = (Left[3] * Right[8]) + (Left[7] * Right[9]) + (Left[11] * Right[10]) + (Left[15] * Right[11]);
tmpMatrix[12] = (Left[0] * Right[12]) + (Left[4] * Right[13]) + (Left[8] * Right[14]) + (Left[12] * Right[15]);
tmpMatrix[13] = (Left[1] * Right[12]) + (Left[5] * Right[13]) + (Left[9] * Right[14]) + (Left[13] * Right[15]);
tmpMatrix[14] = (Left[2] * Right[12]) + (Left[6] * Right[13]) + (Left[10] * Right[14]) + (Left[14] * Right[15]);
tmpMatrix[15] = (Left[3] * Right[12]) + (Left[7] * Right[13]) + (Left[11] * Right[14]) + (Left[15] * Right[15]);
return tmpMatrix;
}
public static Vector3 operator *(Vector3 Left, Matrix44 Right)
{
Vector3 result = new Vector3();
result[0] = Left.X * Right[0] + Left.Y * Right[4] + Left.Z * Right[8] + Right[12];
result[1] = Left.X * Right[1] + Left.Y * Right[5] + Left.Z * Right[9] + Right[13];
result[2] = Left.X * Right[2] + Left.Y * Right[6] + Left.Z * Right[10] + Right[14];
return result;
}
public static Vector3 operator *(Matrix44 Left, Vector3 Right)
{
return Right * Left;
}
public static Matrix44 operator *(Matrix44 Left, float Right)
{
for (int row = 0; row < 4; row++)
{
for (int col = 0; col < 4; col++)
{
Left[row, col] *= Right;
}
}
return Left;
}
public static Matrix44 operator *(float Left, Matrix44 Right)
{
for (int row = 0; row < 4; row++)
{
for (int col = 0; col < 4; col++)
{
Right[row, col] *= Left;
}
}
return Right;
}
public static Matrix44 CreateTranslation(Vector3 Translation)
{
Matrix44 result = Matrix44.Identity;
result[3, 0] = Translation.X;
result[3, 1] = Translation.Y;
result[3, 2] = Translation.Z;
return result;
}
public static Matrix44 CreateScale(Vector3 Scale)
{
Matrix44 result = Matrix44.Identity;
result[0, 0] = Scale.X;
result[1, 1] = Scale.Y;
result[2, 2] = Scale.X;
return result;
}
public static explicit operator float[](Matrix44 Matrix)
{
float[] result = new float[16];
for (int i = 0; i < 16; i++) result[i] = Matrix[i];
return result;
}
}
}

View File

@ -0,0 +1,128 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LibEveryFileExplorer.Collections
{
public struct Vector2
{
public Vector2(float Value)
: this(Value, Value) { }
public Vector2(float X, float Y)
{
x = X;
y = Y;
}
private float x, y;
public float X { get { return x; } set { x = value; } }
public float Y { get { return y; } set { y = value; } }
public float this[int index]
{
get
{
switch (index)
{
case 0: return X;
case 1: return Y;
}
throw new IndexOutOfRangeException();
}
set
{
switch (index)
{
case 0: X = value; return;
case 1: Y = value; return;
}
throw new IndexOutOfRangeException();
}
}
public float Length
{
get { return (float)Math.Sqrt(X * X + Y * Y); }
}
public void Normalize()
{
this /= Length;
}
public float Dot(Vector2 Right)
{
return X * Right.X + Y * Right.Y;
}
public static Vector2 operator +(Vector2 Left, Vector2 Right)
{
return new Vector2(Left.X + Right.X, Left.Y + Right.Y);
}
public static Vector2 operator +(Vector2 Left, float Right)
{
return new Vector2(Left.X + Right, Left.Y + Right);
}
public static Vector2 operator -(Vector2 Left, Vector2 Right)
{
return new Vector2(Left.X - Right.X, Left.Y - Right.Y);
}
public static Vector2 operator -(Vector2 Left, float Right)
{
return new Vector2(Left.X - Right, Left.Y - Right);
}
public static Vector2 operator -(Vector2 Left)
{
return new Vector2(-Left.X, -Left.Y);
}
public static Vector2 operator *(Vector2 Left, Vector2 Right)
{
return new Vector2(Left.X * Right.X, Left.Y * Right.Y);
}
public static Vector2 operator *(Vector2 Left, float Right)
{
return new Vector2(Left.X * Right, Left.Y * Right);
}
public static Vector2 operator *(float Left, Vector2 Right)
{
return new Vector2(Left * Right.X, Left * Right.Y);
}
public static Vector2 operator /(Vector2 Left, float Right)
{
return new Vector2(Left.X / Right, Left.Y / Right);
}
public static bool operator ==(Vector2 Left, Vector2 Right)
{
return Left.Equals(Right);
}
public static bool operator !=(Vector2 Left, Vector2 Right)
{
return !Left.Equals(Right);
}
public override bool Equals(object obj)
{
if (!(obj is Vector2)) return false;
Vector2 vec = (Vector2)obj;
return vec.X == X && vec.Y == Y;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
}

View File

@ -0,0 +1,145 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LibEveryFileExplorer.Collections
{
public struct Vector3
{
public Vector3(float Value)
: this(Value, Value, Value) { }
public Vector3(Vector2 Vector, float Z)
: this(Vector.X, Vector.Y, Z) { }
public Vector3(float X, float Y, float Z)
{
x = X;
y = Y;
z = Z;
}
private float x, y, z;
public float X { get { return x; } set { x = value; } }
public float Y { get { return y; } set { y = value; } }
public float Z { get { return z; } set { z = value; } }
public float this[int index]
{
get
{
switch (index)
{
case 0: return X;
case 1: return Y;
case 2: return Z;
}
throw new IndexOutOfRangeException();
}
set
{
switch (index)
{
case 0: X = value; return;
case 1: Y = value; return;
case 2: Z = value; return;
}
throw new IndexOutOfRangeException();
}
}
public float Length
{
get { return (float)Math.Sqrt(X * X + Y * Y + Z * Z); }
}
public void Normalize()
{
this /= Length;
}
public float Dot(Vector3 Right)
{
return X * Right.X + Y * Right.Y + Z * Right.Z;
}
public Vector3 Cross(Vector3 Right)
{
return new Vector3(Y * Right.Z - Right.Y * Z, Z * Right.X - Right.Z * X, X * Right.Y - Right.X * Y);
}
public float Angle(Vector3 Right)
{
return (float)System.Math.Acos(Dot(Right) / (Length * Right.Length));
}
public static Vector3 operator +(Vector3 Left, Vector3 Right)
{
return new Vector3(Left.X + Right.X, Left.Y + Right.Y, Left.Z + Right.Z);
}
public static Vector3 operator +(Vector3 Left, float Right)
{
return new Vector3(Left.X + Right, Left.Y + Right, Left.Z + Right);
}
public static Vector3 operator -(Vector3 Left, Vector3 Right)
{
return new Vector3(Left.X - Right.X, Left.Y - Right.Y, Left.Z - Right.Z);
}
public static Vector3 operator -(Vector3 Left, float Right)
{
return new Vector3(Left.X - Right, Left.Y - Right, Left.Z - Right);
}
public static Vector3 operator -(Vector3 Left)
{
return new Vector3(-Left.X, -Left.Y, -Left.Z);
}
public static Vector3 operator *(Vector3 Left, Vector3 Right)
{
return new Vector3(Left.X * Right.X, Left.Y * Right.Y, Left.Z * Right.Z);
}
public static Vector3 operator *(Vector3 Left, float Right)
{
return new Vector3(Left.X * Right, Left.Y * Right, Left.Z * Right);
}
public static Vector3 operator *(float Left, Vector3 Right)
{
return new Vector3(Left * Right.X, Left * Right.Y, Left * Right.Z);
}
public static Vector3 operator /(Vector3 Left, float Right)
{
return new Vector3(Left.X / Right, Left.Y / Right, Left.Z / Right);
}
public static bool operator ==(Vector3 Left, Vector3 Right)
{
return Left.Equals(Right);
}
public static bool operator !=(Vector3 Left, Vector3 Right)
{
return !Left.Equals(Right);
}
public override bool Equals(object obj)
{
if (!(obj is Vector3)) return false;
Vector3 vec = (Vector3)obj;
return vec.X == X && vec.Y == Y && vec.Z == Z;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
}

View File

@ -0,0 +1,145 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LibEveryFileExplorer.Collections
{
public struct Vector4
{
public Vector4(float Value)
: this(Value, Value, Value, Value) { }
public Vector4(Vector2 Vector, float Z, float W)
: this(Vector.X, Vector.Y, Z, W) { }
public Vector4(Vector2 Vector1, Vector2 Vector2)
: this(Vector1.X, Vector1.Y, Vector2.X, Vector2.Y) { }
public Vector4(Vector3 Vector, float W)
: this(Vector.X, Vector.Y, Vector.Z, W) { }
public Vector4(float X, float Y, float Z, float W)
{
x = X;
y = Y;
z = Z;
w = W;
}
private float x, y, z, w;
public float X { get { return x; } set { x = value; } }
public float Y { get { return y; } set { y = value; } }
public float Z { get { return z; } set { z = value; } }
public float W { get { return w; } set { w = value; } }
public float this[int index]
{
get
{
switch (index)
{
case 0: return X;
case 1: return Y;
case 2: return Z;
case 3: return W;
}
throw new IndexOutOfRangeException();
}
set
{
switch (index)
{
case 0: X = value; return;
case 1: Y = value; return;
case 2: Z = value; return;
case 3: W = value; return;
}
throw new IndexOutOfRangeException();
}
}
public float Length
{
get { return (float)Math.Sqrt(X * X + Y * Y + Z * Z + W * W); }
}
public void Normalize()
{
this /= Length;
}
public float Dot(Vector4 Right)
{
return X * Right.X + Y * Right.Y + Z * Right.Z;
}
public static Vector4 operator +(Vector4 Left, Vector4 Right)
{
return new Vector4(Left.X + Right.X, Left.Y + Right.Y, Left.Z + Right.Z, Left.W + Right.W);
}
public static Vector4 operator +(Vector4 Left, float Right)
{
return new Vector4(Left.X + Right, Left.Y + Right, Left.Z + Right, Left.W + Right);
}
public static Vector4 operator -(Vector4 Left, Vector4 Right)
{
return new Vector4(Left.X - Right.X, Left.Y - Right.Y, Left.Z - Right.Z, Left.W - Right.W);
}
public static Vector4 operator -(Vector4 Left, float Right)
{
return new Vector4(Left.X - Right, Left.Y - Right, Left.Z - Right, Left.W - Right);
}
public static Vector4 operator -(Vector4 Left)
{
return new Vector4(-Left.X, -Left.Y, -Left.Z, - Left.W);
}
public static Vector4 operator *(Vector4 Left, Vector4 Right)
{
return new Vector4(Left.X * Right.X, Left.Y * Right.Y, Left.Z * Right.Z, Left.W * Right.W);
}
public static Vector4 operator *(Vector4 Left, float Right)
{
return new Vector4(Left.X * Right, Left.Y * Right, Left.Z * Right, Left.W * Right);
}
public static Vector4 operator *(float Left, Vector4 Right)
{
return new Vector4(Left * Right.X, Left * Right.Y, Left * Right.Z, Left * Right.W);
}
public static Vector4 operator /(Vector4 Left, float Right)
{
return new Vector4(Left.X / Right, Left.Y / Right, Left.Z / Right, Left.W / Right);
}
public static bool operator ==(Vector4 Left, Vector4 Right)
{
return Left.Equals(Right);
}
public static bool operator !=(Vector4 Left, Vector4 Right)
{
return !Left.Equals(Right);
}
public override bool Equals(object obj)
{
if (!(obj is Vector4)) return false;
Vector4 vec = (Vector4)obj;
return vec.X == X && vec.Y == Y && vec.Z == Z && vec.W == W;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
}

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LibEveryFileExplorer.Compression
{
public interface CompressionFormatBase
{
byte[] Decompress(byte[] Data);
}
public abstract class CompressionFormat<T> : CompressionFormatBase where T : CompressionFormatIdentifier, new()
{
private static T _identifier = new T();
public static T Identifier { get { return _identifier; } }
public abstract byte[] Decompress(byte[] Data);
}
public abstract class CompressionFormatIdentifier
{
public abstract String GetCompressionDescription();
public abstract bool IsFormat(byte[] Data);
}
}

Some files were not shown because too many files have changed in this diff Show More