Ejemplo n.º 1
0
        public string Decompile(byte[] code)
        {
            SCUMMLineBuilder lineBuilder = new SCUMMLineBuilder();

            InitOpcodes();

            this.code = code;

            StringBuilder builder = new StringBuilder();

            using (Stream stream = new MemoryStream(code))
                using (reader = new BinReader(stream))
                {
                    while (reader.Position < reader.Size)
                    {
                        ulong offset = reader.Position;
                        byte  opcode = reader.ReadU8();
                        Func <int, SCUMMCommand> handler;
                        if (!opcodeHandlers.TryGetValue(opcode, out handler))
                        {
                            throw new SCUMMDecompilerException("Unexpected opcode: {0}", opcode);
                        }
                        SCUMMCommand cmd = handler(opcode);
                        cmd.Offset = offset;
                        builder.AppendLine(lineBuilder.GetLine(cmd));
                    }
                }

            return(builder.ToString());
        }
Ejemplo n.º 2
0
        public string GetLine(SCUMMCommand cmd)
        {
            if (opcodeFormats.ContainsKey(cmd.Opcode))
            {
                return(String.Format(opcodeFormats[cmd.Opcode], cmd.Parameters));
            }

            return(cmd.ToString());
        }