public byte[] Serialize() { List <byte> list = new List <byte>(); list.AddRange(ByteSerializer.SerializeInt(this.userCount)); list.AddRange(ByteSerializer.SerializeInt(this.userCap)); list.AddRange(ByteSerializer.SerializeBool(this.acceptingConnections)); list.AddRange(ByteSerializer.SerializeInt((int)this.lobbyMode)); list.AddRange(ByteSerializer.SerializeBool(this.isFrozen)); list.AddRange(ByteSerializer.SerializeStrings(this.playerNames)); return(list.ToArray()); }
private static void patchSerializerTwo(SandboxLayoutData __instance, List <byte> bytes) { ptfInstance.ptfLogger.LogMessage($"Layout post version: {__instance.m_Version}"); // add number of mods stored //bytes.AddRange(ByteSerializer.SerializeInt(noncheatMods.Where(x => x.shouldSaveData).Count() + cheatMods.Where(x => x.shouldSaveData).Count())); // add mod data for each mod // make sure to be backwards compatible! List <string> modData = cheatMods.Where(x => x.isEnabled).Select(x => $"{x.Info.Metadata.Name}\u058D{x.Info.Metadata.Version}\u058D{x.getSettings()}").ToList(); modData.AddRange(noncheatMods.Where(x => x.shouldSaveData && x.isEnabled).Select(x => $"{x.Info.Metadata.Name}\u058D{x.Info.Metadata.Version}\u058D{x.getSettings()}").ToList()); string[] mods = modData.ToArray(); if (__instance.m_Version >= 0) { return; } bytes.AddRange(ByteSerializer.SerializeStrings(mods)); // add an int indicating the number of mods that will save binary data int modsSavingBinary = noncheatMods.Where(x => x.shouldSaveData).Count() + cheatMods.Where(x => x.shouldSaveData).Count(); bytes.AddRange(ByteSerializer.SerializeInt(modsSavingBinary)); foreach (var mod in noncheatMods) { if (mod.isEnabled && mod.shouldSaveData) { bytes.AddRange(ByteSerializer.SerializeString( $"{mod.Info.Metadata.Name}\u058D{mod.Info.Metadata.Version}" )); bytes.AddRange(ByteSerializer.SerializeByteArray( mod.saveData() )); } } foreach (var mod in cheatMods) { if (mod.isEnabled && mod.shouldSaveData) { bytes.AddRange(ByteSerializer.SerializeString( $"{mod.Info.Metadata.Name}\u058D{mod.Info.Metadata.Version}" )); bytes.AddRange(ByteSerializer.SerializeByteArray( mod.saveData() )); } } ptfInstance.ptfLogger.LogMessage($"Serialized {mods.Length.ToString()} Mod Names"); }