From 085df399f5e2f428a64cc1468c3811aa449c4a09 Mon Sep 17 00:00:00 2001
From: biwa <6475593+biwa@users.noreply.github.com>
Date: Sat, 29 Jul 2023 13:32:42 +0200
Subject: [PATCH] Fixed an issue where sprite offsets defined in TEXTURES were
 not used

---
 Source/Core/Data/ImageData.cs                      |  4 ++++
 Source/Core/Data/SpriteImage.cs                    | 14 --------------
 Source/Core/Data/TEXTURESImage.cs                  |  4 +++-
 Source/Core/ZDoom/TextureStructure.cs              |  2 +-
 .../BuilderModes/VisualModes/BaseVisualThing.cs    |  8 ++------
 5 files changed, 10 insertions(+), 22 deletions(-)

diff --git a/Source/Core/Data/ImageData.cs b/Source/Core/Data/ImageData.cs
index 4c5f24c43..d39802d2e 100755
--- a/Source/Core/Data/ImageData.cs
+++ b/Source/Core/Data/ImageData.cs
@@ -48,6 +48,8 @@ namespace CodeImp.DoomBuilder.Data
 		protected long longname;
 		protected int width;
 		protected int height;
+		protected int offsetx;
+		protected int offsety;
 		protected Vector2D scale;
 		protected bool worldpanning;
 		private bool usecolorcorrection;
@@ -141,6 +143,8 @@ namespace CodeImp.DoomBuilder.Data
 		public int MipMapLevels { get { return mipmaplevels; } set { mipmaplevels = value; } }
 		public virtual int Width { get { return width; } }
 		public virtual int Height { get { return height; } }
+		public int OffsetX { get { return offsetx; } }
+		public int OffsetY { get { return offsety; } }
 		//mxd. Scaled texture size is integer in ZDoom.
 		public virtual float ScaledWidth { get { return (float)Math.Round(width * scale.x); } }
 		public virtual float ScaledHeight { get { return (float)Math.Round(height * scale.y); } }
diff --git a/Source/Core/Data/SpriteImage.cs b/Source/Core/Data/SpriteImage.cs
index 221cf0e7a..94c7ab173 100755
--- a/Source/Core/Data/SpriteImage.cs
+++ b/Source/Core/Data/SpriteImage.cs
@@ -35,20 +35,6 @@ namespace CodeImp.DoomBuilder.Data
 
 	public sealed class SpriteImage : ImageData, ISpriteImage
 	{
-		#region ================== Variables
-
-		private int offsetx;
-		private int offsety;
-		
-		#endregion
-
-		#region ================== Properties
-
-		public int OffsetX { get { return offsetx; } }
-		public int OffsetY { get { return offsety; } }
-		
-		#endregion
-		
 		#region ================== Constructor / Disposer
 
 		// Constructor
diff --git a/Source/Core/Data/TEXTURESImage.cs b/Source/Core/Data/TEXTURESImage.cs
index ac2fc2ea8..f15845ded 100755
--- a/Source/Core/Data/TEXTURESImage.cs
+++ b/Source/Core/Data/TEXTURESImage.cs
@@ -52,12 +52,14 @@ namespace CodeImp.DoomBuilder.Data
 		#region ================== Constructor / Disposer
 
 		// Constructor
-		public TEXTURESImage(string name, string virtualpath, int width, int height, float scalex, float scaley, 
+		public TEXTURESImage(string name, string virtualpath, int width, int height, int offsetx, int offsety, float scalex, float scaley, 
 			bool worldpanning, TextureNamespace texturenamespace, bool optional, bool nulltexture)
 		{
 			// Initialize
 			this.width = width;
 			this.height = height;
+			this.offsetx = offsetx;
+			this.offsety = offsety;
 			this.scale.x = scalex;
 			this.scale.y = scaley;
 			this.worldpanning = worldpanning;
diff --git a/Source/Core/ZDoom/TextureStructure.cs b/Source/Core/ZDoom/TextureStructure.cs
index 5c13de143..d9d332996 100755
--- a/Source/Core/ZDoom/TextureStructure.cs
+++ b/Source/Core/ZDoom/TextureStructure.cs
@@ -249,7 +249,7 @@ namespace CodeImp.DoomBuilder.ZDoom
 			float scaley = ((yscale == 0.0f) ? General.Map.Config.DefaultTextureScale : 1f / yscale);
 
 			// Make texture
-			TEXTURESImage tex = new TEXTURESImage(name, virtualpath, width, height, scalex, scaley, worldpanning, texturenamespace, optional, nulltexture);
+			TEXTURESImage tex = new TEXTURESImage(name, virtualpath, width, height, xoffset, yoffset, scalex, scaley, worldpanning, texturenamespace, optional, nulltexture);
 
 			// Add patches
 			foreach(PatchStructure p in patches) tex.AddPatch(new TexturePatch(p));//mxd
diff --git a/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs b/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs
index e8d6c8988..40e096d44 100755
--- a/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs
+++ b/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs
@@ -322,12 +322,8 @@ namespace CodeImp.DoomBuilder.BuilderModes
 					// Determine sprite size and offset
 					float radius = sprite.ScaledWidth * 0.5f;
 					float height = sprite.ScaledHeight;
-					ISpriteImage spriteimg = sprite as ISpriteImage;
-					if(spriteimg != null)
-					{
-						offsets.x = radius - spriteimg.OffsetX;
-						offsets.y = spriteimg.OffsetY - height;
-					}
+					offsets.x = radius - sprite.OffsetX;
+					offsets.y = sprite.OffsetY - height;
 
 					// Scale by thing type/actor scale
 					// We do this after the offset x/y determination above, because that is entirely in sprite pixels space
-- 
GitLab