Exemplo n.º 1
0
        /// <exception cref="Kirikiri.Tjs2.TJSException"></exception>
        private void ReadObjects(ScriptBlock block, BinaryReader br)
        {
            int totalSize = br.ReadInt32();

            string[]     strarray = mStringArray;
            ByteBuffer[] bbarray  = mByteBufferArray;
            double[]     dblarray = mDoubleArray;
            byte[]       barray   = mByteArray;
            short[]      sarray   = mShortArray;
            int[]        iarray   = mIntArray;
            long[]       larray   = mLongArray;
            int          toplevel = br.ReadInt32();
            int          objcount = br.ReadInt32();

            mObjectsCache.Create(objcount);
            InterCodeObject[]       objs = mObjectsCache.mObjs;
            AList <VariantRepalace> work = mObjectsCache.mWork;

            int[]   parent           = mObjectsCache.mParent;
            int[]   propSetter       = mObjectsCache.mPropSetter;
            int[]   propGetter       = mObjectsCache.mPropGetter;
            int[]   superClassGetter = mObjectsCache.mSuperClassGetter;
            int[][] properties       = mObjectsCache.mProperties;
            for (int o = 0; o < objcount; o++)
            {
                if (br.ReadChars(4).ToRealString() != FILE_TAG_LE)
                {
                    throw new TjsException("ByteCode Broken");
                }
                int objsize = br.ReadInt32();
                parent[o] = br.ReadInt32();
                int name                        = br.ReadInt32();
                int contextType                 = br.ReadInt32();
                int maxVariableCount            = br.ReadInt32();
                int variableReserveCount        = br.ReadInt32();
                int maxFrameCount               = br.ReadInt32();
                int funcDeclArgCount            = br.ReadInt32();
                int funcDeclUnnamedArgArrayBase = br.ReadInt32();
                int funcDeclCollapseBase        = br.ReadInt32();
                propSetter[o]       = br.ReadInt32();
                propGetter[o]       = br.ReadInt32();
                superClassGetter[o] = br.ReadInt32();
                int        count  = br.ReadInt32();
                LongBuffer srcpos = null;
                // codePos/srcPos は今のところ使ってない、ソート济みなので、longにする必要はないが……
                // codePos/srcPos currently not used. it's for debug. Please refer to newer krkrz code and fix here later.
                if (count > 0)
                {
                    for (int i = 0; i < count; i++)
                    {
                        br.ReadInt64();
                    }
                }
                else
                {
                    //br.BaseStream.Seek(count << 3, SeekOrigin.Current);
                    //br.ReadInt32();
                }

                count = br.ReadInt32();
                short[] code = new short[count];
                for (int i = 0; i < count; i++)
                {
                    code[i] = br.ReadInt16();
                }
                //TranslateCodeAddress( block, code, codeSize );
                var padding = 4 - (count * 2) % 4;
                if (padding > 0 && padding < 4)
                {
                    br.ReadBytes(padding);
                }

                count = br.ReadInt32();
                int vcount = count * 2;
                if (mVariantTypeData == null || mVariantTypeData.Length < vcount)
                {
                    mVariantTypeData = new short[vcount];
                }
                for (int i = 0; i < vcount; i++)
                {
                    mVariantTypeData[i] = br.ReadInt16();
                }
                Variant[] vdata     = new Variant[count];
                int       datacount = count;
                Variant   tmp;
                for (int i = 0; i < datacount; i++)
                {
                    int pos   = i << 1;
                    int type  = mVariantTypeData[pos];
                    int index = mVariantTypeData[pos + 1];
                    switch (type)
                    {
                    case TYPE_VOID:
                    {
                        vdata[i] = new Variant();
                        // null
                        break;
                    }

                    case TYPE_OBJECT:
                    {
                        vdata[i] = new Variant(null, null);
                        // null Array Dictionary はまだサポートしていない TODO
                        break;
                    }

                    case TYPE_INTER_OBJECT:
                    {
                        tmp = new Variant();
                        work.AddItem(new VariantRepalace(tmp, index));
                        vdata[i] = tmp;
                        break;
                    }

                    case TYPE_INTER_GENERATOR:
                    {
                        tmp = new Variant();
                        work.AddItem(new VariantRepalace(tmp, index));
                        vdata[i] = tmp;
                        break;
                    }

                    case TYPE_STRING:
                    {
                        vdata[i] = new Variant(strarray[index]);
                        break;
                    }

                    case TYPE_OCTET:
                    {
                        vdata[i] = new Variant(bbarray[index]);
                        break;
                    }

                    case TYPE_REAL:
                    {
                        vdata[i] = new Variant(dblarray[index]);
                        break;
                    }

                    case TYPE_BYTE:
                    {
                        vdata[i] = new Variant(barray[index]);
                        break;
                    }

                    case TYPE_SHORT:
                    {
                        vdata[i] = new Variant(sarray[index]);
                        break;
                    }

                    case TYPE_INTEGER:
                    {
                        vdata[i] = new Variant(iarray[index]);
                        break;
                    }

                    case TYPE_LONG:
                    {
                        vdata[i] = new Variant(larray[index]);
                        break;
                    }

                    case TYPE_UNKNOWN:
                    default:
                    {
                        vdata[i] = new Variant();
                        // null;
                        break;
                        break;
                    }
                    }
                }
                count = br.ReadInt32();
                int[] scgetterps = new int[count];
                for (int i = 0; i < count; i++)
                {
                    scgetterps[i] = br.ReadInt32();
                }
                // properties
                count = br.ReadInt32();
                if (count > 0)
                {
                    int   pcount = count << 1;
                    int[] props  = new int[pcount];
                    for (int i = 0; i < pcount; i++)
                    {
                        props[i] = br.ReadInt32();
                    }
                    properties[o] = props;
                }
                //IntVector superpointer = IntVector.wrap( scgetterps );
                InterCodeObject obj = new InterCodeObject(block, mStringArray[name], contextType,
                                                          code, vdata, maxVariableCount, variableReserveCount, maxFrameCount, funcDeclArgCount
                                                          , funcDeclUnnamedArgArrayBase, funcDeclCollapseBase, true, srcpos, scgetterps);
                //objs.add(obj);
                objs[o] = obj;
            }
            Variant val = new Variant();

            for (int o = 0; o < objcount; o++)
            {
                InterCodeObject parentObj           = null;
                InterCodeObject propSetterObj       = null;
                InterCodeObject propGetterObj       = null;
                InterCodeObject superClassGetterObj = null;
                if (parent[o] >= 0)
                {
                    parentObj = objs[parent[o]];
                }
                if (propSetter[o] >= 0)
                {
                    propSetterObj = objs[propSetter[o]];
                }
                if (propGetter[o] >= 0)
                {
                    propGetterObj = objs[propGetter[o]];
                }
                if (superClassGetter[o] >= 0)
                {
                    superClassGetterObj = objs[superClassGetter[o]];
                }
                objs[o]
                .SetCodeObject(parentObj, propSetterObj, propGetterObj, superClassGetterObj
                               );
                if (properties[o] != null)
                {
                    InterCodeObject obj = parentObj;
                    // objs.get(o).mParent;
                    int[] prop   = properties[o];
                    int   length = (int)(((uint)prop.Length) >> 1);
                    for (int i = 0; i < length; i++)
                    {
                        int pos   = i << 1;
                        int pname = prop[pos];
                        int pobj  = prop[pos + 1];
                        val.Set(objs[pobj]);
                        obj.PropSet(Interface.MEMBERENSURE | Interface.IGNOREPROP, mStringArray[pname], val
                                    , obj);
                    }
                    properties[o] = null;
                }
            }
            for (int i = 0; i < work.Count; i++)
            {
                VariantRepalace w = work[i];
                w.Work.Set(objs[w.Index]);
            }
            work.Clear();
            InterCodeObject top = null;

            if (toplevel >= 0)
            {
                top = objs[toplevel];
            }
            block.SetObjects(top, objs, objcount);
        }