code
stringlengths 26
870k
| docstring
stringlengths 1
65.6k
| func_name
stringlengths 1
194
| language
stringclasses 1
value | repo
stringlengths 8
68
| path
stringlengths 5
194
| url
stringlengths 46
254
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
def verify_recv(self, m, r, s, pk):
""" Verify a message received from pk holder. """
if r < 2 or r > self.q-2 or s < 2 or s > self.q-1:
return False
h = self.H_int(m)
u = self.inv(s, self.q)
v = (h * u) % self.q
w = (r * u) % self.q
return r == ((pow(self.g,v,self.p) * pow(pk,w,self.p)) % self.p) % self.q | Verify a message received from pk holder. | verify_recv | python | sajjadium/ctf-archives | ctfs/K3RN3L/2021/crypto/Objection/objection.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/K3RN3L/2021/crypto/Objection/objection.py | MIT |
def init():
connection.execute('''
create table approved (
id integer primary key autoincrement,
sentence text
);
''')
connection.execute('''
create table pending (
id integer primary key autoincrement,
user text,
sentence text
);
''')
connection.execute('''
create table users (
token text
);
''')
connection.execute('''
create table flags (
flag text
);
''')
initial = [
'rats live on no evil star',
'kayak',
'mr owl ate my metal worm',
'do geese see god',
'313',
'a man a plan a canal panama',
'doc note i dissent a fast never prevents a fatness i diet on cod',
'live on time emit no evil',
]
for palindrome in initial:
connection.execute('''
insert into approved (sentence) values ('%s');
''' % palindrome)
connection.execute('''
insert into flags (flag) values ('%s');
''' % os.environ.get('FLAG', 'flag is missing!')) | )
connection.execute( | init | python | sajjadium/ctf-archives | ctfs/redpwn/2022/web/oeps/app.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/redpwn/2022/web/oeps/app.py | MIT |
async def root(request):
token = request.cookies.get('token', '')
requires_cookie = (
any(c not in ALLOWED_CHARACTERS for c in token) or
len(connection.execute('''
select * from users where token = '%s';
''' % token).fetchall()) != 1
)
headers = {}
if requires_cookie:
token = ''.join(random.choice('0123456789abcdef') for _ in range(32))
headers['set-cookie'] = f'token={token}'
connection.execute('''
insert into users (token) values ('%s');
''' % token)
pending = connection.execute('''
select sentence from pending where user = '%s';
''' % token).fetchall()
return (200, '''
<title>OEPS</title>
<link rel="stylesheet" href="/style.css" />
<div class="container">
<h1>The On-Line Encyclopedia of Palidromic Sentences</h1>
Enter a word or phrase:
<form action="/search" method="GET">
<input type="text" name="search" placeholder="on" />
<input type="submit" value="Search" />
</form>
<h2>Submit Sentence:</h2>
New palindrome:
<form action="/submit" method="POST">
<input type="text" name="submission" />
<input type="submit" value="Submit" />
</form>
<div style="color: red">%s</div>
<h2>Pending submissions:</h2>
<ul>%s</ul>
</div>
''' % (
request.query.get('error', '').replace('<', '<'),
''.join(f'<li>{palindrome}</li>' for (palindrome,) in pending),
), headers) | % token).fetchall()) != 1
)
headers = {}
if requires_cookie:
token = ''.join(random.choice('0123456789abcdef') for _ in range(32))
headers['set-cookie'] = f'token={token}'
connection.execute( | root | python | sajjadium/ctf-archives | ctfs/redpwn/2022/web/oeps/app.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/redpwn/2022/web/oeps/app.py | MIT |
async def search(request):
if 'error' in request.query:
return (200, '''
<title>OEPS</title>
<link rel="stylesheet" href="/style.css" />
<div class="container">
<h1>The On-Line Encyclopedia of Palidromic Sentences</h1>
Enter a word or phrase:
<form action="/search" method="GET">
<input type="text" name="search" placeholder="on" />
<input type="submit" value="Search" />
</form>
<div style="color: red">%s</div>
<hr noshade />
</div>
''' % request.query.get('error', '').replace('<', '<'))
else:
search = request.query.get('search', '')
if search == '':
return (302, '/search?error=Search cannot be empty!')
if any(c not in ALLOWED_CHARACTERS for c in search):
return (302, '/search?error=Search must be alphanumeric!')
result = connection.execute('''
select sentence from approved where sentence like '%%%s%%';
''' % search).fetchall()
count = len(result)
return (200, '''
<title>OEPS</title>
<link rel="stylesheet" href="/style.css" />
<div class="container">
<h1>The On-Line Encyclopedia of Palidromic Sentences</h1>
Enter a word or phrase:
<form action="/search" method="GET">
<input type="text" name="search" placeholder="on" />
<input type="submit" value="Search" />
</form>
<hr noshade />
<h2>%s</h2>
<ul>%s</ul>
</div>
''' % (
'No results.' if count == 0 else f'Results ({count}):',
''.join(f'<li>{palindrome}</li>' for (palindrome,) in result),
)) | % request.query.get('error', '').replace('<', '<'))
else:
search = request.query.get('search', '')
if search == '':
return (302, '/search?error=Search cannot be empty!')
if any(c not in ALLOWED_CHARACTERS for c in search):
return (302, '/search?error=Search must be alphanumeric!')
result = connection.execute( | search | python | sajjadium/ctf-archives | ctfs/redpwn/2022/web/oeps/app.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/redpwn/2022/web/oeps/app.py | MIT |
async def submit(request):
token = request.cookies.get('token', '')
logged_in = (
all(c in ALLOWED_CHARACTERS for c in token) and
len(connection.execute('''
select * from users where token = '%s';
''' % token).fetchall()) == 1
)
if not logged_in:
return (302, '/?error=Authentication error.')
data = await request.post()
submission = data.get('submission', '')
if submission == '':
return (302, '/?error=Submission cannot be empty.')
stripped = submission.replace(' ', '')
if stripped != stripped[::-1]:
return (302, '/?error=Submission must be a palindrome.')
connection.execute('''
insert into pending (user, sentence) values ('%s', '%s');
''' % (
token,
submission
))
return (302, '/') | % token).fetchall()) == 1
)
if not logged_in:
return (302, '/?error=Authentication error.')
data = await request.post()
submission = data.get('submission', '')
if submission == '':
return (302, '/?error=Submission cannot be empty.')
stripped = submission.replace(' ', '')
if stripped != stripped[::-1]:
return (302, '/?error=Submission must be a palindrome.')
connection.execute( | submit | python | sajjadium/ctf-archives | ctfs/redpwn/2022/web/oeps/app.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/redpwn/2022/web/oeps/app.py | MIT |
async def root(request):
admin = request.cookies.get('admin', '')
headers = {}
if admin == '':
headers['set-cookie'] = 'admin=false'
if admin == 'true':
return (200, '''
<title>Secure Page</title>
<link rel="stylesheet" href="/style.css" />
<div class="container">
<h1>Secure Page</h1>
%s
</div>
''' % os.environ.get('FLAG', 'flag is missing!'), headers)
else:
return (200, '''
<title>Secure Page</title>
<link rel="stylesheet" href="/style.css" />
<div class="container">
<h1>Secure Page</h1>
Sorry, you must be the admin to view this content!
</div>
''', headers) | % os.environ.get('FLAG', 'flag is missing!'), headers)
else:
return (200, | root | python | sajjadium/ctf-archives | ctfs/redpwn/2022/web/secure-page/app.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/redpwn/2022/web/secure-page/app.py | MIT |
def init():
# this is terrible but who cares
execute('''
CREATE TABLE IF NOT EXISTS users (
username TEXT PRIMARY KEY,
password TEXT
);
''')
execute('DROP TABLE users;')
execute('''
CREATE TABLE users (
username TEXT PRIMARY KEY,
password TEXT
);
''')
# we also need a table for pastes
execute('''
CREATE TABLE IF NOT EXISTS pastes (
id TEXT PRIMARY KEY,
paste TEXT,
username TEXT
);
''')
execute('DROP TABLE pastes;')
execute('''
CREATE TABLE pastes (
id TEXT PRIMARY KEY,
paste TEXT,
username TEXT
);
''')
# put admin into db
admin_password = secrets.token_hex(32)
execute(
'INSERT OR IGNORE INTO users (username, password) VALUES (?, ?);',
params=('admin', admin_password)
)
execute(
'UPDATE users SET password = ? WHERE username = ?;',
params=(admin_password, 'admin')
)
create_paste(os.getenv('FLAG'), 'admin') | )
execute('DROP TABLE users;')
execute( | init | python | sajjadium/ctf-archives | ctfs/redpwn/2021/web/pastebin-3/app/app.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/redpwn/2021/web/pastebin-3/app/app.py | MIT |
def init():
# this is terrible but who cares
execute('''
CREATE TABLE IF NOT EXISTS users (
username TEXT PRIMARY KEY,
password TEXT
);
''')
execute('DROP TABLE users;')
execute('''
CREATE TABLE users (
username TEXT PRIMARY KEY,
password TEXT
);
''')
# put ginkoid into db
ginkoid_password = generate_token()
execute(
'INSERT OR IGNORE INTO users (username, password)'
f'VALUES (\'ginkoid\', \'{ginkoid_password}\');'
)
execute(
f'UPDATE users SET password=\'{ginkoid_password}\''
f'WHERE username=\'ginkoid\';'
) | )
execute('DROP TABLE users;')
execute( | init | python | sajjadium/ctf-archives | ctfs/redpwn/2021/web/cool/app.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/redpwn/2021/web/cool/app.py | MIT |
def interpret(bcode = [], inp = [], storage = []):
PC = 4
LR = 5
INPLEN = 11
CALLER = 12
FLAG = 13
SP = 14
BP = 15
def translateAddr(addr):
idx = addr>>32
offset = addr&0xffffffff
if idx > 4 or offset > 0x1000:
print(f'invalid addr : {hex(addr)}')
exit()
return idx, offset
def getMem(mem, addr, size):
idx, offset = translateAddr(addr)
if offset + size > 0x1000:
print(f'invalid mem get : {hex(addr)} {hex(size)}')
return int.from_bytes(mem[idx][offset : offset + size],'little')
def setMem(mem, addr, size, val):
idx, offset = translateAddr(addr)
if offset + size > 0x1000:
print(f'invalid mem set : {hex(addr)} {hex(size)}')
val = val & ((1 << (size * 8)) - 1)
v = int.to_bytes(val, size, 'little')
for i in range(size):
mem[idx][offset + i] = v[i]
if type(bcode) == bytes:
bcode = list(bcode)
if type(inp) == bytes:
inp = list(inp)
if type(storage) == bytes:
storage = list(storage)
regs = [0 for i in range(0x10)]
regs[PC] = 0x200000000 #pc
regs[LR] = 0xffffffffffffffff #lr
regs[FLAG] = 0 #flag
regs[SP] = 0x300001000 #sp
regs[BP] = 0x300001000 #bp
mem = [inp + [0 for i in range(0x1000 - len(inp))],
storage + [0 for i in range(0x1000 - len(storage))],
bcode + [0 for i in range(0x1000 - len(bcode))],
[0 for i in range(0x1000)],
[0 for i in range(0x1000)]]
while True:
opcode = getMem(mem, regs[PC], 1)
if (opcode & 0xf0) == 0 and (opcode & 0x8) == 0x8:
size = (opcode & 0x7) + 1
v = getMem(mem, regs[PC] + 1, size)
regs[PC] += 1 + size
regs[SP] -= size
setMem(mem, regs[SP], size, v)
elif (opcode & 0xf0) == 0x10:
size = (opcode & 0x7) + 1
r = getMem(mem, regs[PC] + 1, 1) & 0xf
regs[PC] += 2
if r in (PC, LR):
print(f'invalid opcode at {hex(regs[PC])}')
return mem, regs
if (opcode & 0x8) == 0:
regs[r] = getMem(mem, regs[SP], size)
regs[SP] += size
else:
regs[SP] -= size
setMem(mem, regs[SP], size, regs[r])
elif (opcode & 0xf0) == 0x20:
size = (opcode & 0x7) + 1
r = getMem(mem, regs[PC] + 1, 1)
regs[PC] += 2
r1 = r & 0xf
r2 = r >> 4
if r1 in (PC, LR) or r2 in (PC, LR):
print(f'invalid opcode at {hex(regs[PC])}')
return mem, regs
if (opcode & 0x8) == 0:
regs[r1] = getMem(mem, regs[r2], size)
else:
setMem(mem, regs[r1], size, regs[r2])
elif (opcode & 0xf0) == 0x30:
size = (opcode & 0x7) + 1
r = getMem(mem, regs[PC] + 1, 1) & 0xf
v = getMem(mem, regs[PC] + 2, size)
regs[PC] += 2 + size
if r in (PC, LR):
print(f'invalid opcode at {hex(regs[PC])}')
return mem, regs
if (opcode & 0x8) == 0:
regs[r] = v
else:
setMem(mem, regs[r], size, v)
elif (opcode & 0xf0) == 0x40:
if (opcode & 0x8) == 0x8:
'''
r = getMem(mem, regs[PC] + 1, 1) & 0xf
regs[PC] += 2
dst = regs[r]
'''
print(f'invalid opcode at {hex(regs[PC])}')
return mem, regs
else:
dst = getMem(mem, regs[PC] + 1, 2)
if dst >= 0x8000:
dst -= 0x10000
regs[PC] += 3
dst += regs[PC]
if (opcode & 0xf) == 0:
regs[PC] = dst
elif (opcode & 0xf) == 1:
regs[SP] -= 6
setMem(mem, regs[SP], 6, regs[LR]) #push lr
regs[SP] -= 6
setMem(mem, regs[SP], 6, regs[BP]) #push bp
regs[BP] = regs[SP]
regs[LR] = regs[PC]
regs[PC] = dst
elif (opcode & 0xf) == 2 and (regs[FLAG] & 4) == 4:
regs[PC] = dst
elif (opcode & 0xf) == 3 and (regs[FLAG] & 3) != 0:
regs[PC] = dst
elif (opcode & 0xf) == 4 and (regs[FLAG] & 1) == 1:
regs[PC] = dst
elif (opcode & 0xf) == 5 and (regs[FLAG] & 1) == 0:
regs[PC] = dst
elif (opcode & 0xf) == 6 and (regs[FLAG] & 5) != 0:
regs[PC] = dst
elif (opcode & 0xf) == 7 and (regs[FLAG] & 2) == 2:
regs[PC] = dst
elif (opcode & 0xf0) == 0x50 and (opcode & 0xf) <= 0xa:
r = getMem(mem, regs[PC] + 1, 1)
regs[PC] += 2
r1 = r & 0xf
r2 = r >> 4
if r1 in (PC, LR) or r2 in (PC, LR):
print(f'invalid opcode at {hex(regs[PC])}')
return mem, regs
if (opcode & 0xf) == 0:
regs[r1] = (regs[r1] - regs[r2]) & 0xffffffffffffffff
if regs[r1] < 0:
regs[r1] += 0x10000000000000000
elif (opcode & 0xf) == 1:
regs[r1] = (regs[r1] + regs[r2]) & 0xffffffffffffffff
elif (opcode & 0xf) == 2:
regs[r1] = (regs[r1] * regs[r2]) & 0xffffffffffffffff
elif (opcode & 0xf) == 3:
regs[r1] = (regs[r1] // regs[r2]) & 0xffffffffffffffff
elif (opcode & 0xf) == 4:
regs[r1] = (regs[r1] & regs[r2]) & 0xffffffffffffffff
elif (opcode & 0xf) == 5:
regs[r1] = (regs[r1] | regs[r2]) & 0xffffffffffffffff
elif (opcode & 0xf) == 6:
regs[r1] = (regs[r1] ^ regs[r2]) & 0xffffffffffffffff
elif (opcode & 0xf) == 7:
regs[r1] = (regs[r1] >> (regs[r2] & 0x3f)) & 0xffffffffffffffff
elif (opcode & 0xf) == 8:
regs[r1] = (regs[r1] << (regs[r2] & 0x3f)) & 0xffffffffffffffff
elif (opcode & 0xf) == 9:
regs[r1] = regs[r2]
elif (opcode & 0xf) == 10:
flag = 0
if regs[r1] == regs[r2]:
flag |= 1
if regs[r1] > regs[r2]:
flag |= 2
if regs[r1] < regs[r2]:
flag |= 4
regs[FLAG] = flag
elif (opcode & 0xf0) == 0xf0 and (opcode & 0xf) >= 0xd:
if opcode == 0xfd:
regs[SP] = regs[BP]
regs[BP] = getMem(mem, regs[SP], 6)
regs[SP] += 6
regs[PC] = regs[LR]
regs[LR] = getMem(mem, regs[SP], 6)
regs[SP] += 6
elif opcode == 0xfe:
regs[PC] += 1
input('invoke')
elif opcode == 0xff:
regs[PC] += 1
return mem, regs
else:
print(f'invalid opcode at {hex(regs[PC])}')
return mem, regs | r = getMem(mem, regs[PC] + 1, 1) & 0xf
regs[PC] += 2
dst = regs[r] | interpret | python | sajjadium/ctf-archives | ctfs/Balsn/2023/pwn/ASTRAL_StarryNight/sourcecode/APPLET/interpreter.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/Balsn/2023/pwn/ASTRAL_StarryNight/sourcecode/APPLET/interpreter.py | MIT |
def aasm(code):
def check(condition):
if not condition:
print(f'invalid argument on line {lnum + 1} : {origLine}')
exit()
def getReg(rs):
if rs == 'pc':
return 4
elif rs == 'lr':
return 5
elif rs == 'inplen':
return 11
elif rs == 'caller':
return 12
elif rs == 'flag':
return 13
elif rs == 'sp':
return 14
elif rs == 'bp':
return 15
check(rs[0] == 'r')
try:
reg = int(rs[1:])
except:
check(False)
check(reg >= 0 and reg < 16)
return reg
def getNum(n, size, unsigned = False, dontCareSign = False):
if n[0] == '-':
sign = -1
n = n[1:]
else:
sign = 1
if len(n) > 2 and n[:2] == '0x':
base = 16
else:
base = 10
try:
n = int(n, base)
except:
check(False)
n *= sign
if dontCareSign:
Min = -(1 << size) // 2
Max = (1 << size) - 1
else:
if unsigned is False:
Min = -(1 << size) // 2
Max = (1 << size) // 2 - 1
else:
Min = 0
Max = (1 << size) - 1
check(n >= Min and n <= Max)
if n < 0:
n += (1 << size)
return n
JMP = {
'call': 0x40,
'jmp' : 0x41,
'jb' : 0x42,
'jae' : 0x43,
'je' : 0x44,
'jne' : 0x45,
'jbe' : 0x46,
'ja' : 0x47,
}
ALU = {
'add' : 0x50,
'sub' : 0x51,
'mul' : 0x52,
'div' : 0x53,
'and' : 0x54,
'or' : 0x55,
'xor' : 0x56,
'shr' : 0x57,
'shl' : 0x58,
'mov' : 0x59,
'cmp' : 0x5a,
}
JMPDST = {}
RESOLVE = {}
code = code.strip().split('\n')
bcode = b''
for lnum, line in enumerate(code):
origLine = line
comment = line.find('//')
if comment != -1:
line = line[:comment]
line = line.strip()
if line=='':
continue
#print(line)
line = line.split()
if line[0] == 'push':
check(len(line) == 2 or len(line) == 3)
if len(line) == 2:
#shorthand to not specify push imm size
n = getNum(line[1], 64, dontCareSign = True)
if n == 0:
S = 1
else:
S = (n.bit_length() + 7) // 8
bcode += p8(0x08 | (S - 1)) + int.to_bytes(n, S, 'little')
else:
check(len(line[1]) > 2 and line[1][0] == '<' and line[1][-1] == '>')
S = getNum(line[1][1:-1], 4, unsigned = True)
check(1 <= S and S <= 8)
if line[2][0].isdigit():
n = getNum(line[2], S * 8, dontCareSign = True)
bcode += p8(0x08 | (S - 1)) + int.to_bytes(n, S, 'little')
else:
r0 = getReg(line[2])
bcode += p8(0x18 | (S - 1)) + p8(r0)
elif line[0] == 'pop':
check(len(line) == 3)
check(len(line[1]) > 2 and line[1][0] == '<' and line[1][-1] == '>')
S = getNum(line[1][1:-1], 4, unsigned = True)
check(1 <= S and S <=8)
r0 = getReg(line[2])
bcode += p8(0x10 | (S - 1)) + p8(r0)
elif line[0] == 'load':
line = ' '.join(line[1:]).split(',')
check(len(line) == 2)
hasSize = line[0][0] == '<'
if not hasSize:
#shorthand to not specify load imm size
r0 = getReg(line[0].strip())
n = getNum(line[1].strip(), 64, dontCareSign = True)
if n == 0:
S = 1
else:
S = (n.bit_length() + 7) // 8
bcode += p8(0x30 | (S - 1)) + p8(r0) + int.to_bytes(n, S, 'little')
else:
S, r0 = line[0].strip().split()
check(len(S) > 2 and S[0] == '<' and S[-1] == '>')
S = getNum(S[1:-1], 4, unsigned = True)
check(1 <= S and S <= 8)
r0 = getReg(r0)
line[1] = line[1].strip()
if line[1][0] != '[':
n = getNum(line[1], S * 8, dontCareSign = True)
bcode += p8(0x30 | (S - 1)) + p8(r0) + int.to_bytes(n, S, 'little')
else:
check(line[1][0] == '[' and line[1][-1] == ']')
r1 = getReg(line[1][1:-1])
bcode += p8(0x20 | (S - 1)) + p8(r0 | (r1 << 4))
elif line[0] == 'store':
line = ' '.join(line[1:]).split(',')
check(len(line) == 2)
hasSize = line[0][0] == '<'
if not hasSize:
#shorthand to not specify store imm size
line[0] = line[0].strip()
check(line[0][0] == '[' and line[0][-1] == ']')
r0 = getReg(line[0][1:-1])
n = getNum(line[1].strip(), 64, dontCareSign = True)
if n == 0:
S = 1
else:
S = (n.bit_length() + 7) // 8
bcode += p8(0x38 | (S - 1)) + p8(r0) + int.to_bytes(n, S, 'little')
else:
S = line[0].strip().split()[0]
dst = line[0][len(S):].strip()
check(len(S) > 2 and S[0] == '<' and S[-1] == '>')
S = getNum(S[1:-1], 4, unsigned = True)
check(1 <= S and S <= 8)
dst = dst.strip()
check(dst[0] == '[' and dst[-1] == ']')
dst = dst[1:-1]
line[1] = line[1].strip()
if line[1][0] != 'r':
r0 = getReg(dst)
n = getNum(line[1], S * 8, dontCareSign = True)
bcode += p8(0x38 | (S - 1)) + p8(r0) + int.to_bytes(n, S, 'little')
else:
r0 = getReg(dst)
r1 = getReg(line[1])
bcode += p8(0x28 | (S - 1)) + p8(r0 | (r1 << 4))
elif line[0] in JMP:
check(len(line) == 2)
if line[1][0].isdigit() or line[1] not in ('r0','r1','r2','r3','r4','r5','r6','r7','r8','r9','r10','r11','r12','r13','r14','r15','pc','lr','inplen','caller','flag','sp','bp'):
if line[1][0].isdigit():
#Theoretically, we shouldn't do this, jumping to static offset is error prone, but allow for flexibility
n = getNum(line[1], 16)
bcode += p8(JMP[line[0]]) + p16(n)
else:
tag = line[1]
offset = len(bcode) + 3
if tag in JMPDST:
#This is a backward jump, so delta must be negative
delta = JMPDST[tag] - offset + (1 << 16)
bcode += p8(JMP[line[0]]) + p16(delta)
else:
RESOLVE[offset] = (tag, lnum, origLine)
bcode += p8(JMP[line[0]]) + p16(0)
else:
check(False)
'''
else:
r0 = getReg(line[1])
bcode += p8(JMP[line[0]] | 0x08) + p8(r0)
'''
elif line[0] in ALU:
opc = line[0]
line = ' '.join(line[1:]).strip().split(',')
check(len(line) == 2)
r0, r1 = getReg(line[0].strip()), getReg(line[1].strip())
bcode += p8(ALU[opc]) + p8(r0 | (r1 << 4))
elif line[0] == 'return':
check(len(line) == 1)
bcode += b'\xfd'
elif line[0] == 'invoke':
check(len(line) == 1)
bcode += b'\xfe'
elif line[0] == 'exit':
check(len(line) == 1)
bcode += b'\xff'
else:
check(len(line) == 1 and len(line[0]) > 1)
check(line[0][-1] == ':')
check(not line[0][0].isdigit())
tag = line[0][:-1]
check(tag not in JMPDST)
JMPDST[tag] = len(bcode)
for offset in RESOLVE:
tag, lnum, origLine = RESOLVE[offset]
if tag not in JMPDST:
print(f'unknown tag on line {lnum} : {origLine}')
exit()
delta = JMPDST[tag] - offset
bcode = bcode[:offset-2] + p16(delta) + bcode[offset:]
return bcode | else:
r0 = getReg(line[1])
bcode += p8(JMP[line[0]] | 0x08) + p8(r0) | aasm | python | sajjadium/ctf-archives | ctfs/Balsn/2023/pwn/ASTRAL_StarryNight/sourcecode/APPLET/assembler.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/Balsn/2023/pwn/ASTRAL_StarryNight/sourcecode/APPLET/assembler.py | MIT |
def myInput(prompt):
'''
python input prompts to stderr by default, and there is no option to change this afaik
this wrapper is just normal input with stdout prompt
'''
print(prompt,end='')
return input() | python input prompts to stderr by default, and there is no option to change this afaik
this wrapper is just normal input with stdout prompt | myInput | python | sajjadium/ctf-archives | ctfs/Balsn/2022/pwn/sentinel/share/instanceManager.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/Balsn/2022/pwn/sentinel/share/instanceManager.py | MIT |
def populateInstanceConfig(instanceId,instancePath,instanceConfigPath,guestHomeDir):
Dockerfile = f'''
from ubuntu:jammy
RUN useradd -m sentinel
USER sentinel
WORKDIR /home/sentinel/
ENTRYPOINT ["./sentinel"]
'''
dockerCompose = f'''
version: '3'
volumes:
storage{instanceId}:
driver: local
driver_opts:
type: overlay
o: lowerdir={guestHomeDir},upperdir={os.path.join(instancePath,'upper')},workdir={os.path.join(instancePath,'work')}
device: overlay
services:
sentinel{instanceId}:
build: ./
volumes:
- storage{instanceId}:/home/sentinel/
stdin_open : true
'''
with open(os.path.join(instanceConfigPath,'Dockerfile'),'w') as f:
f.write(Dockerfile)
with open(os.path.join(instanceConfigPath,'docker-compose.yml'),'w') as f:
f.write(dockerCompose) | dockerCompose = f | populateInstanceConfig | python | sajjadium/ctf-archives | ctfs/Balsn/2022/pwn/sentinel/share/instanceManager.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/Balsn/2022/pwn/sentinel/share/instanceManager.py | MIT |
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'secretstore.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv) | Run administrative tasks. | main | python | sajjadium/ctf-archives | ctfs/RACTF/2021/web/Secret_Store/src/manage.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/RACTF/2021/web/Secret_Store/src/manage.py | MIT |
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'notebook.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv) | Run administrative tasks. | main | python | sajjadium/ctf-archives | ctfs/RACTF/2021/web/Emojibook/manage.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/RACTF/2021/web/Emojibook/manage.py | MIT |
def gen_sbox():
"""
SBOX is generated in a similar way as AES, i.e., linear transform over the multiplicative inverse (L * x^-1 + C),
to prevent differential fault analysis.
"""
INV = [0, 1, 142, 244, 71, 167, 122, 186, 173, 157, 221, 152, 61, 170, 93, 150, 216, 114, 192, 88, 224, 62, 76, 102, 144, 222, 85, 128, 160, 131, 75, 42, 108, 237, 57, 81, 96, 86, 44, 138, 112, 208, 31, 74, 38, 139, 51, 110, 72, 137, 111, 46, 164, 195, 64, 94, 80, 34, 207, 169, 171, 12, 21, 225, 54, 95, 248, 213, 146, 78, 166, 4, 48, 136, 43, 30, 22, 103, 69, 147, 56, 35, 104, 140, 129, 26, 37, 97, 19, 193, 203, 99, 151, 14, 55, 65, 36, 87, 202, 91, 185, 196, 23, 77, 82, 141, 239, 179, 32, 236, 47, 50, 40, 209, 17, 217, 233, 251, 218, 121, 219, 119, 6, 187, 132, 205, 254, 252, 27, 84, 161, 29, 124, 204, 228, 176, 73, 49, 39, 45, 83, 105, 2, 245, 24, 223, 68, 79, 155, 188, 15, 92, 11, 220, 189, 148, 172, 9, 199, 162, 28, 130, 159, 198, 52, 194, 70, 5, 206, 59, 13, 60, 156, 8, 190, 183, 135, 229, 238, 107, 235, 242, 191, 175, 197, 100, 7, 123, 149, 154, 174, 182, 18, 89, 165, 53, 101, 184, 163, 158, 210, 247, 98, 90, 133, 125, 168, 58, 41, 113, 200, 246, 249, 67, 215, 214, 16, 115, 118, 120, 153, 10, 25, 145, 20, 63, 230, 240, 134, 177, 226, 241, 250, 116, 243, 180, 109, 33, 178, 106, 227, 231, 181, 234, 3, 143, 211, 201, 66, 212, 232, 117, 127, 255, 126, 253]
L = [[0, 0, 1, 1, 0, 1, 0, 1],
[0, 1, 1, 0, 1, 0, 1, 0],
[1, 1, 0, 1, 0, 1, 0, 0],
[1, 0, 1, 0, 1, 0, 0, 0],
[0, 1, 1, 0, 0, 1, 0, 0],
[1, 1, 1, 1, 1, 1, 0, 0],
[1, 1, 0, 0, 1, 1, 0, 1],
[1, 0, 0, 1, 1, 0, 1, 0]]
C = [1, 0, 1, 1, 1, 0, 1, 0]
S = []
for _ in range(256):
inv = bin(INV[_])[2:].rjust(8, '0')[::-1]
v = [sum([a * int(b) for (a, b) in zip(L[__], inv)] + [C[__]]) % 2 for __ in range(8)]
S.append(sum([v[__] * 2**(7 - __) for __ in range(8)]))
return S | SBOX is generated in a similar way as AES, i.e., linear transform over the multiplicative inverse (L * x^-1 + C),
to prevent differential fault analysis. | gen_sbox | python | sajjadium/ctf-archives | ctfs/0CTF/2022/crypto/leopard/cipher.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/0CTF/2022/crypto/leopard/cipher.py | MIT |
def main():
mcu: MCU = None
while True:
print(
textwrap.dedent(
"""
Main menu:
1. Create new MCU.
2. Flash segment.
3. Dump segment.
4. Run MCU.
5. Exit.
"""
)
)
choice = input("Choice: ")
if choice == "1":
mcu = MCU()
flash_demo_image(mcu)
elif choice == "2":
if mcu is None:
raise Exception("No MCU found.")
segment = int(input("Segment: "))
image = bytes.fromhex(input("Image: "))
signature = bytes.fromhex(input("Signature: "))
mcu.flash(segment, image, signature)
elif choice == "3":
if mcu is None:
raise Exception("No MCU found.")
segment = int(input("Segment: "))
print("Content: ")
hexdump(mcu.dump(segment))
elif choice == "4":
if mcu is None:
raise Exception("No MCU found.")
try:
mcu.run()
except Exception as e:
print("The MCU crashed with error:", e)
break
elif choice == "5":
break | Main menu:
1. Create new MCU.
2. Flash segment.
3. Dump segment.
4. Run MCU.
5. Exit. | main | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/crypto/FusEd/main.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/crypto/FusEd/main.py | MIT |
def zoom(self, value: float) -> None:
"""Here we set zoom, clamp value to minimum of min_zoom and max of max_zoom."""
self._zoom = max(min(value, self.max_zoom), self.min_zoom) | Here we set zoom, clamp value to minimum of min_zoom and max of max_zoom. | zoom | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Dig_It_Up/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Dig_It_Up/src/client/client/game/camera.py | MIT |
def position(self) -> Tuple[float, float]:
"""Query the current offset."""
return self.offset_x, self.offset_y | Query the current offset. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Dig_It_Up/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Dig_It_Up/src/client/client/game/camera.py | MIT |
def position(self, value: Tuple[float, float]) -> None:
"""Set the scroll offset directly."""
# Check for borders
self.offset_x, self.offset_y = value | Set the scroll offset directly. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Dig_It_Up/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Dig_It_Up/src/client/client/game/camera.py | MIT |
def move(self, axis_x: float, axis_y: float) -> None:
"""Move axis direction with scroll_speed.
Example: Move left -> move(-1, 0)
"""
self.offset_x += self.scroll_speed * axis_x
self.offset_y += self.scroll_speed * axis_y | Move axis direction with scroll_speed.
Example: Move left -> move(-1, 0) | move | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Dig_It_Up/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Dig_It_Up/src/client/client/game/camera.py | MIT |
def position(self):
"""Query the current offset."""
return self.offset_x, self.offset_y | Query the current offset. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Dig_It_Up/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Dig_It_Up/src/client/client/game/camera.py | MIT |
def position(self, value: Tuple[float, float]):
"""Set the scroll offset directly."""
# Check for borders
# Check right border
x, y = value
x_screen = x - self.window.width // 2
y_screen = y - self.window.height // 2
if self.max_scroll_x:
x_screen = min(max(0, x_screen), self.max_scroll_x - self.window.width)
if self.max_scroll_y:
y_screen = min(
max(-self.window.height // 2 + 32 * 2, y_screen), self.window.height
) # No idea why we need to 32*2. Was estimated by printing values
self.offset_x = x_screen + self.window.width // 2
self.offset_y = y_screen + self.window.height // 2 | Set the scroll offset directly. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Dig_It_Up/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Dig_It_Up/src/client/client/game/camera.py | MIT |
def draw(self):
"""Draw the sprite at its current position.
See the module documentation for hints on drawing multiple sprites
efficiently.
"""
if not self._group:
return
self._group.set_state_recursive()
if self.program:
self.program["origin_scale"] = (self.origin_scale[0], self.origin_scale[1])
self.program["origin_rotation"] = (
self.origin_rotation[0],
self.origin_rotation[1],
)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
if self._vertex_list:
self._vertex_list.draw(GL_TRIANGLES)
self._group.unset_state_recursive() | Draw the sprite at its current position.
See the module documentation for hints on drawing multiple sprites
efficiently. | draw | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Dig_It_Up/src/client/client/game/nearest_sprite.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Dig_It_Up/src/client/client/game/nearest_sprite.py | MIT |
def zoom(self, value: float) -> None:
"""Here we set zoom, clamp value to minimum of min_zoom and max of max_zoom."""
self._zoom = max(min(value, self.max_zoom), self.min_zoom) | Here we set zoom, clamp value to minimum of min_zoom and max of max_zoom. | zoom | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Unreachable/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Unreachable/src/client/client/game/camera.py | MIT |
def position(self) -> Tuple[float, float]:
"""Query the current offset."""
return self.offset_x, self.offset_y | Query the current offset. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Unreachable/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Unreachable/src/client/client/game/camera.py | MIT |
def position(self, value: Tuple[float, float]) -> None:
"""Set the scroll offset directly."""
# Check for borders
self.offset_x, self.offset_y = value | Set the scroll offset directly. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Unreachable/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Unreachable/src/client/client/game/camera.py | MIT |
def move(self, axis_x: float, axis_y: float) -> None:
"""Move axis direction with scroll_speed.
Example: Move left -> move(-1, 0)
"""
self.offset_x += self.scroll_speed * axis_x
self.offset_y += self.scroll_speed * axis_y | Move axis direction with scroll_speed.
Example: Move left -> move(-1, 0) | move | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Unreachable/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Unreachable/src/client/client/game/camera.py | MIT |
def position(self):
"""Query the current offset."""
return self.offset_x, self.offset_y | Query the current offset. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Unreachable/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Unreachable/src/client/client/game/camera.py | MIT |
def position(self, value: Tuple[float, float]):
"""Set the scroll offset directly."""
# Check for borders
# Check right border
x, y = value
x_screen = x - self.window.width // 2
y_screen = y - self.window.height // 2
if self.max_scroll_x:
x_screen = min(max(0, x_screen), self.max_scroll_x - self.window.width)
if self.max_scroll_y:
y_screen = min(
max(-self.window.height // 2 + 32 * 2, y_screen), self.window.height
) # No idea why we need to 32*2. Was estimated by printing values
self.offset_x = x_screen + self.window.width // 2
self.offset_y = y_screen + self.window.height // 2 | Set the scroll offset directly. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Unreachable/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Unreachable/src/client/client/game/camera.py | MIT |
def draw(self):
"""Draw the sprite at its current position.
See the module documentation for hints on drawing multiple sprites
efficiently.
"""
if not self._group:
return
self._group.set_state_recursive()
if self.program:
self.program["origin_scale"] = (self.origin_scale[0], self.origin_scale[1])
self.program["origin_rotation"] = (
self.origin_rotation[0],
self.origin_rotation[1],
)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
if self._vertex_list:
self._vertex_list.draw(GL_TRIANGLES)
self._group.unset_state_recursive() | Draw the sprite at its current position.
See the module documentation for hints on drawing multiple sprites
efficiently. | draw | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Unreachable/src/client/client/game/nearest_sprite.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Unreachable/src/client/client/game/nearest_sprite.py | MIT |
def zoom(self, value: float) -> None:
"""Here we set zoom, clamp value to minimum of min_zoom and max of max_zoom."""
self._zoom = max(min(value, self.max_zoom), self.min_zoom) | Here we set zoom, clamp value to minimum of min_zoom and max of max_zoom. | zoom | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Merchant/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Merchant/src/client/client/game/camera.py | MIT |
def position(self) -> Tuple[float, float]:
"""Query the current offset."""
return self.offset_x, self.offset_y | Query the current offset. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Merchant/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Merchant/src/client/client/game/camera.py | MIT |
def position(self, value: Tuple[float, float]) -> None:
"""Set the scroll offset directly."""
# Check for borders
self.offset_x, self.offset_y = value | Set the scroll offset directly. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Merchant/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Merchant/src/client/client/game/camera.py | MIT |
def move(self, axis_x: float, axis_y: float) -> None:
"""Move axis direction with scroll_speed.
Example: Move left -> move(-1, 0)
"""
self.offset_x += self.scroll_speed * axis_x
self.offset_y += self.scroll_speed * axis_y | Move axis direction with scroll_speed.
Example: Move left -> move(-1, 0) | move | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Merchant/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Merchant/src/client/client/game/camera.py | MIT |
def position(self):
"""Query the current offset."""
return self.offset_x, self.offset_y | Query the current offset. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Merchant/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Merchant/src/client/client/game/camera.py | MIT |
def position(self, value: Tuple[float, float]):
"""Set the scroll offset directly."""
# Check for borders
# Check right border
x, y = value
x_screen = x - self.window.width // 2
y_screen = y - self.window.height // 2
if self.max_scroll_x:
x_screen = min(max(0, x_screen), self.max_scroll_x - self.window.width)
if self.max_scroll_y:
y_screen = min(
max(-self.window.height // 2 + 32 * 2, y_screen), self.window.height
) # No idea why we need to 32*2. Was estimated by printing values
self.offset_x = x_screen + self.window.width // 2
self.offset_y = y_screen + self.window.height // 2 | Set the scroll offset directly. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Merchant/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Merchant/src/client/client/game/camera.py | MIT |
def draw(self):
"""Draw the sprite at its current position.
See the module documentation for hints on drawing multiple sprites
efficiently.
"""
if not self._group:
return
self._group.set_state_recursive()
if self.program:
self.program["origin_scale"] = (self.origin_scale[0], self.origin_scale[1])
self.program["origin_rotation"] = (
self.origin_rotation[0],
self.origin_rotation[1],
)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
if self._vertex_list:
self._vertex_list.draw(GL_TRIANGLES)
self._group.unset_state_recursive() | Draw the sprite at its current position.
See the module documentation for hints on drawing multiple sprites
efficiently. | draw | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Merchant/src/client/client/game/nearest_sprite.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Merchant/src/client/client/game/nearest_sprite.py | MIT |
def zoom(self, value: float) -> None:
"""Here we set zoom, clamp value to minimum of min_zoom and max of max_zoom."""
self._zoom = max(min(value, self.max_zoom), self.min_zoom) | Here we set zoom, clamp value to minimum of min_zoom and max of max_zoom. | zoom | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Desert_Dino_Dialogue/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Desert_Dino_Dialogue/src/client/client/game/camera.py | MIT |
def position(self) -> Tuple[float, float]:
"""Query the current offset."""
return self.offset_x, self.offset_y | Query the current offset. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Desert_Dino_Dialogue/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Desert_Dino_Dialogue/src/client/client/game/camera.py | MIT |
def position(self, value: Tuple[float, float]) -> None:
"""Set the scroll offset directly."""
# Check for borders
self.offset_x, self.offset_y = value | Set the scroll offset directly. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Desert_Dino_Dialogue/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Desert_Dino_Dialogue/src/client/client/game/camera.py | MIT |
def move(self, axis_x: float, axis_y: float) -> None:
"""Move axis direction with scroll_speed.
Example: Move left -> move(-1, 0)
"""
self.offset_x += self.scroll_speed * axis_x
self.offset_y += self.scroll_speed * axis_y | Move axis direction with scroll_speed.
Example: Move left -> move(-1, 0) | move | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Desert_Dino_Dialogue/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Desert_Dino_Dialogue/src/client/client/game/camera.py | MIT |
def position(self):
"""Query the current offset."""
return self.offset_x, self.offset_y | Query the current offset. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Desert_Dino_Dialogue/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Desert_Dino_Dialogue/src/client/client/game/camera.py | MIT |
def position(self, value: Tuple[float, float]):
"""Set the scroll offset directly."""
# Check for borders
# Check right border
x, y = value
x_screen = x - self.window.width // 2
y_screen = y - self.window.height // 2
if self.max_scroll_x:
x_screen = min(max(0, x_screen), self.max_scroll_x - self.window.width)
if self.max_scroll_y:
y_screen = min(
max(-self.window.height // 2 + 32 * 2, y_screen), self.window.height
) # No idea why we need to 32*2. Was estimated by printing values
self.offset_x = x_screen + self.window.width // 2
self.offset_y = y_screen + self.window.height // 2 | Set the scroll offset directly. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Desert_Dino_Dialogue/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Desert_Dino_Dialogue/src/client/client/game/camera.py | MIT |
def draw(self):
"""Draw the sprite at its current position.
See the module documentation for hints on drawing multiple sprites
efficiently.
"""
if not self._group:
return
self._group.set_state_recursive()
if self.program:
self.program["origin_scale"] = (self.origin_scale[0], self.origin_scale[1])
self.program["origin_rotation"] = (
self.origin_rotation[0],
self.origin_rotation[1],
)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
if self._vertex_list:
self._vertex_list.draw(GL_TRIANGLES)
self._group.unset_state_recursive() | Draw the sprite at its current position.
See the module documentation for hints on drawing multiple sprites
efficiently. | draw | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Desert_Dino_Dialogue/src/client/client/game/nearest_sprite.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Desert_Dino_Dialogue/src/client/client/game/nearest_sprite.py | MIT |
def zoom(self, value: float) -> None:
"""Here we set zoom, clamp value to minimum of min_zoom and max of max_zoom."""
self._zoom = max(min(value, self.max_zoom), self.min_zoom) | Here we set zoom, clamp value to minimum of min_zoom and max of max_zoom. | zoom | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/License/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/License/src/client/client/game/camera.py | MIT |
def position(self) -> Tuple[float, float]:
"""Query the current offset."""
return self.offset_x, self.offset_y | Query the current offset. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/License/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/License/src/client/client/game/camera.py | MIT |
def position(self, value: Tuple[float, float]) -> None:
"""Set the scroll offset directly."""
# Check for borders
self.offset_x, self.offset_y = value | Set the scroll offset directly. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/License/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/License/src/client/client/game/camera.py | MIT |
def move(self, axis_x: float, axis_y: float) -> None:
"""Move axis direction with scroll_speed.
Example: Move left -> move(-1, 0)
"""
self.offset_x += self.scroll_speed * axis_x
self.offset_y += self.scroll_speed * axis_y | Move axis direction with scroll_speed.
Example: Move left -> move(-1, 0) | move | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/License/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/License/src/client/client/game/camera.py | MIT |
def position(self):
"""Query the current offset."""
return self.offset_x, self.offset_y | Query the current offset. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/License/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/License/src/client/client/game/camera.py | MIT |
def position(self, value: Tuple[float, float]):
"""Set the scroll offset directly."""
# Check for borders
# Check right border
x, y = value
x_screen = x - self.window.width // 2
y_screen = y - self.window.height // 2
if self.max_scroll_x:
x_screen = min(max(0, x_screen), self.max_scroll_x - self.window.width)
if self.max_scroll_y:
y_screen = min(
max(-self.window.height // 2 + 32 * 2, y_screen), self.window.height
) # No idea why we need to 32*2. Was estimated by printing values
self.offset_x = x_screen + self.window.width // 2
self.offset_y = y_screen + self.window.height // 2 | Set the scroll offset directly. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/License/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/License/src/client/client/game/camera.py | MIT |
def draw(self):
"""Draw the sprite at its current position.
See the module documentation for hints on drawing multiple sprites
efficiently.
"""
if not self._group:
return
self._group.set_state_recursive()
if self.program:
self.program["origin_scale"] = (self.origin_scale[0], self.origin_scale[1])
self.program["origin_rotation"] = (
self.origin_rotation[0],
self.origin_rotation[1],
)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
if self._vertex_list:
self._vertex_list.draw(GL_TRIANGLES)
self._group.unset_state_recursive() | Draw the sprite at its current position.
See the module documentation for hints on drawing multiple sprites
efficiently. | draw | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/License/src/client/client/game/nearest_sprite.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/License/src/client/client/game/nearest_sprite.py | MIT |
def zoom(self, value: float) -> None:
"""Here we set zoom, clamp value to minimum of min_zoom and max of max_zoom."""
self._zoom = max(min(value, self.max_zoom), self.min_zoom) | Here we set zoom, clamp value to minimum of min_zoom and max of max_zoom. | zoom | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Stegosaurus/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Stegosaurus/src/client/client/game/camera.py | MIT |
def position(self) -> Tuple[float, float]:
"""Query the current offset."""
return self.offset_x, self.offset_y | Query the current offset. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Stegosaurus/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Stegosaurus/src/client/client/game/camera.py | MIT |
def position(self, value: Tuple[float, float]) -> None:
"""Set the scroll offset directly."""
# Check for borders
self.offset_x, self.offset_y = value | Set the scroll offset directly. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Stegosaurus/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Stegosaurus/src/client/client/game/camera.py | MIT |
def move(self, axis_x: float, axis_y: float) -> None:
"""Move axis direction with scroll_speed.
Example: Move left -> move(-1, 0)
"""
self.offset_x += self.scroll_speed * axis_x
self.offset_y += self.scroll_speed * axis_y | Move axis direction with scroll_speed.
Example: Move left -> move(-1, 0) | move | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Stegosaurus/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Stegosaurus/src/client/client/game/camera.py | MIT |
def position(self):
"""Query the current offset."""
return self.offset_x, self.offset_y | Query the current offset. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Stegosaurus/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Stegosaurus/src/client/client/game/camera.py | MIT |
def position(self, value: Tuple[float, float]):
"""Set the scroll offset directly."""
# Check for borders
# Check right border
x, y = value
x_screen = x - self.window.width // 2
y_screen = y - self.window.height // 2
if self.max_scroll_x:
x_screen = min(max(0, x_screen), self.max_scroll_x - self.window.width)
if self.max_scroll_y:
y_screen = min(
max(-self.window.height // 2 + 32 * 2, y_screen), self.window.height
) # No idea why we need to 32*2. Was estimated by printing values
self.offset_x = x_screen + self.window.width // 2
self.offset_y = y_screen + self.window.height // 2 | Set the scroll offset directly. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Stegosaurus/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Stegosaurus/src/client/client/game/camera.py | MIT |
def draw(self):
"""Draw the sprite at its current position.
See the module documentation for hints on drawing multiple sprites
efficiently.
"""
if not self._group:
return
self._group.set_state_recursive()
if self.program:
self.program["origin_scale"] = (self.origin_scale[0], self.origin_scale[1])
self.program["origin_rotation"] = (
self.origin_rotation[0],
self.origin_rotation[1],
)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
if self._vertex_list:
self._vertex_list.draw(GL_TRIANGLES)
self._group.unset_state_recursive() | Draw the sprite at its current position.
See the module documentation for hints on drawing multiple sprites
efficiently. | draw | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Stegosaurus/src/client/client/game/nearest_sprite.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Stegosaurus/src/client/client/game/nearest_sprite.py | MIT |
def zoom(self, value: float) -> None:
"""Here we set zoom, clamp value to minimum of min_zoom and max of max_zoom."""
self._zoom = max(min(value, self.max_zoom), self.min_zoom) | Here we set zoom, clamp value to minimum of min_zoom and max of max_zoom. | zoom | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Race_to_the_Top/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Race_to_the_Top/src/client/client/game/camera.py | MIT |
def position(self) -> Tuple[float, float]:
"""Query the current offset."""
return self.offset_x, self.offset_y | Query the current offset. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Race_to_the_Top/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Race_to_the_Top/src/client/client/game/camera.py | MIT |
def position(self, value: Tuple[float, float]) -> None:
"""Set the scroll offset directly."""
# Check for borders
self.offset_x, self.offset_y = value | Set the scroll offset directly. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Race_to_the_Top/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Race_to_the_Top/src/client/client/game/camera.py | MIT |
def move(self, axis_x: float, axis_y: float) -> None:
"""Move axis direction with scroll_speed.
Example: Move left -> move(-1, 0)
"""
self.offset_x += self.scroll_speed * axis_x
self.offset_y += self.scroll_speed * axis_y | Move axis direction with scroll_speed.
Example: Move left -> move(-1, 0) | move | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Race_to_the_Top/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Race_to_the_Top/src/client/client/game/camera.py | MIT |
def position(self):
"""Query the current offset."""
return self.offset_x, self.offset_y | Query the current offset. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Race_to_the_Top/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Race_to_the_Top/src/client/client/game/camera.py | MIT |
def position(self, value: Tuple[float, float]):
"""Set the scroll offset directly."""
# Check for borders
# Check right border
x, y = value
x_screen = x - self.window.width // 2
y_screen = y - self.window.height // 2
if self.max_scroll_x:
x_screen = min(max(0, x_screen), self.max_scroll_x - self.window.width)
if self.max_scroll_y:
y_screen = min(
max(-self.window.height // 2 + 32 * 2, y_screen), self.window.height
) # No idea why we need to 32*2. Was estimated by printing values
self.offset_x = x_screen + self.window.width // 2
self.offset_y = y_screen + self.window.height // 2 | Set the scroll offset directly. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Race_to_the_Top/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Race_to_the_Top/src/client/client/game/camera.py | MIT |
def draw(self):
"""Draw the sprite at its current position.
See the module documentation for hints on drawing multiple sprites
efficiently.
"""
if not self._group:
return
self._group.set_state_recursive()
if self.program:
self.program["origin_scale"] = (self.origin_scale[0], self.origin_scale[1])
self.program["origin_rotation"] = (
self.origin_rotation[0],
self.origin_rotation[1],
)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
if self._vertex_list:
self._vertex_list.draw(GL_TRIANGLES)
self._group.unset_state_recursive() | Draw the sprite at its current position.
See the module documentation for hints on drawing multiple sprites
efficiently. | draw | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Race_to_the_Top/src/client/client/game/nearest_sprite.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Race_to_the_Top/src/client/client/game/nearest_sprite.py | MIT |
def zoom(self, value: float) -> None:
"""Here we set zoom, clamp value to minimum of min_zoom and max of max_zoom."""
self._zoom = max(min(value, self.max_zoom), self.min_zoom) | Here we set zoom, clamp value to minimum of min_zoom and max of max_zoom. | zoom | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Maze/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Maze/src/client/client/game/camera.py | MIT |
def position(self) -> Tuple[float, float]:
"""Query the current offset."""
return self.offset_x, self.offset_y | Query the current offset. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Maze/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Maze/src/client/client/game/camera.py | MIT |
def position(self, value: Tuple[float, float]) -> None:
"""Set the scroll offset directly."""
# Check for borders
self.offset_x, self.offset_y = value | Set the scroll offset directly. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Maze/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Maze/src/client/client/game/camera.py | MIT |
def move(self, axis_x: float, axis_y: float) -> None:
"""Move axis direction with scroll_speed.
Example: Move left -> move(-1, 0)
"""
self.offset_x += self.scroll_speed * axis_x
self.offset_y += self.scroll_speed * axis_y | Move axis direction with scroll_speed.
Example: Move left -> move(-1, 0) | move | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Maze/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Maze/src/client/client/game/camera.py | MIT |
def position(self):
"""Query the current offset."""
return self.offset_x, self.offset_y | Query the current offset. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Maze/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Maze/src/client/client/game/camera.py | MIT |
def position(self, value: Tuple[float, float]):
"""Set the scroll offset directly."""
# Check for borders
# Check right border
x, y = value
x_screen = x - self.window.width // 2
y_screen = y - self.window.height // 2
if self.max_scroll_x:
x_screen = min(max(0, x_screen), self.max_scroll_x - self.window.width)
if self.max_scroll_y:
y_screen = min(
max(-self.window.height // 2 + 32 * 2, y_screen), self.window.height
) # No idea why we need to 32*2. Was estimated by printing values
self.offset_x = x_screen + self.window.width // 2
self.offset_y = y_screen + self.window.height // 2 | Set the scroll offset directly. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Maze/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Maze/src/client/client/game/camera.py | MIT |
def draw(self):
"""Draw the sprite at its current position.
See the module documentation for hints on drawing multiple sprites
efficiently.
"""
if not self._group:
return
self._group.set_state_recursive()
if self.program:
self.program["origin_scale"] = (self.origin_scale[0], self.origin_scale[1])
self.program["origin_rotation"] = (
self.origin_rotation[0],
self.origin_rotation[1],
)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
if self._vertex_list:
self._vertex_list.draw(GL_TRIANGLES)
self._group.unset_state_recursive() | Draw the sprite at its current position.
See the module documentation for hints on drawing multiple sprites
efficiently. | draw | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Maze/src/client/client/game/nearest_sprite.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Maze/src/client/client/game/nearest_sprite.py | MIT |
def zoom(self, value: float) -> None:
"""Here we set zoom, clamp value to minimum of min_zoom and max of max_zoom."""
self._zoom = max(min(value, self.max_zoom), self.min_zoom) | Here we set zoom, clamp value to minimum of min_zoom and max of max_zoom. | zoom | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Sanity_Check/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Sanity_Check/src/client/client/game/camera.py | MIT |
def position(self) -> Tuple[float, float]:
"""Query the current offset."""
return self.offset_x, self.offset_y | Query the current offset. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Sanity_Check/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Sanity_Check/src/client/client/game/camera.py | MIT |
def position(self, value: Tuple[float, float]) -> None:
"""Set the scroll offset directly."""
# Check for borders
self.offset_x, self.offset_y = value | Set the scroll offset directly. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Sanity_Check/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Sanity_Check/src/client/client/game/camera.py | MIT |
def move(self, axis_x: float, axis_y: float) -> None:
"""Move axis direction with scroll_speed.
Example: Move left -> move(-1, 0)
"""
self.offset_x += self.scroll_speed * axis_x
self.offset_y += self.scroll_speed * axis_y | Move axis direction with scroll_speed.
Example: Move left -> move(-1, 0) | move | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Sanity_Check/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Sanity_Check/src/client/client/game/camera.py | MIT |
def position(self):
"""Query the current offset."""
return self.offset_x, self.offset_y | Query the current offset. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Sanity_Check/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Sanity_Check/src/client/client/game/camera.py | MIT |
def position(self, value: Tuple[float, float]):
"""Set the scroll offset directly."""
# Check for borders
# Check right border
x, y = value
x_screen = x - self.window.width // 2
y_screen = y - self.window.height // 2
if self.max_scroll_x:
x_screen = min(max(0, x_screen), self.max_scroll_x - self.window.width)
if self.max_scroll_y:
y_screen = min(
max(-self.window.height // 2 + 32 * 2, y_screen), self.window.height
) # No idea why we need to 32*2. Was estimated by printing values
self.offset_x = x_screen + self.window.width // 2
self.offset_y = y_screen + self.window.height // 2 | Set the scroll offset directly. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Sanity_Check/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Sanity_Check/src/client/client/game/camera.py | MIT |
def draw(self):
"""Draw the sprite at its current position.
See the module documentation for hints on drawing multiple sprites
efficiently.
"""
if not self._group:
return
self._group.set_state_recursive()
if self.program:
self.program["origin_scale"] = (self.origin_scale[0], self.origin_scale[1])
self.program["origin_rotation"] = (
self.origin_rotation[0],
self.origin_rotation[1],
)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
if self._vertex_list:
self._vertex_list.draw(GL_TRIANGLES)
self._group.unset_state_recursive() | Draw the sprite at its current position.
See the module documentation for hints on drawing multiple sprites
efficiently. | draw | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Sanity_Check/src/client/client/game/nearest_sprite.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Sanity_Check/src/client/client/game/nearest_sprite.py | MIT |
def zoom(self, value: float) -> None:
"""Here we set zoom, clamp value to minimum of min_zoom and max of max_zoom."""
self._zoom = max(min(value, self.max_zoom), self.min_zoom) | Here we set zoom, clamp value to minimum of min_zoom and max of max_zoom. | zoom | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Cheat_Code/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Cheat_Code/src/client/client/game/camera.py | MIT |
def position(self) -> Tuple[float, float]:
"""Query the current offset."""
return self.offset_x, self.offset_y | Query the current offset. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Cheat_Code/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Cheat_Code/src/client/client/game/camera.py | MIT |
def position(self, value: Tuple[float, float]) -> None:
"""Set the scroll offset directly."""
# Check for borders
self.offset_x, self.offset_y = value | Set the scroll offset directly. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Cheat_Code/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Cheat_Code/src/client/client/game/camera.py | MIT |
def move(self, axis_x: float, axis_y: float) -> None:
"""Move axis direction with scroll_speed.
Example: Move left -> move(-1, 0)
"""
self.offset_x += self.scroll_speed * axis_x
self.offset_y += self.scroll_speed * axis_y | Move axis direction with scroll_speed.
Example: Move left -> move(-1, 0) | move | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Cheat_Code/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Cheat_Code/src/client/client/game/camera.py | MIT |
def position(self):
"""Query the current offset."""
return self.offset_x, self.offset_y | Query the current offset. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Cheat_Code/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Cheat_Code/src/client/client/game/camera.py | MIT |
def position(self, value: Tuple[float, float]):
"""Set the scroll offset directly."""
# Check for borders
# Check right border
x, y = value
x_screen = x - self.window.width // 2
y_screen = y - self.window.height // 2
if self.max_scroll_x:
x_screen = min(max(0, x_screen), self.max_scroll_x - self.window.width)
if self.max_scroll_y:
y_screen = min(
max(-self.window.height // 2 + 32 * 2, y_screen), self.window.height
) # No idea why we need to 32*2. Was estimated by printing values
self.offset_x = x_screen + self.window.width // 2
self.offset_y = y_screen + self.window.height // 2 | Set the scroll offset directly. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Cheat_Code/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Cheat_Code/src/client/client/game/camera.py | MIT |
def draw(self):
"""Draw the sprite at its current position.
See the module documentation for hints on drawing multiple sprites
efficiently.
"""
if not self._group:
return
self._group.set_state_recursive()
if self.program:
self.program["origin_scale"] = (self.origin_scale[0], self.origin_scale[1])
self.program["origin_rotation"] = (
self.origin_rotation[0],
self.origin_rotation[1],
)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
if self._vertex_list:
self._vertex_list.draw(GL_TRIANGLES)
self._group.unset_state_recursive() | Draw the sprite at its current position.
See the module documentation for hints on drawing multiple sprites
efficiently. | draw | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Cheat_Code/src/client/client/game/nearest_sprite.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Cheat_Code/src/client/client/game/nearest_sprite.py | MIT |
def zoom(self, value: float) -> None:
"""Here we set zoom, clamp value to minimum of min_zoom and max of max_zoom."""
self._zoom = max(min(value, self.max_zoom), self.min_zoom) | Here we set zoom, clamp value to minimum of min_zoom and max of max_zoom. | zoom | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Boss/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Boss/src/client/client/game/camera.py | MIT |
def position(self) -> Tuple[float, float]:
"""Query the current offset."""
return self.offset_x, self.offset_y | Query the current offset. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Boss/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Boss/src/client/client/game/camera.py | MIT |
def position(self, value: Tuple[float, float]) -> None:
"""Set the scroll offset directly."""
# Check for borders
self.offset_x, self.offset_y = value | Set the scroll offset directly. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Boss/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Boss/src/client/client/game/camera.py | MIT |
def move(self, axis_x: float, axis_y: float) -> None:
"""Move axis direction with scroll_speed.
Example: Move left -> move(-1, 0)
"""
self.offset_x += self.scroll_speed * axis_x
self.offset_y += self.scroll_speed * axis_y | Move axis direction with scroll_speed.
Example: Move left -> move(-1, 0) | move | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Boss/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Boss/src/client/client/game/camera.py | MIT |
def position(self):
"""Query the current offset."""
return self.offset_x, self.offset_y | Query the current offset. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Boss/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Boss/src/client/client/game/camera.py | MIT |
def position(self, value: Tuple[float, float]):
"""Set the scroll offset directly."""
# Check for borders
# Check right border
x, y = value
x_screen = x - self.window.width // 2
y_screen = y - self.window.height // 2
if self.max_scroll_x:
x_screen = min(max(0, x_screen), self.max_scroll_x - self.window.width)
if self.max_scroll_y:
y_screen = min(
max(-self.window.height // 2 + 32 * 2, y_screen), self.window.height
) # No idea why we need to 32*2. Was estimated by printing values
self.offset_x = x_screen + self.window.width // 2
self.offset_y = y_screen + self.window.height // 2 | Set the scroll offset directly. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Boss/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Boss/src/client/client/game/camera.py | MIT |
def draw(self):
"""Draw the sprite at its current position.
See the module documentation for hints on drawing multiple sprites
efficiently.
"""
if not self._group:
return
self._group.set_state_recursive()
if self.program:
self.program["origin_scale"] = (self.origin_scale[0], self.origin_scale[1])
self.program["origin_rotation"] = (
self.origin_rotation[0],
self.origin_rotation[1],
)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
if self._vertex_list:
self._vertex_list.draw(GL_TRIANGLES)
self._group.unset_state_recursive() | Draw the sprite at its current position.
See the module documentation for hints on drawing multiple sprites
efficiently. | draw | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Boss/src/client/client/game/nearest_sprite.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Boss/src/client/client/game/nearest_sprite.py | MIT |
def zoom(self, value: float) -> None:
"""Here we set zoom, clamp value to minimum of min_zoom and max of max_zoom."""
self._zoom = max(min(value, self.max_zoom), self.min_zoom) | Here we set zoom, clamp value to minimum of min_zoom and max of max_zoom. | zoom | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Dino_Runner/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Dino_Runner/src/client/client/game/camera.py | MIT |
def position(self) -> Tuple[float, float]:
"""Query the current offset."""
return self.offset_x, self.offset_y | Query the current offset. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Dino_Runner/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Dino_Runner/src/client/client/game/camera.py | MIT |
def position(self, value: Tuple[float, float]) -> None:
"""Set the scroll offset directly."""
# Check for borders
self.offset_x, self.offset_y = value | Set the scroll offset directly. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Dino_Runner/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Dino_Runner/src/client/client/game/camera.py | MIT |
def move(self, axis_x: float, axis_y: float) -> None:
"""Move axis direction with scroll_speed.
Example: Move left -> move(-1, 0)
"""
self.offset_x += self.scroll_speed * axis_x
self.offset_y += self.scroll_speed * axis_y | Move axis direction with scroll_speed.
Example: Move left -> move(-1, 0) | move | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Dino_Runner/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Dino_Runner/src/client/client/game/camera.py | MIT |
def position(self):
"""Query the current offset."""
return self.offset_x, self.offset_y | Query the current offset. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Dino_Runner/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Dino_Runner/src/client/client/game/camera.py | MIT |
def position(self, value: Tuple[float, float]):
"""Set the scroll offset directly."""
# Check for borders
# Check right border
x, y = value
x_screen = x - self.window.width // 2
y_screen = y - self.window.height // 2
if self.max_scroll_x:
x_screen = min(max(0, x_screen), self.max_scroll_x - self.window.width)
if self.max_scroll_y:
y_screen = min(
max(-self.window.height // 2 + 32 * 2, y_screen), self.window.height
) # No idea why we need to 32*2. Was estimated by printing values
self.offset_x = x_screen + self.window.width // 2
self.offset_y = y_screen + self.window.height // 2 | Set the scroll offset directly. | position | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Dino_Runner/src/client/client/game/camera.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Dino_Runner/src/client/client/game/camera.py | MIT |
def draw(self):
"""Draw the sprite at its current position.
See the module documentation for hints on drawing multiple sprites
efficiently.
"""
if not self._group:
return
self._group.set_state_recursive()
if self.program:
self.program["origin_scale"] = (self.origin_scale[0], self.origin_scale[1])
self.program["origin_rotation"] = (
self.origin_rotation[0],
self.origin_rotation[1],
)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
if self._vertex_list:
self._vertex_list.draw(GL_TRIANGLES)
self._group.unset_state_recursive() | Draw the sprite at its current position.
See the module documentation for hints on drawing multiple sprites
efficiently. | draw | python | sajjadium/ctf-archives | ctfs/CCCamp/2023/game/Dino_Runner/src/client/client/game/nearest_sprite.py | https://github.com/sajjadium/ctf-archives/blob/master/ctfs/CCCamp/2023/game/Dino_Runner/src/client/client/game/nearest_sprite.py | MIT |
Subsets and Splits