game-music-emu: better detection of unrar library header

From 8696670a4cc09a27156083b27e9b95084f103051 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Thu, 5 Oct 2023 17:55:00 +0300
Subject: [PATCH] better detection of unrar library header

---
 cmake/FindUNRAR.cmake | 12 +++++++++++-
 gme/CMakeLists.txt    |  5 +++++
 gme/Spc_Emu.cpp       |  8 ++++++--
 3 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/cmake/FindUNRAR.cmake b/cmake/FindUNRAR.cmake
index ec37701..5eafdcc 100644
--- a/cmake/FindUNRAR.cmake
+++ b/cmake/FindUNRAR.cmake
@@ -21,8 +21,18 @@ set(UNRAR_NAMES_DEBUG unrar)
 
 # Try each search configuration.
 foreach(search ${_UNRAR_SEARCHES})
-  find_path(UNRAR_INCLUDE_DIR NAMES dll.hpp ${${search}} PATH_SUFFIXES include unrar)
+  find_path(UNRAR_INCLUDE_DIR NAMES unrar.h ${${search}} PATH_SUFFIXES include unrar)
 endforeach()
+if(UNRAR_INCLUDE_DIR)
+  set(RAR_HDR_UNRAR_H 1)
+else()
+  foreach(search ${_UNRAR_SEARCHES})
+    find_path(UNRAR_INCLUDE_DIR NAMES dll.hpp ${${search}} PATH_SUFFIXES include unrar)
+  endforeach()
+  if(UNRAR_INCLUDE_DIR)
+    set(RAR_HDR_DLL_HPP 1)
+  endif()
+endif()
 
 # Allow UNRAR_LIBRARY to be set manually, as the location of the unrar library
 if(NOT UNRAR_LIBRARY)
diff --git a/gme/CMakeLists.txt b/gme/CMakeLists.txt
index 5050f04..eb0bc97 100644
--- a/gme/CMakeLists.txt
+++ b/gme/CMakeLists.txt
@@ -185,6 +185,11 @@ if(USE_GME_SPC AND GME_UNRAR_RSN)
     if(UNRAR_FOUND)
         message(" ** unRAR library located, the RSN file format will be supported")
         target_compile_definitions(gme PRIVATE -DRARDLL)
+        if(RAR_HDR_UNRAR_H)
+            target_compile_definitions(gme PRIVATE -DRAR_HDR_UNRAR_H)
+        elseif(RAR_HDR_DLL_HPP)
+            target_compile_definitions(gme PRIVATE -DRAR_HDR_DLL_HPP)
+        endif()
         target_include_directories(gme PRIVATE ${UNRAR_INCLUDE_DIRS})
         target_link_libraries(gme ${UNRAR_LIBRARIES})
         # Is not to be installed though
diff --git a/gme/Spc_Emu.cpp b/gme/Spc_Emu.cpp
index 18f8de8..9f9d0a6 100644
--- a/gme/Spc_Emu.cpp
+++ b/gme/Spc_Emu.cpp
@@ -21,7 +21,11 @@
 #endif
 #include <windows.h>
 #endif
+#if defined RAR_HDR_UNRAR_H
+#include <unrar.h>
+#elif defined RAR_HDR_DLL_HPP
 #include <dll.hpp>
+#endif
 #ifndef ERAR_SUCCESS
 #define ERAR_SUCCESS 0
 #endif
@@ -345,7 +349,7 @@ struct Rsn_File : Spc_File
 		byte *bp;
 		data.OpenMode = RAR_OM_EXTRACT;
 		rar = RAROpenArchive( &data );
-		RARSetCallback( rar, call_rsn, (intptr_t)&bp );
+		RARSetCallback( rar, call_rsn, (LPARAM)&bp );
 		for ( count = 0, pos = 0; RARReadHeader( rar, &head ) == ERAR_SUCCESS; )
 		{
 			bp = &temp[0];
@@ -538,7 +542,7 @@ blargg_err_t Rsn_Emu::load_archive( const char* path )
 	byte *bp = &rsn[0];
 	data.OpenMode = RAR_OM_EXTRACT;
 	rar = RAROpenArchive( &data );
-	RARSetCallback( rar, call_rsn, (intptr_t)&bp );
+	RARSetCallback( rar, call_rsn, (LPARAM)&bp );
 	for ( count = 0, pos = 0; RARReadHeader( rar, &head ) == ERAR_SUCCESS; )
 	{
 		RARProcessFile( rar, RAR_TEST, 0, 0 );