private static void GetAllGameObjects() { _gameObjectInfos = new List <GameObjectInfo>(); // I'll probably revist this formula for getting objects by only grabbing the root objects and adding all the children List <GameObject> gameObjects = Resources.FindObjectsOfTypeAll <GameObject>().Where(n => { if (n != null) { string sceneName = n.scene.name; if (sceneName != null) { if ((sceneName.Contains("Environment") && !sceneName.Contains("Menu")) || n.GetComponent <TrackLaneRing>() != null) { return(true); } } } return(false); }).ToList(); // Adds the children of whitelist GameObjects // Mainly for grabbing cone objects in KaleidoscopeEnvironment gameObjects.ToList().ForEach(n => { List <Transform> allChildren = new List <Transform>(); GetChildRecursive(n.transform, ref allChildren); foreach (Transform transform in allChildren) { if (!gameObjects.Contains(transform.gameObject)) { gameObjects.Add(transform.gameObject); } } }); List <string> objectsToPrint = new List <string>(); foreach (GameObject gameObject in gameObjects) { GameObjectInfo gameObjectInfo = new GameObjectInfo(gameObject); _gameObjectInfos.Add(new GameObjectInfo(gameObject)); objectsToPrint.Add(gameObjectInfo.FullID); // seriously what the f**k beat games // GradientBackground permanently yeeted because it looks awful and can ruin multi-colored chroma maps if (gameObject.name == "GradientBackground") { gameObject.SetActive(false); } } if (Settings.ChromaConfig.Instance !.PrintEnvironmentEnhancementDebug) { objectsToPrint.Sort(); objectsToPrint.ForEach(n => Plugin.Logger.Log(n)); } }
internal static void InitializeComponents(Transform root, Transform original, List <GameObjectInfo> gameObjectInfos, List <IComponentData> componentDatas, int?lightID) { void GetComponentAndOriginal <T>(Action <T, T> initializeDelegate) { T[] rootComponents = root.GetComponents <T>(); T[] originalComponents = original.GetComponents <T>(); for (int i = 0; i < rootComponents.Length; i++) { initializeDelegate(rootComponents[i], originalComponents[i]); if (Settings.ChromaConfig.Instance !.PrintEnvironmentEnhancementDebug) { Plugin.Logger.Log($"Initialized {typeof(T).Name}"); } } } GetComponentAndOriginal <LightWithIdMonoBehaviour>((rootComponent, originalComponent) => { _lightWithIdMonoBehaviourManagerAccessor(ref rootComponent) = _lightWithIdMonoBehaviourManagerAccessor(ref originalComponent); LightColorizer.RegisterLight(rootComponent, lightID); }); GetComponentAndOriginal <LightWithIds>((rootComponent, originalComponent) => { _lightWithIdsManagerAccessor(ref rootComponent) = _lightWithIdsManagerAccessor(ref originalComponent); LightColorizer.RegisterLight(rootComponent, lightID); }); GetComponentAndOriginal <TrackLaneRing>((rootComponent, originalComponent) => { if (EnvironmentEnhancementManager.RingRotationOffsets.TryGetValue(originalComponent, out Quaternion offset)) { EnvironmentEnhancementManager.RingRotationOffsets.Add(rootComponent, offset); } _ringTransformAccessor(ref rootComponent) = root; _positionOffsetAccessor(ref rootComponent) = _positionOffsetAccessor(ref originalComponent); _posZAccessor(ref rootComponent) = _posZAccessor(ref originalComponent); TrackLaneRingsManager?managerToAdd = null; foreach (TrackLaneRingsManager manager in HarmonyPatches.TrackLaneRingsManagerAwake.RingManagers) { TrackLaneRingsManagerComponentData componentData = componentDatas.OfType <TrackLaneRingsManagerComponentData>().Where(n => n.OldTrackLaneRingsManager == manager).FirstOrDefault(); if (componentData != null) { managerToAdd = componentData.NewTrackLaneRingsManager; } else { TrackLaneRingsManager managerRef = manager; TrackLaneRing[] rings = _ringsAccessor(ref managerRef); if (rings.Contains(originalComponent)) { managerToAdd = manager; } } if (managerToAdd != null) { // ToList() to add and then back ToArray() TrackLaneRing[] rings = _ringsAccessor(ref managerToAdd); List <TrackLaneRing> ringsList = rings?.ToList() ?? new List <TrackLaneRing>(); ringsList.Add(rootComponent); _ringsAccessor(ref managerToAdd) = ringsList.ToArray(); break; } } }); GetComponentAndOriginal <TrackLaneRingsPositionStepEffectSpawner>((rootComponent, originalComponent) => { foreach (TrackLaneRingsManager manager in HarmonyPatches.TrackLaneRingsManagerAwake.RingManagers) { TrackLaneRingsManagerComponentData?componentData = componentDatas.OfType <TrackLaneRingsManagerComponentData>().Where(n => n.OldTrackLaneRingsManager == manager).FirstOrDefault(); if (componentData != null) { _stepSpawnerRingsManagerAccessor(ref rootComponent) = componentData.NewTrackLaneRingsManager !; break; } } }); GetComponentAndOriginal <ChromaRingsRotationEffect>((rootComponent, originalComponent) => { foreach (TrackLaneRingsManager manager in HarmonyPatches.TrackLaneRingsManagerAwake.RingManagers) { TrackLaneRingsManagerComponentData?componentData = componentDatas.OfType <TrackLaneRingsManagerComponentData>().Where(n => n.OldTrackLaneRingsManager == manager).FirstOrDefault(); if (componentData != null) { rootComponent.SetNewRingManager(componentData.NewTrackLaneRingsManager !); break; } } }); GetComponentAndOriginal <TrackLaneRingsRotationEffectSpawner>((rootComponent, originalComponent) => { _rotationEffectSpawnerCallbackControllerAccessor(ref rootComponent) = _rotationEffectSpawnerCallbackControllerAccessor(ref originalComponent); _trackLaneRingsRotationEffectAccessor(ref rootComponent) = rootComponent.GetComponent <ChromaRingsRotationEffect>(); }); GetComponentAndOriginal <Spectrogram>((rootComponent, originalComponent) => _spectrogramDataAccessor(ref rootComponent) = _spectrogramDataAccessor(ref originalComponent)); GetComponentAndOriginal <LightRotationEventEffect>((rootComponent, originalComponent) => _lightCallbackControllerAccessor(ref rootComponent) = _lightCallbackControllerAccessor(ref originalComponent)); GetComponentAndOriginal <LightPairRotationEventEffect>((rootComponent, originalComponent) => { _lightPairCallbackControllerAccessor(ref rootComponent) = _lightPairCallbackControllerAccessor(ref originalComponent); Transform transformL = _transformLAccessor(ref originalComponent); Transform transformR = _transformRAccessor(ref originalComponent); _transformLAccessor(ref rootComponent) = root.GetChild(transformL.GetSiblingIndex()); _transformRAccessor(ref rootComponent) = root.GetChild(transformR.GetSiblingIndex()); // We have to enable the object to tell unity to run Start rootComponent.enabled = true; }); GetComponentAndOriginal <ParticleSystemEventEffect>((rootComponent, originalComponent) => { _particleCallbackControllerAccessor(ref rootComponent) = _particleCallbackControllerAccessor(ref originalComponent); _particleSystemAccessor(ref rootComponent) = root.GetComponent <ParticleSystem>(); rootComponent.enabled = true; }); GetComponentAndOriginal <Mirror>((rootComponent, originalComponent) => { _mirrorRendererAccessor(ref rootComponent) = UnityEngine.Object.Instantiate(_mirrorRendererAccessor(ref originalComponent)); _mirrorMaterialAccessor(ref rootComponent) = UnityEngine.Object.Instantiate(_mirrorMaterialAccessor(ref originalComponent)); }); GameObjectInfo newGameObjectInfo = new GameObjectInfo(root.gameObject); gameObjectInfos.Add(newGameObjectInfo); foreach (Transform transform in root) { int index = transform.GetSiblingIndex(); InitializeComponents(transform, original.GetChild(index), gameObjectInfos, componentDatas, lightID); } }