Example #1
0
        public static string getParam(byte tp, UInt16 vl, OProg prog)
        {
            if (tp == ARG_STR)
            {
                foreach (OProg.OString s in prog.strings)
                {
                    if (s.ofs == vl)
                    {
                        return("s" + s.id.ToString());
                    }
                }
                throw new Exception("String Not Found " + vl.ToString("X4"));
            }
            string res = "";

            switch (tp)
            {
            case ARG_IMM: res = "i"; break;

            case ARG_WORD: res = "w"; break;

            case ARG_BYTE: res = "b"; break;

            case ARG_CODE: res = "c"; break;

            default:
                throw new Exception("Anknown arg type " + tp.ToString());
            }
            res += vl.ToString("X4");
            return(res);
        }
Example #2
0
 public static string decompile(OProg prog,string eol)
 {
     foreach(OProg.OString s in prog.strings)
         s.state=0;
     int pos = 0;
     byte[] data=prog.code;
     string res = "";
     while (pos < data.Length)
     {
         byte op = data[pos++];
         if (op >= Opcodes.OPCODE_SIZE)
             throw new Exception(string.Format("Bad Opcode {0:X2} @ {1:X4}",op,pos));
         foreach (Opcodes.opcode b in Opcodes.opcodes)
         {
             if (b.op == op)
             {
                 string s=b.name+"(";
                 for (int i=0;i<b.prms;i++)
                 {
                     byte ptp=data[pos++];
                     s+=getParam(ptp,BinHelper.read_U16LE(data,pos),prog);
                     pos+=2;
                     if (i < b.prms - 1)
                         s += ",";
                 }
                 s+=")"+eol;
                 res += s;
                 break;
             }
         }
     }
     return res;
 }
Example #3
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int    id = (int)comboBox1.SelectedItem;
            OProg  p  = progs.progs[id];
            string s  = String.Format("--{0:X4}--\r\n", p.data.Length);

            s            += String.Format("u0:{0:X4}\r\nexitCnt:{1:X4}\r\n", p.u0, p.exitsCnt);
            s            += String.Format("actorsCnt:{0:X4}\r\nu6:{1:X4}\r\n", p.actorsCnt, p.u6);
            s            += String.Format("exits:{0:X4}\r\nactors:{1:X4}\r\n", p.exits, p.actors);
            s            += String.Format("sprites:{0:X4}\r\nentry:{1:X4}\r\n", p.sprites, p.entry);
            textBox2.Text = s;
            textBox4.Text = "";
            foreach (OProg.OString ss in p.strings)
            {
                textBox4.Text += String.Format("{0:d}:{1:X4}:{2:s}\r\n", ss.id, ss.ofs, ss.data);
            }
            //textBox3.Text = Decompiler.decompile(p, "\r\n");
        }
Example #4
0
        public static string decompile(OProg prog, string eol)
        {
            foreach (OProg.OString s in prog.strings)
            {
                s.state = 0;
            }
            int pos = 0;

            byte[] data = prog.code;
            string res  = "";

            while (pos < data.Length)
            {
                byte op = data[pos++];
                if (op >= Opcodes.OPCODE_SIZE)
                {
                    throw new Exception(string.Format("Bad Opcode {0:X2} @ {1:X4}", op, pos));
                }
                foreach (Opcodes.opcode b in Opcodes.opcodes)
                {
                    if (b.op == op)
                    {
                        string s = b.name + "(";
                        for (int i = 0; i < b.prms; i++)
                        {
                            byte ptp = data[pos++];
                            s   += getParam(ptp, BinHelper.read_U16LE(data, pos), prog);
                            pos += 2;
                            if (i < b.prms - 1)
                            {
                                s += ",";
                            }
                        }
                        s   += ")" + eol;
                        res += s;
                        break;
                    }
                }
            }
            return(res);
        }
Example #5
0
 public static string getParam(byte tp,UInt16 vl,OProg prog)
 {
     if (tp == ARG_STR)
     {
         foreach (OProg.OString s in prog.strings)
             if (s.ofs == vl)
                 return "s" + s.id.ToString();
         throw new Exception("String Not Found "+vl.ToString("X4"));
     }
     string res = "";
     switch (tp)
     {
         case ARG_IMM: res = "i"; break;
         case ARG_WORD: res = "w"; break;
         case ARG_BYTE: res = "b"; break;
         case ARG_CODE: res = "c"; break;
         default:
             throw new Exception("Anknown arg type " + tp.ToString());
     }
     res += vl.ToString("X4");
     return res;
 }