This repository has been archived by the owner on Feb 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrender.js
519 lines (477 loc) · 17.3 KB
/
render.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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
window.onload = function() {
const {remote} = require('electron');
const TabGroup = require("electron-tabs");
const ipc = require('electron').ipcRenderer;
const copy = require('copy-to-clipboard');
const dragula = require("dragula");
var fs = require('fs');
var accounts;
function loadAccounts() {
return new Promise((resolve, reject) => {
fs.readFile(__dirname + '/storage/accounts.json', 'utf8', function (err, data) {
if (err) {
reject(err);
}
resolve(data);
});
});
}
var promise = loadAccounts();
promise.then((msg) => {
accounts = JSON.parse(msg);
});
//var accounts = require('./storage/accounts.json');
const opn = require('opn');
const {BrowserWindow} = remote;
const win = remote.getCurrentWindow();
var dialog = remote.require('dialog');
var tabGroup = new TabGroup({
ready: function (tabGroup) {
dragula([tabGroup.tabContainer], {
direction: "horizontal"
});
}
});
var vers = [];
var tabList = [];
document.getElementById("exit").onclick = function() {
win.close();
}
document.getElementById("max").onclick = function() {
if (win.isMaximized()) {
win.unmaximize();
}
else {
win.maximize();
}
}
document.getElementById("min").onclick = function() {
win.minimize();
}
function zoomOut() {
var ri = document.getElementById("right-interface");
ri.setZoomFactor(0.5);
}
//File
document.getElementById("iiourpg").onclick = function() {
Promise.all([setRayVersion]).then(values => {
vers[2] = values[0];
let tab = tabGroup.addTab({
title: "IOURPG",
src: "http://d2452urjrn3oas.cloudfront.net/iou.swf?v=" + vers[2],
visible: true,
active: true,
webviewAttributes: {
plugins: true
}
});
tabList.push(tab);
});
}
document.getElementById("ikong").onclick = function() {
mainWindow = new BrowserWindow({
'width': 400,
'height': 400,
'frame': false,
'icon': __dirname + '/settings.png',
'title': 'Kongregate Account'
});
mainWindow.loadURL(`file://${__dirname}/kong.html`);
}
ipc.on("sendKong", function(event, message){
Promise.all([setVersions, setRayVersion]).then(values => {
vers = values[0].split(",");
vers.push(values[1]);
var pJson = [message.id, message.token];
accounts[message.user] = pJson;
saveAccounts();
var player2 = new Player(message.user, message.id, message.token, vers[0], vers[1], vers[2]);
let tab = tabGroup.addTab({
title: message.user,
src: player2.getUrl(),
visible: true,
active: true,
webviewAttributes: {
plugins: true
}
});
tabList.push(tab);
});
})
ipc.on("sendSettings", function(event, message){
alert("Settings Saved.");
});
document.getElementById("itest-client").onclick = function() {
Promise.all([setVersions, setRayVersion]).then(values => {
vers = values[0].split(",");
vers.push(values[1]);
var username = tabGroup.getActiveTab().getTitle();
if ((username == null) || username == "IOURPG") {
let tab = tabGroup.addTab({
title: "IOURPG Test",
src: "http://d2452urjrn3oas.cloudfront.net/test.swf?v=" + vers[2],
visible: true,
active: true,
webviewAttributes: {
plugins: true
}
});
tabList.push(tab);
}
else {
for (acc in accounts) {
if (acc == username) {
var player3 = new Player(acc, accounts[acc][0], accounts[acc][1], vers[0], vers[1], vers[2]);
let tab = tabGroup.addTab({
title: player3.getUsername() + " Test",
src: player3.getTestUrl(),
visible: true,
active: true,
webviewAttributes: {
plugins: true
}
});
tabList.push(tab);
}
}
}
});
}
document.getElementById("isave").onclick = function() {
saveAccounts();
}
document.getElementById("isave-as").onclick = function() {
require('electron').remote.dialog.showSaveDialog( { defaultPath: "accounts.json" }, function(fileName) {
fs.writeFile(fileName, JSON.stringify(accounts), "utf8");
alert("Accounts saved.");
});
}
document.getElementById("iload").onclick = function() {
var prom = loadJson();
prom.then((msg) => {
Promise.all([setVersions, setRayVersion]).then(values => {
vers = values[0].split(",");
vers.push(values[1]);
var accounts2 = JSON.parse(msg);
for (acc in accounts2) {
var player2 = new Player(acc, accounts2[acc][0], accounts2[acc][1], vers[0], vers[1], vers[2]);
var aJson = [accounts2[acc][0], accounts2[acc][1]];
accounts[acc] = aJson;
let tab = tabGroup.addTab({
title: player2.getUsername(),
src: player2.getUrl(),
visible: true,
active: true,
webviewAttributes: {
plugins: true
}
});
tabList.push(tab);
}
});
});
}
function loadJson() {
return new Promise((resolve, reject) => {
require('electron').remote.dialog.showOpenDialog( { defaultPath: "accounts.json" }, function(fileName) {
fs.readFile(fileName.toString(), 'utf8', function (err, data) {
if (err) {
reject(err);
}
resolve(data);
});
});
});
}
//Settings
document.getElementById("ssettings").onclick = function() {
mainWindow = new BrowserWindow({
'width': 400,
'height': 400,
'frame': false,
'icon': __dirname + '/settings.png',
'title': 'Settings'
});
mainWindow.loadURL(`file://${__dirname}/settings.html`);
}
//Links
document.getElementById("liou-helper").onclick = function() {
opn('http://www.iouhelper.com/');
}
document.getElementById("liou-helper-discord").onclick = function() {
opn('https://discord.gg/wczWVmZ');
}
document.getElementById("lmulticalc").onclick = function() {
opn('https://docs.google.com/spreadsheets/d/1QGBm6KtcOZraqSkLWVuqTF16vUD7rrOvIpdh59bFLmg/edit#gid=357923173');
}
document.getElementById("liou-discord").onclick = function() {
opn('https://discord.gg/zynuQcP');
}
document.getElementById("liou-forum").onclick = function() {
opn('https://iourpg.com/forum/');
}
document.getElementById("liou-wiki").onclick = function() {
opn('http://iourpg.wikia.com/wiki/Idle_Online_Universe_Wiki');
}
document.getElementById("lcard-calculator").onclick = function() {
opn('http://iouhelper.com/cards.html');
}
const setVersions = new Promise((resolve, reject) => {
var https = require('https');
const options = {
followAllRedirects: true,
host: 'www.kongregate.com',
path: '/games/iouRPG/idle-online-universe'
}
var request = https.request(options, function (res) {
var data = '';
res.on('data', function (chunk) {
data += chunk;
});
res.on('end', function () {
let gameCode = data.substring(data.indexOf('API_AS3_') + 8, data.indexOf('.swf\",\"preview\"'));
let gameVersion = data.substring(data.indexOf('\"game_version\":') + 15, data.indexOf(',\"flash_var_prefix\"'));
resolve(gameCode + "," + gameVersion);
});
});
request.on('error', function (e) {
reject(e.message);
});
request.end();
}
);
var setRayVersion = new Promise(
function (resolve, reject) {
var ranHost = "/v.txt?d=506" + Math.floor((Math.random() * 1000) + 1);
var http = require('http');
var options = {
host: 'd2452urjrn3oas.cloudfront.net',
path: ranHost
}
var request = http.request(options, function (res) {
var data = '';
res.on('data', function (chunk) {
data += chunk;
});
res.on('end', function () {
resolve(data);
});
});
request.on('error', function (e) {
reject(e.message);
});
request.end();
}
);
function saveAccounts() {
fs.writeFile(__dirname + "/storage/accounts.json", JSON.stringify(accounts), "utf8");
}
function saveAccountsFromTab() {
var aJson = {};
for (acc in accounts) {
for (gTab in tabList) {
if (acc == tabList[gTab].getTitle()) {
aJson[acc] = [accounts[acc][0], accounts[acc][1]];
}
}
}
accounts = aJson;
saveAccounts();
}
Promise.all([setVersions, setRayVersion]).then(values => {
vers = values[0].split(",");
vers.push(values[1]);
loadPlayers(vers);
});
function loadPlayers(versionArray) {
for (acc in accounts) {
var player = new Player(acc, accounts[acc][0], accounts[acc][1], versionArray[0], versionArray[1], versionArray[2]);
let tab = tabGroup.addTab({
title: player.getUsername(),
src: player.getUrl(),
visible: true,
active: true,
webviewAttributes: {
plugins: true
}
});
tabList.push(tab);
}
}
tabGroup.on("tab-removed", (tab, tabGroup) => {
saveAccountsFromTab();
});
//Tools
document.getElementById("trefresh").onclick = function() {
singleRefresh();
}
function singleRefresh() {
Promise.all([setVersions, setRayVersion]).then(values => {
vers = values[0].split(",");
vers.push(values[1]);
var aTab = tabGroup.getActiveTab();
if (aTab.getTitle() != null) {
if (aTab.getTitle() == "IOURPG") {
aTab.webview.loadURL("http://d2452urjrn3oas.cloudfront.net/iou.swf?v=" + vers[2]);
}
else if (aTab.getTitle() == "IOURPG Test") {
aTab.webview.loadURL("http://d2452urjrn3oas.cloudfront.net/test.swf?v=" + vers[2]);
}
else {
for (acc in accounts) {
if (aTab.getTitle() == acc) {
var player4 = new Player(acc, accounts[acc][0], accounts[acc][1], vers[0], vers[1], vers[2]);
aTab.webview.loadURL(player4.getUrl());
break;
}
}
}
}
else {
alert("You can't refresh with zero tabs.");
}
});
}
document.getElementById("trefresh-all").onclick = function() {
refreshAll();
}
function refreshAll() {
Promise.all([setVersions, setRayVersion]).then(values => {
vers = values[0].split(",");
vers.push(values[1]);
if (tabList.length > 0) {
for (gTab in tabList) {
if (tabList[gTab].getTitle() == "IOURPG") {
tabList[gTab].webview.loadURL("http://d2452urjrn3oas.cloudfront.net/iou.swf?v=" + vers[2]);
}
else if (tabList[gTab].getTitle() == "IOURPG Test") {
tabList[gTab].webview.loadURL("http://d2452urjrn3oas.cloudfront.net/test.swf?v=" + vers[2]);
}
else {
for (acc in accounts) {
if (tabList[gTab].getTitle() == acc) {
var player5 = new Player(acc, accounts[acc][0], accounts[acc][1], vers[0], vers[1], vers[2]);
tabList[gTab].webview.loadURL(player5.getUrl());
}
}
}
}
}
else {
alert("You can't refresh with zero tabs.");
}
});
}
document.getElementById("tcopy-details").onclick = function() {
var a = tabGroup.getActiveTab().getTitle();
if ((a != "IOURPG") && (a != "IOURPG Test") && (a != null)) {
for (acc in accounts) {
if (a == acc) {
var player6 = new Player(acc, accounts[acc][0], accounts[acc][1], vers[0], vers[1], vers[2]);
copy(player6.getDetails());
alert("Copied account details to clipboard.");
}
}
}
else {
alert("You cannot copy these account details.");
}
}
document.getElementById("tcopy-url").onclick = function() {
var a = tabGroup.getActiveTab().getTitle();
if ((a != "IOURPG") && (a != "IOURPG Test") && (a != null)) {
for (acc in accounts) {
if (a == acc) {
var player6 = new Player(acc, accounts[acc][0], accounts[acc][1], vers[0], vers[1], vers[2]);
copy(player6.getUrl());
alert("Copied account URL to clipboard.");
}
else if (a == acc + " Test") {
var player6 = new Player(acc, accounts[acc][0], accounts[acc][1], vers[0], vers[1], vers[2]);
copy(player6.getTestUrl());
alert("Copied test account URL to clipboard.");
}
}
}
else {
alert("You cannot copy these account details.");
}
}
document.getElementById("body").onkeydown = function(e){
switch (e.which) {
case 112: //f1
toggleAutoclicker(true);
break;
case 113: //f2
toggleAutoclicker(false);
break;
case 114: //f3
toggleAutoskills(true);
break;
case 115: //f4
toggleAutoskills(false);
break;
case 116: //f5
singleRefresh();
break;
case 117: //f5
refreshAll();
break;
default:
break;
}
}
var clicker = null;
function toggleAutoclicker(value) {
var aTab = tabGroup.getActiveTab();
if (aTab == null) {
alert("You cannot enable autoclicker with no tabs");
return;
}
if (clicker == null && value === true) {
clicker = setInterval(() => {
aTab.webview.getWebContents().sendInputEvent({
type: 'mousedown',
x: 600,
y: 350,
clickCount: 1
});
aTab.webview.getWebContents().sendInputEvent({
type: 'mouseup',
x: 600,
y: 350
});
}, 100);
} else {
clearInterval(clicker);
clicker = null;
}
}
let skiller = null;
function toggleAutoskills(value) {
var aTab = tabGroup.getActiveTab();
if (aTab == null) {
alert("You cannot enable auto skills with no tabs");
return;
}
let useKey = (keyCode) => {
aTab.webview.getWebContents().sendInputEvent({
type: 'keyDown',
keyCode: keyCode.toString(),
});
};
if (skiller == null && value === true) {
skiller = setInterval(() => {
useKey(3);
useKey(4);
useKey(5);
useKey(6);
useKey(2);
useKey(1);
}, 1000);
} else {
clearInterval(skiller);
skiller = null;
}
}
}