예제 #1
0
        public string Decompile(MSCScript script)
        {
            var analyzer = new MSCAnalyzer(script);

            analyzer.Analyze_1();
            Target  = script;
            Manager = new MSCCommandManager(Target);
            StringBuilder sb = new StringBuilder();

            while (!Manager.End)
            {
                MSCCommand cmd = Manager.Next();

                // Do ending brackets
                while (INDENT_STACK.Contains(cmd.FileOffset - 0x30))
                {
                    INDENT_STACK.Remove(cmd.FileOffset - 0x30);
                    foreach (int off in INDENT_STACK)
                    {
                        sb.Append("   ");
                    }

                    sb.Append("}\n");
                }

                // If the command is passed to the next add it to the assignment stack
                if (Manager.Position != script.Count &&
                    cmd.Ident == 0x0A && Manager.PeekNext().Ident == 0x36)
                {
                    sb.Append(DoIndent(cmd.ToString()) + "\n");
                    continue;
                }
                else if (cmd.Returns)
                {
                    COMMANDS.Push(cmd);
                    continue;
                }

                sb.Append(DecompileCMD(cmd) /*.TrimEnd() + $" \t// 0x{cmd.FileOffset - 0x30:X}*/ + "\n");
            }
            return(sb.ToString());
        }
예제 #2
0
        public MSCScript ParseScript(BinaryReader reader, uint offset, int size)
        {
            MSCScript script = new MSCScript(Offsets.IndexOf(offset), offset)
            {
                File = this
            };

            if (offset - HEADER_SIZE == EntryPoint)
            {
                script.IsEntrypoint = true;
            }

            reader.BaseStream.Seek(offset, SeekOrigin.Begin);
            uint ident;

            while (reader.BaseStream.Position != offset + size)
            {
                ident = reader.ReadByte();
                var cmd = new MSCCommand(ident);
                cmd.FileOffset = (int)reader.BaseStream.Position - 1;
                for (int i = 0; i < cmd.ParamSpecifiers.Length; i++)
                {
                    switch (cmd.ParamSpecifiers[i])
                    {
                    case "B":
                        cmd.Parameters.Add(reader.ReadByte());
                        break;

                    case "I":
                        cmd.Parameters.Add(reader.ReadBint32());
                        break;

                    case "H":
                        cmd.Parameters.Add(reader.ReadBint16());
                        break;
                    }
                }
                script.Add(cmd);
            }

            return(script);
        }
예제 #3
0
 public MSCFunction(MSCScript target, params object[] parameters)
 {
     TargetScript = target;
     Parameters   = parameters;
 }
예제 #4
0
 public MSCAnalyzer(MSCScript script)
 {
     Target    = script;
     _commands = new List <Tuple <int, MSCCommand> >();
     Manager   = new MSCCommandManager(Target);
 }
예제 #5
0
 public MSCCommandManager(MSCScript script)
 {
     Position = 0;
     End      = false;
     Script   = script;
 }