Exemple #1
0
        static void SerializeObject <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s, SerializeObjectContext ctxt,
                                                    ref BlobObject obj)
            where TDoc : class
            where TCursor : class
        {
            Contract.Requires(obj != null || s.IsReading);

            const string kAttributeNameSignature = "signature";
            const string kAttributeNameVersion   = "version";

            if (s.IsReading)
            {
                string group_tag = null;
                s.ReadAttribute(kAttributeNameSignature, ref group_tag);

                int version = TypeExtensions.kNone;
                s.ReadAttribute(kAttributeNameVersion, ref version);

                BlobGroup blob_group;
                BlobGroupVersionAndBuildInfo info_for_version;
                if (ctxt.System.TryGetBlobGroup(group_tag, version, out blob_group, out info_for_version))
                {
                    var target_build = ctxt.GameTarget.Build;

                    if (!info_for_version.BuildHandle.IsWithinSameBranch(target_build))
                    {
                        s.ThrowReadException(SerializeObjectFoundBuildIncompatibility(ctxt.System,
                                                                                      blob_group, version, info_for_version.BuildHandle, target_build));
                    }

                    obj = ctxt.System.CreateObject(Blam.Engine.BlamEngineTargetHandle.None, blob_group, version);
                }
                else
                {
                    string msg = string.Format(Util.InvariantCultureInfo,
                                               "{0}: No blob matching '{1}'/v{2} exists",
                                               ctxt.GameTarget.ToDisplayString(), group_tag, version);
                    s.ThrowReadException(new System.IO.InvalidDataException(msg));
                }
            }
            else if (s.IsWriting)
            {
                s.WriteAttribute(kAttributeNameSignature, obj.SystemGroup.GroupTag.TagString);
                s.WriteAttribute(kAttributeNameVersion, obj.Version);
            }
            s.StreamAttribute("flags", obj, _obj => _obj.BlobFlags);

            obj.Serialize(s);
        }
Exemple #2
0
        void Read <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s)
            where TDoc : class
            where TCursor : class
        {
            string[] names = kInfo.kValuesEnum.GetEnumNames();

            foreach (var element in s.ElementsByName(kEntryElementName))
            {
                using (s.EnterCursorBookmark(element))
                {
                    string name = null;
                    s.ReadAttribute(kEntryAttrKeyName, ref name);

                    int name_index = Array.IndexOf(names, name);
                    if (name_index < 0)
                    {
                        s.ThrowReadException(new System.IO.InvalidDataException("Invalid name value: " + name));
                    }

                    mArray[name_index] = 0.0f;
                    if (s.ReadAttributeOpt(kEntryAttrValueName, ref mArray[name_index]))                     // #HACK_BLAM: IgnoreWritePredicates hack! didn't used to be Opt
                    {
                        mValidFlags |= 1U << name_index;
                    }
                }
            }
        }
        static Proto.MegaloScriptValueType ReadType <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s, Proto.MegaloScriptDatabase db)
            where TDoc : class
            where TCursor : class
        {
            string value_type_name = null;

            s.ReadAttribute(kTypeAttributeName, ref value_type_name);
            return(db.GetValueType(value_type_name));
        }
        protected override void Read <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s, BXmlSerializerInterface xs, int iteration)
        {
            int index = ReadExplicitIndex(s, xs);

            ListExplicitIndex.InitializeItem(index);
            float value = 0;

            s.ReadAttribute(kAttrName, ref value);
            ListExplicitIndex[index] = value;
        }
Exemple #5
0
        void ReadEngineLanguageTable <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s)
            where TDoc : class
            where TCursor : class
        {
            const string kElementNameEntry       = "E";
            const string kAttributeNameGameIndex = "id";
            const string kAttributeNameLangIndex = "lang";
            const string kAttributeNameOptional  = "optional";

            // number of languages for this build of the engine
            int lang_count = 0;

            foreach (var e in s.ElementsByName(kElementNameEntry))
            {
                using (s.EnterCursorBookmark(e))
                {
                    int  game_index  = TypeExtensions.kNone;
                    int  lang_index  = TypeExtensions.kNone;
                    bool is_optional = false;

                    s.ReadAttribute(kAttributeNameGameIndex, ref game_index, NumeralBase.Decimal);
                    LanguageRegistry.SerializeLanguageId(s, kAttributeNameLangIndex, ref lang_index);
                    s.ReadAttributeOpt(kAttributeNameOptional, ref is_optional);

                    if (IsInvalidGameIndexFromStream(game_index) || lang_index.IsNone())
                    {
                        s.ThrowReadException(new System.IO.InvalidDataException("Invalid table entry data"));
                    }

                    mEngineLanguageTable[lang_index] = new GameLanguageHandle(mBuildHandle, lang_index, game_index);
                    if (is_optional)
                    {
                        mOptionalEngineLanguageFlags[lang_index] = true;
                        mOptionalGameLanguageFlags[game_index]   = true;
                    }

                    lang_count++;
                }
            }

            if (lang_count == 0)
            {
                s.ThrowReadException(new System.IO.InvalidDataException("Table has no entries"));
            }

            if (!InitializeGameLanguageTableFromEngineTable(lang_count))
            {
                s.ThrowReadException(new System.IO.InvalidDataException("Invalid game index data"));
            }
        }
Exemple #6
0
        protected override void ReadNodes <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s, BXmlSerializerInterface xs)
        {
            var penum = mList.TypeValuesParams.kGetProtoEnumFromDB(xs.Database);

            foreach (var attrName in s.AttributeNames)
            {
                // The only attributes in this are actual member names so we don't waste time calling
                // penum.IsValidMemberName only to call GetMemberId when we can just compare id to -1
                int index = penum.GetMemberId(attrName);
                if (index.IsNone())
                {
                    continue;
                }

                mList.InitializeItem(index);
                float value = PhxUtil.kInvalidSingle;
                s.ReadAttribute(attrName, ref value);
                mList[index] = value;
            }
        }