Exemplo n.º 1
0
        static void Main(string[] args)
        {
            System.IO.Directory.CreateDirectory("Red4Assembler/debug");
            System.IO.Directory.CreateDirectory("Red4Assembler/tests");

            var scriptFile = "final.redscripts";

            if (args.Length > 0 && string.IsNullOrWhiteSpace(args[0]) == false)
            {
                scriptFile = args[0];
            }

            const bool validate = true;

            CacheFile scriptCacheFile;
            var       fileBytes = File.ReadAllBytes(scriptFile);

            using (var input = new MemoryStream(fileBytes, false))
                scriptCacheFile = CacheFile.Load(input, validate);

            var functionBodyScripts =
                scriptCacheFile.Definitions
                .OfType <FunctionDefinition>()
                .Where(t => t.Flags.HasFlag(FunctionFlags.HasBody))
                .OrderBy(f => f.SourceFile?.Path)
                .ThenBy(f => f.SourceLine)
                .ToArray();

            var dism = new FunctionDissembler();

            System.IO.File.WriteAllText("Red4Assembler/tests/GetActionAnimationSlideParams.non_ref.ws", dism.Dissemble(functionBodyScripts[0]));
            System.IO.File.WriteAllText("Red4Assembler/tests/GetActionAnimationSlideParams.ref_param.ws", dism.Dissemble(functionBodyScripts[1]));

            // Console.ReadLine();
        }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            const bool validate = true;

            CacheFile cache;
            var       fileBytes = File.ReadAllBytes(args[0]);

            using (var input = new MemoryStream(fileBytes, false))
            {
                cache = CacheFile.Load(input, validate);
            }

            RemoveStaticArraySizeUsage(cache);

            var mySourceFile = new SourceFileDefinition(@"_\gibbed\exec.script");

            cache.Definitions.Add(mySourceFile);

            AddExecCommandSTS(cache, mySourceFile);
            AddMinimapScaler(cache);

            PatchJohnnySkillChecks(cache);

            byte[] testCacheBytes;
            using (var output = new MemoryStream())
            {
                cache.Save(output);
                output.Flush();
                testCacheBytes = output.ToArray();
            }

            File.WriteAllBytes("test_patch.redscripts", testCacheBytes);
        }
Exemplo n.º 3
0
        public static void Main(string[] args)
        {
            const bool validate = true;

            CacheFile cache;
            var       fileBytes = File.ReadAllBytes(args[0]);

            using (var input = new MemoryStream(fileBytes, false))
            {
                cache = CacheFile.Load(input, validate);
            }

            byte[] testCacheBytes;
            using (var output = new MemoryStream())
            {
                cache.Save(output);
                output.Flush();
                testCacheBytes = output.ToArray();
            }

            File.WriteAllBytes("test_roundtrip.redscripts", testCacheBytes);
            CacheFile testCache;

            using (var input = new MemoryStream(testCacheBytes, false))
            {
                testCache = CacheFile.Load(input, validate);
            }

            DumpExecCallableFunctions(cache);
            DumpFunctions(cache, validate);
            DumpEnumerations(cache);
        }
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            if (args[0].Length == 0)
            {
                throw new ArgumentException("You must provide a final.redscripts file!");
            }

            byte[] fileBytes = File.ReadAllBytes(args[0]);

            using MemoryStream input  = new MemoryStream(fileBytes, false);
            using MemoryStream output = new MemoryStream();

            cache = CacheFile.Load(input, false);
            cg    = new CodeGenerator();

            CreateNatives();
            CreateFunctions();

            ApplyPatches();

            cache.Save(output);
            output.Flush();

            File.WriteAllBytes("output.redscripts", output.ToArray());
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            //AR.Compiler.Class1.doTheThing();
            if (args.Length == 0)
            {
                Console.WriteLine("ScriptCompileTester called with <= 1 args, running internal testing code");
                //AR.Compiler.InternalTestClass.doTheThing();
                ScriptDecompilerLib.Class1.doTheThing();
            }
            else if (args.Length == 3 && args[0] == "compile")
            {
                var cacheFileBytes  = File.ReadAllBytes(args[1]);
                var cacheFileStream = new MemoryStream(cacheFileBytes, false);
                var cacheFile       = CacheFile.Load(cacheFileStream, true);

                string script       = File.ReadAllText(args[2]);
                var    parserResult = AR.Compiler.NetAPI.ParseScript(script);

                foreach (var import in parserResult.Imports)
                {
                    Console.WriteLine(String.Format("Adding import to cache: {0}", import.PrettyPrint()));
                    AR.Compiler.NetAPI.AddDefToCacheNoDupes(cacheFile, import.GetDefinition(cacheFile));
                }

                foreach (var func in parserResult.Functions)
                {
                    Console.WriteLine(String.Format("Adding func to cache: {0}", func.PrettyPrint()));
                    var funcDef = func.GetDefinition(cacheFile);
                    AR.Compiler.NetAPI.AddFuncToCache(cacheFile, funcDef);

                    Console.WriteLine("Disassembly: ");
                    var sb = new StringBuilder();
                    TestDisassemblerLib.TestDisassemblerLib.DumpFunction(cacheFile, funcDef, sb, false);
                    Console.WriteLine(sb.ToString());
                }

                foreach (var parsedClass in parserResult.Classes)
                {
                    Console.WriteLine(String.Format("Adding class to cache: {0}", parsedClass.PrettyPrint()));
                    AR.Compiler.NetAPI.AddClassToCache(cacheFile, parsedClass.GetDefinition(cacheFile));
                }
            }
            else
            {
                Console.WriteLine("ScriptCompileTester called with invalid args. Usage: ScriptCompileTester compile <cache file path> <script file path>");
            }
        }
Exemplo n.º 6
0
        public static void Main(string[] args)
        {
            const bool validate = true;

            CacheFile scriptCacheFile;
            var       fileBytes = File.ReadAllBytes(args[0]);

            using (var input = new MemoryStream(fileBytes, false))
            {
                scriptCacheFile = CacheFile.Load(input, validate);
            }

            string             currentSourcePath = null;
            FunctionDefinition previousFunction  = null;
            var sb = new StringBuilder();

            foreach (var function in scriptCacheFile.Definitions
                     .OfType <FunctionDefinition>()
                     .Where(t => t.Flags.HasFlag(FunctionFlags.HasBody))
                     .OrderBy(f => f.SourceFile?.Path)
                     .ThenBy(f => f.SourceLine))
            {
                if (previousFunction != null)
                {
                    sb.AppendLine();
                }

                if (function.SourceFile?.Path != currentSourcePath)
                {
                    currentSourcePath = function.SourceFile?.Path;
                    if (previousFunction != null)
                    {
                        sb.AppendLine();
                        sb.AppendLine();
                        sb.AppendLine();
                    }
                    sb.AppendLine($"// SOURCE PATH: {currentSourcePath ?? "UNKNOWN"}");
                    sb.AppendLine();
                }

                DumpFunction(function, sb, validate);
                previousFunction = function;
            }

            File.WriteAllText("test_function_dump.txt", sb.ToString(), Encoding.UTF8);
        }
Exemplo n.º 7
0
        public static int Main(string[] args)
        {
            const bool validate = true;

            if (args.Length != 1)
            {
                Console.Error.WriteLine("Please provide path to 'final.redscripts' as the first argument.");
                return(1);
            }

            CacheFile cache;
            var       fileBytes = File.ReadAllBytes(args[0]);

            using (var input = new MemoryStream(fileBytes, false))
            {
                cache = CacheFile.Load(input, validate);
            }

            byte[] testCacheBytes;
            using (var output = new MemoryStream())
            {
                cache.Save(output);
                output.Flush();
                testCacheBytes = output.ToArray();
            }

            File.WriteAllBytes("test_roundtrip.redscripts", testCacheBytes);
            CacheFile testCache;

            using (var input = new MemoryStream(testCacheBytes, false))
            {
                testCache = CacheFile.Load(input, validate);
            }

            DumpConsoleCallableFunctions(cache);
            DumpGameInstanceClasses(cache);
            DumpClass(cache.GetClass("TDB"), "TDB_functions.txt");
            DumpFunctions(cache, validate);
            DumpFunctionsToRespectiveFiles(cache);
            DumpEnumerations(cache);
            return(0);
        }
Exemplo n.º 8
0
        public static void Main(string[] args)
        {
            const bool validate = true;

            CacheFile cache;
            var       fileBytes = File.ReadAllBytes("final.redscripts");

            using (var input = new MemoryStream(fileBytes, false))
            {
                cache = CacheFile.Load(input, validate);
            }

            RemoveStaticArraySizeUsage(cache);

            var mySourceFile = new SourceFileDefinition(@"_\gibbed\exec.script");

            cache.Definitions.Add(mySourceFile);

            //AddExecCommandSTS(cache, mySourceFile);
            //AddMinimapScaler(cache);
            //PatchJohnnySkillChecks(cache);
            //EveryoneKillableTest(cache);
            //SortDialerRemoveQuestRelated(cache);
            //SortMessagesByNameAsc(cache);
            //SortQuestLogByLevelAsc(cache);
            TestFunctionsDefs(cache);

            byte[] testCacheBytes;
            using (var output = new MemoryStream())
            {
                cache.Save(output);
                output.Flush();
                testCacheBytes = output.ToArray();
            }

            File.WriteAllBytes("final-test.redscripts", testCacheBytes);
        }