public void Clone(GTAObject other, bool clonePos = true) { this.IsMapObject = other.IsMapObject; this.LegacyID = other.LegacyID; this.SAMPID = other.SAMPID; this.ModelName = other.ModelName; this.DffName = other.DffName; this.TxdName = other.TxdName; this.MeshCount = other.MeshCount; this.VirtualWord = other.VirtualWord; this.InteriorID = other.InteriorID; this.DrawDist = other.DrawDist; this.StreamDist = other.StreamDist; if (clonePos) { this.posX = other.posX; this.posY = other.posY; this.posZ = other.posZ; this.rotX = other.rotX; this.rotY = other.rotY; this.rotZ = other.rotZ; } }
public static IDEConvertResult ToArtconf(string file, bool appendArtconf, string artconfName = "artconfig.txt", bool noLod = false, string dir = "") { StreamReader ideReader = null; StreamWriter artconfWriter = null; int sampidCount = -1000; try { if (appendArtconf) { sampidCount = Utils.GetLatestIDFromArtconf(artconfName); if (sampidCount == -1) { sampidCount = -1000; } else { sampidCount -= 1; } } ideReader = new StreamReader(file); if (appendArtconf) { if (File.Exists(artconfName)) { artconfWriter = new StreamWriter(artconfName, true); } else { artconfWriter = new StreamWriter(artconfName); } } else { artconfWriter = new StreamWriter(artconfName); } } catch { Console.WriteLine("ERROR : error while openning IDE file. Check your paths !"); return(null); } if (Utils.VerboseOpt) { Console.WriteLine($"Reading and parsing {file} ..."); } IDEConvertResult result = new IDEConvertResult(); bool insideObjsSect = false; uint lineCount = 0; while (!ideReader.EndOfStream) { string line = ideReader.ReadLine(); lineCount += 1; if (line == null) { continue; } if (line.StartsWith("#")) { continue; } if (line == "objs") { insideObjsSect = true; continue; } if (insideObjsSect && line == "end") { insideObjsSect = false; } if (insideObjsSect == false) { continue; } string[] lineParams = line.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); if (lineParams.Length < 5 || lineParams.Length > 8) { continue; } try { if (noLod) { if (lineParams[1].StartsWith("lod") || lineParams[1].StartsWith("LOD")) { continue; } } GTAObject tmpObj = new GTAObject(); tmpObj.LegacyID = tmpObj.LegacyID = UInt32.Parse(lineParams[0]); tmpObj.ModelName = lineParams[1]; tmpObj.DffName = lineParams[1] + ".dff"; tmpObj.TxdName = lineParams[2] + ".txd"; switch (lineParams.Length) { case 5: { tmpObj.DrawDist = double.Parse(lineParams[3]); tmpObj.IDEFlags = UInt32.Parse(lineParams[4]); break; } case 6: { tmpObj.MeshCount = uint.Parse(lineParams[3]); tmpObj.DrawDist = double.Parse(lineParams[4]); tmpObj.IDEFlags = UInt32.Parse(lineParams[5]); break; } case 7: { tmpObj.MeshCount = uint.Parse(lineParams[3]); tmpObj.DrawDist = double.Parse(lineParams[4]); tmpObj.IDEFlags = UInt32.Parse(lineParams[6]); break; } case 8: { tmpObj.MeshCount = uint.Parse(lineParams[3]); tmpObj.DrawDist = double.Parse(lineParams[4]); tmpObj.IDEFlags = UInt32.Parse(lineParams[7]); break; } default: break; } result.Objects.Add(tmpObj); } catch (Exception e) { result.ErrorCount += 1; if (Utils.VerboseOpt) { Console.WriteLine($"\t[IDE] Error at line {lineCount}.\n\tExcept : {e.Message}"); } } } ideReader.Close(); if (Utils.VerboseOpt) { Console.WriteLine($"\tFound {result.Objects.Count} objects. Errors : {result.ErrorCount}\n"); } if (Utils.VerboseOpt) { Console.Write($"Writing SAMP {artconfName} ..."); } foreach (GTAObject obj in result.Objects) { obj.SAMPID = sampidCount; artconfWriter.WriteLine($"AddSimpleModel(-1, 19379, {sampidCount}, \"{(dir == "" ? "" : dir+"/")}{obj.DffName}\", \"{(dir == "" ? "" : dir + "/")}{obj.TxdName}\");"); sampidCount -= 1; } result.LastSAMPID = sampidCount; artconfWriter.Close(); if (Utils.VerboseOpt) { Console.Write(" Done !\n\n"); } return(result); }
public static IPLConvertResult ToCreateDynamicObject(string file, string outputPwn, IdeConverter.IDEConvertResult ideResult, bool appendPawnFile = false, bool acceptWithoutCustomID = false, IPLConvertOptions options = null) { StreamReader iplReader = null; StreamWriter streamWriter = null; try { iplReader = new StreamReader(file); streamWriter = new StreamWriter(outputPwn, appendPawnFile); } catch { Console.WriteLine("ERROR : error while openning IPL file. Check your paths !"); return(null); } if (Utils.VerboseOpt) { Console.WriteLine($"Reading and parsing {file} ..."); } bool insideInstSect = false; IPLConvertResult result = new IPLConvertResult(); uint lineCount = 0; while (!iplReader.EndOfStream) { string line = iplReader.ReadLine(); lineCount += 1; if (line == null) { continue; } if (line == "inst") { insideInstSect = true; continue; } if (insideInstSect && line == "end") { insideInstSect = false; } if (insideInstSect == false) { continue; } string[] lineParams = line.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); if (lineParams.Length != 11) { continue; } try { uint LegacyID = UInt32.Parse(lineParams[0]); GTAObject tmpObj = null; if (ideResult != null) { var res = ideResult.Objects.Find(obj => obj.LegacyID == LegacyID); if (res != null) { tmpObj = new GTAObject(); tmpObj.Clone(res); } } if (tmpObj == null) { result.ObjectsWithoutCustomID += 1; if (ideResult != null) { if (!acceptWithoutCustomID) { continue; } } tmpObj = new GTAObject(); tmpObj.LegacyID = LegacyID; tmpObj.ModelName = lineParams[1]; tmpObj.DffName = lineParams[1] + ".dff"; tmpObj.TxdName = lineParams[1] + ".txd"; tmpObj.DrawDist = 0; tmpObj.SAMPID = (int)LegacyID; } tmpObj.InteriorID = UInt32.Parse(lineParams[2]); tmpObj.posX = double.Parse(lineParams[3], CultureInfo.InvariantCulture) + (options == null ? 0 : options.moddx); tmpObj.posY = double.Parse(lineParams[4], CultureInfo.InvariantCulture) + (options == null ? 0 : options.moddy); tmpObj.posZ = double.Parse(lineParams[5], CultureInfo.InvariantCulture) + (options == null ? 0 : options.moddz); double tmpRotX = float.Parse(lineParams[6], CultureInfo.InvariantCulture); double tmpRotY = float.Parse(lineParams[7], CultureInfo.InvariantCulture); double tmpRotZ = float.Parse(lineParams[8], CultureInfo.InvariantCulture); double tmpRotW = float.Parse(lineParams[9], CultureInfo.InvariantCulture); // Utils.QuatToEuler(tmpRotX, tmpRotY, tmpRotZ, tmpRotW, ref tmpObj.rotX, ref tmpObj.rotY, ref tmpObj.rotZ); Quaternions.EulerRot objRot = new Quaternions.EulerRot(); if (Utils.QuatOpt) { objRot = Quaternions.JS.ToEulerAngles(tmpRotX, tmpRotY, tmpRotZ, tmpRotW); } else { objRot = Quaternions.MTA.ToEulerAngles(tmpRotX, tmpRotY, tmpRotZ, tmpRotW); } tmpObj.rotX = objRot.x; tmpObj.rotY = objRot.y; tmpObj.rotZ = objRot.z; tmpObj.IsMapObject = true; if (options != null) { if (options.drawd != -1) { tmpObj.DrawDist = options.drawd; } if (options.streamd != -1) { tmpObj.StreamDist = options.streamd; } } if (result.MapObjects.FindAll(obj => obj.SAMPID == tmpObj.SAMPID && obj.posX == tmpObj.posX && obj.posY == tmpObj.posY && obj.posZ == tmpObj.posZ && obj.rotX == tmpObj.rotX && obj.rotY == tmpObj.rotY && obj.rotZ == tmpObj.rotZ).Count > 0) { Console.WriteLine($"\tIPL Duplicate at line {lineCount}."); } result.MapObjects.Add(tmpObj); } catch (Exception e) { result.ErrorCount += 1; if (Utils.VerboseOpt) { Console.WriteLine($"\t[IDE] Error at line {lineCount}.\n\tExcept : {e.Message}"); } } } iplReader.Close(); if (Utils.VerboseOpt) { Console.WriteLine($"\tFound {result.MapObjects.FindAll(obj => obj.IsMapObject == true).Count} map objects.\n\tErrors : {result.ErrorCount}\n\tObjects without custom IDs : {result.ObjectsWithoutCustomID}"); if (ideResult != null) { Console.WriteLine($"\t{ideResult.Objects.FindAll(obj => obj.IsMapObject == false).Count} objects are not on the map !"); } } if (Utils.VerboseOpt) { Console.Write($"\nWriting SAMP Pawn Streamer Code in {outputPwn} ..."); } foreach (GTAObject obj in result.MapObjects) { streamWriter.WriteLine($"CreateDynamicObject({obj.SAMPID}, {obj.posX.ToString("F", CultureInfo.InvariantCulture)}, {obj.posY.ToString("F", CultureInfo.InvariantCulture)}, {obj.posZ.ToString("F", CultureInfo.InvariantCulture)}, " + $"{obj.rotX.ToString("F", CultureInfo.InvariantCulture)}, {obj.rotY.ToString("F", CultureInfo.InvariantCulture)}, {obj.rotZ.ToString("F", CultureInfo.InvariantCulture)}, -1, {obj.InteriorID}, -1," + $"{(obj.StreamDist == 0 ? "STREAMER_OBJECT_SD" : obj.StreamDist.ToString("F2", CultureInfo.InvariantCulture))}, {(obj.DrawDist == 0 ? "STREAMER_OBJECT_DD" : obj.DrawDist.ToString("F2", CultureInfo.InvariantCulture))});" + $" // {obj.ModelName}"); } streamWriter.Close(); if (Utils.VerboseOpt) { Console.Write(" Done !\n"); } return(result); }