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); } }
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.instance.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); } }
public static void WriteUInt16(ushort value, FastList <byte> data) { SerializableDataExtension.AddToData(BitConverter.GetBytes(value), data); }