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.
Files changed (362) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +165 -0
  3. package/binding.gyp +149 -0
  4. package/deps/tiny-aes/.github/workflows/c-cpp.yml +27 -0
  5. package/deps/tiny-aes/CMakeLists.txt +17 -0
  6. package/deps/tiny-aes/Makefile +61 -0
  7. package/deps/tiny-aes/README.md +83 -0
  8. package/deps/tiny-aes/aes.c +572 -0
  9. package/deps/tiny-aes/aes.h +91 -0
  10. package/deps/tiny-aes/aes.hpp +12 -0
  11. package/deps/tiny-aes/conanfile.py +73 -0
  12. package/deps/tiny-aes/library.json +19 -0
  13. package/deps/tiny-aes/library.properties +11 -0
  14. package/deps/tiny-aes/test.c +316 -0
  15. package/deps/tiny-aes/test.cpp +2 -0
  16. package/deps/tiny-aes/test_package/CMakeLists.txt +11 -0
  17. package/deps/tiny-aes/test_package/conanfile.py +17 -0
  18. package/deps/tiny-aes/unlicense.txt +24 -0
  19. package/deps/zlib/.cmake-format.yaml +245 -0
  20. package/deps/zlib/.github/workflows/c-std.yml +268 -0
  21. package/deps/zlib/.github/workflows/cmake.yml +147 -0
  22. package/deps/zlib/.github/workflows/configure.yml +146 -0
  23. package/deps/zlib/.github/workflows/contribs.yml +64 -0
  24. package/deps/zlib/.github/workflows/fuzz.yml +25 -0
  25. package/deps/zlib/.github/workflows/msys-cygwin.yml +92 -0
  26. package/deps/zlib/.github/workflows/others.yml +153 -0
  27. package/deps/zlib/BUILD.bazel +134 -0
  28. package/deps/zlib/CMakeLists.txt +310 -0
  29. package/deps/zlib/ChangeLog +1669 -0
  30. package/deps/zlib/FAQ +371 -0
  31. package/deps/zlib/INDEX +67 -0
  32. package/deps/zlib/LICENSE +22 -0
  33. package/deps/zlib/MODULE.bazel +9 -0
  34. package/deps/zlib/Makefile.in +426 -0
  35. package/deps/zlib/README +115 -0
  36. package/deps/zlib/README-cmake.md +79 -0
  37. package/deps/zlib/adler32.c +164 -0
  38. package/deps/zlib/amiga/Makefile.pup +69 -0
  39. package/deps/zlib/amiga/Makefile.sas +68 -0
  40. package/deps/zlib/compress.c +99 -0
  41. package/deps/zlib/configure +1078 -0
  42. package/deps/zlib/contrib/CMakeLists.txt +61 -0
  43. package/deps/zlib/contrib/README.contrib +57 -0
  44. package/deps/zlib/contrib/ada/CMakeLists.txt +217 -0
  45. package/deps/zlib/contrib/ada/buffer_demo.adb +106 -0
  46. package/deps/zlib/contrib/ada/cmake/Modules/CMakeADACompiler.cmake.in +23 -0
  47. package/deps/zlib/contrib/ada/cmake/Modules/CMakeADAInformation.cmake +133 -0
  48. package/deps/zlib/contrib/ada/cmake/Modules/CMakeDetermineADACompiler.cmake +33 -0
  49. package/deps/zlib/contrib/ada/cmake/Modules/CMakeTestADACompiler.cmake +46 -0
  50. package/deps/zlib/contrib/ada/cmake/binder_helper.cmake +47 -0
  51. package/deps/zlib/contrib/ada/cmake/compile_helper.cmake +32 -0
  52. package/deps/zlib/contrib/ada/cmake/exe_link_helper.cmake +53 -0
  53. package/deps/zlib/contrib/ada/cmake/shared_link_helper.cmake +52 -0
  54. package/deps/zlib/contrib/ada/cmake/static_link_helper.cmake +25 -0
  55. package/deps/zlib/contrib/ada/mtest.adb +156 -0
  56. package/deps/zlib/contrib/ada/read.adb +156 -0
  57. package/deps/zlib/contrib/ada/readme.txt +65 -0
  58. package/deps/zlib/contrib/ada/test.adb +463 -0
  59. package/deps/zlib/contrib/ada/zlib-streams.adb +225 -0
  60. package/deps/zlib/contrib/ada/zlib-streams.ads +114 -0
  61. package/deps/zlib/contrib/ada/zlib-thin.adb +142 -0
  62. package/deps/zlib/contrib/ada/zlib-thin.ads +450 -0
  63. package/deps/zlib/contrib/ada/zlib.adb +701 -0
  64. package/deps/zlib/contrib/ada/zlib.ads +328 -0
  65. package/deps/zlib/contrib/ada/zlib.gpr +20 -0
  66. package/deps/zlib/contrib/blast/CMakeLists.txt +166 -0
  67. package/deps/zlib/contrib/blast/Makefile +14 -0
  68. package/deps/zlib/contrib/blast/README +4 -0
  69. package/deps/zlib/contrib/blast/blast-test.c +42 -0
  70. package/deps/zlib/contrib/blast/blast.c +422 -0
  71. package/deps/zlib/contrib/blast/blast.h +84 -0
  72. package/deps/zlib/contrib/blast/blastConfig.cmake.in +18 -0
  73. package/deps/zlib/contrib/blast/test/CMakeLists.txt +193 -0
  74. package/deps/zlib/contrib/blast/test/add_subdirectory_exclude_test.cmake.in +27 -0
  75. package/deps/zlib/contrib/blast/test/add_subdirectory_test.cmake.in +25 -0
  76. package/deps/zlib/contrib/blast/test/find_package_no_components_test.cmake.in +24 -0
  77. package/deps/zlib/contrib/blast/test/find_package_test.cmake.in +24 -0
  78. package/deps/zlib/contrib/blast/test/find_package_wrong_components_test.cmake.in +24 -0
  79. package/deps/zlib/contrib/blast/test.pk +0 -0
  80. package/deps/zlib/contrib/blast/test.txt +1 -0
  81. package/deps/zlib/contrib/blast/tester.cmake +28 -0
  82. package/deps/zlib/contrib/crc32vx/CMakeLists.txt +67 -0
  83. package/deps/zlib/contrib/crc32vx/README +9 -0
  84. package/deps/zlib/contrib/crc32vx/crc32_vx.c +254 -0
  85. package/deps/zlib/contrib/crc32vx/crc32_vx_hooks.h +9 -0
  86. package/deps/zlib/contrib/delphi/ZLib.pas +557 -0
  87. package/deps/zlib/contrib/delphi/ZLibConst.pas +11 -0
  88. package/deps/zlib/contrib/delphi/readme.txt +76 -0
  89. package/deps/zlib/contrib/delphi/zlibd32.mak +99 -0
  90. package/deps/zlib/contrib/dotzlib/DotZLib/AssemblyInfo.cs +58 -0
  91. package/deps/zlib/contrib/dotzlib/DotZLib/ChecksumImpl.cs +202 -0
  92. package/deps/zlib/contrib/dotzlib/DotZLib/CircularBuffer.cs +83 -0
  93. package/deps/zlib/contrib/dotzlib/DotZLib/CodecBase.cs +198 -0
  94. package/deps/zlib/contrib/dotzlib/DotZLib/Deflater.cs +106 -0
  95. package/deps/zlib/contrib/dotzlib/DotZLib/DotZLib.cs +288 -0
  96. package/deps/zlib/contrib/dotzlib/DotZLib/DotZLib.csproj +141 -0
  97. package/deps/zlib/contrib/dotzlib/DotZLib/GZipStream.cs +301 -0
  98. package/deps/zlib/contrib/dotzlib/DotZLib/Inflater.cs +105 -0
  99. package/deps/zlib/contrib/dotzlib/DotZLib/UnitTests.cs +274 -0
  100. package/deps/zlib/contrib/dotzlib/DotZLib.build +33 -0
  101. package/deps/zlib/contrib/dotzlib/DotZLib.chm +0 -0
  102. package/deps/zlib/contrib/dotzlib/DotZLib.sln +21 -0
  103. package/deps/zlib/contrib/dotzlib/LICENSE_1_0.txt +23 -0
  104. package/deps/zlib/contrib/dotzlib/readme.txt +58 -0
  105. package/deps/zlib/contrib/gcc_gvmat64/CMakeLists.txt +19 -0
  106. package/deps/zlib/contrib/gcc_gvmat64/gvmat64.S +570 -0
  107. package/deps/zlib/contrib/infback9/CMakeLists.txt +19 -0
  108. package/deps/zlib/contrib/infback9/README +1 -0
  109. package/deps/zlib/contrib/infback9/infback9.c +603 -0
  110. package/deps/zlib/contrib/infback9/infback9.h +37 -0
  111. package/deps/zlib/contrib/infback9/inffix9.h +107 -0
  112. package/deps/zlib/contrib/infback9/inflate9.h +47 -0
  113. package/deps/zlib/contrib/infback9/inftree9.c +319 -0
  114. package/deps/zlib/contrib/infback9/inftree9.h +61 -0
  115. package/deps/zlib/contrib/iostream/test.cpp +24 -0
  116. package/deps/zlib/contrib/iostream/zfstream.cpp +329 -0
  117. package/deps/zlib/contrib/iostream/zfstream.h +128 -0
  118. package/deps/zlib/contrib/iostream2/zstream.h +306 -0
  119. package/deps/zlib/contrib/iostream2/zstream_test.cpp +25 -0
  120. package/deps/zlib/contrib/iostream3/CMakeLists.txt +200 -0
  121. package/deps/zlib/contrib/iostream3/README +35 -0
  122. package/deps/zlib/contrib/iostream3/TODO +17 -0
  123. package/deps/zlib/contrib/iostream3/iostream3Config.cmake.in +23 -0
  124. package/deps/zlib/contrib/iostream3/test/CMakeLists.txt +191 -0
  125. package/deps/zlib/contrib/iostream3/test/add_subdirectory_exclude_test.cmake.in +27 -0
  126. package/deps/zlib/contrib/iostream3/test/add_subdirectory_test.cmake.in +25 -0
  127. package/deps/zlib/contrib/iostream3/test/find_package_no_components_test.cmake.in +24 -0
  128. package/deps/zlib/contrib/iostream3/test/find_package_test.cmake.in +24 -0
  129. package/deps/zlib/contrib/iostream3/test/find_package_wrong_components_test.cmake.in +24 -0
  130. package/deps/zlib/contrib/iostream3/test.cc +50 -0
  131. package/deps/zlib/contrib/iostream3/zfstream.cc +479 -0
  132. package/deps/zlib/contrib/iostream3/zfstream.h +466 -0
  133. package/deps/zlib/contrib/minizip/CMakeLists.txt +387 -0
  134. package/deps/zlib/contrib/minizip/LICENSE.Info-Zip +58 -0
  135. package/deps/zlib/contrib/minizip/Makefile +33 -0
  136. package/deps/zlib/contrib/minizip/Makefile.am +45 -0
  137. package/deps/zlib/contrib/minizip/MiniZip64_Changes.txt +6 -0
  138. package/deps/zlib/contrib/minizip/MiniZip64_info.txt +69 -0
  139. package/deps/zlib/contrib/minizip/configure.ac +32 -0
  140. package/deps/zlib/contrib/minizip/crypt.h +125 -0
  141. package/deps/zlib/contrib/minizip/ints.h +57 -0
  142. package/deps/zlib/contrib/minizip/ioapi.c +231 -0
  143. package/deps/zlib/contrib/minizip/ioapi.h +183 -0
  144. package/deps/zlib/contrib/minizip/iowin32.c +447 -0
  145. package/deps/zlib/contrib/minizip/iowin32.h +27 -0
  146. package/deps/zlib/contrib/minizip/make_vms.com +25 -0
  147. package/deps/zlib/contrib/minizip/miniunz.c +647 -0
  148. package/deps/zlib/contrib/minizip/miniunzip.1 +63 -0
  149. package/deps/zlib/contrib/minizip/minizip.1 +46 -0
  150. package/deps/zlib/contrib/minizip/minizip.c +511 -0
  151. package/deps/zlib/contrib/minizip/minizip.pc.in +13 -0
  152. package/deps/zlib/contrib/minizip/minizip.pc.txt +13 -0
  153. package/deps/zlib/contrib/minizip/minizipConfig.cmake.in +27 -0
  154. package/deps/zlib/contrib/minizip/mztools.c +294 -0
  155. package/deps/zlib/contrib/minizip/mztools.h +37 -0
  156. package/deps/zlib/contrib/minizip/skipset.h +366 -0
  157. package/deps/zlib/contrib/minizip/test/CMakeLists.txt +176 -0
  158. package/deps/zlib/contrib/minizip/test/add_subdirectory_exclude_test.cmake.in +29 -0
  159. package/deps/zlib/contrib/minizip/test/add_subdirectory_test.cmake.in +28 -0
  160. package/deps/zlib/contrib/minizip/test/find_package_no_components_test.cmake.in +26 -0
  161. package/deps/zlib/contrib/minizip/test/find_package_test.cmake.in +26 -0
  162. package/deps/zlib/contrib/minizip/test/find_package_wrong_components_test.cmake.in +26 -0
  163. package/deps/zlib/contrib/minizip/test/test_helper.cm +32 -0
  164. package/deps/zlib/contrib/minizip/unzip.c +1984 -0
  165. package/deps/zlib/contrib/minizip/unzip.h +442 -0
  166. package/deps/zlib/contrib/minizip/zip.c +2246 -0
  167. package/deps/zlib/contrib/minizip/zip.h +371 -0
  168. package/deps/zlib/contrib/nuget/nuget.csproj +45 -0
  169. package/deps/zlib/contrib/nuget/nuget.sln +22 -0
  170. package/deps/zlib/contrib/pascal/example.pas +599 -0
  171. package/deps/zlib/contrib/pascal/readme.txt +76 -0
  172. package/deps/zlib/contrib/pascal/zlibd32.mak +99 -0
  173. package/deps/zlib/contrib/pascal/zlibpas.pas +276 -0
  174. package/deps/zlib/contrib/puff/CMakeLists.txt +154 -0
  175. package/deps/zlib/contrib/puff/Makefile +42 -0
  176. package/deps/zlib/contrib/puff/README +63 -0
  177. package/deps/zlib/contrib/puff/bin-writer.c +26 -0
  178. package/deps/zlib/contrib/puff/puff.c +840 -0
  179. package/deps/zlib/contrib/puff/puff.h +35 -0
  180. package/deps/zlib/contrib/puff/puffConfig.cmake.in +18 -0
  181. package/deps/zlib/contrib/puff/pufftest.c +168 -0
  182. package/deps/zlib/contrib/puff/test/CMakeLists.txt +262 -0
  183. package/deps/zlib/contrib/puff/test/add_subdirectory_exclude_test.cmake.in +26 -0
  184. package/deps/zlib/contrib/puff/test/add_subdirectory_test.cmake.in +25 -0
  185. package/deps/zlib/contrib/puff/test/find_package_no_components_test.cmake.in +24 -0
  186. package/deps/zlib/contrib/puff/test/find_package_test.cmake.in +24 -0
  187. package/deps/zlib/contrib/puff/test/find_package_wrong_components_test.cmake.in +24 -0
  188. package/deps/zlib/contrib/puff/test/tester-cov.cmake +58 -0
  189. package/deps/zlib/contrib/puff/test/tester.cmake +16 -0
  190. package/deps/zlib/contrib/puff/zeros.raw +0 -0
  191. package/deps/zlib/contrib/testzlib/CMakeLists.txt +44 -0
  192. package/deps/zlib/contrib/testzlib/testzlib.c +275 -0
  193. package/deps/zlib/contrib/testzlib/testzlib.txt +10 -0
  194. package/deps/zlib/contrib/vstudio/readme.txt +22 -0
  195. package/deps/zlib/contrib/zlib1-dll/CMakeLists.txt +196 -0
  196. package/deps/zlib/contrib/zlib1-dll/readme.txt +21 -0
  197. package/deps/zlib/crc32.c +983 -0
  198. package/deps/zlib/crc32.h +9446 -0
  199. package/deps/zlib/deflate.c +2185 -0
  200. package/deps/zlib/deflate.h +383 -0
  201. package/deps/zlib/doc/algorithm.txt +209 -0
  202. package/deps/zlib/doc/crc-doc.1.0.pdf +0 -0
  203. package/deps/zlib/doc/rfc1950.txt +619 -0
  204. package/deps/zlib/doc/rfc1951.txt +955 -0
  205. package/deps/zlib/doc/rfc1952.txt +675 -0
  206. package/deps/zlib/doc/txtvsbin.txt +107 -0
  207. package/deps/zlib/examples/README.examples +54 -0
  208. package/deps/zlib/examples/enough.c +597 -0
  209. package/deps/zlib/examples/fitblk.c +233 -0
  210. package/deps/zlib/examples/gun.c +702 -0
  211. package/deps/zlib/examples/gzappend.c +504 -0
  212. package/deps/zlib/examples/gzjoin.c +449 -0
  213. package/deps/zlib/examples/gzlog.c +1061 -0
  214. package/deps/zlib/examples/gzlog.h +91 -0
  215. package/deps/zlib/examples/gznorm.c +474 -0
  216. package/deps/zlib/examples/zlib_how.html +550 -0
  217. package/deps/zlib/examples/zpipe.c +206 -0
  218. package/deps/zlib/examples/zran.c +546 -0
  219. package/deps/zlib/examples/zran.h +53 -0
  220. package/deps/zlib/gzclose.c +23 -0
  221. package/deps/zlib/gzguts.h +216 -0
  222. package/deps/zlib/gzlib.c +609 -0
  223. package/deps/zlib/gzread.c +668 -0
  224. package/deps/zlib/gzwrite.c +700 -0
  225. package/deps/zlib/infback.c +581 -0
  226. package/deps/zlib/inffast.c +321 -0
  227. package/deps/zlib/inffast.h +11 -0
  228. package/deps/zlib/inffixed.h +94 -0
  229. package/deps/zlib/inflate.c +1413 -0
  230. package/deps/zlib/inflate.h +126 -0
  231. package/deps/zlib/inftrees.c +424 -0
  232. package/deps/zlib/inftrees.h +64 -0
  233. package/deps/zlib/make_vms.com +867 -0
  234. package/deps/zlib/msdos/Makefile.bor +115 -0
  235. package/deps/zlib/msdos/Makefile.dj2 +104 -0
  236. package/deps/zlib/msdos/Makefile.emx +69 -0
  237. package/deps/zlib/msdos/Makefile.msc +112 -0
  238. package/deps/zlib/msdos/Makefile.tc +100 -0
  239. package/deps/zlib/os400/README400 +48 -0
  240. package/deps/zlib/os400/bndsrc +144 -0
  241. package/deps/zlib/os400/make.sh +383 -0
  242. package/deps/zlib/os400/zlibfixed.rpgle +578 -0
  243. package/deps/zlib/os400/zlibfree.rpgle +634 -0
  244. package/deps/zlib/qnx/package.qpg +141 -0
  245. package/deps/zlib/test/CMakeLists.txt +318 -0
  246. package/deps/zlib/test/add_subdirectory_exclude_test.cmake.in +29 -0
  247. package/deps/zlib/test/add_subdirectory_test.cmake.in +28 -0
  248. package/deps/zlib/test/example.c +552 -0
  249. package/deps/zlib/test/find_package_no_components_test.cmake.in +27 -0
  250. package/deps/zlib/test/find_package_test.cmake.in +27 -0
  251. package/deps/zlib/test/find_package_wrong_components_test.cmake.in +27 -0
  252. package/deps/zlib/test/infcover.c +672 -0
  253. package/deps/zlib/test/minigzip.c +592 -0
  254. package/deps/zlib/treebuild.xml +116 -0
  255. package/deps/zlib/trees.c +1119 -0
  256. package/deps/zlib/trees.h +128 -0
  257. package/deps/zlib/uncompr.c +101 -0
  258. package/deps/zlib/watcom/watcom_f.mak +43 -0
  259. package/deps/zlib/watcom/watcom_l.mak +43 -0
  260. package/deps/zlib/win32/DLL_FAQ.txt +381 -0
  261. package/deps/zlib/win32/Makefile.bor +109 -0
  262. package/deps/zlib/win32/Makefile.gcc +177 -0
  263. package/deps/zlib/win32/Makefile.msc +159 -0
  264. package/deps/zlib/win32/README-WIN32.txt +103 -0
  265. package/deps/zlib/win32/VisualC.txt +3 -0
  266. package/deps/zlib/win32/zlib.def +104 -0
  267. package/deps/zlib/win32/zlib1.rc +37 -0
  268. package/deps/zlib/zconf.h.in +551 -0
  269. package/deps/zlib/zlib.3 +149 -0
  270. package/deps/zlib/zlib.3.pdf +0 -0
  271. package/deps/zlib/zlib.h +2057 -0
  272. package/deps/zlib/zlib.map +116 -0
  273. package/deps/zlib/zlib.pc.cmakein +14 -0
  274. package/deps/zlib/zlib.pc.in +14 -0
  275. package/deps/zlib/zlibConfig.cmake.in +18 -0
  276. package/deps/zlib/zutil.c +313 -0
  277. package/deps/zlib/zutil.h +331 -0
  278. package/dist/index.d.ts +266 -0
  279. package/dist/index.js +1146 -0
  280. package/dist/libwz.js +5632 -0
  281. package/dist/libwz.wasm +0 -0
  282. package/include/wz/CRC32.h +182 -0
  283. package/include/wz/PngUtility.h +72 -0
  284. package/include/wz/PortalType.h +124 -0
  285. package/include/wz/Properties/WzBinaryProperty.h +70 -0
  286. package/include/wz/Properties/WzCanvasProperty.h +55 -0
  287. package/include/wz/Properties/WzConvexProperty.h +34 -0
  288. package/include/wz/Properties/WzDoubleProperty.h +32 -0
  289. package/include/wz/Properties/WzFloatProperty.h +30 -0
  290. package/include/wz/Properties/WzIntProperty.h +30 -0
  291. package/include/wz/Properties/WzLongProperty.h +30 -0
  292. package/include/wz/Properties/WzLuaProperty.h +31 -0
  293. package/include/wz/Properties/WzNullProperty.h +15 -0
  294. package/include/wz/Properties/WzPngProperty.h +53 -0
  295. package/include/wz/Properties/WzRawDataProperty.h +46 -0
  296. package/include/wz/Properties/WzShortProperty.h +31 -0
  297. package/include/wz/Properties/WzStringProperty.h +32 -0
  298. package/include/wz/Properties/WzSubProperty.h +35 -0
  299. package/include/wz/Properties/WzUOLProperty.h +44 -0
  300. package/include/wz/Properties/WzVectorProperty.h +40 -0
  301. package/include/wz/Properties/WzVideoProperty.h +43 -0
  302. package/include/wz/Result.h +58 -0
  303. package/include/wz/Util/Defines.h +16 -0
  304. package/include/wz/Util/ListFileParser.h +20 -0
  305. package/include/wz/Util/WzBinaryReader.h +95 -0
  306. package/include/wz/Util/WzBinaryWriter.h +72 -0
  307. package/include/wz/Util/WzBlobDataSource.h +30 -0
  308. package/include/wz/Util/WzDataSource.h +49 -0
  309. package/include/wz/Util/WzKeyGenerator.h +28 -0
  310. package/include/wz/Util/WzMutableKey.h +39 -0
  311. package/include/wz/Util/WzPath.h +37 -0
  312. package/include/wz/Util/WzStream.h +86 -0
  313. package/include/wz/Util/WzTool.h +42 -0
  314. package/include/wz/WzAESConstant.h +17 -0
  315. package/include/wz/WzDirectory.h +97 -0
  316. package/include/wz/WzEnums.h +76 -0
  317. package/include/wz/WzFile.h +99 -0
  318. package/include/wz/WzHeader.h +47 -0
  319. package/include/wz/WzImage.h +97 -0
  320. package/include/wz/WzImageProperty.h +92 -0
  321. package/include/wz/WzObject.h +55 -0
  322. package/include/wz/WzPropertyCollection.h +115 -0
  323. package/include/wz/wz.h +41 -0
  324. package/include/wz/wz_api.h +432 -0
  325. package/package.json +93 -0
  326. package/src/PngUtility.cpp +328 -0
  327. package/src/Properties/WzBinaryProperty.cpp +183 -0
  328. package/src/Properties/WzCanvasProperty.cpp +262 -0
  329. package/src/Properties/WzConvexProperty.cpp +159 -0
  330. package/src/Properties/WzDoubleProperty.cpp +12 -0
  331. package/src/Properties/WzFloatProperty.cpp +17 -0
  332. package/src/Properties/WzIntProperty.cpp +12 -0
  333. package/src/Properties/WzLongProperty.cpp +12 -0
  334. package/src/Properties/WzLuaProperty.cpp +37 -0
  335. package/src/Properties/WzNullProperty.cpp +11 -0
  336. package/src/Properties/WzPngProperty.cpp +637 -0
  337. package/src/Properties/WzRawDataProperty.cpp +116 -0
  338. package/src/Properties/WzShortProperty.cpp +12 -0
  339. package/src/Properties/WzStringProperty.cpp +44 -0
  340. package/src/Properties/WzSubProperty.cpp +129 -0
  341. package/src/Properties/WzUOLProperty.cpp +136 -0
  342. package/src/Properties/WzVectorProperty.cpp +22 -0
  343. package/src/Properties/WzVideoProperty.cpp +115 -0
  344. package/src/Util/ListFileParser.cpp +48 -0
  345. package/src/Util/WzBinaryReader.cpp +368 -0
  346. package/src/Util/WzBinaryWriter.cpp +305 -0
  347. package/src/Util/WzBlobDataSource.cpp +47 -0
  348. package/src/Util/WzDataSource.cpp +61 -0
  349. package/src/Util/WzKeyGenerator.cpp +43 -0
  350. package/src/Util/WzMutableKey.cpp +59 -0
  351. package/src/Util/WzStream.cpp +196 -0
  352. package/src/Util/WzTool.cpp +266 -0
  353. package/src/WzAESConstant.cpp +12 -0
  354. package/src/WzDirectory.cpp +669 -0
  355. package/src/WzEnums.cpp +20 -0
  356. package/src/WzFile.cpp +450 -0
  357. package/src/WzImage.cpp +350 -0
  358. package/src/WzImageProperty.cpp +469 -0
  359. package/src/WzObject.cpp +174 -0
  360. package/src/WzPropertyCollection.cpp +84 -0
  361. package/src/capi/wz_api.cpp +1996 -0
  362. package/src/node/binding.cpp +1776 -0
@@ -0,0 +1,669 @@
1
+ #include "wz/WzDirectory.h"
2
+ #include <algorithm>
3
+ #include <limits>
4
+ #include <mutex>
5
+ #include <unordered_set>
6
+ #include <utility>
7
+ #include <vector>
8
+ #include "wz/Util/WzBinaryReader.h"
9
+ #include "wz/Util/WzBinaryWriter.h"
10
+ #include "wz/Util/WzTool.h"
11
+ #include "wz/WzFile.h"
12
+ #include "wz/WzImage.h"
13
+
14
+ namespace wz {
15
+
16
+ namespace {
17
+
18
+ class WzObjectValueSizer {
19
+ public:
20
+ int GetLength(const std::string& value, WzDirectoryType type) {
21
+ std::string storeName =
22
+ std::to_string(static_cast<uint8_t>(type)) + "_" + value;
23
+ if (value.length() > 4 && cache_.contains(storeName)) {
24
+ return 5;
25
+ }
26
+ cache_.insert(std::move(storeName));
27
+ return 1 + WzTool::GetEncodedStringLength(value);
28
+ }
29
+
30
+ private:
31
+ std::unordered_set<std::string> cache_;
32
+ };
33
+
34
+ Result<uint32_t> AddCheckedOffset(uint32_t current,
35
+ uint64_t increment,
36
+ const std::string& context) {
37
+ if (increment > std::numeric_limits<uint32_t>::max() - current) {
38
+ return std::unexpected(
39
+ Error::DataError("WZ offset overflow while adding " + context));
40
+ }
41
+ return current + static_cast<uint32_t>(increment);
42
+ }
43
+
44
+ Result<void> AddCheckedInt(int* target, int increment) {
45
+ if (increment < 0) {
46
+ return std::unexpected(
47
+ Error::DataError("Cannot add negative WZ directory size"));
48
+ }
49
+ if (*target > std::numeric_limits<int>::max() - increment) {
50
+ return std::unexpected(Error::DataError("WZ directory size overflow"));
51
+ }
52
+ *target += increment;
53
+ return {};
54
+ }
55
+
56
+ } // namespace
57
+
58
+ WzDirectory::WzDirectory() = default;
59
+ WzDirectory::WzDirectory(const std::string& dirName) {
60
+ SetName(dirName);
61
+ }
62
+ WzDirectory::WzDirectory(WzBinaryReader* reader,
63
+ const std::string& dirName,
64
+ uint32_t verHash,
65
+ const std::array<uint8_t, 4>& wzIv,
66
+ WzFile* wzFile)
67
+ : reader_(reader), hash_(verHash), wz_iv_(wzIv), wzFile_(wzFile) {
68
+ SetName(dirName);
69
+ }
70
+
71
+ WzDirectory::~WzDirectory() {
72
+ name_.clear();
73
+ reader_ = nullptr;
74
+ images_.clear();
75
+ subDirs_.clear();
76
+ }
77
+
78
+ std::vector<WzImage*> WzDirectory::WzImages() const {
79
+ std::vector<WzImage*> result;
80
+ result.reserve(images_.size());
81
+ for (const auto& img : images_) result.push_back(img.get());
82
+ return result;
83
+ }
84
+
85
+ std::vector<WzDirectory*> WzDirectory::WzDirectories() const {
86
+ std::vector<WzDirectory*> result;
87
+ result.reserve(subDirs_.size());
88
+ for (const auto& dir : subDirs_) result.push_back(dir.get());
89
+ return result;
90
+ }
91
+
92
+ Result<std::unique_ptr<WzObject>> WzDirectory::Remove() {
93
+ if (!Parent() || Parent()->ObjectType() != WzObjectType::Directory) {
94
+ return std::unexpected(
95
+ Error::NotFound("WZ directory has no parent directory"));
96
+ }
97
+ auto result = static_cast<WzDirectory*>(Parent())->RemoveDirectory(this);
98
+ if (!result.has_value()) return std::unexpected(result.error());
99
+ return std::unique_ptr<WzObject>(std::move(result.value()));
100
+ }
101
+
102
+ Result<void> WzDirectory::ParseDirectory() {
103
+ if (!reader_) return {};
104
+ if (reader_->Available() == 0) return {};
105
+
106
+ int entryCount = reader_->ReadCompressedInt();
107
+ if (entryCount < 0 || entryCount > 100000)
108
+ return std::unexpected(
109
+ Error::ParseError("Invalid wz version used for decryption, try "
110
+ "parsing other version numbers."));
111
+
112
+ for (int i = 0; i < entryCount; i++) {
113
+ uint8_t type = reader_->ReadByte();
114
+ std::string fname;
115
+ int fsize, checksum;
116
+ int64_t woffset;
117
+ int64_t rememberPos = 0;
118
+
119
+ switch (static_cast<WzDirectoryType>(type)) {
120
+ case WzDirectoryType::UnknownType_1: {
121
+ reader_->ReadInt32(); // unknown
122
+ reader_->ReadInt16();
123
+ reader_->ReadOffset();
124
+ continue;
125
+ }
126
+ case WzDirectoryType::RetrieveStringFromOffset_2: {
127
+ int stringOffset = reader_->ReadInt32();
128
+ rememberPos = reader_->Position();
129
+ reader_->SetPosition(static_cast<int64_t>(
130
+ reader_->GetHeader()->FStart() + stringOffset));
131
+ type = reader_->ReadByte();
132
+ fname = reader_->ReadString();
133
+ break;
134
+ }
135
+ case WzDirectoryType::WzDirectory_3:
136
+ case WzDirectoryType::WzImage_4: {
137
+ fname = reader_->ReadString();
138
+ rememberPos = reader_->Position();
139
+ break;
140
+ }
141
+ default:
142
+ return std::unexpected(Error::ParseError(
143
+ "[WzDirectory] Unknown directory type = " + std::to_string(type)));
144
+ }
145
+
146
+ reader_->SetPosition(rememberPos);
147
+ fsize = reader_->ReadCompressedInt();
148
+ checksum = reader_->ReadCompressedInt();
149
+ woffset = reader_->ReadOffset();
150
+
151
+ if (type == static_cast<uint8_t>(WzDirectoryType::WzDirectory_3)) {
152
+ auto subDir =
153
+ std::make_unique<WzDirectory>(reader_, fname, hash_, wz_iv_, wzFile_);
154
+ subDir->SetBlockSize(fsize);
155
+ subDir->SetChecksum(checksum);
156
+ subDir->SetOffset(woffset);
157
+ subDir->SetParent(this);
158
+ subDirs_.push_back(std::move(subDir));
159
+ } else {
160
+ auto img = std::make_unique<WzImage>(fname, *reader_, checksum);
161
+ img->SetBlockSize(fsize);
162
+ img->SetOffset(woffset);
163
+ img->SetParent(this);
164
+ images_.push_back(std::move(img));
165
+ }
166
+ }
167
+
168
+ for (auto& subdir : subDirs_) {
169
+ reader_->SetPosition(subdir->Offset());
170
+ auto parseResult = subdir->ParseDirectory();
171
+ if (!parseResult.has_value()) return std::unexpected(parseResult.error());
172
+ }
173
+ return {};
174
+ }
175
+
176
+ Result<void> WzDirectory::ParseImages() {
177
+ for (auto& img : images_) {
178
+ if (img->Reader() && img->Reader()->Position() != img->Offset()) {
179
+ img->Reader()->SetPosition(img->Offset());
180
+ }
181
+ auto parseResult = img->ParseImage();
182
+ if (!parseResult.has_value()) return std::unexpected(parseResult.error());
183
+ }
184
+ for (auto& subdir : subDirs_) {
185
+ if (subdir->Reader() && subdir->Reader()->Position() != subdir->Offset()) {
186
+ subdir->Reader()->SetPosition(subdir->Offset());
187
+ }
188
+ auto parseResult = subdir->ParseImages();
189
+ if (!parseResult.has_value()) return std::unexpected(parseResult.error());
190
+ }
191
+ return {};
192
+ }
193
+
194
+ Result<void> WzDirectory::AddImage(WzImage* img) {
195
+ return AddImage(std::unique_ptr<WzImage>(img));
196
+ }
197
+
198
+ Result<void> WzDirectory::AddDirectory(WzDirectory* dir) {
199
+ return AddDirectory(std::unique_ptr<WzDirectory>(dir));
200
+ }
201
+
202
+ Result<WzDirectory*> WzDirectory::CreateDirectory(const std::string& name) {
203
+ auto dir = std::make_unique<WzDirectory>(name);
204
+ auto* raw = dir.get();
205
+ auto result = AddDirectory(std::move(dir));
206
+ if (!result.has_value()) return std::unexpected(result.error());
207
+ return raw;
208
+ }
209
+
210
+ Result<WzImage*> WzDirectory::CreateImage(const std::string& name) {
211
+ auto img = std::make_unique<WzImage>(name);
212
+ auto* raw = img.get();
213
+ auto result = AddImage(std::move(img));
214
+ if (!result.has_value()) return std::unexpected(result.error());
215
+ return raw;
216
+ }
217
+
218
+ Result<void> WzDirectory::AddDirectory(std::unique_ptr<WzDirectory> dir) {
219
+ if (!dir) {
220
+ return std::unexpected(
221
+ Error::InvalidArgument("Cannot add a null WZ directory"));
222
+ }
223
+ if (dir->Name().empty()) {
224
+ return std::unexpected(
225
+ Error::InvalidArgument("WZ directory name cannot be empty"));
226
+ }
227
+ if (dir->Parent()) {
228
+ return std::unexpected(
229
+ Error::InvalidArgument("WZ directory already has a parent"));
230
+ }
231
+ if (GetDirectoryByName(dir->Name())) {
232
+ return std::unexpected(
233
+ Error::InvalidArgument("Duplicate WZ directory name: " + dir->Name()));
234
+ }
235
+ dir->SetWzFile(wzFile_);
236
+ dir->SetHash(hash_);
237
+ dir->SetWzIv(wz_iv_);
238
+ dir->SetParent(this);
239
+ subDirs_.push_back(std::move(dir));
240
+ return {};
241
+ }
242
+
243
+ Result<void> WzDirectory::AddImage(std::unique_ptr<WzImage> img) {
244
+ if (!img) {
245
+ return std::unexpected(
246
+ Error::InvalidArgument("Cannot add a null WZ image"));
247
+ }
248
+ if (img->Name().empty()) {
249
+ return std::unexpected(
250
+ Error::InvalidArgument("WZ image name cannot be empty"));
251
+ }
252
+ if (img->Parent()) {
253
+ return std::unexpected(
254
+ Error::InvalidArgument("WZ image already has a parent"));
255
+ }
256
+ if (GetImageByName(img->Name())) {
257
+ return std::unexpected(
258
+ Error::InvalidArgument("Duplicate WZ image name: " + img->Name()));
259
+ }
260
+ img->SetParent(this);
261
+ images_.push_back(std::move(img));
262
+ return {};
263
+ }
264
+
265
+ void WzDirectory::ClearImages() {
266
+ images_.clear();
267
+ }
268
+
269
+ void WzDirectory::ClearDirectories() {
270
+ subDirs_.clear();
271
+ }
272
+
273
+ static std::string ToLower(const std::string& s) {
274
+ std::string r = s;
275
+ std::transform(r.begin(), r.end(), r.begin(), [](unsigned char c) {
276
+ return static_cast<char>(std::tolower(c));
277
+ });
278
+ return r;
279
+ }
280
+
281
+ WzImage* WzDirectory::GetImageByName(const std::string& name) {
282
+ std::string lower = ToLower(name);
283
+ for (auto& img : images_) {
284
+ if (ToLower(img->Name()) == lower) return img.get();
285
+ }
286
+ return nullptr;
287
+ }
288
+
289
+ WzDirectory* WzDirectory::GetDirectoryByName(const std::string& name) {
290
+ std::string lower = ToLower(name);
291
+ for (auto& dir : subDirs_) {
292
+ if (ToLower(dir->Name()) == lower) return dir.get();
293
+ }
294
+ return nullptr;
295
+ }
296
+
297
+ Result<std::unique_ptr<WzImage>> WzDirectory::RemoveImage(WzImage* image) {
298
+ if (!image) {
299
+ return std::unexpected(
300
+ Error::InvalidArgument("Cannot remove a null WZ image"));
301
+ }
302
+ auto it = std::find_if(images_.begin(), images_.end(), [image](auto& img) {
303
+ return img.get() == image;
304
+ });
305
+ if (it == images_.end()) {
306
+ return std::unexpected(
307
+ Error::NotFound("WZ image is not owned by this directory"));
308
+ }
309
+ auto removed = std::move(*it);
310
+ images_.erase(it);
311
+ if (removed) removed->SetParent(nullptr);
312
+ return removed;
313
+ }
314
+
315
+ Result<std::unique_ptr<WzDirectory>> WzDirectory::RemoveDirectory(
316
+ WzDirectory* dir) {
317
+ if (!dir) {
318
+ return std::unexpected(
319
+ Error::InvalidArgument("Cannot remove a null WZ directory"));
320
+ }
321
+ auto it = std::find_if(subDirs_.begin(), subDirs_.end(), [dir](auto& subDir) {
322
+ return subDir.get() == dir;
323
+ });
324
+ if (it == subDirs_.end()) {
325
+ return std::unexpected(
326
+ Error::NotFound("WZ directory is not owned by this directory"));
327
+ }
328
+ auto removed = std::move(*it);
329
+ subDirs_.erase(it);
330
+ if (removed) removed->SetParent(nullptr);
331
+ return removed;
332
+ }
333
+
334
+ int WzDirectory::CountImages() const {
335
+ int count = static_cast<int>(images_.size());
336
+ for (auto& dir : subDirs_) {
337
+ count += dir->CountImages();
338
+ }
339
+ return count;
340
+ }
341
+
342
+ WzObject* WzDirectory::operator[](const std::string& name) const {
343
+ std::string lower = ToLower(name);
344
+ for (auto& img : images_) {
345
+ if (ToLower(img->Name()) == lower) return img.get();
346
+ }
347
+ for (auto& dir : subDirs_) {
348
+ if (ToLower(dir->Name()) == lower) return dir.get();
349
+ }
350
+ return nullptr;
351
+ }
352
+
353
+ void WzDirectory::SetWzIv(const std::array<uint8_t, 4>& iv) {
354
+ wz_iv_ = iv;
355
+ for (auto& dir : subDirs_) {
356
+ dir->SetWzIv(iv);
357
+ }
358
+ }
359
+
360
+ void WzDirectory::SetHash(uint32_t h) {
361
+ hash_ = h;
362
+ for (auto& dir : subDirs_) {
363
+ dir->SetHash(h);
364
+ }
365
+ }
366
+
367
+ Result<int> WzDirectory::GenerateDataFile(const std::array<uint8_t, 4>* useIv,
368
+ bool isDefaultUserKey,
369
+ WzMemoryStream* tempStream) {
370
+ if (!tempStream) {
371
+ return std::unexpected(
372
+ Error::InvalidArgument("Cannot generate WZ data with null stream"));
373
+ }
374
+
375
+ const bool useCustomIv = useIv != nullptr;
376
+
377
+ auto prepareImageData = [&](auto&& self, WzDirectory* dir) -> Result<void> {
378
+ for (auto& img : dir->images_) {
379
+ img->SetChanged(img->Changed() || useCustomIv || !isDefaultUserKey);
380
+ if (img->Changed()) {
381
+ WzMemoryStream imageData;
382
+ WzBinaryWriter imageWriter(imageData,
383
+ useCustomIv ? *useIv : dir->wz_iv_);
384
+ auto saveResult =
385
+ img->SaveImage(&imageWriter, isDefaultUserKey, useCustomIv);
386
+ if (!saveResult.has_value()) {
387
+ return std::unexpected(saveResult.error());
388
+ }
389
+
390
+ const auto& bytes = imageData.Buffer();
391
+ img->CalculateAndSetImageChecksum(bytes);
392
+ img->SetTempFileStart(tempStream->Position());
393
+ if (!tempStream->Write(bytes.data(), bytes.size())) {
394
+ return std::unexpected(
395
+ Error::IoError("Failed to write temporary WZ image data"));
396
+ }
397
+ img->SetTempFileEnd(tempStream->Position());
398
+ } else {
399
+ img->SetTempFileStart(img->Offset());
400
+ img->SetTempFileEnd(img->Offset() + img->BlockSize());
401
+ }
402
+ if (!img->Changed()) {
403
+ img->UnparseImage();
404
+ }
405
+ }
406
+
407
+ for (auto& childDir : dir->subDirs_) {
408
+ auto childResult = self(self, childDir.get());
409
+ if (!childResult.has_value()) {
410
+ return std::unexpected(childResult.error());
411
+ }
412
+ }
413
+ return {};
414
+ };
415
+
416
+ auto prepareResult = prepareImageData(prepareImageData, this);
417
+ if (!prepareResult.has_value()) {
418
+ return std::unexpected(prepareResult.error());
419
+ }
420
+
421
+ WzObjectValueSizer objectSizer;
422
+ auto calculateDirectorySize = [&](auto&& self,
423
+ WzDirectory* dir) -> Result<int> {
424
+ dir->size_ = 0;
425
+ const int entryCount =
426
+ static_cast<int>(dir->subDirs_.size() + dir->images_.size());
427
+ if (entryCount == 0) {
428
+ dir->offsetSize_ = 1;
429
+ return dir->size_;
430
+ }
431
+
432
+ dir->size_ = WzTool::GetCompressedIntLength(entryCount);
433
+ dir->offsetSize_ = dir->size_;
434
+
435
+ for (auto& img : dir->images_) {
436
+ const int nameLen =
437
+ objectSizer.GetLength(img->Name(), WzDirectoryType::WzImage_4);
438
+ const int imgLen = img->BlockSize();
439
+ if (imgLen < 0) {
440
+ return std::unexpected(
441
+ Error::DataError("Cannot repack image with negative block size"));
442
+ }
443
+ auto addResult = AddCheckedInt(&dir->size_, nameLen);
444
+ if (!addResult.has_value()) return std::unexpected(addResult.error());
445
+ addResult =
446
+ AddCheckedInt(&dir->size_, WzTool::GetCompressedIntLength(imgLen));
447
+ if (!addResult.has_value()) return std::unexpected(addResult.error());
448
+ addResult = AddCheckedInt(&dir->size_, imgLen);
449
+ if (!addResult.has_value()) return std::unexpected(addResult.error());
450
+ addResult = AddCheckedInt(
451
+ &dir->size_, WzTool::GetCompressedIntLength(img->Checksum()));
452
+ if (!addResult.has_value()) return std::unexpected(addResult.error());
453
+ addResult = AddCheckedInt(&dir->size_, 4);
454
+ if (!addResult.has_value()) return std::unexpected(addResult.error());
455
+
456
+ addResult = AddCheckedInt(&dir->offsetSize_, nameLen);
457
+ if (!addResult.has_value()) return std::unexpected(addResult.error());
458
+ addResult = AddCheckedInt(&dir->offsetSize_,
459
+ WzTool::GetCompressedIntLength(imgLen));
460
+ if (!addResult.has_value()) return std::unexpected(addResult.error());
461
+ addResult = AddCheckedInt(
462
+ &dir->offsetSize_, WzTool::GetCompressedIntLength(img->Checksum()));
463
+ if (!addResult.has_value()) return std::unexpected(addResult.error());
464
+ addResult = AddCheckedInt(&dir->offsetSize_, 4);
465
+ if (!addResult.has_value()) return std::unexpected(addResult.error());
466
+ }
467
+
468
+ std::vector<std::pair<WzDirectory*, int>> childNameLengths;
469
+ childNameLengths.reserve(dir->subDirs_.size());
470
+ for (auto& childDir : dir->subDirs_) {
471
+ childNameLengths.emplace_back(
472
+ childDir.get(),
473
+ objectSizer.GetLength(childDir->Name(),
474
+ WzDirectoryType::WzDirectory_3));
475
+ }
476
+
477
+ for (auto [childDir, nameLen] : childNameLengths) {
478
+ auto childSize = self(self, childDir);
479
+ if (!childSize.has_value()) return std::unexpected(childSize.error());
480
+ auto addResult = AddCheckedInt(&dir->size_, nameLen);
481
+ if (!addResult.has_value()) return std::unexpected(addResult.error());
482
+ addResult = AddCheckedInt(&dir->size_, childSize.value());
483
+ if (!addResult.has_value()) return std::unexpected(addResult.error());
484
+ addResult = AddCheckedInt(
485
+ &dir->size_, WzTool::GetCompressedIntLength(childDir->BlockSize()));
486
+ if (!addResult.has_value()) return std::unexpected(addResult.error());
487
+ addResult = AddCheckedInt(
488
+ &dir->size_, WzTool::GetCompressedIntLength(childDir->Checksum()));
489
+ if (!addResult.has_value()) return std::unexpected(addResult.error());
490
+ addResult = AddCheckedInt(&dir->size_, 4);
491
+ if (!addResult.has_value()) return std::unexpected(addResult.error());
492
+
493
+ addResult = AddCheckedInt(&dir->offsetSize_, nameLen);
494
+ if (!addResult.has_value()) return std::unexpected(addResult.error());
495
+ addResult =
496
+ AddCheckedInt(&dir->offsetSize_,
497
+ WzTool::GetCompressedIntLength(childDir->BlockSize()));
498
+ if (!addResult.has_value()) return std::unexpected(addResult.error());
499
+ addResult =
500
+ AddCheckedInt(&dir->offsetSize_,
501
+ WzTool::GetCompressedIntLength(childDir->Checksum()));
502
+ if (!addResult.has_value()) return std::unexpected(addResult.error());
503
+ addResult = AddCheckedInt(&dir->offsetSize_, 4);
504
+ if (!addResult.has_value()) return std::unexpected(addResult.error());
505
+ }
506
+
507
+ return dir->size_;
508
+ };
509
+
510
+ auto sizeResult = calculateDirectorySize(calculateDirectorySize, this);
511
+ if (!sizeResult.has_value()) {
512
+ return std::unexpected(sizeResult.error());
513
+ }
514
+ return size_;
515
+ }
516
+
517
+ Result<void> WzDirectory::SaveDirectory(WzBinaryWriter* writer) {
518
+ if (!writer) {
519
+ return std::unexpected(
520
+ Error::InvalidArgument("Cannot save WZ directory with null writer"));
521
+ }
522
+
523
+ offset_ = writer->Position();
524
+ const int entryCount = static_cast<int>(subDirs_.size() + images_.size());
525
+ if (entryCount == 0) {
526
+ size_ = 0;
527
+ return {};
528
+ }
529
+
530
+ writer->WriteCompressedInt(entryCount);
531
+ for (auto& img : images_) {
532
+ writer->WriteWzObjectValue(img->Name(), WzDirectoryType::WzImage_4);
533
+ writer->WriteCompressedInt(img->BlockSize());
534
+ writer->WriteCompressedInt(img->Checksum());
535
+ writer->WriteOffset(img->Offset());
536
+ }
537
+ for (auto& dir : subDirs_) {
538
+ writer->WriteWzObjectValue(dir->Name(), WzDirectoryType::WzDirectory_3);
539
+ writer->WriteCompressedInt(dir->BlockSize());
540
+ writer->WriteCompressedInt(dir->Checksum());
541
+ writer->WriteOffset(dir->Offset());
542
+ }
543
+ for (auto& dir : subDirs_) {
544
+ if (dir->BlockSize() > 0) {
545
+ auto saveResult = dir->SaveDirectory(writer);
546
+ if (!saveResult.has_value()) {
547
+ return std::unexpected(saveResult.error());
548
+ }
549
+ } else {
550
+ writer->WriteByte(0);
551
+ }
552
+ }
553
+ return {};
554
+ }
555
+
556
+ Result<void> WzDirectory::SaveImages(WzBinaryWriter* writer,
557
+ WzMemoryStream* tempStream) {
558
+ if (!writer || !tempStream) {
559
+ return std::unexpected(
560
+ Error::InvalidArgument("Cannot save WZ images with null stream"));
561
+ }
562
+
563
+ for (auto& img : images_) {
564
+ const int64_t start = img->TempFileStart();
565
+ const int64_t end = img->TempFileEnd();
566
+ if (end < start) {
567
+ return std::unexpected(
568
+ Error::DataError("Invalid WZ image temporary byte range"));
569
+ }
570
+ const int64_t length = end - start;
571
+ if (img->Changed()) {
572
+ if (img->BlockSize() < 0 ||
573
+ length != static_cast<int64_t>(img->BlockSize())) {
574
+ return std::unexpected(
575
+ Error::DataError("Invalid changed WZ image byte range"));
576
+ }
577
+ if (!tempStream->Seek(start, WzSeekOrigin::Begin)) {
578
+ return std::unexpected(
579
+ Error::IoError("Failed to seek changed WZ image data"));
580
+ }
581
+ std::vector<uint8_t> buffer(static_cast<size_t>(img->BlockSize()));
582
+ if (tempStream->Read(buffer.data(), buffer.size()) != buffer.size()) {
583
+ return std::unexpected(
584
+ Error::IoError("Failed to read changed WZ image data"));
585
+ }
586
+ if (!writer->BaseStream().Write(buffer.data(), buffer.size())) {
587
+ return std::unexpected(
588
+ Error::IoError("Failed to write changed WZ image data"));
589
+ }
590
+ } else {
591
+ if (!img->Reader()) {
592
+ return std::unexpected(Error::InvalidArgument(
593
+ "Cannot copy unchanged WZ image without reader"));
594
+ }
595
+ std::lock_guard<std::recursive_mutex> lock(img->Reader()->Mutex());
596
+ const int64_t originalPos = img->Reader()->Position();
597
+ const uint64_t sourceSize = img->Reader()->SourceSize();
598
+ if (start < 0 || length < 0 ||
599
+ static_cast<uint64_t>(start) > sourceSize ||
600
+ static_cast<uint64_t>(length) >
601
+ sourceSize - static_cast<uint64_t>(start)) {
602
+ img->Reader()->SetPosition(originalPos);
603
+ return std::unexpected(Error::IoError(
604
+ "Unchanged WZ image source range is unavailable: start=" +
605
+ std::to_string(start) + ", length=" + std::to_string(length) +
606
+ ", sourceEnd=" + std::to_string(sourceSize)));
607
+ }
608
+ img->Reader()->SetPosition(start);
609
+ auto bytes = img->Reader()->ReadBytes(static_cast<size_t>(length));
610
+ if (bytes.size() != static_cast<size_t>(length)) {
611
+ img->Reader()->SetPosition(originalPos);
612
+ return std::unexpected(
613
+ Error::IoError("Failed to read unchanged WZ image data"));
614
+ }
615
+ if (!writer->BaseStream().Write(bytes.data(), bytes.size())) {
616
+ img->Reader()->SetPosition(originalPos);
617
+ return std::unexpected(
618
+ Error::IoError("Failed to write unchanged WZ image data"));
619
+ }
620
+ img->Reader()->SetPosition(originalPos);
621
+ }
622
+ }
623
+
624
+ for (auto& dir : subDirs_) {
625
+ auto saveResult = dir->SaveImages(writer, tempStream);
626
+ if (!saveResult.has_value()) return std::unexpected(saveResult.error());
627
+ }
628
+ return {};
629
+ }
630
+
631
+ Result<uint32_t> WzDirectory::GetOffsets(uint32_t currentOffset) {
632
+ offset_ = currentOffset;
633
+ if (offsetSize_ < 0) {
634
+ return std::unexpected(
635
+ Error::DataError("Cannot add negative WZ directory offset size"));
636
+ }
637
+ auto nextOffset = AddCheckedOffset(
638
+ currentOffset, static_cast<uint64_t>(offsetSize_), "directory metadata");
639
+ if (!nextOffset.has_value()) return std::unexpected(nextOffset.error());
640
+ currentOffset = nextOffset.value();
641
+ for (auto& dir : subDirs_) {
642
+ auto childOffset = dir->GetOffsets(currentOffset);
643
+ if (!childOffset.has_value()) return std::unexpected(childOffset.error());
644
+ currentOffset = childOffset.value();
645
+ }
646
+ return currentOffset;
647
+ }
648
+
649
+ Result<uint32_t> WzDirectory::GetImgOffsets(uint32_t currentOffset) {
650
+ for (auto& img : images_) {
651
+ if (img->BlockSize() < 0) {
652
+ return std::unexpected(
653
+ Error::DataError("Cannot add negative WZ image block size"));
654
+ }
655
+ img->SetOffset(currentOffset);
656
+ auto nextOffset = AddCheckedOffset(
657
+ currentOffset, static_cast<uint64_t>(img->BlockSize()), "image block");
658
+ if (!nextOffset.has_value()) return std::unexpected(nextOffset.error());
659
+ currentOffset = nextOffset.value();
660
+ }
661
+ for (auto& dir : subDirs_) {
662
+ auto childOffset = dir->GetImgOffsets(currentOffset);
663
+ if (!childOffset.has_value()) return std::unexpected(childOffset.error());
664
+ currentOffset = childOffset.value();
665
+ }
666
+ return currentOffset;
667
+ }
668
+
669
+ } // namespace wz
@@ -0,0 +1,20 @@
1
+ #include "wz/WzEnums.h"
2
+
3
+ namespace wz {
4
+
5
+ std::string GetErrorDescription(WzFileParseStatus status) {
6
+ switch (status) {
7
+ case WzFileParseStatus::Success:
8
+ return "Success";
9
+ case WzFileParseStatus::Failed_Unknown:
10
+ return "Failed, in this case the causes are undetermined.";
11
+ case WzFileParseStatus::Path_Is_Null:
12
+ return "Path is null";
13
+ case WzFileParseStatus::Error_Game_Ver_Hash:
14
+ return "Error with game version hash : The specified game version is "
15
+ "incorrect and WzLib was unable to determine the version itself";
16
+ }
17
+ return {};
18
+ }
19
+
20
+ } // namespace wz