# HG changeset patch
# User Trillster
# Date 1709873457 18000
#      Thu Mar 07 23:50:57 2024 -0500
# Node ID 1969bb926641d9a9615ae228412fa0d288c9b637
# Parent  2f59d4a1f4d10d32e639890b6963fe96620512d8
Fixed: Non-standard player classes can cause "eaten" skins and crashes.

diff -r 2f59d4a1f4d1 -r 1969bb926641 docs/zandronum-history.txt
--- a/docs/zandronum-history.txt	Mon Mar 04 09:34:51 2024 -0600
+++ b/docs/zandronum-history.txt	Thu Mar 07 23:50:57 2024 -0500
@@ -133,6 +133,7 @@
 -	- Fixed: STRFTIME would crash Zandronum if a negative was passed into the first argument (addresses 4144). [Ru5tK1ng]
 -	- Fixed: the server would freeze after running for long enough (e.g. 24 days on Windows) due to an integer overflow in SERVER_Tick. [Kaminsky]
 -	- Fixed: the SendToCommunicator special didn't stop the previous sound when online. [DrinkyBird]
+-	- Fixed: Non-standard player classes can cause "eaten" skins and crashes. [Trillster]
 !	- The result value of GAMEEVENT_MEDALS event scripts can now be used to determine whether or not the player receives the medal. [Kaminsky]
 !	- GAMEMODE flags are now validated after all GAMEMODE lumps have been parsed instead of after each one. The internal game mode name (e.g. "TeamLMS") is now printed with the error message instead of the actual name. [Kaminsky]
 !	- Added an extra check to ensure that game modes have a (short) name. [Kaminsky]
diff -r 2f59d4a1f4d1 -r 1969bb926641 src/r_data/sprites.cpp
--- a/src/r_data/sprites.cpp	Mon Mar 04 09:34:51 2024 -0600
+++ b/src/r_data/sprites.cpp	Thu Mar 07 23:50:57 2024 -0500
@@ -551,6 +551,9 @@
 		R_CreateSkin();
 		i++;
 
+		// [TRSR] Track how many skins have been created to validate removal.
+		int skinsCreated = 1;
+
 		FScanner sc(base);
 
 		// Data is stored as "key = data".
@@ -576,6 +579,7 @@
 				{
 					R_CreateSkin();
 					i++; // new skin
+					skinsCreated++;
 				}
 				if(s_skin != 2) // If this is at S_SKIN unchangeable then no nothing else get a new string.
 					sc.GetString();
@@ -907,8 +911,11 @@
 				}
 			}
 
-			if (remove)
+			// [TRSR] Only remove skins if we've previously created any.
+			// Otherwise it'll eat into other files' or classes' skins!
+			if (remove && skinsCreated > 0)
 			{
+				skinsCreated--;
 				skins.Delete(i);
 				i--;
 				continue;
