ServerScript added (not finished yet)
This commit is contained in:
@ -10,7 +10,7 @@ using GTA.Math;
|
|||||||
namespace CoopClient
|
namespace CoopClient
|
||||||
{
|
{
|
||||||
#region CLIENT-ONLY
|
#region CLIENT-ONLY
|
||||||
public static class VectorExtensions
|
static class VectorExtensions
|
||||||
{
|
{
|
||||||
public static Vector3 ToVector(this Quaternion vec)
|
public static Vector3 ToVector(this Quaternion vec)
|
||||||
{
|
{
|
||||||
@ -57,7 +57,7 @@ namespace CoopClient
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
[ProtoContract]
|
[ProtoContract]
|
||||||
public struct LVector3
|
struct LVector3
|
||||||
{
|
{
|
||||||
#region CLIENT-ONLY
|
#region CLIENT-ONLY
|
||||||
public Vector3 ToVector()
|
public Vector3 ToVector()
|
||||||
@ -84,7 +84,7 @@ namespace CoopClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
[ProtoContract]
|
[ProtoContract]
|
||||||
public struct LQuaternion
|
struct LQuaternion
|
||||||
{
|
{
|
||||||
#region CLIENT-ONLY
|
#region CLIENT-ONLY
|
||||||
public Quaternion ToQuaternion()
|
public Quaternion ToQuaternion()
|
||||||
@ -114,7 +114,7 @@ namespace CoopClient
|
|||||||
public float W { get; set; }
|
public float W { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum PacketTypes
|
enum PacketTypes
|
||||||
{
|
{
|
||||||
HandshakePacket,
|
HandshakePacket,
|
||||||
PlayerConnectPacket,
|
PlayerConnectPacket,
|
||||||
@ -129,7 +129,7 @@ namespace CoopClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Flags]
|
[Flags]
|
||||||
public enum PedDataFlags
|
enum PedDataFlags
|
||||||
{
|
{
|
||||||
LastSyncWasFull = 1 << 0,
|
LastSyncWasFull = 1 << 0,
|
||||||
IsAiming = 1 << 1,
|
IsAiming = 1 << 1,
|
||||||
@ -143,7 +143,7 @@ namespace CoopClient
|
|||||||
|
|
||||||
#region ===== VEHICLE DATA =====
|
#region ===== VEHICLE DATA =====
|
||||||
[Flags]
|
[Flags]
|
||||||
public enum VehicleDataFlags
|
enum VehicleDataFlags
|
||||||
{
|
{
|
||||||
LastSyncWasFull = 1 << 0,
|
LastSyncWasFull = 1 << 0,
|
||||||
IsInVehicle = 1 << 1,
|
IsInVehicle = 1 << 1,
|
||||||
@ -196,7 +196,7 @@ namespace CoopClient
|
|||||||
|
|
||||||
#region -- PLAYER --
|
#region -- PLAYER --
|
||||||
[ProtoContract]
|
[ProtoContract]
|
||||||
public class HandshakePacket : Packet
|
class HandshakePacket : Packet
|
||||||
{
|
{
|
||||||
[ProtoMember(1)]
|
[ProtoMember(1)]
|
||||||
public string ID { get; set; }
|
public string ID { get; set; }
|
||||||
@ -238,7 +238,7 @@ namespace CoopClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
[ProtoContract]
|
[ProtoContract]
|
||||||
public class PlayerConnectPacket : Packet
|
class PlayerConnectPacket : Packet
|
||||||
{
|
{
|
||||||
[ProtoMember(1)]
|
[ProtoMember(1)]
|
||||||
public string Player { get; set; }
|
public string Player { get; set; }
|
||||||
@ -272,7 +272,7 @@ namespace CoopClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
[ProtoContract]
|
[ProtoContract]
|
||||||
public class PlayerDisconnectPacket : Packet
|
class PlayerDisconnectPacket : Packet
|
||||||
{
|
{
|
||||||
[ProtoMember(1)]
|
[ProtoMember(1)]
|
||||||
public string Player { get; set; }
|
public string Player { get; set; }
|
||||||
@ -298,7 +298,7 @@ namespace CoopClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
[ProtoContract]
|
[ProtoContract]
|
||||||
public class FullSyncPlayerPacket : Packet
|
class FullSyncPlayerPacket : Packet
|
||||||
{
|
{
|
||||||
[ProtoMember(1)]
|
[ProtoMember(1)]
|
||||||
public string Player { get; set; }
|
public string Player { get; set; }
|
||||||
@ -364,7 +364,7 @@ namespace CoopClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
[ProtoContract]
|
[ProtoContract]
|
||||||
public class FullSyncPlayerVehPacket : Packet
|
class FullSyncPlayerVehPacket : Packet
|
||||||
{
|
{
|
||||||
[ProtoMember(1)]
|
[ProtoMember(1)]
|
||||||
public string Player { get; set; }
|
public string Player { get; set; }
|
||||||
@ -446,7 +446,7 @@ namespace CoopClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
[ProtoContract]
|
[ProtoContract]
|
||||||
public class LightSyncPlayerPacket : Packet
|
class LightSyncPlayerPacket : Packet
|
||||||
{
|
{
|
||||||
[ProtoMember(1)]
|
[ProtoMember(1)]
|
||||||
public string Player { get; set; }
|
public string Player { get; set; }
|
||||||
@ -504,7 +504,7 @@ namespace CoopClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
[ProtoContract]
|
[ProtoContract]
|
||||||
public class LightSyncPlayerVehPacket : Packet
|
class LightSyncPlayerVehPacket : Packet
|
||||||
{
|
{
|
||||||
[ProtoMember(1)]
|
[ProtoMember(1)]
|
||||||
public string Player { get; set; }
|
public string Player { get; set; }
|
||||||
@ -570,7 +570,7 @@ namespace CoopClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
[ProtoContract]
|
[ProtoContract]
|
||||||
public class ChatMessagePacket : Packet
|
class ChatMessagePacket : Packet
|
||||||
{
|
{
|
||||||
[ProtoMember(1)]
|
[ProtoMember(1)]
|
||||||
public string Username { get; set; }
|
public string Username { get; set; }
|
||||||
@ -602,7 +602,7 @@ namespace CoopClient
|
|||||||
|
|
||||||
#region -- NPC --
|
#region -- NPC --
|
||||||
[ProtoContract]
|
[ProtoContract]
|
||||||
public class FullSyncNpcPacket : Packet
|
class FullSyncNpcPacket : Packet
|
||||||
{
|
{
|
||||||
[ProtoMember(1)]
|
[ProtoMember(1)]
|
||||||
public string ID { get; set; }
|
public string ID { get; set; }
|
||||||
@ -668,7 +668,7 @@ namespace CoopClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
[ProtoContract]
|
[ProtoContract]
|
||||||
public class FullSyncNpcVehPacket : Packet
|
class FullSyncNpcVehPacket : Packet
|
||||||
{
|
{
|
||||||
[ProtoMember(1)]
|
[ProtoMember(1)]
|
||||||
public string ID { get; set; }
|
public string ID { get; set; }
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
namespace CoopServer.Entities
|
namespace CoopServer.Entities
|
||||||
{
|
{
|
||||||
struct EntitiesPed
|
public struct EntitiesPed
|
||||||
{
|
{
|
||||||
public LVector3 Position { get; set; }
|
public LVector3 Position { get; set; }
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
namespace CoopServer.Entities
|
namespace CoopServer.Entities
|
||||||
{
|
{
|
||||||
class EntitiesPlayer
|
public class EntitiesPlayer
|
||||||
{
|
{
|
||||||
public string SocialClubName { get; set; }
|
public string SocialClubName { get; set; }
|
||||||
public string Username { get; set; }
|
public string Username { get; set; }
|
||||||
|
@ -56,7 +56,7 @@ namespace CoopServer
|
|||||||
public float W { get; set; }
|
public float W { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum PacketTypes
|
enum PacketTypes
|
||||||
{
|
{
|
||||||
HandshakePacket,
|
HandshakePacket,
|
||||||
PlayerConnectPacket,
|
PlayerConnectPacket,
|
||||||
@ -71,7 +71,7 @@ namespace CoopServer
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Flags]
|
[Flags]
|
||||||
public enum PedDataFlags
|
enum PedDataFlags
|
||||||
{
|
{
|
||||||
LastSyncWasFull = 1 << 0,
|
LastSyncWasFull = 1 << 0,
|
||||||
IsAiming = 1 << 1,
|
IsAiming = 1 << 1,
|
||||||
@ -85,7 +85,7 @@ namespace CoopServer
|
|||||||
|
|
||||||
#region ===== VEHICLE DATA =====
|
#region ===== VEHICLE DATA =====
|
||||||
[Flags]
|
[Flags]
|
||||||
public enum VehicleDataFlags
|
enum VehicleDataFlags
|
||||||
{
|
{
|
||||||
LastSyncWasFull = 1 << 0,
|
LastSyncWasFull = 1 << 0,
|
||||||
IsInVehicle = 1 << 1,
|
IsInVehicle = 1 << 1,
|
||||||
@ -98,7 +98,7 @@ namespace CoopServer
|
|||||||
}
|
}
|
||||||
|
|
||||||
[ProtoContract]
|
[ProtoContract]
|
||||||
public struct VehicleDoors
|
struct VehicleDoors
|
||||||
{
|
{
|
||||||
[ProtoMember(1)]
|
[ProtoMember(1)]
|
||||||
public float AngleRatio { get; set; }
|
public float AngleRatio { get; set; }
|
||||||
@ -114,13 +114,13 @@ namespace CoopServer
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public interface IPacket
|
interface IPacket
|
||||||
{
|
{
|
||||||
void PacketToNetOutGoingMessage(NetOutgoingMessage message);
|
void PacketToNetOutGoingMessage(NetOutgoingMessage message);
|
||||||
void NetIncomingMessageToPacket(NetIncomingMessage message);
|
void NetIncomingMessageToPacket(NetIncomingMessage message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class Packet : IPacket
|
abstract class Packet : IPacket
|
||||||
{
|
{
|
||||||
public abstract void PacketToNetOutGoingMessage(NetOutgoingMessage message);
|
public abstract void PacketToNetOutGoingMessage(NetOutgoingMessage message);
|
||||||
public abstract void NetIncomingMessageToPacket(NetIncomingMessage message);
|
public abstract void NetIncomingMessageToPacket(NetIncomingMessage message);
|
||||||
@ -128,7 +128,7 @@ namespace CoopServer
|
|||||||
|
|
||||||
#region -- PLAYER --
|
#region -- PLAYER --
|
||||||
[ProtoContract]
|
[ProtoContract]
|
||||||
public class HandshakePacket : Packet
|
class HandshakePacket : Packet
|
||||||
{
|
{
|
||||||
[ProtoMember(1)]
|
[ProtoMember(1)]
|
||||||
public string ID { get; set; }
|
public string ID { get; set; }
|
||||||
@ -170,7 +170,7 @@ namespace CoopServer
|
|||||||
}
|
}
|
||||||
|
|
||||||
[ProtoContract]
|
[ProtoContract]
|
||||||
public class PlayerConnectPacket : Packet
|
class PlayerConnectPacket : Packet
|
||||||
{
|
{
|
||||||
[ProtoMember(1)]
|
[ProtoMember(1)]
|
||||||
public string Player { get; set; }
|
public string Player { get; set; }
|
||||||
@ -204,7 +204,7 @@ namespace CoopServer
|
|||||||
}
|
}
|
||||||
|
|
||||||
[ProtoContract]
|
[ProtoContract]
|
||||||
public class PlayerDisconnectPacket : Packet
|
class PlayerDisconnectPacket : Packet
|
||||||
{
|
{
|
||||||
[ProtoMember(1)]
|
[ProtoMember(1)]
|
||||||
public string Player { get; set; }
|
public string Player { get; set; }
|
||||||
@ -230,7 +230,7 @@ namespace CoopServer
|
|||||||
}
|
}
|
||||||
|
|
||||||
[ProtoContract]
|
[ProtoContract]
|
||||||
public class FullSyncPlayerPacket : Packet
|
class FullSyncPlayerPacket : Packet
|
||||||
{
|
{
|
||||||
[ProtoMember(1)]
|
[ProtoMember(1)]
|
||||||
public string Player { get; set; }
|
public string Player { get; set; }
|
||||||
@ -296,7 +296,7 @@ namespace CoopServer
|
|||||||
}
|
}
|
||||||
|
|
||||||
[ProtoContract]
|
[ProtoContract]
|
||||||
public class FullSyncPlayerVehPacket : Packet
|
class FullSyncPlayerVehPacket : Packet
|
||||||
{
|
{
|
||||||
[ProtoMember(1)]
|
[ProtoMember(1)]
|
||||||
public string Player { get; set; }
|
public string Player { get; set; }
|
||||||
@ -378,7 +378,7 @@ namespace CoopServer
|
|||||||
}
|
}
|
||||||
|
|
||||||
[ProtoContract]
|
[ProtoContract]
|
||||||
public class LightSyncPlayerPacket : Packet
|
class LightSyncPlayerPacket : Packet
|
||||||
{
|
{
|
||||||
[ProtoMember(1)]
|
[ProtoMember(1)]
|
||||||
public string Player { get; set; }
|
public string Player { get; set; }
|
||||||
@ -436,7 +436,7 @@ namespace CoopServer
|
|||||||
}
|
}
|
||||||
|
|
||||||
[ProtoContract]
|
[ProtoContract]
|
||||||
public class LightSyncPlayerVehPacket : Packet
|
class LightSyncPlayerVehPacket : Packet
|
||||||
{
|
{
|
||||||
[ProtoMember(1)]
|
[ProtoMember(1)]
|
||||||
public string Player { get; set; }
|
public string Player { get; set; }
|
||||||
@ -502,7 +502,7 @@ namespace CoopServer
|
|||||||
}
|
}
|
||||||
|
|
||||||
[ProtoContract]
|
[ProtoContract]
|
||||||
public class ChatMessagePacket : Packet
|
class ChatMessagePacket : Packet
|
||||||
{
|
{
|
||||||
[ProtoMember(1)]
|
[ProtoMember(1)]
|
||||||
public string Username { get; set; }
|
public string Username { get; set; }
|
||||||
@ -534,7 +534,7 @@ namespace CoopServer
|
|||||||
|
|
||||||
#region -- NPC --
|
#region -- NPC --
|
||||||
[ProtoContract]
|
[ProtoContract]
|
||||||
public class FullSyncNpcPacket : Packet
|
class FullSyncNpcPacket : Packet
|
||||||
{
|
{
|
||||||
[ProtoMember(1)]
|
[ProtoMember(1)]
|
||||||
public string ID { get; set; }
|
public string ID { get; set; }
|
||||||
@ -600,7 +600,7 @@ namespace CoopServer
|
|||||||
}
|
}
|
||||||
|
|
||||||
[ProtoContract]
|
[ProtoContract]
|
||||||
public class FullSyncNpcVehPacket : Packet
|
class FullSyncNpcVehPacket : Packet
|
||||||
{
|
{
|
||||||
[ProtoMember(1)]
|
[ProtoMember(1)]
|
||||||
public string ID { get; set; }
|
public string ID { get; set; }
|
||||||
|
@ -4,6 +4,8 @@ using System.Collections.Generic;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Lidgren.Network;
|
using Lidgren.Network;
|
||||||
@ -29,6 +31,8 @@ namespace CoopServer
|
|||||||
|
|
||||||
private static readonly Dictionary<string, EntitiesPlayer> Players = new();
|
private static readonly Dictionary<string, EntitiesPlayer> Players = new();
|
||||||
|
|
||||||
|
private static ServerScript GameMode;
|
||||||
|
|
||||||
public Server()
|
public Server()
|
||||||
{
|
{
|
||||||
// 6d4ec318f1c43bd62fe13d5a7ab28650 = GTACOOP:R
|
// 6d4ec318f1c43bd62fe13d5a7ab28650 = GTACOOP:R
|
||||||
@ -122,6 +126,37 @@ namespace CoopServer
|
|||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Logging.Info("Loading gamemode...");
|
||||||
|
|
||||||
|
Assembly asm = Assembly.LoadFrom(AppDomain.CurrentDomain.BaseDirectory + "gamemodes" + Path.DirectorySeparatorChar + "FirstMod.dll");
|
||||||
|
Type[] types = asm.GetExportedTypes();
|
||||||
|
IEnumerable<Type> validTypes = types.Where(t => !t.IsInterface && !t.IsAbstract).Where(t => typeof(ServerScript).IsAssignableFrom(t));
|
||||||
|
Type[] enumerable = validTypes as Type[] ?? validTypes.ToArray();
|
||||||
|
|
||||||
|
if (!enumerable.Any())
|
||||||
|
{
|
||||||
|
Logging.Error("ERROR: No classes that inherit from ServerScript have been found in the assembly. Starting freeroam.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GameMode = Activator.CreateInstance(enumerable.ToArray()[0]) as ServerScript;
|
||||||
|
if (GameMode == null)
|
||||||
|
{
|
||||||
|
Logging.Warning("Could not create gamemode: it is null.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GameMode.Start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Logging.Error(e.Message);
|
||||||
|
}
|
||||||
|
|
||||||
Listen();
|
Listen();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -437,8 +472,6 @@ namespace CoopServer
|
|||||||
|
|
||||||
// Accept the connection and send back a new handshake packet with the connection ID
|
// Accept the connection and send back a new handshake packet with the connection ID
|
||||||
local.Approve(outgoingMessage);
|
local.Approve(outgoingMessage);
|
||||||
|
|
||||||
Logging.Info("New player [" + packet.SocialClubName + " | " + packet.Username + "] connected!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The connection has been approved, now we need to send all other players to the new player and the new player to all players
|
// The connection has been approved, now we need to send all other players to the new player and the new player to all players
|
||||||
@ -449,6 +482,11 @@ namespace CoopServer
|
|||||||
SendChatMessage(new ChatMessagePacket() { Username = "Server", Message = MainSettings.WelcomeMessage }, new List<NetConnection>() { local });
|
SendChatMessage(new ChatMessagePacket() { Username = "Server", Message = MainSettings.WelcomeMessage }, new List<NetConnection>() { local });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (GameMode != null)
|
||||||
|
{
|
||||||
|
GameMode.OnPlayerConnect(Players[packet.Player]);
|
||||||
|
}
|
||||||
|
|
||||||
List<NetConnection> playerList = FilterAllLocal(local);
|
List<NetConnection> playerList = FilterAllLocal(local);
|
||||||
if (playerList.Count == 0)
|
if (playerList.Count == 0)
|
||||||
{
|
{
|
||||||
@ -486,6 +524,11 @@ namespace CoopServer
|
|||||||
// Send all players a message that someone has left the server
|
// Send all players a message that someone has left the server
|
||||||
private static void SendPlayerDisconnectPacket(PlayerDisconnectPacket packet, string reason = "Disconnected")
|
private static void SendPlayerDisconnectPacket(PlayerDisconnectPacket packet, string reason = "Disconnected")
|
||||||
{
|
{
|
||||||
|
if (GameMode != null)
|
||||||
|
{
|
||||||
|
GameMode.OnPlayerDisconnect(Players[packet.Player], reason);
|
||||||
|
}
|
||||||
|
|
||||||
List<NetConnection> playerList = FilterAllLocal(packet.Player);
|
List<NetConnection> playerList = FilterAllLocal(packet.Player);
|
||||||
if (playerList.Count != 0)
|
if (playerList.Count != 0)
|
||||||
{
|
{
|
||||||
@ -494,7 +537,6 @@ namespace CoopServer
|
|||||||
MainNetServer.SendMessage(outgoingMessage, playerList, NetDeliveryMethod.ReliableOrdered, 0);
|
MainNetServer.SendMessage(outgoingMessage, playerList, NetDeliveryMethod.ReliableOrdered, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Logging.Info(Players[packet.Player].Username + " left the server, reason: " + reason);
|
|
||||||
Players.Remove(packet.Player);
|
Players.Remove(packet.Player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
37
Server/ServerScript.cs
Normal file
37
Server/ServerScript.cs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
using Lidgren.Network;
|
||||||
|
|
||||||
|
namespace CoopServer
|
||||||
|
{
|
||||||
|
public class ServerScript
|
||||||
|
{
|
||||||
|
public virtual void Start()
|
||||||
|
{
|
||||||
|
Logging.Info("Gamemode loaded successfully!");
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnPlayerConnect(Entities.EntitiesPlayer client)
|
||||||
|
{
|
||||||
|
Logging.Info("New player [" + client.SocialClubName + " | " + client.Username + "] connected!");
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnPlayerDisconnect(Entities.EntitiesPlayer client, string reason)
|
||||||
|
{
|
||||||
|
Logging.Info(client.Username + " left the server, reason: " + reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static void SendChatMessageToAll(string message, string username = "Server")
|
||||||
|
{
|
||||||
|
ChatMessagePacket packet = new()
|
||||||
|
{
|
||||||
|
Username = username,
|
||||||
|
Message = message
|
||||||
|
};
|
||||||
|
|
||||||
|
Logging.Info(username + packet.Message);
|
||||||
|
|
||||||
|
NetOutgoingMessage outgoingMessage = Server.MainNetServer.CreateMessage();
|
||||||
|
packet.PacketToNetOutGoingMessage(outgoingMessage);
|
||||||
|
Server.MainNetServer.SendMessage(outgoingMessage, Server.MainNetServer.Connections, NetDeliveryMethod.ReliableOrdered, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -11,27 +11,27 @@ namespace CoopServer
|
|||||||
XmlSerializer ser = new(typeof(T));
|
XmlSerializer ser = new(typeof(T));
|
||||||
|
|
||||||
string path = AppContext.BaseDirectory + file;
|
string path = AppContext.BaseDirectory + file;
|
||||||
T settings;
|
T data;
|
||||||
|
|
||||||
if (File.Exists(path))
|
if (File.Exists(path))
|
||||||
{
|
{
|
||||||
using (FileStream stream = File.OpenRead(path))
|
using (FileStream stream = File.OpenRead(path))
|
||||||
{
|
{
|
||||||
settings = (T)ser.Deserialize(stream);
|
data = (T)ser.Deserialize(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
using (FileStream stream = new(path, File.Exists(path) ? FileMode.Truncate : FileMode.Create, FileAccess.ReadWrite))
|
using (FileStream stream = new(path, File.Exists(path) ? FileMode.Truncate : FileMode.Create, FileAccess.ReadWrite))
|
||||||
{
|
{
|
||||||
ser.Serialize(stream, settings);
|
ser.Serialize(stream, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
using FileStream stream = File.OpenWrite(path);
|
using FileStream stream = File.OpenWrite(path);
|
||||||
ser.Serialize(stream, settings = new T());
|
ser.Serialize(stream, data = new T());
|
||||||
}
|
}
|
||||||
|
|
||||||
return settings;
|
return data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user