diff --git a/Cargo.lock b/Cargo.lock index babb0a6..62f72e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -92,8 +92,8 @@ dependencies = [ "hashbrown", "paste", "static_assertions", - "windows 0.58.0", - "windows-core 0.58.0", + "windows", + "windows-core", ] [[package]] @@ -275,6 +275,25 @@ dependencies = [ "libloading", ] +[[package]] +name = "ashpd" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6cbdf310d77fd3aaee6ea2093db7011dc2d35d2eb3481e5607f1f8d942ed99df" +dependencies = [ + "async-fs", + "async-net", + "enumflags2", + "futures-channel", + "futures-util", + "rand 0.9.0", + "raw-window-handle", + "serde", + "serde_repr", + "url", + "zbus 5.5.0", +] + [[package]] name = "async-broadcast" version = "0.7.2" @@ -353,6 +372,17 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "async-net" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b948000fad4873c1c9339d60f2623323a0cfd3816e5181033c6a5cb68b2accf7" +dependencies = [ + "async-io", + "blocking", + "futures-lite", +] + [[package]] name = "async-process" version = "2.3.0" @@ -481,12 +511,6 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" -[[package]] -name = "beul" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3c3baedf037b161e69da9200947329f52afa3b6e1cdbe6f344d6aa350fedd2f" - [[package]] name = "bit-set" version = "0.8.0" @@ -777,6 +801,15 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "crossbeam-channel" +version = "0.5.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ba6d68e24814cb8de6bb986db8222d3a027d15872cabc0d18817bc3c0e4471" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "crossbeam-utils" version = "0.8.21" @@ -836,6 +869,18 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd0c93bb4b0c6d9b77f4435b0ae98c24d17f1c45b2ff844c6151a07256ca923b" +[[package]] +name = "dispatch2" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a0d569e003ff27784e0e14e4a594048698e0c0f0b66cabcb51511be55a7caa0" +dependencies = [ + "bitflags 2.9.0", + "block2 0.6.0", + "libc", + "objc2 0.6.0", +] + [[package]] name = "displaydoc" version = "0.2.5" @@ -979,6 +1024,15 @@ dependencies = [ "winit", ] +[[package]] +name = "egui_alignments" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf881b608a1a6050fa4f283834592bd814667de900acb4612a03b0da22f529b5" +dependencies = [ + "egui", +] + [[package]] name = "egui_glow" version = "0.31.1" @@ -1654,6 +1708,12 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" +[[package]] +name = "itoa" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" + [[package]] name = "jiff" version = "0.2.5" @@ -1879,30 +1939,6 @@ dependencies = [ "simd-adler32", ] -[[package]] -name = "mundy" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2831eeb1fbfc52f23d3a6bbc4a2f4457b57d016c9c9112cf6a2a4cffc3c4cc6" -dependencies = [ - "async-io", - "beul", - "cfg-if", - "dispatch", - "futures-channel", - "futures-lite", - "objc2 0.6.0", - "objc2-app-kit 0.3.0", - "objc2-foundation 0.3.0", - "pin-project-lite", - "slab", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "windows 0.61.1", - "zbus 5.5.0", -] - [[package]] name = "naga" version = "24.0.0" @@ -2057,10 +2093,10 @@ dependencies = [ "block2 0.5.1", "libc", "objc2 0.5.2", - "objc2-core-data 0.2.2", - "objc2-core-image 0.2.2", + "objc2-core-data", + "objc2-core-image", "objc2-foundation 0.2.2", - "objc2-quartz-core 0.2.2", + "objc2-quartz-core", ] [[package]] @@ -2071,15 +2107,8 @@ checksum = "5906f93257178e2f7ae069efb89fbd6ee94f0592740b5f8a1512ca498814d0fb" dependencies = [ "bitflags 2.9.0", "block2 0.6.0", - "libc", "objc2 0.6.0", - "objc2-cloud-kit 0.3.0", - "objc2-core-data 0.3.0", - "objc2-core-foundation", - "objc2-core-graphics", - "objc2-core-image 0.3.0", "objc2-foundation 0.3.0", - "objc2-quartz-core 0.3.0", ] [[package]] @@ -2095,17 +2124,6 @@ dependencies = [ "objc2-foundation 0.2.2", ] -[[package]] -name = "objc2-cloud-kit" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c1948a9be5f469deadbd6bcb86ad7ff9e47b4f632380139722f7d9840c0d42c" -dependencies = [ - "bitflags 2.9.0", - "objc2 0.6.0", - "objc2-foundation 0.3.0", -] - [[package]] name = "objc2-contacts" version = "0.2.2" @@ -2129,17 +2147,6 @@ dependencies = [ "objc2-foundation 0.2.2", ] -[[package]] -name = "objc2-core-data" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f860f8e841f6d32f754836f51e6bc7777cd7e7053cf18528233f6811d3eceb4" -dependencies = [ - "bitflags 2.9.0", - "objc2 0.6.0", - "objc2-foundation 0.3.0", -] - [[package]] name = "objc2-core-foundation" version = "0.3.0" @@ -2150,18 +2157,6 @@ dependencies = [ "objc2 0.6.0", ] -[[package]] -name = "objc2-core-graphics" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8dca602628b65356b6513290a21a6405b4d4027b8b250f0b98dddbb28b7de02" -dependencies = [ - "bitflags 2.9.0", - "objc2 0.6.0", - "objc2-core-foundation", - "objc2-io-surface", -] - [[package]] name = "objc2-core-image" version = "0.2.2" @@ -2174,16 +2169,6 @@ dependencies = [ "objc2-metal", ] -[[package]] -name = "objc2-core-image" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ffa6bea72bf42c78b0b34e89c0bafac877d5f80bf91e159a5d96ea7f693ca56" -dependencies = [ - "objc2 0.6.0", - "objc2-foundation 0.3.0", -] - [[package]] name = "objc2-core-location" version = "0.2.2" @@ -2220,19 +2205,6 @@ name = "objc2-foundation" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a21c6c9014b82c39515db5b396f91645182611c97d24637cf56ac01e5f8d998" -dependencies = [ - "bitflags 2.9.0", - "block2 0.6.0", - "libc", - "objc2 0.6.0", - "objc2-core-foundation", -] - -[[package]] -name = "objc2-io-surface" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "161a8b87e32610086e1a7a9e9ec39f84459db7b3a0881c1f16ca5a2605581c19" dependencies = [ "bitflags 2.9.0", "objc2 0.6.0", @@ -2276,17 +2248,6 @@ dependencies = [ "objc2-metal", ] -[[package]] -name = "objc2-quartz-core" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fb3794501bb1bee12f08dcad8c61f2a5875791ad1c6f47faa71a0f033f20071" -dependencies = [ - "bitflags 2.9.0", - "objc2 0.6.0", - "objc2-foundation 0.3.0", -] - [[package]] name = "objc2-symbols" version = "0.2.2" @@ -2306,13 +2267,13 @@ dependencies = [ "bitflags 2.9.0", "block2 0.5.1", "objc2 0.5.2", - "objc2-cloud-kit 0.2.2", - "objc2-core-data 0.2.2", - "objc2-core-image 0.2.2", + "objc2-cloud-kit", + "objc2-core-data", + "objc2-core-image", "objc2-core-location", "objc2-foundation 0.2.2", "objc2-link-presentation", - "objc2-quartz-core 0.2.2", + "objc2-quartz-core", "objc2-symbols", "objc2-uniform-type-identifiers", "objc2-user-notifications", @@ -2554,6 +2515,12 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "pollster" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f3a9f18d041e6d0e102a0a46750538147e5e8992d3b4873aaafee2520b00ce3" + [[package]] name = "portable-atomic" version = "1.11.0" @@ -2643,8 +2610,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", - "rand_chacha", - "rand_core", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + +[[package]] +name = "rand" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3779b94aeb87e8bd4e834cee3650289ee9e0d5677f976ecdb6d219e5f4f6cd94" +dependencies = [ + "rand_chacha 0.9.0", + "rand_core 0.9.3", + "zerocopy 0.8.24", ] [[package]] @@ -2654,7 +2632,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core 0.9.3", ] [[package]] @@ -2666,6 +2654,15 @@ dependencies = [ "getrandom 0.2.15", ] +[[package]] +name = "rand_core" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" +dependencies = [ + "getrandom 0.3.2", +] + [[package]] name = "raw-window-handle" version = "0.6.2" @@ -2740,7 +2737,7 @@ dependencies = [ "log", "thiserror 1.0.69", "utfx", - "windows 0.58.0", + "windows", ] [[package]] @@ -2749,6 +2746,30 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19b30a45b0cd0bcca8037f3d0dc3421eaf95327a17cad11964fb8179b4fc4832" +[[package]] +name = "rfd" +version = "0.15.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80c844748fdc82aae252ee4594a89b6e7ebef1063de7951545564cbc4e57075d" +dependencies = [ + "ashpd", + "block2 0.6.0", + "dispatch2", + "js-sys", + "log", + "objc2 0.6.0", + "objc2-app-kit 0.3.0", + "objc2-core-foundation", + "objc2-foundation 0.3.0", + "pollster", + "raw-window-handle", + "urlencoding", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-sys 0.59.0", +] + [[package]] name = "rustc-hash" version = "1.1.0" @@ -2787,6 +2808,12 @@ version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2" +[[package]] +name = "ryu" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" + [[package]] name = "same-file" version = "1.0.6" @@ -2841,6 +2868,18 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_json" +version = "1.0.140" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + [[package]] name = "serde_repr" version = "0.1.20" @@ -3202,14 +3241,20 @@ name = "tundlebool" version = "0.1.0" dependencies = [ "anyhow", + "crossbeam-channel", "dirs", "eframe", "egui", + "egui_alignments", "env_logger", + "hex", "keyvalues-parser", - "mundy", + "regex", "registry", + "rfd", "serde", + "serde_json", + "sha2", ] [[package]] @@ -3277,8 +3322,15 @@ dependencies = [ "form_urlencoded", "idna", "percent-encoding", + "serde", ] +[[package]] +name = "urlencoding" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" + [[package]] name = "utf16_iter" version = "1.0.5" @@ -3645,7 +3697,7 @@ dependencies = [ "wasm-bindgen", "web-sys", "wgpu-types", - "windows 0.58.0", + "windows", ] [[package]] @@ -3697,68 +3749,23 @@ version = "0.58.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6" dependencies = [ - "windows-core 0.58.0", + "windows-core", "windows-targets 0.52.6", ] -[[package]] -name = "windows" -version = "0.61.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5ee8f3d025738cb02bad7868bbb5f8a6327501e870bf51f1b455b0a2454a419" -dependencies = [ - "windows-collections", - "windows-core 0.61.0", - "windows-future", - "windows-link", - "windows-numerics", -] - -[[package]] -name = "windows-collections" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3beeceb5e5cfd9eb1d76b381630e82c4241ccd0d27f1a39ed41b2760b255c5e8" -dependencies = [ - "windows-core 0.61.0", -] - [[package]] name = "windows-core" version = "0.58.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" dependencies = [ - "windows-implement 0.58.0", - "windows-interface 0.58.0", - "windows-result 0.2.0", - "windows-strings 0.1.0", + "windows-implement", + "windows-interface", + "windows-result", + "windows-strings", "windows-targets 0.52.6", ] -[[package]] -name = "windows-core" -version = "0.61.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4763c1de310c86d75a878046489e2e5ba02c649d185f21c67d4cf8a56d098980" -dependencies = [ - "windows-implement 0.60.0", - "windows-interface 0.59.1", - "windows-link", - "windows-result 0.3.2", - "windows-strings 0.4.0", -] - -[[package]] -name = "windows-future" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a1d6bbefcb7b60acd19828e1bc965da6fcf18a7e39490c5f8be71e54a19ba32" -dependencies = [ - "windows-core 0.61.0", - "windows-link", -] - [[package]] name = "windows-implement" version = "0.58.0" @@ -3770,17 +3777,6 @@ dependencies = [ "syn", ] -[[package]] -name = "windows-implement" -version = "0.60.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "windows-interface" version = "0.58.0" @@ -3792,33 +3788,6 @@ dependencies = [ "syn", ] -[[package]] -name = "windows-interface" -version = "0.59.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "windows-link" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38" - -[[package]] -name = "windows-numerics" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9150af68066c4c5c07ddc0ce30421554771e528bde427614c61038bc2c92c2b1" -dependencies = [ - "windows-core 0.61.0", - "windows-link", -] - [[package]] name = "windows-result" version = "0.2.0" @@ -3828,34 +3797,16 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-result" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c64fd11a4fd95df68efcfee5f44a294fe71b8bc6a91993e2791938abcc712252" -dependencies = [ - "windows-link", -] - [[package]] name = "windows-strings" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" dependencies = [ - "windows-result 0.2.0", + "windows-result", "windows-targets 0.52.6", ] -[[package]] -name = "windows-strings" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a2ba9642430ee452d5a7aa78d72907ebe8cfda358e8cb7918a2050581322f97" -dependencies = [ - "windows-link", -] - [[package]] name = "windows-sys" version = "0.45.0" @@ -4273,7 +4224,7 @@ dependencies = [ "hex", "nix", "ordered-stream", - "rand", + "rand 0.8.5", "serde", "serde_repr", "sha1", @@ -4517,6 +4468,7 @@ dependencies = [ "enumflags2", "serde", "static_assertions", + "url", "winnow", "zvariant_derive 5.4.0", "zvariant_utils 3.2.0", diff --git a/Cargo.toml b/Cargo.toml index 1fee7d1..6e12847 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,8 +8,15 @@ egui = "0.31.1" eframe = "0.31.1" env_logger = "0.11.8" anyhow = "1.0.97" -mundy = "0.1.8" serde = { version = "1.0.219", features = ["derive"] } +serde_json = "1.0.140" registry = "1.3.0" dirs = "6.0.0" keyvalues-parser = "0.2.0" +crossbeam-channel = "0.5.14" +rfd = { version = "0.15.3", features = ["xdg-portal"] } +regex = "1.11.1" +sha2 = "0.10.8" +hex = "0.4.3" +egui_alignments = "0.3.4" + diff --git a/flake.lock b/flake.lock index f51f724..65bbc09 100644 --- a/flake.lock +++ b/flake.lock @@ -19,11 +19,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1743568003, - "narHash": "sha256-ZID5T65E8ruHqWRcdvZLsczWDOAWIE7om+vQOREwiX0=", + "lastModified": 1744502386, + "narHash": "sha256-QAd1L37eU7ktL2WeLLLTmI6P9moz9+a/ONO8qNBYJgM=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "b7ba7f9f45c5cd0d8625e9e217c28f8eb6a19a76", + "rev": "f6db44a8daa59c40ae41ba6e5823ec77fe0d2124", "type": "github" }, "original": { @@ -61,11 +61,11 @@ "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1743561237, - "narHash": "sha256-dd97LXek202OWmUXvKYFdYWj0jHrn3p+L5Ojh1SEOqs=", + "lastModified": 1744513456, + "narHash": "sha256-NLVluTmK8d01Iz+WyarQhwFcXpHEwU7m5hH3YQQFJS0=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "1de27ae43712a971c1da100dcd84386356f03ec7", + "rev": "730fd8e82799219754418483fabe1844262fd1e2", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 9adb5fe..d39e68c 100644 --- a/flake.nix +++ b/flake.nix @@ -48,30 +48,4 @@ ] ++ native-deps; }; }; - # flake-utils.lib.eachDefaultSystem (system: - # let - # overlays = [ (import rust-overlay) ]; - # pkgs = import nixpkgs { - # inherit system overlays; - # }; - # native-deps = with pkgs; [ - # pkg-config pipewire lld clang libclang alsa-lib openssl zlib libxkbcommon libGL wayland mangohud - # ]; - # in - # with pkgs; - # { - # devShells.default = mkShell { - # buildInputs = with pkgs; [ - # (rust-bin.stable.latest.default.override { - # extensions = [ "rust-src" ]; - # targets = ["x86_64-unknown-linux-gnu" "x86_64-pc-windows-gnu"]; - # }) - # cargo-bloat - # pkgs.pkgsCross.mingwW64.buildPackages.gcc - # ] ++ native-deps; - # LD_LIBRARY_PATH = (lib.makeLibraryPath native-deps); - # CARGO_TARGET_X86_64_PC_WINDOWS_GNU_RUSTFLAGS = "-L native=${pkgs.pkgsCross.mingwW64.windows.pthreads}/lib"; - # }; - # } - # ); } diff --git a/src/app_logic.rs b/src/app_logic.rs new file mode 100644 index 0000000..78bed54 --- /dev/null +++ b/src/app_logic.rs @@ -0,0 +1,70 @@ +use std::{sync::Arc, thread, time::Duration}; + +use crossbeam_channel::Receiver; +use egui::{mutex::Mutex}; + +use crate::omori_locator; + +#[derive(Clone)] +pub enum UiState { + Loading, + KeyRequired(String) +} + +#[derive(Clone)] +pub struct UiStateHolder { + pub state: Arc> +} + +pub enum UiEvent { + SetKey(Vec) +} + +pub struct AppThread { + ui_state: UiStateHolder, + context: egui::Context, + ui_event_channel: Receiver, + decryption_key: Vec +} + +impl AppThread { + fn commit(&self, s: UiState) { + let mut state = self.ui_state.state.lock(); + *state = s; + } + + fn get_key(&mut self, reason: String) { + self.commit(UiState::KeyRequired(reason)); + loop { + match self.ui_event_channel.recv().expect("The UI event channel was closed.") { + UiEvent::SetKey(key) => { + self.decryption_key = key; + break + } + _ => {} + } + } + + self.commit(UiState::Loading); + } + + pub fn create(state_holder: &UiStateHolder, context: &egui::Context, ui_event_channel: &Receiver) -> AppThread { + AppThread { + ui_state: state_holder.clone(), + context: context.clone(), + ui_event_channel: ui_event_channel.clone(), + decryption_key: Vec::new() + } + } + + pub fn main(&mut self) { + self.commit(UiState::Loading); + + match omori_locator::get_omori_key() { + Ok(key) => self.decryption_key = key, + Err(reason) => self.get_key(format!("{:?}", reason)), + } + + println!("{:?}", self.decryption_key); + } +} diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..91fd61d --- /dev/null +++ b/src/config.rs @@ -0,0 +1,9 @@ +struct Config { + key: Option> +} + +impl Default for Config { + fn default() -> Self { + Self { key: Default::default() } + } +} \ No newline at end of file diff --git a/src/keyhash b/src/keyhash new file mode 100644 index 0000000..b27868d --- /dev/null +++ b/src/keyhash @@ -0,0 +1 @@ + &$ēԐˈu661 \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index f5e1372..abf218e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,16 @@ mod omori_locator; +mod app_logic; +mod config; -use std::{thread, time::Duration}; +use std::{sync::Arc, thread, time::Duration}; +use app_logic::{AppThread, UiEvent, UiState, UiStateHolder}; +use crossbeam_channel::{Receiver, Sender}; use eframe::egui; -use egui::{RichText, ThemePreference}; -use omori_locator::get_omori_path; +use egui::{mutex::{Mutex, RwLock}, Align, Layout, RichText, ThemePreference}; +use egui_alignments::{center_horizontal, center_vertical, top_horizontal, Aligner}; +use omori_locator::{get_omori_key, get_omori_path}; +use sha2::Digest; fn main() -> anyhow::Result<()> { env_logger::init(); @@ -15,13 +21,22 @@ fn main() -> anyhow::Result<()> { ..Default::default() }; + let app_state = UiStateHolder { + state: Arc::new(Mutex::new(UiState::Loading)) + }; + + let (sender, receiver): (Sender, Receiver) = crossbeam_channel::unbounded(); - println!("{:?}", get_omori_path().unwrap()); - eframe::run_native("TundleBool", options, Box::new(|cc| { cc.egui_ctx.set_theme(ThemePreference::System); + + let mut app_thread = AppThread::create(&app_state, &cc.egui_ctx, &receiver); - Ok(Box::::default()) + thread::spawn(move || { + app_thread.main(); + }); + + Ok(Box::::new(Application::create(sender, app_state))) })).unwrap(); Ok(()) @@ -29,32 +44,78 @@ fn main() -> anyhow::Result<()> { struct Application { - updates: u32 + state: UiStateHolder, + sender: Sender, + key_input: String } -impl Default for Application { - fn default() -> Self { - Self { - updates: 0 +impl Application { + fn create(sender: Sender, state: UiStateHolder) -> Application { + Application { + sender, + state, + key_input: "".to_string() } } } +const GAME_KEY_HASH: &[u8; 32] = include_bytes!("keyhash"); + impl eframe::App for Application { fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) { - ctx.request_repaint(); - egui::CentralPanel::default().show(ctx, |ui| { - ui.vertical_centered(|ui| { - ui.label(RichText::new("Welcome to BundleTool").size(32.0)); - ui.label(RichText::new(format!("{}", self.updates)).size(32.0)); - }); - self.updates += 1; - ui.separator(); - egui::ScrollArea::vertical().max_width(300.0).auto_shrink(false).show(ui, |ui| { - for i in 1..3000 { - ui.add(egui::Label::new("Meow")); + let state = self.state.state.lock(); + let state = state.clone(); + + match state { + UiState::Loading => { + egui::CentralPanel::default().show(ctx, |ui| { + center_vertical(ui,|ui| { + ui.label(RichText::new("Loading").size(32.0)); + }); + }); + }, + UiState::KeyRequired(reason) => { + let mut is_valid = true; + let hash = sha2::Sha256::digest(&self.key_input.as_bytes()); + for i in 0..32 { + if hash[i] != GAME_KEY_HASH[i] { + is_valid = false; + } } - }); - }); + + egui::TopBottomPanel::top("key_prompt_title_bar").show(ctx, |ui| { + ui.with_layout(Layout::top_down(Align::Center), |ui| { + ui.label(RichText::new("Decryption key required").size(32.0)); + ui.label(RichText::new(format!("Reason: {reason}")).size(24.0)); + }); + }); + + egui::CentralPanel::default().show(ctx, |ui| { + top_horizontal(ui, |ui| { + ui.horizontal(|ui| { + ui.label("Decryption key: "); + ui.text_edit_singleline(&mut self.key_input); + if is_valid { + ui.label("Valid"); + } else { + ui.label(RichText::new("Invalid").color(ui.visuals().error_fg_color)); + } + }); + }); + }); + + egui::TopBottomPanel::bottom("key_prompt_button_bar").show(ctx, |ui| { + if !is_valid { + ui.disable(); + } + + ui.with_layout(Layout::top_down(Align::Max), |ui| { + if ui.button("Continue").clicked() { + self.sender.send(UiEvent::SetKey(self.key_input.as_bytes().to_vec())).expect("Failed to send"); + } + }) + }); + } + } } } \ No newline at end of file diff --git a/src/omori_locator.rs b/src/omori_locator.rs index 0581fa8..f794bb2 100644 --- a/src/omori_locator.rs +++ b/src/omori_locator.rs @@ -1,4 +1,6 @@ use anyhow::Context; +use regex::bytes::Regex; +use sha2::Digest; use std::{fs::File, io::Read, path::PathBuf}; #[cfg(any(target_os = "linux", target_os = "macos"))] @@ -76,4 +78,38 @@ pub fn get_omori_path() -> anyhow::Result { omori_path.with_context(|| "Failed to find omori") +} + +const GAME_KEY_HASH: &[u8; 32] = include_bytes!("keyhash"); + +pub fn get_omori_key() -> anyhow::Result> { + let mut base: PathBuf = get_steam_root()?; + + base.push("appcache/appinfo.vdf"); + + let mut buffer = Vec::new(); + + let mut fd = File::open(base)?; + fd.read_to_end(&mut buffer)?; + drop(fd); + + let re = Regex::new(r"--([0-9a-f]{32})")?; + + for (_, [key]) in re.captures_iter(&buffer).map(|c| c.extract()) { + let hash = sha2::Sha256::digest(key); + + let mut equal = true; + for i in 0..32 { + if hash[i] != GAME_KEY_HASH[i] { + equal = false; + } + } + + if equal { + return Ok(key.to_vec()) + } + } + + + Err(anyhow::anyhow!("Couldn't find any valid decryption key for OMORI in your Steam installation.")) } \ No newline at end of file