-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathconvert-gen.py
107 lines (82 loc) · 2.95 KB
/
convert-gen.py
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
import econ_pb2
import zlib
import sys
import struct
# All you need to generate a gen code
def generate_inspect(proto):
# Needs to be prefixed with a null byte
buffer = bytearray([0])
buffer.extend(proto.SerializeToString())
# calculate the checksum
crc = zlib.crc32(buffer)
xored_crc = (crc & 0xFFFF) ^ (proto.ByteSize() * crc)
buffer.extend((xored_crc & 0xFFFFFFFF).to_bytes(length=4, byteorder='big'))
# Must be upper case
return buffer.hex().upper()
# Very primitive arg parsing
class ArgParser:
def __init__(self) -> None:
self.args = sys.argv[1:]
@property
def count(self):
return len(self.args)
def pop_string(self, default_value=None):
if len(self.args) > 0:
return self.args.pop(0)
return default_value
def pop_int(self, default_value=None):
if len(self.args) > 0:
try:
return int(self.args.pop(0))
except:
return default_value
return default_value
def pop_float(self, default_value=None):
if len(self.args) > 0:
try:
return float(self.args.pop(0))
except:
return default_value
return default_value
ALLOWED_COMMANDS = ["gen", "gengl", "genrarity"]
def main():
args = ArgParser()
# Not too proud of this
command_name = args.pop_string()
if command_name and len(command_name) > 1 and command_name[0] == "!":
command_name = command_name[1:]
if command_name and command_name.lower() not in ALLOWED_COMMANDS:
print("Invalid or no command name")
return
if args.count < 1:
print("Not enough arguments")
return
command_name = command_name.lower()
is_weapon_gen = command_name == "gen" or command_name == "genrarity"
# You can modify other parameters to your liking (check econ.proto for all variables)
proto = econ_pb2.CEconItemPreviewDataBlock()
if command_name == "genrarity":
proto.rarity = args.pop_int(0)
elif command_name == "gengl":
# Always set the quality to red on gloves
proto.rarity = 6
proto.defindex = args.pop_int(1)
proto.paintindex = args.pop_int(0)
proto.paintseed = args.pop_int(0)
paint_wear = args.pop_float(0)
# Is there a better way to do it in python?
proto.paintwear = int.from_bytes(struct.pack(">f", paint_wear), "big")
if is_weapon_gen:
for slot in range(0, 5):
sticker_id = args.pop_int()
sticker_wear = args.pop_float(0)
if sticker_id is None:
break
sticker = proto.stickers.add()
sticker.slot = slot
sticker.sticker_id = sticker_id
sticker.wear = sticker_wear
generated_payload = generate_inspect(proto)
print(f"steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20{generated_payload}")
if __name__ == "__main__":
main()