From c2b18a913ee048c2bb18bc27668eb501e7388f4d Mon Sep 17 00:00:00 2001
From: biwa <foracc@d00m.info>
Date: Sun, 16 Jun 2019 18:40:10 +0200
Subject: [PATCH] - Fixed a bug where textures for internal model skin names
 did not load when "Path" was specified in MODELDEF

---
 Source/Core/GZBuilder/Data/ModelData.cs  | 2 ++
 Source/Core/GZBuilder/md3/ModelReader.cs | 7 ++++++-
 Source/Core/ZDoom/ModeldefParser.cs      | 2 +-
 Source/Core/ZDoom/ModeldefStructure.cs   | 1 +
 4 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/Source/Core/GZBuilder/Data/ModelData.cs b/Source/Core/GZBuilder/Data/ModelData.cs
index 52b0d01f8..ff2f965ee 100755
--- a/Source/Core/GZBuilder/Data/ModelData.cs
+++ b/Source/Core/GZBuilder/Data/ModelData.cs
@@ -37,6 +37,7 @@ namespace CodeImp.DoomBuilder.GZBuilder.Data
 		internal List<Dictionary<int, string>> SurfaceSkinNames;
 		internal List<string> FrameNames;
 		internal List<int> FrameIndices;
+		internal string Path; // biwa
 
 		internal GZModel Model;
 
@@ -71,6 +72,7 @@ namespace CodeImp.DoomBuilder.GZBuilder.Data
 			SurfaceSkinNames = new List<Dictionary<int, string>>();
 			FrameNames = new List<string>();
 			FrameIndices = new List<int>();
+			Path = string.Empty;
 			transform = Matrix.Identity;
 			transformstretched = Matrix.Identity;
 			hashcode = hashcounter++;
diff --git a/Source/Core/GZBuilder/md3/ModelReader.cs b/Source/Core/GZBuilder/md3/ModelReader.cs
index 79ba3c955..87ab34ad6 100755
--- a/Source/Core/GZBuilder/md3/ModelReader.cs
+++ b/Source/Core/GZBuilder/md3/ModelReader.cs
@@ -185,7 +185,12 @@ namespace CodeImp.DoomBuilder.GZBuilder.MD3
 								continue;
 							}
 
-							Texture t = GetTexture(containers, result.Skins[m], device);
+							string path = result.Skins[m].Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
+
+							if(!String.IsNullOrEmpty(mde.Path))
+								path = Path.Combine(mde.Path, path);
+
+							Texture t = GetTexture(containers, path, device);
 
 							if(t == null)
 							{
diff --git a/Source/Core/ZDoom/ModeldefParser.cs b/Source/Core/ZDoom/ModeldefParser.cs
index a799d8572..7bd1a8210 100755
--- a/Source/Core/ZDoom/ModeldefParser.cs
+++ b/Source/Core/ZDoom/ModeldefParser.cs
@@ -187,7 +187,7 @@ namespace CodeImp.DoomBuilder.ZDoom
 								if(mds.Frames.ContainsKey(targetsprite))
 								{
 									// Create model data
-									ModelData md = new ModelData { InheritActorPitch = mds.InheritActorPitch, UseActorPitch = mds.UseActorPitch, UseActorRoll = mds.UseActorRoll };
+									ModelData md = new ModelData { InheritActorPitch = mds.InheritActorPitch, UseActorPitch = mds.UseActorPitch, UseActorRoll = mds.UseActorRoll, Path = mds.DataPath };
 
 									// Things are complicated in GZDoom...
 									Matrix moffset = Matrix.Translation(mds.Offset.Y, -mds.Offset.X, mds.Offset.Z);
diff --git a/Source/Core/ZDoom/ModeldefStructure.cs b/Source/Core/ZDoom/ModeldefStructure.cs
index af171e2fa..40fe2ca8c 100755
--- a/Source/Core/ZDoom/ModeldefStructure.cs
+++ b/Source/Core/ZDoom/ModeldefStructure.cs
@@ -63,6 +63,7 @@ namespace CodeImp.DoomBuilder.ZDoom
 		public bool InheritActorPitch { get { return inheritactorpitch; } }
 		public bool UseActorPitch { get { return useactorpitch; } }
 		public bool UseActorRoll { get { return useactorroll; } }
+		public string DataPath { get { return path; } } // biwa
 
 		public Dictionary<string, HashSet<FrameStructure>> Frames { get { return frames; } }
 
-- 
GitLab