Skip to content

Commit 56d8284

Browse files
author
Jannify
authored
Adding ServerJsonSerializer to save world/player/base data as json (SubnauticaNitrox#1075)
* Rename ServerProtobufSerializer to ServerProtoBufSerializer * Added option to save world/player/base data as json * Renaming "SubnauticaServerProtobufSerializer" to "SubnauticaServerProtoBufSerializer" * Adding json serialization to tests * > Added NitroxId Converter > Moved JsonConverters one folder up * ServerConfig changes * Fixing serialization tests * Making all constructor without parameter in GameLogic protected so json uses the constructor with parameter * Making ProtoBuf standard serializer * Making ProtoBuf standard serializer * Moving converter to NitroxServer * Adding option to backup world if deserialization fails. * Fixing errors after rebase * Switching from custom Newtonsoft.Json to nuget package * Minor fixes * Added option for serialize/deserialize directly with file path * Only backup save if all files are there
1 parent 81e1936 commit 56d8284

File tree

62 files changed

+685
-301
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+685
-301
lines changed

Nitrox.sln

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.28307.572
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30114.105
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NitroxServer", "NitroxServer\NitroxServer.csproj", "{0FC864B0-694E-4FCA-B78C-8EF98BC6F262}"
77
EndProject
@@ -16,9 +16,9 @@ EndProject
1616
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{56490579-3996-40AB-8FB8-0B91F083FC39}"
1717
ProjectSection(SolutionItems) = preProject
1818
.editorconfig = .editorconfig
19-
SharedConfig.targets = SharedConfig.targets
20-
Directory.Build.targets = Directory.Build.targets
2119
Directory.Build.props = Directory.Build.props
20+
Directory.Build.targets = Directory.Build.targets
21+
SharedConfig.targets = SharedConfig.targets
2222
EndProjectSection
2323
EndProject
2424
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NitroxModel-Subnautica", "NitroxModel-Subnautica\NitroxModel-Subnautica.csproj", "{0A377218-6B36-4522-89A3-A39CFC999209}"
@@ -34,6 +34,9 @@ EndProject
3434
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Nitrox.Subnautica.Assets", "Nitrox.Subnautica.Assets\Nitrox.Subnautica.Assets.shproj", "{0763D551-B1A8-4960-B88A-98833F957936}"
3535
EndProject
3636
Global
37+
GlobalSection(SharedMSBuildProjectFiles) = preSolution
38+
Nitrox.Subnautica.Assets\Nitrox.Subnautica.Assets.projitems*{0763d551-b1a8-4960-b88a-98833f957936}*SharedItemsImports = 13
39+
EndGlobalSection
3740
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3841
Debug|Any CPU = Debug|Any CPU
3942
Debug|x64 = Debug|x64

Nitrox.sln.DotSettings

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,15 @@
228228
</TypePattern>
229229
&lt;/Patterns&gt;</s:String>
230230
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAlwaysTreatStructAsNotReorderableMigration/@EntryIndexedValue">True</s:Boolean>
231+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Bootstrappers/@EntryIndexedValue">True</s:Boolean>
231232
<s:Boolean x:Key="/Default/UserDictionary/Words/=Coroutine/@EntryIndexedValue">True</s:Boolean>
232233
<s:Boolean x:Key="/Default/UserDictionary/Words/=Mathf/@EntryIndexedValue">True</s:Boolean>
233234
<s:Boolean x:Key="/Default/UserDictionary/Words/=Nitrox/@EntryIndexedValue">True</s:Boolean>
234-
<s:Boolean x:Key="/Default/UserDictionary/Words/=Startable/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
235+
<s:Boolean x:Key="/Default/UserDictionary/Words/=PROTOBUF/@EntryIndexedValue">True</s:Boolean>
236+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Seamoth/@EntryIndexedValue">True</s:Boolean>
237+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Spawner/@EntryIndexedValue">True</s:Boolean>
238+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Startable/@EntryIndexedValue">True</s:Boolean>
239+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Subnautica/@EntryIndexedValue">True</s:Boolean>
240+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Triggerer/@EntryIndexedValue">True</s:Boolean>
241+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Unspawned/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
235242

NitroxModel-Subnautica/DataStructures/GameLogic/Buildings/Rotation/Metadata/BaseModuleRotationMetadata.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ public class BaseModuleRotationMetadata : RotationMetadata
1616
[ProtoMember(2)]
1717
public int Direction { get; set; }
1818

19-
public BaseModuleRotationMetadata() : base(typeof(BaseAddModuleGhost))
19+
protected BaseModuleRotationMetadata() : base(typeof(BaseAddModuleGhost))
2020
{
21-
// For serialization purposes
21+
// Constructor for serialization. Has to be "protected" for json serialization.
2222
}
2323

24-
public BaseModuleRotationMetadata(Int3 cell, int direction) : base (typeof(BaseAddModuleGhost))
24+
public BaseModuleRotationMetadata(Int3 cell, int direction) : base(typeof(BaseAddModuleGhost))
2525
{
2626
Cell = cell.Model();
2727
Direction = direction;

NitroxModel-Subnautica/DataStructures/GameLogic/Buildings/Rotation/Metadata/CorridorRotationMetadata.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ public class CorridorRotationMetadata : RotationMetadata
1313
[ProtoMember(1)]
1414
public int Rotation { get; set; }
1515

16-
public CorridorRotationMetadata() : base(typeof(BaseAddCorridorGhost))
16+
protected CorridorRotationMetadata() : base(typeof(BaseAddCorridorGhost))
1717
{
18-
// For serialization purposes
18+
// Constructor for serialization. Has to be "protected" for json serialization.
1919
}
2020

21-
public CorridorRotationMetadata(int rotation) : base (typeof(BaseAddCorridorGhost))
21+
public CorridorRotationMetadata(int rotation) : base(typeof(BaseAddCorridorGhost))
2222
{
2323
Rotation = rotation;
2424
}

NitroxModel-Subnautica/DataStructures/GameLogic/Buildings/Rotation/Metadata/MapRoomRotationMetadata.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ public class MapRoomRotationMetadata : RotationMetadata
1616
[ProtoMember(2)]
1717
public int ConnectionMask { get; set; }
1818

19-
public MapRoomRotationMetadata() : base(typeof(BaseAddMapRoomGhost))
19+
protected MapRoomRotationMetadata() : base(typeof(BaseAddMapRoomGhost))
2020
{
21-
// For serialization purposes
21+
// Constructor for serialization. Has to be "protected" for json serialization.
2222
}
2323

24-
public MapRoomRotationMetadata(byte cellType, int connectionMask) : base (typeof(BaseAddMapRoomGhost))
24+
public MapRoomRotationMetadata(byte cellType, int connectionMask) : base(typeof(BaseAddMapRoomGhost))
2525
{
2626
CellType = cellType;
2727
ConnectionMask = connectionMask;

NitroxModel-Subnautica/DataStructures/GameLogic/CyclopsDamageInfoData.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ public class CyclopsDamageInfoData
2727
[ProtoMember(6)]
2828
public DamageType Type { get; set; }
2929

30-
public CyclopsDamageInfoData()
30+
protected CyclopsDamageInfoData()
3131
{
32-
// Default Constructor for serialization
32+
// Constructor for serialization. Has to be "protected" for json serialization.
3333
}
3434

3535
public CyclopsDamageInfoData(NitroxId receiverId, NitroxId dealerId, float originalDamage, float damage, Vector3 position, DamageType type)
@@ -46,7 +46,7 @@ public override string ToString()
4646
{
4747
return "[DamageInfoData - ReceiverId: " + ReceiverId
4848
+ " DealerId:" + DealerId
49-
+ " OriginalDamage: " + OriginalDamage
49+
+ " OriginalDamage: " + OriginalDamage
5050
+ " Damage: " + Damage
5151
+ " Position: " + Position
5252
+ " Type: " + Type

NitroxModel-Subnautica/DataStructures/GameLogic/CyclopsFireData.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ public class CyclopsFireData
2020
[ProtoMember(4)]
2121
public int NodeIndex { get; set; }
2222

23-
public CyclopsFireData()
23+
protected CyclopsFireData()
2424
{
25-
25+
// Constructor for serialization. Has to be "protected" for json serialization.
2626
}
2727

2828
public CyclopsFireData(NitroxId fireId, NitroxId cyclopsId, CyclopsRooms room, int nodeIndex)

NitroxModel-Subnautica/DataStructures/GameLogic/CyclopsModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public class CyclopsModel : VehicleModel
3333
[ProtoMember(7)]
3434
public CyclopsMotorMode.CyclopsMotorModes EngineMode { get; set; }
3535

36-
public CyclopsModel()
36+
protected CyclopsModel()
3737
{
38-
38+
// Constructor for serialization. Has to be "protected" for json serialization.
3939
}
4040

4141
public CyclopsModel(NitroxModel.DataStructures.GameLogic.NitroxTechType techType, NitroxId id, NitroxVector3 position, NitroxQuaternion rotation, List<InteractiveChildObjectIdentifier> interactiveChildIdentifiers, Optional<NitroxId> dockingBayId, string name, NitroxVector3[] hsb, float health) : base(techType, id, position, rotation, interactiveChildIdentifiers, dockingBayId, name, hsb, health)

NitroxModel-Subnautica/DataStructures/GameLogic/ExoSuitMovementData.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ public class ExosuitMovementData : VehicleMovementData
1515
[ProtoMember(2)]
1616
public NitroxVector3 RightAimTarget { get; }
1717

18-
public ExosuitMovementData()
18+
protected ExosuitMovementData()
1919
{
20-
// For serialization purposes
20+
// Constructor for serialization. Has to be "protected" for json serialization.
2121
}
2222

2323
public ExosuitMovementData(NitroxModel.DataStructures.GameLogic.NitroxTechType techType, NitroxId id, NitroxVector3 position, NitroxQuaternion rotation, NitroxVector3 velocity, NitroxVector3 angularVelocity, float steeringWheelYaw, float steeringWheelPitch, bool appliedThrottle,

NitroxModel-Subnautica/DataStructures/GameLogic/ExosuitModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ public class ExosuitModel : VehicleModel
1818
[ProtoMember(11)]
1919
public NitroxId RightArmId { get; }
2020

21-
public ExosuitModel()
21+
protected ExosuitModel()
2222
{
23-
23+
// Constructor for serialization. Has to be "protected" for json serialization.
2424
}
2525

2626
public ExosuitModel(NitroxModel.DataStructures.GameLogic.NitroxTechType techType, NitroxId id, NitroxVector3 position, NitroxQuaternion rotation, List<InteractiveChildObjectIdentifier> interactiveChildIdentifiers, Optional<NitroxId> dockingBayId, string name, NitroxVector3[] hsb, float health) : base (techType, id, position, rotation, interactiveChildIdentifiers, dockingBayId, name, hsb, health)

0 commit comments

Comments
 (0)