mirror of
https://github.com/4sval/FModel.git
synced 2026-03-22 01:34:37 -05:00
added universal challenges watermark + crash fix
This commit is contained in:
parent
4c80b547ff
commit
a257f4fbde
|
|
@ -5,7 +5,7 @@
|
|||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{8FABCD3A-9D55-4B54-B237-B259D815DEB8}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>FModel</RootNamespace>
|
||||
<AssemblyName>FModel</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
|
||||
|
|
@ -91,6 +91,7 @@
|
|||
<Compile Include="Parser\Challenges\QuestParser.cs" />
|
||||
<Compile Include="Parser\FeaturedParser.cs" />
|
||||
<Compile Include="Parser\ItemIDParser.cs" />
|
||||
<Compile Include="Parser\Meshes\MeshesParser.cs" />
|
||||
<Compile Include="Parser\RenderSwitchMaterial.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ namespace FModel
|
|||
{
|
||||
InitializeComponent();
|
||||
|
||||
treeView1.Sort();
|
||||
//REMOVE SPACE CAUSED BY SIZING GRIP
|
||||
statusStrip1.Padding = new Padding(statusStrip1.Padding.Left, statusStrip1.Padding.Top, statusStrip1.Padding.Left, statusStrip1.Padding.Bottom);
|
||||
|
||||
|
|
@ -1215,22 +1216,29 @@ namespace FModel
|
|||
updateConsole("Parsing " + currentUsedItem + "...", Color.FromArgb(255, 244, 132, 66), "Waiting");
|
||||
for (int i = 0; i < ItemID.Length; i++)
|
||||
{
|
||||
if (Properties.Settings.Default.createIconForCosmetics == true && (ItemID[i].ExportType.Contains("Athena") && ItemID[i].ExportType.Contains("Item") && ItemID[i].ExportType.Contains("Definition")))
|
||||
createItemIcon(ItemID[i], true);
|
||||
else if (Properties.Settings.Default.createIconForConsumablesWeapons == true && (ItemID[i].ExportType.Contains("FortWeaponRangedItemDefinition") || ItemID[i].ExportType.Contains("FortWeaponMeleeItemDefinition")))
|
||||
createItemIcon(ItemID[i], false, true);
|
||||
else if(Properties.Settings.Default.createIconForTraps == true && (ItemID[i].ExportType.Contains("FortTrapItemDefinition") || ItemID[i].ExportType.Contains("FortContextTrapItemDefinition")))
|
||||
createItemIcon(ItemID[i]);
|
||||
else if(Properties.Settings.Default.createIconForVariants == true && (ItemID[i].ExportType == "FortVariantTokenType"))
|
||||
createItemIcon(ItemID[i], false, false, true);
|
||||
else if(ItemID[i].ExportType == "FortChallengeBundleItemDefinition")
|
||||
createChallengesIcon(ItemID[i], theParsedJSON, questJSON);
|
||||
else if(ItemID[i].ExportType == "Texture2D")
|
||||
convertTexture2D();
|
||||
else if(ItemID[i].ExportType == "SoundWave")
|
||||
convertSoundWave();
|
||||
else
|
||||
updateConsole(currentUsedItem + " successfully extracted", Color.FromArgb(255, 66, 244, 66), "Success");
|
||||
try
|
||||
{
|
||||
if (Properties.Settings.Default.createIconForCosmetics == true && (ItemID[i].ExportType.Contains("Athena") && ItemID[i].ExportType.Contains("Item") && ItemID[i].ExportType.Contains("Definition")))
|
||||
createItemIcon(ItemID[i], true);
|
||||
else if (Properties.Settings.Default.createIconForConsumablesWeapons == true && (ItemID[i].ExportType.Contains("FortWeaponRangedItemDefinition") || ItemID[i].ExportType.Contains("FortWeaponMeleeItemDefinition")))
|
||||
createItemIcon(ItemID[i], false, true);
|
||||
else if (Properties.Settings.Default.createIconForTraps == true && (ItemID[i].ExportType.Contains("FortTrapItemDefinition") || ItemID[i].ExportType.Contains("FortContextTrapItemDefinition")))
|
||||
createItemIcon(ItemID[i]);
|
||||
else if (Properties.Settings.Default.createIconForVariants == true && (ItemID[i].ExportType == "FortVariantTokenType"))
|
||||
createItemIcon(ItemID[i], false, false, true);
|
||||
else if (ItemID[i].ExportType == "FortChallengeBundleItemDefinition")
|
||||
createChallengesIcon(ItemID[i], theParsedJSON, questJSON);
|
||||
else if (ItemID[i].ExportType == "Texture2D")
|
||||
convertTexture2D();
|
||||
else if (ItemID[i].ExportType == "SoundWave")
|
||||
convertSoundWave();
|
||||
else
|
||||
updateConsole(currentUsedItem + " successfully extracted", Color.FromArgb(255, 66, 244, 66), "Success");
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void createItemIcon(Parser.Items.ItemsIDParser theItem, bool athIteDef = false, bool consAndWeap = false, bool variant = false)
|
||||
|
|
@ -2067,6 +2075,8 @@ namespace FModel
|
|||
AppendText("DisplayName ", Color.SteelBlue);
|
||||
AppendText("found", Color.Black, true);
|
||||
} //NAME
|
||||
g.FillRectangle(new SolidBrush(Color.FromArgb(100, 0, 0, 0)), new Rectangle(0, iamY + 240, bmp.Width, 40));
|
||||
g.DrawString(theItem.DisplayName + " Generated using FModel & JohnWickParser - " + DateTime.Now, new Font(pfc.Families[0], 20), new SolidBrush(Color.FromArgb(150, 255, 255, 255)), new Point(bmp.Width / 2, iamY + 250), centeredString);
|
||||
using (Bitmap bmp2 = bmp)
|
||||
{
|
||||
var newImg = bmp2.Clone(
|
||||
|
|
|
|||
541
FModel/Parser/Meshes/MeshesParser.cs
Normal file
541
FModel/Parser/Meshes/MeshesParser.cs
Normal file
|
|
@ -0,0 +1,541 @@
|
|||
// <auto-generated />
|
||||
//
|
||||
// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
|
||||
//
|
||||
// using FModel.Parser.Meshes;
|
||||
//
|
||||
// var meshesParser = MeshesParser.FromJson(jsonString);
|
||||
|
||||
namespace FModel.Parser.Meshes
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Globalization;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
public partial class MeshesParser
|
||||
{
|
||||
[JsonProperty("super_object")]
|
||||
public SuperObject SuperObject { get; set; }
|
||||
|
||||
[JsonProperty("imported_bounds")]
|
||||
public ImportedBounds ImportedBounds { get; set; }
|
||||
|
||||
[JsonProperty("materials")]
|
||||
public Material[] Materials { get; set; }
|
||||
|
||||
[JsonProperty("ref_skeleton")]
|
||||
public RefSkeleton RefSkeleton { get; set; }
|
||||
|
||||
[JsonProperty("lod_models")]
|
||||
public LodModel[] LodModels { get; set; }
|
||||
}
|
||||
|
||||
public partial class ImportedBounds
|
||||
{
|
||||
[JsonProperty("origin")]
|
||||
public BoxExtend Origin { get; set; }
|
||||
|
||||
[JsonProperty("box_extend")]
|
||||
public BoxExtend BoxExtend { get; set; }
|
||||
|
||||
[JsonProperty("sphere_radius")]
|
||||
public double SphereRadius { get; set; }
|
||||
}
|
||||
|
||||
public partial class BoxExtend
|
||||
{
|
||||
[JsonProperty("x")]
|
||||
public double X { get; set; }
|
||||
|
||||
[JsonProperty("y")]
|
||||
public double Y { get; set; }
|
||||
|
||||
[JsonProperty("z")]
|
||||
public double Z { get; set; }
|
||||
|
||||
[JsonProperty("w", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public double? W { get; set; }
|
||||
}
|
||||
|
||||
public partial class LodModel
|
||||
{
|
||||
[JsonProperty("sections")]
|
||||
public Section[] Sections { get; set; }
|
||||
|
||||
[JsonProperty("indices")]
|
||||
public Indices Indices { get; set; }
|
||||
|
||||
[JsonProperty("active_bone_indices")]
|
||||
public long[] ActiveBoneIndices { get; set; }
|
||||
|
||||
[JsonProperty("required_bones")]
|
||||
public long[] RequiredBones { get; set; }
|
||||
|
||||
[JsonProperty("position_vertex_buffer")]
|
||||
public PositionVertexBuffer PositionVertexBuffer { get; set; }
|
||||
|
||||
[JsonProperty("static_mesh_vertex_buffer")]
|
||||
public StaticMeshVertexBuffer StaticMeshVertexBuffer { get; set; }
|
||||
|
||||
[JsonProperty("skin_weight_vertex_buffer")]
|
||||
public SkinWeightVertexBuffer SkinWeightVertexBuffer { get; set; }
|
||||
|
||||
[JsonProperty("colour_vertex_buffer")]
|
||||
public object ColourVertexBuffer { get; set; }
|
||||
}
|
||||
|
||||
public partial class Indices
|
||||
{
|
||||
[JsonProperty("Indices16")]
|
||||
public long[] Indices16 { get; set; }
|
||||
}
|
||||
|
||||
public partial class PositionVertexBuffer
|
||||
{
|
||||
[JsonProperty("verts")]
|
||||
public BoxExtend[] Verts { get; set; }
|
||||
|
||||
[JsonProperty("stride")]
|
||||
public long Stride { get; set; }
|
||||
|
||||
[JsonProperty("num_verts")]
|
||||
public long NumVerts { get; set; }
|
||||
}
|
||||
|
||||
public partial class Section
|
||||
{
|
||||
[JsonProperty("material_index")]
|
||||
public long MaterialIndex { get; set; }
|
||||
|
||||
[JsonProperty("base_index")]
|
||||
public long BaseIndex { get; set; }
|
||||
|
||||
[JsonProperty("num_triangles")]
|
||||
public long NumTriangles { get; set; }
|
||||
|
||||
[JsonProperty("base_vertex_index")]
|
||||
public long BaseVertexIndex { get; set; }
|
||||
|
||||
[JsonProperty("cloth_mapping_data")]
|
||||
public object[] ClothMappingData { get; set; }
|
||||
|
||||
[JsonProperty("bone_map")]
|
||||
public long[] BoneMap { get; set; }
|
||||
|
||||
[JsonProperty("num_vertices")]
|
||||
public long NumVertices { get; set; }
|
||||
|
||||
[JsonProperty("max_bone_influences")]
|
||||
public long MaxBoneInfluences { get; set; }
|
||||
|
||||
[JsonProperty("clothing_data")]
|
||||
public ClothingData ClothingData { get; set; }
|
||||
|
||||
[JsonProperty("disabled")]
|
||||
public bool Disabled { get; set; }
|
||||
}
|
||||
|
||||
public partial class ClothingData
|
||||
{
|
||||
[JsonProperty("asset_guid")]
|
||||
public string AssetGuid { get; set; }
|
||||
|
||||
[JsonProperty("asset_lod_index")]
|
||||
public long AssetLodIndex { get; set; }
|
||||
}
|
||||
|
||||
public partial class SkinWeightVertexBuffer
|
||||
{
|
||||
[JsonProperty("weights")]
|
||||
public Weight[] Weights { get; set; }
|
||||
|
||||
[JsonProperty("num_vertices")]
|
||||
public long NumVertices { get; set; }
|
||||
}
|
||||
|
||||
public partial class Weight
|
||||
{
|
||||
[JsonProperty("bone_index")]
|
||||
public long[] BoneIndex { get; set; }
|
||||
|
||||
[JsonProperty("bone_weight")]
|
||||
public long[] BoneWeight { get; set; }
|
||||
}
|
||||
|
||||
public partial class StaticMeshVertexBuffer
|
||||
{
|
||||
[JsonProperty("num_tex_coords")]
|
||||
public long NumTexCoords { get; set; }
|
||||
|
||||
[JsonProperty("num_vertices")]
|
||||
public long NumVertices { get; set; }
|
||||
|
||||
[JsonProperty("tangents")]
|
||||
public Tangents Tangents { get; set; }
|
||||
|
||||
[JsonProperty("uvs")]
|
||||
public Uvs Uvs { get; set; }
|
||||
}
|
||||
|
||||
public partial class Tangents
|
||||
{
|
||||
[JsonProperty("Low")]
|
||||
public TangentsLow[] Low { get; set; }
|
||||
}
|
||||
|
||||
public partial class TangentsLow
|
||||
{
|
||||
[JsonProperty("normal")]
|
||||
public BoxExtend Normal { get; set; }
|
||||
|
||||
[JsonProperty("tangent")]
|
||||
public BoxExtend Tangent { get; set; }
|
||||
}
|
||||
|
||||
public partial class Uvs
|
||||
{
|
||||
[JsonProperty("Low")]
|
||||
public UvsLow[] Low { get; set; }
|
||||
}
|
||||
|
||||
public partial class UvsLow
|
||||
{
|
||||
[JsonProperty("value")]
|
||||
public Value Value { get; set; }
|
||||
}
|
||||
|
||||
public partial class Value
|
||||
{
|
||||
[JsonProperty("x")]
|
||||
public long X { get; set; }
|
||||
|
||||
[JsonProperty("y")]
|
||||
public long Y { get; set; }
|
||||
}
|
||||
|
||||
public partial class Material
|
||||
{
|
||||
[JsonProperty("material_interface")]
|
||||
public string MaterialInterface { get; set; }
|
||||
|
||||
[JsonProperty("material_slot_name")]
|
||||
public string MaterialSlotName { get; set; }
|
||||
|
||||
[JsonProperty("uv_channel_data")]
|
||||
public UvChannelData UvChannelData { get; set; }
|
||||
}
|
||||
|
||||
public partial class UvChannelData
|
||||
{
|
||||
[JsonProperty("initialised")]
|
||||
public bool Initialised { get; set; }
|
||||
|
||||
[JsonProperty("override_densities")]
|
||||
public bool OverrideDensities { get; set; }
|
||||
|
||||
[JsonProperty("local_uv_densities")]
|
||||
public double[] LocalUvDensities { get; set; }
|
||||
}
|
||||
|
||||
public partial class RefSkeleton
|
||||
{
|
||||
[JsonProperty("ref_bone_info")]
|
||||
public RefBoneInfo[] RefBoneInfo { get; set; }
|
||||
|
||||
[JsonProperty("ref_bone_pose")]
|
||||
public RefBonePose[] RefBonePose { get; set; }
|
||||
|
||||
[JsonProperty("name_to_index")]
|
||||
public NameToIndex[][] NameToIndex { get; set; }
|
||||
}
|
||||
|
||||
public partial class RefBoneInfo
|
||||
{
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[JsonProperty("parent_index")]
|
||||
public long ParentIndex { get; set; }
|
||||
}
|
||||
|
||||
public partial class RefBonePose
|
||||
{
|
||||
[JsonProperty("rotation")]
|
||||
public BoxExtend Rotation { get; set; }
|
||||
|
||||
[JsonProperty("translation")]
|
||||
public BoxExtend Translation { get; set; }
|
||||
|
||||
[JsonProperty("scale_3d")]
|
||||
public BoxExtend Scale3D { get; set; }
|
||||
}
|
||||
|
||||
public partial class SuperObject
|
||||
{
|
||||
[JsonProperty("export_type")]
|
||||
public string ExportType { get; set; }
|
||||
|
||||
[JsonProperty("Skeleton")]
|
||||
public string Skeleton { get; set; }
|
||||
|
||||
[JsonProperty("LODInfo")]
|
||||
public LodInfo[] LodInfo { get; set; }
|
||||
|
||||
[JsonProperty("MinLod")]
|
||||
public MinLod MinLod { get; set; }
|
||||
|
||||
[JsonProperty("bHasBeenSimplified")]
|
||||
public bool BHasBeenSimplified { get; set; }
|
||||
|
||||
[JsonProperty("SamplingInfo")]
|
||||
public SamplingInfo SamplingInfo { get; set; }
|
||||
}
|
||||
|
||||
public partial class LodInfo
|
||||
{
|
||||
[JsonProperty("ScreenSize")]
|
||||
public MinLod ScreenSize { get; set; }
|
||||
|
||||
[JsonProperty("LODHysteresis")]
|
||||
public double LodHysteresis { get; set; }
|
||||
|
||||
[JsonProperty("LODMaterialMap")]
|
||||
public object[] LodMaterialMap { get; set; }
|
||||
|
||||
[JsonProperty("ReductionSettings")]
|
||||
public ReductionSettings ReductionSettings { get; set; }
|
||||
|
||||
[JsonProperty("BonesToRemove")]
|
||||
public object[] BonesToRemove { get; set; }
|
||||
|
||||
[JsonProperty("BonesToPrioritize")]
|
||||
public object[] BonesToPrioritize { get; set; }
|
||||
|
||||
[JsonProperty("WeightOfPrioritization")]
|
||||
public long WeightOfPrioritization { get; set; }
|
||||
|
||||
[JsonProperty("BakePose")]
|
||||
[JsonConverter(typeof(ParseStringConverter))]
|
||||
public long BakePose { get; set; }
|
||||
|
||||
[JsonProperty("BakePoseOverride")]
|
||||
[JsonConverter(typeof(ParseStringConverter))]
|
||||
public long BakePoseOverride { get; set; }
|
||||
|
||||
[JsonProperty("SourceImportFilename")]
|
||||
public string SourceImportFilename { get; set; }
|
||||
|
||||
[JsonProperty("bHasBeenSimplified")]
|
||||
public bool BHasBeenSimplified { get; set; }
|
||||
|
||||
[JsonProperty("bHasPerLODVertexColors")]
|
||||
public bool BHasPerLodVertexColors { get; set; }
|
||||
|
||||
[JsonProperty("bAllowCPUAccess")]
|
||||
public bool BAllowCpuAccess { get; set; }
|
||||
|
||||
[JsonProperty("bSupportUniformlyDistributedSampling")]
|
||||
public bool BSupportUniformlyDistributedSampling { get; set; }
|
||||
}
|
||||
|
||||
public partial class ReductionSettings
|
||||
{
|
||||
[JsonProperty("TerminationCriterion")]
|
||||
public string TerminationCriterion { get; set; }
|
||||
|
||||
[JsonProperty("NumOfTrianglesPercentage")]
|
||||
public double NumOfTrianglesPercentage { get; set; }
|
||||
|
||||
[JsonProperty("NumOfVertPercentage")]
|
||||
public double NumOfVertPercentage { get; set; }
|
||||
|
||||
[JsonProperty("MaxNumOfTriangles")]
|
||||
public long MaxNumOfTriangles { get; set; }
|
||||
|
||||
[JsonProperty("MaxNumOfVerts")]
|
||||
public long MaxNumOfVerts { get; set; }
|
||||
|
||||
[JsonProperty("MaxDeviationPercentage")]
|
||||
public double MaxDeviationPercentage { get; set; }
|
||||
|
||||
[JsonProperty("ReductionMethod")]
|
||||
public string ReductionMethod { get; set; }
|
||||
|
||||
[JsonProperty("SilhouetteImportance")]
|
||||
public string SilhouetteImportance { get; set; }
|
||||
|
||||
[JsonProperty("TextureImportance")]
|
||||
public string TextureImportance { get; set; }
|
||||
|
||||
[JsonProperty("ShadingImportance")]
|
||||
public string ShadingImportance { get; set; }
|
||||
|
||||
[JsonProperty("SkinningImportance")]
|
||||
public string SkinningImportance { get; set; }
|
||||
|
||||
[JsonProperty("bRemapMorphTargets")]
|
||||
public bool BRemapMorphTargets { get; set; }
|
||||
|
||||
[JsonProperty("bRecalcNormals")]
|
||||
public bool BRecalcNormals { get; set; }
|
||||
|
||||
[JsonProperty("WeldingThreshold")]
|
||||
public double WeldingThreshold { get; set; }
|
||||
|
||||
[JsonProperty("NormalsThreshold")]
|
||||
public long NormalsThreshold { get; set; }
|
||||
|
||||
[JsonProperty("MaxBonesPerVertex")]
|
||||
public long MaxBonesPerVertex { get; set; }
|
||||
|
||||
[JsonProperty("bEnforceBoneBoundaries")]
|
||||
public bool BEnforceBoneBoundaries { get; set; }
|
||||
|
||||
[JsonProperty("VolumeImportance")]
|
||||
public long VolumeImportance { get; set; }
|
||||
|
||||
[JsonProperty("bLockEdges")]
|
||||
public bool BLockEdges { get; set; }
|
||||
|
||||
[JsonProperty("BaseLOD")]
|
||||
public long BaseLod { get; set; }
|
||||
}
|
||||
|
||||
public partial class MinLod
|
||||
{
|
||||
[JsonProperty("cooked")]
|
||||
public bool Cooked { get; set; }
|
||||
|
||||
[JsonProperty("value")]
|
||||
public double Value { get; set; }
|
||||
}
|
||||
|
||||
public partial class SamplingInfo
|
||||
{
|
||||
[JsonProperty("BuiltData")]
|
||||
public BuiltData BuiltData { get; set; }
|
||||
}
|
||||
|
||||
public partial class BuiltData
|
||||
{
|
||||
[JsonProperty("WholeMeshBuiltData")]
|
||||
public WholeMeshBuiltDatum[] WholeMeshBuiltData { get; set; }
|
||||
}
|
||||
|
||||
public partial class WholeMeshBuiltDatum
|
||||
{
|
||||
[JsonProperty("prob")]
|
||||
public object[] Prob { get; set; }
|
||||
|
||||
[JsonProperty("alias")]
|
||||
public object[] Alias { get; set; }
|
||||
|
||||
[JsonProperty("total_weight")]
|
||||
public long TotalWeight { get; set; }
|
||||
}
|
||||
|
||||
public partial struct NameToIndex
|
||||
{
|
||||
public long? Integer;
|
||||
public string String;
|
||||
|
||||
public static implicit operator NameToIndex(long Integer) => new NameToIndex { Integer = Integer };
|
||||
public static implicit operator NameToIndex(string String) => new NameToIndex { String = String };
|
||||
}
|
||||
|
||||
public partial class MeshesParser
|
||||
{
|
||||
public static MeshesParser[] FromJson(string json) => JsonConvert.DeserializeObject<MeshesParser[]>(json, FModel.Parser.Meshes.Converter.Settings);
|
||||
}
|
||||
|
||||
public static class Serialize
|
||||
{
|
||||
public static string ToJson(this MeshesParser[] self) => JsonConvert.SerializeObject(self, FModel.Parser.Meshes.Converter.Settings);
|
||||
}
|
||||
|
||||
internal static class Converter
|
||||
{
|
||||
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
|
||||
{
|
||||
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
|
||||
DateParseHandling = DateParseHandling.None,
|
||||
Converters =
|
||||
{
|
||||
NameToIndexConverter.Singleton,
|
||||
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
internal class NameToIndexConverter : JsonConverter
|
||||
{
|
||||
public override bool CanConvert(Type t) => t == typeof(NameToIndex) || t == typeof(NameToIndex?);
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
switch (reader.TokenType)
|
||||
{
|
||||
case JsonToken.Integer:
|
||||
var integerValue = serializer.Deserialize<long>(reader);
|
||||
return new NameToIndex { Integer = integerValue };
|
||||
case JsonToken.String:
|
||||
case JsonToken.Date:
|
||||
var stringValue = serializer.Deserialize<string>(reader);
|
||||
return new NameToIndex { String = stringValue };
|
||||
}
|
||||
throw new Exception("Cannot unmarshal type NameToIndex");
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
|
||||
{
|
||||
var value = (NameToIndex)untypedValue;
|
||||
if (value.Integer != null)
|
||||
{
|
||||
serializer.Serialize(writer, value.Integer.Value);
|
||||
return;
|
||||
}
|
||||
if (value.String != null)
|
||||
{
|
||||
serializer.Serialize(writer, value.String);
|
||||
return;
|
||||
}
|
||||
throw new Exception("Cannot marshal type NameToIndex");
|
||||
}
|
||||
|
||||
public static readonly NameToIndexConverter Singleton = new NameToIndexConverter();
|
||||
}
|
||||
|
||||
internal class ParseStringConverter : JsonConverter
|
||||
{
|
||||
public override bool CanConvert(Type t) => t == typeof(long) || t == typeof(long?);
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
if (reader.TokenType == JsonToken.Null) return null;
|
||||
var value = serializer.Deserialize<string>(reader);
|
||||
long l;
|
||||
if (Int64.TryParse(value, out l))
|
||||
{
|
||||
return l;
|
||||
}
|
||||
throw new Exception("Cannot unmarshal type long");
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
|
||||
{
|
||||
if (untypedValue == null)
|
||||
{
|
||||
serializer.Serialize(writer, null);
|
||||
return;
|
||||
}
|
||||
var value = (long)untypedValue;
|
||||
serializer.Serialize(writer, value.ToString());
|
||||
return;
|
||||
}
|
||||
|
||||
public static readonly ParseStringConverter Singleton = new ParseStringConverter();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user