FIx issues with lz11 compression (Still WIP)

also fixed compiling on mingw for now
Readded palladium for the desktop tools
This commit is contained in:
2025-12-29 14:02:46 +01:00
parent bfa6c9e92a
commit ec6968fcb4
6 changed files with 54 additions and 37 deletions

3
.gitmodules vendored
View File

@@ -1,3 +1,6 @@
[submodule "vendor/cli-fancy"]
path = vendor/cli-fancy
url = https://dev.npid7.de/tobid7/cli-fancy
[submodule "vendor/palladium"]
path = vendor/palladium
url = https://github.com/tobid7/palladium

View File

@@ -33,9 +33,10 @@ add_library(ctrff STATIC
target_include_directories(ctrff PUBLIC include)
if(${CTRFF_DESKTOP})
add_subdirectory(vendor/palladium)
add_executable(ctrff-cli tool/main.cpp)
target_include_directories(ctrff-cli PUBLIC include vendor/stb vendor/cli-fancy/include)
target_link_libraries(ctrff-cli PUBLIC ctrff)
target_link_libraries(ctrff-cli PUBLIC ctrff palladium)
add_executable(test tool/test.cpp)
target_include_directories(test PUBLIC include vendor/stb vendor/cli-fancy/include)
target_link_libraries(test PUBLIC ctrff)

View File

@@ -38,7 +38,7 @@ Not all Planned formates are listed here yet
| bcstm | Loading of almost every Data | Fully done and playable by BCSTM-Player |
| bcwav | Basic Loading (not tested yet) | Not finished yet |
| bclim | Nothing done yet (Started creating header) | |
| lz11 | Encoder done, Decoder missing | Files are bit diffrent to the ones bannertool generates (don't know why) |
| lz11 | Encoder done, Decoder missing | WIP |
| romfs | Nothing Done yet (Started creating header) | |
| smdh | Almost done | missing safetey checks |
| cbmd | Nothing done yet | |

View File

@@ -23,7 +23,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/*
#ifdef _WIN32 // Windows (MSVC Tested)
#ifdef CTRFF_BUILD_SHARED
#define CTRFF_API __declspec(dllexport)
@@ -45,9 +45,9 @@ SOFTWARE.
#elif defined(__3DS__) // 3ds Specific
// Only Static supported
#define CTRFF_API
#else
#else*/
#define CTRFF_API
#endif
//#endif
#include <cstddef>
#include <format>

View File

@@ -5,8 +5,8 @@
namespace ctrff {
namespace LZ11 {
ctrff::u32 GetOccurenceLength(const ctrff::u8* new_ptr, size_t new_len,
const ctrff::u8* old_ptr, size_t old_len,
ctrff::u32 GetOccurenceLength(const ctrff::u8* new_ptr, u32 new_len,
const ctrff::u8* old_ptr, u32 old_len,
ctrff::u32& disp) {
disp = 0;
if (new_len == 0) {
@@ -14,11 +14,11 @@ ctrff::u32 GetOccurenceLength(const ctrff::u8* new_ptr, size_t new_len,
}
ctrff::u32 res = 0;
if (old_len > 0) {
for (size_t i = 0; i < old_len - 1; i++) {
for (u32 i = 0; i < old_len - 1; i++) {
auto ref = old_ptr + i;
size_t len = 0;
for (size_t j = 0; j < new_len; j++) {
if (*(ref + j) != (*new_ptr + j)) {
u32 len = 0;
for (u32 j = 0; j < new_len; j++) {
if (*(ref + j) != *(new_ptr + j)) {
break;
}
len++;
@@ -41,32 +41,41 @@ CTRFF_API std::vector<ctrff::u8> Compress(const std::vector<ctrff::u8>& in) {
return std::vector<ctrff::u8>();
}
std::stringstream s;
struct header {
u8 Magic;
u8 Size1;
u8 Size2;
u8 Size3;
};
header hdr;
hdr.Magic = 0x11;
hdr.Size1 = in.size() & 0xFF;
hdr.Size2 = (in.size() >> 8) & 0xFF;
hdr.Size3 = (in.size() >> 16) & 0xFF;
// SETUP HEADER //
s << static_cast<ctrff::u8>(0x11);
s << static_cast<ctrff::u8>(in.size() & 0xFF);
s << static_cast<ctrff::u8>((in.size() >> 8) & 0xFF);
s << static_cast<ctrff::u8>((in.size() >> 16) & 0xFF);
s.write(reinterpret_cast<const char*>(&hdr), sizeof(hdr));
size_t res_len = 4; // 4-byte header
u32 res_len = 4; // 4-byte header
ctrff::u8 out_buf[0x21]; // 33 bytes
out_buf[0] = 0;
size_t obl = 1; // out_buf_len
size_t buf_blocks = 0;
size_t rb = 0;
memset(out_buf, 0x0, sizeof(out_buf));
u32 obl = 1; // out_buf_len
u32 buf_blocks = 0;
u32 rb = 0;
while (rb < in.size()) {
if (buf_blocks == 8 || obl >= sizeof(out_buf) - 3) {
if (buf_blocks == 8) {
s.write(reinterpret_cast<const char*>(out_buf), obl);
res_len += obl;
out_buf[0] = 0;
memset(out_buf, 0x0, sizeof(out_buf));
obl = 1;
buf_blocks = 0;
}
ctrff::u32 disp = 0;
size_t old_len = std::min(rb, static_cast<size_t>(0x1000));
size_t len = LZ11::GetOccurenceLength(
in.data() + rb, std::min(in.size() - rb, static_cast<size_t>(0x10110)),
u32 old_len = std::min(rb, static_cast<u32>(0x1000));
u32 len = LZ11::GetOccurenceLength(
in.data() + rb,
std::min((u32)in.size() - rb, static_cast<u32>(0x10110)),
in.data() + rb - old_len, old_len, disp);
if (len < 3) {
@@ -75,20 +84,24 @@ CTRFF_API std::vector<ctrff::u8> Compress(const std::vector<ctrff::u8>& in) {
rb += len;
out_buf[0] |= static_cast<ctrff::u8>(1 << (7 - buf_blocks));
if (len > 0x110) {
out_buf[obl++] =
0x10 | static_cast<ctrff::u8>(((len - 0x111) >> 12) & 0x0F);
out_buf[obl++] = static_cast<ctrff::u8>(((len - 0x111) >> 4) & 0xFF);
out_buf[obl] = 0x10;
out_buf[obl] |= static_cast<ctrff::u8>(((len - 0x111) >> 12) & 0x0F);
obl++;
out_buf[obl] = static_cast<ctrff::u8>(((len - 0x111) >> 4) & 0xFF);
obl++;
out_buf[obl] = static_cast<ctrff::u8>(((len - 0x111) << 4) & 0xF0);
} else if (len > 0x10) {
out_buf[obl++] =
0x00 | static_cast<ctrff::u8>(((len - 0x11) >> 4) & 0x0F);
out_buf[obl] = static_cast<ctrff::u8>(((len - 0x11) << 4) & 0xF0);
out_buf[obl] = 0x00;
out_buf[obl] |= static_cast<ctrff::u8>(((len - 0x111) >> 4) & 0x0F);
obl++;
out_buf[obl] = static_cast<ctrff::u8>(((len - 0x111) << 4) & 0xF0);
} else {
out_buf[obl] |= static_cast<ctrff::u8>(((len - 1) << 4) & 0xF0);
out_buf[obl] = static_cast<ctrff::u8>(((len - 1) << 4) & 0xF0);
}
out_buf[obl] |= static_cast<ctrff::u8>(((disp - 1) >> 8) & 0x0F);
obl++;
out_buf[obl] = static_cast<ctrff::u8>((disp - 1) & 0xFF);
obl++;
out_buf[obl++] = static_cast<ctrff::u8>(((disp - 1) >> 8) & 0x0F);
out_buf[obl++] = static_cast<ctrff::u8>((disp - 1) & 0xFF);
}
buf_blocks++;
}
@@ -105,9 +118,8 @@ CTRFF_API std::vector<ctrff::u8> Compress(const std::vector<ctrff::u8>& in) {
res_len += pad_len;
}
std::vector<ctrff::u8> res(res_len);
s.read(reinterpret_cast<char*>(res.data()), res.size());
return res;
std::string tmp = s.str();
return std::vector<u8>(tmp.begin(), tmp.end());
}
} // namespace LZ11
} // namespace ctrff

1
vendor/palladium vendored Submodule

Submodule vendor/palladium added at 3575a6787d