Example #1
0
        public void Parse(ICLIFlags toolFlags)
        {
            var flags  = (ExtractFlags)toolFlags;
            var output = Path.Combine(flags.OutputPath, "Dump", "STU");

            if (!Directory.Exists(output))
            {
                Directory.CreateDirectory(output);
            }

            var serializers = new Dictionary <Type, IDragonMLSerializer> {
                { typeof(teStructuredDataAssetRef <>), new teResourceGUIDSerializer() }
            };

            foreach (var type in new ushort[] {
                0x3, 0x15, 0x18, 0x1A, 0x1B, 0x1F, 0x20, 0x21, 0x24, 0x2C, 0x2D,
                0x2E, 0x2F, 0x30, 0x31, 0x32, 0x39, 0x3A, 0x3B, 0x45, 0x49, 0x4C, 0x4E, 0x51, 0x53, 0x54, 0x55, 0x58,
                0x5A, 0x5B, 0x5E, 0x5F, 0x62, 0x63, 0x64, 0x65, 0x66, 0x68, 0x70, 0x71, 0x72, 0x75, 0x78, 0x79, 0x7A,
                0x7F, 0x81, 0x90, 0x91, 0x95, 0x96, 0x97, 0x98, 0x9C, 0x9D, 0x9E, 0x9F, 0xA0, 0xA2, 0xA3, 0xA5, 0xA6,
                0xA8, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xB5, 0xB7, 0xBF, 0xC0, 0xC2, 0xC5, 0xC6, 0xC7, 0xC9, 0xCA, 0xCC,
                0xCE, 0xCF, 0xD0, 0xD4, 0xD5, 0xD6, 0xD7, 0xD9, 0xDC, 0xDF, 0xEB, 0xEC, 0xEE, 0xF8, 0x10D, 0x114, 0x116,
                0x11A, 0x122
            })
            {
                if (!Directory.Exists(Path.Combine(output, type.ToString("X3"))))
                {
                    Directory.CreateDirectory(Path.Combine(output, type.ToString("X3")));
                }

                foreach (var guid in Program.TrackedFiles[type])
                {
                    try {
                        Logger.Log24Bit(ConsoleSwatch.XTermColor.Purple5, true, Console.Out, null, $"Saving {teResourceGUID.AsString(guid)}");

                        using (var stu = STUHelper.OpenSTUSafe(guid))
                            using (Stream f = File.Open(Path.Combine(output, type.ToString("X3"), teResourceGUID.AsString(guid) + ".xml"), FileMode.Create))
                                using (TextWriter w = new StreamWriter(f)) {
                                    w.WriteLine(DragonML.Print(stu?.Instances[0], new DragonMLSettings {
                                        TypeSerializers = serializers
                                    }));
                                }
                    } catch (Exception e) {
                        Logger.Error("STU", e.ToString());
                    }
                }
            }
        }
Example #2
0
        public static void LogProgress(string message, string pre, string post, double value, XTermColor messageColor, XTermColor preColor, XTermColor postColor, XTermColor brickColor, XTermColor processColor, bool showProgressValue, XTermColor processValueColor)
        {
            if (Console.IsOutputRedirected)
            {
                return;
            }
            var width = Console.WindowWidth;
            var empty = new char[width];

            Fill(empty, ' ');
            if (message != LastMessage)
            {
                Console.Out.Write(empty);
                Console.CursorLeft = 0;
                LastMessage        = message;
                Logger.Log24Bit(messageColor, true, Console.Out, null, message);
            }
            Console.Out.Write(empty);
            Console.CursorLeft = 0;
            var remaining = width - pre.Length - post.Length - 4;

            Logger.Log24Bit(preColor, false, Console.Out, null, pre);
            if (remaining > 0)
            {
                Logger.Log24Bit(brickColor, false, Console.Out, null, " [");
                empty = new char[remaining];
                Fill(empty, ' ');
                Fill(empty, '=', 0, (int)System.Math.Round(remaining * System.Math.Min(value, 1)));
                Logger.Log24Bit(processColor, false, Console.Out, null, string.Join("", empty));
                Logger.Log24Bit(brickColor, false, Console.Out, null, "] ");

                if (showProgressValue && remaining > 6)
                {
                    var valueText = (System.Math.Min(value, 1) * 100).ToString().Split('.')[0] + "%";
                    Console.CursorLeft = pre.Length + 2 + (int)System.Math.Floor(remaining / 2.0d - valueText.Length / 2.0d);
                    Logger.Log24Bit(processValueColor, false, Console.Out, null, valueText);
                    Console.CursorLeft = width - post.Length;
                }
            }
            Logger.Log24Bit(postColor, false, Console.Out, null, post);
            Console.CursorLeft = Console.WindowWidth - 1;
            Console.CursorTop -= 1;
        }
Example #3
0
        private static void HandleSingleException(Exception ex)
        {
            if (ex is TargetInvocationException fex)
            {
                ex = fex.InnerException ?? ex;
            }

            Logger.Log24Bit(ConsoleSwatch.XTermColor.HotPink3, true, Console.Error, null, ex.Message);
            Logger.Log24Bit(ConsoleSwatch.XTermColor.MediumPurple, true, Console.Error, null, ex.StackTrace);

            if (ex is BLTEDecoderException decoder)
            {
                File.WriteAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"BLTEDump-{AppDomain.CurrentDomain.FriendlyName}_{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()}.blte"), decoder.GetBLTEData());
            }

            if (ex.InnerException != null)
            {
                HandleSingleException(ex.InnerException);
            }
        }
Example #4
0
        public void Parse(ICLIFlags toolFlags)
        {
            var flags  = (RenderFlags)toolFlags;
            var output = Path.Combine(flags.OutputPath, "UI", "Render");

            if (!Directory.Exists(output))
            {
                Directory.CreateDirectory(output);
            }

            var serializers = new Dictionary <Type, IDragonMLSerializer> {
                { typeof(teStructuredDataAssetRef <>), new teResourceGUIDSerializer() }
            };

            foreach (var type in new ushort[] { 0x5E, 0x5A, 0x45 })
            {
                if (!Directory.Exists(Path.Combine(output, type.ToString("X3"))))
                {
                    Directory.CreateDirectory(Path.Combine(output, type.ToString("X3")));
                }

                foreach (var guid in Program.TrackedFiles[type])
                {
                    Logger.Log24Bit(ConsoleSwatch.XTermColor.Purple5, true, Console.Out, null, $"Saving {teResourceGUID.AsString(guid)}");

                    using (Stream f = File.Open(Path.Combine(output, type.ToString("X3"), teResourceGUID.AsString(guid)), FileMode.Create))
                        using (Stream d = IO.OpenFile(guid)) {
                            d.CopyTo(f);
                        }

                    using (var stu = STUHelper.OpenSTUSafe(guid))
                        using (Stream f = File.Open(Path.Combine(output, type.ToString("X3"), teResourceGUID.AsString(guid) + ".xml"), FileMode.Create))
                            using (TextWriter w = new StreamWriter(f)) {
                                w.WriteLine(DragonML.Print(stu?.Instances[0], new DragonMLSettings {
                                    TypeSerializers = serializers
                                }));
//                        w.WriteLine(JsonConvert.SerializeObject(stu?.Instances[0], Formatting.Indented, settings));
                            }
                }
            }
        }
Example #5
0
        private static void Main()
        {
            InitTankSettings();

            HookConsole();

            var tools = GetTools();

        #if DEBUG
            FlagParser.CheckCollisions(typeof(ToolFlags), (flag, duplicate) => {
                Logger.Error("Flag", $"The flag \"{flag}\" from {duplicate} is a duplicate!");
            });
        #endif

            FlagParser.LoadArgs();

            Logger.Info("Core", $"{Assembly.GetExecutingAssembly().GetName().Name} v{Util.GetVersion(typeof(Program).Assembly)}");

            Logger.Info("Core", $"CommandLine: [{string.Join(", ", FlagParser.AppArgs.Select(x => $"\"{x}\""))}]");

            Flags = FlagParser.Parse <ToolFlags>(full => PrintHelp(full, tools));
            if (Flags == null)
            {
                return;
            }

            Logger.Info("Core", $"CommandLineFile: {FlagParser.ArgFilePath}");

            if (Flags.SaveArgs)
            {
                FlagParser.AppArgs = FlagParser.AppArgs.Where(x => !x.StartsWith("--arg")).ToArray();
                FlagParser.SaveArgs(Flags.OverwatchDirectory);
            }
            else if (Flags.ResetArgs || Flags.DeleteArgs)
            {
                FlagParser.ResetArgs();

                if (Flags.DeleteArgs)
                {
                    FlagParser.DeleteArgs();
                }

                Logger.Info("Core", $"CommandLineNew: [{string.Join(", ", FlagParser.AppArgs.Select(x => $"\"{x}\""))}]");
                Flags = FlagParser.Parse <ToolFlags>(full => PrintHelp(full, tools));
                if (Flags == null)
                {
                    return;
                }
            }

            if (string.IsNullOrWhiteSpace(Flags.OverwatchDirectory) || string.IsNullOrWhiteSpace(Flags.Mode) || Flags.Help)
            {
                PrintHelp(false, tools);
                return;
            }

            ITool         targetTool           = null;
            ICLIFlags     targetToolFlags      = null;
            ToolAttribute targetToolAttributes = null;

            #region Tool Activation

            foreach (var type in tools)
            {
                var attribute = type.GetCustomAttribute <ToolAttribute>();

                if (!string.Equals(attribute.Keyword, Flags.Mode, StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }
                targetTool           = Activator.CreateInstance(type) as ITool;
                targetToolAttributes = attribute;

                if (attribute.CustomFlags != null)
                {
                    var flags = attribute.CustomFlags;
                    if (typeof(ICLIFlags).IsAssignableFrom(flags))
                    {
                        targetToolFlags = typeof(FlagParser).GetMethod(nameof(FlagParser.Parse), new Type[] { })
                                          ?.MakeGenericMethod(flags)
                                          .Invoke(null, null) as ICLIFlags;
                    }
                }

                break;
            }

            if (targetToolFlags == null && targetTool != null)
            {
                return;
            }

            if (targetTool == null)
            {
                FlagParser.Help <ToolFlags>(false, new Dictionary <string, string>());
                PrintHelp(false, tools);
                return;
            }

            #endregion

            if (!targetToolAttributes.UtilNoArchiveNeeded)
            {
                try {
                    InitStorage(Flags.Online);
                } catch {
                    Logger.Log24Bit(ConsoleSwatch.XTermColor.OrangeRed, true, Console.Error, "CASC",
                                    "=================\nError initializing CASC!\n" +
                                    "Please Scan & Repair your game, launch it for a minute, and try the tools again before reporting a bug!\n" +
                                    "========================");
                    throw;
                }

                //foreach (KeyValuePair<ushort, HashSet<ulong>> type in TrackedFiles.OrderBy(x => x.Key)) {
                //    //Console.Out.WriteLine($"Found type: {type.Key:X4} ({type.Value.Count} files)");
                //    Console.Out.WriteLine($"Found type: {type.Key:X4}");
                //}

                InitKeys();
                InitMisc();
            }

            var stopwatch = new Stopwatch();
            Logger.Info("Core", "Tooling...");
            stopwatch.Start();
            targetTool.Parse(targetToolFlags);
            stopwatch.Stop();

            Logger.Success("Core", $"Execution finished in {stopwatch.Elapsed} seconds");

            ShutdownMisc();
        }