Skip to content

Commit

Permalink
Support games in LZH archives
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghabry committed Jul 27, 2023
1 parent a674efc commit 9ae5043
Show file tree
Hide file tree
Showing 9 changed files with 592 additions and 13 deletions.
33 changes: 25 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ add_library(${PROJECT_NAME} OBJECT
src/fileext_guesser.h
src/filesystem.cpp
src/filesystem.h
src/filesystem_lzh.cpp
src/filesystem_lzh.h
src/filesystem_native.cpp
src/filesystem_native.h
src/filesystem_root.cpp
Expand Down Expand Up @@ -819,7 +821,7 @@ endif()
player_find_package(NAME PNG TARGET PNG::PNG REQUIRED)
player_find_package(NAME fmt TARGET fmt::fmt REQUIRED)

# Do not use player_find_package. enable_language used by pixman on Android does work properly inside function calls
# Do not use player_find_package. enable_language used by pixman on Android does not work properly inside function calls
find_package(Pixman REQUIRED)
target_link_libraries(${PROJECT_NAME} PIXMAN::PIXMAN)

Expand Down Expand Up @@ -849,6 +851,15 @@ if(TARGET freetype)
CONFIG_BROKEN)
endif()

# lzh archive support
option(PLAYER_WITH_LHASA "Support running games in lzh archives" ON)

player_find_package(NAME lhasa
CONDITION PLAYER_WITH_LHASA
DEFINITION HAVE_LHASA
TARGET LHASA::liblhasa
)

# Sound system to use
if(${PLAYER_TARGET_PLATFORM} STREQUAL "SDL2")
set(PLAYER_AUDIO_BACKEND "SDL2" CACHE STRING "Audio system to use. Options: SDL2 OFF")
Expand Down Expand Up @@ -1444,7 +1455,7 @@ if(${PLAYER_AUDIO_BACKEND} MATCHES "^(SDL2|SDL1|libretro|psvita|3ds|switch|wii)$
if(WAV_LIBS)
message(STATUS "WAV playback: ${WAV_LIBS}")
else()
message(STATUS "WAV playback: None")
message(STATUS "WAV playback: No")
endif()

set(MIDI_LIBS)
Expand All @@ -1467,41 +1478,41 @@ if(${PLAYER_AUDIO_BACKEND} MATCHES "^(SDL2|SDL1|libretro|psvita|3ds|switch|wii)$
if(MIDI_LIBS)
message(STATUS "MIDI playback: ${MIDI_LIBS}")
else()
message(STATUS "MIDI playback: None")
message(STATUS "MIDI playback: No")
endif()

if(TARGET MPG123::libmpg123)
message(STATUS "MP3 playback: mpg123")
else()
message(STATUS "MP3 playback: None")
message(STATUS "MP3 playback: No")
endif()

if(TARGET Vorbis::vorbisfile)
message(STATUS "Ogg Vorbis playback: libvorbis")
elseif(TARGET Tremor::Tremor)
message(STATUS "Ogg Vorbis playback: tremor")
else()
message(STATUS "Ogg Vorbis playback: None")
message(STATUS "Ogg Vorbis playback: No")
endif()

if(TARGET XMP::XMP)
message(STATUS "MOD playback: libxmp")
else()
message(STATUS "MOD playback: None")
message(STATUS "MOD playback: No")
endif()

if(TARGET OpusFile::opusfile)
message(STATUS "Opus playback: opusfile")
else()
message(STATUS "Opus playback: None")
message(STATUS "Opus playback: No")
endif()

if(TARGET speexdsp::speexdsp)
message(STATUS "Resampler: speexdsp")
elseif(TARGET Samplerate::Samplerate)
message(STATUS "Resampler: libsamplerate")
else()
message(STATUS "Resampler: None")
message(STATUS "Resampler: No")
endif()
endif()

Expand All @@ -1515,6 +1526,12 @@ else()
message(STATUS "Font rendering: built-in")
endif()

if(TARGET LHASA::liblhasa)
message(STATUS "LZH archive support: lhasa")
else()
message(STATUS "LZH archive support: No")
endif()

message(STATUS "")

message(STATUS "Manual page: ${MANUAL_STATUS}")
Expand Down
4 changes: 4 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ libeasyrpg_player_a_SOURCES = \
src/fileext_guesser.h \
src/filesystem.cpp \
src/filesystem.h \
src/filesystem_lzh.cpp \
src/filesystem_lzh.h \
src/filesystem_native.cpp \
src/filesystem_native.h \
src/filesystem_root.cpp \
Expand Down Expand Up @@ -571,6 +573,7 @@ libeasyrpg_player_a_CXXFLAGS = \
$(PIXMAN_CFLAGS) \
$(FREETYPE_CFLAGS) \
$(HARFBUZZ_CFLAGS) \
$(LHASA_CFLAGS) \
$(SDL_CFLAGS) \
$(PNG_CFLAGS) \
$(ZLIB_CFLAGS) \
Expand Down Expand Up @@ -623,6 +626,7 @@ easyrpg_player_LDADD = libeasyrpg-player.a libplayer-version.a \
$(PIXMAN_LIBS) \
$(FREETYPE_LIBS) \
$(HARFBUZZ_LIBS) \
$(LHASA_LIBS) \
$(SDL_LIBS) \
$(PNG_LIBS) \
$(ZLIB_LIBS) \
Expand Down
64 changes: 64 additions & 0 deletions builds/cmake/Modules/Findlhasa.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#.rst:
# Findlhasa
# -----------
#
# Find the lhasa Library
#
# Imported Targets
# ^^^^^^^^^^^^^^^^
#
# This module defines the following :prop_tgt:`IMPORTED` targets:
#
# ``LHASA::liblhasa``
# The ``lhasa`` library, if found.
#
# Result Variables
# ^^^^^^^^^^^^^^^^
#
# This module will set the following variables in your project:
#
# ``LHASA_INCLUDE_DIRS``
# where to find lhasa headers.
# ``LHASA_LIBRARIES``
# the libraries to link against to use lhasa.
# ``LHASA_FOUND``
# true if the lhasa headers and libraries were found.

find_package(PkgConfig QUIET)

pkg_check_modules(PC_LHASA QUIET liblhasa)

# Look for the header file.
find_path(LHASA_INCLUDE_DIR
NAMES lhasa.h
PATH_SUFFIXES liblhasa-1.0 liblhasa
HINTS ${PC_LHASA_INCLUDE_DIRS})

# Look for the library.
# Allow LHASA_LIBRARY to be set manually, as the location of the lhasa library
if(NOT LHASA_LIBRARY)
find_library(LHASA_LIBRARY
NAMES liblhasa lhasa
HINTS ${PC_LHASA_LIBRARY_DIRS})
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(lhasa
REQUIRED_VARS LHASA_LIBRARY LHASA_INCLUDE_DIR)

if(LHASA_FOUND)
set(LHASA_INCLUDE_DIRS ${LHASA_INCLUDE_DIR})

if(NOT LHASA_LIBRARIES)
set(LHASA_LIBRARIES ${LHASA_LIBRARIES})
endif()

if(NOT TARGET LHASA::liblhasa)
add_library(LHASA::liblhasa UNKNOWN IMPORTED)
set_target_properties(LHASA::liblhasa PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${LHASA_INCLUDE_DIRS}"
IMPORTED_LOCATION "${LHASA_LIBRARY}")
endif()
endif()

mark_as_advanced(LHASA_INCLUDE_DIR LHASA_LIBRARY)
2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ EP_PKG_CHECK([FREETYPE],[freetype2],[Custom Font rendering.])
AS_IF([test "$with_freetype" = "yes"],[
EP_PKG_CHECK([HARFBUZZ],[harfbuzz],[Custom Font text shaping.])
])
EP_PKG_CHECK([LHASA],[liblhasa],[Support running games in lzh archives.])

AC_ARG_WITH([audio],[AS_HELP_STRING([--without-audio], [Disable audio support. @<:@default=on@:>@])])
AS_IF([test "x$with_audio" != "xno"],[
Expand Down Expand Up @@ -226,6 +227,7 @@ if test "yes" != "$silent"; then
echo " -custom Font rendering (freetype2): $with_freetype"
test "$with_freetype" = "yes" && \
echo " -custom Font text shaping (harfbuzz): $with_harfbuzz"
echo " -run games in lzh archives (lhasa): $with_lhasa"
if test "$with_audio" = "no"; then
echo "Audio support: no"
Expand Down
10 changes: 7 additions & 3 deletions src/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "filesystem.h"
#include "filesystem_native.h"
#include "filesystem_lzh.h"
#include "filesystem_zip.h"
#include "filesystem_stream.h"
#include "filefinder.h"
Expand Down Expand Up @@ -122,7 +123,7 @@ FilesystemView Filesystem::Create(StringView path) const {
} else {
path_prefix += comp + "/";
auto sv = StringView(comp);
if (sv.ends_with(".zip") || sv.ends_with(".easyrpg")) {
if (sv.ends_with(".zip") || sv.ends_with(".easyrpg") || sv.ends_with(".lzh")) {
path_prefix.pop_back();
handle_internal = true;
}
Expand All @@ -133,9 +134,12 @@ FilesystemView Filesystem::Create(StringView path) const {
internal_path.pop_back();
}

auto filesystem = std::make_shared<ZipFilesystem>(path_prefix, Subtree(dir_of_file));
std::shared_ptr<Filesystem> filesystem = std::make_shared<ZipFilesystem>(path_prefix, Subtree(dir_of_file));
if (!filesystem->IsValid()) {
return FilesystemView();
filesystem = std::make_shared<LzhFilesystem>(path_prefix, Subtree(dir_of_file));
if (!filesystem->IsValid()) {
return FilesystemView();
}
}
if (!internal_path.empty()) {
auto fs_view = filesystem->Create(internal_path);
Expand Down
Loading

0 comments on commit 9ae5043

Please sign in to comment.