Exemplo n.º 1
0
        public static void MaybeUpdateLightsToPeriod(bool forceUpdate = false)
        {
            if (lightsInit && timeInit && weatherInit && config.ready)
            {
                //Generate lightsets for emitters based on time, weather and transition progress
                LightSet lightSet = config.GetCurrentLightSet();

                if (lightSet != null)
                {
                    currentLightSet = lightSet;
                    foreach (var light in lightList)
                    {
                        LightOrientation set = lightSet.orientations[light.orientation];

                        if (set != null)
                        {
                            light.SetLightParams(set, forceUpdate);
                        }
                        else
                        {
                            //MelonLoader.MelonLogger.Log("[AL] No set matches orientation.");
                            ALUtils.Log("ERROR: No set matches orientation.", false, true);
                        }
                    }
                }
                else
                {
                    //MelonLoader.MelonLogger.Log("[AL] No lightset defined");
                    ALUtils.Log("ERROR: No lightset defined.", false, true);
                }
            }
        }
Exemplo n.º 2
0
        public static void SetupLights()
        {
            if (config.ready)
            {
                //Debug.Log("[ambient-lights] Setting up " + config.data.emitters.Count + " light sources for scene.");
                ALUtils.Log("Setting up " + config.data.emitters.Count + " light sources for scene.", false, true);

                foreach (AmbEmitter emitter in config.data.emitters)
                {
                    //Debug.Log("Emitter pos: " + emitter.position);

                    Vector3 newPos = ALUtils.StringToVector3(emitter.position);

                    AmbLight newLight = new AmbLight(newPos, emitter.orientation, emitter.size, emitter.cover);

                    lightList.Add(newLight);
                }

                lightsInit = true;
                MaybeUpdateLightsToPeriod(true);

                if (!GameLights.gameLightsReady)
                {
                    GameLights.AddGameLights();
                }
            }
            else
            {
                //Debug.Log("[ambient-lights] ERROR: Config isn't ready or not present.");
                ALUtils.Log("ERROR: Config isn't ready or not present.", false, true);
            }
        }
Exemplo n.º 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);
            }
Exemplo n.º 4
0
        private void LoadSceneConfig()
        {
            string sceneFile = "scene_" + scene + ".json";

            if (File.Exists(Path.Combine(AmbientLights.MODS_FOLDER_PATH, sceneFile)))
            {
                data = JSON.Load(File.ReadAllText(Path.Combine(AmbientLights.MODS_FOLDER_PATH, sceneFile))).Make <SceneConfig>();
            }
            else
            {
                //Debug.Log("[ambient-lights] No lighting data for scene " + scene + " found. Using game default.");
                ALUtils.Log("No lighting data for scene " + scene + " found. Using game default.", false, true);
            }
        }
Exemplo n.º 5
0
        public static void LoadConfigs()
        {
            currentScene = GameManager.m_ActiveScene;

            //Debug.Log("[ambient-lights] Loaded Scene: " + currentScene);
            ALUtils.Log("Loading Scene: " + currentScene, false, true);

            if (currentScene != "MainMenu")
            {
                config = new LightConfig();
                config.Load();

                if (config.ready)
                {
                    currentLightSet = config.GetCurrentLightSet();
                }

                SetupLights();
            }
        }
Exemplo n.º 6
0
        private void LoadGlobalConfig()
        {
            if (File.Exists(Path.Combine(AmbientLights.MODS_FOLDER_PATH, "weather_sets.json")))
            {
                weathersConfig = JSON.Load(File.ReadAllText(Path.Combine(AmbientLights.MODS_FOLDER_PATH, "weather_sets.json"))).Make <Dictionary <string, WeatherMod> >();
            }
            else
            {
                //Debug.Log("[ambient-lights] ERROR: No weather sets data found");
                ALUtils.Log("ERROR: No weather sets data found.", false, true);
            }

            if (File.Exists(Path.Combine(AmbientLights.MODS_FOLDER_PATH, "global_sets.json")))
            {
                periodsConfig = JSON.Load(File.ReadAllText(Path.Combine(AmbientLights.MODS_FOLDER_PATH, "global_sets.json"))).Make <Dictionary <string, AmbPeriod> >();
            }
            else
            {
                //Debug.Log("[ambient-lights] ERROR: No light sets data found");
                ALUtils.Log("ERROR: No light sets data found.", false, true);
            }
        }
Exemplo n.º 7
0
        public static void Reset(bool firstPass = true)
        {
            debugVer = Settings.options.verbose;
            verbose  = Settings.options.verbose;

            ALUtils.Log("Scene reset.", false);

            lightList.Clear();

            config = null;

            lightsInit = false;

            lightOverride    = false;
            showGameLights   = false;
            enableGameLights = true;

            if (firstPass)
            {
                TimeWeather.Reset();
                timeInit    = false;
                weatherInit = false;
            }
        }
Exemplo n.º 8
0
 internal void DebugLightSet()
 {
     //if (AmbientLights.debugVer)
     //Debug.Log("Intensity: " + light.intensity + ", Range: " + light.range + ", Color: " + light.color);
     ALUtils.Log("Current Lightset - Intensity: " + light.intensity + ", Range: " + light.range + ", Color: " + light.color, false);
 }
Exemplo n.º 9
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;
        }