private static bool Prefix(ref LoadThemePanel __instance, ref UIListBox ___m_SaveList, ref UIButton ___m_LoadButton, string ___m_LastSaveName) { using (AutoProfile.Start("LoadMapPanel.Refresh()")) { ClearListing.Invoke(__instance, null); bool snowfallOwned = SteamHelper.IsDLCOwned(SteamHelper.DLC.SnowFallDLC); foreach (Package.Asset asset in PackageManager.FilterAssets(UserAssetType.MapThemeMetaData)) { if (asset == null || !asset.isEnabled) { continue; } try { var mmd = asset.Instantiate <MapThemeMetaData>(); mmd.SetSelfRef(asset); if (mmd.environment == "Winter" && !snowfallOwned) { continue; } var forbid = false; foreach (string s in Forbidden) { if (asset.fullName.Contains(s)) { forbid = true; } } if (forbid) { continue; } var parameters = _addToListingParamCount == 5 ? new object[] { asset.name, mmd.timeStamp, asset, mmd, true } : new object[] { asset.name, mmd.timeStamp, asset, mmd, true, false }; AddToListing.Invoke(__instance, parameters); } catch (Exception ex) { CODebug.Error(LogChannel.Serialization, "'" + asset.name + "' failed to load.\n" + ex.ToString()); } } ___m_SaveList.items = GetListingItems.Invoke(__instance, null) as string[]; var listingCount = (int)GetListingCount.Invoke(__instance, null); if (listingCount > 0) { var idx = (int)FindIndexOf.Invoke(__instance, new object[] { ___m_LastSaveName }); ___m_SaveList.selectedIndex = (idx != -1) ? idx : 0; ___m_LoadButton.isEnabled = true; } else { ___m_LoadButton.isEnabled = false; } } return(false); }
public override void OnLoadData() { base.OnLoadData(); CODebug.Log(LogChannel.Modding, Mod.modName + " - try loading data"); // if (s_info == null) { // s_info // } try { if (m_serializedData != null) { byte[] data2 = m_serializedData.LoadData(RESILIENTS_VERSION_ID); if (data2 != null) { BinaryFormatter bFormatter = new BinaryFormatter(); MemoryStream mStream = new MemoryStream(data2); s_savedDataVersion = (int)bFormatter.Deserialize(mStream); } else { //save had no data } if (s_savedDataVersion >= 0 && s_savedDataVersion <= SAVE_DATA_VERSION) { byte[] data = m_serializedData.LoadData(RESILIENTS_DATA_ID); if (data != null) { BinaryFormatter bFormatter = new BinaryFormatter(); MemoryStream mStream = new MemoryStream(data); switch (s_savedDataVersion) { case 0: List <ResilientBuildings.ResilientInfo> legacyList = (List <ResilientBuildings.ResilientInfo>)bFormatter.Deserialize(mStream); s_data = convertVersionZeroListToOne(legacyList); break; case 1: case 2: case 3: s_data = (List <ResilientBuildings.ResilientInfoV1>)bFormatter.Deserialize(mStream); break; } CODebug.Log(LogChannel.Modding, Mod.modName + " - successful loading buildings data"); } else { } data = m_serializedData.LoadData(RESILIENTS_DISTRICTS_ID); if (data != null) { BinaryFormatter bFormatter = new BinaryFormatter(); MemoryStream mStream = new MemoryStream(data); switch (s_savedDataVersion) { case 3: s_districts = (List <ResilientBuildings.ResilientDistrict>)bFormatter.Deserialize(mStream); break; } CODebug.Log(LogChannel.Modding, Mod.modName + " - successful loading districts data"); } else { } data = m_serializedData.LoadData(RESILIENTS_SETTINGS_ID); if (data != null) { BinaryFormatter bFormatter = new BinaryFormatter(); MemoryStream mStream = new MemoryStream(data); switch (s_savedDataVersion) { case 2: case 3: Settings.inst = (ResilientSettings)bFormatter.Deserialize(mStream); break; } CODebug.Log(LogChannel.Modding, Mod.modName + " - successful loading settings"); } else { } } else { CODebug.Error(LogChannel.Modding, Mod.modName + " - invalid saved data version"); } } } catch (Exception e) { CODebug.Log(LogChannel.Modding, Mod.modName + " - Error loading data " + e.Message); } }