Skip to content

Commit

Permalink
Fixed indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ulosc committed Feb 4, 2024
1 parent 93fbb32 commit 9f1ea54
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 108 deletions.
54 changes: 34 additions & 20 deletions src/gbatonds.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,24 +129,37 @@ def ivbytes(ivs, name):
def genderbyte(species, pid):
gid = ord(pid[0])
genratio = gender.get(species)
if genratio == 'Genderless': return 4
elif genratio == '0 %': return 2
if genratio == 'Genderless':
return 4
elif genratio == '0 %':
return 2
elif genratio == '12.5 %':
if gid < 223: return 2
else: return 0
if gid < 223:
return 2
else:
return 0
elif genratio == '25 %':
if gid < 191: return 2
else: return 0
if gid < 191:
return 2
else:
return 0
elif genratio == '50 %':
if gid < 127: return 2
else: return 0
if gid < 127:
return 2
else:
return 0
elif genratio == '75 %':
if gid < 63: return 2
else: return 0
if gid < 63:
return 2
else:
return 0
elif genratio == '87.5 %':
if gid < 31: return 2
else: return 0
elif genratio == '100 %': return 0
if gid < 31:
return 2
else:
return 0
elif genratio == '100 %':
return 0

def form(id, gend, pid):
if id == 201:
Expand Down Expand Up @@ -1443,8 +1456,9 @@ def attainpkm():
while True:
path = input().strip()

if path == "Back" or path == "back": return

if path == "Back" or path == "back":
return

path = os.path.normpath(path)
if system() != 'Windows':
path = path.replace('\\', '')
Expand All @@ -1453,7 +1467,8 @@ def attainpkm():
path = path[1:]
if path.endswith('"') or path.endswith("'"):
path = path[:-1]
if os.path.exists(path) and path.lower().endswith('.pkm'): break
if os.path.exists(path) and path.lower().endswith('.pkm'):
break
else:
print('Invalid file name, try again')
continue
Expand All @@ -1464,11 +1479,9 @@ def attainpkm():
return pkm

def threetofour():

pkm = attainpkm()



pkm = makends(pkm)

with open('test.pkm', 'wb') as f:
Expand All @@ -1480,6 +1493,7 @@ def fourtofive():
hl = pkm[0x80:0x82]
pid = pkm[0x00:0x04]

if hl == 30001 and ord(pkm[0x41]) == (pid % 25): return pkm
if hl == 30001 and ord(pkm[0x41]) == (pid % 25):
return pkm

#def threetofive():
15 changes: 10 additions & 5 deletions src/getpkm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
from base64 import urlsafe_b64decode, urlsafe_b64encode
from array import array
from .stats import statread
import os.path, subprocess, platform, hashlib, gtsvar
from . import gtsvar
import os.path, subprocess, platform, hashlib

def makepkm(bytes):
ar = array('B') # Byte array to hold encrypted data
Expand Down Expand Up @@ -61,10 +62,14 @@ def getpkm():
elif a == 'info':
response = '\x01\x00'
print('Connection Established.')
elif a == 'setProfile': response = '\x00' * 8
elif a == 'result': response = '\x05\x00'
elif a == 'delete': response = '\x01\x00'
elif a == 'search': response = '\x01\x00'
elif a == 'setProfile':
response = '\x00' * 8
elif a == 'result':
response = '\x05\x00'
elif a == 'delete':
response = '\x01\x00'
elif a == 'search':
response = '\x01\x00'
elif a == 'post':
response = '\x0c\x00'
print('Receiving Pokemon...')
Expand Down
22 changes: 14 additions & 8 deletions src/pkmlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,41 @@ def rand(self):
self.rngseed&=0xFFFFFFFF
return self.rngseed>>16
__call__=rand


def encode(pkm):
s=list(struct.unpack("IHH"+"H"*(len(pkm)/2-4), pkm))
shift=((s[0]>>0xD & 0x1F) %24)
order=[ord(i) for i in shiftind[4*shift:4*shift+4]]
shifted=s[:3]
for i in order: shifted+=s[3+16*i:19+16*i]
for i in order:
shifted+=s[3+16*i:19+16*i]
shifted+=s[67:]

rand=makerand(s[2])
for i in range(3, 67): shifted[i]^=rand()
for i in range(3, 67):
shifted[i]^=rand()
if len(shifted)>67:
rand=makerand(shifted[0])
for i in range(67, len(shifted)): shifted[i]^=rand()
for i in range(67, len(shifted)):
shifted[i]^=rand()
return struct.pack("IHH"+"H"*(len(pkm)/2-4), *shifted)


def decode(bin):
shifted=list(struct.unpack("IHH"+"H"*(len(bin)/2-4), bin))
rand=makerand(shifted[2])
for i in range(3, 67): shifted[i]^=rand()
for i in range(3, 67):
shifted[i]^=rand()
if len(shifted)>67:
rand=makerand(shifted[0])
for i in range(67, len(shifted)): shifted[i]^=rand()

for i in range(67, len(shifted)):
shifted[i]^=rand()

shift=((shifted[0]>>0xD & 0x1F) %24)
order=[ord(i) for i in shiftind[4*shift:4*shift+4]]
s=shifted[:3]
for i in range(4): s+=shifted[3+16*order.index(i):19+16*order.index(i)]
for i in range(4):
s+=shifted[3+16*order.index(i):19+16*order.index(i)]
s+=shifted[67:]
return struct.pack("IHH"+"H"*(len(bin)/2-4), *s)
17 changes: 10 additions & 7 deletions src/pokecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ def pcsearch():
print('(Type Back to go back)')
path = input().strip()

if path == "Back" or path == "back": return

if path == "Back" or path == "back":
return

path = os.path.normpath(path)
if system() != 'Windows':
path = path.replace('\\', '')
Expand All @@ -23,11 +24,12 @@ def pcsearch():
path = path[1:]
if path.endswith('"') or path.endswith("'"):
path = path[:-1]
if os.path.exists(path) and path.lower().endswith('.pkm'): break
if os.path.exists(path) and path.lower().endswith('.pkm'):
break
else:
print('Invalid file name, try again')
continue

with open(path, 'rb') as f:
pkm = f.read()

Expand All @@ -54,15 +56,16 @@ def pcdownload():
print('(Type Back to go back)')
pcurl = input()

if pcurl == "Back" or pcurl == "back": return

if pcurl == "Back" or pcurl == "back":
return

pcurl = '%s&export=Download+.pkm+file' % pcurl
print('\nDownloading pkm as temp.pkm, will delete after upload.')

if os.path.exists('temp.pkm'):
print('temp.pkm already exists, deleting...')
os.remove("temp.pkm")

urllib.request.urlretrieve(pcurl, "temp.pkm")
print('Download finished, onto encoding...\n')

Expand Down
40 changes: 27 additions & 13 deletions src/pokehaxlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ def __init__(self, h=None):
self.page=None
self.getvars={}
return
if not h.startswith("GET"): raise TypeError("Not a DS header!")
if not h.startswith("GET"):
raise TypeError("Not a DS header!")
request=h[h.find("/syachi2ds/web/")+15:h.find("HTTP/1.1")-1]
#request=h.split("/")[3][:h.find("HTTP")-1]
self.page=request[:request.find("?")]
self.action=request[request.find("/")+1:request.find(".asp?")]
vars=dict((i[:i.find("=")], i[i.find("=")+1:]) for i in request[request.find("?")+1:].split("&"))
self.getvars=vars

def __str__(self):
request="%s?%s"%(self.page, '&'.join("%s=%s"%i for i in list(self.getvars.items())))
return 'GET /syachi2ds/web/%s HTTP/1.1\r\n'%request+ \
'Host: gamestats2.gs.nintendowifi.net\r\nUser-Agent: GameSpyHTTP/1.0\r\n'+ \
'Connection: close\r\n\r\n'

def __repr__(self):
return "<Request for %s, with %s>"%(self.action, ", ".join(i+"="+j for i, j in list(self.getvars.items())))

Expand All @@ -32,12 +35,18 @@ def __init__(self, h):
h=h.split("\r\n")
while True:
line=h.pop(0)
if not line: break
elif line.startswith("P3P"): self.p3p=line[line.find(": ")+2:] #I don't know what this is
elif line.startswith("cluster-server"): self.server=line[line.find(": ")+2:] #for fun
elif line.startswith("X-Server-"): self.sname=line[line.find(": ")+2:] #for fun
elif line.startswith("Content-Length"): self.len=int(line[line.find(": ")+2:]) #need
elif line.startswith("Set-Cookie"): self.cookie=line[line.find(": ")+2:] #don't need
if not line:
break
elif line.startswith("P3P"):
self.p3p=line[line.find(": ")+2:] #I don't know what this is
elif line.startswith("cluster-server"):
self.server=line[line.find(": ")+2:] #for fun
elif line.startswith("X-Server-"):
self.sname=line[line.find(": ")+2:] #for fun
elif line.startswith("Content-Length"):
self.len=int(line[line.find(": ")+2:]) #need
elif line.startswith("Set-Cookie"):
self.cookie=line[line.find(": ")+2:] #don't need
self.data="\r\n".join(h)

def __str__(self):
Expand Down Expand Up @@ -79,7 +88,8 @@ def dnsspoof():
s.connect(('178.62.43.212', 53))
s.send(r[0])
rr=s.recv(512)
if "gamestats2" in rr: rr=rr[:-4]+me
if "gamestats2" in rr:
rr=rr[:-4]+me
dnsserv.sendto(rr, r[1])

serv=None
Expand All @@ -92,7 +102,8 @@ def initServ(logfile=None):
serv.bind(("0.0.0.0", 80))
serv.listen(5)

if logfile: log=open(logfile, 'w')
if logfile:
log=open(logfile, 'w')

def getReq():
global serv, log
Expand All @@ -106,14 +117,16 @@ def getReq():
except socket.timeout:
break
ans=Request(data)
if log: log.write(data+"\ndone---done\n")
if log:
log.write(data+"\ndone---done\n")
#print addr, " requested ", repr(ans)
return sock, ans

def sendResp(sock, data):
global serv, log
resp=Response(data) if not isinstance(data, Response) else data
if log: log.write(str(resp)+"\ndone---done\n")
if log:
log.write(str(resp)+"\ndone---done\n")
sock.send(str(resp))
sock.shutdown(2)
return
Expand All @@ -126,10 +139,11 @@ def respFromServ(req):
data=""
while True:
a=s.recv(500)
if not a: break
if not a:
break
data+=a
return Response(data)

def serverResp():
sock, req=getReq()
resp=respFromServ(req)
Expand Down
Loading

0 comments on commit 9f1ea54

Please sign in to comment.