Esempio n. 1
0
        public static void Init()
        {
            if (Utils.IsModActive(1764208250))
            {
                UnityEngine.Debug.LogWarning("More Vehicles is enabled, applying compatibility workaround");
                MaxVehicleCount = ushort.MaxValue + 1;
            }
            else
            {
                UnityEngine.Debug.Log("More Vehicles is not enabled");
                MaxVehicleCount = VehicleManager.MAX_VEHICLE_COUNT;
            }

            if (CachedVehicleData._isDeployed)
            {
                return;
            }
            if (!CachedVehicleData.TryLoadData(out CachedVehicleData.m_cachedVehicleData))
            {
                Utils.Log((object)"Loading default vehicle data.");
            }

            SerializableDataExtension.instance.EventSaveData += new SerializableDataExtension.SaveDataEventHandler(CachedVehicleData.OnSaveData);
            CachedVehicleData._isDeployed = true;
        }
Esempio n. 2
0
 private void LoadPrefabData()
 {
     try
     {
         string str = "IptVehicleData";
         if (!Directory.Exists(str))
         {
             Directory.CreateDirectory(str);
         }
         string path2 = Utils.RemoveInvalidFileNameChars(this.ObjectName + ".xml");
         string path  = System.IO.Path.Combine(str, path2);
         if (!File.Exists(path))
         {
             Utils.Log((object)("No stored data found for " + this.ObjectName));
         }
         else
         {
             Utils.Log((object)("Found stored data for " + this.ObjectName));
             using (StreamReader streamReader = new StreamReader(path))
             {
                 PrefabData.DefaultPrefabData defaultPrefabData = (PrefabData.DefaultPrefabData) new XmlSerializer(typeof(PrefabData.DefaultPrefabData)).Deserialize((TextReader)streamReader);
                 this.Capacity         = defaultPrefabData.Capacity;
                 this.MaintenanceCost  = defaultPrefabData.MaintenanceCost;
                 this.MaxSpeed         = defaultPrefabData.MaxSpeed;
                 this.EngineOnBothEnds = defaultPrefabData.EngineOnBothEnds;
                 this._changeFlag      = false;
             }
         }
     }
     catch (Exception ex)
     {
         Utils.LogError((object)(ex.Message + System.Environment.NewLine + ex.StackTrace));
     }
 }
 public override void OnLevelUnloading()
 {
     base.OnLevelUnloading();
     if (!inGame)
     {
         return;
     }
     inGame = false;
     this.Deinit();
     Utils.Log((object)("Unloading done!" + System.Environment.NewLine));
 }
Esempio n. 4
0
        public PrefabData(VehicleInfo info)
        {
            this._info = info;
            Utils.Log((object)("Creating PrefabData for " + this.ObjectName));
            if (this.ObjectName == "451494281.London 1992 Stock (4 car)_Data")
            {
                int length = 3;
                this._info.m_trailers = new VehicleInfo.VehicleTrailer[length];
                for (int index = 0; index < length; ++index)
                {
                    this._info.m_trailers[index].m_info = this._info;
                    this._info.m_trailers[index].m_invertProbability = 50;
                    this._info.m_trailers[index].m_probability       = 100;
                }
            }
            else if (this.ObjectName.Contains("D3S Solaris Urbino 24 '15") && this._info.m_trailers != null && this._info.m_trailers.Length != 0)
            {
                this._info.m_dampers = 0.6f;
                VehicleInfo loaded = PrefabCollection <VehicleInfo> .FindLoaded(this.ObjectName.Substring(0, this.ObjectName.IndexOf(".")) + ".D3S Solaris Urbino 24 '15 (II)_Data");

                if ((UnityEngine.Object)loaded != (UnityEngine.Object)null)
                {
                    Utils.Log((object)("Fixing " + this.ObjectName));
                    this._info.m_trailers[0].m_info.m_dampers = 0.6f;
                    loaded.m_attachOffsetFront      = 1.07f;
                    loaded.m_dampers                = 0.6f;
                    this._info.m_trailers[1].m_info = loaded;
                    this._info.m_trailers[1].m_invertProbability = 0;
                    this._info.m_trailers[1].m_probability       = 100;
                    this.ApplyBackEngine(loaded, 0);
                }
            }
            if (this._info.m_trailers != null)
            {
                int length = this._info.m_trailers.Length;
                if (length > 0)
                {
                    this._lastTrailer = this._info.m_trailers[length - 1];
                    this._trailerData = new PrefabData[length];
                    for (int index = 0; index < length; ++index)
                    {
                        VehicleInfo info1 = this._info.m_trailers[index].m_info;
                        if ((UnityEngine.Object)info1 != (UnityEngine.Object)null)
                        {
                            this._trailerData[index] = PrefabData.CreateTrailerData(info1);
                        }
                    }
                }
            }
            this.CacheDefaults();
            this.LoadPrefabData();
        }
Esempio n. 5
0
        public static bool TryLoadData(out VehicleData[] data)
        {
            data = new VehicleData[CachedVehicleData.MaxVehicleCount];
            byte[] data1 = SerializableDataExtension.instance.SerializableData.LoadData(CachedVehicleData._dataID);
            if (data1 == null)
            {
                return(false);
            }
            int    index1 = 0;
            string empty  = string.Empty;

            try
            {
                Utils.Log((object)"Try to load vehicle data.");
                string str = SerializableDataExtension.ReadString(data1, ref index1);
                if (string.IsNullOrEmpty(str) || str.Length != 4)
                {
                    Utils.LogWarning((object)"Unknown data found.");
                    return(false);
                }
                Utils.Log((object)("Found vehicle data version: " + str));
                while (index1 < Math.Min(data1.Length, CachedVehicleData.MaxVehicleCount))
                {
                    int index2 = SerializableDataExtension.ReadInt32(data1, ref index1);
                    if (str == "v001")
                    {
                        int num = (int)SerializableDataExtension.ReadByte(data1, ref index1);
                    }
                    data[index2].LastStopNewPassengers  = SerializableDataExtension.ReadInt32(data1, ref index1);
                    data[index2].LastStopGonePassengers = SerializableDataExtension.ReadInt32(data1, ref index1);
                    data[index2].PassengersThisWeek     = SerializableDataExtension.ReadInt32(data1, ref index1);
                    data[index2].PassengersLastWeek     = SerializableDataExtension.ReadInt32(data1, ref index1);
                    data[index2].IncomeThisWeek         = SerializableDataExtension.ReadInt32(data1, ref index1);
                    data[index2].IncomeLastWeek         = SerializableDataExtension.ReadInt32(data1, ref index1);
                    data[index2].PassengerData          = SerializableDataExtension.ReadFloatArray(data1, ref index1);
                    data[index2].IncomeData             = SerializableDataExtension.ReadFloatArray(data1, ref index1);
                    if (str != "v001" && str != "v002")
                    {
                        data[index2].CurrentStop = SerializableDataExtension.ReadUInt16(data1, ref index1);
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                Utils.LogWarning((object)("Could not load vehicle data. " + ex.Message));
                data = new VehicleData[CachedVehicleData.MaxVehicleCount];
                return(false);
            }
        }
        public static void Init(int maxVehicleCount)
        {
            MaxVehicleCount = maxVehicleCount;
            if (CachedVehicleData._isDeployed)
            {
                return;
            }
            if (!CachedVehicleData.TryLoadData(out CachedVehicleData.m_cachedVehicleData))
            {
                Utils.Log((object)"Loading default vehicle data.");
            }

            SerializableDataExtension.instance.EventSaveData += new SerializableDataExtension.SaveDataEventHandler(CachedVehicleData.OnSaveData);
            CachedVehicleData._isDeployed = true;
        }
        private void ReleaseUnusedCitizenUnits()
        {
            Utils.Log((object)"Find and clear unused citizen units.");
            CitizenManager instance = Singleton <CitizenManager> .instance;
            int            num      = 0;

            for (int index = 0; index < instance.m_units.m_buffer.Length; ++index)
            {
                CitizenUnit citizenUnit = instance.m_units.m_buffer[index];
                if (citizenUnit.m_flags != CitizenUnit.Flags.None && (int)citizenUnit.m_building == 0 && ((int)citizenUnit.m_vehicle == 0 && (int)citizenUnit.m_goods == 0))
                {
                    ++num;
                    instance.m_units.m_buffer[index] = new CitizenUnit();
                    instance.m_units.ReleaseItem((uint)index);
                    Utils.LogToTxt((object)string.Format("CitizenUnit #{0} - Flags: {1} - Citizens: #{2} | #{3} | #{4} | #{5} | #{6}", (object)index, (object)citizenUnit.m_flags, (object)citizenUnit.m_citizen0, (object)citizenUnit.m_citizen1, (object)citizenUnit.m_citizen2, (object)citizenUnit.m_citizen3, (object)citizenUnit.m_citizen4));
                }
            }
            Utils.Log((object)("Cleared " + (object)num + " unused citizen units."));
        }
        public override void OnLevelLoaded(LoadMode mode)
        {
            base.OnLevelLoaded(mode);
            if (mode != LoadMode.LoadGame && mode != LoadMode.NewGame && mode != LoadMode.NewGameFromScenario)
            {
                return;
            }
            inGame = true;
            try
            {
                Utils.Log((object)$"Begin init version: {version}");
                this.ReleaseUnusedCitizenUnits();
                UIView objectOfType = UnityEngine.Object.FindObjectOfType <UIView>();
                if ((UnityEngine.Object)objectOfType != (UnityEngine.Object)null)
                {
                    this._iptGameObject = new GameObject("IptGameObject");
                    this._iptGameObject.transform.parent = objectOfType.transform;
                    this._iptGameObject.AddComponent <SimHelper>();
                    this._iptGameObject.AddComponent <LineWatcher>();
                    this._worldInfoPanel = new GameObject("PublicTransportStopWorldInfoPanel");
                    this._worldInfoPanel.transform.parent = objectOfType.transform;
                    this._worldInfoPanel.AddComponent <PublicTransportStopWorldInfoPanel>();

                    CachedNodeData.Init();

                    Patch(typeof(DepotAI), nameof(DepotAI.StartTransfer), DepotAIPatch.GetPrefix(), null);

                    Patch(typeof(NetManager), nameof(NetManager.ReleaseNode), null,
                          typeof(NetManagerPatch).GetMethod(nameof(NetManagerPatch.ReleaseNode))); //TODO: think, whether it should be pre or post

                    CachedVehicleData.Init();
                    Patch(typeof(VehicleManager), "ReleaseWaterSource", null,
                          typeof(VehicleManagerPatch).GetMethod(nameof(VehicleManagerPatch.ReleaseWaterSource))); //TODO: think, whether it should be pre or post

                    Redirector <BusAIDetour> .Deploy();

                    PatchCountPassengers(typeof(BusAI));

                    Redirector <TrolleybusAIDetour> .Deploy();

                    PatchCountPassengers(typeof(TrolleybusAI));

                    Redirector <PassengerTrainAIDetour> .Deploy();

                    PatchCountPassengers(typeof(PassengerTrainAI));

                    Redirector <PassengerShipAIDetour> .Deploy();

                    PatchCountPassengers(typeof(PassengerShipAI));

                    Redirector <PassengerPlaneAIDetour> .Deploy();

                    PatchCountPassengers(typeof(PassengerPlaneAI));

                    Redirector <PassengerFerryAIDetour> .Deploy();

                    PatchCountPassengers(typeof(PassengerFerryAI));

                    Redirector <PassengerBlimpAIDetour> .Deploy();

                    PatchCountPassengers(typeof(PassengerBlimpAI));

                    Redirector <PassengerHelicopterAIDetour> .Deploy();

                    PatchCountPassengers(typeof(PassengerHelicopterAI));

                    Redirector <TramAIDetour> .Deploy();

                    PatchCountPassengers(typeof(TramAI));

                    Redirector <CommonBuildingAIReverseDetour> .Deploy();

                    Redirector <PublicTransportStopButtonDetour> .Deploy();

                    Redirector <PublicTransportVehicleButtonDetour> .Deploy();

                    Redirector <PublicTransportWorldInfoPanelDetour> .Deploy();

                    BuildingExtension.Init();
                    LineWatcher.instance.Init();

                    CachedTransportLineData.Init();
                    Redirector <TransportLineDetour> .Deploy();

                    VehiclePrefabs.Init();
                    SerializableDataExtension.instance.Loaded = true;
                    LocaleModifier.Init();
                    this._iptGameObject.AddComponent <VehicleEditor>();
                    this._iptGameObject.AddComponent <PanelExtenderLine>();
                    this._iptGameObject.AddComponent <PanelExtenderVehicle>();
                    this._iptGameObject.AddComponent <PanelExtenderCityService>();
                    Utils.Log((object)"Loading done!");
                }
                else
                {
                    Utils.LogError((object)"UIView not found, aborting!");
                }
            }
            catch (Exception ex)
            {
                Utils.LogError((object)("Error during initialization, IPT disables itself." + System.Environment.NewLine + "Please try again without any other mod." + System.Environment.NewLine + "Please upload your log file and post the link here if that didn't help:" + System.Environment.NewLine + "http://steamcommunity.com/workshop/filedetails/discussion/424106600/615086038663282271/" + System.Environment.NewLine + ex.Message + System.Environment.NewLine + (object)ex.InnerException + System.Environment.NewLine + ex.StackTrace));
                this.Deinit();
            }
        }
Esempio n. 9
0
        public override void OnLevelLoaded(LoadMode mode)
        {
            base.OnLevelLoaded(mode);
            if (mode != LoadMode.LoadGame && mode != LoadMode.NewGame && mode != LoadMode.NewGameFromScenario)
            {
                return;
            }
            inGame = true;
            try
            {
                Utils.Log((object)$"IPT2: Begin init version: {version}");
                this.ReleaseUnusedCitizenUnits();
                UIView objectOfType = UnityEngine.Object.FindObjectOfType <UIView>();
                if ((UnityEngine.Object)objectOfType != (UnityEngine.Object)null)
                {
                    this._iptGameObject = new GameObject("IptGameObject");
                    this._iptGameObject.transform.parent = objectOfType.transform;
                    this._iptGameObject.AddComponent <SimHelper>();
                    this._iptGameObject.AddComponent <LineWatcher>();
                    this._worldInfoPanel = new GameObject("PublicTransportStopWorldInfoPanel");
                    this._worldInfoPanel.transform.parent = objectOfType.transform;
                    this._worldInfoPanel.AddComponent <PublicTransportStopWorldInfoPanel>();

                    CachedNodeData.Init();

                    int maxVehicleCount;
                    if (Utils.IsModActive(1764208250))
                    {
                        UnityEngine.Debug.LogWarning("IPT2: More Vehicles is enabled, applying compatibility workaround");
                        maxVehicleCount = ushort.MaxValue + 1;
                    }
                    else
                    {
                        UnityEngine.Debug.Log("IPT2: More Vehicles is not enabled");
                        maxVehicleCount = VehicleManager.MAX_VEHICLE_COUNT;
                    }

                    CachedVehicleData.Init(maxVehicleCount);

                    LoadPassengersPatch.Apply();
                    UnloadPassengersPatch.Apply();
                    DepotAIPatch.Apply();
                    NetManagerPatch.Apply();
                    VehicleManagerPatch.Apply();
                    PublicTransportLineVehicleModelSelectorRefreshPatch.Apply();

                    Redirector <BusAIDetour> .Deploy();

                    Redirector <TrolleybusAIDetour> .Deploy();

                    Redirector <PassengerTrainAIDetour> .Deploy();

                    Redirector <PassengerShipAIDetour> .Deploy();

                    Redirector <PassengerPlaneAIDetour> .Deploy();

                    Redirector <PassengerFerryAIDetour> .Deploy();

                    Redirector <PassengerBlimpAIDetour> .Deploy();

                    Redirector <PassengerHelicopterAIDetour> .Deploy();

                    Redirector <TramAIDetour> .Deploy();

                    Redirector <CommonBuildingAIReverseDetour> .Deploy();

                    Redirector <PublicTransportStopButtonDetour> .Deploy();

                    Redirector <PublicTransportVehicleButtonDetour> .Deploy();

                    Redirector <PublicTransportWorldInfoPanelDetour> .Deploy();

                    BuildingExtension.Init();
                    LineWatcher.instance.Init();

                    CachedTransportLineData.Init();
                    Redirector <TransportLineDetour> .Deploy();

                    TransportLineSimulationStepPatch.Apply();
                    TransportLineGetLineVehiclePatch.Apply();

                    VehiclePrefabs.Init();
                    SerializableDataExtension.instance.Loaded = true;
                    LocaleModifier.Init();
                    this._iptGameObject.AddComponent <VehicleEditor>();
                    this._iptGameObject.AddComponent <PanelExtenderLine>();
                    this._iptGameObject.AddComponent <PanelExtenderVehicle>();
                    this._iptGameObject.AddComponent <PanelExtenderCityService>();
                    Utils.Log((object)"Loading done!");
                }
                else
                {
                    Utils.LogError((object)"UIView not found, aborting!");
                }
            }
            catch (Exception ex)
            {
                Utils.LogError((object)("IPT2: Error during initialization, IPT disables itself." + System.Environment.NewLine + "Please try again without any other mod." + System.Environment.NewLine + "Please upload your log file and post the link here if that didn't help:" + System.Environment.NewLine + "http://steamcommunity.com/workshop/filedetails/discussion/424106600/615086038663282271/" + System.Environment.NewLine + ex.Message + System.Environment.NewLine + (object)ex.InnerException + System.Environment.NewLine + ex.StackTrace));
                this.Deinit();
            }
        }