Beispiel #1
0
        /// <summary>
        /// The managed object.
        /// </summary>
        /// <param name="hash">
        /// The hash.
        /// </param>
        /// <param name="pObj">
        /// The p obj.
        /// </param>
        /// <exception cref="FormatException">
        /// </exception>
        /// <exception cref="ArgumentException">
        /// </exception>
        /// <exception cref="FormatException">
        /// </exception>
        public void ManagedObject(uint hash, ref CIwManaged pObj)
        {
            if (this.mode == IwSerialiseMode.Read)
            {
                IwClassFactory factory = this.ClassRegistry.Get(hash);
                if (factory == null)
                {
                    throw new FormatException(string.Format("Can't Serialise unknown type 0x{0:x}", hash));
                }

                pObj = factory.Create();
            }
            else
            {
                if (hash != pObj.Hash)
                {
                    throw new ArgumentException();
                }
            }

            try
            {
                pObj.Serialise(this);
            }
            catch (Exception ex)
            {
                throw new FormatException(
                          string.Format("Can't Serialise GetResHashed(0x{0:x}, \"0x{1}\")", pObj.Hash, pObj.GetType().Name), ex);
            }
        }
        private void Parse()
        {
            for (;;)
            {
                var s = this.ReadString();
                if (s == null)
                {
                    break;
                }

                if (s == "include")
                {
                    var fileName = this.ReadString();
                    continue;
                }

                if (s == "}")
                {
                    this.GetObject(0).ParseClose(this);
                    this.PopObject();
                    continue;
                }

                if (this.parseStack.Count > 0)
                {
                    if (this.GetObject(0).ParseAttribute(this, s))
                    {
                        continue;
                    }
                }

                if (this.PeekString() == "{")
                {
                    this.ReadString();
                    IwClassFactory iwClassFactory = this.classRegistry.Get(S3E.HashString(s));
                    if (iwClassFactory == null)
                    {
                        throw new Exception(string.Format("Can't find class {0}", s));
                    }

                    this.PushObject(iwClassFactory.Create());
                    this.GetObject(0).ParseOpen(this);
                }
                else
                {
                    throw new Exception(string.Format("{0} is not an attribute in {1}", s, this.GetObject(0).GetType().Name));
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// The managed object.
        /// </summary>
        /// <param name="pObj">
        /// The p obj.
        /// </param>
        /// <exception cref="FormatException">
        /// </exception>
        public void ManagedObject(ref CIwManaged pObj)
        {
            if (this.mode == IwSerialiseMode.Read)
            {
                uint hash = 0;
                this.UInt32(ref hash);
                IwClassFactory factory = this.ClassRegistry.Get(hash);
                if (factory == null)
                {
                    throw new FormatException(string.Format("Can't Serialise unknown type 0x{0:x}", hash));
                }

                pObj = factory.Create();
            }
            else
            {
                uint hash = pObj.Hash;
                this.UInt32(ref hash);
            }

            Debug.WriteLine(string.Format("Serialise {0}", pObj.GetType().Name));
            pObj.Serialise(this);
        }