public static bool TryLoadData(out VehicleData[] data)
        {
            data = new VehicleData[16384];
            byte[] data1 = SerializableDataExtension.instance.SerializableData.LoadData(VehicleManagerMod._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 < data1.Length)
                {
                    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[16384];
                return(false);
            }
        }
        public static bool TryLoadData(out NodeData[] data)
        {
            data = new NodeData[32768];
            byte[] data1 = SerializableDataExtension.instance.SerializableData.LoadData(NetManagerMod._dataID);
            if (data1 == null)
            {
                return(false);
            }
            int    index1 = 0;
            string empty  = string.Empty;

            try
            {
                Utils.Log((object)"Try to load net node 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 net node data version: " + str));
                while (index1 < data1.Length)
                {
                    int index2 = SerializableDataExtension.ReadInt32(data1, ref index1);
                    if (str == "v001")
                    {
                        double num = (double)SerializableDataExtension.ReadFloat(data1, ref index1);
                    }
                    data[index2].PassengersIn          = SerializableDataExtension.ReadInt32(data1, ref index1);
                    data[index2].PassengersOut         = SerializableDataExtension.ReadInt32(data1, ref index1);
                    data[index2].LastWeekPassengersIn  = SerializableDataExtension.ReadInt32(data1, ref index1);
                    data[index2].LastWeekPassengersOut = SerializableDataExtension.ReadInt32(data1, ref index1);
                    data[index2].PassengerInData       = SerializableDataExtension.ReadFloatArray(data1, ref index1);
                    data[index2].PassengerOutData      = SerializableDataExtension.ReadFloatArray(data1, ref index1);
                    data[index2].Unbunching            = str == "v001" || str == "v002" || SerializableDataExtension.ReadBool(data1, ref index1);
                }
                return(true);
            }
            catch (Exception ex)
            {
                Utils.LogWarning((object)("Could not load net node data. " + ex.Message));
                data = new NodeData[32768];
                return(false);
            }
        }
Пример #3
0
        private static bool TryLoadData1(int version, ref Dictionary <ushort, OutsideConnectionSettings> settingsDict, ref byte[] buffer, ref int index)
        {
            var length = SerializableDataExtension.ReadInt32(buffer, ref index);

            for (int i = 0; i < length; ++i)
            {
                var curElementLength = SerializableDataExtension.ReadInt32(buffer, ref index);
                var indexBegin       = index;

                var settings   = new OutsideConnectionSettings();
                var buildingID = SerializableDataExtension.ReadUInt16(buffer, ref index);
                settings.NameMode             = (OutsideConnectionSettings.NameModeType)SerializableDataExtension.ReadUInt16(buffer, ref index);
                settings.SingleGenerationName = SerializableDataExtension.ReadString(buffer, ref index);

                var strCount = SerializableDataExtension.ReadUInt16(buffer, ref index);
                for (int j = 0; j < strCount; ++j)
                {
                    settings.RandomGenerationNames.Add(SerializableDataExtension.ReadString(buffer, ref index));
                }

                settings.CurrentDirectionFlags = (Building.Flags)SerializableDataExtension.ReadUInt16(buffer, ref index) & Building.Flags.IncomingOutgoing;
                settings.Name = SerializableDataExtension.ReadString(buffer, ref index);

                var flags = Utils.QueryBuilding(buildingID).m_flags;
                settings.OriginalDirectionFlags = flags & Building.Flags.IncomingOutgoing;
                flags &= (~Building.Flags.IncomingOutgoing) | settings.CurrentDirectionFlags;
                BuildingManager.instance.m_buildings.m_buffer[buildingID].m_flags = flags;

                if (2 <= version)
                {
                    settings.DummyTrafficFactor = SerializableDataExtension.ReadInt32(buffer, ref index);
                }

                if (3 <= version)
                {
                    // even if length is not equal 3, the data must be read from buffer
                    var touristFactorLength = SerializableDataExtension.ReadUInt16(buffer, ref index);
                    var factors             = new int[touristFactorLength];
                    for (ushort k = 0; k < touristFactorLength; ++k)
                    {
                        factors[k] = SerializableDataExtension.ReadInt32(buffer, ref index);
                    }
                    settings.TouristFactors = factors;
                }

                if (4 <= version)
                {
                    var ratioLength = SerializableDataExtension.ReadUInt16(buffer, ref index);
                    var ratios      = new int[ratioLength];
                    for (ushort k = 0; k < ratioLength; ++k)
                    {
                        ratios[k] = SerializableDataExtension.ReadInt32(buffer, ref index);
                    }
                    settings.ImportResourceRatio = ratios;

                    ratioLength = SerializableDataExtension.ReadUInt16(buffer, ref index);
                    ratios      = new int[ratioLength];
                    for (ushort k = 0; k < ratioLength; ++k)
                    {
                        ratios[k] = SerializableDataExtension.ReadInt32(buffer, ref index);
                    }
                    settings.ExportResourceRatio = ratios;
                }

                if (5 <= version)
                {
                    settings.CargoCapacity    = SerializableDataExtension.ReadInt32(buffer, ref index);
                    settings.ResidentCapacity = SerializableDataExtension.ReadInt32(buffer, ref index);
                }

                ValidateOutsideConnectionSettings(buildingID, ref settings);

                if (settingsDict.ContainsKey(buildingID))
                {
                    Utils.LogWarning("Overrides existing outside connection with buildingID: " + buildingID);
                }
                settingsDict[buildingID] = settings;
            }
            return(true);
        }