Beispiel #1
0
        public override void Link()
        {
            foreach (var cId in this.ComponentIds)
            {
                var component = DataObjectModel.Get <DomClass>(cId);
                this.Components.Add(component);
            }

            foreach (var fId in this.FieldIds)
            {
                var field = DataObjectModel.Get <DomField>(fId);
                this.Fields.Add(field);
            }
        }
Beispiel #2
0
        public void Load()
        {
            if (IsLoaded)
            {
                return;
            }
            if (IsUnloaded)
            {
                throw new InvalidOperationException("Cannot reload object once it's unloaded");
            }

            if ((NumGlommed > 0) || (ObjectSizeInFile > 0))
            {
                byte[] buffer;

                if (IsCompressed)
                {
                    int dataLen = 8 * NumGlommed + ObjectSizeInFile;
                    int maxLen  = dataLen + 8;
                    buffer = new byte[maxLen];

                    // Decompress DataBuffer
                    using (var ms = new System.IO.MemoryStream(DataBuffer))
                        using (var istream = new ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream(ms, new ICSharpCode.SharpZipLib.Zip.Compression.Inflater(false)))
                        {
                            int readBytes = istream.Read(buffer, 0, maxLen);
                            Zeroes = readBytes - dataLen;
                            //istream.Read(buffer, 0, 0xF);
                        }
                }
                else
                {
                    string      path      = String.Format("/resources/systemgenerated/prototypes/{0}.node", this.Id);
                    TorLib.File protoFile = TorLib.Assets.FindFile(path);
                    using (var fs = protoFile.Open())
                        using (var br = new GomBinaryReader(fs, Encoding.UTF8))
                        {
                            br.ReadBytes(NodeDataOffset);
                            buffer = br.ReadBytes(ObjectSizeInFile);
                            Zeroes = 0;
                        }
                }

                // Load data from decompressed buffer
                using (var ms = new System.IO.MemoryStream(buffer))
                    using (var br = new GomBinaryReader(ms))
                    {
                        ms.Position         = Zeroes;
                        this.GlommedClasses = new List <DomClass>();
                        for (var glomIdx = 0; glomIdx < NumGlommed; glomIdx++)
                        {
                            var glomClassId = br.ReadUInt64();
                            var glomClass   = DataObjectModel.Get <DomClass>(glomClassId);
                            this.GlommedClasses.Add(glomClass);
                        }

                        this._data = ScriptObjectReader.ReadObject(this.DomClass, br);
                    }

                //FirstBytes = buffer.Take(0xF).ToArray();
            }

            this.DataBuffer = null; // Since we're loaded, we don't need to hold on to the compressed data anymore
            IsLoaded        = true;
        }
Beispiel #3
0
        //public byte[] FirstBytes { get; set; }

        public override void Link()
        {
            base.Link();
            DomClass = DataObjectModel.Get <DomClass>(ClassId);
        }
Beispiel #4
0
        public static GomObjectData ReadObject(DomClass domClass, GomBinaryReader reader)
        {
            GomObjectData result = new GomObjectData();
            IDictionary <string, object> resultDict = result.Dictionary;

            if (domClass != null)
            {
                resultDict["Script_Type"] = domClass;
            }
            else
            {
                resultDict["Script_Type"] = null;
            }

            resultDict["Script_TypeId"] = reader.ReadNumber();

            int numFields = (int)reader.ReadNumber();

            resultDict["Script_NumFields"] = numFields;

            ulong fieldId = 0;

            for (var i = 0; i < numFields; i++)
            {
                fieldId += reader.ReadNumber();
                DomField field     = DataObjectModel.Get <DomField>(fieldId);
                GomType  fieldType = null;
                if (field == null)
                {
                    // No idea what kind of field this is, so we'll skip it but we still need to read the data..
                    fieldType = GomTypeLoader.Load(reader, false);
                }
                else
                {
                    fieldType = field.GomType;

                    // Confirm the type matches
                    if (!field.ConfirmType(reader))
                    {
                        throw new InvalidOperationException("Unexpected field type for field " + field.Name);
                    }
                }

                // Read in the data
                object fieldValue = fieldType.ReadData(reader);

                // Save data to resulting script object
                string fieldName = null;
                if ((field != null) && (!String.IsNullOrEmpty(field.Name)))
                {
                    fieldName = field.Name;
                }
                else
                {
                    fieldName = DataObjectModel.GetStoredTypeName(fieldId);
                    if (fieldName == null)
                    {
                        fieldName = String.Format("field_{0:X8}", fieldId);
                    }
                }

                resultDict.Add(fieldName, fieldValue);
            }

            return(result);
        }