libwz 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +165 -0
- package/binding.gyp +149 -0
- package/deps/tiny-aes/.github/workflows/c-cpp.yml +27 -0
- package/deps/tiny-aes/CMakeLists.txt +17 -0
- package/deps/tiny-aes/Makefile +61 -0
- package/deps/tiny-aes/README.md +83 -0
- package/deps/tiny-aes/aes.c +572 -0
- package/deps/tiny-aes/aes.h +91 -0
- package/deps/tiny-aes/aes.hpp +12 -0
- package/deps/tiny-aes/conanfile.py +73 -0
- package/deps/tiny-aes/library.json +19 -0
- package/deps/tiny-aes/library.properties +11 -0
- package/deps/tiny-aes/test.c +316 -0
- package/deps/tiny-aes/test.cpp +2 -0
- package/deps/tiny-aes/test_package/CMakeLists.txt +11 -0
- package/deps/tiny-aes/test_package/conanfile.py +17 -0
- package/deps/tiny-aes/unlicense.txt +24 -0
- package/deps/zlib/.cmake-format.yaml +245 -0
- package/deps/zlib/.github/workflows/c-std.yml +268 -0
- package/deps/zlib/.github/workflows/cmake.yml +147 -0
- package/deps/zlib/.github/workflows/configure.yml +146 -0
- package/deps/zlib/.github/workflows/contribs.yml +64 -0
- package/deps/zlib/.github/workflows/fuzz.yml +25 -0
- package/deps/zlib/.github/workflows/msys-cygwin.yml +92 -0
- package/deps/zlib/.github/workflows/others.yml +153 -0
- package/deps/zlib/BUILD.bazel +134 -0
- package/deps/zlib/CMakeLists.txt +310 -0
- package/deps/zlib/ChangeLog +1669 -0
- package/deps/zlib/FAQ +371 -0
- package/deps/zlib/INDEX +67 -0
- package/deps/zlib/LICENSE +22 -0
- package/deps/zlib/MODULE.bazel +9 -0
- package/deps/zlib/Makefile.in +426 -0
- package/deps/zlib/README +115 -0
- package/deps/zlib/README-cmake.md +79 -0
- package/deps/zlib/adler32.c +164 -0
- package/deps/zlib/amiga/Makefile.pup +69 -0
- package/deps/zlib/amiga/Makefile.sas +68 -0
- package/deps/zlib/compress.c +99 -0
- package/deps/zlib/configure +1078 -0
- package/deps/zlib/contrib/CMakeLists.txt +61 -0
- package/deps/zlib/contrib/README.contrib +57 -0
- package/deps/zlib/contrib/ada/CMakeLists.txt +217 -0
- package/deps/zlib/contrib/ada/buffer_demo.adb +106 -0
- package/deps/zlib/contrib/ada/cmake/Modules/CMakeADACompiler.cmake.in +23 -0
- package/deps/zlib/contrib/ada/cmake/Modules/CMakeADAInformation.cmake +133 -0
- package/deps/zlib/contrib/ada/cmake/Modules/CMakeDetermineADACompiler.cmake +33 -0
- package/deps/zlib/contrib/ada/cmake/Modules/CMakeTestADACompiler.cmake +46 -0
- package/deps/zlib/contrib/ada/cmake/binder_helper.cmake +47 -0
- package/deps/zlib/contrib/ada/cmake/compile_helper.cmake +32 -0
- package/deps/zlib/contrib/ada/cmake/exe_link_helper.cmake +53 -0
- package/deps/zlib/contrib/ada/cmake/shared_link_helper.cmake +52 -0
- package/deps/zlib/contrib/ada/cmake/static_link_helper.cmake +25 -0
- package/deps/zlib/contrib/ada/mtest.adb +156 -0
- package/deps/zlib/contrib/ada/read.adb +156 -0
- package/deps/zlib/contrib/ada/readme.txt +65 -0
- package/deps/zlib/contrib/ada/test.adb +463 -0
- package/deps/zlib/contrib/ada/zlib-streams.adb +225 -0
- package/deps/zlib/contrib/ada/zlib-streams.ads +114 -0
- package/deps/zlib/contrib/ada/zlib-thin.adb +142 -0
- package/deps/zlib/contrib/ada/zlib-thin.ads +450 -0
- package/deps/zlib/contrib/ada/zlib.adb +701 -0
- package/deps/zlib/contrib/ada/zlib.ads +328 -0
- package/deps/zlib/contrib/ada/zlib.gpr +20 -0
- package/deps/zlib/contrib/blast/CMakeLists.txt +166 -0
- package/deps/zlib/contrib/blast/Makefile +14 -0
- package/deps/zlib/contrib/blast/README +4 -0
- package/deps/zlib/contrib/blast/blast-test.c +42 -0
- package/deps/zlib/contrib/blast/blast.c +422 -0
- package/deps/zlib/contrib/blast/blast.h +84 -0
- package/deps/zlib/contrib/blast/blastConfig.cmake.in +18 -0
- package/deps/zlib/contrib/blast/test/CMakeLists.txt +193 -0
- package/deps/zlib/contrib/blast/test/add_subdirectory_exclude_test.cmake.in +27 -0
- package/deps/zlib/contrib/blast/test/add_subdirectory_test.cmake.in +25 -0
- package/deps/zlib/contrib/blast/test/find_package_no_components_test.cmake.in +24 -0
- package/deps/zlib/contrib/blast/test/find_package_test.cmake.in +24 -0
- package/deps/zlib/contrib/blast/test/find_package_wrong_components_test.cmake.in +24 -0
- package/deps/zlib/contrib/blast/test.pk +0 -0
- package/deps/zlib/contrib/blast/test.txt +1 -0
- package/deps/zlib/contrib/blast/tester.cmake +28 -0
- package/deps/zlib/contrib/crc32vx/CMakeLists.txt +67 -0
- package/deps/zlib/contrib/crc32vx/README +9 -0
- package/deps/zlib/contrib/crc32vx/crc32_vx.c +254 -0
- package/deps/zlib/contrib/crc32vx/crc32_vx_hooks.h +9 -0
- package/deps/zlib/contrib/delphi/ZLib.pas +557 -0
- package/deps/zlib/contrib/delphi/ZLibConst.pas +11 -0
- package/deps/zlib/contrib/delphi/readme.txt +76 -0
- package/deps/zlib/contrib/delphi/zlibd32.mak +99 -0
- package/deps/zlib/contrib/dotzlib/DotZLib/AssemblyInfo.cs +58 -0
- package/deps/zlib/contrib/dotzlib/DotZLib/ChecksumImpl.cs +202 -0
- package/deps/zlib/contrib/dotzlib/DotZLib/CircularBuffer.cs +83 -0
- package/deps/zlib/contrib/dotzlib/DotZLib/CodecBase.cs +198 -0
- package/deps/zlib/contrib/dotzlib/DotZLib/Deflater.cs +106 -0
- package/deps/zlib/contrib/dotzlib/DotZLib/DotZLib.cs +288 -0
- package/deps/zlib/contrib/dotzlib/DotZLib/DotZLib.csproj +141 -0
- package/deps/zlib/contrib/dotzlib/DotZLib/GZipStream.cs +301 -0
- package/deps/zlib/contrib/dotzlib/DotZLib/Inflater.cs +105 -0
- package/deps/zlib/contrib/dotzlib/DotZLib/UnitTests.cs +274 -0
- package/deps/zlib/contrib/dotzlib/DotZLib.build +33 -0
- package/deps/zlib/contrib/dotzlib/DotZLib.chm +0 -0
- package/deps/zlib/contrib/dotzlib/DotZLib.sln +21 -0
- package/deps/zlib/contrib/dotzlib/LICENSE_1_0.txt +23 -0
- package/deps/zlib/contrib/dotzlib/readme.txt +58 -0
- package/deps/zlib/contrib/gcc_gvmat64/CMakeLists.txt +19 -0
- package/deps/zlib/contrib/gcc_gvmat64/gvmat64.S +570 -0
- package/deps/zlib/contrib/infback9/CMakeLists.txt +19 -0
- package/deps/zlib/contrib/infback9/README +1 -0
- package/deps/zlib/contrib/infback9/infback9.c +603 -0
- package/deps/zlib/contrib/infback9/infback9.h +37 -0
- package/deps/zlib/contrib/infback9/inffix9.h +107 -0
- package/deps/zlib/contrib/infback9/inflate9.h +47 -0
- package/deps/zlib/contrib/infback9/inftree9.c +319 -0
- package/deps/zlib/contrib/infback9/inftree9.h +61 -0
- package/deps/zlib/contrib/iostream/test.cpp +24 -0
- package/deps/zlib/contrib/iostream/zfstream.cpp +329 -0
- package/deps/zlib/contrib/iostream/zfstream.h +128 -0
- package/deps/zlib/contrib/iostream2/zstream.h +306 -0
- package/deps/zlib/contrib/iostream2/zstream_test.cpp +25 -0
- package/deps/zlib/contrib/iostream3/CMakeLists.txt +200 -0
- package/deps/zlib/contrib/iostream3/README +35 -0
- package/deps/zlib/contrib/iostream3/TODO +17 -0
- package/deps/zlib/contrib/iostream3/iostream3Config.cmake.in +23 -0
- package/deps/zlib/contrib/iostream3/test/CMakeLists.txt +191 -0
- package/deps/zlib/contrib/iostream3/test/add_subdirectory_exclude_test.cmake.in +27 -0
- package/deps/zlib/contrib/iostream3/test/add_subdirectory_test.cmake.in +25 -0
- package/deps/zlib/contrib/iostream3/test/find_package_no_components_test.cmake.in +24 -0
- package/deps/zlib/contrib/iostream3/test/find_package_test.cmake.in +24 -0
- package/deps/zlib/contrib/iostream3/test/find_package_wrong_components_test.cmake.in +24 -0
- package/deps/zlib/contrib/iostream3/test.cc +50 -0
- package/deps/zlib/contrib/iostream3/zfstream.cc +479 -0
- package/deps/zlib/contrib/iostream3/zfstream.h +466 -0
- package/deps/zlib/contrib/minizip/CMakeLists.txt +387 -0
- package/deps/zlib/contrib/minizip/LICENSE.Info-Zip +58 -0
- package/deps/zlib/contrib/minizip/Makefile +33 -0
- package/deps/zlib/contrib/minizip/Makefile.am +45 -0
- package/deps/zlib/contrib/minizip/MiniZip64_Changes.txt +6 -0
- package/deps/zlib/contrib/minizip/MiniZip64_info.txt +69 -0
- package/deps/zlib/contrib/minizip/configure.ac +32 -0
- package/deps/zlib/contrib/minizip/crypt.h +125 -0
- package/deps/zlib/contrib/minizip/ints.h +57 -0
- package/deps/zlib/contrib/minizip/ioapi.c +231 -0
- package/deps/zlib/contrib/minizip/ioapi.h +183 -0
- package/deps/zlib/contrib/minizip/iowin32.c +447 -0
- package/deps/zlib/contrib/minizip/iowin32.h +27 -0
- package/deps/zlib/contrib/minizip/make_vms.com +25 -0
- package/deps/zlib/contrib/minizip/miniunz.c +647 -0
- package/deps/zlib/contrib/minizip/miniunzip.1 +63 -0
- package/deps/zlib/contrib/minizip/minizip.1 +46 -0
- package/deps/zlib/contrib/minizip/minizip.c +511 -0
- package/deps/zlib/contrib/minizip/minizip.pc.in +13 -0
- package/deps/zlib/contrib/minizip/minizip.pc.txt +13 -0
- package/deps/zlib/contrib/minizip/minizipConfig.cmake.in +27 -0
- package/deps/zlib/contrib/minizip/mztools.c +294 -0
- package/deps/zlib/contrib/minizip/mztools.h +37 -0
- package/deps/zlib/contrib/minizip/skipset.h +366 -0
- package/deps/zlib/contrib/minizip/test/CMakeLists.txt +176 -0
- package/deps/zlib/contrib/minizip/test/add_subdirectory_exclude_test.cmake.in +29 -0
- package/deps/zlib/contrib/minizip/test/add_subdirectory_test.cmake.in +28 -0
- package/deps/zlib/contrib/minizip/test/find_package_no_components_test.cmake.in +26 -0
- package/deps/zlib/contrib/minizip/test/find_package_test.cmake.in +26 -0
- package/deps/zlib/contrib/minizip/test/find_package_wrong_components_test.cmake.in +26 -0
- package/deps/zlib/contrib/minizip/test/test_helper.cm +32 -0
- package/deps/zlib/contrib/minizip/unzip.c +1984 -0
- package/deps/zlib/contrib/minizip/unzip.h +442 -0
- package/deps/zlib/contrib/minizip/zip.c +2246 -0
- package/deps/zlib/contrib/minizip/zip.h +371 -0
- package/deps/zlib/contrib/nuget/nuget.csproj +45 -0
- package/deps/zlib/contrib/nuget/nuget.sln +22 -0
- package/deps/zlib/contrib/pascal/example.pas +599 -0
- package/deps/zlib/contrib/pascal/readme.txt +76 -0
- package/deps/zlib/contrib/pascal/zlibd32.mak +99 -0
- package/deps/zlib/contrib/pascal/zlibpas.pas +276 -0
- package/deps/zlib/contrib/puff/CMakeLists.txt +154 -0
- package/deps/zlib/contrib/puff/Makefile +42 -0
- package/deps/zlib/contrib/puff/README +63 -0
- package/deps/zlib/contrib/puff/bin-writer.c +26 -0
- package/deps/zlib/contrib/puff/puff.c +840 -0
- package/deps/zlib/contrib/puff/puff.h +35 -0
- package/deps/zlib/contrib/puff/puffConfig.cmake.in +18 -0
- package/deps/zlib/contrib/puff/pufftest.c +168 -0
- package/deps/zlib/contrib/puff/test/CMakeLists.txt +262 -0
- package/deps/zlib/contrib/puff/test/add_subdirectory_exclude_test.cmake.in +26 -0
- package/deps/zlib/contrib/puff/test/add_subdirectory_test.cmake.in +25 -0
- package/deps/zlib/contrib/puff/test/find_package_no_components_test.cmake.in +24 -0
- package/deps/zlib/contrib/puff/test/find_package_test.cmake.in +24 -0
- package/deps/zlib/contrib/puff/test/find_package_wrong_components_test.cmake.in +24 -0
- package/deps/zlib/contrib/puff/test/tester-cov.cmake +58 -0
- package/deps/zlib/contrib/puff/test/tester.cmake +16 -0
- package/deps/zlib/contrib/puff/zeros.raw +0 -0
- package/deps/zlib/contrib/testzlib/CMakeLists.txt +44 -0
- package/deps/zlib/contrib/testzlib/testzlib.c +275 -0
- package/deps/zlib/contrib/testzlib/testzlib.txt +10 -0
- package/deps/zlib/contrib/vstudio/readme.txt +22 -0
- package/deps/zlib/contrib/zlib1-dll/CMakeLists.txt +196 -0
- package/deps/zlib/contrib/zlib1-dll/readme.txt +21 -0
- package/deps/zlib/crc32.c +983 -0
- package/deps/zlib/crc32.h +9446 -0
- package/deps/zlib/deflate.c +2185 -0
- package/deps/zlib/deflate.h +383 -0
- package/deps/zlib/doc/algorithm.txt +209 -0
- package/deps/zlib/doc/crc-doc.1.0.pdf +0 -0
- package/deps/zlib/doc/rfc1950.txt +619 -0
- package/deps/zlib/doc/rfc1951.txt +955 -0
- package/deps/zlib/doc/rfc1952.txt +675 -0
- package/deps/zlib/doc/txtvsbin.txt +107 -0
- package/deps/zlib/examples/README.examples +54 -0
- package/deps/zlib/examples/enough.c +597 -0
- package/deps/zlib/examples/fitblk.c +233 -0
- package/deps/zlib/examples/gun.c +702 -0
- package/deps/zlib/examples/gzappend.c +504 -0
- package/deps/zlib/examples/gzjoin.c +449 -0
- package/deps/zlib/examples/gzlog.c +1061 -0
- package/deps/zlib/examples/gzlog.h +91 -0
- package/deps/zlib/examples/gznorm.c +474 -0
- package/deps/zlib/examples/zlib_how.html +550 -0
- package/deps/zlib/examples/zpipe.c +206 -0
- package/deps/zlib/examples/zran.c +546 -0
- package/deps/zlib/examples/zran.h +53 -0
- package/deps/zlib/gzclose.c +23 -0
- package/deps/zlib/gzguts.h +216 -0
- package/deps/zlib/gzlib.c +609 -0
- package/deps/zlib/gzread.c +668 -0
- package/deps/zlib/gzwrite.c +700 -0
- package/deps/zlib/infback.c +581 -0
- package/deps/zlib/inffast.c +321 -0
- package/deps/zlib/inffast.h +11 -0
- package/deps/zlib/inffixed.h +94 -0
- package/deps/zlib/inflate.c +1413 -0
- package/deps/zlib/inflate.h +126 -0
- package/deps/zlib/inftrees.c +424 -0
- package/deps/zlib/inftrees.h +64 -0
- package/deps/zlib/make_vms.com +867 -0
- package/deps/zlib/msdos/Makefile.bor +115 -0
- package/deps/zlib/msdos/Makefile.dj2 +104 -0
- package/deps/zlib/msdos/Makefile.emx +69 -0
- package/deps/zlib/msdos/Makefile.msc +112 -0
- package/deps/zlib/msdos/Makefile.tc +100 -0
- package/deps/zlib/os400/README400 +48 -0
- package/deps/zlib/os400/bndsrc +144 -0
- package/deps/zlib/os400/make.sh +383 -0
- package/deps/zlib/os400/zlibfixed.rpgle +578 -0
- package/deps/zlib/os400/zlibfree.rpgle +634 -0
- package/deps/zlib/qnx/package.qpg +141 -0
- package/deps/zlib/test/CMakeLists.txt +318 -0
- package/deps/zlib/test/add_subdirectory_exclude_test.cmake.in +29 -0
- package/deps/zlib/test/add_subdirectory_test.cmake.in +28 -0
- package/deps/zlib/test/example.c +552 -0
- package/deps/zlib/test/find_package_no_components_test.cmake.in +27 -0
- package/deps/zlib/test/find_package_test.cmake.in +27 -0
- package/deps/zlib/test/find_package_wrong_components_test.cmake.in +27 -0
- package/deps/zlib/test/infcover.c +672 -0
- package/deps/zlib/test/minigzip.c +592 -0
- package/deps/zlib/treebuild.xml +116 -0
- package/deps/zlib/trees.c +1119 -0
- package/deps/zlib/trees.h +128 -0
- package/deps/zlib/uncompr.c +101 -0
- package/deps/zlib/watcom/watcom_f.mak +43 -0
- package/deps/zlib/watcom/watcom_l.mak +43 -0
- package/deps/zlib/win32/DLL_FAQ.txt +381 -0
- package/deps/zlib/win32/Makefile.bor +109 -0
- package/deps/zlib/win32/Makefile.gcc +177 -0
- package/deps/zlib/win32/Makefile.msc +159 -0
- package/deps/zlib/win32/README-WIN32.txt +103 -0
- package/deps/zlib/win32/VisualC.txt +3 -0
- package/deps/zlib/win32/zlib.def +104 -0
- package/deps/zlib/win32/zlib1.rc +37 -0
- package/deps/zlib/zconf.h.in +551 -0
- package/deps/zlib/zlib.3 +149 -0
- package/deps/zlib/zlib.3.pdf +0 -0
- package/deps/zlib/zlib.h +2057 -0
- package/deps/zlib/zlib.map +116 -0
- package/deps/zlib/zlib.pc.cmakein +14 -0
- package/deps/zlib/zlib.pc.in +14 -0
- package/deps/zlib/zlibConfig.cmake.in +18 -0
- package/deps/zlib/zutil.c +313 -0
- package/deps/zlib/zutil.h +331 -0
- package/dist/index.d.ts +266 -0
- package/dist/index.js +1146 -0
- package/dist/libwz.js +5632 -0
- package/dist/libwz.wasm +0 -0
- package/include/wz/CRC32.h +182 -0
- package/include/wz/PngUtility.h +72 -0
- package/include/wz/PortalType.h +124 -0
- package/include/wz/Properties/WzBinaryProperty.h +70 -0
- package/include/wz/Properties/WzCanvasProperty.h +55 -0
- package/include/wz/Properties/WzConvexProperty.h +34 -0
- package/include/wz/Properties/WzDoubleProperty.h +32 -0
- package/include/wz/Properties/WzFloatProperty.h +30 -0
- package/include/wz/Properties/WzIntProperty.h +30 -0
- package/include/wz/Properties/WzLongProperty.h +30 -0
- package/include/wz/Properties/WzLuaProperty.h +31 -0
- package/include/wz/Properties/WzNullProperty.h +15 -0
- package/include/wz/Properties/WzPngProperty.h +53 -0
- package/include/wz/Properties/WzRawDataProperty.h +46 -0
- package/include/wz/Properties/WzShortProperty.h +31 -0
- package/include/wz/Properties/WzStringProperty.h +32 -0
- package/include/wz/Properties/WzSubProperty.h +35 -0
- package/include/wz/Properties/WzUOLProperty.h +44 -0
- package/include/wz/Properties/WzVectorProperty.h +40 -0
- package/include/wz/Properties/WzVideoProperty.h +43 -0
- package/include/wz/Result.h +58 -0
- package/include/wz/Util/Defines.h +16 -0
- package/include/wz/Util/ListFileParser.h +20 -0
- package/include/wz/Util/WzBinaryReader.h +95 -0
- package/include/wz/Util/WzBinaryWriter.h +72 -0
- package/include/wz/Util/WzBlobDataSource.h +30 -0
- package/include/wz/Util/WzDataSource.h +49 -0
- package/include/wz/Util/WzKeyGenerator.h +28 -0
- package/include/wz/Util/WzMutableKey.h +39 -0
- package/include/wz/Util/WzPath.h +37 -0
- package/include/wz/Util/WzStream.h +86 -0
- package/include/wz/Util/WzTool.h +42 -0
- package/include/wz/WzAESConstant.h +17 -0
- package/include/wz/WzDirectory.h +97 -0
- package/include/wz/WzEnums.h +76 -0
- package/include/wz/WzFile.h +99 -0
- package/include/wz/WzHeader.h +47 -0
- package/include/wz/WzImage.h +97 -0
- package/include/wz/WzImageProperty.h +92 -0
- package/include/wz/WzObject.h +55 -0
- package/include/wz/WzPropertyCollection.h +115 -0
- package/include/wz/wz.h +41 -0
- package/include/wz/wz_api.h +432 -0
- package/package.json +93 -0
- package/src/PngUtility.cpp +328 -0
- package/src/Properties/WzBinaryProperty.cpp +183 -0
- package/src/Properties/WzCanvasProperty.cpp +262 -0
- package/src/Properties/WzConvexProperty.cpp +159 -0
- package/src/Properties/WzDoubleProperty.cpp +12 -0
- package/src/Properties/WzFloatProperty.cpp +17 -0
- package/src/Properties/WzIntProperty.cpp +12 -0
- package/src/Properties/WzLongProperty.cpp +12 -0
- package/src/Properties/WzLuaProperty.cpp +37 -0
- package/src/Properties/WzNullProperty.cpp +11 -0
- package/src/Properties/WzPngProperty.cpp +637 -0
- package/src/Properties/WzRawDataProperty.cpp +116 -0
- package/src/Properties/WzShortProperty.cpp +12 -0
- package/src/Properties/WzStringProperty.cpp +44 -0
- package/src/Properties/WzSubProperty.cpp +129 -0
- package/src/Properties/WzUOLProperty.cpp +136 -0
- package/src/Properties/WzVectorProperty.cpp +22 -0
- package/src/Properties/WzVideoProperty.cpp +115 -0
- package/src/Util/ListFileParser.cpp +48 -0
- package/src/Util/WzBinaryReader.cpp +368 -0
- package/src/Util/WzBinaryWriter.cpp +305 -0
- package/src/Util/WzBlobDataSource.cpp +47 -0
- package/src/Util/WzDataSource.cpp +61 -0
- package/src/Util/WzKeyGenerator.cpp +43 -0
- package/src/Util/WzMutableKey.cpp +59 -0
- package/src/Util/WzStream.cpp +196 -0
- package/src/Util/WzTool.cpp +266 -0
- package/src/WzAESConstant.cpp +12 -0
- package/src/WzDirectory.cpp +669 -0
- package/src/WzEnums.cpp +20 -0
- package/src/WzFile.cpp +450 -0
- package/src/WzImage.cpp +350 -0
- package/src/WzImageProperty.cpp +469 -0
- package/src/WzObject.cpp +174 -0
- package/src/WzPropertyCollection.cpp +84 -0
- package/src/capi/wz_api.cpp +1996 -0
- package/src/node/binding.cpp +1776 -0
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
#include "wz/PngUtility.h"
|
|
2
|
+
#include <cstring>
|
|
3
|
+
|
|
4
|
+
namespace wz {
|
|
5
|
+
|
|
6
|
+
RGBColor PngUtility::RGB565ToColor(uint16_t val) {
|
|
7
|
+
constexpr int rgb565_mask_r = 0xf800;
|
|
8
|
+
constexpr int rgb565_mask_g = 0x07e0;
|
|
9
|
+
constexpr int rgb565_mask_b = 0x001f;
|
|
10
|
+
int r = (val & rgb565_mask_r) >> 11;
|
|
11
|
+
int g = (val & rgb565_mask_g) >> 5;
|
|
12
|
+
int b = (val & rgb565_mask_b);
|
|
13
|
+
return {static_cast<uint8_t>((r << 3) | (r >> 2)),
|
|
14
|
+
static_cast<uint8_t>((g << 2) | (g >> 4)),
|
|
15
|
+
static_cast<uint8_t>((b << 3) | (b >> 2))};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
Result<void> PngUtility::DecompressImagePixelDataBgra4444(
|
|
19
|
+
const std::vector<uint8_t>& rawData,
|
|
20
|
+
int width,
|
|
21
|
+
int height,
|
|
22
|
+
std::vector<uint8_t>& output) {
|
|
23
|
+
int uncompressedSize = width * height * 2;
|
|
24
|
+
if (static_cast<int>(rawData.size()) < uncompressedSize)
|
|
25
|
+
return std::unexpected(Error::InvalidArgument(
|
|
26
|
+
"Raw data length is insufficient for the specified dimensions."));
|
|
27
|
+
|
|
28
|
+
output.resize(width * height * 4);
|
|
29
|
+
|
|
30
|
+
// BGRA4444: each input byte has 2 nibbles (4-bit values)
|
|
31
|
+
// byte 0: low nibble = B, high nibble = G (first pixel)
|
|
32
|
+
// byte 1: low nibble = R, high nibble = A (first pixel)
|
|
33
|
+
// Output format: B, G, R, A per pixel (BGRA32)
|
|
34
|
+
for (int i = 0; i < uncompressedSize; i += 2) {
|
|
35
|
+
int pixelIdx = i / 2;
|
|
36
|
+
uint8_t b_lo = rawData[i] & 0x0F;
|
|
37
|
+
uint8_t g_hi = (rawData[i] & 0xF0) >> 4;
|
|
38
|
+
uint8_t r_lo = rawData[i + 1] & 0x0F;
|
|
39
|
+
uint8_t a_hi = (rawData[i + 1] & 0xF0) >> 4;
|
|
40
|
+
|
|
41
|
+
output[pixelIdx * 4 + 0] = static_cast<uint8_t>(b_lo | (b_lo << 4));
|
|
42
|
+
output[pixelIdx * 4 + 1] = static_cast<uint8_t>(g_hi | (g_hi << 4));
|
|
43
|
+
output[pixelIdx * 4 + 2] = static_cast<uint8_t>(r_lo | (r_lo << 4));
|
|
44
|
+
output[pixelIdx * 4 + 3] = static_cast<uint8_t>(a_hi | (a_hi << 4));
|
|
45
|
+
}
|
|
46
|
+
return {};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
void PngUtility::ExpandColorTable(RGBColor color[4], uint16_t c0, uint16_t c1) {
|
|
50
|
+
color[0] = RGB565ToColor(c0);
|
|
51
|
+
color[1] = RGB565ToColor(c1);
|
|
52
|
+
if (c0 > c1) {
|
|
53
|
+
color[2] = {static_cast<uint8_t>((static_cast<int>(color[0].R) * 2 +
|
|
54
|
+
static_cast<int>(color[1].R) + 1) /
|
|
55
|
+
3),
|
|
56
|
+
static_cast<uint8_t>((static_cast<int>(color[0].G) * 2 +
|
|
57
|
+
static_cast<int>(color[1].G) + 1) /
|
|
58
|
+
3),
|
|
59
|
+
static_cast<uint8_t>((static_cast<int>(color[0].B) * 2 +
|
|
60
|
+
static_cast<int>(color[1].B) + 1) /
|
|
61
|
+
3)};
|
|
62
|
+
color[3] = {static_cast<uint8_t>((static_cast<int>(color[0].R) +
|
|
63
|
+
static_cast<int>(color[1].R) * 2 + 1) /
|
|
64
|
+
3),
|
|
65
|
+
static_cast<uint8_t>((static_cast<int>(color[0].G) +
|
|
66
|
+
static_cast<int>(color[1].G) * 2 + 1) /
|
|
67
|
+
3),
|
|
68
|
+
static_cast<uint8_t>((static_cast<int>(color[0].B) +
|
|
69
|
+
static_cast<int>(color[1].B) * 2 + 1) /
|
|
70
|
+
3)};
|
|
71
|
+
} else {
|
|
72
|
+
color[2] = {
|
|
73
|
+
static_cast<uint8_t>(
|
|
74
|
+
(static_cast<int>(color[0].R) + static_cast<int>(color[1].R)) / 2),
|
|
75
|
+
static_cast<uint8_t>(
|
|
76
|
+
(static_cast<int>(color[0].G) + static_cast<int>(color[1].G)) / 2),
|
|
77
|
+
static_cast<uint8_t>(
|
|
78
|
+
(static_cast<int>(color[0].B) + static_cast<int>(color[1].B)) / 2)};
|
|
79
|
+
color[3] = {0, 0, 0};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
void PngUtility::ExpandColorIndexTable(int colorIndex[16],
|
|
84
|
+
const uint8_t* rawData,
|
|
85
|
+
int offset) {
|
|
86
|
+
for (int i = 0; i < 16; i += 4, offset++) {
|
|
87
|
+
colorIndex[i + 0] = (rawData[offset] & 0x03);
|
|
88
|
+
colorIndex[i + 1] = (rawData[offset] & 0x0c) >> 2;
|
|
89
|
+
colorIndex[i + 2] = (rawData[offset] & 0x30) >> 4;
|
|
90
|
+
colorIndex[i + 3] = (rawData[offset] & 0xc0) >> 6;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
void PngUtility::ExpandAlphaTableDXT3(uint8_t alpha[16],
|
|
95
|
+
const uint8_t* rawData,
|
|
96
|
+
int offset) {
|
|
97
|
+
for (int i = 0; i < 16; i += 2, offset++) {
|
|
98
|
+
alpha[i + 0] = rawData[offset] & 0x0f;
|
|
99
|
+
alpha[i + 1] = (rawData[offset] & 0xf0) >> 4;
|
|
100
|
+
}
|
|
101
|
+
for (int i = 0; i < 16; i++) {
|
|
102
|
+
alpha[i] = static_cast<uint8_t>(alpha[i] | (alpha[i] << 4));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
void PngUtility::ExpandAlphaTableDXT5(uint8_t alpha[8],
|
|
107
|
+
uint8_t a0,
|
|
108
|
+
uint8_t a1) {
|
|
109
|
+
alpha[0] = a0;
|
|
110
|
+
alpha[1] = a1;
|
|
111
|
+
if (a0 > a1) {
|
|
112
|
+
for (int i = 2; i < 8; i++) {
|
|
113
|
+
alpha[i] = static_cast<uint8_t>(((8 - i) * static_cast<int>(a0) +
|
|
114
|
+
(i - 1) * static_cast<int>(a1) + 3) /
|
|
115
|
+
7);
|
|
116
|
+
}
|
|
117
|
+
} else {
|
|
118
|
+
for (int i = 2; i < 6; i++) {
|
|
119
|
+
alpha[i] = static_cast<uint8_t>(((6 - i) * static_cast<int>(a0) +
|
|
120
|
+
(i - 1) * static_cast<int>(a1) + 2) /
|
|
121
|
+
5);
|
|
122
|
+
}
|
|
123
|
+
alpha[6] = 0;
|
|
124
|
+
alpha[7] = 255;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
void PngUtility::ExpandAlphaIndexTableDXT5(int alphaIndex[16],
|
|
129
|
+
const uint8_t* rawData,
|
|
130
|
+
int offset) {
|
|
131
|
+
for (int i = 0; i < 16; i += 8, offset += 3) {
|
|
132
|
+
int flags = rawData[offset] | (rawData[offset + 1] << 8) |
|
|
133
|
+
(rawData[offset + 2] << 16);
|
|
134
|
+
for (int j = 0; j < 8; j++) {
|
|
135
|
+
int mask = 0x07 << (3 * j);
|
|
136
|
+
alphaIndex[i + j] = (flags & mask) >> (3 * j);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
static void SetPixel(std::vector<uint8_t>& pixelData,
|
|
142
|
+
int x,
|
|
143
|
+
int y,
|
|
144
|
+
int width,
|
|
145
|
+
RGBColor color,
|
|
146
|
+
uint8_t alpha) {
|
|
147
|
+
int offset = (y * width + x) * 4;
|
|
148
|
+
pixelData[offset + 0] = color.B;
|
|
149
|
+
pixelData[offset + 1] = color.G;
|
|
150
|
+
pixelData[offset + 2] = color.R;
|
|
151
|
+
pixelData[offset + 3] = alpha;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
Result<void> PngUtility::DecompressImageDXT3(
|
|
155
|
+
const std::vector<uint8_t>& rawData,
|
|
156
|
+
int width,
|
|
157
|
+
int height,
|
|
158
|
+
std::vector<uint8_t>& output) {
|
|
159
|
+
int blockCountX = (width + 3) / 4;
|
|
160
|
+
int blockCountY = (height + 3) / 4;
|
|
161
|
+
int expectedSize = blockCountX * blockCountY * 16;
|
|
162
|
+
if (static_cast<int>(rawData.size()) < expectedSize)
|
|
163
|
+
return std::unexpected(Error::InvalidArgument(
|
|
164
|
+
"Raw data length insufficient for DXT3 decompression."));
|
|
165
|
+
|
|
166
|
+
output.resize(width * height * 4);
|
|
167
|
+
|
|
168
|
+
RGBColor colorTable[4];
|
|
169
|
+
int colorIdxTable[16];
|
|
170
|
+
uint8_t alphaTable[16];
|
|
171
|
+
|
|
172
|
+
for (int blockY = 0; blockY < blockCountY; blockY++) {
|
|
173
|
+
for (int blockX = 0; blockX < blockCountX; blockX++) {
|
|
174
|
+
int blockIndex = blockY * blockCountX + blockX;
|
|
175
|
+
int off = blockIndex * 16;
|
|
176
|
+
int x = blockX * 4;
|
|
177
|
+
int y = blockY * 4;
|
|
178
|
+
|
|
179
|
+
ExpandAlphaTableDXT3(alphaTable, rawData.data(), off);
|
|
180
|
+
uint16_t u0 =
|
|
181
|
+
static_cast<uint16_t>(rawData[off + 8] | (rawData[off + 9] << 8));
|
|
182
|
+
uint16_t u1 =
|
|
183
|
+
static_cast<uint16_t>(rawData[off + 10] | (rawData[off + 11] << 8));
|
|
184
|
+
ExpandColorTable(colorTable, u0, u1);
|
|
185
|
+
ExpandColorIndexTable(colorIdxTable, rawData.data(), off + 12);
|
|
186
|
+
|
|
187
|
+
for (int j = 0; j < 4; j++) {
|
|
188
|
+
int pixelY = y + j;
|
|
189
|
+
if (pixelY >= height) continue;
|
|
190
|
+
for (int i = 0; i < 4; i++) {
|
|
191
|
+
int pixelX = x + i;
|
|
192
|
+
if (pixelX >= width) continue;
|
|
193
|
+
RGBColor c = colorTable[colorIdxTable[j * 4 + i]];
|
|
194
|
+
uint8_t alpha = alphaTable[j * 4 + i];
|
|
195
|
+
SetPixel(output, pixelX, pixelY, width, c, alpha);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return {};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
Result<void> PngUtility::DecompressImageDXT5(
|
|
204
|
+
const std::vector<uint8_t>& rawData,
|
|
205
|
+
int width,
|
|
206
|
+
int height,
|
|
207
|
+
std::vector<uint8_t>& output) {
|
|
208
|
+
int blockCountX = (width + 3) / 4;
|
|
209
|
+
int blockCountY = (height + 3) / 4;
|
|
210
|
+
int expectedSize = blockCountX * blockCountY * 16;
|
|
211
|
+
if (static_cast<int>(rawData.size()) < expectedSize)
|
|
212
|
+
return std::unexpected(Error::InvalidArgument(
|
|
213
|
+
"Raw data length insufficient for DXT5 decompression."));
|
|
214
|
+
|
|
215
|
+
if (width <= 0 || height <= 0)
|
|
216
|
+
return std::unexpected(
|
|
217
|
+
Error::InvalidArgument("Width and height must be positive."));
|
|
218
|
+
|
|
219
|
+
output.resize(width * height * 4);
|
|
220
|
+
|
|
221
|
+
RGBColor colorTable[4];
|
|
222
|
+
int colorIdxTable[16];
|
|
223
|
+
uint8_t alphaTable[8];
|
|
224
|
+
int alphaIdxTable[16];
|
|
225
|
+
|
|
226
|
+
for (int blockY = 0; blockY < blockCountY; blockY++) {
|
|
227
|
+
for (int blockX = 0; blockX < blockCountX; blockX++) {
|
|
228
|
+
int blockIndex = blockY * blockCountX + blockX;
|
|
229
|
+
int off = blockIndex * 16;
|
|
230
|
+
int x = blockX * 4;
|
|
231
|
+
int y = blockY * 4;
|
|
232
|
+
|
|
233
|
+
ExpandAlphaTableDXT5(alphaTable, rawData[off], rawData[off + 1]);
|
|
234
|
+
ExpandAlphaIndexTableDXT5(alphaIdxTable, rawData.data(), off + 2);
|
|
235
|
+
uint16_t u0 =
|
|
236
|
+
static_cast<uint16_t>(rawData[off + 8] | (rawData[off + 9] << 8));
|
|
237
|
+
uint16_t u1 =
|
|
238
|
+
static_cast<uint16_t>(rawData[off + 10] | (rawData[off + 11] << 8));
|
|
239
|
+
ExpandColorTable(colorTable, u0, u1);
|
|
240
|
+
ExpandColorIndexTable(colorIdxTable, rawData.data(), off + 12);
|
|
241
|
+
|
|
242
|
+
for (int j = 0; j < 4; j++) {
|
|
243
|
+
int pixelY = y + j;
|
|
244
|
+
if (pixelY >= height) continue;
|
|
245
|
+
for (int i = 0; i < 4; i++) {
|
|
246
|
+
int pixelX = x + i;
|
|
247
|
+
if (pixelX >= width) continue;
|
|
248
|
+
RGBColor c = colorTable[colorIdxTable[j * 4 + i]];
|
|
249
|
+
uint8_t alpha = alphaTable[alphaIdxTable[j * 4 + i]];
|
|
250
|
+
SetPixel(output, pixelX, pixelY, width, c, alpha);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return {};
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
void PngUtility::DecompressImagePixelDataForm517(
|
|
259
|
+
const std::vector<uint8_t>& rawData,
|
|
260
|
+
int width,
|
|
261
|
+
int height,
|
|
262
|
+
std::vector<uint8_t>& output) {
|
|
263
|
+
int blockCountX = width / 16;
|
|
264
|
+
int blockCountY = height / 16;
|
|
265
|
+
output.resize(width * height * 2);
|
|
266
|
+
|
|
267
|
+
int lineIndex = 0;
|
|
268
|
+
for (int j0 = 0; j0 < blockCountY; j0++) {
|
|
269
|
+
auto dstIndex = lineIndex;
|
|
270
|
+
for (int i0 = 0; i0 < blockCountX; i0++) {
|
|
271
|
+
int idx = (i0 + j0 * blockCountX) * 2;
|
|
272
|
+
uint8_t b0 = rawData[idx];
|
|
273
|
+
uint8_t b1 = rawData[idx + 1];
|
|
274
|
+
for (int k = 0; k < 16; k++) {
|
|
275
|
+
output[dstIndex++] = b0;
|
|
276
|
+
output[dstIndex++] = b1;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
for (int k = 1; k < 16; k++) {
|
|
280
|
+
std::memcpy(
|
|
281
|
+
output.data() + dstIndex, output.data() + lineIndex, width * 2);
|
|
282
|
+
dstIndex += width * 2;
|
|
283
|
+
}
|
|
284
|
+
lineIndex += width * 32;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
void PngUtility::CopyBmpDataWithStride(const std::vector<uint8_t>& source,
|
|
289
|
+
int srcStride,
|
|
290
|
+
int dstHeight,
|
|
291
|
+
int dstStride,
|
|
292
|
+
std::vector<uint8_t>& output) {
|
|
293
|
+
output.resize(dstHeight * dstStride);
|
|
294
|
+
if (dstStride == srcStride) {
|
|
295
|
+
std::memcpy(output.data(), source.data(), source.size());
|
|
296
|
+
} else {
|
|
297
|
+
for (int y = 0; y < dstHeight; y++) {
|
|
298
|
+
std::memcpy(output.data() + dstStride * y,
|
|
299
|
+
source.data() + srcStride * y,
|
|
300
|
+
std::min(srcStride, dstStride));
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
int PngUtility::GetUncompressedSizeByFormat(int width, int height, int format) {
|
|
306
|
+
switch (format) {
|
|
307
|
+
case 1:
|
|
308
|
+
return width * height * 2; // BGRA4444
|
|
309
|
+
case 2:
|
|
310
|
+
return width * height * 4; // BGRA8888
|
|
311
|
+
case 3:
|
|
312
|
+
return width * height * 4; // DXT3 grayscale
|
|
313
|
+
case 257:
|
|
314
|
+
return width * height * 2; // ARGB1555
|
|
315
|
+
case 513:
|
|
316
|
+
return width * height * 2; // RGB565
|
|
317
|
+
case 517:
|
|
318
|
+
return (width / 16) * (height / 16) * 2; // Format517
|
|
319
|
+
case 1026:
|
|
320
|
+
return width * height * 4; // DXT3 color
|
|
321
|
+
case 2050:
|
|
322
|
+
return width * height; // DXT5 raw alpha only
|
|
323
|
+
default:
|
|
324
|
+
return width * height * 4;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
} // namespace wz
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
#include "wz/Properties/WzBinaryProperty.h"
|
|
2
|
+
#include <cstring>
|
|
3
|
+
#include <filesystem>
|
|
4
|
+
#include <mutex>
|
|
5
|
+
#include "wz/Util/WzBinaryReader.h"
|
|
6
|
+
#include "wz/Util/WzBinaryWriter.h"
|
|
7
|
+
#include "wz/Util/WzPath.h"
|
|
8
|
+
#include "wz/Util/WzStream.h"
|
|
9
|
+
#include "wz/WzImage.h"
|
|
10
|
+
|
|
11
|
+
namespace wz {
|
|
12
|
+
|
|
13
|
+
static constexpr size_t kSoundHeaderSize = 51;
|
|
14
|
+
|
|
15
|
+
WzBinaryProperty::WzBinaryProperty(const std::string& name,
|
|
16
|
+
WzBinaryReader* reader,
|
|
17
|
+
bool parseNow)
|
|
18
|
+
: wzReader_(reader) {
|
|
19
|
+
SetName(name);
|
|
20
|
+
|
|
21
|
+
reader->ReadByte(); // skip 1
|
|
22
|
+
|
|
23
|
+
soundDataLen_ = reader->ReadCompressedInt();
|
|
24
|
+
lenMs_ = reader->ReadCompressedInt();
|
|
25
|
+
|
|
26
|
+
// Peek wavFormatLen by jumping past the sound header GUIDs
|
|
27
|
+
int64_t headerOff = reader->Position();
|
|
28
|
+
reader->SetPosition(headerOff + kSoundHeaderSize);
|
|
29
|
+
int wavFormatLen = reader->ReadByte();
|
|
30
|
+
reader->SetPosition(headerOff);
|
|
31
|
+
|
|
32
|
+
// Read header: soundHeader (51) + wavFormatLen (1) + waveFormat (N)
|
|
33
|
+
auto soundHeaderBytes = reader->ReadBytes(kSoundHeaderSize);
|
|
34
|
+
uint8_t unk1 = reader->ReadByte(); // wavFormatLen
|
|
35
|
+
auto waveFormatBytes = reader->ReadBytes(wavFormatLen);
|
|
36
|
+
|
|
37
|
+
header_.reserve(kSoundHeaderSize + 1 + wavFormatLen);
|
|
38
|
+
header_.insert(
|
|
39
|
+
header_.end(), soundHeaderBytes.begin(), soundHeaderBytes.end());
|
|
40
|
+
header_.push_back(unk1);
|
|
41
|
+
header_.insert(header_.end(), waveFormatBytes.begin(), waveFormatBytes.end());
|
|
42
|
+
|
|
43
|
+
ParseWzSoundPropertyHeader();
|
|
44
|
+
|
|
45
|
+
offs_ = reader->Position();
|
|
46
|
+
if (parseNow)
|
|
47
|
+
fileBytes_ = reader->ReadBytes(soundDataLen_);
|
|
48
|
+
else
|
|
49
|
+
reader->SetPosition(offs_ + soundDataLen_);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
Result<void> WzBinaryProperty::WriteValue(WzBinaryWriter* writer) const {
|
|
53
|
+
auto* self = const_cast<WzBinaryProperty*>(this);
|
|
54
|
+
auto data = self->GetBytes(false);
|
|
55
|
+
if (!data.has_value()) return std::unexpected(data.error());
|
|
56
|
+
|
|
57
|
+
writer->WriteStringValue("Sound_DX8",
|
|
58
|
+
WzImage::WzImageHeaderByte_WithoutOffset,
|
|
59
|
+
WzImage::WzImageHeaderByte_WithOffset);
|
|
60
|
+
writer->WriteByte(0);
|
|
61
|
+
writer->WriteCompressedInt(static_cast<int32_t>(data.value().size()));
|
|
62
|
+
writer->WriteCompressedInt(lenMs_);
|
|
63
|
+
if (!writer->BaseStream().Write(header_.data(), header_.size()) ||
|
|
64
|
+
!writer->BaseStream().Write(data.value().data(), data.value().size())) {
|
|
65
|
+
return std::unexpected(Error::IoError("Failed to write binary property"));
|
|
66
|
+
}
|
|
67
|
+
return {};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
void WzBinaryProperty::ParseWzSoundPropertyHeader() {
|
|
71
|
+
if (header_.size() < kSoundHeaderSize + 1 + sizeof(WzWaveFormat)) {
|
|
72
|
+
type_ = WzBinaryPropertyType::Raw;
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
size_t wavHeaderLen = header_.size() - kSoundHeaderSize - 1;
|
|
77
|
+
const uint8_t* wavBytes = header_.data() + kSoundHeaderSize + 1;
|
|
78
|
+
|
|
79
|
+
auto* wfx = reinterpret_cast<const WzWaveFormat*>(wavBytes);
|
|
80
|
+
size_t expectedSize = sizeof(WzWaveFormat) + wfx->cbSize;
|
|
81
|
+
|
|
82
|
+
if (expectedSize != wavHeaderLen) {
|
|
83
|
+
if (!wzReader_) {
|
|
84
|
+
type_ = WzBinaryPropertyType::Raw;
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Try XOR decrypting the wave format header with WzKey (List.wz)
|
|
89
|
+
std::vector<uint8_t> decrypted(wavHeaderLen);
|
|
90
|
+
auto& wzKey = wzReader_->GetWzKey();
|
|
91
|
+
for (size_t i = 0; i < wavHeaderLen; i++) {
|
|
92
|
+
decrypted[i] = wavBytes[i] ^ wzKey[i];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
wfx = reinterpret_cast<const WzWaveFormat*>(decrypted.data());
|
|
96
|
+
expectedSize = sizeof(WzWaveFormat) + wfx->cbSize;
|
|
97
|
+
if (expectedSize != wavHeaderLen) {
|
|
98
|
+
type_ = WzBinaryPropertyType::Raw;
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
headerEncrypted_ = true;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
wavFormat_ = *wfx;
|
|
105
|
+
|
|
106
|
+
if (wfx->wFormatTag == 0x0055 && wavHeaderLen >= sizeof(WzMp3WaveFormat)) {
|
|
107
|
+
type_ = WzBinaryPropertyType::MP3;
|
|
108
|
+
} else if (wfx->wFormatTag == 1) {
|
|
109
|
+
type_ = WzBinaryPropertyType::WAV;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
Result<std::vector<uint8_t>> WzBinaryProperty::GetBytes() {
|
|
114
|
+
return GetBytes(false);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
Result<std::vector<uint8_t>> WzBinaryProperty::GetBytes(bool saveInMemory) {
|
|
118
|
+
std::unique_lock<std::recursive_mutex> lock;
|
|
119
|
+
if (wzReader_) {
|
|
120
|
+
lock = std::unique_lock<std::recursive_mutex>(wzReader_->Mutex());
|
|
121
|
+
}
|
|
122
|
+
if (!fileBytes_.empty()) return fileBytes_;
|
|
123
|
+
if (!wzReader_)
|
|
124
|
+
return std::unexpected(Error::DataError("No reader for binary property"));
|
|
125
|
+
|
|
126
|
+
auto currentPos = wzReader_->Position();
|
|
127
|
+
wzReader_->SetPosition(offs_);
|
|
128
|
+
fileBytes_ = wzReader_->ReadBytes(soundDataLen_);
|
|
129
|
+
wzReader_->SetPosition(currentPos);
|
|
130
|
+
|
|
131
|
+
if (saveInMemory) return fileBytes_;
|
|
132
|
+
auto result = fileBytes_;
|
|
133
|
+
fileBytes_.clear();
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
Result<std::vector<uint8_t>> WzBinaryProperty::GetBytesForWAVPlayback(
|
|
138
|
+
bool saveInMemory) {
|
|
139
|
+
static const uint8_t riffWaveHeader[] = {
|
|
140
|
+
0x52, 0x49, 0x46, 0x46, 0x14, 0x60, 0x28, 0x00, 0x57, 0x41,
|
|
141
|
+
0x56, 0x45, 0x66, 0x6D, 0x74, 0x20, 0x10, 0x00, 0x00, 0x00,
|
|
142
|
+
0x00, 0x01, 0x00, 0x01, 0x00, 0x22, 0x56, 0x00, 0x00,
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
auto bytesResult = GetBytes(saveInMemory);
|
|
146
|
+
if (!bytesResult.has_value()) return std::unexpected(bytesResult.error());
|
|
147
|
+
auto& soundBytes = bytesResult.value();
|
|
148
|
+
if (soundBytes.empty())
|
|
149
|
+
return std::unexpected(Error::DataError("Empty sound data"));
|
|
150
|
+
|
|
151
|
+
size_t totalLen = sizeof(riffWaveHeader) + header_.size() + soundBytes.size();
|
|
152
|
+
std::vector<uint8_t> combined(totalLen);
|
|
153
|
+
|
|
154
|
+
size_t offset = 0;
|
|
155
|
+
std::memcpy(combined.data() + offset, riffWaveHeader, sizeof(riffWaveHeader));
|
|
156
|
+
offset += sizeof(riffWaveHeader);
|
|
157
|
+
std::memcpy(combined.data() + offset, header_.data(), header_.size());
|
|
158
|
+
offset += header_.size();
|
|
159
|
+
std::memcpy(combined.data() + offset, soundBytes.data(), soundBytes.size());
|
|
160
|
+
|
|
161
|
+
return combined;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
Result<void> WzBinaryProperty::SaveToFile(const std::string& filePath) {
|
|
165
|
+
auto result = GetBytes(false);
|
|
166
|
+
if (!result.has_value()) return std::unexpected(result.error());
|
|
167
|
+
auto& bytes = result.value();
|
|
168
|
+
auto outPath = wz::to_path(filePath);
|
|
169
|
+
auto parentPath = outPath.parent_path();
|
|
170
|
+
std::error_code ec;
|
|
171
|
+
if (!parentPath.empty()) {
|
|
172
|
+
std::filesystem::create_directories(parentPath, ec);
|
|
173
|
+
if (ec) return std::unexpected(Error::IoError(ec.message()));
|
|
174
|
+
}
|
|
175
|
+
WzFileStream out;
|
|
176
|
+
if (!out.Open(outPath, "wb"))
|
|
177
|
+
return std::unexpected(Error::IoError("Failed to open file for writing"));
|
|
178
|
+
if (!out.Write(bytes.data(), bytes.size()))
|
|
179
|
+
return std::unexpected(Error::IoError("Failed to write file"));
|
|
180
|
+
return {};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
} // namespace wz
|