-- ModuleScript Viewmodel (via bytefall decompiler) -- Decompiled using ByteFall -- discord.gg/pHTnqmmWzk local module: {[any]: any} = {} module.__index = module local runService: RunService = game:GetService("RunService") local replicatedStorage: ReplicatedStorage = game:GetService("ReplicatedStorage") local userInputService: UserInputService = game:GetService("UserInputService") local players: Players = game:GetService("Players") local maid = require(replicatedStorage.Classes.Maid) local spring = require(replicatedStorage.Classes.Spring) local sound = require(replicatedStorage.ReservesCommon.Domain.Sound) local lerpValue = require(replicatedStorage.Classes.LerpValue) local router = require(replicatedStorage.Common.UI.Router) local fusion = require(replicatedStorage.Packages.Fusion) local replicaController = require(replicatedStorage.Common.Client.Controllers.ReplicaController) local cameraController = require(replicatedStorage.ReservesCommon.Client.Controllers.CameraController) local gameSettings = require(replicatedStorage.GameSettings) local footstepModule = require(replicatedStorage.Modules.FootstepModule) local CurrentCamera: Camera = workspace.CurrentCamera function module.new() local object = setmetatable({}, module) object._maid = maid.new() local v20 = spring.new() local v21 = spring.new(5, 50, 4, 4) local v22 = spring.new(5, 50, 4, 4) local v23 = spring.new() local v24 = spring.new(3, 80, 6, 10) object.Springs = { _sway = v20, _movement = { Offset = v21, Angle = v22 }, _cameraBobbing = v23, _recoil = v24 } v24 = lerpValue.new(Enum.EasingStyle.Quart, Enum.EasingDirection.Out) v23 = lerpValue.new(Enum.EasingStyle.Quart, Enum.EasingDirection.Out) object.LerpValues = { _stance = v24, _equip = v23 } object.LerpValues._equip:Lerp(1, 0) object.Crouching = false object.Proning = false object.Sprinting = false object.LastFootstep = time() object.Debounce = false object._runtime = 0 object._framerate = 0.016666666666666666 object.PhaseShift = 0 object.Frequency = 1 object._character = players.LocalPlayer.Character object._characterRootPart = object._character:WaitForChild("HumanoidRootPart") object._replica = replicaController:WaitForReplica("PlayerData") object._cameraBobbingEnabled = object._replica.Data.Settings.CameraBobbing object._maid:GiveTask(object._replica:OnSet({ "Settings", "CameraBobbing" }, function() object._cameraBobbingEnabled = object._replica.Data.Settings.CameraBobbing end)) object._maid:GiveTask(players.LocalPlayer.CharacterAdded:Connect(function() object:Destroy() end)) object._updateConnection = runService.RenderStepped:Connect(function(deltaTime: number) object:_update(deltaTime) end) object._maid:GiveTask(object._updateConnection) object._viewmodel = nil object:SetModel(replicatedStorage.ViewmodelOld:Clone()) local object_maid = object._maid v22 = router.Scope:Observer(router.State) object_maid:GiveTask(v22:onBind(function() if object._viewmodel then if fusion.peek(router.State).Name ~= "Gameplay" then object._viewmodel.Parent = replicatedStorage if object.CurrentItem and object.CurrentItem._inputContext then object.CurrentItem._inputContext:SetEnabled(false) return end elseif object.CurrentItem then object._viewmodel.Parent = CurrentCamera if object.CurrentItem._inputContext then object.CurrentItem._inputContext:SetEnabled(true) end end return end end)) v22 = object._character.Humanoid.Animator:LoadAnimation(object._viewmodel.CharacterAnimations.Crawl) v21 = object._character.Humanoid.Animator:LoadAnimation(object._viewmodel.CharacterAnimations.CrouchWalk) object.LoadedAnimations = { Viewmodel = {}, Character = { Crawl = v22, CrouchWalk = v21 } } setmetatable(object.LoadedAnimations.Character, { __index = function(_, _) end, __newindex = function(p4, p5, p6) rawset(p4, p5, p6) end }) return object end function module.SetModel(p7, p8) if p7._viewmodel then p7._viewmodel:Destroy() p7._viewmodel = nil end p7._viewmodel = p8 p7._viewmodel.CameraBone.Transparency = 1 local RightHandColor = p7._character.RightHand.Color p7._viewmodel.LeftArm.LeftArm.Color = p7._character.LeftHand.Color p7._viewmodel.LeftArm.LeftArm.Color = RightHandColor p7._viewmodel.Parent = replicatedStorage end function module._getBobbing(p9, p10, p11, p12) local sine = math.sin(((p12 or p9._runtime) + p9.PhaseShift) * 3.141592653589793 * p10) return (p11 or 1) * sine end function module._startAnimationCycle(p13, p14) if p13._idleAnimationSpeedChanged then p13._idleAnimationSpeedChanged:Disconnect() end if p13._animationStoppedConnection then p13._animationStoppedConnection:Disconnect() end if p13._character.Humanoid.MoveDirection.Magnitude > 0 then p14:AdjustSpeed(1) else p14:AdjustSpeed(0) end p13._idleAnimationSpeedChanged = p13._character.Humanoid.Running:Connect(function(p15) if p15 > 0 then p14:AdjustSpeed(1) return end p14:AdjustSpeed(0) end) p13._animationStoppedConnection = p14.Stopped:Connect(function() if p13._idleAnimationSpeedChanged then p13._idleAnimationSpeedChanged:Disconnect() end p13._animationStoppedConnection:Disconnect() end) end local function isGameplay() return fusion.peek(router.State).Name == "Gameplay" end function module.Equip(p16, currentItem) if p16.Debounce then return false end if fusion.peek(router.State).Name ~= "Gameplay" then warn("[Viewmodel]: Cannot equip item in non-gameplay state") return false end p16.Debounce = true if p16.CurrentItem then p16.CurrentItem:Destroy() end p16.CurrentItem = currentItem p16._viewmodel.Parent = CurrentCamera p16.CurrentItem.Model.Parent = p16._viewmodel for _, v in pairs(p16._viewmodel.AnimationController.Animator:GetPlayingAnimationTracks()) do v:Stop() end p16._viewmodel.ViewmodelRootPart.Item.Part1 = p16.CurrentItem.Model.PrimaryPart p16._viewmodel:PivotTo(CurrentCamera.CFrame) p16.LoadedAnimations.Viewmodel.Idle = p16.CurrentItem.LoadedAnimations.Viewmodel.Idle p16.LoadedAnimations.Viewmodel.Idle:Play() p16.LoadedAnimations.Character.Idle = p16.CurrentItem.LoadedAnimations.Character.Idle p16:ToggleSprint(p16.Sprinting) p16.LoadedAnimations.Character.Crawl:Stop() p16.LoadedAnimations.Character.Crawl = p16._character.Humanoid.Animator:LoadAnimation(p16._viewmodel.CharacterAnimations.Crawl) if p16.Proning then p16.LoadedAnimations.Character.Idle:Stop() p16.LoadedAnimations.Character.CrouchWalk:Stop() p16.LoadedAnimations.Character.Crawl:Play() p16:_startAnimationCycle(p16.LoadedAnimations.Character.Crawl) elseif p16.Crouching then p16.LoadedAnimations.Character.Idle:Stop() p16.LoadedAnimations.Character.Crawl:Stop() p16.LoadedAnimations.Character.CrouchWalk:Play() p16:_startAnimationCycle(p16.LoadedAnimations.Character.CrouchWalk) else p16.LoadedAnimations.Character.Idle:Play() end p16._maid:GiveTask(p16._viewmodel) local connection = nil connection = p16.LerpValues._equip:Lerp(0, 0.5).Completed:Connect(function(p18) connection:Disconnect() if p16._equipConnection == connection and p16.CurrentItem == currentItem then p16._equipConnection = nil if p18 == Enum.PlaybackState.Cancelled then return end p16.Debounce = false if currentItem.SetAimIntent then currentItem:SetAimIntent(currentItem.WantsAim) end return end end) p16._equipConnection = connection return true end function module.Unequip(p19, p20: boolean) if p20 == nil then p20 = false end if p19.Debounce and not p20 then return false end if not p19.CurrentItem then return false end if not p19.CurrentItem:IsReady() and not p20 then return false end p19.Debounce = true if p19._equipConnection then p19._equipConnection:Disconnect() p19._equipConnection = nil end if not p20 then p19.LerpValues._equip:Lerp(1, 1, Enum.EasingStyle.Quart, Enum.EasingDirection.In).Completed:Wait() else p19.LerpValues._equip:Lerp(1, 0) end if p19.CurrentItem then p19.CurrentItem:Destroy() end p19._viewmodel.Parent = replicatedStorage p19._updateConnection = nil p19.CurrentItem = nil p19.LoadedAnimations.Character.Idle:Stop() p19.LoadedAnimations.Character.Crawl:Stop() p19.LoadedAnimations.Character.CrouchWalk:Stop() p19.LoadedAnimations.Character.Crawl = p19._character.Humanoid.Animator:LoadAnimation(p19._viewmodel.CharacterAnimations.Crawl) p19.LoadedAnimations.Character.CrouchWalk = p19._character.Humanoid.Animator:LoadAnimation(p19._viewmodel.CharacterAnimations.CrouchWalk) if p19.Proning then p19.LoadedAnimations.Character.Crawl:Play() p19:_startAnimationCycle(p19.LoadedAnimations.Character.Crawl) elseif p19.Crouching then p19.LoadedAnimations.Character.CrouchWalk:Play() p19:_startAnimationCycle(p19.LoadedAnimations.Character.CrouchWalk) end p19.Debounce = false return true end local u18 = nil function module._update(p21, p22) p21._runtime = p21._runtime + p22 p21._framerate = p22 local v45 = not p21._characterRootPart.Anchored and p21._characterRootPart.AssemblyLinearVelocity.Magnitude or 0 if fusion.peek(router.Context.IsSeated) then v45 = 0 end local n1 = 1 / (-0.027499999999999997 * v45 + 0.6825) if math.abs(p21.Frequency - n1) > 0.1 then local v47 = p21:_getBobbing(p21.Frequency, 1, p21._runtime) v47 = (math.asin(v47 / 1) - n1 * 3.141592653589793 * p21._runtime) / (3.141592653589793 * n1) if v47 == v47 then p21.PhaseShift = v47 end p21.Frequency = n1 end p21:_getBobbing(2 * p21.Frequency, 1, p21._runtime - p22) p21:_getBobbing(2 * p21.Frequency, 1, p21._runtime) n1 = p21.Frequency * 2 local cosine = math.cos((p21._runtime - p22) * n1 * 3.141592653589793) local n2 = 3.141592653589793 * n1 * cosine local cosine2 = math.cos(p21._runtime * n1 * 3.141592653589793) local n3 = 3.141592653589793 * n1 * cosine2 if n2 > 0 and n3 <= 0 then p21.Springs._movement.Offset.Speed = 4 p21.Springs._movement.Angle.Speed = 4 if v45 > 0.5 and time() - p21.LastFootstep > 0.2 then local v52 = footstepModule:GetTableFromMaterial(p21._character.Humanoid.FloorMaterial) if v52 then local v53 = footstepModule:GetRandomSound(v52) sound.new(v53, p21._characterRootPart.Position, { ApplyDistanceEffects = false, ConnectToAnalyzer = true, Volume = v45 / 240 }):Play() end p21.LastFootstep = time() end end if p21.CurrentItem then local v54: Vector2 = userInputService:GetMouseDelta() local IdleValue = p21.CurrentItem.Model.Offsets.Idle.Value if p21.CurrentItem.AimLerp then IdleValue = IdleValue:Lerp(p21.CurrentItem.Model.Offsets.Aim.Value, p21.CurrentItem.AimLerp.Value) end p21.CurrentItem.Model.Offsets:FindFirstChild("Aim") local v56 = IdleValue:Lerp(CFrame.new(0, -3, 0), p21.LerpValues._equip.Value) local v57 = CurrentCamera.CFrame:VectorToObjectSpace(p21._characterRootPart.AssemblyLinearVelocity) if v45 > 10 then local offset = p21.Springs._movement.Offset local v59 = p21:_getBobbing(p21.Frequency, v45 / 2) local v60 = p21:_getBobbing(p21.Frequency * 2, v45 / 2) local vector3 = Vector3.new(v59, v60, p21:_getBobbing(p21.Frequency, v45 / 10)) offset:Shove(vector3 * p22) local angle = p21.Springs._movement.Angle v60 = p21:_getBobbing(p21.Frequency, v45 / 5) local vector32 = Vector3.new(0, v60, p21:_getBobbing(p21.Frequency, v45 / 4)) angle:Shove(vector32 * p22) else local v64 = p21.Springs._movement.Offset local v65 = p21:_getBobbing(p21.Frequency, v45 / 5) local v66 = p21:_getBobbing(p21.Frequency * 2, v45 / 10) local vector3 = Vector3.new(v65, v66, p21:_getBobbing(p21.Frequency, v45 / 10)) v64:Shove(vector3 * p22) p21.Springs._movement.Angle:Shove(Vector3.new(0, 0, 0) * p22) end if n2 < 0 and n3 >= 0 then p21.Springs._movement.Offset.Speed = 3 p21.Springs._movement.Angle.Speed = 3 end local _sway = p21.Springs._sway local vector3 = Vector3.new(-v54.X / 10 - v57.X / 5, v54.Y / 10, v57.Z / 5) _sway:Shove(vector3 * p22) local pivot = p21._viewmodel:GetPivot() local _viewmodel = p21._viewmodel local currentCameraCFrame: CFrame = CurrentCamera.CFrame local cFrame = CFrame.new(p21.Springs._sway.Position.X, p21.Springs._sway.Position.Y, -p21.Springs._sway.Position.Z) local cFrame2 = CFrame.new(p21.Springs._movement.Offset.Position.X, p21.Springs._movement.Offset.Position.Y, p21.Springs._movement.Offset.Position.Z) local v75 = CFrame.Angles(p21.Springs._movement.Angle.Position.X, p21.Springs._movement.Angle.Position.Y, p21.Springs._movement.Angle.Position.Z) _viewmodel:PivotTo(currentCameraCFrame * cFrame * cFrame2 * v75 * v56) local pivotPosition = pivot.Position local pivot2 = p21._viewmodel:GetPivot() IdleValue = pivotPosition - pivot2.Position v57 = p21._viewmodel.CameraBone.CFrame:ToObjectSpace(p21._viewmodel.PrimaryPart.CFrame) if u18 then local v78, v79, v80 = v57:ToOrientation() local v81, v82, v83 = v57:ToObjectSpace(u18):ToEulerAnglesXYZ() cameraController:SetCameraOffset("CameraBone", CFrame.Angles(v81, v82, -v80)) end u18 = v57 if p21.CurrentItem.Aiming then local lookVector = p21.CurrentItem.Model.PrimaryPart.BarrelAttachment.WorldCFrame.LookVector local v85 = CurrentCamera.CFrame.LookVector local v86 = v85:Dot(lookVector) local v87 = math.acos(v86 / (v85.Magnitude * lookVector.Magnitude)) math.deg(v87) end end if p21._character then p21._character.Humanoid.CameraOffset = (Vector3.new(0, 0.3, 0)):Lerp(Vector3.new(0, -2.6, -2), p21.LerpValues._stance.Value) end if p21._cameraBobbingEnabled or p21.CurrentItem and (p21.CurrentItem.Aiming or p21.CurrentItem.Spotting) then local n4 = v45 * 1 / 350 local _cameraBobbing = p21.Springs._cameraBobbing local v90 = p21:_getBobbing(2 * p21.Frequency, n4) local v91 = p21:_getBobbing(p21.Frequency, n4) local vector3 = Vector3.new(v90, v91, p21:_getBobbing(p21.Frequency, n4)) _cameraBobbing:Shove(vector3 * p22) n4 = p21.Springs._cameraBobbing.Position + p21.Springs._recoil.Position cameraController:SetCameraOffset("ViewmodelSprings", CFrame.Angles(n4.X, n4.Y, n4.Z)) end for _, v in pairs(p21.Springs) do if p22 > 0.1 then break end if v.Offset then v.Offset:Update(p22) v.Angle:Update(p22) else v:Update(p22) end end end function module.LoadAnimation(p23, p24) return (p23._viewmodel.AnimationController.Animator:LoadAnimation(p24)) end function module.ToggleSprint(p25, sprinting) local n1 = 1 if p25.Proning then n1 = gameSettings.ProneSpeedMultiplier elseif p25.Crouching then n1 = gameSettings.CrouchSpeedMultiplier end if not sprinting then if p25.CurrentItem then p25._character.Humanoid.WalkSpeed = (gameSettings.BaseWalkSpeed - p25.CurrentItem.WalkSpeedPenalty) * n1 else p25._character.Humanoid.WalkSpeed = gameSettings.BaseWalkSpeed * n1 end elseif p25.CurrentItem then p25._character.Humanoid.WalkSpeed = (gameSettings.BaseRunSpeed - p25.CurrentItem.RunSpeedPenalty) * n1 else p25._character.Humanoid.WalkSpeed = gameSettings.BaseRunSpeed * n1 end p25.Sprinting = sprinting end function module.Crouch(p27) if p27.Debounce then return end if p27.CurrentItem and p27.CurrentItem.Aiming then return end if p27.CurrentItem and p27.CurrentItem.Reloading then return end local crouching: boolean = not p27.Crouching p27.Crouching = crouching p27.Proning = false if p27._idleAnimationSpeedChanged then p27._idleAnimationSpeedChanged:Disconnect() end if crouching then p27.LerpValues._stance:Lerp(0.5) if p27.CurrentItem then p27.LoadedAnimations.Character.Idle:Stop() end p27.LoadedAnimations.Character.Crawl:Stop() p27.LoadedAnimations.Character.CrouchWalk:Play() p27:_startAnimationCycle(p27.LoadedAnimations.Character.CrouchWalk) replicatedStorage.ReservesCommon.Remotes.SetCharacterStance:FireServer("Crouching") else p27.LerpValues._stance:Lerp(0) p27.LoadedAnimations.Character.CrouchWalk:Stop() if p27.CurrentItem then p27.LoadedAnimations.Character.Idle:Play() end replicatedStorage.ReservesCommon.Remotes.SetCharacterStance:FireServer("Standing") end p27:ToggleSprint(p27.Sprinting) return true end function module.Prone(p28) if p28.Debounce then return end if p28.CurrentItem and p28.CurrentItem.Aiming then return end if p28.CurrentItem and p28.CurrentItem.Reloading then return end local proning: boolean = not p28.Proning p28.Proning = proning p28.Crouching = false if p28._idleAnimationSpeedChanged then p28._idleAnimationSpeedChanged:Disconnect() end if proning then p28.LerpValues._stance:Lerp(1) if p28.CurrentItem then p28.LoadedAnimations.Character.Idle:Stop() end p28.LoadedAnimations.Character.CrouchWalk:Stop() p28.LoadedAnimations.Character.Crawl:Play() p28:_startAnimationCycle(p28.LoadedAnimations.Character.Crawl) replicatedStorage.ReservesCommon.Remotes.SetCharacterStance:FireServer("Proning") else p28.LerpValues._stance:Lerp(0) p28.LoadedAnimations.Character.Crawl:Stop() if p28.CurrentItem then p28.LoadedAnimations.Character.Idle:Play() end replicatedStorage.ReservesCommon.Remotes.SetCharacterStance:FireServer("Standing") end p28:ToggleSprint(p28.Sprinting) return true end function module.Destroy(p29) if p29._equipConnection then p29._equipConnection:Disconnect() p29._equipConnection = nil end p29._maid:Destroy() CurrentCamera.FieldOfView = 70 if p29.CurrentItem then p29.CurrentItem:Destroy() end table.clear(p29.Springs) table.clear(p29.LerpValues) table.clear(p29) table.freeze(p29) end return module