static void LoadFxLookup(bool forceReload = false)
        {
            var filepath = $"{Main.ModEntry.Path}/fxlookup.txt";

            if (File.Exists(filepath) && !forceReload)
            {
                FXIds = File
                        .ReadAllLines($"{Main.ModEntry.Path}/fxlookup.txt")
                        .Where(id => LibraryThing.GetResourceGuidMap().ContainsKey(id))
                        .ToArray();
            }
            else
            {
                var idList = new List <string>();
                foreach (var kv in LibraryThing.GetResourceGuidMap())
                {
                    var obj = ResourcesLibrary.TryGetResource <UnityEngine.Object>(kv.Key);
                    var go  = obj as GameObject;
                    if (go != null && go.GetComponent <PooledFx>() != null)
                    {
                        idList.Add(kv.Key);
                    }
                    ResourcesLibrary.CleanupLoadedCache();
                }
                FXIds = idList
                        .OrderBy(id => LibraryThing.GetResourceGuidMap()[id])
                        .ToArray();
                File.WriteAllLines(filepath, FXIds);
            }
        }
Exemple #2
0
        static void BuildViewLookup()
        {
            string getViewName(BlueprintUnit bp)
            {
                if (!LibraryThing.GetResourceGuidMap().ContainsKey(bp.Prefab.AssetId))
                {
                    return("NULL");
                }
                var path = LibraryThing.GetResourceGuidMap()[bp.Prefab.AssetId].Split('/');

                return(path[path.Length - 1]);
            }

            var units = BluePrintThing.GetBlueprints <BlueprintUnit>().OrderBy(getViewName);

            foreach (var bp in units)
            {
                if (bp.Prefab.AssetId == "")
                {
                    continue;
                }
                if (!LibraryThing.GetResourceGuidMap().ContainsKey(bp.Prefab.AssetId))
                {
                    continue;
                }
                if (m_Units.ContainsKey(bp.Prefab.AssetId))
                {
                    continue;
                }
                m_Units[bp.Prefab.AssetId] = getViewName(bp);
            }
        }
 static string GetName(EquipmentEntityLink link)
 {
     if (LibraryThing.GetResourceGuidMap().ContainsKey(link.AssetId))
     {
         return(LibraryThing.GetResourceGuidMap()[link.AssetId]);
     }
     return(null);
 }
        //Refer FxHelper.SpawnFxOnGameObject
        static void ShowFxInfo(UnitEntityData unitEntityData)
        {
            //Choose FX
            GUILayout.Label($"Choose FX {FXIds.Length} available", GUILayout.Width(200f));
            if (FXIds.Length == 0)
            {
                LoadFxLookup();
            }
            GUILayout.BeginHorizontal();
            fxIndex = (int)GUILayout.HorizontalSlider(fxIndex, 0, FXIds.Length - 1, GUILayout.Width(300));
            if (GUILayout.Button("Prev", GUILayout.Width(45)))
            {
                fxIndex = fxIndex == 0 ? 0 : fxIndex - 1;
            }
            if (GUILayout.Button("Next", GUILayout.Width(45)))
            {
                fxIndex = fxIndex >= FXIds.Length - 1 ? FXIds.Length - 1 : fxIndex + 1;
            }
            var fxId = FXIds[fxIndex];

            GUILayout.Label($"{LibraryThing.GetResourceGuidMap()[fxId]} {FXIds[fxIndex]}");
            if (GUILayout.Button("Apply", GUILayout.Width(200)))
            {
                var prefab = ResourcesLibrary.TryGetResource <GameObject>(fxId);
                FxHelper.SpawnFxOnUnit(prefab, unitEntityData.View);
            }
            if (GUILayout.Button("Clear FX Cache", GUILayout.Width(200)))
            {
                LoadFxLookup(forceReload: true);
            }
            GUILayout.EndHorizontal();
            //List of SpawnFxOnStart
            var spawnOnStart = unitEntityData.View.GetComponent <SpawnFxOnStart>();

            if (spawnOnStart)
            {
                GUILayout.Label("Spawn on Start", GUILayout.Width(200f));
                GUILayout.Label("FxOnStart " + spawnOnStart.FxOnStart?.Load()?.name, GUILayout.Width(400));
                GUILayout.Label("FXFxOnDeath " + spawnOnStart.FxOnStart?.Load()?.name, GUILayout.Width(400));
            }
            GUILayout.Label("Decals");
            var decals = Traverse.Create(unitEntityData.View).Field("m_Decals").GetValue <List <FxDecal> >();

            for (int i = decals.Count - 1; i >= 0; i--)
            {
                var decal = decals[i];
                GUILayout.Label("Decal: " + decal.name, GUILayout.Width(400));
                if (GUILayout.Button("Destroy", GUILayout.Width(200f)))
                {
                    GameObject.Destroy(decal.gameObject);
                    decals.RemoveAt(i);
                }
            }
            GUILayout.Label("CustomWeaponEffects", GUILayout.Width(200f));
            var dollroom = Game.Instance.UI.Common.DollRoom;

            foreach (var kv in EffectsManager.WeaponEnchantments)
            {
                GUILayout.Label($"{kv.Key.Name} - {kv.Value.Count}");
                foreach (var go in kv.Value)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Label($"  {go?.name ?? "NULL"}");
                    if (dollroom != null && GUILayout.Button("UnscaleFXTimes", GUILayout.ExpandWidth(false)))
                    {
                        Traverse.Create(dollroom).Method("UnscaleFxTimes", new object[] { go }).GetValue();
                    }
                    GUILayout.EndHorizontal();
                }
            }
            GUILayout.Label("FXRoot", GUILayout.Width(200f));
            foreach (Transform t in FxHelper.FxRoot.transform)
            {
                var            pooledFX       = t.gameObject.GetComponent <PooledFx>();
                var            snapToLocaters = (List <SnapToLocator>)AccessTools.Field(typeof(PooledFx), "m_SnapToLocators").GetValue(pooledFX);
                var            fxBone         = snapToLocaters.Select(s => s.Locator).FirstOrDefault();
                UnitEntityView unit           = null;
                if (fxBone != null)
                {
                    var viewTransform = fxBone.Transform;
                    while (viewTransform != null && unit == null)
                    {
                        unit = viewTransform.GetComponent <UnitEntityView>();
                        if (unit == null)
                        {
                            viewTransform = viewTransform.parent;
                        }
                    }
                }
                GUILayout.BeginHorizontal();
                if (unit != null)
                {
                    GUILayout.Label($"{pooledFX.name} - {unit.EntityData.CharacterName} - {unit.name}", GUILayout.Width(200f));
                }
                else
                {
                    GUILayout.Label($"{pooledFX.name}", GUILayout.Width(200f));
                }
                if (GUILayout.Button("DestroyFX", GUILayout.Width(200)))
                {
                    FxHelper.Destroy(t.gameObject);
                }
                GUILayout.EndHorizontal();
            }
        }
        static void BuildOrphanedEquipment()
        {
            string maleFilepath = "Mods/VisualAdjustments/MaleOrphanedEquipment.json";

            if (File.Exists(maleFilepath))
            {
                JsonSerializer serializer = new JsonSerializer();
                using (StreamReader sr = new StreamReader(maleFilepath))
                    using (JsonTextReader reader = new JsonTextReader(sr))
                    {
                        var result = serializer.Deserialize <Dictionary <string, string> >(reader);
                        m_OrphanedMaleEquipment = result;
                        if (m_OrphanedMaleEquipment == null)
                        {
                            Main.Log($"Error loading {maleFilepath}");
                        }
                    }
            }
            var femaleFilepath = "Mods/VisualAdjustments/FemaleOrphanedEquipment.json";

            if (File.Exists(femaleFilepath))
            {
                JsonSerializer serializer = new JsonSerializer();
                using (StreamReader sr = new StreamReader(femaleFilepath))
                    using (JsonTextReader reader = new JsonTextReader(sr))
                    {
                        var result = serializer.Deserialize <Dictionary <string, string> >(reader);
                        m_OrphanedFemaleEquipment = result;
                        if (m_OrphanedFemaleEquipment == null)
                        {
                            Main.Log($"Error loading {femaleFilepath}");
                        }
                    }
            }
            if (m_OrphanedMaleEquipment == null || m_OrphanedFemaleEquipment == null)
            {
                Main.Log("Rebuilding Orphaned Equipment Lookup");
                var eeBlacklist = new HashSet <string>();
                foreach (var gender in new Gender[] { Gender.Male, Gender.Female })
                {
                    foreach (var race in BlueprintRoot.Instance.Progression.CharacterRaces)
                    {
                        var armorLinks = BluePrintThing.GetBlueprints <KingmakerEquipmentEntity>()
                                         .SelectMany(kee => kee.GetLinks(gender, race.RaceId));
                        var options = gender == Gender.Male ? race.MaleOptions : race.FemaleOptions;
                        var links   = race.Presets
                                      .SelectMany(preset => preset.Skin.GetLinks(gender, race.RaceId))
                                      .Concat(armorLinks)
                                      .Concat(options.Beards)
                                      .Concat(options.Eyebrows)
                                      .Concat(options.Hair)
                                      .Concat(options.Heads)
                                      .Concat(options.Horns);
                        foreach (var link in links)
                        {
                            eeBlacklist.Add(link.AssetId);
                        }
                    }
                }

                m_OrphanedMaleEquipment   = new Dictionary <string, string>();
                m_OrphanedFemaleEquipment = new Dictionary <string, string>();
                foreach (var kv in LibraryThing.GetResourceGuidMap().OrderBy(kv => kv.Value))
                {
                    if (eeBlacklist.Contains(kv.Key))
                    {
                        continue;
                    }
                    var ee = ResourcesLibrary.TryGetResource <EquipmentEntity>(kv.Key);
                    if (ee == null)
                    {
                        continue;
                    }
                    var  nameParts = ee.name.Split('_');
                    bool isMale    = nameParts.Contains("M");
                    bool isFemale  = nameParts.Contains("F");
                    if (!isMale && !isFemale)
                    {
                        isMale   = true;
                        isFemale = true;
                    }
                    if (isMale)
                    {
                        m_OrphanedMaleEquipment[kv.Key] = kv.Value;
                    }
                    if (isFemale)
                    {
                        m_OrphanedFemaleEquipment[kv.Key] = kv.Value;
                    }
                }
                JsonSerializer serializer = new JsonSerializer();
                serializer.Formatting = Formatting.Indented;
                using (StreamWriter sw = new StreamWriter(maleFilepath))
                    using (JsonWriter writer = new JsonTextWriter(sw))
                    {
                        serializer.Serialize(writer, m_OrphanedMaleEquipment);
                    }
                using (StreamWriter sw = new StreamWriter(femaleFilepath))
                    using (JsonWriter writer = new JsonTextWriter(sw))
                    {
                        serializer.Serialize(writer, m_OrphanedFemaleEquipment);
                    }
                ResourcesLibrary.CleanupLoadedCache();
            }
        }