Esempio n. 1
0
        public static void SetDirectionImpl(bool lht = true)
        {
            if (lht == NetUtil.LHT)
            {
                return;                        // no need for change.
            }
            SimulationManager.instance.m_metaData.m_invertTraffic =
                lht ? SimulationMetaData.MetaBool.True: SimulationMetaData.MetaBool.False;

            for (ushort i = 0; i < PrefabCollection <NetInfo> .LoadedCount(); ++i)
            {
                var info = PrefabCollection <NetInfo> .GetLoaded(i);

                if (!info)
                {
                    continue;
                }
                foreach (var lane in info.m_lanes)
                {
                    const NetInfo.LaneType flags = NetInfo.LaneType.Vehicle | NetInfo.LaneType.Parking | NetInfo.LaneType.CargoVehicle | NetInfo.LaneType.TransportVehicle;
                    if (lht && lane.m_laneType.IsFlagSet(flags))
                    {
                        lane.m_finalDirection = NetInfo.InvertDirection(lane.m_direction);
                    }
                    else
                    {
                        lane.m_finalDirection = lane.m_direction;
                    }
                }
                Swap(ref info.m_hasForwardVehicleLanes, ref info.m_hasBackwardVehicleLanes);
                Swap(ref info.m_forwardVehicleLaneCount, ref info.m_backwardVehicleLaneCount);
            }

            SimulationManager.instance.m_ThreadingWrapper.QueueMainThread(RoadEditorUtils.RefreshRoadEditor);

            for (ushort segmentID = 1; segmentID < NetManager.MAX_SEGMENT_COUNT; ++segmentID)
            {
                if (NetUtil.IsSegmentValid(segmentID))
                {
                    NetManager.instance.UpdateSegment(segmentID);
                }
            }
        }
        // RoadsUnited.RoadColourChanger
        public static void ChangeColorNetExt(float brightness, string Prefab_Class_Name, string TextureDir)
        {
            for (uint i = 0; i < PrefabCollection <NetInfo> .LoadedCount(); i++)
            {
                var netInfo = PrefabCollection <NetInfo> .GetLoaded(i);

                if (netInfo == null)
                {
                    continue;
                }
                if (netInfo.m_class.name.Contains(Prefab_Class_Name))
                {
                    if (netInfo.m_color != null)
                    {
                        netInfo.m_color = new Color(brightness, brightness, brightness);
                    }
                }
            }
        }
Esempio n. 3
0
        public static void UnlockPlaneButton()
        {
            UnlockManager.instance.m_properties.m_SubServiceMilestones[(int)ItemClass.SubService.PublicTransportPlane] = null;

            for (uint i = 0; i < PrefabCollection <BuildingInfo> .LoadedCount(); i++)
            {
                BuildingInfo buildInfo = PrefabCollection <BuildingInfo> .GetLoaded(i);

                if (buildInfo != null)
                {
                    if (buildInfo.m_class.m_subService == ItemClass.SubService.PublicTransportPlane)
                    {
                        buildInfo.m_UnlockMilestone = null;
                    }
                }
            }

            for (uint x = 0; x < PrefabCollection <TransportInfo> .LoadedCount(); x++)
            {
                TransportInfo transportInfo = PrefabCollection <TransportInfo> .GetLoaded(x);

                if (transportInfo != null)
                {
                    if (transportInfo.m_class.m_subService == ItemClass.SubService.PublicTransportPlane)
                    {
                        transportInfo.m_UnlockMilestone = null;
                    }
                }
            }

            for (uint z = 0; z < PrefabCollection <NetInfo> .LoadedCount(); z++)
            {
                NetInfo netInfo = PrefabCollection <NetInfo> .GetLoaded(z);

                if (netInfo != null)
                {
                    if (netInfo.m_class.m_subService == ItemClass.SubService.PublicTransportPlane)
                    {
                        netInfo.m_UnlockMilestone = null;
                    }
                }
            }
        }
        private static void UpdateMetroTrainEffects()
        {
            var vanillaMetro = PrefabCollection <VehicleInfo> .FindLoaded("Metro");

            var arriveEffect = ((MetroTrainAI)vanillaMetro.m_vehicleAI).m_arriveEffect;

            for (uint i = 0; i < PrefabCollection <VehicleInfo> .LoadedCount(); i++)
            {
                try
                {
                    var info = PrefabCollection <VehicleInfo> .GetLoaded(i);

                    var metroTrainAI = info?.m_vehicleAI as MetroTrainAI;
                    if (metroTrainAI == null)
                    {
                        continue;
                    }
                    if (info.m_effects == null || info.m_effects.Length == 0)
                    {
                        info.m_effects = vanillaMetro.m_effects;
                    }
                    else
                    {
                        for (var j = 0; j < info.m_effects.Length; j++)
                        {
                            if (info.m_effects[j].m_effect?.name == "Train Movement")
                            {
                                info.m_effects[j] = vanillaMetro.m_effects[0];
                            }
                        }
                    }
                    var arriveEffectName = metroTrainAI.m_arriveEffect?.name;
                    if (arriveEffectName == null || arriveEffectName == "Transport Arrive")
                    {
                        metroTrainAI.m_arriveEffect = arriveEffect;
                    }
                }
                catch
                {
                    //swallow
                }
            }
        }
        public static void FixMaxTurnAngles()
        {
            int loadedCount = PrefabCollection <NetInfo> .LoadedCount();

            for (uint i = 0; i < loadedCount; ++i)
            {
                try {
                    NetInfo netInfo = PrefabCollection <NetInfo> .GetLoaded(i);

                    if (netInfo == null)
                    {
                        Log.Warning("Bad prefab with null info");
                        continue;
                    }
                    else if (netInfo.m_netAI == null)
                    {
                        Log.Warning("Bad prefab with null info.m_NetAI");
                        continue;
                    }
                    if (netInfo.m_connectGroup == NetInfo.ConnectGroup.None)
                    {
                        continue;
                    }
                    bool hasTracks = false;
                    foreach (var nodeInfo in netInfo.m_nodes)
                    {
                        bool isMedian = DirectConnectUtil.IsMedian(nodeInfo: nodeInfo, netInfo: netInfo);
                        hasTracks = nodeInfo.m_directConnect && !isMedian;
                    }
                    if (!hasTracks)
                    {
                        if (!OriginalTurnAngles.ContainsKey(netInfo))
                        {
                            OriginalTurnAngles[netInfo] = netInfo.m_maxTurnAngle;
                        }
                        netInfo.SetMaxTurnAngle(180);
                    }
                }
                catch (Exception e) {
                    Log.Error(e.ToString());
                }
            } // end for
        }
Esempio n. 6
0
        private void CacheOriginalData()
        {
            originalBuildingData.Clear();

            for (uint index = 0; index < PrefabCollection <BuildingInfo> .LoadedCount(); index++)
            {
                BuildingInfo building = PrefabCollection <BuildingInfo> .GetLoaded(index);

                if (building == null || building.name == null)
                {
                    continue;
                }

                if (!originalBuildingData.TryGetValue(building.name, out CustomizableProperties originalProperties))
                {
                    originalBuildingData.Add(building.name, building.GetOriginalProperties());
                }
            }
        }
Esempio n. 7
0
        /*
         * In here I'm changing the prefabs to have my classes. This way, every time the game instantiates
         * a prefab that I've changed, that object will run my code.
         * The prefabs aren't available at the moment of creation of this class, that's why I keep trying to
         * run it on update. I want to make sure I make the switch as soon as they exist to prevent the game
         * from instantianting objects without my code.
         */
        private bool TryReplacePrefabs()
        {
            Logger.LogInfo("Queueing prefabs for loading...");

            Singleton <LoadingManager> .instance.QueueLoadingAction(ActionWrapper(() =>
            {
                try
                {
                    Logger.LogInfo("Options: " + TrafficMod.Options);

                    if ((TrafficMod.Options & OptionsManager.ModOptions.RoadCustomizerTool) == OptionsManager.ModOptions.RoadCustomizerTool)
                    {
                        AddTool <RoadCustomizerTool>(ToolsModifierControl.toolController);
                    }

                    if ((TrafficMod.Options & OptionsManager.ModOptions.UseRealisticSpeeds) == OptionsManager.ModOptions.UseRealisticSpeeds)
                    {
                        for (uint i = 0; i < PrefabCollection <CitizenInfo> .LoadedCount(); i++)
                        {
                            CitizenInfo cit = PrefabCollection <CitizenInfo> .GetLoaded(i);
                            cit.m_walkSpeed *= 0.25f;
                        }
                    }

                    AddQueuedActionsToLoadingQueue();

                    FileManager.ClearCache();
                }
                catch (KeyNotFoundException knf)
                {
                    Logger.LogInfo("Error initializing a prefab: " + knf.Message + "\n" + knf.StackTrace + "\n");
                }
                catch (Exception e)
                {
                    Logger.LogInfo("Unexpected " + e.GetType().Name + " initializing prefabs: " + e.Message + "\n" + e.StackTrace + "\n");
                }
            }));

            Logger.LogInfo("Prefabs queued for loading.");

            return(true);
        }
Esempio n. 8
0
        public static void ChangeLoadedRoadColor()
        {
            for (uint i = 0; i < PrefabCollection <NetInfo> .LoadedCount(); i++)
            {
                NetInfo asset = PrefabCollection <NetInfo> .GetLoaded(i);

                if (Utils.IsCSUR(asset))
                {
                    Utils.SetColor(asset, roadColor);
                }
                else if (OptionUI.changeAllRoadColor)
                {
                    if (asset != null && asset.m_netAI is RoadAI)
                    {
                        //Debug.Log("Process color change for " + asset.name.ToString());
                        Utils.SetColor(asset, roadColor);
                    }
                }
            }
        }
        public static List <PropInfo> GetAvailableStreetLights()
        {
            var streetLights = new List <PropInfo>();

            var prefabCount = PrefabCollection <PropInfo> .LoadedCount();

            for (uint prefabIndex = 0; prefabIndex < prefabCount; prefabIndex++)
            {
                var prefab = PrefabCollection <PropInfo> .GetLoaded(prefabIndex);

                if (IsStreetLightProp(prefab))
                {
                    streetLights.Add(prefab);
                }
            }

            streetLights.Sort((a, b) => string.Compare(a.GetUncheckedLocalizedTitle(), b.GetUncheckedLocalizedTitle(), StringComparison.Ordinal));

            return(streetLights);
        }
        private List <PropInfo> GetAvailableCatenaries(CatenaryType type)
        {
            var catenaries = new List <PropInfo>();

            var prefabCount = PrefabCollection <PropInfo> .LoadedCount();

            for (uint prefabIndex = 0; prefabIndex < prefabCount; prefabIndex++)
            {
                var prefab = PrefabCollection <PropInfo> .GetLoaded(prefabIndex);

                if (IsCatenaryProp(prefab, type) && CatenaryUtils.IsCatenaryPropVisibeInUI(prefab))
                {
                    catenaries.Add(prefab);
                }
            }

            catenaries.Sort((a, b) => string.Compare(a.GetUncheckedLocalizedTitle(), b.GetUncheckedLocalizedTitle(), StringComparison.Ordinal));

            return(catenaries);
        }
Esempio n. 11
0
        /// <summary>
        /// Unlocks all road types and all intersections
        /// </summary>
        public void Unlock()
        {
            // Normal road types, easy.
            for (int index = 0; index < PrefabCollection <NetInfo> .LoadedCount(); ++index)
            {
                NetInfo loaded = PrefabCollection <NetInfo> .GetLoaded((uint)index);

                if (loaded == null || loaded.m_class == null || loaded.m_class.name == null)
                {
                    continue;
                }

                if (UnlockClass(loaded.m_class))
                {
                    loaded.m_UnlockMilestone = null;
                }
            }

            // Intersections.
            for (int index = 0; index < PrefabCollection <BuildingInfo> .LoadedCount(); ++index)
            {
                BuildingInfo loaded = PrefabCollection <BuildingInfo> .GetLoaded((uint)index);

                if (loaded == null || loaded.m_class == null || loaded.m_class.name == null)
                {
                    continue;
                }

                if (UnlockClass(loaded.m_class))
                {
                    loaded.m_UnlockMilestone = null;

                    var intersectionAI = loaded.m_buildingAI as IntersectionAI;
                    if (intersectionAI != null)
                    {
                        // The cached milestone here is generally the "highest" road type used.
                        Base.SetPrivateVariable <MilestoneInfo>(intersectionAI, "m_cachedUnlockMilestone", null);
                    }
                }
            }
        }
        public void updateCapacity(float targetValue)
        {
            try {
                DormitoryMod seniorCitizenCenterMod = DormitoryMod.getInstance();
                if (seniorCitizenCenterMod == null || seniorCitizenCenterMod.getDormitoryInitializer() == null)
                {
                    Logger.logInfo(Logger.LOG_OPTIONS, "OptionsManager.updateCapacity -- Skipping capacity update because a game is not loaded yet");
                    return;
                }

                DormitoryInitializer dormitoryInitializer = DormitoryMod.getInstance().getDormitoryInitializer();
                if (dormitoryInitializer.getLoadedLevel() != DormitoryInitializer.LOADED_LEVEL_GAME)
                {
                    Logger.logInfo(Logger.LOG_OPTIONS, "OptionsManager.updateCapacity -- Skipping capacity update because a game is not loaded yet");
                    return;
                }
            } catch (Exception e) {
                Logger.logError(Logger.LOG_OPTIONS, "OptionsManager.updateCapacity -- Skipping capacity update because a game is not loaded yet -- Exception: {0}", e.Message);
            }

            Logger.logInfo(Logger.LOG_OPTIONS, "OptionsManager.updateCapacity -- Updating capacity with modifier: {0}", targetValue);
            for (uint index = 0; PrefabCollection <BuildingInfo> .LoadedCount() > index; ++index)
            {
                BuildingInfo buildingInfo = PrefabCollection <BuildingInfo> .GetLoaded(index);

                if (buildingInfo != null && buildingInfo.m_buildingAI is DormitoryAi)
                {
                    ((DormitoryAi)buildingInfo.m_buildingAI).updateCapacity(targetValue);
                }
            }

            BuildingManager buildingManager = Singleton <BuildingManager> .instance;

            for (ushort i = 0; i < buildingManager.m_buildings.m_buffer.Length; i++)
            {
                if (buildingManager.m_buildings.m_buffer[i].Info != null && buildingManager.m_buildings.m_buffer[i].Info.m_buildingAI != null && buildingManager.m_buildings.m_buffer[i].Info.m_buildingAI is DormitoryAi)
                {
                    ((DormitoryAi)buildingManager.m_buildings.m_buffer[i].Info.m_buildingAI).validateCapacity(i, ref buildingManager.m_buildings.m_buffer[i], true);
                }
            }
        }
Esempio n. 13
0
        private static GameObject GetPlayerModelPrefab()
        {
            GameObject citizenPrefabModel = null;

            for (int i = 0; i < PrefabCollection <CitizenInfo> .LoadedCount(); i++)
            {
                if (PrefabCollection <CitizenInfo> .GetLoaded((uint)i).name.ToLower().Contains(CITIZEN_PREFAB_NAME.ToLower()))
                {
                    citizenPrefabModel = PrefabCollection <CitizenInfo> .GetLoaded((uint)i).gameObject;

                    break;
                }
            }

            if (citizenPrefabModel == null)
            {
                Debug.LogError("Coulden't load player model");
            }

            return(citizenPrefabModel);
        }
Esempio n. 14
0
        //Load RICO Settings from asset folders
        public void AssetSettings()
        {
            var checkedPaths = new List <string>();
            var foo          = new Dictionary <string, string>();


            for (uint i = 0; i < PrefabCollection <BuildingInfo> .LoadedCount(); i++)
            {
                var prefab = PrefabCollection <BuildingInfo> .GetLoaded(i);

                if (prefab == null)
                {
                    continue;
                }

                // search for PloppableRICODefinition.xml
                var asset = PackageManager.FindAssetByName(prefab.name);

                if (asset == null || asset.package == null)
                {
                    continue;
                }

                var crpPath = asset.package.packagePath;
                if (crpPath == null)
                {
                    continue;
                }

                var ricoDefPath = Path.Combine(Path.GetDirectoryName(crpPath), "PloppableRICODefinition.xml");

                if (!checkedPaths.Contains(ricoDefPath))
                {
                    checkedPaths.Add(ricoDefPath);
                    foo.Add(asset.package.packageName, ricoDefPath);
                }
            }

            RicoSettings(foo, isAuthored: true);
        }
Esempio n. 15
0
        public static void CacheNever(IEnumerable <string> roads)
        {
            int count = PrefabCollection <NetInfo> .LoadedCount();

            Never_Table = new Hashtable(count * 10);
            for (uint i = 0; i < count; ++i)
            {
                NetInfo info = PrefabCollection <NetInfo> .GetLoaded(i);

                if (IsNormalGroundRoad(info))
                {
                    string name = GetRoadTitle(info);
                    bool   b    = (bool)roads.Contains(name);
                    RoadAI ai   = info.m_netAI as RoadAI;
                    Never_Table[i] = b;
                    Never_Table[ai.m_slopeInfo.m_prefabDataIndex]    = b;
                    Never_Table[ai.m_elevatedInfo.m_prefabDataIndex] = b;
                    Never_Table[ai.m_bridgeInfo.m_prefabDataIndex]   = b;
                    Never_Table[ai.m_tunnelInfo.m_prefabDataIndex]   = b;
                }
            }
        }
Esempio n. 16
0
        public static string[] GetRoadNames()
        {
            List <string> ret = new List <string>();

            for (uint i = 0; i < PrefabCollection <NetInfo> .LoadedCount(); ++i)
            {
                NetInfo info = PrefabCollection <NetInfo> .GetLoaded(i);

                if (IsNormalGroundRoad(info))
                {
                    string name = GetRoadTitle(info);
                    if (name != null && !ret.Contains(name))
                    {
                        ret.Add(name);
                    }
                }
            }
            var ret2 = ret.ToArray();

            Array.Sort(ret2);
            return(ret2);
        }
        private static T[] GetCustomPrefabs <T>()
            where T : PrefabInfo
        {
            var count = PrefabCollection <T> .LoadedCount();

            var result = new List <T>(count);

            for (uint i = 0; i < count; i++)
            {
                var prefab = PrefabCollection <T> .GetPrefab(i);

                if (prefab == null || !prefab.m_isCustomContent && prefab.name?.Contains('.') == false)
                {
                    continue;
                }

                result.Add(prefab);
            }

            result.Sort((x, y) => string.CompareOrdinal(x?.name, y?.name));
            return(result.ToArray());
        }
Esempio n. 18
0
        /// <summary>
        /// Performs task on completion of level loading - recording of school default properties and application of our settings.
        /// Should be called OnLevelLoaded, after prefabs have been loaded but before gameplay commences.
        /// </summary>
        internal void OnLoad()
        {
            // Initialise original properties dictionary.
            originalStats = new Dictionary <string, OriginalSchoolStats>();

            // Iterate through all loaded building prefabs.
            for (uint i = 0; i < PrefabCollection <BuildingInfo> .LoadedCount(); ++i)
            {
                BuildingInfo building = PrefabCollection <BuildingInfo> .GetLoaded(i);

                // Check for schools.
                if (building?.name != null && building.GetAI() is SchoolAI schoolAI && (building.GetClassLevel() == ItemClass.Level.Level1 || building.GetClassLevel() == ItemClass.Level.Level2))
                {
                    // Found a school; add it to our dictionary.
                    originalStats.Add(building.name, new OriginalSchoolStats
                    {
                        jobs0       = schoolAI.m_workPlaceCount0,
                        jobs1       = schoolAI.m_workPlaceCount1,
                        jobs2       = schoolAI.m_workPlaceCount2,
                        jobs3       = schoolAI.m_workPlaceCount3,
                        cost        = schoolAI.m_constructionCost,
                        maintenance = schoolAI.m_maintenanceCost
                    });

                    // If setting is set, get currently active pack and apply it.
                    if (ModSettings.enableSchoolProperties)
                    {
                        ApplyPack(building, ActivePack(building) as SchoolDataPack);

                        // ApplyPack includes a call to UpdateSchoolPrefab, so no need to do it again here.
                        continue;
                    }

                    // Update school record and tooltip.
                    UpdateSchoolPrefab(building, schoolAI);
                }
            }
        }
Esempio n. 19
0
        public static void OverwriteVehicleAI <T_OldAI, T_NewAI>() where T_OldAI : VehicleAI where T_NewAI : VehicleAI
        {
            for (uint i = 0; i < PrefabCollection <VehicleInfo> .LoadedCount(); i++)
            {
                VehicleInfo info;
                info = PrefabCollection <VehicleInfo> .GetLoaded(i);

                if (info == null)
                {
                    continue;
                }
                //Debug.Log(info.gameObject.name);

                T_OldAI oldAI = info.gameObject.GetComponent <T_OldAI>();
                if (oldAI == null)
                {
                    continue;
                }
                if (!oldAI.GetType().Equals(typeof(T_OldAI)))
                {
                    continue;
                }


                T_NewAI newAI = info.gameObject.AddComponent <T_NewAI>();

                ShallowCopy(oldAI, newAI);

                oldAI.ReleaseAI();

                info.m_vehicleAI = newAI;

                UnityEngine.Object.Destroy(oldAI);

                newAI.InitializeAI();
                Debug.Log("VEHICLE AI REPLACED");
            }
        }
        private void clickNoneToVehicle(UIComponent component, UIMouseEventParameter eventParam)
        {
            Dictionary <NetInfo, ushort> ret = new Dictionary <NetInfo, ushort>();
            int numLoaded = PrefabCollection <NetInfo> .LoadedCount();

            for (uint i = 0; i < numLoaded; ++i)
            {
                NetInfo info = PrefabCollection <NetInfo> .GetLoaded(i);

                if (!(info.m_netAI is RoadBaseAI))
                {
                    continue;
                }
                RoadBaseAI ai = (RoadBaseAI)info.m_netAI;
                if (!ai.m_highwayRules)
                {
                    continue;
                }
                NetInfo.Lane[] laneInfos = info.m_lanes;

                for (byte k = 0; k < Math.Min(2, laneInfos.Length); ++k)
                {
                    NetInfo.Lane laneInfo = laneInfos[k];
                    if (laneInfo.m_vehicleType == VehicleInfo.VehicleType.None)
                    {
                        laneInfo.m_vehicleType = VehicleInfo.VehicleType.Car;
                        laneInfo.m_laneType    = NetInfo.LaneType.Vehicle;
                        Log._Debug($"Changing vehicle type of lane {k} @ {info.name} from None to Car, lane type from None to Vehicle");

                        if (!customEmergencyLanes.ContainsKey(info.name))
                        {
                            customEmergencyLanes.Add(info.name, new List <byte>());
                        }
                        customEmergencyLanes[info.name].Add(k);
                    }
                }
            }
        }
Esempio n. 21
0
        public void RemovePillar()
        {
            for (uint num = 0u; num < PrefabCollection <NetInfo> .LoadedCount(); num++)
            {
                NetInfo loaded = PrefabCollection <NetInfo> .GetLoaded(num);

                if (CSURUtil.IsCSUROffset(loaded))
                {
                    var          roadAI     = loaded.m_netAI as RoadAI;
                    RoadBridgeAI elevatedAI = null;
                    if ((loaded.m_netAI is RoadBridgeAI) && (Regex.Match(loaded.name, "Elevated", RegexOptions.IgnoreCase)).Success)
                    {
                        elevatedAI = loaded.m_netAI as RoadBridgeAI;
                    }
                    else
                    {
                        continue;
                    }
                    elevatedAI.m_bridgePillarInfo = null;// PrefabCollection<BuildingInfo>.FindLoaded("CSUR 2DC.Ama S-1_Data");
                    DebugLog.LogToFileOnly("Remove pilla for " + loaded.name.ToString());
                }
            }
        }
Esempio n. 22
0
        public static List <BuildingInfo> GetAllBuildings()
        {
            List <BuildingInfo> buildings = new List <BuildingInfo>();

            for (var x = 0; x < PrefabCollection <BuildingInfo> .LoadedCount(); x++)
            {
                var building = PrefabCollection <BuildingInfo> .GetLoaded((uint)x);

                if (building.m_buildingAI == null)
                {
                    continue;
                }

                if (!building.m_buildingAI.GetType().IsSubclassOf(typeof(PlayerBuildingAI)))
                {
                    continue;
                }

                buildings.Add(building);
            }

            return(buildings);
        }
Esempio n. 23
0
        /// <summary>
        /// Scans prop assets, adding any using the shader to the list.
        /// </summary>
        private static void Add_Props(List <ManagedAsset> list)
        {
            int count = PrefabCollection <PropInfo> .LoadedCount();

            ItemsScanned += count;

            for (uint index = 0; index < count; index++)
            {
                try
                {
                    var prop = PrefabCollection <PropInfo> .GetLoaded(index);

                    if (prop && prop.m_isCustomContent && prop.m_mesh && HasShaderToken(prop.m_mesh.name))
                    {
                        list.Add(new ManagedAsset(prop));
                    }
                }
                catch (Exception error)
                {
                    Debug.LogError($"[AdditiveShader] PropInfo error: \n{error}");
                }
            }
        }
Esempio n. 24
0
        public PrefabInfo Default(PrefabInfo resolve)
        {
            if (!(resolve is NetInfo))
            {
                return(resolve);
            }

            NetInfo info = resolve as NetInfo;

            for (uint i = 0; i < PrefabCollection <NetInfo> .LoadedCount(); i++)
            {
                NetInfo prefab = PrefabCollection <NetInfo> .GetLoaded(i);

                if ((AssetEditorRoadUtils.TryGetBridge(prefab) != null && AssetEditorRoadUtils.TryGetBridge(prefab).name == info.name) ||
                    (AssetEditorRoadUtils.TryGetElevated(prefab) != null && AssetEditorRoadUtils.TryGetElevated(prefab).name == info.name) ||
                    (AssetEditorRoadUtils.TryGetSlope(prefab) != null && AssetEditorRoadUtils.TryGetSlope(prefab).name == info.name) ||
                    (AssetEditorRoadUtils.TryGetTunnel(prefab) != null && AssetEditorRoadUtils.TryGetTunnel(prefab).name == info.name))
                {
                    return(prefab);
                }
            }
            return(info);
        }
Esempio n. 25
0
        public static void AssignServiceClass()
        {
            for (uint i = 0; i < PrefabCollection <BuildingInfo> .LoadedCount(); i++)
            {
                if (PrefabCollection <BuildingInfo> .GetLoaded(i) != null)
                {
                    var prefab = PrefabCollection <BuildingInfo> .GetLoaded(i);

                    //f (prefab.m_isCustomContent)

                    if (prefab.m_buildingAI is PloppableRICO.PloppableExtractor || prefab.m_buildingAI is PloppableRICO.PloppableResidential ||
                        prefab.m_buildingAI is PloppableRICO.PloppableOffice || prefab.m_buildingAI is PloppableRICO.PloppableCommercial ||
                        prefab.m_buildingAI is PloppableRICO.PloppableIndustrial)
                    {
                        // Just assign any RICO prefab a ploppable ItemClass so it will reload. It gets set back once the mod loads.
                        //ConvertPrefabs.InitializePrefab(prefab, ResidentialBuildingAI, ItemClass.ser)
                        //prefab.m_class = ItemClassCollection.FindClass("Beautification Item");
                        //prefab.m_placementStyle = ItemClass.Placement.Automatic;
                        //prefab.InitializePrefab();
                    }
                }
            }
        }
Esempio n. 26
0
        private IEnumerator initDormitories(BuildingInfo buildingToCopyFrom)
        {
            float capcityModifier = DormitoryMod.getInstance().getOptionsManager().getCapacityModifier();
            uint  index           = 0U;

            while (!Singleton <LoadingManager> .instance.m_loadingComplete)
            {
                for (; PrefabCollection <BuildingInfo> .LoadedCount() > index; ++index)
                {
                    BuildingInfo buildingInfo = PrefabCollection <BuildingInfo> .GetLoaded(index);

                    if (buildingInfo != null && buildingInfo.name.EndsWith("_Data") && buildingInfo.name.Contains("NH123"))
                    {
                        this.aiReplacementHelper.replaceBuildingAi <DormitoryAi>(buildingInfo, buildingToCopyFrom);
                    }
                    if (this.loadedLevel == LOADED_LEVEL_GAME && buildingInfo != null && buildingInfo.m_buildingAI is DormitoryAi)
                    {
                        ((DormitoryAi)buildingInfo.m_buildingAI).updateCapacity(capcityModifier);
                    }
                }
                yield return(new WaitForEndOfFrame());
            }
        }
        /// <summary>
        /// Destroys scene prefabs. Unlike DestroyAll(), simulation prefabs are not affected.
        /// </summary>
        public static void DestroyLoaded <P>() where P : PrefabInfo
        {
            try
            {
                int n = PrefabCollection <P> .LoadedCount();

                List <P> prefabs = new List <P>(n);

                for (int i = 0; i < n; i++)
                {
                    P info = PrefabCollection <P> .GetLoaded((uint)i);

                    if (info != null)
                    {
                        info.m_prefabDataIndex = -1; // leave simulation prefabs as they are
                        prefabs.Add(info);
                    }
                }

                PrefabCollection <P> .DestroyPrefabs(string.Empty, prefabs.ToArray(), null);

                // This has not been necessary yet. However, it is quite fatal if prefabs are left behind so better be sure.
                if (n != prefabs.Count)
                {
                    object fastList = Util.GetStatic(typeof(PrefabCollection <P>), "m_scenePrefabs");
                    Util.Set(fastList, "m_size", 0, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
                }

                object dict = Util.GetStatic(typeof(PrefabCollection <P>), "m_prefabDict");
                dict.GetType().GetMethod("Clear", BindingFlags.Instance | BindingFlags.Public).Invoke(dict, null);
                prefabs.Clear(); prefabs.Capacity = 0;
            }
            catch (Exception e)
            {
                UnityEngine.Debug.LogException(e);
            }
        }
Esempio n. 28
0
        /// <summary>
        /// Builds the lists of loaded trees props.  Must be called before use.
        /// </summary>
        internal static void BuildLists()
        {
            // Initialise lists.
            List <PropInfo> props = new List <PropInfo>();
            List <TreeInfo> trees = new List <TreeInfo>();

            // Iterate through all loaded props.
            for (uint i = 0u; i < PrefabCollection <PropInfo> .LoadedCount(); ++i)
            {
                // Get prop and add to our list, if it isn't null.
                PropInfo prop = PrefabCollection <PropInfo> .GetLoaded(i);

                if (prop?.name != null)
                {
                    props.Add(prop);
                }
            }

            // Iterate through all loaded trees.
            for (uint i = 0u; i < PrefabCollection <TreeInfo> .LoadedCount(); ++i)
            {
                // Get tree and add to our list, if it isn't null.
                TreeInfo tree = PrefabCollection <TreeInfo> .GetLoaded(i);

                if (tree?.name != null)
                {
                    trees.Add(tree);
                }
            }

            randomProps = new List <PropInfo>();
            randomTrees = new List <TreeInfo>();

            // Order lists by name.
            loadedProps = props.OrderBy(prop => GetDisplayName(prop.name)).ToList().ToArray();
            loadedTrees = trees.OrderBy(tree => GetDisplayName(tree.name)).ToList().ToArray();
        }
Esempio n. 29
0
        public static void FindProps()
        {
            // Get replacement prop name mapping
            Dictionary <string, string> propsToLoad = new Dictionary <string, string>(PropConsts.AMERICAN_ROAD_PROPS);

            for (int i = 0; i < PrefabCollection <PropInfo> .LoadedCount(); i++)
            {
                string propName = PrefabCollection <PropInfo> .GetLoaded((uint)i).name.ToLower();

                // Check to see if the prop has been found
                for (int j = 0; j < propsToLoad.Count; j++)
                {
                    var propToLoad = propsToLoad.ElementAt(j);
                    if (propName.Contains(propToLoad.Value))
                    {
                        propReplacementDict[propToLoad.Key] = PrefabCollection <PropInfo> .GetLoaded((uint)i);

                        propsToLoad.Remove(propToLoad.Key);
                        if (config.enable_debug)
                        {
                            DebugUtils.Log(String.Format("{0} found", propToLoad.Value));
                        }
                    }
                }
            }
            if (propsToLoad.Count == 0)
            {
                DebugUtils.Log("All custom props found.");
            }
            else
            {
                foreach (var unloadedProps in propsToLoad)
                {
                    DebugUtils.Log(string.Format("Prop {0} not found!", unloadedProps.Value));
                }
            }
        }
Esempio n. 30
0
        public override void OnLevelLoaded(LoadMode mode)
        {
            if (mode != LoadMode.NewGame && mode != LoadMode.LoadGame)
            {
                return;
            }
            try {
                inGame = true;
                var loadedBuildingInfoCount = PrefabCollection <BuildingInfo> .LoadedCount();

                for (uint i = 0; i < loadedBuildingInfoCount; i++)
                {
                    var bi = PrefabCollection <BuildingInfo> .GetLoaded(i);

                    if (bi is null)
                    {
                        continue;
                    }
                    if (bi.name.Equals("Fish Market 01"))
                    {
                        LogHelper.Information(bi.name);
                        AIHelper.ApplyNewAIToBuilding(bi);
                    }
                    else if (bi.name.Contains("Extractor") && bi.m_class.m_service.Equals("Fishing"))
                    {
                        LogHelper.Information(bi.name);
                        AIHelper.ApplyNewAIToBuilding(bi);
                    }
                }
                LogHelper.Information("Reloaded Mod");
            }
            catch (Exception e) {
                LogHelper.Information(e.ToString());
                Deinit();
            }
        }