Rewrite logic of parsing Scheme object count and type.

Mirrors frontend logic more closely now without the need for static lookup arrays.
This commit is contained in:
Ray Koopa 2020-06-26 19:00:55 +02:00
parent 57815e9072
commit 26a9125f0a
3 changed files with 2448 additions and 2756 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,71 +1,94 @@
using System; using System;
using System.Drawing.Imaging; using System.Collections.Generic;
using System.IO; using System.Drawing.Imaging;
using Syroot.Worms.Mgame; using System.IO;
using Syroot.Worms.Armageddon;
namespace Syroot.Worms.Scratchpad using Syroot.Worms.Mgame;
{
internal class Program namespace Syroot.Worms.Scratchpad
{ {
// ---- METHODS (PRIVATE) -------------------------------------------------------------------------------------- internal class Program
{
private static void Main(string[] args) // ---- METHODS (PRIVATE) --------------------------------------------------------------------------------------
{
} private static void Main()
{
private static void ConvertIgdImages() IEnumerable<string> fileNames = Directory.EnumerateFiles(
{ @"C:\Games\Worms Armageddon 3.7.2.1\User\Schemes", "*.wsc", SearchOption.AllDirectories);
string igdFolder = @"C:\Games\WWP Aqua\Images";
string pngFolder = @"D:\Pictures\IGD"; foreach (string fileName in fileNames)
Directory.CreateDirectory(pngFolder); {
string tempFile = Path.GetTempFileName();
foreach (string igdFilePath in Directory.GetFiles(igdFolder, "*.igd", SearchOption.AllDirectories)) using (Stream tempStream = new FileStream(tempFile, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
{ {
// Load the scheme and save it to temp file.
// Load the IGD and let it convert the images. Scheme origScheme = new Scheme(fileName);
Igd igd = new Igd(igdFilePath); tempStream.Position = 0;
origScheme.Save(tempStream);
// Save the images in the output folder under a relative path.
string igdFileFolder = Path.GetDirectoryName(igdFilePath); // Load the temp file.
string relativePath = igdFileFolder.Substring(igdFolder.Length).TrimStart(Path.DirectorySeparatorChar); tempStream.Position = 0;
string pngIgdFolder = Path.Combine(pngFolder, relativePath, Path.GetFileName(igdFilePath)); Scheme newScheme = new Scheme(tempStream);
Directory.CreateDirectory(pngIgdFolder);
for (int i = 0; i < igd.Images.Count; i++) if (origScheme.ObjectCount != newScheme.ObjectCount || origScheme.ObjectTypes != newScheme.ObjectTypes)
{ throw new InvalidOperationException("mismatch");
string pngFileName = Path.ChangeExtension(i.ToString(), "png"); }
IgdImage image = igd.Images[i]; File.Delete(tempFile);
image.RawBitmap.ToBitmap().Save(Path.Combine(pngIgdFolder, pngFileName), ImageFormat.Png); }
} }
}
} private static void ConvertIgdImages()
{
private static void ConvertKsfImages() string igdFolder = @"C:\Games\WWP Aqua\Images";
{ string pngFolder = @"D:\Pictures\IGD";
string ksfFolder = @"C:\Games\Online Worms\Ksf"; Directory.CreateDirectory(pngFolder);
string palFolder = @"C:\Games\Online Worms\Palette";
string pngFolder = @"D:\Pictures\KSF"; foreach (string igdFilePath in Directory.GetFiles(igdFolder, "*.igd", SearchOption.AllDirectories))
Directory.CreateDirectory(pngFolder); {
Palette fallbackPalette = new Palette(Path.Combine(palFolder, "StaticImage.pal")); // Load the IGD and let it convert the images.
Igd igd = new Igd(igdFilePath);
foreach (string ksfFilePath in Directory.GetFiles(ksfFolder, "*.ksf"))
{ // Save the images in the output folder under a relative path.
// Try to find a palette for every KSF, otherwise use fallback palette. string igdFileFolder = Path.GetDirectoryName(igdFilePath);
string ksfFileName = Path.GetFileName(ksfFilePath); string relativePath = igdFileFolder.Substring(igdFolder.Length).TrimStart(Path.DirectorySeparatorChar);
string palFilePath = Path.Combine(palFolder, Path.ChangeExtension(ksfFileName, "pal")); string pngIgdFolder = Path.Combine(pngFolder, relativePath, Path.GetFileName(igdFilePath));
Palette palette = File.Exists(palFilePath) ? new Palette(palFilePath) : fallbackPalette; Directory.CreateDirectory(pngIgdFolder);
for (int i = 0; i < igd.Images.Count; i++)
// Load the KSF and let it convert the images. {
Ksf ksf = new Ksf(ksfFilePath, palette); string pngFileName = Path.ChangeExtension(i.ToString(), "png");
IgdImage image = igd.Images[i];
// Save the images in the output folder. image.RawBitmap.ToBitmap().Save(Path.Combine(pngIgdFolder, pngFileName), ImageFormat.Png);
string pngKsfFolder = Path.Combine(pngFolder, ksfFileName); }
Directory.CreateDirectory(pngKsfFolder); }
for (int i = 0; i < ksf.Images.Count; i++) }
{
string pngFileName = Path.ChangeExtension(i.ToString(), "png"); private static void ConvertKsfImages()
ksf.Images[i].RawBitmap?.ToBitmap().Save(Path.Combine(pngKsfFolder, pngFileName), ImageFormat.Png); {
} string ksfFolder = @"C:\Games\Online Worms\Ksf";
} string palFolder = @"C:\Games\Online Worms\Palette";
} string pngFolder = @"D:\Pictures\KSF";
} Directory.CreateDirectory(pngFolder);
Palette fallbackPalette = new Palette(Path.Combine(palFolder, "StaticImage.pal"));
foreach (string ksfFilePath in Directory.GetFiles(ksfFolder, "*.ksf"))
{
// Try to find a palette for every KSF, otherwise use fallback palette.
string ksfFileName = Path.GetFileName(ksfFilePath);
string palFilePath = Path.Combine(palFolder, Path.ChangeExtension(ksfFileName, "pal"));
Palette palette = File.Exists(palFilePath) ? new Palette(palFilePath) : fallbackPalette;
// Load the KSF and let it convert the images.
Ksf ksf = new Ksf(ksfFilePath, palette);
// Save the images in the output folder.
string pngKsfFolder = Path.Combine(pngFolder, ksfFileName);
Directory.CreateDirectory(pngKsfFolder);
for (int i = 0; i < ksf.Images.Count; i++)
{
string pngFileName = Path.ChangeExtension(i.ToString(), "png");
ksf.Images[i].RawBitmap?.ToBitmap().Save(Path.Combine(pngKsfFolder, pngFileName), ImageFormat.Png);
}
}
}
}
} }