mirror of
https://gitlab.com/Syroot/Worms.git
synced 2025-01-13 07:18:00 +03:00
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:
parent
57815e9072
commit
26a9125f0a
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,71 +1,94 @@
|
||||
using System;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using Syroot.Worms.Mgame;
|
||||
|
||||
namespace Syroot.Worms.Scratchpad
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
// ---- METHODS (PRIVATE) --------------------------------------------------------------------------------------
|
||||
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
}
|
||||
|
||||
private static void ConvertIgdImages()
|
||||
{
|
||||
string igdFolder = @"C:\Games\WWP Aqua\Images";
|
||||
string pngFolder = @"D:\Pictures\IGD";
|
||||
Directory.CreateDirectory(pngFolder);
|
||||
|
||||
foreach (string igdFilePath in Directory.GetFiles(igdFolder, "*.igd", SearchOption.AllDirectories))
|
||||
{
|
||||
|
||||
// Load the IGD and let it convert the images.
|
||||
Igd igd = new Igd(igdFilePath);
|
||||
|
||||
// Save the images in the output folder under a relative path.
|
||||
string igdFileFolder = Path.GetDirectoryName(igdFilePath);
|
||||
string relativePath = igdFileFolder.Substring(igdFolder.Length).TrimStart(Path.DirectorySeparatorChar);
|
||||
string pngIgdFolder = Path.Combine(pngFolder, relativePath, Path.GetFileName(igdFilePath));
|
||||
Directory.CreateDirectory(pngIgdFolder);
|
||||
for (int i = 0; i < igd.Images.Count; i++)
|
||||
{
|
||||
string pngFileName = Path.ChangeExtension(i.ToString(), "png");
|
||||
IgdImage image = igd.Images[i];
|
||||
image.RawBitmap.ToBitmap().Save(Path.Combine(pngIgdFolder, pngFileName), ImageFormat.Png);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void ConvertKsfImages()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using Syroot.Worms.Armageddon;
|
||||
using Syroot.Worms.Mgame;
|
||||
|
||||
namespace Syroot.Worms.Scratchpad
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
// ---- METHODS (PRIVATE) --------------------------------------------------------------------------------------
|
||||
|
||||
private static void Main()
|
||||
{
|
||||
IEnumerable<string> fileNames = Directory.EnumerateFiles(
|
||||
@"C:\Games\Worms Armageddon 3.7.2.1\User\Schemes", "*.wsc", SearchOption.AllDirectories);
|
||||
|
||||
foreach (string fileName in fileNames)
|
||||
{
|
||||
string tempFile = Path.GetTempFileName();
|
||||
using (Stream tempStream = new FileStream(tempFile, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
|
||||
{
|
||||
// Load the scheme and save it to temp file.
|
||||
Scheme origScheme = new Scheme(fileName);
|
||||
tempStream.Position = 0;
|
||||
origScheme.Save(tempStream);
|
||||
|
||||
// Load the temp file.
|
||||
tempStream.Position = 0;
|
||||
Scheme newScheme = new Scheme(tempStream);
|
||||
|
||||
if (origScheme.ObjectCount != newScheme.ObjectCount || origScheme.ObjectTypes != newScheme.ObjectTypes)
|
||||
throw new InvalidOperationException("mismatch");
|
||||
}
|
||||
File.Delete(tempFile);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ConvertIgdImages()
|
||||
{
|
||||
string igdFolder = @"C:\Games\WWP Aqua\Images";
|
||||
string pngFolder = @"D:\Pictures\IGD";
|
||||
Directory.CreateDirectory(pngFolder);
|
||||
|
||||
foreach (string igdFilePath in Directory.GetFiles(igdFolder, "*.igd", SearchOption.AllDirectories))
|
||||
{
|
||||
// Load the IGD and let it convert the images.
|
||||
Igd igd = new Igd(igdFilePath);
|
||||
|
||||
// Save the images in the output folder under a relative path.
|
||||
string igdFileFolder = Path.GetDirectoryName(igdFilePath);
|
||||
string relativePath = igdFileFolder.Substring(igdFolder.Length).TrimStart(Path.DirectorySeparatorChar);
|
||||
string pngIgdFolder = Path.Combine(pngFolder, relativePath, Path.GetFileName(igdFilePath));
|
||||
Directory.CreateDirectory(pngIgdFolder);
|
||||
for (int i = 0; i < igd.Images.Count; i++)
|
||||
{
|
||||
string pngFileName = Path.ChangeExtension(i.ToString(), "png");
|
||||
IgdImage image = igd.Images[i];
|
||||
image.RawBitmap.ToBitmap().Save(Path.Combine(pngIgdFolder, pngFileName), ImageFormat.Png);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void ConvertKsfImages()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user