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

Commit 821c0e1

Browse files
committed
cpk: (!!) Disable compression for now. Implementation fails with our tests *somehow*.
CriCodecsEx: Properly use Py_ssize_t for buffer sizes docs: Update docs
1 parent 096a901 commit 821c0e1

File tree

9 files changed

+60
-36
lines changed

9 files changed

+60
-36
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ temp_*
77
*.aprof
88
*.pdb
99
dist/
10-
_*
10+
_*
11+
*.so

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
"version": "0.2.0",
66
"configurations": [
77
{
8-
"name": "(gdb) Launch USMDecode",
8+
"name": "(gdb) Launch CPK",
99
"type": "cppdbg",
1010
"request": "launch",
1111
"program": "/opt/miniconda3/bin/python",
1212
"args": [
1313
"-m",
14-
"Tests.test_USMDecode"
14+
"Tests.test_CPK"
1515
],
1616
"stopAtEntry": false,
1717
"cwd": "${workspaceFolder}",

.vscode/settings.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"files.associations": {
3+
"format": "cpp",
4+
"__locale": "cpp",
5+
"ios": "cpp",
6+
"array": "cpp",
7+
"string": "cpp",
8+
"string_view": "cpp",
9+
"ranges": "cpp",
10+
"span": "cpp",
11+
"vector": "cpp"
12+
}
13+
}

CriCodecsEx/adx.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ static PyObject* AdxEncode(PyObject* self, PyObject* args){
542542
PyAdxSetError(AdxErrorCode);
543543
return NULL;
544544
}
545-
unsigned int len = adx.size;
545+
Py_ssize_t len = adx.size;
546546
return Py_BuildValue("y#", adxdata, len);
547547
}
548548

@@ -557,6 +557,6 @@ static PyObject* AdxDecode(PyObject* self, PyObject* args){
557557
return NULL;
558558
}
559559
unsigned char *out = wav.WAVEBuffer;
560-
unsigned int len = wav.wav.size+8;
560+
Py_ssize_t len = wav.wav.size+8;
561561
return Py_BuildValue("y#", out, len);
562562
}

CriCodecsEx/crilayla.cpp

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -108,40 +108,41 @@ unsigned char* layla_decomp(unsigned char* data, crilayla_header header){
108108
return dst;
109109
}
110110

111-
unsigned int layla_comp(unsigned char* dest, unsigned int* destLen, unsigned char* src, unsigned int srcLen){
112-
unsigned int n = srcLen - 1, m = *destLen - 0x1, T = 0, d = 0, p, q, i, j, k;
113-
unsigned char* odest = dest;
111+
unsigned int layla_comp(unsigned char *dest, int *destLen, unsigned char *src, int srcLen)
112+
{
113+
int n = srcLen - 1, m = *destLen - 0x1, T = 0, d = 0, p, q, i, j, k;
114+
unsigned char *odest = dest;
114115
for (; n >= 0x100;)
115116
{
116117
j = n + 3 + 0x2000;
117-
if (j > srcLen) j = srcLen;
118-
for (i = n + 3, p = 0; i < j; i++)
118+
if (j>srcLen) j = srcLen;
119+
for (i = n + 3, p = 0; i<j; i++)
119120
{
120121
for (k = 0; k <= n - 0x100; k++)
121122
{
122123
if (*(src + n - k) != *(src + i - k)) break;
123124
}
124-
if (k > p)
125+
if (k>p)
125126
{
126127
q = i - n - 3; p = k;
127128
}
128129
}
129-
if (p < 3)
130+
if (p<3)
130131
{
131132
d = (d << 9) | (*(src + n--)); T += 9;
132133
}
133134
else
134135
{
135136
d = (((d << 1) | 1) << 13) | q; T += 14; n -= p;
136-
if (p < 6)
137+
if (p<6)
137138
{
138139
d = (d << 2) | (p - 3); T += 2;
139140
}
140-
else if (p < 13)
141+
else if (p<13)
141142
{
142143
d = (((d << 2) | 3) << 3) | (p - 6); T += 5;
143144
}
144-
else if (p < 44)
145+
else if (p<44)
145146
{
146147
d = (((d << 5) | 0x1f) << 5) | (p - 13); T += 10;
147148
}
@@ -152,17 +153,17 @@ unsigned int layla_comp(unsigned char* dest, unsigned int* destLen, unsigned cha
152153
{
153154
for (; T >= 8;)
154155
{
155-
*(dest + m--) = (d >> (T - 8)) & 0xff; T -= 8; d = d & ((1 << T) - 1);
156+
*(dest + m--) = (d >> (T - 8)) & 0xff; T -= 8; d = d&((1 << T) - 1);
156157
}
157-
if (p < 255) break;
158+
if (p<255) break;
158159
d = (d << 8) | 0xff; T += 8; p = p - 0xff;
159160
}
160161
d = (d << 8) | p; T += 8;
161162
}
162163
}
163164
for (; T >= 8;)
164165
{
165-
*(dest + m--) = (d >> (T - 8)) & 0xff; T -= 8; d = d & ((1 << T) - 1);
166+
*(dest + m--) = (d >> (T - 8)) & 0xff; T -= 8; d = d&((1 << T) - 1);
166167
}
167168
}
168169
if (T != 0)
@@ -176,19 +177,19 @@ unsigned int layla_comp(unsigned char* dest, unsigned int* destLen, unsigned cha
176177
*(dest + m--) = 0;
177178
}
178179
*destLen = *destLen - m; dest += m;
179-
unsigned int l[] = { 0x4c495243,0x414c5941,srcLen - 0x100,*destLen };
180-
for (j = 0; j < 4; j++)
180+
int l[] = { 0x4c495243,0x414c5941,srcLen - 0x100,*destLen };
181+
for (j = 0; j<4; j++)
181182
{
182-
for (i = 0; i < 4; i++)
183+
for (i = 0; i<4; i++)
183184
{
184185
*(odest + i + j * 4) = l[j] & 0xff; l[j] >>= 8;
185186
}
186187
}
187-
for (j = 0, odest += 0x10; j < *destLen; j++)
188+
for (j = 0, odest += 0x10; j<*destLen; j++)
188189
{
189190
*(odest++) = *(dest + j);
190191
}
191-
for (j = 0; j < 0x100; j++)
192+
for (j = 0; j<0x100; j++)
192193
{
193194
*(odest++) = *(src + j);
194195
}
@@ -218,18 +219,19 @@ unsigned char* CriLaylaDecompress(unsigned char* d){
218219

219220
PyObject* CriLaylaCompress(PyObject* self, PyObject* args){
220221
unsigned char *data;
221-
unsigned int data_size;
222+
Py_ssize_t data_size;
222223
if(!PyArg_ParseTuple(args, "y#", &data, &data_size)){
223224
return NULL;
224225
}
225226
unsigned char *buf = new unsigned char[data_size];
226227
memset(buf, 0, data_size);
227228

229+
int compressed_size = data_size;
228230
Py_BEGIN_ALLOW_THREADS
229-
layla_comp(buf, &data_size, data, data_size);
231+
layla_comp(buf, &compressed_size, data, compressed_size);
230232
Py_END_ALLOW_THREADS
231233

232-
PyObject* bufObj = Py_BuildValue("y#", buf, data_size);
234+
PyObject* bufObj = Py_BuildValue("y#", buf, compressed_size);
233235
delete[] buf;
234236
return bufObj;
235237
}

CriCodecsEx/hca.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3296,7 +3296,7 @@ static PyObject* HcaCrypt(PyObject* self, PyObject* args){
32963296
}
32973297

32983298
unsigned char *buffer = (unsigned char *)view.buf;
3299-
unsigned int length = view.len;
3299+
Py_ssize_t length = view.len;
33003300
PyBuffer_Release(&view);
33013301

33023302
clHCA* hca = (clHCA*)malloc(sizeof(clHCA));
@@ -3345,7 +3345,7 @@ static PyObject* HcaDecode(PyObject* self, PyObject* args){
33453345
data *wavData = &wav.wav.chunks.WAVEdata;
33463346

33473347
unsigned char *data;
3348-
unsigned int data_size;
3348+
Py_ssize_t data_size;
33493349
unsigned int header_size;
33503350
unsigned long long keycode;
33513351
unsigned short subkey;

PyCriCodecsEx/cpk.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,9 @@ def add_file(self, src : str, dst : str = None, compress=False):
253253
compress (bool, optional): Whether to compress the file. Defaults to False.
254254
255255
NOTE:
256-
- In ITOC-related mode, the insertion order determines the final integer ID of the files.
257-
- Compression can be VERY slow with high entropy files (e.g. encoded media). Use at discretion.
256+
- In ITOC-related mode, the insertion order determines the final integer ID of the files.
258257
"""
258+
assert not compress, "FIXME: Compression not working."
259259
if not dst and self.mode != 0:
260260
raise ValueError("Destination filename must be specified in non-ITOC mode.")
261261

@@ -281,7 +281,8 @@ def _populate_files(self, threads : int = 1):
281281
futures = []
282282
for (src, _, _), (dst, compress) in zip(self.in_files,self.os_files):
283283
if compress:
284-
futures.append(exec.submit(_crilayla_compress_to_file, src, dst))
284+
_crilayla_compress_to_file(src, dst)
285+
# futures.append(exec.submit(_crilayla_compress_to_file, src, dst))
285286
for i, fut in enumerate(as_completed(futures)):
286287
fut.result()
287288
self.progress_cb("Compress %s" % os.path.basename(src), i + 1, len(futures))

docs/source/examples.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Load, Extract and modify ACB files
22
---------------------------
3+
34
.. code-block:: python
5+
46
from PyCriCodecsEx.acb import ACB, ACBBuilder, HCACodec, ADXCodec
57
from PyCriCodecsEx.awb import AWBBuilder
68
# Load the '.acb' file.
@@ -34,7 +36,9 @@ Load, Extract and modify ACB files
3436
Build USM files
3537
**NOTE:** FFmpeg must be installed and available in PATH for this to work.
3638
---------------------------
39+
3740
.. code-block:: python
41+
3842
from PyCriCodecsEx.usm import USM, USMBuilder, ADXCodec, HCACodec
3943
builder = USMBuilder()
4044
builder.add_video('some_video.m1v')
@@ -50,7 +54,9 @@ Build USM files
5054
Load, extract then remux USM files into MP4
5155
**NOTE:** FFmpeg must be installed and available in PATH for this to work.
5256
---------------------------
57+
5358
.. code-block:: python
59+
5460
usm = USM('build.usm')
5561
audio = usm.get_audios()
5662
video = usm.get_video()
@@ -85,7 +91,9 @@ Load, extract then remux USM files into MP4
8591
8692
Extract CPK files
8793
---------------------------
94+
8895
.. code-block:: python
96+
8997
import os
9098
from PyCriCodecsEx.cpk import CPK
9199
@@ -105,7 +113,9 @@ Extract CPK files
105113
106114
Pack files into a CPK
107115
---------------------------
116+
108117
.. code-block:: python
118+
109119
import os
110120
from PyCriCodecsEx.cpk import CPKBuilder
111121

setup.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@ def build_extensions(self):
2020
compile_args += ['/O2']
2121
else:
2222
compile_args = ['-std=c++14']
23-
if ENV_DEBUG:
24-
# ASAN on Linux
25-
# This only works with GCC - you also need to specify
26-
# LD_PRELOAD=$(gcc -print-file-name=libasan.so)
27-
compile_args += ['-O0', '-g', '-fsanitize=address']
23+
if ENV_DEBUG:
24+
compile_args += ['-O0', '-g']
2825
else:
2926
compile_args += ['-O2']
3027
for ext in self.extensions:

0 commit comments

Comments
 (0)