/// <summary> /// Writes the spotlight to a stream /// </summary> /// <param name="writer">Output stream</param> public void Write(EndianWriter writer) { writer.WriteSingle(near); writer.WriteSingle(far); writer.WriteInt32(DegToBAMS(insideAngle)); writer.WriteInt32(DegToBAMS(outsideAngle)); }
public static void Write(this Quaternion quaternion, EndianWriter writer) { writer.WriteSingle(quaternion.W); writer.WriteSingle(quaternion.X); writer.WriteSingle(quaternion.Y); writer.WriteSingle(quaternion.Z); }
/// <summary> /// Writes a Vector3 to a stream /// </summary> /// <param name="writer">Output stream</param> /// <param name="type">Datatype to write object as</param> public static void Write(this Vector3 vector, EndianWriter writer, IOType type) { switch (type) { case IOType.Short: writer.WriteInt16((short)vector.X); writer.WriteInt16((short)vector.Y); writer.WriteInt16((short)vector.Z); break; case IOType.Float: writer.WriteSingle(vector.X); writer.WriteSingle(vector.Y); writer.WriteSingle(vector.Z); break; case IOType.BAMS16: writer.WriteInt16((short)DegToBAMS(vector.X)); writer.WriteInt16((short)DegToBAMS(vector.Y)); writer.WriteInt16((short)DegToBAMS(vector.Z)); break; case IOType.BAMS32: writer.WriteInt32(DegToBAMS(vector.X)); writer.WriteInt32(DegToBAMS(vector.Y)); writer.WriteInt32(DegToBAMS(vector.Z)); break; default: throw new ArgumentException($"Type {type} not available for struct Vector3"); } }
/// <summary> /// Writes the landentrymotion to a stream /// </summary> /// <param name="writer">Output stream</param> /// <param name="labels">C struct labels</param> public void Write(EndianWriter writer, uint imageBase, bool DX, bool writeBuffer, Dictionary <string, uint> labels) { uint mdlAddr = Model.Write(writer, imageBase, labels); uint actionAddr = MotionAction.Write(writer, imageBase, DX, writeBuffer, labels); writer.WriteSingle(Frame); writer.WriteSingle(Step); writer.WriteSingle(MaxFrame); writer.WriteUInt32(mdlAddr); writer.WriteUInt32(actionAddr); writer.WriteUInt32(TexListPtr); }
/// <summary> /// Writes a Vector2 to a stream /// </summary> /// <param name="writer">Output stream</param> /// <param name="type">Datatype to write object as</param> public static void Write(this Vector2 vector, EndianWriter writer, IOType type) { switch (type) { case IOType.Short: writer.WriteInt16((short)vector.X); writer.WriteInt16((short)vector.Y); break; case IOType.Float: writer.WriteSingle(vector.X); writer.WriteSingle(vector.Y); break; default: throw new ArgumentException($"Type {type} not available for Vector2"); } }
public void Write(EndianWriter writer, Dictionary <Action, uint> actionAddresses, Dictionary <string, uint> labels) { writer.WriteSingle(Frame); writer.WriteSingle(Step); writer.WriteSingle(MaxFrame); if (!labels.TryGetValue(Model.Name, out uint mdlAddress)) { throw new NullReferenceException($"Model \"{Model.Name}\" has not been written yet / cannot be found in labels!"); } writer.WriteUInt32(mdlAddress); if (!actionAddresses.TryGetValue(MotionAction, out uint actionAddress)) { throw new NullReferenceException($"Model \"{Model.Name}\" has not been written yet / cannot be found in labels!"); } writer.WriteUInt32(actionAddress); writer.WriteUInt32(TexListPtr); }
/// <summary> /// Writes the landtable to a stream /// </summary> /// <param name="writer">Output stream</param> /// <param name="imageBase">Image base for all addresses</param> /// <param name="labels">C struct labels</param> /// <returns></returns> public uint Write(EndianWriter writer, uint imageBase, Dictionary <string, uint> labels) { // sort the landentries HashSet <Attach> attaches = new(); ushort visCount = 0; if (Format > LandtableFormat.SADX && Format != LandtableFormat.Buffer) { List <LandEntry> visual = new(); List <LandEntry> basic = new(); foreach (LandEntry le in Geometry) { if (le.Attach.Format == AttachFormat.BASIC) { basic.Add(le); } else { visual.Add(le); } attaches.Add(le.Attach); } Geometry.Clear(); Geometry.AddRange(visual); Geometry.AddRange(basic); visCount = (ushort)visual.Count; } else { foreach (LandEntry le in Geometry) { attaches.Add(le.Attach); } } foreach (LandEntryMotion lem in GeometryAnimations) { NJObject[] models = lem.Model.GetObjects(); foreach (NJObject mdl in models) { if (mdl.Attach != null) { attaches.Add(mdl.Attach); } } } // writing all attaches if (Format == LandtableFormat.Buffer) { foreach (var atc in attaches) { atc.WriteBuffer(writer, imageBase, labels); } } else { foreach (var atc in attaches) { atc.Write(writer, imageBase, false, labels); } } var t = labels.GroupBy(x => x.Value).Where(x => x.Count() > 1).ToList(); // write the landentry models foreach (LandEntry le in Geometry) { le.WriteModel(writer, imageBase, labels); } // write the landentry motion models foreach (LandEntryMotion lem in GeometryAnimations) { lem.Model.Write(writer, imageBase, labels); } Dictionary <Action, uint> actionAddresses = new(); // write the landentry motion animations foreach (LandEntryMotion lem in GeometryAnimations) { actionAddresses.Add(lem.MotionAction, lem.MotionAction.Write(writer, imageBase, Format == LandtableFormat.SADX, Format == LandtableFormat.Buffer, labels)); } // writing the geometry list uint geomAddr = 0; if (Geometry.Count > 0) { if (labels.ContainsKey(GeoName)) { geomAddr = labels[GeoName]; } else { geomAddr = writer.Position + imageBase; labels.AddLabel(GeoName, geomAddr); foreach (LandEntry le in Geometry) { le.Write(writer, Format, labels); } } } // writing the animation list uint animAddr = 0; if (GeometryAnimations.Count > 0) { if (labels.ContainsKey(GeoAnimName)) { animAddr = labels[GeoAnimName]; } else { animAddr = writer.Position + imageBase; labels.AddLabel(GeoAnimName, animAddr); foreach (LandEntryMotion lem in GeometryAnimations) { lem.Write(writer, actionAddresses, labels); } } } // write the texture name uint texNameAddr = 0; if (TextureFileName != null) { texNameAddr = writer.Position + imageBase; writer.Write(Encoding.ASCII.GetBytes(TextureFileName)); writer.Write(new byte[1]); } // write the landtable struct itself uint address = writer.Position + imageBase; writer.WriteUInt16((ushort)Geometry.Count); if (Format < LandtableFormat.SA2) // sa1 + sadx { writer.WriteUInt16((ushort)GeometryAnimations.Count); writer.WriteUInt32((uint)Attributes); writer.WriteSingle(DrawDistance); writer.WriteUInt32(geomAddr); writer.WriteUInt32(animAddr); writer.WriteUInt32(texNameAddr); writer.WriteUInt32(TexListPtr); writer.WriteUInt64(0); // two unused pointers } else // sa2 + sa2b { writer.WriteUInt16(visCount); writer.WriteUInt64(0); // todo: figure out what these do writer.WriteSingle(DrawDistance); writer.WriteUInt32(geomAddr); writer.WriteUInt32(animAddr); writer.WriteUInt32(texNameAddr); writer.WriteUInt32(TexListPtr); } labels.AddLabel(Name, address); return(address); }