-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheats
150 lines (130 loc) · 4.03 KB
/
cheats
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash
# "Cheat Codes Console"
# A handy script manager in the form of an easter egg.
# Enter "cheats" to get addons, run fixes, find easter eggs, and more!
# Full list of commands + payloads can be found at the CHEATCODES_URL page below.
# Use `cheats -h` to see more!
# Request sudo upfront
echo "Requesting sudo password..."
sudo -v
# Check for deps
if ! command -v dialog &> /dev/null; then
echo "dialog is not installed. Installing..."
sudo apt-get update
sudo apt-get install -y dialog
fi
if ! command -v jq &> /dev/null; then
echo "jq is not installed. Installing..."
sudo apt-get update
sudo apt-get install -y jq
fi
# Repos
REPOSITORIES='{
"default": "https://raw.githubusercontent.com/Szmelc-INC/Cheats/refs/heads/main/data.json",
"repo2": "https://raw.githubusercontent.com/Szmelc-INC/Cheats/refs/heads/main/data-2.json"
}'
# Initialize variables
REPO_URL=$(echo "$REPOSITORIES" | jq -r '.default')
LIST_ONLY=false
# --help
show_help() {
echo "Cheat Codes Console"
echo "Usage: cheats [OPTIONS]"
echo ""
echo "Options:"
echo " -l, --list List available cheat codes."
echo " -d, --data <repo_name> Specify a repository by name (e.g., 'repo2')."
echo " -h, --help Display this help message."
echo ""
echo "Available repositories:"
echo "$REPOSITORIES" | jq -r 'to_entries | .[] | " \(.key): \(.value)"'
echo ""
exit 0
}
# Parse command-line arguments
while [[ $# -gt 0 ]]; do
case "$1" in
--list|-l)
LIST_ONLY=true
;;
--data|-d)
REPO_NAME="$2"
shift
REPO_URL=$(echo "$REPOSITORIES" | jq -r --arg name "$REPO_NAME" '.[$name] // empty')
if [ -z "$REPO_URL" ]; then
echo "Unknown repository: $REPO_NAME"
echo "Use -h or --help to see available repositories."
exit 1
fi
;;
--help|-h)
show_help
;;
*)
echo "Unknown argument: $1"
echo "Use -h or --help for usage."
exit 1
;;
esac
shift
done
# Fetch JSON from selected repository
json_data=$(curl -s "$REPO_URL")
if [ -z "$json_data" ]; then
echo "Failed to fetch cheat codes data.json from $REPO_URL."
exit 1
fi
# Function to display all available cheats in a dialog box
list_cheats_dialog() {
cheats=$(echo "$json_data" | jq -r '.cheatcodes[] | "\(.code) - \(.desc)\n\(.command)"' | awk '
BEGIN { empty_line = "\n" }
NR % 2 == 1 { printf empty_line "# %s - %s\n", $1, substr($0, index($0,$2)) }
NR % 2 == 0 { printf "> %s\n", $0 empty_line }
')
dialog --title "Available Cheats" --msgbox "$cheats" 20 60
}
# If --list or -l is passed, list cheats and exit
if [ "$LIST_ONLY" = true ]; then
clear
list_cheats_dialog
exit 0
fi
while true; do
# Prompt the user to enter a cheat code
cheatcode=$(dialog --title "Cheat Console v3" --inputbox "Enter cheat \n(or type #list to show list:)" 8 50 3>&1 1>&2 2>&3 3>&-)
# Check if user cancelled or pressed ESC
exit_status=$?
if [ $exit_status -ne 0 ]; then
break
fi
# Handle the `#list` command
if [ "$cheatcode" == "#list" ]; then
list_cheats_dialog
continue
fi
# Find the command and description corresponding to the cheat code
command=$(echo "$json_data" | jq -r --arg code "$cheatcode" '.cheatcodes[] | select(.code==$code) | .command')
description=$(echo "$json_data" | jq -r --arg code "$cheatcode" '.cheatcodes[] | select(.code==$code) | .desc')
if [ -z "$command" ] || [ "$command" == "null" ]; then
dialog --title "Cheat Console" --msgbox "Code not found." 6 40
continue
fi
# Display the description if available
if [ -n "$description" ] && [ "$description" != "null" ]; then
dialog --title "Details" --msgbox "Description: \n$description" 10 60
fi
# Show confirmation dialog
dialog --title "Confirmation" --yesno "Execute? \n\n$command" 10 60
response=$?
case $response in
0) # Yes
# Execute the command
eval "$command"
;;
1|255) # No or ESC
dialog --title "Cheat Console" --msgbox "Command execution cancelled." 6 40
;;
esac
done
# Clean up
clear