Пример #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));
            }
        }
Пример #2
0
        private static void OnSaveData()
        {
            FastList <byte> data = new FastList <byte>();

            try
            {
                SerializableDataExtension.WriteString(CachedNodeData._dataVersion, data);
                for (int index = 0; index < 32768; ++index)
                {
                    if (!CachedNodeData.m_cachedNodeData[index].IsEmpty)
                    {
                        SerializableDataExtension.WriteInt32(index, data);
                        SerializableDataExtension.WriteInt32(CachedNodeData.m_cachedNodeData[index].PassengersIn, data);
                        SerializableDataExtension.WriteInt32(CachedNodeData.m_cachedNodeData[index].PassengersOut, data);
                        SerializableDataExtension.WriteInt32(CachedNodeData.m_cachedNodeData[index].LastWeekPassengersIn, data);
                        SerializableDataExtension.WriteInt32(CachedNodeData.m_cachedNodeData[index].LastWeekPassengersOut, data);
                        SerializableDataExtension.WriteFloatArray(CachedNodeData.m_cachedNodeData[index].PassengerInData, data);
                        SerializableDataExtension.WriteFloatArray(CachedNodeData.m_cachedNodeData[index].PassengerOutData, data);
                        SerializableDataExtension.WriteBool(CachedNodeData.m_cachedNodeData[index].Unbunching, data);
                    }
                }
                SerializableDataExtension.instance.SerializableData.SaveData(CachedNodeData._dataID, data.ToArray());
            }
            catch (Exception ex)
            {
                Utils.LogError((object)("Error while saving net node data! " + ex.Message + " " + (object)ex.InnerException));
            }
        }
 public static void WriteFloatArray(float[] array, FastList <byte> data)
 {
     SerializableDataExtension.WriteInt32(array.Length, data);
     for (ushort index = 0; (int)index < array.Length; ++index)
     {
         SerializableDataExtension.WriteFloat(array[(int)index], data);
     }
 }
 public static void WriteString(string s, FastList <byte> data)
 {
     char[] charArray = s.ToCharArray();
     SerializableDataExtension.WriteInt32(charArray.Length, data);
     for (ushort index = 0; (int)index < charArray.Length; ++index)
     {
         SerializableDataExtension.AddToData(BitConverter.GetBytes(charArray[(int)index]), data);
     }
 }
        public static float[] ReadFloatArray(byte[] data, ref int index)
        {
            int length = SerializableDataExtension.ReadInt32(data, ref index);

            float[] numArray = new float[length];
            for (int index1 = 0; index1 < length; ++index1)
            {
                numArray[index1] = SerializableDataExtension.ReadFloat(data, ref index);
            }
            return(numArray);
        }
        public static string ReadString(byte[] data, ref int index)
        {
            string empty = string.Empty;
            int    num   = SerializableDataExtension.ReadInt32(data, ref index);

            for (int index1 = 0; index1 < num; ++index1)
            {
                empty += BitConverter.ToChar(data, index).ToString();
                index  = index + 2;
            }
            return(empty);
        }
Пример #7
0
        private static void OnSaveData()
        {
            FastList <byte> data = new FastList <byte>();

            try
            {
                SerializableDataExtension.WriteString(_dataVersion, data);
                for (ushort lineID = 0; (int)lineID < 256; ++lineID)
                {
                    SerializableDataExtension.AddToData(
                        BitConverter.GetBytes(GetTargetVehicleCount(lineID)), data);
                    SerializableDataExtension.AddToData(
                        BitConverter.GetBytes(Mathf.Max(
                                                  GetNextSpawnTime(lineID) - SimHelper.SimulationTime, 0.0f)),
                        data);
                    SerializableDataExtension.AddToData(
                        BitConverter.GetBytes(GetBudgetControlState(lineID)), data);
                    SerializableDataExtension.AddToData(BitConverter.GetBytes(GetDepot(lineID)), data);
                    int num = 0;
                    HashSet <string> prefabs = GetPrefabs(lineID);
                    if (prefabs != null)
                    {
                        num = prefabs.Count;
                    }
                    SerializableDataExtension.AddToData(BitConverter.GetBytes(num), data);
                    if (num > 0)
                    {
                        foreach (string s in prefabs)
                        {
                            SerializableDataExtension.WriteString(s, data);
                        }
                    }
                    string[] enqueuedVehicles = GetEnqueuedVehicles(lineID);
                    SerializableDataExtension.AddToData(BitConverter.GetBytes(enqueuedVehicles.Length), data);
                    if (enqueuedVehicles.Length != 0)
                    {
                        foreach (string s in enqueuedVehicles)
                        {
                            SerializableDataExtension.WriteString(s, data);
                        }
                    }
                    SerializableDataExtension.WriteBool(GetUnbunchingState(lineID), data);
                }
                SerializableDataExtension.instance.SerializableData.SaveData(_dataID, data.ToArray());
            }
            catch (Exception ex)
            {
                string msg = "Error while saving transport line data! " + ex.Message + " " + (object)ex.InnerException;
                Utils.LogError((object)msg);
                CODebugBase <LogChannel> .Log(LogChannel.Modding, msg, ErrorLevel.Error);
            }
        }
Пример #8
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);
            }
        }
Пример #9
0
        public static bool TryLoadData(out NodeData[] data)
        {
            data = new NodeData[32768];
            byte[] data1 = SerializableDataExtension.instance.SerializableData.LoadData(CachedNodeData._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);
            }
        }
 public static void WriteUInt16(ushort value, FastList <byte> data)
 {
     SerializableDataExtension.AddToData(BitConverter.GetBytes(value), data);
 }
 public void OnReleased()
 {
     SerializableDataExtension.instance = (SerializableDataExtension)null;
 }
 public void OnCreated(ISerializableData serializedData)
 {
     SerializableDataExtension.instance = this;
     this._serializableData             = serializedData;
 }
Пример #13
0
        public static bool TryLoadData(out LineData[] data)
        {
            data = new LineData[256];
            byte[] data1 = SerializableDataExtension.instance.SerializableData.LoadData(_dataID);
            if (data1 == null)
            {
                return(false);
            }
            int    index1 = 0;
            ushort lineID = 0;
            string empty  = string.Empty;

            try
            {
                Utils.Log((object)"Try to load transport line 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 transport line data version: " + str));
                NetManager       instance1 = Singleton <NetManager> .instance;
                TransportManager instance2 = Singleton <TransportManager> .instance;
                while (index1 < data1.Length)
                {
                    if (instance2.m_lines.m_buffer[(int)lineID].Complete)
                    {
                        int int32 = BitConverter.ToInt32(data1, index1);
                        data[(int)lineID].TargetVehicleCount = int32;
                    }
                    index1 += 4;
                    float num = Mathf.Min(BitConverter.ToSingle(data1, index1),
                                          (float)OptionsWrapper <Settings> .Options.SpawnTimeInterval);
                    if ((double)num > 0.0)
                    {
                        data[(int)lineID].NextSpawnTime = SimHelper.SimulationTime + num;
                    }
                    index1 += 4;
                    bool boolean = BitConverter.ToBoolean(data1, index1);
                    data[(int)lineID].BudgetControl = boolean;
                    ++index1;
                    ushort uint16 = BitConverter.ToUInt16(data1, index1);
                    data[(int)lineID].Depot = (int)uint16 != 0
                        ? uint16
                        : DepotUtil.GetClosestDepot(lineID,
                                                    instance1.m_nodes.m_buffer[(int)instance2.m_lines.m_buffer[(int)lineID].GetStop(0)]
                                                    .m_position);
                    index1 += 2;
                    if (str == "v001")
                    {
                        string name = SerializableDataExtension.ReadString(data1, ref index1);
                        if (name != "Random")
                        {
                            if (data[(int)lineID].Prefabs == null)
                            {
                                data[(int)lineID].Prefabs = new HashSet <string>();
                            }
                            if ((UnityEngine.Object)PrefabCollection <VehicleInfo> .FindLoaded(name) !=
                                (UnityEngine.Object)null)
                            {
                                data[(int)lineID].Prefabs.Add(name);
                            }
                        }
                    }
                    else
                    {
                        int int32 = BitConverter.ToInt32(data1, index1);
                        index1 += 4;
                        for (int index2 = 0; index2 < int32; ++index2)
                        {
                            string name = SerializableDataExtension.ReadString(data1, ref index1);
                            if (data[(int)lineID].Prefabs == null)
                            {
                                data[(int)lineID].Prefabs = new HashSet <string>();
                            }
                            if ((UnityEngine.Object)PrefabCollection <VehicleInfo> .FindLoaded(name) !=
                                (UnityEngine.Object)null)
                            {
                                data[(int)lineID].Prefabs.Add(name);
                            }
                        }
                    }
                    if (str != "v001")
                    {
                        int int32 = BitConverter.ToInt32(data1, index1);
                        index1 += 4;
                        for (int index2 = 0; index2 < int32; ++index2)
                        {
                            string name = SerializableDataExtension.ReadString(data1, ref index1);
                            if (!boolean)
                            {
                                if (data[(int)lineID].QueuedVehicles == null)
                                {
                                    data[(int)lineID].QueuedVehicles = new Queue <string>();
                                }
                                if ((UnityEngine.Object)PrefabCollection <VehicleInfo> .FindLoaded(name) !=
                                    (UnityEngine.Object)null)
                                {
                                    lock (data[(int)lineID].QueuedVehicles)
                                        data[(int)lineID].QueuedVehicles.Enqueue(name);
                                }
                            }
                        }
                    }
                    if (str == "v003")
                    {
                        ++index1;
                    }
                    data[(int)lineID].Unbunching = str != "v004"
                        ? OptionsWrapper <Settings> .Options.Unbunching
                        : SerializableDataExtension.ReadBool(data1, ref index1);
                    ++lineID;
                }
                return(true);
            }
            catch (Exception ex)
            {
                Utils.LogWarning((object)("Could not load transport line data. " + ex.Message));
                data = new LineData[256];
                return(false);
            }
        }