Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
cmake_minimum_required(VERSION 3.18)
project(nx_hbmenu VERSION 3.6.0)

if (NOT NINTENDO_SWITCH)
find_package(SDL2 REQUIRED)
find_package(SDL2 CONFIG COMPONENTS SDL2main)
endif()

find_package(Freetype REQUIRED)
find_package(PNG REQUIRED)
find_package(PhysFS REQUIRED)
find_package(libjpeg-turbo REQUIRED)
find_package(libconfig REQUIRED)

add_compile_options(
-DVERSION=\"${PROJECT_VERSION}\"
)

add_executable(${PROJECT_NAME})

add_custom_command(
OUTPUT ${CMAKE_SOURCE_DIR}/romfs/assets.zip
COMMAND mkdir -p ${CMAKE_SOURCE_DIR}/romfs

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be an idea to use cmake in tool mode for compatibility.
${CMAKE_COMMAND} -E, it has rm, make_directory and tar (which can even work on zip files).

COMMAND rm -f ${CMAKE_SOURCE_DIR}/romfs/assets.zip
COMMAND zip -rj ${CMAKE_SOURCE_DIR}/romfs/assets.zip ${CMAKE_SOURCE_DIR}/assets
DEPENDS assets
assets/eth_icon.bin
assets/airplane_icon.bin
assets/folder_icon.bin
assets/battery_icon.bin
assets/wifi_none_icon.bin
assets/theme_icon_dark.bin
assets/hbmenu_logo_light.bin
assets/wifi2_icon.bin
assets/wifi3_icon.bin
assets/theme_icon_light.bin
assets/invalid_icon.bin
assets/charging_icon.bin
assets/wifi1_icon.bin
assets/hbmenu_logo_dark.bin
assets/eth_none_icon.bin
VERBATIM)

add_custom_target(assets_zip DEPENDS romfs/assets.zip)

add_dependencies(${PROJECT_NAME} assets_zip)

target_sources(${PROJECT_NAME} PRIVATE
common/menu-list.c
common/worker.c
common/math.c
common/menu.c
common/font.c
common/launch.c
common/menu-entry.c
common/theme.c
common/message-box.c
common/text.c
common/ui.c
common/status.c
common/language.c
common/netloader.c
common/assets.c
)

if (NINTENDO_SWITCH)
target_sources(${PROJECT_NAME} PRIVATE
nx_main/nx_power.c
nx_main/nx_netstatus.c
nx_main/nx_audio.c
nx_main/nx_graphics.c
nx_main/nx_touch.c
nx_main/main.c
nx_main/nx_thermalstatus.c
nx_main/nx_launch.c
nx_main/loaders/builtin.c
)



nx_generate_nacp (${PROJECT_NAME}.nacp
NAME "NX HB Menu"
AUTHOR "SwitchBrew"
)

nx_create_nro (${PROJECT_NAME}
NACP ${PROJECT_NAME}.nacp
ICON ${CMAKE_SOURCE_DIR}/icon.jpg
ROMFS ${CMAKE_SOURCE_DIR}/romfs
)

else()
target_sources(${PROJECT_NAME} PRIVATE
pc_main/main.cpp
pc_main/pc_launch.c
pc_main/pc_netstatus.c
pc_main/pc_thermalstatus.c
pc_main/pc_power.c
)

endif()

# SDL2::SDL2main may or may not be available. It is e.g. required by Windows GUI applications
if(TARGET SDL2::SDL2main)
# It has an implicit dependency on SDL2 functions, so it MUST be added before SDL2::SDL2 (or SDL2::SDL2-static)
target_link_libraries(${PROJECT_NAME} PRIVATE SDL2::SDL2main)
endif()

if (NOT NINTENDO_SWITCH)
target_link_libraries(${PROJECT_NAME} PRIVATE
SDL2::SDL2
)
endif()

target_link_libraries(${PROJECT_NAME} PRIVATE
Freetype::Freetype
PNG
PhysFs
z
bz2
libjpeg-turbo::turbojpeg-static
config
)

if(NINTENDO_SWITCH)
target_link_libraries(${PROJECT_NAME} PRIVATE
deko3d
)
endif()
4 changes: 2 additions & 2 deletions common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ typedef enum

// when building for pc we need to include these separately
#ifndef __SWITCH__
#include "switch/nro.h"
#include "switch/nacp.h"
#include "nro.h"
#include "nacp.h"
#endif

#include "font.h"
Expand Down
94 changes: 94 additions & 0 deletions common/nacp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/**
* @file nacp.h
* @brief Control.nacp structure / related code for nacp.
* @copyright libnx Authors
*/

#pragma once

/// Language entry. These strings are UTF-8.
typedef struct {
char name[0x200];
char author[0x100];
} NacpLanguageEntry;

/// ApplicationNeighborDetectionGroupConfiguration
typedef struct {
u64 group_id; ///< GroupId
u8 key[0x10];
} NacpApplicationNeighborDetectionGroupConfiguration;

/// NeighborDetectionClientConfiguration
typedef struct {
NacpApplicationNeighborDetectionGroupConfiguration send_group_configuration; ///< SendGroupConfiguration
NacpApplicationNeighborDetectionGroupConfiguration receivable_group_configurations[0x10]; ///< ReceivableGroupConfigurations
} NacpNeighborDetectionClientConfiguration;

/// ApplicationJitConfiguration
typedef struct {
u64 flags; ///< Flags
u64 memory_size; ///< MemorySize
} NacpApplicationJitConfiguration;

/// ns ApplicationControlProperty
typedef struct {
NacpLanguageEntry lang[16]; ///< \ref NacpLanguageEntry
u8 isbn[0x25]; ///< Isbn
u8 startup_user_account; ///< StartupUserAccount
u8 user_account_switch_lock; ///< UserAccountSwitchLock
u8 add_on_content_registration_type; ///< AddOnContentRegistrationType
u32 attribute_flag; ///< AttributeFlag
u32 supported_language_flag; ///< SupportedLanguageFlag
u32 parental_control_flag; ///< ParentalControlFlag
u8 screenshot; ///< Screenshot
u8 video_capture; ///< VideoCapture
u8 data_loss_confirmation; ///< DataLossConfirmation
u8 play_log_policy; ///< PlayLogPolicy
u64 presence_group_id; ///< PresenceGroupId
s8 rating_age[0x20]; ///< RatingAge
char display_version[0x10]; ///< DisplayVersion
u64 add_on_content_base_id; ///< AddOnContentBaseId
u64 save_data_owner_id; ///< SaveDataOwnerId
u64 user_account_save_data_size; ///< UserAccountSaveDataSize
u64 user_account_save_data_journal_size; ///< UserAccountSaveDataJournalSize
u64 device_save_data_size; ///< DeviceSaveDataSize
u64 device_save_data_journal_size; ///< DeviceSaveDataJournalSize
u64 bcat_delivery_cache_storage_size; ///< BcatDeliveryCacheStorageSize
u64 application_error_code_category; ///< ApplicationErrorCodeCategory
u64 local_communication_id[0x8]; ///< LocalCommunicationId
u8 logo_type; ///< LogoType
u8 logo_handling; ///< LogoHandling
u8 runtime_add_on_content_install; ///< RuntimeAddOnContentInstall
u8 runtime_parameter_delivery; ///< RuntimeParameterDelivery
u8 reserved_x30f4[0x2]; ///< Reserved
u8 crash_report; ///< CrashReport
u8 hdcp; ///< Hdcp
u64 pseudo_device_id_seed; ///< SeedForPseudoDeviceId
char bcat_passphrase[0x41]; ///< BcatPassphrase
u8 startup_user_account_option; ///< StartupUserAccountOption
u8 reserved_for_user_account_save_data_operation[0x6]; ///< ReservedForUserAccountSaveDataOperation
u64 user_account_save_data_size_max; ///< UserAccountSaveDataSizeMax
u64 user_account_save_data_journal_size_max; ///< UserAccountSaveDataJournalSizeMax
u64 device_save_data_size_max; ///< DeviceSaveDataSizeMax
u64 device_save_data_journal_size_max; ///< DeviceSaveDataJournalSizeMax
u64 temporary_storage_size; ///< TemporaryStorageSize
u64 cache_storage_size; ///< CacheStorageSize
u64 cache_storage_journal_size; ///< CacheStorageJournalSize
u64 cache_storage_data_and_journal_size_max; ///< CacheStorageDataAndJournalSizeMax
u16 cache_storage_index_max; ///< CacheStorageIndexMax
u8 reserved_x318a[0x6]; ///< Reserved
u64 play_log_queryable_application_id[0x10]; ///< PlayLogQueryableApplicationId
u8 play_log_query_capability; ///< PlayLogQueryCapability
u8 repair_flag; ///< RepairFlag
u8 program_index; ///< ProgramIndex
u8 required_network_service_license_on_launch; ///< RequiredNetworkServiceLicenseOnLaunchFlag
u32 reserved_x3214; ///< Reserved
NacpNeighborDetectionClientConfiguration neighbor_detection_client_configuration; ///< NeighborDetectionClientConfiguration
NacpApplicationJitConfiguration jit_configuration; ///< JitConfiguration
u8 reserved_x33c0[0xc40]; ///< Reserved
} NacpStruct;

/// Get the NacpLanguageEntry from the input nacp corresponding to the current system language (this may fallback to other languages when needed). Output langentry is NULL if none found / content of entry is empty.
/// If you're using ns you may want to use \ref nsGetApplicationDesiredLanguage instead.
Result nacpGetLanguageEntry(NacpStruct* nacp, NacpLanguageEntry** langentry);

54 changes: 54 additions & 0 deletions common/nro.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* @file nro.h
* @brief NRO headers.
* @copyright libnx Authors
*/

#pragma once

#define NROHEADER_MAGIC 0x304f524e

#define NROASSETHEADER_MAGIC 0x54455341
#define NROASSETHEADER_VERSION 0

/// Entry for each segment in the codebin.
typedef struct {
u32 file_off;
u32 size;
} NroSegment;

/// Offset 0x0 in the NRO.
typedef struct {
u32 unused;
u32 mod_offset;
u8 padding[8];
} NroStart;

/// This follows NroStart, the actual nro-header.
typedef struct {
u32 magic;
u32 unk1;
u32 size;
u32 unk2;
NroSegment segments[3];
u32 bss_size;
u32 unk3;
u8 build_id[0x20];
u8 padding[0x20];
} NroHeader;

/// Custom asset section.
typedef struct {
u64 offset;
u64 size;
} NroAssetSection;

/// Custom asset header.
typedef struct {
u32 magic;
u32 version;
NroAssetSection icon;
NroAssetSection nacp;
NroAssetSection romfs;
} NroAssetHeader;