Example #1
0
        object DeserializeSingleObject(Type type, Type expectedType)
        {
            object obj = CustomDeserializer.CustomDeserialize(package, type, reader);

            if (obj != null)
            {
                return(obj);
            }
            if (typeof(ScriptableObject).IsAssignableFrom(type))
            {
                return(Instantiate(FindAsset(reader.ReadString()), isMain));
            }
            if (typeof(GameObject).IsAssignableFrom(type))
            {
                return(Instantiate(FindAsset(reader.ReadString()), isMain));
            }

            try
            {
                if (package.version < 3 && expectedType != null && expectedType == typeof(Package.Asset))
                {
                    return(reader.ReadUnityType(expectedType));
                }

                return(reader.ReadUnityType(type, package));
            }
            catch (MissingMethodException)
            {
                Util.DebugPrint("Unsupported type for deserialization:", type.Name);
                return(null);
            }
        }
Example #2
0
        bool Used(string fullName, HashSet <string> packagePaths)
        {
            Package.Asset asset = CustomDeserializer.FindAsset(fullName);
            string        path  = asset?.package.packagePath;

            return(path != null && packagePaths.Contains(path));
        }
Example #3
0
 internal bool AllAssetsAvailable(HashSet <string> ignore)
 {
     return(CustomDeserializer.AllAvailable <BuildingInfo>(buildingAssets, ignore) &&
            CustomDeserializer.AllAvailable <PropInfo>(propAssets, ignore) &&
            CustomDeserializer.AllAvailable <TreeInfo>(treeAssets, ignore) &&
            CustomDeserializer.AllAvailable <VehicleInfo>(vehicleAssets, ignore) &&
            CustomDeserializer.AllAvailable <CitizenInfo>(citizenAssets, ignore) &&
            CustomDeserializer.AllAvailable <NetInfo>(netAssets, ignore));
 }
Example #4
0
        public Coroutine LoadLevel(Package.Asset asset, string playerScene, string uiScene, SimulationMetaData ngs, bool forceEnvironmentReload = false)
        {
            LoadingManager lm        = Singleton <LoadingManager> .instance;
            bool           activated = ngs.m_updateMode == SimulationManager.UpdateMode.LoadGame || ngs.m_updateMode == SimulationManager.UpdateMode.NewGameFromMap ||
                                       ngs.m_updateMode == SimulationManager.UpdateMode.NewGameFromScenario || Input.GetKey(KeyCode.LeftControl);

            instance.simulationFailed = instance.assetsStarted = instance.assetsFinished = false;

            if (!lm.m_currentlyLoading && !lm.m_applicationQuitting)
            {
                if (lm.m_LoadingWrapper != null)
                {
                    lm.m_LoadingWrapper.OnLevelUnloading(); // OnLevelUnloading
                }
                if (activated)
                {
                    Settings s = Settings.settings;
                    Util.DebugPrint("Options: 121", s.loadEnabled, s.loadUsed, s.shareTextures, s.shareMaterials, s.shareMeshes, s.reportAssets, s.skipPrefabs);

                    LoadingManager.instance.SetSceneProgress(0f);
                    instance.cityName = asset?.name ?? "NewGame";
                    Profiling.Init();
                    CustomDeserializer.Create();
                    Fixes.Create().Deploy();
                    LoadingScreen.Create().Setup();
                }

                lm.LoadingAnimationComponent.enabled = true;
                lm.m_currentlyLoading      = true;
                lm.m_metaDataLoaded        = false;
                lm.m_simulationDataLoaded  = false;
                lm.m_loadingComplete       = false;
                lm.m_renderDataReady       = false;
                lm.m_essentialScenesLoaded = false;
                lm.m_brokenAssets          = string.Empty;
                Util.Set(lm, "m_sceneProgress", 0f);
                Util.Set(lm, "m_simulationProgress", 0f);

                if (activated)
                {
                    Profiling.Start();
                }

                lm.m_loadingProfilerMain.Reset();
                lm.m_loadingProfilerSimulation.Reset();
                lm.m_loadingProfilerScenes.Reset();
                //LoadingManager.instance.m_loadingProfilerCustomContent.Reset();
                //LoadingManager.instance.m_loadingProfilerCustomAsset.Reset();

                IEnumerator iter = activated ? instance.LoadLevelCoroutine(asset, playerScene, uiScene, ngs, forceEnvironmentReload) :
                                   (IEnumerator)Util.Invoke(lm, "LoadLevelCoroutine", asset, playerScene, uiScene, ngs, forceEnvironmentReload);

                return(lm.StartCoroutine(iter));
            }

            return(null);
        }
        static bool AllAvailable <P>(HashSet <string> fullNames, HashSet <string> ignore) where P : PrefabInfo
        {
            foreach (string name in fullNames)
            {
                if (!ignore.Contains(name) && CustomDeserializer.FindLoaded <P>(name) == null)
                {
                    Util.DebugPrint("Not available:", name);
                    return(false);
                }
            }

            return(true);
        }
Example #6
0
        void Initialize <T>(T info) where T : PrefabInfo
        {
            string fullName     = info.gameObject.name;
            string brokenAssets = LoadingManager.instance.m_brokenAssets;

            PrefabCollection <T> .InitializePrefabs("Custom Assets", info, null);

            LoadingManager.instance.m_brokenAssets = brokenAssets;

            if (CustomDeserializer.FindLoaded <T>(fullName) == null)
            {
                throw new Exception(string.Concat(typeof(T).Name, " ", fullName, " failed"));
            }
        }
Example #7
0
        object DeserializeObject(Type type)
        {
            object obj = CustomDeserializer.CustomDeserialize(package, type, reader);

            if (obj != null)
            {
                return(obj);
            }

            obj = Activator.CreateInstance(type);
            reader.ReadString();
            DeserializeFields(obj, type, true);
            return(obj);
        }
Example #8
0
        UnityEngine.Object DeserializeScriptableObject(Type type)
        {
            object obj = CustomDeserializer.CustomDeserialize(package, type, reader);

            if (obj != null)
            {
                return((UnityEngine.Object)obj);
            }

            ScriptableObject so = ScriptableObject.CreateInstance(type);

            so.name = reader.ReadString();
            DeserializeFields(so, type, false);
            return(so);
        }
 static void ReportMissingAssets <P>(HashSet <string> customAssets) where P : PrefabInfo
 {
     try
     {
         foreach (string fullName in customAssets)
         {
             if (CustomDeserializer.FindLoaded <P>(fullName) == null)
             {
                 AssetLoader.instance.NotFound(fullName);
             }
         }
     }
     catch (Exception e)
     {
         UnityEngine.Debug.LogException(e);
     }
 }
Example #10
0
        HashSet <string> GetPackagePaths(params List <string>[] names)
        {
            HashSet <string> paths = new HashSet <string>();

            for (int i = 0; i < names.Length; i++)
            {
                for (int j = 0; j < names[i].Count; j++)
                {
                    Package.Asset asset = CustomDeserializer.FindAsset(names[i][j]);
                    string        path  = asset?.package.packagePath;

                    if (path != null)
                    {
                        paths.Add(path);
                    }
                }
            }

            return(paths);
        }
Example #11
0
        static void ReportMissingAssets <P>(HashSet <string> customAssets, CustomAssetMetaData.Type type) where P : PrefabInfo
        {
            try
            {
                bool reportAssets = Settings.settings.reportAssets;

                foreach (string fullName in customAssets)
                {
                    if (CustomDeserializer.FindLoaded <P>(fullName, tryName:false) == null)
                    {
                        AssetLoader.instance.NotFound(fullName);

                        if (reportAssets)
                        {
                            AssetReport.instance.AddMissing(fullName, type);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                UnityEngine.Debug.LogException(e);
            }
        }
Example #12
0
        public IEnumerator LoadCustomContent()
        {
            LoadingManager.instance.m_loadingProfilerMain.BeginLoading("LoadCustomContent");
            LoadingManager.instance.m_loadingProfilerCustomContent.Reset();
            LoadingManager.instance.m_loadingProfilerCustomAsset.Reset();
            LoadingManager.instance.m_loadingProfilerCustomContent.BeginLoading("District Styles");
            LoadingManager.instance.m_loadingProfilerCustomAsset.PauseLoading();
            hasStarted = true;

            int                              i, j;
            DistrictStyle                    districtStyle;
            DistrictStyleMetaData            districtStyleMetaData;
            List <DistrictStyle>             districtStyles         = new List <DistrictStyle>();
            HashSet <string>                 styleBuildings         = new HashSet <string>();
            FastList <DistrictStyleMetaData> districtStyleMetaDatas = new FastList <DistrictStyleMetaData>();
            FastList <Package>               districtStylePackages  = new FastList <Package>();

            Package.Asset europeanStyles = PackageManager.FindAssetByName("System." + DistrictStyle.kEuropeanStyleName);

            if (europeanStyles != null && europeanStyles.isEnabled)
            {
                districtStyle = new DistrictStyle(DistrictStyle.kEuropeanStyleName, true);
                Util.InvokeVoid(LoadingManager.instance, "AddChildrenToBuiltinStyle", GameObject.Find("European Style new"), districtStyle, false);
                Util.InvokeVoid(LoadingManager.instance, "AddChildrenToBuiltinStyle", GameObject.Find("European Style others"), districtStyle, true);
                districtStyles.Add(districtStyle);
            }

            if ((bool)typeof(LoadingManager).GetMethod("DLC", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(LoadingManager.instance, new object[] { 715190u }))
            {
                Package.Asset asset = PackageManager.FindAssetByName("System." + DistrictStyle.kEuropeanSuburbiaStyleName);

                if (asset != null && asset.isEnabled)
                {
                    districtStyle = new DistrictStyle(DistrictStyle.kEuropeanSuburbiaStyleName, true);
                    Util.InvokeVoid(LoadingManager.instance, "AddChildrenToBuiltinStyle", GameObject.Find("Modder Pack 3"), districtStyle, false);
                    districtStyles.Add(districtStyle);
                }
            }

            foreach (Package.Asset asset in PackageManager.FilterAssets(UserAssetType.DistrictStyleMetaData))
            {
                try
                {
                    if (asset != null && asset.isEnabled)
                    {
                        districtStyleMetaData = asset.Instantiate <DistrictStyleMetaData>();

                        if (districtStyleMetaData != null && !districtStyleMetaData.builtin)
                        {
                            districtStyleMetaDatas.Add(districtStyleMetaData);
                            districtStylePackages.Add(asset.package);

                            if (districtStyleMetaData.assets != null)
                            {
                                for (i = 0; i < districtStyleMetaData.assets.Length; i++)
                                {
                                    styleBuildings.Add(districtStyleMetaData.assets[i]);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    CODebugBase <LogChannel> .Warn(LogChannel.Modding, string.Concat(new object[] { ex.GetType(), ": Loading custom district style failed[", asset, "]\n", ex.Message }));
                }
            }

            LoadingManager.instance.m_loadingProfilerCustomAsset.ContinueLoading();
            LoadingManager.instance.m_loadingProfilerCustomContent.EndLoading();

            if (Settings.settings.loadUsed)
            {
                UsedAssets.Create();
            }

            lastMillis = Profiling.Millis;
            LoadingScreen.instance.DualSource.Add("Custom Assets");
            LoadingManager.instance.m_loadingProfilerCustomContent.BeginLoading("Calculating asset load order");
            Package.Asset[] queue = GetLoadQueue(styleBuildings);
            Util.DebugPrint("LoadQueue", queue.Length, Profiling.Millis);
            LoadingManager.instance.m_loadingProfilerCustomContent.EndLoading();

            LoadingManager.instance.m_loadingProfilerCustomContent.BeginLoading("Loading Custom Assets");
            Sharing.instance.Start(queue);
            beginMillis = Profiling.Millis;

            for (i = 0; i < queue.Length; i++)
            {
                Package.Asset assetRef = queue[i];

                if ((i & 63) == 0)
                {
                    PrintMem(i);
                }

                Sharing.instance.WaitForWorkers();

                try
                {
                    stack.Clear();
                    LoadImpl(assetRef);
                }
                catch (Exception e)
                {
                    AssetFailed(assetRef.fullName, e);
                }

                Sharing.instance.ManageLoadQueue(i);

                if (Profiling.Millis - lastMillis > yieldInterval)
                {
                    lastMillis = Profiling.Millis;
                    progress   = 0.15f + (i + 1) * 0.7f / queue.Length;
                    LoadingScreen.instance.SetProgress(progress, progress, assetCount, assetCount - i - 1 + queue.Length, beginMillis, lastMillis);
                    yield return(null);
                }
            }

            lastMillis = Profiling.Millis;
            LoadingScreen.instance.SetProgress(0.85f, 1f, assetCount, assetCount, beginMillis, lastMillis);
            LoadingManager.instance.m_loadingProfilerCustomContent.EndLoading();
            Util.DebugPrint("Custom assets loaded in", lastMillis - beginMillis);
            PrintMem();
            queue = null;
            stack.Clear();
            Report();

            LoadingManager.instance.m_loadingProfilerCustomContent.BeginLoading("Finalizing District Styles");
            LoadingManager.instance.m_loadingProfilerCustomAsset.PauseLoading();

            for (i = 0; i < districtStyleMetaDatas.m_size; i++)
            {
                try
                {
                    districtStyleMetaData = districtStyleMetaDatas.m_buffer[i];
                    districtStyle         = new DistrictStyle(districtStyleMetaData.name, false);

                    if (districtStylePackages.m_buffer[i].GetPublishedFileID() != PublishedFileId.invalid)
                    {
                        districtStyle.PackageName = districtStylePackages.m_buffer[i].packageName;
                    }

                    if (districtStyleMetaData.assets != null)
                    {
                        for (j = 0; j < districtStyleMetaData.assets.Length; j++)
                        {
                            BuildingInfo bi = CustomDeserializer.FindLoaded <BuildingInfo>(districtStyleMetaData.assets[j] + "_Data");

                            if (bi != null)
                            {
                                districtStyle.Add(bi);

                                if (districtStyleMetaData.builtin) // this is always false
                                {
                                    bi.m_dontSpawnNormally = !districtStyleMetaData.assetRef.isEnabled;
                                }
                            }
                            else
                            {
                                CODebugBase <LogChannel> .Warn(LogChannel.Modding, "Warning: Missing asset (" + districtStyleMetaData.assets[j] + ") in style " + districtStyleMetaData.name);
                            }
                        }

                        districtStyles.Add(districtStyle);
                    }
                }
                catch (Exception ex)
                {
                    CODebugBase <LogChannel> .Warn(LogChannel.Modding, ex.GetType() + ": Loading district style failed\n" + ex.Message);
                }
            }

            Singleton <DistrictManager> .instance.m_Styles = districtStyles.ToArray();

            if (Singleton <BuildingManager> .exists)
            {
                Singleton <BuildingManager> .instance.InitializeStyleArray(districtStyles.Count);
            }

            LoadingManager.instance.m_loadingProfilerCustomAsset.ContinueLoading();
            LoadingManager.instance.m_loadingProfilerCustomContent.EndLoading();
            LoadingManager.instance.m_loadingProfilerMain.EndLoading();
            hasFinished = true;
        }
Example #13
0
 internal bool AllPrefabsAvailable() => CustomDeserializer.AllAvailable <BuildingInfo>(simulationPrefabs, new HashSet <string>());