├── .github └── workflows │ ├── linux_build.yml │ ├── mac_build.yml │ ├── release.yml │ └── windows_build.yml ├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── Makefile ├── README.md ├── TemplateFactory.cpp ├── TemplateFactory.h ├── assets └── example │ └── demo.yml ├── config.yml ├── lib ├── CLI11.hpp ├── StormLib │ ├── .gitignore │ ├── CMakeLists.txt │ ├── Info.plist │ ├── LICENSE │ ├── Premake5.lua │ ├── Publish.bat │ ├── README.md │ ├── StormLib.kdev4 │ ├── StormLib.xcodeproj │ │ └── project.pbxproj │ ├── StormLib_vs08.sln │ ├── StormLib_vs08.vcproj │ ├── StormLib_vs08_dll.vcproj │ ├── StormLib_vs08_test.vcproj │ ├── StormLib_vs19.sln │ ├── StormLib_vs19.vcxproj │ ├── StormLib_vs19.vcxproj.filters │ ├── StormLib_vs19_dll.vcxproj │ ├── StormLib_vs19_dll.vcxproj.filters │ ├── StormLib_vs19_test.vcxproj │ ├── StormLib_vs19_test.vcxproj.filters │ ├── doc │ │ ├── History.txt │ │ ├── The MoPaQ File Format 0.9.txt │ │ ├── The MoPaQ File Format 1.0.txt │ │ ├── d3-authenticationcode │ │ │ ├── d3-authenticationcode-deDE.txt │ │ │ ├── d3-authenticationcode-enGB.txt │ │ │ ├── d3-authenticationcode-enSG.txt │ │ │ ├── d3-authenticationcode-enUS.txt │ │ │ ├── d3-authenticationcode-esES.txt │ │ │ ├── d3-authenticationcode-esMX.txt │ │ │ ├── d3-authenticationcode-frFR.txt │ │ │ ├── d3-authenticationcode-itIT.txt │ │ │ ├── d3-authenticationcode-koKR.txt │ │ │ ├── d3-authenticationcode-plPL.txt │ │ │ ├── d3-authenticationcode-ptBR.txt │ │ │ └── d3-authenticationcode-zhTW.txt │ │ ├── hots-authenticationcode │ │ │ └── hots-authenticationcode-bgdl.txt │ │ └── sc2-authenticationcode │ │ │ ├── sc2-authenticationcode-deDE.txt │ │ │ ├── sc2-authenticationcode-enGB.txt │ │ │ ├── sc2-authenticationcode-enUS.txt │ │ │ ├── sc2-authenticationcode-esES.txt │ │ │ ├── sc2-authenticationcode-esMX.txt │ │ │ ├── sc2-authenticationcode-frFR.txt │ │ │ ├── sc2-authenticationcode-itIT.txt │ │ │ ├── sc2-authenticationcode-koKR.txt │ │ │ ├── sc2-authenticationcode-plPL.txt │ │ │ ├── sc2-authenticationcode-ptBR.txt │ │ │ ├── sc2-authenticationcode-ruRU.txt │ │ │ └── sc2-authenticationcode-zhTW.txt │ ├── make-msvc.bat │ ├── make.bat │ ├── sources │ ├── src │ │ ├── DllMain.c │ │ ├── DllMain.def │ │ ├── DllMain.rc │ │ ├── FileStream.cpp │ │ ├── FileStream.h │ │ ├── SBaseCommon.cpp │ │ ├── SBaseDumpData.cpp │ │ ├── SBaseFileTable.cpp │ │ ├── SBaseSubTypes.cpp │ │ ├── SCompression.cpp │ │ ├── SFileAddFile.cpp │ │ ├── SFileAttributes.cpp │ │ ├── SFileCompactArchive.cpp │ │ ├── SFileCreateArchive.cpp │ │ ├── SFileExtractFile.cpp │ │ ├── SFileFindFile.cpp │ │ ├── SFileGetFileInfo.cpp │ │ ├── SFileListFile.cpp │ │ ├── SFileOpenArchive.cpp │ │ ├── SFileOpenFileEx.cpp │ │ ├── SFilePatchArchives.cpp │ │ ├── SFileReadFile.cpp │ │ ├── SFileVerify.cpp │ │ ├── StormCommon.h │ │ ├── StormLib.exp │ │ ├── StormLib.h │ │ ├── StormPort.h │ │ ├── adpcm │ │ │ ├── adpcm.cpp │ │ │ └── adpcm.h │ │ ├── bzip2 │ │ │ ├── blocksort.c │ │ │ ├── bzlib.c │ │ │ ├── bzlib.h │ │ │ ├── bzlib_private.h │ │ │ ├── compress.c │ │ │ ├── crctable.c │ │ │ ├── decompress.c │ │ │ ├── huffman.c │ │ │ └── randtable.c │ │ ├── huffman │ │ │ ├── huff.cpp │ │ │ └── huff.h │ │ ├── jenkins │ │ │ ├── lookup.h │ │ │ └── lookup3.c │ │ ├── libtomcrypt │ │ │ └── src │ │ │ │ ├── hashes │ │ │ │ ├── hash_memory.c │ │ │ │ ├── md5.c │ │ │ │ └── sha1.c │ │ │ │ ├── headers │ │ │ │ ├── tomcrypt.h │ │ │ │ ├── tomcrypt_argchk.h │ │ │ │ ├── tomcrypt_cfg.h │ │ │ │ ├── tomcrypt_cipher.h │ │ │ │ ├── tomcrypt_custom.h │ │ │ │ ├── tomcrypt_hash.h │ │ │ │ ├── tomcrypt_mac.h │ │ │ │ ├── tomcrypt_macros.h │ │ │ │ ├── tomcrypt_math.h │ │ │ │ ├── tomcrypt_misc.h │ │ │ │ ├── tomcrypt_pk.h │ │ │ │ ├── tomcrypt_pkcs.h │ │ │ │ └── tomcrypt_prng.h │ │ │ │ ├── math │ │ │ │ ├── ltm_desc.c │ │ │ │ ├── multi.c │ │ │ │ └── rand_prime.c │ │ │ │ ├── misc │ │ │ │ ├── base64_decode.c │ │ │ │ ├── crypt_argchk.c │ │ │ │ ├── crypt_find_hash.c │ │ │ │ ├── crypt_find_prng.c │ │ │ │ ├── crypt_hash_descriptor.c │ │ │ │ ├── crypt_hash_is_valid.c │ │ │ │ ├── crypt_libc.c │ │ │ │ ├── crypt_ltc_mp_descriptor.c │ │ │ │ ├── crypt_prng_descriptor.c │ │ │ │ ├── crypt_prng_is_valid.c │ │ │ │ ├── crypt_register_hash.c │ │ │ │ ├── crypt_register_prng.c │ │ │ │ └── zeromem.c │ │ │ │ └── pk │ │ │ │ ├── asn1 │ │ │ │ ├── der_decode_bit_string.c │ │ │ │ ├── der_decode_boolean.c │ │ │ │ ├── der_decode_choice.c │ │ │ │ ├── der_decode_ia5_string.c │ │ │ │ ├── der_decode_integer.c │ │ │ │ ├── der_decode_object_identifier.c │ │ │ │ ├── der_decode_octet_string.c │ │ │ │ ├── der_decode_printable_string.c │ │ │ │ ├── der_decode_sequence_ex.c │ │ │ │ ├── der_decode_sequence_flexi.c │ │ │ │ ├── der_decode_sequence_multi.c │ │ │ │ ├── der_decode_short_integer.c │ │ │ │ ├── der_decode_utctime.c │ │ │ │ ├── der_decode_utf8_string.c │ │ │ │ ├── der_encode_bit_string.c │ │ │ │ ├── der_encode_boolean.c │ │ │ │ ├── der_encode_ia5_string.c │ │ │ │ ├── der_encode_integer.c │ │ │ │ ├── der_encode_object_identifier.c │ │ │ │ ├── der_encode_octet_string.c │ │ │ │ ├── der_encode_printable_string.c │ │ │ │ ├── der_encode_sequence_ex.c │ │ │ │ ├── der_encode_sequence_multi.c │ │ │ │ ├── der_encode_set.c │ │ │ │ ├── der_encode_setof.c │ │ │ │ ├── der_encode_short_integer.c │ │ │ │ ├── der_encode_utctime.c │ │ │ │ ├── der_encode_utf8_string.c │ │ │ │ ├── der_length_bit_string.c │ │ │ │ ├── der_length_boolean.c │ │ │ │ ├── der_length_ia5_string.c │ │ │ │ ├── der_length_integer.c │ │ │ │ ├── der_length_object_identifier.c │ │ │ │ ├── der_length_octet_string.c │ │ │ │ ├── der_length_printable_string.c │ │ │ │ ├── der_length_sequence.c │ │ │ │ ├── der_length_short_integer.c │ │ │ │ ├── der_length_utctime.c │ │ │ │ ├── der_length_utf8_string.c │ │ │ │ └── der_sequence_free.c │ │ │ │ ├── ecc │ │ │ │ ├── ltc_ecc_map.c │ │ │ │ ├── ltc_ecc_mul2add.c │ │ │ │ ├── ltc_ecc_mulmod.c │ │ │ │ ├── ltc_ecc_points.c │ │ │ │ ├── ltc_ecc_projective_add_point.c │ │ │ │ └── ltc_ecc_projective_dbl_point.c │ │ │ │ ├── pkcs1 │ │ │ │ ├── pkcs_1_mgf1.c │ │ │ │ ├── pkcs_1_oaep_decode.c │ │ │ │ ├── pkcs_1_pss_decode.c │ │ │ │ ├── pkcs_1_pss_encode.c │ │ │ │ ├── pkcs_1_v1_5_decode.c │ │ │ │ └── pkcs_1_v1_5_encode.c │ │ │ │ └── rsa │ │ │ │ ├── rsa_exptmod.c │ │ │ │ ├── rsa_free.c │ │ │ │ ├── rsa_import.c │ │ │ │ ├── rsa_make_key.c │ │ │ │ ├── rsa_sign_hash.c │ │ │ │ ├── rsa_verify_hash.c │ │ │ │ └── rsa_verify_simple.c │ │ ├── libtommath │ │ │ ├── bn_fast_mp_invmod.c │ │ │ ├── bn_fast_mp_montgomery_reduce.c │ │ │ ├── bn_fast_s_mp_mul_digs.c │ │ │ ├── bn_fast_s_mp_mul_high_digs.c │ │ │ ├── bn_fast_s_mp_sqr.c │ │ │ ├── bn_mp_2expt.c │ │ │ ├── bn_mp_abs.c │ │ │ ├── bn_mp_add.c │ │ │ ├── bn_mp_add_d.c │ │ │ ├── bn_mp_addmod.c │ │ │ ├── bn_mp_and.c │ │ │ ├── bn_mp_clamp.c │ │ │ ├── bn_mp_clear.c │ │ │ ├── bn_mp_clear_multi.c │ │ │ ├── bn_mp_cmp.c │ │ │ ├── bn_mp_cmp_d.c │ │ │ ├── bn_mp_cmp_mag.c │ │ │ ├── bn_mp_cnt_lsb.c │ │ │ ├── bn_mp_copy.c │ │ │ ├── bn_mp_count_bits.c │ │ │ ├── bn_mp_div.c │ │ │ ├── bn_mp_div_2.c │ │ │ ├── bn_mp_div_2d.c │ │ │ ├── bn_mp_div_3.c │ │ │ ├── bn_mp_div_d.c │ │ │ ├── bn_mp_dr_is_modulus.c │ │ │ ├── bn_mp_dr_reduce.c │ │ │ ├── bn_mp_dr_setup.c │ │ │ ├── bn_mp_exch.c │ │ │ ├── bn_mp_expt_d.c │ │ │ ├── bn_mp_exptmod.c │ │ │ ├── bn_mp_exptmod_fast.c │ │ │ ├── bn_mp_exteuclid.c │ │ │ ├── bn_mp_fread.c │ │ │ ├── bn_mp_fwrite.c │ │ │ ├── bn_mp_gcd.c │ │ │ ├── bn_mp_get_int.c │ │ │ ├── bn_mp_grow.c │ │ │ ├── bn_mp_init.c │ │ │ ├── bn_mp_init_copy.c │ │ │ ├── bn_mp_init_multi.c │ │ │ ├── bn_mp_init_set.c │ │ │ ├── bn_mp_init_set_int.c │ │ │ ├── bn_mp_init_size.c │ │ │ ├── bn_mp_invmod.c │ │ │ ├── bn_mp_invmod_slow.c │ │ │ ├── bn_mp_is_square.c │ │ │ ├── bn_mp_jacobi.c │ │ │ ├── bn_mp_karatsuba_mul.c │ │ │ ├── bn_mp_karatsuba_sqr.c │ │ │ ├── bn_mp_lcm.c │ │ │ ├── bn_mp_lshd.c │ │ │ ├── bn_mp_mod.c │ │ │ ├── bn_mp_mod_2d.c │ │ │ ├── bn_mp_mod_d.c │ │ │ ├── bn_mp_montgomery_calc_normalization.c │ │ │ ├── bn_mp_montgomery_reduce.c │ │ │ ├── bn_mp_montgomery_setup.c │ │ │ ├── bn_mp_mul.c │ │ │ ├── bn_mp_mul_2.c │ │ │ ├── bn_mp_mul_2d.c │ │ │ ├── bn_mp_mul_d.c │ │ │ ├── bn_mp_mulmod.c │ │ │ ├── bn_mp_n_root.c │ │ │ ├── bn_mp_neg.c │ │ │ ├── bn_mp_or.c │ │ │ ├── bn_mp_prime_fermat.c │ │ │ ├── bn_mp_prime_is_divisible.c │ │ │ ├── bn_mp_prime_is_prime.c │ │ │ ├── bn_mp_prime_miller_rabin.c │ │ │ ├── bn_mp_prime_next_prime.c │ │ │ ├── bn_mp_prime_rabin_miller_trials.c │ │ │ ├── bn_mp_prime_random_ex.c │ │ │ ├── bn_mp_radix_size.c │ │ │ ├── bn_mp_radix_smap.c │ │ │ ├── bn_mp_rand.c │ │ │ ├── bn_mp_read_radix.c │ │ │ ├── bn_mp_read_signed_bin.c │ │ │ ├── bn_mp_read_unsigned_bin.c │ │ │ ├── bn_mp_reduce.c │ │ │ ├── bn_mp_reduce_2k.c │ │ │ ├── bn_mp_reduce_2k_l.c │ │ │ ├── bn_mp_reduce_2k_setup.c │ │ │ ├── bn_mp_reduce_2k_setup_l.c │ │ │ ├── bn_mp_reduce_is_2k.c │ │ │ ├── bn_mp_reduce_is_2k_l.c │ │ │ ├── bn_mp_reduce_setup.c │ │ │ ├── bn_mp_rshd.c │ │ │ ├── bn_mp_set.c │ │ │ ├── bn_mp_set_int.c │ │ │ ├── bn_mp_shrink.c │ │ │ ├── bn_mp_signed_bin_size.c │ │ │ ├── bn_mp_sqr.c │ │ │ ├── bn_mp_sqrmod.c │ │ │ ├── bn_mp_sqrt.c │ │ │ ├── bn_mp_sub.c │ │ │ ├── bn_mp_sub_d.c │ │ │ ├── bn_mp_submod.c │ │ │ ├── bn_mp_to_signed_bin.c │ │ │ ├── bn_mp_to_signed_bin_n.c │ │ │ ├── bn_mp_to_unsigned_bin.c │ │ │ ├── bn_mp_to_unsigned_bin_n.c │ │ │ ├── bn_mp_toom_mul.c │ │ │ ├── bn_mp_toom_sqr.c │ │ │ ├── bn_mp_toradix.c │ │ │ ├── bn_mp_toradix_n.c │ │ │ ├── bn_mp_unsigned_bin_size.c │ │ │ ├── bn_mp_xor.c │ │ │ ├── bn_mp_zero.c │ │ │ ├── bn_prime_tab.c │ │ │ ├── bn_reverse.c │ │ │ ├── bn_s_mp_add.c │ │ │ ├── bn_s_mp_exptmod.c │ │ │ ├── bn_s_mp_mul_digs.c │ │ │ ├── bn_s_mp_mul_high_digs.c │ │ │ ├── bn_s_mp_sqr.c │ │ │ ├── bn_s_mp_sub.c │ │ │ ├── bncore.c │ │ │ ├── tommath.h │ │ │ ├── tommath_class.h │ │ │ └── tommath_superclass.h │ │ ├── lzma │ │ │ ├── C │ │ │ │ ├── LzFind.c │ │ │ │ ├── LzFind.h │ │ │ │ ├── LzFindMt.c │ │ │ │ ├── LzFindMt.h │ │ │ │ ├── LzHash.h │ │ │ │ ├── LzmaDec.c │ │ │ │ ├── LzmaDec.h │ │ │ │ ├── LzmaEnc.c │ │ │ │ ├── LzmaEnc.h │ │ │ │ ├── Threads.c │ │ │ │ ├── Threads.h │ │ │ │ └── Types.h │ │ │ └── info.txt │ │ ├── pklib │ │ │ ├── crc32.c │ │ │ ├── explode.c │ │ │ ├── implode.c │ │ │ └── pklib.h │ │ ├── resource.h │ │ ├── sparse │ │ │ ├── sparse.cpp │ │ │ └── sparse.h │ │ ├── wdk │ │ │ ├── sources-cpp.cpp │ │ │ ├── sources-wdk-bzip2.c │ │ │ ├── sources-wdk-ltc.c │ │ │ ├── sources-wdk-lzma.c │ │ │ ├── sources-wdk-misc.c │ │ │ ├── sources-wdk-tomcrypt.c │ │ │ ├── sources-wdk-tommath.c │ │ │ └── sources-wdk-zlib.c │ │ └── zlib │ │ │ ├── adler32.c │ │ │ ├── compress.c │ │ │ ├── compress_zlib.c │ │ │ ├── crc32.c │ │ │ ├── crc32.h │ │ │ ├── deflate.c │ │ │ ├── deflate.h │ │ │ ├── gzguts.h │ │ │ ├── inffast.c │ │ │ ├── inffast.h │ │ │ ├── inffixed.h │ │ │ ├── inflate.c │ │ │ ├── inflate.h │ │ │ ├── inftrees.c │ │ │ ├── inftrees.h │ │ │ ├── trees.c │ │ │ ├── trees.h │ │ │ ├── zconf.h │ │ │ ├── zlib.h │ │ │ ├── zutil.c │ │ │ └── zutil.h │ ├── storm_dll │ │ ├── storm.cpp │ │ ├── storm.def │ │ ├── storm.h │ │ ├── storm.vcxproj │ │ ├── storm.vcxproj.filters │ │ ├── storm_test.cpp │ │ ├── storm_test.vcxproj │ │ ├── storm_test.vcxproj.filters │ │ └── storm_vs19.sln │ └── test │ │ ├── Readme.txt │ │ ├── StormTest.cpp │ │ ├── TLogHelper.cpp │ │ └── stormlib-test.txt ├── binarytools │ ├── BinaryReader.cpp │ ├── BinaryReader.h │ ├── BinaryWriter.cpp │ ├── BinaryWriter.h │ ├── CMakeLists.txt │ ├── FileHelper.h │ ├── MemoryStream.cpp │ ├── MemoryStream.h │ ├── PathHelper.h │ ├── Stream.cpp │ ├── Stream.h │ └── endianness.h ├── hj │ ├── pyutils.h │ ├── sha1.h │ └── zip.h ├── libmio0 │ ├── mio0.c │ ├── mio0.h │ ├── tkmk00.c │ ├── tkmk00.h │ ├── utils.c │ └── utils.h ├── libyay0 │ ├── yay0.c │ └── yay0.h ├── miniz │ └── zip_file.hpp ├── n64graphics │ ├── CMakeLists.txt │ ├── n64graphics.c │ ├── n64graphics.h │ ├── stb_image.h │ └── stb_image_write.h ├── nposix │ └── dirent.h └── strhash64 │ ├── StrHash64.cpp │ └── StrHash64.h ├── src ├── Companion.cpp ├── Companion.h ├── archive │ ├── BinaryWrapper.cpp │ ├── BinaryWrapper.h │ ├── SWrapper.cpp │ ├── SWrapper.h │ ├── ZWrapper.cpp │ └── ZWrapper.h ├── factories │ ├── AssetArrayFactory.cpp │ ├── AssetArrayFactory.h │ ├── BaseFactory.cpp │ ├── BaseFactory.h │ ├── BlobFactory.cpp │ ├── BlobFactory.h │ ├── CompressedTextureFactory.cpp │ ├── CompressedTextureFactory.h │ ├── DisplayListFactory.cpp │ ├── DisplayListFactory.h │ ├── DisplayListOverrides.cpp │ ├── DisplayListOverrides.h │ ├── FloatFactory.cpp │ ├── FloatFactory.h │ ├── GenericArrayFactory.cpp │ ├── GenericArrayFactory.h │ ├── IncludeFactory.cpp │ ├── IncludeFactory.h │ ├── LightsFactory.cpp │ ├── LightsFactory.h │ ├── MtxFactory.cpp │ ├── MtxFactory.h │ ├── ResourceType.h │ ├── TextureFactory.cpp │ ├── TextureFactory.h │ ├── Vec3fFactory.cpp │ ├── Vec3fFactory.h │ ├── Vec3sFactory.cpp │ ├── Vec3sFactory.h │ ├── ViewportFactory.cpp │ ├── ViewportFactory.h │ ├── VtxFactory.cpp │ ├── VtxFactory.h │ ├── fzerox │ │ ├── CourseFactory.cpp │ │ ├── CourseFactory.h │ │ ├── GhostRecordFactory.cpp │ │ ├── GhostRecordFactory.h │ │ ├── course │ │ │ └── Course.h │ │ └── ghost │ │ │ └── Ghost.h │ ├── mk64 │ │ ├── CourseMetadata.cpp │ │ ├── CourseMetadata.h │ │ ├── CourseVtx.cpp │ │ ├── CourseVtx.h │ │ ├── DrivingBehaviour.cpp │ │ ├── DrivingBehaviour.h │ │ ├── ItemCurve.cpp │ │ ├── ItemCurve.h │ │ ├── SpawnData.cpp │ │ ├── SpawnData.h │ │ ├── TrackSections.cpp │ │ ├── TrackSections.h │ │ ├── UnkSpawnData.cpp │ │ ├── UnkSpawnData.h │ │ ├── Waypoints.cpp │ │ └── Waypoints.h │ ├── naudio │ │ ├── v0 │ │ │ ├── AIFCDecode.cpp │ │ │ ├── AIFCDecode.h │ │ │ ├── AudioHeaderFactory.cpp │ │ │ ├── AudioHeaderFactory.h │ │ │ ├── AudioManager.cpp │ │ │ ├── AudioManager.h │ │ │ ├── BankFactory.cpp │ │ │ ├── BankFactory.h │ │ │ ├── SampleFactory.cpp │ │ │ ├── SampleFactory.h │ │ │ ├── SequenceFactory.cpp │ │ │ └── SequenceFactory.h │ │ └── v1 │ │ │ ├── AudioContext.cpp │ │ │ ├── AudioContext.h │ │ │ ├── AudioConverter.cpp │ │ │ ├── AudioConverter.h │ │ │ ├── AudioTableFactory.cpp │ │ │ ├── AudioTableFactory.h │ │ │ ├── BookFactory.cpp │ │ │ ├── BookFactory.h │ │ │ ├── DrumFactory.cpp │ │ │ ├── DrumFactory.h │ │ │ ├── EnvelopeFactory.cpp │ │ │ ├── EnvelopeFactory.h │ │ │ ├── InstrumentFactory.cpp │ │ │ ├── InstrumentFactory.h │ │ │ ├── LoopFactory.cpp │ │ │ ├── LoopFactory.h │ │ │ ├── SampleFactory.cpp │ │ │ ├── SampleFactory.h │ │ │ ├── SequenceFactory.cpp │ │ │ ├── SequenceFactory.h │ │ │ ├── SoundFontFactory.cpp │ │ │ └── SoundFontFactory.h │ ├── sf64 │ │ ├── AnimFactory.cpp │ │ ├── AnimFactory.h │ │ ├── ColPolyFactory.cpp │ │ ├── ColPolyFactory.h │ │ ├── EnvironmentFactory.cpp │ │ ├── EnvironmentFactory.h │ │ ├── HitboxFactory.cpp │ │ ├── HitboxFactory.h │ │ ├── MessageFactory.cpp │ │ ├── MessageFactory.h │ │ ├── MessageLookupFactory.cpp │ │ ├── MessageLookupFactory.h │ │ ├── ObjInitFactory.cpp │ │ ├── ObjInitFactory.h │ │ ├── ScriptFactory.cpp │ │ ├── ScriptFactory.h │ │ ├── SkeletonFactory.cpp │ │ ├── SkeletonFactory.h │ │ ├── TriangleFactory.cpp │ │ ├── TriangleFactory.h │ │ └── audio │ │ │ ├── AudioDecompressor.cpp │ │ │ └── AudioDecompressor.h │ └── sm64 │ │ ├── AnimationFactory.cpp │ │ ├── AnimationFactory.h │ │ ├── BehaviorScriptFactory.cpp │ │ ├── BehaviorScriptFactory.h │ │ ├── CollisionFactory.cpp │ │ ├── CollisionFactory.h │ │ ├── DialogFactory.cpp │ │ ├── DialogFactory.h │ │ ├── DictionaryFactory.cpp │ │ ├── DictionaryFactory.h │ │ ├── GeoLayoutFactory.cpp │ │ ├── GeoLayoutFactory.h │ │ ├── LevelScriptFactory.cpp │ │ ├── LevelScriptFactory.h │ │ ├── MacroFactory.cpp │ │ ├── MacroFactory.h │ │ ├── MovtexFactory.cpp │ │ ├── MovtexFactory.h │ │ ├── MovtexQuadFactory.cpp │ │ ├── MovtexQuadFactory.h │ │ ├── PaintingFactory.cpp │ │ ├── PaintingFactory.h │ │ ├── PaintingMapFactory.cpp │ │ ├── PaintingMapFactory.h │ │ ├── TextFactory.cpp │ │ ├── TextFactory.h │ │ ├── TrajectoryFactory.cpp │ │ ├── TrajectoryFactory.h │ │ ├── WaterDropletFactory.cpp │ │ ├── WaterDropletFactory.h │ │ ├── behavior │ │ └── BehaviorCommand.h │ │ ├── collision │ │ ├── SpecialPresetNames.h │ │ └── SurfaceTerrains.h │ │ ├── geo │ │ ├── GeoCommand.h │ │ ├── GeoUtils.cpp │ │ └── GeoUtils.h │ │ ├── level │ │ └── LevelCommand.h │ │ └── macro │ │ └── MacroPresets.h ├── main.cpp ├── n64 │ ├── Cartridge.cpp │ ├── Cartridge.h │ ├── CommandMacros.h │ ├── gbi-otr.h │ └── types.h ├── preprocess │ ├── CompTool.cpp │ └── CompTool.h ├── types │ ├── RawBuffer.h │ ├── SegmentedAddr.h │ ├── Vec3D.cpp │ └── Vec3D.h └── utils │ ├── Decompressor.cpp │ ├── Decompressor.h │ ├── StringHelper.cpp │ ├── StringHelper.h │ ├── TextureUtils.cpp │ ├── TextureUtils.h │ ├── TorchUtils.cpp │ └── TorchUtils.h └── test ├── config.yml ├── mk64 └── audio │ └── root.yml ├── sf64 ├── jp │ └── ast_audio.yaml └── us │ ├── ast_bank.yaml │ └── ast_tables.yaml ├── sm64 ├── jp │ └── root.yml └── us │ └── root.yml └── torch.hash.yml /.github/workflows/linux_build.yml: -------------------------------------------------------------------------------- 1 | name: Linux Compile 2 | 3 | on: 4 | push: 5 | branches: [ "*" ] 6 | pull_request: 7 | branches: [ "master" ] 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v4 14 | - name: Install dependencies 15 | run: sudo apt-get install cmake ninja-build libbz2-dev 16 | - name: Build 17 | run: | 18 | cmake -H. -Bbuild-cmake -GNinja -DCMAKE_BUILD_TYPE=Release 19 | cmake --build build-cmake -j 20 | - name: Create Package 21 | run: | 22 | mkdir torch-release 23 | mv build-cmake/torch torch-release/ 24 | cp "$(ldconfig -p | grep libbz2.so.1.0 | tr ' ' '\n' | grep /| head -n1)" torch-release/ 25 | - name: Publish packaged artifacts 26 | uses: actions/upload-artifact@v4 27 | with: 28 | name: torch-linux-x64 29 | path: torch-release -------------------------------------------------------------------------------- /.github/workflows/mac_build.yml: -------------------------------------------------------------------------------- 1 | name: Macos Compile 2 | 3 | on: 4 | push: 5 | branches: [ "*" ] 6 | pull_request: 7 | branches: [ "master" ] 8 | 9 | jobs: 10 | build: 11 | runs-on: macOS-latest 12 | steps: 13 | - uses: actions/checkout@v4 14 | - name: Install dependencies 15 | run: brew install cmake ninja xcodes 16 | - name: Build 17 | run: | 18 | cmake -H. -Bbuild-cmake -GNinja -DCMAKE_BUILD_TYPE=Release 19 | cmake --build build-cmake -j 20 | - name: Create Package 21 | run: | 22 | mkdir torch-release 23 | mv build-cmake/torch torch-release/ 24 | - name: Publish packaged artifacts 25 | uses: actions/upload-artifact@v4 26 | with: 27 | name: torch-mac-bin 28 | path: torch-release 29 | -------------------------------------------------------------------------------- /.github/workflows/windows_build.yml: -------------------------------------------------------------------------------- 1 | name: Windows Compile 2 | 3 | on: 4 | push: 5 | branches: [ "*" ] 6 | pull_request: 7 | branches: [ "master" ] 8 | 9 | jobs: 10 | build: 11 | runs-on: windows-2022 12 | steps: 13 | - uses: actions/checkout@v4 14 | - name: Build 15 | run: | 16 | cmake -S . -B "build/x64" -G "Visual Studio 17 2022" -T v142 -A x64 -DCMAKE_BUILD_TYPE:STRING=Release 17 | cmake --build ./build/x64 18 | - name: Publish packaged artifacts 19 | uses: actions/upload-artifact@v4 20 | with: 21 | name: torch-windows-x64 22 | path: build/x64/Debug/torch.exe -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | build-*/ 3 | cmake-build-*/ 4 | *.otr 5 | *.log 6 | .DS_Store 7 | debug/ 8 | !src/factories/debug/ 9 | *.z64 10 | *.n64 11 | *.inc.c 12 | headers/ 13 | build/ 14 | code/ 15 | .vscode/ 16 | tools/ 17 | modding/* -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Lywx admin@undervolt.dev 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /TemplateFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | // namespace GAME { 6 | 7 | class TypeData : public IParsedData { 8 | public: 9 | uint32_t mData; 10 | 11 | explicit TypeData(uint32_t data) {} 12 | }; 13 | 14 | class TypeHeaderExporter : public BaseExporter { 15 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 16 | }; 17 | 18 | class TypeBinaryExporter : public BaseExporter { 19 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 20 | }; 21 | 22 | class TypeCodeExporter : public BaseExporter { 23 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 24 | }; 25 | 26 | class TypeFactory : public BaseFactory { 27 | public: 28 | std::optional> parse(std::vector& buffer, YAML::Node& data) override; 29 | inline std::unordered_map> GetExporters() override { 30 | return { 31 | REGISTER(Code, TypeCodeExporter) 32 | REGISTER(Header, TypeHeaderExporter) 33 | REGISTER(Binary, TypeBinaryExporter) 34 | }; 35 | } 36 | }; 37 | // } 38 | -------------------------------------------------------------------------------- /assets/example/demo.yml: -------------------------------------------------------------------------------- 1 | hud/health: 2 | type: TEXTURE 3 | size: 512 4 | width: 16 5 | height: 16 6 | offset: 0xFF 7 | format: RGBA16 8 | symbol: health_icon_FF -------------------------------------------------------------------------------- /config.yml: -------------------------------------------------------------------------------- 1 | # This is a sample configuration file to use on Torch. 2 | # You can find more information about the configuration file on the wiki (WIP) 3 | 4 | N64Hash: 5 | name: Game # The name of the game; you can use any name you want. 6 | path: assets/example/ # The path to the ymls folder 7 | config: 8 | gbi: F3D # You can use F3D, F3DEX, F3DEX-MK64, F3DB, F3DEX2, F3DEXB, 9 | sort: OFFSET # This is how the assets are going to be sorted when generating the Header / C files. You can use OFFSET, ROFFSET for a reverse order or even specify a manual order using a list with the types. 10 | output: 11 | binary: example.otr # The name of the output binary file 12 | headers: include # The name of the output headers folder 13 | code: code # The name of the output code folder 14 | segments: # A list with all the segmented addresses in order 15 | - 0x12345678 -------------------------------------------------------------------------------- /lib/StormLib/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | net.zezula.${PRODUCT_NAME:rfc1034Identifier} 11 | CFBundleName 12 | ${PRODUCT_NAME} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 8.01 21 | 22 | 23 | -------------------------------------------------------------------------------- /lib/StormLib/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 1999-2013 Ladislav Zezula 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /lib/StormLib/Publish.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | rem This BAT file updates the ZIP file that is to be uploaded to web 3 | rem Only use when both 32-bit and 64-bit are properly compiled 4 | 5 | set STORMLIB_NAME=stormlib-9.00 6 | 7 | echo Creating %STORMLIB_NAME%.zip ... 8 | cd \Ladik\Appdir 9 | zip.exe -ur9 ..\WWW\web\download\%STORMLIB_NAME%.zip StormLib\doc\* 10 | zip.exe -ur9 ..\WWW\web\download\%STORMLIB_NAME%.zip StormLib\src\* 11 | zip.exe -ur9 ..\WWW\web\download\%STORMLIB_NAME%.zip StormLib\storm_dll\* 12 | zip.exe -ur9 ..\WWW\web\download\%STORMLIB_NAME%.zip StormLib\StormLib.xcodeproj\* 13 | zip.exe -ur9 ..\WWW\web\download\%STORMLIB_NAME%.zip StormLib\stormlib_dll\* 14 | zip.exe -ur9 ..\WWW\web\download\%STORMLIB_NAME%.zip StormLib\test\* 15 | zip.exe -u9 ..\WWW\web\download\%STORMLIB_NAME%.zip StormLib\CMakeLists.txt 16 | zip.exe -u9 ..\WWW\web\download\%STORMLIB_NAME%.zip StormLib\makefile.* 17 | zip.exe -u9 ..\WWW\web\download\%STORMLIB_NAME%.zip StormLib\Info.plist 18 | zip.exe -u9 ..\WWW\web\download\%STORMLIB_NAME%.zip StormLib\*.bat 19 | zip.exe -u9 ..\WWW\web\download\%STORMLIB_NAME%.zip StormLib\*.sln 20 | zip.exe -u9 ..\WWW\web\download\%STORMLIB_NAME%.zip StormLib\*.vcproj 21 | zip.exe -u9 ..\WWW\web\download\%STORMLIB_NAME%.zip StormLib\*.vcxproj 22 | echo. 23 | 24 | echo Press any key to exit ... 25 | pause >nul 26 | -------------------------------------------------------------------------------- /lib/StormLib/README.md: -------------------------------------------------------------------------------- 1 | # StormLib 2 | 3 | This is official repository for the StomLib library, an open-source project that can work with Blizzard MPQ archives. 4 | 5 | ## Installation and basic usage 6 | ### Linux 7 | 1. Download latest release 8 | 2. Install StormLib: 9 | ``` 10 | $ cd 11 | $ cmake CMakeLists.txt 12 | $ make 13 | $ make install 14 | ``` 15 | 3. Include StormLib in your project: `#include ` 16 | 4. Make sure you compile your project with `-lstorm -lz -lbz2` 17 | 18 | ### Windows (Visual Studio 2008) 19 | 1. Download the latest release of StormLib 20 | 2. Open the solution file `StormLib_vs08.sln` in Visual Studio 2008 21 | 3. Choose "Build / Batch Build" and select every build of "StormLib" 22 | 4. Choose "Rebuild" 23 | 5. The result libraries are in `.\bin\Win32` and `.\bin\x64` 24 | 25 | ### Windows (Visual Studio 2017 or 2019) 26 | 0. Make sure you have SDK 10.0.17134.0 installed 27 | 1. Download the latest release of StormLib 28 | 2. Open the solution file `StormLib_vs19.sln` in Visual Studio 2017/2019 29 | 3. Choose "Build / Batch Build" and select every build of "StormLib" 30 | 4. Choose "Rebuild" 31 | 5. The result libraries are in `.\bin\Win32` and `.\bin\x64` 32 | 33 | ### Windows (Test Project) 34 | 1. Include the main StormLib header: `#include ` 35 | 2. Set the correct library directory for StormLibXYZ.lib: 36 | * X: D = Debug, R = Release 37 | * Y: A = ANSI build, U = Unicode build 38 | * Z: S = Using static CRT library, D = Using Dynamic CRT library 39 | 3. Rebuild 40 | -------------------------------------------------------------------------------- /lib/StormLib/StormLib.kdev4: -------------------------------------------------------------------------------- 1 | [Project] 2 | Manager=KDevCMakeManager 3 | Name=StormLib 4 | -------------------------------------------------------------------------------- /lib/StormLib/doc/d3-authenticationcode/d3-authenticationcode-deDE.txt: -------------------------------------------------------------------------------- 1 | UCMXF6EJY352EFH4XFRXCFH2XC9MQRZK -------------------------------------------------------------------------------- /lib/StormLib/doc/d3-authenticationcode/d3-authenticationcode-enGB.txt: -------------------------------------------------------------------------------- 1 | MMKVHY48RP7WXP4GHYBQ7SL9J9UNPHBP -------------------------------------------------------------------------------- /lib/StormLib/doc/d3-authenticationcode/d3-authenticationcode-enSG.txt: -------------------------------------------------------------------------------- 1 | 8MXLWHQ7VGGLTZ9MQZQSFDCLJYET3CPP -------------------------------------------------------------------------------- /lib/StormLib/doc/d3-authenticationcode/d3-authenticationcode-enUS.txt: -------------------------------------------------------------------------------- 1 | EJ2R5TM6XFE2GUNG5QDGHKQ9UAKPWZSZ -------------------------------------------------------------------------------- /lib/StormLib/doc/d3-authenticationcode/d3-authenticationcode-esES.txt: -------------------------------------------------------------------------------- 1 | PBGFBE42Z6LNK65UGJQ3WZVMCLP4HQQT -------------------------------------------------------------------------------- /lib/StormLib/doc/d3-authenticationcode/d3-authenticationcode-esMX.txt: -------------------------------------------------------------------------------- 1 | X7SEJJS9TSGCW5P28EBSC47AJPEY8VU2 -------------------------------------------------------------------------------- /lib/StormLib/doc/d3-authenticationcode/d3-authenticationcode-frFR.txt: -------------------------------------------------------------------------------- 1 | 5KVBQA8VYE6XRY3DLGC5ZDE4XS4P7YA2 -------------------------------------------------------------------------------- /lib/StormLib/doc/d3-authenticationcode/d3-authenticationcode-itIT.txt: -------------------------------------------------------------------------------- 1 | 478JD2K56EVNVVY4XX8TDWYT5B8KB254 -------------------------------------------------------------------------------- /lib/StormLib/doc/d3-authenticationcode/d3-authenticationcode-koKR.txt: -------------------------------------------------------------------------------- 1 | 8TS4VNFQRZTN6YWHE9CHVDH9NVWD474A -------------------------------------------------------------------------------- /lib/StormLib/doc/d3-authenticationcode/d3-authenticationcode-plPL.txt: -------------------------------------------------------------------------------- 1 | LJ52Z32DF4LZ4ZJJXVKK3AZQA6GABLJB -------------------------------------------------------------------------------- /lib/StormLib/doc/d3-authenticationcode/d3-authenticationcode-ptBR.txt: -------------------------------------------------------------------------------- 1 | K6BDHY2ECUE2545YKNLBJPVYWHE7XYAG -------------------------------------------------------------------------------- /lib/StormLib/doc/d3-authenticationcode/d3-authenticationcode-zhTW.txt: -------------------------------------------------------------------------------- 1 | 6VWCQTN8V3ZZMRUCZXV8A8CGUX2TAA8H -------------------------------------------------------------------------------- /lib/StormLib/doc/hots-authenticationcode/hots-authenticationcode-bgdl.txt: -------------------------------------------------------------------------------- 1 | S48B6CDTN5XEQAKQDJNDLJBJ73FDFM3U -------------------------------------------------------------------------------- /lib/StormLib/doc/sc2-authenticationcode/sc2-authenticationcode-deDE.txt: -------------------------------------------------------------------------------- 1 | Y45MD3CAK4KXSSXHYD9VY64Z8EKJ4XFX -------------------------------------------------------------------------------- /lib/StormLib/doc/sc2-authenticationcode/sc2-authenticationcode-enGB.txt: -------------------------------------------------------------------------------- 1 | G8MN8UDG6NA2ANGY6A3DNY82HRGF29ZH -------------------------------------------------------------------------------- /lib/StormLib/doc/sc2-authenticationcode/sc2-authenticationcode-enUS.txt: -------------------------------------------------------------------------------- 1 | 3DH5RE5NVM5GTFD85LXGWT6FK859ETR5 -------------------------------------------------------------------------------- /lib/StormLib/doc/sc2-authenticationcode/sc2-authenticationcode-esES.txt: -------------------------------------------------------------------------------- 1 | 8WLKUAXE94PFQU4Y249PAZ24N4R4XKTQ -------------------------------------------------------------------------------- /lib/StormLib/doc/sc2-authenticationcode/sc2-authenticationcode-esMX.txt: -------------------------------------------------------------------------------- 1 | A34DXX3VHGGXSQBRFE5UFFDXMF9G4G54 -------------------------------------------------------------------------------- /lib/StormLib/doc/sc2-authenticationcode/sc2-authenticationcode-frFR.txt: -------------------------------------------------------------------------------- 1 | ZG7J9K938HJEFWPQUA768MA2PFER6EAJ -------------------------------------------------------------------------------- /lib/StormLib/doc/sc2-authenticationcode/sc2-authenticationcode-itIT.txt: -------------------------------------------------------------------------------- 1 | NE7CUNNNTVAPXV7E3G2BSVBWGVMW8BL2 -------------------------------------------------------------------------------- /lib/StormLib/doc/sc2-authenticationcode/sc2-authenticationcode-koKR.txt: -------------------------------------------------------------------------------- 1 | 3V9E2FTMBM9QQWK7U6MAMWAZWQDB838F -------------------------------------------------------------------------------- /lib/StormLib/doc/sc2-authenticationcode/sc2-authenticationcode-plPL.txt: -------------------------------------------------------------------------------- 1 | 2NSFB8MELULJ83U6YHA3UP6K4MQD48L6 -------------------------------------------------------------------------------- /lib/StormLib/doc/sc2-authenticationcode/sc2-authenticationcode-ptBR.txt: -------------------------------------------------------------------------------- 1 | QA2TZ9EWZ4CUU8BMB5WXCTY65F9CSW4E -------------------------------------------------------------------------------- /lib/StormLib/doc/sc2-authenticationcode/sc2-authenticationcode-ruRU.txt: -------------------------------------------------------------------------------- 1 | VHB378W64BAT9SH7D68VV9NLQDK9YEGT -------------------------------------------------------------------------------- /lib/StormLib/doc/sc2-authenticationcode/sc2-authenticationcode-zhTW.txt: -------------------------------------------------------------------------------- 1 | U3NFQJV4M6GC7KBN9XQJ3BRDN3PLD9NE -------------------------------------------------------------------------------- /lib/StormLib/make.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | if not "x%WDKDIR%" == "x" goto SELECT_LIB 3 | echo The WDKDIR environment variable is not set 4 | echo Set this variable to your WDK directory (without ending backslash) 5 | echo Example: set WDKDIR C:\WinDDK\6001 6 | pause 7 | goto:eof 8 | 9 | :SELECT_LIB 10 | set PROJECT_DIR=%~dp0 11 | set LIBRARY_NAME=StormLibWDK 12 | 13 | :PREPARE_SOURCES 14 | echo Preparing sources ... 15 | copy .\src\wdk\sources-cpp.cpp . >nul 16 | copy .\src\wdk\sources-wdk-* . >nul 17 | echo. 18 | 19 | :BUILD_LIB_32 20 | echo Building %LIBRARY_NAME%.lib (32-bit) ... 21 | set DDKBUILDENV= 22 | call %WDKDIR%\bin\setenv.bat %WDKDIR%\ fre w2k 23 | cd %PROJECT_DIR% 24 | build.exe -czgw 25 | del buildfre_w2k_x86.log 26 | echo. 27 | 28 | :BUILD_LIB_64 29 | echo Building %LIBRARY_NAME%.lib (64-bit) ... 30 | set DDKBUILDENV= 31 | call %WDKDIR%\bin\setenv.bat %WDKDIR%\ fre x64 WLH 32 | cd %PROJECT_DIR% 33 | build.exe -czgw 34 | del buildfre_wlh_amd64.log 35 | echo. 36 | 37 | :COPY_LIBS 38 | xcopy /Y /D .\src\StormLib.h ..\aaa\inc >nul 39 | xcopy /Y /D .\src\StormPort.h ..\aaa\inc >nul 40 | xcopy /Y /D .\objfre_w2k_x86\i386\%LIBRARY_NAME%.lib ..\aaa\lib32\%LIBRARY_NAME%.lib >nul 41 | xcopy /Y /D .\objfre_wlh_amd64\amd64\%LIBRARY_NAME%.lib ..\aaa\lib64\%LIBRARY_NAME%.lib >nul 42 | 43 | :CLEANUP 44 | if exist sources-cpp.cpp del sources-cpp.cpp 45 | if exist sources-wdk-* del sources-wdk-* 46 | if exist build.bat del build.bat 47 | -------------------------------------------------------------------------------- /lib/StormLib/sources: -------------------------------------------------------------------------------- 1 | TARGETNAME=StormLibWDK 2 | TARGETTYPE=LIBRARY 3 | USE_MSVCRT=1 4 | 5 | C_DEFINES=$(C_DEFINES) -DUNICODE -D_UNICODE -DWDK_BUILD 6 | 7 | SOURCES=sources-cpp.cpp \ 8 | sources-wdk-bzip2.c \ 9 | sources-wdk-ltc.c \ 10 | sources-wdk-lzma.c \ 11 | sources-wdk-misc.c \ 12 | sources-wdk-tomcrypt.c \ 13 | sources-wdk-tommath.c \ 14 | sources-wdk-zlib.c 15 | -------------------------------------------------------------------------------- /lib/StormLib/src/DllMain.c: -------------------------------------------------------------------------------- 1 | /*****************************************************************************/ 2 | /* DllMain.c Copyright (c) Ladislav Zezula 2006 */ 3 | /*---------------------------------------------------------------------------*/ 4 | /* Description: DllMain for the StormLib.dll library */ 5 | /*---------------------------------------------------------------------------*/ 6 | /* Date Ver Who Comment */ 7 | /* -------- ---- --- ------- */ 8 | /* 23.11.06 1.00 Lad The first version of DllMain.c */ 9 | /*****************************************************************************/ 10 | 11 | #define WIN32_LEAN_AND_MEAN 12 | #include 13 | 14 | //----------------------------------------------------------------------------- 15 | // DllMain 16 | 17 | BOOL WINAPI DllMain(HINSTANCE hInst, DWORD dwReason, LPVOID lpReserved) 18 | { 19 | UNREFERENCED_PARAMETER(hInst); 20 | UNREFERENCED_PARAMETER(dwReason); 21 | UNREFERENCED_PARAMETER(lpReserved); 22 | 23 | return TRUE; 24 | } 25 | -------------------------------------------------------------------------------- /lib/StormLib/src/DllMain.def: -------------------------------------------------------------------------------- 1 | ; 2 | ; Export file for Windows 3 | ; Copyright (c) 2007-2010 Ladislav Zezula 4 | ; ladik@zezula.net 5 | ; 6 | 7 | LIBRARY StormLib.dll 8 | 9 | EXPORTS 10 | 11 | SFileSetLocale 12 | SFileGetLocale 13 | 14 | SFileOpenArchive 15 | SFileCreateArchive 16 | SFileCreateArchive2 17 | SFileFlushArchive 18 | SFileCloseArchive 19 | 20 | SFileAddListFile 21 | 22 | SFileSetCompactCallback 23 | SFileCompactArchive 24 | 25 | SFileGetMaxFileCount 26 | SFileSetMaxFileCount 27 | 28 | SFileGetAttributes 29 | SFileSetAttributes 30 | SFileUpdateFileAttributes 31 | 32 | SFileOpenPatchArchive 33 | SFileIsPatchedArchive 34 | 35 | SFileOpenFileEx 36 | SFileGetFileSize 37 | SFileSetFilePointer 38 | SFileReadFile 39 | SFileCloseFile 40 | 41 | SFileHasFile 42 | SFileGetFileName 43 | SFileGetFileInfo 44 | 45 | SFileExtractFile 46 | 47 | SFileVerifyFile 48 | SFileVerifyRawData 49 | SFileVerifyArchive 50 | 51 | SFileFindFirstFile 52 | SFileFindNextFile 53 | SFileFindClose 54 | 55 | SListFileFindFirstFile 56 | SListFileFindNextFile 57 | SListFileFindClose 58 | 59 | SFileEnumLocales 60 | 61 | SFileCreateFile 62 | SFileWriteFile 63 | SFileFinishFile 64 | SFileAddFileEx 65 | SFileAddFile 66 | SFileAddWave 67 | SFileRemoveFile 68 | SFileRenameFile 69 | SFileSetFileLocale 70 | SFileSetDataCompression 71 | SFileSetAddFileCallback 72 | 73 | SCompImplode 74 | SCompExplode 75 | SCompCompress 76 | SCompDecompress 77 | 78 | GetLastError=Kernel32.GetLastError 79 | SetLastError=Kernel32.SetLastError 80 | -------------------------------------------------------------------------------- /lib/StormLib/src/StormLib.exp: -------------------------------------------------------------------------------- 1 | # 2 | # Export file for Mac OS X 3 | # Copyright (c) 2009 Sam Wilkins 4 | # swilkins1337@gmail.com 5 | # 6 | 7 | _SFileSetLocale 8 | _SFileGetLocale 9 | 10 | _SFileOpenArchive 11 | _SFileCreateArchive 12 | _SFileFlushArchive 13 | _SFileCloseArchive 14 | 15 | _SFileAddListFile 16 | 17 | _SFileSetCompactCallback 18 | _SFileCompactArchive 19 | 20 | _SFileGetMaxFileCount 21 | _SFileSetMaxFileCount 22 | 23 | _SFileGetAttributes 24 | _SFileSetAttributes 25 | _SFileUpdateFileAttributes 26 | 27 | _SFileOpenPatchArchive 28 | _SFileIsPatchedArchive 29 | 30 | _SFileOpenFileEx 31 | _SFileGetFileSize 32 | _SFileSetFilePointer 33 | _SFileReadFile 34 | _SFileCloseFile 35 | 36 | _SFileHasFile 37 | _SFileGetFileName 38 | _SFileGetFileInfo 39 | 40 | _SFileExtractFile 41 | 42 | _SFileVerifyFile 43 | _SFileVerifyRawData 44 | _SFileVerifyArchive 45 | 46 | _SFileFindFirstFile 47 | _SFileFindNextFile 48 | _SFileFindClose 49 | 50 | _SListFileFindFirstFile 51 | _SListFileFindNextFile 52 | _SListFileFindClose 53 | 54 | _SFileEnumLocales 55 | 56 | _SFileCreateFile 57 | _SFileWriteFile 58 | _SFileFinishFile 59 | _SFileAddFileEx 60 | _SFileAddFile 61 | _SFileAddWave 62 | _SFileRemoveFile 63 | _SFileRenameFile 64 | _SFileSetFileLocale 65 | _SFileSetDataCompression 66 | _SFileSetAddFileCallback 67 | 68 | _SCompImplode 69 | _SCompExplode 70 | _SCompCompress 71 | _SCompDecompress 72 | 73 | _SetLastError 74 | _GetLastError 75 | -------------------------------------------------------------------------------- /lib/StormLib/src/adpcm/adpcm.h: -------------------------------------------------------------------------------- 1 | /*****************************************************************************/ 2 | /* adpcm.h Copyright (c) Ladislav Zezula 2003 */ 3 | /*---------------------------------------------------------------------------*/ 4 | /* Header file for adpcm decompress functions */ 5 | /*---------------------------------------------------------------------------*/ 6 | /* Date Ver Who Comment */ 7 | /* -------- ---- --- ------- */ 8 | /* 31.03.03 1.00 Lad The first version of adpcm.h */ 9 | /*****************************************************************************/ 10 | 11 | #ifndef __ADPCM_H__ 12 | #define __ADPCM_H__ 13 | 14 | //----------------------------------------------------------------------------- 15 | // Defines 16 | 17 | #define MAX_ADPCM_CHANNEL_COUNT 2 18 | #define INITIAL_ADPCM_STEP_INDEX 0x2C 19 | 20 | //----------------------------------------------------------------------------- 21 | // Public functions 22 | 23 | int CompressADPCM (void * pvOutBuffer, int dwOutLength, void * pvInBuffer, int dwInLength, int nCmpType, int ChannelCount); 24 | int DecompressADPCM (void * pvOutBuffer, int dwOutLength, void * pvInBuffer, int dwInLength, int ChannelCount); 25 | int DecompressADPCM_SC1B(void * pvOutBuffer, int cbOutBuffer, void * pvInBuffer, int cbInBuffer, int ChannelCount); 26 | 27 | #endif // __ADPCM_H__ 28 | -------------------------------------------------------------------------------- /lib/StormLib/src/jenkins/lookup.h: -------------------------------------------------------------------------------- 1 | #ifndef __LOOKUP3_H__ 2 | #define __LOOKUP3_H__ 3 | 4 | #ifdef WIN32 5 | typedef unsigned char uint8_t; 6 | typedef unsigned short uint16_t; 7 | typedef unsigned int uint32_t; 8 | #else 9 | #include /* defines uint32_t etc */ 10 | #endif 11 | 12 | #ifdef __cplusplus 13 | extern "C" 14 | { 15 | #endif 16 | 17 | uint32_t hashlittle(const void *key, size_t length, uint32_t initval); 18 | void hashlittle2(const void *key, size_t length, uint32_t *pc, uint32_t *pb); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | #endif // __LOOKUP3_H__ 25 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtomcrypt/src/headers/tomcrypt_argchk.h: -------------------------------------------------------------------------------- 1 | /* Defines the LTC_ARGCHK macro used within the library */ 2 | /* ARGTYPE is defined in mycrypt_cfg.h */ 3 | #if ARGTYPE == 0 4 | 5 | #include 6 | 7 | /* this is the default LibTomCrypt macro */ 8 | void crypt_argchk(char *v, char *s, int d); 9 | #define LTC_ARGCHK(x) if (!(x)) { crypt_argchk(#x, __FILE__, __LINE__); } 10 | #define LTC_ARGCHKVD(x) LTC_ARGCHK(x) 11 | 12 | #elif ARGTYPE == 1 13 | 14 | /* fatal type of error */ 15 | #define LTC_ARGCHK(x) assert((x)) 16 | #define LTC_ARGCHKVD(x) LTC_ARGCHK(x) 17 | 18 | #elif ARGTYPE == 2 19 | 20 | #define LTC_ARGCHK(x) if (!(x)) { fprintf(stderr, "\nwarning: ARGCHK failed at %s:%d\n", __FILE__, __LINE__); } 21 | #define LTC_ARGCHKVD(x) LTC_ARGCHK(x) 22 | 23 | #elif ARGTYPE == 3 24 | 25 | #define LTC_ARGCHK(x) 26 | #define LTC_ARGCHKVD(x) LTC_ARGCHK(x) 27 | 28 | #elif ARGTYPE == 4 29 | 30 | #define LTC_ARGCHK(x) if (!(x)) return CRYPT_INVALID_ARG; 31 | #define LTC_ARGCHKVD(x) if (!(x)) return; 32 | 33 | #endif 34 | 35 | 36 | /* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_argchk.h,v $ */ 37 | /* $Revision: 1.5 $ */ 38 | /* $Date: 2006/08/27 20:50:21 $ */ 39 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtomcrypt/src/headers/tomcrypt_misc.h: -------------------------------------------------------------------------------- 1 | /* ---- LTC_BASE64 Routines ---- */ 2 | #ifdef LTC_BASE64 3 | int base64_encode(const unsigned char *in, unsigned long len, 4 | unsigned char *out, unsigned long *outlen); 5 | 6 | int base64_decode(const unsigned char *in, unsigned long len, 7 | unsigned char *out, unsigned long *outlen); 8 | #endif 9 | 10 | /* ---- MEM routines ---- */ 11 | void zeromem(void *dst, size_t len); 12 | void burn_stack(unsigned long len); 13 | 14 | const char *error_to_string(int err); 15 | 16 | extern const char *crypt_build_settings; 17 | 18 | /* ---- HMM ---- */ 19 | int crypt_fsa(void *mp, ...); 20 | 21 | /* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_misc.h,v $ */ 22 | /* $Revision: 1.5 $ */ 23 | /* $Date: 2007/05/12 14:32:35 $ */ 24 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtomcrypt/src/math/multi.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "../headers/tomcrypt.h" 12 | 13 | #ifdef MPI 14 | #include 15 | 16 | int ltc_init_multi(void **a, ...) 17 | { 18 | void **cur = a; 19 | int np = 0; 20 | va_list args; 21 | 22 | va_start(args, a); 23 | while (cur != NULL) { 24 | if (mp_init(cur) != CRYPT_OK) { 25 | /* failed */ 26 | va_list clean_list; 27 | 28 | va_start(clean_list, a); 29 | cur = a; 30 | while (np--) { 31 | mp_clear(*cur); 32 | cur = va_arg(clean_list, void**); 33 | } 34 | va_end(clean_list); 35 | return CRYPT_MEM; 36 | } 37 | ++np; 38 | cur = va_arg(args, void**); 39 | } 40 | va_end(args); 41 | return CRYPT_OK; 42 | } 43 | 44 | void ltc_deinit_multi(void *a, ...) 45 | { 46 | void *cur = a; 47 | va_list args; 48 | 49 | va_start(args, a); 50 | while (cur != NULL) { 51 | mp_clear(cur); 52 | cur = va_arg(args, void *); 53 | } 54 | va_end(args); 55 | } 56 | 57 | #endif 58 | 59 | /* $Source: /cvs/libtom/libtomcrypt/src/math/multi.c,v $ */ 60 | /* $Revision: 1.6 $ */ 61 | /* $Date: 2006/12/28 01:27:23 $ */ 62 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtomcrypt/src/misc/crypt_argchk.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "../headers/tomcrypt.h" 12 | #include 13 | 14 | /** 15 | @file crypt_argchk.c 16 | Perform argument checking, Tom St Denis 17 | */ 18 | 19 | #if (ARGTYPE == 0) 20 | void crypt_argchk(char *v, char *s, int d) 21 | { 22 | fprintf(stderr, "LTC_ARGCHK '%s' failure on line %d of file %s\n", 23 | v, d, s); 24 | (void)raise(SIGABRT); 25 | } 26 | #endif 27 | 28 | /* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_argchk.c,v $ */ 29 | /* $Revision: 1.5 $ */ 30 | /* $Date: 2006/12/28 01:27:24 $ */ 31 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtomcrypt/src/misc/crypt_find_hash.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "../headers/tomcrypt.h" 12 | 13 | /** 14 | @file crypt_find_hash.c 15 | Find a hash, Tom St Denis 16 | */ 17 | 18 | /** 19 | Find a registered hash by name 20 | @param name The name of the hash to look for 21 | @return >= 0 if found, -1 if not present 22 | */ 23 | int find_hash(const char *name) 24 | { 25 | int x; 26 | LTC_ARGCHK(name != NULL); 27 | LTC_MUTEX_LOCK(<c_hash_mutex); 28 | for (x = 0; x < TAB_SIZE; x++) { 29 | if (hash_descriptor[x].name != NULL && XSTRCMP(hash_descriptor[x].name, name) == 0) { 30 | LTC_MUTEX_UNLOCK(<c_hash_mutex); 31 | return x; 32 | } 33 | } 34 | LTC_MUTEX_UNLOCK(<c_hash_mutex); 35 | return -1; 36 | } 37 | 38 | /* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_find_hash.c,v $ */ 39 | /* $Revision: 1.7 $ */ 40 | /* $Date: 2006/12/28 01:27:24 $ */ 41 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtomcrypt/src/misc/crypt_find_prng.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "../headers/tomcrypt.h" 12 | 13 | /** 14 | @file crypt_find_prng.c 15 | Find a PRNG, Tom St Denis 16 | */ 17 | 18 | /** 19 | Find a registered PRNG by name 20 | @param name The name of the PRNG to look for 21 | @return >= 0 if found, -1 if not present 22 | */ 23 | int find_prng(const char *name) 24 | { 25 | int x; 26 | LTC_ARGCHK(name != NULL); 27 | LTC_MUTEX_LOCK(<c_prng_mutex); 28 | for (x = 0; x < TAB_SIZE; x++) { 29 | if ((prng_descriptor[x].name != NULL) && XSTRCMP(prng_descriptor[x].name, name) == 0) { 30 | LTC_MUTEX_UNLOCK(<c_prng_mutex); 31 | return x; 32 | } 33 | } 34 | LTC_MUTEX_UNLOCK(<c_prng_mutex); 35 | return -1; 36 | } 37 | 38 | 39 | /* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_find_prng.c,v $ */ 40 | /* $Revision: 1.7 $ */ 41 | /* $Date: 2006/12/28 01:27:24 $ */ 42 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtomcrypt/src/misc/crypt_hash_descriptor.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "../headers/tomcrypt.h" 12 | 13 | /** 14 | @file crypt_hash_descriptor.c 15 | Stores the hash descriptor table, Tom St Denis 16 | */ 17 | 18 | struct ltc_hash_descriptor hash_descriptor[TAB_SIZE] = { 19 | { NULL, 0, 0, 0, { 0 }, 0, NULL, NULL, NULL, NULL, NULL } 20 | }; 21 | 22 | LTC_MUTEX_GLOBAL(ltc_hash_mutex) 23 | 24 | 25 | /* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_hash_descriptor.c,v $ */ 26 | /* $Revision: 1.10 $ */ 27 | /* $Date: 2006/12/28 01:27:24 $ */ 28 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtomcrypt/src/misc/crypt_hash_is_valid.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "../headers/tomcrypt.h" 12 | 13 | /** 14 | @file crypt_hash_is_valid.c 15 | Determine if hash is valid, Tom St Denis 16 | */ 17 | 18 | /* 19 | Test if a hash index is valid 20 | @param idx The index of the hash to search for 21 | @return CRYPT_OK if valid 22 | */ 23 | int hash_is_valid(int idx) 24 | { 25 | LTC_MUTEX_LOCK(<c_hash_mutex); 26 | if (idx < 0 || idx >= TAB_SIZE || hash_descriptor[idx].name == NULL) { 27 | LTC_MUTEX_UNLOCK(<c_hash_mutex); 28 | return CRYPT_INVALID_HASH; 29 | } 30 | LTC_MUTEX_UNLOCK(<c_hash_mutex); 31 | return CRYPT_OK; 32 | } 33 | 34 | /* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_hash_is_valid.c,v $ */ 35 | /* $Revision: 1.6 $ */ 36 | /* $Date: 2006/12/28 01:27:24 $ */ 37 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtomcrypt/src/misc/crypt_libc.c: -------------------------------------------------------------------------------- 1 | /*****************************************************************************/ 2 | /* crypt_libc.c Copyright (c) Ladislav Zezula 2010 */ 3 | /*---------------------------------------------------------------------------*/ 4 | /* Description: */ 5 | /*---------------------------------------------------------------------------*/ 6 | /* Date Ver Who Comment */ 7 | /* -------- ---- --- ------- */ 8 | /* 05.05.10 1.00 Lad The first version of crypt_libc.c */ 9 | /*****************************************************************************/ 10 | 11 | // LibTomCrypt header 12 | #include 13 | #include "../headers/tomcrypt.h" 14 | 15 | LTC_EXPORT void * LTC_CALL LibTomMalloc(size_t n) 16 | { 17 | return malloc(n); 18 | } 19 | 20 | LTC_EXPORT void * LTC_CALL LibTomCalloc(size_t n, size_t s) 21 | { 22 | return calloc(n, s); 23 | } 24 | 25 | LTC_EXPORT void * LTC_CALL LibTomRealloc(void *p, size_t n) 26 | { 27 | return realloc(p, n); 28 | } 29 | 30 | LTC_EXPORT void LTC_CALL LibTomFree(void * p) 31 | { 32 | free(p); 33 | } 34 | 35 | LTC_EXPORT clock_t LTC_CALL LibTomClock(void) 36 | { 37 | return clock(); 38 | } 39 | 40 | LTC_EXPORT void LTC_CALL LibTomQsort(void *base, size_t nmemb, size_t size, int(LTC_CALL * compar)(const void *, const void *)) 41 | { 42 | qsort(base, nmemb, size, compar); 43 | } 44 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtomcrypt/src/misc/crypt_ltc_mp_descriptor.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "../headers/tomcrypt.h" 12 | 13 | ltc_math_descriptor ltc_mp = {0}; 14 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtomcrypt/src/misc/crypt_prng_descriptor.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "../headers/tomcrypt.h" 12 | 13 | /** 14 | @file crypt_prng_descriptor.c 15 | Stores the PRNG descriptors, Tom St Denis 16 | */ 17 | struct ltc_prng_descriptor prng_descriptor[TAB_SIZE] = { 18 | { NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL } 19 | }; 20 | 21 | LTC_MUTEX_GLOBAL(ltc_prng_mutex) 22 | 23 | 24 | /* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_prng_descriptor.c,v $ */ 25 | /* $Revision: 1.8 $ */ 26 | /* $Date: 2006/12/28 01:27:24 $ */ 27 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtomcrypt/src/misc/crypt_prng_is_valid.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "../headers/tomcrypt.h" 12 | 13 | /** 14 | @file crypt_prng_is_valid.c 15 | Determine if PRNG is valid, Tom St Denis 16 | */ 17 | 18 | /* 19 | Test if a PRNG index is valid 20 | @param idx The index of the PRNG to search for 21 | @return CRYPT_OK if valid 22 | */ 23 | int prng_is_valid(int idx) 24 | { 25 | LTC_MUTEX_LOCK(<c_prng_mutex); 26 | if (idx < 0 || idx >= TAB_SIZE || prng_descriptor[idx].name == NULL) { 27 | LTC_MUTEX_UNLOCK(<c_prng_mutex); 28 | return CRYPT_INVALID_PRNG; 29 | } 30 | LTC_MUTEX_UNLOCK(<c_prng_mutex); 31 | return CRYPT_OK; 32 | } 33 | 34 | /* $Source: /cvs/libtom/libtomcrypt/src/misc/crypt/crypt_prng_is_valid.c,v $ */ 35 | /* $Revision: 1.6 $ */ 36 | /* $Date: 2006/12/28 01:27:24 $ */ 37 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtomcrypt/src/misc/zeromem.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "../headers/tomcrypt.h" 12 | 13 | /** 14 | @file zeromem.c 15 | Zero a block of memory, Tom St Denis 16 | */ 17 | 18 | /** 19 | Zero a block of memory 20 | @param out The destination of the area to zero 21 | @param outlen The length of the area to zero (octets) 22 | */ 23 | void zeromem(void *out, size_t outlen) 24 | { 25 | unsigned char *mem = out; 26 | LTC_ARGCHKVD(out != NULL); 27 | while (outlen-- > 0) { 28 | *mem++ = 0; 29 | } 30 | } 31 | 32 | /* $Source: /cvs/libtom/libtomcrypt/src/misc/zeromem.c,v $ */ 33 | /* $Revision: 1.7 $ */ 34 | /* $Date: 2006/12/28 01:27:24 $ */ 35 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtomcrypt/src/pk/asn1/der_decode_boolean.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "../../headers/tomcrypt.h" 12 | 13 | /** 14 | @file der_decode_boolean.c 15 | ASN.1 DER, decode a BOOLEAN, Tom St Denis 16 | */ 17 | 18 | 19 | #ifdef LTC_DER 20 | 21 | /** 22 | Read a BOOLEAN 23 | @param in The destination for the DER encoded BOOLEAN 24 | @param inlen The size of the DER BOOLEAN 25 | @param out [out] The boolean to decode 26 | @return CRYPT_OK if successful 27 | */ 28 | int der_decode_boolean(const unsigned char *in, unsigned long inlen, 29 | int *out) 30 | { 31 | LTC_ARGCHK(in != NULL); 32 | LTC_ARGCHK(out != NULL); 33 | 34 | if (inlen != 3 || in[0] != 0x01 || in[1] != 0x01 || (in[2] != 0x00 && in[2] != 0xFF)) { 35 | return CRYPT_INVALID_ARG; 36 | } 37 | 38 | *out = (in[2]==0xFF) ? 1 : 0; 39 | 40 | return CRYPT_OK; 41 | } 42 | 43 | #endif 44 | 45 | /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/boolean/der_decode_boolean.c,v $ */ 46 | /* $Revision: 1.2 $ */ 47 | /* $Date: 2006/12/28 01:27:24 $ */ 48 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtomcrypt/src/pk/asn1/der_encode_boolean.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "../../headers/tomcrypt.h" 12 | 13 | /** 14 | @file der_encode_boolean.c 15 | ASN.1 DER, encode a BOOLEAN, Tom St Denis 16 | */ 17 | 18 | 19 | #ifdef LTC_DER 20 | 21 | /** 22 | Store a BOOLEAN 23 | @param in The boolean to encode 24 | @param out [out] The destination for the DER encoded BOOLEAN 25 | @param outlen [in/out] The max size and resulting size of the DER BOOLEAN 26 | @return CRYPT_OK if successful 27 | */ 28 | int der_encode_boolean(int in, 29 | unsigned char *out, unsigned long *outlen) 30 | { 31 | LTC_ARGCHK(outlen != NULL); 32 | LTC_ARGCHK(out != NULL); 33 | 34 | if (*outlen < 3) { 35 | *outlen = 3; 36 | return CRYPT_BUFFER_OVERFLOW; 37 | } 38 | 39 | *outlen = 3; 40 | out[0] = 0x01; 41 | out[1] = 0x01; 42 | out[2] = in ? 0xFF : 0x00; 43 | 44 | return CRYPT_OK; 45 | } 46 | 47 | #endif 48 | 49 | /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/boolean/der_encode_boolean.c,v $ */ 50 | /* $Revision: 1.4 $ */ 51 | /* $Date: 2006/12/28 01:27:24 $ */ 52 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtomcrypt/src/pk/asn1/der_length_bit_string.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "../../headers/tomcrypt.h" 12 | 13 | /** 14 | @file der_length_bit_string.c 15 | ASN.1 DER, get length of BIT STRING, Tom St Denis 16 | */ 17 | 18 | #ifdef LTC_DER 19 | /** 20 | Gets length of DER encoding of BIT STRING 21 | @param nbits The number of bits in the string to encode 22 | @param outlen [out] The length of the DER encoding for the given string 23 | @return CRYPT_OK if successful 24 | */ 25 | int der_length_bit_string(unsigned long nbits, unsigned long *outlen) 26 | { 27 | unsigned long nbytes; 28 | LTC_ARGCHK(outlen != NULL); 29 | 30 | /* get the number of the bytes */ 31 | nbytes = (nbits >> 3) + ((nbits & 7) ? 1 : 0) + 1; 32 | 33 | if (nbytes < 128) { 34 | /* 03 LL PP DD DD DD ... */ 35 | *outlen = 2 + nbytes; 36 | } else if (nbytes < 256) { 37 | /* 03 81 LL PP DD DD DD ... */ 38 | *outlen = 3 + nbytes; 39 | } else if (nbytes < 65536) { 40 | /* 03 82 LL LL PP DD DD DD ... */ 41 | *outlen = 4 + nbytes; 42 | } else { 43 | return CRYPT_INVALID_ARG; 44 | } 45 | 46 | return CRYPT_OK; 47 | } 48 | 49 | #endif 50 | 51 | 52 | /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/bit/der_length_bit_string.c,v $ */ 53 | /* $Revision: 1.3 $ */ 54 | /* $Date: 2006/12/28 01:27:24 $ */ 55 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtomcrypt/src/pk/asn1/der_length_boolean.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "../../headers/tomcrypt.h" 12 | 13 | /** 14 | @file der_length_boolean.c 15 | ASN.1 DER, get length of a BOOLEAN, Tom St Denis 16 | */ 17 | 18 | #ifdef LTC_DER 19 | /** 20 | Gets length of DER encoding of a BOOLEAN 21 | @param outlen [out] The length of the DER encoding 22 | @return CRYPT_OK if successful 23 | */ 24 | int der_length_boolean(unsigned long *outlen) 25 | { 26 | LTC_ARGCHK(outlen != NULL); 27 | *outlen = 3; 28 | return CRYPT_OK; 29 | } 30 | 31 | #endif 32 | 33 | /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/boolean/der_length_boolean.c,v $ */ 34 | /* $Revision: 1.3 $ */ 35 | /* $Date: 2006/12/28 01:27:24 $ */ 36 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtomcrypt/src/pk/asn1/der_length_octet_string.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "../../headers/tomcrypt.h" 12 | 13 | /** 14 | @file der_length_octet_string.c 15 | ASN.1 DER, get length of OCTET STRING, Tom St Denis 16 | */ 17 | 18 | #ifdef LTC_DER 19 | /** 20 | Gets length of DER encoding of OCTET STRING 21 | @param noctets The number of octets in the string to encode 22 | @param outlen [out] The length of the DER encoding for the given string 23 | @return CRYPT_OK if successful 24 | */ 25 | int der_length_octet_string(unsigned long noctets, unsigned long *outlen) 26 | { 27 | LTC_ARGCHK(outlen != NULL); 28 | 29 | if (noctets < 128) { 30 | /* 04 LL DD DD DD ... */ 31 | *outlen = 2 + noctets; 32 | } else if (noctets < 256) { 33 | /* 04 81 LL DD DD DD ... */ 34 | *outlen = 3 + noctets; 35 | } else if (noctets < 65536UL) { 36 | /* 04 82 LL LL DD DD DD ... */ 37 | *outlen = 4 + noctets; 38 | } else if (noctets < 16777216UL) { 39 | /* 04 83 LL LL LL DD DD DD ... */ 40 | *outlen = 5 + noctets; 41 | } else { 42 | return CRYPT_INVALID_ARG; 43 | } 44 | 45 | return CRYPT_OK; 46 | } 47 | 48 | #endif 49 | 50 | 51 | /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/octet/der_length_octet_string.c,v $ */ 52 | /* $Revision: 1.3 $ */ 53 | /* $Date: 2006/12/28 01:27:24 $ */ 54 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtomcrypt/src/pk/asn1/der_length_utctime.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "../../headers/tomcrypt.h" 12 | 13 | /** 14 | @file der_length_utctime.c 15 | ASN.1 DER, get length of UTCTIME, Tom St Denis 16 | */ 17 | 18 | #ifdef LTC_DER 19 | 20 | /** 21 | Gets length of DER encoding of UTCTIME 22 | @param utctime The UTC time structure to get the size of 23 | @param outlen [out] The length of the DER encoding 24 | @return CRYPT_OK if successful 25 | */ 26 | int der_length_utctime(ltc_utctime *utctime, unsigned long *outlen) 27 | { 28 | LTC_ARGCHK(outlen != NULL); 29 | LTC_ARGCHK(utctime != NULL); 30 | 31 | if (utctime->off_hh == 0 && utctime->off_mm == 0) { 32 | /* we encode as YYMMDDhhmmssZ */ 33 | *outlen = 2 + 13; 34 | } else { 35 | /* we encode as YYMMDDhhmmss{+|-}hh'mm' */ 36 | *outlen = 2 + 17; 37 | } 38 | 39 | return CRYPT_OK; 40 | } 41 | 42 | #endif 43 | 44 | /* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/utctime/der_length_utctime.c,v $ */ 45 | /* $Revision: 1.5 $ */ 46 | /* $Date: 2006/12/28 01:27:24 $ */ 47 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtomcrypt/src/pk/ecc/ltc_ecc_points.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | 12 | /* Implements ECC over Z/pZ for curve y^2 = x^3 - 3x + b 13 | * 14 | * All curves taken from NIST recommendation paper of July 1999 15 | * Available at http://csrc.nist.gov/cryptval/dss.htm 16 | */ 17 | #include "../../headers/tomcrypt.h" 18 | 19 | /** 20 | @file ltc_ecc_points.c 21 | ECC Crypto, Tom St Denis 22 | */ 23 | 24 | #ifdef LTC_MECC 25 | 26 | /** 27 | Allocate a new ECC point 28 | @return A newly allocated point or NULL on error 29 | */ 30 | ecc_point *ltc_ecc_new_point(void) 31 | { 32 | ecc_point *p; 33 | p = XCALLOC(1, sizeof(*p)); 34 | if (p == NULL) { 35 | return NULL; 36 | } 37 | if (mp_init_multi(&p->x, &p->y, &p->z, NULL) != CRYPT_OK) { 38 | XFREE(p); 39 | return NULL; 40 | } 41 | return p; 42 | } 43 | 44 | /** Free an ECC point from memory 45 | @param p The point to free 46 | */ 47 | void ltc_ecc_del_point(ecc_point *p) 48 | { 49 | /* prevents free'ing null arguments */ 50 | if (p != NULL) { 51 | mp_clear_multi(p->x, p->y, p->z, NULL); /* note: p->z may be NULL but that's ok with this function anyways */ 52 | XFREE(p); 53 | } 54 | } 55 | 56 | #endif 57 | /* $Source: /cvs/libtom/libtomcrypt/src/pk/ecc/ltc_ecc_points.c,v $ */ 58 | /* $Revision: 1.7 $ */ 59 | /* $Date: 2007/05/12 14:32:35 $ */ 60 | 61 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtomcrypt/src/pk/rsa/rsa_free.c: -------------------------------------------------------------------------------- 1 | /* LibTomCrypt, modular cryptographic library -- Tom St Denis 2 | * 3 | * LibTomCrypt is a library that provides various cryptographic 4 | * algorithms in a highly modular and flexible manner. 5 | * 6 | * The library is free for all purposes without any express 7 | * guarantee it works. 8 | * 9 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 10 | */ 11 | #include "../../headers/tomcrypt.h" 12 | 13 | /** 14 | @file rsa_free.c 15 | Free an RSA key, Tom St Denis 16 | */ 17 | 18 | #ifdef LTC_MRSA 19 | 20 | /** 21 | Free an RSA key from memory 22 | @param key The RSA key to free 23 | */ 24 | void rsa_free(rsa_key *key) 25 | { 26 | LTC_ARGCHKVD(key != NULL); 27 | mp_clear_multi(key->e, key->d, key->N, key->dQ, key->dP, key->qP, key->p, key->q, NULL); 28 | } 29 | 30 | #endif 31 | 32 | /* $Source: /cvs/libtom/libtomcrypt/src/pk/rsa/rsa_free.c,v $ */ 33 | /* $Revision: 1.10 $ */ 34 | /* $Date: 2007/05/12 14:32:35 $ */ 35 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_2expt.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_2EXPT_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* computes a = 2**b 19 | * 20 | * Simple algorithm which zeroes the int, grows it then just sets one bit 21 | * as required. 22 | */ 23 | int 24 | mp_2expt (mp_int * a, int b) 25 | { 26 | int res; 27 | 28 | /* zero a as per default */ 29 | mp_zero (a); 30 | 31 | /* grow a to accomodate the single bit */ 32 | if ((res = mp_grow (a, b / DIGIT_BIT + 1)) != MP_OKAY) { 33 | return res; 34 | } 35 | 36 | /* set the used count of where the bit will go */ 37 | a->used = b / DIGIT_BIT + 1; 38 | 39 | /* put the single bit in its place */ 40 | a->dp[b / DIGIT_BIT] = ((mp_digit)1) << (b % DIGIT_BIT); 41 | 42 | return MP_OKAY; 43 | } 44 | #endif 45 | 46 | /* $Source: /cvs/libtom/libtommath/bn_mp_2expt.c,v $ */ 47 | /* $Revision: 1.4 $ */ 48 | /* $Date: 2006/12/28 01:25:13 $ */ 49 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_abs.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_ABS_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* b = |a| 19 | * 20 | * Simple function copies the input and fixes the sign to positive 21 | */ 22 | int 23 | mp_abs (mp_int * a, mp_int * b) 24 | { 25 | int res; 26 | 27 | /* copy a to b */ 28 | if (a != b) { 29 | if ((res = mp_copy (a, b)) != MP_OKAY) { 30 | return res; 31 | } 32 | } 33 | 34 | /* force the sign of b to positive */ 35 | b->sign = MP_ZPOS; 36 | 37 | return MP_OKAY; 38 | } 39 | #endif 40 | 41 | /* $Source: /cvs/libtom/libtommath/bn_mp_abs.c,v $ */ 42 | /* $Revision: 1.4 $ */ 43 | /* $Date: 2006/12/28 01:25:13 $ */ 44 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_add.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_ADD_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* high level addition (handles signs) */ 19 | int mp_add (mp_int * a, mp_int * b, mp_int * c) 20 | { 21 | int sa, sb, res; 22 | 23 | /* get sign of both inputs */ 24 | sa = a->sign; 25 | sb = b->sign; 26 | 27 | /* handle two cases, not four */ 28 | if (sa == sb) { 29 | /* both positive or both negative */ 30 | /* add their magnitudes, copy the sign */ 31 | c->sign = sa; 32 | res = s_mp_add (a, b, c); 33 | } else { 34 | /* one positive, the other negative */ 35 | /* subtract the one with the greater magnitude from */ 36 | /* the one of the lesser magnitude. The result gets */ 37 | /* the sign of the one with the greater magnitude. */ 38 | if (mp_cmp_mag (a, b) == MP_LT) { 39 | c->sign = sb; 40 | res = s_mp_sub (b, a, c); 41 | } else { 42 | c->sign = sa; 43 | res = s_mp_sub (a, b, c); 44 | } 45 | } 46 | return res; 47 | } 48 | 49 | #endif 50 | 51 | /* $Source: /cvs/libtom/libtommath/bn_mp_add.c,v $ */ 52 | /* $Revision: 1.4 $ */ 53 | /* $Date: 2006/12/28 01:25:13 $ */ 54 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_addmod.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_ADDMOD_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* d = a + b (mod c) */ 19 | int 20 | mp_addmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d) 21 | { 22 | int res; 23 | mp_int t; 24 | 25 | if ((res = mp_init (&t)) != MP_OKAY) { 26 | return res; 27 | } 28 | 29 | if ((res = mp_add (a, b, &t)) != MP_OKAY) { 30 | mp_clear (&t); 31 | return res; 32 | } 33 | res = mp_mod (&t, c, d); 34 | mp_clear (&t); 35 | return res; 36 | } 37 | #endif 38 | 39 | /* $Source: /cvs/libtom/libtommath/bn_mp_addmod.c,v $ */ 40 | /* $Revision: 1.4 $ */ 41 | /* $Date: 2006/12/28 01:25:13 $ */ 42 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_and.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_AND_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* AND two ints together */ 19 | int 20 | mp_and (mp_int * a, mp_int * b, mp_int * c) 21 | { 22 | int res, ix, px; 23 | mp_int t, *x; 24 | 25 | if (a->used > b->used) { 26 | if ((res = mp_init_copy (&t, a)) != MP_OKAY) { 27 | return res; 28 | } 29 | px = b->used; 30 | x = b; 31 | } else { 32 | if ((res = mp_init_copy (&t, b)) != MP_OKAY) { 33 | return res; 34 | } 35 | px = a->used; 36 | x = a; 37 | } 38 | 39 | for (ix = 0; ix < px; ix++) { 40 | t.dp[ix] &= x->dp[ix]; 41 | } 42 | 43 | /* zero digits above the last from the smallest mp_int */ 44 | for (; ix < t.used; ix++) { 45 | t.dp[ix] = 0; 46 | } 47 | 48 | mp_clamp (&t); 49 | mp_exch (c, &t); 50 | mp_clear (&t); 51 | return MP_OKAY; 52 | } 53 | #endif 54 | 55 | /* $Source: /cvs/libtom/libtommath/bn_mp_and.c,v $ */ 56 | /* $Revision: 1.4 $ */ 57 | /* $Date: 2006/12/28 01:25:13 $ */ 58 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_clamp.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_CLAMP_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* trim unused digits 19 | * 20 | * This is used to ensure that leading zero digits are 21 | * trimed and the leading "used" digit will be non-zero 22 | * Typically very fast. Also fixes the sign if there 23 | * are no more leading digits 24 | */ 25 | void 26 | mp_clamp (mp_int * a) 27 | { 28 | /* decrease used while the most significant digit is 29 | * zero. 30 | */ 31 | while (a->used > 0 && a->dp[a->used - 1] == 0) { 32 | --(a->used); 33 | } 34 | 35 | /* reset the sign flag if used == 0 */ 36 | if (a->used == 0) { 37 | a->sign = MP_ZPOS; 38 | } 39 | } 40 | #endif 41 | 42 | /* $Source: /cvs/libtom/libtommath/bn_mp_clamp.c,v $ */ 43 | /* $Revision: 1.4 $ */ 44 | /* $Date: 2006/12/28 01:25:13 $ */ 45 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_clear.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_CLEAR_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* clear one (frees) */ 19 | void 20 | mp_clear (mp_int * a) 21 | { 22 | int i; 23 | 24 | /* only do anything if a hasn't been freed previously */ 25 | if (a->dp != NULL) { 26 | /* first zero the digits */ 27 | for (i = 0; i < a->used; i++) { 28 | a->dp[i] = 0; 29 | } 30 | 31 | /* free ram */ 32 | XFREE(a->dp); 33 | 34 | /* reset members to make debugging easier */ 35 | a->dp = NULL; 36 | a->alloc = a->used = 0; 37 | a->sign = MP_ZPOS; 38 | } 39 | } 40 | #endif 41 | 42 | /* $Source: /cvs/libtom/libtommath/bn_mp_clear.c,v $ */ 43 | /* $Revision: 1.4 $ */ 44 | /* $Date: 2006/12/28 01:25:13 $ */ 45 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_clear_multi.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_CLEAR_MULTI_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | #include 18 | 19 | void mp_clear_multi(mp_int *mp, ...) 20 | { 21 | mp_int* next_mp = mp; 22 | va_list args; 23 | va_start(args, mp); 24 | while (next_mp != NULL) { 25 | mp_clear(next_mp); 26 | next_mp = va_arg(args, mp_int*); 27 | } 28 | va_end(args); 29 | } 30 | #endif 31 | 32 | /* $Source: /cvs/libtom/libtommath/bn_mp_clear_multi.c,v $ */ 33 | /* $Revision: 1.4 $ */ 34 | /* $Date: 2006/12/28 01:25:13 $ */ 35 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_cmp.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_CMP_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* compare two ints (signed)*/ 19 | int 20 | mp_cmp (mp_int * a, mp_int * b) 21 | { 22 | /* compare based on sign */ 23 | if (a->sign != b->sign) { 24 | if (a->sign == MP_NEG) { 25 | return MP_LT; 26 | } else { 27 | return MP_GT; 28 | } 29 | } 30 | 31 | /* compare digits */ 32 | if (a->sign == MP_NEG) { 33 | /* if negative compare opposite direction */ 34 | return mp_cmp_mag(b, a); 35 | } else { 36 | return mp_cmp_mag(a, b); 37 | } 38 | } 39 | #endif 40 | 41 | /* $Source: /cvs/libtom/libtommath/bn_mp_cmp.c,v $ */ 42 | /* $Revision: 1.4 $ */ 43 | /* $Date: 2006/12/28 01:25:13 $ */ 44 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_cmp_d.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_CMP_D_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* compare a digit */ 19 | int mp_cmp_d(mp_int * a, mp_digit b) 20 | { 21 | /* compare based on sign */ 22 | if (a->sign == MP_NEG) { 23 | return MP_LT; 24 | } 25 | 26 | /* compare based on magnitude */ 27 | if (a->used > 1) { 28 | return MP_GT; 29 | } 30 | 31 | /* compare the only digit of a to b */ 32 | if (a->dp[0] > b) { 33 | return MP_GT; 34 | } else if (a->dp[0] < b) { 35 | return MP_LT; 36 | } else { 37 | return MP_EQ; 38 | } 39 | } 40 | #endif 41 | 42 | /* $Source: /cvs/libtom/libtommath/bn_mp_cmp_d.c,v $ */ 43 | /* $Revision: 1.4 $ */ 44 | /* $Date: 2006/12/28 01:25:13 $ */ 45 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_cmp_mag.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_CMP_MAG_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* compare maginitude of two ints (unsigned) */ 19 | int mp_cmp_mag (mp_int * a, mp_int * b) 20 | { 21 | int n; 22 | mp_digit *tmpa, *tmpb; 23 | 24 | /* compare based on # of non-zero digits */ 25 | if (a->used > b->used) { 26 | return MP_GT; 27 | } 28 | 29 | if (a->used < b->used) { 30 | return MP_LT; 31 | } 32 | 33 | /* alias for a */ 34 | tmpa = a->dp + (a->used - 1); 35 | 36 | /* alias for b */ 37 | tmpb = b->dp + (a->used - 1); 38 | 39 | /* compare based on digits */ 40 | for (n = 0; n < a->used; ++n, --tmpa, --tmpb) { 41 | if (*tmpa > *tmpb) { 42 | return MP_GT; 43 | } 44 | 45 | if (*tmpa < *tmpb) { 46 | return MP_LT; 47 | } 48 | } 49 | return MP_EQ; 50 | } 51 | #endif 52 | 53 | /* $Source: /cvs/libtom/libtommath/bn_mp_cmp_mag.c,v $ */ 54 | /* $Revision: 1.4 $ */ 55 | /* $Date: 2006/12/28 01:25:13 $ */ 56 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_cnt_lsb.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_CNT_LSB_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | static const int lnz[16] = { 19 | 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0 20 | }; 21 | 22 | /* Counts the number of lsbs which are zero before the first zero bit */ 23 | int mp_cnt_lsb(mp_int *a) 24 | { 25 | int x; 26 | mp_digit q, qq; 27 | 28 | /* easy out */ 29 | if (mp_iszero(a) == 1) { 30 | return 0; 31 | } 32 | 33 | /* scan lower digits until non-zero */ 34 | for (x = 0; x < a->used && a->dp[x] == 0; x++); 35 | q = a->dp[x]; 36 | x *= DIGIT_BIT; 37 | 38 | /* now scan this digit until a 1 is found */ 39 | if ((q & 1) == 0) { 40 | do { 41 | qq = q & 15; 42 | x += lnz[qq]; 43 | q >>= 4; 44 | } while (qq == 0); 45 | } 46 | return x; 47 | } 48 | 49 | #endif 50 | 51 | /* $Source: /cvs/libtom/libtommath/bn_mp_cnt_lsb.c,v $ */ 52 | /* $Revision: 1.4 $ */ 53 | /* $Date: 2006/12/28 01:25:13 $ */ 54 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_count_bits.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_COUNT_BITS_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* returns the number of bits in an int */ 19 | int 20 | mp_count_bits (mp_int * a) 21 | { 22 | int r; 23 | mp_digit q; 24 | 25 | /* shortcut */ 26 | if (a->used == 0) { 27 | return 0; 28 | } 29 | 30 | /* get number of digits and add that */ 31 | r = (a->used - 1) * DIGIT_BIT; 32 | 33 | /* take the last digit and count the bits in it */ 34 | q = a->dp[a->used - 1]; 35 | while (q > ((mp_digit) 0)) { 36 | ++r; 37 | q >>= ((mp_digit) 1); 38 | } 39 | return r; 40 | } 41 | #endif 42 | 43 | /* $Source: /cvs/libtom/libtommath/bn_mp_count_bits.c,v $ */ 44 | /* $Revision: 1.4 $ */ 45 | /* $Date: 2006/12/28 01:25:13 $ */ 46 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_dr_is_modulus.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_DR_IS_MODULUS_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* determines if a number is a valid DR modulus */ 19 | int mp_dr_is_modulus(mp_int *a) 20 | { 21 | int ix; 22 | 23 | /* must be at least two digits */ 24 | if (a->used < 2) { 25 | return 0; 26 | } 27 | 28 | /* must be of the form b**k - a [a <= b] so all 29 | * but the first digit must be equal to -1 (mod b). 30 | */ 31 | for (ix = 1; ix < a->used; ix++) { 32 | if (a->dp[ix] != MP_MASK) { 33 | return 0; 34 | } 35 | } 36 | return 1; 37 | } 38 | 39 | #endif 40 | 41 | /* $Source: /cvs/libtom/libtommath/bn_mp_dr_is_modulus.c,v $ */ 42 | /* $Revision: 1.4 $ */ 43 | /* $Date: 2006/12/28 01:25:13 $ */ 44 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_dr_setup.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_DR_SETUP_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* determines the setup value */ 19 | void mp_dr_setup(mp_int *a, mp_digit *d) 20 | { 21 | /* the casts are required if DIGIT_BIT is one less than 22 | * the number of bits in a mp_digit [e.g. DIGIT_BIT==31] 23 | */ 24 | *d = (mp_digit)((((mp_word)1) << ((mp_word)DIGIT_BIT)) - 25 | ((mp_word)a->dp[0])); 26 | } 27 | 28 | #endif 29 | 30 | /* $Source: /cvs/libtom/libtommath/bn_mp_dr_setup.c,v $ */ 31 | /* $Revision: 1.4 $ */ 32 | /* $Date: 2006/12/28 01:25:13 $ */ 33 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_exch.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_EXCH_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* swap the elements of two integers, for cases where you can't simply swap the 19 | * mp_int pointers around 20 | */ 21 | void 22 | mp_exch (mp_int * a, mp_int * b) 23 | { 24 | mp_int t; 25 | 26 | t = *a; 27 | *a = *b; 28 | *b = t; 29 | } 30 | #endif 31 | 32 | /* $Source: /cvs/libtom/libtommath/bn_mp_exch.c,v $ */ 33 | /* $Revision: 1.4 $ */ 34 | /* $Date: 2006/12/28 01:25:13 $ */ 35 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_expt_d.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_EXPT_D_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* calculate c = a**b using a square-multiply algorithm */ 19 | int mp_expt_d (mp_int * a, mp_digit b, mp_int * c) 20 | { 21 | int res, x; 22 | mp_int g; 23 | 24 | if ((res = mp_init_copy (&g, a)) != MP_OKAY) { 25 | return res; 26 | } 27 | 28 | /* set initial result */ 29 | mp_set (c, 1); 30 | 31 | for (x = 0; x < (int) DIGIT_BIT; x++) { 32 | /* square */ 33 | if ((res = mp_sqr (c, c)) != MP_OKAY) { 34 | mp_clear (&g); 35 | return res; 36 | } 37 | 38 | /* if the bit is set multiply */ 39 | if ((b & (mp_digit) (((mp_digit)1) << (DIGIT_BIT - 1))) != 0) { 40 | if ((res = mp_mul (c, &g, c)) != MP_OKAY) { 41 | mp_clear (&g); 42 | return res; 43 | } 44 | } 45 | 46 | /* shift to next bit */ 47 | b <<= 1; 48 | } 49 | 50 | mp_clear (&g); 51 | return MP_OKAY; 52 | } 53 | #endif 54 | 55 | /* $Source: /cvs/libtom/libtommath/bn_mp_expt_d.c,v $ */ 56 | /* $Revision: 1.4 $ */ 57 | /* $Date: 2006/12/28 01:25:13 $ */ 58 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_fwrite.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_FWRITE_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | int mp_fwrite(mp_int *a, int radix, FILE *stream) 19 | { 20 | char *buf; 21 | int err, len, x; 22 | 23 | if ((err = mp_radix_size(a, radix, &len)) != MP_OKAY) { 24 | return err; 25 | } 26 | 27 | buf = OPT_CAST(char) XMALLOC (len); 28 | if (buf == NULL) { 29 | return MP_MEM; 30 | } 31 | 32 | if ((err = mp_toradix(a, buf, radix)) != MP_OKAY) { 33 | XFREE (buf); 34 | return err; 35 | } 36 | 37 | for (x = 0; x < len; x++) { 38 | if (fputc(buf[x], stream) == EOF) { 39 | XFREE (buf); 40 | return MP_VAL; 41 | } 42 | } 43 | 44 | XFREE (buf); 45 | return MP_OKAY; 46 | } 47 | 48 | #endif 49 | 50 | /* $Source: /cvs/libtom/libtommath/bn_mp_fwrite.c,v $ */ 51 | /* $Revision: 1.4 $ */ 52 | /* $Date: 2006/12/28 01:25:13 $ */ 53 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_get_int.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_GET_INT_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* get the lower 32-bits of an mp_int */ 19 | unsigned long mp_get_int(mp_int * a) 20 | { 21 | int i; 22 | unsigned long res; 23 | 24 | if (a->used == 0) { 25 | return 0; 26 | } 27 | 28 | /* get number of digits of the lsb we have to read */ 29 | i = MIN(a->used,(int)((sizeof(unsigned long)*CHAR_BIT+DIGIT_BIT-1)/DIGIT_BIT))-1; 30 | 31 | /* get most significant digit of result */ 32 | res = DIGIT(a,i); 33 | 34 | while (--i >= 0) { 35 | res = (res << DIGIT_BIT) | DIGIT(a,i); 36 | } 37 | 38 | /* force result to 32-bits always so it is consistent on non 32-bit platforms */ 39 | return res & 0xFFFFFFFFUL; 40 | } 41 | #endif 42 | 43 | /* $Source: /cvs/libtom/libtommath/bn_mp_get_int.c,v $ */ 44 | /* $Revision: 1.4 $ */ 45 | /* $Date: 2006/12/28 01:25:13 $ */ 46 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_init.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_INIT_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* init a new mp_int */ 19 | int mp_init (mp_int * a) 20 | { 21 | int i; 22 | 23 | /* allocate memory required and clear it */ 24 | a->dp = OPT_CAST(mp_digit) XMALLOC (sizeof (mp_digit) * MP_PREC); 25 | if (a->dp == NULL) { 26 | return MP_MEM; 27 | } 28 | 29 | /* set the digits to zero */ 30 | for (i = 0; i < MP_PREC; i++) { 31 | a->dp[i] = 0; 32 | } 33 | 34 | /* set the used to zero, allocated digits to the default precision 35 | * and sign to positive */ 36 | a->used = 0; 37 | a->alloc = MP_PREC; 38 | a->sign = MP_ZPOS; 39 | 40 | return MP_OKAY; 41 | } 42 | #endif 43 | 44 | /* $Source: /cvs/libtom/libtommath/bn_mp_init.c,v $ */ 45 | /* $Revision: 1.4 $ */ 46 | /* $Date: 2006/12/28 01:25:13 $ */ 47 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_init_copy.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_INIT_COPY_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* creates "a" then copies b into it */ 19 | int mp_init_copy (mp_int * a, mp_int * b) 20 | { 21 | int res; 22 | 23 | if ((res = mp_init (a)) != MP_OKAY) { 24 | return res; 25 | } 26 | return mp_copy (b, a); 27 | } 28 | #endif 29 | 30 | /* $Source: /cvs/libtom/libtommath/bn_mp_init_copy.c,v $ */ 31 | /* $Revision: 1.4 $ */ 32 | /* $Date: 2006/12/28 01:25:13 $ */ 33 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_init_set.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_INIT_SET_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* initialize and set a digit */ 19 | int mp_init_set (mp_int * a, mp_digit b) 20 | { 21 | int err; 22 | if ((err = mp_init(a)) != MP_OKAY) { 23 | return err; 24 | } 25 | mp_set(a, b); 26 | return err; 27 | } 28 | #endif 29 | 30 | /* $Source: /cvs/libtom/libtommath/bn_mp_init_set.c,v $ */ 31 | /* $Revision: 1.4 $ */ 32 | /* $Date: 2006/12/28 01:25:13 $ */ 33 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_init_set_int.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_INIT_SET_INT_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* initialize and set a digit */ 19 | int mp_init_set_int (mp_int * a, unsigned long b) 20 | { 21 | int err; 22 | if ((err = mp_init(a)) != MP_OKAY) { 23 | return err; 24 | } 25 | return mp_set_int(a, b); 26 | } 27 | #endif 28 | 29 | /* $Source: /cvs/libtom/libtommath/bn_mp_init_set_int.c,v $ */ 30 | /* $Revision: 1.4 $ */ 31 | /* $Date: 2006/12/28 01:25:13 $ */ 32 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_init_size.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_INIT_SIZE_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* init an mp_init for a given size */ 19 | int mp_init_size (mp_int * a, int size) 20 | { 21 | int x; 22 | 23 | /* pad size so there are always extra digits */ 24 | size += (MP_PREC * 2) - (size % MP_PREC); 25 | 26 | /* alloc mem */ 27 | a->dp = OPT_CAST(mp_digit) XMALLOC (sizeof (mp_digit) * size); 28 | if (a->dp == NULL) { 29 | return MP_MEM; 30 | } 31 | 32 | /* set the members */ 33 | a->used = 0; 34 | a->alloc = size; 35 | a->sign = MP_ZPOS; 36 | 37 | /* zero the digits */ 38 | for (x = 0; x < size; x++) { 39 | a->dp[x] = 0; 40 | } 41 | 42 | return MP_OKAY; 43 | } 44 | #endif 45 | 46 | /* $Source: /cvs/libtom/libtommath/bn_mp_init_size.c,v $ */ 47 | /* $Revision: 1.4 $ */ 48 | /* $Date: 2006/12/28 01:25:13 $ */ 49 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_invmod.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_INVMOD_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* hac 14.61, pp608 */ 19 | int mp_invmod (mp_int * a, mp_int * b, mp_int * c) 20 | { 21 | /* b cannot be negative */ 22 | if (b->sign == MP_NEG || mp_iszero(b) == 1) { 23 | return MP_VAL; 24 | } 25 | 26 | #ifdef BN_FAST_MP_INVMOD_C 27 | /* if the modulus is odd we can use a faster routine instead */ 28 | if (mp_isodd (b) == 1) { 29 | return fast_mp_invmod (a, b, c); 30 | } 31 | #endif 32 | 33 | #ifdef BN_MP_INVMOD_SLOW_C 34 | return mp_invmod_slow(a, b, c); 35 | #endif 36 | 37 | return MP_VAL; 38 | } 39 | #endif 40 | 41 | /* $Source: /cvs/libtom/libtommath/bn_mp_invmod.c,v $ */ 42 | /* $Revision: 1.4 $ */ 43 | /* $Date: 2006/12/28 01:25:13 $ */ 44 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_mod.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_MOD_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* c = a mod b, 0 <= c < b */ 19 | int 20 | mp_mod (mp_int * a, mp_int * b, mp_int * c) 21 | { 22 | mp_int t; 23 | int res; 24 | 25 | if ((res = mp_init (&t)) != MP_OKAY) { 26 | return res; 27 | } 28 | 29 | if ((res = mp_div (a, b, NULL, &t)) != MP_OKAY) { 30 | mp_clear (&t); 31 | return res; 32 | } 33 | 34 | if (t.sign != b->sign) { 35 | res = mp_add (b, &t, c); 36 | } else { 37 | res = MP_OKAY; 38 | mp_exch (&t, c); 39 | } 40 | 41 | mp_clear (&t); 42 | return res; 43 | } 44 | #endif 45 | 46 | /* $Source: /cvs/libtom/libtommath/bn_mp_mod.c,v $ */ 47 | /* $Revision: 1.4 $ */ 48 | /* $Date: 2006/12/28 01:25:13 $ */ 49 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_mod_2d.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_MOD_2D_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* calc a value mod 2**b */ 19 | int 20 | mp_mod_2d (mp_int * a, int b, mp_int * c) 21 | { 22 | int x, res; 23 | 24 | /* if b is <= 0 then zero the int */ 25 | if (b <= 0) { 26 | mp_zero (c); 27 | return MP_OKAY; 28 | } 29 | 30 | /* if the modulus is larger than the value than return */ 31 | if (b >= (int) (a->used * DIGIT_BIT)) { 32 | res = mp_copy (a, c); 33 | return res; 34 | } 35 | 36 | /* copy */ 37 | if ((res = mp_copy (a, c)) != MP_OKAY) { 38 | return res; 39 | } 40 | 41 | /* zero digits above the last digit of the modulus */ 42 | for (x = (b / DIGIT_BIT) + ((b % DIGIT_BIT) == 0 ? 0 : 1); x < c->used; x++) { 43 | c->dp[x] = 0; 44 | } 45 | /* clear the digit that is not completely outside/inside the modulus */ 46 | c->dp[b / DIGIT_BIT] &= 47 | (mp_digit) ((((mp_digit) 1) << (((mp_digit) b) % DIGIT_BIT)) - ((mp_digit) 1)); 48 | mp_clamp (c); 49 | return MP_OKAY; 50 | } 51 | #endif 52 | 53 | /* $Source: /cvs/libtom/libtommath/bn_mp_mod_2d.c,v $ */ 54 | /* $Revision: 1.4 $ */ 55 | /* $Date: 2006/12/28 01:25:13 $ */ 56 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_mod_d.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_MOD_D_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | int 19 | mp_mod_d (mp_int * a, mp_digit b, mp_digit * c) 20 | { 21 | return mp_div_d(a, b, NULL, c); 22 | } 23 | #endif 24 | 25 | /* $Source: /cvs/libtom/libtommath/bn_mp_mod_d.c,v $ */ 26 | /* $Revision: 1.4 $ */ 27 | /* $Date: 2006/12/28 01:25:13 $ */ 28 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_mulmod.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_MULMOD_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* d = a * b (mod c) */ 19 | int mp_mulmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d) 20 | { 21 | int res; 22 | mp_int t; 23 | 24 | if ((res = mp_init (&t)) != MP_OKAY) { 25 | return res; 26 | } 27 | 28 | if ((res = mp_mul (a, b, &t)) != MP_OKAY) { 29 | mp_clear (&t); 30 | return res; 31 | } 32 | res = mp_mod (&t, c, d); 33 | mp_clear (&t); 34 | return res; 35 | } 36 | #endif 37 | 38 | /* $Source: /cvs/libtom/libtommath/bn_mp_mulmod.c,v $ */ 39 | /* $Revision: 1.5 $ */ 40 | /* $Date: 2006/12/28 01:25:13 $ */ 41 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_neg.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_NEG_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* b = -a */ 19 | int mp_neg (mp_int * a, mp_int * b) 20 | { 21 | int res; 22 | if (a != b) { 23 | if ((res = mp_copy (a, b)) != MP_OKAY) { 24 | return res; 25 | } 26 | } 27 | 28 | if (mp_iszero(b) != MP_YES) { 29 | b->sign = (a->sign == MP_ZPOS) ? MP_NEG : MP_ZPOS; 30 | } else { 31 | b->sign = MP_ZPOS; 32 | } 33 | 34 | return MP_OKAY; 35 | } 36 | #endif 37 | 38 | /* $Source: /cvs/libtom/libtommath/bn_mp_neg.c,v $ */ 39 | /* $Revision: 1.4 $ */ 40 | /* $Date: 2006/12/28 01:25:13 $ */ 41 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_or.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_OR_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* OR two ints together */ 19 | int mp_or (mp_int * a, mp_int * b, mp_int * c) 20 | { 21 | int res, ix, px; 22 | mp_int t, *x; 23 | 24 | if (a->used > b->used) { 25 | if ((res = mp_init_copy (&t, a)) != MP_OKAY) { 26 | return res; 27 | } 28 | px = b->used; 29 | x = b; 30 | } else { 31 | if ((res = mp_init_copy (&t, b)) != MP_OKAY) { 32 | return res; 33 | } 34 | px = a->used; 35 | x = a; 36 | } 37 | 38 | for (ix = 0; ix < px; ix++) { 39 | t.dp[ix] |= x->dp[ix]; 40 | } 41 | mp_clamp (&t); 42 | mp_exch (c, &t); 43 | mp_clear (&t); 44 | return MP_OKAY; 45 | } 46 | #endif 47 | 48 | /* $Source: /cvs/libtom/libtommath/bn_mp_or.c,v $ */ 49 | /* $Revision: 1.4 $ */ 50 | /* $Date: 2006/12/28 01:25:13 $ */ 51 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_prime_is_divisible.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_PRIME_IS_DIVISIBLE_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* determines if an integers is divisible by one 19 | * of the first PRIME_SIZE primes or not 20 | * 21 | * sets result to 0 if not, 1 if yes 22 | */ 23 | int mp_prime_is_divisible (mp_int * a, int *result) 24 | { 25 | int err, ix; 26 | mp_digit res; 27 | 28 | /* default to not */ 29 | *result = MP_NO; 30 | 31 | for (ix = 0; ix < PRIME_SIZE; ix++) { 32 | /* what is a mod LBL_prime_tab[ix] */ 33 | if ((err = mp_mod_d (a, ltm_prime_tab[ix], &res)) != MP_OKAY) { 34 | return err; 35 | } 36 | 37 | /* is the residue zero? */ 38 | if (res == 0) { 39 | *result = MP_YES; 40 | return MP_OKAY; 41 | } 42 | } 43 | 44 | return MP_OKAY; 45 | } 46 | #endif 47 | 48 | /* $Source: /cvs/libtom/libtommath/bn_mp_prime_is_divisible.c,v $ */ 49 | /* $Revision: 1.4 $ */ 50 | /* $Date: 2006/12/28 01:25:13 $ */ 51 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_prime_rabin_miller_trials.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_PRIME_RABIN_MILLER_TRIALS_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | 19 | static const struct { 20 | int k, t; 21 | } sizes[] = { 22 | { 128, 28 }, 23 | { 256, 16 }, 24 | { 384, 10 }, 25 | { 512, 7 }, 26 | { 640, 6 }, 27 | { 768, 5 }, 28 | { 896, 4 }, 29 | { 1024, 4 } 30 | }; 31 | 32 | /* returns # of RM trials required for a given bit size */ 33 | int mp_prime_rabin_miller_trials(int size) 34 | { 35 | int x; 36 | 37 | for (x = 0; x < (int)(sizeof(sizes)/(sizeof(sizes[0]))); x++) { 38 | if (sizes[x].k == size) { 39 | return sizes[x].t; 40 | } else if (sizes[x].k > size) { 41 | return (x == 0) ? sizes[0].t : sizes[x - 1].t; 42 | } 43 | } 44 | return sizes[x-1].t + 1; 45 | } 46 | 47 | 48 | #endif 49 | 50 | /* $Source: /cvs/libtom/libtommath/bn_mp_prime_rabin_miller_trials.c,v $ */ 51 | /* $Revision: 1.4 $ */ 52 | /* $Date: 2006/12/28 01:25:13 $ */ 53 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_radix_smap.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_RADIX_SMAP_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* chars used in radix conversions */ 19 | const char *mp_s_rmap = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/"; 20 | #endif 21 | 22 | /* $Source: /cvs/libtom/libtommath/bn_mp_radix_smap.c,v $ */ 23 | /* $Revision: 1.4 $ */ 24 | /* $Date: 2006/12/28 01:25:13 $ */ 25 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_rand.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_RAND_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* makes a pseudo-random int of a given size */ 19 | int 20 | mp_rand (mp_int * a, int digits) 21 | { 22 | int res; 23 | mp_digit d; 24 | 25 | mp_zero (a); 26 | if (digits <= 0) { 27 | return MP_OKAY; 28 | } 29 | 30 | /* first place a random non-zero digit */ 31 | do { 32 | d = ((mp_digit) abs (rand ())) & MP_MASK; 33 | } while (d == 0); 34 | 35 | if ((res = mp_add_d (a, d, a)) != MP_OKAY) { 36 | return res; 37 | } 38 | 39 | while (--digits > 0) { 40 | if ((res = mp_lshd (a, 1)) != MP_OKAY) { 41 | return res; 42 | } 43 | 44 | if ((res = mp_add_d (a, ((mp_digit) abs (rand ())), a)) != MP_OKAY) { 45 | return res; 46 | } 47 | } 48 | 49 | return MP_OKAY; 50 | } 51 | #endif 52 | 53 | /* $Source: /cvs/libtom/libtommath/bn_mp_rand.c,v $ */ 54 | /* $Revision: 1.4 $ */ 55 | /* $Date: 2006/12/28 01:25:13 $ */ 56 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_read_signed_bin.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_READ_SIGNED_BIN_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* read signed bin, big endian, first byte is 0==positive or 1==negative */ 19 | int mp_read_signed_bin (mp_int * a, const unsigned char *b, int c) 20 | { 21 | int res; 22 | 23 | /* read magnitude */ 24 | if ((res = mp_read_unsigned_bin (a, b + 1, c - 1)) != MP_OKAY) { 25 | return res; 26 | } 27 | 28 | /* first byte is 0 for positive, non-zero for negative */ 29 | if (b[0] == 0) { 30 | a->sign = MP_ZPOS; 31 | } else { 32 | a->sign = MP_NEG; 33 | } 34 | 35 | return MP_OKAY; 36 | } 37 | #endif 38 | 39 | /* $Source: /cvs/libtom/libtommath/bn_mp_read_signed_bin.c,v $ */ 40 | /* $Revision: 1.5 $ */ 41 | /* $Date: 2006/12/28 01:25:13 $ */ 42 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_read_unsigned_bin.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_READ_UNSIGNED_BIN_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* reads a unsigned char array, assumes the msb is stored first [big endian] */ 19 | int mp_read_unsigned_bin (mp_int * a, const unsigned char *b, int c) 20 | { 21 | int res; 22 | 23 | /* make sure there are at least two digits */ 24 | if (a->alloc < 2) { 25 | if ((res = mp_grow(a, 2)) != MP_OKAY) { 26 | return res; 27 | } 28 | } 29 | 30 | /* zero the int */ 31 | mp_zero (a); 32 | 33 | /* read the bytes in */ 34 | while (c-- > 0) { 35 | if ((res = mp_mul_2d (a, 8, a)) != MP_OKAY) { 36 | return res; 37 | } 38 | 39 | #ifndef MP_8BIT 40 | a->dp[0] |= *b++; 41 | a->used += 1; 42 | #else 43 | a->dp[0] = (*b & MP_MASK); 44 | a->dp[1] |= ((*b++ >> 7U) & 1); 45 | a->used += 2; 46 | #endif 47 | } 48 | mp_clamp (a); 49 | return MP_OKAY; 50 | } 51 | #endif 52 | 53 | /* $Source: /cvs/libtom/libtommath/bn_mp_read_unsigned_bin.c,v $ */ 54 | /* $Revision: 1.5 $ */ 55 | /* $Date: 2006/12/28 01:25:13 $ */ 56 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_reduce_2k.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_REDUCE_2K_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* reduces a modulo n where n is of the form 2**p - d */ 19 | int mp_reduce_2k(mp_int *a, mp_int *n, mp_digit d) 20 | { 21 | mp_int q; 22 | int p, res; 23 | 24 | if ((res = mp_init(&q)) != MP_OKAY) { 25 | return res; 26 | } 27 | 28 | p = mp_count_bits(n); 29 | top: 30 | /* q = a/2**p, a = a mod 2**p */ 31 | if ((res = mp_div_2d(a, p, &q, a)) != MP_OKAY) { 32 | goto ERR; 33 | } 34 | 35 | if (d != 1) { 36 | /* q = q * d */ 37 | if ((res = mp_mul_d(&q, d, &q)) != MP_OKAY) { 38 | goto ERR; 39 | } 40 | } 41 | 42 | /* a = a + q */ 43 | if ((res = s_mp_add(a, &q, a)) != MP_OKAY) { 44 | goto ERR; 45 | } 46 | 47 | if (mp_cmp_mag(a, n) != MP_LT) { 48 | s_mp_sub(a, n, a); 49 | goto top; 50 | } 51 | 52 | ERR: 53 | mp_clear(&q); 54 | return res; 55 | } 56 | 57 | #endif 58 | 59 | /* $Source: /cvs/libtom/libtommath/bn_mp_reduce_2k.c,v $ */ 60 | /* $Revision: 1.4 $ */ 61 | /* $Date: 2006/12/28 01:25:13 $ */ 62 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_reduce_2k_setup.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_REDUCE_2K_SETUP_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* determines the setup value */ 19 | int mp_reduce_2k_setup(mp_int *a, mp_digit *d) 20 | { 21 | int res, p; 22 | mp_int tmp; 23 | 24 | if ((res = mp_init(&tmp)) != MP_OKAY) { 25 | return res; 26 | } 27 | 28 | p = mp_count_bits(a); 29 | if ((res = mp_2expt(&tmp, p)) != MP_OKAY) { 30 | mp_clear(&tmp); 31 | return res; 32 | } 33 | 34 | if ((res = s_mp_sub(&tmp, a, &tmp)) != MP_OKAY) { 35 | mp_clear(&tmp); 36 | return res; 37 | } 38 | 39 | *d = tmp.dp[0]; 40 | mp_clear(&tmp); 41 | return MP_OKAY; 42 | } 43 | #endif 44 | 45 | /* $Source: /cvs/libtom/libtommath/bn_mp_reduce_2k_setup.c,v $ */ 46 | /* $Revision: 1.4 $ */ 47 | /* $Date: 2006/12/28 01:25:13 $ */ 48 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_reduce_2k_setup_l.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_REDUCE_2K_SETUP_L_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* determines the setup value */ 19 | int mp_reduce_2k_setup_l(mp_int *a, mp_int *d) 20 | { 21 | int res; 22 | mp_int tmp; 23 | 24 | if ((res = mp_init(&tmp)) != MP_OKAY) { 25 | return res; 26 | } 27 | 28 | if ((res = mp_2expt(&tmp, mp_count_bits(a))) != MP_OKAY) { 29 | goto ERR; 30 | } 31 | 32 | if ((res = s_mp_sub(&tmp, a, d)) != MP_OKAY) { 33 | goto ERR; 34 | } 35 | 36 | ERR: 37 | mp_clear(&tmp); 38 | return res; 39 | } 40 | #endif 41 | 42 | /* $Source: /cvs/libtom/libtommath/bn_mp_reduce_2k_setup_l.c,v $ */ 43 | /* $Revision: 1.4 $ */ 44 | /* $Date: 2006/12/28 01:25:13 $ */ 45 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_reduce_is_2k.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_REDUCE_IS_2K_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* determines if mp_reduce_2k can be used */ 19 | int mp_reduce_is_2k(mp_int *a) 20 | { 21 | int ix, iy, iw; 22 | mp_digit iz; 23 | 24 | if (a->used == 0) { 25 | return MP_NO; 26 | } else if (a->used == 1) { 27 | return MP_YES; 28 | } else if (a->used > 1) { 29 | iy = mp_count_bits(a); 30 | iz = 1; 31 | iw = 1; 32 | 33 | /* Test every bit from the second digit up, must be 1 */ 34 | for (ix = DIGIT_BIT; ix < iy; ix++) { 35 | if ((a->dp[iw] & iz) == 0) { 36 | return MP_NO; 37 | } 38 | iz <<= 1; 39 | if (iz > (mp_digit)MP_MASK) { 40 | ++iw; 41 | iz = 1; 42 | } 43 | } 44 | } 45 | return MP_YES; 46 | } 47 | 48 | #endif 49 | 50 | /* $Source: /cvs/libtom/libtommath/bn_mp_reduce_is_2k.c,v $ */ 51 | /* $Revision: 1.4 $ */ 52 | /* $Date: 2006/12/28 01:25:13 $ */ 53 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_reduce_is_2k_l.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_REDUCE_IS_2K_L_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* determines if reduce_2k_l can be used */ 19 | int mp_reduce_is_2k_l(mp_int *a) 20 | { 21 | int ix, iy; 22 | 23 | if (a->used == 0) { 24 | return MP_NO; 25 | } else if (a->used == 1) { 26 | return MP_YES; 27 | } else if (a->used > 1) { 28 | /* if more than half of the digits are -1 we're sold */ 29 | for (iy = ix = 0; ix < a->used; ix++) { 30 | if (a->dp[ix] == MP_MASK) { 31 | ++iy; 32 | } 33 | } 34 | return (iy >= (a->used/2)) ? MP_YES : MP_NO; 35 | 36 | } 37 | return MP_NO; 38 | } 39 | 40 | #endif 41 | 42 | /* $Source: /cvs/libtom/libtommath/bn_mp_reduce_is_2k_l.c,v $ */ 43 | /* $Revision: 1.4 $ */ 44 | /* $Date: 2006/12/28 01:25:13 $ */ 45 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_reduce_setup.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_REDUCE_SETUP_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* pre-calculate the value required for Barrett reduction 19 | * For a given modulus "b" it calulates the value required in "a" 20 | */ 21 | int mp_reduce_setup (mp_int * a, mp_int * b) 22 | { 23 | int res; 24 | 25 | if ((res = mp_2expt (a, b->used * 2 * DIGIT_BIT)) != MP_OKAY) { 26 | return res; 27 | } 28 | return mp_div (a, b, a, NULL); 29 | } 30 | #endif 31 | 32 | /* $Source: /cvs/libtom/libtommath/bn_mp_reduce_setup.c,v $ */ 33 | /* $Revision: 1.4 $ */ 34 | /* $Date: 2006/12/28 01:25:13 $ */ 35 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_set.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_SET_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* set to a digit */ 19 | void mp_set (mp_int * a, mp_digit b) 20 | { 21 | mp_zero (a); 22 | a->dp[0] = b & MP_MASK; 23 | a->used = (a->dp[0] != 0) ? 1 : 0; 24 | } 25 | #endif 26 | 27 | /* $Source: /cvs/libtom/libtommath/bn_mp_set.c,v $ */ 28 | /* $Revision: 1.4 $ */ 29 | /* $Date: 2006/12/28 01:25:13 $ */ 30 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_set_int.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_SET_INT_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* set a 32-bit const */ 19 | int mp_set_int (mp_int * a, unsigned long b) 20 | { 21 | int x, res; 22 | 23 | mp_zero (a); 24 | 25 | /* set four bits at a time */ 26 | for (x = 0; x < 8; x++) { 27 | /* shift the number up four bits */ 28 | if ((res = mp_mul_2d (a, 4, a)) != MP_OKAY) { 29 | return res; 30 | } 31 | 32 | /* OR in the top four bits of the source */ 33 | a->dp[0] |= (b >> 28) & 15; 34 | 35 | /* shift the source up to the next four bits */ 36 | b <<= 4; 37 | 38 | /* ensure that digits are not clamped off */ 39 | a->used += 1; 40 | } 41 | mp_clamp (a); 42 | return MP_OKAY; 43 | } 44 | #endif 45 | 46 | /* $Source: /cvs/libtom/libtommath/bn_mp_set_int.c,v $ */ 47 | /* $Revision: 1.4 $ */ 48 | /* $Date: 2006/12/28 01:25:13 $ */ 49 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_shrink.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_SHRINK_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* shrink a bignum */ 19 | int mp_shrink (mp_int * a) 20 | { 21 | mp_digit *tmp; 22 | if (a->alloc != a->used && a->used > 0) { 23 | if ((tmp = OPT_CAST(mp_digit) XREALLOC (a->dp, sizeof (mp_digit) * a->used)) == NULL) { 24 | return MP_MEM; 25 | } 26 | a->dp = tmp; 27 | a->alloc = a->used; 28 | } 29 | return MP_OKAY; 30 | } 31 | #endif 32 | 33 | /* $Source: /cvs/libtom/libtommath/bn_mp_shrink.c,v $ */ 34 | /* $Revision: 1.4 $ */ 35 | /* $Date: 2006/12/28 01:25:13 $ */ 36 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_signed_bin_size.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_SIGNED_BIN_SIZE_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* get the size for an signed equivalent */ 19 | int mp_signed_bin_size (mp_int * a) 20 | { 21 | return 1 + mp_unsigned_bin_size (a); 22 | } 23 | #endif 24 | 25 | /* $Source: /cvs/libtom/libtommath/bn_mp_signed_bin_size.c,v $ */ 26 | /* $Revision: 1.4 $ */ 27 | /* $Date: 2006/12/28 01:25:13 $ */ 28 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_sqr.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_SQR_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* computes b = a*a */ 19 | int 20 | mp_sqr (mp_int * a, mp_int * b) 21 | { 22 | int res; 23 | 24 | #ifdef BN_MP_TOOM_SQR_C 25 | /* use Toom-Cook? */ 26 | if (a->used >= TOOM_SQR_CUTOFF) { 27 | res = mp_toom_sqr(a, b); 28 | /* Karatsuba? */ 29 | } else 30 | #endif 31 | #ifdef BN_MP_KARATSUBA_SQR_C 32 | if (a->used >= KARATSUBA_SQR_CUTOFF) { 33 | res = mp_karatsuba_sqr (a, b); 34 | } else 35 | #endif 36 | { 37 | #ifdef BN_FAST_S_MP_SQR_C 38 | /* can we use the fast comba multiplier? */ 39 | if ((a->used * 2 + 1) < MP_WARRAY && 40 | a->used < 41 | (1 << (sizeof(mp_word) * CHAR_BIT - 2*DIGIT_BIT - 1))) { 42 | res = fast_s_mp_sqr (a, b); 43 | } else 44 | #endif 45 | #ifdef BN_S_MP_SQR_C 46 | res = s_mp_sqr (a, b); 47 | #else 48 | res = MP_VAL; 49 | #endif 50 | } 51 | b->sign = MP_ZPOS; 52 | return res; 53 | } 54 | #endif 55 | 56 | /* $Source: /cvs/libtom/libtommath/bn_mp_sqr.c,v $ */ 57 | /* $Revision: 1.4 $ */ 58 | /* $Date: 2006/12/28 01:25:13 $ */ 59 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_sqrmod.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_SQRMOD_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* c = a * a (mod b) */ 19 | int 20 | mp_sqrmod (mp_int * a, mp_int * b, mp_int * c) 21 | { 22 | int res; 23 | mp_int t; 24 | 25 | if ((res = mp_init (&t)) != MP_OKAY) { 26 | return res; 27 | } 28 | 29 | if ((res = mp_sqr (a, &t)) != MP_OKAY) { 30 | mp_clear (&t); 31 | return res; 32 | } 33 | res = mp_mod (&t, b, c); 34 | mp_clear (&t); 35 | return res; 36 | } 37 | #endif 38 | 39 | /* $Source: /cvs/libtom/libtommath/bn_mp_sqrmod.c,v $ */ 40 | /* $Revision: 1.4 $ */ 41 | /* $Date: 2006/12/28 01:25:13 $ */ 42 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_submod.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_SUBMOD_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* d = a - b (mod c) */ 19 | int 20 | mp_submod (mp_int * a, mp_int * b, mp_int * c, mp_int * d) 21 | { 22 | int res; 23 | mp_int t; 24 | 25 | 26 | if ((res = mp_init (&t)) != MP_OKAY) { 27 | return res; 28 | } 29 | 30 | if ((res = mp_sub (a, b, &t)) != MP_OKAY) { 31 | mp_clear (&t); 32 | return res; 33 | } 34 | res = mp_mod (&t, c, d); 35 | mp_clear (&t); 36 | return res; 37 | } 38 | #endif 39 | 40 | /* $Source: /cvs/libtom/libtommath/bn_mp_submod.c,v $ */ 41 | /* $Revision: 1.4 $ */ 42 | /* $Date: 2006/12/28 01:25:13 $ */ 43 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_to_signed_bin.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_TO_SIGNED_BIN_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* store in signed [big endian] format */ 19 | int mp_to_signed_bin (mp_int * a, unsigned char *b) 20 | { 21 | int res; 22 | 23 | if ((res = mp_to_unsigned_bin (a, b + 1)) != MP_OKAY) { 24 | return res; 25 | } 26 | b[0] = (unsigned char) ((a->sign == MP_ZPOS) ? 0 : 1); 27 | return MP_OKAY; 28 | } 29 | #endif 30 | 31 | /* $Source: /cvs/libtom/libtommath/bn_mp_to_signed_bin.c,v $ */ 32 | /* $Revision: 1.4 $ */ 33 | /* $Date: 2006/12/28 01:25:13 $ */ 34 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_to_signed_bin_n.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_TO_SIGNED_BIN_N_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* store in signed [big endian] format */ 19 | int mp_to_signed_bin_n (mp_int * a, unsigned char *b, unsigned long *outlen) 20 | { 21 | if (*outlen < (unsigned long)mp_signed_bin_size(a)) { 22 | return MP_VAL; 23 | } 24 | *outlen = mp_signed_bin_size(a); 25 | return mp_to_signed_bin(a, b); 26 | } 27 | #endif 28 | 29 | /* $Source: /cvs/libtom/libtommath/bn_mp_to_signed_bin_n.c,v $ */ 30 | /* $Revision: 1.4 $ */ 31 | /* $Date: 2006/12/28 01:25:13 $ */ 32 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_to_unsigned_bin.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_TO_UNSIGNED_BIN_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* store in unsigned [big endian] format */ 19 | int mp_to_unsigned_bin (mp_int * a, unsigned char *b) 20 | { 21 | int x, res; 22 | mp_int t; 23 | 24 | if ((res = mp_init_copy (&t, a)) != MP_OKAY) { 25 | return res; 26 | } 27 | 28 | x = 0; 29 | while (mp_iszero (&t) == 0) { 30 | #ifndef MP_8BIT 31 | b[x++] = (unsigned char) (t.dp[0] & 255); 32 | #else 33 | b[x++] = (unsigned char) (t.dp[0] | ((t.dp[1] & 0x01) << 7)); 34 | #endif 35 | if ((res = mp_div_2d (&t, 8, &t, NULL)) != MP_OKAY) { 36 | mp_clear (&t); 37 | return res; 38 | } 39 | } 40 | bn_reverse (b, x); 41 | mp_clear (&t); 42 | return MP_OKAY; 43 | } 44 | #endif 45 | 46 | /* $Source: /cvs/libtom/libtommath/bn_mp_to_unsigned_bin.c,v $ */ 47 | /* $Revision: 1.4 $ */ 48 | /* $Date: 2006/12/28 01:25:13 $ */ 49 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_to_unsigned_bin_n.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_TO_UNSIGNED_BIN_N_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* store in unsigned [big endian] format */ 19 | int mp_to_unsigned_bin_n (mp_int * a, unsigned char *b, unsigned long *outlen) 20 | { 21 | if (*outlen < (unsigned long)mp_unsigned_bin_size(a)) { 22 | return MP_VAL; 23 | } 24 | *outlen = mp_unsigned_bin_size(a); 25 | return mp_to_unsigned_bin(a, b); 26 | } 27 | #endif 28 | 29 | /* $Source: /cvs/libtom/libtommath/bn_mp_to_unsigned_bin_n.c,v $ */ 30 | /* $Revision: 1.4 $ */ 31 | /* $Date: 2006/12/28 01:25:13 $ */ 32 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_unsigned_bin_size.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_UNSIGNED_BIN_SIZE_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* get the size for an unsigned equivalent */ 19 | int mp_unsigned_bin_size (mp_int * a) 20 | { 21 | int size = mp_count_bits (a); 22 | return (size / 8 + ((size & 7) != 0 ? 1 : 0)); 23 | } 24 | #endif 25 | 26 | /* $Source: /cvs/libtom/libtommath/bn_mp_unsigned_bin_size.c,v $ */ 27 | /* $Revision: 1.4 $ */ 28 | /* $Date: 2006/12/28 01:25:13 $ */ 29 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_xor.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_XOR_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* XOR two ints together */ 19 | int 20 | mp_xor (mp_int * a, mp_int * b, mp_int * c) 21 | { 22 | int res, ix, px; 23 | mp_int t, *x; 24 | 25 | if (a->used > b->used) { 26 | if ((res = mp_init_copy (&t, a)) != MP_OKAY) { 27 | return res; 28 | } 29 | px = b->used; 30 | x = b; 31 | } else { 32 | if ((res = mp_init_copy (&t, b)) != MP_OKAY) { 33 | return res; 34 | } 35 | px = a->used; 36 | x = a; 37 | } 38 | 39 | for (ix = 0; ix < px; ix++) { 40 | t.dp[ix] ^= x->dp[ix]; 41 | } 42 | mp_clamp (&t); 43 | mp_exch (c, &t); 44 | mp_clear (&t); 45 | return MP_OKAY; 46 | } 47 | #endif 48 | 49 | /* $Source: /cvs/libtom/libtommath/bn_mp_xor.c,v $ */ 50 | /* $Revision: 1.4 $ */ 51 | /* $Date: 2006/12/28 01:25:13 $ */ 52 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_mp_zero.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_MP_ZERO_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* set to zero */ 19 | void mp_zero (mp_int * a) 20 | { 21 | int n; 22 | mp_digit *tmp; 23 | 24 | a->sign = MP_ZPOS; 25 | a->used = 0; 26 | 27 | tmp = a->dp; 28 | for (n = 0; n < a->alloc; n++) { 29 | *tmp++ = 0; 30 | } 31 | } 32 | #endif 33 | 34 | /* $Source: /cvs/libtom/libtommath/bn_mp_zero.c,v $ */ 35 | /* $Revision: 1.4 $ */ 36 | /* $Date: 2006/12/28 01:25:13 $ */ 37 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bn_reverse.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BN_REVERSE_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* reverse an array, used for radix code */ 19 | void 20 | bn_reverse (unsigned char *s, int len) 21 | { 22 | int ix, iy; 23 | unsigned char t; 24 | 25 | ix = 0; 26 | iy = len - 1; 27 | while (ix < iy) { 28 | t = s[ix]; 29 | s[ix] = s[iy]; 30 | s[iy] = t; 31 | ++ix; 32 | --iy; 33 | } 34 | } 35 | #endif 36 | 37 | /* $Source: /cvs/libtom/libtommath/bn_reverse.c,v $ */ 38 | /* $Revision: 1.4 $ */ 39 | /* $Date: 2006/12/28 01:25:13 $ */ 40 | -------------------------------------------------------------------------------- /lib/StormLib/src/libtommath/bncore.c: -------------------------------------------------------------------------------- 1 | #include "tommath.h" 2 | #ifdef BNCORE_C 3 | /* LibTomMath, multiple-precision integer library -- Tom St Denis 4 | * 5 | * LibTomMath is a library that provides multiple-precision 6 | * integer arithmetic as well as number theoretic functionality. 7 | * 8 | * The library was designed directly after the MPI library by 9 | * Michael Fromberger but has been written from scratch with 10 | * additional optimizations in place. 11 | * 12 | * The library is free for all purposes without any express 13 | * guarantee it works. 14 | * 15 | * Tom St Denis, tomstdenis@gmail.com, http://libtom.org 16 | */ 17 | 18 | /* Known optimal configurations 19 | 20 | CPU /Compiler /MUL CUTOFF/SQR CUTOFF 21 | ------------------------------------------------------------- 22 | Intel P4 Northwood /GCC v3.4.1 / 88/ 128/LTM 0.32 ;-) 23 | AMD Athlon64 /GCC v3.4.4 / 80/ 120/LTM 0.35 24 | 25 | */ 26 | 27 | int KARATSUBA_MUL_CUTOFF = 80, /* Min. number of digits before Karatsuba multiplication is used. */ 28 | KARATSUBA_SQR_CUTOFF = 120, /* Min. number of digits before Karatsuba squaring is used. */ 29 | 30 | TOOM_MUL_CUTOFF = 350, /* no optimal values of these are known yet so set em high */ 31 | TOOM_SQR_CUTOFF = 400; 32 | #endif 33 | 34 | /* $Source: /cvs/libtom/libtommath/bncore.c,v $ */ 35 | /* $Revision: 1.5 $ */ 36 | /* $Date: 2006/12/28 01:25:13 $ */ 37 | -------------------------------------------------------------------------------- /lib/StormLib/src/lzma/info.txt: -------------------------------------------------------------------------------- 1 | Taken from LZMA SDK v 9.11 -------------------------------------------------------------------------------- /lib/StormLib/src/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by DllMain.rc 4 | // 5 | 6 | // Next default values for new objects 7 | // 8 | #ifdef APSTUDIO_INVOKED 9 | #ifndef APSTUDIO_READONLY_SYMBOLS 10 | #define _APS_NEXT_RESOURCE_VALUE 101 11 | #define _APS_NEXT_COMMAND_VALUE 40001 12 | #define _APS_NEXT_CONTROL_VALUE 1000 13 | #define _APS_NEXT_SYMED_VALUE 101 14 | #endif 15 | #endif 16 | -------------------------------------------------------------------------------- /lib/StormLib/src/sparse/sparse.h: -------------------------------------------------------------------------------- 1 | /*****************************************************************************/ 2 | /* sparse.h Copyright (c) Ladislav Zezula 2010 */ 3 | /*---------------------------------------------------------------------------*/ 4 | /* implementation of Sparse compression, used in Starcraft II */ 5 | /*---------------------------------------------------------------------------*/ 6 | /* Date Ver Who Comment */ 7 | /* -------- ---- --- ------- */ 8 | /* 05.03.10 1.00 Lad The first version of sparse.h */ 9 | /*****************************************************************************/ 10 | 11 | #ifndef __SPARSE_H__ 12 | #define __SPARSE_H__ 13 | 14 | void CompressSparse(void * pvOutBuffer, int * pcbOutBuffer, void * pvInBuffer, int cbInBuffer); 15 | int DecompressSparse(void * pvOutBuffer, int * pcbOutBuffer, void * pvInBuffer, int cbInBuffer); 16 | 17 | #endif // __SPARSE_H__ 18 | -------------------------------------------------------------------------------- /lib/StormLib/src/wdk/sources-cpp.cpp: -------------------------------------------------------------------------------- 1 | // This is a source file for WDK build of StormLib 2 | // It is copied to the root folder during the build process 3 | 4 | #include "src\adpcm\adpcm.cpp" 5 | #include "src\huffman\huff.cpp" 6 | #include "src\sparse\sparse.cpp" 7 | 8 | #include "src\FileStream.cpp" 9 | #include "src\SBaseCommon.cpp" 10 | #include "src\SBaseDumpData.cpp" 11 | #include "src\SBaseFileTable.cpp" 12 | #include "src\SBaseSubTypes.cpp" 13 | #include "src\SCompression.cpp" 14 | #include "src\SFileAddFile.cpp" 15 | #include "src\SFileAttributes.cpp" 16 | #include "src\SFileCompactArchive.cpp" 17 | #include "src\SFileCreateArchive.cpp" 18 | #include "src\SFileExtractFile.cpp" 19 | #include "src\SFileFindFile.cpp" 20 | #include "src\SFileGetFileInfo.cpp" 21 | #include "src\SFileListFile.cpp" 22 | #include "src\SFileOpenArchive.cpp" 23 | #include "src\SFileOpenFileEx.cpp" 24 | #include "src\SFilePatchArchives.cpp" 25 | #include "src\SFileReadFile.cpp" 26 | #include "src\SFileVerify.cpp" 27 | -------------------------------------------------------------------------------- /lib/StormLib/src/wdk/sources-wdk-bzip2.c: -------------------------------------------------------------------------------- 1 | // This is a source file for WDK build of StormLib 2 | // It is copied to the root folder during the build process 3 | 4 | #pragma warning(disable: 4242) // '=' : conversion from 'Int32' to 'UChar', possible loss of data 5 | #pragma warning(disable: 4244) // '=' : conversion from '__int64' to 'Int32', possible loss of data 6 | 7 | #include "src\bzip2\blocksort.c" 8 | #include "src\bzip2\bzlib.c" 9 | #include "src\bzip2\compress.c" 10 | #include "src\bzip2\crctable.c" 11 | #include "src\bzip2\decompress.c" 12 | #include "src\bzip2\huffman.c" 13 | #include "src\bzip2\randtable.c" 14 | -------------------------------------------------------------------------------- /lib/StormLib/src/wdk/sources-wdk-ltc.c: -------------------------------------------------------------------------------- 1 | // This is a source file for WDK build of StormLib 2 | // It is copied to the root folder during the build process 3 | 4 | #include "src\libtomcrypt\src\math\ltm_desc.c" 5 | -------------------------------------------------------------------------------- /lib/StormLib/src/wdk/sources-wdk-lzma.c: -------------------------------------------------------------------------------- 1 | // This is a source file for WDK build of StormLib 2 | // It is copied to the root folder during the build process 3 | 4 | #include "src\lzma\C\LzFind.c" 5 | #include "src\lzma\C\LzFindMt.c" 6 | #include "src\lzma\C\LzmaDec.c" 7 | #include "src\lzma\C\LzmaEnc.c" 8 | #include "src\lzma\C\Threads.c" 9 | -------------------------------------------------------------------------------- /lib/StormLib/src/wdk/sources-wdk-misc.c: -------------------------------------------------------------------------------- 1 | // This is a source file for WDK build of StormLib 2 | // It is copied to the root folder during the build process 3 | 4 | #include "src\jenkins\lookup3.c" 5 | #include "src\pklib\explode.c" 6 | #include "src\pklib\implode.c" 7 | -------------------------------------------------------------------------------- /lib/StormLib/src/wdk/sources-wdk-zlib.c: -------------------------------------------------------------------------------- 1 | // This is a source file for WDK build of StormLib 2 | // It is copied to the root folder during the build process 3 | 4 | #pragma warning(disable:4242) // deflate.c(1693) : warning C4242: '=' : conversion from 'unsigned int' to 'Bytef', possible loss of data 5 | 6 | #define NO_DUMMY_DECL 7 | #define NO_GZIP 8 | #include "src\zlib\adler32.c" 9 | #undef DO1 10 | #undef DO8 11 | #undef MIN 12 | #include "src\zlib\compress.c" 13 | #include "src\zlib\crc32.c" 14 | #include "src\zlib\deflate.c" 15 | #include "src\zlib\trees.c" 16 | #include "src\zlib\zutil.c" 17 | 18 | #undef COPY // Conflicting definition 19 | #include "src\zlib\inflate.c" 20 | #include "src\zlib\inffast.c" 21 | #include "src\zlib\inftrees.c" 22 | -------------------------------------------------------------------------------- /lib/StormLib/src/zlib/compress_zlib.c: -------------------------------------------------------------------------------- 1 | // Some compilers (e.g. Visual Studio 2012) don't like the name conflict between 2 | // zlib\compress.c and bzip2\compress.c. This file is plain wrapper for compress.c 3 | // in order to create obj file with a different name. 4 | 5 | #include "compress.c" 6 | -------------------------------------------------------------------------------- /lib/StormLib/src/zlib/inffast.h: -------------------------------------------------------------------------------- 1 | /* inffast.h -- header to use inffast.c 2 | * Copyright (C) 1995-2003, 2010 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start)); 12 | -------------------------------------------------------------------------------- /lib/StormLib/storm_dll/storm.def: -------------------------------------------------------------------------------- 1 | ; Storm definition file with alternate Storm.dll names 2 | LIBRARY "Storm" 3 | 4 | EXPORTS 5 | StormCloseArchive @252 ; 0x0FC 6 | StormCloseFile @253 ; 0x0FD 7 | StormDestroy @262 ; 0x106 8 | StormGetFileArchive @264 ; 0x108 9 | StormGetFileSize @265 ; 0x109 10 | StormOpenArchive @266 ; 0x10A 11 | StormOpenFile @267 ; 0x10B 12 | StormOpenFileEx @268 ; 0x10C 13 | StormReadFile @269 ; 0x10D 14 | StormSetBasePath @270 ; 0x10E 15 | StormSetFilePointer @271 ; 0x10F 16 | StormSetLocale @272 ; 0x110 17 | StormGetBasePath @273 ; 0x111 18 | StormGetArchiveName @275 ; 0x113 19 | StormGetFileName @276 ; 0x114 20 | 21 | ; StormSetLastError @465 ; 0x 22 | 23 | StormCompress @551 ; 0x227 24 | StormDecompress @552 ; 0x228 25 | -------------------------------------------------------------------------------- /lib/StormLib/storm_dll/storm.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | 14 | 15 | Source Files 16 | 17 | 18 | 19 | 20 | Source Files 21 | 22 | 23 | 24 | 25 | Header Files 26 | 27 | 28 | -------------------------------------------------------------------------------- /lib/StormLib/storm_dll/storm_test.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {10b55df7-950e-4099-ab74-ee928278fc62} 10 | 11 | 12 | 13 | 14 | Source Files 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | -------------------------------------------------------------------------------- /lib/binarytools/BinaryReader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include "lib/binarytools/endianness.h" 7 | #include "lib/binarytools/Stream.h" 8 | 9 | class BinaryReader; 10 | 11 | namespace LUS { 12 | 13 | class BinaryReader { 14 | public: 15 | BinaryReader(char* nBuffer, size_t nBufferSize); 16 | BinaryReader(uint8_t* nBuffer, size_t nBufferSize); 17 | BinaryReader(Stream* nStream); 18 | BinaryReader(std::shared_ptr nStream); 19 | 20 | void Close(); 21 | 22 | void SetEndianness(Torch::Endianness endianness); 23 | Torch::Endianness GetEndianness() const; 24 | 25 | void Seek(int32_t offset, SeekOffsetType seekType); 26 | uint32_t GetBaseAddress(); 27 | size_t GetLength(); 28 | 29 | void Read(int32_t length); 30 | void Read(char* buffer, int32_t length); 31 | char ReadChar(); 32 | int8_t ReadInt8(); 33 | int16_t ReadInt16(); 34 | int32_t ReadInt32(); 35 | uint8_t ReadUByte(); 36 | uint16_t ReadUInt16(); 37 | uint32_t ReadUInt32(); 38 | uint64_t ReadUInt64(); 39 | unsigned short ReadUShort(); 40 | short ReadShort(); 41 | float ReadFloat(); 42 | double ReadDouble(); 43 | std::string ReadString(); 44 | std::string ReadCString(); 45 | 46 | std::vector ToVector(); 47 | 48 | protected: 49 | std::shared_ptr mStream; 50 | Torch::Endianness mEndianness = Torch::Endianness::Native; 51 | }; 52 | } // namespace LUS 53 | -------------------------------------------------------------------------------- /lib/binarytools/BinaryWriter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "lib/binarytools/endianness.h" 8 | #include "lib/binarytools/Stream.h" 9 | 10 | namespace LUS { 11 | class BinaryWriter { 12 | public: 13 | BinaryWriter(); 14 | BinaryWriter(Stream* nStream); 15 | BinaryWriter(std::shared_ptr nStream); 16 | 17 | void SetEndianness(Torch::Endianness endianness); 18 | 19 | std::shared_ptr GetStream(); 20 | uint64_t GetBaseAddress(); 21 | uint64_t GetLength(); 22 | void Seek(int32_t offset, SeekOffsetType seekType); 23 | void Close(); 24 | 25 | void Write(int8_t value); 26 | void Write(uint8_t value); 27 | void Write(int16_t value); 28 | void Write(uint16_t value); 29 | void Write(int32_t value); 30 | void Write(int32_t valueA, int32_t valueB); 31 | void Write(uint32_t value); 32 | void Write(int64_t value); 33 | void Write(uint64_t value); 34 | void Write(float value); 35 | void Write(double value); 36 | void Write(const std::string& str, bool writeLength = true); 37 | void Write(char* srcBuffer, size_t length); 38 | void WriteByte(char value); 39 | 40 | std::vector ToVector(); 41 | 42 | void Finish(std::ostream &output); 43 | 44 | protected: 45 | std::shared_ptr mStream; 46 | Torch::Endianness mEndianness = Torch::Endianness::Native; 47 | 48 | }; 49 | } // namespace LUS 50 | -------------------------------------------------------------------------------- /lib/binarytools/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.12) 2 | project(BinaryTools) 3 | 4 | set(CMAKE_CXX_STANDARD 20) 5 | 6 | file(GLOB CXX_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) 7 | set(SRC_DIR ${CXX_FILES}) 8 | 9 | add_library(${PROJECT_NAME} STATIC ${SRC_DIR}) 10 | target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) -------------------------------------------------------------------------------- /lib/binarytools/MemoryStream.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "Stream.h" 6 | 7 | namespace LUS { 8 | class MemoryStream : public Stream { 9 | public: 10 | MemoryStream(); 11 | MemoryStream(char* nBuffer, size_t nBufferSize); 12 | ~MemoryStream(); 13 | 14 | uint64_t GetLength() override; 15 | 16 | void Seek(int32_t offset, SeekOffsetType seekType) override; 17 | 18 | std::unique_ptr Read(size_t length) override; 19 | void Read(const char* dest, size_t length) override; 20 | int8_t ReadByte() override; 21 | 22 | void Write(char* srcBuffer, size_t length) override; 23 | void WriteByte(int8_t value) override; 24 | 25 | std::vector ToVector() override; 26 | 27 | void Flush() override; 28 | void Close() override; 29 | 30 | protected: 31 | std::vector mBuffer; 32 | std::size_t mBufferSize; 33 | }; 34 | } // namespace LUS 35 | -------------------------------------------------------------------------------- /lib/binarytools/PathHelper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "Utils/StringHelper.h" 6 | 7 | #if __has_include() 8 | #include 9 | namespace fs = std::filesystem; 10 | #else 11 | #include 12 | namespace fs = std::experimental::filesystem; 13 | #endif 14 | 15 | namespace LUS { 16 | class PathHelper { 17 | public: 18 | static std::string GetFileName(const fs::path& input) { 19 | // https://en.cppreference.com/w/cpp/filesystem/path/filename 20 | return input.filename().string(); 21 | }; 22 | 23 | static std::string GetFileNameWithoutExtension(const fs::path& input) { 24 | // https://en.cppreference.com/w/cpp/filesystem/path/stem 25 | return input.stem().string(); 26 | }; 27 | 28 | static std::string GetFileNameExtension(const std::string& input) { 29 | return input.substr(input.find_last_of("."), input.length()); 30 | }; 31 | 32 | static fs::path GetPath(const std::string& input) { 33 | std::vector split = StringHelper::Split(input, "/"); 34 | fs::path output; 35 | 36 | for (std::string str : split) { 37 | if (str.find_last_of(".") == std::string::npos) { 38 | output /= str; 39 | } 40 | } 41 | 42 | return output; 43 | }; 44 | 45 | static fs::path GetDirectoryName(const fs::path& path) { 46 | return path.parent_path(); 47 | }; 48 | }; 49 | } // namespace LUS 50 | -------------------------------------------------------------------------------- /lib/binarytools/Stream.cpp: -------------------------------------------------------------------------------- 1 | #include "Stream.h" 2 | 3 | uint64_t LUS::Stream::GetBaseAddress() { 4 | return mBaseAddress; 5 | } 6 | -------------------------------------------------------------------------------- /lib/binarytools/Stream.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace LUS { 8 | enum class SeekOffsetType { Start, Current, End }; 9 | 10 | class Stream { 11 | public: 12 | virtual ~Stream() = default; 13 | virtual uint64_t GetLength() = 0; 14 | uint64_t GetBaseAddress(); 15 | 16 | virtual void Seek(int32_t offset, SeekOffsetType seekType) = 0; 17 | 18 | virtual std::unique_ptr Read(size_t length) = 0; 19 | virtual void Read(const char* dest, size_t length) = 0; 20 | virtual int8_t ReadByte() = 0; 21 | 22 | virtual void Write(char* destBuffer, size_t length) = 0; 23 | virtual void WriteByte(int8_t value) = 0; 24 | 25 | virtual std::vector ToVector() = 0; 26 | 27 | virtual void Flush() = 0; 28 | virtual void Close() = 0; 29 | 30 | protected: 31 | uint64_t mBaseAddress; 32 | }; 33 | } // namespace LUS 34 | -------------------------------------------------------------------------------- /lib/libmio0/tkmk00.h: -------------------------------------------------------------------------------- 1 | #ifndef TKMK00_H_ 2 | #define TKMK00_H_ 3 | 4 | #include 5 | 6 | // decode TKMK00 data in memory 7 | // tkmk: buffer containing TKMK00 data 8 | // tmp_buf: tempory buffer to load pixel data (must be >= width*height bytes) 9 | // rgba: buffer to output decompressed RGBA16 data (must be >= 2*width*height bytes) 10 | // alpha_color: RGBA color to set apha to 0 11 | void tkmk00_decode(const uint8_t *tkmk, uint8_t *tmp_buf, uint8_t *rgba16, int32_t alpha_color); 12 | 13 | #endif // TKMK00_H_ 14 | -------------------------------------------------------------------------------- /lib/libyay0/yay0.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | extern uint8_t* yay0_decode(const uint8_t* in, uint32_t* out_size); -------------------------------------------------------------------------------- /lib/n64graphics/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.12) 2 | project(N64Graphics) 3 | 4 | set(CMAKE_CXX_STANDARD 20) 5 | 6 | file(GLOB CXX_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.c) 7 | set(SRC_DIR ${CXX_FILES}) 8 | 9 | add_library(${PROJECT_NAME} STATIC ${SRC_DIR}) 10 | target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) -------------------------------------------------------------------------------- /src/archive/BinaryWrapper.cpp: -------------------------------------------------------------------------------- 1 | #include "BinaryWrapper.h" 2 | 3 | BinaryWrapper::BinaryWrapper(const std::string& path) : mPath(path) {} 4 | -------------------------------------------------------------------------------- /src/archive/BinaryWrapper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | class BinaryWrapper { 8 | public: 9 | BinaryWrapper() {} 10 | BinaryWrapper(const std::string& path); 11 | virtual ~BinaryWrapper() = default; 12 | 13 | virtual int32_t CreateArchive(void) = 0; 14 | virtual bool AddFile(const std::string& path, std::vector data) = 0; 15 | virtual int32_t Close(void) = 0; 16 | protected: 17 | std::mutex mMutex; 18 | std::string mPath; 19 | }; 20 | -------------------------------------------------------------------------------- /src/archive/SWrapper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "BinaryWrapper.h" 6 | #ifdef USE_STORMLIB 7 | #include 8 | #endif 9 | 10 | class SWrapper : public BinaryWrapper { 11 | public: 12 | explicit SWrapper(const std::string& path); 13 | 14 | int32_t CreateArchive(void) override; 15 | bool AddFile(const std::string& path, std::vector data) override; 16 | int32_t Close(void) override; 17 | #ifdef USE_STORMLIB 18 | private: 19 | HANDLE hMpq{}; 20 | #endif 21 | }; 22 | -------------------------------------------------------------------------------- /src/archive/ZWrapper.cpp: -------------------------------------------------------------------------------- 1 | #include "ZWrapper.h" 2 | #include 3 | #include 4 | #include 5 | 6 | #include "spdlog/spdlog.h" 7 | #include 8 | #include 9 | 10 | namespace fs = std::filesystem; 11 | 12 | ZWrapper::ZWrapper(const std::string& path) { 13 | this->mPath = path; 14 | this->mZip = new miniz_cpp::zip_file; 15 | } 16 | 17 | int32_t ZWrapper::CreateArchive() { 18 | SPDLOG_INFO("Loaded ZIP (O2R) archive: {}", mPath.c_str()); 19 | return 0; 20 | } 21 | 22 | bool ZWrapper::AddFile(const std::string& path, std::vector data) { 23 | char* fileData = data.data(); 24 | size_t fileSize = data.size(); 25 | 26 | if(Companion::Instance != nullptr && Companion::Instance->IsDebug()){ 27 | SPDLOG_INFO("Creating debug file: debug/{}", path); 28 | std::string dpath = "debug/" + path; 29 | if(!fs::exists(fs::path(dpath).parent_path())){ 30 | fs::create_directories(fs::path(dpath).parent_path()); 31 | } 32 | std::ofstream stream(dpath, std::ios::binary); 33 | stream.write(fileData, fileSize); 34 | stream.close(); 35 | } 36 | 37 | this->mZip->writebytes(path, data); 38 | return true; 39 | } 40 | 41 | int32_t ZWrapper::Close(void) { 42 | this->mZip->save(this->mPath); 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /src/archive/ZWrapper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "BinaryWrapper.h" 6 | 7 | namespace miniz_cpp { 8 | class zip_file; 9 | } 10 | 11 | class ZWrapper : public BinaryWrapper { 12 | public: 13 | explicit ZWrapper(const std::string& path); 14 | 15 | int32_t CreateArchive(void) override; 16 | bool AddFile(const std::string& path, std::vector data) override; 17 | int32_t Close(void) override; 18 | 19 | miniz_cpp::zip_file* mZip; 20 | }; 21 | -------------------------------------------------------------------------------- /src/factories/AssetArrayFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "factories/BaseFactory.h" 4 | 5 | class AssetArrayData : public IParsedData { 6 | public: 7 | std::vector mPtrs; 8 | std::string mType; 9 | 10 | AssetArrayData(std::vector ptrs, std::string type) : mPtrs(std::move(ptrs)), mType(type) {} 11 | }; 12 | 13 | class AssetArrayHeaderExporter : public BaseExporter { 14 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 15 | }; 16 | 17 | class AssetArrayBinaryExporter : public BaseExporter { 18 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 19 | }; 20 | 21 | class AssetArrayCodeExporter : public BaseExporter { 22 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 23 | }; 24 | 25 | class AssetArrayFactory : public BaseFactory { 26 | public: 27 | std::optional> parse(std::vector& buffer, YAML::Node& data) override; 28 | inline std::unordered_map> GetExporters() override { 29 | return { 30 | REGISTER(Code, AssetArrayCodeExporter) 31 | REGISTER(Header, AssetArrayHeaderExporter) 32 | REGISTER(Binary, AssetArrayBinaryExporter) 33 | }; 34 | } 35 | }; 36 | -------------------------------------------------------------------------------- /src/factories/BaseFactory.cpp: -------------------------------------------------------------------------------- 1 | #include "BaseFactory.h" 2 | 3 | void BaseExporter::WriteHeader(LUS::BinaryWriter &writer, Torch::ResourceType resType, int32_t version) { 4 | writer.Write((int8_t)(Torch::Endianness::Native)); // 0x00 - Endianness 5 | writer.Write((int8_t)0); // 0x01 - Is Asset Custom 6 | writer.Write((int8_t)0); // 0x02 - 7 | writer.Write((int8_t)0); // 0x03 8 | writer.Write((uint32_t) resType); // 0x04 9 | writer.Write((uint32_t) version); // 0x08 10 | writer.Write((uint64_t) 0xDEADBEEFDEADBEEF); // id, 0x0C 11 | writer.Write((uint32_t) 0); // 0x10 12 | writer.Write((uint64_t) 0); // ROM CRC, 0x14 13 | writer.Write((uint32_t) 0); // ROM Enum, 0x1C 14 | 15 | while (writer.GetBaseAddress() < 0x40) 16 | writer.Write((uint32_t)0); // To be used at a later date! 17 | } -------------------------------------------------------------------------------- /src/factories/BlobFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "BaseFactory.h" 4 | #include "../types/RawBuffer.h" 5 | 6 | class BlobHeaderExporter : public BaseExporter { 7 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 8 | }; 9 | 10 | class BlobBinaryExporter : public BaseExporter { 11 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 12 | }; 13 | 14 | class BlobCodeExporter : public BaseExporter { 15 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 16 | }; 17 | 18 | class BlobFactory : public BaseFactory { 19 | public: 20 | std::optional> parse(std::vector& buffer, YAML::Node& data) override; 21 | inline std::unordered_map> GetExporters() override { 22 | return { 23 | REGISTER(Header, BlobHeaderExporter) 24 | REGISTER(Binary, BlobBinaryExporter) 25 | REGISTER(Code, BlobCodeExporter) 26 | }; 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /src/factories/DisplayListFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "BaseFactory.h" 4 | #include "n64/CommandMacros.h" 5 | #include 6 | 7 | class DListData : public IParsedData { 8 | public: 9 | std::vector mGfxs; 10 | 11 | DListData() {} 12 | DListData(std::vector gfxs) : mGfxs(gfxs) {} 13 | }; 14 | 15 | class DListHeaderExporter : public BaseExporter { 16 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 17 | }; 18 | 19 | class DListBinaryExporter : public BaseExporter { 20 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 21 | }; 22 | 23 | #ifdef STANDALONE 24 | class DListCodeExporter : public BaseExporter { 25 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 26 | }; 27 | #endif 28 | 29 | class DListFactory : public BaseFactory { 30 | public: 31 | std::optional> parse(std::vector& buffer, YAML::Node& data) override; 32 | std::unordered_map> GetExporters() override { 33 | return { 34 | REGISTER(Header, DListHeaderExporter) 35 | REGISTER(Binary, DListBinaryExporter) 36 | #ifdef STANDALONE 37 | REGISTER(Code, DListCodeExporter) 38 | #endif 39 | }; 40 | } 41 | uint32_t GetAlignment() override { 42 | return 8; 43 | } 44 | }; 45 | -------------------------------------------------------------------------------- /src/factories/DisplayListOverrides.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "DisplayListFactory.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | typedef struct { 10 | uint32_t w0; 11 | uint32_t w1; 12 | } N64Words; 13 | 14 | typedef union { 15 | N64Words words; 16 | long long int force_structure_alignment; 17 | } N64Gfx; 18 | 19 | typedef struct { 20 | int16_t ob[3]; 21 | uint16_t flag; 22 | int16_t tc[2]; 23 | unsigned char cn[4]; 24 | } N64Vtx_t; 25 | 26 | typedef struct { 27 | int16_t ob[3]; 28 | uint16_t flag; 29 | int16_t tc[2]; 30 | signed char n[3]; 31 | unsigned char a; 32 | } N64Vtx_tn; 33 | 34 | typedef union { 35 | N64Vtx_t v; 36 | N64Vtx_tn n; 37 | } N64Vtx; 38 | 39 | namespace GFXDOverride { 40 | #ifdef STANDALONE 41 | void Quadrangle(const N64Gfx* gfx); 42 | void Triangle2(const N64Gfx* gfx); 43 | int Vtx(uint32_t vtx, int32_t num); 44 | int Texture(uint32_t timg, int32_t fmt, int32_t siz, int32_t width, int32_t height, int32_t pal); 45 | int Palette(uint32_t tlut, int32_t idx, int32_t count); 46 | int Lights(uint32_t lightsn, int32_t count); 47 | int Light(uint32_t light); 48 | int DisplayList(uint32_t dl); 49 | int Viewport(uint32_t vp); 50 | int Matrix(uint32_t mtx); 51 | #endif 52 | void RegisterVTXOverlap(uint32_t ptr, std::tuple& vtx); 53 | std::optional> GetVtxOverlap(uint32_t ptr); 54 | void ClearVtx(); 55 | }; -------------------------------------------------------------------------------- /src/factories/FloatFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "BaseFactory.h" 4 | 5 | class FloatData : public IParsedData { 6 | public: 7 | std::vector mFloats; 8 | 9 | explicit FloatData(std::vector floats) : mFloats(floats) {} 10 | }; 11 | 12 | class FloatHeaderExporter : public BaseExporter { 13 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 14 | }; 15 | 16 | class FloatBinaryExporter : public BaseExporter { 17 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 18 | }; 19 | 20 | class FloatCodeExporter : public BaseExporter { 21 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 22 | }; 23 | 24 | class FloatFactory : public BaseFactory { 25 | public: 26 | std::optional> parse(std::vector& buffer, YAML::Node& data) override; 27 | std::optional> parse_modding(std::vector& buffer, YAML::Node& data) override { 28 | return std::nullopt; 29 | } 30 | inline std::unordered_map> GetExporters() override { 31 | return { 32 | REGISTER(Code, FloatCodeExporter) 33 | REGISTER(Header, FloatHeaderExporter) 34 | REGISTER(Binary, FloatBinaryExporter) 35 | }; 36 | } 37 | }; -------------------------------------------------------------------------------- /src/factories/IncludeFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "BaseFactory.h" 4 | 5 | class IncludeData : public IParsedData { 6 | public: 7 | uint32_t blanks; 8 | 9 | explicit IncludeData(uint32_t blank) : blanks(blank) {} 10 | }; 11 | 12 | class IncludeHeaderExporter : public BaseExporter { 13 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 14 | }; 15 | 16 | class IncludeBinaryExporter : public BaseExporter { 17 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 18 | }; 19 | 20 | class IncludeCodeExporter : public BaseExporter { 21 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 22 | }; 23 | 24 | class IncludeFactory : public BaseFactory { 25 | public: 26 | std::optional> parse(std::vector& buffer, YAML::Node& data) override; 27 | inline std::unordered_map> GetExporters() override { 28 | return { 29 | REGISTER(Code, IncludeCodeExporter) 30 | REGISTER(Header, IncludeHeaderExporter) 31 | }; 32 | } 33 | uint32_t GetAlignment() override { 34 | return 8; 35 | }; 36 | }; 37 | -------------------------------------------------------------------------------- /src/factories/Vec3fFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "BaseFactory.h" 4 | #include "types/Vec3D.h" 5 | 6 | class Vec3fData : public IParsedData { 7 | public: 8 | std::vector mVecs; 9 | int mMaxWidth; 10 | int mMaxPrec; 11 | 12 | explicit Vec3fData(std::vector vecs); 13 | }; 14 | 15 | class Vec3fHeaderExporter : public BaseExporter { 16 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 17 | }; 18 | 19 | class Vec3fBinaryExporter : public BaseExporter { 20 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 21 | }; 22 | 23 | class Vec3fCodeExporter : public BaseExporter { 24 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 25 | }; 26 | 27 | class Vec3fFactory : public BaseFactory { 28 | public: 29 | std::optional> parse(std::vector& buffer, YAML::Node& data) override; 30 | inline std::unordered_map> GetExporters() override { 31 | return { 32 | REGISTER(Code, Vec3fCodeExporter) 33 | REGISTER(Header, Vec3fHeaderExporter) 34 | REGISTER(Binary, Vec3fBinaryExporter) 35 | }; 36 | } 37 | }; 38 | -------------------------------------------------------------------------------- /src/factories/Vec3sFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "BaseFactory.h" 4 | #include "types/Vec3D.h" 5 | 6 | class Vec3sData : public IParsedData { 7 | public: 8 | std::vector mVecs; 9 | int mMaxWidth; 10 | 11 | explicit Vec3sData(std::vector vecs); 12 | }; 13 | 14 | class Vec3sHeaderExporter : public BaseExporter { 15 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 16 | }; 17 | 18 | class Vec3sBinaryExporter : public BaseExporter { 19 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 20 | }; 21 | 22 | class Vec3sCodeExporter : public BaseExporter { 23 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 24 | }; 25 | 26 | class Vec3sFactory : public BaseFactory { 27 | public: 28 | std::optional> parse(std::vector& buffer, YAML::Node& data) override; 29 | inline std::unordered_map> GetExporters() override { 30 | return { 31 | REGISTER(Code, Vec3sCodeExporter) 32 | REGISTER(Header, Vec3sHeaderExporter) 33 | REGISTER(Binary, Vec3sBinaryExporter) 34 | }; 35 | } 36 | }; 37 | -------------------------------------------------------------------------------- /src/factories/ViewportFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "BaseFactory.h" 4 | 5 | typedef struct { 6 | int16_t vscale[4]; /* scale */ 7 | int16_t vtrans[4]; /* translate */ 8 | } VpRaw; 9 | 10 | class VpData : public IParsedData { 11 | public: 12 | VpRaw mViewport; 13 | 14 | VpData(VpRaw viewport) : mViewport(std::move(viewport)) {} 15 | }; 16 | 17 | class ViewportHeaderExporter : public BaseExporter { 18 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 19 | }; 20 | 21 | class ViewportBinaryExporter : public BaseExporter { 22 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 23 | }; 24 | 25 | class ViewportCodeExporter : public BaseExporter { 26 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 27 | }; 28 | 29 | class ViewportFactory : public BaseFactory { 30 | public: 31 | std::optional> parse(std::vector& buffer, YAML::Node& data) override; 32 | inline std::unordered_map> GetExporters() override { 33 | return { 34 | REGISTER(Code, ViewportCodeExporter) 35 | REGISTER(Header, ViewportHeaderExporter) 36 | REGISTER(Binary, ViewportBinaryExporter) 37 | }; 38 | } 39 | }; 40 | -------------------------------------------------------------------------------- /src/factories/VtxFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "BaseFactory.h" 4 | 5 | struct VtxRaw { 6 | int16_t ob[3]; /* x, y, z */ 7 | uint16_t flag; 8 | int16_t tc[2]; /* texture coord */ 9 | uint8_t cn[4]; /* color & alpha */ 10 | }; 11 | 12 | class VtxData : public IParsedData { 13 | public: 14 | std::vector mVtxs; 15 | 16 | explicit VtxData(std::vector vtxs) : mVtxs(vtxs) {} 17 | }; 18 | 19 | class VtxHeaderExporter : public BaseExporter { 20 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 21 | }; 22 | 23 | class VtxBinaryExporter : public BaseExporter { 24 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 25 | }; 26 | 27 | class VtxCodeExporter : public BaseExporter { 28 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 29 | }; 30 | 31 | class VtxFactory : public BaseFactory { 32 | public: 33 | std::optional> parse(std::vector& buffer, YAML::Node& data) override; 34 | inline std::unordered_map> GetExporters() override { 35 | return { 36 | REGISTER(Code, VtxCodeExporter) 37 | REGISTER(Header, VtxHeaderExporter) 38 | REGISTER(Binary, VtxBinaryExporter) 39 | }; 40 | } 41 | uint32_t GetAlignment() override { 42 | return 8; 43 | }; 44 | }; -------------------------------------------------------------------------------- /src/factories/naudio/v0/AIFCDecode.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "lib/binarytools/BinaryWriter.h" 5 | 6 | void write_aiff(std::vector data, LUS::BinaryWriter& writer); -------------------------------------------------------------------------------- /src/factories/naudio/v0/AudioHeaderFactory.cpp: -------------------------------------------------------------------------------- 1 | #include "AudioHeaderFactory.h" 2 | 3 | #include 4 | #include "Companion.h" 5 | #include "AIFCDecode.h" 6 | #include "spdlog/spdlog.h" 7 | #include 8 | 9 | /* 10 | ExportResult AudioAIFCExporter::Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) { 11 | 12 | auto samples = AudioManager::Instance->get_samples(); 13 | 14 | int temp = 0; 15 | for(auto& sample : samples){ 16 | std::string dpath = Companion::Instance->GetOutputPath() + "/" + (*replacement); 17 | if(!exists(fs::path(dpath).parent_path())){ 18 | create_directories(fs::path(dpath).parent_path()); 19 | } 20 | std::ofstream file(dpath + "_bank_" + std::to_string(++temp) + ".aiff", std::ios::binary); 21 | 22 | LUS::BinaryWriter aifc = LUS::BinaryWriter(); 23 | AudioConverter::SampleV0ToAIFC(sample, aifc); 24 | 25 | LUS::BinaryWriter aiff = LUS::BinaryWriter(); 26 | write_aiff(aifc.ToVector(), aiff); 27 | aifc.Close(); 28 | aiff.Finish(file); 29 | file.close(); 30 | // SPDLOG_INFO("Exported {}", dpath + "_bank_" + std::to_string(temp) + ".aiff"); 31 | 32 | SPDLOG_INFO("sample_{}:", temp); 33 | SPDLOG_INFO(" type: NAUDIO:V0:SAMPLE"); 34 | SPDLOG_INFO(" id: {}\n", temp); 35 | } 36 | 37 | return std::nullopt; 38 | } 39 | */ 40 | 41 | std::optional> AudioHeaderFactory::parse(std::vector& buffer, YAML::Node& data) { 42 | AudioManager::Instance->initialize(buffer, data); 43 | return std::make_shared(); 44 | } -------------------------------------------------------------------------------- /src/factories/naudio/v0/AudioHeaderFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | /* 6 | class AudioAIFCExporter : public BaseExporter { 7 | public: 8 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement); 9 | }; 10 | */ 11 | 12 | class AudioDummyExporter : public BaseExporter { 13 | public: 14 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override { 15 | return std::nullopt; 16 | } 17 | }; 18 | 19 | class AudioHeaderFactory : public BaseFactory { 20 | public: 21 | std::optional> parse(std::vector& buffer, YAML::Node& data) override; 22 | std::optional> parse_modding(std::vector& buffer, YAML::Node& data) override { 23 | return std::nullopt; 24 | } 25 | std::unordered_map> GetExporters() override { 26 | return { 27 | // REGISTER(Modding, AudioGenericAIFCExporter) 28 | REGISTER(Header, AudioDummyExporter) 29 | REGISTER(Binary, AudioDummyExporter) 30 | REGISTER(Code, AudioDummyExporter) 31 | }; 32 | } 33 | bool HasModdedDependencies() override { return true; } 34 | }; -------------------------------------------------------------------------------- /src/factories/naudio/v0/BankFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include "AudioManager.h" 7 | 8 | class BankData : public IParsedData { 9 | public: 10 | Bank mBank; 11 | uint32_t mBankId; 12 | 13 | BankData(Bank bank, const uint32_t bankId) : mBank(std::move(bank)), mBankId(bankId) {} 14 | }; 15 | 16 | class BankBinaryExporter : public BaseExporter { 17 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 18 | }; 19 | 20 | class BankFactory : public BaseFactory { 21 | public: 22 | std::optional> parse(std::vector& buffer, YAML::Node& data) override; 23 | inline std::unordered_map> GetExporters() override { 24 | return { 25 | REGISTER(Binary, BankBinaryExporter) 26 | }; 27 | } 28 | }; -------------------------------------------------------------------------------- /src/factories/naudio/v0/SampleFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include "AudioManager.h" 7 | 8 | class SampleModdingExporter : public BaseExporter { 9 | public: 10 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement); 11 | }; 12 | 13 | class SampleData : public IParsedData { 14 | public: 15 | AudioBankSample mSample; 16 | 17 | explicit SampleData(AudioBankSample sample) : mSample(std::move(sample)) {} 18 | }; 19 | 20 | class SampleBinaryExporter : public BaseExporter { 21 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 22 | }; 23 | 24 | class SampleFactory : public BaseFactory { 25 | public: 26 | std::optional> parse(std::vector& buffer, YAML::Node& data) override; 27 | std::unordered_map> GetExporters() override { 28 | return { 29 | REGISTER(Modding, SampleModdingExporter) 30 | REGISTER(Binary, SampleBinaryExporter) 31 | }; 32 | } 33 | 34 | bool SupportModdedAssets() override { return true; } 35 | }; -------------------------------------------------------------------------------- /src/factories/naudio/v0/SequenceFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "types/RawBuffer.h" 5 | 6 | class SequenceData : public IParsedData { 7 | public: 8 | uint32_t mId; 9 | uint32_t mSize; 10 | std::vector mBuffer; 11 | std::vector mBanks; 12 | 13 | SequenceData(uint32_t id, uint32_t size, uint8_t* data, std::vector& banks) : mId(id), mSize(size), mBanks(banks) { 14 | mBuffer = std::vector(data, data + size); 15 | } 16 | }; 17 | 18 | class SequenceBinaryExporter : public BaseExporter { 19 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 20 | }; 21 | 22 | class SequenceModdingExporter : public BaseExporter { 23 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 24 | }; 25 | 26 | class SequenceFactory : public BaseFactory { 27 | public: 28 | std::optional> parse(std::vector& buffer, YAML::Node& data) override; 29 | std::optional> parse_modding(std::vector& buffer, YAML::Node& data) override; 30 | 31 | inline std::unordered_map> GetExporters() override { 32 | return { 33 | REGISTER(Modding, SequenceModdingExporter) 34 | REGISTER(Binary, SequenceBinaryExporter) 35 | }; 36 | } 37 | 38 | bool SupportModdedAssets() override { return true; } 39 | }; -------------------------------------------------------------------------------- /src/factories/naudio/v1/AudioConverter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | enum AIFCMagicValues { 8 | FORM = (uint32_t) 0x464f524d, 9 | AIFC = (uint32_t) 0x41494643, 10 | VAPC = (uint32_t) 0x56415043, 11 | AAPL = (uint32_t) 0x4150504c 12 | }; 13 | 14 | #define NONE 0xFFFF 15 | #define ALIGN(val, al) (size_t) ((val + (al - 1)) & -al) 16 | 17 | class AudioConverter { 18 | public: 19 | static void SampleV0ToAIFC(AudioBankSample* entry, LUS::BinaryWriter &out); 20 | static void SampleV1ToAIFC(NSampleData* tSample, LUS::BinaryWriter &out); 21 | }; 22 | 23 | struct AIFCChunk { 24 | std::string id; 25 | std::vector data; 26 | }; 27 | 28 | class AIFCWriter { 29 | public: 30 | std::vector Chunks; 31 | size_t totalSize = 0; 32 | 33 | LUS::BinaryWriter Start(){ 34 | auto writer = LUS::BinaryWriter(); 35 | writer.SetEndianness(Torch::Endianness::Big); 36 | return writer; 37 | } 38 | void End(std::string chunk, LUS::BinaryWriter& writer); 39 | void Close(LUS::BinaryWriter& out); 40 | }; -------------------------------------------------------------------------------- /src/factories/naudio/v1/BookFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "AudioContext.h" 5 | 6 | class ADPCMBookData : public IParsedData { 7 | public: 8 | int32_t order; 9 | int32_t numPredictors; 10 | std::vector book; 11 | }; 12 | 13 | class ADPCMBookHeaderExporter : public BaseExporter { 14 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 15 | }; 16 | 17 | class ADPCMBookBinaryExporter : public BaseExporter { 18 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 19 | }; 20 | 21 | class ADPCMBookCodeExporter : public BaseExporter { 22 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 23 | }; 24 | 25 | class ADPCMBookFactory : public BaseFactory { 26 | public: 27 | std::optional> parse(std::vector& buffer, YAML::Node& data) override; 28 | inline std::unordered_map> GetExporters() override { 29 | return { 30 | REGISTER(Header, ADPCMBookHeaderExporter) 31 | REGISTER(Binary, ADPCMBookBinaryExporter) 32 | REGISTER(Code, ADPCMBookCodeExporter) 33 | }; 34 | } 35 | 36 | bool HasModdedDependencies() override { return true; } 37 | }; 38 | -------------------------------------------------------------------------------- /src/factories/naudio/v1/DrumFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "AudioContext.h" 5 | 6 | class DrumData : public IParsedData { 7 | public: 8 | uint8_t adsrDecayIndex; 9 | uint8_t pan; 10 | uint8_t isRelocated; 11 | TunedSample tunedSample; 12 | uint32_t envelope; 13 | }; 14 | 15 | class DrumHeaderExporter : public BaseExporter { 16 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 17 | }; 18 | 19 | class DrumBinaryExporter : public BaseExporter { 20 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 21 | }; 22 | 23 | class DrumCodeExporter : public BaseExporter { 24 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 25 | }; 26 | 27 | class DrumFactory : public BaseFactory { 28 | public: 29 | std::optional> parse(std::vector& buffer, YAML::Node& data) override; 30 | inline std::unordered_map> GetExporters() override { 31 | return { 32 | REGISTER(Header, DrumHeaderExporter) 33 | REGISTER(Binary, DrumBinaryExporter) 34 | REGISTER(Code, DrumCodeExporter) 35 | }; 36 | } 37 | 38 | bool HasModdedDependencies() override { return true; } 39 | }; 40 | -------------------------------------------------------------------------------- /src/factories/naudio/v1/EnvelopeFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "AudioContext.h" 6 | 7 | struct EnvelopePoint { 8 | int16_t delay; 9 | int16_t arg; 10 | }; 11 | 12 | class EnvelopeData : public IParsedData { 13 | public: 14 | std::vector points; 15 | 16 | EnvelopeData(std::vector points) : points(points) {}; 17 | }; 18 | 19 | class EnvelopeHeaderExporter : public BaseExporter { 20 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 21 | }; 22 | 23 | class EnvelopeBinaryExporter : public BaseExporter { 24 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 25 | }; 26 | 27 | class EnvelopeCodeExporter : public BaseExporter { 28 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 29 | }; 30 | 31 | class EnvelopeFactory : public BaseFactory { 32 | public: 33 | std::optional> parse(std::vector& buffer, YAML::Node& data) override; 34 | inline std::unordered_map> GetExporters() override { 35 | return { 36 | REGISTER(Header, EnvelopeHeaderExporter) 37 | REGISTER(Binary, EnvelopeBinaryExporter) 38 | REGISTER(Code, EnvelopeCodeExporter) 39 | }; 40 | } 41 | 42 | bool HasModdedDependencies() override { return true; } 43 | }; 44 | -------------------------------------------------------------------------------- /src/factories/naudio/v1/LoopFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "AudioContext.h" 5 | 6 | class ADPCMLoopData : public IParsedData { 7 | public: 8 | uint32_t start; 9 | uint32_t end; 10 | uint32_t count; 11 | int16_t predictorState[16]; 12 | }; 13 | 14 | class ADPCMLoopHeaderExporter : public BaseExporter { 15 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 16 | }; 17 | 18 | class ADPCMLoopBinaryExporter : public BaseExporter { 19 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 20 | }; 21 | 22 | class ADPCMLoopCodeExporter : public BaseExporter { 23 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 24 | }; 25 | 26 | class ADPCMLoopFactory : public BaseFactory { 27 | public: 28 | std::optional> parse(std::vector& buffer, YAML::Node& data) override; 29 | inline std::unordered_map> GetExporters() override { 30 | return { 31 | REGISTER(Header, ADPCMLoopHeaderExporter) 32 | REGISTER(Binary, ADPCMLoopBinaryExporter) 33 | REGISTER(Code, ADPCMLoopCodeExporter) 34 | }; 35 | } 36 | 37 | bool HasModdedDependencies() override { return true; } 38 | }; 39 | -------------------------------------------------------------------------------- /src/factories/sf64/HitboxFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace SF64 { 6 | 7 | class HitboxData : public IParsedData { 8 | public: 9 | std::vector mData; 10 | std::vector mTypes; 11 | 12 | HitboxData(std::vector data, std::vector types); 13 | }; 14 | 15 | class HitboxHeaderExporter : public BaseExporter { 16 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 17 | }; 18 | 19 | class HitboxBinaryExporter : public BaseExporter { 20 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 21 | }; 22 | 23 | class HitboxCodeExporter : public BaseExporter { 24 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 25 | }; 26 | 27 | class HitboxFactory : public BaseFactory { 28 | public: 29 | std::optional> parse(std::vector& buffer, YAML::Node& data) override; 30 | inline std::unordered_map> GetExporters() override { 31 | return { 32 | REGISTER(Code, HitboxCodeExporter) 33 | REGISTER(Header, HitboxHeaderExporter) 34 | REGISTER(Binary, HitboxBinaryExporter) 35 | }; 36 | } 37 | }; 38 | } 39 | -------------------------------------------------------------------------------- /src/factories/sf64/TriangleFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "factories/BaseFactory.h" 4 | #include "types/Vec3D.h" 5 | 6 | namespace SF64 { 7 | 8 | class TriangleData : public IParsedData { 9 | public: 10 | std::vector mTris; 11 | std::vector mMeshNodes; 12 | 13 | TriangleData(std::vector tris, std::vector meshNodes); 14 | }; 15 | 16 | class TriangleHeaderExporter : public BaseExporter { 17 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 18 | }; 19 | 20 | class TriangleBinaryExporter : public BaseExporter { 21 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 22 | }; 23 | 24 | class TriangleCodeExporter : public BaseExporter { 25 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 26 | }; 27 | 28 | class TriangleFactory : public BaseFactory { 29 | public: 30 | std::optional> parse(std::vector& buffer, YAML::Node& data) override; 31 | inline std::unordered_map> GetExporters() override { 32 | return { 33 | REGISTER(Code, TriangleCodeExporter) 34 | REGISTER(Header, TriangleHeaderExporter) 35 | REGISTER(Binary, TriangleBinaryExporter) 36 | }; 37 | } 38 | }; 39 | } 40 | -------------------------------------------------------------------------------- /src/factories/sf64/audio/AudioDecompressor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace SF64 { 7 | void DecompressAudio(std::vector data, int16_t* output); 8 | } -------------------------------------------------------------------------------- /src/factories/sm64/AnimationFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace SM64 { 6 | class AnimationData : public IParsedData { 7 | public: 8 | int16_t mFlags; 9 | int16_t mAnimYTransDivisor; 10 | int16_t mStartFrame; 11 | int16_t mLoopStart; 12 | int16_t mLoopEnd; 13 | int16_t mUnusedBoneCount; 14 | int16_t mLength; 15 | std::vector mIndices; 16 | std::vector mEntries; 17 | 18 | AnimationData(int16_t flags, int16_t animYTransDivisor, int16_t startFrame, int16_t loopStart, int16_t loopEnd, int16_t unusedBoneCount, int16_t length, std::vector indices, std::vector entries) : mFlags(flags), mAnimYTransDivisor(animYTransDivisor), mStartFrame(startFrame), mLoopStart(loopStart), mLoopEnd(loopEnd), mUnusedBoneCount(unusedBoneCount), mLength(length), mIndices(std::move(indices)), mEntries(std::move(entries)) {} 19 | }; 20 | 21 | class AnimationBinaryExporter : public BaseExporter { 22 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 23 | }; 24 | 25 | class AnimationFactory : public BaseFactory { 26 | public: 27 | std::optional> parse(std::vector& buffer, YAML::Node& data) override; 28 | inline std::unordered_map> GetExporters() override { 29 | return { REGISTER(Binary, AnimationBinaryExporter) }; 30 | } 31 | }; 32 | } -------------------------------------------------------------------------------- /src/factories/sm64/DialogFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace SM64 { 6 | class DialogData : public IParsedData { 7 | public: 8 | uint32_t mUnused; 9 | uint8_t mLinesPerBox; 10 | uint16_t mLeftOffset; 11 | uint16_t mWidth; 12 | std::vector mText; 13 | 14 | DialogData(uint32_t unused, uint8_t linesPerBox, uint16_t leftOffset, uint16_t width, std::vector& text) : mUnused(unused), mLinesPerBox(linesPerBox), mLeftOffset(leftOffset), mWidth(width), mText(text) {} 15 | }; 16 | 17 | class DialogBinaryExporter : public BaseExporter { 18 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 19 | }; 20 | 21 | class DialogFactory : public BaseFactory { 22 | public: 23 | std::optional> parse(std::vector& buffer, YAML::Node& data) override; 24 | inline std::unordered_map> GetExporters() override { 25 | return { REGISTER(Binary, DialogBinaryExporter) }; 26 | } 27 | }; 28 | } -------------------------------------------------------------------------------- /src/factories/sm64/DictionaryFactory.cpp: -------------------------------------------------------------------------------- 1 | #include "DictionaryFactory.h" 2 | 3 | #include "spdlog/spdlog.h" 4 | 5 | ExportResult SM64::DictionaryBinaryExporter::Export(std::ostream &write, std::shared_ptr raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { 6 | auto writer = LUS::BinaryWriter(); 7 | const auto data = std::static_pointer_cast(raw); 8 | 9 | WriteHeader(writer, Torch::ResourceType::Dictionary, 0); 10 | 11 | writer.Write(static_cast(data->mDictionary.size())); 12 | for(auto& [key, value] : data->mDictionary){ 13 | writer.Write(key); 14 | writer.Write(static_cast(value.size())); 15 | writer.Write(reinterpret_cast(value.data()), value.size()); 16 | } 17 | writer.Finish(write); 18 | return std::nullopt; 19 | } 20 | 21 | std::optional> SM64::DictionaryFactory::parse(std::vector& buffer, YAML::Node& data) { 22 | std::unordered_map> dictionary; 23 | 24 | for (auto it = data["keys"].begin(); it != data["keys"].end(); ++it) { 25 | auto key = it->first.as(); 26 | auto offset = it->second.as(); 27 | 28 | std::vector text; 29 | const auto bytes = buffer.data(); 30 | 31 | while(bytes[offset] != 0xFF){ 32 | auto c = bytes[offset++]; 33 | text.push_back(c); 34 | } 35 | 36 | text.push_back(0xFF); 37 | dictionary[key] = text; 38 | 39 | SPDLOG_INFO("Found key: {} at offset {}", key, offset); 40 | } 41 | 42 | return std::make_shared(dictionary); 43 | } -------------------------------------------------------------------------------- /src/factories/sm64/DictionaryFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace SM64 { 6 | 7 | class DictionaryData : public IParsedData { 8 | public: 9 | std::unordered_map> mDictionary; 10 | 11 | DictionaryData(std::unordered_map> dictionary) : mDictionary(dictionary) {} 12 | }; 13 | 14 | class DictionaryBinaryExporter : public BaseExporter { 15 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 16 | }; 17 | 18 | class DictionaryFactory : public BaseFactory { 19 | public: 20 | std::optional> parse(std::vector& buffer, YAML::Node& data) override; 21 | std::unordered_map> GetExporters() override { 22 | return { REGISTER(Binary, DictionaryBinaryExporter) }; 23 | } 24 | }; 25 | } -------------------------------------------------------------------------------- /src/factories/sm64/MovtexFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "factories/BaseFactory.h" 4 | #include "types/Vec3D.h" 5 | 6 | namespace SM64 { 7 | 8 | class MovtexData : public IParsedData { 9 | public: 10 | std::vector mMovtexData; 11 | bool mIsQuad; 12 | uint32_t mVertexCount; 13 | bool mHasColor; 14 | MovtexData(std::vector movtexData, bool isQuad, uint32_t count, bool hasColor) : mMovtexData(std::move(movtexData)), mIsQuad(isQuad), mVertexCount(count), mHasColor(hasColor) {} 15 | }; 16 | 17 | class MovtexHeaderExporter : public BaseExporter { 18 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 19 | }; 20 | 21 | class MovtexBinaryExporter : public BaseExporter { 22 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 23 | }; 24 | 25 | class MovtexCodeExporter : public BaseExporter { 26 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 27 | }; 28 | 29 | class MovtexFactory : public BaseFactory { 30 | public: 31 | std::optional> parse(std::vector& buffer, YAML::Node& data) override; 32 | inline std::unordered_map> GetExporters() override { 33 | return { 34 | REGISTER(Code, MovtexCodeExporter) 35 | REGISTER(Header, MovtexHeaderExporter) 36 | REGISTER(Binary, MovtexBinaryExporter) 37 | }; 38 | } 39 | }; 40 | } 41 | -------------------------------------------------------------------------------- /src/factories/sm64/MovtexQuadFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "factories/BaseFactory.h" 4 | #include "types/Vec3D.h" 5 | 6 | namespace SM64 { 7 | 8 | class MovtexQuadData : public IParsedData { 9 | public: 10 | std::vector> mMovtexQuads; 11 | 12 | MovtexQuadData(std::vector> movtexQuads) : mMovtexQuads(std::move(movtexQuads)) {} 13 | }; 14 | 15 | class MovtexQuadHeaderExporter : public BaseExporter { 16 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 17 | }; 18 | 19 | class MovtexQuadBinaryExporter : public BaseExporter { 20 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 21 | }; 22 | 23 | class MovtexQuadCodeExporter : public BaseExporter { 24 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 25 | }; 26 | 27 | class MovtexQuadFactory : public BaseFactory { 28 | public: 29 | std::optional> parse(std::vector& buffer, YAML::Node& data) override; 30 | inline std::unordered_map> GetExporters() override { 31 | return { 32 | REGISTER(Code, MovtexQuadCodeExporter) 33 | REGISTER(Header, MovtexQuadHeaderExporter) 34 | REGISTER(Binary, MovtexQuadBinaryExporter) 35 | }; 36 | } 37 | }; 38 | } 39 | -------------------------------------------------------------------------------- /src/factories/sm64/TextFactory.cpp: -------------------------------------------------------------------------------- 1 | #include "TextFactory.h" 2 | #include "utils/Decompressor.h" 3 | 4 | ExportResult SM64::TextBinaryExporter::Export(std::ostream &write, std::shared_ptr raw, std::string& entryName, YAML::Node &node, std::string* replacement ) { 5 | auto writer = LUS::BinaryWriter(); 6 | auto data = std::static_pointer_cast(raw)->mBuffer; 7 | 8 | WriteHeader(writer, Torch::ResourceType::Blob, 0); 9 | writer.Write((uint32_t) data.size()); 10 | writer.Write((char*) data.data(), data.size()); 11 | writer.Finish(write); 12 | return std::nullopt; 13 | } 14 | 15 | std::optional> SM64::TextFactory::parse(std::vector& buffer, YAML::Node& node) { 16 | 17 | std::vector text; 18 | auto [_, segment] = Decompressor::AutoDecode(node, buffer); 19 | size_t idx = 0; 20 | 21 | while(segment.data[idx] != 0xFF){ 22 | auto c = segment.data[idx++]; 23 | text.push_back(c); 24 | } 25 | text.push_back(0xFF); 26 | 27 | return std::make_shared(text); 28 | } -------------------------------------------------------------------------------- /src/factories/sm64/TextFactory.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "../../types/RawBuffer.h" 5 | 6 | namespace SM64 { 7 | class TextBinaryExporter : public BaseExporter { 8 | ExportResult Export(std::ostream& write, std::shared_ptr data, std::string& entryName, YAML::Node& node, std::string* replacement) override; 9 | }; 10 | 11 | class TextFactory : public BaseFactory { 12 | public: 13 | std::optional> parse(std::vector& buffer, YAML::Node& data) override; 14 | inline std::unordered_map> GetExporters() override { 15 | return { REGISTER(Binary, TextBinaryExporter) }; 16 | } 17 | }; 18 | }; -------------------------------------------------------------------------------- /src/factories/sm64/geo/GeoUtils.cpp: -------------------------------------------------------------------------------- 1 | #include "GeoUtils.h" 2 | 3 | #define next_s16_in_geo_script(src) (int16_t) BSWAP16((*(*src)++)) 4 | 5 | int16_t* read_vec3s_to_vec3f(Vec3f& dst, int16_t *src) { 6 | dst.x = next_s16_in_geo_script(&src); 7 | dst.y = next_s16_in_geo_script(&src); 8 | dst.z = next_s16_in_geo_script(&src); 9 | return src; 10 | } 11 | 12 | int16_t* read_vec3s(Vec3s& dst, int16_t *src) { 13 | dst.x = next_s16_in_geo_script(&src); 14 | dst.y = next_s16_in_geo_script(&src); 15 | dst.z = next_s16_in_geo_script(&src); 16 | return src; 17 | } 18 | 19 | int16_t* read_vec3s_angle(Vec3s& dst, int16_t *src) { 20 | dst.x = next_s16_in_geo_script(&src); 21 | dst.y = next_s16_in_geo_script(&src); 22 | dst.z = next_s16_in_geo_script(&src); 23 | return src; 24 | } -------------------------------------------------------------------------------- /src/factories/sm64/geo/GeoUtils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "GeoCommand.h" 5 | 6 | int16_t* read_vec3s_to_vec3f(Vec3f& dst, int16_t *src); 7 | int16_t* read_vec3s(Vec3s& dst, int16_t *src); 8 | int16_t* read_vec3s_angle(Vec3s& dst, int16_t *src); -------------------------------------------------------------------------------- /src/n64/Cartridge.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace N64 { 8 | enum class CountryCode { 9 | Japan, 10 | NorthAmerica, 11 | Europe, 12 | Unknown 13 | }; 14 | 15 | class Cartridge { 16 | public: 17 | explicit Cartridge(const std::vector& romData) 18 | : gRomData(romData), gCountryCode(CountryCode::Unknown), gVersion(0), gGameTitle("Unknown"), gRomCRC(0) { 19 | } 20 | void Initialize(); 21 | const std::string& GetGameTitle(); 22 | std::string GetCountryCode(); 23 | CountryCode GetCountry(); 24 | uint8_t GetVersion() const; 25 | std::string GetHash(); 26 | uint32_t GetCRC(); 27 | private: 28 | std::vector gRomData; 29 | CountryCode gCountryCode; 30 | uint8_t gVersion; 31 | std::string gGameTitle; 32 | std::string gHash; 33 | uint32_t gRomCRC; 34 | }; 35 | } -------------------------------------------------------------------------------- /src/n64/CommandMacros.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #define _SHIFTL(v, s, w) ((uint32_t)(((uint32_t)(v) & ((0x01 << (w)) - 1)) << (s))) 6 | #define _SHIFTR(v, s, w) ((uint32_t)(((uint32_t)(v) >> (s)) & ((0x01 << (w)) - 1))) 7 | 8 | #define CMD_SIZE_SHIFT (sizeof(uint32_t) >> 3) 9 | #define CMD_PROCESS_OFFSET(offset) (((offset) & 3) | (((offset) & ~3) << CMD_SIZE_SHIFT)) 10 | 11 | #define CMD_BBBB(a, b, c, d) (_SHIFTL(a, 0, 8) | _SHIFTL(b, 8, 8) | _SHIFTL(c, 16, 8) | _SHIFTL(d, 24, 8)) 12 | #define CMD_BBH(a, b, c) (_SHIFTL(a, 0, 8) | _SHIFTL(b, 8, 8) | _SHIFTL(c, 16, 16)) 13 | #define CMD_HH(a, b) (_SHIFTL(a, 0, 16) | _SHIFTL(b, 16, 16)) 14 | #define CMD_W(a) (a) 15 | #define CMD_PTR(a) ((uintptr_t)(a)) 16 | 17 | #define CMD_HHHHHH(a, b, c, d, e, f) CMD_HH(a, b), CMD_HH(c, d), CMD_HH(e, f) 18 | -------------------------------------------------------------------------------- /src/n64/types.h: -------------------------------------------------------------------------------- 1 | #ifndef ULTRA64_TYPES_H 2 | #define ULTRA64_TYPES_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | typedef signed char s8; 9 | typedef unsigned char u8; 10 | typedef signed short int s16; 11 | typedef unsigned short int u16; 12 | typedef signed int s32; 13 | typedef unsigned int u32; 14 | typedef signed long long int s64; 15 | typedef unsigned long long int u64; 16 | 17 | typedef volatile u8 vu8; 18 | typedef volatile u16 vu16; 19 | typedef volatile u32 vu32; 20 | typedef volatile u64 vu64; 21 | typedef volatile s8 vs8; 22 | typedef volatile s16 vs16; 23 | typedef volatile s32 vs32; 24 | typedef volatile s64 vs64; 25 | 26 | typedef float f32; 27 | typedef double f64; 28 | #if 0 29 | 30 | typedef s32 ptrdiff_t; 31 | typedef s32 intptr_t; 32 | typedef u32 uintptr_t; 33 | #endif 34 | 35 | #ifndef GBI_FLOATS 36 | typedef int Mtx_t[4][4]; 37 | typedef union { 38 | Mtx_t m; 39 | struct { 40 | u16 intPart[4][4]; 41 | u16 fracPart[4][4]; 42 | }; 43 | long long int forc_structure_alignment; 44 | } Mtx; 45 | #else 46 | typedef struct { 47 | float m[4][4]; 48 | } Mtx; 49 | #endif 50 | 51 | typedef float MtxF_t[4][4]; 52 | typedef union { 53 | MtxF_t mf; 54 | struct { 55 | float xx, yx, zx, wx, xy, yy, zy, wy, xz, yz, zz, wz, xw, yw, zw, ww; 56 | }; 57 | } MtxF; 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /src/preprocess/CompTool.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "lib/binarytools/BinaryWriter.h" 4 | #include 5 | #include 6 | #include 7 | 8 | enum class CompType { 9 | UNCOMPRESSED, 10 | COMPRESSED, 11 | UNKNOWN 12 | }; 13 | 14 | class CompTool { 15 | public: 16 | static std::vector Decompress(std::vector rom); 17 | private: 18 | static uint32_t FindFileTable(std::vector& rom); 19 | static std::pair CalculateCRCs(LUS::BinaryWriter& decompFile); 20 | static inline const uint32_t sCrcSeed = 0xF8CA4DDC; 21 | }; 22 | -------------------------------------------------------------------------------- /src/types/RawBuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../factories/BaseFactory.h" 4 | 5 | class RawBuffer : public IParsedData { 6 | public: 7 | std::vector mBuffer; 8 | 9 | RawBuffer(uint8_t* data, size_t size) : mBuffer(data, data + size) {} 10 | explicit RawBuffer(std::vector& buffer) : mBuffer(std::move(buffer)) {} 11 | RawBuffer(std::vector::iterator begin, std::vector::iterator end) : mBuffer(begin, end) {} 12 | }; -------------------------------------------------------------------------------- /src/types/SegmentedAddr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | struct SegmentedAddr { 6 | uint32_t offset; 7 | }; -------------------------------------------------------------------------------- /src/utils/Decompressor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "lib/binarytools/BinaryReader.h" 10 | 11 | enum class CompressionType { 12 | None, 13 | MIO0, 14 | YAY0, 15 | YAZ0, 16 | }; 17 | 18 | 19 | struct DataChunk { 20 | uint8_t* data; 21 | size_t size; 22 | }; 23 | 24 | struct DecompressedData { 25 | DataChunk* root; 26 | DataChunk segment; 27 | 28 | LUS::BinaryReader GetReader() { 29 | return LUS::BinaryReader(reinterpret_cast(segment.data), segment.size); 30 | } 31 | }; 32 | 33 | class Decompressor { 34 | public: 35 | static DataChunk* Decode(const std::vector& buffer, uint32_t offset, CompressionType type, bool ignoreCache = false); 36 | static DataChunk* DecodeTKMK00(const std::vector& buffer, const uint32_t offset, const uint32_t size, const uint32_t alpha); 37 | static DecompressedData AutoDecode(YAML::Node& node, std::vector& buffer, std::optional size = std::nullopt); 38 | static DecompressedData AutoDecode(uint32_t offset, std::optional size, std::vector& buffer); 39 | static CompressionType GetCompressionType(std::vector& buffer, const uint32_t offset); 40 | static uint32_t TranslateAddr(uint32_t addr, bool baseAddress = false); 41 | static bool IsSegmented(uint32_t addr); 42 | 43 | static void ClearCache(); 44 | }; -------------------------------------------------------------------------------- /src/utils/StringHelper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | class StringHelper { 13 | public: 14 | static std::vector Split(std::string s, const std::string& delimiter); 15 | static std::vector Split(std::string_view s, const std::string& delimiter); 16 | static std::string Strip(std::string s, const std::string& delimiter); 17 | static std::string Replace(std::string str, const std::string& from, const std::string& to); 18 | static void ReplaceOriginal(std::string& str, const std::string& from, const std::string& to); 19 | static bool StartsWith(const std::string& s, const std::string& input); 20 | static bool Contains(const std::string& s, const std::string& input); 21 | static bool EndsWith(const std::string& s, const std::string& input); 22 | static std::string Sprintf(const char* format, ...); 23 | static std::string Implode(std::vector& elements, const char* const separator); 24 | static int64_t StrToL(const std::string& str, int32_t base = 10); 25 | static std::string BoolStr(bool b); 26 | static bool HasOnlyDigits(const std::string& str); 27 | static bool IsValidHex(std::string_view str); 28 | static bool IsValidHex(const std::string& str); 29 | static bool IsValidOffset(std::string_view str); 30 | static bool IsValidOffset(const std::string& str); 31 | static bool IEquals(const std::string& a, const std::string& b); 32 | }; -------------------------------------------------------------------------------- /src/utils/TextureUtils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | enum class TextureType { 8 | Error, 9 | RGBA32bpp, 10 | RGBA16bpp, 11 | Palette4bpp, 12 | Palette8bpp, 13 | Grayscale4bpp, 14 | Grayscale8bpp, 15 | GrayscaleAlpha4bpp, 16 | GrayscaleAlpha8bpp, 17 | GrayscaleAlpha16bpp, 18 | GrayscaleAlpha1bpp, 19 | TLUT 20 | }; 21 | 22 | struct TextureFormat { 23 | TextureType type; 24 | uint32_t depth; 25 | }; 26 | 27 | class TextureUtils { 28 | public: 29 | static size_t CalculateTextureSize(TextureType type, uint32_t width, uint32_t height); 30 | static std::vector alloc_ia8_text_from_i1(uint16_t *in, int16_t width, int16_t height); 31 | }; 32 | -------------------------------------------------------------------------------- /src/utils/TorchUtils.cpp: -------------------------------------------------------------------------------- 1 | #include "TorchUtils.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include "spdlog/spdlog.h" 7 | 8 | namespace fs = std::filesystem; 9 | 10 | uint32_t Torch::translate(const uint32_t offset) { 11 | if(SEGMENT_NUMBER(offset) > 0x01) { 12 | auto segment = SEGMENT_NUMBER(offset); 13 | const auto addr = Companion::Instance->GetFileOffsetFromSegmentedAddr(segment); 14 | if(!addr.has_value()) { 15 | SPDLOG_ERROR("Segment data missing from game config\nPlease add an entry for segment {}", segment); 16 | throw std::runtime_error("Failed to find offset"); 17 | } 18 | 19 | return addr.value() + SEGMENT_OFFSET(offset); 20 | } 21 | 22 | return offset; 23 | } 24 | 25 | int getFileDepth(const fs::path& base, const fs::path& p) { 26 | return std::distance(base.begin(), p.begin()); 27 | } 28 | 29 | std::vector Torch::getRecursiveEntries(const fs::path baseDir) { 30 | std::set result; 31 | 32 | for (const auto& entry : fs::recursive_directory_iterator(baseDir)) { 33 | result.insert(entry); 34 | } 35 | 36 | std::vector sortedEntries(result.begin(), result.end()); 37 | return sortedEntries; 38 | } -------------------------------------------------------------------------------- /src/utils/TorchUtils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace Torch { 13 | template< typename T > 14 | std::string to_hex(T number, const bool append0x = true) { 15 | std::stringstream stream; 16 | if(append0x) { 17 | stream << "0x"; 18 | } 19 | stream << std::setfill ('0') 20 | << std::hex << number; 21 | 22 | auto format = stream.str(); 23 | std::transform(format.begin(), format.end(), format.begin(), ::toupper); 24 | return format; 25 | } 26 | 27 | uint32_t translate(uint32_t offset); 28 | std::vector getRecursiveEntries(const std::filesystem::path baseDir); 29 | 30 | }; -------------------------------------------------------------------------------- /test/config.yml: -------------------------------------------------------------------------------- 1 | f7475fb11e7e6830f82883412638e8390791ab87: 2 | name: Star Fox 64 (U) (V1.1) 3 | path: sf64/us 4 | logging: ERROR 5 | config: 6 | gbi: F3DEX 7 | sort: OFFSET 8 | output: 9 | code: sf64/src 10 | 11 | d064229a32cc05ab85e2381ce07744eb3ffaf530: 12 | name: Star Fox 64 (JP) (V1.0) 13 | path: sf64/jp 14 | config: 15 | gbi: F3DEX 16 | sort: OFFSET 17 | output: 18 | code: sf64/src 19 | 20 | 8a20a5c83d6ceb0f0506cfc9fa20d8f438cafe51: 21 | name: Super Mario 64 [JP] 22 | path: sm64/jp 23 | config: 24 | gbi: F3D 25 | sort: OFFSET 26 | output: 27 | code: sm64/src 28 | 29 | 9bef1128717f958171a4afac3ed78ee2bb4e86ce: 30 | name: Super Mario 64 [US] 31 | path: sm64/us 32 | config: 33 | gbi: F3D 34 | sort: OFFSET 35 | output: 36 | code: sm64/src -------------------------------------------------------------------------------- /test/mk64/audio/root.yml: -------------------------------------------------------------------------------- 1 | header: 2 | type: NAUDIO:V0:AUDIO_HEADER 3 | ctl: 4 | offset: 0x966260 5 | size: 0x13840 6 | tbl: 7 | offset: 0x979AA0 8 | size: 0x24C4C0 -------------------------------------------------------------------------------- /test/sf64/jp/ast_audio.yaml: -------------------------------------------------------------------------------- 1 | :config: 2 | force: true 3 | header: 4 | code: 5 | - '#include "sys.h"' 6 | - '#include "sf64audio_provisional.h"' 7 | 8 | audio_sample_bank_table: 9 | { type: NAUDIO:AUDIO_TABLE, format: SAMPLE, offset: 0xC1360, symbol: gSampleBankTableInit } 10 | 11 | audio_seq_table: 12 | { type: NAUDIO:AUDIO_TABLE, format: SEQUENCE, offset: 0xC13B0, symbol: gSeqTableInit } 13 | 14 | audio_soundfont_table: 15 | { type: NAUDIO:AUDIO_TABLE, format: SOUNDFONT, offset: 0xC17E0, symbol: gSoundFontTableInit } 16 | 17 | audio_seq_font_table: 18 | { type: ARRAY, count: 566, array_type: u8, offset: 0xC1A00, symbol: gSeqFontTableInit } 19 | 20 | # audio_seq: 21 | # { type: BLOB, offset: 0xDEA20, size: 0x3ACF0, symbol: gAudioSeq } 22 | 23 | # audio_bank: 24 | # { type: BLOB, offset: 0x119710, size: 0x1E020, symbol: gAudioBank } 25 | 26 | # audio_table: 27 | # { type: BLOB, offset: 0x137730, size: 0x73C580, symbol: gAudioTable } -------------------------------------------------------------------------------- /test/sf64/us/ast_bank.yaml: -------------------------------------------------------------------------------- 1 | :config: 2 | force: true 3 | external_files: 4 | - "sf64/us/ast_tables.yaml" 5 | 6 | # sf_00000: 7 | # type: NAUDIO:V1:SOUND_FONT 8 | # offset: 0x0 9 | # symbol: sf_00000 -------------------------------------------------------------------------------- /test/sf64/us/ast_tables.yaml: -------------------------------------------------------------------------------- 1 | :config: 2 | force: true 3 | header: 4 | code: 5 | - '#include "sys.h"' 6 | - '#include "sf64audio_provisional.h"' 7 | 8 | audio_setup: 9 | type: NAUDIO:V1:AUDIO_SETUP 10 | audio_seq: 11 | size: 0x3ACF0 12 | offset: 0xDEA20 13 | audio_bank: 14 | size: 0x1E020 15 | offset: 0x119710 16 | audio_table: 17 | size: 0x73C580 18 | offset: 0x137730 19 | 20 | audio_sample_bank_table: 21 | { type: NAUDIO:V1:AUDIO_TABLE, format: SAMPLE, offset: 0xC4210, symbol: gSampleBankTableInit } 22 | 23 | audio_seq_table: 24 | { type: NAUDIO:V1:AUDIO_TABLE, format: SEQUENCE, offset: 0xC4260, symbol: gSeqTableInit } 25 | 26 | audio_soundfont_table: 27 | { type: NAUDIO:V1:AUDIO_TABLE, format: SOUNDFONT, offset: 0xC4690, symbol: gSoundFontTableInit } 28 | 29 | audio_seq_font_table: 30 | { type: ARRAY, count: 566, array_type: u8, offset: 0xC48B0, symbol: gSeqFontTableInit } 31 | 32 | # audio_seq: 33 | # { type: BLOB, offset: 0xDEA20, size: 0x3ACF0, symbol: gAudioSeq } 34 | 35 | # audio_bank: 36 | # { type: BLOB, offset: 0x119710, size: 0x1E020, symbol: gAudioBank } 37 | 38 | # audio_table: 39 | # { type: BLOB, offset: 0x137730, size: 0x73C580, symbol: gAudioTable } -------------------------------------------------------------------------------- /test/sm64/jp/root.yml: -------------------------------------------------------------------------------- 1 | header: 2 | type: NAUDIO:V0:AUDIO_HEADER 3 | ctl: 4 | offset: 5738816 5 | size: 94400 6 | tbl: 7 | offset: 5833216 8 | size: 1793408 -------------------------------------------------------------------------------- /test/sm64/us/root.yml: -------------------------------------------------------------------------------- 1 | header: 2 | type: NAUDIO:V0:AUDIO_HEADER 3 | ctl: 4 | offset: 0x57B720 5 | size: 0x17E40 6 | tbl: 7 | offset: 0x593560 8 | size: 0x21D300 -------------------------------------------------------------------------------- /test/torch.hash.yml: -------------------------------------------------------------------------------- 1 | sf64/us/ast_tables.yaml: 2 | hash: d9bdec9158d17171b170d4e57e9d474068bfc80e 3 | extracted: 4 | Header: true 5 | Code: false 6 | Binary: false 7 | Modding: false 8 | sf64/us/ast_bank.yaml: 9 | hash: f71943d7829a89ed3065630b3d5c3ca60440c238 10 | extracted: 11 | Header: false 12 | Code: false 13 | Binary: false 14 | Modding: false --------------------------------------------------------------------------------