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 static void DumpQuick()
        {
            var types = new HashSet <Type>()
            {
                typeof(BlueprintCharacterClass),
                typeof(BlueprintRaceVisualPreset),
                typeof(BlueprintRace),
                typeof(BlueprintArchetype),
                typeof(BlueprintProgression),
                typeof(BlueprintStatProgression),
                typeof(BlueprintFeature),
                typeof(BlueprintFeatureSelection),
                typeof(BlueprintSpellbook),
                typeof(BlueprintSpellList),
                typeof(BlueprintSpellsTable),
                typeof(BlueprintItemWeapon),
            };

            foreach (var blueprint in ResourcesLibrary.GetBlueprints <BlueprintScriptableObject>())
            {
                if (types.Contains(blueprint.GetType()))
                {
                    JsonBlueprints.Dump(blueprint);
                }
            }
        }
        public override void WriteJson(JsonWriter w, object o, JsonSerializer szr)
        {
            var go = (UnityEngine.Object)o;
            var j  = new JObject {
                { "$type", JsonBlueprints.GetTypeName(o.GetType()) },
                { "name", go.name },
            };

            j.WriteTo(w);
        }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer szr)
        {
            JObject jObject    = JObject.Load(reader);
            var     name       = (string)jObject["name"];
            var     typeName   = (string)jObject["$type"];
            var     realType   = Type.GetType(typeName);
            var     settings   = JsonBlueprints.CreateSettings(realType);
            var     serializer = JsonSerializer.Create(settings);
            BlueprintScriptableObject result = null;

            if (jObject["$append"] != null)
            {
                serializer.ObjectCreationHandling = ObjectCreationHandling.Reuse;
                var copy = (string)jObject["$append"];
                jObject.Remove("$append");
                var parts = copy.Split(':');
                result = ResourcesLibrary.TryGetBlueprint(parts[1]);
                name   = result.name;
                Main.DebugLog($"Appending to {result.name}");
            }
            if (jObject["$replace"] != null)
            {
                var copy = (string)jObject["$replace"];
                jObject.Remove("$replace");
                var parts = copy.Split(':');
                result = ResourcesLibrary.TryGetBlueprint(parts[1]);
                name   = result.name;
                Main.DebugLog($"replacing to {result.name}");
            }
            if (jObject["$copy"] != null)
            {
                var copy = (string)jObject["$copy"];
                jObject.Remove("$copy");
                var parts    = copy.Split(':');
                var resource = ResourcesLibrary.TryGetBlueprint(parts[1]);
                result = (BlueprintScriptableObject)BlueprintUtil.ShallowClone(resource);
                Main.DebugLog($"Copying {resource.name}");
            }
            if (name == null)
            {
                throw new System.Exception("Missing name");
            }
            if (JsonBlueprints.Blueprints.ContainsKey(name))
            {
                //throw new System.Exception("Cannot create blueprint twice");
            }
            if (result == null)
            {
                result = ScriptableObject.CreateInstance(realType) as BlueprintScriptableObject;
            }
            JsonBlueprints.Blueprints[name] = result;
            BlueprintUtil.AddBlueprint(result, name);
            serializer.Populate(jObject.CreateReader(), result);
            return(result);
        }
Esempio n. 5
0
        public static void DumpBlueprint(BlueprintScriptableObject blueprint, string directory = "Blueprints", bool verbose = false)
        {
            JsonSerializerSettings settings = null;

            if (verbose)
            {
                settings = JsonBlueprints.CreateSettings();
                settings.DefaultValueHandling = DefaultValueHandling.Include;
            }
            JsonBlueprints.Dump(blueprint, $"{directory}/{blueprint.GetType()}/{blueprint.name}.{blueprint.AssetGuid}.json", settings);
        }
 public static void DumpUnitViews()
 {
     foreach (var kv in ResourcesLibrary.LibraryObject.ResourcePathsByAssetId)
     {
         var resource = ResourcesLibrary.TryGetResource <UnitEntityView>(kv.Key);
         if (resource == null)
         {
             continue;
         }
         JsonBlueprints.Dump(resource, kv.Key);
     }
 }
        public override void WriteJson(JsonWriter w, object o, JsonSerializer szr)
        {
            var newSerializer = JsonSerializer.Create(JsonBlueprints.CreateSettings(null));
            var j             = new JObject();

            j.AddFirst(new JProperty("$type", o.GetType().Name));
            foreach (var field in GetSerializableMembers(o.GetType()))
            {
                var value = Traverse.Create(o).Field(field.Name).GetValue();
                j.Add(field.Name, value != null ? JToken.FromObject(value, newSerializer) : null);
            }
            j.WriteTo(w);
        }
        public static void DumpBlueprints()
        {
            var seen = new HashSet <Type>();

            var blueprints = ResourcesLibrary.GetBlueprints <BlueprintScriptableObject>();

            foreach (var blueprint in blueprints)
            {
                if (!seen.Contains(blueprint.GetType()))
                {
                    seen.Add(blueprint.GetType());
                    JsonBlueprints.Dump(blueprint);
                }
            }
        }
        public override void WriteJson(JsonWriter w, object o, JsonSerializer szr)
        {
            var tmp = o as TextMeshProUGUI;

            if (tmp == null)
            {
                w.WriteNull();
                return;
            }
            var j = new JObject();

            j.Add("$type", JsonBlueprints.GetTypeName(tmp.GetType()));
            j.Add("text", tmp.text);
            j.WriteTo(w);
        }
Esempio n. 10
0
 public static void DumpScriptableObjects()
 {
     Directory.CreateDirectory("ScriptableObjects");
     foreach (var obj in UnityEngine.Object.FindObjectsOfType <ScriptableObject>())
     {
         try
         {
             JsonBlueprints.Dump(obj, $"ScriptableObjects/{obj.GetType()}/{obj.name}.{obj.GetInstanceID()}.json");
         }
         catch (Exception ex)
         {
             File.WriteAllText($"ScriptableObjects/{obj.GetType()}/{obj.name}.{obj.GetInstanceID()}.txt", ex.ToString());
         }
     }
 }
Esempio n. 11
0
 public static void DumpScriptableObjects()
 {
     Directory.CreateDirectory("ScriptableObjects");
     foreach (var obj in UnityEngine.Object.FindObjectsOfType <ScriptableObject>())
     {
         try
         {
             if (obj is BlueprintScriptableObject blueprint &&
                 !GetBlueprintMap().ContainsKey(blueprint.AssetGuid))
             {
                 JsonBlueprints.Dump(blueprint, $"ScriptableObjects/{blueprint.GetType()}/{blueprint.name}.{blueprint.AssetGuid}.json");
             }
             else
             {
                 JsonBlueprints.Dump(obj, $"ScriptableObjects/{obj.GetType()}/{obj.name}.{obj.GetInstanceID()}.json");
             }
         }
        public object ReadResource(JsonReader reader, Type objectType, object existingValue, JsonSerializer szr)
        {
            JObject jObject = JObject.Load(reader);
            var     name    = (string)jObject["name"];

            Main.DebugLog($"Deserializing {name} of {objectType.Name} with {GetType().Name}");
            var typeName            = (string)jObject["$type"];
            var realType            = Type.GetType(typeName);
            ScriptableObject result = null;

            if (jObject["$append"] != null)
            {
                var settings = JsonBlueprints.CreateSettings(null);
                szr = JsonSerializer.Create(settings);
                szr.ObjectCreationHandling = ObjectCreationHandling.Reuse;
                var copy = (string)jObject["$append"];
                jObject.Remove("$append");
                var parts = copy.Split(':');
                result = ResourcesLibrary.TryGetResource <ScriptableObject>(parts[1]);
                name   = result.name;
                Main.DebugLog($"Appending to {result.name}");
            }
            if (jObject["$replace"] != null)
            {
                var copy = (string)jObject["$replace"];
                jObject.Remove("$replace");
                var parts = copy.Split(':');
                result = ResourcesLibrary.TryGetBlueprint(parts[1]);
                name   = result.name;
            }
            if (jObject["$copy"] != null)
            {
                var copy = (string)jObject["$copy"];
                jObject.Remove("$copy");
                var parts    = copy.Split(':');
                var resource = ResourcesLibrary.TryGetResource <ScriptableObject>(parts[1]);
                result = (ScriptableObject)BlueprintUtil.ShallowClone(resource);
                Main.DebugLog($"Copying {resource.name}");
            }
            if (result == null)
            {
                result = ScriptableObject.CreateInstance(realType);
            }
            szr.Populate(jObject.CreateReader(), result);
            return(result);
        }
        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}");
        }
Esempio n. 14
0
        public static void DumpUI()
        {
            JsonBlueprints.DumpResource(Game.Instance, "UI/Game.json");
            JsonBlueprints.DumpResource(Game.Instance.UI, "UI/Game.UI.json");
            JsonBlueprints.DumpResource(Game.Instance.BlueprintRoot.UIRoot, "UI/Game.BlueprintRoot.UIRoot.json");
            JsonBlueprints.DumpResource(Game.Instance.DialogController, "UI/Game.DialogController.json");
            var ui = Game.Instance.UI;

            foreach (var field in ui.GetType().GetFields())
            {
                try
                {
                    var value = field.GetValue(ui);
                    if (value == null)
                    {
                        Main.DebugLog($"Null field {field.Name}");
                        continue;
                    }
                    JsonBlueprints.DumpResource(value, $"UI/UI.{value.GetType().FullName}.json");
                }
                catch (Exception ex)
                {
                    Main.DebugLog($"Error dumping UI field {field.Name}");
                }
            }
            foreach (var prop in ui.GetType().GetProperties())
            {
                try
                {
                    var value = prop.GetValue(ui);
                    if (value == null)
                    {
                        Main.DebugLog($"Null property {prop.Name}");
                        continue;
                    }
                    JsonBlueprints.DumpResource(value, $"UI/UI.{value.GetType().FullName}.json");
                }
                catch (Exception ex)
                {
                    Main.DebugLog($"Error dumping UI property {prop.Name}");
                }
            }
        }
        public override void WriteJson(JsonWriter w, object o, JsonSerializer szr)
        {
            var settings      = JsonBlueprints.CreateSettings(null);
            var newSerializer = JsonSerializer.Create(settings);
            var j             = new JObject();

            j.AddFirst(new JProperty("$type", JsonBlueprints.GetTypeName(o.GetType())));
            foreach (var memberInfo in JsonBlueprints.GetUnitySerializableMembers(o.GetType()))
            {
                object value = null;
                if (memberInfo.MemberType == MemberTypes.Field)
                {
                    value = ((FieldInfo)memberInfo).GetValue(o);
                }
                else if (memberInfo.MemberType == MemberTypes.Property)
                {
                    value = ((PropertyInfo)memberInfo).GetValue(o);
                }
                j.Add(memberInfo.Name, value != null ? JToken.FromObject(value, newSerializer) : null);
            }
            j.WriteTo(w);
        }
        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));
        }
        public static void DumpAllBlueprints()
        {
            var blueprints = ResourcesLibrary.GetBlueprints <BlueprintScriptableObject>();

            Directory.CreateDirectory("Blueprints");
            using (var file = new StreamWriter("Blueprints/log.txt"))
            {
                foreach (var blueprint in blueprints)
                {
                    if (blueprint.AssetGuid.Length != 32)
                    {
                        continue;
                    }
                    try
                    {
                        JsonBlueprints.Dump(blueprint);
                    } catch (Exception ex)
                    {
                        file.WriteLine($"Error dumping {blueprint.name}:{blueprint.AssetGuid}:{blueprint.GetType().FullName}, {ex.ToString()}");
                    }
                }
            }
        }
 protected override List <MemberInfo> GetSerializableMembers(Type objectType)
 {
     return(JsonBlueprints.GetUnitySerializableMembers(objectType).Distinct().ToList());
 }
Esempio n. 19
0
        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);
            }
        }
        protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
        {
            var jsonProp = base.CreateProperty(member, memberSerialization);

            void Skip()
            {
                jsonProp.ShouldSerialize   = o => false;
                jsonProp.ShouldDeserialize = o => false;
            }

            void Allow()
            {
                jsonProp.ShouldSerialize   = o => true;
                jsonProp.ShouldDeserialize = o => true;
            }

            if (member is FieldInfo field)
            {
                jsonProp.Readable = true;
                jsonProp.Writable = true;
                if (JsonBlueprints.IsBlacklisted(field))
                {
                    Skip();
                    return(null);
                }
                //BodyPartTypes used by EquipmentEntities are stored as longs with a LongAsEnumAttribute
                if (field.FieldType == typeof(long))
                {
                    var attribute = field.GetCustomAttribute <LongAsEnumAttribute>();
                    if (attribute != null)
                    {
                        jsonProp.ValueProvider   = new LongAsEnumValueProvider(field, attribute.EnumType);
                        jsonProp.PropertyType    = attribute.EnumType;
                        jsonProp.MemberConverter = stringEnumConverter;
                        jsonProp.Converter       = stringEnumConverter;
                    }
                }
                //BlueprintSettingsRoot contains Action and Func fields
                if (field.FieldType == typeof(System.Action) || field.FieldType == typeof(System.Func <bool>))
                {
                    Skip();
                    return(null);
                }
                if (typeof(IEnumerable <BlueprintScriptableObject>).IsAssignableFrom(field.FieldType))
                {
                    //Needed to deserialize AbilityFocus.b689c0b78297dda40a6ae2ff3b8adb5c.json
                    //Newtonsoft.Json.JsonSerializationException
                    // Error converting value "Blueprint:fc4b01e4c4ebbb4448016c03df01902f:MandragoraSwarmDamageFeature" to type 'Kingmaker.Blueprints.BlueprintScriptableObject'.Path 'CustomParameterVariants[0]'
                    //ArgumentException: Could not cast or convert from System.String to Kingmaker.Blueprints.BlueprintScriptableObject.
                    jsonProp.ItemConverter = BlueprintAssetIdConverter;
                }
                if (typeof(BlueprintScriptableObject).IsAssignableFrom(field.FieldType))
                {
                    //MemberConverter required to deserialize see
                    //https://stackoverflow.com/questions/24946362/custom-jsonconverter-is-ignored-for-deserialization-when-using-custom-contract-r
                    //jsonProp.MemberConverter = BlueprintAssetIdConverter;
                    //jsonProp.Converter = BlueprintAssetIdConverter;
                    //Allow();
                }
            }
            else if (member is PropertyInfo property)
            {
            }
            else
            {
                throw new NotImplementedException($"Member type {member.MemberType} not implemented");
            }

            return(jsonProp);
        }
        public override void WriteJson(JsonWriter w, object value, JsonSerializer szr)
        {
            var type = JsonBlueprints.GetTypeName(value.GetType());

            switch (value)
            {
            case Vector2 v:
            {
                new JArray(v.x, v.y)
                .WriteTo(w);
                return;
            }

            case Vector3 v:
            {
                new JArray(v.x, v.y, v.z)
                .WriteTo(w);
                return;
            }

            case Vector4 v:
            {
                new JArray(v.x, v.y, v.z, v.w)
                .WriteTo(w);
                return;
            }

            case Vector2Int v:
            {
                new JArray(v.x, v.y)
                .WriteTo(w);
                return;
            }

            case Vector3Int v:
            {
                new JArray(v.x, v.y, v.z)
                .WriteTo(w);
                return;
            }

            case Matrix4x4 m:
            {
                new JArray(
                    new JArray(m.m00, m.m01, m.m02, m.m03),
                    new JArray(m.m10, m.m11, m.m12, m.m13),
                    new JArray(m.m20, m.m21, m.m22, m.m23),
                    new JArray(m.m30, m.m31, m.m32, m.m33)
                    )
                .WriteTo(w);
                return;
            }

            case Rect r:
            {
                // ReSharper disable once SimilarAnonymousTypeNearby // float
                JObject.FromObject(new { r.x, r.y, r.width, r.height })
                .WriteTo(w);
                return;
            }

            case RectInt r:
            {
                // ReSharper disable once SimilarAnonymousTypeNearby // int
                JObject.FromObject(new { r.x, r.y, r.width, r.height })
                .WriteTo(w);
                return;
            }

            case Bounds b:
            {
                // ReSharper disable once SimilarAnonymousTypeNearby // float
                //Bounds stores vectors as center and extent internally,
                //but size vector is serialized to be consistent with
                //the constructor interface and with BoundsInt
                new JArray(
                    new JArray(b.center.x, b.center.y, b.center.z),
                    new JArray(b.size.x, b.size.y, b.size.z)
                    )
                .WriteTo(w);
                return;
            }

            case BoundsInt b:
            {
                // ReSharper disable once SimilarAnonymousTypeNearby // int
                new JArray(
                    new JArray(b.center.x, b.center.y, b.center.z),
                    new JArray(b.size.x, b.size.y, b.size.z)
                    )
                .WriteTo(w);
                return;
            }

            case Color c:
            {
                var a = new JArray(c.r, c.g, c.b, c.a);
                a.WriteTo(w);
                return;
            }

            case Color32 c:
            {
                var a = new JArray(c.r, c.g, c.b, c.a);
                a.WriteTo(w);
                return;
            }

            case Texture2D t:
            {
                var o = new JObject();
                o.Add("$type", type);
                o.Add("name", t.name);
                o.WriteTo(w);
                return;
            }

            case Sprite s:
            {
                var o = new JObject();
                o.Add("$type", type);
                o.Add("name", s.name);
                o.WriteTo(w);
                return;
            }

            case Mesh m:
            {
                var o = new JObject();
                o.Add("$type", type);
                o.Add("name", m.name);
                o.WriteTo(w);
                return;
            }

            case Material m:
            {
                var o = new JObject();
                o.Add("$type", type);
                o.Add("name", m.name);
                o.WriteTo(w);
                return;
            }

            case AnimationCurve ac:
            {
                var o = new JObject();
                o.Add("$type", type);
                o.Add("preWrapMode", ac.preWrapMode.ToString());
                o.Add("postWrapMode", ac.postWrapMode.ToString());
                var keys = new JArray();
                foreach (var key in ac.keys)
                {
                    var jkey = new JObject();
                    jkey.Add("time", key.time);
                    jkey.Add("value", key.value);
                    jkey.Add("inTangent", key.inTangent);
                    jkey.Add("outTangent", key.outTangent);
                    jkey.Add("inWeight", key.inWeight);
                    jkey.Add("outWeight", key.outWeight);
                    keys.Add(jkey);
                }
                o.Add("keys", keys);
                o.WriteTo(w);
                return;
            }
            }
        }
Esempio n. 22
0
        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);
            }
        }
Esempio n. 23
0
 public static BlueprintInfo Load()
 {
     return(JsonBlueprints.Load <BlueprintInfo>($"{Main.ModPath}/data/BlueprintInfo.json"));
 }
 List <MemberInfo> GetSerializableMembers(Type objectType)
 {
     return(JsonBlueprints.GetUnitySerializableMembers(objectType));
 }
Esempio n. 25
0
 public static void DumpBlueprint(BlueprintScriptableObject blueprint)
 {
     JsonBlueprints.Dump(blueprint, $"Blueprints/{blueprint.GetType()}/{blueprint.name}.{blueprint.AssetGuid}.json");
 }
Esempio n. 26
0
 static void DumpResource(UnityEngine.Object resource, string assetId)
 {
     Directory.CreateDirectory($"Blueprints/{resource.GetType()}");
     JsonBlueprints.Dump(resource, $"Blueprints/{resource.GetType()}/{resource.name}.{assetId}.json");
 }
Esempio n. 27
0
 public static void DumpKingdom()
 {
     JsonBlueprints.Dump(KingdomState.Instance, "Kingdom");
 }