internal static void Read(ResFileSwitchLoader loader, ShapeAnim shapeAnim) { if (loader.ResFile.VersionMajor2 == 9) { shapeAnim.Flags = (ShapeAnimFlags)loader.ReadUInt32(); } else { loader.LoadHeaderBlock(); } shapeAnim.Name = loader.LoadString(); shapeAnim.Path = loader.LoadString(); shapeAnim.BindModel = loader.Load <Model>(); uint BindIndicesOffset = loader.ReadOffset(); uint VertexShapeAnimsArrayOffset = loader.ReadOffset(); shapeAnim.UserData = loader.LoadDictValues <UserData>(); if (loader.ResFile.VersionMajor2 < 9) { shapeAnim.Flags = (ShapeAnimFlags)loader.ReadInt16(); } ushort numUserData = loader.ReadUInt16(); ushort numVertexShapeAnim = loader.ReadUInt16(); ushort numKeyShapeAnim = loader.ReadUInt16(); shapeAnim.FrameCount = loader.ReadInt32(); shapeAnim.BakedSize = loader.ReadUInt32(); ushort numCurve = loader.ReadUInt16(); shapeAnim.BindIndices = loader.LoadCustom(() => loader.ReadUInt16s(numVertexShapeAnim), BindIndicesOffset); shapeAnim.VertexShapeAnims = loader.LoadList <VertexShapeAnim>(numVertexShapeAnim, VertexShapeAnimsArrayOffset); }
internal static void Read(ResFileSwitchLoader loader, Model model) { if (loader.ResFile.VersionMajor2 == 9) { model.Flags = loader.ReadUInt32(); } else { loader.LoadHeaderBlock(); } model.Name = loader.LoadString(); model.Path = loader.LoadString(); model.Skeleton = loader.Load <Skeleton>(); long VertexArrayOffset = loader.ReadOffset(); model.Shapes = loader.LoadDictValues <Shape>(); long materialValuesOffset = loader.ReadOffset(); if (loader.ResFile.VersionMajor2 == 9) { loader.ReadOffset(); //padding? } long materialDictOffset = loader.ReadOffset(); model.Materials = loader.LoadDictValues <Material>(materialDictOffset, materialValuesOffset); model.UserData = loader.LoadDictValues <UserData>(); long UserPointer = loader.ReadOffset(); ushort numVertexBuffer = loader.ReadUInt16(); ushort numShape = loader.ReadUInt16(); ushort numMaterial = loader.ReadUInt16(); ushort numUserData = 0; if (loader.ResFile.VersionMajor2 == 9) { loader.ReadUInt16(); //padding? numUserData = loader.ReadUInt16(); loader.ReadUInt16(); //padding? uint padding = loader.ReadUInt32(); } else { numUserData = loader.ReadUInt16(); uint totalVertexCount = loader.ReadUInt32(); uint padding = loader.ReadUInt32(); } model.VertexBuffers = loader.LoadList <VertexBuffer>(numVertexBuffer, (uint)VertexArrayOffset); }
public static void Read(ResFileSwitchLoader loader, LightAnim lightAnim) { if (loader.ResFile.VersionMajor2 == 9) { lightAnim.Flags = loader.ReadEnum <LightAnimFlags>(true); loader.Seek(2); } else { loader.LoadHeaderBlock(); } lightAnim.Name = loader.LoadString(); long CurveArrayOffset = loader.ReadInt64(); lightAnim.BaseData = loader.LoadCustom(() => new LightAnimData(loader, lightAnim.AnimatedFields)); lightAnim.UserData = loader.LoadDictValues <UserData>(); lightAnim.LightTypeName = loader.LoadString(); lightAnim.DistanceAttnFuncName = loader.LoadString(); lightAnim.AngleAttnFuncName = loader.LoadString(); ushort numUserData = 0; byte numCurve = 0; if (loader.ResFile.VersionMajor2 == 9) { lightAnim.FrameCount = loader.ReadInt32(); numCurve = loader.ReadByte(); lightAnim.LightTypeIndex = loader.ReadSByte(); lightAnim.DistanceAttnFuncIndex = loader.ReadSByte(); lightAnim.AngleAttnFuncIndex = loader.ReadSByte(); lightAnim.BakedSize = loader.ReadUInt32(); numUserData = loader.ReadUInt16(); loader.Seek(2); } else { lightAnim.Flags = loader.ReadEnum <LightAnimFlags>(true); numUserData = loader.ReadUInt16(); lightAnim.FrameCount = loader.ReadInt32(); numCurve = loader.ReadByte(); lightAnim.LightTypeIndex = loader.ReadSByte(); lightAnim.DistanceAttnFuncIndex = loader.ReadSByte(); lightAnim.AngleAttnFuncIndex = loader.ReadSByte(); lightAnim.BakedSize = loader.ReadUInt32(); } lightAnim.Curves = loader.LoadList <AnimCurve>(numCurve); }
public static void Read(ResFileSwitchLoader loader, VisibilityAnim visibilityAnim) { if (loader.ResFile.VersionMajor2 == 9) { visibilityAnim._flags = loader.ReadUInt16(); loader.ReadUInt16(); //Padding } else { loader.LoadHeaderBlock(); } visibilityAnim.Name = loader.LoadString(); visibilityAnim.Path = loader.LoadString(); visibilityAnim.BindModel = loader.Load <Model>(); long BindIndicesOffset = loader.ReadInt64(); long CurveArrayOffset = loader.ReadInt64(); long BaseDataArrayOffset = loader.ReadInt64(); long NameArrayOffset = loader.ReadInt64(); visibilityAnim.UserData = loader.LoadDictValues <UserData>(); if (loader.ResFile.VersionMajor2 != 9) { visibilityAnim._flags = loader.ReadUInt16(); } else { loader.ReadUInt16(); //Idk what this is } ushort numUserData = loader.ReadUInt16(); visibilityAnim.FrameCount = loader.ReadInt32(); ushort numAnim = loader.ReadUInt16(); ushort numCurve = loader.ReadUInt16(); visibilityAnim.BakedSize = loader.ReadUInt32(); visibilityAnim.BindIndices = loader.LoadCustom(() => loader.ReadUInt16s(numAnim), (uint)BindIndicesOffset); visibilityAnim.Names = loader.LoadCustom(() => loader.LoadStrings(numAnim), (uint)NameArrayOffset); // Offset to name list. visibilityAnim.Curves = loader.LoadList <AnimCurve>(numCurve, (uint)CurveArrayOffset); visibilityAnim.baseDataBytes = new List <byte>(); visibilityAnim.BaseDataList = loader.LoadCustom(() => { bool[] baseData = new bool[numAnim]; int i = 0; while (i < numAnim) { byte b = loader.ReadByte(); visibilityAnim.baseDataBytes.Add(b); for (int j = 0; j < 8 && i < numAnim; j++) { baseData[i] = b.GetBit(j); } i++; } return(baseData); }, (uint)BaseDataArrayOffset); }
public static void Read(ResFileSwitchLoader loader, CameraAnim cameraAnim) { if (loader.ResFile.VersionMajor2 == 9) { cameraAnim.Flags = loader.ReadEnum <CameraAnimFlags>(true); loader.Seek(2); } else { loader.LoadHeaderBlock(); } cameraAnim.Name = loader.LoadString(); long CurveArrayOffset = loader.ReadInt64(); cameraAnim.BaseData = loader.LoadCustom(() => new CameraAnimData(loader)); cameraAnim.UserData = loader.LoadDictValues <UserData>(); byte numCurve = 0; if (loader.ResFile.VersionMajor2 == 9) { cameraAnim.FrameCount = loader.ReadInt32(); cameraAnim.BakedSize = loader.ReadUInt32(); ushort numUserData = loader.ReadUInt16(); numCurve = loader.ReadByte(); loader.Seek(1); loader.Seek(4); } else { cameraAnim.Flags = loader.ReadEnum <CameraAnimFlags>(true); loader.Seek(2); cameraAnim.FrameCount = loader.ReadInt32(); numCurve = loader.ReadByte(); loader.Seek(1); ushort numUserData = loader.ReadUInt16(); cameraAnim.BakedSize = loader.ReadUInt32(); } cameraAnim.Curves = loader.LoadList <AnimCurve>(numCurve, (uint)CurveArrayOffset); }
internal static void Read(ResFileSwitchLoader loader, SceneAnim sceneAnim) { if (loader.ResFile.VersionMajor2 == 9) { sceneAnim.Flags = loader.ReadUInt32(); } else { loader.LoadHeaderBlock(); } sceneAnim.Name = loader.LoadString(); sceneAnim.Path = loader.LoadString(); sceneAnim.CameraAnims = loader.LoadDictValues <CameraAnim>(); sceneAnim.LightAnims = loader.LoadDictValues <LightAnim>(); sceneAnim.FogAnims = loader.LoadDictValues <FogAnim>(); sceneAnim.UserData = loader.LoadDictValues <UserData>(); ushort numUserData = loader.ReadUInt16(); ushort numCameraAnim = loader.ReadUInt16(); ushort numLightAnim = loader.ReadUInt16(); ushort numFogAnim = loader.ReadUInt16(); }
public static void Load(ResFileSwitchLoader loader, VertexBuffer vertexBuffer) { if (loader.ResFile.VersionMajor2 == 9) { vertexBuffer.Flags = loader.ReadUInt32(); } else { loader.LoadHeaderBlock(); } vertexBuffer.Attributes = loader.LoadDictValues <VertexAttrib>(); vertexBuffer.MemoryPool = loader.Load <MemoryPool>(); long unk = loader.ReadOffset(); if (loader.ResFile.VersionMajor2 > 2 || loader.ResFile.VersionMajor > 0) { loader.ReadOffset();// unk2 } long VertexBufferSizeOffset = loader.ReadOffset(); long VertexStrideSizeOffset = loader.ReadOffset(); long padding = loader.ReadInt64(); int BufferOffset = loader.ReadInt32(); byte numVertexAttrib = loader.ReadByte(); byte numBuffer = loader.ReadByte(); ushort Idx = loader.ReadUInt16(); uint vertexCount = loader.ReadUInt32(); vertexBuffer.VertexSkinCount = (byte)loader.ReadUInt32(); //Buffers use the index buffer offset from memory info section //This goes to a section in the memory pool which stores all the buffer data, including faces //To obtain a list of all the buffer data, it would be by the index buffer offset + BufferOffset var StrideArray = loader.LoadList <VertexBufferStride>(numBuffer, (uint)VertexStrideSizeOffset); var VertexBufferSizeArray = loader.LoadList <VertexBufferSize>(numBuffer, (uint)VertexBufferSizeOffset); vertexBuffer.Buffers = new List <Buffer>(); for (int buff = 0; buff < numBuffer; buff++) { Buffer data = new Buffer(); data.Flags = VertexBufferSizeArray[buff].GpuAccessFlags; data.Stride = (ushort)StrideArray[buff].Stride; uint size = VertexBufferSizeArray[buff].Size; if (buff == 0) { data.BufferOffset = ((int)BufferInfo.BufferOffset + BufferOffset); } if (buff > 0) { data.BufferOffset = vertexBuffer.Buffers[buff - 1].BufferOffset + vertexBuffer.Buffers[buff - 1].Size; } if (data.BufferOffset % 8 != 0) { data.BufferOffset = data.BufferOffset + (8 - (data.BufferOffset % 8)); } data.Data = new byte[1][]; data.Data[0] = loader.LoadCustom(() => //Load buffer data from mem block { return(loader.ReadBytes((int)size)); }, (uint)data.BufferOffset); vertexBuffer.Buffers.Add(data); } }
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); } } }
public static void Read(ResFileSwitchLoader loader, VisibilityAnim visibilityAnim) { if (loader.ResFile.VersionMajor2 == 9) { visibilityAnim._flags = loader.ReadUInt16(); loader.ReadUInt16(); //Padding } else { loader.LoadHeaderBlock(); } visibilityAnim.Name = loader.LoadString(); visibilityAnim.Path = loader.LoadString(); visibilityAnim.BindModel = loader.Load <Model>(); long BindIndicesOffset = loader.ReadInt64(); long CurveArrayOffset = loader.ReadInt64(); long BaseDataArrayOffset = loader.ReadInt64(); long NameArrayOffset = loader.ReadInt64(); visibilityAnim.UserData = loader.LoadDictValues <UserData>(); if (loader.ResFile.VersionMajor2 != 9) { visibilityAnim._flags = loader.ReadUInt16(); } else { loader.ReadUInt16(); //Idk what this is } ushort numUserData = loader.ReadUInt16(); visibilityAnim.FrameCount = loader.ReadInt32(); ushort numAnim = loader.ReadUInt16(); ushort numCurve = loader.ReadUInt16(); visibilityAnim.BakedSize = loader.ReadUInt32(); visibilityAnim.BindIndices = loader.LoadCustom(() => loader.ReadUInt16s(numAnim), (uint)BindIndicesOffset); visibilityAnim.Names = loader.LoadCustom(() => loader.LoadStrings(numAnim), (uint)NameArrayOffset); // Offset to name list. visibilityAnim.Curves = loader.LoadList <AnimCurve>(numCurve, (uint)CurveArrayOffset); visibilityAnim.baseDataBytes = new List <byte>(); visibilityAnim.BaseDataList = loader.LoadCustom(() => { bool[] baseData = new bool[numAnim]; int keyIndex = 0; for (int i = 0; i < numAnim; i++) { if (numAnim <= keyIndex) { break; } int value = loader.ReadInt32(); //Bit shift each key value for (int j = 0; j < 32; j++) { if (numAnim <= keyIndex) { break; } bool set = (value & 0x1) != 0; value >>= 1; baseData[keyIndex] = set; keyIndex++; } } return(baseData); }, (uint)BaseDataArrayOffset); }
public static void Load(ResFileSwitchLoader loader, Material mat) { if (loader.ResFile.VersionMajor2 == 9) { mat.Flags = loader.ReadEnum <MaterialFlags>(true); } else { loader.LoadHeaderBlock(); } mat.Name = loader.LoadString(); mat.RenderInfos = loader.LoadDictValues <RenderInfo>(); mat.ShaderAssign = loader.Load <ShaderAssign>(); long TextureArrayOffset = loader.ReadInt64(); long TextureNameArray = loader.ReadInt64(); long SamplerArrayOffset = loader.ReadInt64(); mat.Samplers = loader.LoadDictValues <Sampler>(); mat.ShaderParams = loader.LoadDictValues <ShaderParam>(); long SourceParamOffset = loader.ReadInt64(); mat.UserData = loader.LoadDictValues <UserData>(); long VolatileFlagsOffset = loader.ReadInt64(); long userPointer = loader.ReadInt64(); long SamplerSlotArrayOffset = loader.ReadInt64(); long TexSlotArrayOffset = loader.ReadInt64(); if (loader.ResFile.VersionMajor2 != 9) { mat.Flags = loader.ReadEnum <MaterialFlags>(true); } ushort idx = loader.ReadUInt16(); ushort numRenderInfo = loader.ReadUInt16(); byte numTextureRef = loader.ReadByte(); byte numSampler = loader.ReadByte(); ushort numShaderParam = loader.ReadUInt16(); ushort numShaderParamVolatile = loader.ReadUInt16(); ushort sizParamSource = loader.ReadUInt16(); ushort sizParamRaw = loader.ReadUInt16(); ushort numUserData = loader.ReadUInt16(); if (loader.ResFile.VersionMajor2 != 9) { loader.ReadUInt32(); //Padding } var textures = loader.LoadCustom(() => loader.LoadStrings(numTextureRef), (uint)TextureNameArray); mat.TextureRefs = new List <TextureRef>(); if (textures != null) { foreach (var tex in textures) { mat.TextureRefs.Add(new TextureRef() { Name = tex }); } } //Add names to the value as switch does not store any foreach (var sampler in mat.Samplers) { sampler.Value.Name = sampler.Key; } mat.ShaderParamData = loader.LoadCustom(() => loader.ReadBytes(sizParamSource), (uint)SourceParamOffset); mat.VolatileFlags = loader.LoadCustom(() => loader.ReadBytes((int)Math.Ceiling(numShaderParam / 8f)), (uint)VolatileFlagsOffset); mat.TextureSlotArray = loader.LoadCustom(() => loader.ReadInt64s(numTextureRef), (uint)SamplerSlotArrayOffset); mat.SamplerSlotArray = loader.LoadCustom(() => loader.ReadInt64s(numSampler), (uint)TexSlotArrayOffset); }