Exemplo n.º 1
0
        private void HandleFile(string filePath)
        {
            try
            {
                // parse lua file
                var file = LuaFileFactory.Create(filePath, UsesDebugInfo);

#if DEBUG
                Console.WriteLine($"Decompiling file: {filePath}");
#endif

                // decompile file
                var output = _decompiler.Decompile(file);

                // replace extension
                var outFileName = Path.ChangeExtension(filePath, ".dec.lua");

                // save output
                File.WriteAllText(outFileName, output);

                Console.WriteLine($"Decompiled file: {filePath}");
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error while decompiling file: {filePath}");
                Console.WriteLine(e);
            }
        }
Exemplo n.º 2
0
        private static void Main(string[] args)
        {
            //
            Console.WriteLine("CoD Havok Decompiler made from katalash's DSLuaDecompiler");

            // setup dependency injection
            var builder = new ContainerBuilder();

            // CoDHavokTool.Common
            builder.Register((context, parameters) =>
            {
                if (parameters.Count() != 1)
                {
                    throw new ArgumentOutOfRangeException();
                }

                return(LuaFileFactory.Create(parameters.Positional <string>(0)));
            }).As <ILuaFile>().InstancePerLifetimeScope();

            // CoDHavokTool.LuaDecompiler
            builder.RegisterType <Decompiler>().As <IDecompiler>().SingleInstance();

            // CodHavokTool
            builder.RegisterType <Program>().SingleInstance();


            var container = builder.Build();

            container.Resolve <Program>().Main(args);
        }
Exemplo n.º 3
0
        private void HandleFile(string filePath)
        {
            try
            {
                // parse lua file
                var file = LuaFileFactory.Create(filePath);

                // decompile file
                var output = _decompiler.Decompile(file);

                // replace extension
                var outFileName = Path.ChangeExtension(filePath, ".dec.lua");

                // save output
                File.WriteAllText(outFileName, output);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Exemplo n.º 4
0
        private static async Task Main(string[] args)
        {
            Console.WriteLine("CoD Lua Decompiler");

            // setup dependency injection
            var builder = new ContainerBuilder();

            // CoDHavokTool.Common
            builder.Register((context, parameters) =>
            {
                if (parameters.Count() != 1)
                {
                    throw new ArgumentOutOfRangeException();
                }

                return(LuaFileFactory.Create(parameters.Positional <string>(0)));
            }).As <ILuaFile>().InstancePerLifetimeScope();

            // CoDHavokTool.LuaDecompiler
            builder.RegisterType <Decompiler.Decompiler>().As <IDecompiler>().SingleInstance();

            // CodHavokTool
            builder.RegisterType <GithubUpdateChecker>().SingleInstance();
            builder.RegisterType <AssetExport>().As <IAssetExport>().SingleInstance();
            builder.RegisterType <PackageIndex>().As <IPackageIndex>().SingleInstance();
            builder.RegisterType <Program>().SingleInstance();

            var container  = builder.Build();
            var updateTask = container.Resolve <GithubUpdateChecker>().CheckForUpdate();

            container.Resolve <Program>().Main(args);
            await updateTask;

            Console.WriteLine("Press enter to exit");
            Console.ReadLine();
        }
Exemplo n.º 5
0
        private void HandleLuaFiles(List <LuaFileData> luaFiles, IGame game, bool dumpRaw = false)
        {
            Parallel.ForEach(luaFiles, file =>
            {
                string filePath = file.Name;
                if (String.IsNullOrEmpty(filePath))
                {
                    ulong hashNumber = (ulong)(file.Hash & 0xFFFFFFFFFFFFFFF);

                    if (_hashEntries.ContainsKey(hashNumber))
                    {
                        filePath = _hashEntries[hashNumber];
                    }
                    else
                    {
                        filePath = String.Format("Luafile_{0:x}", hashNumber);
                    }
                }


                var directory = Path.GetDirectoryName(game.ExportFolder + filePath);
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory !);
                }

                var outFileName = Path.ChangeExtension(game.ExportFolder + filePath, ".dec.lua");

                // Check if we already decompiled the file
                string hash = "";
                if (File.Exists(outFileName))
                {
                    string line = File.ReadLines(outFileName).FirstOrDefault();
                    if (!String.IsNullOrEmpty(line) && line.StartsWith("-- "))
                    {
                        var checksum = line.Remove(0, 3);
                        hash         = GetHash(file);
                        if (checksum == hash)
                        {
                            return;
                        }
                    }
                }

                if (dumpRaw)
                {
                    using (var fileStream = File.Create(Path.ChangeExtension(game.ExportFolder + filePath, ".luac")))
                    {
                        file.Reader.BaseStream.Seek(0, SeekOrigin.Begin);
                        file.Reader.BaseStream.CopyTo(fileStream);
                    }
                }

                var luaFile = LuaFileFactory.Create(file.Reader, null);
                try
                {
                    if (String.IsNullOrEmpty(hash))
                    {
                        hash = GetHash(file);
                    }
                    var prefix         = $"-- {hash}\n-- This hash is used for caching, delete to decompile the file again\n\n";
                    var decompiledFile = _decompiler.Decompile(luaFile);

                    // save output
                    File.WriteAllText(outFileName, prefix + decompiledFile);
                    Console.WriteLine($"Decompiled file: {Path.GetFileName(filePath)}");
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Error while trying to decompile file {Path.GetFileName(filePath)}: {e.Message}");
                }
            });
        }