예제 #1
0
 public MegaloScriptSingleValue(MegaloScriptValueType valueType) : base(valueType)
 {
     Contract.Requires(valueType.BaseType == MegaloScriptValueBaseType.Single);
 }
예제 #2
0
        public MegaloScriptVirtualTriggerValue(MegaloScriptValueType valueType) : base(valueType)
        {
            Contract.Requires(valueType.BaseType == MegaloScriptValueBaseType.VirtualTrigger);

            mVirtualTriggerHandle = MegaloScriptModelObjectHandle.Null;
        }
예제 #3
0
        public TEnum BitDecode(uint bits, Bitwise.BitFieldTraits traits)
        {
            Contract.Requires(!traits.IsEmpty);

            return(BitDecode(bits, traits.BitIndex));
        }
        public bool TryStreamData <TContext>(
            Engine.XmlFileInfo xfi, FA mode,
            Action <IO.XmlElementStream, TContext> streamProc, TContext ctxt,
            string ext = null)
        {
            Contract.Requires(xfi != null);
            Contract.Requires(streamProc != null);

            bool result = false;

            if (mode == FA.Read)
            {
                result = true;
                System.IO.FileInfo file;
                var xml_or_xmb = GameEngine.Directories.TryGetXmlOrXmbFile(xfi.Location, xfi.Directory, xfi.FileName, out file, ext);

                if (xml_or_xmb == Engine.GetXmlOrXmbFileResult.FileNotFound)
                {
                    GameEngine.UpdateFileLoadStatus(xfi, Engine.XmlFileLoadState.FileDoesNotExist);
                    throw new System.IO.FileNotFoundException("Neither XML or XMB exists: " + file.FullName);
                }

                try
                {
                    if (result)
                    {
                        using (var s = GameEngine.OpenXmlOrXmbForRead(xml_or_xmb, file.FullName))
                        {
                            SetupStream(s, mode, this);
                            streamProc(s, ctxt);

                            GameEngine.UpdateFileLoadStatus(xfi, Engine.XmlFileLoadState.Loaded);
                        }
                    }
                } catch (Exception ex)
                {
                    ex.UnusedExceptionVar();
                    GameEngine.UpdateFileLoadStatus(xfi, Engine.XmlFileLoadState.Failed);
                    throw;
                }
            }
            else if (mode == FA.Write)
            {
                System.IO.FileInfo file;
                result = GameEngine.Directories.TryGetFile(xfi.Location, xfi.Directory, xfi.FileName, out file, ext);

                if (Engine.XmlFileInfo.RespectWritableFlag)
                {
                    result = result && xfi.Writable;
                }

                if (result)
                {
                    using (var s = IO.XmlElementStream.CreateForWrite(xfi.RootName))
                    {
                        SetupStream(s, mode, this);
                        streamProc(s, ctxt);
                        s.Document.Save(file.FullName);
                    }
                }
            }

            return(result);
        }
예제 #5
0
        internal static void SerializeValue <TDoc, TCursor>(MegaloScriptModel model, IO.TagElementStream <TDoc, TCursor, string> s,
                                                            MegaloScriptValueType valueType, ref int value,
                                                            IO.TagElementNodeType nodeType = IO.TagElementNodeType.Text, string nodeName = null)
            where TDoc : class
            where TCursor : class
        {
            Contract.Requires(valueType.BaseType == MegaloScriptValueBaseType.Index);

            var target = valueType.IndexTarget;

            if ((model.TagElementStreamSerializeFlags & MegaloScriptModelTagElementStreamFlags.EmbedObjects) != 0 &&
                target == MegaloScriptValueIndexTarget.Trigger)
            {
                SerializeTriggerReferenceValue(model, s, valueType, ref value);
            }
            #region UseIndexNames
            else if ((model.TagElementStreamSerializeFlags & MegaloScriptModelTagElementStreamFlags.UseIndexNames) != 0 &&
                     target.HasIndexName())
            {
                var id_resolving_ctxt = new MegaloScriptModel.IndexNameResolvingContext(model, target);
                var id_resolver       = MegaloScriptModel.IndexNameResolvingContext.IdResolver;
                var name_resolver     = MegaloScriptModel.IndexNameResolvingContext.NameResolver;

                switch (nodeType)
                {
                case IO.TagElementNodeType.Element:
                    s.StreamElementIdAsString(nodeName, ref value, id_resolving_ctxt, id_resolver, name_resolver);
                    break;

                case IO.TagElementNodeType.Attribute:
                    s.StreamAttributeIdAsString(nodeName, ref value, id_resolving_ctxt, id_resolver, name_resolver);
                    break;

                case IO.TagElementNodeType.Text:
                    s.StreamCursorIdAsString(ref value, id_resolving_ctxt, id_resolver, name_resolver);
                    break;
                }
            }
            #endregion
            else
            {
                switch (nodeType)
                {
                case IO.TagElementNodeType.Element:             s.StreamElement(nodeName, ref value); break;

                case IO.TagElementNodeType.Attribute:   s.StreamAttribute(nodeName, ref value); break;

                case IO.TagElementNodeType.Text:                s.StreamCursor(ref value); break;
                }
            }

            // #REVIEW_BLAM: this will fail when embedding and the target is a Trigger since we don't preload triggers or such
            if (s.IsReading &&
                ((model.TagElementStreamSerializeFlags & MegaloScriptModelTagElementStreamFlags.EmbedObjects) == 0 || target != MegaloScriptValueIndexTarget.Trigger)
                )
            {
                if (!model.IndexTargetIsValid(target, valueType.IndexTraits, value))
                {
                    s.ThrowReadException(new System.IO.InvalidDataException(string.Format(
                                                                                "A {0} reference has an invalid value {1}", target, value)));
                }
            }
        }
예제 #6
0
 public MegaloScriptTeamFilterParametersValue(MegaloScriptValueType valueType) : base(valueType)
 {
     Contract.Requires(valueType.BaseType == MegaloScriptValueBaseType.TeamFilterParameters);
 }
        public static BXmlSerializerInterface GetNullInterface(Phx.BDatabaseBase db)
        {
            Contract.Requires(db != null);

            return(new NullInterface(db));
        }
예제 #8
0
 public BitFieldTraits(int bitCount, BitFieldTraits prev)
     : this(false, bitCount, prev.NextFieldBitIndex)
 {
     Contract.Requires <ArgumentOutOfRangeException>(bitCount > 0 && bitCount <= kMaxBitCount);
     Contract.Requires <ArgumentException>((prev.NextFieldBitIndex + bitCount) <= kMaxBitCount);
 }
예제 #9
0
        public static BitFieldTraits For <TUInt>(IEnumBitEncoder <TUInt> enumEncoder, BitFieldTraits prev)
        {
            Contract.Requires(enumEncoder != null);

            return(new BitFieldTraits(enumEncoder.BitCountTrait, prev));
        }
예제 #10
0
        public Collections.IBTypeNames GetNamesInterface(HPBarDataObjectKind kind)
        {
            Contract.Requires <ArgumentOutOfRangeException>(kind != HPBarDataObjectKind.None);

            return(HPBars.GetNamesInterface(kind));
        }
예제 #11
0
 public BitFieldTraits(int bitCount)
     : this(false, bitCount, 0)
 {
     Contract.Requires <ArgumentOutOfRangeException>(bitCount > 0 && bitCount <= kMaxBitCount);
 }
예제 #12
0
 public MegaloScriptBoolValue(MegaloScriptValueType valueType) : base(valueType)
 {
     Contract.Requires(valueType.BaseType == MegaloScriptValueBaseType.Bool);
 }
예제 #13
0
 public MegaloScriptVarIndexValue(MegaloScriptValueType valueType) : base(valueType)
 {
     Contract.Requires(valueType.BaseType == MegaloScriptValueBaseType.Var);
 }
예제 #14
0
 public MegaloScriptPoint3dValue(MegaloScriptValueType valueType) : base(valueType)
 {
     Contract.Requires(valueType.BaseType == MegaloScriptValueBaseType.Point3d);
 }
예제 #15
0
        public static int BitDecodeNoneable(uint bits, Bitwise.BitFieldTraits traits)
        {
            Contract.Requires/*<ArgumentException>*/ (!traits.IsEmpty);

            return((int)BitDecode(bits, traits.BitIndex, traits.Bitmask32) - 1);
        }
예제 #16
0
 void ObjectInvariant()
 {
     Contract.Invariant(mFixedLength >= 0);
 }
 public BTypeValuesInt32XmlSerializer(BTypeValuesXmlParams <int> @params, Collections.BTypeValuesInt32 list) : base(@params, list)
 {
     Contract.Requires <ArgumentNullException>(@params != null);
     Contract.Requires <ArgumentNullException>(list != null);
 }
예제 #18
0
        public void Serialize <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s)
            where TDoc : class
            where TCursor : class
        {
            #region MultiplayerEffects (Halo4 only)
            using (var bm = s.EnterCursorBookmarkOpt(kGroupTagMultiplayerEffects, MultiplayerEffects, Predicates.HasItems)) if (bm.IsNotNull)
                {
                    using (s.EnterCursorBookmark("effects"))
                        s.StreamableElements("entry", MultiplayerEffects);
                }
            #endregion

            #region multiplayer_object_type_list
            using (s.EnterCursorBookmark(kGroupTagMultiplayerObjectTypeList))
                ObjectTypeList.Serialize(s);

            Contract.Assert(ObjectTypeList.Types.Count <= mLimits.MultiplayerObjectTypes.MaxCount);
            #endregion

            #region custom_app_globals (Halo4 only)
            using (var bm = s.EnterCursorBookmarkOpt(kGroupTagCustomAppGlobals, CustomApps, Predicates.HasItems)) if (bm.IsNotNull)
                {
                    using (s.EnterCursorBookmark("apps"))
                        s.StreamableElements("entry", CustomApps);
                }
            #endregion

            #region game_globals_ordnance_list (Halo4 only)
            using (var bm = s.EnterCursorBookmarkOpt(kGroupTagGameGlobalsOrdnanceList, OrdnanceList, obj => !obj.IsAvailable)) if (bm.IsNotNull)
                {
                    OrdnanceList.Serialize(s);

                    Contract.Assert(OrdnanceList.Types.Count <= mLimits.GameOrdnanceTypes.MaxCount);
                }
            #endregion

            #region game_medal_globals
            using (s.EnterCursorBookmark(kGroupTagGameMedalGlobals))
                using (s.EnterCursorBookmark("medals"))
                    s.StreamableElements("entry", Medals);

            Contract.Assert(Medals.Count <= mLimits.GameMedals.MaxCount);
            #endregion

            #region incident_globals_definition
            using (s.EnterCursorBookmark(kGroupTagIncidentGlobalsDefinition))
                using (s.EnterCursorBookmark("incidents"))
                    s.StreamableElements("entry", Incidents);

            Contract.Assert(Incidents.Count <= mLimits.GameIncidentTypes.MaxCount);
            #endregion

            #region loadout_globals_definition
            #endregion

            #region megalogamengine_sounds
            using (s.EnterCursorBookmark(kGroupTagMegaloGamEngineSounds))
                using (s.EnterCursorBookmark("sounds"))
                    s.StreamableElements("entry", Sounds);

            Contract.Assert(Sounds.Count == mLimits.MegaloEngineSounds.MaxCount);
            #endregion

            #region megalo_string_id_table
            using (s.EnterCursorBookmark(kGroupTagMegaloStringIdTable))
                using (s.EnterCursorBookmark("names"))
                    s.StreamableElements("entry", Names);

            Contract.Assert(Names.Count <= mLimits.MegaloStringIds.MaxCount);
            #endregion

            #region HudWidgetIcons
            using (s.EnterCursorBookmark("hud_widget_icons"))
                using (s.EnterCursorBookmark("icons"))
                    s.StreamableElements("entry", HudWidgetIcons);

            Contract.Assert(HudWidgetIcons.Count <= mLimits.MegaloHudWidgetIcons.MaxCount);
            #endregion

            #region GameEngineIcons
            using (s.EnterCursorBookmark("engine_icons"))
                using (s.EnterCursorBookmark("icons"))
                    s.StreamableElements("entry", GameEngineIcons);

            Contract.Assert(GameEngineIcons.Count <= mLimits.GameEngineIcons.MaxCount);
            #endregion

            if (s.IsReading)
            {
                MultiplayerEffects.TrimExcess();
                CustomApps.TrimExcess();
                Medals.TrimExcess();
                Incidents.TrimExcess();
                Sounds.TrimExcess();
                Names.TrimExcess();
                HudWidgetIcons.TrimExcess();
                GameEngineIcons.TrimExcess();

                for (int x = 0; x < Sounds.Count; x++)
                {
                    if (Sounds[x].IsAvailable)
                    {
                        continue;
                    }

                    Sounds[x].UpdateForUndefined("MEGALO_SOUND", x);
                }

                for (int x = 0; x < Incidents.Count; x++)
                {
                    if (Incidents[x].IsAvailable)
                    {
                        continue;
                    }

                    Incidents[x].UpdateForUndefined("INCIDENT", x);
                }

                for (int x = 0; x < HudWidgetIcons.Count; x++)
                {
                    if (HudWidgetIcons[x].IsAvailable)
                    {
                        continue;
                    }

                    HudWidgetIcons[x].UpdateForUndefined("HUD_WIDGET", x);
                }

                for (int x = 0; x < GameEngineIcons.Count; x++)
                {
                    if (GameEngineIcons[x].IsAvailable)
                    {
                        continue;
                    }

                    GameEngineIcons[x].UpdateForUndefined("ENGINE_ICON", x);
                }
            }
        }
예제 #19
0
 public TextLineInfo(ITextLineInfo otherLineInfo) : this(otherLineInfo.LineNumber, otherLineInfo.LinePosition)
 {
     Contract.Requires <ArgumentNullException>(otherLineInfo != null);
 }
        public void RemapTriggerReference(ref int triggerIndex)
        {
            Contract.Requires(triggerIndex.IsNotNone());

            RemapTriggerIndex(ref triggerIndex);
        }
        public bool StreamDBID <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s,
                                               string xmlName, ref int dbid,
                                               Phx.DatabaseObjectKind kind,
                                               bool isOptional = true, IO.TagElementNodeType xmlSource = XmlUtil.kSourceElement)
            where TDoc : class
            where TCursor : class
        {
            Contract.Requires(xmlSource.RequiresName() == (xmlName != XML.XmlUtil.kNoXmlName));

            string id_name      = null;
            bool   was_streamed = true;
            bool   to_lower     = ToLowerName(kind);

            if (s.IsReading)
            {
                if (isOptional)
                {
                    was_streamed = s.StreamStringOpt(xmlName, ref id_name, to_lower, xmlSource, intern: true);
                }
                else
                {
                    s.StreamString(xmlName, ref id_name, to_lower, xmlSource, intern: true);
                }

                if (was_streamed)
                {
                    dbid = Database.GetId(kind, id_name);
                    Contract.Assert(dbid.IsNotNone());
                    if (PhxUtil.IsUndefinedReferenceHandle(dbid))
                    {
                        TraceUndefinedHandle(s, id_name, xmlName, dbid, kind.ToString());
                    }
                }
                else
                {
                    dbid = TypeExtensions.kNone;
                }
            }
            else if (s.IsWriting)
            {
                if (dbid.IsNone())
                {
                    was_streamed = false;
                    return(was_streamed);
                }

                id_name = Database.GetName(kind, dbid);
                Contract.Assert(!string.IsNullOrEmpty(id_name));

                if (isOptional)
                {
                    s.StreamStringOpt(xmlName, ref id_name, to_lower, xmlSource, intern: true);
                }
                else
                {
                    s.StreamString(xmlName, ref id_name, to_lower, xmlSource, intern: true);
                }
            }

            return(was_streamed);
        }
예제 #22
0
        public void Postprocess(MegaloStaticDatabase associatedStaticDb, TextWriter errorWriter = null)
        {
            Contract.Requires(associatedStaticDb != null);

            // #REVIEW_BLAM: I've added TraceInformation calls now, can we get rid of the TextWriter?

            this.StaticDatabase = associatedStaticDb;

            #region ValueTypes
            foreach (var type in ValueTypes)
            {
                if (type.BaseType.RequiresBitLength() && type.BitLength == 0)
                {
                    string msg = string.Format("ValueType '{0}' doesn't define bitLength", ValueTypeNames[type.NameIndex]);

                    Debug.Trace.MegaloProto.TraceInformation(msg);
                    errorWriter?.WriteLine(msg);
                }

                switch (type.BaseType)
                {
                case MegaloScriptValueBaseType.Flags:
                {
                    var etype         = Enums[type.EnumIndex];
                    int bc_difference = etype.ValidBitLengthForFlags(type.BitLength);
                    if (bc_difference < 0)
                    {
                        string msg = string.Format("Flags '{0}->{1}' bitLength '{2}' is too small (need {3} more bits)",
                                                   etype.Name, ValueTypeNames[type.NameIndex],
                                                   type.BitLength, -bc_difference);

                        Debug.Trace.MegaloProto.TraceInformation(msg);
                        errorWriter?.WriteLine(msg);
                    }
                } break;

                case MegaloScriptValueBaseType.Enum:
                {
                    var etype         = Enums[type.EnumIndex];
                    int bc_difference = etype.ValidBitLengthForEnum(type.BitLength, type.EnumTraits);
                    if (bc_difference < 0)
                    {
                        string msg = string.Format("Enum '{0}->{1}' bitLength '{2}' is too small (need {3} more bits)",
                                                   etype.Name, ValueTypeNames[type.NameIndex],
                                                   type.BitLength, -bc_difference);

                        Debug.Trace.MegaloProto.TraceInformation(msg);
                        errorWriter?.WriteLine(msg);
                    }
                } break;

                case MegaloScriptValueBaseType.Index:
                {
                    if (type.IndexTraits == MegaloScriptValueIndexTraits.PointerRaw)
                    {
                        int bit_length = type.BitLength;
                        if (bit_length != Bits.kByteBitCount && bit_length != Bits.kInt16BitCount && bit_length != Bits.kInt32BitCount)
                        {
                            string msg = string.Format("Index-type '{0}' is a 'raw' value but doesn't use a natural word size: {1}",
                                                       ValueTypeNames[type.NameIndex], bit_length);

                            Debug.Trace.MegaloProto.TraceInformation(msg);
                            errorWriter?.WriteLine(msg);
                        }
                    }
                } break;
                }
            }
            #endregion
            #region Actions
            foreach (var action in Actions)
            {
                var state = new MegaloScriptProtoParamsPostprocessState(errorWriter, action);
                state.Postprocess();
            }
            #endregion
            // #TODO_BLAM: would be nice to dump unused ActionTemplates...as I only copy-pasted H4's in Reach's DB
        }
예제 #23
0
        public void UpdateHeader(ref EcfHeader header)
        {
            Contract.Requires <InvalidOperationException>(HeaderId != 0);

            header.InitializeChunkInfo(HeaderId, ChunkExtraDataSize);
        }
예제 #24
0
        protected BListExplicitIndexXmlSerializerBase(BListExplicitIndexXmlParams <T> @params)
        {
            Contract.Requires <ArgumentNullException>(@params != null);

            mParams = @params;
        }
예제 #25
0
        public void ChangeValue(MegaloScriptModel model, string indexName)
        {
            Contract.Requires(!string.IsNullOrEmpty(indexName));

            Value = model.GetTargetIndexFromName(ValueType.IndexTarget, indexName);
        }
예제 #26
0
        public static long BitDecodeNoneable(ulong bits, Bitwise.BitFieldTraits traits)
        {
            Contract.Requires/*<ArgumentException>*/ (!traits.IsEmpty);

            return((long)BitDecode(bits, traits.BitIndex, traits.Bitmask64) - 1);
        }
예제 #27
0
        public uint BitEncode(TEnum value, uint bits, Bitwise.BitFieldTraits traits)
        {
            Contract.Requires(!traits.IsEmpty);

            return(BitEncode(value, bits, traits.BitIndex));
        }
예제 #28
0
        public static uint BitDecode(uint bits, Bitwise.BitFieldTraits traits)
        {
            Contract.Requires/*<ArgumentException>*/ (!traits.IsEmpty);

            return((bits >> traits.BitIndex) & traits.Bitmask32);
        }
예제 #29
0
        public EnumBitEncoder64(int defaultBitIndex)
        {
            Contract.Requires(defaultBitIndex >= 0);

            mDefaultBitIndex = defaultBitIndex;
        }
예제 #30
0
        internal static void BitEncodeIndex(ref Bitwise.HandleBitEncoder encoder, int branchIndex)
        {
            Contract.Requires <ArgumentOutOfRangeException>(branchIndex.IsNoneOrPositive());

            encoder.EncodeNoneable32(branchIndex, kIndexBitMask);
        }