mirror of
https://gitlab.com/Syroot/Worms.git
synced 2025-01-27 22:27:58 +03:00
Fix several issues when saving new files.
- Fix writing raw bytes. - In case of saving into Stream instances, uniquely leave them open everywhere.
This commit is contained in:
parent
84ba8c56a0
commit
ed2785e339
@ -66,7 +66,9 @@ namespace Syroot.Worms.Armageddon.ProjectX
|
||||
// Read the header.
|
||||
if (reader.ReadInt32() != _signature)
|
||||
throw new InvalidDataException("Invalid PXL file signature.");
|
||||
Version = reader.Read1Byte();
|
||||
Version = reader.Read1Byte();
|
||||
if (Version != _version)
|
||||
throw new InvalidDataException("Invalid PXL file version.");
|
||||
|
||||
// Read the items.
|
||||
Clear();
|
||||
@ -106,7 +108,7 @@ namespace Syroot.Worms.Armageddon.ProjectX
|
||||
/// <param name="stream">The <see cref="Stream"/> to save the data to.</param>
|
||||
public void Save(Stream stream)
|
||||
{
|
||||
using BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII);
|
||||
using BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true);
|
||||
|
||||
// Write the header.
|
||||
writer.Write(_signature);
|
||||
@ -123,7 +125,7 @@ namespace Syroot.Worms.Armageddon.ProjectX
|
||||
case LibraryItemType.File:
|
||||
byte[] value = (byte[])item.Value;
|
||||
writer.Write(value.Length);
|
||||
writer.WriteStructs(value);
|
||||
writer.Write(value);
|
||||
break;
|
||||
case LibraryItemType.Script:
|
||||
writer.Write((string)item.Value, StringCoding.Int32CharCount);
|
||||
|
@ -129,7 +129,7 @@ namespace Syroot.Worms.Armageddon.ProjectX
|
||||
/// <param name="stream">The <see cref="Stream"/> to save the data to.</param>
|
||||
public void Save(Stream stream)
|
||||
{
|
||||
using BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII);
|
||||
using BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true);
|
||||
|
||||
// Write the header.
|
||||
writer.Write(_signature, StringCoding.Raw);
|
||||
@ -152,7 +152,7 @@ namespace Syroot.Worms.Armageddon.ProjectX
|
||||
{
|
||||
writer.Write(file.Key, StringCoding.Int32CharCount);
|
||||
writer.Write(file.Value.Length);
|
||||
writer.WriteStructs(file.Value);
|
||||
writer.Write(file.Value);
|
||||
}
|
||||
|
||||
// Write attached scripts.
|
||||
|
@ -284,7 +284,7 @@ namespace Syroot.Worms.Armageddon
|
||||
writer.Write(Kills);
|
||||
writer.Write(DeathmatchKills);
|
||||
writer.Write(Deaths);
|
||||
writer.Write(DeathmatchDeaths);
|
||||
writer.Write(DeathmatchDeaths);
|
||||
writer.WriteStructs(MissionStatuses);
|
||||
|
||||
writer.WriteString(FlagFileName, 0x20);
|
||||
|
@ -132,7 +132,7 @@ namespace Syroot.Worms.WorldParty
|
||||
/// <param name="stream">The <see cref="Stream"/> to save the data to.</param>
|
||||
public void Save(Stream stream)
|
||||
{
|
||||
using BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII);
|
||||
using BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true);
|
||||
|
||||
// Write the header.
|
||||
writer.Write(_signature);
|
||||
|
@ -269,7 +269,7 @@ namespace Syroot.Worms.WorldParty
|
||||
{
|
||||
writer.WriteString(GraveFileName, 0x20);
|
||||
writer.WriteStructs(Grave.Palette);
|
||||
writer.WriteStructs(Grave.Data);
|
||||
writer.Write(Grave.Data);
|
||||
}
|
||||
|
||||
writer.WriteEnum(TeamWeapon, true);
|
||||
@ -287,13 +287,13 @@ namespace Syroot.Worms.WorldParty
|
||||
|
||||
writer.WriteString(FlagFileName, 0x20);
|
||||
writer.WriteStructs(Flag.Palette);
|
||||
writer.WriteStructs(Flag.Data);
|
||||
writer.Write(Flag.Data);
|
||||
|
||||
writer.Write(Unknown1);
|
||||
writer.Write(DeathmatchRank);
|
||||
writer.Write(TrainingMissionTimes);
|
||||
writer.Write(UnknownTrainingMissionTime);
|
||||
writer.WriteStructs(WeaponPoints);
|
||||
writer.Write(WeaponPoints);
|
||||
writer.Write(Fort);
|
||||
writer.Write(Unknown2);
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ namespace Syroot.Worms.WorldParty
|
||||
/// <param name="stream">The <see cref="Stream"/> to save the data to.</param>
|
||||
public void Save(Stream stream)
|
||||
{
|
||||
using BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII);
|
||||
using BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true);
|
||||
|
||||
// Write the header.
|
||||
writer.Write(_signature, StringCoding.ZeroTerminated);
|
||||
@ -114,7 +114,7 @@ namespace Syroot.Worms.WorldParty
|
||||
writer.Write((byte)Teams.Count);
|
||||
writer.Write(Unknown1);
|
||||
writer.Write(Unknown2);
|
||||
writer.WriteStructs(Unknown3);
|
||||
writer.Write(Unknown3);
|
||||
|
||||
// Write the teams.
|
||||
foreach (Team team in Teams)
|
||||
|
@ -138,7 +138,7 @@ namespace Syroot.Worms.Worms2
|
||||
/// <param name="stream">The <see cref="Stream"/> to save the data to.</param>
|
||||
public void Save(Stream stream)
|
||||
{
|
||||
using BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII);
|
||||
using BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true);
|
||||
|
||||
// Write the header.
|
||||
writer.Write(_signature);
|
||||
|
@ -272,7 +272,7 @@ namespace Syroot.Worms.Worms2
|
||||
/// <param name="stream">The <see cref="Stream"/> to save the data to.</param>
|
||||
public void Save(Stream stream)
|
||||
{
|
||||
using BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII);
|
||||
using BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true);
|
||||
|
||||
// Write the header.
|
||||
writer.Write(_signature, StringCoding.Raw);
|
||||
|
@ -82,10 +82,10 @@ namespace Syroot.Worms.Worms2
|
||||
/// <param name="stream">The <see cref="Stream"/> to save the data to.</param>
|
||||
public void Save(Stream stream)
|
||||
{
|
||||
using BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII);
|
||||
using BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true);
|
||||
|
||||
// Write the header.
|
||||
writer.WriteStructs(new byte[_trashLength]);
|
||||
writer.Write(new byte[_trashLength]);
|
||||
writer.Write(_signature, StringCoding.ZeroTerminated);
|
||||
|
||||
// Write the weapon settings.
|
||||
|
@ -69,7 +69,7 @@ namespace Syroot.Worms.Worms2
|
||||
/// <param name="stream">The <see cref="Stream"/> to save the data to.</param>
|
||||
public void Save(Stream stream)
|
||||
{
|
||||
using BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII);
|
||||
using BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true);
|
||||
foreach (Team team in Teams)
|
||||
team.Save(writer.BaseStream);
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ namespace Syroot.Worms
|
||||
/// <param name="stream">The <see cref="Stream"/> to save the data in.</param>
|
||||
public void Save(Stream stream)
|
||||
{
|
||||
using BinaryStream writer = new BinaryStream(stream);
|
||||
using BinaryStream writer = new BinaryStream(stream, leaveOpen: true);
|
||||
|
||||
// Write the header.
|
||||
writer.Write(_signature);
|
||||
@ -123,7 +123,7 @@ namespace Syroot.Worms
|
||||
Offset = (int)writer.Position,
|
||||
Length = item.Value.Length
|
||||
};
|
||||
writer.WriteStructs(item.Value);
|
||||
writer.Write(item.Value);
|
||||
|
||||
int hash = CalculateHash(item.Key);
|
||||
if (hashTable[hash] == null)
|
||||
|
@ -67,7 +67,7 @@ namespace Syroot.Worms.Core.Riff
|
||||
/// <param name="stream">The <see cref="Stream"/> to save the RIFF data in.</param>
|
||||
protected void SaveRiff(Stream stream)
|
||||
{
|
||||
using BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII);
|
||||
using BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true);
|
||||
|
||||
// Write the header.
|
||||
writer.Write(_signature, StringCoding.Raw);
|
||||
|
@ -180,7 +180,7 @@ namespace Syroot.Worms
|
||||
/// <param name="alignData"><c>true</c> to align the data array by 4 bytes.</param>
|
||||
public void Save(Stream stream, bool compress, bool alignData)
|
||||
{
|
||||
using BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII);
|
||||
using BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true);
|
||||
|
||||
// Write the header.
|
||||
writer.Write(_signature);
|
||||
@ -222,7 +222,7 @@ namespace Syroot.Worms
|
||||
byte[] data = Data;
|
||||
if (compress)
|
||||
data = Team17Compression.Compress(data);
|
||||
writer.WriteStructs(data);
|
||||
writer.Write(data);
|
||||
|
||||
writer.SatisfyOffset(fileSizeOffset, (int)writer.Position);
|
||||
}
|
||||
|
@ -101,8 +101,9 @@ namespace Syroot.Worms
|
||||
|
||||
// ---- METHODS (PRIVATE) --------------------------------------------------------------------------------------
|
||||
|
||||
[RiffChunkLoad("data")]
|
||||
private void LoadDataChunk(BinaryStream reader, int length)
|
||||
#pragma warning disable IDE0051 // Remove unused private members
|
||||
[RiffChunkLoad("data")]
|
||||
private void LoadDataChunk(BinaryStream reader, int length)
|
||||
{
|
||||
// Read the PAL version.
|
||||
Version = reader.ReadInt16();
|
||||
@ -146,12 +147,13 @@ namespace Syroot.Worms
|
||||
}
|
||||
|
||||
[RiffChunkSave("offl")]
|
||||
private void SaveOfflChunk(BinaryStream writer) => writer.WriteStructs(OfflData);
|
||||
private void SaveOfflChunk(BinaryStream writer) => writer.Write(OfflData);
|
||||
|
||||
[RiffChunkSave("tran")]
|
||||
private void SaveTranChunk(BinaryStream writer) => writer.WriteStructs(TranData);
|
||||
private void SaveTranChunk(BinaryStream writer) => writer.Write(TranData);
|
||||
|
||||
[RiffChunkSave("unde")]
|
||||
private void SaveUndeChunk(BinaryStream writer) => writer.WriteStructs(UndeData);
|
||||
private void SaveUndeChunk(BinaryStream writer) => writer.Write(UndeData);
|
||||
#pragma warning restore IDE0051
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user