-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSROMCv0-9-5.py
More file actions
538 lines (470 loc) · 16.8 KB
/
SROMCv0-9-5.py
File metadata and controls
538 lines (470 loc) · 16.8 KB
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
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
# SRO Mobile Center v0.95 - Plugin for phBot - Silkroad Online Game
# Copyright ILKERC - Under MIT License
# https://sromc.com/
from locale import getlocale
from phBot import *
import phBotChat
import QtBind
import os
import random
import urllib.request
import json
import struct
import string
import sqlite3
import time
from datetime import datetime
from types import SimpleNamespace
# Global Variables
appName = 'SROMC'
appFullName = 'SRO Mobile Center'
appVersion = 'v0.95'
appAuthor = 'ILKERC'
appRunning = False
accountCreated = False
apiEndpoint = 'https://api.sromc.com'
apiRequests = 0
taskCompleted = False
deadCounter = 0
itemCounter = 0
rareItemCounter = 0
appUsing = False
messages = []
# Create GUI
gui = QtBind.init(__name__, appName + ' ' + appVersion)
QtBind.createLabel(gui, '<b>' + appFullName + ' ' +
appVersion + '</b>', 10, 10)
QtBind.createLabel(gui, '', 10, 40)
QtBind.createLabel(
gui, 'Generate a character login info with the button below and enter it in the mobile app. Visit <a href="https://sromc.com/">https://sromc.com</a>', 10, 40)
btnReset = QtBind.createButton(gui, 'reset_click', 'Reset and Stop', 10, 70)
btnCreate = QtBind.createButton(
gui, 'showCode_click', 'Create Character', 10, 70)
lblCode = QtBind.createLabel(gui, '', 10, 120)
lblPassword = QtBind.createLabel(gui, '', 10, 140)
lblCodeDesc = QtBind.createLabel(gui, '', 10, 180)
# Run app
def showCode_click():
global accountCreated
global appRunning
global appUsing
global apiRequests
char = get_character_data()
status = get_status()
accountId = str(char['account_id'])
apiRequests = 0
# Before created
if(accountCreatedBefore() == True):
accountCreated = True
# Check character is in the game
if isCharInGame() == False:
QtBind.setText(gui, lblCode, 'Error!')
QtBind.setText(gui, lblCodeDesc,
'Make sure the character is in the game.')
else:
server = str(char['server'])
charName = str(char['name'])
playerId = str(char['player_id'])
randomNumber = str(get_random_string())
# Create account and get userid
if accountCreated == False:
response = requestApi(
'/account/create', {'PlayerId': playerId, 'Server': server, 'CharName': charName, 'Password': randomNumber})
_result = json.loads(response)
userId = str(_result["charId"])
randomPassword = str(randomNumber)
secret = str(_result["token"])
QtBind.setText(gui, lblCode, 'Char ID: <b>' + userId + '</b>')
QtBind.setText(gui, lblPassword, 'Password: <b>' +
randomPassword + '</b> (Password will be hidden in 60 seconds)')
QtBind.setText(
gui, lblCodeDesc, 'You can log in to the mobile application with the above information. \nSave your password in a secure area. It will not be shown again')
accountCreated = True
saveAccount(server, charName, userId, secret)
writeMessage('New account successfuly created. (' +
server + '/' + charName + ')')
appRunning = True
appUsing = True
else:
alreadyHave()
toggleButtons()
# Reset and delete account
def reset_click():
global accountCreated
global appRunning
char = get_character_data()
os.remove('Plugins/SROMC_' + char['server'] + '_' + char['name'] + '.txt')
writeMessage('Account successfuly deleted.')
accountCreated = False
appRunning = False
toggleButtons()
# Already have account message
def alreadyHave():
QtBind.setText(gui, lblCode, 'Char ID: <b>' + getUserId() + '</b>')
QtBind.setText(
gui, lblPassword, 'Password: XXXXXX <i>(If you forgot, reset and create new account)</i>')
QtBind.setText(gui, lblCodeDesc,
'You have already created a user account.')
# Random password
def get_random_string():
letters = string.ascii_letters + string.digits
result_str = ''.join(random.choice(letters) for i in range(12))
return result_str
# If account created before, get user id
def getUserId():
char = get_character_data()
try:
lines = list(
open('Plugins/SROMC_' + char['server'] + '_' + char['name'] + '.txt', 'r'))
if len(lines) == 2:
return str(lines[0]).replace('\n', '')
else:
return ''
except:
pass
return ''
# Get token of user
def getToken():
char = get_character_data()
try:
lines = list(
open('Plugins/SROMC_' + char['server'] + '_' + char['name'] + '.txt', 'r'))
if len(lines) == 2:
return str(lines[1]).replace('\n', '')
else:
return ''
except:
pass
return ''
# Check account created before
def accountCreatedBefore():
char = get_character_data()
try:
lines = list(
open('Plugins/SROMC_' + char['server'] + '_' + char['name'] + '.txt', 'r'))
if len(lines) == 2:
return True
else:
return False
except:
pass
return False
# Save account info to file
def saveAccount(server, charName, userId, secret):
lines = [userId, secret]
with open('Plugins/SROMC_' + server + '_' + charName + '.txt', 'w') as f:
f.write('\n'.join(lines))
f.close()
# Check is char in game
def isCharInGame():
accountId = str(get_character_data()['account_id'])
if accountId == "0":
return False
return True
# Important events
def handle_event(t, data):
global deadCounter
global itemCounter
global rareItemCounter
if t == 5:
rareItemCounter += 1
elif t == 4:
log('Under attack by player')
elif t == 6:
itemCounter += 1
elif t == 7:
deadCounter += 1
# Messages
class Message:
def __init__(self, message, player, type, typeInt, date):
self.message = message
self.player = player
self.type = type
self.typeInt = typeInt
self.date = date
def toDict(self):
return {"message": self.message, "player": self.player, "type": self.type, "typeInt": self.typeInt, "date": self.date}
# Chat message received
def handle_chat(t, player, msg):
global messages
max_messages = 120
message = str(msg)
message = urllib.parse.quote(message)
currentDate = datetime.now()
type = str(messageType(t))
sender = str(player)
_m = Message(message, sender, type, t, currentDate.strftime("%d/%m/%Y %H:%M:%S"))
messages.append(_m.toDict())
if len(messages) > max_messages :
messages.pop(len(messages) - max_messages - 1)
#Message type
def messageType(type):
if type == 1:
return "all"
elif type == 2:
return "private"
elif type == 3:
return "gm"
elif type == 4:
return "party"
elif type == 5:
return "guild"
elif type == 6:
return "global"
elif type == 7:
return "notice"
elif type == 9:
return "stall"
elif type == 11:
return "union"
elif type == 16:
return "academy"
else:
return "all"
# Send PM
def sendPM(message, to, player):
if to == 'party':
phBotChat.Party(message)
elif to == 'guild':
phBotChat.Guild(message)
elif to == 'union':
phBotChat.Union(message)
elif to == 'stall':
phBotChat.Stall(message)
elif to == 'global':
phBotChat.Global(message)
elif to == 'private':
phBotChat.Private(player, message)
else:
phBotChat.All(message)
# Event loop 500ms
def event_loop():
global appRunning
if isCharInGame() == True and accountCreatedBefore() == True:
sendInfo()
appRunning = True
else:
appRunning = False
def training_area():
t = str(get_training_area())
if t == "None":
t = "{'x': 0, 'y': 0, 'z': 0, 'region': 24305, 'path': '', 'radius': 0, 'pick_radius': 0}"
return t
# Send info to api
def sendInfo():
global appRunning
global apiRequests
global taskCompleted
global messages
global deadCounter
global itemCounter
global rareItemCounter
global appUsing
apiRequests += 1
if ((appRunning == True) and (isCharInGame() == True) and (apiRequests % 5 == 0)):
if apiRequests >= 60:
alreadyHave()
apiRequests = 0
if appUsing == True:
writeMessage('Data sent successfully. (Power mode)')
else:
writeMessage('Data sent successfully. (Sleep mode)')
if(appUsing == True):
char_data = get_character_data();
char_data_str = str(char_data);
char_data_str = char_data_str[:len(char_data_str)-1] + ", 'regionName':'" + get_zone_name(char_data['region']) + "', 'items': " + str(itemCounter) + ", 'rareItems': " + str(rareItemCounter) + ", 'trainingArea': " + str(training_area()) + ", 'dies': " + str(deadCounter) + " }"
game = str(get_locale())
status = str(get_status())
char = char_data_str
guild = str(get_guild())
guild_union = str(get_guild_union())
party = str(get_party())
inventory = str(get_inventory())
storage = str(get_storage())
storage_guild = str(get_guild_storage())
academy = str(get_academy())
pets = str(get_pets())
players = str(get_players())
taxi = str(get_taxi())
monsters = str(get_monsters())
drops = str(get_drops())
quests = str(get_quests())
skills = str(get_active_skills())
token = str(getToken())
user_id = str(getUserId())
_messages = str(messages)
requestJson = {
'charId': user_id,
'token': token,
'status': status,
'game': game,
'character': char,
'inventory': inventory,
'storage': storage,
'storage_guild': storage_guild,
'quests': quests,
'drops': drops,
'guild': guild,
'guild_union': guild_union,
'party': party,
'taxi': taxi,
'monsters': monsters,
'pets': pets,
'skills': skills,
'players': players,
'academy': academy,
'messages': _messages,
'taskCompleted': str(taskCompleted)
}
else:
requestJson = {
'charId': str(getUserId()),
'token': str(getToken()),
'status': str(get_status())
}
toggleButtons()
try:
response = requestApi('/charinfo/create', requestJson)
hasTask = json.loads(response, object_hook=lambda d: SimpleNamespace(**d))
tasks = str(hasTask.tasks.command)
lastActionUTCDate = datetime.fromisoformat(str(hasTask.mobileLastActionDate))
currentUTCDate = datetime.utcnow()
seconds = (currentUTCDate - lastActionUTCDate).total_seconds()
if seconds >= 30:
appUsing = False
else:
appUsing = True
if tasks == "start_bot":
start_bot()
writeMessage("Task > Bot start")
elif tasks == "stop_bot":
stop_bot()
writeMessage("Task > Bot stop")
elif tasks == "set_training_radius":
set_training_radius(float(hasTask.tasks.arg1))
writeMessage("Task > Set training radius")
elif tasks == "set_training_position":
set_training_position(0, float(hasTask.tasks.arg1), float(hasTask.tasks.arg2), float(hasTask.tasks.arg3))
writeMessage("Task > Set training position")
elif tasks == "start_trace":
start_trace(str(hasTask.tasks.arg1))
writeMessage("Task > Start tracing (" + str(hasTask.tasks.arg1) + ")")
elif tasks == "start_script":
start_script(str(hasTask.tasks.arg1))
writeMessage("Task > Start script")
elif tasks == "stop_script":
stop_script()
writeMessage("Task > Stop script")
elif tasks == "stop_trace":
stop_trace()
writeMessage("Task > Stop tracing")
elif tasks == "send_global":
sendPM(str(hasTask.tasks.arg1), 'global', '')
writeMessage("Task > Sent global message")
elif tasks == "guild_invite":
isSuccess = phBotChat.Private(str(hasTask.tasks.arg1), str(hasTask.tasks.arg2))
data = b'\x08\x00'
for c in str(hasTask.tasks.arg1):
data += struct.pack('b', ord(c))
if isSuccess:
inject_joymax(0x70F3, data, False)
writeMessage("Task > Invite guild")
elif tasks == "guild_kick":
isSuccess = phBotChat.Private(str(hasTask.tasks.arg1), str(hasTask.tasks.arg2))
data = b'\x08\x00'
for c in str(hasTask.tasks.arg1):
data += struct.pack('b', ord(c))
if isSuccess:
inject_joymax(0x70F4, data, False)
writeMessage("Task > Kick from guild")
elif tasks == "leave_party":
if get_party():
inject_joymax(0x7061, b'', False)
writeMessage("Task > Leave from party")
elif tasks == "move_to":
move_to(float(hasTask.tasks.arg1), float(hasTask.tasks.arg2), 0)
writeMessage("Task > Moving target X and Y")
elif tasks == "send_message":
sendPM(str(hasTask.tasks.arg1), str(hasTask.tasks.arg2), str(hasTask.tasks.arg3))
if str(hasTask.tasks.arg2) == "private":
charName = str(char_data['name'])
toCharName = str(hasTask.tasks.arg3)
message = str(hasTask.tasks.arg1)
message = urllib.parse.quote(message)
currentDate = datetime.now()
_m = Message(str(message), charName + "|" + toCharName, str("private"), 2, currentDate.strftime("%d/%m/%Y %H:%M:%S"))
messages.append(_m.toDict())
writeMessage("Task > Message sent. (" + hasTask.tasks.arg2 + ")")
elif tasks == "reverse_return":
reverse_return(int(hasTask.tasks.arg1), str(hasTask.tasks.arg2))
writeMessage("Task > Reverse scroll")
elif tasks == "disconnect":
disconnect()
writeMessage("Task > Disconnect from server")
if tasks != "":
taskCompleted = True
else:
taskCompleted = False
except Exception as e:
writeMessage('API Error.' + str(e))
# Disconnected from game
def disconnected():
global appRunning
appRunning = False
writeMessage('Disconnected from game')
# Finished
def finished():
global appRunning
appRunning = False
writeMessage('Exit from SROMC')
# Request API
def requestApi(path, _data):
headers = {
"Content-Type": "application/json",
"Accept": "application/json",
"User-Agent": "Mozilla/5.0",
}
data = json.dumps(_data).encode("utf-8")
req = urllib.request.Request(apiEndpoint + path, data, headers)
with urllib.request.urlopen(req) as f:
res = f.read()
return res
# Connected to game
def joined_game():
global appRunning
appRunning = True
writeMessage('Connected to game')
# Write message
def writeMessage(message):
log('[' + appName + '] : ' + message)
# First load check char has account
def start():
global appRunning
if accountCreatedBefore() == True:
appRunning = True
alreadyHave()
else:
appRunning = False
# Get .db3 file for game locale
def getDBFile():
bot_path = os.getcwd()
locale = get_locale()
if locale == 56:
return bot_path + "/Data/TRSRO.db3"
# Toggle buttons on click
def toggleButtons():
if accountCreatedBefore() == True:
QtBind.move(gui, btnCreate, 10, -70)
QtBind.move(gui, btnReset, 10, 70)
else:
QtBind.move(gui, btnCreate, 10, 70)
QtBind.move(gui, btnReset, 10, -70)
QtBind.setText(gui, lblCode, '')
QtBind.setText(gui, lblPassword, '')
QtBind.setText(gui, lblCodeDesc, '')
start()
toggleButtons()
# WARNING
# If you want to edit this code, read carefully.
# There are some limits we set for storing data.
# If you make any changes above these limits, your character will be banned from the system and you will not be able to use it again.