Review code, update code standards and NuGet packages.

This commit is contained in:
Ray Koopa 2019-09-27 20:13:24 +02:00
parent c5391c3d66
commit e57c593efa
62 changed files with 1765 additions and 2221 deletions

View File

@ -11,31 +11,20 @@ namespace Syroot.Worms.Armageddon.ProjectX
public object Read(Stream stream, object instance, BinaryMemberAttribute memberAttribute,
ByteConverter byteConverter)
{
ExplosionAction explosionAction;
switch (instance)
ExplosionAction explosionAction = instance switch
{
case LauncherStyle launcherStyle:
explosionAction = launcherStyle.ExplosionAction;
break;
case ClusterTarget clusterTarget:
explosionAction = clusterTarget.ExplosionAction;
break;
default:
throw new NotImplementedException();
}
switch (explosionAction)
LauncherStyle launcherStyle => launcherStyle.ExplosionAction,
ClusterTarget clusterTarget => clusterTarget.ExplosionAction,
_ => throw new NotImplementedException(),
};
return explosionAction switch
{
case ExplosionAction.Bounce:
return stream.ReadObject<BounceAction>();
case ExplosionAction.Dig:
return stream.ReadObject<DigAction>();
case ExplosionAction.Home:
return stream.ReadObject<HomeAction>();
case ExplosionAction.Roam:
return stream.ReadObject<RoamAction>();
}
return null;
ExplosionAction.Bounce => stream.ReadObject<BounceAction>(),
ExplosionAction.Dig => stream.ReadObject<DigAction>(),
ExplosionAction.Home => stream.ReadObject<HomeAction>(),
ExplosionAction.Roam => stream.ReadObject<RoamAction>(),
_ => null,
};
}
public void Write(Stream stream, object instance, BinaryMemberAttribute memberAttribute, object value,

View File

@ -1,6 +1,4 @@
namespace Syroot.Worms.Armageddon.ProjectX
{
public interface IAction
{
}
public interface IAction { }
}

View File

@ -25,28 +25,20 @@ namespace Syroot.Worms.Armageddon.ProjectX
/// <summary>
/// Initializes a new instance of the <see cref="Scheme"/> class.
/// </summary>
public Library()
{
}
public Library() { }
/// <summary>
/// Initializes a new instance of the <see cref="Scheme"/> class, loading the data from the given
/// <see cref="Stream"/>.
/// </summary>
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
public Library(Stream stream)
{
Load(stream);
}
public Library(Stream stream) => Load(stream);
/// <summary>
/// Initializes a new instance of the <see cref="Scheme"/> class, loading the data from the given file.
/// </summary>
/// <param name="fileName">The name of the file to load the data from.</param>
public Library(string fileName)
{
Load(fileName);
}
public Library(string fileName) => Load(fileName);
// ---- PROPERTIES ---------------------------------------------------------------------------------------------
@ -59,13 +51,7 @@ namespace Syroot.Worms.Armageddon.ProjectX
/// </summary>
/// <param name="key">The key of the entries to match.</param>
/// <returns>All matching entries.</returns>
public IEnumerable<LibraryItem> this[string key]
{
get
{
return this.Where(x => x.Key == key);
}
}
public IEnumerable<LibraryItem> this[string key] => this.Where(x => x.Key == key);
// ---- METHODS (PUBLIC) ---------------------------------------------------------------------------------------
@ -75,13 +61,11 @@ namespace Syroot.Worms.Armageddon.ProjectX
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
public void Load(Stream stream)
{
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
{
using BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true);
// Read the header.
if (reader.ReadInt32() != _signature)
{
throw new InvalidDataException("Invalid PXL file signature.");
}
Version = reader.Read1Byte();
// Read the items.
@ -105,7 +89,6 @@ namespace Syroot.Worms.Armageddon.ProjectX
}
}
}
}
/// <summary>
/// Loads the data from the given file.
@ -113,11 +96,9 @@ namespace Syroot.Worms.Armageddon.ProjectX
/// <param name="fileName">The name of the file to load the data from.</param>
public void Load(string fileName)
{
using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
using FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
Load(stream);
}
}
/// <summary>
/// Saves the data into the given <paramref name="stream"/>.
@ -125,8 +106,8 @@ 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);
// Write the header.
writer.Write(_signature);
writer.Write(Version);
@ -153,7 +134,6 @@ namespace Syroot.Worms.Armageddon.ProjectX
}
}
}
}
/// <summary>
/// Saves the data in the given file.
@ -161,38 +141,30 @@ namespace Syroot.Worms.Armageddon.ProjectX
/// <param name="fileName">The name of the file to save the data in.</param>
public void Save(string fileName)
{
using (FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
{
using FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None);
Save(stream);
}
}
/// <summary>
/// Gets all attached files.
/// </summary>
/// <returns>The enumeration of attached files.</returns>
public IEnumerable<byte[]> GetFiles()
{
return this.Where(x => x.Type == LibraryItemType.File).Select(x => (byte[])x.Value);
}
=> this.Where(x => x.Type == LibraryItemType.File).Select(x => (byte[])x.Value);
/// <summary>
/// Gets all attached scripts.
/// </summary>
/// <returns>The enumeration of attached scripts.</returns>
public IEnumerable<string> GetScripts()
{
return this.Where(x => x.Type == LibraryItemType.Script).Select(x => (string)x.Value);
}
=> this.Where(x => x.Type == LibraryItemType.Script).Select(x => (string)x.Value);
/// <summary>
/// Gets all attached weapons.
/// </summary>
/// <returns>The enumeration of attached weapons.</returns>
public IEnumerable<Weapon> GetWeapons()
{
return this.Where(x => x.Type == LibraryItemType.Weapon).Select(x => (Weapon)x.Value);
}
=> this.Where(x => x.Type == LibraryItemType.Weapon).Select(x => (Weapon)x.Value);
}
/// <summary>
@ -236,29 +208,18 @@ namespace Syroot.Worms.Armageddon.ProjectX
/// </summary>
public object Value
{
get
{
return _value;
}
get => _value;
set
{
// Validate the type.
if (value.GetType() == typeof(byte[]))
{
Type = LibraryItemType.File;
}
else if (value.GetType() == typeof(string))
{
Type = LibraryItemType.Script;
}
else if (value.GetType() == typeof(Weapon))
{
Type = LibraryItemType.Weapon;
}
else
{
throw new ArgumentException("Invalid LibraryItemType.", nameof(value));
}
_value = value;
}
}

View File

@ -23,28 +23,20 @@ namespace Syroot.Worms.Armageddon.ProjectX
/// <summary>
/// Initializes a new instance of the <see cref="Scheme"/> class.
/// </summary>
public Scheme()
{
}
public Scheme() { }
/// <summary>
/// Initializes a new instance of the <see cref="Scheme"/> class, loading the data from the given
/// <see cref="Stream"/>.
/// </summary>
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
public Scheme(Stream stream)
{
Load(stream);
}
public Scheme(Stream stream) => Load(stream);
/// <summary>
/// Initializes a new instance of the <see cref="Scheme"/> class, loading the data from the given file.
/// </summary>
/// <param name="fileName">The name of the file to load the data from.</param>
public Scheme(string fileName)
{
Load(fileName);
}
public Scheme(string fileName) => Load(fileName);
// ---- PROPERTIES ---------------------------------------------------------------------------------------------
@ -72,13 +64,11 @@ namespace Syroot.Worms.Armageddon.ProjectX
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
public void Load(Stream stream)
{
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
{
using BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true);
// Read the header.
if (reader.ReadString(_signature.Length) != _signature)
{
throw new InvalidDataException("Invalid PXS file signature.");
}
Version = reader.ReadInt32();
// Read the scheme flags.
@ -88,9 +78,7 @@ namespace Syroot.Worms.Armageddon.ProjectX
int weaponTableCount = reader.ReadInt32();
WeaponTables = new List<Weapon[]>(weaponTableCount);
for (int i = 0; i < weaponTableCount; i++)
{
WeaponTables.Add(reader.Load<Weapon>(_weaponsPerTable));
}
// Read a placeholder array.
reader.Seek(sizeof(int));
@ -109,10 +97,8 @@ namespace Syroot.Worms.Armageddon.ProjectX
int scriptsCount = reader.ReadInt32();
Scripts = new Dictionary<string, string>(scriptsCount);
for (int i = 0; i < scriptsCount; i++)
{
Scripts.Add(reader.ReadString(StringCoding.Int32CharCount),
reader.ReadString(StringCoding.Int32CharCount));
}
// Read required libraries.
int librariesCount = reader.ReadInt32();
@ -126,7 +112,6 @@ namespace Syroot.Worms.Armageddon.ProjectX
GameSchemeName = reader.ReadString(StringCoding.Int32CharCount);
}
}
}
/// <summary>
/// Loads the data from the given file.
@ -134,11 +119,9 @@ namespace Syroot.Worms.Armageddon.ProjectX
/// <param name="fileName">The name of the file to load the data from.</param>
public void Load(string fileName)
{
using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
using FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
Load(stream);
}
}
/// <summary>
/// Saves the data into the given <paramref name="stream"/>.
@ -146,8 +129,8 @@ 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);
// Write the header.
writer.Write(_signature, StringCoding.Raw);
writer.Write(Version);
@ -158,9 +141,7 @@ namespace Syroot.Worms.Armageddon.ProjectX
// Write the weapon tables.
writer.Write(WeaponTables.Count);
foreach (Weapon[] weaponTable in WeaponTables)
{
writer.Save(weaponTable);
}
// Write a placeholder array.
writer.Write(0);
@ -199,7 +180,6 @@ namespace Syroot.Worms.Armageddon.ProjectX
writer.Write(GameSchemeName, StringCoding.Int32CharCount);
}
}
}
/// <summary>
/// Saves the data in the given file.
@ -207,10 +187,8 @@ namespace Syroot.Worms.Armageddon.ProjectX
/// <param name="fileName">The name of the file to save the data in.</param>
public void Save(string fileName)
{
using (FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
{
using FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None);
Save(stream);
}
}
}
}

View File

@ -11,24 +11,17 @@ namespace Syroot.Worms.Armageddon.ProjectX
public object Read(Stream stream, object instance, BinaryMemberAttribute memberAttribute,
ByteConverter byteConverter)
{
WeaponAirstrikeSubstyle airstrikeSubstyle;
switch (instance)
WeaponAirstrikeSubstyle airstrikeSubstyle = instance switch
{
case AirstrikeStyle airstrikeStyle:
airstrikeSubstyle = airstrikeStyle.AirstrikeSubstyle;
break;
default:
throw new NotImplementedException();
}
switch (airstrikeSubstyle)
AirstrikeStyle airstrikeStyle => airstrikeStyle.AirstrikeSubstyle,
_ => throw new NotImplementedException(),
};
return airstrikeSubstyle switch
{
case WeaponAirstrikeSubstyle.Launcher:
return stream.ReadObject<LauncherStyle>();
case WeaponAirstrikeSubstyle.Mines:
return stream.ReadObject<MineStyle>();
}
return null;
WeaponAirstrikeSubstyle.Launcher => stream.ReadObject<LauncherStyle>(),
WeaponAirstrikeSubstyle.Mines => stream.ReadObject<MineStyle>(),
_ => null,
};
}
public void Write(Stream stream, object instance, BinaryMemberAttribute memberAttribute, object value,

View File

@ -1,6 +1,4 @@
namespace Syroot.Worms.Armageddon.ProjectX
{
public interface IStyle
{
}
public interface IStyle { }
}

View File

@ -14,7 +14,7 @@
<PackageTags>worms;team17</PackageTags>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://gitlab.com/Syroot/Worms</RepositoryUrl>
<TargetFrameworks>net461;netstandard2.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<Version>2.0.0-alpha1</Version>
</PropertyGroup>
<ItemGroup>

View File

@ -1,6 +1,4 @@
namespace Syroot.Worms.Armageddon.ProjectX
{
public interface ITarget
{
}
public interface ITarget { }
}

View File

@ -11,24 +11,17 @@ namespace Syroot.Worms.Armageddon.ProjectX
public object Read(Stream stream, object instance, BinaryMemberAttribute memberAttribute,
ByteConverter byteConverter)
{
ExplosionTarget explosionTarget;
switch (instance)
ExplosionTarget explosionTarget = instance switch
{
case LauncherStyle launcherStyle:
explosionTarget = launcherStyle.ExplosionTarget;
break;
default:
throw new NotImplementedException();
}
switch (explosionTarget)
LauncherStyle launcherStyle => launcherStyle.ExplosionTarget,
_ => throw new NotImplementedException(),
};
return explosionTarget switch
{
case ExplosionTarget.Clusters:
return stream.ReadObject<ClusterTarget>();
case ExplosionTarget.Fire:
return stream.ReadObject<FireTarget>();
}
return null;
ExplosionTarget.Clusters => stream.ReadObject<ClusterTarget>(),
ExplosionTarget.Fire => stream.ReadObject<FireTarget>(),
_ => null,
};
}
public void Write(Stream stream, object instance, BinaryMemberAttribute memberAttribute, object value,

View File

@ -2,7 +2,6 @@ using System.Diagnostics;
using System.IO;
using System.Text;
using Syroot.BinaryData;
using Syroot.Worms.Core;
using Syroot.Worms.Core.IO;
namespace Syroot.Worms.Armageddon.ProjectX
@ -114,8 +113,8 @@ namespace Syroot.Worms.Armageddon.ProjectX
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
public void Load(Stream stream)
{
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
{
using BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true);
// Read the header.
long offset = reader.Position;
Version = reader.ReadEnum<WeaponVersion>(true);
@ -272,11 +271,8 @@ namespace Syroot.Worms.Armageddon.ProjectX
PickSpriteOverride = reader.ReadBoolean();
FireSpriteOverride = reader.ReadBoolean();
if (Version == WeaponVersion.Version_0_8_0)
{
Utility = reader.ReadBoolean();
}
}
}
/// <summary>
/// Saves the data into the given <paramref name="stream"/>.
@ -284,8 +280,8 @@ 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, leaveOpen: true))
{
using BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true);
// Write the header.
long offset = writer.Position;
writer.WriteEnum(Version, true);
@ -315,9 +311,7 @@ namespace Syroot.Worms.Armageddon.ProjectX
writer.Write(NotUsed);
writer.WriteEnum(CrosshairAction, true);
if (CrosshairAction != WeaponCrosshairAction.None)
{
writer.WriteObject(Style);
}
break;
case WeaponActivation.Spacebar:
writer.WriteEnum(SpacebarAction, true);
@ -345,9 +339,7 @@ namespace Syroot.Worms.Armageddon.ProjectX
writer.Write(ThrowHerdCount);
writer.WriteEnum(ThrowAction, true);
if (ThrowAction != WeaponThrowAction.None)
{
writer.WriteObject(Style);
}
break;
}
@ -385,12 +377,9 @@ namespace Syroot.Worms.Armageddon.ProjectX
writer.Write(PickSpriteOverride);
writer.Write(FireSpriteOverride);
if (Version == WeaponVersion.Version_0_8_0)
{
writer.Write(Utility);
}
}
}
}
public enum WeaponVersion : int
{

View File

@ -16,28 +16,20 @@ namespace Syroot.Worms.Armageddon
/// <summary>
/// Initializes a new instance of the <see cref="GeneratedMap"/> class.
/// </summary>
public GeneratedMap()
{
}
public GeneratedMap() { }
/// <summary>
/// Initializes a new instance of the <see cref="GeneratedMap"/> class, loading the data from the given
/// <see cref="Stream"/>.
/// </summary>
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
public GeneratedMap(Stream stream)
{
Load(stream);
}
public GeneratedMap(Stream stream) => Load(stream);
/// <summary>
/// Initializes a new instance of the <see cref="GeneratedMap"/> class, loading the data from the given file.
/// </summary>
/// <param name="fileName">The name of the file to load the data from.</param>
public GeneratedMap(string fileName)
{
Load(fileName);
}
public GeneratedMap(string fileName) => Load(fileName);
// ---- PROPERTIES ---------------------------------------------------------------------------------------------
@ -54,11 +46,9 @@ namespace Syroot.Worms.Armageddon
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
public void Load(Stream stream)
{
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
{
using BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true);
Settings = reader.ReadStruct<MapGeneratorSettings>();
}
}
/// <summary>
/// Loads the data from the given file.
@ -66,11 +56,9 @@ namespace Syroot.Worms.Armageddon
/// <param name="fileName">The name of the file to load the data from.</param>
public void Load(string fileName)
{
using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
using FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
Load(stream);
}
}
/// <summary>
/// Saves the data into the given <paramref name="stream"/>.
@ -78,11 +66,9 @@ namespace Syroot.Worms.Armageddon
/// <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);
writer.WriteStruct(Settings);
}
}
/// <summary>
/// Saves the data in the given file.
@ -90,10 +76,8 @@ namespace Syroot.Worms.Armageddon
/// <param name="fileName">The name of the file to save the data in.</param>
public void Save(string fileName)
{
using (FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
{
using FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None);
Save(stream);
}
}
}
}

View File

@ -28,19 +28,13 @@ namespace Syroot.Worms.Armageddon
/// <see cref="Stream"/>.
/// </summary>
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
public LandData(Stream stream)
{
Load(stream);
}
public LandData(Stream stream) => Load(stream);
/// <summary>
/// Initializes a new instance of the <see cref="LandData"/> class, loading the data from the given file.
/// </summary>
/// <param name="fileName">The name of the file to load the data from.</param>
public LandData(string fileName)
{
Load(fileName);
}
public LandData(string fileName) => Load(fileName);
// ---- PROPERTIES ---------------------------------------------------------------------------------------------
@ -102,8 +96,8 @@ namespace Syroot.Worms.Armageddon
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
public void Load(Stream stream)
{
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
{
using BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true);
// Read the header.
if (reader.ReadInt32() != _signature)
throw new InvalidDataException("Invalid LND file signature.");
@ -127,7 +121,6 @@ namespace Syroot.Worms.Armageddon
LandTexturePath = reader.ReadString(StringCoding.ByteCharCount);
WaterDirPath = reader.ReadString(StringCoding.ByteCharCount);
}
}
/// <summary>
/// Loads the data from the given file.
@ -135,7 +128,7 @@ namespace Syroot.Worms.Armageddon
/// <param name="fileName">The name of the file to load the data from.</param>
public void Load(string fileName)
{
using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
using FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
Load(stream);
}
@ -145,8 +138,8 @@ namespace Syroot.Worms.Armageddon
/// <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);
// Write the header.
writer.Write(_signature);
uint fileSizeOffset = writer.ReserveOffset();
@ -172,7 +165,6 @@ namespace Syroot.Worms.Armageddon
writer.SatisfyOffset(fileSizeOffset, (int)writer.Position);
}
}
/// <summary>
/// Saves the data in the given file.
@ -180,7 +172,7 @@ namespace Syroot.Worms.Armageddon
/// <param name="fileName">The name of the file to save the data in.</param>
public void Save(string fileName)
{
using (FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
using FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None);
Save(stream);
}
}

View File

@ -99,19 +99,13 @@ namespace Syroot.Worms.Armageddon
/// <see cref="Stream"/>.
/// </summary>
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
public Scheme(Stream stream)
{
Load(stream);
}
public Scheme(Stream stream) => Load(stream);
/// <summary>
/// Initializes a new instance of the <see cref="Scheme"/> class, loading the data from the given file.
/// </summary>
/// <param name="fileName">The name of the file to load the data from.</param>
public Scheme(string fileName)
{
Load(fileName);
}
public Scheme(string fileName) => Load(fileName);
// ---- PROPERTIES ---------------------------------------------------------------------------------------------
@ -229,16 +223,11 @@ namespace Syroot.Worms.Armageddon
/// </summary>
public byte MineDelay
{
get
{
return _mineDelay;
}
get => _mineDelay;
set
{
if (value == 4 || value > 0x7F)
{
throw new ArgumentException("Mine delay must be between 0-127 and not be 4.", nameof(value));
}
_mineDelay = value;
}
}
@ -270,16 +259,11 @@ namespace Syroot.Worms.Armageddon
/// </summary>
public byte TurnTime
{
get
{
return _turnTime;
}
get => _turnTime;
set
{
if (value > 0x7F)
{
throw new ArgumentException("Turn time must be between 0-127.", nameof(value));
}
_turnTime = value;
}
}
@ -295,16 +279,11 @@ namespace Syroot.Worms.Armageddon
/// </summary>
public byte RoundTimeMinutes
{
get
{
return _roundTimeMinutes;
}
get => _roundTimeMinutes;
set
{
if (value > 0x7F)
{
throw new ArgumentException("Round time must be between 0-127 minutes.", nameof(value));
}
_roundTimeMinutes = value;
}
}
@ -315,16 +294,11 @@ namespace Syroot.Worms.Armageddon
/// </summary>
public byte RoundTimeSeconds
{
get
{
return _roundTimeSeconds;
}
get => _roundTimeSeconds;
set
{
if (value > 0x80)
{
throw new ArgumentException("Round time must be between 0-128 seconds.", nameof(value));
}
_roundTimeSeconds = value;
}
}
@ -334,16 +308,11 @@ namespace Syroot.Worms.Armageddon
/// </summary>
public byte NumberOfWins
{
get
{
return _numberOfWins;
}
get => _numberOfWins;
set
{
if (value == 0)
{
throw new ArgumentException("Number of wins must not be 0.", nameof(value));
}
_numberOfWins = value;
}
}
@ -486,10 +455,7 @@ namespace Syroot.Worms.Armageddon
/// </summary>
public sbyte RwGravity
{
get
{
return _rwGravity;
}
get => _rwGravity;
set
{
if (value != 0)
@ -507,10 +473,7 @@ namespace Syroot.Worms.Armageddon
/// </summary>
public sbyte RwGravityConstBlackHole
{
get
{
return _rwGravityConstBlackHole;
}
get => _rwGravityConstBlackHole;
set
{
if (value != 0)
@ -529,10 +492,7 @@ namespace Syroot.Worms.Armageddon
/// </summary>
public sbyte RwGravityPropBlackHole
{
get
{
return _rwGravityPropBlackHole;
}
get => _rwGravityPropBlackHole;
set
{
if (value != 0)
@ -550,16 +510,11 @@ namespace Syroot.Worms.Armageddon
/// </summary>
public byte RwKaosMod
{
get
{
return _rwKaosMod;
}
get => _rwKaosMod;
set
{
if (value > 0xF)
{
throw new ArgumentException("Kaos mod must not be greater than 15.");
}
_rwKaosMod = value;
}
}
@ -650,13 +605,11 @@ namespace Syroot.Worms.Armageddon
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
public void Load(Stream stream)
{
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
{
using BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true);
// Read the header.
if (reader.ReadString(_signature.Length) != _signature)
{
throw new InvalidDataException("Invalid WSC file signature.");
}
Version = reader.ReadEnum<SchemeVersion>(true);
// Read the options.
@ -701,16 +654,13 @@ namespace Syroot.Worms.Armageddon
Weapons = new SchemeWeaponSetting[64];
int weaponCount = GetWeaponCount();
for (int i = 0; i < weaponCount; i++)
{
Weapons[i] = reader.ReadStruct<SchemeWeaponSetting>();
}
// Ignore possible unknown WWP trash at the end of the file.
// Parse the RubberWorm settings.
LoadRubberWormSettings();
}
}
/// <summary>
/// Loads the data from the given file.
@ -718,20 +668,15 @@ namespace Syroot.Worms.Armageddon
/// <param name="fileName">The name of the file to load the data from.</param>
public void Load(string fileName)
{
using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
using FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
Load(stream);
}
}
/// <summary>
/// Saves the data into the given <paramref name="stream"/>.
/// </summary>
/// <param name="stream">The <see cref="Stream"/> to save the data to.</param>
public void Save(Stream stream)
{
Save(stream, SchemeSaveFormat.ExtendedWithObjectCount);
}
public void Save(Stream stream) => Save(stream, SchemeSaveFormat.ExtendedWithObjectCount);
/// <summary>
/// Saves the data into the given <paramref name="stream"/> with the specified <paramref name="format"/>.
@ -740,8 +685,8 @@ namespace Syroot.Worms.Armageddon
/// <param name="format">The <see cref="SchemeSaveFormat"/> to respect when storing the settings.</param>
public void Save(Stream stream, SchemeSaveFormat format)
{
using (BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII))
{
using BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII);
// Write the header.
writer.Write(_signature, StringCoding.Raw);
writer.Write((byte)Version);
@ -790,22 +735,14 @@ namespace Syroot.Worms.Armageddon
// Write the weapon settings. Old versions do not store super weapon settings.
int weaponCount = GetWeaponCount();
foreach (SchemeWeaponSetting weapon in Weapons)
{
writer.WriteStruct(weapon);
}
// Ignore possible unknown WWP trash at the end of the file.
}
}
/// <summary>
/// Saves the data in the given file.
/// </summary>
/// <param name="fileName">The name of the file to save the data in.</param>
public void Save(string fileName)
{
Save(fileName, SchemeSaveFormat.ExtendedWithObjectCount);
}
public void Save(string fileName) => Save(fileName, SchemeSaveFormat.ExtendedWithObjectCount);
/// <summary>
/// Saves the data in the given file with the specified <paramref name="format"/>.
@ -814,11 +751,9 @@ namespace Syroot.Worms.Armageddon
/// <param name="format">The <see cref="SchemeSaveFormat"/> to respect when storing the settings.</param>
public void Save(string fileName, SchemeSaveFormat format)
{
using (FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
{
using FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None);
Save(stream, format);
}
}
// ---- METHODS (PRIVATE) --------------------------------------------------------------------------------------
@ -942,14 +877,10 @@ namespace Syroot.Worms.Armageddon
if (mailStrikeProb.GetBit(7))
{
if (mailStrikeProb.GetBit(6))
{
RwGravityPropBlackHole = mailStrikeProb.DecodeSByte(6);
}
else
{
RwGravityConstBlackHole = mailStrikeProb.DecodeSByte(6);
}
}
else
{
RwGravity = mailStrikeProb.DecodeSByte(7);
@ -1019,38 +950,26 @@ namespace Syroot.Worms.Armageddon
private void SaveMineDelayConfig(BinaryStream writer)
{
if (MineDelayRandom)
{
writer.Write((byte)4);
}
else
{
writer.Write(MineDelay);
}
}
private void SaveTurnTimeConfig(BinaryStream writer)
{
if (TurnTimeInfinite)
{
writer.Write((byte)0xFF);
}
else
{
writer.Write(TurnTime);
}
}
private void SaveRoundTimeConfig(BinaryStream writer)
{
if (RoundTimeSeconds > 0)
{
writer.Write((byte)(0xFF - (RoundTimeSeconds - 1)));
}
else
{
writer.Write(RoundTimeMinutes);
}
}
private void SaveRubberWormSettings()
{

View File

@ -14,7 +14,7 @@
<PackageTags>worms;team17</PackageTags>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://gitlab.com/Syroot/Worms</RepositoryUrl>
<TargetFrameworks>net461;netstandard2.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<Version>2.0.0-alpha1</Version>
</PropertyGroup>
<ItemGroup>

View File

@ -196,8 +196,8 @@ namespace Syroot.Worms.Armageddon
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
public void Load(Stream stream)
{
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
{
using BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true);
Name = reader.ReadString(17);
WormNames = reader.ReadStrings(8, 17);
CpuLevel = reader.Read1Byte();
@ -249,7 +249,6 @@ namespace Syroot.Worms.Armageddon
Unknown3 = reader.ReadInt32s(7);
Unknown4 = reader.Read1Byte();
}
}
/// <summary>
/// Saves the data into the given <paramref name="stream"/>.
@ -257,8 +256,8 @@ namespace Syroot.Worms.Armageddon
/// <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, leaveOpen: true))
{
using BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true);
writer.WriteString(Name, 17);
writer.WriteStrings(WormNames, 17);
writer.Write(CpuLevel);
@ -301,7 +300,6 @@ namespace Syroot.Worms.Armageddon
writer.Write(Unknown4);
}
}
}
/// <summary>
/// Represents a team's progress in a mission.

View File

@ -22,29 +22,20 @@ namespace Syroot.Worms.Armageddon
/// <summary>
/// Initializes a new instance of the <see cref="TeamContainer"/> class.
/// </summary>
public TeamContainer()
{
Teams = new List<Team>();
}
public TeamContainer() => Teams = new List<Team>();
/// <summary>
/// Initializes a new instance of the <see cref="TeamContainer"/> class, loading the data from the given
/// <see cref="Stream"/>.
/// </summary>
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
public TeamContainer(Stream stream)
{
Load(stream);
}
public TeamContainer(Stream stream) => Load(stream);
/// <summary>
/// Initializes a new instance of the <see cref="TeamContainer"/> class, loading the data from the given file.
/// </summary>
/// <param name="fileName">The name of the file to load the data from.</param>
public TeamContainer(string fileName)
{
Load(fileName);
}
public TeamContainer(string fileName) => Load(fileName);
// ---- PROPERTIES ---------------------------------------------------------------------------------------------
@ -76,13 +67,11 @@ namespace Syroot.Worms.Armageddon
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
public void Load(Stream stream)
{
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
{
using BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true);
// Read the header.
if (reader.ReadString(StringCoding.ZeroTerminated) != _signature)
{
throw new InvalidDataException("Invalid WGT file signature.");
}
Version = reader.Read1Byte(); // Really version?
// Read global settings.
@ -93,7 +82,6 @@ namespace Syroot.Worms.Armageddon
// Read the teams.
Teams = new List<Team>(reader.Load<Team>(teamCount));
}
}
/// <summary>
/// Loads the data from the given file.
@ -101,11 +89,9 @@ namespace Syroot.Worms.Armageddon
/// <param name="fileName">The name of the file to load the data from.</param>
public void Load(string fileName)
{
using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
using FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
Load(stream);
}
}
/// <summary>
/// Saves the data into the given <paramref name="stream"/>.
@ -113,8 +99,8 @@ namespace Syroot.Worms.Armageddon
/// <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);
// Write the header.
writer.Write(_signature, StringCoding.ZeroTerminated);
writer.Write(Version);
@ -126,11 +112,8 @@ namespace Syroot.Worms.Armageddon
// Write the teams.
foreach (Team team in Teams)
{
team.Save(writer.BaseStream);
}
}
}
/// <summary>
/// Saves the data in the given file.
@ -138,12 +121,10 @@ namespace Syroot.Worms.Armageddon
/// <param name="fileName">The name of the file to save the data in.</param>
public void Save(string fileName)
{
using (FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
{
using FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None);
Save(stream);
}
}
}
/// <summary>
/// Represents unlockable features of the game.

View File

@ -3,13 +3,14 @@ using System.Drawing;
using System.IO;
using Syroot.BinaryData;
using Syroot.Worms.Core;
using Syroot.Worms.Core.IO;
namespace Syroot.Worms.Mgame
{
/// <summary>
/// Represents an IGD image container.
/// </summary>
public class Igd
public class Igd : ILoadableFile
{
// ---- CONSTRUCTORS & DESTRUCTOR ------------------------------------------------------------------------------
@ -18,20 +19,14 @@ namespace Syroot.Worms.Mgame
/// <paramref name="fileName"/>.
/// </summary>
/// <param name="fileName">The name of the file to load the data from.</param>
public Igd(string fileName)
{
Load(fileName);
}
public Igd(string fileName) => Load(fileName);
/// <summary>
/// Initializes a new instance of the <see cref="Igd"/> class, loading data from the given
/// <paramref name="stream"/>.
/// </summary>
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
public Igd(Stream stream)
{
Load(stream);
}
public Igd(Stream stream) => Load(stream);
// ---- PROPERTIES ---------------------------------------------------------------------------------------------
@ -50,7 +45,7 @@ namespace Syroot.Worms.Mgame
/// <param name="fileName">The name of the file to load the data from.</param>
public void Load(string fileName)
{
using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
using FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
Load(stream);
}

View File

@ -23,10 +23,7 @@ namespace Syroot.Worms.Mgame
/// </summary>
/// <param name="fileName">The name of the file to load the data from.</param>
/// <param name="palette">The color palette which is indexed by the image data.</param>
public Ksf(string fileName, Palette palette)
{
Load(fileName, palette);
}
public Ksf(string fileName, Palette palette) => Load(fileName, palette);
/// <summary>
/// Initializes a new instance of the <see cref="Ksf"/> class, loading data from the given
@ -34,10 +31,7 @@ namespace Syroot.Worms.Mgame
/// </summary>
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
/// <param name="palette">The color palette which is indexed by the image data.</param>
public Ksf(Stream stream, Palette palette)
{
Load(stream, palette);
}
public Ksf(Stream stream, Palette palette) => Load(stream, palette);
// ---- PROPERTIES ---------------------------------------------------------------------------------------------
@ -56,7 +50,7 @@ namespace Syroot.Worms.Mgame
/// <param name="palette">The color palette which is indexed by the image data.</param>
public void Load(string fileName, Palette palette)
{
using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
using FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
Load(stream, palette);
}
@ -69,7 +63,7 @@ namespace Syroot.Worms.Mgame
public void Load(Stream stream, Palette palette)
{
int imageCount = stream.ReadInt32(); // Includes terminator.
int dataSize = stream.ReadInt32();
_ = stream.ReadInt32(); // data size
// Read image headers. Terminating image is of 0 size and data offset at end of data block.
KsfImage[] images = new KsfImage[imageCount];

View File

@ -2,13 +2,14 @@
using System.Drawing;
using System.IO;
using Syroot.BinaryData;
using Syroot.Worms.Core.IO;
namespace Syroot.Worms.Mgame
{
/// <summary>
/// Represents an LPD layout description file used in Worms World Party Aqua.
/// </summary>
public class Lpd
public class Lpd : ILoadableFile
{
// ---- CONSTRUCTORS & DESTRUCTOR ------------------------------------------------------------------------------
@ -17,20 +18,14 @@ namespace Syroot.Worms.Mgame
/// <paramref name="fileName"/>.
/// </summary>
/// <param name="fileName">The name of the file to load the data from.</param>
public Lpd(string fileName)
{
Load(fileName);
}
public Lpd(string fileName) => Load(fileName);
/// <summary>
/// Initializes a new instance of the <see cref="Lpd"/> class, loading data from the given
/// <paramref name="stream"/>.
/// </summary>
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
public Lpd(Stream stream)
{
Load(stream);
}
public Lpd(Stream stream) => Load(stream);
// ---- PROPERTIES ---------------------------------------------------------------------------------------------
@ -47,7 +42,7 @@ namespace Syroot.Worms.Mgame
/// <param name="fileName">The name of the file to load the data from.</param>
public void Load(string fileName)
{
using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
using FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
Load(stream);
}

View File

@ -19,17 +19,12 @@ namespace Syroot.Worms.Mgame
{
// ---- FIELDS -------------------------------------------------------------------------------------------------
private static int _numBytesTransferred = 0;
private static int _field_4 = 4;
private static int _field_8 = 0;
private static int _field_C = 0;
private static int _field_10 = 0;
private static readonly int[] _bufferDwords = new int[512];
private static byte[] _buffer = new byte[256];
private static readonly byte[] _buffer = new byte[256];
private static int _bufferCursor = 0;
// ---- METHODS (INTERNAL) -------------------------------------------------------------------------------------
@ -102,7 +97,6 @@ namespace Syroot.Worms.Mgame
compressor.Shift(shiftValue1, 8);
compressor.Shift(idxDword - 18, 8);
field_10 = _field_10;
++_field_C;
_field_10 = idxDword - 3 + field_10;
}
else
@ -110,7 +104,6 @@ namespace Syroot.Worms.Mgame
compressor.Shift(idxDword - 2, 4);
compressor.Shift(shiftValue1 - 1, 8);
field_8 = _field_8;
++_field_4;
_field_8 = idxDword - 2 + field_8;
}
idx += idxDword;
@ -209,7 +202,6 @@ namespace Syroot.Worms.Mgame
bufferCursor = _bufferCursor;
if (bufferCursor != 0)
{
_numBytesTransferred += bufferCursor;
compressor.Compress(false);
compressor.Shift(_bufferCursor - 1, 8);
for (i = 0; i < _bufferCursor; ++i)

View File

@ -54,7 +54,7 @@ namespace Syroot.Worms.Mgame
/// <param name="fileName">The name of the file to load the data from.</param>
public void Load(string fileName)
{
using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
using FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
Load(stream);
}

View File

@ -37,13 +37,13 @@ namespace Syroot.Worms.Mgame
/// <returns>The encrypted text.</returns>
public static string Encrypt(string data, uint key)
{
using (MemoryStream inStream = new MemoryStream(new byte[_bufferSize]))
{
using MemoryStream inStream = new MemoryStream(new byte[_bufferSize]);
// Write input into a buffer. Required to loop over the input password end.
inStream.WriteString(data, StringCoding.ZeroTerminated, Encodings.Korean);
inStream.Position = 0;
using (MemoryStream outStream = new MemoryStream(new byte[_bufferSize]))
{
using MemoryStream outStream = new MemoryStream(new byte[_bufferSize]);
// Encrypt the contents character by character.
while (inStream.Position < data.Length)
{
@ -59,8 +59,6 @@ namespace Syroot.Worms.Mgame
outStream.Position = 0;
return outStream.ReadString(StringCoding.ZeroTerminated, Encodings.Korean);
}
}
}
/// <summary>
/// Decrypts the given <paramref name="data"/> with the specified <paramref name="key"/>.
@ -70,13 +68,13 @@ namespace Syroot.Worms.Mgame
/// <returns>The decrypted text.</returns>
public static string Decrypt(string data, uint key)
{
using (MemoryStream inStream = new MemoryStream(new byte[_bufferSize]))
{
using MemoryStream inStream = new MemoryStream(new byte[_bufferSize]);
// Write input into a buffer. Required to loop over the input password end.
inStream.WriteString(data, StringCoding.Raw, Encodings.Korean);
inStream.Position = 0;
using (MemoryStream outStream = new MemoryStream(new byte[_bufferSize]))
{
using MemoryStream outStream = new MemoryStream(new byte[_bufferSize]);
// Decrypt the contents character by character.
for (int i = 0; i < data.Length; i += 7)
{
@ -95,8 +93,6 @@ namespace Syroot.Worms.Mgame
outStream.Position = 0;
return outStream.ReadString(StringCoding.ZeroTerminated, Encodings.Korean);
}
}
}
// ---- METHODS (PRIVATE) --------------------------------------------------------------------------------------

View File

@ -14,7 +14,7 @@
<PackageTags>worms;team17</PackageTags>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://gitlab.com/Syroot/Worms</RepositoryUrl>
<TargetFrameworks>net461;netstandard2.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<Version>2.0.0-alpha1</Version>
</PropertyGroup>
<ItemGroup>

View File

@ -91,8 +91,8 @@ namespace Syroot.Worms.WorldParty
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
public void Load(Stream stream)
{
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
{
using BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true);
// Read the header.
if (reader.ReadInt32() != _signature)
throw new InvalidDataException("Invalid LND file signature.");
@ -115,7 +115,6 @@ namespace Syroot.Worms.WorldParty
LandTexturePath = reader.ReadString(StringCoding.ByteCharCount);
WaterDirPath = reader.ReadString(StringCoding.ByteCharCount);
}
}
/// <summary>
/// Loads the data from the given file.
@ -123,7 +122,7 @@ namespace Syroot.Worms.WorldParty
/// <param name="fileName">The name of the file to load the data from.</param>
public void Load(string fileName)
{
using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
using FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
Load(stream);
}
@ -133,8 +132,8 @@ 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);
// Write the header.
writer.Write(_signature);
uint fileSizeOffset = writer.ReserveOffset();
@ -159,7 +158,6 @@ namespace Syroot.Worms.WorldParty
writer.SatisfyOffset(fileSizeOffset, (int)writer.Position);
}
}
/// <summary>
/// Saves the data in the given file.
@ -167,7 +165,7 @@ namespace Syroot.Worms.WorldParty
/// <param name="fileName">The name of the file to save the data in.</param>
public void Save(string fileName)
{
using (FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
using FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None);
Save(stream);
}
}

View File

@ -14,7 +14,7 @@
<PackageTags>worms;team17</PackageTags>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://gitlab.com/Syroot/Worms</RepositoryUrl>
<TargetFrameworks>net461;netstandard2.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<Version>2.0.0-alpha1</Version>
</PropertyGroup>
<ItemGroup>

View File

@ -195,8 +195,8 @@ namespace Syroot.Worms.WorldParty
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
public void Load(Stream stream)
{
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
{
using BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true);
Name = reader.ReadString(17);
WormNames = reader.ReadStrings(8, 17);
CpuLevel = reader.Read1Byte();
@ -247,7 +247,6 @@ namespace Syroot.Worms.WorldParty
Fort = reader.Read1Byte();
Unknown2 = reader.ReadInt32s(7);
}
}
/// <summary>
/// Saves the data into the given <paramref name="stream"/>.
@ -255,8 +254,8 @@ 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, leaveOpen: true))
{
using BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true);
writer.WriteString(Name, 17);
writer.WriteStrings(WormNames, 17);
writer.Write(CpuLevel);
@ -299,7 +298,6 @@ namespace Syroot.Worms.WorldParty
writer.Write(Unknown2);
}
}
}
/// <summary>
/// Represents a team's progress in a mission.

View File

@ -21,29 +21,20 @@ namespace Syroot.Worms.WorldParty
/// <summary>
/// Initializes a new instance of the <see cref="TeamContainer"/> class.
/// </summary>
public TeamContainer()
{
Teams = new List<Team>();
}
public TeamContainer() => Teams = new List<Team>();
/// <summary>
/// Initializes a new instance of the <see cref="TeamContainer"/> class, loading the data from the given
/// <see cref="Stream"/>.
/// </summary>
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
public TeamContainer(Stream stream)
{
Load(stream);
}
public TeamContainer(Stream stream) => Load(stream);
/// <summary>
/// Initializes a new instance of the <see cref="TeamContainer"/> class, loading the data from the given file.
/// </summary>
/// <param name="fileName">The name of the file to load the data from.</param>
public TeamContainer(string fileName)
{
Load(fileName);
}
public TeamContainer(string fileName) => Load(fileName);
// ---- PROPERTIES ---------------------------------------------------------------------------------------------
@ -80,13 +71,11 @@ namespace Syroot.Worms.WorldParty
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
public void Load(Stream stream)
{
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
{
using BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true);
// Read the header.
if (reader.ReadString(StringCoding.ZeroTerminated) != _signature)
{
throw new InvalidDataException("Invalid WWP file signature.");
}
Version = reader.Read1Byte(); // Really version?
// Read global settings.
@ -98,7 +87,6 @@ namespace Syroot.Worms.WorldParty
// Read the teams.
Teams = new List<Team>(reader.Load<Team>(teamCount));
}
}
/// <summary>
/// Loads the data from the given file.
@ -106,11 +94,9 @@ namespace Syroot.Worms.WorldParty
/// <param name="fileName">The name of the file to load the data from.</param>
public void Load(string fileName)
{
using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
using FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
Load(stream);
}
}
/// <summary>
/// Saves the data into the given <paramref name="stream"/>.
@ -118,8 +104,8 @@ 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);
// Write the header.
writer.Write(_signature, StringCoding.ZeroTerminated);
writer.Write(Version);
@ -132,11 +118,8 @@ namespace Syroot.Worms.WorldParty
// Write the teams.
foreach (Team team in Teams)
{
team.Save(writer.BaseStream);
}
}
}
/// <summary>
/// Saves the data in the given file.
@ -144,10 +127,8 @@ namespace Syroot.Worms.WorldParty
/// <param name="fileName">The name of the file to save the data in.</param>
public void Save(string fileName)
{
using (FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
{
using FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None);
Save(stream);
}
}
}
}

View File

@ -96,8 +96,8 @@ namespace Syroot.Worms.Worms2
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
public void Load(Stream stream)
{
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
{
using BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true);
// Read the header.
if (reader.ReadInt32() != _signature)
throw new InvalidDataException("Invalid LND file signature.");
@ -121,7 +121,6 @@ namespace Syroot.Worms.Worms2
LandTexturePath = reader.ReadString(StringCoding.ByteCharCount);
WaterDirPath = reader.ReadString(StringCoding.ByteCharCount);
}
}
/// <summary>
/// Loads the data from the given file.
@ -129,7 +128,7 @@ namespace Syroot.Worms.Worms2
/// <param name="fileName">The name of the file to load the data from.</param>
public void Load(string fileName)
{
using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
using FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
Load(stream);
}
@ -139,8 +138,8 @@ 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);
// Write the header.
writer.Write(_signature);
uint fileSizeOffset = writer.ReserveOffset();
@ -166,7 +165,6 @@ namespace Syroot.Worms.Worms2
writer.SatisfyOffset(fileSizeOffset, (int)writer.Position);
}
}
/// <summary>
/// Saves the data in the given file.
@ -174,7 +172,7 @@ namespace Syroot.Worms.Worms2
/// <param name="fileName">The name of the file to save the data in.</param>
public void Save(string fileName)
{
using (FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
using FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None);
Save(stream);
}
}

View File

@ -26,7 +26,6 @@ namespace Syroot.Worms.Worms2
Manual = 3
}
/// <summary>
/// Represents the weapons in the game.
/// </summary>

View File

@ -20,28 +20,20 @@ namespace Syroot.Worms.Worms2
/// <summary>
/// Initializs a new instance of the <see cref="SchemeOptions"/> class.
/// </summary>
public SchemeOptions()
{
}
public SchemeOptions() { }
/// <summary>
/// Initializes a new instance of the <see cref="SchemeOptions"/> class, loading the data from the given
/// <see cref="Stream"/>.
/// </summary>
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
public SchemeOptions(Stream stream)
{
Load(stream);
}
public SchemeOptions(Stream stream) => Load(stream);
/// <summary>
/// Initializes a new instance of the <see cref="SchemeOptions"/> class, loading the data from the given file.
/// </summary>
/// <param name="fileName">The name of the file to load the data from.</param>
public SchemeOptions(string fileName)
{
Load(fileName);
}
public SchemeOptions(string fileName) => Load(fileName);
// ---- PROPERTIES ---------------------------------------------------------------------------------------------
@ -221,13 +213,11 @@ namespace Syroot.Worms.Worms2
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
public void Load(Stream stream)
{
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
{
using BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true);
// Read the header.
if (reader.ReadString(_signature.Length) != _signature)
{
throw new InvalidDataException("Invalid OPT file signature.");
}
// Read the options.
RoundTime = reader.ReadInt32();
@ -263,11 +253,8 @@ namespace Syroot.Worms.Worms2
SuddenDeathDisableWormSelect = reader.ReadBoolean(BooleanCoding.Dword);
// The following option does not exist in all schemes.
if (!reader.EndOfStream)
{
UseOilDrums = reader.ReadBoolean(BooleanCoding.Dword);
}
}
}
/// <summary>
/// Loads the data from the given file.
@ -275,11 +262,9 @@ namespace Syroot.Worms.Worms2
/// <param name="fileName">The name of the file to load the data from.</param>
public void Load(string fileName)
{
using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
using FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
Load(stream);
}
}
/// <summary>
/// Saves the data into the given <paramref name="stream"/>.
@ -287,8 +272,8 @@ 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);
// Write the header.
writer.Write(_signature, StringCoding.Raw);
@ -326,7 +311,6 @@ namespace Syroot.Worms.Worms2
writer.Write(SuddenDeathDisableWormSelect, BooleanCoding.Dword);
writer.Write(UseOilDrums, BooleanCoding.Dword);
}
}
/// <summary>
/// Saves the data in the given file.
@ -334,10 +318,8 @@ namespace Syroot.Worms.Worms2
/// <param name="fileName">The name of the file to save the data in.</param>
public void Save(string fileName)
{
using (FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
{
using FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None);
Save(stream);
}
}
}
}

View File

@ -22,29 +22,20 @@ namespace Syroot.Worms.Worms2
/// <summary>
/// Initializes a new instance of the <see cref="SchemeWeapons"/> class.
/// </summary>
public SchemeWeapons()
{
Weapons = new SchemeWeaponSetting[_weaponCount];
}
public SchemeWeapons() => Weapons = new SchemeWeaponSetting[_weaponCount];
/// <summary>
/// Initializes a new instance of the <see cref="SchemeWeapons"/> class, loading the data from the given
/// <see cref="Stream"/>.
/// </summary>
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
public SchemeWeapons(Stream stream)
{
Load(stream);
}
public SchemeWeapons(Stream stream) => Load(stream);
/// <summary>
/// Initializes a new instance of the <see cref="SchemeWeapons"/> class, loading the data from the given file.
/// </summary>
/// <param name="fileName">The name of the file to load the data from.</param>
public SchemeWeapons(string fileName)
{
Load(fileName);
}
public SchemeWeapons(string fileName) => Load(fileName);
// ---- PROPERTIES ---------------------------------------------------------------------------------------------
@ -62,23 +53,18 @@ namespace Syroot.Worms.Worms2
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
public void Load(Stream stream)
{
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
{
using BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true);
// Read the header.
reader.Seek(_trashLength);
if (reader.ReadString(StringCoding.ZeroTerminated) != _signature)
{
throw new InvalidDataException("Invalid WEP file signature.");
}
// Read the weapon settings.
Weapons = new SchemeWeaponSetting[_weaponCount];
for (int i = 0; i < _weaponCount; i++)
{
Weapons[i] = reader.ReadStruct<SchemeWeaponSetting>();
}
}
}
/// <summary>
/// Loads the data from the given file.
@ -86,11 +72,9 @@ namespace Syroot.Worms.Worms2
/// <param name="fileName">The name of the file to load the data from.</param>
public void Load(string fileName)
{
using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
using FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
Load(stream);
}
}
/// <summary>
/// Saves the data into the given <paramref name="stream"/>.
@ -98,19 +82,16 @@ 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);
// Write the header.
writer.WriteStructs(new byte[_trashLength]);
writer.Write(_signature, StringCoding.ZeroTerminated);
// Write the weapon settings.
foreach (SchemeWeaponSetting weapon in Weapons)
{
writer.WriteStruct(weapon);
}
}
}
/// <summary>
/// Saves the data in the given file.
@ -118,10 +99,8 @@ namespace Syroot.Worms.Worms2
/// <param name="fileName">The name of the file to save the data in.</param>
public void Save(string fileName)
{
using (FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
{
using FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None);
Save(stream);
}
}
}
}

View File

@ -14,7 +14,7 @@
<PackageTags>worms;team17</PackageTags>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://gitlab.com/Syroot/Worms</RepositoryUrl>
<TargetFrameworks>net461;netstandard2.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<Version>2.0.0-alpha1</Version>
</PropertyGroup>
<ItemGroup>

View File

@ -109,8 +109,7 @@ namespace Syroot.Worms.Worms2
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
public void Load(Stream stream)
{
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
{
using BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true);
Unknown1 = reader.ReadInt16();
Name = reader.ReadString(66);
SoundBankName = reader.ReadString(36);
@ -153,7 +152,6 @@ namespace Syroot.Worms.Worms2
GamesPlayed = reader.ReadInt32();
Points = reader.ReadInt32();
}
}
/// <summary>
/// Saves the data into the given <paramref name="stream"/>.
@ -161,8 +159,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, leaveOpen: true))
{
using BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true);
writer.Write(Unknown1);
writer.WriteString(Name, 66);
writer.WriteString(SoundBankName, 36);
@ -209,4 +206,3 @@ namespace Syroot.Worms.Worms2
}
}
}
}

View File

@ -17,29 +17,20 @@ namespace Syroot.Worms.Worms2
/// <summary>
/// Initializes a new instance of the <see cref="TeamContainer"/> class.
/// </summary>
public TeamContainer()
{
Teams = new List<Team>();
}
public TeamContainer() => Teams = new List<Team>();
/// <summary>
/// Initializes a new instance of the <see cref="TeamContainer"/> class, loading the data from the given
/// <see cref="Stream"/>.
/// </summary>
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
public TeamContainer(Stream stream)
{
Load(stream);
}
public TeamContainer(Stream stream) => Load(stream);
/// <summary>
/// Initializes a new instance of the <see cref="TeamContainer"/> class, loading the data from the given file.
/// </summary>
/// <param name="fileName">The name of the file to load the data from.</param>
public TeamContainer(string fileName)
{
Load(fileName);
}
public TeamContainer(string fileName) => Load(fileName);
// ---- PROPERTIES ---------------------------------------------------------------------------------------------
@ -56,15 +47,11 @@ namespace Syroot.Worms.Worms2
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
public void Load(Stream stream)
{
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
{
using BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true);
Teams = new List<Team>();
while (!reader.EndOfStream)
{
Teams.Add(reader.Load<Team>());
}
}
}
/// <summary>
/// Loads the data from the given file.
@ -72,11 +59,9 @@ namespace Syroot.Worms.Worms2
/// <param name="fileName">The name of the file to load the data from.</param>
public void Load(string fileName)
{
using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
using FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
Load(stream);
}
}
/// <summary>
/// Saves the data into the given <paramref name="stream"/>.
@ -84,14 +69,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);
foreach (Team team in Teams)
{
team.Save(writer.BaseStream);
}
}
}
/// <summary>
/// Saves the data in the given file.
@ -99,10 +80,8 @@ namespace Syroot.Worms.Worms2
/// <param name="fileName">The name of the file to save the data in.</param>
public void Save(string fileName)
{
using (FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
{
using FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None);
Save(stream);
}
}
}
}

View File

@ -28,28 +28,20 @@ namespace Syroot.Worms
/// <summary>
/// Initializes a new instance of the <see cref="Archive"/> class.
/// </summary>
public Archive()
{
}
public Archive() { }
/// <summary>
/// Initializes a new instance of the <see cref="Archive"/> class, loading the data from the given
/// <see cref="Stream"/>.
/// </summary>
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
public Archive(Stream stream)
{
Load(stream);
}
public Archive(Stream stream) => Load(stream);
/// <summary>
/// Initializes a new instance of the <see cref="Archive"/> class, loading the data from the given file.
/// </summary>
/// <param name="fileName">The name of the file to load the data from.</param>
public Archive(string fileName)
{
Load(fileName);
}
public Archive(string fileName) => Load(fileName);
// ---- METHODS (PUBLIC) ---------------------------------------------------------------------------------------
@ -60,18 +52,14 @@ namespace Syroot.Worms
public void Load(Stream stream)
{
if (!stream.CanSeek)
{
throw new ArgumentException("Stream requires to be seekable.", nameof(stream));
}
Clear();
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
{
using BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true);
// Read the header.
if (reader.ReadInt32() != _signature)
{
throw new InvalidDataException("Invalid DIR file signature.");
}
int fileSize = reader.ReadInt32();
int tocOffset = reader.ReadInt32();
@ -79,9 +67,7 @@ namespace Syroot.Worms
reader.Position = tocOffset;
int tocSignature = reader.ReadInt32();
if (tocSignature != _tocSignature)
{
throw new InvalidDataException("Invalid DIR table of contents signature.");
}
// Generate a data dictionary out of the hash table and file entries.
int[] hashTable = reader.ReadInt32s(_hashSize);
foreach (int entryOffset in hashTable)
@ -98,14 +84,11 @@ namespace Syroot.Worms
int length = reader.ReadInt32();
string name = reader.ReadString(StringCoding.ZeroTerminated);
using (reader.TemporarySeek(offset, SeekOrigin.Begin))
{
Add(name, reader.ReadBytes(length));
}
} while (nextEntryOffset != 0);
}
}
}
}
/// <summary>
/// Loads the data from the given file.
@ -113,11 +96,9 @@ namespace Syroot.Worms
/// <param name="fileName">The name of the file to load the data from.</param>
public void Load(string fileName)
{
using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
using FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
Load(stream);
}
}
/// <summary>
/// Saves the data into the given <paramref name="stream"/>.
@ -125,8 +106,8 @@ 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);
// Write the header.
writer.Write(_signature);
uint fileSizeOffset = writer.ReserveOffset();
@ -146,9 +127,7 @@ namespace Syroot.Worms
int hash = CalculateHash(item.Key);
if (hashTable[hash] == null)
{
hashTable[hash] = new List<HashTableEntry>();
}
hashTable[hash].Add(entry);
}
@ -179,10 +158,8 @@ namespace Syroot.Worms
writer.Write(entry.Name, StringCoding.ZeroTerminated);
writer.Align(4);
if (j < entries.Count - 1)
{
writer.SatisfyOffset(nextEntryOffset, (int)writer.Position - tocStart);
}
}
fileEntryOffset = (int)writer.Position - tocStart;
}
}
@ -190,7 +167,6 @@ namespace Syroot.Worms
writer.SatisfyOffset(fileSizeOffset, tocStart + fileEntryOffset - 1);
}
}
/// <summary>
/// Saves the data in the file with the given <paramref name="fileName"/>.
@ -198,11 +174,9 @@ namespace Syroot.Worms
/// <param name="fileName">The name of the file to save the data in.</param>
public void Save(string fileName)
{
using (FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
{
using FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None);
Save(stream);
}
}
// ---- METHODS (PRIVATE) --------------------------------------------------------------------------------------

View File

@ -5,6 +5,8 @@
/// </summary>
public static class Algebra
{
// ---- METHODS (PUBLIC) ---------------------------------------------------------------------------------------
/// <summary>
/// Gets the nearest, bigger <paramref name="multiple"/> of the given <paramref name="value"/>.
/// </summary>

View File

@ -65,9 +65,7 @@ namespace Syroot.Worms.Core
/// <param name="enable"><c>true</c> to enable the bit; otherwise <c>false</c>.</param>
/// <returns>The current byte with the bit enabled or disabled.</returns>
public static byte SetBit(this byte self, int index, bool enable)
{
return enable ? EnableBit(self, index) : DisableBit(self, index);
}
=> enable ? EnableBit(self, index) : DisableBit(self, index);
/// <summary>
/// Returns the current byte with the bit at the <paramref name="index"/> enabled when it is disabled or
@ -77,9 +75,7 @@ namespace Syroot.Worms.Core
/// <param name="index">The 0-based index of the bit to toggle.</param>
/// <returns>The current byte with the bit toggled.</returns>
public static byte ToggleBit(this byte self, int index)
{
return GetBit(self, index) ? DisableBit(self, index) : EnableBit(self, index);
}
=> GetBit(self, index) ? DisableBit(self, index) : EnableBit(self, index);
/// <summary>
/// Returns an <see cref="Byte"/> instance represented by the given number of <paramref name="bits"/>.
@ -100,10 +96,7 @@ namespace Syroot.Worms.Core
/// <param name="firstBit">The first bit of the encoded value.</param>
/// <returns>The decoded <see cref="Byte"/>.</returns>
public static byte DecodeByte(this byte self, int bits, int firstBit)
{
// Shift to the first bit and keep only the required bits.
return (byte)((self >> firstBit) & ((1 << bits) - 1));
}
=> (byte)((self >> firstBit) & ((1 << bits) - 1)); // shift to the first bit and keep only required bits
/// <summary>
/// Returns an <see cref="SByte"/> instance represented by the given number of <paramref name="bits"/>.

View File

@ -15,10 +15,7 @@ namespace Syroot.Worms.Core
// ---- CONSTRUCTORS & DESTRUCTOR ------------------------------------------------------------------------------
public DisposableGCHandle(object value, GCHandleType type)
{
_handle = GCHandle.Alloc(value, GCHandleType.Pinned);
}
public DisposableGCHandle(object value, GCHandleType type) => _handle = GCHandle.Alloc(value, type);
// ---- PROPERTIES ---------------------------------------------------------------------------------------------
@ -26,18 +23,15 @@ namespace Syroot.Worms.Core
// ---- METHODS (PUBLIC) ---------------------------------------------------------------------------------------
public void Dispose()
{
// Do not change this code. Put cleanup code in Dispose(bool disposing).
Dispose(true);
}
public void Dispose() => Dispose(true);
// ---- METHODS (PROTECTED) ------------------------------------------------------------------------------------
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
{
if (_disposed)
return;
if (disposing)
{
if (_handle.IsAllocated)
@ -48,4 +42,3 @@ namespace Syroot.Worms.Core
}
}
}
}

View File

@ -22,8 +22,8 @@ namespace Syroot.Worms.Core.Graphics
/// <returns>The <see cref="Bitmap"/> instance.</returns>
public static Bitmap CreateIndexed(Size size, IList<Color> palette, byte[] data)
{
using (DisposableGCHandle dataPin = new DisposableGCHandle(data, GCHandleType.Pinned))
{
using DisposableGCHandle dataPin = new DisposableGCHandle(data, GCHandleType.Pinned);
// Transfer the pixel data, respecting power-of-2 strides.
Bitmap bitmap = new Bitmap(size.Width, size.Height, PixelFormat.Format8bppIndexed);
BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, size.Width, size.Height),
@ -42,4 +42,3 @@ namespace Syroot.Worms.Core.Graphics
}
}
}
}

View File

@ -41,8 +41,8 @@ namespace Syroot.Worms
/// <returns>The <see cref="Bitmap"/> created from the raw data.</returns>
public Bitmap ToBitmap()
{
using (DisposableGCHandle dataPin = new DisposableGCHandle(Data, GCHandleType.Pinned))
{
using DisposableGCHandle dataPin = new DisposableGCHandle(Data, GCHandleType.Pinned);
// Transfer the pixel data, respecting power-of-2 strides.
Bitmap bitmap = new Bitmap(Size.Width, Size.Height, PixelFormat.Format8bppIndexed);
BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, Size.Width, Size.Height),
@ -61,4 +61,3 @@ namespace Syroot.Worms
}
}
}
}

View File

@ -87,12 +87,10 @@ namespace Syroot.Worms.Core.IO
byte[] bytes = self.ReadBytes(Marshal.SizeOf<T>());
// Convert them to a structure instance and return it.
using (DisposableGCHandle handle = new DisposableGCHandle(bytes, GCHandleType.Pinned))
{
using DisposableGCHandle handle = new DisposableGCHandle(bytes, GCHandleType.Pinned);
T instance = Marshal.PtrToStructure<T>(handle.AddrOfPinnedObject);
return instance;
}
}
/// <summary>
/// Reads raw byte structures from the current stream and returns them.

View File

@ -16,10 +16,7 @@ namespace Syroot.Worms.Core.Riff
/// <paramref name="identifier"/>.
/// </summary>
/// <param name="identifier">The chunk identifier required to invoke this method for loading it.</param>
internal RiffChunkLoadAttribute(string identifier)
{
Identifier = identifier;
}
internal RiffChunkLoadAttribute(string identifier) => Identifier = identifier;
// ---- PROPERTIES ---------------------------------------------------------------------------------------------

View File

@ -16,10 +16,7 @@ namespace Syroot.Worms.Core.Riff
/// <paramref name="identifier"/>.
/// </summary>
/// <param name="identifier">The chunk identifier saved in the file.</param>
internal RiffChunkSaveAttribute(string identifier)
{
Identifier = identifier;
}
internal RiffChunkSaveAttribute(string identifier) => Identifier = identifier;
// ---- PROPERTIES ---------------------------------------------------------------------------------------------

View File

@ -21,17 +21,14 @@ namespace Syroot.Worms.Core.Riff
private static readonly Dictionary<Type, TypeData> _typeDataCache = new Dictionary<Type, TypeData>();
private TypeData _typeData;
private readonly TypeData _typeData;
// ---- CONSTRUCTORS & DESTRUCTOR ------------------------------------------------------------------------------
/// <summary>
/// Initializes a new instance of the <see cref="RiffFile"/> class.
/// </summary>
protected RiffFile()
{
_typeData = GetTypeData();
}
protected RiffFile() => _typeData = GetTypeData();
// ---- METHODS (PROTECTED) ------------------------------------------------------------------------------------
@ -41,19 +38,15 @@ namespace Syroot.Worms.Core.Riff
/// <param name="stream">The <see cref="Stream"/> to load the RIFF data from.</param>
protected void LoadRiff(Stream stream)
{
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
{
using BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true);
// Read the file header.
if (reader.ReadString(_signature.Length) != _signature)
{
throw new InvalidDataException("Invalid RIFF file signature.");
}
int fileSize = reader.ReadInt32();
string fileIdentifier = reader.ReadString(4);
if (fileIdentifier != _typeData.FileIdentifier)
{
throw new InvalidDataException("Invalid RIFF file identifier.");
}
// Read the chunks.
while (!reader.EndOfStream)
@ -62,16 +55,11 @@ namespace Syroot.Worms.Core.Riff
int chunkLength = reader.ReadInt32();
// Invoke a loader method if matching the identifier or skip the chunk.
if (_typeData.ChunkLoaders.TryGetValue(chunkIdentifier, out MethodInfo loader))
{
loader.Invoke(this, new object[] { reader, chunkLength });
}
else
{
reader.Seek(chunkLength);
}
}
}
}
/// <summary>
/// Saves the RIFF data in the given <paramref name="stream"/>.
@ -79,8 +67,8 @@ 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);
// Write the header.
writer.Write(_signature, StringCoding.Raw);
uint fileSizeOffset = writer.ReserveOffset();
@ -99,7 +87,6 @@ namespace Syroot.Worms.Core.Riff
writer.SatisfyOffset(fileSizeOffset, (int)(writer.Position - 8));
}
}
// ---- METHODS (PRIVATE) --------------------------------------------------------------------------------------
@ -135,11 +122,8 @@ namespace Syroot.Worms.Core.Riff
if (saveAttribute != null)
{
ParameterInfo[] parameters = method.GetParameters();
if (parameters.Length == 1
&& parameters[0].ParameterType == typeof(BinaryStream))
{
if (parameters.Length == 1 && parameters[0].ParameterType == typeof(BinaryStream))
typeData.ChunkSavers.Add(saveAttribute.Identifier, method);
}
continue;
}
}

View File

@ -15,10 +15,7 @@ namespace Syroot.Worms.Core.Riff
/// <paramref name="identifier"/>.
/// </summary>
/// <param name="identifier">The file identifier in the RIFF file header which will be validated.</param>
internal RiffFileAttribute(string identifier)
{
Identifier = identifier;
}
internal RiffFileAttribute(string identifier) => Identifier = identifier;
// ---- PROPERTIES ---------------------------------------------------------------------------------------------

View File

@ -18,9 +18,7 @@ namespace Syroot.Worms.Core
/// <param name="bytes">The data to compress.</param>
/// <returns>The compressed data.</returns>
internal static byte[] Compress(byte[] bytes)
{
throw new NotImplementedException("Compressing data has not been implemented yet.");
}
=> throw new NotImplementedException("Compressing data has not been implemented yet.");
/// <summary>
/// Decompresses the data available in the given <paramref name="stream"/> into the provided

View File

@ -67,7 +67,7 @@ namespace Syroot.Worms
/// <param name="fileName">The name of the file to load the data from.</param>
public void Load(string fileName)
{
using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
using FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
Load(stream);
}
@ -78,8 +78,8 @@ namespace Syroot.Worms
/// <param name="alignData"><c>true</c> to align the data array by 4 bytes.</param>
public void Load(Stream stream, bool alignData)
{
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
{
using BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true);
// Read the header.
if (reader.ReadInt32() != _signature)
throw new InvalidDataException("Invalid IMG file signature.");
@ -133,7 +133,6 @@ namespace Syroot.Worms
Data = data;
}
}
/// <summary>
/// Loads the data from the given file. The data block can be aligned to a 4-bte boundary.
@ -142,8 +141,8 @@ namespace Syroot.Worms
/// <param name="alignData"><c>true</c> to align the data array by 4 bytes.</param>
public void Load(string fileName, bool alignData)
{
using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
Load(stream);
using FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
Load(stream, alignData);
}
/// <summary>
@ -181,8 +180,8 @@ 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);
// Write the header.
writer.Write(_signature);
uint fileSizeOffset = writer.ReserveOffset();
@ -227,7 +226,6 @@ namespace Syroot.Worms
writer.SatisfyOffset(fileSizeOffset, (int)writer.Position);
}
}
/// <summary>
/// Saves the optionally compressed data in the given file. The data block can be aligned to a 4-byte boundary.
@ -237,7 +235,7 @@ namespace Syroot.Worms
/// <param name="alignData"><c>true</c> to align the data array by 4 bytes.</param>
public void Save(string fileName, bool compress, bool alignData)
{
using (FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
using FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None);
Save(stream, compress, alignData);
}

View File

@ -23,29 +23,20 @@ namespace Syroot.Worms
/// <summary>
/// Initializes a new instance of the <see cref="RiffPalette"/> class.
/// </summary>
public RiffPalette()
{
Version = _version;
}
public RiffPalette() => Version = _version;
/// <summary>
/// Initializes a new instance of the <see cref="RiffPalette"/> class, loading the data from the given
/// <see cref="Stream"/>.
/// </summary>
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
public RiffPalette(Stream stream)
{
Load(stream);
}
public RiffPalette(Stream stream) => Load(stream);
/// <summary>
/// Initializes a new instance of the <see cref="RiffPalette"/> class, loading the data from the given file.
/// </summary>
/// <param name="fileName">The name of the file to load the data from.</param>
public RiffPalette(string fileName)
{
Load(fileName);
}
public RiffPalette(string fileName) => Load(fileName);
// ---- PROPERTIES ---------------------------------------------------------------------------------------------
@ -80,10 +71,7 @@ namespace Syroot.Worms
/// Loads the data from the given <see cref="Stream"/>.
/// </summary>
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
public void Load(Stream stream)
{
LoadRiff(stream);
}
public void Load(Stream stream) => LoadRiff(stream);
/// <summary>
/// Loads the data from the given file.
@ -91,20 +79,15 @@ namespace Syroot.Worms
/// <param name="fileName">The name of the file to load the data from.</param>
public void Load(string fileName)
{
using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
using FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
Load(stream);
}
}
/// <summary>
/// Saves the data into the given <paramref name="stream"/>.
/// </summary>
/// <param name="stream">The <see cref="Stream"/> to save the data to.</param>
public void Save(Stream stream)
{
SaveRiff(stream);
}
public void Save(Stream stream) => SaveRiff(stream);
/// <summary>
/// Saves the data in the given file.
@ -112,11 +95,9 @@ namespace Syroot.Worms
/// <param name="fileName">The name of the file to save the data in.</param>
public void Save(string fileName)
{
using (FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
{
using FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None);
Save(stream);
}
}
// ---- METHODS (PRIVATE) --------------------------------------------------------------------------------------
@ -126,36 +107,25 @@ namespace Syroot.Worms
// Read the PAL version.
Version = reader.ReadInt16();
if (Version != _version)
{
throw new InvalidDataException("Unknown PAL version.");
}
// Read the colors.
Colors = new Color[reader.ReadInt16()];
for (int i = 0; i < Colors.Length; i++)
{
Colors[i] = Color.FromArgb(reader.Read1Byte(), reader.Read1Byte(), reader.Read1Byte());
int alpha = reader.ReadByte(); // Dismiss alpha, as it is not used in WA.
_ = reader.ReadByte(); // Dismiss alpha, as it is not used in WA.
}
}
[RiffChunkLoad("offl")]
private void LoadOfflChunk(BinaryStream reader, int length)
{
OfflData = reader.ReadBytes(length);
}
private void LoadOfflChunk(BinaryStream reader, int length) => OfflData = reader.ReadBytes(length);
[RiffChunkLoad("tran")]
private void LoadTranChunk(BinaryStream reader, int length)
{
TranData = reader.ReadBytes(length);
}
private void LoadTranChunk(BinaryStream reader, int length) => TranData = reader.ReadBytes(length);
[RiffChunkLoad("unde")]
private void LoadUndeChunk(BinaryStream reader, int length)
{
UndeData = reader.ReadBytes(length);
}
private void LoadUndeChunk(BinaryStream reader, int length) => UndeData = reader.ReadBytes(length);
[RiffChunkSave("data")]
private void SaveDataChunk(BinaryStream writer)
@ -176,21 +146,12 @@ namespace Syroot.Worms
}
[RiffChunkSave("offl")]
private void SaveOfflChunk(BinaryStream writer)
{
writer.WriteStructs(OfflData);
}
private void SaveOfflChunk(BinaryStream writer) => writer.WriteStructs(OfflData);
[RiffChunkSave("tran")]
private void SaveTranChunk(BinaryStream writer)
{
writer.WriteStructs(TranData);
}
private void SaveTranChunk(BinaryStream writer) => writer.WriteStructs(TranData);
[RiffChunkSave("unde")]
private void SaveUndeChunk(BinaryStream writer)
{
writer.WriteStructs(UndeData);
}
private void SaveUndeChunk(BinaryStream writer) => writer.WriteStructs(UndeData);
}
}

View File

@ -14,13 +14,13 @@
<PackageTags>worms;team17</PackageTags>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://gitlab.com/Syroot/Worms</RepositoryUrl>
<TargetFrameworks>net461;netstandard2.0</TargetFrameworks>
<Version>2.0.0-alpha1</Version>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<Version>2.0.0</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Syroot.BinaryData.Serialization" Version="5.0.0" />
<PackageReference Include="Syroot.BinaryData" Version="5.1.0" />
<PackageReference Include="System.Drawing.Common" Version="4.5.1" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.5.1" />
<PackageReference Include="Syroot.BinaryData.Serialization" Version="5.2.0" />
<PackageReference Include="Syroot.BinaryData" Version="5.2.0" />
<PackageReference Include="System.Drawing.Common" Version="4.6.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.6.0" />
</ItemGroup>
</Project>

View File

@ -4,9 +4,9 @@
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.0.0" />
<PackageReference Include="MSTest.TestFramework" Version="2.0.0" />
<ProjectReference Include="..\..\library\Syroot.Worms.Armageddon.ProjectX\Syroot.Worms.Armageddon.ProjectX.csproj" />
<ProjectReference Include="..\Syroot.Worms.Test\Syroot.Worms.Test.csproj" />
</ItemGroup>

View File

@ -4,9 +4,9 @@
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.0.0" />
<PackageReference Include="MSTest.TestFramework" Version="2.0.0" />
<ProjectReference Include="..\..\library\Syroot.Worms.Armageddon\Syroot.Worms.Armageddon.csproj" />
<ProjectReference Include="..\Syroot.Worms.Test\Syroot.Worms.Test.csproj" />
</ItemGroup>

View File

@ -4,9 +4,9 @@
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.0.0" />
<PackageReference Include="MSTest.TestFramework" Version="2.0.0" />
<ProjectReference Include="..\..\library\Syroot.Worms.Mgame\Syroot.Worms.Mgame.csproj" />
</ItemGroup>
</Project>

View File

@ -4,9 +4,9 @@
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.0.0" />
<PackageReference Include="MSTest.TestFramework" Version="2.0.0" />
<ProjectReference Include="..\..\library\Syroot.Worms\Syroot.Worms.csproj" />
</ItemGroup>
</Project>

View File

@ -4,9 +4,9 @@
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.0.0" />
<PackageReference Include="MSTest.TestFramework" Version="2.0.0" />
<ProjectReference Include="..\..\library\Syroot.Worms.WorldParty\Syroot.Worms.WorldParty.csproj" />
<ProjectReference Include="..\Syroot.Worms.Test\Syroot.Worms.Test.csproj" />
</ItemGroup>

View File

@ -4,9 +4,9 @@
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.0.0" />
<PackageReference Include="MSTest.TestFramework" Version="2.0.0" />
<ProjectReference Include="..\..\library\Syroot.Worms.Worms2\Syroot.Worms.Worms2.csproj" />
<ProjectReference Include="..\Syroot.Worms.Test\Syroot.Worms.Test.csproj" />
</ItemGroup>

View File

@ -33,7 +33,7 @@ namespace Syroot.Worms.Mgame.GameServer
// Retrieve external IP if not yet done and given IP is invalid.
if (_ipAddress == null && (IP == null || !IPAddress.TryParse(IP, out _ipAddress)))
{
using (WebClient webClient = new WebClient())
using WebClient webClient = new WebClient();
_ipAddress = IPAddress.Parse(webClient.DownloadString("https://ip.syroot.com"));
}
return _ipAddress;

View File

@ -91,6 +91,7 @@ namespace Syroot.Worms.Mgame.GameServer.Packets
{
if (disposing)
TcpClient.Dispose();
_tcpStream.Dispose();
_disposed = true;
}
}
@ -102,10 +103,8 @@ namespace Syroot.Worms.Mgame.GameServer.Packets
{
// Let each packet format try to serialize the data.
foreach (IPacketFormat format in _packetFormatPipe)
{
if (format.TrySave(_tcpStream, packet))
return;
}
throw new NotImplementedException("Cannot send unhandled packet format.");
}
catch (IOException) { } // A network error appeared, and communication should end.

View File

@ -9,7 +9,7 @@ namespace Syroot.Worms.Mgame.GameServer
{
// ---- METHODS (PRIVATE) --------------------------------------------------------------------------------------
private static void Main(string[] args)
private static void Main()
{
try
{

View File

@ -7,11 +7,11 @@
<TargetFrameworks>netcoreapp2.1</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.2.0" />
<PackageReference Include="Syroot.BinaryData.Memory" Version="5.2.0-alpha1" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.5.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="3.0.0" />
<PackageReference Include="Syroot.BinaryData.Memory" Version="5.2.2" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.6.0" />
<ProjectReference Include="..\..\library\Syroot.Worms.Mgame\Syroot.Worms.Mgame.csproj" />
<ProjectReference Include="..\..\library\Syroot.Worms\Syroot.Worms.csproj" />
<None Update="ServerConfig.json">

View File

@ -14,7 +14,7 @@ namespace Syroot.Worms.Mgame.Launcher
{
// ---- METHODS (PRIVATE) --------------------------------------------------------------------------------------
private static void Main(string[] args)
private static void Main()
{
try
{
@ -36,9 +36,10 @@ namespace Syroot.Worms.Mgame.Launcher
using (launchConfig.CreateMappedFile(config.MappingName))
{
// Create and run the process.
NativeProcess process = CreateProcess(executablePath,
using (NativeProcess process = CreateProcess(executablePath,
String.Join(" ", config.MappingName, config.ExecutableArgs).TrimEnd(),
config.StartSuspended);
config.StartSuspended))
{
if (config.StartSuspended)
{
if (ShowMessage(MessageBoxIcon.Information,
@ -55,6 +56,7 @@ namespace Syroot.Worms.Mgame.Launcher
process.WaitForExit();
}
}
}
catch (Exception ex)
{
ShowMessage(MessageBoxIcon.Error, ex.Message, MessageBoxButtons.OK);

View File

@ -15,10 +15,10 @@
<Version>1.0.0</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Costura.Fody" Version="3.3.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.2.0" />
<PackageReference Include="Costura.Fody" Version="4.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="3.0.0" />
<ProjectReference Include="..\..\library\Syroot.Worms.Mgame\Syroot.Worms.Mgame.csproj" />
<ProjectReference Include="..\..\library\Syroot.Worms\Syroot.Worms.csproj" />
<Reference Include="System.Windows.Forms" />

View File

@ -4,7 +4,7 @@
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Syroot.BinaryData" Version="5.1.0" />
<PackageReference Include="Syroot.BinaryData" Version="5.2.0" />
<ProjectReference Include="..\..\library\Syroot.Worms.Armageddon.ProjectX\Syroot.Worms.Armageddon.ProjectX.csproj" />
<ProjectReference Include="..\..\library\Syroot.Worms.Armageddon\Syroot.Worms.Armageddon.csproj" />
<ProjectReference Include="..\..\library\Syroot.Worms.Mgame\Syroot.Worms.Mgame.csproj" />