Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // @Author: Max G. (CloneTrooper1019)
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // JSON API Dump can be fetched like such:
- // http://setup.roblox.com/versionQTStudio -> "version-b724ac4d89fb4d66"
- // http://setup.roblox.com/version-b724ac4d89fb4d66-API-Dump.json
- // Plug in the resulting JSON data from that url into ReflectionDatabase.Load() and it should give you the full data structure.
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- #pragma warning disable 0649
- namespace Roblox.Reflection
- {
- public enum MemberType
- {
- Property,
- Function,
- Event,
- Callback
- }
- public enum SecurityType
- {
- None,
- PluginSecurity,
- LocalUserSecurity,
- RobloxScriptSecurity,
- RobloxSecurity,
- NotAccessibleSecurity
- }
- public enum TypeCategory
- {
- Primitive,
- Class,
- Enum,
- Group,
- DataType
- }
- public struct ReadWriteSecurity
- {
- public SecurityType Read;
- public SecurityType Write;
- public override string ToString()
- {
- return "Read: " + Enum.GetName(typeof(SecurityType), Read) +
- " | Write: " + Enum.GetName(typeof(SecurityType), Write);
- }
- }
- public struct MemberSerialization
- {
- public bool CanSave;
- public bool CanLoad;
- public override string ToString()
- {
- return "Saves: " + CanSave + " | Loads: " + CanLoad;
- }
- }
- public struct RobloxType
- {
- public TypeCategory Category;
- public string Name;
- public override string ToString()
- {
- return Name;
- }
- }
- public struct Parameter
- {
- public RobloxType Type;
- public string Name;
- public string Default;
- public override string ToString()
- {
- if (Default != null && Default.Length > 0)
- {
- return Type.Name + " " + Name + " = " + Default;
- }
- else
- {
- return Type.Name + " " + Name;
- }
- }
- }
- public class ClassReader : JsonConverter
- {
- public override bool CanRead => true;
- public override bool CanWrite => false;
- public override bool CanConvert(Type objectType)
- {
- return objectType == typeof(ClassDescriptor);
- }
- public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
- {
- JObject obj = JObject.Load(reader);
- JToken[] members = obj.GetValue("Members").ToArray();
- JToken superToken = obj.GetValue("Superclass");
- Descriptor desc = obj.ToObject<Descriptor>();
- ClassDescriptor classDesc = new ClassDescriptor();
- classDesc.Name = desc.Name;
- classDesc.Tags = desc.Tags;
- classDesc.Superclass = superToken.ToString();
- foreach (JToken member in members)
- {
- MemberType memberType;
- if (Enum.TryParse(member.Value<string>("MemberType"), out memberType))
- {
- switch (memberType)
- {
- case MemberType.Property:
- PropertyDescriptor prop = member.ToObject<PropertyDescriptor>();
- classDesc.Properties.Add(prop);
- break;
- case MemberType.Function:
- FunctionDescriptor func = member.ToObject<FunctionDescriptor>();
- classDesc.Functions.Add(func);
- break;
- case MemberType.Callback:
- CallbackDescriptor call = member.ToObject<CallbackDescriptor>();
- classDesc.Callbacks.Add(call);
- break;
- case MemberType.Event:
- EventDescriptor evnt = member.ToObject<EventDescriptor>();
- classDesc.Events.Add(evnt);
- break;
- }
- }
- }
- return classDesc;
- }
- public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
- {
- throw new NotImplementedException();
- }
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- public class Descriptor
- {
- public string Name;
- public List<string> Tags;
- public override string ToString()
- {
- return Name;
- }
- }
- [ JsonConverter( typeof(ClassReader) ) ]
- public class ClassDescriptor : Descriptor
- {
- public string Superclass;
- public List<PropertyDescriptor> Properties;
- public List<FunctionDescriptor> Functions;
- public List<CallbackDescriptor> Callbacks;
- public List<EventDescriptor> Events;
- public ClassDescriptor()
- {
- Properties = new List<PropertyDescriptor>();
- Functions = new List<FunctionDescriptor>();
- Callbacks = new List<CallbackDescriptor>();
- Events = new List<EventDescriptor>();
- }
- }
- public class MemberDescriptor : Descriptor
- {
- public MemberType MemberType;
- }
- public class PropertyDescriptor : MemberDescriptor
- {
- public string Category;
- public RobloxType ValueType;
- public ReadWriteSecurity Security;
- }
- public class FunctionDescriptor : MemberDescriptor
- {
- public List<Parameter> Parameters;
- public RobloxType ReturnType;
- public SecurityType Security;
- }
- public class EventDescriptor : MemberDescriptor
- {
- public List<Parameter> Parameters;
- public SecurityType Security;
- }
- public class CallbackDescriptor : MemberDescriptor
- {
- public List<Parameter> Parameters;
- public RobloxType ReturnType;
- public SecurityType Security;
- }
- public class EnumDescriptor : Descriptor
- {
- public List<EnumItemDescriptor> Items;
- }
- public class EnumItemDescriptor : Descriptor
- {
- public int Value;
- }
- public class ReflectionDatabase
- {
- public int Version;
- public List<ClassDescriptor> Classes;
- public List<EnumDescriptor> Enums;
- public static ReflectionDatabase Load(string fullJsonApiDump)
- {
- JsonSerializerSettings settings = new JsonSerializerSettings();
- settings.TypeNameHandling = TypeNameHandling.All;
- ReflectionDatabase api = JsonConvert.DeserializeObject<ReflectionDatabase>(fullJsonApiDump);
- return api;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement