Example #1
0
 private void PatchForm_Load(object sender, EventArgs e)
 {
     tvPatch.Nodes.Clear();
     List<String> files = new List<String>(Directory.GetFiles("mge3", "*.mcp", SearchOption.AllDirectories));
     files.Add(patchSettings); // last of all
     foreach (String file in files) {
         INIFile mcpFile = new INIFile(file, new INIFile.INIVariableDef[] { INIFile.iniDefEmpty }, Encoding.Default);
         String[] sections = mcpFile.getSections();
         foreach (String Section in sections) {
             Patch patch = new Patch(mcpFile, Section);
             String[] parents = patch.Parent.Split(new String[] { Patch.SepInternal.ToString() }, StringSplitOptions.RemoveEmptyEntries);
             TreeNodeCollection nodes = tvPatch.Nodes;
             TreeNode[] exist;
             for (int i = 0; i < parents.Length; i++) {
                 exist = nodes.Find(parents[i].ToLower(), false);
                 if (exist.Length > 0) nodes = exist[0].Nodes;
                 else {
                     TreeNode node = nodes.Add(parents[i].ToLower(), parents[i]);
                     node.Checked = true;
                     nodes = node.Nodes;
                 }
             }
             exist = nodes.Find(Section.ToLower(), false);
             if (exist.Length > 0) {
                 Patch existing = (Patch)exist[0].Tag;
                 bool update = existing == null;
                 if (!update) {
                     if (patch.Version <= existing.Version) continue;
                     if (patch.Original == null && patch.Patched == null && patch.Attach == null) {
                         exist[0].Checked = existing.Checked = patch.Checked;
                         existing.Removed = patch.Removed || existing.Removed;
                         existing.Expanded = patch.Expanded;
                         continue;
                     }
                     update = true;
                 }
                 if (update) {
                     exist[0].Checked = patch.Checked;
                     exist[0].Tag = patch;
                     continue;
                 }
             } else {
                 TreeNode node = nodes.Add(Section.ToLower(), Section);
                 node.Tag = patch;
                 node.Checked = patch.Checked;
                 node.ToolTipText = "";
                 foreach(String language in Languages)
                     if (node.ToolTipText == "")
                         foreach(Unit description in patch.Description)
                             if (language == description.Name) { node.ToolTipText = description.Hex.Replace("\t", "\n"); break; }
             }
         }
     }
     RemoveEmptyNodes(tvPatch.Nodes);
     UpdateColour(tvPatch.Nodes, true);
     ExpandNodes(tvPatch.Nodes);
     tvPatch.Sort();
     loaded = true;
 }
Example #2
0
 private bool SaveFile(String fileName)
 {
     try { File.Delete(fileName); } catch { return false; }
     List<INIFile.INIVariableDef> defmcp = new List<INIFile.INIVariableDef>();
     List<String[]> comments = new List<String[]>(); //  0 - section, 1 - key, 2 - comment above
     defmcp.Add(INIFile.iniDefEmpty);
     foreach (String section in selections.Sections.Keys) {
         Patch patch = selections.Sections[section];
         if (patch.Checked != new Patch().Checked)
             defmcp.Add(new INIFile.INIVariableDef(defmcp.Count.ToString(), section, Patch.Keys[Patch.Key.Checked], INIFile.INIVariableType.Dictionary, patch.Checked.ToString()));
         defmcp.Add(new INIFile.INIVariableDef(defmcp.Count.ToString(), section, Patch.Keys[Patch.Key.Version], INIFile.INIVariableType.Dictionary, patch.Version.ToString()));
         Dictionary<Patch.Key, String> str = new Dictionary<Patch.Key, String> { { Patch.Key.Parent, patch.Parent }, { Patch.Key.Author, patch.Author } };
         foreach (Patch.Key key in str.Keys) if (str[key].Trim().Length > 0)
             defmcp.Add(new INIFile.INIVariableDef(defmcp.Count.ToString(), section, Patch.Keys[key], INIFile.INIVariableType.Dictionary, str[key].Trim()));
         if (patch.FileVersion != new Patch().FileVersion)
             defmcp.Add(new INIFile.INIVariableDef(defmcp.Count.ToString(), section, Patch.Keys[Patch.Key.FileVersion], INIFile.INIVariableType.Dictionary, patch.FileVersion.ToString()));
         Dictionary<Patch.Key, Unit[]> array = new Dictionary<Patch.Key, Unit[]> { { Patch.Key.Original, patch.Original }, { Patch.Key.Patch, patch.Patched }, { Patch.Key.Attach, patch.Attach }, { Patch.Key.Description, patch.Description } };
         foreach (Patch.Key key in array.Keys) if (array[key] != null) foreach (Unit unit in array[key]) {
             String[] asm_lines = unit.Asm.Split(new Char[] { '\n' });
             String[] hex_lines = unit.Hex.Split(new Char[] { '\n' });
             String hex = "";
             int comment = 0;
             foreach (String line in hex_lines) hex += (hex.Length > 0 ? "\t" : "") + ((comment = line.IndexOf(INIFile.INIComment)) < 0 ? line : line.Substring(0, comment)).TrimEnd(null);
             if (hex.Trim().Length == 0) continue;
             String variable = Patch.Keys[key] + " " + unit.ToString();
             for (int i = 0; i < asm_lines.Length; i++) if (i == asm_lines.Length - 1 ? asm_lines[i].Trim().Length > 0 : true) comments.Add(new String[3] { section, variable, asm_lines[i] });
             defmcp.Add(new INIFile.INIVariableDef(defmcp.Count.ToString(), section, variable, INIFile.INIVariableType.Dictionary, hex));
         }
         if (patch.Removed != new Patch().Removed)
             defmcp.Add(new INIFile.INIVariableDef(defmcp.Count.ToString(), section, Patch.Keys[Patch.Key.Removed], INIFile.INIVariableType.Dictionary, patch.Removed.ToString()));
     }
     INIFile mcpFile = new INIFile(fileName, defmcp.ToArray(), Encoding.Default, true);
     mcpFile.initialize();
     foreach (String[] triplet in comments) mcpFile.setCommentAbove(triplet[0], triplet[1], triplet[2]);
     return mcpFile.save();
 }
Example #3
0
 private void bOpen_Click(object sender, EventArgs e)
 {
     RestoreButton();
     if (!SaveChanges(true)) return;
     if (openPatch.ShowDialog() != DialogResult.OK) return;
     INIFile mcpFile = new INIFile(openPatch.FileName, new INIFile.INIVariableDef[] { INIFile.iniDefEmpty }, Encoding.Default);
     String[] sections = mcpFile.getSections();
     if (sections.Length > 0) {
         selections.Sections.Clear();
         lbSections.Items.Clear();
     }
     foreach (String section in sections) {
         selections.Sections.Add(section, new Patch(mcpFile, section));
         lbSections.Items.Add(section);
     }
     propertyGrid.SelectedObject = null;
     currentState = 0;
     HistoryUpdate();
     savePatch.FileName = openPatch.FileName;
     DisableEditor();
 }
Example #4
0
 private void tvPatch_AfterEditing(object sender, TreeViewEventArgs e)
 {
     if (!loaded) return;
     UpdateColour(tvPatch.Nodes, true);
     List<INIFile.INIVariableDef> guimcp = new List<INIFile.INIVariableDef> { INIFile.iniDefEmpty };
     SaveNodes(tvPatch.Nodes, guimcp);
     INIFile mcpFile = new INIFile(patchSettings, guimcp.ToArray(), true);
     mcpFile.reinitialize();
     mcpFile.save();
 }
Example #5
0
 public Patch(INIFile mcpFile, String section)
 {
     Dictionary<String, String> keys = mcpFile.getSectionKeys(section);
     foreach (String sKey in keys.Keys) {
         String value = mcpFile.getKeyString(section, sKey).Trim();
         bool oKey = sKey.StartsWith(Keys[Key.Original], StringComparison.OrdinalIgnoreCase);
         bool pKey = sKey.StartsWith(Keys[Key.Patch], StringComparison.OrdinalIgnoreCase);
         bool aKey = sKey.StartsWith(Keys[Key.Attach], StringComparison.OrdinalIgnoreCase);
         bool dKey = sKey.StartsWith(Keys[Key.Description], StringComparison.OrdinalIgnoreCase);
         if (aKey || oKey || pKey || dKey) {
             value = value.Replace("\t", "\n");
             String comment = mcpFile.getCommentAbove(section, sKey);
             Unit[] units = oKey ? Original : pKey ? Patched : aKey ? Attach : Description;
             List<Unit> array = units != null ? new List<Unit>(units) : new List<Unit>();
             String tag = sKey.Substring(Keys[oKey ? Key.Original : pKey ? Key.Patch : aKey ? Key.Attach : Key.Description].Length).Trim();
             array.Add(aKey || dKey ? new Unit(tag, 0, value, comment) : new Unit(Convert.ToUInt32(tag, 16), value, comment));
             if (oKey) Original = array.ToArray(); else if (pKey) Patched = array.ToArray(); else if (aKey) Attach = array.ToArray();
             else Description = array.ToArray();
             continue;
         }
         foreach (Key key in Keys.Keys) {
             if (sKey.ToLower() == Keys[key].ToLower()) {
                 NumberFormatInfo provider = new NumberFormatInfo();
                 provider.NumberDecimalSeparator = ".";
                 switch (key) {
                     case Key.Checked: { try { Checked = Convert.ToBoolean(value.ToLower()); } catch { } break; }
                     case Key.Parent: { Parent = value; break; }
                     case Key.Version: { try { version = Math.Abs((float)Convert.ToDouble(value, provider)); } catch { } break; }
                     case Key.FileVersion: { try { fileVersion = Math.Abs(Convert.ToInt32(value)); } catch { } break; }
                     case Key.Author: { Author = value; break; }
                     case Key.Removed: { try { Removed = Convert.ToBoolean(value.ToLower()); } catch { } break; }
                     case Key.Expanded: { try { Expanded = Convert.ToBoolean(value.ToLower()); } catch { } break; }
                 }
                 break;
             }
         }
     }
 }