public void Write(Stream output, STULib.Types.Map.Map map, STULib.Types.Map.Map detail1, STULib.Types.Map.Map detail2, STULib.Types.Map.Map entities, STULib.Types.Map.Map lights, string name, IDataWriter modelFormat, FindLogic.Combo.ComboInfo info) { if (modelFormat == null) { modelFormat = new OWMDLWriter(); } using (BinaryWriter writer = new BinaryWriter(output)) { writer.Write((ushort)1); // version major writer.Write((ushort)1); // version minor if (name.Length == 0) { writer.Write((byte)0); } else { writer.Write(name); } uint size = 0; foreach (IMapFormat t in map.Records) { if (t != null && t.GetType() != typeof(Map01)) { continue; } size++; } writer.Write(size); // nr objects size = 1; foreach (IMapFormat t in detail1.Records) { if (t != null && t.GetType() != typeof(Map02)) { continue; } size++; } foreach (IMapFormat t in detail2.Records) { if (t != null && t.GetType() != typeof(Map08)) { continue; } size++; } foreach (IMapFormat t in entities.Records) { if (t != null && t.GetType() != typeof(MapEntity)) { continue; } if (((MapEntity)t).Model == 0) { continue; } size++; } writer.Write(size); // nr details // Extension 1.1 - Lights size = 0; foreach (IMapFormat t in lights.Records) { if (t != null && t.GetType() != typeof(Map09)) { continue; } size++; } writer.Write(size); // nr Lights foreach (IMapFormat t in map.Records) { if (t != null && t.GetType() != typeof(Map01)) { continue; } Map01 obj = (Map01)t; FindLogic.Combo.Find(info, obj.Header.Model); FindLogic.Combo.ModelInfoNew modelInfo = info.Models[obj.Header.Model]; string modelFn = $"Models\\{modelInfo.GetName()}\\{modelInfo.GetNameIndex()}{modelFormat.Format}"; writer.Write(modelFn); writer.Write(obj.Header.groupCount); for (int j = 0; j < obj.Header.groupCount; ++j) { Map01.Map01Group group = obj.Groups[j]; FindLogic.Combo.Find(info, group.ModelLook, null, new FindLogic.Combo.ComboContext { Model = obj.Header.Model }); string materialFn; if (!info.ModelLooks.ContainsKey(group.ModelLook)) { materialFn = ""; // encrypted } else { FindLogic.Combo.ModelLookInfo modelLookInfo = info.ModelLooks[group.ModelLook]; materialFn = $"Models\\{modelInfo.GetName()}\\ModelLooks\\{modelLookInfo.GetNameIndex()}.owmat"; } writer.Write(materialFn); writer.Write(group.recordCount); for (int k = 0; k < group.recordCount; ++k) { Map01.Map01GroupRecord record = obj.Records[j][k]; writer.Write(record.position.x); writer.Write(record.position.y); writer.Write(record.position.z); writer.Write(record.scale.x); writer.Write(record.scale.y); writer.Write(record.scale.z); writer.Write(record.rotation.x); writer.Write(record.rotation.y); writer.Write(record.rotation.z); writer.Write(record.rotation.w); } } } // todo: broken? writer.Write($"Models\\physics\\physics.{modelFormat.Format}"); writer.Write((byte)0); writer.Write(0.0f); writer.Write(0.0f); writer.Write(0.0f); writer.Write(1.0f); writer.Write(1.0f); writer.Write(1.0f); writer.Write(0.0f); writer.Write(0.0f); writer.Write(0.0f); writer.Write(1.0f); foreach (IMapFormat t in detail1.Records) { if (t != null && t.GetType() != typeof(Map02)) { continue; } Map02 obj = (Map02)t; FindLogic.Combo.Find(info, obj.Header.Model); FindLogic.Combo.Find(info, obj.Header.ModelLook, null, new FindLogic.Combo.ComboContext { Model = obj.Header.Model }); FindLogic.Combo.ModelInfoNew modelInfo = info.Models[obj.Header.Model]; FindLogic.Combo.ModelLookInfo modelLookInfo = info.ModelLooks[obj.Header.ModelLook]; string modelFn = $"Models\\{modelInfo.GetName()}\\{modelInfo.GetNameIndex()}{modelFormat.Format}"; string matFn = $"Models\\{modelInfo.GetName()}\\ModelLooks\\{modelLookInfo.GetNameIndex()}.owmat"; writer.Write(modelFn); writer.Write(matFn); writer.Write(obj.Header.position.x); writer.Write(obj.Header.position.y); writer.Write(obj.Header.position.z); writer.Write(obj.Header.scale.x); writer.Write(obj.Header.scale.y); writer.Write(obj.Header.scale.z); writer.Write(obj.Header.rotation.x); writer.Write(obj.Header.rotation.y); writer.Write(obj.Header.rotation.z); writer.Write(obj.Header.rotation.w); } foreach (IMapFormat t in detail2.Records) { if (t != null && t.GetType() != typeof(Map08)) { continue; } Map08 obj = (Map08)t; FindLogic.Combo.Find(info, obj.Header.Model); FindLogic.Combo.Find(info, obj.Header.ModelLook, null, new FindLogic.Combo.ComboContext { Model = obj.Header.Model }); FindLogic.Combo.ModelInfoNew modelInfo = info.Models[obj.Header.Model]; FindLogic.Combo.ModelLookInfo modelLookInfo = info.ModelLooks[obj.Header.ModelLook]; string modelFn = $"Models\\{modelInfo.GetName()}\\{modelInfo.GetNameIndex()}{modelFormat.Format}"; string matFn = $"Models\\{modelInfo.GetName()}\\ModelLooks\\{modelLookInfo.GetNameIndex()}.owmat"; writer.Write(modelFn); writer.Write(matFn); writer.Write(obj.Header.position.x); writer.Write(obj.Header.position.y); writer.Write(obj.Header.position.z); writer.Write(obj.Header.scale.x); writer.Write(obj.Header.scale.y); writer.Write(obj.Header.scale.z); writer.Write(obj.Header.rotation.x); writer.Write(obj.Header.rotation.y); writer.Write(obj.Header.rotation.z); writer.Write(obj.Header.rotation.w); } foreach (IMapFormat t in entities.Records) { if (t != null && t.GetType() != typeof(MapEntity)) { continue; } MapEntity mapEntity = (MapEntity)t; if (mapEntity.Model == 0) { continue; } ulong modelLook = mapEntity.ModelLook; foreach (object container in mapEntity.STUContainers) { ISTU realContainer = (ISTU)container; foreach (Common.STUInstance instance in realContainer.Instances) { if (instance is STUModelComponentInstanceData modelComponentInstanceData) { if (modelComponentInstanceData.Look != 0) { modelLook = modelComponentInstanceData.Look; } } } } FindLogic.Combo.Find(info, mapEntity.Model); FindLogic.Combo.Find(info, modelLook, null, new FindLogic.Combo.ComboContext { Model = mapEntity.Model }); FindLogic.Combo.ModelInfoNew modelInfo = info.Models[mapEntity.Model]; string matFn = ""; if (info.ModelLooks.ContainsKey(modelLook)) { FindLogic.Combo.ModelLookInfo modelLookInfo = info.ModelLooks[modelLook]; matFn = $"Models\\{modelInfo.GetName()}\\ModelLooks\\{modelLookInfo.GetNameIndex()}.owmat"; } string modelFn = $"Models\\{modelInfo.GetName()}\\{modelInfo.GetNameIndex()}{modelFormat.Format}"; writer.Write(modelFn); writer.Write(matFn); writer.Write(mapEntity.Header.Position.x); writer.Write(mapEntity.Header.Position.y); writer.Write(mapEntity.Header.Position.z); writer.Write(mapEntity.Header.Scale.x); writer.Write(mapEntity.Header.Scale.y); writer.Write(mapEntity.Header.Scale.z); writer.Write(mapEntity.Header.Rotation.x); writer.Write(mapEntity.Header.Rotation.y); writer.Write(mapEntity.Header.Rotation.z); writer.Write(mapEntity.Header.Rotation.w); } // Extension 1.1 - Lights foreach (IMapFormat t in lights.Records) { if (t != null && t.GetType() != typeof(Map09)) { continue; } Map09 obj = (Map09)t; writer.Write(obj.Header.position.x); writer.Write(obj.Header.position.y); writer.Write(obj.Header.position.z); writer.Write(obj.Header.rotation.x); writer.Write(obj.Header.rotation.y); writer.Write(obj.Header.rotation.z); writer.Write(obj.Header.rotation.w); writer.Write(obj.Header.LightType); writer.Write(obj.Header.LightFOV); writer.Write(obj.Header.Color.x); writer.Write(obj.Header.Color.y); writer.Write(obj.Header.Color.z); writer.Write(obj.Header.unknown1A); writer.Write(obj.Header.unknown1B); writer.Write(obj.Header.unknown2A); writer.Write(obj.Header.unknown2B); writer.Write(obj.Header.unknown2C); writer.Write(obj.Header.unknown2D); writer.Write(obj.Header.unknown3A); writer.Write(obj.Header.unknown3B); writer.Write(obj.Header.unknownPos1.x); writer.Write(obj.Header.unknownPos1.y); writer.Write(obj.Header.unknownPos1.z); writer.Write(obj.Header.unknownQuat1.x); writer.Write(obj.Header.unknownQuat1.y); writer.Write(obj.Header.unknownQuat1.z); writer.Write(obj.Header.unknownQuat1.w); writer.Write(obj.Header.unknownPos2.x); writer.Write(obj.Header.unknownPos2.y); writer.Write(obj.Header.unknownPos2.z); writer.Write(obj.Header.unknownQuat2.x); writer.Write(obj.Header.unknownQuat2.y); writer.Write(obj.Header.unknownQuat2.z); writer.Write(obj.Header.unknownQuat2.w); writer.Write(obj.Header.unknownPos3.x); writer.Write(obj.Header.unknownPos3.y); writer.Write(obj.Header.unknownPos3.z); writer.Write(obj.Header.unknownQuat3.x); writer.Write(obj.Header.unknownQuat3.y); writer.Write(obj.Header.unknownQuat3.z); writer.Write(obj.Header.unknownQuat3.w); writer.Write(obj.Header.unknown4A); writer.Write(obj.Header.unknown4B); writer.Write(obj.Header.unknown5); writer.Write(obj.Header.unknown6A); writer.Write(obj.Header.unknown6B); writer.Write(obj.Header.unknown7A); writer.Write(obj.Header.unknown7B); } } }
public Dictionary <ulong, List <string> >[] Write(Stream output, Map map, Map detail1, Map detail2, Map props, Map lights, string name, IDataWriter modelFormat) { if (modelFormat == null) { modelFormat = new OWMDLWriter(); } //Console.Out.WriteLine("Writing OWMAP"); using (BinaryWriter writer = new BinaryWriter(output)) { writer.Write((ushort)1); // version major writer.Write((ushort)1); // version minor if (name.Length == 0) { writer.Write((byte)0); } else { writer.Write(name); } uint size = 0; for (int i = 0; i < map.Records.Length; ++i) { if (map.Records[i] != null && map.Records[i].GetType() != typeof(Map01)) { continue; } size++; } writer.Write(size); // nr objects size = 1; for (int i = 0; i < detail1.Records.Length; ++i) { if (detail1.Records[i] != null && detail1.Records[i].GetType() != typeof(Map02)) { continue; } size++; } for (int i = 0; i < detail2.Records.Length; ++i) { if (detail2.Records[i] != null && detail2.Records[i].GetType() != typeof(Map08)) { continue; } size++; } for (int i = 0; i < props.Records.Length; ++i) { if (props.Records[i] != null && props.Records[i].GetType() != typeof(Map0B)) { continue; } if (((Map0B)props.Records[i]).ModelKey == 0) { continue; } size++; } writer.Write(size); // nr details // Extension 1.1 - Lights size = 0; for (int i = 0; i < lights.Records.Length; ++i) { if (lights.Records[i] != null && lights.Records[i].GetType() != typeof(Map09)) { continue; } size++; } writer.Write(size); // nr Lights Dictionary <ulong, List <string> >[] ret = new Dictionary <ulong, List <string> > [2]; ret[0] = new Dictionary <ulong, List <string> >(); ret[1] = new Dictionary <ulong, List <string> >(); for (int i = 0; i < map.Records.Length; ++i) { if (map.Records[i] != null && map.Records[i].GetType() != typeof(Map01)) { continue; } Map01 obj = (Map01)map.Records[i]; string modelFn = $"{GUID.Index(obj.Header.model):X12}{modelFormat.Format}"; writer.Write(modelFn); if (!ret[0].ContainsKey(obj.Header.model)) { ret[0].Add(obj.Header.model, new List <string>()); } ret[0][obj.Header.model].Add(modelFn); writer.Write(obj.Header.groupCount); for (int j = 0; j < obj.Header.groupCount; ++j) { Map01.Map01Group group = obj.Groups[j]; string materialFn = $"{GUID.Index(obj.Header.model):X12}_{GUID.Index(@group.material):X12}.owmat"; writer.Write(materialFn); if (!ret[1].ContainsKey(group.material)) { ret[1].Add(group.material, new List <string>()); } ret[1][group.material].Add(materialFn); writer.Write(group.recordCount); for (int k = 0; k < group.recordCount; ++k) { Map01.Map01GroupRecord record = obj.Records[j][k]; writer.Write(record.position.x); writer.Write(record.position.y); writer.Write(record.position.z); writer.Write(record.scale.x); writer.Write(record.scale.y); writer.Write(record.scale.z); writer.Write(record.rotation.x); writer.Write(record.rotation.y); writer.Write(record.rotation.z); writer.Write(record.rotation.w); } } } writer.Write($"physics.{modelFormat.Format}"); writer.Write((byte)0); writer.Write(0.0f); writer.Write(0.0f); writer.Write(0.0f); writer.Write(1.0f); writer.Write(1.0f); writer.Write(1.0f); writer.Write(0.0f); writer.Write(0.0f); writer.Write(0.0f); writer.Write(1.0f); for (int i = 0; i < detail1.Records.Length; ++i) { if (detail1.Records[i] != null && detail1.Records[i].GetType() != typeof(Map02)) { continue; } Map02 obj = (Map02)detail1.Records[i]; string modelFn = $"{GUID.LongKey(obj.Header.model):X12}{modelFormat.Format}"; string matFn = $"{GUID.LongKey(obj.Header.model):X12}.owmat"; writer.Write(modelFn); writer.Write(matFn); writer.Write(obj.Header.position.x); writer.Write(obj.Header.position.y); writer.Write(obj.Header.position.z); writer.Write(obj.Header.scale.x); writer.Write(obj.Header.scale.y); writer.Write(obj.Header.scale.z); writer.Write(obj.Header.rotation.x); writer.Write(obj.Header.rotation.y); writer.Write(obj.Header.rotation.z); writer.Write(obj.Header.rotation.w); if (!ret[0].ContainsKey(obj.Header.model)) { ret[0].Add(obj.Header.model, new List <string>()); } ret[0][obj.Header.model].Add(modelFn); if (!ret[1].ContainsKey(obj.Header.material)) { ret[1].Add(obj.Header.material, new List <string>()); } ret[1][obj.Header.material].Add(matFn); } for (int i = 0; i < detail2.Records.Length; ++i) { if (detail2.Records[i] != null && detail2.Records[i].GetType() != typeof(Map08)) { continue; } Map08 obj = (Map08)detail2.Records[i]; string modelFn = $"{GUID.LongKey(obj.Header.model):X12}{modelFormat.Format}"; string matFn = $"{GUID.LongKey(obj.Header.model):X12}.owmat"; writer.Write(modelFn); writer.Write(matFn); writer.Write(obj.Header.position.x); writer.Write(obj.Header.position.y); writer.Write(obj.Header.position.z); writer.Write(obj.Header.scale.x); writer.Write(obj.Header.scale.y); writer.Write(obj.Header.scale.z); writer.Write(obj.Header.rotation.x); writer.Write(obj.Header.rotation.y); writer.Write(obj.Header.rotation.z); writer.Write(obj.Header.rotation.w); if (!ret[0].ContainsKey(obj.Header.model)) { ret[0].Add(obj.Header.model, new List <string>()); } ret[0][obj.Header.model].Add(modelFn); if (!ret[1].ContainsKey(obj.Header.material)) { ret[1].Add(obj.Header.material, new List <string>()); } ret[1][obj.Header.material].Add(matFn); } for (int i = 0; i < props.Records.Length; ++i) { if (props.Records[i] != null && props.Records[i].GetType() != typeof(Map0B)) { continue; } Map0B obj = (Map0B)props.Records[i]; if (obj.ModelKey == 0) { continue; } string modelFn = $"{GUID.LongKey(obj.ModelKey):X12}{modelFormat.Format}"; string matFn = $"{GUID.LongKey(obj.MaterialKey):X12}.owmat"; writer.Write(modelFn); writer.Write(matFn); writer.Write(obj.Header.position.x); writer.Write(obj.Header.position.y); writer.Write(obj.Header.position.z); writer.Write(obj.Header.scale.x); writer.Write(obj.Header.scale.y); writer.Write(obj.Header.scale.z); writer.Write(obj.Header.rotation.x); writer.Write(obj.Header.rotation.y); writer.Write(obj.Header.rotation.z); writer.Write(obj.Header.rotation.w); if (!ret[0].ContainsKey(obj.ModelKey)) { ret[0].Add(obj.ModelKey, new List <string>()); } ret[0][obj.ModelKey].Add(modelFn); if (!ret[1].ContainsKey(obj.MaterialKey)) { ret[1].Add(obj.MaterialKey, new List <string>()); } ret[1][obj.MaterialKey].Add(matFn); } // Extension 1.1 - Lights for (int i = 0; i < lights.Records.Length; ++i) { if (lights.Records[i] != null && lights.Records[i].GetType() != typeof(Map09)) { continue; } Map09 obj = (Map09)lights.Records[i]; writer.Write(obj.Header.position.x); writer.Write(obj.Header.position.y); writer.Write(obj.Header.position.z); writer.Write(obj.Header.rotation.x); writer.Write(obj.Header.rotation.y); writer.Write(obj.Header.rotation.z); writer.Write(obj.Header.rotation.w); writer.Write(obj.Header.LightType); writer.Write(obj.Header.LightFOV); writer.Write(obj.Header.Color.x); writer.Write(obj.Header.Color.y); writer.Write(obj.Header.Color.z); writer.Write(obj.Header.unknown1A); writer.Write(obj.Header.unknown1B); writer.Write(obj.Header.unknown2A); writer.Write(obj.Header.unknown2B); writer.Write(obj.Header.unknown2C); writer.Write(obj.Header.unknown2D); writer.Write(obj.Header.unknown3A); writer.Write(obj.Header.unknown3B); writer.Write(obj.Header.unknownPos1.x); writer.Write(obj.Header.unknownPos1.y); writer.Write(obj.Header.unknownPos1.z); writer.Write(obj.Header.unknownQuat1.x); writer.Write(obj.Header.unknownQuat1.y); writer.Write(obj.Header.unknownQuat1.z); writer.Write(obj.Header.unknownQuat1.w); writer.Write(obj.Header.unknownPos2.x); writer.Write(obj.Header.unknownPos2.y); writer.Write(obj.Header.unknownPos2.z); writer.Write(obj.Header.unknownQuat2.x); writer.Write(obj.Header.unknownQuat2.y); writer.Write(obj.Header.unknownQuat2.z); writer.Write(obj.Header.unknownQuat2.w); writer.Write(obj.Header.unknownPos3.x); writer.Write(obj.Header.unknownPos3.y); writer.Write(obj.Header.unknownPos3.z); writer.Write(obj.Header.unknownQuat3.x); writer.Write(obj.Header.unknownQuat3.y); writer.Write(obj.Header.unknownQuat3.z); writer.Write(obj.Header.unknownQuat3.w); writer.Write(obj.Header.unknown4A); writer.Write(obj.Header.unknown4B); writer.Write(obj.Header.unknown5); writer.Write(obj.Header.unknown6A); writer.Write(obj.Header.unknown6B); writer.Write(obj.Header.unknown7A); writer.Write(obj.Header.unknown7B); } return(ret); } }