private static ushort GetBufferStatus(ushort vehicleID, ref Vehicle data)
        {
            ushort transferSize = data.m_transferSize;

            if ((int)data.m_leadingVehicle == 0)
            {
                VehicleManager instance        = Singleton <VehicleManager> .instance;
                ushort         trailingVehicle = data.m_trailingVehicle;
                int            num             = 0;
                while ((int)trailingVehicle != 0)
                {
                    VehicleInfo info = instance.m_vehicles.m_buffer[(int)trailingVehicle].Info;
                    if ((int)instance.m_vehicles.m_buffer[(int)trailingVehicle].m_leadingVehicle != 0)
                    {
                        ushort bufferStatus = PassengerTrainAIMod.GetBufferStatus(trailingVehicle, ref instance.m_vehicles.m_buffer[(int)trailingVehicle]);
                        transferSize += bufferStatus;
                    }
                    trailingVehicle = instance.m_vehicles.m_buffer[(int)trailingVehicle].m_trailingVehicle;
                    if (++num > 16384)
                    {
                        CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + System.Environment.StackTrace);

                        break;
                    }
                }
            }
            return(transferSize);
        }
 public void OnLevelLoaded(LoadMode mode)
 {
     this._loadMode = mode;
     if (mode != LoadMode.LoadGame && mode != LoadMode.NewGame)
     {
         return;
     }
     try
     {
         Utils.Log((object)"Begin init version: 3.8.10");
         ImprovedPublicTransportMod.Settings.LogSettings();
         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 <VehicleEditor>();
             this._iptGameObject.AddComponent <PanelExtenderLine>();
             this._iptGameObject.AddComponent <PanelExtenderVehicle>();
             this._iptGameObject.AddComponent <PanelExtenderCityService>();
             this._iptGameObject.AddComponent <SimHelper>();
             this._iptGameObject.AddComponent <LineWatcher>();
             this._worldInfoPanel = new GameObject("PublicTransportStopWorldInfoPanel");
             this._worldInfoPanel.transform.parent = objectOfType.transform;
             this._worldInfoPanel.AddComponent <PublicTransportStopWorldInfoPanel>().Show();
             NetManagerMod.Init();
             VehicleManagerMod.Init();
             BusAIMod.Init();
             PassengerTrainAIMod.Init();
             PassengerShipAIMod.Init();
             PassengerPlaneAIMod.Init();
             TramAIMod.Init();
             BuildingWatcher.instance.Init();
             LineWatcher.instance.Init();
             TransportLineMod.Init();
             VehiclePrefabs.Init();
             SerializableDataExtension.instance.Loaded = true;
             LocaleModifier.Init();
             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();
     }
 }
        private void UnloadPassengers(ushort vehicleID, ref Vehicle data, ushort currentStop, ushort nextStop)
        {
            if ((int)currentStop == 0)
            {
                return;
            }
            VehicleManager   instance1 = Singleton <VehicleManager> .instance;
            NetManager       instance2 = Singleton <NetManager> .instance;
            TransportManager instance3 = Singleton <TransportManager> .instance;
            Vector3          position  = instance2.m_nodes.m_buffer[(int)currentStop].m_position;
            Vector3          targetPos = Vector3.zero;

            if ((int)nextStop != 0)
            {
                targetPos = instance2.m_nodes.m_buffer[(int)nextStop].m_position;
            }
            int    serviceCounter = 0;
            int    num1           = 0;
            ushort vehicleID1     = vehicleID;
            ushort bufferStatus   = PassengerTrainAIMod.GetBufferStatus(vehicleID1, ref instance1.m_vehicles.m_buffer[(int)vehicleID1]);

            while ((int)vehicleID != 0)
            {
                if ((int)data.m_transportLine != 0)
                {
                    BusAI.TransportArriveAtTarget(vehicleID, ref instance1.m_vehicles.m_buffer[(int)vehicleID], position, targetPos, ref serviceCounter, ref instance3.m_lines.m_buffer[(int)data.m_transportLine].m_passengers, (int)nextStop == 0);
                }
                else
                {
                    BusAI.TransportArriveAtTarget(vehicleID, ref instance1.m_vehicles.m_buffer[(int)vehicleID], position, targetPos, ref serviceCounter, ref instance3.m_passengers[(int)this.m_transportInfo.m_transportType], (int)nextStop == 0);
                }
                vehicleID = instance1.m_vehicles.m_buffer[(int)vehicleID].m_trailingVehicle;
                if (++num1 > 16384)
                {
                    CODebugBase <LogChannel> .Error(LogChannel.Core, "Invalid list detected!\n" + System.Environment.StackTrace);

                    break;
                }
            }
            Singleton <StatisticsManager> .instance.Acquire <StatisticArray>(StatisticType.PassengerCount).Acquire <StatisticInt32>((int)this.m_transportInfo.m_transportType, 8).Add(serviceCounter);

            serviceCounter += (int)instance2.m_nodes.m_buffer[(int)currentStop].m_tempCounter;
            instance2.m_nodes.m_buffer[(int)currentStop].m_tempCounter = (ushort)Mathf.Min(serviceCounter, (int)ushort.MaxValue);
            ushort num2 = (ushort)((uint)bufferStatus - (uint)PassengerTrainAIMod.GetBufferStatus(vehicleID1, ref instance1.m_vehicles.m_buffer[(int)vehicleID1]));

            VehicleManagerMod.m_cachedVehicleData[(int)vehicleID1].LastStopGonePassengers = (int)num2;
            VehicleManagerMod.m_cachedVehicleData[(int)vehicleID1].CurrentStop            = currentStop;
            NetManagerMod.m_cachedNodeData[(int)currentStop].PassengersOut += (int)num2;
        }
 private void Deinit()
 {
     TramAIMod.Deinit();
     PassengerTrainAIMod.Deinit();
     PassengerShipAIMod.Deinit();
     PassengerPlaneAIMod.Deinit();
     BusAIMod.Deinit();
     TransportLineMod.Deinit();
     BuildingWatcher.instance.Deinit();
     NetManagerMod.Deinit();
     VehicleManagerMod.Deinit();
     VehiclePrefabs.Deinit();
     SerializableDataExtension.instance.Loaded = false;
     LocaleModifier.Deinit();
     if ((UnityEngine.Object) this._iptGameObject != (UnityEngine.Object)null)
     {
         UnityEngine.Object.Destroy((UnityEngine.Object) this._iptGameObject);
     }
     if (!((UnityEngine.Object) this._worldInfoPanel != (UnityEngine.Object)null))
     {
         return;
     }
     UnityEngine.Object.Destroy((UnityEngine.Object) this._worldInfoPanel);
 }