private static void OnSaveData()
        {
            FastList <byte> data = new FastList <byte>();

            try
            {
                SerializableDataExtension.WriteString(VehicleManagerMod._dataVersion, data);
                for (int index = 0; index < 16384; ++index)
                {
                    if (!VehicleManagerMod.m_cachedVehicleData[index].IsEmpty)
                    {
                        SerializableDataExtension.WriteInt32(index, data);
                        SerializableDataExtension.WriteInt32(VehicleManagerMod.m_cachedVehicleData[index].LastStopNewPassengers, data);
                        SerializableDataExtension.WriteInt32(VehicleManagerMod.m_cachedVehicleData[index].LastStopGonePassengers, data);
                        SerializableDataExtension.WriteInt32(VehicleManagerMod.m_cachedVehicleData[index].PassengersThisWeek, data);
                        SerializableDataExtension.WriteInt32(VehicleManagerMod.m_cachedVehicleData[index].PassengersLastWeek, data);
                        SerializableDataExtension.WriteInt32(VehicleManagerMod.m_cachedVehicleData[index].IncomeThisWeek, data);
                        SerializableDataExtension.WriteInt32(VehicleManagerMod.m_cachedVehicleData[index].IncomeLastWeek, data);
                        SerializableDataExtension.WriteFloatArray(VehicleManagerMod.m_cachedVehicleData[index].PassengerData, data);
                        SerializableDataExtension.WriteFloatArray(VehicleManagerMod.m_cachedVehicleData[index].IncomeData, data);
                        SerializableDataExtension.WriteUInt16(VehicleManagerMod.m_cachedVehicleData[index].CurrentStop, data);
                    }
                }
                SerializableDataExtension.instance.SerializableData.SaveData(VehicleManagerMod._dataID, data.ToArray());
            }
            catch (Exception ex)
            {
                Utils.LogError((object)("Error while saving vehicle data! " + ex.Message + " " + (object)ex.InnerException));
            }
        }
        private static void OnSaveData()
        {
            FastList <byte> data = new FastList <byte>();

            try
            {
                SerializableDataExtension.WriteString(NetManagerMod._dataVersion, data);
                for (int index = 0; index < 32768; ++index)
                {
                    if (!NetManagerMod.m_cachedNodeData[index].IsEmpty)
                    {
                        SerializableDataExtension.WriteInt32(index, data);
                        SerializableDataExtension.WriteInt32(NetManagerMod.m_cachedNodeData[index].PassengersIn, data);
                        SerializableDataExtension.WriteInt32(NetManagerMod.m_cachedNodeData[index].PassengersOut, data);
                        SerializableDataExtension.WriteInt32(NetManagerMod.m_cachedNodeData[index].LastWeekPassengersIn, data);
                        SerializableDataExtension.WriteInt32(NetManagerMod.m_cachedNodeData[index].LastWeekPassengersOut, data);
                        SerializableDataExtension.WriteFloatArray(NetManagerMod.m_cachedNodeData[index].PassengerInData, data);
                        SerializableDataExtension.WriteFloatArray(NetManagerMod.m_cachedNodeData[index].PassengerOutData, data);
                        SerializableDataExtension.WriteBool(NetManagerMod.m_cachedNodeData[index].Unbunching, data);
                    }
                }
                SerializableDataExtension.instance.SerializableData.SaveData(NetManagerMod._dataID, data.ToArray());
            }
            catch (Exception ex)
            {
                Utils.LogError((object)("Error while saving net node data! " + ex.Message + " " + (object)ex.InnerException));
            }
        }
Exemple #3
0
        private static void OnSaveData()
        {
            Utils.Log("Begin save data.");
            FastList <byte> buffer = new FastList <byte>();

            try
            {
                SerializableDataExtension.WriteUInt16(_dataVersion, buffer);
                SerializableDataExtension.WriteInt32(instance.SettingsDict.Count, buffer);
                foreach (var keyValue in instance.SettingsDict)
                {
                    FastList <byte> elementBuffer = new FastList <byte>();
                    SerializableDataExtension.WriteUInt16(keyValue.Key, elementBuffer);
                    SerializableDataExtension.WriteUInt16((ushort)keyValue.Value.NameMode, elementBuffer);
                    SerializableDataExtension.WriteString(keyValue.Value.SingleGenerationName, elementBuffer);

                    SerializableDataExtension.WriteUInt16((ushort)keyValue.Value.RandomGenerationNames.Count, elementBuffer);
                    foreach (var str in keyValue.Value.RandomGenerationNames)
                    {
                        SerializableDataExtension.WriteString(str, elementBuffer);
                    }

                    SerializableDataExtension.WriteUInt16((ushort)keyValue.Value.CurrentDirectionFlags, elementBuffer);
                    SerializableDataExtension.WriteString(keyValue.Value.Name, elementBuffer);
                    SerializableDataExtension.WriteInt32(keyValue.Value.DummyTrafficFactor, elementBuffer);     // addition with version 2

                    SerializableDataExtension.WriteUInt16((ushort)keyValue.Value.TouristFactors.Length, elementBuffer);
                    foreach (var value in keyValue.Value.TouristFactors)
                    {
                        SerializableDataExtension.WriteInt32(value, elementBuffer);
                    }

                    SerializableDataExtension.WriteUInt16((ushort)keyValue.Value.ImportResourceRatio.Length, elementBuffer);
                    foreach (var value in keyValue.Value.ImportResourceRatio)
                    {
                        SerializableDataExtension.WriteInt32(value, elementBuffer);
                    }

                    SerializableDataExtension.WriteUInt16((ushort)keyValue.Value.ExportResourceRatio.Length, elementBuffer);
                    foreach (var value in keyValue.Value.ExportResourceRatio)
                    {
                        SerializableDataExtension.WriteInt32(value, elementBuffer);
                    }

                    SerializableDataExtension.WriteInt32(keyValue.Value.CargoCapacity, elementBuffer);
                    SerializableDataExtension.WriteInt32(keyValue.Value.ResidentCapacity, elementBuffer);

                    SerializableDataExtension.WriteByteArray(elementBuffer, buffer);
                }
                SerializableDataExtension.instance.SerializableData.SaveData(_dataID, buffer.ToArray());
                Utils.Log("End save data. Version: " + _dataVersion + " bytes written: " + buffer.m_size);
            }
            catch (Exception ex)
            {
                Utils.LogError("Error while saving data! " + ex.Message + " " + (object)ex.InnerException);
            }
        }
Exemple #4
0
        private static void OnSaveData()
        {
            FastList <byte> data = new FastList <byte>();

            try
            {
                SerializableDataExtension.WriteString(TransportLineMod._dataVersion, data);
                for (ushort lineID = 0; (int)lineID < 256; ++lineID)
                {
                    SerializableDataExtension.AddToData(
                        BitConverter.GetBytes(TransportLineMod.GetTargetVehicleCount(lineID)), data);
                    SerializableDataExtension.AddToData(
                        BitConverter.GetBytes(Mathf.Max(
                                                  TransportLineMod.GetNextSpawnTime(lineID) - SimHelper.SimulationTime, 0.0f)),
                        data);
                    SerializableDataExtension.AddToData(
                        BitConverter.GetBytes(TransportLineMod.GetBudgetControlState(lineID)), data);
                    SerializableDataExtension.AddToData(BitConverter.GetBytes(TransportLineMod.GetDepot(lineID)), data);
                    int num = 0;
                    HashSet <string> prefabs = TransportLineMod.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 = TransportLineMod.GetEnqueuedVehicles(lineID);
                    SerializableDataExtension.AddToData(BitConverter.GetBytes(enqueuedVehicles.Length), data);
                    if (enqueuedVehicles.Length != 0)
                    {
                        foreach (string s in enqueuedVehicles)
                        {
                            SerializableDataExtension.WriteString(s, data);
                        }
                    }
                    SerializableDataExtension.WriteBool(TransportLineMod.GetUnbunchingState(lineID), data);
                }
                SerializableDataExtension.instance.SerializableData.SaveData(TransportLineMod._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);
            }
        }