// ---- METHODS ------------------------------------------------------------------------------------------------ void IResData.Load(ResFileLoader loader) { loader.CheckSignature(_signature); if (loader.IsSwitch) { Switch.VisibilityAnimParser.Read((Switch.Core.ResFileSwitchLoader)loader, this); } else { Name = loader.LoadString(); Path = loader.LoadString(); _flags = loader.ReadUInt16(); ushort numAnim = 0; ushort numCurve = 0; if (loader.ResFile.Version >= 0x03040000) { ushort numUserData = loader.ReadUInt16(); FrameCount = loader.ReadInt32(); numAnim = loader.ReadUInt16(); numCurve = loader.ReadUInt16(); BakedSize = loader.ReadUInt32(); } else { FrameCount = loader.ReadInt16(); numAnim = loader.ReadUInt16(); numCurve = loader.ReadUInt16(); ushort numUserData = loader.ReadUInt16(); BakedSize = loader.ReadUInt32(); int padding2 = loader.ReadInt16(); } BindModel = loader.Load <Model>(); BindIndices = loader.LoadCustom(() => loader.ReadUInt16s(numAnim)); Names = loader.LoadCustom(() => loader.LoadStrings(numAnim)); // Offset to name list. Curves = loader.LoadList <AnimCurve>(numCurve); baseDataBytes = new List <byte>(); BaseDataList = loader.LoadCustom(() => { bool[] baseData = new bool[numAnim]; int i = 0; while (i < numAnim) { byte b = loader.ReadByte(); baseDataBytes.Add(b); for (int j = 0; j < 8 && i < numAnim; j++) { baseData[i] = b.GetBit(j); } i++; } return(baseData); }); UserData = loader.LoadDict <UserData>(); } }
// ---- METHODS ------------------------------------------------------------------------------------------------ void IResData.Load(ResFileLoader loader) { Name = loader.LoadString(); ushort idx = loader.ReadUInt16(); ParentIndex = loader.ReadUInt16(); SmoothMatrixIndex = loader.ReadInt16(); RigidMatrixIndex = loader.ReadInt16(); BillboardIndex = loader.ReadUInt16(); ushort numUserData = loader.ReadUInt16(); _flags = loader.ReadUInt32(); Scale = loader.ReadVector3F(); Rotation = loader.ReadVector4F(); Position = loader.ReadVector3F(); UserData = loader.LoadDict <UserData>(); }
void IResData.Load(ResFileLoader loader) { if (loader.ResFile.Version >= 0x02040000) { loader.CheckSignature(_signature); Name = loader.LoadString(); Path = loader.LoadString(); Flags = loader.ReadEnum <ShaderParamAnimFlags>(true); ushort numMatAnim = 0; if (loader.ResFile.Version >= 0x03040000) { FrameCount = loader.ReadInt32(); numMatAnim = loader.ReadUInt16(); ushort numUserData = loader.ReadUInt16(); int numParamAnim = loader.ReadInt32(); int numCurve = loader.ReadInt32(); BakedSize = loader.ReadUInt32(); } else { FrameCount = loader.ReadUInt16(); numMatAnim = loader.ReadUInt16(); unk = loader.ReadUInt32(); int numCurve = loader.ReadInt32(); BakedSize = loader.ReadUInt32(); int padding2 = loader.ReadInt32(); } BindModel = loader.Load <Model>(); BindIndices = loader.LoadCustom(() => loader.ReadUInt16s(numMatAnim)); ShaderParamMatAnims = loader.LoadList <ShaderParamMatAnim>(numMatAnim); UserData = loader.LoadDict <UserData>(); } else { Flags = loader.ReadEnum <ShaderParamAnimFlags>(true); FrameCount = loader.ReadInt16(); ushort numMatAnim = loader.ReadUInt16(); ushort numUserData = loader.ReadUInt16(); ushort unk = loader.ReadUInt16(); BakedSize = loader.ReadUInt32(); Name = loader.LoadString(); Path = loader.LoadString(); BindModel = loader.Load <Model>(); BindIndices = loader.LoadCustom(() => loader.ReadUInt16s(numMatAnim)); ShaderParamMatAnims = loader.LoadList <ShaderParamMatAnim>(numMatAnim); } }
// ---- METHODS ------------------------------------------------------------------------------------------------ void IResData.Load(ResFileLoader loader) { if (loader.IsSwitch) { Name = loader.LoadString(); UserData = loader.LoadDictValues <UserData>(); if (loader.ResFile.VersionMajor2 == 8 || loader.ResFile.VersionMajor2 == 9) { loader.Seek(16); } ushort idx = loader.ReadUInt16(); ParentIndex = loader.ReadInt16(); SmoothMatrixIndex = loader.ReadInt16(); RigidMatrixIndex = loader.ReadInt16(); BillboardIndex = loader.ReadInt16(); ushort numUserData = loader.ReadUInt16(); _flags = loader.ReadUInt32(); Scale = loader.ReadVector3F(); Rotation = loader.ReadVector4F(); Position = loader.ReadVector3F(); } else { Name = loader.LoadString(); ushort idx = loader.ReadUInt16(); ParentIndex = loader.ReadInt16(); SmoothMatrixIndex = loader.ReadInt16(); RigidMatrixIndex = loader.ReadInt16(); BillboardIndex = loader.ReadInt16(); ushort numUserData = loader.ReadUInt16(); _flags = loader.ReadUInt32(); Scale = loader.ReadVector3F(); Rotation = loader.ReadVector4F(); Position = loader.ReadVector3F(); UserData = loader.LoadDict <UserData>(); if (loader.ResFile.Version < 0x03040000) { InverseMatrix = loader.ReadMatrix3x4(); } } }
// ---- METHODS ------------------------------------------------------------------------------------------------ void IResData.Load(ResFileLoader loader) { if (loader.IsSwitch) { Name = loader.LoadString(); CurveIndex = loader.ReadInt16(); BeginConstant = loader.ReadUInt16(); SubBindIndex = loader.ReadSByte(); loader.Seek(3); //padding } else { CurveIndex = loader.ReadSByte(); SubBindIndex = loader.ReadSByte(); loader.Seek(2); Name = loader.LoadString(); } }
// ---- METHODS ------------------------------------------------------------------------------------------------ void IResData.Load(ResFileLoader loader) { signature = loader.ReadString(4, Encoding.ASCII); uint materialAnimOffset = 0; ushort materialCount = 0; if (signature == "FMAA") { if (loader.ResFile.VersionMajor2 == 9) { Flags = loader.ReadEnum <MaterialAnimFlags>(true); loader.ReadUInt16(); } else { ((Switch.Core.ResFileSwitchLoader)loader).LoadHeaderBlock(); } Name = loader.LoadString(); Path = loader.LoadString(); BindModel = loader.Load <Model>(true); uint BindIndicesOffset = loader.ReadOffset(); materialAnimOffset = loader.ReadOffset(); uint unk = loader.ReadOffset(); //Empty section. Maybe set at runtime uint TextureNameArrayOffset = loader.ReadOffset(); UserData = loader.LoadDictValues <UserData>(); uint TextureBindArrayOffset = loader.ReadOffset(); if (loader.ResFile.VersionMajor2 != 9) { Flags = loader.ReadEnum <MaterialAnimFlags>(true); } ushort numUserData = 0; ushort CurveCount = 0; if (loader.ResFile.VersionMajor2 == 9) { FrameCount = loader.ReadInt32(); BakedSize = loader.ReadUInt32(); numUserData = loader.ReadUInt16(); materialCount = loader.ReadUInt16(); CurveCount = loader.ReadUInt16(); } else { numUserData = loader.ReadUInt16(); materialCount = loader.ReadUInt16(); CurveCount = loader.ReadUInt16(); FrameCount = loader.ReadInt32(); BakedSize = loader.ReadUInt32(); } ushort ShaderParamAnimCount = loader.ReadUInt16(); ushort TexturePatternAnimCount = loader.ReadUInt16(); ushort VisabiltyAnimCount = loader.ReadUInt16(); ushort TextureCount = loader.ReadUInt16(); if (loader.ResFile.VersionMajor2 == 9) { loader.ReadUInt16(); //padding } BindIndices = loader.LoadCustom(() => loader.ReadUInt16s(materialCount), BindIndicesOffset); var textureList = loader.LoadCustom(() => loader.LoadStrings(TextureCount), TextureNameArrayOffset); TextureBindArray = loader.LoadCustom(() => loader.ReadInt64s(TextureCount), TextureBindArrayOffset); if (textureList == null) { textureList = new List <string>(); } foreach (var tex in textureList) { TextureNames.Add(tex, new TextureRef() { Name = tex }); } } else if (signature == "FSHU") { if (loader.ResFile.Version >= 0x02040000) { Name = loader.LoadString(); Path = loader.LoadString(); Flags = (MaterialAnimFlags)loader.ReadUInt32(); if (loader.ResFile.Version >= 0x03040000) { FrameCount = loader.ReadInt32(); materialCount = loader.ReadUInt16(); ushort numUserData = loader.ReadUInt16(); int numParamAnim = loader.ReadInt32(); int numCurve = loader.ReadInt32(); BakedSize = loader.ReadUInt32(); } else { FrameCount = loader.ReadUInt16(); materialCount = loader.ReadUInt16(); UnknownValue = loader.ReadUInt32(); int numCurve = loader.ReadInt32(); BakedSize = loader.ReadUInt32(); int padding2 = loader.ReadInt32(); } BindModel = loader.Load <Model>(); BindIndices = loader.LoadCustom(() => loader.ReadUInt16s(materialCount)); materialAnimOffset = loader.ReadOffset(); UserData = loader.LoadDict <UserData>(); } else { Flags = (MaterialAnimFlags)loader.ReadUInt32(); FrameCount = loader.ReadInt16(); materialCount = loader.ReadUInt16(); ushort numUserData = loader.ReadUInt16(); ushort unk = loader.ReadUInt16(); BakedSize = loader.ReadUInt32(); Name = loader.LoadString(); Path = loader.LoadString(); BindModel = loader.Load <Model>(); BindIndices = loader.LoadCustom(() => loader.ReadUInt16s(materialCount)); materialAnimOffset = loader.ReadOffset(); } } else if (signature == "FTXP") { Name = loader.LoadString(); Path = loader.LoadString(); Flags = loader.ReadEnum <MaterialAnimFlags>(true); ushort numTextureRef = 0; if (loader.ResFile.Version >= 0x03040000) { ushort numUserData = loader.ReadUInt16(); FrameCount = loader.ReadInt32(); numTextureRef = loader.ReadUInt16(); materialCount = loader.ReadUInt16(); int numPatAnim = loader.ReadInt32(); int numCurve = loader.ReadInt32(); BakedSize = loader.ReadUInt32(); } else { FrameCount = loader.ReadUInt16(); numTextureRef = loader.ReadUInt16(); materialCount = loader.ReadUInt16(); ushort numUserData = loader.ReadUInt16(); int numPatAnim = loader.ReadInt16(); int numCurve = loader.ReadInt32(); BakedSize = loader.ReadUInt32(); loader.Seek(4); //padding } BindModel = loader.Load <Model>(); BindIndices = loader.LoadCustom(() => loader.ReadUInt16s(materialCount)); materialAnimOffset = loader.ReadOffset(); if (loader.ResFile.Version >= 0x03040000) { TextureNames = loader.LoadDict <TextureRef>(); } else { int TextureCount = 0; foreach (var patternAnim in MaterialAnimDataList) { foreach (var curve in patternAnim.Curves) { List <uint> frames = new List <uint>(); foreach (float key in curve.Keys) { frames.Add((uint)key); } TextureCount = (short)frames.Max(); } } var TextureRefNames = loader.LoadList <TextureRef>(numTextureRef); foreach (var texRef in TextureRefNames) { TextureNames.Add(texRef.Name, texRef); } } UserData = loader.LoadDict <UserData>(); } //Load materials and parse based on the signature of the section MaterialAnimDataList = loader.LoadCustom(() => { List <MaterialAnimData> materialAnims = new List <MaterialAnimData>(); for (int i = 0; i < materialCount; i++) { materialAnims.Add(new MaterialAnimData(loader, signature)); } return(materialAnims); }, materialAnimOffset); }
// ---- METHODS ------------------------------------------------------------------------------------------------ void IResData.Load(ResFileLoader loader) { loader.CheckSignature(_signature); Name = loader.LoadString(); Path = loader.LoadString(); Flags = loader.ReadEnum <TexPatternAnimFlags>(true); ushort numMatAnim = 0; ushort numTextureRef = 0; if (loader.ResFile.Version >= 0x03040000) { ushort numUserData = loader.ReadUInt16(); FrameCount = loader.ReadInt32(); numTextureRef = loader.ReadUInt16(); numMatAnim = loader.ReadUInt16(); int numPatAnim = loader.ReadInt32(); int numCurve = loader.ReadInt32(); BakedSize = loader.ReadUInt32(); } else { FrameCount = loader.ReadUInt16(); numTextureRef = loader.ReadUInt16(); numMatAnim = loader.ReadUInt16(); ushort numUserData = loader.ReadUInt16(); // loader.Seek(2); //padding int numPatAnim = loader.ReadInt16(); int numCurve = loader.ReadInt32(); BakedSize = loader.ReadUInt32(); loader.Seek(4); //padding } BindModel = loader.Load <Model>(); BindIndices = loader.LoadCustom(() => loader.ReadUInt16s(numMatAnim)); TexPatternMatAnims = loader.LoadList <TexPatternMatAnim>(numMatAnim); if (loader.ResFile.Version >= 0x03040000) { TextureRefs = loader.LoadDict <TextureRef>(); } else { int TextureCount = 0; foreach (var patternAnim in TexPatternMatAnims) { foreach (var curve in patternAnim.Curves) { List <uint> frames = new List <uint>(); foreach (float key in curve.Keys) { // Console.WriteLine((uint)key); frames.Add((uint)key); } TextureCount = (short)frames.Max(); /* * for (int i = 0; i < (ushort)curve.Frames.Length; i++) * { * if (curve.Scale != 0) * { * int test = (int)curve.Keys[i, 0]; * float key = curve.Offset + test * curve.Scale; * frames.Add((int)key); * } * else * { * float test = curve.Keys[i, 0]; * int key = curve.Offset + (int)test; * frames.Add((int)key); * * int testCeiling = (int)Math.Ceiling(test); * int testFloor = (int)Math.Floor(test); * int testRound = (int)Math.Round(test); * * Console.WriteLine("convert int = {0}", (Decimal10x5)test); * } * }*/ } } Console.WriteLine(Name + " Tex Total " + (TextureCount + 1)); TextureRefNames = loader.LoadList <TextureRef>(numTextureRef); } UserData = loader.LoadDict <UserData>(); }
// ---- METHODS ------------------------------------------------------------------------------------------------ void IResData.Load(ResFileLoader loader) { _flags = loader.ReadUInt16(); ushort numKey = loader.ReadUInt16(); AnimDataOffset = loader.ReadUInt32(); StartFrame = loader.ReadSingle(); EndFrame = loader.ReadSingle(); Scale = loader.ReadSingle(); Offset = loader.ReadSingle(); if (loader.ResFile.Version >= 0x03040000) { Delta = loader.ReadSingle(); } Frames = loader.LoadCustom(() => { switch (FrameType) { case AnimCurveFrameType.Single: if (CurveType == AnimCurveType.StepInt) { float[] dec10x5Frame = new float[numKey]; for (int i = 0; i < numKey; i++) { dec10x5Frame[i] = loader.ReadUInt32(); } return(dec10x5Frame); } else { return(loader.ReadSingles(numKey)); } case AnimCurveFrameType.Decimal10x5: float[] dec10x5Frames = new float[numKey]; for (int i = 0; i < numKey; i++) { dec10x5Frames[i] = (float)loader.ReadDecimal10x5(); } return(dec10x5Frames); case AnimCurveFrameType.Byte: float[] byteFrames = new float[numKey]; for (int i = 0; i < numKey; i++) { byteFrames[i] = loader.ReadByte(); } return(byteFrames); default: throw new ResException($"Invalid {nameof(FrameType)}."); } }); //Bools use bits to store values. if (CurveType == AnimCurveType.StepBool) { int KeyBool = 0; if (KeyType == AnimCurveKeyType.Single) //Read them as a int instead of a float { KeyBool = loader.LoadCustom(() => loader.ReadInt32()); } else if (KeyType == AnimCurveKeyType.Int16) { KeyBool = loader.LoadCustom(() => loader.ReadInt16()); } else if (KeyType == AnimCurveKeyType.SByte) { KeyBool = loader.LoadCustom(() => loader.ReadSByte()); } KeyStepBoolData = new bool[numKey]; for (int i = 0; i < numKey; i++) { bool set = (KeyBool & 0x1) != 0; KeyBool >>= 1; KeyStepBoolData[i] = set; } } else { Keys = loader.LoadCustom(() => { int elementsPerKey = ElementsPerKey; float[,] keys = new float[numKey, elementsPerKey]; switch (KeyType) { case AnimCurveKeyType.Single: for (int i = 0; i < numKey; i++) { for (int j = 0; j < elementsPerKey; j++) { if (CurveType == AnimCurveType.StepInt) { keys[i, j] = loader.ReadUInt32(); } else { keys[i, j] = loader.ReadSingle(); } } } break; case AnimCurveKeyType.Int16: for (int i = 0; i < numKey; i++) { for (int j = 0; j < elementsPerKey; j++) { keys[i, j] = loader.ReadInt16(); } } break; case AnimCurveKeyType.SByte: for (int i = 0; i < numKey; i++) { for (int j = 0; j < elementsPerKey; j++) { keys[i, j] = loader.ReadSByte(); } } break; default: throw new ResException($"Invalid {nameof(KeyType)}."); } return(keys); }); } }
void IResData.Load(ResFileLoader loader) { long FrameArrayOffset = 0; long KeyArrayOffset = 0; ushort numKey = 0; if (loader.IsSwitch) { FrameArrayOffset = loader.ReadOffset(); KeyArrayOffset = loader.ReadOffset(); _flags = loader.ReadUInt16(); numKey = loader.ReadUInt16(); AnimDataOffset = loader.ReadUInt32(); StartFrame = loader.ReadSingle(); EndFrame = loader.ReadSingle(); Scale = loader.ReadSingle(); Offset = loader.ReadSingle(); Delta = loader.ReadSingle(); int padding = loader.ReadInt32(); } else { _flags = loader.ReadUInt16(); numKey = loader.ReadUInt16(); AnimDataOffset = loader.ReadUInt32(); StartFrame = loader.ReadSingle(); EndFrame = loader.ReadSingle(); Scale = loader.ReadSingle(); Offset = loader.ReadSingle(); if (loader.ResFile.Version >= 0x03040000) { Delta = loader.ReadSingle(); } FrameArrayOffset = loader.ReadOffset(); KeyArrayOffset = loader.ReadOffset(); } Frames = loader.LoadCustom(() => { switch (FrameType) { case AnimCurveFrameType.Single: return(loader.ReadSingles(numKey)); case AnimCurveFrameType.Decimal10x5: float[] dec10x5Frames = new float[numKey]; for (int i = 0; i < numKey; i++) { dec10x5Frames[i] = (float)loader.ReadDecimal10x5(); } return(dec10x5Frames); case AnimCurveFrameType.Byte: float[] byteFrames = new float[numKey]; for (int i = 0; i < numKey; i++) { byteFrames[i] = loader.ReadByte(); } return(byteFrames); default: throw new ResException($"Invalid {nameof(FrameType)}."); } }, (uint)FrameArrayOffset); Keys = loader.LoadCustom(() => { int elementsPerKey = ElementsPerKey; float[,] keys = new float[numKey, elementsPerKey]; switch (KeyType) { case AnimCurveKeyType.Single: for (int i = 0; i < numKey; i++) { for (int j = 0; j < elementsPerKey; j++) { if (CurveType == AnimCurveType.StepInt || CurveType == AnimCurveType.StepBool) { keys[i, j] = loader.ReadUInt32(); } else { keys[i, j] = loader.ReadSingle(); } } } break; case AnimCurveKeyType.Int16: for (int i = 0; i < numKey; i++) { for (int j = 0; j < elementsPerKey; j++) { keys[i, j] = loader.ReadInt16(); } } break; case AnimCurveKeyType.SByte: for (int i = 0; i < numKey; i++) { for (int j = 0; j < elementsPerKey; j++) { keys[i, j] = loader.ReadSByte(); } } break; default: throw new ResException($"Invalid {nameof(KeyType)}."); } return(keys); }, (uint)KeyArrayOffset); //Bools use bits to store values. if (CurveType == AnimCurveType.StepBool) { int keyIndex = 0; KeyStepBoolData = new bool[numKey]; for (int i = 0; i < Keys.Length; i++) { if (numKey <= keyIndex) { break; } int value = (int)Keys[i, 0]; //Bit shift each key value for (int j = 0; j < 32; j++) { if (numKey <= keyIndex) { break; } bool set = (value & 0x1) != 0; value >>= 1; KeyStepBoolData[keyIndex] = set; keyIndex++; } } } }