using System; using System.Collections.Generic; using Newtonsoft.Json; using UnityEngine; public class UnixTimestampConverter : JsonConverter { public override bool CanConvert(Type objectType) { return objectType == typeof(DateTime); } public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { if (reader.Value == null) { return null; // or handle the null value as appropriate for your use case } if (reader.Value is long timestamp) { return new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(timestamp); } else { throw new JsonSerializationException("Expected a long value for Unix timestamp."); } } public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { DateTime dateTime = (DateTime)value; long timestamp = (long)(dateTime - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds; writer.WriteValue(timestamp); } } public class NexusMods : MonoBehaviour { [JsonProperty("Mod")] public Mod ModJSON { get; set; } [JsonProperty("NMProfile")] public NMProfile Profile { get; set; } [JsonProperty("files")] public List NMFiles { get; set; } [JsonProperty("file_updates")] public List UpdatedFiles { get; set; } [JsonProperty("CDNs")] public List CDNs { get; set; } public class NMProfile { [JsonProperty("user_id")] public long UserId { get; set; } [JsonProperty("key")] public string Key { get; set; } [JsonProperty("name")] public string Name { get; set; } [JsonProperty("email")] public string Email { get; set; } [JsonProperty("profile_url")] public string ProfileUrl { get; set; } [JsonProperty("is_supporter")] public bool IsSupporter { get; set; } [JsonProperty("is_premium")] public bool IsPremium { get; set; } } public class Mod { [JsonProperty("name")] public string Name { get; set; } [JsonProperty("summary")] public string Summary { get; set; } [JsonProperty("description")] public string Description { get; set; } [JsonProperty("picture_url")] public string ImageURL { get; set; } [JsonProperty("mod_downloads")] public long Downloads { get; set; } [JsonProperty("mod_unique_downloads")] public long UniqueDownload { get; set; } [JsonProperty("uid")] public long UID { get; set; } [JsonProperty("mod_id")] public long ModID { get; set; } [JsonProperty("game_id")] public long GameID { get; set; } [JsonProperty("allow_rating")] public bool CanRate { get; set; } [JsonProperty("domain_name")] public string GameName { get; set; } [JsonProperty("category_id")] public int CategoryID { get; set; } [JsonProperty("version")] public string Version { get; set; } [JsonProperty("endorsement_count")] public long EndorsmentCount { get; set; } [JsonProperty("created_timestamp")] [JsonConverter(typeof(UnixTimestampConverter))] public DateTime CreatedTimestamp { get; set; } [JsonProperty("created_time")] public DateTime CreatedTime { get; set; } [JsonProperty("updated_timestamp")] [JsonConverter(typeof(UnixTimestampConverter))] public DateTime UpdatedTimestamp { get; set; } [JsonProperty("updated_time")] public DateTime UpdatedTime { get; set; } [JsonProperty("author")] public string Author { get; set; } [JsonProperty("uploaded_by")] public string Uploader { get; set; } [JsonProperty("uploaded_users_profile_url")] public string UploaderProfileURL { get; set; } [JsonProperty("contains_adult_content")] public bool AdultContent { get; set; } [JsonProperty("status")] public string Status { get; set; } [JsonProperty("available")] public bool Available { get; set; } [JsonProperty("user")] public User ModAuthor { get; set; } [JsonProperty("endorsement")] public Endorsement Endorse { get; set; } } public class Files { [JsonProperty("id")] public List Id { get; set; } [JsonProperty("uid")] public long Uid { get; set; } [JsonProperty("file_id")] public long FileId { get; set; } [JsonProperty("name")] public string Name { get; set; } [JsonProperty("version")] public string Version { get; set; } [JsonProperty("category_id")] public int CategoryId { get; set; } [JsonProperty("category_name")] public string CategoryName { get; set; } [JsonProperty("is_primary")] public bool IsPrimary { get; set; } [JsonProperty("size")] public long Size { get; set; } [JsonProperty("file_name")] public string FileName { get; set; } [JsonProperty("uploaded_timestamp")] public long UploadedTimestamp { get; set; } [JsonProperty("uploaded_time")] public string UploadedTime { get; set; } [JsonProperty("mod_version")] public string ModVersion { get; set; } [JsonProperty("external_virus_scan_url")] public string ExternalVirusScanUrl { get; set; } [JsonProperty("description")] public string Description { get; set; } [JsonProperty("size_kb")] public long SizeKb { get; set; } [JsonProperty("size_in_bytes")] public long SizeInBytes { get; set; } [JsonProperty("changelog_html")] public string ChangelogHtml { get; set; } [JsonProperty("content_preview_link")] public string ContentPreviewLink { get; set; } } public class Downloads { [JsonProperty("name")] public string Name { get; set; } [JsonProperty("short_name")] public string ShortName { get; set; } [JsonProperty("URI")] public string Url { get; set; } } public class User { [JsonProperty("member_id")] public long ID { get; set; } [JsonProperty("member_group_id")] public long Group { get; set; } [JsonProperty("name")] public string Name { get; set; } } public class Endorsement { [JsonProperty("endorse_status")] public string Status { get; set; } [JsonProperty("timestamp")] [JsonConverter(typeof(UnixTimestampConverter))] public DateTime? Time { get; set; } [JsonProperty("version")] public long? Version { get; set; } } }