示例#1
0
 internal void CreateEffects(GameObject currentPlatform)
 {
     if (_beatmapObjectCallbackController != null)
     {
         foreach (PairRotationEventEffect descriptor in currentPlatform.GetComponentsInChildren <PairRotationEventEffect>(true))
         {
             LightPairRotationEventEffect rotEffect = descriptor.gameObject.AddComponent <LightPairRotationEventEffect>();
             rotEffect.SetField("_beatmapObjectCallbackController", _beatmapObjectCallbackController);
             rotEffect.SetField("_eventL", (BeatmapEventType)descriptor.eventL);
             rotEffect.SetField("_eventR", (BeatmapEventType)descriptor.eventR);
             rotEffect.SetField("_rotationVector", descriptor.rotationVector);
             rotEffect.SetField("_transformL", descriptor.tranformL);
             rotEffect.SetField("_transformR", descriptor.tranformR);
             rotEffect.SetField("_useZPositionForAngleOffset", descriptor.useZPositionForAngleOffset);
             rotEffect.SetField("_overrideRandomValues", descriptor.overrideRandomValues);
             rotEffect.SetField("_randomStartRotation", descriptor.randomStartRotation);
             rotEffect.SetField("_randomDirection", descriptor.randomDirection);
             PlatformManager.SpawnedComponents.Add(rotEffect);
         }
         foreach (var descriptor in currentPlatform.GetComponentsInChildren <RotationEventEffect>(true))
         {
             LightRotationEventEffect rotEffect = descriptor.gameObject.AddComponent <LightRotationEventEffect>();
             rotEffect.SetField("_beatmapObjectCallbackController", _beatmapObjectCallbackController);
             rotEffect.SetField("_event", (BeatmapEventType)descriptor.eventType);
             rotEffect.SetField("_rotationVector", descriptor.rotationVector);
             rotEffect.SetField("_transform", descriptor.transform);
         }
     }
 }
        static bool Prefix(LightPairRotationEventEffect __instance)
        {
            ReflectionUtil.GetPrivateField <BeatmapObjectCallbackController>(__instance, "_beatmapObjectCallbackController").beatmapEventDidTriggerEvent += __instance.HandleBeatmapObjectCallbackControllerBeatmapEventDidTrigger;

            Vector3 rotationVector = ReflectionUtil.GetPrivateField <Vector3>(__instance, "_rotationVector");
            float   startRotation  = ReflectionUtil.GetPrivateField <float>(__instance, "_startRotation");

            ReflectionUtil.GetPrivateField <Transform>(__instance, "_transformL").transform.Rotate(rotationVector, startRotation, Space.Self);
            ReflectionUtil.GetPrivateField <Transform>(__instance, "_transformR").transform.Rotate(rotationVector, -startRotation, Space.Self);

            // Since LightPairRotationEventEffect.RotationData is a private internal member, we need to get its type dynamically.
            Type RotationData = Type.GetType("LightPairRotationEventEffect+RotationData,MainAssembly");

            var rotationDataL = Activator.CreateInstance(RotationData);

            rotationDataL.SetField("enabled", false);
            rotationDataL.SetField("rotationSpeed", 0f);
            rotationDataL.SetField("startRotation", ReflectionUtil.GetPrivateField <Transform>(__instance, "_transformL").localRotation); // This is the fix.
            rotationDataL.SetField("transform", ReflectionUtil.GetPrivateField <Transform>(__instance, "_transformL"));
            ReflectionUtil.SetPrivateField(__instance, "_rotationDataL", rotationDataL);

            var rotationDataR = Activator.CreateInstance(RotationData);

            rotationDataR.SetField("enabled", false);
            rotationDataR.SetField("rotationSpeed", 0f);
            rotationDataR.SetField("startRotation", ReflectionUtil.GetPrivateField <Transform>(__instance, "_transformR").localRotation); // This is the fix.
            rotationDataR.SetField("transform", ReflectionUtil.GetPrivateField <Transform>(__instance, "_transformR"));
            ReflectionUtil.SetPrivateField(__instance, "_rotationDataR", rotationDataR);

            __instance.enabled = false;

            return(false);
        }
        private static bool Prefix(LightPairRotationEventEffect __instance, BeatmapEventType ____eventL, float startRotationOffset, float direction, object ____rotationDataL, object ____rotationDataR)
        {
            BeatmapEventData beatmapEventData = LightPairRotationEventEffectHandleBeatmapObjectCallbackControllerBeatmapEventDidTrigger.LastLightPairRotationEventEffectData;

            bool isLeftEvent = beatmapEventData.type == ____eventL;

            if (_rotationDataType == null)
            {
                GetRotationData();
            }

            object rotationData = isLeftEvent ? ____rotationDataL : ____rotationDataR;

            ChromaLaserSpeedEventData chromaData = (ChromaLaserSpeedEventData)ChromaEventDatas[beatmapEventData];

            bool  lockPosition   = chromaData.LockPosition;
            float precisionSpeed = chromaData.PreciseSpeed;
            int?  dir            = chromaData.Direction;

            switch (dir)
            {
            case 0:
                direction = isLeftEvent ? -1 : 1;
                break;

            case 1:
                direction = isLeftEvent ? 1 : -1;
                break;
            }

            // Actual lasering
            Transform  transform          = (Transform)_rotationDataType.GetField("transform").GetValue(rotationData);
            Quaternion startRotation      = (Quaternion)_rotationDataType.GetField("startRotation").GetValue(rotationData);
            float      startRotationAngle = (float)_rotationDataType.GetField("startRotationAngle").GetValue(rotationData);
            Vector3    rotationVector     = __instance.GetField <Vector3, LightPairRotationEventEffect>("_rotationVector");

            if (beatmapEventData.value == 0)
            {
                _rotationDataType.GetField("enabled").SetValue(rotationData, false);
                if (!lockPosition)
                {
                    _rotationDataType.GetField("rotationAngle").SetValue(rotationData, startRotationAngle);
                    transform.localRotation = startRotation * Quaternion.Euler(rotationVector * startRotationAngle);
                }
            }
            else if (beatmapEventData.value > 0)
            {
                _rotationDataType.GetField("enabled").SetValue(rotationData, true);
                _rotationDataType.GetField("rotationSpeed").SetValue(rotationData, precisionSpeed * 20f * direction);
                if (!lockPosition)
                {
                    float rotationAngle = startRotationOffset + startRotationAngle;
                    _rotationDataType.GetField("rotationAngle").SetValue(rotationData, rotationAngle);
                    transform.localRotation = startRotation * Quaternion.Euler(rotationVector * rotationAngle);
                }
            }

            return(false);
        }
示例#4
0
        public static LightPairRotationEffectController Create(LightPairRotationEventEffect baseEffect)
        {
            BeatmapEventType eventToggleRandomize = Helper.GetValue <BeatmapEventType>(baseEffect, "_switchOverrideRandomValuesEvent");
            BeatmapEventType eventL = Helper.GetValue <BeatmapEventType>(baseEffect, "_eventL");
            BeatmapEventType eventR = Helper.GetValue <BeatmapEventType>(baseEffect, "_eventR");

            bool  useZOffset   = Helper.GetValue <bool>(baseEffect, "_useZPositionForAngleOffset");
            float zOffsetScale = Helper.GetValue <float>(baseEffect, "_zPositionAngleOffsetScale");

            Vector3 rotationVector = Helper.GetValue <Vector3>(baseEffect, "_rotationVector");

            object baseRotationDataL = Helper.GetValue <object>(baseEffect, "_rotationDataL");
            object baseRotationDataR = Helper.GetValue <object>(baseEffect, "_rotationDataR");

            Transform  transformL          = Helper.GetValue <Transform>(baseRotationDataL, "transform");
            Quaternion startRotationL      = Helper.GetValue <Quaternion>(baseRotationDataL, "startRotation");
            float      startRotationAngleL = Helper.GetValue <float>(baseRotationDataL, "startRotationAngle");

            Transform  transformR          = Helper.GetValue <Transform>(baseRotationDataR, "transform");
            Quaternion startRotationR      = Helper.GetValue <Quaternion>(baseRotationDataR, "startRotation");
            float      startRotationAngleR = Helper.GetValue <float>(baseRotationDataR, "startRotationAngle");

            RotationData rotationDataL = new RotationData(transformL, startRotationL, startRotationAngleL);
            RotationData rotationDataR = new RotationData(transformR, startRotationR, startRotationAngleR);

            LightPairRotationEffectController controller = new GameObject("TwitchFXLightPairRotationEffectController").AddComponent <LightPairRotationEffectController>();

            controller.eventToggleRandomize = eventToggleRandomize;
            controller.eventL         = eventL;
            controller.eventR         = eventR;
            controller.transform      = baseEffect.transform;
            controller.useZOffset     = useZOffset;
            controller.zOffsetScale   = zOffsetScale;
            controller.rotationVector = rotationVector;
            controller.rotationL      = rotationDataL;
            controller.rotationR      = rotationDataR;

            return(controller);
        }
        public void CreateEffects(GameObject go)
        {
            if (lightRotationEffects == null)
            {
                lightRotationEffects = new List <LightPairRotationEventEffect>();
            }
            if (effectDescriptors == null)
            {
                effectDescriptors = new List <PairRotationEventEffect>();
            }

            PairRotationEventEffect[] localDescriptors = go.GetComponentsInChildren <PairRotationEventEffect>(true);

            if (localDescriptors == null)
            {
                return;
            }

            // Get the BeatmapObjectCallbackController floating in the level.
            BeatmapObjectCallbackController beatmapObjectCallbackController = ((BeatmapObjectCallbackController[])GameObject.FindObjectsOfType(typeof(BeatmapObjectCallbackController)))[0];

            foreach (PairRotationEventEffect effectDescriptor in localDescriptors)
            {
                LightPairRotationEventEffect rotEvent = effectDescriptor.gameObject.AddComponent <LightPairRotationEventEffect>();
                PlatformManager.SpawnedComponents.Add(rotEvent);

                // Convert the effect descriptor into the behaviour from the base game.
                ReflectionUtil.SetPrivateField(rotEvent, "_eventL", (BeatmapEventType)effectDescriptor.eventTypeL);
                ReflectionUtil.SetPrivateField(rotEvent, "_eventR", (BeatmapEventType)effectDescriptor.eventTypeR);
                ReflectionUtil.SetPrivateField(rotEvent, "_rotationVector", effectDescriptor.rotationVector);
                ReflectionUtil.SetPrivateField(rotEvent, "_overrideRandomValues", false);
                ReflectionUtil.SetPrivateField(rotEvent, "_startRotation", effectDescriptor.startRotation);
                ReflectionUtil.SetPrivateField(rotEvent, "_transformL", effectDescriptor.transformL);
                ReflectionUtil.SetPrivateField(rotEvent, "_transformR", effectDescriptor.transformR);
                ReflectionUtil.SetPrivateField(rotEvent, "_beatmapObjectCallbackController", beatmapObjectCallbackController);
                lightRotationEffects.Add(rotEvent);
                effectDescriptors.Add(effectDescriptor);
            }
        }
        protected override void Init()
        {
            if (rotationEffects.Length == 0 && pairRotationEffects.Length == 0)
            {
                return;
            }

            bocc.beatmapEventDidTriggerEvent += OnBeatmapEvent;

            rotationEffectControllers     = new LightRotationEffectController[rotationEffects.Length];
            pairRotationEffectControllers = new LightPairRotationEffectController[pairRotationEffects.Length];

            for (int i = 0; i < rotationEffects.Length; i++)
            {
                LightRotationEventEffect rotationEffect = rotationEffects[i];

                onPipedBeatmapEvent += rotationEffect.HandleBeatmapObjectCallbackControllerBeatmapEventDidTrigger;
                bocc.beatmapEventDidTriggerEvent -= rotationEffect.HandleBeatmapObjectCallbackControllerBeatmapEventDidTrigger;

                LightRotationEffectController rotationEffectController = LightRotationEffectController.Create(rotationEffect);
                CustomBeatmapEventManager.onCustomBeatmapEvent += rotationEffectController.OnEvent;

                rotationEffectControllers[i] = rotationEffectController;
            }

            for (int i = 0; i < pairRotationEffects.Length; i++)
            {
                LightPairRotationEventEffect pairRotationEffect = pairRotationEffects[i];

                onPipedBeatmapEvent += pairRotationEffect.HandleBeatmapObjectCallbackControllerBeatmapEventDidTrigger;
                bocc.beatmapEventDidTriggerEvent -= pairRotationEffect.HandleBeatmapObjectCallbackControllerBeatmapEventDidTrigger;

                LightPairRotationEffectController pairRotationEffectController = LightPairRotationEffectController.Create(pairRotationEffect);
                CustomBeatmapEventManager.onCustomBeatmapEvent += pairRotationEffectController.OnEvent;

                pairRotationEffectControllers[i] = pairRotationEffectController;
            }
        }
示例#7
0
#pragma warning disable SA1313 // Parameter names should begin with lower-case letter
        private static bool Prefix(LightPairRotationEventEffect __instance, BeatmapEventType ____eventL, float startRotationOffset, float direction, object ____rotationDataL, object ____rotationDataR)
#pragma warning restore SA1313 // Parameter names should begin with lower-case letter
        {
            BeatmapEventData beatmapEventData = LightPairRotationEventEffectHandleBeatmapObjectCallbackControllerBeatmapEventDidTrigger.LastLightPairRotationEventEffectData;

            bool isLeftEvent = beatmapEventData.type == ____eventL;

            if (_rotationDataType == null)
            {
                GetRotationData();
            }

            object rotationData = isLeftEvent ? ____rotationDataL : ____rotationDataR;

            if (beatmapEventData is CustomBeatmapEventData customData)
            {
                dynamic dynData = customData.customData;

                bool lockPosition = ((bool?)Trees.at(dynData, LOCKPOSITION)).GetValueOrDefault(false);

                float precisionSpeed = ((float?)Trees.at(dynData, PRECISESPEED)).GetValueOrDefault(beatmapEventData.value);

                int?dir = (int?)Trees.at(dynData, DIRECTION);
                dir = dir.GetValueOrDefault(-1);

                switch (dir)
                {
                case 0:
                    direction = isLeftEvent ? -1 : 1;
                    break;

                case 1:
                    direction = isLeftEvent ? 1 : -1;
                    break;
                }

                // Actual lasering
                Transform  transform          = (Transform)_rotationDataType.GetField("transform").GetValue(rotationData);
                Quaternion startRotation      = (Quaternion)_rotationDataType.GetField("startRotation").GetValue(rotationData);
                float      startRotationAngle = (float)_rotationDataType.GetField("startRotationAngle").GetValue(rotationData);
                Vector3    rotationVector     = __instance.GetField <Vector3, LightPairRotationEventEffect>("_rotationVector");
                if (beatmapEventData.value == 0)
                {
                    _rotationDataType.GetField("enabled").SetValue(rotationData, false);
                    if (!lockPosition)
                    {
                        _rotationDataType.GetField("rotationAngle").SetValue(rotationData, startRotationAngle);
                        transform.localRotation = startRotation * Quaternion.Euler(rotationVector * startRotationAngle);
                    }
                }
                else if (beatmapEventData.value > 0)
                {
                    _rotationDataType.GetField("enabled").SetValue(rotationData, true);
                    _rotationDataType.GetField("rotationSpeed").SetValue(rotationData, precisionSpeed * 20f * direction);
                    if (!lockPosition)
                    {
                        float rotationAngle = startRotationOffset + startRotationAngle;
                        _rotationDataType.GetField("rotationAngle").SetValue(rotationData, rotationAngle);
                        transform.localRotation = startRotation * Quaternion.Euler(rotationVector * rotationAngle);
                    }
                }

                return(false);
            }

            return(true);
        }