protected override void Install() { if (Done) // Only one Assets installation throughout the application { return; } foreach (var action in AssetManager.instance.CreateLoadingSequence(RExModule.GetPath())) { var localAction = action; Loading.QueueAction(() => { try { localAction(); } catch (Exception ex) { Debug.Log("REx: Crashed-AssetsInstaller"); Debug.Log("REx: " + ex.Message); Debug.Log("REx: " + ex.ToString()); } }); } Done = true; }
protected override void Install() { if (Done) //Only one localization throughout the application { return; } Loading.QueueAction(() => { try { //Debug.Log("REx: Localization"); var locale = SingletonLite <LocaleManager> .instance.GetLocale(); locale.CreateMenuTitleLocalizedString(Menus.AdditionnalMenus.ROADS_SMALL_HV, "Small Heavy Roads"); foreach (var builder in RExModule.NetInfoBuilders) { locale.CreateNetTitleLocalizedString(builder.Name, builder.DisplayName); locale.CreateNetDescriptionLocalizedString(builder.Name, builder.Description); } } catch (Exception ex) { Debug.Log("REx: Crashed-Localization"); Debug.Log("REx: " + ex.Message); Debug.Log("REx: " + ex.ToString()); } Done = true; }); }
private static void InstallNetInfosModifiers(RExModule host) { var niModifiers = host.Parts .OfType <INetInfoModifier>() .WhereActivated() .ToArray(); foreach (var nimodifier in niModifiers) { var modifier = nimodifier; Stopwatch sw = new Stopwatch(); Loading.QueueAction(() => { try { sw.Start(); modifier.ModifyExistingNetInfo(); sw.Stop(); Debug.Log(string.Format("REx: {0} modifications applied in {1}ms", modifier.Name, sw.ElapsedMilliseconds)); } catch (Exception ex) { Debug.Log(string.Format("REx: Crashed-Network modifiers {0}", modifier.Name)); Debug.Log("REx: " + ex.Message); Debug.Log("REx: " + ex.ToString()); } }); } }
private static void InstallCompatibilities(RExModule host) { Loading.QueueAction(() => { var compParts = host.Parts .OfType <ICompatibilityPart>() .ToArray(); foreach (var compatibilityPart in compParts) { try { if (compatibilityPart.IsPluginActive) { compatibilityPart.Setup(host._roads.m_prefabs); Debug.Log(string.Format("REx: {0} compatibility activated", compatibilityPart.Name)); } } catch (Exception ex) { Debug.Log(string.Format("REx: Crashed-CompatibilitySupport {0}", compatibilityPart.Name)); Debug.Log("REx: " + ex.Message); Debug.Log("REx: " + ex.ToString()); } } }); }
public void LateBuildUp(NetInfo info, NetInfoVersion version) { if (version == NetInfoVersion.Bridge) { foreach (var building in BuildingCollection.FindObjectsOfType <BuildingInfo>()) { if (building.name.ToLower().Contains("pillar")) { Debug.Log($"PILLARNAME = {building.name}"); } } var bridgePillar = PrefabCollection <BuildingInfo> .FindLoaded($"{Tools.PackageName("BridgePillar")}.CableStay32m_Data"); if (bridgePillar == null) { Debug.Log($"{info.name}: CableStay32m Pillar not found!"); } else { var bridgeAI = info.GetComponent <RoadBridgeAI>(); if (bridgeAI != null) { bridgeAI.m_doubleLength = true; bridgeAI.m_bridgePillarInfo = null; bridgeAI.m_middlePillarInfo = bridgePillar; bridgeAI.m_middlePillarOffset = 58; } } } }
public static void AddWoodBollards(this NetInfo info, NetInfoVersion version) { var bollardName = "WoodBollard"; float?bollardOffset = null; float?pillarOffset = null; var bollardInfo = PrefabCollection <PropInfo> .FindLoaded($"{Tools.PackageName(bollardName)}.{bollardName}_Data"); if (bollardInfo == null) { Debug.Log($"{info.name}: {bollardName} not found!"); } else { bollardOffset = 0; } BuildingInfo pillarInfo = null; if (version == NetInfoVersion.Elevated || version == NetInfoVersion.Bridge) { var pillarName = "Wood8mEPillar"; pillarInfo = PrefabCollection <BuildingInfo> .FindLoaded($"{Tools.PackageName(pillarName)}.{pillarName}_Data"); if (pillarInfo == null) { Debug.Log($"{info.name}: {pillarName} not found!"); } } info.AddBollards(version, bollardInfo, pillarInfo, pillarOffset, bollardOffset); }
protected override void Install() { Loading.QueueAction(() => { try { var menuInstalled = false; var group = FindObjectsOfType <RoadsGroupPanel>().FirstOrDefault(); if (InstallRoadSmallHV(group)) { menuInstalled = true; } if (menuInstalled) { Debug.Log("REx: Additionnal Menus have been installed successfully"); } #if DEBUG else { Debug.Log("REx: Something has happened, Additionnal Menus have not been installed"); } #endif } catch (Exception ex) { Debug.Log("REx: Crashed-Initialized Additionnal Menus"); Debug.Log("REx: " + ex.Message); Debug.Log("REx: " + ex.ToString()); } }); }
protected override void Install() { var version = GetType().Assembly.GetName().Version; Debug.Log(string.Format("REx: Version {0}", version)); InstallRedirections(); }
private static void InstallPropInfos(RExModule host) { var newInfos = new List <PropInfo>(); var piBuilders = host.Parts .OfType <IPrefabBuilder <PropInfo> >() .WhereActivated() .ToArray(); foreach (var piBuilder in piBuilders) { var builder = piBuilder; Stopwatch sw = new Stopwatch(); Loading.QueueAction(() => { try { sw.Start(); newInfos.Add(builder.Build()); sw.Stop(); Debug.Log(string.Format("REx: Prop {0} installed in {1}ms", builder.Name, sw.ElapsedMilliseconds)); } catch (Exception ex) { Debug.Log(string.Format("REx: Crashed-Prop builder {0}", builder.Name)); Debug.Log("REx: " + ex.Message); Debug.Log("REx: " + ex.ToString()); Debug.Log(string.Format("REx: Fallbacking-Prop builder {0}", builder.Name)); try { newInfos.Add(builder.BuildEmergencyFallback()); } catch (Exception exFallback) { Debug.Log(string.Format("REx: Crashed-Fallback Prop builder {0}", builder.Name)); Debug.Log("REx: " + exFallback.Message); Debug.Log("REx: " + exFallback.ToString()); } } }); } Loading.QueueAction(() => { var props = host._props = host._container.AddComponent <PropCollection>(); props.name = REX_PROPCOLLECTION; if (newInfos.Count > 0) { props.m_prefabs = newInfos.ToArray(); PrefabCollection <PropInfo> .InitializePrefabs(props.name, props.m_prefabs, new string[] { }); PrefabCollection <PropInfo> .BindPrefabs(); } }); }
private static string GetAssetPath(string defaultFolderPath, ulong workshopId) { // 1. Check Local path (CurrentUser\Appdata\Local\Colossal Order\Cities_Skylines\Addons\Mods) var localPath = Path.Combine(DataLocation.modsPath, defaultFolderPath); Debug.Log(string.Format("TFW: Exist={0} DataLocation.modsPath={1}", Directory.Exists(localPath), localPath)); if (Directory.Exists(localPath)) { return(localPath); } // 2. Check Local path (CurrentUser\Appdata\Local\Colossal Order\Cities_Skylines\Addons\Mods) without spaces localPath = Path.Combine(DataLocation.modsPath, defaultFolderPath.Replace(" ", "")); Debug.Log(string.Format("TFW: Exist={0} DataLocation.modsPath={1}", Directory.Exists(localPath), localPath)); if (Directory.Exists(localPath)) { return(localPath); } // 3. Check Steam foreach (var mod in PlatformService.workshop.GetSubscribedItems()) { if (mod.AsUInt64 == workshopId) { var workshopPath = PlatformService.workshop.GetSubscribedItemPath(mod); Debug.Log(string.Format("TFW: Exist={0} WorkshopPath={1}", Directory.Exists(workshopPath), workshopPath)); if (Directory.Exists(workshopPath)) { return(workshopPath); } } } // 4. Check Cities Skylines files folder var csFolderPath = Path.Combine(Path.Combine(DataLocation.gameContentPath, "Mods"), defaultFolderPath); Debug.Log(string.Format("TFW: Exist={0} DataLocation.gameContentPath={1}", Directory.Exists(csFolderPath), csFolderPath)); if (Directory.Exists(csFolderPath)) { return(csFolderPath); } // 5. Check Cities Skylines files folder without spaces csFolderPath = Path.Combine(Path.Combine(DataLocation.gameContentPath, "Mods"), defaultFolderPath.Replace(" ", "")); Debug.Log(string.Format("TFW: Exist={0} DataLocation.gameContentPath={1}", Directory.Exists(csFolderPath), csFolderPath)); if (Directory.Exists(csFolderPath)) { return(csFolderPath); } return(Assets.PATH_NOT_FOUND); }
public static void AddStoneBollard(this NetInfo info, NetInfoVersion version) { var bollardName = "StoneBollard"; var bollardInfo = PrefabCollection <PropInfo> .FindLoaded($"{Tools.PackageName(bollardName)}.{bollardName}_Data"); if (bollardInfo == null) { Debug.Log($"{info.name}: {bollardName} not found!"); } info.AddBollards(version, bollardInfo); }
protected override void Install(RExModule host) { InstallPropInfos(host); var swAll = new Stopwatch(); swAll.Start(); InstallNetInfos(host); swAll.Stop(); Debug.Log($"All NetInfos in {swAll.ElapsedMilliseconds}ms"); InstallNetInfosModifiers(host); InstallCompatibilities(host); }
public static string GetPath() { if (s_path == null) { s_path = AssetAccess.GetPath("Transit Addon Mod", WORKSHOP_ID); if (s_path != PATH_NOT_FOUND) { Debug.Log("REx: Mod path " + s_path); } else { Debug.Log("REx: Path not found"); } } return(s_path); }
private static void InstallCompatibilities(RExModule host) { var swAll = new Stopwatch(); swAll.Start(); Stopwatch sw = new Stopwatch(); Loading.QueueAction(() => { var compParts = host.Parts .OfType <ICompatibilityPart>() .ToArray(); sw.Stop(); Debug.Log($"Compatibilities got in {sw.ElapsedMilliseconds}ms"); foreach (var compatibilityPart in compParts) { Stopwatch sw2 = new Stopwatch(); try { sw2.Start(); if (compatibilityPart.IsPluginActive) { compatibilityPart.Setup(host._roads.m_prefabs); sw2.Stop(); Debug.Log(string.Format("REx: {0} compatibility activated in {1}", compatibilityPart.Name, sw2.ElapsedMilliseconds)); } else { sw2.Stop(); } } catch (Exception ex) { Debug.Log(string.Format("REx: Crashed-CompatibilitySupport {0}", compatibilityPart.Name)); Debug.Log("REx: " + ex.Message); Debug.Log("REx: " + ex.ToString()); } } }); swAll.Stop(); Debug.Log($"All Compatibilities in {swAll.ElapsedMilliseconds}ms"); }
private void InstallRoadsGroupPanelRedirect() { var originalMethod = typeof(RoadsGroupPanel).GetMethod("GetCategoryOrder", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); if (originalMethod == null) { Debug.Log("REx: Cannot find the GetCategoryOrder original method, continuing"); return; } var newMethod = typeof(RExRoadsGroupPanel).GetMethod("GetCategoryOrder", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); if (newMethod == null) { Debug.Log("REx: Cannot find the GetCategoryOrder new method, continuing"); return; } s_rmoRedirect = RedirectionHelper.RedirectCalls(originalMethod, newMethod); }
public static void SetSharedLaneProps(this NetInfo.Lane lane) { var prop = Prefabs.Find <PropInfo>("SharedLaneText", false); if (prop == null) { Debug.Log("SharedLaneText doesnt exist"); return; } if (lane.m_laneProps == null) { lane.m_laneProps = ScriptableObject.CreateInstance <NetLaneProps>(); lane.m_laneProps.m_props = new NetLaneProps.Prop[] { }; } else { lane.m_laneProps = lane.m_laneProps.Clone(); } var tempProps = lane.m_laneProps.m_props.ToList(); tempProps.RemoveProps("arrow"); lane.m_laneProps.m_props = tempProps.ToArray(); lane.m_laneProps.m_props = lane .m_laneProps .m_props .Union(new NetLaneProps.Prop { m_prop = prop, m_position = new Vector3(0f, 0f, 7.5f), m_angle = 180f, m_segmentOffset = -1f, m_minLength = 8f, m_startFlagsRequired = NetNode.Flags.Junction }) .ToArray(); }
private void InstallRedirections() { if (s_redirectionsInstalled) { return; } try { InstallRoadsGroupPanelRedirect(); } catch (Exception ex) { Debug.Log("REx: Crashed-RedirectionsInstall"); Debug.Log("REx: " + ex.Message); Debug.Log("REx: " + ex.ToString()); } finally { s_redirectionsInstalled = true; } }
public void LateBuildUp(NetInfo info, NetInfoVersion version) { if (version == NetInfoVersion.Bridge) { var bridgePillar = PrefabCollection <BuildingInfo> .FindLoaded($"{Tools.PackageName("BridgePillar")}.CableStay32m_Data"); if (bridgePillar == null) { Debug.Log($"{info.name}: CableStay32m Pillar not found!"); } else { var bridgeAI = info.GetComponent <RoadBridgeAI>(); if (bridgeAI != null) { bridgeAI.m_doubleLength = true; bridgeAI.m_bridgePillarInfo = null; bridgeAI.m_middlePillarInfo = bridgePillar; bridgeAI.m_middlePillarOffset = 58; } } } }
protected override void Install() { var localNewRoads = NewRoads; Loading.QueueAction(() => { //Debug.Log("REx: Setting up new Roads and Logic"); // Builders ----------------------------------------------------------------------- var newInfos = new List <NetInfo>(); foreach (var builder in RExModule.NetInfoBuilders) { try { newInfos.AddRange(builder.Build()); Debug.Log(string.Format("REx: {0} installed", builder.DisplayName)); } catch (Exception ex) { Debug.Log(string.Format("REx: Crashed-Network builders {0}", builder)); Debug.Log("REx: " + ex.Message); Debug.Log("REx: " + ex.ToString()); } } if (newInfos.Count > 0) { localNewRoads.m_prefabs = newInfos.ToArray(); PrefabCollection <NetInfo> .InitializePrefabs(localNewRoads.name, localNewRoads.m_prefabs, new string[] { }); PrefabCollection <NetInfo> .BindPrefabs(); } // Modifiers ---------------------------------------------------------------------- foreach (var modifier in RExModule.NetInfoModifiers) { try { modifier.ModifyExistingNetInfo(); Debug.Log(string.Format("REx: {0} modifications applied", modifier.DisplayName)); } catch (Exception ex) { Debug.Log(string.Format("REx: Crashed-Network modifiers {0}", modifier)); Debug.Log("REx: " + ex.Message); Debug.Log("REx: " + ex.ToString()); } } // Cross mods support ------------------------------------------------------------- foreach (var compatibilityPart in RExModule.CompatibilityParts) { try { if (compatibilityPart.IsPluginActive) { compatibilityPart.Setup(newInfos); Debug.Log(string.Format("REx: {0} compatibility activated", compatibilityPart.Name)); } } catch (Exception ex) { Debug.Log(string.Format("REx: Crashed-CompatibilitySupport {0}", compatibilityPart.Name)); Debug.Log("REx: " + ex.Message); Debug.Log("REx: " + ex.ToString()); } } }); }
private static void InstallNetInfos(RExModule host) { var newInfos = new List <NetInfo>(); var niBuilders = host.Parts .OfType <INetInfoBuilder>() .WhereActivated() .ToArray(); var lateOperations = new List <Action>(); foreach (var niBuilder in niBuilders) { var builder = niBuilder; Loading.QueueAction(() => { try { newInfos.AddRange(builder.Build(lateOperations)); Debug.Log(string.Format("REx: {0} installed", builder.Name)); } catch (Exception ex) { Debug.Log(string.Format("REx: Crashed-Network builder {0}", builder.Name)); Debug.Log("REx: " + ex.Message); Debug.Log("REx: " + ex.ToString()); Debug.Log(string.Format("REx: Fallbacking-Network builder {0}", builder.Name)); try { newInfos.AddRange(builder.BuildEmergencyFallback()); } catch (Exception exFallback) { Debug.Log(string.Format("REx: Crashed-Fallback Network builder {0}", builder.Name)); Debug.Log("REx: " + exFallback.Message); Debug.Log("REx: " + exFallback.ToString()); } } }); } Loading.QueueAction(() => { var roads = host._roads = host._container.AddComponent <NetCollection>(); roads.name = REX_NETCOLLECTION; if (newInfos.Count > 0) { roads.m_prefabs = newInfos.ToArray(); PrefabCollection <NetInfo> .InitializePrefabs(roads.name, roads.m_prefabs, new string[] {}); PrefabCollection <NetInfo> .BindPrefabs(); } }); Loading.QueueAction(() => { host._lateOperations = lateOperations; }); }
private void InstallNetInfos(RExModule host) { var newInfos = new List <NetInfo>(); var niBuilders = host.Parts .OfType <INetInfoBuilder>() .WhereActivated() .ToArray(); var lateOperations = new List <Action>(); foreach (var niBuilder in niBuilders) { var builder = niBuilder; Loading.QueueAction(() => { Stopwatch sw = new Stopwatch(); try { sw.Start(); var isMultiMenu = builder is IMenuItemBuildersProvider; var isSingleMenu = builder is IMenuItemBuilder; m_Infos.Clear(); foreach (NetInfoVersion version in Enum.GetValues(typeof(NetInfoVersion))) { NetInfo info = null; if (version != NetInfoVersion.All && version != NetInfoVersion.AllWithDecoration && builder.SupportedVersions.HasFlag(version)) { var basedPrefabName = builder.GetBasedPrefabName(version); var newPrefabName = builder.GetBuiltPrefabName(version); if (m_BasedPrefabs.ContainsKey(basedPrefabName) == false) { m_BasedPrefabs.Add(basedPrefabName, Resources.FindObjectsOfTypeAll <NetInfo>().FirstOrDefault(netInfo => netInfo.name == basedPrefabName)); } info = m_BasedPrefabs[basedPrefabName].Clone(newPrefabName, transform); builder.BuildUp(info, version); var lateBuilder = builder as INetInfoLateBuilder; if (lateBuilder != null) { lateOperations.Add(() => lateBuilder.LateBuildUp(info, version)); } m_Infos.Add(version, info); } } List <NetInfo> groundInfos = new List <NetInfo>(); foreach (var kvp in m_Infos) { if (kvp.Value != null) { if (kvp.Key == NetInfoVersion.Ground || kvp.Key == NetInfoVersion.GroundGrass || kvp.Key == NetInfoVersion.GroundTrees) { groundInfos.Add(kvp.Value); } } } if (isSingleMenu) { if (m_Infos.ContainsKey(NetInfoVersion.GroundGrass) || m_Infos.ContainsKey(NetInfoVersion.GroundTrees)) { throw new Exception("Multiple netinfo menuitem cannot be build with the IMenuItemBuilder, use the IMenuItemBuildersProvider"); } else { var mib = builder as IMenuItemBuilder; m_Infos[NetInfoVersion.Ground].SetMenuItemConfig(mib); } } else if (builder is IMenuItemBuildersProvider) { var mibp = builder as IMenuItemBuildersProvider; var mibs = mibp.MenuItemBuilders.ToDictionary(x => x.Name, StringComparer.InvariantCultureIgnoreCase); foreach (var info in groundInfos) { if (mibs.ContainsKey(info.name)) { var mib = mibs[info.name]; info.SetMenuItemConfig(mib); } } } else { throw new Exception("Cannot set the menuitem on netinfo, either implement IMenuItemBuilder or IMenuItemBuildersProvider"); } foreach (var info in groundInfos) { var ai = info.GetComponent <RoadAI>(); ai.m_elevatedInfo = m_Infos.ContainsKey(NetInfoVersion.Elevated) ? m_Infos[NetInfoVersion.Elevated] : null; ai.m_bridgeInfo = m_Infos.ContainsKey(NetInfoVersion.Bridge) ? m_Infos[NetInfoVersion.Bridge] : null; ai.m_tunnelInfo = m_Infos.ContainsKey(NetInfoVersion.Tunnel) ? m_Infos[NetInfoVersion.Tunnel] : null; ai.m_slopeInfo = m_Infos.ContainsKey(NetInfoVersion.Slope) ? m_Infos[NetInfoVersion.Slope] : null; } newInfos.AddRange(m_Infos.Values); sw.Stop(); Debug.Log(string.Format("REx: {0} installed in {1}ms", builder.Name, sw.ElapsedMilliseconds)); } catch (Exception ex) { Debug.Log(string.Format("REx: Crashed-Network builder {0}", builder.Name)); Debug.Log("REx: " + ex.Message); Debug.Log("REx: " + ex.ToString()); Debug.Log(string.Format("REx: Fallbacking-Network builder {0}", builder.Name)); try { newInfos.AddRange(builder.BuildEmergencyFallback()); } catch (Exception exFallback) { Debug.Log(string.Format("REx: Crashed-Fallback Network builder {0}", builder.Name)); Debug.Log("REx: " + exFallback.Message); Debug.Log("REx: " + exFallback.ToString()); } } }); } Loading.QueueAction(() => { var roads = host._roads = host._container.AddComponent <NetCollection>(); roads.name = REX_NETCOLLECTION; if (newInfos.Count > 0) { roads.m_prefabs = newInfos.ToArray(); PrefabCollection <NetInfo> .InitializePrefabs(roads.name, roads.m_prefabs, new string[] { }); PrefabCollection <NetInfo> .BindPrefabs(); } }); Loading.QueueAction(() => { host._lateOperations = lateOperations; }); }