1
0
Fork 0

Fix LEDHangingLight (GarageTile & PoolTile) lights flickering

This commit is contained in:
ivan tkachenko 2025-08-02 04:36:08 +03:00
parent 4d84a2d001
commit 78370da460
2 changed files with 35 additions and 3 deletions

View File

@ -11,7 +11,9 @@ namespace MuzikaGromche
{ {
internal class PoweredLightsAnimators internal class PoweredLightsAnimators
{ {
private readonly record struct AnimatorPatch(string AnimatorContainerPath, RuntimeAnimatorController AnimatorController); private delegate void ManualPatch(GameObject animatorContainer);
private readonly record struct AnimatorPatch(string AnimatorContainerPath, RuntimeAnimatorController AnimatorController, ManualPatch? ManualPatch);
private readonly record struct TilePatch(string TileName, AnimatorPatch[] Patches) private readonly record struct TilePatch(string TileName, AnimatorPatch[] Patches)
{ {
@ -19,13 +21,13 @@ namespace MuzikaGromche
public readonly string TileCloneName = $"{TileName}(Clone)"; public readonly string TileCloneName = $"{TileName}(Clone)";
} }
private readonly record struct AnimatorPatchDescriptor(string AnimatorContainerPath, string AnimatorControllerAssetPath) private readonly record struct AnimatorPatchDescriptor(string AnimatorContainerPath, string AnimatorControllerAssetPath, ManualPatch? ManualPatch = null)
{ {
public AnimatorPatch Load(AssetBundle assetBundle) public AnimatorPatch Load(AssetBundle assetBundle)
{ {
var animationController = assetBundle.LoadAsset<RuntimeAnimatorController>(AnimatorControllerAssetPath) var animationController = assetBundle.LoadAsset<RuntimeAnimatorController>(AnimatorControllerAssetPath)
?? throw new FileNotFoundException($"RuntimeAnimatorController not found: {AnimatorControllerAssetPath}", AnimatorControllerAssetPath); ?? throw new FileNotFoundException($"RuntimeAnimatorController not found: {AnimatorControllerAssetPath}", AnimatorControllerAssetPath);
return new(AnimatorContainerPath, animationController); return new(AnimatorContainerPath, animationController, ManualPatch);
} }
} }
@ -58,6 +60,7 @@ namespace MuzikaGromche
const string MineshaftSpotlight = $"{BasePath}MineshaftSpotlight (Patched).controller"; const string MineshaftSpotlight = $"{BasePath}MineshaftSpotlight (Patched).controller";
const string LightbulbsLine = $"{BasePath}lightbulbsLineMesh (Patched).controller"; const string LightbulbsLine = $"{BasePath}lightbulbsLineMesh (Patched).controller";
const string CeilingFan = $"{BasePath}CeilingFan (originally GameObject) (Patched).controller"; const string CeilingFan = $"{BasePath}CeilingFan (originally GameObject) (Patched).controller";
const string LEDHangingLight = $"{BasePath}LEDHangingLight (Patched).controller";
TilePatchDescriptor[] descriptors = TilePatchDescriptor[] descriptors =
[ [
@ -87,6 +90,17 @@ namespace MuzikaGromche
new("CeilingFanAnimContainer", CeilingFan), new("CeilingFanAnimContainer", CeilingFan),
new("MineshaftSpotlight (1)", MineshaftSpotlight), new("MineshaftSpotlight (1)", MineshaftSpotlight),
]), ]),
new("GarageTile", [
new("HangingLEDBarLight (3)", LEDHangingLight),
new("HangingLEDBarLight (4)", LEDHangingLight,
// This HangingLEDBarLight's IndirectLight is wrongly named, so animator couldn't find it
RenameGameObjectPatch("IndirectLight (1)", "IndirectLight")),
]),
new("PoolTile", [
new("PoolLights/HangingLEDBarLight", LEDHangingLight),
new("PoolLights/HangingLEDBarLight (4)", LEDHangingLight),
new("PoolLights/HangingLEDBarLight (5)", LEDHangingLight),
]),
]; ];
Patches = descriptors Patches = descriptors
@ -127,11 +141,29 @@ namespace MuzikaGromche
#pragma warning restore CS0162 // Unreachable code detected #pragma warning restore CS0162 // Unreachable code detected
} }
patch.ManualPatch?.Invoke(animationContainerTransform.gameObject);
animator.runtimeAnimatorController = patch.AnimatorController; animator.runtimeAnimatorController = patch.AnimatorController;
Debug.Log($"{nameof(MuzikaGromche)} {nameof(PoweredLightsAnimatorsPatch)} {tilePatch.TileName}/{patch.AnimatorContainerPath}: Replaced animator controller"); Debug.Log($"{nameof(MuzikaGromche)} {nameof(PoweredLightsAnimatorsPatch)} {tilePatch.TileName}/{patch.AnimatorContainerPath}: Replaced animator controller");
} }
} }
} }
private static ManualPatch RenameGameObjectPatch(string relativePath, string newName) => animatorContainer =>
{
var targetObject = animatorContainer.transform.Find(relativePath)?.gameObject;
if (targetObject == null)
{
#if DEBUG
throw new NullReferenceException($"{animatorContainer.name}/{relativePath}: GameObject not found!");
#endif
#pragma warning disable CS0162 // Unreachable code detected
return;
#pragma warning restore CS0162 // Unreachable code detected
}
targetObject.name = newName;
Debug.Log($"{nameof(MuzikaGromche)} {nameof(PoweredLightsAnimatorsPatch)} {animatorContainer.name}/{relativePath}: Renamed GameObject");
};
} }
[HarmonyPatch(typeof(Tile))] [HarmonyPatch(typeof(Tile))]