internal override void WriteTypeData(BinaryWriterEx bw) { bw.WriteInt32(UnkT00); bw.WriteSingle(UnkT04); bw.WriteSingle(UnkT08); bw.WriteSingle(UnkT0C); bw.WriteSingle(UnkT10); bw.WriteSingle(UnkT14); bw.WriteSingle(UnkT18); bw.WriteInt32(0); }
internal void WriteValue(BinaryWriterEx bw, object value) { switch (Type) { case ParamType.aob: bw.WriteBytes((byte[])value); break; case ParamType.b: bw.WriteBoolean((bool)value); break; case ParamType.u8: case ParamType.x8: bw.WriteByte(Convert.ToByte(value)); break; case ParamType.s8: bw.WriteSByte(Convert.ToSByte(value)); break; case ParamType.u16: case ParamType.x16: bw.WriteUInt16(Convert.ToUInt16(value)); break; case ParamType.s16: bw.WriteInt16(Convert.ToInt16(value)); break; case ParamType.u32: case ParamType.x32: bw.WriteUInt32(Convert.ToUInt32(value)); break; case ParamType.s32: bw.WriteInt32(Convert.ToInt32(value)); break; case ParamType.u64: case ParamType.x64: bw.WriteUInt64(Convert.ToUInt64(value)); break; case ParamType.s64: bw.WriteInt64(Convert.ToInt64(value)); break; case ParamType.f32: bw.WriteSingle(Convert.ToSingle(value)); break; case ParamType.f64: bw.WriteDouble(Convert.ToDouble(value)); break; default: throw new Exception($"Invalid ParamTemplate ParamType: {Type.ToString()}"); } }
internal override void Write(BinaryWriterEx bw, int id) { base.Write(bw, id); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteInt32(ThinkParamID); bw.WriteInt32(NPCParamID); bw.WriteInt32(TalkID); bw.WriteSingle(UnkT14); bw.WriteInt32(CharaInitID); bw.WriteInt32(CollisionIndex); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteInt16s(MovePointIndices); bw.WriteInt32(UnkT38); bw.WriteInt32(UnkT3C); }
internal void Write(BinaryWriterEx bw) { bw.WriteVector3(XAngles); bw.WriteInt32(0); bw.WriteVector3(YAngles); bw.WriteInt32(0); bw.WriteVector3(ZAngles); bw.WriteInt32(0); bw.WriteVector3(Position); bw.WriteSingle(Unk3C); bw.WriteInt32(DecalParamID); bw.WriteInt16(Size1); bw.WriteInt16(Size2); bw.WriteInt64(0); bw.WriteInt64(0); bw.WriteInt64(0); }
/// <summary> /// Packs an enumeration of arg values into a byte array for use in an instruction. /// </summary> public void PackArgs(IEnumerable <object> args, bool bigEndian = false) { using (var ms = new MemoryStream()) { var bw = new BinaryWriterEx(bigEndian, ms); foreach (object arg in args) { switch (arg) { case byte ub: bw.WriteByte(ub); break; case ushort us: bw.Pad(2); bw.WriteUInt16(us); break; case uint ui: bw.Pad(4); bw.WriteUInt32(ui); break; case sbyte sb: bw.WriteSByte(sb); break; case short ss: bw.Pad(2); bw.WriteInt16(ss); break; case int si: bw.Pad(4); bw.WriteInt32(si); break; case float f: bw.Pad(4); bw.WriteSingle(f); break; case long sl: bw.Pad(8); bw.WriteInt64(sl); break; default: throw new NotSupportedException($"Unsupported argument type: {arg.GetType()}"); } } ArgData = bw.FinishBytes(); } }
private protected override void WriteTypeData(BinaryWriterEx bw) { bw.WriteInt32(UnkT00); bw.WriteInt32(UnkT04); bw.WriteSingle(UnkT08); bw.WriteInt32(NPCParamID); bw.WriteInt32(TalkID); bw.WriteByte(PointMoveType); bw.WriteByte(0); bw.WriteUInt16(PlatoonID); bw.WriteInt32(CharaInitID); bw.WriteInt32(CollisionIndex); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteInt16s(MovePointIndices); bw.WriteInt32(InitAnimID); bw.WriteInt32(DamageAnimID); }
internal override void WriteSpecific(BinaryWriterEx bw) { bw.WriteByte(HitFilterID); bw.WriteByte((byte)SoundSpaceType); bw.WriteInt16(EnvLightMapSpotIndex); bw.WriteSingle(ReflectPlaneHeight); bw.WriteInt16(MapNameID); bw.WriteInt16(UnkT08b); bw.WriteInt32(DisableBonfireEntityID); bw.WriteInt16(LockCamID1); bw.WriteInt16(LockCamID2); bw.WriteInt32(UnkT14); bw.WriteInt32(UnkT18); bw.WriteInt32(UnkT1C); bw.WriteInt32(UnkT20); bw.WriteInt32(UnkT24); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteInt32(UnkT38); bw.WriteInt32(0); bw.WriteInt32(UnkT40); bw.WriteInt32(UnkT44); bw.WriteInt32(UnkT48); bw.WriteInt32(UnkT4C); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteInt32(UnkT70); bw.WriteInt32(UnkT74); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteInt32(0); }
private protected override void WriteTypeData(BinaryWriterEx bw) { bw.WriteBoolean(UnkT00); bw.WriteBoolean(UnkT01); bw.WriteBoolean(UnkT02); bw.WriteByte(0); bw.WriteSingle(UnkT04); bw.WriteSingle(UnkT08); bw.WriteSingle(UnkT0C); bw.WriteSingle(UnkT10); bw.WriteSingle(UnkT14); bw.WriteSingle(UnkT18); bw.WriteInt32(0); }
private protected override void WriteTypeData(BinaryWriterEx bw) { bw.WriteInt32(0); bw.WriteSingle(UnkT04); bw.WriteSingle(UnkT08); bw.WriteSingle(UnkT0C); bw.WriteInt32(0); bw.WriteSingle(UnkT14); bw.WriteSingle(UnkT18); bw.WriteInt32(0); bw.WriteSingle(UnkT20); bw.WriteRGBA(ColorT24); bw.WritePattern(0x18, 0x00); }
private protected override void WriteTypeData(BinaryWriterEx bw) { bw.WriteSingle(UnkT00); bw.WriteSingle(UnkT04); bw.WriteSingle(UnkT08); bw.WriteSingle(UnkT0C); bw.WriteInt32(UnkT10); bw.WriteInt32(UnkT14); bw.WriteSingle(UnkT18); bw.WriteSingle(UnkT1C); bw.WriteInt32(UnkT20); bw.WriteInt32(UnkT24); bw.WriteSingle(UnkT28); bw.WriteInt32(UnkT2C); bw.WriteInt32(UnkT30); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteInt32(0); }
internal void Write(BinaryWriterEx bw, int version, int index) { bw.WriteVector3(Position); bw.WriteSingle(1); bw.WriteVector3(Rotation); bw.WriteInt32(0); bw.WriteVector3(Scale); bw.WriteInt32(0); bw.WriteInt32(NameID); bw.WriteInt32(ModelID); bw.WriteInt32(Unk38); bw.WriteInt32(0); bw.WriteInt32(VertexCount); bw.WriteInt32(NameReferenceIDs.Count); bw.WriteInt16(MapNodesIndex); bw.WriteInt16((short)MapNodes.Count); bw.WriteInt32(Unk4C ? 1 : 0); if (version < 4) { if (NameReferenceIDs.Count > 16) { throw new InvalidDataException("Name reference count should not exceed 16 in DS3/BB."); } bw.WriteInt32s(NameReferenceIDs); for (int i = 0; i < 16 - NameReferenceIDs.Count; i++) { bw.WriteInt32(-1); } } else { bw.ReserveInt32($"NameRefOffset{index}"); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteInt32(0); } }
internal void WriteAssertValue(BinaryWriterEx bw) { switch (Type) { case ParamType.aob: var assertAob = (byte[])ValueToAssert; bw.WriteBytes(assertAob); break; case ParamType.b: bw.WriteBoolean((bool)ValueToAssert); break; case ParamType.u8: case ParamType.x8: bw.WriteByte((byte)ValueToAssert); break; case ParamType.s8: bw.WriteSByte((sbyte)ValueToAssert); break; case ParamType.u16: case ParamType.x16: bw.WriteUInt16((ushort)ValueToAssert); break; case ParamType.s16: bw.WriteInt16((short)ValueToAssert); break; case ParamType.u32: case ParamType.x32: bw.WriteUInt32((uint)ValueToAssert); break; case ParamType.s32: bw.WriteInt32((int)ValueToAssert); break; case ParamType.u64: case ParamType.x64: bw.WriteUInt64((ulong)ValueToAssert); break; case ParamType.s64: bw.WriteInt64((long)ValueToAssert); break; case ParamType.f32: bw.WriteSingle((float)ValueToAssert); break; case ParamType.f64: bw.WriteDouble((double)ValueToAssert); break; default: throw new Exception($"Invalid ParamTemplate ParamType: {Type.ToString()}"); } }
internal override void Write(BinaryWriterEx bw, int id) { base.Write(bw, id); bw.WriteByte(HitFilterID); bw.WriteByte(SoundSpaceType); bw.WriteInt16(EnvLightMapSpotIndex); bw.WriteSingle(ReflectPlaneHeight); bw.WriteUInt32s(NvmGroups); bw.WriteInt32s(VagrantEntityIDs); bw.WriteInt16(MapNameID); bw.WriteInt16(DisableStart); bw.WriteInt32(DisableBonfireEntityID); bw.WriteInt32(-1); bw.WriteInt32(-1); bw.WriteInt32(-1); bw.WriteInt32(PlayRegionID); bw.WriteInt16(LockCamParamID1); bw.WriteInt16(LockCamParamID2); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteInt32(0); }
private protected override void WriteTypeData(BinaryWriterEx bw) { bw.WriteByte(HitFilterID); bw.WriteByte(SoundSpaceType); bw.WriteInt16(EnvLightMapSpotIndex); bw.WriteSingle(ReflectPlaneHeight); bw.WriteUInt32s(NvmGroups); bw.WriteInt32s(VagrantEntityIDs); bw.WriteInt16(MapNameID); bw.WriteBoolean(DisableStart); bw.WriteByte(UnkT27); bw.WriteInt32(DisableBonfireEntityID); bw.WriteInt32(-1); bw.WriteInt32(-1); bw.WriteInt32(-1); bw.WriteInt32(PlayRegionID); bw.WriteInt16(LockCamParamID1); bw.WriteInt16(LockCamParamID2); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteInt32(0); }
internal override void WriteSpecific(BinaryWriterEx bw) { bw.WriteVector3(Position); bw.WriteSingle(Degree); }
internal void Write(BinaryWriterEx bw, long nameOffset, int version, bool longOffsets) { bw.WriteInt32(Unk00); bw.WriteInt32(Unk04); bw.WriteInt32(Unk08); bw.WriteInt32(Unk0C); if (longOffsets) { bw.WriteInt64(nameOffset); } else { bw.WriteInt32((int)nameOffset); } bw.WriteUInt32((uint)Type); bw.WriteBoolean(Unk1C); bw.WriteByte(DiffuseColor.R); bw.WriteByte(DiffuseColor.G); bw.WriteByte(DiffuseColor.B); bw.WriteSingle(DiffusePower); bw.WriteByte(SpecularColor.R); bw.WriteByte(SpecularColor.G); bw.WriteByte(SpecularColor.B); bw.WriteBoolean(CastShadows); bw.WriteSingle(SpecularPower); bw.WriteSingle(ConeAngle); bw.WriteSingle(Unk30); bw.WriteSingle(Unk34); bw.WriteVector3(Position); bw.WriteVector3(Rotation); bw.WriteInt32(Unk50); bw.WriteSingle(Unk54); bw.WriteSingle(Radius); bw.WriteInt32(Unk5C); bw.WriteInt32(0); bw.WriteBytes(Unk64); bw.WriteSingle(Unk68); bw.WriteByte(ShadowColor.R); bw.WriteByte(ShadowColor.G); bw.WriteByte(ShadowColor.B); bw.WriteByte(ShadowColor.A); bw.WriteSingle(Unk70); bw.WriteSingle(FlickerIntervalMin); bw.WriteSingle(FlickerIntervalMax); bw.WriteSingle(FlickerBrightnessMult); bw.WriteInt32(Unk80); bw.WriteBytes(Unk84); bw.WriteSingle(Unk88); bw.WriteInt32(0); bw.WriteSingle(Unk90); bw.WriteInt32(0); bw.WriteSingle(Unk98); bw.WriteSingle(Unk9C); bw.WriteBytes(UnkA0); bw.WriteSingle(Sharpness); bw.WriteInt32(0); bw.WriteSingle(UnkAC); if (longOffsets) { bw.WriteInt64(0); } else { bw.WriteInt32(0); } bw.WriteSingle(Width); bw.WriteSingle(UnkBC); bw.WriteBytes(UnkC0); bw.WriteSingle(UnkC4); if (version >= 16) { bw.WriteSingle(UnkC8); bw.WriteSingle(UnkCC); bw.WriteSingle(UnkD0); bw.WriteSingle(UnkD4); bw.WriteSingle(UnkD8); bw.WriteInt32(UnkDC); bw.WriteSingle(UnkE0); bw.WriteInt32(0); } }
internal void WriteDefaultValue(BinaryWriterEx bw) { if (ValueToAssert != null) { WriteAssertValue(bw); } else if (DefaultValue == null) { switch (Type) { case ParamType.aob: for (int i = 0; i < AobLength; i++) { bw.WriteByte(0); } break; case ParamType.b: case ParamType.u8: case ParamType.x8: bw.WriteByte(0); break; case ParamType.s8: bw.WriteSByte(0); break; case ParamType.u16: case ParamType.x16: bw.WriteUInt16(0); break; case ParamType.s16: bw.WriteInt16(0); break; case ParamType.u32: case ParamType.x32: bw.WriteUInt32(0); break; case ParamType.s32: bw.WriteInt32(0); break; case ParamType.u64: case ParamType.x64: bw.WriteUInt64(0); break; case ParamType.s64: bw.WriteInt64(0); break; case ParamType.f32: bw.WriteSingle(0); break; case ParamType.f64: bw.WriteDouble(0); break; default: throw new Exception($"Invalid ParamTemplate ParamType: {Type.ToString()}"); } } else { switch (Type) { case ParamType.aob: var assertAob = (byte[])DefaultValue; bw.WriteBytes(assertAob); break; case ParamType.b: case ParamType.u8: case ParamType.x8: bw.WriteByte((byte)DefaultValue); break; case ParamType.s8: bw.WriteSByte((sbyte)DefaultValue); break; case ParamType.u16: case ParamType.x16: bw.WriteUInt16((ushort)DefaultValue); break; case ParamType.s16: bw.WriteInt16((short)DefaultValue); break; case ParamType.u32: case ParamType.x32: bw.WriteUInt32((uint)DefaultValue); break; case ParamType.s32: bw.WriteInt32((int)DefaultValue); break; case ParamType.u64: case ParamType.x64: bw.WriteUInt64((ulong)DefaultValue); break; case ParamType.s64: bw.WriteInt64((long)DefaultValue); break; case ParamType.f32: bw.WriteSingle((float)DefaultValue); break; case ParamType.f64: bw.WriteDouble((double)DefaultValue); break; default: throw new Exception($"Invalid ParamTemplate ParamType: {Type.ToString()}"); } } }
private protected override void WriteTypeData(BinaryWriterEx bw) { bw.WriteVector3(Position); bw.WriteSingle(Degree); }
internal void Write(BinaryWriterEx bw, BufferLayout layout, int vertexSize, int version) { var tangentQueue = new Queue <Vector4>(Tangents); var colorQueue = new Queue <Color>(Colors); var uvQueue = new Queue <Vector3>(UVs); float uvFactor = 1024; foreach (BufferLayout.Member member in layout) { switch (member.Semantic) { case BufferLayout.MemberSemantic.Position: if (member.Type == BufferLayout.MemberType.Float3) { bw.WriteVector3(Position); } else { throw new NotImplementedException(); } break; case BufferLayout.MemberSemantic.BoneWeights: if (member.Type == BufferLayout.MemberType.Byte4C) { for (int i = 0; i < 4; i++) { bw.WriteSByte((sbyte)(BoneWeights[i] * sbyte.MaxValue)); } } else if (member.Type == BufferLayout.MemberType.Short4toFloat4A) { for (int i = 0; i < 4; i++) { bw.WriteInt16((short)(BoneWeights[i] * short.MaxValue)); } } else { throw new NotImplementedException(); } break; case BufferLayout.MemberSemantic.BoneIndices: if (member.Type == BufferLayout.MemberType.Byte4B) { for (int i = 0; i < 4; i++) { bw.WriteByte((byte)BoneIndices[i]); } } else if (member.Type == BufferLayout.MemberType.ShortBoneIndices) { for (int i = 0; i < 4; i++) { bw.WriteUInt16((ushort)BoneIndices[i]); } } else if (member.Type == BufferLayout.MemberType.Byte4E) { for (int i = 0; i < 4; i++) { bw.WriteByte((byte)BoneIndices[i]); } } else { throw new NotImplementedException(); } break; case BufferLayout.MemberSemantic.Normal: if (member.Type == BufferLayout.MemberType.Float4) { bw.WriteVector4(Normal); } else if (member.Type == BufferLayout.MemberType.Byte4A) { bw.WriteByte((byte)(Normal.X * 127 + 127)); bw.WriteByte((byte)(Normal.Y * 127 + 127)); bw.WriteByte((byte)(Normal.Z * 127 + 127)); bw.WriteByte((byte)(Normal.W * 127 + 127)); } else if (member.Type == BufferLayout.MemberType.Byte4B) { bw.WriteByte((byte)(Normal.X * 127 + 127)); bw.WriteByte((byte)(Normal.Y * 127 + 127)); bw.WriteByte((byte)(Normal.Z * 127 + 127)); bw.WriteByte((byte)(Normal.W * 127 + 127)); } else if (member.Type == BufferLayout.MemberType.Byte4C) { bw.WriteByte((byte)(Normal.X * 127 + 127)); bw.WriteByte((byte)(Normal.Y * 127 + 127)); bw.WriteByte((byte)(Normal.Z * 127 + 127)); bw.WriteByte((byte)(Normal.W * 127 + 127)); } else if (member.Type == BufferLayout.MemberType.Short4toFloat4B) { bw.WriteInt16((short)(Normal.X * 32767 + 32767)); bw.WriteInt16((short)(Normal.Y * 32767 + 32767)); bw.WriteInt16((short)(Normal.Z * 32767 + 32767)); bw.WriteInt16((short)(Normal.W * 32767 + 32767)); } else { throw new NotImplementedException(); } break; case BufferLayout.MemberSemantic.UV: Vector3 uv = uvQueue.Dequeue() * uvFactor; if (member.Type == BufferLayout.MemberType.Float2) { bw.WriteSingle(uv.X); bw.WriteSingle(uv.Y); } else if (member.Type == BufferLayout.MemberType.Float3) { bw.WriteVector3(uv); } else if (member.Type == BufferLayout.MemberType.Byte4A) { bw.WriteInt16((short)uv.X); bw.WriteInt16((short)uv.Y); } else if (member.Type == BufferLayout.MemberType.Byte4B) { bw.WriteInt16((short)uv.X); bw.WriteInt16((short)uv.Y); } else if (member.Type == BufferLayout.MemberType.Short2toFloat2) { bw.WriteInt16((short)uv.X); bw.WriteInt16((short)uv.Y); } else if (member.Type == BufferLayout.MemberType.Byte4C) { bw.WriteInt16((short)uv.X); bw.WriteInt16((short)uv.Y); } else if (member.Type == BufferLayout.MemberType.UV) { bw.WriteInt16((short)uv.X); bw.WriteInt16((short)uv.Y); } else if (member.Type == BufferLayout.MemberType.UVPair) { bw.WriteInt16((short)uv.X); bw.WriteInt16((short)uv.Y); uv = uvQueue.Dequeue() * uvFactor; bw.WriteInt16((short)uv.X); bw.WriteInt16((short)uv.Y); } else { throw new NotImplementedException(); } break; case BufferLayout.MemberSemantic.Tangent: Vector4 tangent = tangentQueue.Dequeue(); if (member.Type == BufferLayout.MemberType.Byte4A) { bw.WriteByte((byte)(tangent.X * 127 + 127)); bw.WriteByte((byte)(tangent.Y * 127 + 127)); bw.WriteByte((byte)(tangent.Z * 127 + 127)); bw.WriteByte((byte)(tangent.W * 127 + 127)); } else if (member.Type == BufferLayout.MemberType.Byte4B) { bw.WriteByte((byte)(tangent.X * 127 + 127)); bw.WriteByte((byte)(tangent.Y * 127 + 127)); bw.WriteByte((byte)(tangent.Z * 127 + 127)); bw.WriteByte((byte)(tangent.W * 127 + 127)); } else if (member.Type == BufferLayout.MemberType.Byte4C) { bw.WriteByte((byte)(tangent.X * 127 + 127)); bw.WriteByte((byte)(tangent.Y * 127 + 127)); bw.WriteByte((byte)(tangent.Z * 127 + 127)); bw.WriteByte((byte)(tangent.W * 127 + 127)); } else { throw new NotImplementedException(); } break; case BufferLayout.MemberSemantic.UnknownVector4A: if (member.Type == BufferLayout.MemberType.Byte4B) { bw.WriteBytes(UnknownVector4); } else if (member.Type == BufferLayout.MemberType.Byte4C) { bw.WriteBytes(UnknownVector4); } else { throw new NotImplementedException(); } break; case BufferLayout.MemberSemantic.VertexColor: Color color = colorQueue.Dequeue(); if (member.Type == BufferLayout.MemberType.Float4) { bw.WriteSingle(color.R); bw.WriteSingle(color.G); bw.WriteSingle(color.B); bw.WriteSingle(color.A); } else if (member.Type == BufferLayout.MemberType.Byte4A) { bw.WriteByte((byte)(color.A * 255)); bw.WriteByte((byte)(color.R * 255)); bw.WriteByte((byte)(color.G * 255)); bw.WriteByte((byte)(color.B * 255)); } else if (member.Type == BufferLayout.MemberType.Byte4C) { bw.WriteByte((byte)(color.R * 255)); bw.WriteByte((byte)(color.G * 255)); bw.WriteByte((byte)(color.B * 255)); bw.WriteByte((byte)(color.A * 255)); } else { throw new NotImplementedException(); } break; default: throw new NotImplementedException(); } } }
internal void Write(BinaryWriterEx bw, List <LayoutMember> layout, float uvFactor) { foreach (LayoutMember member in layout) { if (member.Semantic == LayoutSemantic.Position) { if (member.Type == LayoutType.Float3) { bw.WriteVector3(Position); } else if (member.Type == LayoutType.Float4) { bw.WriteVector3(Position); bw.WriteSingle(0); } else { throw new NotImplementedException($"Write not implemented for {member.Type} {member.Semantic}."); } } else if (member.Semantic == LayoutSemantic.BoneWeights) { if (member.Type == LayoutType.Byte4A) { for (int i = 0; i < 4; i++) { bw.WriteSByte((sbyte)Math.Round(BoneWeights[i] * 127)); } } else if (member.Type == LayoutType.Byte4C) { for (int i = 0; i < 4; i++) { bw.WriteByte((byte)Math.Round(BoneWeights[i] * 255)); } } else if (member.Type == LayoutType.UVPair) { for (int i = 0; i < 4; i++) { bw.WriteInt16((short)Math.Round(BoneWeights[i] * 32767)); } } else if (member.Type == LayoutType.Short4toFloat4A) { for (int i = 0; i < 4; i++) { bw.WriteInt16((short)Math.Round(BoneWeights[i] * 32767)); } } else { throw new NotImplementedException($"Write not implemented for {member.Type} {member.Semantic}."); } } else if (member.Semantic == LayoutSemantic.BoneIndices) { if (member.Type == LayoutType.Byte4B) { for (int i = 0; i < 4; i++) { bw.WriteByte((byte)BoneIndices[i]); } } else if (member.Type == LayoutType.ShortBoneIndices) { for (int i = 0; i < 4; i++) { bw.WriteUInt16((ushort)BoneIndices[i]); } } else if (member.Type == LayoutType.Byte4E) { for (int i = 0; i < 4; i++) { bw.WriteByte((byte)BoneIndices[i]); } } else { throw new NotImplementedException($"Write not implemented for {member.Type} {member.Semantic}."); } } else if (member.Semantic == LayoutSemantic.Normal) { if (member.Type == LayoutType.Float3) { bw.WriteVector3(Normal); } else if (member.Type == LayoutType.Float4) { bw.WriteVector3(Normal); bw.WriteSingle(NormalW); } else if (member.Type == LayoutType.Byte4A) { WriteByteNormVector3(bw, Normal); bw.WriteByte((byte)NormalW); } else if (member.Type == LayoutType.Byte4B) { WriteByteNormVector3(bw, Normal); bw.WriteByte((byte)NormalW); } else if (member.Type == LayoutType.Byte4C) { WriteByteNormVector3(bw, Normal); bw.WriteByte((byte)NormalW); } else if (member.Type == LayoutType.Short4toFloat4A) { WriteShortNormVector3(bw, Normal); bw.WriteInt16((short)NormalW); } else if (member.Type == LayoutType.Short4toFloat4B) { WriteUShortNormVector3(bw, Normal); bw.WriteInt16((short)NormalW); } else if (member.Type == LayoutType.Byte4E) { WriteByteNormVector3(bw, Normal); bw.WriteByte((byte)NormalW); } else { throw new NotImplementedException($"Write not implemented for {member.Type} {member.Semantic}."); } } else if (member.Semantic == LayoutSemantic.UV) { Vector3 uv = uvQueue.Dequeue() * uvFactor; if (member.Type == LayoutType.Float2) { bw.WriteSingle(uv.X); bw.WriteSingle(uv.Y); } else if (member.Type == LayoutType.Float3) { bw.WriteVector3(uv); } else if (member.Type == LayoutType.Float4) { bw.WriteSingle(uv.X); bw.WriteSingle(uv.Y); uv = uvQueue.Dequeue() * uvFactor; bw.WriteSingle(uv.X); bw.WriteSingle(uv.Y); } else if (member.Type == LayoutType.Byte4A) { bw.WriteInt16((short)Math.Round(uv.X)); bw.WriteInt16((short)Math.Round(uv.Y)); } else if (member.Type == LayoutType.Byte4B) { bw.WriteInt16((short)Math.Round(uv.X)); bw.WriteInt16((short)Math.Round(uv.Y)); } else if (member.Type == LayoutType.Short2toFloat2) { bw.WriteInt16((short)Math.Round(uv.X)); bw.WriteInt16((short)Math.Round(uv.Y)); } else if (member.Type == LayoutType.Byte4C) { bw.WriteInt16((short)Math.Round(uv.X)); bw.WriteInt16((short)Math.Round(uv.Y)); } else if (member.Type == LayoutType.UV) { bw.WriteInt16((short)Math.Round(uv.X)); bw.WriteInt16((short)Math.Round(uv.Y)); } else if (member.Type == LayoutType.UVPair) { bw.WriteInt16((short)Math.Round(uv.X)); bw.WriteInt16((short)Math.Round(uv.Y)); uv = uvQueue.Dequeue() * uvFactor; bw.WriteInt16((short)Math.Round(uv.X)); bw.WriteInt16((short)Math.Round(uv.Y)); } else if (member.Type == LayoutType.Short4toFloat4B) { bw.WriteInt16((short)Math.Round(uv.X)); bw.WriteInt16((short)Math.Round(uv.Y)); bw.WriteInt16((short)Math.Round(uv.Z)); bw.WriteInt16(0); } else { throw new NotImplementedException($"Write not implemented for {member.Type} {member.Semantic}."); } } else if (member.Semantic == LayoutSemantic.Tangent) { Vector4 tangent = tangentQueue.Dequeue(); if (member.Type == LayoutType.Float4) { bw.WriteVector4(tangent); } else if (member.Type == LayoutType.Byte4A) { WriteByteNormVector4(bw, tangent); } else if (member.Type == LayoutType.Byte4B) { WriteByteNormVector4(bw, tangent); } else if (member.Type == LayoutType.Byte4C) { WriteByteNormVector4(bw, tangent); } else if (member.Type == LayoutType.Short4toFloat4A) { WriteShortNormVector4(bw, tangent); } else if (member.Type == LayoutType.Byte4E) { WriteByteNormVector4(bw, tangent); } else { throw new NotImplementedException($"Write not implemented for {member.Type} {member.Semantic}."); } } else if (member.Semantic == LayoutSemantic.Bitangent) { if (member.Type == LayoutType.Byte4A) { WriteByteNormVector4(bw, Bitangent); } else if (member.Type == LayoutType.Byte4B) { WriteByteNormVector4(bw, Bitangent); } else if (member.Type == LayoutType.Byte4C) { WriteByteNormVector4(bw, Bitangent); } else if (member.Type == LayoutType.Byte4E) { WriteByteNormVector4(bw, Bitangent); } else { throw new NotImplementedException($"Write not implemented for {member.Type} {member.Semantic}."); } } else if (member.Semantic == LayoutSemantic.VertexColor) { VertexColor color = colorQueue.Dequeue(); if (member.Type == LayoutType.Float4) { color.WriteFloatRGBA(bw); } else if (member.Type == LayoutType.Byte4A) { color.WriteByteARGB(bw); } else if (member.Type == LayoutType.Byte4C) { color.WriteByteRGBA(bw); } else { throw new NotImplementedException($"Write not implemented for {member.Type} {member.Semantic}."); } } else { throw new NotImplementedException($"Write not implemented for {member.Type} {member.Semantic}."); } } }
internal void Write(BinaryWriterEx bw, int nameOffset) { bw.WriteInt32(Unk00); bw.WriteInt32(Unk04); bw.WriteInt32(Unk08); bw.WriteInt32(Unk0C); bw.WriteInt32(nameOffset); bw.WriteInt32(0); bw.WriteInt32(Unk18); bw.WriteBoolean(Unk1C); bw.WriteByte(DiffuseColor.R); bw.WriteByte(DiffuseColor.G); bw.WriteByte(DiffuseColor.B); bw.WriteSingle(DiffuseBrightness); bw.WriteByte(SpecularColor.R); bw.WriteByte(SpecularColor.G); bw.WriteByte(SpecularColor.B); bw.WriteBoolean(Unk27); bw.WriteSingle(SpecularBrightness); bw.WriteSingle(ConeAngle); bw.WriteSingle(Unk30); bw.WriteSingle(Unk34); bw.WriteVector3(Position); bw.WriteVector3(Rotation); bw.WriteInt32(Unk50); bw.WriteSingle(Unk54); bw.WriteSingle(Radius); bw.WriteInt32(Unk5C); bw.WriteInt32(0); bw.WriteInt32(Unk64); bw.WriteSingle(Unk68); bw.WriteSingle(Unk6C); bw.WriteSingle(Unk70); bw.WriteSingle(Unk74); bw.WriteSingle(Unk78); bw.WriteSingle(Unk7C); bw.WriteInt32(-1); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteSingle(Unk98); bw.WriteSingle(Unk9C); bw.WriteInt32(UnkA0); bw.WriteSingle(Unk74); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteSingle(Width); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteSingle(UnkC4); }
internal override void WriteShapeData(BinaryWriterEx bw) { bw.WriteSingle(Radius); bw.WriteSingle(Height); }
protected override void Write(BinaryWriterEx bw) { bw.BigEndian = BigEndian; bw.VarintLong = Version == MQBVersion.DarkSouls2Scholar; bw.WriteASCII("MQB "); bw.WriteSByte((sbyte)(BigEndian ? -1 : 0)); bw.WriteByte(0); bw.WriteSByte((sbyte)(Version == MQBVersion.DarkSouls2Scholar ? -1 : 0)); bw.WriteByte(0); bw.WriteUInt32((uint)Version); switch (Version) { case MQBVersion.DarkSouls2: bw.WriteInt32(0x14); break; case MQBVersion.DarkSouls2Scholar: bw.WriteInt32(0x28); break; case MQBVersion.Bloodborne: bw.WriteInt32(0x20); break; case MQBVersion.DarkSouls3: bw.WriteInt32(0x24); break; default: throw new NotImplementedException($"Missing header size for version {Version}."); } bw.ReserveVarint("ResourcePathsOffset"); if (Version == MQBVersion.DarkSouls2Scholar) { bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteInt32(0); } else if (Version >= MQBVersion.Bloodborne) { bw.WriteInt32(1); bw.WriteInt32(0); bw.WriteInt32(0); if (Version >= MQBVersion.DarkSouls3) { bw.WriteInt32(0); } } bw.WriteFixStrW(Name, 0x40, 0x00); bw.WriteSingle(Framerate); bw.WriteInt32(Resources.Count); bw.WriteInt32(Cuts.Count); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteInt32(0); var allCustomData = new List <CustomData>(); var customDataValueOffsets = new List <long>(); for (int i = 0; i < Resources.Count; i++) { Resources[i].Write(bw, i, allCustomData, customDataValueOffsets); } var offsetsByDispos = new Dictionary <Disposition, long>(); for (int i = 0; i < Cuts.Count; i++) { Cuts[i].Write(bw, Version, offsetsByDispos, i, allCustomData, customDataValueOffsets); } for (int i = 0; i < Cuts.Count; i++) { Cuts[i].WriteTimelines(bw, Version, i); } for (int i = 0; i < Cuts.Count; i++) { Cuts[i].WriteTimelineCustomData(bw, i, allCustomData, customDataValueOffsets); } for (int i = 0; i < Cuts.Count; i++) { Cuts[i].WriteDisposOffsets(bw, offsetsByDispos, i); } bw.FillVarint("ResourcePathsOffset", bw.Position); for (int i = 0; i < Resources.Count; i++) { bw.ReserveVarint($"ResourcePathOffset{i}"); } bw.WriteUTF16(ResourceDirectory, true); for (int i = 0; i < Resources.Count; i++) { if (Resources[i].Path == null) { bw.FillVarint($"ResourcePathOffset{i}", 0); } else { bw.FillVarint($"ResourcePathOffset{i}", bw.Position); bw.WriteUTF16(Resources[i].Path, true); } } // I know this is weird, but trust me. if (Version >= MQBVersion.Bloodborne) { bw.WriteInt16(0); bw.Pad(4); } for (int i = 0; i < allCustomData.Count; i++) { allCustomData[i].WriteSequences(bw, i, customDataValueOffsets[i]); } for (int i = 0; i < allCustomData.Count; i++) { allCustomData[i].WriteSequencePoints(bw, i); } }
internal override void WriteShapeData(BinaryWriterEx bw) { bw.WriteSingle(Width); bw.WriteSingle(Depth); bw.WriteSingle(Height); }
internal override void WriteSpecific(BinaryWriterEx bw, long start) { bw.FillInt64("TypeDataOffset", bw.Position - start); bw.WriteSingle(Radius); bw.WriteSingle(Height); }
internal void WriteCells(BinaryWriterEx bw, int i, Layout layout) { bw.FillInt64($"RowOffset{i}", bw.Position); for (int j = 0; j < layout.Count; j++) { Cell cell = Cells[j]; Layout.Entry entry = layout[j]; CellType type = entry.Type; object value = cell.Value; if (entry.Name != cell.Name || type != cell.Type) { throw new FormatException("Layout does not match cells."); } if (type == CellType.s8) { bw.WriteSByte((sbyte)value); } else if (type == CellType.u8 || type == CellType.x8) { bw.WriteByte((byte)value); } else if (type == CellType.s16) { bw.WriteInt16((short)value); } else if (type == CellType.u16 || type == CellType.x16) { bw.WriteUInt16((ushort)value); } else if (type == CellType.s32) { bw.WriteInt32((int)value); } else if (type == CellType.u32 || type == CellType.x32) { bw.WriteUInt32((uint)value); } else if (type == CellType.f32) { bw.WriteSingle((float)value); } else if (type == CellType.dummy8) { bw.WriteBytes((byte[])value); } else if (type == CellType.fixstr) { bw.WriteFixStr((string)value, entry.Size); } else if (type == CellType.fixstrW) { bw.WriteFixStrW((string)value, entry.Size); } else if (type == CellType.b8) { byte b = 0; int k; for (k = 0; k < 8; k++) { if (j + k >= layout.Count || layout[j + k].Type != CellType.b8) { break; } if ((bool)Cells[j + k].Value) { b |= (byte)(1 << k); } } j += k - 1; bw.WriteByte(b); } else if (type == CellType.b32) { byte[] b = new byte[4]; int k; for (k = 0; k < 32; k++) { if (j + k >= layout.Count || layout[j + k].Type != CellType.b32) { break; } if ((bool)Cells[j + k].Value) { b[k / 8] |= (byte)(1 << (k % 8)); } } j += k - 1; bw.WriteBytes(b); } } }
internal override void Write(BinaryWriterEx bw, int id) { base.Write(bw, id); bw.WriteSingle(UnkT00); bw.WriteSingle(UnkT04); bw.WriteSingle(UnkT08); bw.WriteSingle(UnkT0C); bw.WriteSingle(UnkT10); bw.WriteSingle(UnkT14); bw.WriteSingle(UnkT18); bw.WriteSingle(UnkT1C); bw.WriteSingle(UnkT20); bw.WriteSingle(UnkT24); bw.WriteSingle(UnkT28); bw.WriteSingle(UnkT2C); bw.WriteSingle(UnkT30); bw.WriteSingle(UnkT34); bw.WriteSingle(UnkT38); bw.WriteSingle(UnkT3C); }
internal void Write(BinaryWriterEx bw, int nameOffset, int version) { bw.WriteInt32(Unk00); bw.WriteInt32(Unk04); bw.WriteInt32(Unk08); bw.WriteInt32(Unk0C); bw.WriteInt32(nameOffset); bw.WriteInt32(0); bw.WriteInt32(Unk18); bw.WriteBoolean(Unk1C); bw.WriteByte((byte)DiffuseColor.r); bw.WriteByte((byte)DiffuseColor.g); bw.WriteByte((byte)DiffuseColor.b); bw.WriteSingle(DiffusePower); bw.WriteByte((byte)SpecularColor.r); bw.WriteByte((byte)SpecularColor.g); bw.WriteByte((byte)SpecularColor.b); bw.WriteBoolean(Unk27); bw.WriteSingle(SpecularPower); bw.WriteSingle(ConeAngle); bw.WriteSingle(Unk30); bw.WriteSingle(Unk34); bw.WriteVector3(Position); bw.WriteVector3(Rotation); bw.WriteInt32(Unk50); bw.WriteSingle(Unk54); bw.WriteSingle(Radius); bw.WriteInt32(Unk5C); bw.WriteInt32(0); bw.WriteInt32(Unk64); bw.WriteSingle(Unk68); bw.WriteSingle(Unk6C); bw.WriteSingle(Unk70); bw.WriteSingle(Unk74); bw.WriteSingle(Unk78); bw.WriteSingle(Unk7C); bw.WriteInt32(-1); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteSingle(Unk98); bw.WriteSingle(Unk9C); bw.WriteInt32(UnkA0); bw.WriteSingle(UnkA4); bw.WriteInt32(0); bw.WriteSingle(UnkAC); bw.WriteInt32(0); bw.WriteInt32(0); bw.WriteSingle(Width); bw.WriteSingle(UnkBC); bw.WriteInt32(UnkC0); bw.WriteSingle(UnkC4); if (version >= 16) { bw.WriteSingle(UnkC8); bw.WriteSingle(UnkCC); bw.WriteSingle(UnkD0); bw.WriteSingle(UnkD4); bw.WriteSingle(UnkD8); bw.WriteInt32(UnkDC); bw.WriteSingle(UnkE0); bw.WriteInt32(0); } }
internal void WriteCells(BinaryWriterEx bw, byte format2D, int index) { if ((format2D & 0x7F) < 4) { bw.FillUInt32($"RowOffset{index}", (uint)bw.Position); } else { bw.FillInt64($"RowOffset{index}", bw.Position); } int bitOffset = -1; PARAMDEF.DefType bitType = PARAMDEF.DefType.u8; uint bitValue = 0; for (int i = 0; i < Cells.Count; i++) { Cell cell = Cells[i]; object value = cell.Value; PARAMDEF.Field field = cell.Def; PARAMDEF.DefType type = field.DisplayType; if (type == PARAMDEF.DefType.s8) { bw.WriteSByte((sbyte)value); } else if (type == PARAMDEF.DefType.s16) { bw.WriteInt16((short)value); } else if (type == PARAMDEF.DefType.s32) { bw.WriteInt32((int)value); } else if (type == PARAMDEF.DefType.f32) { bw.WriteSingle((float)value); } else if (type == PARAMDEF.DefType.fixstr) { bw.WriteFixStr((string)value, field.ArrayLength); } else if (type == PARAMDEF.DefType.fixstrW) { bw.WriteFixStrW((string)value, field.ArrayLength * 2); } else if (ParamUtil.IsBitType(type)) { if (field.BitSize == -1) { if (type == PARAMDEF.DefType.u8) { bw.WriteByte((byte)value); } else if (type == PARAMDEF.DefType.u16) { bw.WriteUInt16((ushort)value); } else if (type == PARAMDEF.DefType.u32) { bw.WriteUInt32((uint)value); } else if (type == PARAMDEF.DefType.dummy8) { bw.WriteBytes((byte[])value); } } else { if (bitOffset == -1) { bitOffset = 0; bitType = type == PARAMDEF.DefType.dummy8 ? PARAMDEF.DefType.u8 : type; bitValue = 0; } uint shifted = 0; if (bitType == PARAMDEF.DefType.u8) { shifted = (byte)value; } else if (bitType == PARAMDEF.DefType.u16) { shifted = (ushort)value; } else if (bitType == PARAMDEF.DefType.u32) { shifted = (uint)value; } // Shift left first to clear any out-of-range bits shifted = shifted << (32 - field.BitSize) >> (32 - field.BitSize - bitOffset); bitValue |= shifted; bitOffset += field.BitSize; bool write = false; if (i == Cells.Count - 1) { write = true; } else { PARAMDEF.Field nextField = Cells[i + 1].Def; PARAMDEF.DefType nextType = nextField.DisplayType; int bitLimit = ParamUtil.GetBitLimit(bitType); if (!ParamUtil.IsBitType(nextType) || nextField.BitSize == -1 || bitOffset + nextField.BitSize > bitLimit || (nextType == PARAMDEF.DefType.dummy8 ? PARAMDEF.DefType.u8 : nextType) != bitType) { write = true; } } if (write) { bitOffset = -1; if (bitType == PARAMDEF.DefType.u8) { bw.WriteByte((byte)bitValue); } else if (bitType == PARAMDEF.DefType.u16) { bw.WriteUInt16((ushort)bitValue); } else if (bitType == PARAMDEF.DefType.u32) { bw.WriteUInt32(bitValue); } } } } else { throw new NotImplementedException($"Unsupported field type: {type}"); } } }
internal override void Write(BinaryWriterEx bw, int id) { base.Write(bw, id); bw.WriteVector3(Position); bw.WriteSingle(Degree); }