-
Notifications
You must be signed in to change notification settings - Fork 0
/
cheat.js
271 lines (227 loc) · 7.43 KB
/
cheat.js
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
let gameLocations = [];
let isBusy = false;
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function isInNormalMode() {
var infoDiv = document.querySelector("div.info");
if (infoDiv) {
var totalDiv = infoDiv.querySelector("div.total");
if (totalDiv) {
return true;
} else {
return false;
}
} else {
return false;
}
}
function clickMapCenter() {
const panelElement = document.querySelector('[data-control="Panel"]');
const panelRect = panelElement.getBoundingClientRect();
const screenWidth = window.innerWidth;
const remainingWidth = screenWidth - panelRect.width;
const x = panelRect.width + remainingWidth / 2;
const y = window.innerHeight / 2 - 15;
const clickEvent = new MouseEvent("click", {
bubbles: true,
cancelable: true,
view: window,
detail: 1,
clientX: x,
clientY: y,
ctrlKey: false,
altKey: false,
shiftKey: false,
metaKey: false,
button: 0,
buttons: 1,
relatedTarget: null,
screenX: x,
screenY: y,
pageX: x,
pageY: y,
movementX: 0,
movementY: 0,
offsetDirection: 0,
layerX: x,
layerY: y,
fromElement: null,
toElement: document.elementFromPoint(x, y),
currentTarget: document.elementFromPoint(x, y),
target: document.elementFromPoint(x, y),
isTrusted: true,
});
document.elementFromPoint(x, y).dispatchEvent(clickEvent);
}
async function getVersusLocations() {
if (isBusy) {
return;
}
isBusy = true;
const lobbyID = localStorage.getItem("lobbyId");
const lobbyUserID = localStorage.getItem("lobbyUserId");
let response = await fetch("https://gtaguessr.com/API/GetVersusLocations", {
method: "POST",
body: JSON.stringify({
lobbyId: lobbyID,
lobyUserId: lobbyUserID,
}),
headers: {
"Content-Type": "application/json",
},
});
response = await response.json();
gameLocations = response?.locations ?? [];
isBusy = false;
}
async function getLocationByID(id) {
selectedRound = id + 1;
const lobbyID = localStorage.getItem("lobbyId");
const lobbyUserID = localStorage.getItem("lobbyUserId");
let response = await fetch("https://gtaguessr.com/API/SubmitAGuess", {
method: "POST",
body: JSON.stringify({
sessionId: getRandomInt(10000000, 99999999).toString(),
locationId: gameLocations[id]?.locationId ?? 0,
lat: `${getRandomInt(-7000, 7000)}.${getRandomInt(0, 99999)}`,
lng: `${getRandomInt(7000, 7000)}.${getRandomInt(0, 99999)}`,
lobyId: getRandomInt(10000000, 99999999).toString(),
lobyUserId: getRandomInt(555555, 999999).toString(),
game: getRandomInt(1, 5).toString(),
}),
headers: {
"Content-Type": "application/json",
},
});
response = await response.json();
const lat = response?.lat ?? 0;
const lng = response?.lng ?? 0;
return { lat, lng };
}
async function setLocation(locationID) {
if (isBusy) {
return;
}
isBusy = true;
changeCopyrightText("Finding the exact coordinates...");
let exactLocation;
const mapElement = document.querySelector('[data-control="Map"]');
mapElement.style.transition = "filter 200ms";
mapElement.style.filter = "grayscale(1) brightness(20%)";
document.body.style.cursor = "progress";
try {
exactLocation = await getLocationByID(locationID);
} catch {
alert("Error while finding exact location");
mapElement.style.filter = "grayscale(0) brightness(100%)";
document.body.style.cursor = "inherit";
return;
}
window.location.href =
"/Guess#5/" + exactLocation.lat + "/" + exactLocation.lng;
changeCopyrightText("Setting map marker...");
await new Promise((resolve) => {
setTimeout(resolve, 2000);
});
clickMapCenter();
mapElement.style.filter = "grayscale(0) brightness(100%)";
document.body.style.cursor = "inherit";
isBusy = false;
changeCopyrightText(
"Select the round number to locate the coordinates for it",
);
}
// UI
function changeCopyrightText(text) {
const element = document.getElementById("copyright");
element.innerText = "© GtaGuessr | " + text;
}
async function getLocationsAndInitUI() {
if (document.getElementById("cheatLocations")) {
document.getElementById("cheatLocations").remove();
changeCopyrightText("Reloading Locations...");
} else {
changeCopyrightText("Finding Locations...");
}
try {
await getVersusLocations();
} catch (e) {
alert("Error while getting locations!");
console.error(e.message);
return;
}
changeCopyrightText(
"Select the round number to locate the coordinates for it",
);
document.getElementById("cheatFindLocations").remove();
const targetElement = document.querySelector('[data-control="Panel"]');
const newElement = document.createElement("div");
newElement.id = "cheatLocations";
newElement.style.display = "grid";
newElement.style.gridTemplateColumns = "repeat(5, 1fr)";
newElement.style.columnGap = "5px";
newElement.style.marginBottom = "5px";
const buttons = [
{ id: "setFirstLocation", onclick: "setLocation(0);", text: "1" },
{ id: "setSecondLocation", onclick: "setLocation(1);", text: "2" },
{ id: "setThirdLocation", onclick: "setLocation(2);", text: "3" },
{ id: "setFourthLocation", onclick: "setLocation(3);", text: "4" },
{ id: "setFifthLocation", onclick: "setLocation(4);", text: "5" },
];
buttons.forEach((button) => {
const buttonElement = document.createElement("button");
buttonElement.id = button.id;
buttonElement.style.backgroundColor = "#f83849";
buttonElement.style.border = "none";
buttonElement.style.padding = "10px 10px";
buttonElement.style.width = "100%";
buttonElement.style.fontWeight = "500";
buttonElement.style.color = "white";
buttonElement.onclick = new Function(button.onclick);
buttonElement.textContent = button.text;
newElement.appendChild(buttonElement);
});
targetElement.insertBefore(newElement, targetElement.firstChild);
}
async function activateCheats() {
if (window.location.host != "gtaguessr.com") {
alert(
"Unsupported website! Cheats only work on gtaguessr.com (Versus Mode)!",
);
return;
}
if (!document.querySelector('[data-control="Map"]')) {
alert("Cheats can only be initiated while in game (Versus Mode)!");
return;
}
if (isInNormalMode()) {
alert("Normal Mode is not supported! Only Versus Mode is!");
return;
}
if (document.body.attributes["cheats-init"]) {
alert("Cheats already activated!");
return;
} else {
document.body.attributes["cheats-init"] = "yes";
}
const findLocationsCheatElement = document.createElement("button");
findLocationsCheatElement.style.border = "none";
findLocationsCheatElement.id = "cheatFindLocations";
findLocationsCheatElement.style.backgroundColor = "#f83849";
findLocationsCheatElement.style.padding = "10px 50px";
findLocationsCheatElement.style.fontWeight = "500";
findLocationsCheatElement.style.color = "white";
findLocationsCheatElement.style.zIndex = "9999999999";
findLocationsCheatElement.style.bottom = "50px";
findLocationsCheatElement.style.position = "absolute";
findLocationsCheatElement.style.right = "20px";
findLocationsCheatElement.onclick = getLocationsAndInitUI;
findLocationsCheatElement.textContent = "Find Locations";
document.body.insertBefore(
findLocationsCheatElement,
document.body.firstChild,
);
changeCopyrightText("Versus Mode Cheats Activated");
}
activateCheats();