/// <summary> /// Writes the data element into the given buffer (at its current position). /// </summary> /// <param name="buffer">The buffer where the data element should be deserialized into.</param> public void WriteData(RAMBuffer buffer) { buffer.WriteUShort((ushort)PlayerName.Length); buffer.WriteString(PlayerName); buffer.WriteFloat(InitialCameraX); buffer.WriteFloat(InitialCameraY); buffer.WriteShort(UnknownX); buffer.WriteShort(UnknownY); buffer.WriteByte(AlliedVictory); ScenarioDataElementTools.AssertTrue(Diplomacy1.Count == Diplomacy2.Count); buffer.WriteUShort((ushort)Diplomacy1.Count); Diplomacy1.ForEach(d => buffer.WriteByte((byte)d)); Diplomacy2.ForEach(d => buffer.WriteUInteger((uint)d)); buffer.WriteUInteger(Color); buffer.WriteFloat(Unknown1); buffer.WriteUShort(Unknown3Count); if (Unknown1 == 2) { ScenarioDataElementTools.AssertListLength(Unknown2, 8); Unknown2.ForEach(b => buffer.WriteByte(b)); } ScenarioDataElementTools.AssertListLength(Unknown3, Unknown3Count * 44); Unknown3.ForEach(b => buffer.WriteByte(b)); ScenarioDataElementTools.AssertListLength(Unknown4, 7); Unknown4.ForEach(b => buffer.WriteByte(b)); buffer.WriteInteger(Unknown5); }
public void WriteData(RAMBuffer buffer) { AssertListLength(RequiredTechs, 6); RequiredTechs.ForEach(e => buffer.WriteShort(e)); AssertListLength(ResourceCosts, 3); ResourceCosts.ForEach(e => { buffer.WriteShort(e.Type); buffer.WriteShort(e.Amount); buffer.WriteByte(e.Mode); }); buffer.WriteShort(RequiredTechCount); buffer.WriteShort(Civ); buffer.WriteShort(FullTechMode); buffer.WriteShort(ResearchLocation); buffer.WriteUShort(LanguageDLLName1); buffer.WriteUShort(LanguageDLLDescription); buffer.WriteShort(ResearchTime); buffer.WriteShort(TechageID); buffer.WriteShort(Type); buffer.WriteShort(IconID); buffer.WriteByte(ButtonID); buffer.WriteInteger(LanguageDLLHelp); buffer.WriteInteger(LanguageDLLName2); buffer.WriteInteger(Unknown1); buffer.WriteUShort((ushort)Name.Length); buffer.WriteString(Name); }
public void WriteData(RAMBuffer buffer) { buffer.WriteInteger(VirtualFunctionPtr); buffer.WriteInteger(MapPointer); buffer.WriteInteger(MapWidth); buffer.WriteInteger(MapHeight); buffer.WriteInteger(WorldWidth); buffer.WriteInteger(WorldHeight); AssertListLength(TileSizes, 19); TileSizes.ForEach(ts => ts.WriteData(buffer)); buffer.WriteShort(PaddingTS); Terrains.ForEach(t => t.WriteData(buffer)); AssertListLength(TerrainBorders, 16); TerrainBorders.ForEach(tb => tb.WriteData(buffer)); buffer.WriteInteger(MapRowOffset); buffer.WriteFloat(MapMinX); buffer.WriteFloat(MapMinY); buffer.WriteFloat(MapMaxX); buffer.WriteFloat(MapMaxY); buffer.WriteFloat(MapMaxXplus1); buffer.WriteFloat(MapMaxYplus1); buffer.WriteUShort(TerrainsUsed2); buffer.WriteUShort(BordersUsed); buffer.WriteShort(MaxTerrain); buffer.WriteShort(TileWidth); buffer.WriteShort(TileHeight); buffer.WriteShort(TileHalfHeight); buffer.WriteShort(TileHalfWidth); buffer.WriteShort(ElevHeight); buffer.WriteShort(CurRow); buffer.WriteShort(CurCol); buffer.WriteShort(BlockBegRow); buffer.WriteShort(BlockEndRow); buffer.WriteShort(BlockBegCol); buffer.WriteShort(BlockEndCol); buffer.WriteInteger(SearchMapPtr); buffer.WriteInteger(SearchMapRowsPtr); buffer.WriteByte(AnyFrameChange); buffer.WriteByte(MapVisibleFlag); buffer.WriteByte(FogFlag); AssertListLength(SomeBytes, 21); SomeBytes.ForEach(b => buffer.WriteByte(b)); AssertListLength(SomeInt32, 157); SomeInt32.ForEach(i => buffer.WriteInteger(i)); }
/// <summary> /// Writes the data element into the given buffer (at its current position). /// </summary> /// <param name="buffer">The buffer where the data element should be deserialized into.</param> public void WriteData(RAMBuffer buffer) { buffer.WriteFloat(PositionX); buffer.WriteFloat(PositionY); buffer.WriteFloat(PositionZ); buffer.WriteUInteger(Id); buffer.WriteUShort(UnitId); buffer.WriteByte(State); buffer.WriteFloat(Rotation); buffer.WriteUShort(Frame); buffer.WriteInteger(GarrisonId); }
public void WriteData(RAMBuffer buffer) { buffer.WriteByte(Exists); if (Exists != 0) { buffer.WriteUShort((ushort)Commands.Count); Commands.ForEach(e => e.WriteData(buffer)); } }
public void WriteData(RAMBuffer buffer) { buffer.WriteByte(One); buffer.WriteString(Name, 20); buffer.WriteUShort((ushort)Resources.Count); buffer.WriteShort(TechTreeID); buffer.WriteShort(TeamBonusID); Resources.ForEach(e => buffer.WriteFloat(e)); buffer.WriteByte(IconSet); buffer.WriteUShort((ushort)UnitPointers.Count); UnitPointers.ForEach(e => buffer.WriteInteger(e)); // Sicherstellen, dass genau jede definierte Einheit einen entsprechenden Pointer hat; hier nur über die Listenlänge, sollte aber die meisten auftretenden Fehler abdecken AssertListLength(Units, UnitPointers.Count(p => p != 0)); foreach (var u in Units) { u.Value.WriteData(buffer); } }
public void WriteData(RAMBuffer buffer) { buffer.WriteString(Name1, 21); buffer.WriteString(Name2, 13); buffer.WriteInteger(SLP); buffer.WriteByte(Unknown1); buffer.WriteByte(Unknown2); buffer.WriteByte(Layer); buffer.WriteByte(PlayerColor); buffer.WriteByte(Rainbow); buffer.WriteByte(Replay); AssertListLength(Coordinates, 4); Coordinates.ForEach(e => buffer.WriteShort(e)); buffer.WriteUShort((ushort)Deltas.Count); buffer.WriteShort(SoundID); buffer.WriteByte(AttackSoundUsed); buffer.WriteUShort(FrameCount); buffer.WriteUShort(AngleCount); buffer.WriteFloat(NewSpeed); buffer.WriteFloat(FrameRate); buffer.WriteFloat(ReplayDelay); buffer.WriteByte(SequenceType); buffer.WriteShort(ID); buffer.WriteByte(MirroringMode); buffer.WriteByte(Unknown3); Deltas.ForEach(e => e.WriteData(buffer)); if (AttackSoundUsed != 0) { AssertListLength(AttackSounds, AngleCount); AttackSounds.ForEach(e => e.WriteData(buffer)); } }
public void WriteData(RAMBuffer buffer) { buffer.WriteShort(DefaultArmor); buffer.WriteUShort((ushort)Attacks.Count); foreach (KeyValuePair <ushort, ushort> currA in Attacks) { buffer.WriteUShort(currA.Key); buffer.WriteUShort(currA.Value); } buffer.WriteUShort((ushort)Armors.Count); foreach (KeyValuePair <ushort, ushort> currA in Armors) { buffer.WriteUShort(currA.Key); buffer.WriteUShort(currA.Value); } buffer.WriteShort(TerrainRestrictionForDamageMultiplying); buffer.WriteFloat(MaxRange); buffer.WriteFloat(BlastRadius); buffer.WriteFloat(ReloadTime); buffer.WriteShort(ProjectileUnitID); buffer.WriteShort(ProjectileAccuracyPercent); buffer.WriteByte(TowerMode); buffer.WriteShort(ProjectileFrameDelay); AssertListLength(ProjectileGraphicDisplacement, 3); ProjectileGraphicDisplacement.ForEach(e => buffer.WriteFloat(e)); buffer.WriteByte(BlastLevel); buffer.WriteFloat(MinRange); buffer.WriteFloat(ProjectileDispersion); buffer.WriteShort(AttackGraphic); buffer.WriteShort(DisplayedMeleeArmor); buffer.WriteShort(DisplayedAttack); buffer.WriteFloat(DisplayedRange); buffer.WriteFloat(DisplayedReloadTime); }
/// <summary> /// Speichert die enthaltene Bitmap in den angegebenen Puffer. /// </summary> /// <param name="buffer">Der Puffer, in den das Bild gespeichert werden soll.</param> /// <param name="writeFileHeader">Optional. Gibt an, ob der Dateiheader geschrieben werden oder direkt mit der BITMAPINFOHEADER-Struktur begonnen werden soll.</param> public void SaveToBuffer(RAMBuffer buffer, bool writeFileHeader = true) { // Bilddatenbreite ggf. auf ein Vielfaches von 4 Bytes erhöhen int width = _header.width; // Hilfsvariable zur Performanceerhöhung (immer gleichwertig mit _header.width) int width2 = width; while (width2 % 4 != 0) { width2++; } // Bilddaten-Binär-Zielarray erstellen _imageDataBin = new byte[width2 * Math.Abs(_header.height)]; // Bilddaten in Zielarray schreiben int height2 = Math.Abs(_header.height); for (int x = 0; x < width2; x++) // Start: Links { for (int y = 0; y < height2; y++) // Start: Oben { if (x >= width) { // Falls x außerhalb der Bildbreite liegt, Füllbyte einsetzen _imageDataBin[y * width2 + x] = 0; } else { // Normaler Pixel: Farbtabellenindex schreiben, dabei Bottom-Up-Richtung beachten _imageDataBin[y * width2 + x] = _imageData[(height2 - y - 1) * width + x]; } } } // Header vorbereiten (einige wurden zwar schon definiert, aber lieber alle beisammen) _header.type = 19778; _header.fileSize = (uint)(44 + 256 * 4 + _imageDataBin.Length); _header.reserved = 0; _header.offsetData = (uint)(44 + 256 * 4); _header.imageHeaderSize = 40; _header.width = width; _header.height = height2; _header.layerCount = 1; _header.bitsPerPixel = 8; _header.compression = Header.COMPR_RGB; _header.size = (uint)(height2 * width); _header.xDPI = 0; _header.yDPI = 0; _header.colorCount = 0; _header.colorImportantCount = 0; // Header schreiben if (writeFileHeader) { buffer.WriteUShort(_header.type); buffer.WriteUInteger(_header.fileSize); buffer.WriteUInteger(_header.reserved); buffer.WriteUInteger(_header.offsetData); } buffer.WriteUInteger(_header.imageHeaderSize); buffer.WriteInteger(_header.width); buffer.WriteInteger(_header.height); buffer.WriteUShort(_header.layerCount); buffer.WriteUShort(_header.bitsPerPixel); buffer.WriteUInteger(_header.compression); buffer.WriteUInteger(_header.size); buffer.WriteInteger(_header.xDPI); buffer.WriteInteger(_header.yDPI); buffer.WriteUInteger(_header.colorCount); buffer.WriteUInteger(_header.colorImportantCount); // Farbtabelle schreiben _colorTable.ToBinary(ref buffer); // Bilddaten schreiben buffer.Write(_imageDataBin); }
public void WriteData(RAMBuffer buffer) { buffer.WriteString(Name, 31); buffer.WriteUShort((ushort)Effects.Count); Effects.ForEach(e => e.WriteData(buffer)); }
public void WriteData(RAMBuffer buffer) { buffer.WriteByte((byte)Type); buffer.WriteUShort((ushort)Name1.Length); buffer.WriteShort(ID1); buffer.WriteUShort(LanguageDLLName); buffer.WriteUShort(LanguageDLLCreation); buffer.WriteShort(Class); buffer.WriteShort(StandingGraphic1); buffer.WriteShort(StandingGraphic2); buffer.WriteShort(DyingGraphic1); buffer.WriteShort(DyingGraphic2); buffer.WriteByte(DeathMode); buffer.WriteShort(HitPoints); buffer.WriteFloat(LineOfSight); buffer.WriteByte(GarrisonCapacity); buffer.WriteFloat(SizeRadius1); buffer.WriteFloat(SizeRadius2); buffer.WriteFloat(HPBarHeight1); buffer.WriteShort(TrainSound1); buffer.WriteShort(TrainSound2); buffer.WriteShort(DeadUnitID); buffer.WriteByte(PlacementMode); buffer.WriteByte(AirMode); buffer.WriteShort(IconID); buffer.WriteByte(HideInEditor); buffer.WriteShort(Unknown1); buffer.WriteByte(Enabled); buffer.WriteByte(Disabled); buffer.WriteShort(PlacementBypassTerrain1); buffer.WriteShort(PlacementBypassTerrain2); buffer.WriteShort(PlacementTerrain1); buffer.WriteShort(PlacementTerrain2); buffer.WriteFloat(EditorRadius1); buffer.WriteFloat(EditorRadius2); buffer.WriteByte(HillMode); buffer.WriteByte(VisibleInFog); buffer.WriteShort(TerrainRestriction); buffer.WriteByte(FlyMode); buffer.WriteShort(ResourceCapacity); buffer.WriteFloat(ResourceDecay); buffer.WriteByte(BlastType); buffer.WriteByte(Unknown2); buffer.WriteByte(InteractionMode); buffer.WriteByte(MinimapMode); buffer.WriteByte(CommandAttribute); buffer.WriteFloat(Unknown3A); buffer.WriteByte(MinimapColor); buffer.WriteInteger(LanguageDLLHelp); buffer.WriteInteger(LanguageDLLHotKeyText); buffer.WriteInteger(HotKey); buffer.WriteByte(Unselectable); buffer.WriteByte(Unknown6); buffer.WriteByte(UnknownSelectionMode); buffer.WriteByte(Unknown8); buffer.WriteByte(SelectionMask); buffer.WriteByte(SelectionShapeType); buffer.WriteByte(SelectionShape); buffer.WriteByte(Attribute); buffer.WriteByte(Civilization); buffer.WriteShort(Nothing); buffer.WriteByte(SelectionEffect); buffer.WriteByte(EditorSelectionColor); buffer.WriteFloat(SelectionRadius1); buffer.WriteFloat(SelectionRadius2); buffer.WriteFloat(HPBarHeight2); AssertListLength(ResourceStorages, 3); ResourceStorages.ForEach(e => { buffer.WriteShort(e.Type); buffer.WriteFloat(e.Amount); buffer.WriteByte(e.Mode); }); buffer.WriteByte((byte)DamageGraphics.Count); DamageGraphics.ForEach(e => e.WriteData(buffer)); buffer.WriteShort(SelectionSound); buffer.WriteShort(DyingSound); buffer.WriteByte(AttackMode); buffer.WriteByte(EdibleMeat); buffer.WriteString(Name1); buffer.WriteShort(ID2); buffer.WriteShort(ID3); if (Type >= UnitType.Flag) { buffer.WriteFloat(Speed); } if (Type >= UnitType.DeadFish) { DeadFish.WriteData(buffer); } if (Type >= UnitType.Bird) { Bird.WriteData(buffer); } if (Type >= UnitType.Type50) { Type50.WriteData(buffer); } if (Type == UnitType.Projectile) { Projectile.WriteData(buffer); } if (Type >= UnitType.Creatable) { Creatable.WriteData(buffer); } if (Type == UnitType.Building) { Building.WriteData(buffer); } }
/// <summary> /// Schreibt die enthaltenen Daten in das interne RAMBuffer-Objekt. /// </summary> /// <remarks></remarks> private void WriteData() { // Puffer initialisieren if (_buffer == null) { _buffer = new RAMBuffer(); } else if (_buffer.Length != 0) { _buffer.Clear(); } // Dateiversion schreiben _buffer.WriteString("VER 5.7", 8); // Anzahlen schreiben IGenieDataElement.AssertTrue(TerrainRestrictionPointers1.Count == TerrainRestrictionPointers2.Count); _buffer.WriteUShort((ushort)TerrainRestrictionPointers1.Count); _buffer.WriteUShort((ushort)DataElements.TerrainRestriction.TerrainCount); // Terrain-Pointer schreiben TerrainRestrictionPointers1.ForEach(e => _buffer.WriteInteger(e)); TerrainRestrictionPointers2.ForEach(e => _buffer.WriteInteger(e)); // Terrain-Beschränkungen schreiben TerrainRestrictions.ForEach(e => e.WriteData(_buffer)); // Anzahl schreiben _buffer.WriteUShort((ushort)PlayerColors.Count); // Spielerfarben schreiben PlayerColors.ForEach(e => e.WriteData(_buffer)); // Anzahl schreiben _buffer.WriteUShort((ushort)Sounds.Count); // Sounds schreiben Sounds.ForEach(e => e.WriteData(_buffer)); // Anzahl schreiben _buffer.WriteUShort((ushort)GraphicPointers.Count); // Grafik-Pointer schreiben GraphicPointers.ForEach(e => _buffer.WriteInteger(e)); // Grafiken schreiben Sicherstellen, dass genau jede definierte Grafik einen entsprechenden Pointer hat; hier nur über die Listenlänge, sollte aber die meisten auftretenden Fehler abdecken IGenieDataElement.AssertListLength(Graphics, GraphicPointers.Count(p => p != 0)); foreach (var e in Graphics) { e.Value.WriteData(_buffer); } // Terrain-Daten schreiben TerrainBlock.WriteData(_buffer); // RandomMap-Daten schreiben RandomMaps.WriteData(_buffer); // Anzahl schreiben _buffer.WriteInteger(Techages.Count); // Technologie-Effekte schreiben Techages.ForEach(e => e.WriteData(_buffer)); // Anzahl schreiben _buffer.WriteInteger(UnitHeaders.Count); // Einheiten-Header schreiben UnitHeaders.ForEach(e => e.WriteData(_buffer)); // Anzahl schreiben _buffer.WriteUShort((ushort)Civs.Count); // Kulturen schreiben Civs.ForEach(e => e.WriteData(_buffer)); // Anzahl schreiben _buffer.WriteUShort((ushort)Researches.Count); // Technologien schreiben Researches.ForEach(e => e.WriteData(_buffer)); // Unbekannte Technologiebaum-Daten schreiben IGenieDataElement.AssertListLength(TechTreeUnknown, 7); TechTreeUnknown.ForEach(e => _buffer.WriteInteger(e)); // Technologiebaum schreiben TechTree.WriteData(_buffer); if (_newTechTree) { // Marker und neuen TechTree schreiben _buffer.WriteString(NEW_TECH_TREE_MARKER); TechTreeNew.WriteData(_buffer); } // Fertig }