Esempio n. 1
0
        private void UpdateSaberColor(SaberModelController saberModel, Color color)
        {
            SetSaberGlowColor[]     glowColors     = Helper.GetValue <SetSaberGlowColor[]>(saberModel, "_setSaberGlowColors");
            SetSaberFakeGlowColor[] fakeGlowColors = Helper.GetValue <SetSaberFakeGlowColor[]>(saberModel, "_setSaberFakeGlowColors");

            Color      trailTintColor = Helper.GetValue <SaberModelController.InitData>(saberModel, "_initData").trailTintColor;
            SaberTrail trail          = Helper.GetValue <SaberTrail>(saberModel, "_saberTrail");

            Helper.SetValue <Color>(trail, "_color", (color * trailTintColor).linear);

            TubeBloomPrePassLight light = Helper.GetValue <TubeBloomPrePassLight>(saberModel, "_saberLight");

            if (light != null)
            {
                light.color = color;
            }

            foreach (SetSaberGlowColor glowColor in glowColors)
            {
                glowColor.SetColors();
            }

            foreach (SetSaberFakeGlowColor fakeGlowColor in fakeGlowColors)
            {
                fakeGlowColor.SetColors();
            }
        }
Esempio n. 2
0
        public void Init(Saber saber, ColorManager colorManager)
        {
            Logger.log.Debug($"Replacing Trail for '{saber?.saberType}'");

            if (gameObject.name != "LeftSaber" && gameObject.name != "RightSaber")
            {
                Logger.log.Warn("Parent not LeftSaber or RightSaber");
                Destroy(this);
            }

            if (!saber)
            {
                Logger.log.Warn("Saber not found");
                Destroy(this);
            }

            IEnumerable<SaberTrailRenderer> trails = Resources.FindObjectsOfTypeAll<SaberTrailRenderer>();
            foreach (SaberTrailRenderer trail in trails)
            {
                ReflectionUtil.SetField(trail, "_trailWidth", 0f);
            }

            SaberTrail oldtrail = Resources.FindObjectsOfTypeAll<SaberModelContainer>().FirstOrDefault()
                ?.GetField<SaberModelController, SaberModelContainer>("_saberModelControllerPrefab")
                ?.GetField<SaberTrail, SaberModelController>("_saberTrail");

            if (oldtrail)
            {
                try
                {
                    oldTrailRendererPrefab = ReflectionUtil.GetField<SaberTrailRenderer, SaberTrail>(oldtrail, "_trailRendererPrefab");
                }
                catch (Exception ex)
                {
                    Logger.log.Error(ex);
                    throw;
                }

                if (Configuration.OverrideTrailLength)
                {
                    Length = (int)(Length * Configuration.TrailLength);
                    Granularity = (int)(Granularity * Configuration.TrailLength);
                }

                if (Length > 1)
                {
                    trail = gameObject.AddComponent<CustomWeaponTrail>();
                    trail.Init(oldTrailRendererPrefab, colorManager, PointStart, PointEnd, TrailMaterial, TrailColor, Length, Granularity, MultiplierColor, colorType);
                }

                //if (Configuration.OverrideTrailLength) SetGranularity((int)(trail.GetField<int, CustomWeaponTrail>("_granularity") * Configuration.TrailLength));
            }
            else
            {
                Logger.log.Debug($"Trail not found for '{saber?.saberType}'");
                Destroy(this);
            }
        }
Esempio n. 3
0
 private static void Prefix(SaberTrail __instance, ref float ____trailDuration, ref int ____granularity, ref float ____whiteSectionMaxDuration)
 {
     if (Configuration.Trail.TweakEnabled && Configuration.Trail.TrailEnabled)
     {
         ____trailDuration           = Configuration.Trail.Duration / 1000f;
         ____granularity             = Configuration.Trail.Granularity;
         ____whiteSectionMaxDuration = Configuration.Trail.WhiteSectionDuration / 1000f;
         Logger.log.Info("Successfully modified trails!");
     }
 }
Esempio n. 4
0
            private BSMColorManager(SaberModelController bsm, SaberType saberType)
            {
                _bsm       = bsm;
                _saberType = saberType;

                _saberWeaponTrail       = _saberWeaponTrailAccessor(ref _bsm);
                _trailTintColor         = _initDataAccessor(ref _bsm).trailTintColor;
                _setSaberGlowColors     = _setSaberGlowColorsAccessor(ref _bsm);
                _setSaberFakeGlowColors = _SetSaberFakeGlowAccessor(ref _bsm);
                _saberLight             = _saberLightAccessor(ref _bsm);
            }
Esempio n. 5
0
            internal void SetSaberColor(Color?colorNullable)
            {
                if (colorNullable.HasValue)
                {
                    Color color = colorNullable.Value;

                    SaberColorOverride[(int)_saberType] = color;

                    SaberTrail saberTrail = _saberWeaponTrail;
                    _saberTrailColorAccessor(ref saberTrail) = (color * _trailTintColor).linear;
                    if (_saberLight != null)
                    {
                        _saberLight.color = color;
                    }

                    foreach (SetSaberGlowColor setSaberGlowColor in _setSaberGlowColors)
                    {
                        setSaberGlowColor.SetColors();
                    }

                    foreach (SetSaberFakeGlowColor setSaberFakeGlowColor in _setSaberFakeGlowColors)
                    {
                        setSaberFakeGlowColor.SetColors();
                    }

                    SaberBurnMarkArea saberBurnMarkArea = SaberBurnMarkArea;
                    LineRenderer[]    lineRenderers     = _lineRenderersAccessor(ref saberBurnMarkArea);
                    lineRenderers[(int)_saberType].startColor = color;
                    lineRenderers[(int)_saberType].endColor   = color;

                    // Custom sabers suck
                    IEnumerable <Renderer> renderers = _bsm.transform.parent.GetComponentsInChildren <Renderer>();
                    foreach (Renderer renderer in renderers)
                    {
                        foreach (Material material in renderer.materials)
                        {
                            if (material.HasProperty("_Color"))
                            {
                                if (material.HasProperty("_CustomColors"))
                                {
                                    if (material.GetFloat("_CustomColors") > 0)
                                    {
                                        material.SetColor("_Color", color);
                                    }
                                }
                                else if ((material.HasProperty("_Glow") && material.GetFloat("_Glow") > 0) || (material.HasProperty("_Bloom") && material.GetFloat("_Bloom") > 0))
                                {
                                    material.SetColor("_Color", color);
                                }
                            }
                        }
                    }
                }
            }
 public MainTrailHandler(GameObject gameobject, SaberTrail backupTrail) : this(gameobject)
 {
     _backupTrail = backupTrail;
 }
        private IEnumerator PreloadDefaultSabers()
        {
            bool   isSceneLoaded = false;
            string sceneName;

            try
            {
                sceneName = "StandardGameplay";
                Logger.log.Debug($"Loading {sceneName} scene");
                var loadScene = SceneManager.LoadSceneAsync("StandardGameplay", LoadSceneMode.Additive);
                while (!loadScene.isDone)
                {
                    yield return(null);
                }

                sceneName = "GameCore";
                Logger.log.Debug($"Loading {sceneName} scene");
                loadScene = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
                while (!loadScene.isDone)
                {
                    yield return(null);
                }

                isSceneLoaded = true;
                Logger.log.Debug("Loaded!");

                yield return(new WaitForSecondsRealtime(0.1f));

                SaberModelController saber = Resources.FindObjectsOfTypeAll <SaberModelController>().FirstOrDefault();
                trail = saber.GetComponent <SaberTrail>();

                Logger.log.Debug("Got sabers!");

                Logger.log.Debug($"Saber: {saber.name}, GameObj: {saber.gameObject.name}, {saber.ToString()}");

                // Left Saber
                defaultLeftSaber = Instantiate(saber).gameObject;
                DestroyImmediate(defaultLeftSaber.GetComponent <SaberModelController>());
                DestroyImmediate(defaultLeftSaber.GetComponentInChildren <ConditionalMaterialSwitcher>());
                foreach (var c in defaultLeftSaber.GetComponentsInChildren <SetSaberGlowColor>())
                {
                    DestroyImmediate(c);
                }

                DontDestroyOnLoad(defaultLeftSaber);
                defaultLeftSaber.transform.SetParent(this.transform);
                defaultLeftSaber.gameObject.name         = "LeftSaber";
                defaultLeftSaber.transform.localPosition = Vector3.zero;
                defaultLeftSaber.transform.localRotation = Quaternion.identity;
                defaultLeftSaber.AddComponent <DummySaber>();
                //defaultLeftSaber.name = "defaultleft";

                // Right Saber
                defaultRightSaber = Instantiate(saber).gameObject;
                DestroyImmediate(defaultRightSaber.GetComponent <SaberModelController>());
                DestroyImmediate(defaultRightSaber.GetComponentInChildren <ConditionalMaterialSwitcher>());
                foreach (var c in defaultRightSaber.GetComponentsInChildren <SetSaberGlowColor>())
                {
                    DestroyImmediate(c);
                }

                DontDestroyOnLoad(defaultRightSaber);
                defaultRightSaber.transform.SetParent(this.transform);
                defaultRightSaber.gameObject.name         = "RightSaber";
                defaultRightSaber.transform.localPosition = Vector3.zero;
                defaultRightSaber.transform.localRotation = Quaternion.identity;
                defaultRightSaber.AddComponent <DummySaber>();
                //defaultRightSaber.name = "defaultright";

                Logger.log.Debug("Finished! Got default sabers! Setting active state");

                if (defaultLeftSaber)
                {
                    Logger.log.Debug("Found default left saber");
                    defaultLeftSaber.SetActive(false);
                }

                if (defaultRightSaber)
                {
                    Logger.log.Debug("Found default right saber");
                    defaultRightSaber.SetActive(false);
                }

                if (defaultLeftSaber && defaultRightSaber)
                {
                    // Add them as the first Object in the list, replacing the empty version.
                    CustomSaberData defaultSabers = new CustomSaberData(defaultLeftSaber.gameObject, defaultRightSaber.gameObject);
                    SaberAssetLoader.CustomSabers[0] = defaultSabers;
                    isCompleted = true;
                }
            }
            finally
            {
                if (isSceneLoaded)
                {
                    sceneName = "StandardGameplay";
                    Logger.log.Debug($"Unloading {sceneName}");
                    SceneManager.UnloadSceneAsync(sceneName);

                    sceneName = "GameCore";
                    Logger.log.Debug($"Unloading {sceneName}");
                    SceneManager.UnloadSceneAsync(sceneName);
                }
            }
        }
        public void GenerateHandheldSaberPreview()
        {
            if (Environment.CommandLine.Contains("fpfc"))
            {
                return;
            }
            var customSaber = SaberAssetLoader.CustomSabers[SaberAssetLoader.SelectedSaber];

            if (customSaber == null || !customSaber.Sabers || preview == null)
            {
                return;
            }
            var controllers  = Resources.FindObjectsOfTypeAll <VRController>();
            var sabers       = CreatePreviewSaber(customSaber.Sabers, preview.transform, sabersPos);
            var colorManager = Resources.FindObjectsOfTypeAll <ColorManager>().First();

            try
            {
                foreach (var collider in sabers.GetComponentsInChildren <Collider>())
                {
                    collider.enabled = false;
                }

                if (_trailRendererPrefab == null)
                {
                    foreach (var trail in Resources.FindObjectsOfTypeAll <SaberTrail>())
                    {
                        _trailRendererPrefab = trail.GetField <SaberTrailRenderer, SaberTrail>("_trailRendererPrefab");
                        if (_trailRendererPrefab != null)
                        {
                            break;
                        }
                    }
                }

                foreach (var controller in controllers)
                {
                    if (controller?.node == XRNode.LeftHand)
                    {
                        _leftController = controller;

                        leftSaber = sabers?.transform.Find("LeftSaber").gameObject;
                        if (!leftSaber)
                        {
                            continue;
                        }

                        leftSaber.transform.parent   = controller.transform;
                        leftSaber.transform.position = controller.transform.position;
                        leftSaber.transform.rotation = controller.transform.rotation;

                        leftSaber.SetActive(true);

                        var trails = leftSaber.GetComponentsInChildren <CustomTrail>();

                        if (trails == null || trails.Count() == 0)
                        {
                            SaberTrail saberTrail = leftSaber.AddComponent <SaberTrail>();
                            saberTrail.SetField("_trailRenderer", Instantiate(_trailRendererPrefab, Vector3.zero, Quaternion.identity));
                            saberTrail.Setup(colorManager.ColorForSaberType(SaberType.SaberA), _leftMovementData);

                            if (Configuration.OverrideTrailLength)
                            {
                                float length = Configuration.TrailLength * 30;
                                saberTrail.SetField("_trailDuration", length / 75f);
                            }
                            if (Configuration.DisableWhitestep)
                            {
                                saberTrail.SetField("_whiteSectionMaxDuration", 0f);
                            }
                        }
                        else
                        {
                            foreach (var trail in trails)
                            {
                                trail.Length = (Configuration.OverrideTrailLength) ? (int)(trail.Length * Configuration.TrailLength) : trail.Length;
                                if (trail.Length < 2 || !trail.PointStart || !trail.PointEnd)
                                {
                                    continue;
                                }
                                {
                                    leftSaber.AddComponent <CustomWeaponTrail>().Init(_trailRendererPrefab, colorManager, trail.PointStart, trail.PointEnd,
                                                                                      trail.TrailMaterial, trail.TrailColor, trail.Length, trail.Granularity, trail.MultiplierColor, trail.colorType);
                                }
                            }
                        }

                        leftSaber.AddComponent <DummySaber>();

                        controller.transform.Find("MenuHandle")?.gameObject.SetActive(false);
                    }
                    else if (controller?.node == XRNode.RightHand)
                    {
                        _rightController = controller;

                        rightSaber = sabers?.transform.Find("RightSaber").gameObject;
                        if (!rightSaber)
                        {
                            continue;
                        }

                        rightSaber.transform.parent   = controller.transform;
                        rightSaber.transform.position = controller.transform.position;
                        rightSaber.transform.rotation = controller.transform.rotation;

                        rightSaber.SetActive(true);

                        var trails = rightSaber.GetComponentsInChildren <CustomTrail>();

                        if (trails == null || trails.Count() == 0)
                        {
                            SaberTrail saberTrail = rightSaber.AddComponent <SaberTrail>();
                            saberTrail.SetField("_trailRenderer", Instantiate(_trailRendererPrefab, Vector3.zero, Quaternion.identity));
                            saberTrail.Setup(colorManager.ColorForSaberType(SaberType.SaberB), _rightMovementData);

                            if (Configuration.OverrideTrailLength)
                            {
                                float length = Configuration.TrailLength * 30;
                                saberTrail.SetField("_trailDuration", length / 75f);
                            }
                            if (Configuration.DisableWhitestep)
                            {
                                saberTrail.SetField("_whiteSectionMaxDuration", 0f);
                            }
                        }
                        else
                        {
                            foreach (var trail in trails)
                            {
                                trail.Length = (Configuration.OverrideTrailLength) ? (int)(trail.Length * Configuration.TrailLength) : trail.Length;
                                if (trail.Length < 2 || !trail.PointStart || !trail.PointEnd)
                                {
                                    continue;
                                }
                                rightSaber.AddComponent <CustomWeaponTrail>().Init(_trailRendererPrefab, colorManager, trail.PointStart, trail.PointEnd,
                                                                                   trail.TrailMaterial, trail.TrailColor, trail.Length, trail.Granularity, trail.MultiplierColor, trail.colorType);
                            }
                        }

                        rightSaber.AddComponent <DummySaber>();

                        controller.transform.Find("MenuHandle")?.gameObject.SetActive(false);
                    }
                    if (leftSaber && rightSaber)
                    {
                        break;
                    }
                }
                StartCoroutine(HideOrShowPointer());
            }
            catch (Exception e)
            {
                Logger.log.Error($"Error generating saber preview\n{e.Message} - {e.StackTrace}");
            }
            finally
            {
                DestroyGameObject(ref sabers);
            }
        }