Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aeb99992bb
|
||
|
|
8ab6e14560
|
||
|
|
b9ebdfdb5c
|
||
|
|
2804812691
|
||
|
|
606fb7e191
|
||
|
|
e2a779b7f5
|
||
|
|
a8b04bb72b
|
||
|
|
c34cf187d5
|
||
|
|
f07421e75a
|
||
|
|
8b4a455dc1
|
||
|
|
a1300f8d76
|
||
|
|
9e623219a5
|
||
|
|
09e19b6e16
|
||
|
|
4498c45965
|
||
|
|
af8a5b1746
|
||
|
|
560d9659f4
|
||
|
|
bf086d0442
|
||
|
|
a6ea8ad8e2
|
||
|
|
4c00d1846b
|
||
|
|
e5e335f4f3
|
||
|
|
3ab5987b67
|
||
|
|
2030796337
|
||
|
|
2edb4f492a
|
||
|
|
114292d912
|
||
|
|
8adc1f49ad
|
||
|
|
bb27334f57
|
||
|
|
1e13905885
|
||
|
|
8fc73b2992
|
||
|
|
43b72995dd
|
||
|
|
d3473d46e3
|
||
|
|
1363f5b125
|
||
|
|
d15b8070ec | ||
|
|
efccd6ed50 | ||
|
|
5c73ee7bd5 | ||
|
|
445b63fa4c | ||
|
|
941868dcc8 | ||
|
|
762a3b9b26 | ||
|
|
0cb211c103 | ||
|
|
90b32c5c5a | ||
|
|
71c3c69ea2 | ||
|
|
b553e418f5 | ||
|
|
ab026c0bc6 | ||
|
|
32e21f58a1 | ||
|
|
b0c339cc5f | ||
|
|
c2584b5d01 | ||
|
|
3322f9582f | ||
|
|
5348a1d6ee | ||
|
|
05ce68cb47 | ||
|
|
f63d24ea43 | ||
|
|
356d5f17e5 | ||
|
|
bc5e80aaca | ||
|
|
e050231692 | ||
|
|
6e33536dfe | ||
|
|
c36a41f919 | ||
|
|
660e7a874f | ||
|
|
72abda7352 | ||
|
|
ebf704c6f4 | ||
|
|
5c5e6d60a1 | ||
|
|
98a6545b27 | ||
|
|
a9a965462a | ||
|
|
81b4b26f96 | ||
|
|
06df466d24 | ||
|
|
b8c444dc5b | ||
|
|
e848ca8d79 | ||
|
|
0a831580e2 | ||
|
|
10e69eaac3 | ||
|
|
9dbfbc4419 | ||
|
|
ef0b6de6ba | ||
|
|
e7470bd694 | ||
|
|
936f683385 | ||
|
|
b3158f71fb | ||
|
|
070e477fd4 | ||
|
|
7745bba10e | ||
|
|
8d7a0d12b9 | ||
|
|
b325ebb03c | ||
|
|
38c6402a12 | ||
|
|
2d42c0c3c4 | ||
|
|
a423721aee | ||
|
|
f3436c8ddc | ||
|
|
afcf0a87c0 | ||
|
|
73d610949f | ||
|
|
7f358d9adb | ||
|
|
7caa5421f7 | ||
|
|
ecac0d54aa | ||
|
|
a84401ca33 | ||
|
|
1bcd6b2c7d | ||
|
|
1dbdc0e4cb | ||
|
|
3610e44a08 | ||
|
|
f5fd22d35c | ||
|
|
022828b802 | ||
|
|
262d2d0720 | ||
|
|
2326edf97b | ||
|
|
301be82837 | ||
|
|
0d7dde929d | ||
|
|
3ab802fd56 | ||
|
|
53030cc5f7 | ||
|
|
383224c2fa | ||
|
|
575a6a4f1d | ||
|
|
17579de277 | ||
|
|
00727b9913 | ||
|
|
1f6fc22525 | ||
|
|
27b09be76e | ||
|
|
6f15e8c348 | ||
|
|
d294aa9861 | ||
|
|
f688f1c3c4 | ||
|
|
58ec9f6567 | ||
|
|
1c9ce2a4d3 | ||
|
|
8a5d6cf38c | ||
|
|
d789b0f62d | ||
|
|
6079a72f47 | ||
|
|
914ffe46d2 | ||
|
|
935703e1ab | ||
|
|
202554e03b | ||
|
|
da2b15a0b6 | ||
|
|
ccc27b1944 | ||
|
|
10168e84d1 | ||
|
|
e72964a9f8 | ||
|
|
18052d0c78 | ||
|
|
09f5a3895b | ||
|
|
89892ef592 | ||
|
|
61de3aeee3 | ||
|
|
4ed00e6ac3 | ||
|
|
332db0ea03 | ||
|
|
64d13e3964 | ||
|
|
feb3a793d9 | ||
|
|
585f454bc0 | ||
|
|
27524e855a | ||
|
|
0257834d04 | ||
|
|
64e94bf790 | ||
|
|
668a6eb38b | ||
|
|
0de79769d2 | ||
|
|
b79c5f62b3 | ||
|
|
2c3092026a | ||
|
|
69eda1103d | ||
|
|
19b1ade758 | ||
|
|
18f667a91a | ||
|
|
186371f835 | ||
|
|
ce2022db55 | ||
|
|
d992d6b8f6 | ||
|
|
b71dbbdf03 | ||
|
|
c85a169765 | ||
|
|
9df757c169 | ||
|
|
92cbec7934 | ||
|
|
41cfb12ea8 | ||
|
|
e328eb91f6 | ||
|
|
10c840ac4d | ||
|
|
2fc0aa2005 | ||
|
|
29f726b1bd | ||
|
|
16d3c2cd96 | ||
|
|
4ce7f3459d | ||
|
|
c8cbb51f43 | ||
|
|
9c53239276 | ||
|
|
af5ea259e9 | ||
|
|
162350699a | ||
|
|
2977398437 | ||
|
|
36dce5aa1e | ||
|
|
6935b852ce | ||
|
|
1c048e6aff | ||
|
|
84a659a2b1 | ||
|
|
db4ca22f95 | ||
|
|
284c4bb46d | ||
|
|
5fe697223c | ||
|
|
33fbbc7fc0 | ||
|
|
5bcdccdfea | ||
|
|
31ac09cd25 | ||
|
|
1283f34174 | ||
|
|
072c8ae406 | ||
|
|
e283393889 | ||
|
|
cf5c37c7dc | ||
|
|
c6cd0cf2f9 | ||
|
|
d182ca5318 | ||
|
|
42ee688639 | ||
|
|
ba49ed0e67 | ||
|
|
f9f326904e | ||
|
|
c3a1e864a7 | ||
|
|
7f795ba52e |
@@ -0,0 +1,31 @@
|
|||||||
|
name: Create release for pushed tag
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- "*"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release-on-tag:
|
||||||
|
runs-on: windows-latest
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- uses: dtolnay/rust-toolchain@stable
|
||||||
|
- name: Create release
|
||||||
|
shell: bash
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
TAG: ${{ github.ref_name }}
|
||||||
|
run: |
|
||||||
|
if gh release view "$TAG" >/dev/null 2>&1; then
|
||||||
|
echo "A release already exists for $TAG, skipping"
|
||||||
|
else
|
||||||
|
cargo build --release
|
||||||
|
prev_tag=$(gh release list --limit 100 --json tagName --jq '.[0].tagName')
|
||||||
|
notes="**Full Changelog**: https://github.com/${{ github.repository }}/compare/${prev_tag}...${TAG}"
|
||||||
|
gh release create "$TAG" target/release/gta-tools.exe \
|
||||||
|
--title "$TAG" \
|
||||||
|
--notes "$notes"
|
||||||
|
fi
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
name: Create releases for existing tags
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release-retroactively:
|
||||||
|
runs-on: windows-latest
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v5
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Install Rust toolchain
|
||||||
|
uses: dtolnay/rust-toolchain@stable
|
||||||
|
- name: Get tags and create release for each
|
||||||
|
shell: bash
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: |
|
||||||
|
mapfile -t tags < <(git tag -l)
|
||||||
|
echo "${#tags[@]} tags found."
|
||||||
|
prev_tag=""
|
||||||
|
for tag in "${tags[@]}"; do
|
||||||
|
if gh release view "$tag" >/dev/null 2>&1; then
|
||||||
|
echo "A release already exists for $tag, skipping"
|
||||||
|
else
|
||||||
|
echo "Proceeding with tag $tag"
|
||||||
|
git checkout "$tag"
|
||||||
|
cargo build --release
|
||||||
|
if [ -n "$prev_tag" ]; then
|
||||||
|
notes="**Full Changelog**: https://github.com/${{ github.repository }}/compare/${prev_tag}...${tag}"
|
||||||
|
else
|
||||||
|
notes="**Full Changelog**: https://github.com/${{ github.repository }}/commits/${tag}"
|
||||||
|
fi
|
||||||
|
gh release create "$tag" target/release/gta-tools.exe \
|
||||||
|
--title "$tag" \
|
||||||
|
--notes "$notes"
|
||||||
|
fi
|
||||||
|
prev_tag="$tag"
|
||||||
|
done
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
/target
|
/target
|
||||||
.vscode
|
.vscode
|
||||||
|
.idea
|
||||||
Generated
+775
-2002
File diff suppressed because it is too large
Load Diff
+26
-18
@@ -1,34 +1,42 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "gta-tools"
|
name = "gta-tools"
|
||||||
version = "0.3.0"
|
version = "0.10.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
license = "Apache-2.0"
|
||||||
|
authors = ["futile <git@futile.eu>"]
|
||||||
|
description = "A toolset of convenient things for GTA V Online."
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
catppuccin-egui = { version = "5.5.0", default-features = false, features = [
|
catppuccin-egui = { version = "5.6.0", default-features = false, features = [
|
||||||
"egui31",
|
"egui32",
|
||||||
] }
|
] }
|
||||||
dirs = "6.0.0"
|
eframe = { version = "0.32.2", default-features = false, features = [
|
||||||
eframe = "0.31.1"
|
"glow",
|
||||||
egui_extras = { version = "0.31.1", features = ["image"] }
|
"default_fonts",
|
||||||
image = { version = "0.25.6", default-features = false, features = ["png"] }
|
] }
|
||||||
|
egui_extras = { version = "0.32.2", default-features = false, features = [
|
||||||
|
"image",
|
||||||
|
"svg",
|
||||||
|
] }
|
||||||
|
humantime = "2.3.0"
|
||||||
|
image = { version = "0.25.8", default-features = false, features = ["png"] }
|
||||||
|
log = "0.4.28"
|
||||||
open = "5.3.2"
|
open = "5.3.2"
|
||||||
serde = { version = "1.0.219", features = ["derive"] }
|
serde = { version = "1.0.219", features = ["derive"] }
|
||||||
serde_json = "1.0.140"
|
serde_json = "1.0.143"
|
||||||
sysinfo = "0.34.2"
|
strum = { version = "0.27.2", features = ["derive"] }
|
||||||
windows = { version = "0.61.1", features = [
|
windows = { version = "0.62.0", features = [
|
||||||
"Win32_UI_Input_KeyboardAndMouse",
|
"Win32_NetworkManagement_WindowsFirewall",
|
||||||
|
"Win32_Security",
|
||||||
|
"Win32_System_Com",
|
||||||
|
"Win32_System_Diagnostics_ToolHelp",
|
||||||
"Win32_System_Threading",
|
"Win32_System_Threading",
|
||||||
|
"Win32_UI_Input_KeyboardAndMouse",
|
||||||
"Win32_UI_Shell",
|
"Win32_UI_Shell",
|
||||||
"Win32_UI_WindowsAndMessaging",
|
"Win32_UI_WindowsAndMessaging",
|
||||||
"Win32_Security",
|
|
||||||
] }
|
] }
|
||||||
winreg = "0.55.0"
|
winreg = "0.55.0"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
static_vcruntime = "2.0.0"
|
static_vcruntime = "2.0.0"
|
||||||
winresource = "0.1.20"
|
tauri-winres = "0.3.3"
|
||||||
|
|
||||||
[profile.release]
|
|
||||||
strip = true
|
|
||||||
lto = true
|
|
||||||
codegen-units = 1
|
|
||||||
|
|||||||
@@ -0,0 +1,176 @@
|
|||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
@@ -1,3 +1,69 @@
|
|||||||
more spaghetti than the nation of italy
|
# GTA Tools
|
||||||
|
|
||||||

|
A toolset of convenient things for GTA V Online.
|
||||||
|
|
||||||
|
<picture>
|
||||||
|
<source srcset="https://i.vgy.me/M4sOHh.png" media="(prefers-color-scheme: dark)">
|
||||||
|
<img src="https://i.vgy.me/mpO9uc.png">
|
||||||
|
</picture>
|
||||||
|
|
||||||
|
## Installing
|
||||||
|
|
||||||
|
**Option 1** — <ins>Download</ins>
|
||||||
|
Download the latest release [here](https://github.com/elituf/gta-tools/releases/latest/download/gta-tools.exe) and place it somewhere convenient for you, such as Documents. You could then make a shortcut titled "GTA Tools", and pin it to taskbar or Start.
|
||||||
|
|
||||||
|
**Option 2** — <ins>Build from source</ins>
|
||||||
|
You will need the Rust toolchain, which can be obtained [here](https://rustup.rs). Follow the instructions of its installer. Once you have Rust installed, clone this repo and navigate to it. At this point, you should probably `git checkout x.x.x`, where `x.x.x` is the latest tag. You can then run `cargo build --release`. Once you do that, you can use the binary located at `.\target\release\gta-tools.exe` in the same way as **Option 1**.
|
||||||
|
|
||||||
|
## Guide
|
||||||
|
|
||||||
|
Every feature of GTA Tools is Legacy/Enhanced-agnostic. Some functionality of GTA Tools requires administrator access. If necessary, GTA Tools can either be started as admin manually, or, the user can simply use the <kbd>Elevate</kbd> button to relaunch GTA Tools as admin.
|
||||||
|
|
||||||
|
It is recommended to always use an up-to-date version of GTA Tools from [releases](https://github.com/elituf/gta-tools/releases). You can also easily access this repository by going to the <kbd>About</kbd> page of GTA Tools and clicking the GitHub button beside the version number.
|
||||||
|
|
||||||
|
#### Game
|
||||||
|
|
||||||
|
This section is quite simple.
|
||||||
|
|
||||||
|
There is a <kbd>Launch</kbd> feature, which will start your game on the chosen launcher and game version.
|
||||||
|
|
||||||
|
There is also a <kbd>Force close game</kbd> feature, which simply kills all game processes. This button requires a second press after the first one for confirmation. This *does not* touch Rockstar Games Launcher or any other processes, only ones named `GTA5_Enhanced.exe` or `GTA5.exe`.
|
||||||
|
|
||||||
|
#### Session
|
||||||
|
|
||||||
|
This section also has two features.
|
||||||
|
|
||||||
|
The first being <kbd>Empty current session</kbd>, which "removes everyone" from your session by suspending your game for 10 seconds, and then resuming it. This method is exceedingly similar to the Resource Monitor method, but made convenient in one button. This can be useful in numerous ways:
|
||||||
|
* You are stuck loading into a session
|
||||||
|
* You are stuck loading into an interior
|
||||||
|
* You are about to get griefed while doing a freemode mission
|
||||||
|
* You want to quickly get a "new" session
|
||||||
|
|
||||||
|
The other feature is <kbd>Anti AFK</kbd>, which, when toggled, prevents you from getting kicked for idling by pressing keys on your keyboard every 60 seconds. At present, those keys are `VK_NUMPAD4` & `VK_NUMPAD6`, due to being a relatively good balance of keys that the game actually registers but don't interrupt gameplay too much if they activate while you're playing. You *must* be tabbed into GTA V for <kbd>Anti AFK</kbd> to work. While toggled, <kbd>Anti AFK</kbd> will only activate when all of the following conditions are true:
|
||||||
|
* The `Grand Theft Auto V` window is currently focused
|
||||||
|
* None of the designated keys are currently being pressed[^1]
|
||||||
|
* The mouse cursor is not currently visible[^2]
|
||||||
|
|
||||||
|
#### Network
|
||||||
|
|
||||||
|
The last section has a single feature, <kbd>Game's network access</kbd>, with two buttons, <kbd>Block</kbd> and <kbd>Unblock</kbd>, and a coloured indicator dot. This feature requires administrator, and blocks/unblocks GTA V's entire internet access using the Windows Firewall. The coloured indicator dot has these meanings:
|
||||||
|
* **Green** - the game is connected to the internet
|
||||||
|
* **Yellow** - the game could not be found running, and thus was not blocked
|
||||||
|
* **Red** - the game is blocked from the internet
|
||||||
|
|
||||||
|
This feature is primarily useful for **replay glitching**, which is an exploit that allows you to complete any heist/mission finale, get the money for it, and then be able to do it again right away. Here's how you can do a replay glitch:
|
||||||
|
1. Get to the finale of a heist/contract/mission series, such as **The Contract: Dr. Dre**
|
||||||
|
2. Complete the finale as normal
|
||||||
|
3. Right *after* the **HEIST/MISSION PASSED** screen you get when you complete a finale (basically, when your cut is being shown), <kbd>Block</kbd> the game's internet access
|
||||||
|
4. After a few seconds, you will be shown an error screen and kicked to the main menu
|
||||||
|
5. At this point, <kbd>Unblock</kbd> the game's internet access and load back into online
|
||||||
|
6. Finally, spend any amount of money, and you should receive the finale cut, but also be able to go play the finale again immediately
|
||||||
|
|
||||||
|
## Issues
|
||||||
|
|
||||||
|
- I have noticed that on my current Windows 10 install, when not elevated (administrator), the <kbd>Force close game</kbd> and <kbd>Empty current session</kbd> features can fail due to being denied access. This was tested by other people and is not guaranteed to happen. If this does happen to you, I recommend using GTA Tools always in elevated mode. Check "Always start elevated" in the Settings tab.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[^1]: Otherwise, if you are, for example, using those keys to fly a plane, <kbd>Anti AFK</kbd> activating could cancel the input.
|
||||||
|
[^2]: Specifically, the Windows mouse cursor, not the in-game mouse cursor. This check is mostly used to prevent typing while you are in the Rockstar overlay.
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
width="512"
|
||||||
|
height="512"
|
||||||
|
viewBox="0 0 512 512"
|
||||||
|
version="1.1"
|
||||||
|
id="svg1"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg">
|
||||||
|
<defs
|
||||||
|
id="defs1" />
|
||||||
|
<g
|
||||||
|
id="layer1">
|
||||||
|
<circle
|
||||||
|
style="fill:#ffffff"
|
||||||
|
id="path1"
|
||||||
|
cx="256"
|
||||||
|
cy="256"
|
||||||
|
r="256" />
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 458 B |
@@ -1,7 +1,23 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
static_vcruntime::metabuild();
|
static_vcruntime::metabuild();
|
||||||
winresource::WindowsResource::new()
|
tauri_winres::WindowsResource::new()
|
||||||
|
.set("FileDescription", "GTA Tools")
|
||||||
|
.set("ProductName", "GTA Tools")
|
||||||
|
.set("LegalCopyright", "futile <git@futile.eu>")
|
||||||
|
.set_language(0x0009)
|
||||||
.set_icon("assets/icon.ico")
|
.set_icon("assets/icon.ico")
|
||||||
.compile()
|
.compile()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
embed_latest_git_hash();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn embed_latest_git_hash() {
|
||||||
|
let git_rev_parse = std::process::Command::new("git")
|
||||||
|
.args(["rev-parse", "--short=8", "HEAD"])
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
let git_hash = String::from_utf8(git_rev_parse.stdout).unwrap();
|
||||||
|
println!("cargo::rustc-env=LATEST_GIT_COMMIT_HASH={git_hash}");
|
||||||
|
println!("cargo::rerun-if-changed=.git/refs/heads/main");
|
||||||
|
println!("cargo::rerun-if-changed=.git/HEAD");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
set windows-shell := ["pwsh", "-NoLogo", "-NoProfileLoadTime", "-Command"]
|
|
||||||
|
|
||||||
build:
|
|
||||||
cargo build --release
|
|
||||||
upx .\target\release\gta-tools.exe --best
|
|
||||||
|
|
||||||
install: build
|
|
||||||
cp .\target\release\gta-tools.exe ~\.cargo\bin
|
|
||||||
cp .\target\release\gta-tools.exe ~\Documents
|
|
||||||
+34
-26
@@ -1,12 +1,12 @@
|
|||||||
use crate::util::{self, consts::GTA_WINDOW_TITLE};
|
use crate::util::{self, consts::game::WINDOW_TITLE};
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
use windows::Win32::UI::Input::KeyboardAndMouse::{
|
use windows::Win32::UI::Input::KeyboardAndMouse::{
|
||||||
KEYBD_EVENT_FLAGS, MAP_VIRTUAL_KEY_TYPE, MapVirtualKeyW, keybd_event,
|
INPUT, INPUT_KEYBOARD, KEYBD_EVENT_FLAGS, KEYBDINPUT, KEYEVENTF_KEYUP, MAPVK_VK_TO_VSC,
|
||||||
|
MapVirtualKeyW, SendInput, VIRTUAL_KEY, VK_NUMPAD4, VK_NUMPAD6,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const INTERVAL: Duration = Duration::from_secs(60);
|
const INTERVAL: Duration = Duration::from_secs(60);
|
||||||
const VK_NUMPAD4: u8 = 0x64;
|
const PRESS_KEYS: [VIRTUAL_KEY; 2] = [VK_NUMPAD4, VK_NUMPAD6];
|
||||||
const VK_NUMPAD6: u8 = 0x66;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct AntiAfk {
|
pub struct AntiAfk {
|
||||||
@@ -24,31 +24,39 @@ impl Default for AntiAfk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AntiAfk {
|
impl AntiAfk {
|
||||||
pub fn activate(&mut self) {
|
pub fn can_activate(&self) -> bool {
|
||||||
if util::is_window_focused(GTA_WINDOW_TITLE)
|
use util::win::{is_any_key_pressed, is_cursor_visible, is_window_focused};
|
||||||
&& !util::is_key_pressed(VK_NUMPAD4 as i32)
|
is_window_focused(WINDOW_TITLE) && !is_any_key_pressed(&PRESS_KEYS) && !is_cursor_visible()
|
||||||
&& !util::is_key_pressed(VK_NUMPAD6 as i32)
|
|
||||||
{
|
|
||||||
send(VK_NUMPAD4);
|
|
||||||
send(VK_NUMPAD6);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn should_activate(&self) -> bool {
|
||||||
|
self.enabled && self.interval.elapsed() >= INTERVAL
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn activate(&mut self) {
|
||||||
|
send(&PRESS_KEYS);
|
||||||
self.interval = Instant::now();
|
self.interval = Instant::now();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send(vk_code: u8) {
|
fn send(vk_codes: &[VIRTUAL_KEY]) {
|
||||||
unsafe {
|
let mut inputs = Vec::new();
|
||||||
keybd_event(
|
for &vk_code in vk_codes {
|
||||||
vk_code,
|
let scan_code = unsafe { MapVirtualKeyW(u32::from(vk_code.0), MAPVK_VK_TO_VSC) } as u16;
|
||||||
u8::try_from(MapVirtualKeyW(u32::from(vk_code), MAP_VIRTUAL_KEY_TYPE(0))).unwrap(),
|
for event in [KEYBD_EVENT_FLAGS(0), KEYEVENTF_KEYUP] {
|
||||||
KEYBD_EVENT_FLAGS(0),
|
let mut input = INPUT {
|
||||||
0,
|
r#type: INPUT_KEYBOARD,
|
||||||
);
|
..Default::default()
|
||||||
keybd_event(
|
};
|
||||||
vk_code,
|
input.Anonymous.ki = KEYBDINPUT {
|
||||||
u8::try_from(MapVirtualKeyW(u32::from(vk_code), MAP_VIRTUAL_KEY_TYPE(0))).unwrap(),
|
wVk: vk_code,
|
||||||
KEYBD_EVENT_FLAGS(2),
|
wScan: scan_code,
|
||||||
0,
|
dwFlags: event,
|
||||||
);
|
time: 0,
|
||||||
|
dwExtraInfo: 0,
|
||||||
|
};
|
||||||
|
inputs.push(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
unsafe { SendInput(&inputs, size_of::<INPUT>() as i32) };
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
use crate::{features, gui::App, util::countdown::Countdown};
|
use crate::util::{
|
||||||
|
consts::game::{EXE_ENHANCED, EXE_LEGACY},
|
||||||
|
countdown::Countdown,
|
||||||
|
system_info::SystemInfo,
|
||||||
|
};
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
use sysinfo::System;
|
|
||||||
use windows::Win32::{
|
use windows::Win32::{
|
||||||
Foundation::{CloseHandle, HANDLE, NTSTATUS},
|
Foundation::{HANDLE, NTSTATUS},
|
||||||
System::Threading::{OpenProcess, PROCESS_SUSPEND_RESUME},
|
System::Threading::{OpenProcess, PROCESS_SUSPEND_RESUME},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const INTERVAL: Duration = Duration::from_secs(10);
|
const INTERVAL: Duration = Duration::from_secs(10);
|
||||||
const ENHANCED: &str = "GTA5_Enhanced.exe";
|
|
||||||
const LEGACY: &str = "GTA5.exe";
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct EmptySession {
|
pub struct EmptySession {
|
||||||
@@ -22,45 +23,58 @@ impl Default for EmptySession {
|
|||||||
Self {
|
Self {
|
||||||
disabled: false,
|
disabled: false,
|
||||||
interval: Instant::now(),
|
interval: Instant::now(),
|
||||||
countdown: Countdown::new(features::empty_session::INTERVAL.as_secs()),
|
countdown: Countdown::new(INTERVAL.as_secs()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EmptySession {
|
||||||
|
pub fn run_timers(&mut self, game_handle: &mut HANDLE) {
|
||||||
|
if self.disabled {
|
||||||
|
self.countdown.count();
|
||||||
|
} else {
|
||||||
|
self.countdown.reset();
|
||||||
|
}
|
||||||
|
if self.interval.elapsed() >= INTERVAL {
|
||||||
|
deactivate(game_handle);
|
||||||
|
self.disabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[link(name = "ntdll")]
|
#[link(name = "ntdll")]
|
||||||
unsafe extern "system" {
|
unsafe extern "system" {
|
||||||
pub unsafe fn NtSuspendProcess(ProcessHandle: HANDLE) -> NTSTATUS;
|
unsafe fn NtSuspendProcess(ProcessHandle: HANDLE) -> NTSTATUS;
|
||||||
pub unsafe fn NtResumeProcess(ProcessHandle: HANDLE) -> NTSTATUS;
|
unsafe fn NtResumeProcess(ProcessHandle: HANDLE) -> NTSTATUS;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_gta_pid(sysinfo: &mut System) -> u32 {
|
fn get_gta_pid(system_info: &mut SystemInfo) -> Option<u32> {
|
||||||
sysinfo.refresh_all();
|
system_info.refresh();
|
||||||
if let Some((pid, _)) = sysinfo
|
system_info
|
||||||
.processes()
|
.processes()
|
||||||
.iter()
|
.iter()
|
||||||
.find(|(_, p)| p.name() == ENHANCED || p.name() == LEGACY)
|
.find(|p| p.name() == EXE_ENHANCED || p.name() == EXE_LEGACY)
|
||||||
{
|
.map(|p| p.pid())
|
||||||
return pid.as_u32();
|
}
|
||||||
|
|
||||||
|
pub fn activate(game_handle: &mut HANDLE, system_info: &mut SystemInfo) -> bool {
|
||||||
|
let Some(pid) = get_gta_pid(system_info) else {
|
||||||
|
return false;
|
||||||
};
|
};
|
||||||
u32::MAX
|
match unsafe { OpenProcess(PROCESS_SUSPEND_RESUME, false, pid) } {
|
||||||
|
Ok(handle) => *game_handle = handle,
|
||||||
|
Err(why) => {
|
||||||
|
log::error!("failed to suspend game for empty session:\n{why}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unsafe { NtSuspendProcess(*game_handle) }.unwrap();
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn activate(app: &mut App) {
|
pub fn deactivate(game_handle: &mut HANDLE) {
|
||||||
let pid = get_gta_pid(&mut app.sysinfo);
|
if !game_handle.is_invalid() {
|
||||||
if pid == u32::MAX {
|
// ignoring the return because this function behaves very weirdly
|
||||||
return;
|
let _ = unsafe { NtResumeProcess(*game_handle) };
|
||||||
}
|
|
||||||
unsafe {
|
|
||||||
app.game_handle = OpenProcess(PROCESS_SUSPEND_RESUME, false, pid).unwrap();
|
|
||||||
let _ = NtSuspendProcess(app.game_handle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn deactivate(app: &mut App) {
|
|
||||||
unsafe {
|
|
||||||
if !app.game_handle.is_invalid() {
|
|
||||||
let _ = NtResumeProcess(app.game_handle);
|
|
||||||
let _ = CloseHandle(app.game_handle);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+47
-19
@@ -1,40 +1,68 @@
|
|||||||
use crate::util::consts::{ENHANCED, LEGACY};
|
use crate::util::{
|
||||||
use std::time::Instant;
|
consts::game::{EXE_ENHANCED, EXE_LEGACY},
|
||||||
use sysinfo::System;
|
system_info::SystemInfo,
|
||||||
|
};
|
||||||
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
|
const INTERVAL: Duration = Duration::from_secs(3);
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ForceClose {
|
pub struct ForceClose {
|
||||||
pub button_text: String,
|
pub button_text: String,
|
||||||
pub prompting: bool,
|
timer: Instant,
|
||||||
pub interval: Instant,
|
counting: bool,
|
||||||
|
current_frame: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ForceClose {
|
impl Default for ForceClose {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
button_text: "Force close game".to_string(),
|
button_text: "Force close game".to_owned(),
|
||||||
prompting: false,
|
timer: Instant::now(),
|
||||||
interval: Instant::now(),
|
counting: false,
|
||||||
|
current_frame: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ForceClose {
|
impl ForceClose {
|
||||||
pub fn prompting(&mut self) {
|
pub fn prompt(&mut self, force_close_button_clicked: bool, system_info: &mut SystemInfo) {
|
||||||
self.button_text = "Are you sure?".to_string();
|
if force_close_button_clicked && !self.counting {
|
||||||
self.prompting = true;
|
self.button_text = "Are you sure?".to_owned();
|
||||||
self.interval = Instant::now();
|
self.timer = Instant::now();
|
||||||
|
self.counting = true;
|
||||||
|
self.current_frame = true;
|
||||||
|
}
|
||||||
|
if self.counting && self.timer.elapsed() >= INTERVAL {
|
||||||
|
self.reset();
|
||||||
|
} else if force_close_button_clicked && !self.current_frame {
|
||||||
|
activate(system_info);
|
||||||
|
self.reset();
|
||||||
|
}
|
||||||
|
self.finish_current_frame();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn reset(&mut self) {
|
||||||
|
*self = Self::default();
|
||||||
|
}
|
||||||
|
|
||||||
|
const fn finish_current_frame(&mut self) {
|
||||||
|
if self.current_frame {
|
||||||
|
self.current_frame = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn activate(sysinfo: &mut System) {
|
fn activate(system_info: &mut SystemInfo) {
|
||||||
sysinfo.refresh_all();
|
system_info.refresh();
|
||||||
sysinfo
|
system_info
|
||||||
.processes()
|
.processes()
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|(_, p)| p.name() == ENHANCED || p.name() == LEGACY)
|
.filter(|p| p.name() == EXE_ENHANCED || p.name() == EXE_LEGACY)
|
||||||
.for_each(|(_, p)| {
|
.for_each(|p| {
|
||||||
p.kill();
|
if !p.kill() {
|
||||||
|
log::error!("failed to force close game, probably due to access denied");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
sysinfo.refresh_all();
|
system_info.refresh();
|
||||||
}
|
}
|
||||||
|
|||||||
+129
-60
@@ -1,72 +1,141 @@
|
|||||||
#![allow(clippy::zombie_processes)]
|
use crate::util::{
|
||||||
|
consts::game::{EXE_ENHANCED, EXE_LEGACY},
|
||||||
|
system_info::SystemInfo,
|
||||||
|
};
|
||||||
|
use std::{
|
||||||
|
path::Path,
|
||||||
|
time::{Duration, Instant},
|
||||||
|
};
|
||||||
|
use strum::{Display, EnumIter};
|
||||||
|
use windows::{
|
||||||
|
Win32::{
|
||||||
|
NetworkManagement::WindowsFirewall::{
|
||||||
|
INetFwPolicy2, INetFwRule, NET_FW_ACTION_BLOCK, NET_FW_IP_PROTOCOL_ANY,
|
||||||
|
NET_FW_RULE_DIR_IN, NET_FW_RULE_DIR_OUT, NetFwPolicy2, NetFwRule,
|
||||||
|
},
|
||||||
|
System::Com::{
|
||||||
|
CLSCTX_INPROC_SERVER, COINIT_MULTITHREADED, CoCreateInstance, CoInitializeEx,
|
||||||
|
CoUninitialize,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
core::BSTR,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::util::consts::{ENHANCED, LEGACY};
|
const FILTER_NAME_IN: &str = "[GTA Tools] Block all inbound traffic for GTA V";
|
||||||
use std::{os::windows::process::CommandExt, path::Path, process::Command};
|
const FILTER_NAME_OUT: &str = "[GTA Tools] Block all outbound traffic for GTA V";
|
||||||
use sysinfo::System;
|
|
||||||
|
|
||||||
const FILTER_NAME: &str = "[GTA Tools] Block all traffic for GTA V";
|
const INTERVAL: Duration = Duration::from_secs(3);
|
||||||
const CREATE_NO_WINDOW: u32 = 0x0800_0000;
|
|
||||||
|
|
||||||
fn get_game_exe_path(sysinfo: &mut System) -> Option<&Path> {
|
#[derive(Clone, Copy, Debug, Display, PartialEq, Eq, EnumIter)]
|
||||||
sysinfo.refresh_all();
|
pub enum BlockedStatus {
|
||||||
if let Some((_, process)) = sysinfo
|
Blocked,
|
||||||
.processes()
|
Failed,
|
||||||
.iter()
|
Unblocked,
|
||||||
.find(|(_, p)| p.name() == ENHANCED || p.name() == LEGACY)
|
}
|
||||||
{
|
|
||||||
process.exe()
|
impl From<bool> for BlockedStatus {
|
||||||
|
fn from(value: bool) -> Self {
|
||||||
|
if value {
|
||||||
|
Self::Blocked
|
||||||
} else {
|
} else {
|
||||||
None
|
Self::Unblocked
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn block_all(sysinfo: &mut System) {
|
#[derive(Debug)]
|
||||||
let Some(exe_path) = get_game_exe_path(sysinfo) else {
|
pub struct GameNetworking {
|
||||||
|
com_initialized: bool,
|
||||||
|
pub blocked_status: BlockedStatus,
|
||||||
|
timer: Instant,
|
||||||
|
counting: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for GameNetworking {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
blocked_status: Self::is_blocked().into(),
|
||||||
|
com_initialized: unsafe { CoInitializeEx(None, COINIT_MULTITHREADED) }.is_ok(),
|
||||||
|
timer: Instant::now(),
|
||||||
|
counting: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for GameNetworking {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
if self.com_initialized {
|
||||||
|
unsafe { CoUninitialize() };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GameNetworking {
|
||||||
|
pub fn block_all(&mut self, system_info: &mut SystemInfo) {
|
||||||
|
let Some(exe_path) = get_game_exe_path(system_info) else {
|
||||||
|
self.blocked_status = BlockedStatus::Failed;
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let exe_path = exe_path.display().to_string();
|
let policy: INetFwPolicy2 =
|
||||||
Command::new("netsh")
|
unsafe { CoCreateInstance(&NetFwPolicy2, None, CLSCTX_INPROC_SERVER) }.unwrap();
|
||||||
.args([
|
let rules = unsafe { policy.Rules() }.unwrap();
|
||||||
"advfirewall",
|
let exe_path = BSTR::from(exe_path.to_string_lossy().to_string());
|
||||||
"firewall",
|
for filter in [
|
||||||
"add",
|
(FILTER_NAME_IN, NET_FW_RULE_DIR_IN),
|
||||||
"rule",
|
(FILTER_NAME_OUT, NET_FW_RULE_DIR_OUT),
|
||||||
&format!("name={FILTER_NAME}"),
|
] {
|
||||||
"dir=out",
|
unsafe { rules.Remove(&BSTR::from(filter.0)) }.unwrap();
|
||||||
"action=block",
|
let rule: INetFwRule =
|
||||||
"protocol=ANY",
|
unsafe { CoCreateInstance(&NetFwRule, None, CLSCTX_INPROC_SERVER) }.unwrap();
|
||||||
&format!("program={exe_path}"),
|
unsafe { rule.SetName(&BSTR::from(filter.0)) }.unwrap();
|
||||||
])
|
unsafe { rule.SetApplicationName(&exe_path) }.unwrap();
|
||||||
.creation_flags(CREATE_NO_WINDOW)
|
unsafe { rule.SetDirection(filter.1) }.unwrap();
|
||||||
.spawn()
|
unsafe { rule.SetEnabled(true.into()) }.unwrap();
|
||||||
.unwrap();
|
unsafe { rule.SetAction(NET_FW_ACTION_BLOCK) }.unwrap();
|
||||||
Command::new("netsh")
|
unsafe { rule.SetProtocol(NET_FW_IP_PROTOCOL_ANY.0) }.unwrap();
|
||||||
.args([
|
unsafe { rules.Add(&rule) }.unwrap();
|
||||||
"advfirewall",
|
}
|
||||||
"firewall",
|
self.blocked_status = Self::is_blocked().into();
|
||||||
"add",
|
|
||||||
"rule",
|
|
||||||
&format!("name={FILTER_NAME}"),
|
|
||||||
"dir=in",
|
|
||||||
"action=block",
|
|
||||||
"protocol=ANY",
|
|
||||||
&format!("program={exe_path}"),
|
|
||||||
])
|
|
||||||
.creation_flags(CREATE_NO_WINDOW)
|
|
||||||
.spawn()
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unblock_all() {
|
pub fn unblock_all(&mut self) {
|
||||||
Command::new("netsh")
|
let policy: INetFwPolicy2 =
|
||||||
.args([
|
unsafe { CoCreateInstance(&NetFwPolicy2, None, CLSCTX_INPROC_SERVER) }.unwrap();
|
||||||
"advfirewall",
|
let rules = unsafe { policy.Rules() }.unwrap();
|
||||||
"firewall",
|
unsafe { rules.Remove(&BSTR::from(FILTER_NAME_IN)) }.unwrap();
|
||||||
"delete",
|
unsafe { rules.Remove(&BSTR::from(FILTER_NAME_OUT)) }.unwrap();
|
||||||
"rule",
|
self.blocked_status = Self::is_blocked().into();
|
||||||
&format!("name={FILTER_NAME}"),
|
}
|
||||||
])
|
|
||||||
.creation_flags(CREATE_NO_WINDOW)
|
fn is_blocked() -> bool {
|
||||||
.spawn()
|
let policy: INetFwPolicy2 =
|
||||||
.unwrap();
|
unsafe { CoCreateInstance(&NetFwPolicy2, None, CLSCTX_INPROC_SERVER) }.unwrap();
|
||||||
|
let rules = unsafe { policy.Rules() }.unwrap();
|
||||||
|
let in_rule_exists = unsafe { rules.Item(&BSTR::from(FILTER_NAME_IN)) }.is_ok();
|
||||||
|
let out_rule_exists = unsafe { rules.Item(&BSTR::from(FILTER_NAME_OUT)) }.is_ok();
|
||||||
|
in_rule_exists || out_rule_exists
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn if_failed_return_to_boolean(&mut self) {
|
||||||
|
if self.blocked_status == BlockedStatus::Failed && !self.counting {
|
||||||
|
self.counting = true;
|
||||||
|
self.timer = Instant::now();
|
||||||
|
}
|
||||||
|
if self.blocked_status == BlockedStatus::Failed
|
||||||
|
&& self.counting
|
||||||
|
&& self.timer.elapsed() >= INTERVAL
|
||||||
|
{
|
||||||
|
self.counting = false;
|
||||||
|
self.blocked_status = Self::is_blocked().into();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_game_exe_path(system_info: &mut SystemInfo) -> Option<&Path> {
|
||||||
|
system_info.refresh();
|
||||||
|
system_info
|
||||||
|
.processes()
|
||||||
|
.iter()
|
||||||
|
.find(|p| p.name() == EXE_ENHANCED || p.name() == EXE_LEGACY)
|
||||||
|
.and_then(|p| p.exe())
|
||||||
}
|
}
|
||||||
|
|||||||
+27
-21
@@ -1,41 +1,40 @@
|
|||||||
|
use crate::gui::settings::LaunchVersion;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{fmt::Display, path::PathBuf, process::Command};
|
use std::{path::PathBuf, process::Command};
|
||||||
|
use strum::{Display, EnumIter};
|
||||||
use winreg::{RegKey, enums::HKEY_LOCAL_MACHINE};
|
use winreg::{RegKey, enums::HKEY_LOCAL_MACHINE};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Default, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Clone, Copy, Default, Debug, Display, PartialEq, Eq, Serialize, Deserialize, EnumIter)]
|
||||||
pub enum Platform {
|
pub enum Platform {
|
||||||
#[default]
|
#[default]
|
||||||
Steam,
|
Steam,
|
||||||
|
#[strum(to_string = "Rockstar Games")]
|
||||||
Rockstar,
|
Rockstar,
|
||||||
|
#[strum(to_string = "Epic Games")]
|
||||||
Epic,
|
Epic,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for Platform {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
let x = match self {
|
|
||||||
Self::Steam => "Steam",
|
|
||||||
Self::Rockstar => "Rockstar Games",
|
|
||||||
Self::Epic => "Epic Games",
|
|
||||||
};
|
|
||||||
write!(f, "{x}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct Launch {
|
pub struct Launch {
|
||||||
pub selected: Platform,
|
pub selected: Platform,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn launch(platform: &Platform) {
|
pub fn launch(platform: &Platform, version: &LaunchVersion) {
|
||||||
match platform {
|
match platform {
|
||||||
Platform::Steam => {
|
Platform::Steam => {
|
||||||
let _ = open::that_detached("steam://run/3240220");
|
let steam_url = match version {
|
||||||
|
LaunchVersion::Enhanced => "steam://run/3240220",
|
||||||
|
LaunchVersion::Legacy => "steam://run/271590",
|
||||||
|
};
|
||||||
|
open::that_detached(steam_url).unwrap();
|
||||||
}
|
}
|
||||||
Platform::Rockstar => {
|
Platform::Rockstar => {
|
||||||
let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);
|
let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);
|
||||||
let Ok(gta_v_enhanced) =
|
let rockstar_url = match version {
|
||||||
hklm.open_subkey(r"SOFTWARE\WOW6432Node\Rockstar Games\GTAV Enhanced")
|
LaunchVersion::Enhanced => r"SOFTWARE\WOW6432Node\Rockstar Games\GTAV Enhanced",
|
||||||
else {
|
LaunchVersion::Legacy => r"SOFTWARE\WOW6432Node\Rockstar Games\Grand Theft Auto V",
|
||||||
|
};
|
||||||
|
let Ok(gta_v_enhanced) = hklm.open_subkey(rockstar_url) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let Ok(install_folder): Result<String, std::io::Error> =
|
let Ok(install_folder): Result<String, std::io::Error> =
|
||||||
@@ -45,12 +44,19 @@ pub fn launch(platform: &Platform) {
|
|||||||
};
|
};
|
||||||
let mut play_gtav_path = PathBuf::from(install_folder);
|
let mut play_gtav_path = PathBuf::from(install_folder);
|
||||||
play_gtav_path.push("PlayGTAV.exe");
|
play_gtav_path.push("PlayGTAV.exe");
|
||||||
|
// ignoring the return because if it errors that means GTA isn't installed via Rockstar
|
||||||
let _ = Command::new(play_gtav_path).spawn();
|
let _ = Command::new(play_gtav_path).spawn();
|
||||||
}
|
}
|
||||||
Platform::Epic => {
|
Platform::Epic => {
|
||||||
let _ = open::that_detached(
|
let epic_url = match version {
|
||||||
"com.epicgames.launcher://apps/331226ba7c944720baa99103cb1fe80c?action=launch&silent=true",
|
LaunchVersion::Enhanced => {
|
||||||
);
|
"com.epicgames.launcher://apps/8769e24080ea413b8ebca3f1b8c50951?action=launch&silent=true"
|
||||||
|
}
|
||||||
|
LaunchVersion::Legacy => {
|
||||||
|
"com.epicgames.launcher://apps/9d2d0eb64d5c44529cece33fe2a46482?action=launch&silent=true"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
open::that_detached(epic_url).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-409
@@ -1,409 +1,6 @@
|
|||||||
use crate::{
|
pub mod app;
|
||||||
features::{
|
mod debug;
|
||||||
self,
|
pub mod run;
|
||||||
anti_afk::AntiAfk,
|
pub mod settings;
|
||||||
empty_session::EmptySession,
|
mod tools;
|
||||||
force_close::ForceClose,
|
mod ui_ext;
|
||||||
launch::{Launch, Platform},
|
|
||||||
},
|
|
||||||
util::{
|
|
||||||
self,
|
|
||||||
consts::{ENHANCED, GTA_WINDOW_TITLE, LEGACY},
|
|
||||||
elevation,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
use eframe::egui;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::{
|
|
||||||
fs::{self, File},
|
|
||||||
io::Write,
|
|
||||||
path::PathBuf,
|
|
||||||
sync::LazyLock,
|
|
||||||
time::{Duration, Instant},
|
|
||||||
};
|
|
||||||
use sysinfo::System;
|
|
||||||
use windows::Win32::Foundation::HANDLE;
|
|
||||||
|
|
||||||
const THEME: catppuccin_egui::Theme = catppuccin_egui::MOCHA;
|
|
||||||
const WINDOW_SIZE: [f32; 2] = [240.0, 240.0];
|
|
||||||
static CONFIG_PATH: LazyLock<PathBuf> = LazyLock::new(|| {
|
|
||||||
dirs::config_local_dir()
|
|
||||||
.unwrap()
|
|
||||||
.join("GTA Tools")
|
|
||||||
.join("config.json")
|
|
||||||
});
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
|
||||||
struct PersistentState {
|
|
||||||
launcher: Platform,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Default, PartialEq, Eq)]
|
|
||||||
pub enum Stage {
|
|
||||||
#[default]
|
|
||||||
Main,
|
|
||||||
About,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(clippy::struct_excessive_bools)]
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct App {
|
|
||||||
stage: Stage,
|
|
||||||
closing: bool,
|
|
||||||
debug: bool,
|
|
||||||
initialized: bool,
|
|
||||||
elevated: bool,
|
|
||||||
current_frame: bool,
|
|
||||||
pub sysinfo: System,
|
|
||||||
pub game_handle: HANDLE,
|
|
||||||
launch: Launch,
|
|
||||||
force_close: ForceClose,
|
|
||||||
empty_session: EmptySession,
|
|
||||||
anti_afk: AntiAfk,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for App {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
stage: Stage::default(),
|
|
||||||
closing: false,
|
|
||||||
initialized: false,
|
|
||||||
debug: false,
|
|
||||||
elevated: elevation::is_elevated(),
|
|
||||||
current_frame: false,
|
|
||||||
sysinfo: System::new_all(),
|
|
||||||
game_handle: HANDLE::default(),
|
|
||||||
launch: Launch::default(),
|
|
||||||
force_close: ForceClose::default(),
|
|
||||||
empty_session: EmptySession::default(),
|
|
||||||
anti_afk: AntiAfk::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl eframe::App for App {
|
|
||||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
|
||||||
if !self.initialized {
|
|
||||||
catppuccin_egui::set_theme(ctx, THEME);
|
|
||||||
egui_extras::install_image_loaders(ctx);
|
|
||||||
if let Ok(config) = fs::read_to_string(CONFIG_PATH.as_path()) {
|
|
||||||
if let Ok(persistent_state) = serde_json::from_str::<PersistentState>(&config) {
|
|
||||||
self.launch.selected = persistent_state.launcher;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ctx.style_mut(|style| style.spacing.item_spacing = egui::vec2(4.0, 4.0));
|
|
||||||
self.initialized = true;
|
|
||||||
}
|
|
||||||
self.run_timers();
|
|
||||||
egui::TopBottomPanel::bottom("bottom_panel")
|
|
||||||
.exact_height(25.0)
|
|
||||||
.show(ctx, |ui| {
|
|
||||||
ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| {
|
|
||||||
ui.selectable_value(&mut self.stage, Stage::Main, "Main");
|
|
||||||
ui.selectable_value(&mut self.stage, Stage::About, "About");
|
|
||||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
|
||||||
let button = ui
|
|
||||||
.add_enabled(!self.elevated, egui::Button::new("Elevate"))
|
|
||||||
.on_hover_text("Relaunch ourselves as administrator.")
|
|
||||||
.on_disabled_hover_text("We are already running elevated.");
|
|
||||||
if button.clicked() {
|
|
||||||
elevation::elevate(&mut self.closing);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
egui::CentralPanel::default().show(ctx, |ui| match self.stage {
|
|
||||||
Stage::Main => {
|
|
||||||
self.header(ui, "Game");
|
|
||||||
self.show_game(ctx, ui);
|
|
||||||
self.header(ui, "Session");
|
|
||||||
self.show_session(ctx, ui);
|
|
||||||
self.header(ui, "Network");
|
|
||||||
self.show_network(ctx, ui);
|
|
||||||
}
|
|
||||||
Stage::About => self.show_about(ctx, ui),
|
|
||||||
});
|
|
||||||
if check_debug_keycombo_pressed(ctx) {
|
|
||||||
self.debug = !self.debug;
|
|
||||||
}
|
|
||||||
if check_debug_viewport_close_button_pressed(ctx) {
|
|
||||||
self.debug = false;
|
|
||||||
}
|
|
||||||
if self.debug {
|
|
||||||
let main_rect = ctx.input(|i| {
|
|
||||||
i.viewport()
|
|
||||||
.clone()
|
|
||||||
.outer_rect
|
|
||||||
.unwrap_or(egui::Rect::EVERYTHING)
|
|
||||||
});
|
|
||||||
let position = [main_rect.right(), main_rect.min.y];
|
|
||||||
ctx.show_viewport_immediate(
|
|
||||||
egui::ViewportId::from_hash_of("debug_viewport"),
|
|
||||||
egui::ViewportBuilder::default()
|
|
||||||
.with_title("GTA Tools Debug")
|
|
||||||
.with_minimize_button(false)
|
|
||||||
.with_maximize_button(false)
|
|
||||||
.with_inner_size(WINDOW_SIZE)
|
|
||||||
.with_position(position)
|
|
||||||
.with_icon(load_icon()),
|
|
||||||
|ctx, _class| {
|
|
||||||
if check_debug_keycombo_pressed(ctx) {
|
|
||||||
self.debug = !self.debug;
|
|
||||||
}
|
|
||||||
egui::CentralPanel::default().show(ctx, |ui| {
|
|
||||||
egui::ScrollArea::both()
|
|
||||||
.auto_shrink([false, false])
|
|
||||||
.show(ui, |ui| {
|
|
||||||
self.show_debug(ctx, ui);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
ctx.request_repaint_after(Duration::from_millis(100));
|
|
||||||
if self.closing {
|
|
||||||
ctx.send_viewport_cmd(egui::ViewportCommand::Close);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl App {
|
|
||||||
#[allow(clippy::unused_self)]
|
|
||||||
fn header(&self, ui: &mut egui::Ui, text: &str) {
|
|
||||||
ui.horizontal(|ui| {
|
|
||||||
ui.label(text);
|
|
||||||
ui.add(egui::Separator::default().horizontal());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
fn show_game(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
|
||||||
ui.horizontal(|ui| {
|
|
||||||
if ui.button("Launch").clicked() {
|
|
||||||
features::launch::launch(&self.launch.selected);
|
|
||||||
};
|
|
||||||
egui::ComboBox::from_label("")
|
|
||||||
.selected_text(self.launch.selected.to_string())
|
|
||||||
.width(120.0)
|
|
||||||
.show_ui(ui, |ui| {
|
|
||||||
ui.selectable_value(
|
|
||||||
&mut self.launch.selected,
|
|
||||||
Platform::Steam,
|
|
||||||
Platform::Steam.to_string(),
|
|
||||||
);
|
|
||||||
ui.selectable_value(
|
|
||||||
&mut self.launch.selected,
|
|
||||||
Platform::Rockstar,
|
|
||||||
Platform::Rockstar.to_string(),
|
|
||||||
);
|
|
||||||
ui.selectable_value(
|
|
||||||
&mut self.launch.selected,
|
|
||||||
Platform::Epic,
|
|
||||||
Platform::Epic.to_string(),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
let force_close_button = ui.add_sized(
|
|
||||||
[104.0, 0.0],
|
|
||||||
egui::Button::new(&self.force_close.button_text),
|
|
||||||
);
|
|
||||||
if force_close_button.clicked() && !self.force_close.prompting {
|
|
||||||
self.force_close.prompting();
|
|
||||||
self.current_frame = true;
|
|
||||||
};
|
|
||||||
if self.force_close.prompting
|
|
||||||
&& self.force_close.interval.elapsed() <= Duration::from_secs(3)
|
|
||||||
{
|
|
||||||
if force_close_button.clicked() && !self.current_frame {
|
|
||||||
features::force_close::activate(&mut self.sysinfo);
|
|
||||||
self.force_close = ForceClose::default();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
self.force_close = ForceClose::default();
|
|
||||||
}
|
|
||||||
if self.current_frame {
|
|
||||||
self.current_frame = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn show_session(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
|
||||||
ui.add_enabled_ui(!self.empty_session.disabled, |ui| {
|
|
||||||
ui.horizontal(|ui| {
|
|
||||||
if ui.button("Empty current session").clicked() {
|
|
||||||
self.empty_session.interval = Instant::now();
|
|
||||||
self.empty_session.disabled = true;
|
|
||||||
features::empty_session::activate(self);
|
|
||||||
}
|
|
||||||
ui.label(&self.empty_session.countdown.i_string);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
ui.horizontal(|ui| {
|
|
||||||
ui.checkbox(&mut self.anti_afk.enabled, "Anti AFK")
|
|
||||||
.on_hover_text("You should be tabbed in\nfor this to work.");
|
|
||||||
if self.anti_afk.enabled {
|
|
||||||
ui.add_space(8.0);
|
|
||||||
ui.add_enabled_ui(false, |ui| {
|
|
||||||
ui.label(if util::is_window_focused(GTA_WINDOW_TITLE) {
|
|
||||||
"GTA is focused."
|
|
||||||
} else {
|
|
||||||
"GTA is not focused!"
|
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if self.anti_afk.enabled && self.anti_afk.interval.elapsed() >= features::anti_afk::INTERVAL
|
|
||||||
{
|
|
||||||
self.anti_afk.activate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn show_network(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
|
||||||
egui::Frame::new()
|
|
||||||
.inner_margin(egui::vec2(4.0, 4.0))
|
|
||||||
.stroke(egui::Stroke::new(1.0, THEME.overlay1))
|
|
||||||
.show(ui, |ui| {
|
|
||||||
let response = ui.add_enabled_ui(self.elevated, |ui| {
|
|
||||||
let label = ui.label("Game's network access");
|
|
||||||
ui.horizontal(|ui| {
|
|
||||||
let available_width = label.rect.width();
|
|
||||||
let spacing = ui.spacing().item_spacing.x;
|
|
||||||
let button_width = (available_width - spacing) / 2.0;
|
|
||||||
if ui
|
|
||||||
.add_sized([button_width, 18.0], egui::Button::new("Block"))
|
|
||||||
.clicked()
|
|
||||||
{
|
|
||||||
features::game_networking::block_all(&mut self.sysinfo);
|
|
||||||
};
|
|
||||||
if ui
|
|
||||||
.add_sized([button_width, 18.0], egui::Button::new("Unblock"))
|
|
||||||
.clicked()
|
|
||||||
{
|
|
||||||
features::game_networking::unblock_all();
|
|
||||||
};
|
|
||||||
});
|
|
||||||
});
|
|
||||||
response.response.on_disabled_hover_text(
|
|
||||||
"This requires administrator.\nUse the Elevate button.",
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(clippy::unused_self)]
|
|
||||||
fn show_about(&self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
|
||||||
ui.with_layout(egui::Layout::bottom_up(egui::Align::Center), |ui| {
|
|
||||||
ui.horizontal(|ui| {
|
|
||||||
ui.horizontal(|ui| {
|
|
||||||
ui.spacing_mut().item_spacing.x = 0.0;
|
|
||||||
ui.label("with love from ");
|
|
||||||
ui.hyperlink_to("futile", "http://futile.eu");
|
|
||||||
});
|
|
||||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
|
||||||
ui.label(format!(
|
|
||||||
"v{} {}",
|
|
||||||
env!("CARGO_PKG_VERSION"),
|
|
||||||
if cfg!(debug_assertions) { "(dev)" } else { "" }
|
|
||||||
));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
ui.add(egui::Image::new(egui::include_image!("../assets/icon.png")));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
fn show_debug(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
|
||||||
ui.collapsing("times", |ui| {
|
|
||||||
ui.label(format!(
|
|
||||||
"anti afk timer: {}",
|
|
||||||
self.anti_afk.interval.elapsed().as_secs()
|
|
||||||
))
|
|
||||||
});
|
|
||||||
ui.collapsing("sysinfo", |ui| {
|
|
||||||
if ui.button("refresh all").clicked() {
|
|
||||||
self.sysinfo.refresh_all();
|
|
||||||
}
|
|
||||||
let pid = self
|
|
||||||
.sysinfo
|
|
||||||
.processes()
|
|
||||||
.iter()
|
|
||||||
.find(|(_, p)| p.name() == ENHANCED || p.name() == LEGACY)
|
|
||||||
.map_or_else(
|
|
||||||
|| "no pid found!".to_string(),
|
|
||||||
|(pid, _)| pid.as_u32().to_string(),
|
|
||||||
);
|
|
||||||
ui.label(format!("gta pid: {pid}"));
|
|
||||||
});
|
|
||||||
ui.collapsing("app state", |ui| ui.label(format!("{self:#?}")));
|
|
||||||
}
|
|
||||||
|
|
||||||
fn run_timers(&mut self) {
|
|
||||||
if self.empty_session.disabled {
|
|
||||||
self.empty_session.countdown.count();
|
|
||||||
} else {
|
|
||||||
self.empty_session.countdown.reset();
|
|
||||||
}
|
|
||||||
if self.empty_session.interval.elapsed() >= features::empty_session::INTERVAL {
|
|
||||||
features::empty_session::deactivate(self);
|
|
||||||
self.empty_session.disabled = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Drop for App {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
// save any persistent state to config file
|
|
||||||
let persistent_state = PersistentState {
|
|
||||||
launcher: self.launch.selected,
|
|
||||||
};
|
|
||||||
let config_path = CONFIG_PATH.as_path();
|
|
||||||
let config_path_parent = config_path.parent().unwrap();
|
|
||||||
if !config_path_parent.exists() {
|
|
||||||
fs::create_dir(config_path_parent).unwrap();
|
|
||||||
}
|
|
||||||
let mut config_file = File::create(config_path).unwrap();
|
|
||||||
let json = serde_json::to_string_pretty(&persistent_state).unwrap();
|
|
||||||
config_file.write_all(json.as_bytes()).unwrap();
|
|
||||||
// make sure we are not suspending game
|
|
||||||
features::empty_session::deactivate(self);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn check_debug_keycombo_pressed(ctx: &egui::Context) -> bool {
|
|
||||||
ctx.input(|i| i.modifiers.all() && i.key_pressed(egui::Key::D))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn check_debug_viewport_close_button_pressed(ctx: &egui::Context) -> bool {
|
|
||||||
ctx.input(|i| {
|
|
||||||
i.raw
|
|
||||||
.viewports
|
|
||||||
.get(&egui::ViewportId::from_hash_of("debug_viewport"))
|
|
||||||
.filter(|vp| vp.close_requested())
|
|
||||||
.is_some()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn load_icon() -> eframe::egui::IconData {
|
|
||||||
let icon = include_bytes!("../assets/icon.png");
|
|
||||||
let image = image::load_from_memory(icon).unwrap().into_rgba8();
|
|
||||||
let (width, height) = image.dimensions();
|
|
||||||
eframe::egui::IconData {
|
|
||||||
rgba: image.into_raw(),
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn run() {
|
|
||||||
let options = eframe::NativeOptions {
|
|
||||||
viewport: egui::ViewportBuilder::default()
|
|
||||||
.with_resizable(false)
|
|
||||||
.with_maximize_button(false)
|
|
||||||
.with_inner_size(WINDOW_SIZE)
|
|
||||||
.with_icon(load_icon()),
|
|
||||||
centered: true,
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
eframe::run_native(
|
|
||||||
"GTA Tools",
|
|
||||||
options,
|
|
||||||
Box::new(|_cc| Ok(Box::<App>::default())),
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
|
|||||||
+270
@@ -0,0 +1,270 @@
|
|||||||
|
use crate::{
|
||||||
|
features,
|
||||||
|
gui::{settings::Settings, tools, ui_ext::UiExt},
|
||||||
|
util::{
|
||||||
|
consts::{colours, game::WINDOW_TITLE},
|
||||||
|
persistent_state::PersistentState,
|
||||||
|
system_info::SystemInfo,
|
||||||
|
win,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
use eframe::egui;
|
||||||
|
use std::time::{Duration, Instant};
|
||||||
|
use strum::{Display, EnumIter};
|
||||||
|
|
||||||
|
pub const WINDOW_SIZE: [f32; 2] = [240.0, 240.0];
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, Default, Display, PartialEq, Eq, EnumIter)]
|
||||||
|
enum Stage {
|
||||||
|
#[default]
|
||||||
|
Main,
|
||||||
|
Settings,
|
||||||
|
About,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Flags {
|
||||||
|
pub elevated: bool,
|
||||||
|
pub debug: bool,
|
||||||
|
closing: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Flags {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
elevated: win::is_elevated(),
|
||||||
|
debug: false,
|
||||||
|
closing: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Default)]
|
||||||
|
pub struct App {
|
||||||
|
pub settings: Settings,
|
||||||
|
stage: Stage,
|
||||||
|
pub flags: Flags,
|
||||||
|
pub system_info: SystemInfo,
|
||||||
|
game_handle: windows::Win32::Foundation::HANDLE,
|
||||||
|
pub anti_afk: features::anti_afk::AntiAfk,
|
||||||
|
empty_session: features::empty_session::EmptySession,
|
||||||
|
force_close: features::force_close::ForceClose,
|
||||||
|
pub game_networking: features::game_networking::GameNetworking,
|
||||||
|
pub launch: features::launch::Launch,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl eframe::App for App {
|
||||||
|
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||||
|
ctx.request_repaint_after(Duration::from_millis(100));
|
||||||
|
self.empty_session.run_timers(&mut self.game_handle);
|
||||||
|
egui::TopBottomPanel::bottom("bottom_panel")
|
||||||
|
.exact_height(25.0)
|
||||||
|
.show(ctx, |ui| {
|
||||||
|
ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| {
|
||||||
|
ui.build_menu(&mut self.stage);
|
||||||
|
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||||
|
let button = ui
|
||||||
|
.add_enabled(!self.flags.elevated, egui::Button::new("Elevate"))
|
||||||
|
.on_hover_text("Relaunch ourselves as administrator.")
|
||||||
|
.on_disabled_hover_text("We are already running elevated.");
|
||||||
|
if button.clicked() {
|
||||||
|
win::elevate(win::ElevationExitMethod::Gentle(&mut self.flags.closing));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
|
egui::ScrollArea::vertical()
|
||||||
|
.auto_shrink([false, true])
|
||||||
|
.show(ui, |ui| match self.stage {
|
||||||
|
Stage::Main => self.show_main_stage(ctx, ui),
|
||||||
|
Stage::Settings => self.show_settings_stage(ctx, ui),
|
||||||
|
Stage::About => self.show_about_stage(ctx, ui),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
if tools::debug_keycombo_pressed(ctx) || tools::debug_viewport_close_pressed(ctx) {
|
||||||
|
self.flags.debug = !self.flags.debug;
|
||||||
|
}
|
||||||
|
if self.flags.debug {
|
||||||
|
self.show_debug_viewport(ctx);
|
||||||
|
}
|
||||||
|
if self.flags.closing {
|
||||||
|
ctx.send_viewport_cmd(egui::ViewportCommand::Close);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl App {
|
||||||
|
fn show_game_section(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||||
|
ui.header("Game");
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
if ui.button("Launch").clicked() {
|
||||||
|
features::launch::launch(&self.launch.selected, &self.settings.launch_version);
|
||||||
|
}
|
||||||
|
egui::ComboBox::from_id_salt("Launch")
|
||||||
|
.selected_text(self.launch.selected.to_string())
|
||||||
|
.width(120.0)
|
||||||
|
.show_ui(ui, |ui| {
|
||||||
|
ui.build_menu(&mut self.launch.selected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
let force_close_button = ui.add_sized(
|
||||||
|
[108.0, 0.0],
|
||||||
|
egui::Button::new(&self.force_close.button_text),
|
||||||
|
);
|
||||||
|
self.force_close
|
||||||
|
.prompt(force_close_button.clicked(), &mut self.system_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn show_session_section(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||||
|
ui.header("Session");
|
||||||
|
ui.add_enabled_ui(!self.empty_session.disabled, |ui| {
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
if ui.button("Empty current session").clicked()
|
||||||
|
&& features::empty_session::activate(
|
||||||
|
&mut self.game_handle,
|
||||||
|
&mut self.system_info,
|
||||||
|
)
|
||||||
|
{
|
||||||
|
self.empty_session.interval = Instant::now();
|
||||||
|
self.empty_session.disabled = true;
|
||||||
|
}
|
||||||
|
ui.label(&self.empty_session.countdown.i_string);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
ui.checkbox(&mut self.anti_afk.enabled, "Anti AFK")
|
||||||
|
.on_hover_text("You should be tabbed in\nfor this to work.");
|
||||||
|
if self.anti_afk.enabled {
|
||||||
|
ui.add_space(8.0);
|
||||||
|
ui.add_enabled_ui(false, |ui| {
|
||||||
|
ui.label(if win::is_window_focused(WINDOW_TITLE) {
|
||||||
|
"GTA is focused."
|
||||||
|
} else {
|
||||||
|
"GTA is not focused!"
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if self.anti_afk.can_activate() && self.anti_afk.should_activate() {
|
||||||
|
self.anti_afk.activate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn show_network_section(&mut self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||||
|
ui.header("Network");
|
||||||
|
egui::Frame::new()
|
||||||
|
.outer_margin(egui::vec2(0.0, -2.0))
|
||||||
|
.show(ui, |ui| {
|
||||||
|
let response = ui.add_enabled_ui(self.flags.elevated, |ui| {
|
||||||
|
let label = ui.horizontal(|ui| {
|
||||||
|
let label = ui.label("Game's network access");
|
||||||
|
ui.add_space(1.0);
|
||||||
|
ui.create_indicator_dot(self.game_networking.blocked_status)
|
||||||
|
.on_hover_text(
|
||||||
|
"This turns yellow if GTA Tools\ncannot find your game.",
|
||||||
|
);
|
||||||
|
self.game_networking.if_failed_return_to_boolean();
|
||||||
|
label
|
||||||
|
});
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
let available_width = label.inner.rect.width();
|
||||||
|
let spacing = ui.spacing().item_spacing.x;
|
||||||
|
let button_width = (available_width - spacing) / 2.0;
|
||||||
|
if ui
|
||||||
|
.add_sized([button_width, 18.0], egui::Button::new("Block"))
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
self.game_networking.block_all(&mut self.system_info);
|
||||||
|
}
|
||||||
|
if ui
|
||||||
|
.add_sized([button_width, 18.0], egui::Button::new("Unblock"))
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
self.game_networking.unblock_all();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
response.response.on_disabled_hover_text(
|
||||||
|
"This requires administrator.\nUse the Elevate button.",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn show_main_stage(&mut self, ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||||
|
self.show_game_section(ctx, ui);
|
||||||
|
self.show_session_section(ctx, ui);
|
||||||
|
self.show_network_section(ctx, ui);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn show_settings_stage(&mut self, ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
ui.label("Launch version");
|
||||||
|
egui::ComboBox::from_id_salt("Launch version")
|
||||||
|
.selected_text(self.settings.launch_version.to_string())
|
||||||
|
.show_ui(ui, |ui| {
|
||||||
|
ui.build_menu(&mut self.settings.launch_version);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
let selection = self.settings.theme;
|
||||||
|
ui.label("Theme");
|
||||||
|
egui::ComboBox::from_id_salt("Theme")
|
||||||
|
.selected_text(self.settings.theme.to_string())
|
||||||
|
.show_ui(ui, |ui| {
|
||||||
|
ui.build_menu(&mut self.settings.theme);
|
||||||
|
});
|
||||||
|
if selection != self.settings.theme {
|
||||||
|
catppuccin_egui::set_theme(ctx, self.settings.theme.into());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ui.checkbox(&mut self.settings.start_elevated, "Always start elevated");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn show_about_stage(&self, _ctx: &egui::Context, ui: &mut egui::Ui) {
|
||||||
|
ui.with_layout(egui::Layout::bottom_up(egui::Align::Center), |ui| {
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
ui.spacing_mut().item_spacing.x = 0.0;
|
||||||
|
ui.label("with ");
|
||||||
|
ui.scope(|ui| {
|
||||||
|
ui.style_mut().visuals.override_text_color = Some(colours::RED);
|
||||||
|
ui.label("❤");
|
||||||
|
});
|
||||||
|
ui.label(" from ");
|
||||||
|
ui.hyperlink_to("futile", "https://futile.eu");
|
||||||
|
});
|
||||||
|
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||||
|
ui.style_mut().spacing.button_padding = egui::Vec2::new(4.0, 0.0);
|
||||||
|
if ui.button("").on_hover_text("View source code").clicked() {
|
||||||
|
open::that("https://github.com/elituf/gta-tools").unwrap();
|
||||||
|
}
|
||||||
|
if cfg!(debug_assertions) {
|
||||||
|
ui.label("(dev)");
|
||||||
|
}
|
||||||
|
ui.label(format!("v{}", env!("CARGO_PKG_VERSION")))
|
||||||
|
.on_hover_text(
|
||||||
|
egui::RichText::new(env!("LATEST_GIT_COMMIT_HASH")).monospace(),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
ui.add(egui::Image::new(egui::include_image!(
|
||||||
|
"../../assets/icon.png"
|
||||||
|
)));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for App {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
// save any persistent state to config file
|
||||||
|
PersistentState {
|
||||||
|
launcher: self.launch.selected,
|
||||||
|
anti_afk_enabled: self.anti_afk.enabled,
|
||||||
|
settings: self.settings.clone(),
|
||||||
|
}
|
||||||
|
.set();
|
||||||
|
// make sure we are not suspending game
|
||||||
|
features::empty_session::deactivate(&mut self.game_handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
use crate::{
|
||||||
|
gui::{
|
||||||
|
app::{App, WINDOW_SIZE},
|
||||||
|
tools,
|
||||||
|
ui_ext::UiExt,
|
||||||
|
},
|
||||||
|
util::consts::{
|
||||||
|
game::{EXE_ENHANCED, EXE_LEGACY},
|
||||||
|
path,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
use eframe::egui;
|
||||||
|
|
||||||
|
impl App {
|
||||||
|
fn add_debug_viewport_contents(&mut self, ui: &mut egui::Ui) {
|
||||||
|
ui.collapsing("misc", |ui| {
|
||||||
|
if ui.button("open storage path").clicked() {
|
||||||
|
open::that_detached(path::APP_STORAGE.as_path()).unwrap();
|
||||||
|
}
|
||||||
|
ui.scope(|ui| {
|
||||||
|
use windows::Win32::UI::WindowsAndMessaging::{
|
||||||
|
GetForegroundWindow, GetWindowTextW,
|
||||||
|
};
|
||||||
|
let current_title = {
|
||||||
|
let mut buffer = [0; 512];
|
||||||
|
let hwnd = unsafe { GetForegroundWindow() };
|
||||||
|
let length = unsafe { GetWindowTextW(hwnd, &mut buffer) };
|
||||||
|
String::from_utf16_lossy(&buffer[..length as usize])
|
||||||
|
};
|
||||||
|
ui.label(format!("focused: \"{current_title}\""));
|
||||||
|
});
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
ui.label("blocked_status");
|
||||||
|
egui::ComboBox::from_id_salt("blocked_status")
|
||||||
|
.selected_text(self.game_networking.blocked_status.to_string())
|
||||||
|
.show_ui(ui, |ui| {
|
||||||
|
ui.build_menu(&mut self.game_networking.blocked_status);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
if ui.add(egui::Button::new("force refresh theme")).clicked() {
|
||||||
|
catppuccin_egui::set_theme(ui.ctx(), self.settings.theme.into());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ui.collapsing("anti afk", |ui| {
|
||||||
|
ui.label(format!(
|
||||||
|
"timer: {}",
|
||||||
|
self.anti_afk.interval.elapsed().as_secs()
|
||||||
|
));
|
||||||
|
ui.label(format!("can activate: {}", self.anti_afk.can_activate()));
|
||||||
|
});
|
||||||
|
ui.collapsing("system info", |ui| {
|
||||||
|
if ui.button("refresh").clicked() {
|
||||||
|
self.system_info.refresh();
|
||||||
|
}
|
||||||
|
let pid = self
|
||||||
|
.system_info
|
||||||
|
.processes()
|
||||||
|
.iter()
|
||||||
|
.find(|p| p.name() == EXE_ENHANCED || p.name() == EXE_LEGACY)
|
||||||
|
.map_or_else(|| "no pid found!".to_owned(), |p| p.pid().to_string());
|
||||||
|
ui.label(format!("gta pid: {pid}"));
|
||||||
|
});
|
||||||
|
ui.collapsing("app state", |ui| ui.label(format!("{self:#?}")));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn show_debug_viewport(&mut self, ctx: &egui::Context) {
|
||||||
|
let main = ctx.input(|i| i.viewport().outer_rect.unwrap_or(egui::Rect::EVERYTHING));
|
||||||
|
let builder = egui::ViewportBuilder::default()
|
||||||
|
.with_title("GTA Tools Debug")
|
||||||
|
.with_minimize_button(false)
|
||||||
|
.with_maximize_button(false)
|
||||||
|
.with_inner_size(WINDOW_SIZE)
|
||||||
|
.with_position([main.right() - 12.0, main.min.y])
|
||||||
|
.with_icon(tools::load_icon());
|
||||||
|
ctx.show_viewport_immediate(
|
||||||
|
egui::ViewportId::from_hash_of("debug_viewport"),
|
||||||
|
builder,
|
||||||
|
|ctx, _class| {
|
||||||
|
if tools::debug_keycombo_pressed(ctx) {
|
||||||
|
self.flags.debug = !self.flags.debug;
|
||||||
|
}
|
||||||
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
|
egui::ScrollArea::both()
|
||||||
|
.auto_shrink([false, true])
|
||||||
|
.show(ui, |ui| self.add_debug_viewport_contents(ui));
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
use crate::{
|
||||||
|
gui::{
|
||||||
|
app::{App, WINDOW_SIZE},
|
||||||
|
tools,
|
||||||
|
},
|
||||||
|
util::{persistent_state::PersistentState, win},
|
||||||
|
};
|
||||||
|
use eframe::egui;
|
||||||
|
|
||||||
|
fn app_creator(
|
||||||
|
cc: &eframe::CreationContext<'_>,
|
||||||
|
) -> Result<Box<dyn eframe::App>, Box<dyn std::error::Error + Send + Sync>> {
|
||||||
|
// initialize App early to modify some things before returning it
|
||||||
|
let mut app = Box::new(App::default());
|
||||||
|
// load previously selected launch platform & settings from persistent state
|
||||||
|
if let Some(persistent_state) = PersistentState::get() {
|
||||||
|
persistent_state.apply_to(&mut app);
|
||||||
|
}
|
||||||
|
// check if we're elevated. if not, and the user wants an elevated launch - relaunch elevated
|
||||||
|
if !app.flags.elevated && app.settings.start_elevated {
|
||||||
|
win::elevate(win::ElevationExitMethod::Forced);
|
||||||
|
}
|
||||||
|
// refresh system info because it initializes with nothing
|
||||||
|
app.system_info.refresh();
|
||||||
|
// enable image loading support in egui
|
||||||
|
egui_extras::install_image_loaders(&cc.egui_ctx);
|
||||||
|
// set our initial theme, from earlier loaded settings. we set the egui theme
|
||||||
|
// to dark here to work around system theme based switching of the egui style
|
||||||
|
cc.egui_ctx.set_theme(egui::Theme::Dark);
|
||||||
|
catppuccin_egui::set_theme(&cc.egui_ctx, app.settings.theme.into());
|
||||||
|
// apply some global styling that we like
|
||||||
|
cc.egui_ctx.all_styles_mut(|style| {
|
||||||
|
style.spacing.item_spacing = egui::vec2(4.0, 4.0);
|
||||||
|
style.interaction.selectable_labels = false;
|
||||||
|
style.visuals.hyperlink_color = catppuccin_egui::Theme::from(app.settings.theme).text;
|
||||||
|
});
|
||||||
|
// load any extra fonts that we need
|
||||||
|
let mut fonts = egui::FontDefinitions::default();
|
||||||
|
fonts.font_data.insert(
|
||||||
|
"Inter 18pt Light".to_owned(),
|
||||||
|
egui::FontData::from_static(include_bytes!("../../assets/Inter_18pt-Light.ttf")).into(),
|
||||||
|
);
|
||||||
|
fonts
|
||||||
|
.families
|
||||||
|
.get_mut(&egui::FontFamily::Proportional)
|
||||||
|
.unwrap()
|
||||||
|
.insert(0, "Inter 18pt Light".to_owned());
|
||||||
|
fonts.font_data.insert(
|
||||||
|
"Inter 18pt Regular".to_owned(),
|
||||||
|
egui::FontData::from_static(include_bytes!("../../assets/Inter_18pt-Regular.ttf")).into(),
|
||||||
|
);
|
||||||
|
fonts.families.insert(
|
||||||
|
egui::FontFamily::Name("Inter 18pt Regular".into()),
|
||||||
|
vec!["Inter 18pt Regular".to_owned()],
|
||||||
|
);
|
||||||
|
cc.egui_ctx.set_fonts(fonts);
|
||||||
|
// finally return the App
|
||||||
|
Ok(app)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn run() {
|
||||||
|
let options = eframe::NativeOptions {
|
||||||
|
viewport: egui::ViewportBuilder::default()
|
||||||
|
.with_resizable(false)
|
||||||
|
.with_maximize_button(false)
|
||||||
|
.with_inner_size(WINDOW_SIZE)
|
||||||
|
.with_icon(tools::load_icon()),
|
||||||
|
centered: true,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
eframe::run_native("GTA Tools", options, Box::new(app_creator)).unwrap();
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
use crate::util::win;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use strum::{Display, EnumIter};
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, Default, Display, PartialEq, Eq, Serialize, Deserialize, EnumIter)]
|
||||||
|
pub enum LaunchVersion {
|
||||||
|
#[default]
|
||||||
|
Enhanced,
|
||||||
|
Legacy,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, Default, Display, PartialEq, Eq, Serialize, Deserialize, EnumIter)]
|
||||||
|
pub enum Theme {
|
||||||
|
#[default]
|
||||||
|
#[strum(to_string = "Auto")]
|
||||||
|
Auto,
|
||||||
|
#[strum(to_string = "Catppuccin Latte")]
|
||||||
|
CatppuccinLatte,
|
||||||
|
#[strum(to_string = "Catppuccin Frappe")]
|
||||||
|
CatppuccinFrappe,
|
||||||
|
#[strum(to_string = "Catppuccin Macchiato")]
|
||||||
|
CatppuccinMacchiato,
|
||||||
|
#[strum(to_string = "Catppuccin Mocha")]
|
||||||
|
CatppuccinMocha,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Theme> for catppuccin_egui::Theme {
|
||||||
|
fn from(val: Theme) -> Self {
|
||||||
|
match val {
|
||||||
|
Theme::Auto => {
|
||||||
|
if win::is_system_theme_dark() {
|
||||||
|
catppuccin_egui::MOCHA
|
||||||
|
} else {
|
||||||
|
catppuccin_egui::LATTE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Theme::CatppuccinLatte => catppuccin_egui::LATTE,
|
||||||
|
Theme::CatppuccinFrappe => catppuccin_egui::FRAPPE,
|
||||||
|
Theme::CatppuccinMacchiato => catppuccin_egui::MACCHIATO,
|
||||||
|
Theme::CatppuccinMocha => catppuccin_egui::MOCHA,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
|
||||||
|
pub struct Settings {
|
||||||
|
pub launch_version: LaunchVersion,
|
||||||
|
pub theme: Theme,
|
||||||
|
pub start_elevated: bool,
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
use eframe::egui;
|
||||||
|
|
||||||
|
pub fn load_icon() -> egui::IconData {
|
||||||
|
let icon = include_bytes!("../../assets/icon.png");
|
||||||
|
let image = image::load_from_memory(icon).unwrap().into_rgba8();
|
||||||
|
let (width, height) = image.dimensions();
|
||||||
|
egui::IconData {
|
||||||
|
rgba: image.into_raw(),
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn debug_keycombo_pressed(ctx: &egui::Context) -> bool {
|
||||||
|
ctx.input(|i| i.modifiers.all() && i.key_pressed(egui::Key::D))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn debug_viewport_close_pressed(ctx: &egui::Context) -> bool {
|
||||||
|
ctx.input(|i| {
|
||||||
|
i.raw
|
||||||
|
.viewports
|
||||||
|
.get(&egui::ViewportId::from_hash_of("debug_viewport"))
|
||||||
|
.filter(|vp| vp.close_requested())
|
||||||
|
.is_some()
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
use eframe::egui;
|
||||||
|
|
||||||
|
pub trait UiExt {
|
||||||
|
fn header(&mut self, text: &str);
|
||||||
|
fn build_menu<E>(&mut self, current_value: &mut E)
|
||||||
|
where
|
||||||
|
E: strum::IntoEnumIterator + std::fmt::Display + std::cmp::PartialEq + Copy;
|
||||||
|
fn create_indicator_dot(&mut self, colour: impl Into<egui::Color32>) -> egui::Response;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl UiExt for egui::Ui {
|
||||||
|
fn header(&mut self, text: &str) {
|
||||||
|
self.horizontal(|ui| {
|
||||||
|
ui.label(egui::RichText::new(text).font(egui::FontId::new(
|
||||||
|
12.5,
|
||||||
|
egui::FontFamily::Name("Inter 18pt Regular".into()),
|
||||||
|
)));
|
||||||
|
ui.add(egui::Separator::default().horizontal());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build_menu<E>(&mut self, current_value: &mut E)
|
||||||
|
where
|
||||||
|
E: strum::IntoEnumIterator + std::fmt::Display + std::cmp::PartialEq + Copy,
|
||||||
|
{
|
||||||
|
E::iter().for_each(|variant| {
|
||||||
|
self.selectable_value(current_value, variant, variant.to_string());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn create_indicator_dot(&mut self, colour: impl Into<egui::Color32>) -> egui::Response {
|
||||||
|
self.add(
|
||||||
|
egui::Image::new(egui::include_image!("../../assets/circle.svg"))
|
||||||
|
.max_size([4.0, 4.0].into())
|
||||||
|
.tint(colour),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
+19
-1
@@ -4,6 +4,24 @@ mod features;
|
|||||||
mod gui;
|
mod gui;
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
|
fn init_storage() {
|
||||||
|
if !util::consts::path::APP_STORAGE.exists() {
|
||||||
|
std::fs::create_dir_all(util::consts::path::APP_STORAGE.as_path()).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn panic_hook(panic_info: &std::panic::PanicHookInfo<'_>) {
|
||||||
|
let backtrace = std::backtrace::Backtrace::capture();
|
||||||
|
let mut message = format!("{panic_info}");
|
||||||
|
if backtrace.status() == std::backtrace::BacktraceStatus::Captured {
|
||||||
|
message += &format!("\nstack backtrace:\n{backtrace}");
|
||||||
|
}
|
||||||
|
log::error!("{message}");
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
gui::run();
|
init_storage();
|
||||||
|
util::logging::Logger::init(log::LevelFilter::Info);
|
||||||
|
std::panic::set_hook(Box::new(panic_hook));
|
||||||
|
gui::run::run();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
pub mod consts;
|
||||||
|
pub mod countdown;
|
||||||
|
pub mod logging;
|
||||||
|
pub mod persistent_state;
|
||||||
|
pub mod system_info;
|
||||||
|
pub mod win;
|
||||||
+33
-3
@@ -1,4 +1,34 @@
|
|||||||
pub const ENHANCED: &str = "GTA5_Enhanced.exe";
|
pub mod path {
|
||||||
pub const LEGACY: &str = "GTA5.exe";
|
use std::{env, path::PathBuf, sync::LazyLock};
|
||||||
|
pub static APP_STORAGE: LazyLock<PathBuf> = LazyLock::new(|| {
|
||||||
|
PathBuf::from(env::var("LOCALAPPDATA").unwrap_or_else(|_| String::from(".")))
|
||||||
|
.join("GTA Tools")
|
||||||
|
});
|
||||||
|
pub static APP_CONFIG: LazyLock<PathBuf> = LazyLock::new(|| APP_STORAGE.join("config.json"));
|
||||||
|
pub static APP_LOG: LazyLock<PathBuf> = LazyLock::new(|| APP_STORAGE.join("gta-tools.log"));
|
||||||
|
}
|
||||||
|
|
||||||
pub const GTA_WINDOW_TITLE: &str = "Grand Theft Auto V";
|
pub mod game {
|
||||||
|
pub const EXE_ENHANCED: &str = "GTA5_Enhanced.exe";
|
||||||
|
pub const EXE_LEGACY: &str = "GTA5.exe";
|
||||||
|
pub const WINDOW_TITLE: &str = "Grand Theft Auto V";
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod colours {
|
||||||
|
use crate::features::game_networking::BlockedStatus;
|
||||||
|
use eframe::egui;
|
||||||
|
|
||||||
|
pub const RED: egui::Color32 = egui::Color32::from_rgb(255, 96, 96);
|
||||||
|
pub const YELLOW: egui::Color32 = egui::Color32::from_rgb(255, 255, 96);
|
||||||
|
pub const GREEN: egui::Color32 = egui::Color32::from_rgb(96, 255, 96);
|
||||||
|
|
||||||
|
impl From<BlockedStatus> for egui::Color32 {
|
||||||
|
fn from(value: BlockedStatus) -> Self {
|
||||||
|
match value {
|
||||||
|
BlockedStatus::Blocked => RED,
|
||||||
|
BlockedStatus::Failed => YELLOW,
|
||||||
|
BlockedStatus::Unblocked => GREEN,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ use std::time::{Duration, Instant};
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Countdown {
|
pub struct Countdown {
|
||||||
pub i: u64,
|
i: u64,
|
||||||
pub i_original: u64,
|
i_original: u64,
|
||||||
pub i_string: String,
|
pub i_string: String,
|
||||||
pub interval: Instant,
|
interval: Instant,
|
||||||
pub first_count: bool,
|
first_count: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Countdown {
|
impl Countdown {
|
||||||
@@ -36,6 +36,6 @@ impl Countdown {
|
|||||||
self.i_string = self.i.to_string();
|
self.i_string = self.i.to_string();
|
||||||
if self.i == 0 {
|
if self.i == 0 {
|
||||||
self.reset();
|
self.reset();
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
use windows::{
|
|
||||||
Win32::Foundation::{CloseHandle, HANDLE},
|
|
||||||
Win32::Security::{GetTokenInformation, TOKEN_ELEVATION, TOKEN_QUERY, TokenElevation},
|
|
||||||
Win32::System::Threading::{GetCurrentProcess, OpenProcessToken},
|
|
||||||
Win32::UI::{Shell::ShellExecuteW, WindowsAndMessaging::SW_HIDE},
|
|
||||||
core::{HSTRING, PCWSTR},
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn elevate(closing: &mut bool) {
|
|
||||||
let exe = std::env::current_exe().unwrap();
|
|
||||||
unsafe {
|
|
||||||
ShellExecuteW(
|
|
||||||
None,
|
|
||||||
&HSTRING::from("runas"),
|
|
||||||
&HSTRING::from(exe.as_path()),
|
|
||||||
PCWSTR::null(),
|
|
||||||
PCWSTR::null(),
|
|
||||||
SW_HIDE,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
*closing = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_elevated() -> bool {
|
|
||||||
unsafe {
|
|
||||||
let mut token: HANDLE = HANDLE::default();
|
|
||||||
if OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &mut token).is_ok() {
|
|
||||||
let mut elevation = TOKEN_ELEVATION::default();
|
|
||||||
let size = u32::try_from(std::mem::size_of::<TOKEN_ELEVATION>()).unwrap();
|
|
||||||
let mut ret_size = size;
|
|
||||||
let result = GetTokenInformation(
|
|
||||||
token,
|
|
||||||
TokenElevation,
|
|
||||||
Some((&raw mut elevation).cast()),
|
|
||||||
size,
|
|
||||||
&mut ret_size,
|
|
||||||
);
|
|
||||||
CloseHandle(token).unwrap();
|
|
||||||
if result.is_ok() && elevation.TokenIsElevated != 0 {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
use std::{
|
||||||
|
fs::File,
|
||||||
|
io::Write,
|
||||||
|
sync::{LazyLock, Mutex},
|
||||||
|
time::SystemTime,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub struct Logger {
|
||||||
|
file: Mutex<File>,
|
||||||
|
}
|
||||||
|
|
||||||
|
static LOGGER: LazyLock<Logger> = LazyLock::new(|| Logger {
|
||||||
|
file: File::options()
|
||||||
|
.create(true)
|
||||||
|
.append(true)
|
||||||
|
.open(crate::util::consts::path::APP_LOG.as_path())
|
||||||
|
.unwrap()
|
||||||
|
.into(),
|
||||||
|
});
|
||||||
|
|
||||||
|
impl log::Log for Logger {
|
||||||
|
fn enabled(&self, metadata: &log::Metadata) -> bool {
|
||||||
|
metadata.level() <= log::Level::Info
|
||||||
|
}
|
||||||
|
|
||||||
|
fn flush(&self) {}
|
||||||
|
|
||||||
|
fn log(&self, record: &log::Record) {
|
||||||
|
if self.enabled(record.metadata()) {
|
||||||
|
self.log_to_stderr(record);
|
||||||
|
self.log_to_file(record);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Logger {
|
||||||
|
pub fn init(level: log::LevelFilter) {
|
||||||
|
log::set_logger(&*LOGGER)
|
||||||
|
.map(|()| log::set_max_level(level))
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn log_to_file(&self, record: &log::Record) {
|
||||||
|
let mut file = self.file.lock().unwrap();
|
||||||
|
write!(
|
||||||
|
file,
|
||||||
|
"[{}][{}]\n{}\n\n",
|
||||||
|
humantime::format_rfc3339_seconds(SystemTime::now()),
|
||||||
|
record.level(),
|
||||||
|
record.args()
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
file.flush().unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn log_to_stderr(&self, record: &log::Record) {
|
||||||
|
eprintln!(
|
||||||
|
"[{}][{}]\n{}",
|
||||||
|
humantime::format_rfc3339_seconds(SystemTime::now()),
|
||||||
|
record.level(),
|
||||||
|
record.args()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
pub mod consts;
|
|
||||||
pub mod countdown;
|
|
||||||
pub mod elevation;
|
|
||||||
|
|
||||||
use windows::Win32::UI::{
|
|
||||||
Input::KeyboardAndMouse::GetAsyncKeyState,
|
|
||||||
WindowsAndMessaging::{GetForegroundWindow, GetWindowTextW},
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn is_window_focused(target_title: &str) -> bool {
|
|
||||||
unsafe {
|
|
||||||
let hwnd = GetForegroundWindow();
|
|
||||||
let mut buffer: [u16; 512] = [0; 512];
|
|
||||||
let length = GetWindowTextW(hwnd, &mut buffer);
|
|
||||||
let current_title = String::from_utf16_lossy(&buffer[..length as usize]);
|
|
||||||
current_title == target_title
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_key_pressed(key: i32) -> bool {
|
|
||||||
unsafe { (GetAsyncKeyState(key) as i32 & 0x8000) != 0 }
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
use crate::{
|
||||||
|
features::launch::Platform,
|
||||||
|
gui::{app, settings::Settings},
|
||||||
|
util::consts::path,
|
||||||
|
};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::{
|
||||||
|
fs::{self, File},
|
||||||
|
io::Write,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct PersistentState {
|
||||||
|
pub launcher: Platform,
|
||||||
|
pub anti_afk_enabled: bool,
|
||||||
|
pub settings: Settings,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PersistentState {
|
||||||
|
pub fn get() -> Option<Self> {
|
||||||
|
fs::read_to_string(path::APP_CONFIG.as_path())
|
||||||
|
.ok()
|
||||||
|
.and_then(|config| serde_json::from_str::<Self>(&config).ok())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set(&self) {
|
||||||
|
let mut config_file = File::create(path::APP_CONFIG.as_path()).unwrap();
|
||||||
|
let json = serde_json::to_string_pretty(&self).unwrap();
|
||||||
|
config_file.write_all(json.as_bytes()).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn apply_to(self, app: &mut app::App) {
|
||||||
|
let Self {
|
||||||
|
launcher,
|
||||||
|
anti_afk_enabled,
|
||||||
|
settings,
|
||||||
|
} = self;
|
||||||
|
app.launch.selected = launcher;
|
||||||
|
app.anti_afk.enabled = anti_afk_enabled;
|
||||||
|
app.settings = settings;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
use std::{
|
||||||
|
ffi::{OsStr, OsString},
|
||||||
|
os::windows::{ffi::OsStringExt, process::CommandExt},
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
process::Command,
|
||||||
|
};
|
||||||
|
use windows::{
|
||||||
|
Win32::System::{
|
||||||
|
Diagnostics::ToolHelp::{
|
||||||
|
CreateToolhelp32Snapshot, PROCESSENTRY32W, Process32FirstW, Process32NextW,
|
||||||
|
TH32CS_SNAPPROCESS,
|
||||||
|
},
|
||||||
|
Threading::{
|
||||||
|
CREATE_NO_WINDOW, OpenProcess, PROCESS_NAME_WIN32, PROCESS_QUERY_LIMITED_INFORMATION,
|
||||||
|
QueryFullProcessImageNameW,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
core::PWSTR,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct Process {
|
||||||
|
pid: u32,
|
||||||
|
name: OsString,
|
||||||
|
exe: Option<PathBuf>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Process {
|
||||||
|
pub const fn pid(&self) -> u32 {
|
||||||
|
self.pid
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn name(&self) -> &OsStr {
|
||||||
|
&self.name
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn exe(&self) -> Option<&Path> {
|
||||||
|
self.exe.as_deref()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn kill(&self) -> bool {
|
||||||
|
let mut taskkill = Command::new("taskkill.exe");
|
||||||
|
taskkill.creation_flags(CREATE_NO_WINDOW.0);
|
||||||
|
taskkill.arg("/F").arg("/PID").arg(self.pid.to_string());
|
||||||
|
match taskkill.output() {
|
||||||
|
Ok(output) => output.status.success(),
|
||||||
|
Err(_) => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Default)]
|
||||||
|
pub struct SystemInfo {
|
||||||
|
processes: Vec<Process>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SystemInfo {
|
||||||
|
pub fn refresh(&mut self) {
|
||||||
|
let mut processes = Vec::new();
|
||||||
|
let snapshot_handle = unsafe { CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0) }.unwrap();
|
||||||
|
let mut process_entry = PROCESSENTRY32W {
|
||||||
|
dwSize: size_of::<PROCESSENTRY32W>() as u32,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
unsafe { Process32FirstW(snapshot_handle, &raw mut process_entry) }.unwrap();
|
||||||
|
let exe_full_path = get_exe_full_path(&process_entry);
|
||||||
|
processes.push(Process {
|
||||||
|
pid: process_entry.th32ProcessID,
|
||||||
|
name: wide_array_to_os_string(&process_entry.szExeFile),
|
||||||
|
exe: exe_full_path,
|
||||||
|
});
|
||||||
|
while unsafe { Process32NextW(snapshot_handle, &raw mut process_entry) }.is_ok() {
|
||||||
|
let exe_full_path = get_exe_full_path(&process_entry);
|
||||||
|
processes.push(Process {
|
||||||
|
pid: process_entry.th32ProcessID,
|
||||||
|
name: wide_array_to_os_string(&process_entry.szExeFile),
|
||||||
|
exe: exe_full_path,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
self.processes = processes;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn processes(&self) -> &[Process] {
|
||||||
|
&self.processes
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_exe_full_path(process_entry: &PROCESSENTRY32W) -> Option<PathBuf> {
|
||||||
|
let process_handle_result = unsafe {
|
||||||
|
OpenProcess(
|
||||||
|
PROCESS_QUERY_LIMITED_INFORMATION,
|
||||||
|
false,
|
||||||
|
process_entry.th32ProcessID,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
process_handle_result.map_or(None, |process_handle| {
|
||||||
|
let mut exe_name = [0u16; 260];
|
||||||
|
let mut dw_size = exe_name.len() as u32;
|
||||||
|
let image_name_result = unsafe {
|
||||||
|
QueryFullProcessImageNameW(
|
||||||
|
process_handle,
|
||||||
|
PROCESS_NAME_WIN32,
|
||||||
|
PWSTR(exe_name.as_mut_ptr()),
|
||||||
|
&raw mut dw_size,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
match image_name_result {
|
||||||
|
Ok(()) => Some(PathBuf::from(wide_array_to_os_string(&exe_name))),
|
||||||
|
Err(_) => None,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn wide_array_to_os_string(wide: &[u16]) -> OsString {
|
||||||
|
let null_pos = wide.iter().position(|&x| x == 0).unwrap_or(wide.len());
|
||||||
|
OsString::from_wide(&wide[..null_pos])
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
use windows::{
|
||||||
|
Win32::{
|
||||||
|
Foundation::{CloseHandle, HANDLE},
|
||||||
|
Security::{GetTokenInformation, TOKEN_ELEVATION, TOKEN_QUERY, TokenElevation},
|
||||||
|
System::Threading::{GetCurrentProcess, OpenProcessToken},
|
||||||
|
UI::{
|
||||||
|
Input::KeyboardAndMouse::{GetAsyncKeyState, VIRTUAL_KEY},
|
||||||
|
Shell::ShellExecuteW,
|
||||||
|
WindowsAndMessaging::{
|
||||||
|
CURSOR_SHOWING, CURSORINFO, GetCursorInfo, GetForegroundWindow, GetWindowTextW,
|
||||||
|
SW_NORMAL,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
core::{HSTRING, PCWSTR},
|
||||||
|
};
|
||||||
|
|
||||||
|
pub enum ElevationExitMethod<'a> {
|
||||||
|
Gentle(&'a mut bool),
|
||||||
|
Forced,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_cursor_visible() -> bool {
|
||||||
|
let mut ci = CURSORINFO {
|
||||||
|
cbSize: u32::try_from(std::mem::size_of::<CURSORINFO>()).unwrap(),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
unsafe { GetCursorInfo(&raw mut ci) }.unwrap();
|
||||||
|
ci.flags == CURSOR_SHOWING
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_window_focused(target_title: &str) -> bool {
|
||||||
|
let mut buffer = [0; 512];
|
||||||
|
let hwnd = unsafe { GetForegroundWindow() };
|
||||||
|
let length = unsafe { GetWindowTextW(hwnd, &mut buffer) };
|
||||||
|
let current_title = String::from_utf16_lossy(&buffer[..length as usize]);
|
||||||
|
current_title == target_title
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_any_key_pressed(keys: &[VIRTUAL_KEY]) -> bool {
|
||||||
|
keys.iter()
|
||||||
|
.any(|&key| unsafe { GetAsyncKeyState(i32::from(key.0)) } & i16::MIN != 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn elevate(closing: ElevationExitMethod) {
|
||||||
|
let exe = std::env::current_exe().unwrap();
|
||||||
|
unsafe {
|
||||||
|
ShellExecuteW(
|
||||||
|
None,
|
||||||
|
&HSTRING::from("runas"),
|
||||||
|
&HSTRING::from(exe.as_path()),
|
||||||
|
PCWSTR::null(),
|
||||||
|
PCWSTR::null(),
|
||||||
|
SW_NORMAL,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
match closing {
|
||||||
|
ElevationExitMethod::Gentle(closing) => *closing = true,
|
||||||
|
ElevationExitMethod::Forced => std::process::exit(0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_elevated() -> bool {
|
||||||
|
let mut token: HANDLE = HANDLE::default();
|
||||||
|
if unsafe { OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &raw mut token) }.is_err() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
let mut elevation = TOKEN_ELEVATION::default();
|
||||||
|
let mut size = u32::try_from(std::mem::size_of::<TOKEN_ELEVATION>()).unwrap();
|
||||||
|
let result = unsafe {
|
||||||
|
GetTokenInformation(
|
||||||
|
token,
|
||||||
|
TokenElevation,
|
||||||
|
Some((&raw mut elevation).cast()),
|
||||||
|
size,
|
||||||
|
&raw mut size,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
unsafe { CloseHandle(token) }.unwrap();
|
||||||
|
result.is_ok() && elevation.TokenIsElevated != 0
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_system_theme_dark() -> bool {
|
||||||
|
use winreg::RegKey;
|
||||||
|
let hkcu = RegKey::predef(winreg::enums::HKEY_CURRENT_USER);
|
||||||
|
let Ok(subkey) =
|
||||||
|
hkcu.open_subkey("Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize")
|
||||||
|
else {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
let Ok(dword): Result<u32, std::io::Error> = subkey.get_value("AppsUseLightTheme") else {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
dword != 1
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user