From abed19a844d7e4ef30f598c7e306b160a0db7cd3 Mon Sep 17 00:00:00 2001 From: Bryan Soong Date: Sat, 6 Nov 2021 19:23:21 +0800 Subject: [PATCH] :sparkles: initial commit --- README.md | Bin 0 -> 40 bytes chars/0c.png | Bin 0 -> 425 bytes chars/10c.png | Bin 0 -> 171 bytes chars/1c.png | Bin 0 -> 259 bytes chars/2c.png | Bin 0 -> 440 bytes chars/3c.png | Bin 0 -> 431 bytes chars/4c.png | Bin 0 -> 340 bytes chars/5c.png | Bin 0 -> 396 bytes chars/6c.png | Bin 0 -> 425 bytes chars/7c.png | Bin 0 -> 354 bytes chars/8c.png | Bin 0 -> 440 bytes chars/9c.png | Bin 0 -> 440 bytes main.py | 105 +++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | Bin 0 -> 636 bytes test.png | Bin 0 -> 1182 bytes 15 files changed, 105 insertions(+) create mode 100644 README.md create mode 100644 chars/0c.png create mode 100644 chars/10c.png create mode 100644 chars/1c.png create mode 100644 chars/2c.png create mode 100644 chars/3c.png create mode 100644 chars/4c.png create mode 100644 chars/5c.png create mode 100644 chars/6c.png create mode 100644 chars/7c.png create mode 100644 chars/8c.png create mode 100644 chars/9c.png create mode 100644 main.py create mode 100644 requirements.txt create mode 100644 test.png diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..f2b33fd4bc92bc10566e871f28256d7418d6d707 GIT binary patch literal 40 rcmezWPnki1!G|H0A(0`Sp%h3vGXyjEGn4^YMGQGW(Mkqh1}+8w$$$tW literal 0 HcmV?d00001 diff --git a/chars/0c.png b/chars/0c.png new file mode 100644 index 0000000000000000000000000000000000000000..f3be0ac13de6c3464c3d4b05ea57765043b01f09 GIT binary patch literal 425 zcmV;a0apHrP)>yFw%;^5`r zBrlPd6c^=XS>&)*yY1}m%=moB9Sp#6f`&FX)!y04ld0_f@$-D_)XWta5qWqZU}*cB zgGQ<6<}T4tUo6Y6qvNN6@jbv{j4(aX!ppVU`GZh6*3-XiS$1z%b$7^T+ctBnuAxXB zfYr5g$y;>&VxC@p02mu?vP_fJR{2y#%w`LpUw@+NA%{+`5&-IIi>*w?RZ*q^NM~{& z5(ELj&rccvukbqgyi4;)0CY_zBHJ#2D4EIvNM}sjve-u=1wa%9U6%oZ1Gg#yh{u14 zh&{dj0szn+t^^zs7&mkP*SGH^2<-Jeb#f605S{F>^EpKpB7HRgmX^<$B#{>2ZOz8^ zN<>k_hsSSOk*b2;^^L2M(JiHzXZL<#@sKI1?DzizglT}T T7V5AV00000NkvXXu0mjf2MNIS literal 0 HcmV?d00001 diff --git a/chars/10c.png b/chars/10c.png new file mode 100644 index 0000000000000000000000000000000000000000..351449893470f4dd421153a7616d74eee420e697 GIT binary patch literal 171 zcmeAS@N?(olHy`uVBq!ia0vp^AT|#N6Og>Zx%)eiD)Mx345^rtI$@{iVFR9{40fiH zimu=8U$Sr2JDsK~$E5M|XKm*c79owizyJ<$7K6bYVabC@|5jxd-E;gMmdP)F>%3Fft>0DhucU5Ytf)ONpCKUE U(9WxO3}`!pr>mdKI;Vst0L8IA3;+NC literal 0 HcmV?d00001 diff --git a/chars/1c.png b/chars/1c.png new file mode 100644 index 0000000000000000000000000000000000000000..56d59ed725478a2c17752558d085c7cb9840a20f GIT binary patch literal 259 zcmV+e0sQ`nP))B@s7X8pF?(HM{`{C7n+|fdwVTn5fTWrwJ4qDyT>-?CB|Jcz{ia6&S); z+!aiAr0@cfS_I8_i2mGYzVYdyqq(a4= zO<()1q(ZI~@b!ztyZfh)V!T|X?VFd;c#)%`fWYQ^e_pGfE4Dc3ad7|u002ov JPDHLkV1l8taSs3h literal 0 HcmV?d00001 diff --git a/chars/2c.png b/chars/2c.png new file mode 100644 index 0000000000000000000000000000000000000000..403c801b5d10d93c0097d0923ad8f701cc04c035 GIT binary patch literal 440 zcmeAS@N?(olHy`uVBq!ia0vp^AT|#N6Og>Zx%)c<17p3Xi(^Q|9L5sH?thG&(lU&U z|Kme-Vnehwl!gBM{deN*^X3W1uiSXe2n1ZxGBY||fpYIZ{y25|k)@d&A0NlZPd}`@ zm)w8$g~7_z@c)mVx6hk-dD$76nAEkTzklceinKL*bBIeYsVWHqt^ND=FBca(yM*MU zkBnDtz6OdYD+>Mj_Lb@A>8JnyGl+`t1PACc{{PR&z#u8k3zWWi`Pu(Je^_3=`WBtF zNmYt{+RUTu0s=lhy3!InpFaPXJ@+IND;oo^v@DN|45yGVJ0G8y85}Sb4q9e05j;5ApigX literal 0 HcmV?d00001 diff --git a/chars/3c.png b/chars/3c.png new file mode 100644 index 0000000000000000000000000000000000000000..7527952cca1cfb698991238a712f18ed0345b25f GIT binary patch literal 431 zcmV;g0Z{&lP)VJZXXLH1B059;Dbl+KYsZB|38C>2)B$h|GD!|^Rk!!VPR(w zP>^%-F=b?8W@Kh&=jJ$ns`$gJ7G))2MpjmK2`L6HDQQkgDOOQYc4_JUDUttw^aKYR zFfcN)iHWmIN;5GqGB7YPGPANeTgm1p8_!;NX6@PwtbziJ%q)zI3``6R42%p6B7&TA zdp#K$8Iod*4(!b_H&tL@VEF%^fsso}nt_o)TAatqMAAS_AUeW8RD|dE@4r^wi!R^! z0F`F=&+z~6-+#Y;i3_ox+Mg~i#~iB~V_;xl;NoPlx0GXGU^spD@&AASSiXGy#lgYC$IE{C zVCvb+FLgD=1O+(m+BUhCUCm&#-`oqz%o@!oi} zCx2Xge5xtqS8Gsc)>dQH+WX#q!D4qH(i%5XGXtS<@BKsND4#a0w#Y;`ke&~Yj`^0B z3sSsViH3drht;!z!yhnNtj+1-d`Z6@WY?2FalqEm`Ta!DE{_Ya+bxE(&FpMfXwX`; m2Hb92IOqkYr~0jCCGZ8aR!)cxXQ@E|0000(o!?#QomSeVcojhz5T(mTZxQVp~jutgEL=jZ> z&!NI38>|})E6}3y2K8%5gx>moyhrqkGBRjA*_p@x_@?9MsXQeNHdzGl`u3%&#YTOb z%rH)*9Dz+X0Elg#t*svrO2O(vuu#f?4p{_{fBDpjB5yJQXb4JBA72W3#wPmJm+yEY zlT$zb0Fe}BD>@bMI~uRmDvQJ}RwGFOknD=6D7;=Tw@cpf-u>N0riGano|$v&?Ft8g z08MS?ve0ss{h3|Zd3byW;P>@Zv@!>f0f)us>1G7baW%?kb0q*KV{=W@xWHuJQDQ!{ z;*|sdFiL`Vv>U+XwF<^)v7}K-oDR#)@nY((Fg$2AN<#X+5ZyQ>yn%@J&LL;(a?s^= qb(z}?PtV2ey>uvi`1w^4Wce51Np4unitv#D0000QBqz}cpR=dUD!oOw_HHNVjv}(g69xc+z;7?N zRNGC`>-XUBdT{%a69hh8&r<@%Fg?~#Z8u%tyt&+S(rYv+Gm8@h06YU+wT0cSmWZr+ z8t0|3nqo8($^igC3DDPF0bphIbRp3G9vVN`>}qW;OEAeTDSA5V=QyG$zvmZ{*`zNJ z4FEcN*EaU=XmMdC#}NRd{vC&Nw$wHi+`0hZ8*u!oDmCY&17M6TE}f+4Gk8Pxbl?nt zr93aLMrr6p0YC_e$K#wX4Frl71Mu;w#k3!KbsLVzDu9up`a~!3+TFV*loFjNdOK}1 zem8*Q)5ni!%;PKy%Su(v%)O)%ojD(1O?3qW-b$;*6qc34X^6Y literal 0 HcmV?d00001 diff --git a/chars/7c.png b/chars/7c.png new file mode 100644 index 0000000000000000000000000000000000000000..ec9d708ced12c2fcf6bccb900edf5c91c019e34c GIT binary patch literal 354 zcmV-o0iFJdP)ytX$O^jZg0yi}num zht4mmCxx;$KPEA``*2%Twv7l-IoklXb46u$NgxvWYPCdbu`FOVJyghN9;>gz@hu64 zw19RTV+_WCY-UqHZm0BZ#OL}oARq`Z5)DsJ4K|x!`TepE1ObH+01U9cIsqIWRbF13 zmfr<5{Q2EMdodFS_VQ)z^NXc0sJ6+{Ts+{~wWqgY>0Z08XDP%W2FNZafz#q0N?DHM zb)dYF8t)s8g@Nmv=MHPXW>}d|czeD6uC(spUkZ^|km<=F3;+NC07*qoM6N<$f+ACr AjsO4v literal 0 HcmV?d00001 diff --git a/chars/8c.png b/chars/8c.png new file mode 100644 index 0000000000000000000000000000000000000000..2df433781c3fce1cc10201214f8cd6a55e44c897 GIT binary patch literal 440 zcmeAS@N?(olHy`uVBq!ia0vp^AT|#N6Og>Zx%)c<17p3Xi(^Q|9L5sH?thFN($b9o z|GU^J6sMaSXp8;%`|s5G=dF`YoW1yxfsuicOG-M-SAE_Dudm;JZQXH0Raw}`KpM!l z_E~)M{wD?=Y3Zw%D*ylJi3~SnU}R+F=DK&Y8py4$abp(~XZp{;ASc5IwE6w}?`(pC z%mRX^FTDbC|NZ;__xpDyMh1r62kry;WyKDX;=C3Hl1|og@7{l3u;?^UiVc8c=Ps~v&W3fS6{G;iZL<#XB6b;`2GuM3B&UjpML)QBO=VTWqp!?r3NE2 zGlPt#@~fv!K(~a38Ua-Z3i0gUl?mjYIbI0T?d_^8D$Mov-M7`N&v6I|{pRGKw&*fY zosoeQ!`DwtA3pv7a)bmqt*sPUI5~lA3lnJ|dE@4*pWl8kN~kFwTpyvPEd1-&-$TbA ziHL9m!|w0j|G^OpHf_Jj$Ri~qD$J3epyTVMDJ9AO_WifhXC8NU?>lkoA)An}^xVlj UTYWrk1C3+wboFyt=akR{08;p)x&QzG literal 0 HcmV?d00001 diff --git a/chars/9c.png b/chars/9c.png new file mode 100644 index 0000000000000000000000000000000000000000..b979459618bf4397846e95036009907c16e635ac GIT binary patch literal 440 zcmeAS@N?(olHy`uVBq!ia0vp^AT|#N6Og>Zx%)c<17p3Xi(^Q|9L5sH?thFN($b9o z|NFSAWX2m9YKy)9^z-Do=aub;UcCIuz{tSF^q(O!&T!RCKYcCHlcyi?^RPzvYn<8= zEh5Oy@SlM}PFwl&+qVBddNkC<7@3$PWrZKyss?f=^aij?NHUokO7d{CUA*+{#?4pk zqN4Bram-n91?Ui4E5$#bKeLDkasoMQY|KootW3--Km-5$0UF96E6e}?*H5Nvx84Fd zni}H1UYbDXvobS=c&hHeSr~Z7mt(-5OGUNvvP9-m8Ydx0-gQn zPAv-y6Pu6_3j-s_A&d-+>;eKoF3M9U`uzL%KPhd+-~WuP9GombIUwNRV6Muu%u6+9 zW@ap{+_GoiZFXT1pg7PcjAlj>)diM18lvyse@jYRxnnPc6Ok2+`IZymn&6V PK}LAG`njxgN@xNACUlWU literal 0 HcmV?d00001 diff --git a/main.py b/main.py new file mode 100644 index 0000000..f907f6e --- /dev/null +++ b/main.py @@ -0,0 +1,105 @@ +from typing import List, Tuple +import math +import requests +import urllib3 +import tkinter as tk +from PIL import ImageGrab + +# Ignore insercure SSL ceritifcate warning since it is not relevant here +urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) + +class SimpleOCR: + """ Class to convert image captured from the game to text """ + def __init__(self): + # An array of size 11 (digits 0-9 and no digit) x 120 (10 x 12 pixels) target grayscale data of the digits + # The array at i-th index corresponds to the grayscale values of digit i (eg: target_digits[3] are the grayscale values for 3) + # except for 10th index where the grayscale value is for blank (no digit) + self.target_digits = [[25, 24, 51, 163, 217, 204, 140, 29, 23, 24, 24, 50, 212, 236, 192, 231, 238, 175, 23, 23, 25, 152, 238, 114, 0, 58, 235, 238, 75, 21, 35, 229, 238, 22, 13, 24, 184, 238, 165, 15, 68, 238, 230, 0, 22, 24, 134, 238, 201, 7, 93, 238, 220, 1, 25, 25, 115, 238, 228, 3, 104, 238, 233, 2, 22, 23, 101, 238, 218, 1, 80, 238, 238, 15, 23, 23, 111, 238, 192, 2, 51, 238, 238, 69, 22, 25, 137, 238, 147, 4, 24, 185, 238, 172, 18, 32, 206, 238, 51, 9, 25, 76, 229, 238, 200, 208, 238, 150, 0, 19, 25, 24, 65, 173, 222, 194, 119, 2, 9, 24], [21, 21, 21, 46, 213, 238, 81, 21, 21, 21, 21, 21, 39, 205, 238, 238, 66, 15, 21, 21, 22, 35, 198, 233, 238, 238, 66, 15, 21, 21, 22, 57, 222, 87, 238, 238, 66, 15, 21, 21, 22, 22, 35, 2, 238, 238, 66, 15, 21, 21, 22, 22, 22, 20, 238, 238, 66, 15, 21, 21, 22, 22, 22, 22, 238, 238, 66, 15, 21, 21, 22, 22, 22, 22, 238, 238, 66, 15, 21, 21, 22, 22, 22, 22, 238, 238, 66, 15, 21, 21, 22, 22, 22, 24, 238, 238, 69, 15, 21, 21, 22, 22, 22, 45, 238, 238, 92, 15, 21, 21, 22, 22, 22, 138, 238, 238, 188, 23, 21, 21], [22, 23, 106, 188, 222, 219, 170, 60, 21, 22, 22, 156, 238, 223, 172, 224, 238, 224, 48, 22, 63, 238, 221, 12, 2, 39, 230, 238, 126, 19, 96, 238, 218, 22, 21, 22, 192, 238, 157, 10, 45, 237, 238, 99, 20, 22, 214, 238, 114, 7, 24, 91, 118, 0, 13, 86, 238, 225, 19, 11, 23, 23, 15, 12, 34, 209, 238, 97, 1, 19, 23, 23, 23, 24, 167, 238, 155, 0, 13, 22, 23, 23, 24, 136, 238, 189, 8, 8, 23, 21, 25, 25, 111, 238, 210, 21, 6, 24, 55, 44, 25, 92, 235, 238, 211, 190, 194, 209, 238, 30, 74, 231, 238, 238, 238, 238, 238, 238, 215, 0], [20, 184, 238, 238, 238, 238, 238, 238, 148, 21, 21, 217, 209, 194, 193, 212, 238, 191, 7, 9, 27, 70, 2, 2, 9, 194, 224, 33, 4, 19, 21, 20, 16, 21, 140, 238, 79, 1, 17, 20, 22, 22, 21, 78, 237, 146, 0, 14, 20, 21, 22, 22, 38, 216, 238, 235, 181, 65, 20, 20, 21, 22, 45, 96, 134, 218, 238, 233, 57, 20, 21, 22, 21, 19, 14, 32, 217, 238, 149, 16, 21, 49, 78, 22, 22, 22, 167, 238, 168, 8, 84, 225, 213, 29, 22, 31, 222, 238, 119, 6, 74, 233, 238, 217, 172, 212, 238, 204, 13, 10, 22, 61, 163, 217, 229, 199, 131, 17, 3, 20], [22, 21, 21, 21, 160, 238, 238, 132, 21, 21, 22, 22, 21, 58, 236, 238, 238, 122, 10, 21, 23, 22, 21, 172, 233, 188, 238, 122, 10, 21, 23, 22, 69, 238, 139, 160, 238, 122, 10, 21, 23, 22, 183, 229, 22, 163, 238, 122, 10, 22, 23, 82, 238, 130, 1, 166, 238, 122, 10, 21, 22, 194, 226, 17, 10, 167, 238, 122, 10, 21, 93, 238, 213, 160, 166, 215, 238, 200, 163, 23, 188, 238, 238, 238, 238, 238, 238, 238, 238, 10, 23, 5, 0, 0, 0, 160, 238, 122, 0, 0, 23, 23, 23, 22, 22, 179, 238, 132, 10, 21, 22, 22, 22, 22, 38, 223, 238, 194, 16, 22], [22, 65, 238, 238, 238, 238, 238, 238, 69, 19, 21, 86, 238, 218, 189, 189, 189, 189, 17, 16, 23, 106, 238, 119, 2, 5, 4, 4, 4, 19, 22, 127, 238, 95, 10, 22, 22, 21, 21, 21, 23, 147, 238, 195, 154, 129, 51, 21, 21, 21, 23, 168, 238, 238, 238, 238, 235, 133, 21, 21, 22, 22, 8, 19, 60, 172, 238, 238, 83, 21, 22, 23, 22, 22, 20, 20, 202, 238, 147, 14, 22, 59, 79, 22, 22, 23, 170, 238, 159, 8, 93, 229, 202, 29, 22, 34, 226, 238, 109, 7, 78, 233, 238, 217, 172, 215, 238, 198, 9, 11, 22, 61, 163, 213, 229, 200, 126, 15, 4, 20], [22, 21, 21, 26, 143, 228, 208, 142, 37, 21, 21, 21, 29, 189, 238, 217, 74, 3, 10, 19, 23, 22, 155, 238, 203, 22, 2, 15, 21, 21, 22, 79, 238, 221, 27, 3, 19, 21, 21, 21, 23, 171, 238, 136, 176, 226, 195, 96, 21, 21, 32, 235, 238, 228, 188, 212, 238, 238, 88, 21, 62, 238, 238, 108, 1, 10, 166, 238, 194, 14, 85, 238, 237, 19, 12, 22, 67, 238, 234, 7, 64, 238, 238, 17, 21, 23, 59, 238, 220, 0, 30, 221, 238, 128, 21, 23, 134, 238, 156, 2, 22, 110, 238, 238, 189, 177, 237, 220, 31, 7, 22, 22, 85, 182, 224, 207, 155, 25, 2, 18], [56, 238, 238, 238, 238, 238, 238, 238, 238, 73, 83, 228, 184, 174, 174, 174, 210, 238, 189, 0, 81, 37, 1, 5, 6, 6, 197, 238, 82, 4, 22, 16, 19, 22, 22, 82, 238, 210, 4, 13, 23, 22, 21, 21, 21, 179, 238, 106, 2, 21, 23, 23, 22, 22, 58, 238, 230, 16, 11, 21, 22, 23, 22, 22, 150, 238, 152, 1, 19, 21, 22, 23, 22, 34, 228, 238, 60, 8, 21, 20, 22, 22, 22, 113, 238, 213, 1, 16, 21, 21, 23, 23, 22, 201, 238, 152, 2, 22, 21, 21, 23, 23, 67, 238, 238, 112, 8, 22, 21, 21, 22, 22, 147, 238, 238, 91, 12, 22, 21, 21], [21, 21, 81, 182, 224, 221, 173, 66, 20, 21, 21, 97, 237, 227, 158, 192, 238, 228, 53, 20, 23, 201, 238, 83, 1, 9, 208, 238, 119, 18, 22, 228, 238, 67, 14, 21, 162, 238, 117, 10, 23, 166, 238, 177, 37, 69, 220, 221, 27, 11, 23, 38, 178, 238, 238, 238, 220, 43, 2, 19, 22, 53, 172, 238, 215, 231, 238, 211, 54, 21, 36, 219, 238, 81, 0, 17, 178, 238, 191, 17, 103, 238, 220, 0, 15, 23, 86, 238, 237, 9, 89, 238, 237, 55, 23, 23, 137, 238, 199, 0, 33, 204, 238, 232, 177, 196, 238, 235, 74, 3, 22, 40, 135, 206, 230, 213, 164, 52, 0, 15], [21, 21, 88, 181, 223, 209, 161, 42, 20, 21, 21, 113, 238, 222, 172, 221, 238, 219, 37, 20, 38, 227, 238, 37, 2, 27, 209, 238, 135, 19, 86, 238, 194, 0, 19, 21, 122, 238, 191, 9, 103, 238, 199, 4, 21, 21, 119, 238, 218, 4, 66, 238, 238, 75, 22, 25, 192, 238, 193, 2, 22, 177, 238, 234, 180, 203, 232, 238, 158, 4, 22, 32, 142, 210, 216, 141, 191, 238, 77, 7, 22, 22, 21, 9, 2, 96, 238, 211, 4, 14, 23, 23, 22, 23, 89, 235, 236, 63, 2, 21, 23, 23, 29, 137, 235, 238, 108, 0, 16, 21, 22, 70, 179, 218, 219, 71, 0, 12, 21, 21], [23, 22, 23, 23, 22, 22, 22, 22, 22, 22, 23, 23, 22, 22, 22, 22, 22, 22, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 22, 22, 22, 23, 23, 24, 24, 24, 23, 23, 22, 22, 22, 23, 23, 24, 24, 24, 24, 24, 23, 22, 22, 24, 24, 24, 24, 24, 24, 24, 24, 23, 22, 24, 24, 24, 24, 24, 24, 24, 24, 24, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24]] + + def get_sample(self) -> Tuple[List[int], List[int], List[int]]: + """ Returns the observed grayscale data of each digit from the screenshot taken """ + # Takes a screenshot of the in game creep score counter region + sample_im = ImageGrab.grab(bbox=(1920 - 138, 5, 1920 - 108, 25)).convert('L') + + # Crops the screenshot to 3 regions each representing one digit of 0-9 or blank + return \ + list(sample_im.crop((0, 3, 10, 15)).getdata()), \ + list(sample_im.crop((10, 3, 20, 15)).getdata()), \ + list(sample_im.crop((20, 3, 30, 15)).getdata()) + + def compute_mse(self, observed_data: List[int], predicted_data: List[int]) -> float: + """ Returns the mean squared error (MSE) between the observed values and predicted values """ + mse: float = 0.0 + num_points: int = len(observed_data) + + for i in range(num_points): + mse += math.pow(observed_data[i] - predicted_data[i], 2) + + return math.sqrt(mse / num_points) + + def most_similar_digit(self, digit_data: List[int]) -> str: + """ Returns the most similar digit by finding a target digit with smallest MSE with the digit given """ + computed_mse: List[float] = [0.0] * len(self.target_digits) + + # Calcuate the MSE between the digit given and each of the possible target digits + for i in range(len(self.target_digits)): + computed_mse[i] = self.compute_mse(digit_data, self.target_digits[i]) + + # Find the target digit with smallest MSE + most_similar_digit = str(computed_mse.index(min(computed_mse))) + + return most_similar_digit if most_similar_digit != '10' else '' + +class Overlay: + """ Class to create and handle the Tkinter overlay """ + def __init__(self): + self.root = tk.Tk() + self.ocr = SimpleOCR() + + self.cs_per_minute_text = tk.StringVar() + self.cs_per_minute_text.set("cs/min: 0.00") + + def set_attributes(self): + """ Set the attributes of the overlay """ + self.root.wm_attributes("-fullscreen", True) + self.root.wm_attributes("-topmost", True) + self.root.wm_attributes("-alpha", 0.8) + self.root.wm_attributes("-transparentcolor", "#f0f0f0") + + def build(self): + """ Add the widgets to the overlay """ + frame = tk.Frame(width=160, height=60, pady=60, padx=10) + frame.pack(side=tk.TOP, anchor=tk.NE) + label = tk.Label(frame, textvariable=self.cs_per_minute_text, fg="white", font=("Terminal", 11)) + label.pack() + + def update_counter(self): + """ Updates the CS Per Minute counter text in the overlay """ + digit_1, digit_2, digit_3 = self.ocr.get_sample() + total_cs: str = self.ocr.most_similar_digit(digit_1) + self.ocr.most_similar_digit(digit_2) + self.ocr.most_similar_digit(digit_3) + + try: + # Fetch the game elapsed time in seconds from the game's LiveClientAPI + game_time: float = requests.get("https://127.0.0.1:2999/liveclientdata/gamestats", verify=False).json()["gameTime"] / 60 + cs_per_min: float = int(total_cs) / game_time + + # Update the overlay text + self.cs_per_minute_text.set("cs/min: " + format(cs_per_min, ".2f")) + + except Exception: + # If failed to fetch game_time -> no game is in progress + self.cs_per_minute_text.set("cs/min: 0.00") + + # Run again the next second + self.root.after(1000, self.update_counter) + + def loop(self): + """ Starts the Tkinter main loop """ + self.root.after(1000, self.update_counter) + self.root.mainloop() + +if __name__ == "__main__": + overlay = Overlay() + overlay.set_attributes() + overlay.build() + overlay.loop() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..d92f358163a62612810b8b74f3c6c861c5f7e73a GIT binary patch literal 636 zcmZuu+fKqj5IxT(eo6_p2Jpdu@D~;>uyIS*vP9wI)pKS_>x0=q(wTFcnV;`~gn~T= z1Y{iW%(uh>4_NcR#y#%vikAI?h#h}I)Wp=p2q*Mr#2u(I;6!{ug(G@?b*v@wuBPJb zg|XJg+Tl#}naK8!`(|>Fc%xFVUc+i*tVrE#`o+|@^y|zw5Fe=Mj7LkSoSLL#wv#EX zSXcg~)iarzEsYuG`JN`n7wac_ewu<3O8usAVgE>VIVV#Z3@6NLbomccaqB(bJGm8i z-BYD-8xdRM&slu(j0+RUtKkjAD6D7#pG^0tr(D|V2e+$k84>E%%yi4{d@1g!*W!!F m)@F&8#&xxOzqUJQpSqf6Ro2GRYNxL4*S)fr`E++F%&xz<)n6R| literal 0 HcmV?d00001 diff --git a/test.png b/test.png new file mode 100644 index 0000000000000000000000000000000000000000..abb2440e911691422dcb936428c3ca88970e5e02 GIT binary patch literal 1182 zcmV;P1Y!G$P)J5(S!8(L%9dOVyw;5+78I7?5hT)LjeN17yyF+0AN4|0|b~`WErWYn{N^zkgfwF-7SMt=g7n~w+LV`O#>xP`L+kg*&rTO89Ek&yubx{1XWM2aa0WQAlVV(3V*HWE-{wtUC1q7{yFtj*_6NR zybYJEt_oFMx!k|G`oaAN&mB8x%&#Y6*Vv`P$(d_1$eRuX$<#0A>~j z#PF?TMqd7Hps98s;r#{rXiQ9Hei!iBK37GVpCn1j$moxwJ9r(y%v?t@8oM5f0U#n>*QLx% zFyiqffXJ<}sL$nf7)2K78Dv0))&AHL%PN;B4?ep45A;h6jh@ z0P40>80U>19zW4TLddCl6wI_6rl-IO?lLz`nzOR8=26)&0+cdAalau9hRe7cbe> zdu>?Ga*=(OH&y6~NF))B0uYL-&X{2g1&H*-#AGz8kB>7m$&#emB!``ZOk~zDIU1jg zM)hQpgb=DKyIdp*vU|NeO{oDkGNCCoHI