Ejemplo n.º 1
0
        /// <summary>
        /// Gets a BoxMobile object from a type
        /// </summary>
        /// <param name="t">The type to evaluate</param>
        /// <returns>A BoxMobile object or null if the type can't be constructed properly</returns>
        public static BoxMobile FromType(Type t)
        {
            ConstructorInfo[] ctors = t.GetConstructors();

            bool      constructable = false;
            BoxMobile mobile        = null;

            foreach (ConstructorInfo c in ctors)
            {
                if (BoxUtil.IsConstructable(c))
                {
                    constructable = true;
                    break;
                }
            }

            if (constructable)
            {
                mobile        = new BoxMobile();
                mobile.m_Name = t.Name;

                foreach (ConstructorInfo c in ctors)
                {
                    if (BoxUtil.IsConstructable(c))
                    {
                        ParameterInfo[] pms = c.GetParameters();

                        if (pms.Length == 0)
                        {
                            try
                            {
                                Mobile theMobile = (Mobile)Activator.CreateInstance(t);

                                mobile.m_Art = theMobile.Body.BodyID;
                                mobile.Hue   = theMobile.Hue;

                                if (theMobile != null)
                                {
                                    theMobile.Delete();
                                }
                            }
                            catch
                            {
                                // TODO : Logging?
                                return(null);
                            }
                        }
                        else if (pms.Length == 1 && (pms[0].ParameterType == typeof(string)))
                        {
                            mobile.CanBeNamed = true;
                        }
                    }
                }
            }

            return(mobile);
        }
Ejemplo n.º 2
0
 public override void HandlerInput(InputState input)
 {
     if (input.CurrentState.IsKeyDown(key) && !input.LastKeyState.IsKeyDown(key))
     {
         do
         {
             ctrl.dropBox.MoveDown();
         } while (ctrl.dropBox.position.Y > -BoxUtil.getTop(ctrl.dropBox.boxData) * DropBox.size);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a BoxItem definition from a type
        /// </summary>
        /// <param name="type">The type that will be analyzed</param>
        /// <returns>The corresponding BoxItem object, null if the object can't be constructed</returns>
        public static BoxItem FromType(Type type)
        {
            BoxItem item = new BoxItem();

            ConstructorInfo[] ctors = type.GetConstructors();

            item.m_Name = type.Name;

            foreach (ConstructorInfo ctor in ctors)
            {
                if (BoxUtil.IsConstructable(ctor))
                {
                    int NumOfParams = ctor.GetParameters().Length;

                    if (NumOfParams == 0)
                    {
                        item.m_EmptyCtor = true;
                        item.m_Item      = ItemDef.GetItemDef(type);
                    }
                    else if (NumOfParams <= 2)
                    {
                        if (item.m_AdditionalCtors == null)
                        {
                            item.m_AdditionalCtors = new ArrayList();
                        }

                        item.m_AdditionalCtors.Add(ConstructorDef.FromConstructorInfo(ctor));
                    }
                }
            }

            if (item.m_EmptyCtor || item.m_AdditionalCtors != null)
            {
                // If there's no default constructor, try to get the ItemDef from the additional constructors
                if (!item.m_EmptyCtor)
                {
                    // Get the first available def
                    foreach (ConstructorDef cDef in item.m_AdditionalCtors)
                    {
                        if (cDef.DefaultArt != null)
                        {
                            item.m_Item = cDef.DefaultArt.Clone() as ItemDef;
                            break;
                        }
                    }
                }

                return(item);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a new BoxFolderInfo object
        /// </summary>
        /// <param name="username">The username of the user registered for acess to the explorer</param>
        public FolderInfo(string username)
        {
            m_Structure = new GenericNode();
            m_Folders   = new System.Collections.ArrayList(RemoteExplorerConfig.GetExplorerFolder(username));

            // Create the folders structure
            foreach (string folder in m_Folders)
            {
                BoxUtil.EnsureFolder(folder);

                GenericNode fNode = new GenericNode(folder);

                DoFolder(Path.Combine(BoxUtil.RunUOFolder, folder), fNode);

                m_Structure.Elements.Add(fNode);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Processes a type and collects information about its properties
        /// </summary>
        /// <param name="t">The Type to examine</param>
        private void ProcessType(Type t)
        {
            ArrayList list = new ArrayList();

            if ((BoxUtil.IsItem(t) || BoxUtil.IsMobile(t)))
            {
                PropertyInfo[] props = t.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);

                if (props.Length > 0)
                {
                    foreach (PropertyInfo info in props)
                    {
                        BoxProp p = BoxProp.FromPropertyInfo(info);

                        if (p != null)
                        {
                            list.Add(p);

                            if (p.ValueType == BoxPropType.Enumeration)
                            {
                                if (!EnumListed(p.EnumName))
                                {
                                    BoxEnum e = BoxEnum.FromPropertyInfo(info);
                                    m_Enums.Add(e);
                                }
                            }
                        }
                    }
                }
            }

            if (list.Count > 0)
            {
                m_Constructables[t.Name] = list;
            }
            else
            {
                m_Constructables[t.Name] = null;
            }
        }
Ejemplo n.º 6
0
        public override BoxMessage Perform()
        {
            string file = null;
            string path = null;
            Type   type = null;

            switch (m_DataType)
            {
            case BoxDatafile.BoxData:

                file = "BoxData.xml";
                type = typeof(BoxData);
                break;

            case BoxDatafile.PropsData:

                file = "PropsData.xml";
                type = typeof(PropsData);
                break;

            case BoxDatafile.SpawnData:

                file = "SpawnData.xml";
                type = typeof(SpawnData);
                break;
            }

            path = System.IO.Path.Combine(BoxUtil.BoxFolder, file);

            object data = BoxUtil.XmlLoad(path, type);

            if (data == null)
            {
                return(new DatafileNotFound());
            }
            else
            {
                return(new ReturnDatafile(data));
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Reads a BoxData object from a file
 /// </summary>
 /// <param name="filename">The filename containing the BoxData object</param>
 /// <returns>The BoxData object read from file, or null if not succesful</returns>
 public static BoxData Load(string filename)
 {
     return(BoxUtil.XmlLoad(filename, typeof(BoxData)) as BoxData);
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Saves the box data to file
        /// </summary>
        private static void Save(BoxData data)
        {
            string path = Path.Combine(BoxUtil.BoxFolder, "BoxData.xml");

            BoxUtil.XmlSave(data, path);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Saves the PropsData to an xml file in the RunUO\TheBox folder
        /// </summary>
        public void Save()
        {
            string file = Path.Combine(BoxUtil.BoxFolder, "PropsData.xml");

            BoxUtil.XmlSave(this, file);
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Loads a PropsData object from an xml file
 /// </summary>
 /// <param name="file">The xml file containing the PropsData object</param>
 /// <returns>The loaded PropsData</returns>
 public static PropsData Load(string file)
 {
     return(BoxUtil.XmlLoad(file, typeof(PropsData)) as PropsData);
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Saves the SpawnData to the TheBox folder
        /// </summary>
        private void Save()
        {
            string filename = System.IO.Path.Combine(BoxUtil.BoxFolder, "SpawnData.xml");

            BoxUtil.XmlSave(this, filename);
        }
Ejemplo n.º 12
0
 private static void EmitConvert(CodeEmitter ilgen, java.lang.Class srcClass, java.lang.Class dstClass, int level)
 {
     if (srcClass != dstClass)
     {
         TypeWrapper src = TypeWrapper.FromClass(srcClass);
         TypeWrapper dst = TypeWrapper.FromClass(dstClass);
         src.Finish();
         dst.Finish();
         if (src.IsNonPrimitiveValueType)
         {
             src.EmitBox(ilgen);
         }
         if (dst == PrimitiveTypeWrapper.VOID)
         {
             ilgen.Emit(OpCodes.Pop);
         }
         else if (src.IsPrimitive)
         {
             if (dst.IsPrimitive)
             {
                 if (src == PrimitiveTypeWrapper.BYTE)
                 {
                     ilgen.Emit(OpCodes.Conv_I1);
                 }
                 if (dst == PrimitiveTypeWrapper.FLOAT)
                 {
                     ilgen.Emit(OpCodes.Conv_R4);
                 }
                 else if (dst == PrimitiveTypeWrapper.DOUBLE)
                 {
                     ilgen.Emit(OpCodes.Conv_R8);
                 }
                 else if (dst == PrimitiveTypeWrapper.LONG)
                 {
                     if (src == PrimitiveTypeWrapper.FLOAT)
                     {
                         ilgen.Emit(OpCodes.Call, ByteCodeHelperMethods.f2l);
                     }
                     else if (src == PrimitiveTypeWrapper.DOUBLE)
                     {
                         ilgen.Emit(OpCodes.Call, ByteCodeHelperMethods.d2l);
                     }
                     else
                     {
                         ilgen.Emit(OpCodes.Conv_I8);
                     }
                 }
                 else if (dst == PrimitiveTypeWrapper.BOOLEAN)
                 {
                     if (src == PrimitiveTypeWrapper.FLOAT)
                     {
                         ilgen.Emit(OpCodes.Call, ByteCodeHelperMethods.f2i);
                     }
                     else if (src == PrimitiveTypeWrapper.DOUBLE)
                     {
                         ilgen.Emit(OpCodes.Call, ByteCodeHelperMethods.d2i);
                     }
                     else
                     {
                         ilgen.Emit(OpCodes.Conv_I4);
                     }
                     ilgen.Emit(OpCodes.Ldc_I4_1);
                     ilgen.Emit(OpCodes.And);
                 }
                 else if (src == PrimitiveTypeWrapper.LONG)
                 {
                     ilgen.Emit(OpCodes.Conv_I4);
                 }
                 else if (src == PrimitiveTypeWrapper.FLOAT)
                 {
                     ilgen.Emit(OpCodes.Call, ByteCodeHelperMethods.f2i);
                 }
                 else if (src == PrimitiveTypeWrapper.DOUBLE)
                 {
                     ilgen.Emit(OpCodes.Call, ByteCodeHelperMethods.d2i);
                 }
             }
             else
             {
                 BoxUtil.Box(ilgen, srcClass, dstClass, level);
             }
         }
         else if (src.IsGhost)
         {
             src.EmitConvSignatureTypeToStackType(ilgen);
             EmitConvert(ilgen, [email protected] <java.lang.Object> .Value, dstClass, level);
         }
         else if (srcClass == [email protected] <sun.invoke.empty.Empty> .Value)
         {
             ilgen.Emit(OpCodes.Pop);
             ilgen.Emit(OpCodes.Ldloc, ilgen.DeclareLocal(dst.TypeAsSignatureType));
         }
         else if (dst.IsPrimitive)
         {
             BoxUtil.Unbox(ilgen, srcClass, dstClass, level);
         }
         else if (dst.IsGhost)
         {
             dst.EmitConvStackTypeToSignatureType(ilgen, null);
         }
         else if (dst.IsNonPrimitiveValueType)
         {
             dst.EmitUnbox(ilgen);
         }
         else
         {
             dst.EmitCheckcast(ilgen);
         }
     }
 }
Ejemplo n.º 13
0
        private void ParseBoxes(Box parent)
        {
            while (_reader.BaseStream.Position < _reader.BaseStream.Length)
            {
                UInt32  boxSize = _reader.ReadUInt32();
                BoxType boxType = (BoxType)_reader.ReadUInt32();

                var sibling = BoxUtil.CreateInstance(boxType);
                sibling.Parent = parent;
                parent.Children.Add(sibling);

                ParseBox(sibling, boxSize);

                switch (boxType)
                {
                case BoxType.moov:
                case BoxType.trak:
                case BoxType.mdia:
                case BoxType.minf:
                case BoxType.dinf:
                case BoxType.udta:
                    ParseDefaultParentBox(sibling);
                    break;

                case BoxType.ftyp:
                    ParseFtyp(sibling);
                    break;

                case BoxType.mdat:
                    ParseMdat(sibling);
                    break;

                case BoxType.mvhd:
                    ParseMvhd(sibling);
                    break;

                case BoxType.hdlr:
                    ParseHdlr(sibling);
                    break;

                case BoxType.dref:
                    ParseDref(sibling);
                    break;

                case BoxType.stbl:
                    ParseStbl(sibling);
                    break;

                case BoxType.stts:
                    ParseStts(sibling);
                    break;

                case BoxType.stsc:
                    ParseStsc(sibling);
                    break;

                case BoxType.stsz:
                    ParseStsz(sibling);
                    break;

                case BoxType.stco:
                    ParseStco(sibling);
                    break;

                case BoxType.stsd:
                    ParseStsd(sibling);
                    break;

                case BoxType.avc1:
                    ParseAvc1(sibling);
                    break;

                case BoxType.mp4a:
                    ParseMp4a(sibling);
                    break;

                case BoxType.esds:
                    ParseEsds(sibling);
                    break;

                default:
                    _reader.BaseStream.Seek((boxSize - 4 * 2), SeekOrigin.Current);
                    break;
                }

                if (sibling.IsLastPosition())
                {
                    return;
                }
            }
        }