Skip to content

Commit

Permalink
More previews and proper README
Browse files Browse the repository at this point in the history
  • Loading branch information
cengelha committed Oct 31, 2022
1 parent 97bb1f1 commit dad4646
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 39 deletions.
41 changes: 28 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,44 @@
The `libNOM` label is a collection of .NET class libraries originally developed
and used in [NomNom](https://github.com/zencq/NomNom), a savegame editor for [No Man's Sky](https://www.nomanssky.com/).

`libNOM.collect` can be used to backup and restore your collections.
`libNOM.collect` can be used to backup and restore collections like Starships and
Companions to bypass the in-game limits.

## Getting Started

TODO
All commonly used formats are supported. This includes those used by [goatfungus](https://github.com/goatfungus/NMSSaveEditor),
[NMS Companion](https://www.nexusmods.com/nomanssky/mods/1879), and the [NMS Ship Editor/Colorizer/Customizer](https://www.patreon.com/posts/65130473).

There is also a new version of the NMS Companion format that unifies the
file content (including features such as marking as favorite) and adds missing entries
like the customization.

### Usage

TODO
Create a collection and add/remove items.
```csharp
// Export
var format = FormatEnum.N3C2;
var json = container.GetJsonObject();
var path = "...";
var path = "..."; // where the collection is stored
var companionCollection = new CompanionCollection(path);

// Adding a new item to the collection can be done via a JSON string or reading from a file.
var jsonString = "..."; // JSON string in one of the supported formats (depends on collection type)
companionCollection.AddOrUpdate(jsonString, libNOM.collect.Enums.FormatEnum.Kaii, out var stringCompanion);

new Outfit().Export(path, format, json); // export current
var pathToFile = "...";
companionCollection.AddOrUpdate(pathToFile, out var fileCompanion); // format will be automatically detected
// Remove
companionCollection.Remove(fileCompanion);
```

TODO
Backup an item.
```csharp
// Import
var path "...";
// Export
var json = container.GetJsonObject(); // JObject of the entire save
var format = libNOM.collect.Enums.FormatEnum.Kaii; // one of the supported formats (depends on collection type)
var path = "..."; // where the collection is stored
var outfit = new Outfit().Import(path);
stringCompanion.Export(json, format, path);
```

## License
Expand All @@ -51,8 +65,9 @@ file for details.

Thanks to the following people for their help in one way or another.

* [Dr. Kaii](https://www.nexusmods.com/nomanssky/mods/1879) - Collaboration to create a common import/export format (N3C) as well as providing some code
* [Dr. Kaii](https://www.nexusmods.com/nomanssky/mods/1879) - Collaboration for the import/export format as well as providing some code

## Dependencies

* [libNOM.map](https://github.com/zencq/libNOM.map) - Obfuscation and deobfuscation
* [Newtonsoft.Json](https://www.nuget.org/packages/Newtonsoft.Json/) - Handle JSON objects
8 changes: 6 additions & 2 deletions libNOM.collect/Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ protected override string GetTag(JObject json, int index)

/// <summary>
/// ...
/// Note: NMS Base supports up to 6 previews/thumbnails.
/// </summary>
public class Base : CollectionItem
{
Expand Down Expand Up @@ -417,7 +416,12 @@ protected override byte[] ExportKaii()
{ "Galaxy", galacticAddress.GetGalaxy() },
{ "GlyphsString", galacticAddress.GetGlyphsString() },
{ nameof(Starred), Starred },
{ "Thumbnail", Preview },
{ "Thumbnail", Preview?.ToBase64String() },
{ "Thumbnail2", Preview2?.ToBase64String() },
{ "Thumbnail3", Preview3?.ToBase64String() },
{ "Thumbnail4", Preview4?.ToBase64String() },
{ "Thumbnail5", Preview5?.ToBase64String() },
{ "Thumbnail6", Preview6?.ToBase64String() },
};

// Return
Expand Down
20 changes: 19 additions & 1 deletion libNOM.collect/ByteBeat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,25 @@ protected override byte[] ExportKaii()
{ "OriginalAuthorPlatform", Data["Song"]!.SelectToken("d2f")!.Value<string>() },
{ "OriginalName", Data["Song"]!.SelectToken("NKm")!.Value<string>() },
{ nameof(Starred), Starred },
{ "Track", Preview },
{ "Track", Preview?.ToBase64String() },
};

// Return
return result.Serialize().GetBytes();
}

protected override byte[] ExportStandard()
{
// Prepare
Obfuscate();
var result = new Dictionary<string, object?>
{
{ nameof(Data), Data },
{ nameof(DateCreated), DateCreated.ToUniversalTime() },
{ nameof(Description), Description },
{ "FileVersion", 2 },
{ nameof(Preview), Preview?.ToBase64String() },
{ nameof(Starred), Starred },
};

// Return
Expand Down
17 changes: 16 additions & 1 deletion libNOM.collect/CollectionItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ public virtual string Name

public byte[]? Preview { get; set; }

public byte[]? Preview2 { get; set; }

public byte[]? Preview3 { get; set; }

public byte[]? Preview4 { get; set; }

public byte[]? Preview5 { get; set; }

public byte[]? Preview6 { get; set; }

public bool Starred { get; set; } // = false;

// //
Expand Down Expand Up @@ -165,7 +175,12 @@ protected virtual byte[] ExportStandard()
{ nameof(DateCreated), DateCreated.ToUniversalTime() },
{ nameof(Description), Description },
{ "FileVersion", 2 },
{ nameof(Preview), Preview.ToBase64String() },
{ nameof(Preview), Preview?.ToBase64String() },
{ nameof(Preview2), Preview2?.ToBase64String() },
{ nameof(Preview3), Preview3?.ToBase64String() },
{ nameof(Preview4), Preview4?.ToBase64String() },
{ nameof(Preview5), Preview5?.ToBase64String() },
{ nameof(Preview6), Preview6?.ToBase64String() },
{ nameof(Starred), Starred },
};

Expand Down
8 changes: 6 additions & 2 deletions libNOM.collect/Companion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ protected override string GetTag(JObject json, int index)

/// <summary>
/// ...
/// Note: NMS Companion supports up to 6 previews/thumbnails.
/// </summary>
public class Companion : CollectionItem
{
Expand Down Expand Up @@ -257,7 +256,12 @@ protected override byte[] ExportKaii()
{ "GalacticAddress", universeAddress },
{ "Galaxy", universeAddress.GetGalaxy() },
{ "GlyphsString", universeAddress.GetGlyphsString() },
{ "Thumbnail", Preview },
{ "Thumbnail", Preview?.ToBase64String() },
{ "Thumbnail2", Preview2?.ToBase64String() },
{ "Thumbnail3", Preview3?.ToBase64String() },
{ "Thumbnail4", Preview4?.ToBase64String() },
{ "Thumbnail5", Preview5?.ToBase64String() },
{ "Thumbnail6", Preview6?.ToBase64String() },
};

// Return
Expand Down
5 changes: 1 addition & 4 deletions libNOM.collect/Extensions/IEnumarable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,8 @@ internal static string GetCount(this JArray self)
return self.Count.ToString("D3");
}

internal static string? ToBase64String(this byte[]? self)
internal static string ToBase64String(this byte[] self)
{
if (self is null)
return null;

return Convert.ToBase64String(self);
}
}
8 changes: 6 additions & 2 deletions libNOM.collect/Freighter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ protected override string GetTag(JObject json, int index)

/// <summary>
/// ...
/// Note: NMS Companion supports up to 6 previews/thumbnails.
/// </summary>
public class Freighter : CollectionItem
{
Expand Down Expand Up @@ -284,7 +283,12 @@ protected override byte[] ExportKaii()
},
{ nameof(Description), Description },
{ "FileVersion", 1 },
{ "Thumbnail", Preview },
{ "Thumbnail", Preview?.ToBase64String() },
{ "Thumbnail2", Preview2?.ToBase64String() },
{ "Thumbnail3", Preview3?.ToBase64String() },
{ "Thumbnail4", Preview4?.ToBase64String() },
{ "Thumbnail5", Preview5?.ToBase64String() },
{ "Thumbnail6", Preview6?.ToBase64String() },
};

// Return
Expand Down
8 changes: 6 additions & 2 deletions libNOM.collect/Frigate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ protected override string GetTag(JObject json, int index)

/// <summary>
/// ...
/// Note: NMS Companion supports up to 6 previews/thumbnails.
/// </summary>
public class Frigate : CollectionItem
{
Expand Down Expand Up @@ -208,7 +207,12 @@ protected override byte[] ExportKaii()
{ "Frigate", Data["Frigate"] },
{ nameof(Description), Description },
{ "FileVersion", 1 },
{ "Thumbnail", Preview },
{ "Thumbnail", Preview?.ToBase64String() },
{ "Thumbnail2", Preview2?.ToBase64String() },
{ "Thumbnail3", Preview3?.ToBase64String() },
{ "Thumbnail4", Preview4?.ToBase64String() },
{ "Thumbnail5", Preview5?.ToBase64String() },
{ "Thumbnail6", Preview6?.ToBase64String() },
};

// Return
Expand Down
8 changes: 6 additions & 2 deletions libNOM.collect/Place.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ protected override string GetTag(JObject json, int index)

/// <summary>
/// ...
/// Note: NMS Companion supports up to 6 previews/thumbnails.
/// </summary>
public class Place : CollectionItem
{
Expand Down Expand Up @@ -288,7 +287,12 @@ protected override byte[] ExportKaii()
{ "Galaxy", universeAddress.GetGalaxy() },
{ "GlyphsString", universeAddress.GetGlyphsString() },
{ nameof(Starred), Starred },
{ "Thumbnail", Preview },
{ "Thumbnail", Preview?.ToBase64String() },
{ "Thumbnail2", Preview2?.ToBase64String() },
{ "Thumbnail3", Preview3?.ToBase64String() },
{ "Thumbnail4", Preview4?.ToBase64String() },
{ "Thumbnail5", Preview5?.ToBase64String() },
{ "Thumbnail6", Preview6?.ToBase64String() },
{ "Type", Data["Type"] },
};

Expand Down
8 changes: 6 additions & 2 deletions libNOM.collect/Settlement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ protected override string GetTag(JObject json, int index)

/// <summary>
/// ...
/// Note: NMS Companion supports up to 6 previews/thumbnails.
/// </summary>
public class Settlement : CollectionItem
{
Expand Down Expand Up @@ -208,7 +207,12 @@ protected override byte[] ExportKaii()
},
{ nameof(Description), Description },
{ "FileVersion", 1 },
{ "Thumbnail", Preview },
{ "Thumbnail", Preview?.ToBase64String() },
{ "Thumbnail2", Preview2?.ToBase64String() },
{ "Thumbnail3", Preview3?.ToBase64String() },
{ "Thumbnail4", Preview4?.ToBase64String() },
{ "Thumbnail5", Preview5?.ToBase64String() },
{ "Thumbnail6", Preview6?.ToBase64String() },
};

// Return
Expand Down
8 changes: 6 additions & 2 deletions libNOM.collect/SquadronPilot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ protected override string GetTag(JObject json, int index)

/// <summary>
/// ...
/// Note: NMS Companion supports up to 6 previews/thumbnails.
/// </summary>
public class SquadronPilot : CollectionItem
{
Expand Down Expand Up @@ -203,7 +202,12 @@ protected override byte[] ExportKaii()
{ "Squadron", Data["Pilot"] },
{ nameof(Description), Description },
{ "FileVersion", 1 },
{ "Thumbnail", Preview },
{ "Thumbnail", Preview?.ToBase64String() },
{ "Thumbnail2", Preview2?.ToBase64String() },
{ "Thumbnail3", Preview3?.ToBase64String() },
{ "Thumbnail4", Preview4?.ToBase64String() },
{ "Thumbnail5", Preview5?.ToBase64String() },
{ "Thumbnail6", Preview6?.ToBase64String() },
};

// Return
Expand Down
8 changes: 6 additions & 2 deletions libNOM.collect/Starship.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ protected override string GetTag(JObject json, int index)

/// <summary>
/// ...
/// Note: NMS Companion supports up to 6 previews/thumbnails.
/// </summary>
public class Starship : CollectionItem
{
Expand Down Expand Up @@ -286,7 +285,12 @@ protected override byte[] ExportKaii()
{ "Colours", Data["Colours"] }, // custom addition by Mjstral (MetaIdea)
{ nameof(Description), Description },
{ "FileVersion", 1 },
{ "Thumbnail", Preview },
{ "Thumbnail", Preview?.ToBase64String() },
{ "Thumbnail2", Preview2?.ToBase64String() },
{ "Thumbnail3", Preview3?.ToBase64String() },
{ "Thumbnail4", Preview4?.ToBase64String() },
{ "Thumbnail5", Preview5?.ToBase64String() },
{ "Thumbnail6", Preview6?.ToBase64String() },
};

// Return
Expand Down
8 changes: 6 additions & 2 deletions libNOM.collect/Vehicle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ protected override string GetTag(JObject json, int index)

/// <summary>
/// ...
/// Note: NMS Companion supports up to 6 previews/thumbnails.
/// </summary>
public class Vehicle : CollectionItem
{
Expand Down Expand Up @@ -266,7 +265,12 @@ protected override byte[] ExportKaii()
{ nameof(Description), Description },
{ "FileVersion", 1 },
{ nameof(Starred), Starred },
{ "Thumbnail", Preview },
{ "Thumbnail", Preview?.ToBase64String() },
{ "Thumbnail2", Preview2?.ToBase64String() },
{ "Thumbnail3", Preview3?.ToBase64String() },
{ "Thumbnail4", Preview4?.ToBase64String() },
{ "Thumbnail5", Preview5?.ToBase64String() },
{ "Thumbnail6", Preview6?.ToBase64String() },
{ "Type", _index },
};

Expand Down
8 changes: 6 additions & 2 deletions libNOM.collect/Weapon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ protected override string GetTag(JObject json, int index)

/// <summary>
/// ...
/// Note: NMS Companion supports up to 6 previews/thumbnails.
/// </summary>
public class Weapon : CollectionItem
{
Expand Down Expand Up @@ -243,7 +242,12 @@ protected override byte[] ExportKaii()
{ "MultiTool", Data["Multitool"] },
{ nameof(Description), Description },
{ "FileVersion", 1 },
{ "Thumbnail", Preview },
{ "Thumbnail", Preview?.ToBase64String() },
{ "Thumbnail2", Preview2?.ToBase64String() },
{ "Thumbnail3", Preview3?.ToBase64String() },
{ "Thumbnail4", Preview4?.ToBase64String() },
{ "Thumbnail5", Preview5?.ToBase64String() },
{ "Thumbnail6", Preview6?.ToBase64String() },
};

// Return
Expand Down

0 comments on commit dad4646

Please sign in to comment.