public MegaloScriptPoint3dValue(MegaloScriptValueType valueType) : base(valueType) { Contract.Requires(valueType.BaseType == MegaloScriptValueBaseType.Point3d); }
public TEnum BitDecode(ulong bits, Bitwise.BitFieldTraits traits) { Contract.Requires(!traits.IsEmpty); return(BitDecode(bits, traits.BitIndex)); }
public static ActiveListDesc <T> CreateForNullData(int capacity, bool fixedLength = true) { Contract.Requires(capacity >= 0); return(new ActiveListDesc <T>(capacity, fixedLength)); }
public void ChangeValue(MegaloScriptModel model, string indexName) { Contract.Requires(!string.IsNullOrEmpty(indexName)); Value = model.GetTargetIndexFromName(ValueType.IndexTarget, indexName); }
public EnumBitEncoder64(int defaultBitIndex) { Contract.Requires(defaultBitIndex >= 0); mDefaultBitIndex = defaultBitIndex; }
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); }
public void UpdateHeader(ref EcfHeader header) { Contract.Requires <InvalidOperationException>(HeaderId != 0); header.InitializeChunkInfo(HeaderId, ChunkExtraDataSize); }
public static BitFieldTraits For <TUInt>(IEnumBitEncoder <TUInt> enumEncoder, BitFieldTraits prev) { Contract.Requires(enumEncoder != null); return(new BitFieldTraits(enumEncoder.BitCountTrait, prev)); }
public void RemapTriggerReference(ref int triggerIndex) { Contract.Requires(triggerIndex.IsNotNone()); RemapTriggerIndex(ref triggerIndex); }
public BitFieldTraits(int bitCount) : this(false, bitCount, 0) { Contract.Requires <ArgumentOutOfRangeException>(bitCount > 0 && bitCount <= kMaxBitCount); }
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); }
public Collections.IBTypeNames GetNamesInterface(HPBarDataObjectKind kind) { Contract.Requires <ArgumentOutOfRangeException>(kind != HPBarDataObjectKind.None); return(HPBars.GetNamesInterface(kind)); }
public MegaloScriptBoolValue(MegaloScriptValueType valueType) : base(valueType) { Contract.Requires(valueType.BaseType == MegaloScriptValueBaseType.Bool); }
public MegaloScriptVarIndexValue(MegaloScriptValueType valueType) : base(valueType) { Contract.Requires(valueType.BaseType == MegaloScriptValueBaseType.Var); }
public TextLineInfo(ITextLineInfo otherLineInfo) : this(otherLineInfo.LineNumber, otherLineInfo.LinePosition) { Contract.Requires <ArgumentNullException>(otherLineInfo != null); }
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 }
public static BXmlSerializerInterface GetNullInterface(Phx.BDatabaseBase db) { Contract.Requires(db != null); return(new NullInterface(db)); }
protected BListExplicitIndexXmlSerializerBase(BListExplicitIndexXmlParams <T> @params) { Contract.Requires <ArgumentNullException>(@params != null); mParams = @params; }
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); }
public static long BitDecodeNoneable(ulong bits, Bitwise.BitFieldTraits traits) { Contract.Requires/*<ArgumentException>*/ (!traits.IsEmpty); return((long)BitDecode(bits, traits.BitIndex, traits.Bitmask64) - 1); }
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))); } } }
public static uint BitDecode(uint bits, Bitwise.BitFieldTraits traits) { Contract.Requires/*<ArgumentException>*/ (!traits.IsEmpty); return((bits >> traits.BitIndex) & traits.Bitmask32); }
public MegaloScriptVirtualTriggerValue(MegaloScriptValueType valueType) : base(valueType) { Contract.Requires(valueType.BaseType == MegaloScriptValueBaseType.VirtualTrigger); mVirtualTriggerHandle = MegaloScriptModelObjectHandle.Null; }
public static int BitDecodeNoneable(uint bits, Bitwise.BitFieldTraits traits) { Contract.Requires/*<ArgumentException>*/ (!traits.IsEmpty); return((int)BitDecode(bits, traits.BitIndex, traits.Bitmask32) - 1); }
public ulong BitEncode(TEnum value, ulong bits, Bitwise.BitFieldTraits traits) { Contract.Requires(!traits.IsEmpty); return(BitEncode(value, bits, traits.BitIndex)); }
public BTypeValuesInt32XmlSerializer(BTypeValuesXmlParams <int> @params, Collections.BTypeValuesInt32 list) : base(@params, list) { Contract.Requires <ArgumentNullException>(@params != null); Contract.Requires <ArgumentNullException>(list != null); }
public MegaloScriptVarReferenceValue(MegaloScriptValueType valueType) : base(valueType) { Contract.Requires(valueType.BaseType == MegaloScriptValueBaseType.VarReference); }
public MegaloScriptTeamFilterParametersValue(MegaloScriptValueType valueType) : base(valueType) { Contract.Requires(valueType.BaseType == MegaloScriptValueBaseType.TeamFilterParameters); }
internal static void BitEncodeResourceModelIndex(ref Bitwise.HandleBitEncoder encoder, int resourceModelIndex) { Contract.Requires <ArgumentOutOfRangeException>(IsValidResourceModelIndex(resourceModelIndex)); encoder.EncodeNoneable32(resourceModelIndex, kResourceModelBitMask); }
public MegaloScriptSingleValue(MegaloScriptValueType valueType) : base(valueType) { Contract.Requires(valueType.BaseType == MegaloScriptValueBaseType.Single); }