Tool dedicated to isohacking for Xenosaga on Playstation 2
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
4.8 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. using System.Collections.Generic;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using System.Text;
  5. namespace Hack.Xenosaga.Common
  6. {
  7. public class Functions
  8. {
  9. public static void usage()
  10. {
  11. Trace.WriteLine("");
  12. Trace.WriteLine("xenosaga <option> <file> [encode/regroup]");
  13. Trace.WriteLine(" option : -l = List files from index");
  14. Trace.WriteLine(" -u = Unpack files from index");
  15. Trace.WriteLine(" -p = Pack files from index");
  16. Trace.WriteLine(" -e = Extract text from file");
  17. Trace.WriteLine(" file : Index file (the first one of each decade : xenosaga.00, xenosaga.10, xenosaga.20...)");
  18. Trace.WriteLine(" encode : (-e) Encoding of the output/input file (ANSI( default), ASCII, UTF8, UNICODE)");
  19. Trace.WriteLine(" regroup : (-p) true to pack all files in only one (ex: 11, 12, 13 in 11) ; false or empty (default) to keep the same system of increment files");
  20. }
  21. public static bool CheckArgs(string[] args, out Variables.stArgs listArgs)
  22. {
  23. listArgs = new Variables.stArgs();
  24. List<string> listActions = new List<string>() { "-l", "-p", "-u", "-e", "-i" };
  25. Trace.Write("Checking arguments : ");
  26. if (args.Length != 2 && args.Length != 3)
  27. {
  28. Trace.WriteLine("Incorrect number of parameter!");
  29. return false;
  30. }
  31. if (!listActions.Contains(args[0]))
  32. {
  33. Trace.WriteLine("Incorrect parameter - unknown <option>");
  34. return false;
  35. }
  36. if (!File.Exists(args[1]) && !Directory.Exists(args[1]))
  37. {
  38. Trace.WriteLine("Incorrect parameter - unknown <file>");
  39. return false;
  40. }
  41. if ((args.Length == 3 && args[0] == "-p") && (args[2] != "true" && args[2] != "false"))
  42. {
  43. Trace.WriteLine("Incorrect parameter - unknown <regroup>");
  44. return false;
  45. }
  46. if ((args.Length == 3 && (args[0] == "-e" || args[0] == "-i")) && (args[2] != "ANSI" && args[2] != "ASCII" && args[2] != "UTF8" && args[2] != "UNICODE"))
  47. {
  48. Trace.WriteLine("Incorrect parameter - unknown <encode>");
  49. return false;
  50. }
  51. listArgs.option = args[0];
  52. listArgs.filename = args[1];
  53. if (args.Length == 3 && listArgs.option == "-p")
  54. listArgs.regroup = args[2] == "true" ? true : false;
  55. listArgs.encode = args.Length == 2 ? Encoding.Default : null;
  56. if (args.Length == 3 && (listArgs.option == "-e" || listArgs.option == "-i"))
  57. {
  58. switch (args[2])
  59. {
  60. case "ASCII":
  61. listArgs.encode = Encoding.ASCII;
  62. break;
  63. case "UTF8":
  64. listArgs.encode = Encoding.UTF8;
  65. break;
  66. case "UNICODE":
  67. listArgs.encode = Encoding.Unicode;
  68. break;
  69. case "ANSI":
  70. default:
  71. listArgs.encode = Encoding.Default;
  72. break;
  73. }
  74. }
  75. Trace.WriteLine("OK");
  76. return true;
  77. }
  78. public static void ManageListener(bool consoleTrace, bool fileTrace = false, StreamWriter sw = null)
  79. {
  80. string traceFileName = "TraceFile";
  81. string traceConsoleName = "TraceConsole";
  82. for (int i = 0; i < Trace.Listeners.Count; i++)
  83. {
  84. TraceListener trace = Trace.Listeners[i];
  85. if (trace.Name == "Default" || (trace.Name == traceConsoleName && !consoleTrace) || (trace.Name == traceFileName && !fileTrace))
  86. {
  87. Trace.Listeners.Remove(trace);
  88. trace.Dispose();
  89. }
  90. }
  91. if (consoleTrace)
  92. {
  93. ConsoleTraceListener traceConsole = new ConsoleTraceListener();
  94. traceConsole.Name = traceConsoleName;
  95. Trace.Listeners.Add(traceConsole);
  96. }
  97. if (fileTrace)
  98. {
  99. TextWriterTraceListener traceFile = new TextWriterTraceListener(sw);
  100. traceFile.Name = traceFileName;
  101. Trace.Listeners.Add(traceFile);
  102. }
  103. }
  104. public static void Padding(MemoryStream ms)
  105. {
  106. long size = ms.Length;
  107. while (size % 4 != 0)
  108. {
  109. ms.WriteByte(0);
  110. size++;
  111. }
  112. }
  113. }
  114. }