Skip to content

Commit

Permalink
Revert "Update UTMT submodule, replace imagesharp with imagemagick.net"
Browse files Browse the repository at this point in the history
This reverts commit 15cc72b.
  • Loading branch information
Miepee committed Aug 30, 2024
1 parent 939acf3 commit b4fad0b
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 40 deletions.
2 changes: 1 addition & 1 deletion UndertaleModTool
1 change: 1 addition & 0 deletions YAMS-LIB/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Globalization;
using System.Reflection;
using System.Text.Json;
using SixLabors.ImageSharp.Processing;
using UndertaleModLib;
using UndertaleModLib.Decompiler;
using UndertaleModLib.Models;
Expand Down
1 change: 1 addition & 0 deletions YAMS-LIB/YAMS-LIB.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

<ItemGroup>
<PackageReference Include="Macross.Json.Extensions" Version="3.0.0"/>
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.4"/>
<PackageReference Include="NaturalSort.Extension" Version="4.3.0" />
</ItemGroup>

Expand Down
41 changes: 20 additions & 21 deletions YAMS-LIB/patches/CosmeticRotation.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using ImageMagick;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.Processing;
using UndertaleModLib;
using UndertaleModLib.Decompiler;
using UndertaleModLib.Models;
using UndertaleModLib.Util;

namespace YAMS_LIB.patches;

Expand Down Expand Up @@ -252,25 +253,23 @@ public class CosmeticRotation
"bgWFilter2",
];

static void RotateTextureAndSaveToTexturePage(UndertaleEmbeddedTexture texture, List<Tuple<MagickGeometry, int>> rectangleRotationTuple)
static void RotateTextureAndSaveToTexturePage(UndertaleEmbeddedTexture texture, List<Tuple<Rectangle, int>> rectangleRotationTuple)
{
using MagickImage texturePage = texture.TextureData.Image.GetMagickImage();
using Image texturePage = Image.Load(texture.TextureData.TextureBlob);
foreach ((var rectangle, var rotation) in rectangleRotationTuple)
{
using var mask = new MagickImage(MagickColors.White, texturePage.Width, texturePage.Height);
mask.Draw(new DrawableFillColor(MagickColors.Black), new DrawableRectangle(rectangle.X, rectangle.Y, rectangle.X+rectangle.Width, rectangle.Y+rectangle.Height));
texturePage.SetWriteMask(mask);
texturePage.Modulate((Percentage)100.0, (Percentage)100.0, (Percentage)((rotation * 100 / 180) + 100));
texturePage.RemoveWriteMask();
texturePage.Mutate(im => im.Hue(rotation, rectangle));
}

texture.TextureData.Image = GMImage.FromPng(texturePage.ToByteArray(MagickFormat.Png));
using MemoryStream ms = new MemoryStream();
texturePage.Save(ms, PngFormat.Instance);
texture.TextureData.TextureBlob = ms.ToArray();
}


public static void Apply(UndertaleData gmData, GlobalDecompileContext decompileContext, SeedObject seedObject)
{
var textureDict = new Dictionary<UndertaleEmbeddedTexture, List<Tuple<MagickGeometry, int>>>();
var textureDict = new Dictionary<UndertaleEmbeddedTexture, List<Tuple<Rectangle, int>>>();

// TODO: less copypaste
// Hue shift etanks
Expand All @@ -281,8 +280,8 @@ public static void Apply(UndertaleData gmData, GlobalDecompileContext decompileC
var texture = textureEntry.Texture;
bool wasInDict = textureDict.TryGetValue(texture.TexturePage, out var tupleList);
if (tupleList is null)
tupleList = new List<Tuple<MagickGeometry, int>>();
tupleList.Add(new Tuple<MagickGeometry, int>(new MagickGeometry(texture.SourceX, texture.SourceY, texture.SourceWidth, texture.SourceHeight),
tupleList = new List<Tuple<Rectangle, int>>();
tupleList.Add(new Tuple<Rectangle, int>(new Rectangle(texture.SourceX, texture.SourceY, texture.SourceWidth, texture.SourceHeight),
seedObject.Cosmetics.EtankHUDRotation));
if (!wasInDict)
textureDict.Add(texture.TexturePage, null);
Expand All @@ -299,8 +298,8 @@ public static void Apply(UndertaleData gmData, GlobalDecompileContext decompileC
var texture = textureEntry.Texture;
bool wasInDict = textureDict.TryGetValue(texture.TexturePage, out var tupleList);
if (tupleList is null)
tupleList = new List<Tuple<MagickGeometry, int>>();
tupleList.Add(new Tuple<MagickGeometry, int>(new MagickGeometry(texture.SourceX, texture.SourceY, texture.SourceWidth, texture.SourceHeight),
tupleList = new List<Tuple<Rectangle, int>>();
tupleList.Add(new Tuple<Rectangle, int>(new Rectangle(texture.SourceX, texture.SourceY, texture.SourceWidth, texture.SourceHeight),
seedObject.Cosmetics.HealthHUDRotation));
if (!wasInDict)
textureDict.Add(texture.TexturePage, null);
Expand All @@ -317,8 +316,8 @@ public static void Apply(UndertaleData gmData, GlobalDecompileContext decompileC
var texture = bg.Texture;
bool wasInDict = textureDict.TryGetValue(texture.TexturePage, out var tupleList);
if (tupleList is null)
tupleList = new List<Tuple<MagickGeometry, int>>();
tupleList.Add(new Tuple<MagickGeometry, int>(new MagickGeometry(texture.SourceX, texture.SourceY, texture.SourceWidth, texture.SourceHeight),
tupleList = new List<Tuple<Rectangle, int>>();
tupleList.Add(new Tuple<Rectangle, int>(new Rectangle(texture.SourceX, texture.SourceY, texture.SourceWidth, texture.SourceHeight),
seedObject.Cosmetics.DNAHUDRotation));
if (!wasInDict)
textureDict.Add(texture.TexturePage, null);
Expand All @@ -335,8 +334,8 @@ public static void Apply(UndertaleData gmData, GlobalDecompileContext decompileC
var texture = bg.Texture;
bool wasInDict = textureDict.TryGetValue(texture.TexturePage, out var tupleList);
if (tupleList is null)
tupleList = new List<Tuple<MagickGeometry, int>>();
tupleList.Add(new Tuple<MagickGeometry, int>(new MagickGeometry(texture.SourceX, texture.SourceY, texture.SourceWidth, texture.SourceHeight),
tupleList = new List<Tuple<Rectangle, int>>();
tupleList.Add(new Tuple<Rectangle, int>(new Rectangle(texture.SourceX, texture.SourceY, texture.SourceWidth, texture.SourceHeight),
seedObject.Cosmetics.TilesetRotation));
if (!wasInDict)
textureDict.Add(texture.TexturePage, null);
Expand All @@ -353,8 +352,8 @@ public static void Apply(UndertaleData gmData, GlobalDecompileContext decompileC
var texture = bg.Texture;
bool wasInDict = textureDict.TryGetValue(texture.TexturePage, out var tupleList);
if (tupleList is null)
tupleList = new List<Tuple<MagickGeometry, int>>();
tupleList.Add(new Tuple<MagickGeometry, int>(new MagickGeometry(texture.SourceX, texture.SourceY, texture.SourceWidth, texture.SourceHeight),
tupleList = new List<Tuple<Rectangle, int>>();
tupleList.Add(new Tuple<Rectangle, int>(new Rectangle(texture.SourceX, texture.SourceY, texture.SourceWidth, texture.SourceHeight),
seedObject.Cosmetics.BackgroundRotation));
if (!wasInDict)
textureDict.Add(texture.TexturePage, null);
Expand Down
41 changes: 23 additions & 18 deletions YAMS-LIB/patches/Sprites.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System.Reflection;
using System.Text.Json;
using ImageMagick;
using NaturalSort.Extension;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.Processing;
using UndertaleModLib;
using UndertaleModLib.Decompiler;
using UndertaleModLib.Models;
using UndertaleModLib.Util;

namespace YAMS_LIB.patches;

Expand All @@ -17,11 +18,13 @@ public static void Apply(UndertaleData gmData, GlobalDecompileContext decompileC
var nameToPageItemDict = new Dictionary<string, int>();
UndertaleEmbeddedTexture? utTexturePage = new UndertaleEmbeddedTexture();

using var texturePage = new MagickImage(new FileInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "/sprites/texturepage.png"));
using (MemoryStream ms = new MemoryStream())
{
var texturePage = Image.Load(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "/sprites/texturepage.png");
utTexturePage.TextureWidth = texturePage.Width;
utTexturePage.TextureHeight = texturePage.Height;
utTexturePage.TextureData = new UndertaleEmbeddedTexture.TexData { Image = GMImage.FromPng(texturePage.ToByteArray(MagickFormat.Png)) };
texturePage.Save(ms, PngFormat.Instance);
utTexturePage.TextureData = new UndertaleEmbeddedTexture.TexData { TextureBlob = ms.ToArray() };
}
gmData.EmbeddedTextures.Add(utTexturePage);

Expand All @@ -41,25 +44,27 @@ public static void Apply(UndertaleData gmData, GlobalDecompileContext decompileC
// Replace A4 doors
{
UndertaleTexturePageItem? a4DoorTex = gmData.TexturePageItems[nameToPageItemDict["newA4Doors"]];
using var a4DoorImage = a4DoorTex.TexturePage.TextureData.Image.GetMagickImage();
Image a4DoorImage = Image.Load(a4DoorTex.TexturePage.TextureData.TextureBlob);
a4DoorImage.Mutate(i => i.Crop(new Rectangle(a4DoorTex.SourceX, a4DoorTex.SourceY, a4DoorTex.SourceWidth, a4DoorTex.SourceHeight)));
UndertaleTexturePageItem? a4Tex = gmData.Backgrounds.ByName("tlArea4Tech").Texture;
Image a4PageImage = Image.Load(a4Tex.TexturePage.TextureData.TextureBlob);
a4PageImage.Mutate(i => i.DrawImage(a4DoorImage, new Point(a4Tex.SourceX + 104, a4Tex.SourceY), 1));
using (MemoryStream ms = new MemoryStream())
{
a4DoorImage.Crop(new MagickGeometry(a4DoorTex.SourceX, a4DoorTex.SourceY, a4DoorTex.SourceWidth, a4DoorTex.SourceHeight));
a4DoorImage.RePage();
UndertaleTexturePageItem? a4Tex = gmData.Backgrounds.ByName("tlArea4Tech").Texture;
using var a4PageImage = a4Tex.TexturePage.TextureData.Image.GetMagickImage();
a4PageImage.Composite(a4DoorImage, a4Tex.SourceX + 104, a4Tex.SourceY, CompositeOperator.Over);
a4Tex.TexturePage.TextureData.Image = GMImage.FromPng(a4PageImage.ToByteArray(MagickFormat.Png));
a4PageImage.Save(ms, PngFormat.Instance);
a4Tex.TexturePage.TextureData.TextureBlob = ms.ToArray();
}

UndertaleTexturePageItem? a4door2Tex = gmData.TexturePageItems[nameToPageItemDict["newA4Doors2"]];
using var a4Door2Image = a4door2Tex.TexturePage.TextureData.Image.GetMagickImage();
Image a4Door2Image = Image.Load(a4door2Tex.TexturePage.TextureData.TextureBlob);
a4Door2Image.Mutate(i => i.Crop(new Rectangle(a4door2Tex.SourceX, a4door2Tex.SourceY, a4door2Tex.SourceWidth, a4door2Tex.SourceHeight)));
UndertaleTexturePageItem? a4Tex2 = gmData.Backgrounds.ByName("tlArea4Tech2").Texture;
Image a4Page2Image = Image.Load(a4Tex2.TexturePage.TextureData.TextureBlob);
a4Page2Image.Mutate(i => i.DrawImage(a4Door2Image, new Point(a4Tex2.SourceX + 104, a4Tex2.SourceY), 1));
using (MemoryStream ms = new MemoryStream())
{
a4Door2Image.Crop(new MagickGeometry(a4door2Tex.SourceX, a4door2Tex.SourceY, a4door2Tex.SourceWidth, a4door2Tex.SourceHeight));
a4Door2Image.RePage();
UndertaleTexturePageItem? a4Tex2 = gmData.Backgrounds.ByName("tlArea4Tech2").Texture;
using var a4Page2Image = a4Tex2.TexturePage.TextureData.Image.GetMagickImage();
a4Page2Image.Composite(a4Door2Image, a4Tex2.SourceX + 104, a4Tex2.SourceY, CompositeOperator.Over);
a4Tex2.TexturePage.TextureData.Image = GMImage.FromPng(a4Page2Image.ToByteArray(MagickFormat.Png));
a4Page2Image.Save(ms, PngFormat.Instance);
a4Tex2.TexturePage.TextureData.TextureBlob = ms.ToArray();
}
}

Expand Down

0 comments on commit b4fad0b

Please sign in to comment.