private static void InitializeLocalization() { Loading.QueueAction(() => { try { Debug.Log("NExt: Localization"); var localeManager = SingletonLite <LocaleManager> .instance; var localeField = typeof(LocaleManager).GetFieldByName("m_Locale"); var locale = (Locale)localeField.GetValue(localeManager); // For future extensions //locale.AddCategoryLocalizedString(); foreach (var builder in Mod.NetInfoBuilders) { builder.DefineLocalization(locale); } } catch (Exception ex) { Debug.Log("NExt: Crashed-Localization"); Debug.Log("NExt: " + ex.Message); Debug.Log("NExt: " + ex.ToString()); } }); }
public void Save() { if (Mod.GetPath() == Mod.PATH_NOT_FOUND) { return; } var configPath = Path.Combine(Mod.GetPath(), FILENAME); Debug.Log(string.Format("NExt: Saving config at {0}", configPath)); try { var xDoc = new XmlDocument(); var settings = xDoc.CreateElement("NetworkExtensionsSettings"); xDoc.AppendChild(settings); foreach (var part in PartsEnabled) { var xmlElem = xDoc.CreateElement(part.Key); xmlElem.InnerText = part.Value.ToString(); settings.AppendChild(xmlElem); } xDoc.Save(configPath); } catch (Exception ex) { Debug.Log(string.Format("NExt: Crashed saving config at {0} {1}", configPath, ex)); } }
private static void InitializeNewRoads(NetCollection newRoads) { Loading.QueueAction(() => { Debug.Log("NExt: Build NetworkExtensions"); // Builders ----------------------------------------------------------------------- var newInfos = new List <NetInfo>(); foreach (var builder in Mod.NetInfoBuilders) { try { newInfos.AddRange(builder.Build()); } catch (Exception ex) { Debug.Log(string.Format("NExt: Crashed-Network builders {0}", builder)); Debug.Log("NExt: " + ex.Message); Debug.Log("NExt: " + ex.ToString()); } } if (newInfos.Count > 0) { newRoads.m_prefabs = newInfos.ToArray(); PrefabCollection <NetInfo> .InitializePrefabs(newRoads.name, newRoads.m_prefabs, new string[] { }); PrefabCollection <NetInfo> .BindPrefabs(); } // Modifiers ---------------------------------------------------------------------- foreach (var modifier in Mod.NetInfoModifiers) { try { modifier.ModifyExistingNetInfo(); } catch (Exception ex) { Debug.Log(string.Format("NExt: Crashed-Network modifiers {0}", modifier)); Debug.Log("NExt: " + ex.Message); Debug.Log("NExt: " + ex.ToString()); } } Debug.Log("NExt: Finished installing components"); }); }
private void Initialize() { #if DEBUG if (_frameNb++ < 20) // Giving some time for the UI to refresh **NB. Putting this constant higher than 100 causes wierd behavior** { return; } if (!_versionShown) { var version = typeof(ModInitializer).Assembly.GetName().Version; Debug.Log(string.Format("NExt: Version {0}", version)); _versionShown = true; } #endif if (!s_initializedLocalization) { if (ValidateLocalizationPrerequisites()) { InitializeLocalization(); s_initializedLocalization = true; } } if (!_initializedNetworkInfo) { if (ValidateNetworkPrerequisites(NewRoads)) { InitializeNewRoads(NewRoads); _initializedNetworkInfo = true; } } _doneWithInit = _initializedNetworkInfo && s_initializedLocalization; if (_doneWithInit) { if (InitializationCompleted != null) { InitializationCompleted(this, EventArgs.Empty); } } }
private static Options Load() { if (Mod.GetPath() == Mod.PATH_NOT_FOUND) { return(new Options()); } var configPath = Path.Combine(Mod.GetPath(), FILENAME); Debug.Log(string.Format("NExt: Loading config at {0}", configPath)); if (!File.Exists(configPath)) { return(new Options()); } try { var configuration = new Options(); var xDoc = new XmlDocument(); xDoc.Load(configPath); if (xDoc.DocumentElement == null) { return(configuration); } foreach (XmlNode node in xDoc.DocumentElement.ChildNodes) { var nodeValue = true; if (!bool.TryParse(node.InnerText, out nodeValue)) { nodeValue = true; } configuration.PartsEnabled[node.Name] = nodeValue; } return(configuration); } catch (Exception ex) { Debug.Log(string.Format("NExt: Crashed load config at {0} {1}", configPath, ex)); return(new Options()); } }
public static string GetPath() { if (s_path == null) { s_path = CheckForPath(); if (s_path != PATH_NOT_FOUND) { Debug.Log("NExt: Mod path " + s_path); } else { Debug.Log("NExt: Path not found"); } } return(s_path); }
private static string CheckForPath() { // 1. Check Local path (CurrentUser\Appdata\Local\Colossal Order\Cities_Skylines\Addons\Mods) var localPath = Path.Combine(DataLocation.modsPath, "NetworkExtensions"); Debug.Log(string.Format("NExt: Exist={0} DataLocation.modsPath={1}", Directory.Exists(localPath), localPath)); if (Directory.Exists(localPath)) { return(localPath); } // 2. Check Steam foreach (var mod in Steam.workshop.GetSubscribedItems()) { if (mod.AsUInt64 == WORKSHOP_ID) { var workshopPath = Steam.workshop.GetSubscribedItemPath(mod); Debug.Log(string.Format("NExt: Exist={0} WorkshopPath={1}", Directory.Exists(workshopPath), workshopPath)); if (Directory.Exists(workshopPath)) { return(workshopPath); } } } // 3. Check Cities Skylines files folder var csFolderPath = Path.Combine(Path.Combine(DataLocation.gameContentPath, "Mods"), "NetworkExtensions"); Debug.Log(string.Format("NExt: Exist={0} DataLocation.gameContentPath={1}", Directory.Exists(csFolderPath), csFolderPath)); if (Directory.Exists(csFolderPath)) { return(csFolderPath); } return(PATH_NOT_FOUND); }