コード例 #1
0
        internal static void HandleHotkeys()
        {
            if ((InputManager.GetKeyDown(InputManager.m_CurrentContext, KeyCode.L) && !InputManager.GetSprintDown(InputManager.m_CurrentContext) && AmbientLights.debugVer) || (InputManager.GetKeyDown(InputManager.m_CurrentContext, KeyCode.L) && InputManager.GetSprintDown(InputManager.m_CurrentContext) && Settings.options.enableDebugKey && !AmbientLights.debugVer))
            {
                if (AmbientLights.lightOverride)
                {
                    AmbientLights.lightOverride = false;
                    AmbientLights.MaybeUpdateLightsToPeriod(true);

                    Log("Ambient Lights: On", true, false, true);

                    /*HUDMessage.AddMessage("Ambient Lights: On");
                     * if (AmbientLights.debugVer)
                     *  Debug.Log("Ambient Lights: On");*/
                }
                else
                {
                    AmbientLights.lightOverride = true;
                    AmbientLights.SetLightsIntensity(0f);

                    Log("Ambient Lights: Off", true, false, true);

                    /*HUDMessage.AddMessage("Ambient Lights: Off");
                     * if (AmbientLights.debugVer)
                     *  Debug.Log("Ambient Lights: Off");*/
                }
            }

            if (InputManager.GetKeyDown(InputManager.m_CurrentContext, KeyCode.L) && InputManager.GetSprintDown(InputManager.m_CurrentContext) && AmbientLights.debugVer)
            {
                AmbientLights.Unload(true);
                AmbientLights.Reset(false);
                AmbientLights.LoadConfigs();
                //HUDMessage.AddMessage("Reloading Config");
                Log("Reloading Scene Config", true, false, true);
            }

            if (InputManager.GetKeyDown(InputManager.m_CurrentContext, KeyCode.Z) && !InputManager.GetSprintDown(InputManager.m_CurrentContext) && AmbientLights.debugVer)
            {
                GetPoint();
            }

            if (InputManager.GetKeyDown(InputManager.m_CurrentContext, KeyCode.Z) && InputManager.GetSprintDown(InputManager.m_CurrentContext) && AmbientLights.debugVer)
            {
                ShowGameLights();
            }

            if (InputManager.GetKeyDown(InputManager.m_CurrentContext, KeyCode.F6) && AmbientLights.debugVer)
            {
                TimeWeather.GetCurrentPeriodAndWeather();

                //HUDMessage.AddMessage(AmbientLights.currentScene + " " + TimeWeather.GetCurrentTimeString() + " - " + TimeWeather.currentWeather + " (" + (Math.Round(TimeWeather.currentWeatherPct, 2) * 100) + " %)" + TimeWeather.currentPeriod + "(" + (Math.Round(TimeWeather.currentPeriodPct, 2) * 100) + "%)");

                Log("Environment data: " + AmbientLights.currentScene + " " + TimeWeather.GetCurrentTimeString() + " - " + TimeWeather.currentWeather + " (" + (Math.Round(TimeWeather.currentWeatherPct, 2) * 100) + " %)" + TimeWeather.currentPeriod + "(" + (Math.Round(TimeWeather.currentPeriodPct, 2) * 100) + "%)", true);

                ALUtils.debugNext = true;
            }
        }
コード例 #2
0
 public static void Postfix(GameManager __instance)
 {
     //AmbientLights.Update();
     //ALUtils.Log("GameManager Update 1.", false, true);
     if (!InterfaceManager.m_Panel_PauseMenu.IsEnabled())
     {
         //ALUtils.Log("GameManager Update 1.", false, true);
         AmbientLights.Update();
     }
 }
コード例 #3
0
            public static void Postfix(TimeOfDay __instance)
            {
                ALUtils.hourNow   = GameManager.GetTimeOfDayComponent().GetHour();
                ALUtils.minuteNow = GameManager.GetTimeOfDayComponent().GetMinutes();

                //Debug.Log("[ambient-lights] Initialized at: " + ALUtils.hourNow + ":" + ALUtils.minuteNow);
                ALUtils.Log("Initialized at: " + ALUtils.hourNow + ":" + ALUtils.minuteNow, false, true);

                AmbientLights.timeInit = true;
                AmbientLights.MaybeUpdateLightsToPeriod(true);
            }
コード例 #4
0
            public static void Prefix()
            {
                if (!InterfaceManager.IsMainMenuEnabled())
                {
                    GameLights.gameLightsList.Clear();
                    GameLights.gameExtraLightsList.Clear();
                    GameLights.gameSpotLightsList.Clear();
                    GameLights.gameExtraLightsColors.Clear();
                    GameLights.gameExtraLightsIntensity.Clear();
                    GameLights.gameShaftsList.Clear();
                    GameLights.gameWindows.Clear();

                    AmbientLights.Reset(true);
                }
            }
コード例 #5
0
 public static void Postfix(UniStormWeatherSystem __instance)
 {
     AmbientLights.weatherInit = true;
     AmbientLights.MaybeUpdateLightsToPeriod(true);
 }
コード例 #6
0
 private static void Postfix(MissionServicesManager __instance)
 {
     //MelonLoader.MelonLogger.Log("[AL] SceneUnloaded");
     AmbientLights.Unload();
 }
コード例 #7
0
 public static void Postfix(SaveGameSystem __instance, string name, string sceneSaveName)
 {
     //MelonLoader.MelonLogger.Log("[AL] Unload and load");
     AmbientLights.Unload();
     AmbientLights.LoadConfigs();
 }
コード例 #8
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;
        }