public static void LoadStrings()
        {
            Dictionary <string, string> strings = null;
            var currentLocale = LocalizationManager.CurrentLocale;

            if (File.Exists($"{Main.ModPath}/data/localization/{currentLocale}.json"))
            {
                strings = JsonBlueprints.Load <Dictionary <string, string> >($"{Main.ModPath}/data/localization/{currentLocale}.json");
            }
            else if (File.Exists($"{Main.ModPath}/data/localization/enGB.json"))
            {
                Main.DebugLog($"Could not find locale {currentLocale}");
                strings = JsonBlueprints.Load <Dictionary <string, string> >($"{Main.ModPath}/data/localization/enGB.json");
            }
            else
            {
                Main.DebugLog($"Could not find any localization file");
            }
            if (strings == null)
            {
                return;
            }
            foreach (var kv in strings)
            {
                if (LocalizationManager.CurrentPack.Strings.ContainsKey(kv.Key))
                {
                    Main.DebugLog($"Duplicate localization string key {kv.Key}");
                }
                else
                {
                    LocalizationManager.CurrentPack.Strings[kv.Key] = kv.Value;
                }
            }
        }
        public override object ReadJson(JsonReader reader, Type type, object existing, JsonSerializer serializer)
        {
            string text = (string)reader.Value;

            if (text == null || text == "null")
            {
                return(null);
            }
            if (text.StartsWith("Resource"))
            {
                var parts = text.Split(':');
                var link  = (WeakResourceLink)Activator.CreateInstance(type);
                link.AssetId = parts[1];
                return(link);
            }
            if (text.StartsWith("File:"))
            {
                var parts = text.Split(':');
                var path  = $"{Main.ModPath}/data/{parts[1]}";
                if (JsonBlueprints.ResourceAssetIds.ContainsKey(path))
                {
                    var link = (WeakResourceLink)Activator.CreateInstance(type);
                    link.AssetId = JsonBlueprints.ResourceAssetIds[path];
                    return(link);
                }
                else
                {
                    var baseType = type;
                    while (baseType.IsSubclassOf(typeof(WeakResourceLink)))
                    {
                        baseType = baseType.BaseType;
                    }
                    var isType       = baseType == typeof(WeakResourceLink);
                    var resourceLink = type.BaseType;
                    var resourceType = resourceLink.GenericTypeArguments[0];
                    var resource     = (UnityEngine.Object)JsonBlueprints.Load(path, resourceType);
                    var assetId      = BlueprintUtil.AddResource <UnityEngine.Object>(resource, path);
                    JsonBlueprints.ResourceAssetIds[path] = assetId;
                    var link = (WeakResourceLink)Activator.CreateInstance(type);
                    link.AssetId = assetId;
                    return(link);
                }
            }
            throw new NotImplementedException($"Not implemented for type {type} with value {text}");
        }
        public override object ReadJson(
            JsonReader reader,
            Type objectType,
            object existingValue,
            JsonSerializer serializer
            )
        {
            string text = (string)reader.Value;

            if (text == null || text == "null")
            {
                return(null);
            }
            if (text.StartsWith("Blueprint"))
            {
                var parts = text.Split(':');
                BlueprintScriptableObject blueprintScriptableObject = ResourcesLibrary.TryGetBlueprint(parts[1]);
                if (blueprintScriptableObject == null)
                {
                    //throw new JsonSerializationException(string.Format("Failed to load blueprint by guid {0}", text));
                }
                return(blueprintScriptableObject);
            }
            if (text.StartsWith("File"))
            {
                var parts         = text.Split(':');
                var path          = $"{Main.ModPath}/data/{parts[1]}";
                var blueprintName = Path.GetFileNameWithoutExtension(path);
                if (JsonBlueprints.Blueprints.ContainsKey(blueprintName))
                {
                    return(JsonBlueprints.Blueprints[blueprintName]);
                }
                Main.DebugLog($"Reading blueprint from file: {text}");
                var result = JsonBlueprints.Load(path, objectType);
                return(result);
            }
            throw new JsonSerializationException(string.Format("Invalid blueprint format {0}", text));
        }
        static void OnGUI(UnityModManager.ModEntry modEntry)
        {
            try
            {
                if (!enabled)
                {
                    return;
                }
#if (DEBUG)
                if (GUILayout.Button("DumpClassRaceBlueprints"))
                {
                    AssetsDump.DumpQuick();
                }
                if (GUILayout.Button("DumpSampleOfBlueprints"))
                {
                    AssetsDump.DumpBlueprints();
                }
                if (GUILayout.Button("DumpAllBlueprints"))
                {
                    AssetsDump.DumpAllBlueprints();
                }
                if (GUILayout.Button("DumpEquipmentEntities"))
                {
                    AssetsDump.DumpEquipmentEntities();
                }
                if (GUILayout.Button("DumpUnitViews"))
                {
                    AssetsDump.DumpUnitViews();
                }
                if (GUILayout.Button("DumpList"))
                {
                    AssetsDump.DumpList();
                }
                if (GUILayout.Button("TestLoad"))
                {
                    //var bp = JsonBlueprints.Load<BlueprintCharacterClass>("mods/customraces/data/slayerclass.json");
                    //DebugLog("Loaded " + (bp?.name ?? "NULL"));
                    //var info = BlueprintInfo.Load();
                    //DebugLog("Loaded " + info.Classes[0].name);
                    var vp = JsonBlueprints.Load <BlueprintRaceVisualPreset>("mods/customraces/data/TestPreset.json");
                    DebugLog("Loaded " + vp.name);
                }

                /*
                 * UnityEngine.Networking.NetworkTransport.GetAssetId(go) //returns ""
                 * internal static extern bool Object.DoesObjectWithInstanceIDExist(int instanceID); //returns true
                 * internal static extern Object Object.FindObjectFromInstanceID(int instanceID); // returns CR_Hair_VioletDark_U_HM
                 * Resources.FindObjectsOfTypeAll<Texture2D>() // returns CR_Hair_VioletDark_U_HM after it has been loaded with Resource.Load
                 */
                if (GUILayout.Button("FindObject"))
                {
                    var go = BlueprintUtil.FindObjectByInstanceId <GameObject>(270194);
                    DebugLog("FindByID " + go == null ? "NULL" : go.name); //OH_LongswordThieves

                    var sprite = BlueprintUtil.FindObjectByInstanceId <Sprite>(45820);
                    DebugLog(sprite == null ? "NULL" : sprite.name); //OH_LongswordThieves

                    var texture1 = BlueprintUtil.FindObjectByInstanceId <Texture2D>(552466);
                    DebugLog(texture1 == null ? "NULL" : texture1.name);                                                   //CR_Hair_VioletDark_U_HM

                    var humanHair = ResourcesLibrary.TryGetResource <EquipmentEntity>("a9558cfc0705d4e48af7ecd2ebd75411"); //EE_Hair_HairLongWavy_M_HM

                    var texture2 = BlueprintUtil.FindObjectByInstanceId <Texture2D>(552466);
                    DebugLog(texture2 == null ? "NULL" : texture2.name); //CR_Hair_VioletDark_U_HM
                }
                if (GUILayout.Button("FindObject2"))
                {
                    var doesExist = Traverse.Create <UnityEngine.Object>().Method("DoesObjectWithInstanceIDExist", new object[] { 552466 }).GetValue <bool>();
                    DebugLog($"Does resource exist first {doesExist}");
                    var tex1 = Traverse.Create <UnityEngine.Object>().Method("FindObjectFromInstanceID", new object[] { 552466 }).GetValue <UnityEngine.Object>();
                    DebugLog(tex1 == null ? "NULL" : tex1.name);                                                           //CR_Hair_VioletDark_U_HM

                    var humanHair = ResourcesLibrary.TryGetResource <EquipmentEntity>("a9558cfc0705d4e48af7ecd2ebd75411"); //EE_Hair_HairLongWavy_M_HM

                    doesExist = Traverse.Create <UnityEngine.Object>().Method("DoesObjectWithInstanceIDExist", new object[] { 552466 }).GetValue <bool>();
                    DebugLog($"Does resource exist second {doesExist}");
                    var tex2 = Traverse.Create <UnityEngine.Object>().Method("FindObjectFromInstanceID", new object[] { 552466 }).GetValue <UnityEngine.Object>();
                    DebugLog(tex2 == null ? "NULL" : tex2.name); //CR_Hair_VioletDark_U_HM


                    var go = (GameObject)BlueprintUtil.FindObjectByInstanceId <GameObject>(270194);
                    DebugLog("FindByID " + go == null ? "NULL" : go.name); //OH_LongswordThieves

                    var assetId = UnityEngine.Networking.NetworkTransport.GetAssetId(go);
                    if (assetId == null)
                    {
                        assetId = "NULL";
                    }
                    if (assetId == "")
                    {
                        assetId = "Empty";
                    }
                    DebugLog($"AssetId: {assetId}");
                }

                if (GUILayout.Button("Reload"))
                {
                    BlueprintManager.Reload();
                }
                int newTorso = (int)GUILayout.HorizontalSlider(torso, -1, MeshTestRace.testAssets.Length - 1, GUILayout.Width(300));
                GUILayout.Label("Torso: " + newTorso);
                if (torso != newTorso)
                {
                    torso = newTorso;
                    MeshTestRace.ChooseTorso(torso);
                }
#endif
            } catch (Exception e)
            {
                DebugLog(e.ToString() + " " + e.StackTrace);
            }
        }
        static void OnGUI(UnityModManager.ModEntry modEntry)
        {
            try
            {
                if (!enabled)
                {
                    return;
                }
#if (DEBUG)
                GUILayout.Label($"Game Version: {GameVersion.GetVersion()}");
                if (GUILayout.Button("DumpAssets"))
                {
                    AssetsDump.DumpAssets();
                }
                if (GUILayout.Button("DumpClassRaceBlueprints"))
                {
                    AssetsDump.DumpQuick();
                }
                if (GUILayout.Button("DumpSampleOfBlueprints"))
                {
                    AssetsDump.DumpBlueprints();
                }
                if (GUILayout.Button("DumpAllBlueprints"))
                {
                    AssetsDump.DumpAllBlueprints();
                }
                if (GUILayout.Button("DumpAllBlueprintsVerbose"))
                {
                    AssetsDump.DumpAllBlueprintsVerbose();
                }
                if (GUILayout.Button("DumpFlags"))
                {
                    var blueprints = ResourcesLibrary.GetBlueprints <BlueprintUnlockableFlag>();
                    Directory.CreateDirectory("Blueprints");
                    using (var file = new StreamWriter("Blueprints/log.txt"))
                    {
                        foreach (var blueprint in blueprints)
                        {
                            if (blueprint.AssetGuid.Length != 32)
                            {
                                continue;
                            }
                            Main.DebugLog($"Dumping {blueprint.name} - {blueprint.AssetGuid}");
                            try
                            {
                                AssetsDump.DumpBlueprint(blueprint);
                            }
                            catch (Exception ex)
                            {
                                file.WriteLine($"Error dumping {blueprint.name}:{blueprint.AssetGuid}:{blueprint.GetType().FullName}, {ex.ToString()}");
                            }
                        }
                    }
                }
                if (GUILayout.Button("DumpEquipmentEntities"))
                {
                    AssetsDump.DumpEquipmentEntities();
                }
                if (GUILayout.Button("DumpUnitViews"))
                {
                    AssetsDump.DumpUnitViews();
                }
                if (GUILayout.Button("DumpList"))
                {
                    AssetsDump.DumpList();
                }
                if (GUILayout.Button("DumpScriptableObjects"))
                {
                    AssetsDump.DumpScriptableObjects();
                }
                if (GUILayout.Button("DumpAssetBundles"))
                {
                    AssetsDump.DumpAssetBundles();
                }
                if (GUILayout.Button("DumpUI"))
                {
                    AssetsDump.DumpUI();
                }
                if (GUILayout.Button("DumpSceneList"))
                {
                    AssetsDump.DumpSceneList();
                }
                if (GUILayout.Button("DumpKingdom"))
                {
                    AssetsDump.DumpKingdom();
                }
                if (GUILayout.Button("DumpView"))
                {
                    var view      = ResourcesLibrary.TryGetResource <GameObject>("adf003833b2463543a065d5160c7e8f1");
                    var character = view.GetComponent <Character>();
                    JsonBlueprints.Dump(character, "adf003833b2463543a065d5160c7e8f1");
                }
                if (GUILayout.Button("TestLoad"))
                {
                    var vp = JsonBlueprints.Load <BlueprintRaceVisualPreset>("mods/customraces/data/TestPreset.json");
                    DebugLog("Loaded " + vp.name);
                }
#endif
            } catch (Exception e)
            {
                DebugLog(e.ToString() + " " + e.StackTrace);
            }
        }
Exemple #6
0
 public static BlueprintInfo Load()
 {
     return(JsonBlueprints.Load <BlueprintInfo>($"{Main.ModPath}/data/BlueprintInfo.json"));
 }