Skip to content

Commit

Permalink
added support for x64
Browse files Browse the repository at this point in the history
  • Loading branch information
ExtReMLapin committed Jun 18, 2019
1 parent e91fad3 commit 7cea842
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions garrysmod/garrysmod/lua/autorun/TrackIR.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
if CLIENT then
if not file.Exists("garrysmod/lua/bin/gmcl_TrackIR_win32.dll", "BASE_PATH") then
print("no trackir m8")
return
end

local DPS = 66 -- tickrate
local draw = draw
local math = math
Expand All @@ -12,8 +7,6 @@ if CLIENT then
local data1
local data2



local function RotateVector(vector, angle)
local _vector = vector
local _angle = angle
Expand All @@ -22,6 +15,8 @@ if CLIENT then
return _vector
end


-- no ugly view like 'max is 130, min is 130, more like max is 130 but every ° over 130 is reducted (1/exp function)
local function Nicerlimit(var, minu, maxi)
local _maxi = maxi + 0.2 * maxi -- +20%
local _minu = minu + 0.2 * minu
Expand All @@ -47,7 +42,8 @@ if CLIENT then
var = math.min(math.max(_minu, var), _maxi)

return var
end -- no ugly view like 'max is 130, min is 130, more like max is 130 but every ° over 130 is reducted (1/exp function)
end


local function TrackIR_View(ply, origin, angles, fov, znear, zfar)
local vehicle = LocalPlayer():GetVehicle()
Expand All @@ -60,12 +56,10 @@ if CLIENT then
return
end


if LocalPlayer():GetNWEntity("ScriptedVehicle", NULL) ~= NULL and string.StartWith(LocalPlayer():GetNetworkedEntity("ScriptedVehicle", NULL):GetClass(), "sent_") then
return
end


local ang1 = Angle(Nicerlimit(TrackIR.Pitch / 90, -70, 70), 0, 0)
local ang2 = Angle(0, Nicerlimit(TrackIR.Yaw / 90, -130, 130), 0)
local ang3 = Angle(0, 0, Nicerlimit(-1 * TrackIR.Roll / 90 + -2 * TrackIR.X / 900, -70, 70))
Expand All @@ -81,9 +75,9 @@ if CLIENT then
view.drawviewer = false

return view
end -- for the players
end

local function TrackIR_View2(ply, origin, angles, fov, znear, zfar)
local function TrackIR_View2(ply, origin, angles, fov, znear, zfar)
local ang1 = Angle(Nicerlimit(TrackIR.Pitch / 90, -70, 70) + angles[1], 0, 0)
local ang2 = Angle(0, Nicerlimit(TrackIR.Yaw / 90, -130, 130) + angles[2], 0)
local ang3 = Angle(0, 0, Nicerlimit(-1 * TrackIR.Roll / 90 + -2 * TrackIR.X / 900, -70, 70))
Expand All @@ -99,9 +93,11 @@ if CLIENT then
view.drawviewer = false

return view
end -- for the players
end


local function TrackIR_Timer()
-- the best way would be to make it 60/120 times per sec. (i mean, not 60-120, it's 60 OR 120 (depending of the trackir device))
TrackIR.Update()
TrackIR.Pitch = TrackIR.get_Pitch() or 0
TrackIR.Yaw = TrackIR.get_Yaw() or 0
Expand All @@ -113,33 +109,32 @@ if CLIENT then
Var_TrackIR_Angle_APIRAW = Angle(Nicerlimit(TrackIR.Pitch / 90, -70, 70), Nicerlimit(TrackIR.Yaw / 90, -130, 130), Nicerlimit(-1 * TrackIR.Roll / 90 + -2 * TrackIR.X / 900, -70, 70))
data1 = Angle(Nicerlimit(TrackIR.Roll / 90 + TrackIR.X / 900, -70, 70), -1 * Nicerlimit(TrackIR.Pitch / 90, -70, 70), Nicerlimit(TrackIR.Yaw / 90, -130, 130))
data2 = -1 * TrackIR.X / 500
end -- the best way would be to make it 60/120 times per sec. (i mean, not 60-120, it's 60 OR 120 (depending of the trackir device))
end


hook.Add("HUDPaint", "TrackIr real aiming", function()
-- don't get lost my friend, know where you're aiming ;)
local tr = (util.TraceLine(util.GetPlayerTrace(LocalPlayer())).HitPos):ToScreen()
draw.RoundedBox(0, tr.x - 6, tr.y - 6, 12, 12, Color(0, 0, 0, 105))
draw.RoundedBox(4, tr.x - 5, tr.y - 5, 10, 10, Color(64, 134, 195, 170))
end) -- don't get lost my friend, know where you're aiming ;)
end)


hook.Add("Tick", "fix *AfxGetMainWnd()", function()
-- wait until gmod has focus, else *AfxGetMainWnd() from the module will return NULL (0x0)
if not system.HasFocus() then
return
end

require("TrackIR") -- no shit sherlock

TrackIR.Pitch = 0
TrackIR.Roll = 0
TrackIR.Yaw = 0
TrackIR.X = 0
TrackIR.Y = 0
TrackIR.Z = 0


local _data1
local _data2


hook.Add("Think", "TrackIRupdate", TrackIR_Timer)

timer.Create("TrackIR_Net", 1 / DPS, 0, function()
Expand All @@ -165,7 +160,8 @@ if CLIENT then
end

hook.Remove("Tick", "fix *AfxGetMainWnd()") -- everything has been executed, don't let it get executed twice
end) -- wait until gmod has focus, else *AfxGetMainWnd() from the module will return NULL (0x0)
end)

end

if SERVER then
Expand Down
Binary file modified garrysmod/garrysmod/lua/bin/gmcl_TrackIR_win32.dll
Binary file not shown.
Binary file not shown.

0 comments on commit 7cea842

Please sign in to comment.