From 8863e13fde2e2e1189185483aea4e033e67aa08c Mon Sep 17 00:00:00 2001
From: Jaime Passos <lazymyuutsu@gmail.com>
Date: Sat, 15 Aug 2020 20:14:36 -0300
Subject: [PATCH] Rename R_CheckIfPatch

---
 src/p_setup.c |  2 +-
 src/r_patch.c | 18 ++++++------------
 src/r_patch.h |  3 ++-
 3 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/src/p_setup.c b/src/p_setup.c
index 0105a06da..8d7904bb0 100644
--- a/src/p_setup.c
+++ b/src/p_setup.c
@@ -603,7 +603,7 @@ texturefound:
 	{
 flatfound:
 		/* This could be a flat, patch, or PNG. */
-		if (R_CheckIfPatch(flatnum))
+		if (Patch_CheckIfDoom((patch_t *)W_CacheLumpNum(flatnum, PU_STATIC), W_LumpLength(flatnum)))
 			levelflat->type = LEVELFLAT_PATCH;
 		else
 		{
diff --git a/src/r_patch.c b/src/r_patch.c
index 783c1fbec..9a5364f9a 100644
--- a/src/r_patch.c
+++ b/src/r_patch.c
@@ -143,29 +143,23 @@ void *Patch_CreateGL(patch_t *patch)
 #endif // HWRENDER
 
 //
-// R_CheckIfPatch
+// Patch_CheckIfDoom
 //
-// Returns true if the lump is a valid patch.
+// Returns true if the lump is a valid Doom patch.
 //
-boolean R_CheckIfPatch(lumpnum_t lump)
+boolean Patch_CheckIfDoom(softwarepatch_t *patch, size_t length)
 {
-	size_t size;
 	INT16 width, height;
-	patch_t *patch;
 	boolean result;
 
-	size = W_LumpLength(lump);
-
 	// minimum length of a valid Doom patch
-	if (size < 13)
+	if (length < 13)
 		return false;
 
-	patch = (patch_t *)W_CacheLumpNum(lump, PU_STATIC);
-
 	width = SHORT(patch->width);
 	height = SHORT(patch->height);
 
-	result = (height > 0 && height <= 16384 && width > 0 && width <= 16384 && width < (INT16)(size / 4));
+	result = (height > 0 && height <= 16384 && width > 0 && width <= 16384 && width < (INT16)(length / 4));
 
 	if (result)
 	{
@@ -180,7 +174,7 @@ boolean R_CheckIfPatch(lumpnum_t lump)
 			UINT32 ofs = LONG(patch->columnofs[x]);
 
 			// Need one byte for an empty column (but there's patches that don't know that!)
-			if (ofs < (UINT32)width * 4 + 8 || ofs >= (UINT32)size)
+			if (ofs < (UINT32)width * 4 + 8 || ofs >= (UINT32)length)
 			{
 				result = false;
 				break;
diff --git a/src/r_patch.h b/src/r_patch.h
index de4981fba..9fe5fde72 100644
--- a/src/r_patch.h
+++ b/src/r_patch.h
@@ -46,8 +46,9 @@ void *Patch_AllocateHardwarePatch(patch_t *patch);
 void *Patch_CreateGL(patch_t *patch);
 #endif
 
+boolean Patch_CheckIfDoom(softwarepatch_t *patch, size_t length);
+
 // Conversions between patches / flats / textures...
-boolean R_CheckIfPatch(lumpnum_t lump);
 void R_TextureToFlat(size_t tex, UINT8 *flat);
 void R_PatchToFlat(patch_t *patch, UINT8 *flat);
 void R_PatchToMaskedFlat(patch_t *patch, UINT16 *raw, boolean flip);