Ejemplo n.º 1
0
        private void ConvertCsObj(object csObj, IMPObject mpObj)
        {
            Type   type     = csObj.GetType();
            string fullName = type.FullName;

            if (!(mpObj is Serializable))
            {
                throw new Exception(string.Concat("Cannot serialize object: ", csObj, ", type: ", fullName, " -- It doesn't implement the SerializableSFSType interface"));
            }
            IMPArray val = MPArray.NewInstance();

            mpObj.PutUtfString(CLASS_MARKER_KEY, fullName);
            mpObj.PutMPArray(CLASS_FIELDS_KEY, val);
            foreach (FieldInfo info in type.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance))
            {
                string        name    = info.Name;
                object        obj2    = info.GetValue(csObj);
                IMPObject     obj3    = MPObject.NewInstance();
                MPDataWrapper wrapper = WrapField(obj2);
                if (wrapper != null)
                {
                    obj3.PutUtfString(FIELD_NAME_KEY, name);
                    obj3.Put(FIELD_VALUE_KEY, wrapper);
                    val.AddMPObject(obj3);
                }
                else
                {
                    throw new Exception(string.Concat("Cannot serialize field of object: ", csObj, ", field: ", name, ", type: ", info.GetType().Name, " -- unsupported type!"));
                }
            }
        }
Ejemplo n.º 2
0
        private IMPObject UnrollDictionary(IDictionary dict)
        {
            IMPObject   obj2       = MPObject.NewInstance();
            IEnumerator enumerator = dict.Keys.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    string        current = (string)enumerator.Current;
                    MPDataWrapper val     = WrapField(dict[current]);
                    if (val == null)
                    {
                        throw new Exception(string.Concat("Cannot serialize field of dictionary with key: ", current, ", ", dict[current], " -- unsupported type!"));
                    }
                    obj2.Put(current, val);
                }
            }
            finally
            {
                IDisposable disposable = enumerator as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
            return(obj2);
        }
Ejemplo n.º 3
0
        //----------------------------------  Class Mapping  -------------------------------------
        //*********************************** Class to MPObject  *********************************
        private IMPObject Cs2Mp(object csObj)
        {
            IMPObject sfsObj = MPObject.NewInstance();

            ConvertCsObj(csObj, sfsObj);
            return(sfsObj);
        }
Ejemplo n.º 4
0
        private IMPObject DecodeMPObject(ByteArray buffer)
        {
            MPObject obj2 = MPObject.NewInstance();
            byte     num  = buffer.ReadByte();

            if (num != Convert.ToByte(MPDataType.MP_OBJECT))
            {
                throw new Exception(string.Concat("Invalid MPDataType. Expected: ", MPDataType.MP_OBJECT, ", found: ", num));
            }
            int num2 = buffer.ReadShort();

            if (num2 < 0)
            {
                throw new Exception("Can't decode MPObject. Size is negative: " + num2);
            }
            for (int i = 0; i < num2; i++)
            {
                string        key = buffer.ReadUTF();
                MPDataWrapper val = DecodeObject(buffer);
                if (val == null)
                {
                    throw new Exception("Could not decode value for MPObject with key: " + key);
                }
                obj2.Put(key, val);
            }
            return(obj2);
        }
Ejemplo n.º 5
0
 static int NewInstance(IntPtr L)
 {
     LuaScriptMgr.CheckArgsCount(L, 0);
     com.gt.entities.MPObject o = MPObject.NewInstance();
     LuaScriptMgr.PushObject(L, o);
     return(1);
 }
Ejemplo n.º 6
0
 static int NewFromBinaryData(IntPtr L)
 {
     LuaScriptMgr.CheckArgsCount(L, 1);
     com.gt.units.ByteArray   arg0 = LuaScriptMgr.GetNetObject <com.gt.units.ByteArray>(L, 1);
     com.gt.entities.MPObject o    = MPObject.NewFromBinaryData(arg0);
     LuaScriptMgr.PushObject(L, o);
     return(1);
 }
Ejemplo n.º 7
0
    static int NewFromObject(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 1);
        object arg0 = LuaScriptMgr.GetVarObject(L, 1);

        com.gt.entities.MPObject o = MPObject.NewFromObject(arg0);
        LuaScriptMgr.PushObject(L, o);
        return(1);
    }