using System.Windows.Forms; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Diagnostics; using System; using System.IO; using System.Globalization; using System.Threading; using System.Collections; using System.Collections.Generic; class Pizda { // Нужные утилиты const string L2_ASM_PATH = "l2asm-disasm/l2asm.exe"; const string L2_DISASM_PATH = "l2asm-disasm/l2disasm.exe"; const string L2_ENCDEC = "l2encdec/l2encdec.exe"; const string L2_PROTOCOL = "413"; const string L2_DDF_FILE = "l2asm-disasm/DAT_defs/CT2_5en/systemmsg-e.ddf"; static bool L2_IS_ORIGINAL = false; const string TEMP_PATH = "tmp/"; static string BASE_PATH = ""; public class DelaySpeed { public string Name {get; set; } public int Value {get; set; } }; public static ArrayList delay_speeds = new ArrayList() { new DelaySpeed() { Name = "Fast", Value = 0}, new DelaySpeed() { Name = "Slow", Value = 1}, new DelaySpeed() { Name = "Very slow", Value = 11} }; public static void saveL2File(string file, string protocol, DataTable table) { } public static void parseL2File(string file, DataGridView table) { string decoded_tmp_file = TEMP_PATH + "systemmsg_" + UnixTimeNow() + "_decoded.dat"; string cvs_tmp_file = TEMP_PATH + "systemmsg_" + UnixTimeNow() + "_cvs.dat"; Process p = null; try { // decrypt p = exec(BASE_PATH + L2_ENCDEC, (L2_IS_ORIGINAL ? "-l " : "-d ") + EscapeCommandArg(file) + " " + EscapeCommandArg(decoded_tmp_file)); p.Start(); p.WaitForExit(); if (!File.Exists(decoded_tmp_file)) throw new Exception("File " + decoded_tmp_file + " not found! Can't decrypt!"); // disassemble to CVS p = exec(BASE_PATH + L2_DISASM_PATH, "-q -f -d " + L2_DDF_FILE + " " + EscapeCommandArg(decoded_tmp_file) + " " + EscapeCommandArg(cvs_tmp_file)); p.Start(); p.WaitForExit(); if (!File.Exists(cvs_tmp_file)) throw new Exception("File " + cvs_tmp_file + " not found! Can't disassemble!"); StreamReader rd = new StreamReader(cvs_tmp_file); table.Rows.Clear(); int i = 0; while (!rd.EndOfStream) { var splits = rd.ReadLine().Split('\t'); ushort a = Convert.ToUInt16(splits[7], 16); ushort r = Convert.ToUInt16(splits[6], 16); ushort g = Convert.ToUInt16(splits[5], 16); ushort b = Convert.ToUInt16(splits[4], 16); table.Rows.Add(); table.Rows[i].DefaultCellStyle.BackColor = Color.FromArgb(0xFF, 0, 0, 0); table.Rows[i].DefaultCellStyle.ForeColor = Color.FromArgb(a, r, g, b); table.Rows[i].Cells[0] = new DataGridViewTextBoxCell() { Value = Convert.ToInt32(splits[0]) }; var m = new DataGridViewTextBoxCell() { Value = splits[2] + "\r\nssss\r\nssssss\r\n" }; //m.DataGridViewCellStyle.WrapMode = DataGridViewTriState.True;\\, \t, \0, \r and \n. table.Rows[i].Cells[1] = m; table.Rows[i].Cells[2] = new DataGridViewTextBoxCell() { Value = splits[4] + splits[5] + splits[6] + splits[7] }; table.Rows[i].Cells[3] = new DataGridViewTextBoxCell() { Value = Convert.ToInt32(splits[10]) }; table.Rows[i].Cells[4] = new DataGridViewTextBoxCell() { Value = Convert.ToInt32(splits[12]) }; var c = new DataGridViewComboBoxCell(); int v = Convert.ToInt32(splits[13]); foreach (DelaySpeed row in delay_speeds) { c.Items.Add(row.Name); if (row.Value == v) { c.Value = row.Name; } } table.Rows[i].Cells[5] = c; table.Rows[i].Cells[6] = new DataGridViewCheckBoxCell() { Value = Convert.ToInt32(splits[14]) != 0 }; table.Rows[i].Cells[7] = new DataGridViewTextBoxCell() { Value = splits[15] }; ++i; } rd.Close(); } catch (Exception e) { Console.WriteLine(e); } File.Delete(cvs_tmp_file); File.Delete(decoded_tmp_file); } public static void Main() { BASE_PATH = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + "/"; Directory.SetCurrentDirectory(BASE_PATH); // grid DataGridView grid = new DataGridView(); grid.Columns.Add(new DataGridViewTextBoxColumn() { HeaderText = "id", MinimumWidth = 40 }); grid.Columns.Add(new DataGridViewTextBoxColumn() { HeaderText = "message", MinimumWidth = 50 }); grid.Columns.Add(new DataGridViewTextBoxColumn() { HeaderText = "color", MinimumWidth = 80 }); grid.Columns.Add(new DataGridViewTextBoxColumn() { HeaderText = "position", MinimumWidth = 10 }); grid.Columns.Add(new DataGridViewTextBoxColumn() { HeaderText = "delay", MinimumWidth = 10 }); var c = new DataGridViewComboBoxColumn() { HeaderText = "delay_speed" }; grid.Columns.Add(c); grid.Columns.Add(new DataGridViewCheckBoxColumn() { HeaderText = "border", MinimumWidth = 10 }); grid.Columns.Add(new DataGridViewTextBoxColumn() { HeaderText = "sub_msg", MinimumWidth = 60 }); grid.AutoGenerateColumns = false; parseL2File("H:/wine/drive_c/Program Files (x86)/averia.ws/system/systemmsg-ru.dat", grid); grid.AllowUserToAddRows = false; grid.AllowUserToDeleteRows = false; //grid.AutoGenerateColumns = false; grid.Width = 900; grid.Height = 660; grid.DefaultCellStyle.WrapMode = DataGridViewTriState.True; //grid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; //grid.DefaultView.AllowDelete(); //grid.ColumnHeadersBorderStyle = ProperColumnHeadersBorderStyle; // form Form form = new Form(); form.Controls.Add(grid); form.Width = 1000; form.Height = 700; form.ShowDialog(); } public static Process exec(string path, string args) { return new Process { StartInfo = new ProcessStartInfo { FileName = path, Arguments = args, UseShellExecute = false, // RedirectStandardOutput = true, WorkingDirectory = BASE_PATH, CreateNoWindow = true } }; } public static long UnixTimeNow() { var timeSpan = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0)); return (long)timeSpan.TotalSeconds; } private static string EscapeCommandArg(string arg) { return "\"" + arg.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\""; } }