public void Serialize(IO.BitStream s) { s.Stream(ref Transparent); s.Stream(ref Red); s.Stream(ref Green); s.Stream(ref Blue); }
public void Serialize(IO.BitStream s) { for (int x = 0; x < Possibilities.Length; x++) { s.StreamValue(ref Possibilities[x]); } }
public void Serialize(IO.BitStream s) { s.Stream(ref Modifiers, Bits.kInt64BitCount, WeaponModifiersBitStreamer.Instance); if (EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value0)) { s.Stream(ref mValue0, 0f, 1f, 20, true, true); } if (EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value1)) { s.Stream(ref mValue1, 0f, 1f, 20, true, true); } if (EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value2)) { s.Stream(ref mValue2, 0f, 1f, 20, true, true); } if (EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value3)) { s.Stream(ref mValue3, 0f, 1f, 20, true, true); } if (EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value4)) { s.Stream(ref mValue4, 0f, 1f, 20, true, true); } if (EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value5)) { s.Stream(ref mValue5, 0f, 1.5706964f, 20, true, true); } if (EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value6)) { s.Stream(ref mValue6, 0f, 1000f, 20, true, true); } if (EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value7)) { s.Stream(ref mValue7, 0f, 1000f, 20, true, true); } if (EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value8)) { s.Stream(ref mValue8, 0f, 1000f, 20, true, true); } if (EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value9)) { s.Stream(ref mValue9, 0f, 1.5706964f, 20, true, true); } if (EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value10)) { s.Stream(ref mValue10, 0f, 1000f, 20, true, true); } if (EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value11)) { s.Stream(ref mValue11, 0f, 1000f, 20, true, true); } if (EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value12)) { s.Stream(ref mValue12, 0f, 1000f, 20, true, true); } if (EnumFlags.Test(Modifiers, WeaponTuningModifiers.Value13)) { s.Stream(ref mValue13, 0f, 6.2831855f, 20, true, true); } }
void Serialize(MegaloScriptModel model, IO.BitStream s, Proto.MegaloScriptProtoVariableReference protoType) { s.Stream(ref Type, protoType.TypeBitLength); if (Type < 0 || Type >= protoType.Members.Count) { throw new System.IO.InvalidDataException(string.Format(Util.InvariantCultureInfo, "{0}/{1}: Encountered invalid {2} type data", s.StreamName, model.MegaloVariant.BaseVariant.Header.Title, mReferenceKind)); } var member = protoType.Members[Type]; if (member.HasDataType) { MegaloScriptEnumValue.SerializeValue(model, s, member.EnumValueType, ref DataType); } else { DataType = TypeExtensions.kNone; } if (member.HasDataValue) { SerializeData(model, s, member.ValueType); } else { Data = TypeExtensions.kNone; } }
protected virtual void SerializeImpl(IO.BitStream s) { var condition_write_order = s.IsWriting ? mCompilerState.ConditionWriteOrder : null; var action_write_order = s.IsWriting ? mCompilerState.ActionWriteOrder : null; var trigger_write_order = s.IsWriting ? mCompilerState.TriggerWriteOrder : null; Collections.ActiveListUtil.Serialize(s, Conditions, Database.Limits.Conditions.CountBitLength, this, NewConditionFromBitStream, condition_write_order); Collections.ActiveListUtil.Serialize(s, Actions, Database.Limits.Actions.CountBitLength, this, NewActionFromBitStream, action_write_order); Collections.ActiveListUtil.Serialize(s, Triggers, Database.Limits.Triggers.CountBitLength, this, NewTriggerFromBitStream, trigger_write_order); s.StreamElements(GameStatistics, Database.Limits.GameStatistics.CountBitLength, this, _model => _model.NewGameStatistic()); GlobalVariables.Serialize(this, s); PlayerVariables.Serialize(this, s); ObjectVariables.Serialize(this, s); TeamVariables.Serialize(this, s); s.StreamElements(HudWidgets, Database.Limits.HudWidgets.CountBitLength); SerializeTriggerEntryPoints(s); ObjectTypeReferences.SerializeWords(s, Shell.EndianFormat.Little); s.StreamElements(ObjectFilters, Database.Limits.ObjectFilters.CountBitLength); if (Database.Limits.SupportsGameObjectFilters) { SerializeGameObjectFilters(s); } }
public void Serialize(IO.BitStream s) { s.Stream(ref Type, 4, ContentTypeBitStreamer.Instance); s.Stream(ref FileLength); s.Stream(ref unk08); s.Stream(ref unk10); s.Stream(ref unk18); s.Stream(ref unk20); SerializeActivity(s); s.Stream(ref Mode, 3, GameModeBitStreamer.Instance); s.Stream(ref EngineType, 3, GameEngineTypeBitStreamer.Instance); s.Stream(ref unk2C); s.Stream(ref EngineCategoryIndex, 8, signExtend:true); s.StreamObject(Creator); s.StreamObject(Modifier); s.Stream(ref Title, Memory.Strings.StringStorage.CStringUnicodeBigEndian, maxLength: kStringLength-1); s.Stream(ref Description, Memory.Strings.StringStorage.CStringUnicodeBigEndian, maxLength: kStringLength-1); if (Type == ContentType.Film || Type == ContentType.FilmClip) s.Stream(ref unk280); else if (Type == ContentType.GameVariant) s.Stream(ref unk280, 8, signExtend:true); if (Activity == 2) s.Stream(ref HopperId); SerializeGameSpecificData(s); }
void Read(IO.BitStream bs) { int uncompressed_size; bool is_compressed; bs.Read(out uncompressed_size, mOwner.kInfo.BufferSizeBitLength); int size = uncompressed_size; if (uncompressed_size > mOwner.kInfo.BufferMaxSize) { throw new System.IO.InvalidDataException("Input string table buffer size too large by (bytes): " + (uncompressed_size - mOwner.kInfo.BufferMaxSize).ToString()); } bs.Read(out is_compressed); if (is_compressed) { bs.Read(out size, mOwner.kInfo.BufferSizeBitLength); } Buffer = new byte[size]; bs.Read(Buffer); if (is_compressed) { Buffer = IO.Compression.ZLib.LowLevelDecompress(Buffer, uncompressed_size); } }
/// <remarks>Used for indexes which *are not* typically NONE (-1)</remarks> public static void StreamIndexPos(this IO.BitStream s, ref int value, int bitCount = Bits.kInt32BitCount) { Contract.Requires(bitCount <= Bits.kInt32BitCount); if (s.IsReading) { bool not_none = s.ReadBoolean(); if (not_none) { s.Read(out value, bitCount); } else { value = TypeExtensions.kNone; } } else if (s.IsWriting) { bool not_none = value.IsNotNone(); s.Write(not_none); if (not_none) { s.Write(value, bitCount); } } }
protected override void SerializeImpl(IO.BitStream s) { #region struct // 0x BaseVariant // 0x734 StringTable // 0x5DBC EncodingVersion // 0x5DC0 PlayerTraits // 0x60C4 UserDefinedOptions // 0x63A8 EngineDefinition // 0xE668 BaseNameStringIndex // 0x EngineIconIndex // 0x EngineCategory // 0x MapPermissions // 0x PlayerRatingParameters // 0x ScoreToWinRound // 0xE66C DisabledEngineOptions // 0xE70C HiddenEngineOptions // 0xE7AC DisabledUserOptions // 0xE7B0 HiddenUserOptions #endregion s.Stream(ref FireTeamsEnabled); s.Stream(ref SymmetricGametype); SerializeOptionToggles(s); s.StreamObject(EngineDefinition); // 0x63A8 if (mEncodingVersion >= kEncodingVersionTU1) { s.StreamObject(TU1); } }
public void Serialize(IO.BitStream s) { using (s.EnterOwnerBookmark(this)) { s.Stream(ref mEncodingVersion); if (s.IsReading && !VerifyEncodingVersion()) { throw new IO.VersionMismatchException("Megalo encoding", (uint)mEncodingVersion); } s.Stream(ref EngineVersion); // global, not a c_game_engine_megalo_variant member s.StreamObject(BaseVariant); s.StreamElements(PlayerTraits, MegaloDatabase.Limits.PlayerTraits.CountBitLength, this, _this => _this.NewMegaloPlayerTraits()); s.StreamElements(UserDefinedOptions, MegaloDatabase.Limits.UserDefinedOptions.CountBitLength); s.StreamObject(StringTable); StreamStringTableIndexPointer(s, ref BaseNameStringIndex); SerializeDescriptionLocaleStrings(s); s.StreamNoneable(ref EngineIconIndex, MegaloDatabase.Limits.EngineCategories.IndexBitLength); s.StreamNoneable(ref EngineCategory, MegaloDatabase.Limits.EngineCategories.IndexBitLength); s.StreamObject(MapPermissions); s.StreamObject(PlayerRatingParameters); s.Stream(ref ScoreToWinRound); SerializeImpl(s); } }
protected override void SerializeWeaponsAndEquipment(IO.BitStream s) { base.SerializeWeaponsAndEquipment(s); s.Stream(ref TacticalPackage); s.Stream(ref SupportUpgrade); }
protected void SerializeOptionToggles(IO.BitStream s) { DisabledEngineOptions.SerializeWords(s, Shell.EndianFormat.Little); HiddenEngineOptions.SerializeWords(s, Shell.EndianFormat.Little); DisabledUserOptions.SerializeWords(s, Shell.EndianFormat.Little); HiddenUserOptions.SerializeWords(s, Shell.EndianFormat.Little); }
public override void Serialize(MegaloScriptModel model, IO.BitStream s) { s.Stream(ref mShapeType, 2, MegaloScriptShapeTypeBitStreamer.Instance); switch (ShapeType) { case MegaloScriptShapeType.Sphere: mRadius.SerializeCustom(model, s); break; case MegaloScriptShapeType.Cylinder: mRadius.SerializeCustom(model, s); mTop.SerializeCustom(model, s); mBottom.SerializeCustom(model, s); break; case MegaloScriptShapeType.Box: mRadius.SerializeCustom(model, s); mLength.SerializeCustom(model, s); mTop.SerializeCustom(model, s); mBottom.SerializeCustom(model, s); break; case MegaloScriptShapeType.None: break; default: throw new KSoft.Debug.UnreachableException(ShapeType.ToString()); } }
public override void Serialize(IO.BitStream s) { base.Serialize(s); s.Stream(ref IsHidden); s.Stream(ref IsRuntime); }
public void Enum_BitStreamerUpCastTest() { const int k_bit_count = 64; using (var ms = new System.IO.MemoryStream()) using (var s = new IO.BitStream(ms)) { const System.TypeCode kExpectedValue = System.TypeCode.String; var value = kExpectedValue; s.StreamMode = System.IO.FileAccess.Write; TypeCodeStreamer64.Write(s, value, k_bit_count); s.Flush(); s.SeekToStart(); s.StreamMode = System.IO.FileAccess.Read; TypeCodeStreamer64.Read(s, out value, k_bit_count); Assert.AreEqual(kExpectedValue, value); ////////////////////////////////////////////////////////////////////////// // Test the instance interface var streamer_instance = TypeCodeStreamer64.Instance; s.SeekToStart(); s.StreamMode = System.IO.FileAccess.Write; streamer_instance.Write(s, value, k_bit_count); s.Flush(); s.SeekToStart(); s.StreamMode = System.IO.FileAccess.Read; streamer_instance.Read(s, out value, k_bit_count); Assert.AreEqual(kExpectedValue, value); } }
/// <summary>Read a single-byte CString from a bitstream</summary> /// <param name="s">Endian stream to read from</param> /// <param name="ms">Stream to write the character's bytes to</param> /// <param name="maxLength">Optional maximum length of this specific string</param> void ReadCStringSingleByte(IO.BitStream s, System.IO.MemoryStream ms, int maxLength) { byte character; if (maxLength > 0) { int x = 0; while ((character = s.ReadByte()) != 0 && ++x <= maxLength) { ms.WriteByte(character); } } else if (!mStorage.IsFixedLength) { while ((character = s.ReadByte()) != 0) { ms.WriteByte(character); } } else { byte[] characters = s.ReadBytes(mFixedLengthByteLength); int x; for (x = 0; x < characters.Length; x++) { if (characters[x] == 0) { break; } } ms.Write(characters, 0, x); } }
protected override void SerializeDescriptionLocaleStrings(IO.BitStream s) { s.StreamObject(NameString); // 0x18350 s.StreamObject(DescriptionString); // 0x187BC s.StreamObject(IntroDescriptionString); // 0x198E8. haven't seen this used... s.StreamObject(CategoryString); // 0x1AA14 }
byte[] ReadStrPascal(IO.BitStream s, out int actualCount, int prefixBitLength) { actualCount = TypeExtensions.kNone; if (prefixBitLength.IsNone()) { switch (mStorage.LengthPrefix) { case StringStorageLengthPrefix.Int8: prefixBitLength = Bits.kByteBitCount; break; case StringStorageLengthPrefix.Int16: prefixBitLength = Bits.kInt16BitCount; break; case StringStorageLengthPrefix.Int32: prefixBitLength = Bits.kInt32BitCount; break; } } int length; switch (mStorage.LengthPrefix) { case StringStorageLengthPrefix.Int7: throw new NotSupportedException(); case StringStorageLengthPrefix.Int8: length = s.ReadByte(prefixBitLength); break; case StringStorageLengthPrefix.Int16: length = s.ReadInt16(prefixBitLength); break; case StringStorageLengthPrefix.Int32: length = s.ReadInt32(prefixBitLength); break; default: throw new Debug.UnreachableException(); } return(s.ReadBytes(GetMaxCleanByteCount(length))); }
void ReferencesWrite(IO.BitStream s) { for (int x = 0; x < mStringReferences.Count; x++) { mStringReferences[x].Serialize(s, kInfo.BufferOffsetBitLength); } }
/// <summary>Read a string from an bitstream using <see cref="Storage"/>'s specifications</summary> /// <param name="s">Endian stream to read from</param> /// <param name="length">Optional length specification</param> /// <param name="maxLength">CString only: Optional maximum length of this specific string</param> /// <param name="prefixBitLength">Pascal only: Number of bits in the prefix count</param> /// <returns></returns> internal string ReadString(IO.BitStream s, int length, int maxLength = -1, int prefixBitLength = -1) { Contract.Requires(s != null); if (length < 0) // Not <= because FixedLength might just be zero itself, resulting in a redundant expression { length = mStorage.FixedLength; } byte[] bytes = null; int actual_count = 0; switch (mStorage.Type) { // Type streamers should set actual_count to -1 if we're to assume all the bytes are characters. // Otherwise, set actual_count to a byte count for padded string cases (where we don't want to // include null characters in the result string) case StringStorageType.CString: bytes = ReadStrCString(s, length, out actual_count, maxLength); break; case StringStorageType.Pascal: bytes = ReadStrPascal(s, out actual_count, prefixBitLength); break; case StringStorageType.CharArray: bytes = ReadStrCharArray(s, length, out actual_count); break; default: throw new Debug.UnreachableException(); } return(new string(actual_count != -1 ? mBaseEncoding.GetChars(bytes, 0, actual_count) // for padded string cases : mBaseEncoding.GetChars(bytes))); // for complete string cases }
void SerializeData(MegaloScriptModel model, IO.BitStream s, Proto.MegaloScriptValueType valueType) { var base_type = valueType.BaseType; switch (base_type) { case Proto.MegaloScriptValueBaseType.Int: s.Stream(ref Data, valueType.BitLength, signExtend: true); break; case Proto.MegaloScriptValueBaseType.UInt: case Proto.MegaloScriptValueBaseType.Var: s.Stream(ref Data, valueType.BitLength); break; case Proto.MegaloScriptValueBaseType.Enum: MegaloScriptEnumValue.SerializeValue(model, s, valueType, ref Data); break; case Proto.MegaloScriptValueBaseType.Index: MegaloScriptIndexValue.SerializeValue(model, s, valueType, ref Data); break; default: throw new KSoft.Debug.UnreachableException(base_type.ToString()); } }
public void Serialize(IO.BitStream s) { foreach (var lo in Loadouts) { lo.Serialize(s); } }
public void Serialize(IO.BitStream s) { s.Stream(ref PlayerRequisitionFrequencySeconds); s.Stream(ref InitialGameCurrency); s.StreamElements(RequisitionItems, 7); // 0x26E0 0x26E4 Contract.Assert(RequisitionItems.Count == 0); }
private void SerializePalettes(IO.BitStream s) { foreach (var p in Palettes) { p.Serialize(s); } }
public override void Serialize(MegaloScriptModel model, IO.BitStream s) { base.Serialize(model, s); model.Database.ObjectReferenceWithPlayerVarIndex.StreamPlayerVarIndex(s, ref mPlayerVarIndex, Var.Type, model); }
public void Enum_BitStreamerUsingUnderlyingTypeTest() { const int k_bit_count = 32; using (var ms = new System.IO.MemoryStream()) using (var s = new IO.BitStream(ms)) { const EnumBinaryStreamerTest.UInt32Enum kExpectedValue = EnumBinaryStreamerTest.UInt32Enum.DeadBeef; var value = kExpectedValue; s.StreamMode = System.IO.FileAccess.Write; UInt32EnumStreamer.Write(s, value, k_bit_count); s.Flush(); s.SeekToStart(); s.StreamMode = System.IO.FileAccess.Read; UInt32EnumStreamer.Read(s, out value, k_bit_count); Assert.AreEqual(kExpectedValue, value); ////////////////////////////////////////////////////////////////////////// // Test the instance interface var streamer_instance = UInt32EnumStreamer.Instance; s.SeekToStart(); s.StreamMode = System.IO.FileAccess.Write; streamer_instance.Write(s, value, k_bit_count); s.Flush(); s.SeekToStart(); s.StreamMode = System.IO.FileAccess.Read; streamer_instance.Read(s, out value, k_bit_count); Assert.AreEqual(kExpectedValue, value); } }
void StreamEntryPointTriggerIndex(IO.BitStream s, ref int triggerIndex, Proto.MegaloScriptTriggerEntryPoints entryPoint) { if (Database.Limits.Supports(entryPoint)) { int local_trigger_index = triggerIndex; if (s.IsWriting) { mCompilerState.RemapTriggerPointer(ref local_trigger_index); } if (!Database.Limits.StreamEntryPointIndexAsPointer) { s.StreamIndex(ref local_trigger_index, Database.Limits.Triggers.IndexBitLength); // pointer-has-value } else { s.StreamNoneable(ref local_trigger_index, Database.Limits.Triggers.CountBitLength); // pointer } if (s.IsReading) { triggerIndex = local_trigger_index; } } else { triggerIndex = -1; } }
public void EnumBitStreamer_TestNoneSentinelEncoding() { const int k_bit_count = 32; using (var ms = new System.IO.MemoryStream()) using (var s = new IO.BitStream(ms)) { const NoneSentinelEncodedEnum kExpectedValue = NoneSentinelEncodedEnum.Three; var value = kExpectedValue; s.StreamMode = System.IO.FileAccess.Write; NoneSentinelEncodedEnumStreamer.Stream(s, ref value, k_bit_count); s.Flush(); s.SeekToStart(); s.StreamMode = System.IO.FileAccess.Read; NoneSentinelEncodedEnumStreamer.Stream(s, ref value, k_bit_count); Assert.AreEqual(kExpectedValue, value); ////////////////////////////////////////////////////////////////////////// // Test the instance interface var streamer_instance = NoneSentinelEncodedEnumStreamer.Instance; s.SeekToStart(); s.StreamMode = System.IO.FileAccess.Write; streamer_instance.Stream(s, ref value, k_bit_count); s.Flush(); s.SeekToStart(); s.StreamMode = System.IO.FileAccess.Read; streamer_instance.Stream(s, ref value, k_bit_count); Assert.AreEqual(kExpectedValue, value); } }
protected void SerializeFrameUpdate(MegaloScriptModel model, IO.BitStream s) { Util.MarkUnusedVariable(ref model); s.StreamNoneable(ref mFrameUpdateFrequency, 8); s.StreamNoneable(ref mFrameUpdateOffset, 8); }
public override void Serialize(IO.BitStream s) { Modifiers.Serialize(s); s.Stream(ref WeaponPickupAllowed, 2); s.Stream(ref InitialGrenadeCount, 5); s.Stream(ref InfAmmo, 2); s.Stream(ref EquipmentUsage, 2); s.Stream(ref EquipmentUsageExceptingAutoTurret, 2); s.Stream(ref EquipmentDrop, 2); s.Stream(ref InfEquipment, 2); s.Stream(ref WellEquipped, 2); s.Stream(ref Grenadier, 2); s.Stream(ref ExplodeOnDeathArmorMod, 2); s.Stream(ref OrdnanceMarkersVisable, 2); s.Stream(ref Resourceful, 2); s.Stream(ref Ammopack, 2); s.Stream(ref OrdnanceRerollAvailable, 2); // #TODO_BLAM: verify s.Stream(ref OrdnanceDisabled, 2); s.Stream(ref InitialPrimaryWeapon); s.Stream(ref InitialSecondaryWeapon); s.Stream(ref InitialEquipment); s.Stream(ref InitialTacticalPackage); s.Stream(ref InitialSupportUpgrade); }