Advertisement
CloneTrooper1019

Roblox Json.NET API Dump

Aug 8th, 2018
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.43 KB | None | 0 0
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. // @Author: Max G. (CloneTrooper1019)
  3. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4. // JSON API Dump can be fetched like such:
  5. //     http://setup.roblox.com/versionQTStudio -> "version-b724ac4d89fb4d66"
  6. //     http://setup.roblox.com/version-b724ac4d89fb4d66-API-Dump.json
  7. // Plug in the resulting JSON data from that url into ReflectionDatabase.Load() and it should give you the full data structure.
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  9.  
  10. using System;
  11. using System.Linq;
  12. using System.Collections.Generic;
  13. using Newtonsoft.Json;
  14. using Newtonsoft.Json.Linq;
  15.  
  16. #pragma warning disable 0649
  17.  
  18. namespace Roblox.Reflection
  19. {
  20.     public enum MemberType
  21.     {
  22.         Property,
  23.         Function,
  24.         Event,
  25.         Callback
  26.     }
  27.  
  28.     public enum SecurityType
  29.     {
  30.         None,
  31.         PluginSecurity,
  32.         LocalUserSecurity,
  33.         RobloxScriptSecurity,
  34.         RobloxSecurity,
  35.         NotAccessibleSecurity
  36.     }
  37.  
  38.     public enum TypeCategory
  39.     {
  40.         Primitive,
  41.         Class,
  42.         Enum,
  43.         Group,
  44.         DataType
  45.     }
  46.  
  47.     public struct ReadWriteSecurity
  48.     {
  49.         public SecurityType Read;
  50.         public SecurityType Write;
  51.  
  52.         public override string ToString()
  53.         {
  54.             return "Read: "  + Enum.GetName(typeof(SecurityType), Read) +
  55.                 " | Write: " + Enum.GetName(typeof(SecurityType), Write);
  56.         }
  57.     }
  58.  
  59.     public struct MemberSerialization
  60.     {
  61.         public bool CanSave;
  62.         public bool CanLoad;
  63.  
  64.         public override string ToString()
  65.         {
  66.             return "Saves: " + CanSave + " | Loads: " + CanLoad;
  67.         }
  68.     }
  69.  
  70.     public struct RobloxType
  71.     {
  72.         public TypeCategory Category;
  73.         public string Name;
  74.  
  75.         public override string ToString()
  76.         {
  77.             return Name;
  78.         }
  79.     }
  80.  
  81.     public struct Parameter
  82.     {
  83.         public RobloxType Type;
  84.         public string Name;
  85.         public string Default;
  86.  
  87.         public override string ToString()
  88.         {
  89.             if (Default != null && Default.Length > 0)
  90.             {
  91.                 return Type.Name + " " + Name + " = " + Default;
  92.             }
  93.             else
  94.             {
  95.                 return Type.Name + " " + Name;
  96.             }
  97.         }
  98.     }
  99.  
  100.     public class ClassReader : JsonConverter
  101.     {
  102.         public override bool CanRead => true;
  103.         public override bool CanWrite => false;
  104.  
  105.         public override bool CanConvert(Type objectType)
  106.         {
  107.             return objectType == typeof(ClassDescriptor);
  108.         }
  109.  
  110.         public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
  111.         {
  112.             JObject obj = JObject.Load(reader);
  113.             JToken[] members = obj.GetValue("Members").ToArray();
  114.             JToken superToken = obj.GetValue("Superclass");
  115.  
  116.             Descriptor desc = obj.ToObject<Descriptor>();
  117.  
  118.             ClassDescriptor classDesc = new ClassDescriptor();
  119.             classDesc.Name = desc.Name;
  120.             classDesc.Tags = desc.Tags;
  121.             classDesc.Superclass = superToken.ToString();
  122.  
  123.             foreach (JToken member in members)
  124.             {
  125.                 MemberType memberType;
  126.                 if (Enum.TryParse(member.Value<string>("MemberType"), out memberType))
  127.                 {
  128.                     switch (memberType)
  129.                     {
  130.                         case MemberType.Property:
  131.                             PropertyDescriptor prop = member.ToObject<PropertyDescriptor>();
  132.                             classDesc.Properties.Add(prop);
  133.                             break;
  134.                         case MemberType.Function:
  135.                             FunctionDescriptor func = member.ToObject<FunctionDescriptor>();
  136.                             classDesc.Functions.Add(func);
  137.                             break;
  138.                         case MemberType.Callback:
  139.                             CallbackDescriptor call = member.ToObject<CallbackDescriptor>();
  140.                             classDesc.Callbacks.Add(call);
  141.                             break;
  142.                         case MemberType.Event:
  143.                             EventDescriptor evnt = member.ToObject<EventDescriptor>();
  144.                             classDesc.Events.Add(evnt);
  145.                             break;
  146.                     }
  147.                 }
  148.             }
  149.  
  150.             return classDesc;
  151.         }
  152.  
  153.         public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
  154.         {
  155.             throw new NotImplementedException();
  156.         }
  157.     }
  158.  
  159.     ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  160.  
  161.     public class Descriptor
  162.     {
  163.         public string Name;
  164.         public List<string> Tags;
  165.  
  166.         public override string ToString()
  167.         {
  168.             return Name;
  169.         }
  170.     }
  171.  
  172.     [ JsonConverter( typeof(ClassReader) ) ]
  173.     public class ClassDescriptor : Descriptor
  174.     {
  175.         public string Superclass;
  176.  
  177.         public List<PropertyDescriptor> Properties;
  178.         public List<FunctionDescriptor> Functions;
  179.         public List<CallbackDescriptor> Callbacks;
  180.         public List<EventDescriptor>    Events;
  181.  
  182.         public ClassDescriptor()
  183.         {
  184.             Properties = new List<PropertyDescriptor>();
  185.             Functions  = new List<FunctionDescriptor>();
  186.             Callbacks  = new List<CallbackDescriptor>();
  187.             Events     = new List<EventDescriptor>();
  188.         }
  189.     }
  190.  
  191.     public class MemberDescriptor : Descriptor
  192.     {
  193.         public MemberType MemberType;
  194.     }
  195.  
  196.     public class PropertyDescriptor : MemberDescriptor
  197.     {
  198.         public string Category;
  199.         public RobloxType ValueType;
  200.         public ReadWriteSecurity Security;
  201.     }
  202.  
  203.     public class FunctionDescriptor : MemberDescriptor
  204.     {
  205.         public List<Parameter> Parameters;
  206.         public RobloxType ReturnType;
  207.         public SecurityType Security;
  208.     }
  209.  
  210.     public class EventDescriptor : MemberDescriptor
  211.     {
  212.         public List<Parameter> Parameters;
  213.         public SecurityType Security;
  214.     }
  215.  
  216.     public class CallbackDescriptor : MemberDescriptor
  217.     {
  218.         public List<Parameter> Parameters;
  219.         public RobloxType ReturnType;
  220.         public SecurityType Security;
  221.     }
  222.  
  223.     public class EnumDescriptor : Descriptor
  224.     {
  225.         public List<EnumItemDescriptor> Items;
  226.     }
  227.  
  228.     public class EnumItemDescriptor : Descriptor
  229.     {
  230.         public int Value;
  231.     }
  232.  
  233.     public class ReflectionDatabase
  234.     {
  235.         public int Version;
  236.         public List<ClassDescriptor> Classes;
  237.         public List<EnumDescriptor> Enums;
  238.  
  239.         public static ReflectionDatabase Load(string fullJsonApiDump)
  240.         {
  241.             JsonSerializerSettings settings = new JsonSerializerSettings();
  242.             settings.TypeNameHandling = TypeNameHandling.All;
  243.  
  244.             ReflectionDatabase api = JsonConvert.DeserializeObject<ReflectionDatabase>(fullJsonApiDump);
  245.             return api;
  246.         }
  247.     }
  248. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement