public static void Load(ResFileLoader loader, ResFile resFile) { loader.CheckSignature("FRES"); resFile.Version = loader.ReadUInt32(); resFile.SetVersionInfo(resFile.Version); resFile.ByteOrder = loader.ReadByteOrder(); ushort sizHeader = loader.ReadUInt16(); uint sizFile = loader.ReadUInt32(); resFile.Alignment = loader.ReadUInt32(); resFile.Name = loader.LoadString(); uint sizStringPool = loader.ReadUInt32(); uint ofsStringPool = loader.ReadOffset(); resFile.Models = loader.LoadDict <Model>(); var textures = loader.LoadDict <Texture>(); resFile.SkeletalAnims = loader.LoadDict <SkeletalAnim>(); resFile.ShaderParamAnims = loader.LoadDict <MaterialAnim>(); resFile.ColorAnims = loader.LoadDict <MaterialAnim>(); resFile.TexSrtAnims = loader.LoadDict <MaterialAnim>(); resFile.TexPatternAnims = loader.LoadDict <MaterialAnim>(); resFile.BoneVisibilityAnims = loader.LoadDict <VisibilityAnim>(); loader.LoadDict <VisibilityAnim>(); resFile.ShapeAnims = loader.LoadDict <ShapeAnim>(); resFile.Textures = new ResDict <TextureShared>(); foreach (var tex in textures) { resFile.Textures.Add(tex.Key, tex.Value); } if (loader.ResFile.Version >= 0x02040000) { resFile.SceneAnims = loader.LoadDict <SceneAnim>(); resFile.ExternalFiles = loader.LoadDict <ExternalFile>(); ushort numModel = loader.ReadUInt16(); ushort numTexture = loader.ReadUInt16(); ushort numSkeletalAnim = loader.ReadUInt16(); ushort numShaderParamAnim = loader.ReadUInt16(); ushort numColorAnim = loader.ReadUInt16(); ushort numTexSrtAnim = loader.ReadUInt16(); ushort numTexPatternAnim = loader.ReadUInt16(); ushort numBoneVisibilityAnim = loader.ReadUInt16(); ushort numMatVisibilityAnim = loader.ReadUInt16(); ushort numShapeAnim = loader.ReadUInt16(); ushort numSceneAnim = loader.ReadUInt16(); ushort numExternalFile = loader.ReadUInt16(); uint userPointer = loader.ReadUInt32(); } else //Note very old versions have no counts and is mostly unkown atm { uint userPointer = loader.ReadUInt32(); uint userPointer2 = loader.ReadUInt32(); resFile.SceneAnims = loader.LoadDict <SceneAnim>(); resFile.ExternalFiles = loader.LoadDict <ExternalFile>(); } }
private void ReadImportedFileHeader() { Seek(8, SeekOrigin.Begin); uint Version = ReadUInt32(); ushort ByteOrder = ReadUInt16(); ushort Alignment = ReadUInt16(); ResFile.SetVersionInfo(Version); ResFile.Alignment = Alignment; Seek(0x20, SeekOrigin.Begin); }
private void ReadImportedFileHeader() { this.ByteOrder = ByteOrder.BigEndian; Seek(8, SeekOrigin.Begin); //SUB MAGIC ResFile.Version = ReadUInt32(); ResFile.SetVersionInfo(ResFile.Version); string sectionMagic = ReadString(8, Encoding.ASCII); uint offset = ReadUInt32(); uint platformFlag = ReadUInt32(); ReadUInt32(); this.ByteOrder = ByteOrder.BigEndian; if (platformFlag != 0) { Seek(0x30, SeekOrigin.Begin); this.ByteOrder = ByteOrder.LittleEndian; } }
public static void Load(ResFileSwitchLoader loader, ResFile resFile) { loader.CheckSignature("FRES"); uint padding = loader.ReadUInt32(); resFile.Version = loader.ReadUInt32(); resFile.SetVersionInfo(resFile.Version); resFile.ByteOrder = loader.ReadByteOrder(); resFile.Alignment = loader.ReadByte(); resFile.TargetAddressSize = loader.ReadByte(); //Thanks MasterF0X for pointing out the layout of the these uint OffsetToFileName = loader.ReadUInt32(); resFile.Flag = loader.ReadUInt16(); resFile.BlockOffset = loader.ReadUInt16(); uint RelocationTableOffset = loader.ReadUInt32(); uint sizFile = loader.ReadUInt32(); resFile.Name = loader.LoadString(); long modelOffset = loader.ReadOffset(); long modelDictOffset = loader.ReadOffset(); if (loader.ResFile.VersionMajor2 == 9) { loader.ReadBytes(32); //reserved } resFile.SkeletalAnims = loader.LoadDictValues <SkeletalAnim>(); resFile.MaterialAnims = loader.LoadDictValues <MaterialAnim>(); resFile.BoneVisibilityAnims = loader.LoadDictValues <VisibilityAnim>(); resFile.ShapeAnims = loader.LoadDictValues <ShapeAnim>(); resFile.SceneAnims = loader.LoadDictValues <SceneAnim>(); resFile.MemoryPool = loader.Load <MemoryPool>(); resFile.BufferInfo = loader.Load <BufferInfo>(); resFile.ExternalFiles = loader.LoadDictValues <ExternalFile>(); long padding1 = loader.ReadInt64(); resFile.StringTable = loader.Load <StringTable>(); uint StringPoolSize = loader.ReadUInt32(); ushort numModel = loader.ReadUInt16(); //Read models after buffer data resFile.Models = loader.LoadDictValues <Model>(modelDictOffset, modelOffset); if (loader.ResFile.VersionMajor2 == 9) { //Count for 2 new sections ushort unkCount = loader.ReadUInt16(); ushort unk2Count = loader.ReadUInt16(); if (unkCount != 0) { throw new System.Exception("unk1 has section!"); } if (unk2Count != 0) { throw new System.Exception("unk2 has section!"); } } ushort numSkeletalAnim = loader.ReadUInt16(); ushort numMaterialAnim = loader.ReadUInt16(); ushort numBoneVisibilityAnim = loader.ReadUInt16(); ushort numShapeAnim = loader.ReadUInt16(); ushort numSceneAnim = loader.ReadUInt16(); ushort numExternalFile = loader.ReadUInt16(); uint padding2 = loader.ReadUInt16(); uint padding3 = loader.ReadUInt32(); resFile.Textures = new ResDict <TextureShared>(); foreach (var ext in resFile.ExternalFiles) { if (ext.Key.Contains(".bntx")) { BntxFile bntx = new BntxFile(new MemoryStream(ext.Value.Data)); ext.Value.LoadedFileData = bntx; foreach (var tex in bntx.Textures) { resFile.Textures.Add(tex.Name, new SwitchTexture(bntx, tex)); } } } resFile.TexPatternAnims = new ResDict <MaterialAnim>(); resFile.MatVisibilityAnims = new ResDict <MaterialAnim>(); resFile.ShaderParamAnims = new ResDict <MaterialAnim>(); resFile.ColorAnims = new ResDict <MaterialAnim>(); resFile.TexSrtAnims = new ResDict <MaterialAnim>(); //Split material animations into shader, texture, and visual animation lists foreach (var anim in resFile.MaterialAnims.Values) { if (anim.Name.Contains("_ftp")) { resFile.TexPatternAnims.Add(anim.Name, anim); } else if (anim.Name.Contains("_fts")) { resFile.ShaderParamAnims.Add(anim.Name, anim); } else if (anim.Name.Contains("_fcl")) { resFile.ColorAnims.Add(anim.Name, anim); } else if (anim.Name.Contains("_fst")) { resFile.TexSrtAnims.Add(anim.Name, anim); } else if (anim.Name.Contains("_fvt")) { resFile.MatVisibilityAnims.Add(anim.Name, anim); } else if (anim.MaterialAnimDataList != null && anim.MaterialAnimDataList.Any(x => x.VisibilyCount > 0)) { resFile.MatVisibilityAnims.Add(anim.Name, anim); } else if (anim.MaterialAnimDataList != null && anim.MaterialAnimDataList.Any(x => x.TexturePatternCount > 0)) { resFile.TexPatternAnims.Add(anim.Name, anim); } else { resFile.ShaderParamAnims.Add(anim.Name, anim); } } }