Пример #1
0
        private static void ReloadTextures()
        {
            LoadCustomTextures();
            foreach (KeyValuePair <int, Texture2D> kvp in customTextures)
            {
                Actor actor = Module <ActorMgr> .Self.Get(kvp.Key);

                if (actor == null)
                {
                    continue;
                }
                NpcAppear appear = actor.GetComponent <NpcAppear>();
                if (appear != null)
                {
                    appear.RebuildMesh();
                }
                else
                {
                    SkinnedMeshRenderer smr = (SkinnedMeshRenderer)typeof(Actor).GetField("skinnedMeshRenderer", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(actor);
                    if (smr != null)
                    {
                        smr.material.mainTexture = kvp.Value;
                    }
                }
            }
        }
Пример #2
0
            private static void Prefix(NpcAppear __instance, ref List <NpcAppearUnit> npcAppearUnits, Actor ___m_Actor)
            {
                if (___m_Actor == null)
                {
                    Dbgl($"no actor");
                    return;
                }
                if (npcAppearUnits == null)
                {
                    Dbgl($"no npcAppearUnits");
                    return;
                }

                if (customTextures.ContainsKey(___m_Actor.InstanceId))
                {
                    foreach (NpcAppearUnit unit in npcAppearUnits)
                    {
                        if (unit == null || unit.smrs == null)
                        {
                            continue;
                        }
                        foreach (SkinnedMeshRenderer meshRenderer in unit.smrs)
                        {
                            if (meshRenderer != null && meshRenderer.material != null)
                            {
                                Dbgl($"got mesh for: {___m_Actor.ActorName}");
                                meshRenderer.material.mainTexture = customTextures[___m_Actor.InstanceId];
                            }
                        }
                    }
                }
            }
Пример #3
0
            static void Prefix(NpcAppearModule __instance, ref Dictionary <int, NpcAppearDBData> ___m_NpcAppearDBDataDir)
            {
                return;

                if (!enabled)
                {
                    return;
                }

                NpcAppearDBData phyllisData   = ___m_NpcAppearDBDataDir[4000035];
                NpcAppear       phyllisAppear = ActorMgr.Self.Get(4000035).GetComponent <NpcAppear>();

                foreach (ClothesChanger cc in noClothes)
                {
                    continue;
                    ___m_NpcAppearDBDataDir.Add(cc.id, phyllisData);
                    Actor actor = ActorMgr.Self.Get(cc.id);
                    actor.gameObject.AddComponent <NpcAppear>();
                    NpcAppear component = actor.GetComponent <NpcAppear>();
                    AccessTools.FieldRefAccess <NpcAppear, Dictionary <int, AppearDBData> >(component, "m_DefaultAppearDBDatas") = AccessTools.FieldRefAccess <NpcAppear, Dictionary <int, AppearDBData> >(phyllisAppear, "m_DefaultAppearDBDatas");
                    AccessTools.FieldRefAccess <NpcAppear, int[]>(component, "defaultAppearIDs")       = AccessTools.FieldRefAccess <NpcAppear, int[]>(phyllisAppear, "defaultAppearIDs");
                    AccessTools.FieldRefAccess <NpcAppear, Transform>(component, "m_BoneRoot")         = AccessTools.FieldRefAccess <NpcAppear, Transform>(phyllisAppear, "m_BoneRoot");
                    AccessTools.FieldRefAccess <NpcAppear, SkinnedMeshRenderer[]>(component, "m_Smrs") = AccessTools.FieldRefAccess <NpcAppear, SkinnedMeshRenderer[]>(phyllisAppear, "m_Smrs");
                    //component.InitAppear(phyllisData, phyllisAppear.appearData, actor);
                    typeof(NpcAppearModule).GetMethod("InitNPCAppear", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { cc.id, phyllisAppear.appearData, phyllisAppear.npcAppearDBData });
                    //typeof(NpcAppear).GetProperty("appearData").SetValue(component, phyllisAppear.appearData, null);
                    //AccessTools.FieldRefAccess<NpcAppear, Dictionary<int, AppearDBData>>(component, "m_DefaultAppearDBDatas") = AccessTools.FieldRefAccess<NpcAppear, Dictionary<int, AppearDBData>>(phyllisAppear, "m_DefaultAppearDBDatas");
                    //AccessTools.FieldRefAccess<NpcAppear, Actor>(component, "m_Actor") = actor;
                }
            }
Пример #4
0
            static void Postfix(NpcAppearDBData npcAppearDBData, NpcAppearData appearData, Actor actor)
            {
                if (!enabled)
                {
                    return;
                }

                for (int i = 0; i < clothesChangers.Count; i++)
                {
                    //Dbgl($"changing for {i} {clothesChangers[i].name}");
                    if (clothesChangers[i].id == actor.InstanceId)
                    {
                        Dbgl($"actor: {actor.ActorName}");
                        Dictionary <int, AppearDBData> appearDbDatas = AccessTools.FieldRefAccess <NpcAppearModule, Dictionary <int, AppearDBData> >(Module <NpcAppearModule> .Self, "m_AppearDBDataDic");
                        NpcAppear component = actor.GetComponent <NpcAppear>();
                        if (component == null)
                        {
                            Dbgl("actor does not have npcappear");
                            return;
                        }
                        Dbgl($"i {i} hair setting {settings.hairs[i]} actor hair: {hairs[settings.hairs[i]]}");
                        //if(settings.hairs[i] != 0)
                        component.SetPart(appearDbDatas[hairs[settings.hairs[i]]]);
                        Dbgl($"actor clothes: {clothes[settings.clothes[i]]}");
                        //if (settings.clothes[i] != 0)
                        component.SetPart(appearDbDatas[clothes[settings.clothes[i]]]);
                    }
                }
            }
Пример #5
0
        private static void ChangeClothes(Actor actor, int hairId, int clothesId)
        {
            if (!enabled)
            {
                return;
            }

            Dictionary <int, AppearDBData> appearDbDatas = AccessTools.FieldRefAccess <NpcAppearModule, Dictionary <int, AppearDBData> >(NpcAppearModule.Self, "m_AppearDBDataDic");

            Dbgl($"changing clothes for {actor.ActorName}");


            NpcAppear component = actor.GetComponent <NpcAppear>();

            if (component == null || !appearDbDatas.ContainsKey(hairId) || !appearDbDatas.ContainsKey(clothesId))
            {
                Dbgl($"no npcappear for {actor.ActorName}");
                return;
            }
            if (hairId > -1)
            {
                component.SetPart(appearDbDatas[hairId]);
            }
            if (clothesId > -1)
            {
                component.SetPart(appearDbDatas[clothesId]);
            }
        }
Пример #6
0
        private static void ReloadActorTextures()
        {
            foreach (KeyValuePair <int, Texture2D> kvp in customTextures)
            {
                Actor actor = Module <ActorMgr> .Self.Get(kvp.Key);

                if (actor == null)
                {
                    continue;
                }
                NpcAppear appear = actor.GetComponent <NpcAppear>();
                if (appear != null)
                {
                    appear.RebuildMesh();
                }
                else
                {
                    SkinnedMeshRenderer[] smrs = actor.gameObject.GetComponentsInChildren <SkinnedMeshRenderer>();
                    for (int i = 0; i < smrs.Length; i++)
                    {
                        if (smrs[i].material?.HasProperty("_MainTex") == true && smrs[i].material.mainTexture != null)
                        {
                            smrs[i].material.mainTexture = kvp.Value;
                        }
                    }
                }
            }
            foreach (KeyValuePair <int, Dictionary <int, Texture2D> > kvp in customTexturesPartial)
            {
                Actor actor = Module <ActorMgr> .Self.Get(kvp.Key);

                if (actor == null)
                {
                    continue;
                }
                NpcAppear appear = actor.GetComponent <NpcAppear>();
                if (appear != null)
                {
                    appear.RebuildMesh();
                }
            }


            int[] rint = Module <RidableModuleManager> .Self.GetAllRidableUid();

            foreach (int r in rint)
            {
                IRidable ridable = Module <RidableModuleManager> .Self.GetRidable(r);

                if (ridable == null)
                {
                    continue;
                }
                string name = ridable.GetNickName();
                Dbgl($"got horse '{name}'");
                if (customTexturesHorse.ContainsKey(name))
                {
                    Dbgl($"got horse texture for {name}");
                    GameObject            go   = ridable.GetActor().gameObject;
                    SkinnedMeshRenderer[] smrs = go.GetComponentsInChildren <SkinnedMeshRenderer>();
                    foreach (SkinnedMeshRenderer mr in smrs)
                    {
                        if (mr.material?.HasProperty("_MainTex") == true && mr.material.mainTexture != null)
                        {
                            Dbgl($"Changing smr texture for {mr.name}");
                            if (mr.name == "saddle")
                            {
                                Dbgl($"Changing saddle");
                                if (customTexturesMisc.ContainsKey($"Saddle_{name}"))
                                {
                                    Texture2D tex = customTexturesMisc[$"Saddle_{name}"];
                                    tex.name = $"Saddle_{name}.png";
                                    mr.material.mainTexture = tex;
                                }
                            }
                            else
                            {
                                Texture2D tex = customTexturesHorse[name];
                                tex.name = $"Horse_{name}.png";
                                mr.material.mainTexture = tex;
                            }
                        }
                    }
                }
            }
        }
Пример #7
0
            private static void Prefix(NpcAppear __instance, List <NpcAppearUnit> npcAppearUnits, Actor ___m_Actor)
            {
                if (___m_Actor == null)
                {
                    Dbgl($"no actor");
                    return;
                }
                if (npcAppearUnits == null)
                {
                    Dbgl($"no npcAppearUnits");
                    return;
                }
                if (customTextures.ContainsKey(___m_Actor.InstanceId))
                {
                    foreach (NpcAppearUnit unit in npcAppearUnits)
                    {
                        if (unit == null || unit.smrs == null)
                        {
                            continue;
                        }
                        for (int i = 0; i < unit.smrs.Length; i++)
                        {
                            Dbgl($"replacing texture for smr {unit.smrs[i].name}");
                            unit.smrs[i].material.mainTexture      = customTextures[___m_Actor.InstanceId];
                            unit.smrs[i].material.mainTexture.name = $"{___m_Actor.InstanceId}_{ unit.smrs[i].name}";
                        }
                    }
                }
                else if (customTexturesExact.ContainsKey(___m_Actor.InstanceId))
                {
                    foreach (NpcAppearUnit unit in npcAppearUnits)
                    {
                        if (unit == null || unit.smrs == null)
                        {
                            continue;
                        }

                        for (int i = 0; i < unit.smrs.Length; i++)
                        {
                            if (customTexturesExact[___m_Actor.InstanceId].ContainsKey(unit.smrs[i].name))
                            {
                                Dbgl($"replacing texture for smr {unit.smrs[i].name}");
                                unit.smrs[i].material.mainTexture      = customTexturesExact[___m_Actor.InstanceId][unit.smrs[i].name];
                                unit.smrs[i].material.mainTexture.name = $"{___m_Actor.InstanceId}_{ unit.smrs[i].name}";
                            }
                        }
                    }
                }
                else if (customTexturesPartial.ContainsKey(___m_Actor.InstanceId))
                {
                    int i = 1;
                    foreach (NpcAppearUnit unit in npcAppearUnits)
                    {
                        if (unit == null || unit.smrs == null)
                        {
                            continue;
                        }
                        if (customTexturesPartial[___m_Actor.InstanceId].ContainsKey(i))
                        {
                            //Dbgl($"got mesh for: {___m_Actor.ActorName} at {i}");
                            unit.smrs[0].material.mainTexture = customTexturesPartial[___m_Actor.InstanceId][i];
                        }
                        i++;
                    }
                }
            }