private static string ExecuteAddTexture(BasicBase db, string root, string node, string path) { if (!db.TryGetCollection(node, root, out var collection)) { return($"Collection {node} cannot be found in root {root}."); } if (!(collection is TPKBlock tpk)) { return($"Collection {node} is not a {root} collection."); } if (!File.Exists(path)) { return($"File named {path} does not exist."); } if (tpk.TryAddTexture(Path.GetFileNameWithoutExtension(path), path, out var error)) { return(null); } else if (Settings.Default.EnableSuppressABCI) { return(null); } else { return(error); } }
private static string ExecuteImportCollection(BasicBase db, string root, string path) { if (root == "Collision") { if (db.TryAddCollision(Path.GetFileNameWithoutExtension(path), path, out var error)) { return(null); } else { return(error); } } else { if (db.TryImportCollection(root, path, out var error)) { return(null); } else if (Settings.Default.EnableSuppressABCI) { return(null); } else { return(error); } } }
/// <summary> /// Loads data from Global files in the directory chosen. /// </summary> /// <param name="db"><see cref="BasicBase"/> where data should be loaded.</param> /// <param name="dir">Directory of the game.</param> /// <returns>True on success; false otherwise.</returns> public static bool LoadData(BasicBase db, string dir) { bool done = true; switch (db.GameINT) { case GameINT.Carbon: Initialize.Init(); done &= Support.Carbon.LoadData.LoadVaults(dir); done &= Support.Carbon.LoadData.LoadLanguage(dir, (Database.Carbon)db); done &= Support.Carbon.LoadData.LoadGlobalA(dir, (Database.Carbon)db); done &= Support.Carbon.LoadData.LoadGlobalB(dir, (Database.Carbon)db); return(done); case GameINT.MostWanted: Initialize.Init(); done &= Support.MostWanted.LoadData.LoadVaults(dir); done &= Support.MostWanted.LoadData.LoadLanguage(dir, (Database.MostWanted)db); done &= Support.MostWanted.LoadData.LoadGlobalA(dir, (Database.MostWanted)db); done &= Support.MostWanted.LoadData.LoadGlobalB(dir, (Database.MostWanted)db); return(done); case GameINT.Underground2: Initialize.InitUG2(); done &= Support.Underground2.LoadData.LoadLanguage(dir, (Database.Underground2)db); done &= Support.Underground2.LoadData.LoadAudios(dir); done &= Support.Underground2.LoadData.LoadWheels(dir); done &= Support.Underground2.LoadData.LoadGlobalA(dir, (Database.Underground2)db); done &= Support.Underground2.LoadData.LoadGlobalB(dir, (Database.Underground2)db); return(done); default: return(false); } }
private static string ExecuteStaticCollection(BasicBase db, string root, string field, string value) { if (db.TrySetStaticValue(root, field, value, out var error)) { return(null); } else { return(error); } }
private static string ExecuteDeleteTPKSTR(BasicBase db, string root, string node, string hash) { switch (root) { case TPKBlocks: if (!db.TryGetCollection(node, root, out var inter)) { return($"Collection {node} cannot be found in root {root}."); } if (!(inter is TPKBlock tpk)) { return($"Collection {node} is not a {STRBlocks} collection."); } if (tpk.TryRemoveTexture(ConvertX.ToUInt32(hash), eKeyType.BINKEY, out var error)) { return(null); } else if (Settings.Default.EnableSuppressABCI) { return(null); } else { return(error); } case STRBlocks: if (!db.TryGetCollection(node, root, out var collection)) { return($"Collection {node} cannot be found in root {root}."); } if (!(collection is STRBlock str)) { return($"Collection {node} is not a {STRBlocks} collection."); } if (str.TryRemoveRecord(hash, out var fail)) { return(null); } else if (Settings.Default.EnableSuppressABCI) { return(null); } else { return(fail); } default: return($"Invalid root passed named {root}."); } }
private static string ExecuteUpdateTPKSTR(BasicBase db, string root, string node, string hash, string field, string value) { switch (root) { case TPKBlocks: if (!db.TryGetCollection(node, root, out var inter)) { return($"Collection {node} cannot be found in root {root}."); } if (!(inter is TPKBlock tpk)) { return($"Collection {node} is not a {STRBlocks} collection."); } var texture = tpk.FindTexture(ConvertX.ToUInt32(hash), eKeyType.BINKEY); if (texture == null) { return($"Texture with key {hash} does not exist in {node}"); } string error = null; texture.SetValue(field, value, ref error); return(error); case STRBlocks: if (!db.TryGetCollection(node, root, out var collection)) { return($"Collection {node} cannot be found in root {root}."); } if (!(collection is STRBlock str)) { return($"Collection {node} is not a {STRBlocks} collection."); } var record = str.GetRecord(hash); if (record == null) { return($"StringRecord with key {hash} does not exist."); } if (!record.TrySetValue(field, value)) { return($"Unable to set value {value} in field {field} specified."); } else { return(null); } default: return($"Invalid root passed named {root}."); } }
private static string ExecuteDeleteCollection(BasicBase db, string root, string node) { if (db.TryRemoveCollection(node, root, out var error)) { return(null); } else if (Settings.Default.EnableSuppressABCI) { return(null); } else { return(error); } }
private static string ExecuteCopyCollection(BasicBase db, string root, string copyfrom, string newname) { if (db.TryCloneCollection(newname, copyfrom, root, out var error)) { return(null); } else if (Settings.Default.EnableSuppressABCI) { return(null); } else { return(error); } }
private static string ExecuteUpdateSubNode(BasicBase db, string root, string node, string subroute, string subnode, string field, string value) { string error = null; var collection = db.GetPrimitive(root, node, subroute, subnode); if (collection == null) { return($"SubNode {subnode} does not exist in collection {node} in root {root}."); } if (collection.SetValue(field, value, ref error)) { return(null); } else { return(error); } }
/// <summary> /// Saves data into Global files in the directory chosen. /// </summary> /// <param name="db"><see cref="BasicBase"/> from where data should be unloaded.</param> /// <param name="dir">Directory of the game.</param> /// <param name="compressed">True if compress GlobalB file on the output; false otherwise.</param> /// <returns>True on success; false otherwise.</returns> public static bool SaveData(BasicBase db, string dir, bool compressed) { bool done = true; switch (db.GameINT) { case GameINT.Carbon: done &= Support.Carbon.SaveData.SaveGlobalA(dir, (Database.Carbon)db); done &= Support.Carbon.SaveData.SaveGlobalB(dir, (Database.Carbon)db); done &= Support.Carbon.SaveData.SaveLanguage(dir, (Database.Carbon)db); if (done && compressed) { CompressFiles(dir); } return(done); case GameINT.MostWanted: done &= Support.MostWanted.SaveData.SaveGlobalA(dir, (Database.MostWanted)db); done &= Support.MostWanted.SaveData.SaveGlobalB(dir, (Database.MostWanted)db); done &= Support.MostWanted.SaveData.SaveLanguage(dir, (Database.MostWanted)db); if (done && compressed) { CompressFiles(dir); } return(done); case GameINT.Underground2: done &= Support.Underground2.SaveData.SaveGlobalA(dir, (Database.Underground2)db); done &= Support.Underground2.SaveData.SaveGlobalB(dir, (Database.Underground2)db); done &= Support.Underground2.SaveData.SaveLanguage(dir, (Database.Underground2)db); if (done && compressed) { CompressFiles(dir); } return(done); default: return(false); } }
private static string ExecuteUpdateCollection(BasicBase db, string root, string node, string field, string value) { if (root == FNGroups) { return(ExecuteUpdateFNG(db, node, field, value)); } string error = null; if (!db.TryGetCollection(node, root, out var collection)) { return($"Collection {node} cannot be found in root {root}."); } if (collection.SetValue(field, value, ref error)) { return(null); } else { return(error); } }
private static string ExecuteReplaceTexture(BasicBase db, string root, string node, string hash, string path) { if (!db.TryGetCollection(node, root, out var collection)) { return($"Collection {node} cannot be found in root {root}."); } if (!(collection is TPKBlock tpk)) { return($"Collection {node} is not a {STRBlocks} collection."); } if (!File.Exists(path)) { return($"File named {path} does not exist."); } if (tpk.TryReplaceTexture(ConvertX.ToUInt32(hash), eKeyType.BINKEY, path, out var error)) { return(null); } else { return(error); } }
private static string ExecuteCopyTexture(BasicBase db, string root, string node, string hash, string cname) { if (!db.TryGetCollection(node, root, out var collection)) { return($"Collection {node} cannot be found in root {root}."); } if (!(collection is TPKBlock tpk)) { return($"Collection {node} is not a {STRBlocks} collection."); } if (tpk.TryCloneTexture(cname, ConvertX.ToUInt32(hash), eKeyType.BINKEY, out var error)) { return(null); } else if (Settings.Default.EnableSuppressABCI) { return(null); } else { return(error); } }
private static string ExecuteAddString(BasicBase db, string root, string node, string key, string label, string text) { if (!db.TryGetCollection(node, root, out var collection)) { return($"Collection {node} cannot be found in root {root}."); } if (!(collection is STRBlock str)) { return($"Collection {node} is not a {STRBlocks} collection."); } if (str.TryAddRecord(key, label, text, out var error)) { return(null); } else if (Settings.Default.EnableSuppressABCI) { return(null); } else { return(error); } }
private static string ExecuteUpdateFNG(BasicBase db, string node, string field, string value) { if (!db.TryGetCollection(node, FNGroups, out var collection)) { return($"Collection {node} does not exist in root {FNGroups}."); } if (!(collection is FNGroup fng)) { return($"Collection {node} is not a {FNGroups} collection."); } if (!SAT.CanBeColor(value)) { return($"Value {value} is not an 8-digit hexadecimal color-type."); } var color = new FEngColor(null); color.Alpha = SAT.GetAlpha(value); color.Red = SAT.GetRed(value); color.Green = SAT.GetGreen(value); color.Blue = SAT.GetBlue(value); if (field.StartsWith("ReplaceSame")) { if (field.StartsWith("ReplaceSameNoAlpha[") && field.EndsWith("]")) { if (FormatX.GetInt32(field, "ReplaceSameNoAlpha[{X}]", out int index)) { fng.TrySetSame(index, color, true); } else { return($"Unable to get color index from field named {field}."); } } else if (field.StartsWith("ReplaceSameWithAlpha[") && field.EndsWith("]")) { if (FormatX.GetInt32(field, "ReplaceSameWithAlpha[{X}]", out int index)) { fng.TrySetSame(index, color, false); } else { return($"Unable to get color index from field named {field}."); } } else { return($"Incorrect passed parameter named {field}."); } } else if (field == "ReplaceAllNoAlpha") { fng.TrySetAll(color, true); } else if (field == "ReplaceAllWithAlpha") { fng.TrySetAll(color, false); } else { int index = SAT.GetIndex(field); if (index >= fng.InfoLength || index == -1) { return($"Field named {field} does not exist."); } fng.TrySetOne(index, color); } return(null); }
public static string ExecuteEndscriptLine(string line, BasicBase db, string filedir = "") { string error = "Incorrect amount of passed script parameters."; var words = DisperseLine(line, new char[] { ' ', '\t', '\n' }); if (!Enum.TryParse(words[0], out eCommands command)) { return($"Unrecognized command {words[0]}; unable to process."); } int len = words.Length; switch (command) { case eCommands.update: if (len == 5) { return(ExecuteUpdateCollection(db, words[1], words[2], words[3], words[4])); } else if (len == 6) { return(ExecuteUpdateTPKSTR(db, words[1], words[2], words[3], words[4], words[5])); } else if (len == 7) { return(ExecuteUpdateSubNode(db, words[1], words[2], words[3], words[4], words[5], words[6])); } else { goto default; } case eCommands.add: if (len == 3) { return(ExecuteAddCollection(db, words[1], words[2])); } else if (len == 4) { return(ExecuteAddTexture(db, words[1], words[2], Path.Combine(filedir, words[3]))); } else if (len == 6) { return(ExecuteAddString(db, words[1], words[2], words[3], words[4], words[5])); } else { goto default; } case eCommands.delete: if (len == 3) { return(ExecuteDeleteCollection(db, words[1], words[2])); } else if (len == 4) { return(ExecuteDeleteTPKSTR(db, words[1], words[2], words[3])); } else { goto default; } case eCommands.copy: if (len == 4) { return(ExecuteCopyCollection(db, words[1], words[2], words[3])); } else if (len == 5) { return(ExecuteCopyTexture(db, words[1], words[2], words[3], words[4])); } else { goto default; } case eCommands.@static: if (!Settings.Default.EnableStaticEnd) { return("Static command execution is not enabled. Unable to process."); } if (len == 4) { return(ExecuteStaticCollection(db, words[1], words[2], words[3])); } else { goto default; } case eCommands.replace: if (len == 5) { return(ExecuteReplaceTexture(db, words[1], words[2], words[3], Path.Combine(filedir, words[4]))); } else { goto default; } case eCommands.import: if (len == 3) { return(ExecuteImportCollection(db, words[1], Path.Combine(filedir, words[2]))); } else { goto default; } case eCommands.move: if (string.IsNullOrWhiteSpace(GlobalDir)) { return("This command can be executed only through endscript."); } if (len == 5) { return(ExecuteMoveCommand(words[1], words[2], filedir, words[3], words[4])); } else { goto default; } case eCommands.erase: if (string.IsNullOrWhiteSpace(GlobalDir)) { return("This command can be executed only through endscript."); } if (len == 4) { return(ExecuteEraseCommand(words[1], words[2], filedir, words[3])); } else { goto default; } case eCommands.create: if (string.IsNullOrWhiteSpace(GlobalDir)) { return("This command can be executed only through endscript."); } if (len == 4) { return(ExecuteCreateCommand(words[1], words[2], filedir, words[3])); } else { goto default; } case eCommands.attach: return("This command can be executed only through endscript."); case eCommands.execute: if (string.IsNullOrWhiteSpace(GlobalDir)) { return("This command can be executed only through endscript."); } if (len == 2) { watch.Stop(); error = Linear.LaunchProcess(Path.Combine(filedir, words[1]), filedir); watch.Start(); return(error); } else { goto default; } case eCommands.@switch: if (len == 3) { return(ExecuteSwitchSetting(words[1], words[2])); } else { goto default; } default: return(error); } }
public static bool ProcessEndscript(string dir, string filepath, BasicBase db, out string label, out string text) { label = null; text = string.Empty; GlobalDir = dir; if (!ProceedSafeLoading(filepath, out var EndLines)) { return(false); } var MenuEndLines = new List <string>(); int begin = -1; int end = -1; for (int loop = 0; loop < EndLines.Count; ++loop) { // If encountered <menu> tag, begin accumulating EndMenu lines if (EndLines[loop].Text == "<menu>") { begin = loop; continue; } // If encountered </menu> tag, stop accumulating EndMenu lines else if (EndLines[loop].Text == "</menu>") { end = loop; continue; } // If accumulating, append and continue else if (begin != -1 && end == -1) { MenuEndLines.Add(EndLines[loop].Text); } else { EndLines[loop].Text = ScriptX.CleanString(EndLines[loop].Text, true); } } if (begin != -1 && end != -1) { EndLines.RemoveRange(begin, end - begin + 1); } int total_line_count = EndLines.Count; var ErrorEndLines = new List <EndLine>(); var window = new Interact.EndMenu(MenuEndLines.ToArray(), Path.GetDirectoryName(filepath)); if (window.ShowDialog() == DialogResult.OK) { string filedir = Path.GetDirectoryName(filepath); watch.Reset(); watch.Start(); foreach (var endline in EndLines) { endline.Error = ExecuteEndscriptLine(endline.Text, db, filedir); if (endline.Error != null) { ErrorEndLines.Add(endline); } } watch.Stop(); if (ErrorEndLines.Count > 0) { var errorwindow = new Interact.ErrorView(ErrorEndLines); errorwindow.ShowDialog(); } var build = new StringBuilder(EndLines.Count * 100); foreach (var endline in EndLines) { build.Append(endline.Text + Environment.NewLine); } text = build.ToString(); label = $"Processed {total_line_count} lines of script in {watch.ElapsedMilliseconds}ms"; GlobalDir = string.Empty; return(true); } else { GlobalDir = string.Empty; return(false); } }