private void Solve() { Console.WriteLine(ReadStr.Split('+').Count(x => !x.Contains('0'))); #if DEBUG Solve(); #endif }
private void InjectButton_Click(object sender, EventArgs e) { string ExecFile, FixFile; string ReadStr; // Select source and target files OpenFileDialog1.Title = "Select Exec file to fix:"; OpenFileDialog1.FileName = ""; OpenFileDialog1.Filter = "L2Server.exe|L2Server.exe|All files (*.*)|*.*"; if (OpenFileDialog1.ShowDialog() == DialogResult.Cancel) { return; } else { ExecFile = OpenFileDialog1.FileName; ExecName.Text = ExecFile; } OpenFileDialog1.Title = "Select Fix file:"; OpenFileDialog1.FileName = ""; OpenFileDialog1.Filter = "Text file format|*.txt|All files|*.*"; if (OpenFileDialog1.ShowDialog() == DialogResult.Cancel) { return; } else { FixFile = OpenFileDialog1.FileName; FixName.Text = FixFile; } // Make backup for exec System.IO.File.Copy(ExecFile, ExecFile + ".bak", true); // Start fix var InFixFile = new System.IO.StreamReader(FixFile, System.Text.Encoding.Default, true, 1); System.IO.Stream OExecFile = new System.IO.FileStream(ExecFile, System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite); var OutExecFile = new System.IO.StreamWriter(OExecFile); if (System.IO.File.Exists(FixFile + ".bak") == true & RecoveryBox.Checked == true) { if ((int)MessageBox.Show("Backup file already exist. Owerwrite last good recovery backup?", "Owerwrite backup?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == (int)DialogResult.No) { return; } } System.IO.Stream OExecFileBak = null; System.IO.StreamWriter OutExecFileBak = null; if (RecoveryBox.Checked == true) { // System.IO.Path.GetDirectoryName() OExecFileBak = new System.IO.FileStream(System.IO.Path.GetDirectoryName(FixFile) + @"\backup~" + System.IO.Path.GetFileName(FixFile), System.IO.FileMode.Create, System.IO.FileAccess.Write); OutExecFileBak = new System.IO.StreamWriter(OExecFileBak); } int WriteOffset, WriteLenght, tempOff; ReadStr = Strings.Trim(InFixFile.ReadLine()); while (ReadStr != null) { WriteOffset = Conversions.ToInteger(Conversions.Val("&H" + Strings.Mid(ReadStr, 1, Strings.InStr(ReadStr, ":")))); if (IsOffset.Checked == true) { WriteOffset -= 0x400000; if (WriteOffset < 0) { MessageBox.Show("This fix no required inject offset", "No required offset", MessageBoxButtons.OK, MessageBoxIcon.Error); OExecFile.Close(); InFixFile.Close(); if (RecoveryBox.Checked == true) { OutExecFileBak.Close(); } return; } } ReadStr = Strings.Mid(ReadStr, Strings.InStr(ReadStr, ":") + 1, ReadStr.Length).TrimStart(); string[] TempArr; TempArr = ReadStr.Split((char)32); var FixStr = new byte[TempArr.Length - 1 + 1]; if (RecoveryBox.Checked == true) { var BackupArr = new byte[TempArr.Length - 1 + 1]; OExecFile.Position = WriteOffset; OExecFile.Read(BackupArr, 0, TempArr.Length); OutExecFileBak.Write(Conversions.Hex(WriteOffset) + ":"); //byte tChr; foreach (byte tChr in BackupArr) { OutExecFileBak.Write(" " + Conversions.Hex(tChr).PadLeft(2, Convert.ToChar("0"))); } OutExecFileBak.WriteLine(""); OutExecFileBak.Flush(); } var loopTo = TempArr.Length - 1; for (tempOff = 0; tempOff <= loopTo; tempOff++) { try { FixStr[tempOff] = Conversions.ToByte(Conversions.Val("&H" + TempArr[tempOff])); } catch (Exception ex) { MessageBox.Show("Fix file have incorrect format. Make recovery fix from backup (.bak) file.", "Incorrect fix", MessageBoxButtons.OK, MessageBoxIcon.Error); OExecFile.Close(); InFixFile.Close(); if (RecoveryBox.Checked == true) { OutExecFileBak.Close(); } return; } } WriteLenght = tempOff; OExecFile.Position = WriteOffset; OExecFile.Write(FixStr, 0, WriteLenght); OutExecFile.Flush(); ReadStr = Strings.Trim(InFixFile.ReadLine()); } OExecFile.Close(); InFixFile.Close(); if (RecoveryBox.Checked == true) { OutExecFileBak.Close(); } MessageBox.Show("Injection success.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); return; }
private void ItemCacheScript_Click(object sender, EventArgs e) { // 1 [Short Sword] [no description] consume_type_normal 0 OpenFileDialog.FileName = ""; OpenFileDialog.Filter = "Lineage II config (itemdata.txt)|itemdata.txt|All files (*.*)|*.*"; if (OpenFileDialog.ShowDialog() == DialogResult.Cancel) { return; } System.IO.StreamReader inEFile; try { inEFile = new System.IO.StreamReader(System.IO.Path.GetDirectoryName(OpenFileDialog.FileName) + @"\itemname-e.txt", System.Text.Encoding.Default, true, 1); } catch (Exception ex) { MessageBox.Show("You must have itemdata-e in work folder for generation itemcache file. Put and try again."); return; } // Initialization ProgressBar.Value = 0; var inFile = new System.IO.StreamReader(OpenFileDialog.FileName, System.Text.Encoding.Default, true, 1); System.IO.Stream oAiFile = new System.IO.FileStream(System.IO.Path.GetDirectoryName(OpenFileDialog.FileName) + @"\itemcache.txt", System.IO.FileMode.Create, System.IO.FileAccess.Write); var outAiData = new System.IO.StreamWriter(oAiFile, System.Text.Encoding.Unicode, 1); string ReadStr, OutStr; string[] ReadSplitStr; ProgressBar.Value = 0; ProgressBar.Maximum = Conversions.ToInteger(inEFile.BaseStream.Length); var ItemDB = new string[30001, 4]; // 0- id, 1 - name, 2 - consume, 3 - type (for quest) int ItemDBMarker = 0; string CommentName; string CommentDescription; while (inEFile.EndOfStream != true) { ReadStr = inEFile.ReadLine(); if (ReadStr != null) { if ((Strings.Mid(ReadStr, 1, 2) ?? "") != "//") { ReadSplitStr = ReadStr.Split((char)9); ItemDBMarker = Conversions.ToInteger(ReadSplitStr[1].Replace("id=", "")); if (ItemDBMarker >= 30000) { MessageBox.Show("Item ID must be less then 30000. Custom items not supported. Last item_id:" + ItemDBMarker.ToString(), "ItemID above them 30000", MessageBoxButtons.OK, MessageBoxIcon.Error); ProgressBar.Value = 0; inFile.Close(); outAiData.Close(); return; } ItemDB[ItemDBMarker, 0] = ReadSplitStr[2].Replace("name=", ""); ItemDB[ItemDBMarker, 1] = ReadSplitStr[5].Replace("description=", ""); } } ProgressBar.Value = Conversions.ToInteger(inFile.BaseStream.Position * 100 / (double)inFile.BaseStream.Length); } ProgressBar.Maximum = Conversions.ToInteger(inFile.BaseStream.Length); ProgressBar.Value = 0; while (inFile.BaseStream.Position != inFile.BaseStream.Length) { ReadStr = Strings.Replace(inFile.ReadLine(), "\t", " "); // tabs and spaces correction while (Strings.InStr(ReadStr, " ") != 0) { ReadStr = Strings.Replace(ReadStr, " ", " "); } if (!String.IsNullOrWhiteSpace(ReadStr)) { if ((Strings.Mid(Strings.Trim(ReadStr), 1, 2) ?? "") != "//") { ReadSplitStr = ReadStr.Split((char)32); if (Strings.InStr(ReadStr, "set_begin") == 0) { // Find Item in Itemname-e CommentName = ReadSplitStr[3]; CommentDescription = "[no description]"; ItemDBMarker = Conversions.ToInteger(ReadSplitStr[2]); if (ItemDBMarker <= 30000) { if (!string.IsNullOrEmpty(ItemDB[ItemDBMarker, 0])) { CommentName = ItemDB[ItemDBMarker, 0]; } if (!string.IsNullOrEmpty(ItemDB[ItemDBMarker, 1])) { CommentDescription = ItemDB[ItemDBMarker, 1]; } } else if (StopError.Checked == false) { CommentName = "[L2ScriptMaker: Customs skills not supported]"; CommentDescription = "[L2ScriptMaker: Customs skills not supported]"; } else { MessageBox.Show("Item ID must be less then 30000. Custom Items not supported. Last item_id:" + ItemDBMarker.ToString(), "ItemID above them 30000", MessageBoxButtons.OK, MessageBoxIcon.Error); ProgressBar.Value = 0; inFile.Close(); outAiData.Close(); return; } // 500 symbols fix if (CommentDescription.Length > 500) { CommentDescription = CommentDescription.Substring(0, 500) + "]"; } OutStr = ReadSplitStr[2] + Conversions.ToString((char)9) + CommentName + Conversions.ToString((char)9) + CommentDescription + Conversions.ToString((char)9); if (Strings.InStr(ReadStr, "consume_type_normal") != 0) { OutStr += "consume_type_normal" + Conversions.ToString((char)9); } else if (Strings.InStr(ReadStr, "consume_type_stackable") != 0) { OutStr += "consume_type_stackable" + Conversions.ToString((char)9); } else if (Strings.InStr(ReadStr, "consume_type_asset") != 0) { OutStr += "consume_type_asset" + Conversions.ToString((char)9); } else { MessageBox.Show("Unknown consume_type. Please report me about it", "Unknown consume_type", MessageBoxButtons.OK, MessageBoxIcon.Error); inFile.Close(); outAiData.Close(); return; } if (Strings.InStr(ReadStr, "questitem") != 0) { OutStr += "1"; } else { OutStr += "0"; } outAiData.WriteLine(OutStr); } } } ProgressBar.Value = Conversions.ToInteger(inFile.BaseStream.Position * 100 / (double)inFile.BaseStream.Length); } MessageBox.Show("itemcache.txt Complete"); ProgressBar.Value = 0; inFile.Close(); outAiData.Close(); }
private void NpcCacheScript_Click(object sender, EventArgs e) { // 10 Felim Lizardman Scout OpenFileDialog.FileName = ""; OpenFileDialog.Filter = "Lineage II config (npcdata.txt)|npcdata.txt|All files (*.*)|*.*"; if (OpenFileDialog.ShowDialog() == DialogResult.Cancel) { return; } System.IO.StreamReader inEFile; try { inEFile = new System.IO.StreamReader(System.IO.Path.GetDirectoryName(OpenFileDialog.FileName) + @"\npcname-e.txt", System.Text.Encoding.Default, true, 1); } catch (Exception ex) { MessageBox.Show("You must have npcname-e.txt in work folder for generation npccache.txt file. Put and try again."); return; } // Initialization ProgressBar.Value = 0; var inFile = new System.IO.StreamReader(OpenFileDialog.FileName, System.Text.Encoding.Default, true, 1); System.IO.Stream oAiFile = new System.IO.FileStream(System.IO.Path.GetDirectoryName(OpenFileDialog.FileName) + @"\npccache.txt", System.IO.FileMode.Create, System.IO.FileAccess.Write); var outAiData = new System.IO.StreamWriter(oAiFile, System.Text.Encoding.Unicode, 1); string ReadStr; ProgressBar.Value = 0; ProgressBar.Maximum = (int)(inEFile.BaseStream.Length); var NpcDB = new string[15001]; // 0- id, 1 - name, 2 - consume, 3 - type (for quest) int NpcDBMarker = 0; string CommentName; string[] ReadSplitStr; // Creating ID Table from NPCdata.txt while (inEFile.EndOfStream != true) { ReadStr = inEFile.ReadLine(); if (ReadStr != null) { if (!ReadStr.StartsWith("//")) { // ReadSplitStr = ReadStr.Split(Chr(9)) NpcDBMarker = Convert.ToInt32(Libraries.GetNeedParamFromStr(ReadStr, "id")); if (NpcDBMarker >= NpcDB.Length) { Array.Resize(ref NpcDB, NpcDBMarker + 1); } NpcDB[NpcDBMarker] = Libraries.GetNeedParamFromStr(ReadStr, "name"); // ReadSplitStr(4).Replace("name=[", "").Replace("]", "") } } ProgressBar.Value = (int)(inFile.BaseStream.Position * 100 / (double)inFile.BaseStream.Length); } ProgressBar.Maximum = (int)(inFile.BaseStream.Length); ProgressBar.Value = 0; while (inFile.BaseStream.Position != inFile.BaseStream.Length) { ReadStr = inFile.ReadLine(); ReadStr = ReadStr.Replace("\t", " "); if (!string.IsNullOrEmpty(ReadStr.Trim()) & ReadStr.StartsWith("//") == false) { // tabs and spaces correction while (ReadStr.IndexOf(" ") >= 0) { ReadStr = ReadStr.Replace(" ", " "); } ReadSplitStr = ReadStr.Split((char)32); // Find Npc in Npcname-e ReadSplitStr[3] = ReadSplitStr[3].Substring(1, ReadSplitStr[3].Length - 2); CommentName = ReadSplitStr[3]; NpcDBMarker = Convert.ToInt32(ReadSplitStr[2]); if (NpcDBMarker <= NpcDB.Length) { if (!string.IsNullOrEmpty(NpcDB[Convert.ToInt32(ReadSplitStr[2])])) { CommentName = NpcDB[Convert.ToInt32(ReadSplitStr[2])]; } } ReadStr = ReadSplitStr[2] + "\t" + CommentName; outAiData.WriteLine(ReadStr); } ProgressBar.Value = (int)(inFile.BaseStream.Position); } MessageBox.Show("npccache.txt Complete"); ProgressBar.Value = 0; inFile.Close(); outAiData.Close(); }
private void SplitButton_Click(object sender, EventArgs e) { OpenFileDialog.FileName = ""; OpenFileDialog.Filter = "Lineage II config (itemdata.txt)|itemdata.txt|All files (*.*)|*.*"; if (OpenFileDialog.ShowDialog() == DialogResult.Cancel) { return; } else { SourceFile.Text = OpenFileDialog.FileName; } // Select folder to work if (FolderBrowserDialog.ShowDialog() == DialogResult.Cancel) { return; } string[] str; str = System.IO.Directory.GetFiles(FolderBrowserDialog.SelectedPath, "*.*", System.IO.SearchOption.AllDirectories); if (str.Length != 0 & OverwriteBox.Checked == false) { if ((int)MessageBox.Show("Source directory no empty! Continue?", "No empty directory", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == (int)DialogResult.No) { return; } } TargetFile.Text = FolderBrowserDialog.SelectedPath; // Initialization ProgressBar.Value = 0; var inFile = new System.IO.StreamReader(SourceFile.Text, System.Text.Encoding.Default, true, 1); string ReadStr; string[] ReadSplitStr; string FileName = String.Empty, FileDirName = String.Empty; while (inFile.BaseStream.Position != inFile.BaseStream.Length) { ReadStr = Strings.Replace(inFile.ReadLine(), Conversions.ToString((char)9), Conversions.ToString((char)32)); // tabs and spaces correction while (Strings.InStr(ReadStr, " ") != 0) { ReadStr = Strings.Replace(ReadStr, " ", Conversions.ToString((char)32)); } // fix for comments and empty string in itemdata if (ReadStr.Length == default(int)) { goto nextitem; } if ((Strings.Mid(ReadStr, 1, 2) ?? "") == "//") { goto nextitem; } ReadSplitStr = ReadStr.Split((char)32); StatusBox.Text = "Please wait... Split item: " + ReadSplitStr[3]; this.Refresh(); switch (ReadSplitStr[0]) { case "item_begin": { // error symbols correction ReadSplitStr[3] = Strings.Replace(ReadSplitStr[3], ":", "_"); ReadSplitStr[3] = Strings.Replace(ReadSplitStr[3], "*", "_"); ReadSplitStr[3] = Strings.Mid(ReadSplitStr[3], 2, Strings.Len(ReadSplitStr[3]) - 2); ReadSplitStr[2] = ReadSplitStr[2].PadLeft(5, Conversions.ToChar("0")); FileDirName = FolderBrowserDialog.SelectedPath + @"\item_begin\" + ReadSplitStr[2] + "-" + ReadSplitStr[3]; FileName = ReadSplitStr[2] + "-" + ReadSplitStr[3] + ".txt"; break; } case "set_begin": { ReadSplitStr[1] = ReadSplitStr[1].PadLeft(5, Conversions.ToChar("0")); FileDirName = FolderBrowserDialog.SelectedPath + @"\set_begin\" + ReadSplitStr[1]; FileName = ReadSplitStr[1] + ".txt"; break; } default: { MessageBox.Show("Unknown/bad file format for :" + Conversions.ToString((char)13) + Conversions.ToString((char)10) + Conversions.ToString((char)13) + Conversions.ToString((char)10) + ReadStr, "Unknown/bad file format", MessageBoxButtons.OK, MessageBoxIcon.Error); break; break; } } // FileDirName = FileDirName + "\" + ReadSplitStr(2) + "-" + ReadSplitStr(3) + "\" + ReadSplitStr(2) + "-" + ReadSplitStr(3) + ".txt" System.IO.Directory.CreateDirectory(FileDirName); System.IO.Stream oAiFile = new System.IO.FileStream(FileDirName + @"\" + FileName, System.IO.FileMode.Create, System.IO.FileAccess.Write); var outAiData = new System.IO.StreamWriter(oAiFile, System.Text.Encoding.Unicode, 1); // == ART Correction == SymbolCorrection(ReadStr); ReadStr = Strings.Replace(ReadStr, " = ", "="); ReadStr = Strings.Replace(ReadStr, Conversions.ToString((char)32), Conversions.ToString((char)9)); outAiData.WriteLine(ReadStr); outAiData.Close(); nextitem: ; ProgressBar.Value = Conversions.ToInteger(inFile.BaseStream.Position * 100 / (double)inFile.BaseStream.Length); } StatusBox.Text = "Splitting done."; ProgressBar.Value = 0; inFile.Close(); }
private void SplitButton_Click(object sender, EventArgs e) { // Define file OpenFileDialog.FileName = ""; OpenFileDialog.Filter = "Lineage II config (npcdata.txt)|npcdata.txt"; if (OpenFileDialog.ShowDialog() == DialogResult.Cancel) { return; } else { SourceFile.Text = OpenFileDialog.FileName; } // Select folder to work if (FolderBrowserDialog.ShowDialog() == DialogResult.Cancel) { return; } string[] str; str = System.IO.Directory.GetFiles(FolderBrowserDialog.SelectedPath, "*.*", System.IO.SearchOption.AllDirectories); if (str.Length != 0 & OverwriteBox.Checked == false) { if ((int)MessageBox.Show("Source directory no empty! Continue?", "No empty directory", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == (int)DialogResult.No) { return; } } TargetFile.Text = FolderBrowserDialog.SelectedPath; // Initialization ProgressBar.Value = 0; var inFile = new System.IO.StreamReader(SourceFile.Text, System.Text.Encoding.Default, true, 1); string ReadStr; string[] ReadSplitStr; string FileName, FileDirName; while (inFile.BaseStream.Position != inFile.BaseStream.Length) { ReadStr = Strings.Replace(inFile.ReadLine(), Conversions.ToString((char)9), " "); // tabs and spaces correction ReadStr = SymbolCorrection(ReadStr); ReadSplitStr = ReadStr.Split((char)32); StatusBox.Text = "Please wait... Split npc: " + ReadSplitStr[3]; this.Refresh(); // Npcdata or not if ((ReadSplitStr[0] ?? "") != "npc_begin") { MessageBox.Show("File format is not npcdata. Invalid record is: " + Conversions.ToString((char)13) + Conversions.ToString((char)13) + ReadStr, "Invalid format", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ReadSplitStr[3] = Strings.Mid(ReadSplitStr[3], 2, Strings.Len(ReadSplitStr[3]) - 2); ReadSplitStr[2] = ReadSplitStr[2].PadLeft(5, Conversions.ToChar("0")); FileDirName = FolderBrowserDialog.SelectedPath + @"\npc_begin\" + ReadSplitStr[2] + "-" + ReadSplitStr[3]; FileName = ReadSplitStr[2] + "-" + ReadSplitStr[3] + ".txt"; System.IO.Directory.CreateDirectory(FileDirName); System.IO.Stream oAiFile = new System.IO.FileStream(FileDirName + @"\" + FileName, System.IO.FileMode.Create, System.IO.FileAccess.Write); var outAiData = new System.IO.StreamWriter(oAiFile, System.Text.Encoding.Unicode, 1); // == ART Correction == SymbolCorrection(ReadStr); ReadStr = Strings.Replace(ReadStr, " = ", "="); ReadStr = Strings.Replace(ReadStr, Conversions.ToString((char)32), Conversions.ToString((char)9)); outAiData.WriteLine(ReadStr); outAiData.Close(); ProgressBar.Value = Conversions.ToInteger(inFile.BaseStream.Position * 100 / (double)inFile.BaseStream.Length); } StatusBox.Text = "Splitting done."; ProgressBar.Value = 0; inFile.Close(); }