public void LoadSavedGame2(Package.Asset savedGame) { LogCalled(); AssertNotNull(savedGame, "could not find save"); var metaData = savedGame?.Instantiate <SaveGameMetaData>(); AssertNotNull(metaData, "metadata"); AssertNotNull(metaData.assetRef, "assetRef"); var package = savedGame.package ?? metaData.assetRef.package; AssertNotNull(package, "package"); PrintModsInfo(metaData.mods); SimulationMetaData ngs = new SimulationMetaData { m_CityName = metaData.cityName, m_updateMode = SimulationManager.UpdateMode.LoadGame, }; if (package.GetPublishedFileID() != PublishedFileId.invalid) { ngs.m_disableAchievements = MetaBool.True; } UpdateTheme(metaData.mapThemeRef, ngs); Log.Info($"Loading new game from " + $"map:{ngs.m_CityName} " + $"assetName:{savedGame.name} " + $"filePath:{package.packagePath}) " + $"theme={(ngs.m_MapThemeMetaData?.name).ToSTR()} " + $"LHT:{ngs.m_invertTraffic}", true); LoadGame(metaData, ngs); }
bool PropTreeTrailer(Package.Asset asset) { CustomAssetMetaData assetMetaData = null; try { bool wantBecauseEnabled = loadEnabled && IsEnabled(asset); if (!wantBecauseEnabled && !(loadUsed && refs.GotPropTreeTrailerPackage(asset.package.packageName))) { return(false); } assetMetaData = asset.Instantiate <CustomAssetMetaData>(); if (assetMetaData.type == CustomAssetMetaData.Type.Building || assetMetaData.type == CustomAssetMetaData.Type.Vehicle || assetMetaData.type == CustomAssetMetaData.Type.Unknown || (AssetImporterAssetTemplate.GetAssetDLCMask(assetMetaData) & notMask) != 0) { return(false); } if (wantBecauseEnabled || loadUsed && refs.GotPropTreeAsset(assetMetaData.assetRef.fullName) || loadUsed && assetMetaData.type == CustomAssetMetaData.Type.Trailer && refs.GotTrailerAsset(assetMetaData.assetRef.fullName)) { PropTreeTrailerImpl(asset.package.packageName, assetMetaData.assetRef); } } catch (Exception ex) { Failed(assetMetaData?.assetRef, ex); // CODebugBase<LogChannel>.Warn(LogChannel.Modding, string.Concat(new object[] { ex.GetType(), ": Loading custom asset failed[", asset, "]\n", ex.Message })); } return(true); }
internal void PropTreeTrailerImpl(string packageName, Package.Asset data) { try { string name = AssetName(data.name); LoadingManager.instance.m_loadingProfilerCustomAsset.BeginLoading(name); // CODebugBase<LogChannel>.Log(LogChannel.Modding, string.Concat("Loading custom asset ", assetMetaData.name, " from ", asset)); GameObject go = data.Instantiate <GameObject>(); go.name = packageName + "." + go.name; go.SetActive(false); PrefabInfo info = go.GetComponent <PrefabInfo>(); info.m_isCustomContent = true; if (info.m_Atlas != null && info.m_InfoTooltipThumbnail != null && info.m_InfoTooltipThumbnail != string.Empty && info.m_Atlas[info.m_InfoTooltipThumbnail] != null) { info.m_InfoTooltipAtlas = info.m_Atlas; } PropInfo pi = go.GetComponent <PropInfo>(); if (pi != null) { if (pi.m_lodObject != null) { pi.m_lodObject.SetActive(false); } PrefabCollection <PropInfo> .InitializePrefabs("Custom Assets", pi, null); propsCount++; } TreeInfo ti = go.GetComponent <TreeInfo>(); if (ti != null) { PrefabCollection <TreeInfo> .InitializePrefabs("Custom Assets", ti, null); treeCount++; } // Trailers, this way. VehicleInfo vi = go.GetComponent <VehicleInfo>(); if (vi != null) { PrefabCollection <VehicleInfo> .InitializePrefabs("Custom Assets", vi, null); if (vi.m_lodObject != null) { vi.m_lodObject.SetActive(false); } } } finally { LoadingManager.instance.m_loadingProfilerCustomAsset.EndLoading(); } }
void SetupAssetDistrictStyle(Package.Asset asset) { int i; try { if (asset != null && asset.isEnabled) { DistrictStyleMetaData 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 })); } }
public void LoadAssetEditor(bool load = true, bool lht = false, bool lsm = true) { LogCalled(); //Patches.ForceLSMPatch.ForceLSM = lsm; var mode = load ? SimulationManager.UpdateMode.LoadAsset : SimulationManager.UpdateMode.NewAsset; Package.Asset theme = GetDefaultTheme(); AssertNotNull(theme, "theme not found"); var themeMetaData = theme.Instantiate <SystemMapMetaData>(); AssertNotNull(themeMetaData, "themeMetaData"); SimulationMetaData ngs = new SimulationMetaData { m_gameInstanceIdentifier = Guid.NewGuid().ToString(), m_WorkshopPublishedFileId = PublishedFileId.invalid, m_updateMode = mode, //m_MapThemeMetaData = themeMetaData, m_invertTraffic = lht ? MetaBool.True : MetaBool.False, }; Singleton <LoadingManager> .instance.LoadLevel(themeMetaData.assetRef, "AssetEditor", "InAssetEditor", ngs, false); }
private void StartNewGameRoutine() { //begin mod var m_MapName = this.Find <UITextField>("MapName"); var m_FileList = this.Find <UIListBox>("MapList"); //end mod SimulationMetaData ngs = new SimulationMetaData() { m_CityName = m_MapName.text, m_gameInstanceIdentifier = Guid.NewGuid().ToString(), m_invertTraffic = !this.Find <UICheckBox>("InvertTraffic").isChecked ? SimulationMetaData.MetaBool.False : SimulationMetaData.MetaBool.True, m_disableAchievements = Singleton <PluginManager> .instance.enabledModCount <= 0 ? SimulationMetaData.MetaBool.False : SimulationMetaData.MetaBool.True, m_currentDateTime = DateTime.Now, m_newGameAppVersion = 159507472, m_updateMode = SimulationManager.UpdateMode.NewGameFromMap }; //begin mod ngs.m_environment = m_forceEnvironment; //end mod MapMetaData listingMetaData = this.GetListingMetaData(m_FileList.selectedIndex); if (listingMetaData.mapThemeRef != null) { Package.Asset assetByName = PackageManager.FindAssetByName(listingMetaData.mapThemeRef); if (assetByName != (Package.Asset)null) { ngs.m_MapThemeMetaData = assetByName.Instantiate <MapThemeMetaData>(); ngs.m_MapThemeMetaData.SetSelfRef(assetByName); } } Singleton <LoadingManager> .instance.LoadLevel(this.GetListingData(m_FileList.selectedIndex), "Game", "InGame", ngs); UIView.library.Hide(this.GetType().Name, 1); }
/// <summary> /// Load the world byte array sent by the server /// </summary> public static void LoadLevel(byte[] world) { Log.Info($"Preparing to load world (of size {world.Length})..."); // Load the package Package package = new Package(SYNC_NAME, world); // Ensure that the LoadingManager is ready. // Don't know if thats really necessary but doesn't hurt either. - root#0042 Singleton <LoadingManager> .Ensure(); // Get the meta data Package.Asset asset = package.Find(package.packageMainAsset); SaveGameMetaData metaData = asset.Instantiate <SaveGameMetaData>(); // Build the simulation SimulationMetaData simulation = new SimulationMetaData() { m_CityName = metaData.cityName, m_updateMode = SimulationManager.UpdateMode.LoadGame, m_environment = UIView.GetAView().panelsLibrary.Get <LoadPanel>("LoadPanel").m_forceEnvironment }; // Load the level Log.Info("Telling the loading manager to load the level"); Singleton <LoadingManager> .instance.LoadLevel(metaData.assetRef, "Game", "InGame", simulation, false); }
public CustomAssetMetaData InstantiateAssetMetaData(Package.Asset asset) { //Profiler.Trace( "Instantiate asset start" ); CustomAssetMetaData assetMetaData = asset.Instantiate <CustomAssetMetaData>(); //Profiler.Trace( "Instantiate asset end" ); return(assetMetaData); }
void BuildingVehicleImpl(string packageName, Package.Asset data, bool wanted) { try { string name = AssetName(data.name); LoadingManager.instance.m_loadingProfilerCustomAsset.BeginLoading(name); // CODebugBase<LogChannel>.Log(LogChannel.Modding, string.Concat("Loading custom asset ", assetMetaData.name, " from ", asset)); loadedAsset = data; GameObject go = data.Instantiate <GameObject>(); go.name = packageName + "." + go.name; go.SetActive(false); PrefabInfo info = go.GetComponent <PrefabInfo>(); info.m_isCustomContent = true; if (info.m_Atlas != null && info.m_InfoTooltipThumbnail != null && info.m_InfoTooltipThumbnail != string.Empty && info.m_Atlas[info.m_InfoTooltipThumbnail] != null) { info.m_InfoTooltipAtlas = info.m_Atlas; } BuildingInfo bi = go.GetComponent <BuildingInfo>(); if (bi != null) { if (bi.m_lodObject != null) { bi.m_lodObject.SetActive(false); } PrefabCollection <BuildingInfo> .InitializePrefabs("Custom Assets", bi, null); bi.m_dontSpawnNormally = !wanted; buildingsCount++; } VehicleInfo vi = go.GetComponent <VehicleInfo>(); if (vi != null) { PrefabCollection <VehicleInfo> .InitializePrefabs("Custom Assets", vi, null); if (vi.m_lodObject != null) { vi.m_lodObject.SetActive(false); } vehicleCount++; } } finally { loadedAsset = null; LoadingManager.instance.m_loadingProfilerCustomAsset.EndLoading(); } }
static void UpdateTheme(string mapThemeRef, SimulationMetaData ngs) { if (!string.IsNullOrEmpty(mapThemeRef)) { Package.Asset asset = PackageManager.FindAssetByName(mapThemeRef, UserAssetType.MapThemeMetaData); if (asset != null) { ngs.m_MapThemeMetaData = asset.Instantiate <MapThemeMetaData>(); ngs.m_MapThemeMetaData.SetSelfRef(asset); } } }
protected void Refresh() { ClearListing(); Package.AssetType[] assetTypes = new Package.AssetType[] { UserAssetType.SaveGameMetaData }; IEnumerator <Package.Asset> enumerator = PackageManager.FilterAssets(assetTypes).GetEnumerator(); try { while (enumerator.MoveNext()) { Package.Asset current = enumerator.Current; if ((current != null) && current.isEnabled && current.package.GetPublishedFileID() != PublishedFileId.invalid) { SaveGameMetaData mmd = current.Instantiate <SaveGameMetaData>(); AddToListing(current.name + " - " + mmd.timeStamp, current, mmd); } } } finally { if (enumerator == null) { } enumerator.Dispose(); } foreach (Package.Asset asset2 in SaveHelper.GetSavesOnDisk()) { SaveGameMetaData data2 = new SaveGameMetaData { assetRef = asset2 }; AddToListing("<color red>" + asset2.name + "</color>", asset2, data2); } this.m_SaveList.items = base.GetListingItems(); if (this.m_SaveList.items.Length > 0) { int num = FindIndexOf(m_LastSaveName); m_SaveList.selectedIndex = (num == -1) ? 0 : num; this.m_LoadButton.isEnabled = true; } else { this.m_LoadButton.isEnabled = false; Invoke("ShowNeedToRestartGamePanel", 0.1f); } }
void StartGame(Package.Asset package) { m_connectionInfoLabel.text = "Game Starting"; SaveGameMetaData mmd = package.Instantiate <SaveGameMetaData>(); SavePanel.lastLoadedName = package.name; Debug.Log(mmd.cityName); SimulationMetaData ngs = new SimulationMetaData { m_CityName = mmd.cityName, m_updateMode = SimulationManager.UpdateMode.LoadGame, m_environment = "", m_disableAchievements = SimulationMetaData.MetaBool.True }; Singleton <LoadingManager> .instance.LoadLevel(mmd.assetRef, "Game", "InGame", ngs); }
private void StartGame(Package.Asset package) { ConnectSettings.Ip = m_serverList[m_selectedIndex]["ip"]; ConnectSettings.Port = int.Parse(m_serverList[m_selectedIndex]["port"]); SaveGameMetaData mmd = package.Instantiate <SaveGameMetaData>(); SavePanel.lastLoadedName = package.name; SimulationMetaData ngs = new SimulationMetaData { m_CityName = mmd.cityName, m_updateMode = SimulationManager.UpdateMode.LoadGame, m_environment = "", m_disableAchievements = SimulationMetaData.MetaBool.True }; Singleton <LoadingManager> .instance.LoadLevel(mmd.assetRef, "Game", "InGame", ngs); }
void Load(Package.Asset asset) { string fullName = null; try { CustomAssetMetaData assetMetaData = asset.Instantiate <CustomAssetMetaData>(); // Always remember: assetRef may point to another package because the deserialization method accepts any asset with a matching checksum. // There is a bug in the 1.6.0 game update in this. fullName = asset.package.packageName + "." + assetMetaData.assetRef.name; CustomAssetMetaData.Type type = assetMetaData.type; bool spawnNormally = (type == CustomAssetMetaData.Type.Building || type == CustomAssetMetaData.Type.SubBuilding) ? loadEnabled && IsEnabled(asset) || loadUsed && UsedAssets.instance.GotBuilding(fullName) : true; stack.Clear(); LoadImpl(fullName, assetMetaData.assetRef, spawnNormally); } catch (Exception e) { AssetFailed(fullName ?? asset.fullName, e); } }
public bool SetTexture(Package.Asset asset) { if (asset == null) { return(false); } Texture2D oldTexture = Texture; Texture = asset.Instantiate <Texture2D>(); if (Texture == null) { Texture = oldTexture; return(false); } Texture.anisoLevel = 8; Texture.filterMode = FilterMode.Trilinear; Texture.Apply(); if (oldTexture != null) { Object.Destroy(oldTexture); } return(true); }
public void LoadMap2(Package.Asset map, bool lht = false) { LogCalled(); AssertNotNull(map, "map not found"); var metaData = map?.Instantiate <MapMetaData>(); AssertNotNull(metaData, "metadata"); AssertNotNull(metaData.assetRef, "assetRef"); var package = map.package ?? metaData.assetRef.package; AssertNotNull(package, "package"); PrintModsInfo(metaData.mods); SimulationMetaData ngs = new SimulationMetaData { m_CityName = metaData.mapName, m_gameInstanceIdentifier = Guid.NewGuid().ToString(), m_invertTraffic = lht ? MetaBool.True : MetaBool.False, m_disableAchievements = MetaBool.True, m_startingDateTime = DateTime.Now, m_currentDateTime = DateTime.Now, m_newGameAppVersion = DataLocation.productVersion, m_updateMode = SimulationManager.UpdateMode.NewGameFromMap, }; UpdateTheme(metaData.mapThemeRef, ngs); Log.Info($"Loading new game from " + $"map:{ngs.m_CityName} " + $"fileName:{map.name} " + $"filePath:{package.packagePath}) " + $"theme={(ngs.m_MapThemeMetaData?.name).ToSTR()}" + $"LHT:{ngs.m_invertTraffic}", true); LoadGame(metaData, ngs); }
bool BuildingVehicle(Package.Asset asset, bool includedInStyle) { CustomAssetMetaData assetMetaData = null; try { bool wantBecauseEnabled = loadEnabled && IsEnabled(asset); if (!includedInStyle && !wantBecauseEnabled && !(loadUsed && refs.GotBuildingVehiclePackage(asset.package.packageName))) { return(false); } assetMetaData = asset.Instantiate <CustomAssetMetaData>(); if (assetMetaData.type != CustomAssetMetaData.Type.Building && assetMetaData.type != CustomAssetMetaData.Type.Vehicle && assetMetaData.type != CustomAssetMetaData.Type.Unknown || (AssetImporterAssetTemplate.GetAssetDLCMask(assetMetaData) & notMask) != 0) { return(false); } bool wanted = wantBecauseEnabled || loadUsed && refs.GotBuildingVehicleAsset(assetMetaData.assetRef.fullName); if (includedInStyle || wanted) { BuildingVehicleImpl(asset.package.packageName, assetMetaData.assetRef, wanted); } } catch (Exception ex) { Failed(assetMetaData?.assetRef, ex); // CODebugBase<LogChannel>.Warn(LogChannel.Modding, string.Concat(new object[] { ex.GetType(), ": Loading custom asset failed:[", asset, "]\n", ex.Message })); } return(true); }
List <Package.Asset>[] GetLoadQueues(HashSet <string> styleBuildings) { Package.Asset[] assets = FilterAssets(UserAssetType.CustomAssetMetaData); List <Package.Asset>[] queues = { new List <Package.Asset>(4), new List <Package.Asset>(64), new List <Package.Asset>(4), new List <Package.Asset>(64) }; SteamHelper.DLC_BitMask notMask = ~SteamHelper.GetOwnedDLCMask(); for (int i = 0; i < assets.Length; i++) { Package.Asset asset = assets[i]; string fullName = null; try { bool wantThis = loadEnabled && IsEnabled(asset) || styleBuildings.Contains(asset.fullName); // Make the first check fast. if (wantThis || loadUsed && UsedAssets.instance.GotPackage(asset.package.packageName)) { CustomAssetMetaData assetMetaData = asset.Instantiate <CustomAssetMetaData>(); // Always remember: assetRef may point to another package because the deserialization method accepts any asset with the same checksum. // Think of identical vehicle trailers in different crp's. // There is a bug in the 1.6.0 game update in this. fullName = asset.package.packageName + "." + assetMetaData.assetRef.name; if ((AssetImporterAssetTemplate.GetAssetDLCMask(assetMetaData) & notMask) == 0) { switch (assetMetaData.type) { case CustomAssetMetaData.Type.Building: if ((wantThis || loadUsed && UsedAssets.instance.GotBuilding(fullName)) && !IsDuplicate(fullName, loadedBuildings, asset.package)) { queues[3].Add(asset); } break; case CustomAssetMetaData.Type.Prop: if ((wantThis || loadUsed && UsedAssets.instance.GotProp(fullName)) && !IsDuplicate(fullName, loadedProps, asset.package)) { queues[1].Add(asset); } break; case CustomAssetMetaData.Type.Tree: if ((wantThis || loadUsed && UsedAssets.instance.GotTree(fullName)) && !IsDuplicate(fullName, loadedTrees, asset.package)) { queues[1].Add(asset); } break; case CustomAssetMetaData.Type.Vehicle: if ((wantThis || loadUsed && UsedAssets.instance.GotVehicle(fullName)) && !IsDuplicate(fullName, loadedVehicles, asset.package)) { queues[3].Add(asset); } break; case CustomAssetMetaData.Type.Trailer: if ((wantThis || loadUsed && UsedAssets.instance.GotVehicle(fullName)) && !IsDuplicate(fullName, loadedVehicles, asset.package)) { queues[1].Add(asset); } break; case CustomAssetMetaData.Type.Unknown: if (wantThis) { queues[3].Add(asset); } break; case CustomAssetMetaData.Type.SubBuilding: if ((wantThis || loadUsed && UsedAssets.instance.GotBuilding(fullName)) && !IsDuplicate(fullName, loadedBuildings, asset.package)) { queues[2].Add(asset); } break; case CustomAssetMetaData.Type.PropVariation: if ((wantThis || loadUsed && UsedAssets.instance.GotProp(fullName)) && !IsDuplicate(fullName, loadedProps, asset.package)) { queues[0].Add(asset); } break; } } } } catch (Exception e) { AssetFailed(fullName ?? asset.fullName, e); } } return(queues); }
internal void LoadImpl(string fullName, Package.Asset assetRef, bool spawnNormally = true) { try { stack.Push(fullName); LoadingManager.instance.m_loadingProfilerCustomAsset.BeginLoading(AssetName(assetRef.name)); GameObject go = assetRef.Instantiate <GameObject>(); go.name = fullName; go.SetActive(false); PrefabInfo info = go.GetComponent <PrefabInfo>(); info.m_isCustomContent = true; if (info.m_Atlas != null && !string.IsNullOrEmpty(info.m_InfoTooltipThumbnail) && info.m_Atlas[info.m_InfoTooltipThumbnail] != null) { info.m_InfoTooltipAtlas = info.m_Atlas; } PropInfo pi = go.GetComponent <PropInfo>(); if (pi != null) { if (pi.m_lodObject != null) { pi.m_lodObject.SetActive(false); } if (loadedProps.Add(fullName)) { PrefabCollection <PropInfo> .InitializePrefabs("Custom Assets", pi, null); propCount++; } } TreeInfo ti = go.GetComponent <TreeInfo>(); if (ti != null && loadedTrees.Add(fullName)) { PrefabCollection <TreeInfo> .InitializePrefabs("Custom Assets", ti, null); treeCount++; } BuildingInfo bi = go.GetComponent <BuildingInfo>(); if (bi != null) { if (bi.m_lodObject != null) { bi.m_lodObject.SetActive(false); } if (loadedBuildings.Add(fullName)) { PrefabCollection <BuildingInfo> .InitializePrefabs("Custom Assets", bi, null); bi.m_dontSpawnNormally = !spawnNormally; buildingCount++; if (bi.GetAI() is IntersectionAI) { loadedIntersections.Add(fullName); } } } VehicleInfo vi = go.GetComponent <VehicleInfo>(); if (vi != null) { if (vi.m_lodObject != null) { vi.m_lodObject.SetActive(false); } if (loadedVehicles.Add(fullName)) { PrefabCollection <VehicleInfo> .InitializePrefabs("Custom Assets", vi, null); vehicleCount++; } } } finally { stack.Pop(); LoadingManager.instance.m_loadingProfilerCustomAsset.EndLoading(); } }