Skip to content
This repository was archived by the owner on Feb 6, 2026. It is now read-only.

Commit b7bc159

Browse files
committed
Version 0.0.5
cpk: Fix CRILAYLA header detection (#2) cpk: Add compressed CRILAYLA sample
1 parent 55aac49 commit b7bc159

File tree

6 files changed

+28
-7
lines changed

6 files changed

+28
-7
lines changed

CriCodecsEx/crilayla.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ See also:
2222
#include <stdlib.h>
2323
#include <string.h>
2424

25+
unsigned fourCC(const char a, const char b, const char c, const char d) {
26+
return (a << 0) | (b << 8) | (c << 16) | (d << 24);
27+
};
28+
const unsigned CRILAYLA_LO = fourCC('C', 'R', 'I', 'L');
29+
const unsigned CRILAYLA_HI = fourCC('A', 'Y', 'L', 'A');
30+
const unsigned long long CRILAYLA_MAGIC = CRILAYLA_LO | (unsigned long long)CRILAYLA_HI << 32uLL;
31+
2532
struct crilayla_header{
2633
unsigned long long crilayla;
2734
unsigned int decompress_size;
@@ -186,7 +193,7 @@ unsigned int layla_comp(unsigned char *dest, int *destLen, unsigned char *src, i
186193
return 0; // Underflow
187194
*destLen = *destLen - m; dest += m;
188195
// CRIL AYLA srcLen-0x100 destLen
189-
int l[] = { 0x4c495243,0x414c5941,srcLen - 0x100,*destLen };
196+
int l[] = { CRILAYLA_LO,CRILAYLA_HI,srcLen - 0x100,*destLen };
190197
for (j = 0; j<4; j++)
191198
{
192199
for (i = 0; i<4; i++)
@@ -210,7 +217,7 @@ PyObject* CriLaylaDecompress(PyObject* self, PyObject* d){
210217
unsigned char *data = (unsigned char *)PyBytes_AsString(d);
211218
crilayla_header header = *(crilayla_header*)data;
212219

213-
if (header.crilayla != 0x414c59434152494cULL) {
220+
if (header.crilayla != CRILAYLA_MAGIC) {
214221
PyErr_SetString(PyExc_ValueError, "Invalid CRILAYLA header.");
215222
return NULL;
216223
}

PyCriCodecsEx/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.0.4"
1+
__version__ = "0.0.5"

Tests/CPK/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,9 @@ default.cpk
77
88
└───subdir
99
niko-512.png
10-
```
10+
```
11+
### compressed.cpk
12+
```
13+
compressed.cpk
14+
niko.png
15+
```

Tests/CPK/compressed.cpk

10.1 KB
Binary file not shown.

Tests/test_CPK.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
from . import sample_file_path, temp_file_path
33
from PyCriCodecsEx.cpk import CPK, CPKBuilder
44

5-
def test_cpk_unpack():
5+
def cpk_unpack(fname):
66
# Extract CPK content
77
cpkdir = temp_file_path('cpk')
8-
cpk = CPK(sample_file_path('CPK/default.cpk'))
8+
cpk = CPK(sample_file_path(fname))
99
for f in cpk.files:
1010
dst = os.path.join(cpkdir, f.path)
1111
os.makedirs(os.path.dirname(dst), exist_ok=True)
@@ -29,5 +29,12 @@ def progress_callback(stage: str, current: int, total: int):
2929
cpk.save(temp_file_path('rebuild.cpk'))
3030
print('Repack done.')
3131

32+
def test_cpk_regular():
33+
cpk_unpack('CPK/default.cpk')
34+
35+
def test_cpk_compressed():
36+
cpk_unpack('CPK/compressed.cpk')
37+
3238
if __name__ == "__main__":
33-
test_cpk_unpack()
39+
test_cpk_regular()
40+
test_cpk_compressed()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# TODO: Fix CRILAYLA Compression
2+
# Decompression is tested in test_CPK.py
13
import os
24
from . import sample_file_path, temp_file_path
35
from CriCodecsEx import CriLaylaCompress, CriLaylaDecompress

0 commit comments

Comments
 (0)