-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHiscore.cs
169 lines (142 loc) · 4.58 KB
/
Hiscore.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
168
169
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;
namespace HiToText
{
abstract class Hiscore
{
protected string[] m_fileNames = null;
protected byte[] m_data = null;
protected int m_numEntries = 0;
protected int[] m_numAltEntries = { 0 };
protected string m_format = "";
protected string[] m_altFormat = { "" };
protected string m_gamesSupported = "";
protected string m_extensionsRequired = "";
protected DateTime m_versionDate = DateTime.MaxValue;
public Hiscore()
{
}
private void ReadData(string[] fileNames)
{
m_fileNames = new string[fileNames.Length];
for (int i = 0; i < fileNames.Length; i++)
{
if (!String.IsNullOrEmpty(fileNames[i]))
{
if (File.Exists(fileNames[i]))
{
m_fileNames[i] = fileNames[i];
AppendData(File.ReadAllBytes(fileNames[i]));
}
}
}
}
private void AppendData(byte[] data)
{
byte[] temp = m_data;
m_data = new byte[data.Length];
if (temp != null)
{
m_data = new byte[temp.Length + data.Length];
for (int i = 0; i < temp.Length; i++)
m_data[i] = temp[i];
for (int j = 0; j < data.Length; j++)
m_data[j + temp.Length] = data[j];
}
else
m_data = data;
}
public abstract string HiToString();
public abstract void EmptyScores();
public abstract void SetHiScore(String[] args);
public virtual void ModifyName(int rank, string score)
{
throw new NotImplementedException("ModifyName is not currently implemented for this game.");
}
public string[] FileNames
{
get { return m_fileNames; }
set { ReadData(value); }
}
public int NumEntries
{
get { return m_numEntries; }
}
public int[] NumAltEntries
{
get { return m_numAltEntries; }
}
public string Format
{
get { return m_format; }
}
public string[] AltFormat
{
get { return m_altFormat; }
}
public string[] AltScoreName
{
get
{
string[] altScoreNames = new string[m_altFormat.Length];
for (int i = 0; i < altScoreNames.Length; i++)
{
int newLineLoc = m_altFormat[i].IndexOf(Environment.NewLine);
altScoreNames[i] = m_altFormat[i].Substring(0, newLineLoc);
}
return altScoreNames;
}
}
public int FieldCount
{
get { return m_format.Split(new char[] { '|' }).Length; }
}
public int[] AltFieldCount
{
get
{
int[] altFieldCount = new int[m_altFormat.Length];
for (int i = 0; i < altFieldCount.Length; i++)
{
int newLineLoc = m_altFormat[i].IndexOf(Environment.NewLine);
altFieldCount[i] = m_altFormat[i].Substring(newLineLoc + Environment.NewLine.Length).Split(new char[] { '|' }).Length;
}
return altFieldCount;
}
}
public int NumAltScores
{
get { return m_numAltEntries.Length; }
}
public DateTime GetVersionDate
{
get { return m_versionDate; }
}
public string[] GamesSupported
{
get { return m_gamesSupported.Split(new char[] { ',' }); }
}
public string[] ExtensionsRequired
{
get { return m_extensionsRequired.Split(new char[] { ',' }); }
}
public byte[] ByteData
{
get { return m_data; }
}
public virtual void SaveData()
{
File.WriteAllBytes(m_fileNames[0], m_data);
}
public virtual String[] OptimizeScoresForGame(String[] scoreArray)
{
return scoreArray;
}
public virtual void SetAlternateScore(String[] args)
{
}
}
}