Esempio n. 1
0
        //private StringTableEntry LoadString(XElement row)
        //{
        //    StringTableEntry result = new StringTableEntry();
        //    result.Id = row.Attribute("id").AsLong();
        //    result.Text = (string)row.Element("text");
        //    result.TextFemale = (string)row.Element("textFemale");
        //    result.InAlien = row.Element("inAlien").AsBool();
        //    result.DisableVoRecording = row.Element("disableVoRecording").AsBool();
        //    return result;
        //}

        public static string TryGetString(string fqn, GomObjectData textRetriever)
        {
            string locBucket  = textRetriever.ValueOrDefault <string>("strLocalizedTextRetrieverBucket", null);
            long   strId      = textRetriever.ValueOrDefault <long>("strLocalizedTextRetrieverStringID", -1);
            string defaultStr = textRetriever.ValueOrDefault <string>("strLocalizedTextRetrieverDesignModeText", String.Empty);

            if ((locBucket == null) || (strId == -1))
            {
                return(defaultStr);
            }

            StringTable strTable = null;

            try
            {
                strTable = StringTable.Find(locBucket);
            }
            catch
            {
                strTable = null;
            }

            if (strTable == null)
            {
                return(defaultStr);
            }

            string result = strTable.GetText(strId, fqn);

            return(result ?? defaultStr);
        }
Esempio n. 2
0
 public void Unload()
 {
     this._data = null;
     IsLoaded   = false;
     IsUnloaded = true;
 }
Esempio n. 3
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;
        }
Esempio n. 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);
        }