Advertisement
Guest User

Untitled

a guest
Dec 21st, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 38.71 KB | None | 0 0
  1. using Serialization;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.IO;
  7. using System.Net;
  8. using System.Reflection;
  9. using System.Runtime.CompilerServices;
  10. using System.Text;
  11. using TheForest.Utils;
  12. using UniLinq;
  13. using UnityEngine;
  14.  
  15. public class LevelSerializer
  16. {
  17.     public enum SerializationModes
  18.     {
  19.         SerializeWhenFree,
  20.         CacheSerialization
  21.     }
  22.  
  23.     private class CompareGameObjects : IEqualityComparer<GameObject>
  24.     {
  25.         public static readonly LevelSerializer.CompareGameObjects Instance = new LevelSerializer.CompareGameObjects();
  26.  
  27.         public bool Equals(GameObject x, GameObject y)
  28.         {
  29.             return string.Compare(x.GetComponent<PrefabIdentifier>().ClassId, y.GetComponent<PrefabIdentifier>().ClassId, StringComparison.Ordinal) == 0;
  30.         }
  31.  
  32.         public int GetHashCode(GameObject obj)
  33.         {
  34.             return obj.GetComponent<PrefabIdentifier>().ClassId.GetHashCode();
  35.         }
  36.     }
  37.  
  38.     public class LevelData
  39.     {
  40.         public string Name;
  41.  
  42.         public List<LevelSerializer.StoredData> StoredItems;
  43.  
  44.         public List<LevelSerializer.StoredItem> StoredObjectNames;
  45.  
  46.         public string rootObject;
  47.     }
  48.  
  49.     private class ProgressHelper
  50.     {
  51.         public void SetProgress(long inSize, long outSize)
  52.         {
  53.             LevelSerializer.RaiseProgress("Compression", 5f);
  54.         }
  55.     }
  56.  
  57.     public class SaveEntry
  58.     {
  59.         public string Data;
  60.  
  61.         public string Level;
  62.  
  63.         public string Name;
  64.  
  65.         public DateTime When;
  66.  
  67.         public string Caption
  68.         {
  69.             get
  70.             {
  71.                 return string.Format("{0} - {1} - {2:g}", this.Name, this.Level, this.When);
  72.             }
  73.         }
  74.  
  75.         public SaveEntry(string contents)
  76.         {
  77.             UnitySerializer.DeserializeInto(Convert.FromBase64String(contents), this);
  78.         }
  79.  
  80.         public SaveEntry()
  81.         {
  82.         }
  83.  
  84.         public void Load()
  85.         {
  86.             LevelSerializer.LoadSavedLevel(this.Data);
  87.         }
  88.  
  89.         public void Delete()
  90.         {
  91.             KeyValuePair<string, List<LevelSerializer.SaveEntry>> keyValuePair = LevelSerializer.SavedGames.FirstOrDefault((KeyValuePair<string, List<LevelSerializer.SaveEntry>> p) => p.Value.Contains(this));
  92.             if (keyValuePair.Value != null)
  93.             {
  94.                 keyValuePair.Value.Remove(this);
  95.                 LevelSerializer.SaveDataToPlayerPrefs();
  96.             }
  97.         }
  98.  
  99.         public override string ToString()
  100.         {
  101.             return Convert.ToBase64String(UnitySerializer.Serialize(this));
  102.         }
  103.     }
  104.  
  105.     public class SerializationHelper : MonoBehaviour
  106.     {
  107.         public string gameName;
  108.  
  109.         public Action<string, bool> perform;
  110.  
  111.         private void Update()
  112.         {
  113.             if (!LevelSerializer.IsSuspended)
  114.             {
  115.                 if (this.perform != null)
  116.                 {
  117.                     this.perform(this.gameName, false);
  118.                 }
  119.                 UnityEngine.Object.DestroyImmediate(base.gameObject);
  120.             }
  121.         }
  122.     }
  123.  
  124.     public class SerializationSuspendedException : Exception
  125.     {
  126.         public SerializationSuspendedException() : base("Serialization was suspended: " + LevelSerializer._suspensionCount + " times")
  127.         {
  128.         }
  129.     }
  130.  
  131.     public class StoredData
  132.     {
  133.         public string ClassId;
  134.  
  135.         public byte[] Data;
  136.  
  137.         public string Name;
  138.  
  139.         public string Type;
  140.     }
  141.  
  142.     public class StoredItem
  143.     {
  144.         public bool Active;
  145.  
  146.         public int layer;
  147.  
  148.         public string tag;
  149.  
  150.         public bool setExtraData;
  151.  
  152.         public readonly List<string> ChildIds = new List<string>();
  153.  
  154.         public Dictionary<string, List<string>> Children = new Dictionary<string, List<string>>();
  155.  
  156.         public string ClassId;
  157.  
  158.         public Dictionary<string, bool> Components;
  159.  
  160.         [DoNotSerialize]
  161.         public GameObject GameObject;
  162.  
  163.         public string GameObjectName;
  164.  
  165.         public string Name;
  166.  
  167.         public string ParentName;
  168.  
  169.         public bool createEmptyObject;
  170.  
  171.         public override string ToString()
  172.         {
  173.             return string.Format("{0}  child of {2} - ({1})", this.Name, this.ClassId, this.ParentName);
  174.         }
  175.     }
  176.  
  177.     public delegate void StoreQuery(GameObject go, ref bool store);
  178.  
  179.     public delegate void StoreComponentQuery(Component component, ref bool store);
  180.  
  181.     [CompilerGenerated]
  182.     private sealed class <DownloadFromServer>c__Iterator2ED : IEnumerator, IDisposable, IEnumerator<object>
  183.     {
  184.         internal string uri;
  185.  
  186.         internal WWW <www>__0;
  187.  
  188.         internal Action<LevelLoader> onComplete;
  189.  
  190.         internal int $PC;
  191.  
  192.         internal object $current;
  193.  
  194.         internal string <$>uri;
  195.  
  196.         internal Action<LevelLoader> <$>onComplete;
  197.  
  198.         object IEnumerator<object>.Current
  199.         {
  200.             [DebuggerHidden]
  201.             get
  202.             {
  203.                 return this.$current;
  204.             }
  205.         }
  206.  
  207.         object IEnumerator.Current
  208.         {
  209.             [DebuggerHidden]
  210.             get
  211.             {
  212.                 return this.$current;
  213.             }
  214.         }
  215.  
  216.         public bool MoveNext()
  217.         {
  218.             uint num = (uint)this.$PC;
  219.             this.$PC = -1;
  220.             switch (num)
  221.             {
  222.             case 0u:
  223.                 this.<www>__0 = new WWW(this.uri);
  224.                 this.$current = this.<www>__0;
  225.                 this.$PC = 1;
  226.                 return true;
  227.             case 1u:
  228.                 this.<www>__0.bytes.LoadObjectTree(this.onComplete);
  229.                 this.$PC = -1;
  230.                 break;
  231.             }
  232.             return false;
  233.         }
  234.  
  235.         [DebuggerHidden]
  236.         public void Dispose()
  237.         {
  238.             this.$PC = -1;
  239.         }
  240.  
  241.         [DebuggerHidden]
  242.         public void Reset()
  243.         {
  244.             throw new NotSupportedException();
  245.         }
  246.     }
  247.  
  248.     [CompilerGenerated]
  249.     private sealed class <DownloadLevelFromServer>c__Iterator2EE : IEnumerator, IDisposable, IEnumerator<object>
  250.     {
  251.         internal string uri;
  252.  
  253.         internal WWW <www>__0;
  254.  
  255.         internal int $PC;
  256.  
  257.         internal object $current;
  258.  
  259.         internal string <$>uri;
  260.  
  261.         object IEnumerator<object>.Current
  262.         {
  263.             [DebuggerHidden]
  264.             get
  265.             {
  266.                 return this.$current;
  267.             }
  268.         }
  269.  
  270.         object IEnumerator.Current
  271.         {
  272.             [DebuggerHidden]
  273.             get
  274.             {
  275.                 return this.$current;
  276.             }
  277.         }
  278.  
  279.         public bool MoveNext()
  280.         {
  281.             uint num = (uint)this.$PC;
  282.             this.$PC = -1;
  283.             switch (num)
  284.             {
  285.             case 0u:
  286.                 this.<www>__0 = new WWW(this.uri);
  287.                 this.$current = this.<www>__0;
  288.                 this.$PC = 1;
  289.                 return true;
  290.             case 1u:
  291.                 LevelSerializer.LoadSavedLevel(this.<www>__0.text);
  292.                 this.$PC = -1;
  293.                 break;
  294.             }
  295.             return false;
  296.         }
  297.  
  298.         [DebuggerHidden]
  299.         public void Dispose()
  300.         {
  301.             this.$PC = -1;
  302.         }
  303.  
  304.         [DebuggerHidden]
  305.         public void Reset()
  306.         {
  307.             throw new NotSupportedException();
  308.         }
  309.     }
  310.  
  311.     [CompilerGenerated]
  312.     private sealed class <PerformLoad>c__Iterator2EF : IEnumerator, IDisposable, IEnumerator<object>
  313.     {
  314.         internal LevelLoader loader;
  315.  
  316.         internal Action<LevelLoader> complete;
  317.  
  318.         internal int $PC;
  319.  
  320.         internal object $current;
  321.  
  322.         internal LevelLoader <$>loader;
  323.  
  324.         internal Action<LevelLoader> <$>complete;
  325.  
  326.         object IEnumerator<object>.Current
  327.         {
  328.             [DebuggerHidden]
  329.             get
  330.             {
  331.                 return this.$current;
  332.             }
  333.         }
  334.  
  335.         object IEnumerator.Current
  336.         {
  337.             [DebuggerHidden]
  338.             get
  339.             {
  340.                 return this.$current;
  341.             }
  342.         }
  343.  
  344.         public bool MoveNext()
  345.         {
  346.             uint num = (uint)this.$PC;
  347.             this.$PC = -1;
  348.             switch (num)
  349.             {
  350.             case 0u:
  351.                 this.$current = this.loader.StartCoroutine(this.loader.Load(0, Time.timeScale));
  352.                 this.$PC = 1;
  353.                 return true;
  354.             case 1u:
  355.                 if (this.complete != null)
  356.                 {
  357.                     this.complete(this.loader);
  358.                 }
  359.                 this.$PC = -1;
  360.                 break;
  361.             }
  362.             return false;
  363.         }
  364.  
  365.         [DebuggerHidden]
  366.         public void Dispose()
  367.         {
  368.             this.$PC = -1;
  369.         }
  370.  
  371.         [DebuggerHidden]
  372.         public void Reset()
  373.         {
  374.             throw new NotSupportedException();
  375.         }
  376.     }
  377.  
  378.     protected static Dictionary<string, GameObject> allPrefabs = new Dictionary<string, GameObject>();
  379.  
  380.     public static HashSet<string> IgnoreTypes = new HashSet<string>();
  381.  
  382.     internal static Dictionary<Type, IComponentSerializer> CustomSerializers = new Dictionary<Type, IComponentSerializer>();
  383.  
  384.     internal static int lastFrame;
  385.  
  386.     public static string PlayerName = string.Empty;
  387.  
  388.     public static bool SaveResumeInformation = true;
  389.  
  390.     protected static int _suspensionCount;
  391.  
  392.     protected static LevelSerializer.SaveEntry _cachedState;
  393.  
  394.     public static LevelSerializer.SerializationModes SerializationMode = LevelSerializer.SerializationModes.CacheSerialization;
  395.  
  396.     public static int MaxGames = 20;
  397.  
  398.     public static global::Lookup<string, List<LevelSerializer.SaveEntry>> SavedGames = new Index<string, List<LevelSerializer.SaveEntry>>();
  399.  
  400.     protected static readonly List<Type> _stopCases = new List<Type>();
  401.  
  402.     public static bool IsDeserializing;
  403.  
  404.     protected static readonly List<object> createdPlugins = new List<object>();
  405.  
  406.     public static bool useCompression = false;
  407.  
  408.     protected static WebClient webClient = new WebClient();
  409.  
  410.     protected static readonly object Guard = new object();
  411.  
  412.     protected static int uploadCount;
  413.  
  414.     protected static int _collectionCount = 0;
  415.  
  416.     public static AsyncOperation LevelLoadingOperation;
  417.  
  418.     public static event Action Deserialized
  419.     {
  420.         [MethodImpl(MethodImplOptions.Synchronized)]
  421.         add
  422.         {
  423.             LevelSerializer.Deserialized = (Action)Delegate.Combine(LevelSerializer.Deserialized, value);
  424.         }
  425.         [MethodImpl(MethodImplOptions.Synchronized)]
  426.         remove
  427.         {
  428.             LevelSerializer.Deserialized = (Action)Delegate.Remove(LevelSerializer.Deserialized, value);
  429.         }
  430.     }
  431.  
  432.     public static event Action GameSaved
  433.     {
  434.         [MethodImpl(MethodImplOptions.Synchronized)]
  435.         add
  436.         {
  437.             LevelSerializer.GameSaved = (Action)Delegate.Combine(LevelSerializer.GameSaved, value);
  438.         }
  439.         [MethodImpl(MethodImplOptions.Synchronized)]
  440.         remove
  441.         {
  442.             LevelSerializer.GameSaved = (Action)Delegate.Remove(LevelSerializer.GameSaved, value);
  443.         }
  444.     }
  445.  
  446.     public static event Action SuspendingSerialization
  447.     {
  448.         [MethodImpl(MethodImplOptions.Synchronized)]
  449.         add
  450.         {
  451.             LevelSerializer.SuspendingSerialization = (Action)Delegate.Combine(LevelSerializer.SuspendingSerialization, value);
  452.         }
  453.         [MethodImpl(MethodImplOptions.Synchronized)]
  454.         remove
  455.         {
  456.             LevelSerializer.SuspendingSerialization = (Action)Delegate.Remove(LevelSerializer.SuspendingSerialization, value);
  457.         }
  458.     }
  459.  
  460.     public static event Action ResumingSerialization
  461.     {
  462.         [MethodImpl(MethodImplOptions.Synchronized)]
  463.         add
  464.         {
  465.             LevelSerializer.ResumingSerialization = (Action)Delegate.Combine(LevelSerializer.ResumingSerialization, value);
  466.         }
  467.         [MethodImpl(MethodImplOptions.Synchronized)]
  468.         remove
  469.         {
  470.             LevelSerializer.ResumingSerialization = (Action)Delegate.Remove(LevelSerializer.ResumingSerialization, value);
  471.         }
  472.     }
  473.  
  474.     public static event LevelSerializer.StoreQuery Store
  475.     {
  476.         [MethodImpl(MethodImplOptions.Synchronized)]
  477.         add
  478.         {
  479.             LevelSerializer.Store = (LevelSerializer.StoreQuery)Delegate.Combine(LevelSerializer.Store, value);
  480.         }
  481.         [MethodImpl(MethodImplOptions.Synchronized)]
  482.         remove
  483.         {
  484.             LevelSerializer.Store = (LevelSerializer.StoreQuery)Delegate.Remove(LevelSerializer.Store, value);
  485.         }
  486.     }
  487.  
  488.     public static event LevelSerializer.StoreComponentQuery StoreComponent
  489.     {
  490.         [MethodImpl(MethodImplOptions.Synchronized)]
  491.         add
  492.         {
  493.             LevelSerializer.StoreComponent = (LevelSerializer.StoreComponentQuery)Delegate.Combine(LevelSerializer.StoreComponent, value);
  494.         }
  495.         [MethodImpl(MethodImplOptions.Synchronized)]
  496.         remove
  497.         {
  498.             LevelSerializer.StoreComponent = (LevelSerializer.StoreComponentQuery)Delegate.Remove(LevelSerializer.StoreComponent, value);
  499.         }
  500.     }
  501.  
  502.     public static event Action<string, float> Progress
  503.     {
  504.         [MethodImpl(MethodImplOptions.Synchronized)]
  505.         add
  506.         {
  507.             LevelSerializer.Progress = (Action<string, float>)Delegate.Combine(LevelSerializer.Progress, value);
  508.         }
  509.         [MethodImpl(MethodImplOptions.Synchronized)]
  510.         remove
  511.         {
  512.             LevelSerializer.Progress = (Action<string, float>)Delegate.Remove(LevelSerializer.Progress, value);
  513.         }
  514.     }
  515.  
  516.     internal static Dictionary<string, GameObject> AllPrefabs
  517.     {
  518.         get
  519.         {
  520.             if (Time.frameCount != LevelSerializer.lastFrame)
  521.             {
  522.                 LevelSerializer.allPrefabs = (from p in LevelSerializer.allPrefabs
  523.                 where p.Value
  524.                 select p).ToDictionary((KeyValuePair<string, GameObject> p) => p.Key, (KeyValuePair<string, GameObject> p) => p.Value);
  525.                 LevelSerializer.lastFrame = Time.frameCount;
  526.             }
  527.             return LevelSerializer.allPrefabs;
  528.         }
  529.         set
  530.         {
  531.             LevelSerializer.allPrefabs = value;
  532.         }
  533.     }
  534.  
  535.     public static bool CanResume
  536.     {
  537.         get
  538.         {
  539.             return PlayerPrefsFile.KeyExist(LevelSerializer.PlayerName + "__RESUME__");
  540.         }
  541.     }
  542.  
  543.     public static bool IsSuspended
  544.     {
  545.         get
  546.         {
  547.             return LevelSerializer._suspensionCount > 0;
  548.         }
  549.     }
  550.  
  551.     public static int SuspensionCount
  552.     {
  553.         get
  554.         {
  555.             return LevelSerializer._suspensionCount;
  556.         }
  557.     }
  558.  
  559.     public static bool ShouldCollect
  560.     {
  561.         get
  562.         {
  563.             return LevelSerializer._collectionCount <= 0;
  564.         }
  565.     }
  566.  
  567.     static LevelSerializer()
  568.     {
  569.         // Note: this type is marked as 'beforefieldinit'.
  570.         LevelSerializer.Deserialized = delegate
  571.         {
  572.         };
  573.         LevelSerializer.GameSaved = delegate
  574.         {
  575.         };
  576.         LevelSerializer.SuspendingSerialization = delegate
  577.         {
  578.         };
  579.         LevelSerializer.ResumingSerialization = delegate
  580.         {
  581.         };
  582.         LevelSerializer.StoreComponent = delegate
  583.         {
  584.         };
  585.         LevelSerializer.Progress = delegate
  586.         {
  587.         };
  588.         LevelSerializer.webClient.UploadDataCompleted += new UploadDataCompletedEventHandler(LevelSerializer.HandleWebClientUploadDataCompleted);
  589.         LevelSerializer.webClient.UploadStringCompleted += new UploadStringCompletedEventHandler(LevelSerializer.HandleWebClientUploadStringCompleted);
  590.         LevelSerializer._stopCases.Add(typeof(PrefabIdentifier));
  591.         UnitySerializer.AddPrivateType(typeof(AnimationClip));
  592.         Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
  593.         for (int i = 0; i < assemblies.Length; i++)
  594.         {
  595.             Assembly assembly = assemblies[i];
  596.             UnitySerializer.ScanAllTypesForAttribute(delegate(Type tp, Attribute attr)
  597.             {
  598.                 LevelSerializer.createdPlugins.Add(Activator.CreateInstance(tp));
  599.             }, assembly, typeof(SerializerPlugIn));
  600.             UnitySerializer.ScanAllTypesForAttribute(delegate(Type tp, Attribute attr)
  601.             {
  602.                 LevelSerializer.CustomSerializers[((ComponentSerializerFor)attr).SerializesType] = (Activator.CreateInstance(tp) as IComponentSerializer);
  603.             }, assembly, typeof(ComponentSerializerFor));
  604.         }
  605.         LevelSerializer.AllPrefabs = Resources.FindObjectsOfTypeAll(typeof(GameObject)).Cast<GameObject>().Where(delegate(GameObject go)
  606.         {
  607.             PrefabIdentifier component = go.GetComponent<PrefabIdentifier>();
  608.             return component != null && !component.IsInScene();
  609.         }).Distinct(LevelSerializer.CompareGameObjects.Instance).ToDictionary((GameObject go) => go.GetComponent<PrefabIdentifier>().ClassId, (GameObject go) => go);
  610.         try
  611.         {
  612.             string @string = PlayerPrefsFile.GetString("_Save_Game_Data_", string.Empty, true);
  613.             if (!string.IsNullOrEmpty(@string))
  614.             {
  615.                 try
  616.                 {
  617.                     LevelSerializer.SavedGames = UnitySerializer.Deserialize<global::Lookup<string, List<LevelSerializer.SaveEntry>>>(Convert.FromBase64String(@string));
  618.                 }
  619.                 catch
  620.                 {
  621.                     LevelSerializer.SavedGames = null;
  622.                 }
  623.             }
  624.             if (LevelSerializer.SavedGames == null)
  625.             {
  626.                 LevelSerializer.SavedGames = new Index<string, List<LevelSerializer.SaveEntry>>();
  627.                 LevelSerializer.SaveDataToPlayerPrefs();
  628.             }
  629.         }
  630.         catch
  631.         {
  632.             LevelSerializer.SavedGames = new Index<string, List<LevelSerializer.SaveEntry>>();
  633.         }
  634.     }
  635.  
  636.     protected static void HandleWebClientUploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
  637.     {
  638.         object guard = LevelSerializer.Guard;
  639.         lock (guard)
  640.         {
  641.             LevelSerializer.uploadCount--;
  642.         }
  643.         Loom.QueueOnMainThread(delegate
  644.         {
  645.             if (e.UserState is Action<Exception>)
  646.             {
  647.                 (e.UserState as Action<Exception>)(e.Error);
  648.             }
  649.         });
  650.     }
  651.  
  652.     protected static void HandleWebClientUploadDataCompleted(object sender, UploadDataCompletedEventArgs e)
  653.     {
  654.         object guard = LevelSerializer.Guard;
  655.         lock (guard)
  656.         {
  657.             LevelSerializer.uploadCount--;
  658.         }
  659.         Loom.QueueOnMainThread(delegate
  660.         {
  661.             if (e.UserState is Action<Exception>)
  662.             {
  663.                 (e.UserState as Action<Exception>)(e.Error);
  664.             }
  665.         });
  666.     }
  667.  
  668.     public static void SaveObjectTreeToFile(string filename, GameObject rootOfTree)
  669.     {
  670.         byte[] data = rootOfTree.SaveObjectTree();
  671.         data.WriteToFile(Application.persistentDataPath + "/" + filename);
  672.     }
  673.  
  674.     public static void LoadObjectTreeFromFile(string filename, Action<LevelLoader> onComplete = null)
  675.     {
  676.         FileStream fileStream = File.Open(Application.persistentDataPath + "/" + filename, FileMode.Open);
  677.         byte[] array = new byte[fileStream.Length];
  678.         fileStream.Read(array, 0, (int)fileStream.Length);
  679.         fileStream.Close();
  680.         array.LoadObjectTree(onComplete);
  681.     }
  682.  
  683.     public static void LoadSavedLevelFromFile(string filename)
  684.     {
  685.         StreamReader streamReader = File.OpenText(Application.persistentDataPath + "/" + filename);
  686.         string data = streamReader.ReadToEnd();
  687.         streamReader.Close();
  688.         LevelSerializer.LoadSavedLevel(data);
  689.     }
  690.  
  691.     public static void SaveObjectTreeToServer(string uri, GameObject rootOfTree, string userName = "", string password = "", Action<Exception> onComplete = null)
  692.     {
  693.         LevelSerializer.<SaveObjectTreeToServer>c__AnonStorey3E0 <SaveObjectTreeToServer>c__AnonStorey3E = new LevelSerializer.<SaveObjectTreeToServer>c__AnonStorey3E0();
  694.         <SaveObjectTreeToServer>c__AnonStorey3E.rootOfTree = rootOfTree;
  695.         <SaveObjectTreeToServer>c__AnonStorey3E.userName = userName;
  696.         <SaveObjectTreeToServer>c__AnonStorey3E.password = password;
  697.         <SaveObjectTreeToServer>c__AnonStorey3E.uri = uri;
  698.         <SaveObjectTreeToServer>c__AnonStorey3E.onComplete = onComplete;
  699.         LevelSerializer.<SaveObjectTreeToServer>c__AnonStorey3E0 arg_55_0 = <SaveObjectTreeToServer>c__AnonStorey3E;
  700.         Action<Exception> arg_55_1;
  701.         if ((arg_55_1 = <SaveObjectTreeToServer>c__AnonStorey3E.onComplete) == null)
  702.         {
  703.             arg_55_1 = delegate
  704.             {
  705.             };
  706.         }
  707.         arg_55_0.onComplete = arg_55_1;
  708.         Action action = delegate
  709.         {
  710.             byte[] data = <SaveObjectTreeToServer>c__AnonStorey3E.rootOfTree.SaveObjectTree();
  711.             Action upload = delegate
  712.             {
  713.                 LevelSerializer.uploadCount++;
  714.                 LevelSerializer.webClient.Credentials = new NetworkCredential(<SaveObjectTreeToServer>c__AnonStorey3E.userName, <SaveObjectTreeToServer>c__AnonStorey3E.password);
  715.                 LevelSerializer.webClient.UploadDataAsync(new Uri(<SaveObjectTreeToServer>c__AnonStorey3E.uri), null, data, <SaveObjectTreeToServer>c__AnonStorey3E.onComplete);
  716.             };
  717.             LevelSerializer.DoWhenReady(upload);
  718.         };
  719.         action();
  720.     }
  721.  
  722.     protected static void DoWhenReady(Action upload)
  723.     {
  724.         object guard = LevelSerializer.Guard;
  725.         lock (guard)
  726.         {
  727.             if (LevelSerializer.uploadCount > 0)
  728.             {
  729.                 Loom.QueueOnMainThread(delegate
  730.                 {
  731.                     LevelSerializer.DoWhenReady(upload);
  732.                 }, 0.4f);
  733.             }
  734.             else
  735.             {
  736.                 upload();
  737.             }
  738.         }
  739.     }
  740.  
  741.     public static void LoadObjectTreeFromServer(string uri, Action<LevelLoader> onComplete = null)
  742.     {
  743.         Action<LevelLoader> arg_25_0;
  744.         if ((arg_25_0 = onComplete) == null)
  745.         {
  746.             arg_25_0 = delegate
  747.             {
  748.             };
  749.         }
  750.         onComplete = arg_25_0;
  751.         RadicalRoutineHelper.Current.StartCoroutine(LevelSerializer.DownloadFromServer(uri, onComplete));
  752.     }
  753.  
  754.     public static void SerializeLevelToServer(string uri, string userName = "", string password = "", Action<Exception> onComplete = null)
  755.     {
  756.         LevelSerializer.<SerializeLevelToServer>c__AnonStorey3E3 <SerializeLevelToServer>c__AnonStorey3E = new LevelSerializer.<SerializeLevelToServer>c__AnonStorey3E3();
  757.         <SerializeLevelToServer>c__AnonStorey3E.uri = uri;
  758.         <SerializeLevelToServer>c__AnonStorey3E.userName = userName;
  759.         <SerializeLevelToServer>c__AnonStorey3E.password = password;
  760.         <SerializeLevelToServer>c__AnonStorey3E.onComplete = onComplete;
  761.         object guard = LevelSerializer.Guard;
  762.         lock (guard)
  763.         {
  764.             if (LevelSerializer.uploadCount > 0)
  765.             {
  766.                 Loom.QueueOnMainThread(delegate
  767.                 {
  768.                     LevelSerializer.SerializeLevelToServer(<SerializeLevelToServer>c__AnonStorey3E.uri, <SerializeLevelToServer>c__AnonStorey3E.userName, <SerializeLevelToServer>c__AnonStorey3E.password, <SerializeLevelToServer>c__AnonStorey3E.onComplete);
  769.                 }, 0.5f);
  770.             }
  771.             else
  772.             {
  773.                 LevelSerializer.uploadCount++;
  774.                 LevelSerializer.<SerializeLevelToServer>c__AnonStorey3E3 arg_8B_0 = <SerializeLevelToServer>c__AnonStorey3E;
  775.                 Action<Exception> arg_8B_1;
  776.                 if ((arg_8B_1 = <SerializeLevelToServer>c__AnonStorey3E.onComplete) == null)
  777.                 {
  778.                     arg_8B_1 = delegate
  779.                     {
  780.                     };
  781.                 }
  782.                 arg_8B_0.onComplete = arg_8B_1;
  783.                 string data = LevelSerializer.SerializeLevel();
  784.                 LevelSerializer.webClient.Credentials = new NetworkCredential(<SerializeLevelToServer>c__AnonStorey3E.userName, <SerializeLevelToServer>c__AnonStorey3E.password);
  785.                 LevelSerializer.webClient.UploadStringAsync(new Uri(<SerializeLevelToServer>c__AnonStorey3E.uri), null, data, <SerializeLevelToServer>c__AnonStorey3E.onComplete);
  786.             }
  787.         }
  788.     }
  789.  
  790.     [DebuggerHidden]
  791.     protected static IEnumerator DownloadFromServer(string uri, Action<LevelLoader> onComplete)
  792.     {
  793.         LevelSerializer.<DownloadFromServer>c__Iterator2ED <DownloadFromServer>c__Iterator2ED = new LevelSerializer.<DownloadFromServer>c__Iterator2ED();
  794.         <DownloadFromServer>c__Iterator2ED.uri = uri;
  795.         <DownloadFromServer>c__Iterator2ED.onComplete = onComplete;
  796.         <DownloadFromServer>c__Iterator2ED.<$>uri = uri;
  797.         <DownloadFromServer>c__Iterator2ED.<$>onComplete = onComplete;
  798.         return <DownloadFromServer>c__Iterator2ED;
  799.     }
  800.  
  801.     [DebuggerHidden]
  802.     protected static IEnumerator DownloadLevelFromServer(string uri)
  803.     {
  804.         LevelSerializer.<DownloadLevelFromServer>c__Iterator2EE <DownloadLevelFromServer>c__Iterator2EE = new LevelSerializer.<DownloadLevelFromServer>c__Iterator2EE();
  805.         <DownloadLevelFromServer>c__Iterator2EE.uri = uri;
  806.         <DownloadLevelFromServer>c__Iterator2EE.<$>uri = uri;
  807.         return <DownloadLevelFromServer>c__Iterator2EE;
  808.     }
  809.  
  810.     internal static void InvokeDeserialized()
  811.     {
  812.         LevelSerializer._suspensionCount = 0;
  813.         if (LevelSerializer.Deserialized != null)
  814.         {
  815.             LevelSerializer.Deserialized();
  816.         }
  817.         foreach (GameObject current in UnityEngine.Object.FindObjectsOfType(typeof(GameObject)).Cast<GameObject>())
  818.         {
  819.             current.SendMessage("OnDeserialized", null, SendMessageOptions.DontRequireReceiver);
  820.         }
  821.     }
  822.  
  823.     public static void Resume()
  824.     {
  825.         string @string = PlayerPrefsFile.GetString(LevelSerializer.PlayerName + "__RESUME__", string.Empty, true);
  826.         GC.Collect();
  827.         if (!string.IsNullOrEmpty(@string))
  828.         {
  829.             byte[] array = Convert.FromBase64String(@string);
  830.             GC.Collect();
  831.             LevelSerializer.SaveEntry saveEntry = UnitySerializer.Deserialize<LevelSerializer.SaveEntry>(array);
  832.             string name = saveEntry.Name;
  833.             switch (name)
  834.             {
  835.             case "Peaceful":
  836.                 GameSetup.SetDifficulty(0);
  837.                 goto IL_105;
  838.             case "Hard":
  839.                 GameSetup.SetDifficulty(2);
  840.                 goto IL_105;
  841.             case "HardSurvival":
  842.                 GameSetup.SetDifficulty(3);
  843.                 goto IL_105;
  844.             case "Creative":
  845.                 GameSetup.SetDifficulty(0);
  846.                 GameSetup.SetGameType(2);
  847.                 goto IL_105;
  848.             }
  849.             GameSetup.SetDifficulty(1);
  850.             IL_105:
  851.             saveEntry.Load();
  852.         }
  853.     }
  854.  
  855.     public static void Checkpoint()
  856.     {
  857.         LevelSerializer.SaveGame((!GameSetup.IsCreativeGame) ? GameSetup.Difficulty.ToString() : "Creative", false, new Action<string, bool>(LevelSerializer.PerformSaveCheckPoint));
  858.     }
  859.  
  860.     protected static void PerformSaveCheckPoint(string name, bool urgent)
  861.     {
  862.         GC.Collect();
  863.         LevelSerializer.SaveEntry entry = LevelSerializer.CreateSaveEntry(name, urgent);
  864.         GC.Collect();
  865.         byte[] inArray = LevelSerializer.SerializeLevelToBytes(entry);
  866.         GC.Collect();
  867.         string data = Convert.ToBase64String(inArray);
  868.         GC.Collect();
  869.         PlayerPrefsFile.SetString(LevelSerializer.PlayerName + "__RESUME__", data, true);
  870.         PlayerPrefsFile.Save();
  871.     }
  872.  
  873.     protected static byte[] SerializeLevelToBytes(LevelSerializer.SaveEntry entry)
  874.     {
  875.         return UnitySerializer.Serialize(entry);
  876.     }
  877.  
  878.     public static void SuspendSerialization()
  879.     {
  880.         if (LevelSerializer._suspensionCount == 0)
  881.         {
  882.             LevelSerializer.SuspendingSerialization();
  883.             if (LevelSerializer.SerializationMode == LevelSerializer.SerializationModes.CacheSerialization)
  884.             {
  885.                 LevelSerializer._cachedState = LevelSerializer.CreateSaveEntry("resume", true);
  886.                 if (LevelSerializer.SaveResumeInformation)
  887.                 {
  888.                     PlayerPrefsFile.SetString(LevelSerializer.PlayerName + "__RESUME__", Convert.ToBase64String(UnitySerializer.Serialize(LevelSerializer._cachedState)), true);
  889.                     PlayerPrefsFile.Save();
  890.                 }
  891.             }
  892.         }
  893.         LevelSerializer._suspensionCount++;
  894.     }
  895.  
  896.     public static void ResumeSerialization()
  897.     {
  898.         LevelSerializer._suspensionCount--;
  899.         if (LevelSerializer._suspensionCount == 0)
  900.         {
  901.             LevelSerializer.ResumingSerialization();
  902.         }
  903.     }
  904.  
  905.     public static void IgnoreType(string typename)
  906.     {
  907.         LevelSerializer.IgnoreTypes.Add(typename);
  908.     }
  909.  
  910.     public static void UnIgnoreType(string typename)
  911.     {
  912.         LevelSerializer.IgnoreTypes.Remove(typename);
  913.     }
  914.  
  915.     public static void IgnoreType(Type tp)
  916.     {
  917.         if (tp.FullName != null)
  918.         {
  919.             LevelSerializer.IgnoreTypes.Add(tp.FullName);
  920.         }
  921.     }
  922.  
  923.     public static LevelSerializer.SaveEntry CreateSaveEntry(string name, bool urgent)
  924.     {
  925.         return new LevelSerializer.SaveEntry
  926.         {
  927.             Name = name,
  928.             When = DateTime.Now,
  929.             Level = Application.loadedLevelName,
  930.             Data = LevelSerializer.SerializeLevel(urgent)
  931.         };
  932.     }
  933.  
  934.     public static void SaveGame(string name)
  935.     {
  936.         LevelSerializer.SaveGame(name, false, null);
  937.     }
  938.  
  939.     public static void SaveGame(string name, bool urgent, Action<string, bool> perform)
  940.     {
  941.         perform = (perform ?? new Action<string, bool>(LevelSerializer.PerformSave));
  942.         if (urgent || !LevelSerializer.IsSuspended || LevelSerializer.SerializationMode != LevelSerializer.SerializationModes.SerializeWhenFree)
  943.         {
  944.             perform(name, urgent);
  945.             return;
  946.         }
  947.         if (GameObject.Find("/SerializationHelper") != null)
  948.         {
  949.             return;
  950.         }
  951.         GameObject gameObject = new GameObject("SerializationHelper");
  952.         LevelSerializer.SerializationHelper serializationHelper = gameObject.AddComponent(typeof(LevelSerializer.SerializationHelper)) as LevelSerializer.SerializationHelper;
  953.         serializationHelper.gameName = name;
  954.         serializationHelper.perform = perform;
  955.     }
  956.  
  957.     protected static void PerformSave(string name, bool urgent)
  958.     {
  959.         LevelSerializer.SaveEntry item = LevelSerializer.CreateSaveEntry(name, urgent);
  960.         LevelSerializer.SavedGames[LevelSerializer.PlayerName].Insert(0, item);
  961.         while (LevelSerializer.SavedGames[LevelSerializer.PlayerName].Count > LevelSerializer.MaxGames)
  962.         {
  963.             LevelSerializer.SavedGames[LevelSerializer.PlayerName].RemoveAt(LevelSerializer.SavedGames.Count - 1);
  964.         }
  965.         LevelSerializer.SaveDataToPlayerPrefs();
  966.         PlayerPrefsFile.SetString(LevelSerializer.PlayerName + "__RESUME__", Convert.ToBase64String(UnitySerializer.Serialize(item)), true);
  967.         PlayerPrefsFile.Save();
  968.         LevelSerializer.GameSaved();
  969.     }
  970.  
  971.     public static void SaveDataToPlayerPrefs()
  972.     {
  973.         PlayerPrefsFile.SetString("_Save_Game_Data_", Convert.ToBase64String(UnitySerializer.Serialize(LevelSerializer.SavedGames)), true);
  974.         PlayerPrefsFile.Save();
  975.     }
  976.  
  977.     public static void RegisterAssembly()
  978.     {
  979.         UnitySerializer.ScanAllTypesForAttribute(delegate(Type tp, Attribute attr)
  980.         {
  981.             LevelSerializer.CustomSerializers[((ComponentSerializerFor)attr).SerializesType] = (Activator.CreateInstance(tp) as IComponentSerializer);
  982.         }, Assembly.GetCallingAssembly(), typeof(ComponentSerializerFor));
  983.     }
  984.  
  985.     public static void AddPrefabPath(string path)
  986.     {
  987.         foreach (KeyValuePair<string, GameObject> current in from pair in (from GameObject go in Resources.LoadAll(path, typeof(GameObject))
  988.         where go.GetComponent<UniqueIdentifier>() != null
  989.         select go).ToDictionary((GameObject go) => go.GetComponent<UniqueIdentifier>().ClassId, (GameObject go) => go)
  990.         where !LevelSerializer.AllPrefabs.ContainsKey(pair.Key)
  991.         select pair)
  992.         {
  993.             LevelSerializer.AllPrefabs.Add(current.Key, current.Value);
  994.         }
  995.     }
  996.  
  997.     public static void DontCollect()
  998.     {
  999.         LevelSerializer._collectionCount++;
  1000.     }
  1001.  
  1002.     public static void Collect()
  1003.     {
  1004.         LevelSerializer._collectionCount--;
  1005.     }
  1006.  
  1007.     public static string SerializeLevel()
  1008.     {
  1009.         return LevelSerializer.SerializeLevel(false);
  1010.     }
  1011.  
  1012.     public static string SerializeLevel(bool urgent)
  1013.     {
  1014.         if (!LevelSerializer.IsSuspended || urgent)
  1015.         {
  1016.             Resources.UnloadUnusedAssets();
  1017.             GC.Collect();
  1018.             StringBuilder stringBuilder = new StringBuilder("NOCOMPRESSION");
  1019.             byte[] inArray = LevelSerializer.SerializeLevel(false, null);
  1020.             GC.Collect();
  1021.             stringBuilder.Append(Convert.ToBase64String(inArray));
  1022.             if (LevelSerializer.ShouldCollect)
  1023.             {
  1024.                 GC.Collect();
  1025.             }
  1026.             return stringBuilder.ToString();
  1027.         }
  1028.         if (LevelSerializer.SerializationMode == LevelSerializer.SerializationModes.CacheSerialization)
  1029.         {
  1030.             return LevelSerializer._cachedState.Data;
  1031.         }
  1032.         throw new LevelSerializer.SerializationSuspendedException();
  1033.     }
  1034.  
  1035.     internal static void RaiseProgress(string section, float complete)
  1036.     {
  1037.         LevelSerializer.Progress(section, complete);
  1038.     }
  1039.  
  1040.     internal static bool HasParent(UniqueIdentifier i, string id)
  1041.     {
  1042.         if (i)
  1043.         {
  1044.             GameObject byName = UniqueIdentifier.GetByName(i.Id);
  1045.             if (byName)
  1046.             {
  1047.                 Transform transform = byName.transform;
  1048.                 while (transform != null)
  1049.                 {
  1050.                     UniqueIdentifier component;
  1051.                     if ((component = transform.GetComponent<UniqueIdentifier>()) != null && id == component.Id)
  1052.                     {
  1053.                         return true;
  1054.                     }
  1055.                     transform = transform.parent;
  1056.                 }
  1057.             }
  1058.         }
  1059.         return false;
  1060.     }
  1061.  
  1062.     protected static void GetComponentsInChildrenWithClause(Transform t, List<StoreInformation> components)
  1063.     {
  1064.         foreach (Transform current in t.Cast<Transform>())
  1065.         {
  1066.             StoreInformation component = current.GetComponent<StoreInformation>();
  1067.             if (component != null)
  1068.             {
  1069.                 if (!(component is PrefabIdentifier))
  1070.                 {
  1071.                     components.Add(component);
  1072.                     LevelSerializer.GetComponentsInChildrenWithClause(current, components);
  1073.                 }
  1074.             }
  1075.             else
  1076.             {
  1077.                 LevelSerializer.GetComponentsInChildrenWithClause(current, components);
  1078.             }
  1079.         }
  1080.     }
  1081.  
  1082.     public static List<StoreInformation> GetComponentsInChildrenWithClause(GameObject go)
  1083.     {
  1084.         List<StoreInformation> list = new List<StoreInformation>();
  1085.         LevelSerializer.GetComponentsInChildrenWithClause(go.transform, list);
  1086.         return list;
  1087.     }
  1088.  
  1089.     public static byte[] SaveObjectTree(this GameObject rootOfTree)
  1090.     {
  1091.         if (!rootOfTree.GetComponent<UniqueIdentifier>())
  1092.         {
  1093.             EmptyObjectIdentifier.FlagAll(rootOfTree);
  1094.         }
  1095.         return LevelSerializer.SerializeLevel(false, rootOfTree.GetComponent<UniqueIdentifier>().Id);
  1096.     }
  1097.  
  1098.     public static byte[] SerializeLevel(bool urgent, string id)
  1099.     {
  1100.         LevelSerializer.LevelData levelData;
  1101.         using (new UnitySerializer.SerializationScope())
  1102.         {
  1103.             levelData = new LevelSerializer.LevelData
  1104.             {
  1105.                 Name = Application.loadedLevelName,
  1106.                 rootObject = ((!string.IsNullOrEmpty(id)) ? id : null)
  1107.             };
  1108.             levelData.StoredObjectNames = (from si in (from i in UniqueIdentifier.AllIdentifiers
  1109.             where string.IsNullOrEmpty(id) || i.Id == id || LevelSerializer.HasParent(i, id)
  1110.             select i.gameObject into go
  1111.             where go != null
  1112.             select go).Where(delegate(GameObject go)
  1113.             {
  1114.                 IControlSerializationEx controlSerializationEx = go.FindInterface<IControlSerializationEx>();
  1115.                 return controlSerializationEx == null || controlSerializationEx.ShouldSaveWholeObject();
  1116.             }).Where(delegate(GameObject go)
  1117.             {
  1118.                 if (LevelSerializer.Store == null)
  1119.                 {
  1120.                     return true;
  1121.                 }
  1122.                 bool result = true;
  1123.                 LevelSerializer.Store(go, ref result);
  1124.                 return result;
  1125.             }).Select(delegate(GameObject n)
  1126.             {
  1127.                 LevelSerializer.StoredItem result;
  1128.                 try
  1129.                 {
  1130.                     LevelSerializer.StoredItem storedItem = new LevelSerializer.StoredItem();
  1131.                     storedItem.createEmptyObject = (n.GetComponent<EmptyObjectIdentifier>() != null);
  1132.                     storedItem.layer = n.layer;
  1133.                     storedItem.tag = n.tag;
  1134.                     storedItem.setExtraData = true;
  1135.                     storedItem.Active = n.activeSelf;
  1136.                     storedItem.Components = (from c in n.GetComponents<Component>()
  1137.                     where c != null
  1138.                     select c.GetType().FullName).Distinct<string>().ToDictionary((string v) => v, (string v) => true);
  1139.                     storedItem.Name = n.GetComponent<UniqueIdentifier>().Id;
  1140.                     storedItem.GameObjectName = n.name;
  1141.                     storedItem.ParentName = ((!(n.transform.parent == null) && !(n.transform.parent.GetComponent<UniqueIdentifier>() == null)) ? n.transform.parent.GetComponent<UniqueIdentifier>().Id : null);
  1142.                     storedItem.ClassId = ((!(n.GetComponent<PrefabIdentifier>() != null)) ? string.Empty : n.GetComponent<PrefabIdentifier>().ClassId);
  1143.                     LevelSerializer.StoredItem storedItem2 = storedItem;
  1144.                     if (n.GetComponent<StoreInformation>())
  1145.                     {
  1146.                         n.SendMessage("OnSerializing", SendMessageOptions.DontRequireReceiver);
  1147.                     }
  1148.                     PrefabIdentifier component = n.GetComponent<PrefabIdentifier>();
  1149.                     if (component != null)
  1150.                     {
  1151.                         List<StoreInformation> componentsInChildrenWithClause = LevelSerializer.GetComponentsInChildrenWithClause(n);
  1152.                         storedItem2.Children = (from c in componentsInChildrenWithClause
  1153.                         group c by c.ClassId).ToDictionary((IGrouping<string, StoreInformation> c) => c.Key, (IGrouping<string, StoreInformation> c) => (from i in c
  1154.                         select i.Id).ToList<string>());
  1155.                     }
  1156.                     result = storedItem2;
  1157.                 }
  1158.                 catch (Exception ex)
  1159.                 {
  1160.                     UnityEngine.Debug.LogWarning("Failed to serialize status of " + n.name + " with error " + ex.ToString());
  1161.                     result = null;
  1162.                 }
  1163.                 return result;
  1164.             })
  1165.             where si != null
  1166.             select si).ToList<LevelSerializer.StoredItem>();
  1167.             List<<>__AnonType4<StoreInformation, Component>> toBeProcessed = (from c in (from o in UniqueIdentifier.AllIdentifiers
  1168.             where o.GetComponent<StoreInformation>() != null || o.GetComponent<PrefabIdentifier>() != null
  1169.             select o into i
  1170.             where string.IsNullOrEmpty(id) || i.Id == id || LevelSerializer.HasParent(i, id)
  1171.             where i != null
  1172.             select i.gameObject into i
  1173.             where i != null
  1174.             select i).Where(delegate(GameObject go)
  1175.             {
  1176.                 IControlSerializationEx controlSerializationEx = go.FindInterface<IControlSerializationEx>();
  1177.                 return controlSerializationEx == null || controlSerializationEx.ShouldSaveWholeObject();
  1178.             }).Distinct<GameObject>().Where(delegate(GameObject go)
  1179.             {
  1180.                 if (LevelSerializer.Store == null)
  1181.                 {
  1182.                     return true;
  1183.                 }
  1184.                 bool result = true;
  1185.                 LevelSerializer.Store(go, ref result);
  1186.                 return result;
  1187.             }).SelectMany((GameObject o) => o.GetComponents<Component>()).Where(delegate(Component c)
  1188.             {
  1189.                 if (c == null)
  1190.                 {
  1191.                     return false;
  1192.                 }
  1193.                 Type type = c.GetType();
  1194.                 bool flag = true;
  1195.                 LevelSerializer.StoreComponent(c, ref flag);
  1196.                 return flag && (!(c is IControlSerialization) || (c as IControlSerialization).ShouldSave()) && !type.IsDefined(typeof(DontStoreAttribute), true) && !LevelSerializer.IgnoreTypes.Contains(type.FullName);
  1197.             })
  1198.             select new
  1199.             {
  1200.                 Identifier = (StoreInformation)c.gameObject.GetComponent(typeof(StoreInformation)),
  1201.                 Component = c
  1202.             } into cp
  1203.             where cp.Identifier.StoreAllComponents || cp.Identifier.Components.Contains(cp.Component.GetType().FullName)
  1204.             orderby cp.Identifier.Id, cp.Component.GetType().FullName
  1205.             select cp).ToList();
  1206.             int processed = 0;
  1207.             levelData.StoredItems = (from s in toBeProcessed.Select(delegate(cp)
  1208.             {
  1209.                 LevelSerializer.StoredData result;
  1210.                 try
  1211.                 {
  1212.                     LevelSerializer.StoredData storedData = new LevelSerializer.StoredData
  1213.                     {
  1214.                         Type = cp.Component.GetType().FullName,
  1215.                         ClassId = cp.Identifier.ClassId,
  1216.                         Name = cp.Component.GetComponent<UniqueIdentifier>().Id
  1217.                     };
  1218.                     if (LevelSerializer.CustomSerializers.ContainsKey(cp.Component.GetType()))
  1219.                     {
  1220.                         storedData.Data = LevelSerializer.CustomSerializers[cp.Component.GetType()].Serialize(cp.Component);
  1221.                     }
  1222.                     else
  1223.                     {
  1224.                         storedData.Data = UnitySerializer.SerializeForDeserializeInto(cp.Component);
  1225.                     }
  1226.                     processed++;
  1227.                     LevelSerializer.Progress("Storing", (float)processed / (float)toBeProcessed.Count);
  1228.                     result = storedData;
  1229.                 }
  1230.                 catch (Exception ex)
  1231.                 {
  1232.                     processed++;
  1233.                     UnityEngine.Debug.LogWarning(string.Concat(new string[]
  1234.                     {
  1235.                         "Failed to serialize data (",
  1236.                         cp.Component.GetType().AssemblyQualifiedName,
  1237.                         ") of ",
  1238.                         cp.Component.name,
  1239.                         " with error ",
  1240.                         ex.ToString()
  1241.                     }));
  1242.                     result = null;
  1243.                 }
  1244.                 return result;
  1245.             })
  1246.             where s != null
  1247.             select s).ToList<LevelSerializer.StoredData>();
  1248.         }
  1249.         return UnitySerializer.Serialize(levelData);
  1250.     }
  1251.  
  1252.     public static void LoadObjectTree(this byte[] data, Action<LevelLoader> onComplete = null)
  1253.     {
  1254.         Action<LevelLoader> arg_25_0;
  1255.         if ((arg_25_0 = onComplete) == null)
  1256.         {
  1257.             arg_25_0 = delegate
  1258.             {
  1259.             };
  1260.         }
  1261.         onComplete = arg_25_0;
  1262.         LevelSerializer.LoadNow(data, true, false, onComplete);
  1263.     }
  1264.  
  1265.     public static void LoadNow(object data)
  1266.     {
  1267.         LevelSerializer.LoadNow(data, false, true, null);
  1268.     }
  1269.  
  1270.     public static void LoadNow(object data, bool dontDeleteExistingItems)
  1271.     {
  1272.         LevelSerializer.LoadNow(data, dontDeleteExistingItems, true, null);
  1273.     }
  1274.  
  1275.     public static void LoadNow(object data, bool dontDeleteExistingItems, bool showLoadingGUI)
  1276.     {
  1277.         LevelSerializer.LoadNow(data, dontDeleteExistingItems, showLoadingGUI, null);
  1278.     }
  1279.  
  1280.     public static void LoadNow(object data, bool dontDeleteExistingItems, bool showLoadingGUI, Action<LevelLoader> complete)
  1281.     {
  1282.         byte[] array = null;
  1283.         if (data is byte[])
  1284.         {
  1285.             array = (byte[])data;
  1286.         }
  1287.         if (data is string)
  1288.         {
  1289.             string text = (string)data;
  1290.             if (text.StartsWith("NOCOMPRESSION"))
  1291.             {
  1292.                 array = Convert.FromBase64String(text.Substring(13));
  1293.             }
  1294.             else
  1295.             {
  1296.                 array = CompressionHelper.Decompress(text);
  1297.             }
  1298.         }
  1299.         if (array == null)
  1300.         {
  1301.             throw new ArgumentException("data parameter must be either a byte[] or a base64 encoded string");
  1302.         }
  1303.         GameObject gameObject = new GameObject();
  1304.         LevelLoader levelLoader = gameObject.AddComponent<LevelLoader>();
  1305.         levelLoader.showGUI = showLoadingGUI;
  1306.         LevelSerializer.LevelData data2 = UnitySerializer.Deserialize<LevelSerializer.LevelData>(array);
  1307.         levelLoader.Data = data2;
  1308.         levelLoader.DontDelete = dontDeleteExistingItems;
  1309.         levelLoader.StartCoroutine(LevelSerializer.PerformLoad(levelLoader, complete));
  1310.     }
  1311.  
  1312.     [DebuggerHidden]
  1313.     protected static IEnumerator PerformLoad(LevelLoader loader, Action<LevelLoader> complete)
  1314.     {
  1315.         LevelSerializer.<PerformLoad>c__Iterator2EF <PerformLoad>c__Iterator2EF = new LevelSerializer.<PerformLoad>c__Iterator2EF();
  1316.         <PerformLoad>c__Iterator2EF.loader = loader;
  1317.         <PerformLoad>c__Iterator2EF.complete = complete;
  1318.         <PerformLoad>c__Iterator2EF.<$>loader = loader;
  1319.         <PerformLoad>c__Iterator2EF.<$>complete = complete;
  1320.         return <PerformLoad>c__Iterator2EF;
  1321.     }
  1322.  
  1323.     public static LevelLoader LoadSavedLevel(string data)
  1324.     {
  1325.         LevelSerializer.IsDeserializing = true;
  1326.         LevelSerializer.LevelData levelData;
  1327.         if (data.StartsWith("NOCOMPRESSION"))
  1328.         {
  1329.             GC.Collect();
  1330.             string s = data.Substring(13);
  1331.             byte[] array = Convert.FromBase64String(s);
  1332.             GC.Collect();
  1333.             levelData = UnitySerializer.Deserialize<LevelSerializer.LevelData>(array);
  1334.             GC.Collect();
  1335.         }
  1336.         else
  1337.         {
  1338.             levelData = UnitySerializer.Deserialize<LevelSerializer.LevelData>(CompressionHelper.Decompress(data));
  1339.         }
  1340.         SaveGameManager.Loaded();
  1341.         GameObject gameObject = new GameObject();
  1342.         UnityEngine.Object.DontDestroyOnLoad(gameObject);
  1343.         LevelLoader levelLoader = gameObject.AddComponent<LevelLoader>();
  1344.         levelLoader.Data = levelData;
  1345.         LevelSerializer.LevelLoadingOperation = Application.LoadLevelAsync(levelData.Name);
  1346.         return levelLoader;
  1347.     }
  1348. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement