From 1970342ae05d2185a2c2622c604aec663bd6d9d0 Mon Sep 17 00:00:00 2001 From: josh Date: Wed, 4 Jun 2025 19:20:02 -0500 Subject: [PATCH] Stable Build --- CMakeLists.txt | 10 ++- include/ReArchive/Endianness.h | 139 ------------------------------- include/ReArchive/types/Header.h | 2 +- src/Endianness.cpp | 59 ------------- src/ReArchive.cpp | 2 +- src/types/FileEntry.cpp | 2 +- src/types/FileTable.cpp | 2 +- 7 files changed, 12 insertions(+), 204 deletions(-) delete mode 100644 include/ReArchive/Endianness.h delete mode 100644 src/Endianness.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 814752a..5845f69 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,9 @@ include(cmake/CPM.cmake) CPMAddPackage(NAME mcolor URL https://git.redacted.cc/maxine/mcolor/archive/Release-1.zip) +CPMAddPackage(NAME Endianness + URL https://git.redacted.cc/josh/Endianness/archive/Release-1.zip) + target_compile_definitions(ReArchive PUBLIC ARCHIVE_PROJECT_VERSION=${ArchiveProjectVersion}) target_compile_definitions(ReArchive PUBLIC ARCHIVE_FORMAT_VERSION=${ArchiveFormatVersion}) @@ -39,13 +42,16 @@ target_compile_definitions(ReArchive PUBLIC ARCHIVE_FORMAT_VERSION=${ArchiveForm set_target_properties(ReArchive PROPERTIES LINKER_LANGUAGE CXX) target_include_directories(ReArchive PUBLIC ${PROJECT_SOURCE_DIR}/include) +target_include_directories(ReArchive PRIVATE ${Endianness_SOURCE_DIR}/include) +target_link_libraries(ReArchive PRIVATE Endianness) add_executable(rsarchive main.cpp) target_compile_definitions(rsarchive PRIVATE ARCHIVE_APP_VERSION=${ArchiveAppVersion}) -target_include_directories(rsarchive PUBLIC ${mcolor_SOURCE_DIR}/include) -target_link_libraries(rsarchive PUBLIC ReArchive mcolor) +target_link_libraries(rsarchive PUBLIC ReArchive) +target_include_directories(rsarchive PRIVATE ${mcolor_SOURCE_DIR}/include) +target_link_libraries(rsarchive PRIVATE mcolor) if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the build type" FORCE) diff --git a/include/ReArchive/Endianness.h b/include/ReArchive/Endianness.h deleted file mode 100644 index 30ec303..0000000 --- a/include/ReArchive/Endianness.h +++ /dev/null @@ -1,139 +0,0 @@ - -#pragma once -#include -#include -#include -#include -#include - -namespace IntegerLiterals -{ - using u8 = uint8_t; using ub = u8; - using u16 = uint16_t; using us = u16; - using u32 = uint32_t; //using ul = u32; - using u64 = uint64_t; using ud = u64; - - using s8 = int8_t; using sb = s8; - using s16 = int16_t; using ss = s16; - using s32 = int32_t; using sl = s32; - using s64 = int64_t; using sd = s64; - - constexpr inline u8 operator ""_u8(unsigned long long int value) { return value;} - constexpr inline ub operator ""_ub(unsigned long long int value) { return value;} - constexpr inline u16 operator ""_u16(unsigned long long int value) { return value;} - constexpr inline us operator ""_us(unsigned long long int value) { return value;} - constexpr inline u32 operator ""_u32(unsigned long long int value) { return value;} - constexpr inline u32 operator ""_ul(unsigned long long int value) { return value;} - constexpr inline u64 operator ""_u64(unsigned long long int value) { return value;} - constexpr inline u64 operator ""_ud(unsigned long long int value) { return value;} - - constexpr inline s8 operator ""_s8(long double value) { return value;} - constexpr inline s8 operator ""_sb(long double value) { return value;} - constexpr inline s16 operator ""_s16(long double value) { return value;} - constexpr inline s16 operator ""_ss(long double value) { return value;} - constexpr inline s32 operator ""_s32(long double value) { return value;} - constexpr inline s32 operator ""_sl(long double value) { return value;} - constexpr inline s64 operator ""_s64(long double value) { return value;} - constexpr inline s64 operator ""_sd(long double value) { return value;} -} - -using namespace IntegerLiterals; - -/// https://commandcenter.blogspot.com/2012/04/byte-order-fallacy.html - - -/// Platform-independent functions for swapping the byte order of common data types. -namespace Endianness -{ - - - // TODO: It seems these can't have their implementation put into - // a separate .cpp file else the compiler throws undefined reference - // is it because they're constexpr? - constexpr bool IsBigEndian() { return (std::endian::native == std::endian::big); } - - constexpr bool IsLittleEndian() { return (std::endian::native == std::endian::little); } - - template - T ReverseByteOrder(T val) - { - T retVal; - char* pVal = (char*)&val; - char* pRetVal = (char*)&retVal; - int size = sizeof(T); - for (int i = 0; i < size; i++) - { - pRetVal[size - 1 - i] = pVal[i]; - } - return retVal; - - //return byteswap(val); - } - - - template - T ReverseByteOrderIfLittleEndian(T val) - { - if (IsLittleEndian()) - return ReverseByteOrder(val); - else return val; - - } - - /// Returns the given values converted into network byte order. - /// Generally on x86, numbers are stored in 'little-endian' order. - /// Network order is 'big-endian'. Supposing a big-endian host machine, - /// no conversion will take place and the original value will be returned. - - - - u16 HostToNetworkOrder(u16 host); - u32 HostToNetworkOrder(u32 host); - u64 HostToNetworkOrder(u64 host); - s16 HostToNetworkOrder(s16 host); - s32 HostToNetworkOrder(s32 host); - s64 HostToNetworkOrder(s64 host); - float HostToNetworkOrder(float host); - double HostToNetworkOrder(double host); - - template T HostToNetworkOrder(T host) { return HostToNetworkOrder(host);} - - template<> inline u16 HostToNetworkOrder(u16 host) { return HostToNetworkOrder(host);} - template<> inline u32 HostToNetworkOrder(u32 host) { return HostToNetworkOrder(host);} - template<> inline u64 HostToNetworkOrder(u64 host) { return HostToNetworkOrder(host);} - template<> inline s16 HostToNetworkOrder(s16 host) { return HostToNetworkOrder(host);} - template<> inline s32 HostToNetworkOrder(s32 host) { return HostToNetworkOrder(host);} - template<> inline s64 HostToNetworkOrder(s64 host) { return HostToNetworkOrder(host);} - template<> inline float HostToNetworkOrder(float host) { return HostToNetworkOrder(host);} - template<> inline double HostToNetworkOrder(double host) { return HostToNetworkOrder(host);} - - /// Returns the given values converted into host-byte order. - /// On x86, this will usually be 'little-endian' - /// On ARM (and other RISC architectures), it is often big-endian. - /// Supposing a big-endian host machine, no conversion will take place and the original value will be returned. - u16 NetworkToHostOrder(u16 network); - u32 NetworkToHostOrder(u32 network); - u64 NetworkToHostOrder(u64 network); - s16 NetworkToHostOrder(s16 network); - s32 NetworkToHostOrder(s32 network); - s64 NetworkToHostOrder(s64 network); - float NetworkToHostOrder(float network); - double NetworkToHostOrder(double network); - - - template T NetworkToHostOrder(T network) { return NetworkToHostOrder(network);} - - template<> inline u16 NetworkToHostOrder(u16 network) { return NetworkToHostOrder(network);} - template<> inline u32 NetworkToHostOrder(u32 network) { return NetworkToHostOrder(network);} - template<> inline u64 NetworkToHostOrder(u64 network) { return NetworkToHostOrder(network);} - template<> inline s16 NetworkToHostOrder(s16 network) { return NetworkToHostOrder(network);} - template<> inline s32 NetworkToHostOrder(s32 network) { return NetworkToHostOrder(network);} - template<> inline s64 NetworkToHostOrder(s64 network) { return NetworkToHostOrder(network);} - template<> inline float NetworkToHostOrder(float network) { return NetworkToHostOrder(network);} - template<> inline double NetworkToHostOrder(double network) { return NetworkToHostOrder(network);} - - - - - -} diff --git a/include/ReArchive/types/Header.h b/include/ReArchive/types/Header.h index 7f25193..da2bfd5 100644 --- a/include/ReArchive/types/Header.h +++ b/include/ReArchive/types/Header.h @@ -3,7 +3,7 @@ #include #include #include -#include +#include namespace ReArchive { diff --git a/src/Endianness.cpp b/src/Endianness.cpp deleted file mode 100644 index 202c5e8..0000000 --- a/src/Endianness.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#ifdef WIN32 -#pragma comment(lib, "Ws2_32.lib") - #define WIN32_LEAN_AND_MEAN - #include - -#endif - -#ifdef __linux__ - #include -#endif - -#include - -namespace Endianness -{ - - // TODO: Manually swap bytes so we can depend less on clunky include directives. - u16 HostToNetworkOrder(u16 host) { return htons(host); } - u16 NetworkToHostOrder(u16 network) { return ntohs(network); } - s16 HostToNetworkOrder(s16 host) { return htons( host); } - s16 NetworkToHostOrder(s16 network) { return ntohs(network);} - u32 HostToNetworkOrder(u32 host) { return htonl(host); } - u32 NetworkToHostOrder(u32 network) { return ntohl(network); } - s32 HostToNetworkOrder(s32 host) { return htonl(host);} - s32 NetworkToHostOrder(s32 network) { return ntohl(network);} - u64 HostToNetworkOrder(u64 host) { return ReverseByteOrderIfLittleEndian(host); } - u64 NetworkToHostOrder(u64 network) { return ReverseByteOrderIfLittleEndian(network); } - s64 HostToNetworkOrder(s64 host) { return ReverseByteOrderIfLittleEndian(host); } - s64 NetworkToHostOrder(s64 network) { return ReverseByteOrderIfLittleEndian(network); } - - - float HostToNetworkOrder(float host) { - if (IsLittleEndian()) - return ReverseByteOrder(host); - else - return host; - } - - float NetworkToHostOrder(float network) { - if (IsLittleEndian()) - return ReverseByteOrder(network); - else - return network; - } - - double HostToNetworkOrder(double host) { - if (IsLittleEndian()) - return ReverseByteOrder(host); - else - return host; - } - - double NetworkToHostOrder(double network) { - if (IsLittleEndian()) - return ReverseByteOrder(network); - else - return network; - } -} \ No newline at end of file diff --git a/src/ReArchive.cpp b/src/ReArchive.cpp index 8550484..75a7192 100644 --- a/src/ReArchive.cpp +++ b/src/ReArchive.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include using ReArchive::Header; using ReArchive::FileTable; diff --git a/src/types/FileEntry.cpp b/src/types/FileEntry.cpp index da62f34..d9e1ebb 100644 --- a/src/types/FileEntry.cpp +++ b/src/types/FileEntry.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include using namespace ReArchive; diff --git a/src/types/FileTable.cpp b/src/types/FileTable.cpp index b4603e5..801032a 100644 --- a/src/types/FileTable.cpp +++ b/src/types/FileTable.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include using namespace ReArchive;