// ---- 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); }); } }
// ---- 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: 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)}."); } }); Keys = loader.LoadCustom(() => { int elementsPerKey = ElementsPerKey; float[,] keys = new float[numKey, elementsPerKey]; switch (KeyType) { case AnimCurveKeyType.Single: for (int i = 0; i < numKey; i++) { keys[i, 0] = loader.ReadSingle(); } break; case AnimCurveKeyType.Int16: for (int i = 0; i < numKey; i++) { for (int j = 0; j < elementsPerKey; j++) { keys[i, j] = loader.ReadUInt16(); } } 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++; } } } }