private static void ReadAnimsBG(GFPackage.Entry File, BinaryReader Reader, GFMotionPack MotPack) { if (File.Length < 0x80) { return; } Reader.BaseStream.Seek(File.Address, SeekOrigin.Begin); GFPackage.Header Header = GFPackage.GetPackageHeader(Reader.BaseStream); foreach (GFPackage.Entry Entry in Header.Entries) { if (Entry.Length < 4) { continue; } Reader.BaseStream.Seek(Entry.Address, SeekOrigin.Begin); uint MagicNum = Reader.ReadUInt32(); if (MagicNum == GFMotionConstant) { Reader.BaseStream.Seek(-4, SeekOrigin.Current); MotPack.Add(new GFMotion(Reader, MotPack.Count)); } } }
private static void ReadAnimsBG(GFPackage.Entry file, BinaryReader reader, GFMotionPack motPack) { if (file.Length < 0x80) { return; } reader.BaseStream.Seek(file.Address, SeekOrigin.Begin); var header = GFPackage.GetPackageHeader(reader.BaseStream); foreach (var entry in header.Entries) { if (entry.Length < 4) { continue; } reader.BaseStream.Seek(entry.Address, SeekOrigin.Begin); var magicNum = reader.ReadUInt32(); if (magicNum == GFMotionConstant) { reader.BaseStream.Seek(-4, SeekOrigin.Current); motPack.Add(new GFMotion(reader, motPack.Count)); } } }
public static H3D OpenAsH3D(Stream Input, GFPackage.Header Header) { H3D Output; //Model Input.Seek(Header.Entries[0].Address, SeekOrigin.Begin); GFModelPack MdlPack = new GFModelPack(Input); Output = MdlPack.ToH3D(); //Animations Input.Seek(Header.Entries[1].Address, SeekOrigin.Begin); GFMotionPack MotPack = new GFMotionPack(Input); Output.Merge(MotPack.ToH3D(MdlPack.Models[0].Skeleton)); //Texture if (Header.Entries.Length > 3 && Header.Entries[3].Length >= 4) { Input.Seek(Header.Entries[3].Address, SeekOrigin.Begin); BinaryReader Reader = new BinaryReader(Input); uint MagicNum = Reader.ReadUInt32(); if (MagicNum == 0x15041213) { Input.Seek(-4, SeekOrigin.Current); GFTexture Tex = new GFTexture(Reader); Output.Textures.Add(Tex.ToH3DTexture()); } } return(Output); }
public static H3D OpenAsH3D(Stream Input, GFPackage.Header Header, H3DDict <H3DBone> Skeleton = null) { BinaryReader Reader = new BinaryReader(Input); GFModelPack MdlPack = new GFModelPack(); GFMotionPack MotPack = new GFMotionPack(); ReadModelsBG(Header.Entries[0], Reader, MdlPack); //Textures ReadModelsBG(Header.Entries[1], Reader, MdlPack); //Shaders ReadModelsBG(Header.Entries[2], Reader, MdlPack); //Models ReadModelsBG(Header.Entries[3], Reader, MdlPack); //Models? ReadModelsBG(Header.Entries[4], Reader, MdlPack); //More models ReadAnimsBG(Header.Entries[5], Reader, MotPack); //Animations ReadAnimsBG(Header.Entries[6], Reader, MotPack); //More animations H3D Output = MdlPack.ToH3D(); foreach (GFMotion Mot in MotPack) { H3DMaterialAnim MatAnim = Mot.ToH3DMaterialAnimation(); H3DAnimation VisAnim = Mot.ToH3DVisibilityAnimation(); if (MatAnim != null) { MatAnim.Name = $"Motion_{Mot.Index}"; Output.MaterialAnimations.Add(MatAnim); } if (VisAnim != null) { VisAnim.Name = $"Motion_{Mot.Index}"; Output.VisibilityAnimations.Add(VisAnim); } } return(Output); }
public static H3D OpenAsH3D(Stream input, GFPackage.Header header, H3DDict <H3DBone> skeleton = null) { var reader = new BinaryReader(input); var mdlPack = new GFModelPack(); var motPack = new GFMotionPack(); ReadModelsBG(header.Entries[0], reader, mdlPack); //Textures ReadModelsBG(header.Entries[1], reader, mdlPack); //Shaders ReadModelsBG(header.Entries[2], reader, mdlPack); //Models ReadModelsBG(header.Entries[3], reader, mdlPack); //Models? ReadModelsBG(header.Entries[4], reader, mdlPack); //More models ReadAnimsBG(header.Entries[5], reader, motPack); //Animations ReadAnimsBG(header.Entries[6], reader, motPack); //More animations var output = mdlPack.ToH3D(); foreach (var mot in motPack) { var matAnim = mot.ToH3DMaterialAnimation(); var visAnim = mot.ToH3DVisibilityAnimation(); if (matAnim != null) { matAnim.Name = $"Motion_{mot.Index}"; output.MaterialAnimations.Add(matAnim); } if (visAnim != null) { visAnim.Name = $"Motion_{mot.Index}"; output.VisibilityAnimations.Add(visAnim); } } return(output); }
public static H3D OpenAsH3D(Stream Input, GFPackage.Header Header) { H3D Output; //Model Input.Seek(Header.Entries[0].Address, SeekOrigin.Begin); GFModelPack MdlPack = new GFModelPack(Input); Output = MdlPack.ToH3D(); //Animations Input.Seek(Header.Entries[1].Address, SeekOrigin.Begin); GFMotionPack MotPack = new GFMotionPack(Input); foreach (GFMotion Mot in MotPack) { H3DAnimation SklAnim = Mot.ToH3DSkeletalAnimation(MdlPack.Models[0].Skeleton); H3DMaterialAnim MatAnim = Mot.ToH3DMaterialAnimation(); H3DAnimation VisAnim = Mot.ToH3DVisibilityAnimation(); if (SklAnim != null) { SklAnim.Name = $"Motion_{Mot.Index}"; Output.SkeletalAnimations.Add(SklAnim); } if (MatAnim != null) { MatAnim.Name = $"Motion_{Mot.Index}"; Output.MaterialAnimations.Add(MatAnim); } if (VisAnim != null) { VisAnim.Name = $"Motion_{Mot.Index}"; Output.VisibilityAnimations.Add(VisAnim); } } //Texture if (Header.Entries.Length > 3 && Header.Entries[3].Length >= 4) { Input.Seek(Header.Entries[3].Address, SeekOrigin.Begin); BinaryReader Reader = new BinaryReader(Input); uint MagicNum = Reader.ReadUInt32(); if (MagicNum == 0x15041213) { Input.Seek(-4, SeekOrigin.Current); GFTexture Tex = new GFTexture(Reader); Output.Textures.Add(Tex.ToH3DTexture()); } } return(Output); }
public static H3D IdentifyByMagic(Stream Stream, H3DDict <H3DBone> Skeleton, string FileName) { H3D Output = null; if (Stream.Length > 4) { BinaryReader Reader = new BinaryReader(Stream); uint MagicNum = Reader.ReadUInt32(); Stream.Seek(-4, SeekOrigin.Current); string Magic = Encoding.ASCII.GetString(Reader.ReadBytes(4)); Stream.Seek(0, SeekOrigin.Begin); if (Magic.StartsWith("BCH")) { return(H3D.Open(Reader.ReadBytes((int)Stream.Length))); } else if (Magic.StartsWith("MOD") && FileName != null) { return(LoadMTModel(Reader, FileName, Path.GetDirectoryName(FileName))); } else if (Magic.StartsWith("TEX") && FileName != null) { return(new MTTexture(Reader, Path.GetFileNameWithoutExtension(FileName)).ToH3D()); } else if (Magic.StartsWith("MFX")) { MTShader = new MTShaderEffects(Reader); } else if (Magic.StartsWith("CGFX")) { return(Gfx.Open(Stream)); } else if (Magic.StartsWith("CMIF")) { return(new CMIFFile(Stream).ToH3D()); } else { switch (MagicNum) { case GFModel.MagicNum: GFModel Model = new GFModel(Reader, "Model"); Output = Model.ToH3D(); Output.SourceData.Add(Model); break; case GFTexture.MagicNum: //Can be GFShader or GFTexture Reader.BaseStream.Seek(0x8, SeekOrigin.Current); string GFMagicStr = StringUtils.ReadPaddedString(Reader, 8); if (GFMagicStr == GFTexture.MagicStr) { Reader.BaseStream.Seek(-0x10, SeekOrigin.Current); Output = new H3D(); Output.Textures.Add(new GFTexture(Reader).ToH3DTexture()); } else { Reader.BaseStream.Seek(0x8, SeekOrigin.Current); GFMagicStr = StringUtils.ReadPaddedString(Reader, 8); if (GFMagicStr == GFShader.MagicStr) { Reader.BaseStream.Seek(-0x18, SeekOrigin.Current); Output = new H3D(); Output.SourceData.Add(new GFShader(Reader)); } } break; case GFModelPack.MagicNum: if (GFModelPack.IsModelPack(Reader)) { Output = new GFModelPack(Reader).ToH3D(); } break; case GFMotion.MagicNum: if (Skeleton != null) { Output = new H3D(); GFMotion Motion = new GFMotion(Reader, 0); H3DAnimation SklAnim = Motion.ToH3DSkeletalAnimation(Skeleton); H3DMaterialAnim MatAnim = Motion.ToH3DMaterialAnimation(); H3DAnimation VisAnim = Motion.ToH3DVisibilityAnimation(); if (SklAnim != null) { Output.SkeletalAnimations.Add(SklAnim); } if (MatAnim != null) { Output.MaterialAnimations.Add(MatAnim); } if (VisAnim != null) { Output.VisibilityAnimations.Add(VisAnim); } } break; } if (GFMotionPack.IsGFL2MotionPack(Reader)) { GFMotionPack Pack = new GFMotionPack(Reader); Output = Pack.ToH3D(Skeleton); } if (GF1MotionPack.IsGFL1MotionPack(Reader)) { Output = new GF1MotionPack(Reader).ToH3D(Skeleton); } } } return(Output); }
public static H3D OpenAsH3D(Stream input, GFPackage.Header header) { var output = default(H3D); //Model input.Seek(header.Entries[0].Address, SeekOrigin.Begin); var mdlPack = new GFModelPack(input); output = mdlPack.ToH3D(); //Animations input.Seek(header.Entries[1].Address, SeekOrigin.Begin); var motPack = new GFMotionPack(input); foreach (var mot in motPack) { var sklAnim = mot.ToH3DSkeletalAnimation(mdlPack.Models[0].Skeleton); var matAnim = mot.ToH3DMaterialAnimation(); var visAnim = mot.ToH3DVisibilityAnimation(); if (sklAnim != null) { sklAnim.Name = $"Motion_{mot.Index}"; output.SkeletalAnimations.Add(sklAnim); } if (matAnim != null) { matAnim.Name = $"Motion_{mot.Index}"; output.MaterialAnimations.Add(matAnim); } if (visAnim != null) { visAnim.Name = $"Motion_{mot.Index}"; output.VisibilityAnimations.Add(visAnim); } } //Texture if (header.Entries.Length > 3 && header.Entries[3].Length >= 4) { input.Seek(header.Entries[3].Address, SeekOrigin.Begin); var reader = new BinaryReader(input); var magicNum = reader.ReadUInt32(); if (magicNum == 0x15041213) { input.Seek(-4, SeekOrigin.Current); var tex = new GFTexture(reader); output.Textures.Add(tex.ToH3DTexture()); } } return(output); }