-
Notifications
You must be signed in to change notification settings - Fork 1
/
Asset.cs
167 lines (137 loc) · 6.33 KB
/
Asset.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
namespace DiscordBot
{
//// A Spore Asset (creation)
public class Asset
{
private int version;
private string typeId;
private string groupId;
private string instanceId;
private string machineId;
private long assetId;
private long parentId;
private string time;
private string username;
private long userId;
private string name;
private string desc;
private string tags;
private int partCount;
public Asset(string filePath)
{
// Extract data to XML file
if (!File.Exists(filePath + ".xml"))
{
Process.Start("python2", "\"C:\\Users\\KyleN\\OneDrive\\Documents\\Spore Files\\PNG Decoder\\spore_decoder_by_ymgve_and_rick.py\" \"" + filePath + "\"");
int timer = 0;
while (!File.Exists(filePath + ".xml") && timer < 1000)
{
Thread.Sleep(1);
timer++;
}
Console.WriteLine($"Decoding took {timer}ms");
}
// Read data from the file
//try
{
using (var reader = new StreamReader(filePath + ".xml", Encoding.GetEncoding("iso-8859-1")))
{
var spore = ReadAssetData(reader, 5);
if (!spore.Equals("spore")) Console.WriteLine("File is not a Spore asset!");
version = Convert.ToInt32(ReadAssetData(reader, 4));
if (version != 5 && version != 6) Console.WriteLine("Asset version is unknown!");
typeId = ReadAssetData(reader, 8);
groupId = ReadAssetData(reader, 8);
instanceId = ReadAssetData(reader, 8);
machineId = ReadAssetData(reader, 8);
assetId = Convert.ToInt64(ReadAssetData(reader, 16), 16);
if (version == 6)
{
parentId = Convert.ToInt64(ReadAssetData(reader, 16), 16);
}
time = ReadAssetData(reader, 16);
var userLength = Convert.ToInt32(ReadAssetData(reader, 2), 16);
username = ReadAssetData(reader, userLength);
userId = Convert.ToInt64(ReadAssetData(reader, 16), 16);
var nameLength = Convert.ToInt32(ReadAssetData(reader, 2), 16);
name = ReadAssetData(reader, nameLength);
var descLength = Convert.ToInt32(ReadAssetData(reader, 3), 16);
desc = ReadAssetData(reader, descLength);
var tagsLength = Convert.ToInt32(ReadAssetData(reader, 2), 16);
tags = ReadAssetData(reader, tagsLength);
// Skip two zeroes
ReadAssetData(reader, 2);
// XML doc
var doc = reader.ReadToEnd();
var partCountIndex = doc.IndexOf("blocks count=") + 14;
var endIndex = doc.IndexOf("\"", partCountIndex) - partCountIndex;
var partCountString = doc.Substring(partCountIndex, endIndex);
partCount = Convert.ToInt32(partCountString);
printInfo();
}
}
//catch (Exception)
{
}
}
private static string ReadAssetData(StreamReader reader, int length)
{
var data = new char[length];
reader.Read(data, 0, data.Length);
return new string(data);
}
public long Id { get => assetId; }
public string Name { get => name; }
public string Author { get => username; }
public long AuthorId { get => userId; }
public string Created { get => time; }
public string Description { get => desc; }
public string Tags { get => tags; }
//public string Type {get;}
//public string Subtype {get;}
//public double Rating {get;}
public long Parent { get => parentId; }
public string SporeWebUrl { get => "http://www.spore.com/sporepedia#qry=sast-" + Id; }
public int PartCount { get => partCount; }
public void printInfo()
{
Console.WriteLine($"{Name} (ID: {Id}) by {Author}");
}
public string getInfo()
{
var url = Id > 0 ? SporeWebUrl : "*Unshared*";
var original = Parent > 0 ? "*Edited Creation*\n" : "";
var desc = Description.Length > 0 ? Description + "\n" : "";
var tags = Tags.Length > 0 ? " - Tags: " + Tags : "";
return $"**{Name}** by {Author}\n{desc}*{PartCount} parts{tags}*\n{original}{url}";
}
public string getInfoAdvanced()
{
return $"Asset ID: {Id}\nAuthor ID: {AuthorId}\nCreated: {Created}\nParent Asset: {Parent}\nPart Count: {PartCount}\nPNG version: {version}\nType ID: {typeId}\nGroup ID: {groupId}\nInstance ID: {instanceId}\nMachine ID: {machineId}";
}
public string getApiUrls()
{
var assetInfo = "http://www.spore.com/rest/asset/" + Id;
var creatureStats = "http://www.spore.com/rest/creature/" + Id;
var subId1 = Id.ToString().Substring(0, 3);
var subId2 = Id.ToString().Substring(3, 3);
var subId3 = Id.ToString().Substring(6, 3);
var xmlModel = $"http://www.spore.com/static/model/{subId1}/{subId2}/{subId3}/{Id}.xml";
var largePng = $"http://www.spore.com/static/image/{subId1}/{subId2}/{subId3}/{Id}_lrg.png";
var smallPng = $"http://www.spore.com/static/thumb/{subId1}/{subId2}/{subId3}/{Id}.png";
return $"Asset Info: {assetInfo}\nCreature Stats: {creatureStats}\nXML Model: {xmlModel}\nLarge PNG: {largePng}\nSmall PNG: {smallPng}";
}
public string getPollinatorUrls()
{
var pollinatorUrl = "http://pollinator.spore.com/pollinator/admin/asset/" + Id;
var validityUrl = "http://pollinator.spore.com/pollinator/admin/validation/" + Id;
return $"Pollinator URL: {pollinatorUrl}\nTest Validity: {validityUrl}";
}
}
}