dogeshaders112388

Fake Vr Script!

Jul 17th, 2021
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.43 KB | None | 0 0
  1.  
  2. local plyrs = game:GetService("Players")
  3. local rs = game:GetService("RunService")
  4. local uis = game:GetService("UserInputService")
  5. local cam = workspace.Camera
  6. local headset
  7. local p
  8.  
  9. local bodybinds = {
  10. [Enum.UserInputType.MouseButton1] = "lHand",
  11. [Enum.UserInputType.MouseButton2] = "rHand",
  12. [Enum.KeyCode.W] = Vector3.new(0, 1, 0),
  13. [Enum.KeyCode.A] = Vector3.new(-1, 0, 0),
  14. [Enum.KeyCode.S] = Vector3.new(0, -1, 0),
  15. [Enum.KeyCode.D] = Vector3.new(1, 0, 0),
  16. [Enum.KeyCode.Q] = false,
  17. [Enum.KeyCode.E] = true,
  18. [Enum.KeyCode.LeftShift] = 1,
  19. [Enum.KeyCode.LeftControl] = 2,
  20. [Enum.KeyCode.LeftAlt] = 3
  21. }
  22.  
  23. local gesturebinds = {
  24. "Fist",
  25. "Index",
  26. "Thumb"
  27. }
  28.  
  29. local body = setmetatable({ -- least fav part of the script
  30. lastHand = "",
  31. lHand = {
  32. false,
  33. CFrame.new(-math.cos(math.pi / 4), -0.5, -math.sin(math.pi / 4)),
  34. 0
  35. },
  36. rHand = {
  37. false,
  38. CFrame.new(-math.cos(3 * math.pi / 4), -0.5, -math.sin(3 * math.pi / 4)),
  39. 0
  40. }
  41. }, {
  42. __call = function(t, k, mult)
  43. mult = mult or 1
  44.  
  45. local bind = bodybinds[k]
  46. if bind and headset then
  47. if typeof(bind) == "string" then
  48. t[bind][1] = mult > 0
  49.  
  50. lastHand = mult > 0 and bind or lastHand
  51.  
  52. elseif typeof(bind) == "Vector3" then
  53. headset.StickPosition += bind * mult
  54. elseif typeof(bind) == "boolean" then
  55. headset.Stick2 = mult > 0 and bind and 1 or 0
  56. elseif typeof(bind) == "number" and lastHand:len() > 0 then
  57. local gesture = lastHand:sub(1,1)..gesturebinds[bind]
  58.  
  59. if mult > 0 then
  60. headset[gesture] = headset[gesture] == 0 and 1 or 0
  61. end
  62. end
  63. end
  64. end
  65. })
  66.  
  67. local ind, nc, nind
  68.  
  69. local events = {}
  70.  
  71. local cfs = {
  72. [Enum.UserCFrame.Head] = CFrame.new(0, 0, 0),
  73. [Enum.UserCFrame.LeftHand] = CFrame.new(-1, 0, -1),
  74. [Enum.UserCFrame.RightHand] = CFrame.new(1, 0, -1)
  75.  
  76. }
  77.  
  78. local realVrService = game:GetService("VRService")
  79.  
  80. local fakeVrService = setmetatable({
  81. VREnabled = true,
  82. SetTouchpadMode = function()
  83. end,
  84. RecenterUserHeadCFrame = function()
  85. end,
  86. GetUserCFrameEnabled = function(cf)
  87. return true
  88. end,
  89. GetUserCFrame = function(cf)
  90. return cfs[cf] or CFrame.new(0, 0, 0)
  91. end
  92.  
  93. }, {
  94. __index = function(t, k)
  95. local real = ind(realVrService, k)
  96. if typeof(real) == "RBXScriptSignal" then
  97. events[k] = events[k] or {
  98. Name = k,
  99. Connect = function(t, f)
  100. t.Function = f
  101.  
  102. if t.Name == "UserCFrameChanged" then
  103. headset = debug.getupvalue(t.Function, 1)
  104.  
  105. debug.setupvalue(headset.UpdateHand, 5, setmetatable({}, {
  106. __index = function(t, k)
  107. return cam[k]
  108. end,
  109. __newindex = function(t, k, v)
  110. if cam.CameraType == Enum.CameraType.Scriptable and p then -- unfortunately the first time this will run may or may not be before the cameratype is set
  111. cam.CameraType = Enum.CameraType.Custom
  112. cam.CameraSubject = headset.Head
  113. end
  114.  
  115. if k ~= "CFrame" then -- fuck you
  116. cam[k] = v
  117. end
  118. end
  119. }))
  120.  
  121. cam:GetPropertyChangedSignal("CameraSubject"):connect(function()
  122. if cam.CameraSubject ~= headset.Head then
  123. cam.CameraSubject = headset.Head
  124. end
  125. end)
  126. end
  127.  
  128. end,
  129. Fire = function(t, ...)
  130. return t.Function(...)
  131. end
  132. }
  133.  
  134. return events[k]
  135. end
  136.  
  137. return real
  138. end,
  139. __call = function(t, method, vr, ...)
  140. return t[method](...)
  141. end
  142. })
  143.  
  144. ind = hookmetamethod(game, "__index", function(...)
  145. local t, k = ...
  146.  
  147. local scr = getcallingscript()
  148.  
  149. if t == realVrService and not (scr and ind(scr, "Name") == "CameraModule") then
  150. return fakeVrService[k]
  151. end
  152.  
  153. return ind(...)
  154. end)
  155.  
  156. nc = hookmetamethod(game, "__namecall", function(...)
  157. local t = ...
  158.  
  159. if t == realVrService then
  160. local method = getnamecallmethod()
  161. return fakeVrService(method, ...)
  162. end
  163.  
  164. return nc(...)
  165. end)
  166.  
  167. nind = hookmetamethod(game, "__newindex", function(...)
  168. local t, k, v = ...
  169.  
  170. if t == cam and k == "CFrame" and events.UserCFrameChanged then
  171. events.UserCFrameChanged:Fire(Enum.UserCFrame.Head, CFrame.Angles(cam.CFrame:ToEulerAnglesXYZ()))
  172. end
  173.  
  174. nind(t, k, v)
  175. end)
  176.  
  177.  
  178.  
  179. uis.InputBegan:connect(function(i) -- also least favorite
  180. if headset then
  181. if i.UserInputType == Enum.UserInputType.Keyboard then
  182. body(i.KeyCode)
  183. elseif i.UserInputType == Enum.UserInputType.MouseButton1 or i.UserInputType == Enum.UserInputType.MouseButton2 or i.UserInputType == Enum.UserInputType.MouseButton3 then
  184. body(i.UserInputType)
  185. end
  186. end
  187. end)
  188.  
  189. uis.InputEnded:connect(function(i)
  190. if headset then
  191. if i.UserInputType == Enum.UserInputType.Keyboard then
  192. body(i.KeyCode, -1)
  193. elseif i.UserInputType == Enum.UserInputType.MouseButton1 or i.UserInputType == Enum.UserInputType.MouseButton2 or i.UserInputType == Enum.UserInputType.MouseButton3 then
  194. body(i.UserInputType, -1)
  195. end
  196. end
  197. end)
  198.  
  199. rs:BindToRenderStep(game:GetService("HttpService"):GenerateGUID(), Enum.RenderPriority.Camera.Value - 1, function() -- at least it works
  200. if events.UserCFrameChanged and headset then
  201. local mpos = uis:GetMouseLocation()
  202.  
  203. local cursordir = cam:ViewportPointToRay(mpos.x, mpos.y).Direction
  204.  
  205. body.lHand[3] = body.lHand[1] and math.clamp(body.lHand[3] + 0.05, 0, 1) or body.lHand[3] > 0 and math.clamp(body.lHand[3] - 0.05, 0, 1) or body.lHand[3]
  206. body.rHand[3] = body.rHand[1] and math.clamp(body.rHand[3] + 0.05, 0, 1) or body.rHand[3] > 0 and math.clamp(body.rHand[3] - 0.05, 0, 1) or body.rHand[3]
  207.  
  208. local theta = math.acos(Vector3.new(-1, 0, 0):Dot((cam.CFrame.LookVector * Vector3.new(1, 0, 1)).unit))
  209.  
  210. theta = cam.CFrame.LookVector.z > 0 and (2 * math.pi) - theta or theta
  211.  
  212.  
  213. body.lHand[2] = CFrame.new(-math.cos(theta - (math.pi / 4)), -0.5, -math.sin(theta - (math.pi / 4)))
  214. body.rHand[2] = CFrame.new(-math.cos(theta + (math.pi / 4)), -0.5, -math.sin(theta + (math.pi / 4)))
  215.  
  216. local lcf = ((body.lHand[2]):lerp(CFrame.new(cursordir * 100 / cam.HeadScale), body.lHand[3]))
  217. local rcf = ((body.rHand[2]):lerp(CFrame.new(cursordir * 100 / cam.HeadScale), body.rHand[3]))
  218.  
  219. events.UserCFrameChanged:Fire(Enum.UserCFrame.LeftHand, lcf * CFrame.Angles(cam.CFrame:ToEulerAnglesXYZ()))
  220. events.UserCFrameChanged:Fire(Enum.UserCFrame.RightHand, rcf * CFrame.Angles(cam.CFrame:ToEulerAnglesXYZ()))
  221. end
  222. end)
  223.  
  224. p = plyrs.LocalPlayer or (function()
  225. plyrs:GetPropertyChangedSignal("LocalPlayer"):wait() -- this doesnt return anything for some reason??
  226. return plyrs.LocalPlayer
  227. end)()
Add Comment
Please, Sign In to add comment