} //Size 4 public static UnkSkeletonData Read(byte[] rawBytes, int offset) { UnkSkeletonData data = new UnkSkeletonData(); data.Values = BitConverter_Ex.ToUInt16Array(rawBytes, offset + 0, 4); return(data); }
public static Bone Read(byte[] rawBytes, int offset, int unkDataOffset, int index) { Bone bone = new Bone(); bone.Index = (ushort)index; bone.I_00 = BitConverter.ToUInt16(rawBytes, offset + 0); bone.I_02 = BitConverter.ToUInt16(rawBytes, offset + 2); bone.I_04 = BitConverter.ToUInt16(rawBytes, offset + 4); bone.I_06 = BitConverter.ToUInt16(rawBytes, offset + 6); bone.I_08 = BitConverter.ToUInt16(rawBytes, offset + 8); bone.I_10 = BitConverter.ToUInt16(rawBytes, offset + 10); bone.I_12 = BitConverter.ToUInt16(rawBytes, offset + 12); bone.I_14 = BitConverter.ToUInt16(rawBytes, offset + 14); bone.Matrix = TransformMatrix.Read(rawBytes, offset + 16); if (unkDataOffset > 0) { bone.UnknownValues = UnkSkeletonData.Read(rawBytes, unkDataOffset); } return(bone); }
public List <byte> Write() { List <byte> bytes = new List <byte>(); int boneCount = (Bones != null) ? Bones.Count : 0; int ikCount = (IKEntries != null) ? IKEntries.Count : 0; bool useUnkSkeletonData = false; //Header bytes.AddRange(BitConverter.GetBytes((ushort)boneCount)); //Bone count bytes.AddRange(BitConverter.GetBytes(I_02)); bytes.AddRange(BitConverter.GetBytes((ushort)ikCount)); //IK count bytes.AddRange(BitConverter.GetBytes(I_06)); bytes.AddRange(new byte[4]); //Bone offset bytes.AddRange(new byte[4]); //Names offset bytes.AddRange(BitConverter.GetBytes(I_16)); bytes.AddRange(BitConverter.GetBytes(I_20)); bytes.AddRange(new byte[4]); //UnkSkeletonData offset bytes.AddRange(new byte[4]); //MatrixData offset bytes.AddRange(new byte[4]); //IkData offset bytes.AddRange(BitConverter.GetBytes(I_36)); bytes.AddRange(BitConverter.GetBytes(I_40)); bytes.AddRange(BitConverter.GetBytes(I_44)); bytes.AddRange(BitConverter.GetBytes(I_48)); bytes.AddRange(BitConverter.GetBytes(I_52)); bytes.AddRange(BitConverter.GetBytes(I_54)); bytes.AddRange(BitConverter.GetBytes(F_56)); bytes.AddRange(BitConverter.GetBytes(F_60)); //Bones bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count), 8); for (int i = 0; i < boneCount; i++) { if (Bones[i].UnknownValues != null) { useUnkSkeletonData = true; } bytes.AddRange(Bones[i].Write()); } //UnknownSkeletonData if (useUnkSkeletonData) { bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count), 24); for (int i = 0; i < boneCount; i++) { if (Bones[i].UnknownValues == null) { Bones[i].UnknownValues = UnkSkeletonData.GetDefault(); } bytes.AddRange(Bones[i].UnknownValues.Write()); } } //Names Offsets int namesOffsetStart = bytes.Count; bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(namesOffsetStart), 12); for (int i = 0; i < boneCount; i++) { bytes.AddRange(new byte[4]); } //Names for (int i = 0; i < boneCount; i++) { bytes = Utils.ReplaceRange(bytes, BitConverter.GetBytes(bytes.Count), namesOffsetStart + (i * 4)); bytes.AddRange(Encoding.ASCII.GetBytes(Bones[i].Name)); bytes.Add(0); } //Padding bytes.AddRange(new byte[Utils.CalculatePadding(bytes.Count, 16)]); return(bytes); }