Ejemplo n.º 1
0
        private static void GetVRLookInput(ILContext il)
        {
            ILCursor c = new ILCursor(il);

            //Remove target info from stack. Why is it pushed so early anyway?
            c.GotoNext(x =>
                       x.MatchLdflda(typeof(RoR2.CameraModes.CameraModeBase.CameraModeContext), "targetInfo")
                       );

            c.Index--;

            c.RemoveRange(2);

            //Fixing brtrue label
            c.GotoNext(x =>
                       x.MatchLdloca(6)
                       );

            ILLabel sussyLabel = c.IncomingLabels.First();

            c.Index++;
            sussyLabel.Target = c.Next;
            c.Index--;

            //Replacing input vectors
            c.Remove();
            c.Index++;
            c.RemoveRange(6);

            c.EmitDelegate <Func <Rewired.Player, Vector2> >((player) =>
            {
                return(ModConfig.InitialMotionControlsValue ? Vector2.zero : new Vector2(player.GetAxisRaw(ModConfig.SnapTurn.Value ? 26 : 2), ModConfig.TempLockedCameraPitchValue ? 0 : player.GetAxisRaw(3)));
            });
            c.Emit(OpCodes.Stloc_S, (byte)6);

            c.Remove();
            c.Index++;
            c.RemoveRange(6);

            c.EmitDelegate <Func <Rewired.Player, Vector2> >((player) =>
            {
                return(new Vector2(player.GetAxisRaw(16), ModConfig.TempLockedCameraPitchValue ? 0 : player.GetAxisRaw(17)));
            });
            c.Emit(OpCodes.Stloc_S, (byte)7);

            int startIndex = c.Index;

            //Removing aim assist
            c.GotoNext(x => x.MatchCall(typeof(RoR2.CameraModes.CameraModePlayerBasic), "PerformAimAssist"));

            c.Index -= 3;

            c.RemoveRange(4);

            //Adding snap turn code
            c.GotoNext(x => x.MatchLdflda(typeof(RoR2.CameraModes.CameraModeBase.CollectLookInputResult), "lookInput"));

            c.Index--;

            int snapTurnIndex = c.Index;

            c.Emit(OpCodes.Ldarg_3);
            c.Emit(OpCodes.Ldloc_S, (byte)6);
            c.Emit(OpCodes.Ldloc_S, (byte)7);
            c.EmitDelegate <Func <Vector2, Vector2, Vector2> >((mouseVector, joystickVector) =>
            {
                wasTurningLeft  = isTurningLeft;
                wasTurningRight = isTurningRight;

                isTurningLeft  = joystickVector.x < -0.8f;
                isTurningRight = joystickVector.x > 0.8f;

                if (!ModConfig.MotionControlsEnabled)
                {
                    isTurningLeft  = isTurningLeft || mouseVector.x < -0.8f;
                    isTurningRight = isTurningRight || mouseVector.x > 0.8f;
                }

                Vector2 result = Vector2.zero;

                if (justTurnedLeft)
                {
                    result.x = -ModConfig.SnapTurnAngle.Value;
                }
                else if (justTurnedRight)
                {
                    result.x = ModConfig.SnapTurnAngle.Value;
                }

                if ((isTurningLeft || isTurningRight) && timeSinceLastSnapTurn <= ModConfig.SnapTurnHoldDelay.Value)
                {
                    timeSinceLastSnapTurn += Time.deltaTime;
                }
                else
                {
                    timeSinceLastSnapTurn = 0;
                }

                return(result);
            });
            c.Emit(OpCodes.Stfld, typeof(RoR2.CameraModes.CameraModeBase.CollectLookInputResult).GetField("lookInput"));

            //Removing sensitivity modifications;
            var labels = il.GetIncomingLabels(c.Next);

            c.RemoveRange(24);

            foreach (var label in labels)
            {
                label.Target = c.Next;
            }

            //Adding jump after smooth turn code
            ILLabel endLabel = c.MarkLabel();

            c.Index = snapTurnIndex;

            c.Emit(OpCodes.Br_S, endLabel);

            //Adding snap turn condition and jump to snap turn
            ILLabel snapTurnLabel = c.MarkLabel();

            c.Index = startIndex;

            c.EmitDelegate <Func <bool> >(() => { return(ModConfig.SnapTurn.Value); });

            c.Emit(OpCodes.Brtrue_S, snapTurnLabel);
        }