예제 #1
0
        internal static void UpdateAmbience(TodAmbientLight TodLightInstance, ref float multiplier)
        {
            if (AmbientLights.lightOverride || Settings.options.alPreset == ALPresets.TLD_Default)
            {
                TodLightInstance.m_AmbientIndoorsDay   = defaultColorDay;
                TodLightInstance.m_AmbientIndoorsNight = defaultColorNight;

                return;
            }

            if (defaultColorDay == null)
            {
                defaultColorDay = TodLightInstance.m_AmbientIndoorsDay;
            }

            if (defaultColorNight == null)
            {
                defaultColorNight = TodLightInstance.m_AmbientIndoorsNight;
            }

            multiplier *= Settings.options.ambienceLevel * AmbientLights.currentLightSet.intMod * AmbientLights.config.data.options.ambient_intensity_multiplier * AmbientLights.globalAmbienceLevel * ALUtils.GetIntensityNightMod();

            TodLightInstance.m_AmbientIndoorsDay   = AmbientLights.currentLightSet.ambientDayColor;
            TodLightInstance.m_AmbientIndoorsNight = AmbientLights.currentLightSet.ambientNightColor;
        }
예제 #2
0
        /****** SETUP ******/

        internal static void AddGameLights()
        {
            if (AmbientLights.config == null || !AmbientLights.config.ready)
            {
                return;
            }

            //if (AmbientLights.debugVer)
            //    Debug.Log("[ambient-lights] InteriorLightingManager initialized.");

            //if (AmbientLights.debugVer)
            //    MelonLoader.MelonLogger.Log("[AL] Game Lights init");

            ALUtils.Log("Game Lights Manager initialized.");

            if (gameLightsList != null)
            {
                gameLightsList.Clear();
            }

            if (gameExtraLightsList != null)
            {
                gameExtraLightsList.Clear();
            }

            if (gameSpotLightsList != null)
            {
                gameSpotLightsList.Clear();
            }

            if (gameExtraLightsColors != null)
            {
                gameExtraLightsColors.Clear();
            }

            if (gameExtraLightsIntensity != null)
            {
                gameExtraLightsIntensity.Clear();
            }

            if (gameWindows != null)
            {
                gameWindows.Clear();
            }

            theSun   = null;
            sunlight = null;

            //if (AmbientLights.debugVer)
            //    MelonLoader.MelonLogger.Log("[AL] Add Game Lights");
            ALUtils.Log("Adding game lights.", false);

            gameLights = new GameObject();

            List <InteriorLightingGroup> lightGroups = new List <InteriorLightingGroup>();

            InteriorLightingGroup[] lightGroupsArr = null;

            if (mngr != null)
            {
                lightGroupsArr = mngr.m_LightGroupList.ToArray();

                foreach (InteriorLightingGroup lightGroup in lightGroupsArr)
                {
                    lightGroups.Add(lightGroup);
                }
            }

            int pCount = 0;
            int sCount = 0;
            int wCount = 0;
            int eCount = 0;
            int lCount = 0;

            //Add sun
            if (!AmbientLights.currentScene.ToLower().Contains("cave") && Settings.options.trueSun)
            {
                //if (AmbientLights.debugVer)
                //    MelonLoader.MelonLogger.Log("[AL] Add sun");
                ALUtils.Log("Creating sun", false);

                theSun                    = new GameObject();
                theSun.name               = "AmbientLightsSun";
                sunlight                  = theSun.AddComponent <Light>();
                sunlight.type             = LightType.Directional;
                sunlight.shadows          = LightShadows.Soft;
                sunlight.shadowStrength   = 1f;
                sunlight.shadowNormalBias = 0;
                sunlight.shadowBias       = 0;
                sunlight.shadowResolution = UnityEngine.Rendering.LightShadowResolution.VeryHigh;

                sunlight.cullingMask &= ~(1 << 7);


                sunlight.intensity = 1f;

                theSun.transform.position = new Vector3(0, 2f, 0);
                sunlight.transform.parent = theSun.transform;

                Vector3 sunRotation = new Vector3(10f, 10f, 0);
                theSun.transform.localRotation = Quaternion.Euler(sunRotation);

                PrepareSceneShadows();
            }

            //Window Lights
            //if (AmbientLights.debugVer)
            //    MelonLoader.MelonLogger.Log("[AL] Window lights");

            ALUtils.Log("Adding window lights", false);

            foreach (InteriorLightingGroup group in lightGroups)
            {
                List <Light> lights      = new List <Light>();
                Light[]      groupLights = group.GetLights().ToArray();

                foreach (Light gLight in groupLights)
                {
                    if (gLight != null)
                    {
                        lights.Add(gLight);
                    }
                    else
                    {
                        //if (AmbientLights.debugVer)
                        //    Debug.Log("[ambient-lights] gLight is null.");
                        ALUtils.Log("gLight is null", false);
                    }
                }

                foreach (Light light in lights)
                {
                    GameObject lightMark;

                    //Add lights to list and to debug object
                    if (light.type == LightType.Point)
                    {
                        lightMark = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                        (lightMark.GetComponent(UnhollowerRuntimeLib.Il2CppType.Of <SphereCollider>()).Cast <Collider>()).enabled = false;

                        light.gameObject.name += "_XPZ_GameLight";

                        gameLightsList.Add(light);

                        pCount++;
                    }
                    else if (light.type == LightType.Spot)
                    {
                        lightMark = GameObject.CreatePrimitive(PrimitiveType.Cube);
                        lightMark.transform.rotation = light.gameObject.transform.rotation;

                        sCount++;

                        light.gameObject.name += "_XPZ_SpotLight";

                        gameSpotLightsList.Add(light);
                    }
                    else
                    {
                        lightMark = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
                    }

                    lightMark.transform.localScale = new Vector3(0.15f, 0.15f, 0.15f);
                    lightMark.transform.position   = light.gameObject.transform.position;

                    lightMark.transform.parent = gameLights.transform;

                    foreach (Renderer rend in lightMark.GetComponentsInChildren <Renderer>())
                    {
                        rend.material.color = light.color;
                        rend.receiveShadows = false;
                    }
                }
            }

            //Main Ambient Light
            //if (AmbientLights.debugVer)
            //    MelonLoader.MelonLogger.Log("[AL] Main Ambient Light");

            ALUtils.Log("Adding main ambient light", false);

            if (mngr != null)
            {
                gameAmbientLight = mngr.m_AmbientLight;
            }
            else
            {
                TodAmbientLight[] array = UnityEngine.Object.FindObjectsOfType <TodAmbientLight>();
                if (array.Length > 0)
                {
                    gameAmbientLight = array[0];
                }
            }

            if (gameAmbientLight != null)
            {
                defaultColorDay   = gameAmbientLight.m_AmbientIndoorsDay;
                defaultColorNight = gameAmbientLight.m_AmbientIndoorsNight;

                gameAmbientLight.name += "_XPZ_AmbientLight";
                //if (AmbientLights.debugVer)
                //    Debug.Log("[ambient-lights] Ambient light found.");
                ALUtils.Log("Main ambient light found", false);
            }
            else
            {
                //if (AmbientLights.debugVer)
                //    Debug.Log("[ambient-lights] Ambient light NOT found.");
                ALUtils.Log("Main ambient light missing", false);
            }

            //Loose Lights
            //With Manager
            //if (AmbientLights.debugVer)
            //    MelonLoader.MelonLogger.Log("[AL] Managed Loose Lights");

            ALUtils.Log("Adding managed loose lights", false);

            List <Light> looseLights       = new List <Light>();
            List <Light> looseLightsMidday = new List <Light>();

            Light[] lLightsArr = null;
            if (mngr != null && mngr.m_LooseLightList != null)
            {
                lLightsArr = mngr.m_LooseLightList.ToArray();
            }

            Light[] lLightsMidArr = null;
            if (mngr != null && mngr.m_LooseLightsMiddayList != null)
            {
                lLightsMidArr = mngr.m_LooseLightsMiddayList.ToArray();
            }

            List <Light> extraLights      = new List <Light>();
            List <Color> extraLightsColor = new List <Color>();

            if (lLightsArr != null)
            {
                foreach (Light l in lLightsArr)
                {
                    if (!l.gameObject.name.Contains("XPZ_SpotLight") && !l.gameObject.name.Contains("XPZ_GameLight"))
                    {
                        l.gameObject.name += "_XPZ_GameLight";
                        extraLights.Add(l);
                        lCount++;
                    }
                }
            }

            if (lLightsMidArr != null)
            {
                foreach (Light l in lLightsMidArr)
                {
                    if (!l.gameObject.name.Contains("XPZ_SpotLight") && !l.gameObject.name.Contains("XPZ_GameLight"))
                    {
                        l.gameObject.name += "_XPZ_GameLight";
                        extraLights.Add(l);
                        lCount++;
                    }
                }
            }

            foreach (Light light in extraLights)
            {
                extraLightsColor.Add(light.color);

                gameExtraLightsColors.Add(light.color);
                gameExtraLightsIntensity.Add(light.intensity);
                gameExtraLightsList.Add(light);
            }


            //if (AmbientLights.debugVer)
            //    MelonLoader.MelonLogger.Log("[AL] Unmanaged Loose Lights");

            ALUtils.Log("Adding unmanaged loose lights", false);

            //No Manager
            UnhollowerBaseLib.Il2CppReferenceArray <UnityEngine.Object> sclights = UnityEngine.Object.FindObjectsOfType(UnhollowerRuntimeLib.Il2CppType.Of <Light>());

            foreach (UnityEngine.Object lightItem in sclights)
            {
                Light light = lightItem.Cast <Light>();

                if (!light.gameObject.name.Contains("XPZ_GameLight") && !light.gameObject.name.Contains("XPZ_Light") && light.type == LightType.Point)
                {
                    light.gameObject.name += "_XPZ_GameLight";
                    gameExtraLightsList.Add(light);
                    gameExtraLightsColors.Add(light.color);
                    gameExtraLightsIntensity.Add(light.intensity);
                    eCount++;
                }
                else if (!light.gameObject.name.Contains("XPZ_SpotLight") && !light.gameObject.name.Contains("XPZ_GameLight") && light.type == LightType.Spot)
                {
                    if (light.cookie && light.cookie.ToString().Contains("Window"))
                    {
                        light.gameObject.name += "_XPZ_SpotLight";
                        gameSpotLightsList.Add(light);
                    }
                    else
                    {
                        light.gameObject.name += "_XPZ_GameLight";
                        gameExtraLightsList.Add(light);
                        gameExtraLightsColors.Add(light.color);
                        gameExtraLightsIntensity.Add(light.intensity);
                        eCount++;
                    }
                }
            }

            //Add fill lights to debug object
            //if (AmbientLights.debugVer)
            //    MelonLoader.MelonLogger.Log("[AL] Add to debug");

            ALUtils.Log("Adding fill lights to debug object", false);

            foreach (Light light in gameExtraLightsList)
            {
                GameObject eLightMark;

                eLightMark = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                //eLightMark.GetComponent(typeof(SphereCollider)).Cast<Collider>().enabled = false;
                eLightMark.transform.localScale = new Vector3(0.15f, 0.15f, 0.15f);
                eLightMark.transform.position   = light.gameObject.transform.position;

                eLightMark.transform.parent = gameLights.transform;

                foreach (Renderer rend in eLightMark.GetComponentsInChildren <Renderer>())
                {
                    rend.material.color = light.color;
                    rend.receiveShadows = false;
                }
            }

            int weCount = GetWindows();

            if (!AmbientLights.showGameLights)
            {
                gameLights.SetActive(false);
            }

            //MelonLoader.MelonModLogger.Log("[AL] Done Preparing");
            //if (AmbientLights.debugVer)
            //    Debug.Log("[ambient-lights] Gamelights setup done. Window Lights:" + pCount + ". Spotlights:" + sCount +  ". Loose Lights:" + lCount + ". Windows:" + wCount + ". Windows outside lighting groups:" + weCount + ". Extra Lights:" + eCount);

            ALUtils.Log("Gamelights setup complete. Window Lights:" + pCount + ". Spotlights:" + sCount + ". Loose Lights:" + lCount + ". Windows:" + wCount + ". Windows outside lighting groups:" + weCount + ". Extra Lights:" + eCount, false);

            AmbientLights.SetupGameLights();

            gameLightsReady = true;
        }