|  | @@ -51,6 +51,67 @@ namespace ArcToolkitCLI.Commands.Converters
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          int ToNei(string filePath)
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  | +            string nameNoExt = Path.GetFileNameWithoutExtension(filePath);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            List<string[]> values = new List<string[]>();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            int cols = 0;
 | 
	
		
			
				|  |  | +            int rows = 0;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            using (var tr = File.OpenText(filePath))
 | 
	
		
			
				|  |  | +            {
 | 
	
		
			
				|  |  | +                string line;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                while ((line = tr.ReadLine()) != null)
 | 
	
		
			
				|  |  | +                {
 | 
	
		
			
				|  |  | +                    var colValues = line.Split(new []{ValueSeparator}, StringSplitOptions.None);
 | 
	
		
			
				|  |  | +                    if(colValues.Length == 0)
 | 
	
		
			
				|  |  | +                        continue;
 | 
	
		
			
				|  |  | +                    cols = Math.Max(cols, colValues.Length);
 | 
	
		
			
				|  |  | +                    values.Add(colValues);
 | 
	
		
			
				|  |  | +                    rows++;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            using (var ms = new MemoryStream())
 | 
	
		
			
				|  |  | +            {
 | 
	
		
			
				|  |  | +                using (var bw = new BinaryWriter(ms))
 | 
	
		
			
				|  |  | +                {
 | 
	
		
			
				|  |  | +                    bw.Write(NEI_MAGIC);
 | 
	
		
			
				|  |  | +                    bw.Write(cols);
 | 
	
		
			
				|  |  | +                    bw.Write(rows);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    int totalLength = 0;
 | 
	
		
			
				|  |  | +                    foreach (var row in values)
 | 
	
		
			
				|  |  | +                    {
 | 
	
		
			
				|  |  | +                        for (int colIndex = 0; colIndex < cols; colIndex++)
 | 
	
		
			
				|  |  | +                        {
 | 
	
		
			
				|  |  | +                            bw.Write(totalLength);
 | 
	
		
			
				|  |  | +                            var strLen = colIndex < row.Length ? row[colIndex].Length : 0;
 | 
	
		
			
				|  |  | +                            bw.Write(strLen);
 | 
	
		
			
				|  |  | +                            totalLength += strLen;
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    foreach (var row in values)
 | 
	
		
			
				|  |  | +                    {
 | 
	
		
			
				|  |  | +                        for (int colIndex = 0; colIndex < cols; colIndex++)
 | 
	
		
			
				|  |  | +                        {
 | 
	
		
			
				|  |  | +                            if(colIndex < row.Length)
 | 
	
		
			
				|  |  | +                                bw.Write(ShiftJisEncoding.GetBytes(row[colIndex]));
 | 
	
		
			
				|  |  | +                            bw.Write(0x00); // Add null terminator
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                var data = ms.ToArray();
 | 
	
		
			
				|  |  | +                byte[] extraData = null;
 | 
	
		
			
				|  |  | +                if ((data.Length & 0xf) == 0) // If the data size is padded to 16 bytes, add a bit of junk data at the end
 | 
	
		
			
				|  |  | +                    extraData = new []{ (byte)0x00 };
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                File.WriteAllBytes(Path.Combine(Output, $"{nameNoExt}.nei"), Encryption.EncryptBytes(data, NEI_KEY, extraData: extraData));
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |              return 0;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -89,17 +150,17 @@ namespace ArcToolkitCLI.Commands.Converters
 | 
	
		
			
				|  |  |                          values[cell] = ShiftJisEncoding.GetString(br.ReadBytes(len), 0, Math.Max(len - 1, 0));
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                    using (var sw = new StreamWriter(File.Create(Path.Combine(Output, $"{nameNoExt}.csv"))))
 | 
	
		
			
				|  |  | +                    using (var tw = File.CreateText(Path.Combine(Output, $"{nameNoExt}.csv")))
 | 
	
		
			
				|  |  |                      {
 | 
	
		
			
				|  |  |                          for (int row = 0; row < rows; row++)
 | 
	
		
			
				|  |  |                          {
 | 
	
		
			
				|  |  |                              for (int col = 0; col < cols; col++)
 | 
	
		
			
				|  |  |                              {
 | 
	
		
			
				|  |  | -                                sw.Write(values[row * cols + col]);
 | 
	
		
			
				|  |  | +                                tw.Write(values[row * cols + col]);
 | 
	
		
			
				|  |  |                                  if(col != cols - 1)
 | 
	
		
			
				|  |  | -                                    sw.Write(ValueSeparator);
 | 
	
		
			
				|  |  | +                                    tw.Write(ValueSeparator);
 | 
	
		
			
				|  |  |                              }
 | 
	
		
			
				|  |  | -                            sw.WriteLine();
 | 
	
		
			
				|  |  | +                            tw.WriteLine();
 | 
	
		
			
				|  |  |                          }
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  |                  }
 |