cmooref17 / Lethal-Company-TooManyEmotes

https://thunderstore.io/c/lethal-company/p/FlipMods/TooManyEmotes/
MIT License
16 stars 10 forks source link

[Conflict issue] not compatible with ChineseBrideAndNewYearGhostgirl mods, author says you rewrote the logic about ghost girl rendering #92

Closed suwonsarara closed 8 months ago

suwonsarara commented 8 months ago

Hello, this mod audio works fine independently, but when paired with Toomanyemotes, the ghost girl model doesn't activate. The author mentioned you modified the rendering layer of ghost girl. I'm curious why this mod would alter its rendering layer. Thank you for your response.

https://thunderstore.io/c/lethal-company/p/TShine/ChineseBrideAndNewYearGhostgirl/

cmooref17 commented 8 months ago

https://github.com/cmooref17/Lethal-Company-TooManyEmotes/blob/main/TooManyEmotes/Patches/DressGirlVisibilityPatcher.cs

You can view the code here, but I disable the mesh when the girl is on rendering layer 23. This layer is used for enemies that are not meant to be seen by the player, so The first person camera does not see layer 23. Normally you can't see your main body from this camera, but most third person mods, as well as my mod, Make it so your player model is rendered, but only on layer 23, and then they make their third person cameras view layer 23 so those cameras can see your player body, but the first person camera cannot.

Because of this, third person cameras from many mods will see the girl, even when she is not supposed to be visible.

So what my patch does, is if it detects that the girl is on layer 23, it also disables the mesh so no camera can see her. I thought I had a config option to disable this if it conflicted with other mods, but now that I'm looking in my config, I never added that option. I can add this if it would be helpful.

Sorry if any of that was really confusing, because it also confuses me!

cmooref17 commented 8 months ago

Actually, upon referencing my code, I don't touch the rendering layer for the girl at all. I just disable the mesh if the girl is on layer 23, which as I mentioned before, is the layer that enemies are not supposed to be rendered on. That layer is called EnemiesNotRendered I think.

suwonsarara commented 8 months ago

I understand now. The emotes activate third-person cameras, but the third person camera can see the girl. So, there's a possibility that when you're making emotes, you might see the girl, which shouldn't happen under normal circumstances. It's a very meticulous design. I'll go ask the author of this mod if your modification will help them. Thank you for your explanation.

TShineCN commented 8 months ago

Hello, I'm the author of the ChineseBrideAndNewYearGhostgirl. Here is my speculation on the conflict issue: In my code, the default setting for the ghostgirl is on level 23. Because I did not modify the original game's EnableEnemyMesh method. So I set the layer of the ghostgirl to 23, otherwise the ghostgirl will remain displayed in game all the time. And when Toomanyemotes recognized the initial layer was 23, disabled my custom mesh model. This is my code:

List<SkinnedMeshRenderer> list = new List<SkinnedMeshRenderer>(__instance.skinnedMeshRenderers);
                Transform[] meshes = { ChineseModelObject.transform.Find("body"), ChineseModelObject.transform.Find("dress"), ChineseModelObject.transform.Find("head") };
                  foreach (var meshTransform in meshes)
                    {
                        if (meshTransform != null)
                        {
                            SkinnedMeshRenderer meshRenderer = meshTransform.GetComponent<SkinnedMeshRenderer>();
                            if (meshRenderer != null)
                            {
                                meshRenderer.rootBone = rigTransform;
                                meshRenderer.gameObject.tag = "DoNotSet";
                                meshRenderer.gameObject.layer = LayerMask.NameToLayer("EnemiesNotRendered");
                                meshRenderer.material = Plugin.ChineseGirlMaterial1;

                                list.Add(meshRenderer);
                            }

                        }

                        __instance.skinnedMeshRenderers = list.ToArray();
                        animationTransform.name = "old_metarig2";

                    }
cmooref17 commented 8 months ago

When the game hides the girl, they put her on layer 23, and when that happens, I hide the mesh. When they display her again, they put her into another layer, and my code should enable her mesh again. Have you confirmed that this doesn't work? Or do you run into errors?

Here's my code:

namespace TooManyEmotes.Patches
{
    [HarmonyPatch]
    public class DressGirlVisibilityPatcher
    {
        [HarmonyPatch(typeof(EnemyAI), "EnableEnemyMesh")]
        [HarmonyPostfix]
        public static void HideGirlMesh(bool enable, EnemyAI __instance, bool overrideDoNotSet = false)
        {
            if (!(__instance is DressGirlAI))
                return;

            foreach (var renderer in __instance.skinnedMeshRenderers)
                renderer.enabled = renderer.gameObject.layer != 23;
            foreach (var renderer in __instance.meshRenderers)
                renderer.enabled = renderer.gameObject.layer != 23;
        }
    }
}
TShineCN commented 8 months ago

When the game hides the girl, they put her on layer 23, and when that happens, I hide the mesh. When they display her again, they put her into another layer, and my code should enable her mesh again. Have you confirmed that this doesn't work? Or do you run into errors?

Here's my code:

namespace TooManyEmotes.Patches
{
    [HarmonyPatch]
    public class DressGirlVisibilityPatcher
    {
        [HarmonyPatch(typeof(EnemyAI), "EnableEnemyMesh")]
        [HarmonyPostfix]
        public static void HideGirlMesh(bool enable, EnemyAI __instance, bool overrideDoNotSet = false)
        {
            if (!(__instance is DressGirlAI))
                return;

            foreach (var renderer in __instance.skinnedMeshRenderers)
                renderer.enabled = renderer.gameObject.layer != 23;
            foreach (var renderer in __instance.meshRenderers)
                renderer.enabled = renderer.gameObject.layer != 23;
        }
    }
}

Oh, there is no problem with the display and disappearance logic of ghostgirl. And there are no errors in the log. It's just that the model I customized won't display. Perhaps it's because I disabled the original skinnedMeshRenderer component of the game and created a new skinnedMeshRenderer component?

 [HarmonyPatch(typeof(DressGirlAI))]
    internal class DressGirlChineseModelPatch
    {
        [HarmonyPatch("Start")]
        [HarmonyPostfix]
        public static void StartPatch(DressGirlAI __instance)
        {
            Transform transformDressGirlModel = __instance.transform.Find("DressGirlModel");
            Transform animationTransform = transformDressGirlModel.Find("AnimContainer").Find("metarig");
            SkinnedMeshRenderer skinnedMeshRenderer = transformDressGirlModel.Find("basemesh").GetComponent<SkinnedMeshRenderer>();
            if (skinnedMeshRenderer != null && skinnedMeshRenderer.enabled)
            {

                skinnedMeshRenderer.enabled = false;

                foreach (MeshRenderer item in animationTransform.GetComponentsInChildren<MeshRenderer>())
                {
                    item.enabled = false;
                }

                GameObject ChineseModelObject = Object.Instantiate(Plugin.ChineseModelPrefab1);
                ChineseModelObject.transform.SetParent(transformDressGirlModel);
                ChineseModelObject.transform.localPosition = Vector3.zero;
                ChineseModelObject.transform.localRotation = Quaternion.identity;
                ChineseModelObject.transform.localScale = Vector3.one;

                Transform rigTransform = ChineseModelObject.transform.Find("metarig");
                rigTransform.SetParent(animationTransform.parent, worldPositionStays: true);
                rigTransform.transform.localScale = animationTransform.transform.localScale;
                rigTransform.transform.localRotation = animationTransform.transform.localRotation;
                rigTransform.transform.localPosition = animationTransform.transform.localPosition;

                List<SkinnedMeshRenderer> list = new List<SkinnedMeshRenderer>(__instance.skinnedMeshRenderers);
                Transform[] meshes = { ChineseModelObject.transform.Find("body"), ChineseModelObject.transform.Find("dress"), ChineseModelObject.transform.Find("head") };
                  foreach (var meshTransform in meshes)
                    {
                        if (meshTransform != null)
                        {
                            SkinnedMeshRenderer meshRenderer = meshTransform.GetComponent<SkinnedMeshRenderer>();
                            if (meshRenderer != null)
                            {
                                meshRenderer.rootBone = rigTransform;
                                meshRenderer.gameObject.tag = "DoNotSet";
                                meshRenderer.gameObject.layer = LayerMask.NameToLayer("EnemiesNotRendered");
                                meshRenderer.material = Plugin.ChineseGirlMaterial1;

                                list.Add(meshRenderer);
                            }

                        }

                        __instance.skinnedMeshRenderers = list.ToArray();
                        animationTransform.name = "old_metarig2";

                    }
                }

        }           
    }
cmooref17 commented 8 months ago

I am about to push an update to my TooManyEmotes mod, and in the config, I created an option to disable the girl patch that I have. I'd like to create a better solution for this in the future, just in case my solution is causing issues, but maybe you can use this to test if it works for you after disabling my girl patch.

If you could let me know what you find out, that would be great! It will be on update 2.0.6

TShineCN commented 8 months ago

I am about to push an update to my TooManyEmotes mod, and in the config, I created an option to disable the girl patch that I have. I'd like to create a better solution for this in the future, just in case my solution is causing issues, but maybe you can use this to test if it works for you after disabling my girl patch.

If you could let me know what you find out, that would be great! It will be on update 2.0.6

Thank you very much for your patient response!

cmooref17 commented 8 months ago

The update has been pushed now. It might take a while to show up on Thunderstore or on mod managers.