forked from kralicky/Imgur-Screenshots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcl_ss.lua
237 lines (235 loc) · 6.5 KB
/
cl_ss.lua
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
-- Create a Client-ID for your account: https://api.imgur.com/oauth2/addclient
local _rendercap = render.Capture
local _utilb64e = util.Base64Encode
local CLIENT_ID = ""
local capturing = false
local inprogress = false
local fr
function StartCapturing()
if fr then
return
end
fr = vgui.Create( "DFrame" )
fr:MakePopup()
fr:SetPos( 0, 0 )
fr:SetSize( ScrW(), ScrH() )
fr:SetDraggable( false )
fr:SetTitle( " " )
fr:ShowCloseButton( false )
function fr:Paint()
end
function fr:OnClose()
self:Remove()
fr = nil
end
function fr:Think()
fr:SetCursor( "crosshair" )
end
capturing = true
end
function CaptureImage( startpos, endpos )
local v1x = math.min( startpos.x, endpos.x )
local v1y = math.min( startpos.y, endpos.y )
local v2x = math.max( startpos.x, endpos.x )
local v2y = math.max( startpos.y, endpos.y )
local distx = v2x - v1x
local disty = v2y - v1y
local capture = {
format = "jpeg",
h = disty,
w = distx,
quality = 90,
x = v1x,
y = v1y
}
if capture.h <= 5 or capture.w <= 5 then
chat.AddText( Color( 255, 0, 0 ), "Upload failed - Image must be greater than 5x5 px" )
surface.PlaySound( "buttons/button11.wav" )
inprogress = false
return
end
local data1 = render.Capture( capture )
if not data1 then
chat.AddText( Color( 255, 0, 0 ), "render.Capture has been overriden, attempting to bypass..." )
data1 = _rendercap( capture )
if data1 then
chat.AddText( Color( 0, 255, 0 ), "render.Capture override has been bypassed." )
else
chat.AddText( Color( 255, 0, 0 ), "render.Capture override could not be bypassed." )
surface.PlaySound( "buttons/button11.wav" )
return
end
end
local data = util.Base64Encode( data1 )
if not data then
chat.AddText( Color( 255, 0, 0 ), "util.Base64Encode has been overriden, attempting to bypass..." )
data = _utilb64e( data1 )
if data then
chat.AddText( Color( 0, 255, 0 ), "util.Base64Encode override has been bypassed." )
else
chat.AddText( Color( 255, 0, 0 ), "util.Base64Encode override could not be bypassed." )
surface.PlaySound( "buttons/button11.wav" )
return
end
end
local params = {
[ "image" ] = data,
[ "type" ] = "base64"
}
local tab = {
[ "failed" ] =
function()
print( "Upload failed!" )
end,
[ "success" ] =
function( status, response, headers )
local res = util.JSONToTable( response )
inprogress = false
if status == 200 then
SetClipboardText( res.data.link )
surface.PlaySound( "garrysmod/content_downloaded.wav" )
chat.AddText( Color( 0, 255, 0 ), "Upload success - URL Copied to clipboard" )
return
elseif status == 400 then
chat.AddText( Color( 255, 0, 0 ), "Upload failed - Invalid parameters" )
elseif status == 401 then
chat.AddText( Color( 255, 0, 0 ), "Upload failed - Authentication required" )
elseif status == 403 then
chat.AddText( Color( 255, 0, 0 ), "Upload failed - Invalid Authentication" )
elseif status == 404 then
chat.AddText( Color( 255, 0, 0 ), "Upload failed - Resource does not exist" )
elseif status == 429 then
chat.AddText( Color( 255, 0, 0 ), "Upload failed - Application rate limit reached" )
elseif status == 500 then
chat.AddText( Color( 255, 0, 0 ), "Upload failed - Imgur.com is down" )
end
surface.PlaySound( "buttons/button11.wav" )
end,
[ "method" ] =
"post",
[ "url" ] =
"https://api.imgur.com/3/upload",
[ "parameters" ] =
params,
[ "headers" ] =
{
[ "Authorization" ] = "Client-ID " .. CLIENT_ID
}
}
HTTP( tab )
chat.AddText( color_white, "Starting image upload (" .. distx .. "x" .. disty .. ")" )
end
local cappin
local startpos
local endpos
hook.Add( "Think", "CheckMouseClicks", function()
if input.IsKeyDown( KEY_4 ) then
if input.IsKeyDown( KEY_LSHIFT ) and input.IsKeyDown( KEY_LALT ) then
if inprogress == false then
inprogress = true
if not capturing then
StartCapturing()
else
inprogress = false
end
end
end
elseif input.IsKeyDown( KEY_3 ) then
if input.IsKeyDown( KEY_LSHIFT ) and input.IsKeyDown( KEY_LALT ) then
if inprogress == false then
inprogress = true
CaptureImage( Vector( 0, 0 ), Vector( ScrW(), ScrH() ) )
end
end
end
if not capturing then
return
end
if input.IsMouseDown( MOUSE_LEFT ) and not cappin then
cappin = true
local p, p2 = input.GetCursorPos()
startpos = { x = p, y = p2 }
elseif not input.IsMouseDown( MOUSE_LEFT ) and cappin then
cappin = false
local p, p2 = input.GetCursorPos()
endpos = { x = p, y = p2 }
capturing = false
fr:Close()
timer.Simple( 0.1, function()
CaptureImage( startpos, endpos )
startpos = nil
end )
end
end )
function math.n( num )
return -num
end
function surface.DrawVectorRect( pos1, pos2 )
local pos1x = pos1.x
local pos1y = pos1.y
local pos2x = pos2.x
local pos2y = pos2.y
local distx
local disty
if pos1x - pos2x < 0 then
distx = pos2x - pos1x
else
distx = math.n( pos1x - pos2x )
end
if pos1y - pos2y < 0 then
disty = pos2y - pos1y
else
disty = math.n( pos1y - pos2y )
end
if disty < 0 and distx < 0 then
pos1x, pos1y = input.GetCursorPos()
distx, disty = math.abs( distx ), math.abs( disty )
elseif distx < 0 and disty > 0 then
pos1x = input.GetCursorPos()
distx = math.abs( distx )
elseif disty < 0 and distx > 0 then
_, pos1y = input.GetCursorPos()
disty = math.abs( disty )
end
return surface.DrawRect( pos1x, pos1y, distx, disty )
end
function surface.DrawOutlinedVectorRect( pos1, pos2 )
local pos1x = pos1.x
local pos1y = pos1.y
local pos2x = pos2.x
local pos2y = pos2.y
local distx
local disty
if pos1x - pos2x < 0 then
distx = pos2x - pos1x
else
distx = math.n( pos1x - pos2x )
end
if pos1y - pos2y < 0 then
disty = pos2y - pos1y
else
disty = math.n( pos1y - pos2y )
end
if disty < 0 and distx < 0 then
pos1x, pos1y = input.GetCursorPos()
distx, disty = math.abs( distx ), math.abs( disty )
elseif distx < 0 and disty > 0 then
pos1x = input.GetCursorPos()
distx = math.abs( distx )
elseif disty < 0 and distx > 0 then
_, pos1y = input.GetCursorPos()
disty = math.abs( disty )
end
return surface.DrawOutlinedRect( pos1x, pos1y, distx, disty )
end
hook.Add( "HUDPaint", "DrawCap", function()
if capturing then
if startpos then
local px, py = input.GetCursorPos()
surface.SetDrawColor( 0, 0, 0, 220 )
surface.DrawOutlinedVectorRect( Vector( startpos.x, startpos.y ), Vector( px, py ) )
surface.SetDrawColor( 255, 255, 255, 45 )
surface.DrawVectorRect( Vector( startpos.x, startpos.y ), Vector( px, py ) )
end
end
end )