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);
            }
        }
Ejemplo n.º 2
0
        public static void DumpList()
        {
            var resourceTypes = new Type[]
            {
                typeof(EquipmentEntity),
                typeof(Familiar),
                typeof(UnitEntityView),
                typeof(ProjectileView)
                //Note: PrefabLink : WeakResourceLink<GameObject> exists
            };

            Directory.CreateDirectory($"Blueprints/");
            var blueprints          = ResourcesLibrary.GetBlueprints <BlueprintScriptableObject>().ToList();
            var blueprintsByAssetId = ResourcesLibrary.LibraryObject.BlueprintsByAssetId;

            Main.DebugLog($"BlueprintsByAssetId contains  {blueprintsByAssetId.Count} blueprints");
            Main.DebugLog($"Dumping {blueprints.Count} blueprints");
            using (var file = new StreamWriter("Blueprints/Blueprints.txt"))
            {
                file.WriteLine($"name\tAssetId\tType");
                foreach (var blueprint in blueprints)
                {
                    file.WriteLine($"{blueprint.name}\t{blueprint.AssetGuid}\t{blueprint.GetType()}");
                }
            }
            var resourcePathsByAssetId = ResourcesLibrary.LibraryObject.ResourceNamesByAssetId;

            Main.DebugLog($"ResourcePathsByAssetId contains  {blueprintsByAssetId.Count} resources");
            using (var file = new StreamWriter("Blueprints/Resources.txt"))
            {
                file.WriteLine($"Name\tAssetId\tType\tBaseType\tInstanceId");
                foreach (var kv in ResourcesLibrary.LibraryObject.ResourceNamesByAssetId)
                {
                    var resource = ResourcesLibrary.TryGetResource <UnityEngine.Object>(kv.Key);
                    if (resource != null)
                    {
                        var baseType = resource.GetType().IsAssignableFrom(typeof(UnityEngine.GameObject)) ? "GameObject" :
                                       resource.GetType().IsAssignableFrom(typeof(UnityEngine.ScriptableObject)) ? "ScriptableObject" :
                                       resource.GetType().IsAssignableFrom(typeof(UnityEngine.Component)) ? "Component" :
                                       "Object";
                        var go       = resource as GameObject;
                        var typeName = resource?.GetType().Name ?? "NULL";
                        if (go != null)
                        {
                            foreach (var type in resourceTypes)
                            {
                                if (go.GetComponent(type) != null)
                                {
                                    typeName = type.Name;
                                }
                            }
                        }
                        file.WriteLine($"{kv.Value}\t{kv.Key}\t{typeName}\t{baseType}\t{resource?.GetInstanceID()}");
                        ResourcesLibrary.CleanupLoadedCache();
                    }
                }
            }
        }
Ejemplo n.º 3
0
 public static void DumpUnitViews()
 {
     foreach (var kv in ResourcesLibrary.LibraryObject.ResourceNamesByAssetId)
     {
         var resource = ResourcesLibrary.TryGetResource <UnitEntityView>(kv.Key);
         if (resource == null)
         {
             continue;
         }
         DumpResource(resource, kv.Key);
         ResourcesLibrary.CleanupLoadedCache();
     }
 }
Ejemplo n.º 4
0
        public static void DumpList()
        {
            Directory.CreateDirectory($"Blueprints/");
            var blueprints          = ResourcesLibrary.GetBlueprints <BlueprintScriptableObject>().ToList();
            var blueprintsByAssetId = ResourcesLibrary.LibraryObject.BlueprintsByAssetId;

            Main.DebugLog($"BlueprintsByAssetId contains  {blueprintsByAssetId.Count} blueprints");
            Main.DebugLog($"Dumping {blueprints.Count} blueprints");
            using (var file = new StreamWriter("Blueprints/Blueprints.txt"))
            {
                file.WriteLine($"name\tAssetId\tType");
                foreach (var blueprint in blueprints)
                {
                    file.WriteLine($"{blueprint.name}\t{blueprint.AssetGuid}\t{blueprint.GetType()}");
                }
            }
            var resourcePathsByAssetId = ResourcesLibrary.LibraryObject.ResourceNamesByAssetId;

            Main.DebugLog($"ResourcePathsByAssetId contains  {blueprintsByAssetId.Count} resources");
            using (var file = new StreamWriter("Blueprints/Resources.txt"))
            {
                file.WriteLine($"name\tResourcenName\tAssetId\tType\tBaseType\tInstanceId");
                foreach (var kv in ResourcesLibrary.LibraryObject.ResourceNamesByAssetId)
                {
                    var resource = ResourcesLibrary.TryGetResource <UnityEngine.Object>(kv.Key);
                    if (resource != null)
                    {
                        var baseType = resource.GetType().IsAssignableFrom(typeof(UnityEngine.GameObject)) ? "GameObject" :
                                       resource.GetType().IsAssignableFrom(typeof(UnityEngine.ScriptableObject)) ? "ScriptableObject" :
                                       resource.GetType().IsAssignableFrom(typeof(UnityEngine.Component)) ? "Component" :
                                       "Object";
                        var go       = resource as GameObject;
                        var typeName = resource?.GetType().Name ?? "NULL";
                        if (go != null)
                        {
                            typeName = go.GetComponents <MonoBehaviour>().Join(c => c.GetType().Name);
                        }
                        file.WriteLine($"{resource?.name ?? "NULL"}\t{kv.Key}\t{kv.Value}\t{typeName}\t{baseType}\t{resource?.GetInstanceID()}");
                        ResourcesLibrary.CleanupLoadedCache();
                    }
                }
            }
        }
        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();
            }
        }