Ejemplo n.º 1
0
        private static void OnSaveData()
        {
            FastList <byte> data = new FastList <byte>();

            try
            {
                SerializableDataExtension.WriteString(CachedVehicleData._dataVersion, data);
                for (int index = 0; index < CachedVehicleData.MaxVehicleCount; ++index)
                {
                    if (!CachedVehicleData.m_cachedVehicleData[index].IsEmpty)
                    {
                        SerializableDataExtension.WriteInt32(index, data);
                        SerializableDataExtension.WriteInt32(CachedVehicleData.m_cachedVehicleData[index].LastStopNewPassengers, data);
                        SerializableDataExtension.WriteInt32(CachedVehicleData.m_cachedVehicleData[index].LastStopGonePassengers, data);
                        SerializableDataExtension.WriteInt32(CachedVehicleData.m_cachedVehicleData[index].PassengersThisWeek, data);
                        SerializableDataExtension.WriteInt32(CachedVehicleData.m_cachedVehicleData[index].PassengersLastWeek, data);
                        SerializableDataExtension.WriteInt32(CachedVehicleData.m_cachedVehicleData[index].IncomeThisWeek, data);
                        SerializableDataExtension.WriteInt32(CachedVehicleData.m_cachedVehicleData[index].IncomeLastWeek, data);
                        SerializableDataExtension.WriteFloatArray(CachedVehicleData.m_cachedVehicleData[index].PassengerData, data);
                        SerializableDataExtension.WriteFloatArray(CachedVehicleData.m_cachedVehicleData[index].IncomeData, data);
                        SerializableDataExtension.WriteUInt16(CachedVehicleData.m_cachedVehicleData[index].CurrentStop, data);
                    }
                }
                SerializableDataExtension.instance.SerializableData.SaveData(CachedVehicleData._dataID, data.ToArray());
            }
            catch (Exception ex)
            {
                Utils.LogError((object)("Error while saving vehicle data! " + ex.Message + " " + (object)ex.InnerException));
            }
        }
Ejemplo n.º 2
0
 private void SavePrefabData()
 {
     if (!this._saveToXml)
     {
         return;
     }
     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);
         PrefabData.DefaultPrefabData defaultPrefabData = new PrefabData.DefaultPrefabData();
         defaultPrefabData.Capacity         = this.Capacity;
         defaultPrefabData.MaintenanceCost  = this.MaintenanceCost;
         defaultPrefabData.MaxSpeed         = this.MaxSpeed;
         defaultPrefabData.EngineOnBothEnds = this.EngineOnBothEnds;
         using (StreamWriter streamWriter = new StreamWriter(path))
             new XmlSerializer(typeof(PrefabData.DefaultPrefabData)).Serialize((TextWriter)streamWriter, (object)defaultPrefabData);
     }
     catch (Exception ex)
     {
         Utils.LogError((object)(ex.Message + System.Environment.NewLine + ex.StackTrace));
     }
 }
Ejemplo n.º 3
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 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();
            }
        }
Ejemplo n.º 5
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();
            }
        }