-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinjector.py
148 lines (92 loc) · 3.32 KB
/
injector.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
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
#!/bin/python3
import math
import pygame
import serial
pygame.init()
width,height=900,600
win=pygame.display.set_mode((width,height))
fps=60
pygame.display.set_caption("injector")
white=(255,255,255)
black =(0,0,0)
gridlist=[]
collums=16#left to rigth collumns
rows=15 #top to bottom rows
usb_port="COM10"
ser = serial.Serial(usb_port,baudrate=9600,timeout=1)
gridw=width/collums
gridh=height/rows
def find_grid(collum,row):#gives the name of a grid piece given collum and row
name=row*collums+collum
if name>=0 and name<=collums*rows:
return name
class piece:
def __init__(self,name):
self.name=name#name is the number of the piece
self.w=gridw#these 2 are kinda useless rn
self.h=gridh
self.row=math.ceil(name/collums)-1
#self.collum=name-(self.row)*(collums)
self.collum=name-(self.row)*(collums)-1
#self.x=((collums - self.collum)*gridw)
self.x=self.collum*gridw
self.y=(gridh*self.row)
self.state=False
def render(self):
rect=pygame.Rect(self.x,self.y,self.w,self.h)
if self.state:
pygame.draw.rect(win,black,rect)
else:
pygame.draw.rect(win,black,rect,1)
def findclose(self):#left right up down
#returns indexes of the grid spaces that on the left, right, above and below
#
left= find_grid(self.collum-1,self.row)
right= find_grid(self.collum+1,self.row)
up= find_grid(self.collum,self.row-1)
down= find_grid(self.collum,self.row+1)
return(left,right,up,down)
#this might have a problem with giving numbers that are not existant but those numbers should be ignored
def clicked(self,x,y):#be wary this worked really fast
if x>=self.x and x<=self.x+self.w:
if y>=self.y and y<=self.y+self.h:
return True
return False
def changestate(self):
self.state= not self.state
def main():
win.fill(white)
run=True
for i in range(collums*rows):
gridlist.append(i)
gridlist[i]=piece(i+1)
while run:
win.fill(white)
for i in gridlist:
i.render()
pygame.display.update()
for event in pygame.event.get():
if event.type==pygame.QUIT:
run=False
if event.type==pygame.KEYDOWN:
if event.key==pygame.K_s:
send=[]
for i in gridlist:
if i.state:
send.append(int(i.name))
print(bytearray(send))
print(send)
#end.append('\n')
ser.write(bytearray([119,len(send)]))
ser.write(bytearray(send))
ser.flush()
if event.type==pygame.MOUSEBUTTONDOWN:
mx,my=pygame.mouse.get_pos()
for i in gridlist:
if i.clicked(mx,my):
print(i.name)
#print(i.findclose())
i.changestate()
pygame.quit()
if __name__=="__main__":
main()