1
0
mirror of https://gitlab.com/Syroot/Worms.git synced 2025-04-10 11:20:05 +03:00

Added support for ST1 team files.

This commit is contained in:
Ray Koopa 2017-04-23 16:40:40 +02:00
parent cf37f99ece
commit 21b48ad76b
6 changed files with 389 additions and 5 deletions

@ -34,7 +34,7 @@ Formats of the second generation 2D games are mostly focused right now.
| Scheme | WSC | WA, WWP | Yes | Yes |
| Scheme Options | OPT | W2 | Yes | Yes |
| Scheme Weapons | WEP | W2 | Yes | Yes |
| Team Container | ST1 | W2 | No | No |
| Team Container | ST1 | W2 | Yes | Yes |
| Team Container | WGT | WA, WWP | No | No |
## Third Generation (3D)

@ -0,0 +1,25 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Syroot.Worms.Gen2.Worms2;
using Syroot.Worms.UnitTest.Common;
namespace Syroot.Worms.UnitTest.Gen2.Worms2
{
/// <summary>
/// Represents a collection of tests for the <see cref="TeamContainer"/> class.
/// </summary>
[TestCategory("TeamContainer (Worms2)")]
[TestClass]
public class TeamContainerTests
{
// ---- METHODS (PUBLIC) ---------------------------------------------------------------------------------------
/// <summary>
/// Loads all files found in any game directories.
/// </summary>
[TestMethod]
public void LoadTeamContainers()
{
TestHelpers.LoadFiles<TeamContainer>(Game.Worms2, "*.st1");
}
}
}

@ -1,6 +1,6 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using Syroot.IO;
namespace Syroot.Worms.Core
{

@ -9,7 +9,7 @@ namespace Syroot.Worms.Core
internal static class BinaryWriterExtensions
{
// ---- METHODS (INTERNAL) -------------------------------------------------------------------------------------
/// <summary>
/// Writes the bytes of a structure into the current stream.
/// </summary>

@ -0,0 +1,142 @@
using System;
namespace Syroot.Worms.Gen2.Worms2
{
/// <summary>
/// Represents a team stored in a <see cref="TeamContainer"/> file.
/// </summary>
public struct Team
{
// ---- PROPERTIES ---------------------------------------------------------------------------------------------
public short Unknown1;
/// <summary>
/// The name of the team.
/// </summary>
public string Name;
/// <summary>
/// The name of soundbank for the voice of team worms.
/// </summary>
public string SoundBankName;
/// <summary>
/// The name of the first worm.
/// </summary>
public string Worm1Name;
/// <summary>
/// The name of the second worm.
/// </summary>
public string Worm2Name;
/// <summary>
/// The name of the third worm.
/// </summary>
public string Worm3Name;
/// <summary>
/// The name the fourth worm.
/// </summary>
public string Worm4Name;
/// <summary>
/// The name the fifth worm.
/// </summary>
public string Worm5Name;
/// <summary>
/// The name the second worm.
/// </summary>
public string Worm6Name;
/// <summary>
/// The name the seventh worm.
/// </summary>
public string Worm7Name;
/// <summary>
/// The name the eighth worm.
/// </summary>
public string Worm8Name;
/// <summary>
/// The number of games lost.
/// </summary>
public int GamesLost;
/// <summary>
/// The number of games won.
/// </summary>
public int GamesWon;
/// <summary>
/// The number of opponent worms killed by this team.
/// </summary>
public int WormsKilled;
/// <summary>
/// The number of worms which got killed in this team.
/// </summary>
public int WormsLost;
/// <summary>
/// The AI intelligence, from 0-64, where 0 is human-controlled.
/// </summary>
public int CpuLevel;
public int KillsKilled;
/// <summary>
/// The number of games played, always being 0 for AI controlled teams.
/// </summary>
public int GamesPlayed;
public int Unknown2;
public int Unknown3;
public int Unknown4;
public int Unknown5;
public int Unknown6;
public int Unknown7;
public int Unknown8;
public int Unknown9;
public int Unknown10;
public int Unknown11;
public int Unknown12;
public int Unknown13;
public int Unknown14;
public int Unknown15;
public int Unknown16;
public int Unknown17;
public int Unknown18;
public int Unknown19;
public int Unknown20;
public int Unknown21;
public int Unknown22;
/// <summary>
/// The number of hits goaled by this team.
/// </summary>
public int Hits;
/// <summary>
/// The number of hits by others on this team.
/// </summary>
public int HitsByOthers;
public int Unknown23;
public int Unknown24;
public int Unknown25;
public int Unknown26;
public int Difference;
public int Unknown27;
/// <summary>
/// The points gained by this team.
/// </summary>
public int Points;
}
}

@ -1,10 +1,227 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using Syroot.IO;
using Syroot.Maths;
using Syroot.Worms.Core;
namespace Syroot.Worms.Gen2.Worms2
{
class TeamContainer
/// <summary>
/// Represents the list of teams stored in ST1 files.
/// Used by W2. S. https://worms2d.info/Worms_2_team_file.
/// </summary>
public class TeamContainer : ILoadableFile, ISaveableFile
{
// ---- CONSTANTS ----------------------------------------------------------------------------------------------
private static readonly char[] _trimChars = new char[] { (char)0x00 };
// ---- CONSTRUCTORS & DESTRUCTOR ------------------------------------------------------------------------------
/// <summary>
/// Initializes a new instance of the <see cref="TeamContainer"/> class.
/// </summary>
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);
}
/// <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);
}
// ---- PROPERTIES ---------------------------------------------------------------------------------------------
/// <summary>
/// Gets or sets the list of <see cref="Team"/> instances stored.
/// </summary>
public List<Team> Teams { get; set; }
// ---- METHODS (PUBLIC) ---------------------------------------------------------------------------------------
/// <summary>
/// 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)
{
using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true))
{
Teams = new List<Team>();
while (!reader.EndOfStream)
{
Teams.Add(new Team()
{
Unknown1 = reader.ReadInt16(),
Name = ReadFixedString(reader, 66),
SoundBankName = ReadFixedString(reader, 36),
Worm1Name = ReadFixedString(reader, 20),
Worm2Name = ReadFixedString(reader, 20),
Worm3Name = ReadFixedString(reader, 20),
Worm4Name = ReadFixedString(reader, 20),
Worm5Name = ReadFixedString(reader, 20),
Worm6Name = ReadFixedString(reader, 20),
Worm7Name = ReadFixedString(reader, 20),
Worm8Name = ReadFixedString(reader, 20),
GamesLost = reader.ReadInt32(),
GamesWon = reader.ReadInt32(),
WormsKilled = reader.ReadInt32(),
WormsLost = reader.ReadInt32(),
CpuLevel = reader.ReadInt32(),
KillsKilled = reader.ReadInt32(),
GamesPlayed = reader.ReadInt32(),
Unknown2 = reader.ReadInt32(),
Unknown3 = reader.ReadInt32(),
Unknown4 = reader.ReadInt32(),
Unknown5 = reader.ReadInt32(),
Unknown6 = reader.ReadInt32(),
Unknown7 = reader.ReadInt32(),
Unknown8 = reader.ReadInt32(),
Unknown9 = reader.ReadInt32(),
Unknown10 = reader.ReadInt32(),
Unknown11 = reader.ReadInt32(),
Unknown12 = reader.ReadInt32(),
Unknown13 = reader.ReadInt32(),
Unknown14 = reader.ReadInt32(),
Unknown15 = reader.ReadInt32(),
Unknown16 = reader.ReadInt32(),
Unknown17 = reader.ReadInt32(),
Unknown18 = reader.ReadInt32(),
Unknown19 = reader.ReadInt32(),
Unknown20 = reader.ReadInt32(),
Unknown21 = reader.ReadInt32(),
Unknown22 = reader.ReadInt32(),
Hits = reader.ReadInt32(),
HitsByOthers = reader.ReadInt32(),
Unknown23 = reader.ReadInt32(),
Unknown24 = reader.ReadInt32(),
Unknown25 = reader.ReadInt32(),
Unknown26 = reader.ReadInt32(),
Difference = reader.ReadInt32(),
Unknown27 = reader.ReadInt32(),
Points = reader.ReadInt32()
});
}
}
}
/// <summary>
/// Loads the data from the given file.
/// </summary>
/// <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))
{
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)
{
using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII))
{
foreach (Team team in Teams)
{
writer.Write(team.Unknown1);
WriteFixedString(writer, team.Name, 66);
WriteFixedString(writer, team.SoundBankName, 36);
WriteFixedString(writer, team.Worm1Name, 20);
WriteFixedString(writer, team.Worm2Name, 20);
WriteFixedString(writer, team.Worm3Name, 20);
WriteFixedString(writer, team.Worm4Name, 20);
WriteFixedString(writer, team.Worm5Name, 20);
WriteFixedString(writer, team.Worm6Name, 20);
WriteFixedString(writer, team.Worm7Name, 20);
WriteFixedString(writer, team.Worm8Name, 20);
writer.Write(team.GamesLost);
writer.Write(team.GamesWon);
writer.Write(team.WormsKilled);
writer.Write(team.WormsLost);
writer.Write(team.CpuLevel);
writer.Write(team.KillsKilled);
writer.Write(team.GamesPlayed);
writer.Write(team.Unknown2);
writer.Write(team.Unknown3);
writer.Write(team.Unknown4);
writer.Write(team.Unknown5);
writer.Write(team.Unknown6);
writer.Write(team.Unknown7);
writer.Write(team.Unknown8);
writer.Write(team.Unknown9);
writer.Write(team.Unknown10);
writer.Write(team.Unknown11);
writer.Write(team.Unknown12);
writer.Write(team.Unknown13);
writer.Write(team.Unknown14);
writer.Write(team.Unknown15);
writer.Write(team.Unknown16);
writer.Write(team.Unknown17);
writer.Write(team.Unknown18);
writer.Write(team.Unknown19);
writer.Write(team.Unknown20);
writer.Write(team.Unknown21);
writer.Write(team.Unknown22);
writer.Write(team.Hits);
writer.Write(team.HitsByOthers);
writer.Write(team.Unknown23);
writer.Write(team.Unknown24);
writer.Write(team.Unknown25);
writer.Write(team.Unknown26);
writer.Write(team.Difference);
writer.Write(team.Unknown27);
writer.Write(team.Points);
}
}
}
/// <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)
{
using (FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
{
Save(stream);
}
}
// ---- METHODS (PRIVATE) --------------------------------------------------------------------------------------
private static string ReadFixedString(BinaryDataReader reader, int length)
{
string str = reader.ReadString(BinaryStringFormat.ZeroTerminated);
reader.Seek(length - str.Length - 1);
return str;
}
private static void WriteFixedString(BinaryDataWriter writer, string value, int length)
{
byte[] bytes = writer.Encoding.GetBytes(value);
writer.Write(bytes);
writer.Write(new byte[length - bytes.Length]);
}
}
}