-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMagicEditor.cs
More file actions
230 lines (204 loc) · 6.3 KB
/
MagicEditor.cs
File metadata and controls
230 lines (204 loc) · 6.3 KB
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;
namespace ED7Editor
{
public partial class MagicEditor : Form
{
public MagicEditor()
{
InitializeComponent();
}
[StructLayout(LayoutKind.Sequential)]
[TypeConverter(typeof(ExpandableObjectConverter))]
class MagicField
{
ushort type;
public ushort Type
{
get { return type; }
set { type = value; }
}
byte target;
public byte Target
{
get { return target; }
set { target = value; }
}
byte shape;
public byte Shape
{
get { return shape; }
set { shape = value; }
}
byte attr;
public byte Attr
{
get { return attr; }
set { attr = value; }
}
byte what;
public byte What
{
get { return what; }
set { what = value; }
}
byte aff1;
public byte Aff1
{
get { return aff1; }
set { aff1 = value; }
}
byte aff2;
public byte Aff2
{
get { return aff2; }
set { aff2 = value; }
}
ushort rng;
public ushort Rng
{
get { return rng; }
set { rng = value; }
}
ushort region;
public ushort Region
{
get { return region; }
set { region = value; }
}
ushort drive;
public ushort Drive
{
get { return drive; }
set { drive = value; }
}
ushort wait;
public ushort Wait
{
get { return wait; }
set { wait = value; }
}
ushort ep;
public ushort Ep
{
get { return ep; }
set { ep = value; }
}
ushort id;
public ushort ID
{
get { return id; }
set { id = value; }
}
short amount1;
public short Amount1
{
get { return amount1; }
set { amount1 = value; }
}
ushort time1;
public ushort Time1
{
get { return time1; }
set { time1 = value; }
}
short amount2;
public short Amount2
{
get { return amount2; }
set { amount2 = value; }
}
ushort time2;
public ushort Time2
{
get { return time2; }
set { time2 = value; }
}
ushort str1;
public ushort Str1
{
get { return str1; }
set { str1 = value; }
}
ushort str2;
public ushort Str2
{
get { return str2; }
set { str2 = value; }
}
}
class Magic
{
public MagicField Field { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public override string ToString()
{
return Name;
}
}
string ReadString(Stream stream)
{
byte b;
List<byte> a = new List<byte>();
while ((b = (byte)stream.ReadByte()) != 0) a.Add(b);
string s = Helper.Encoding.GetString(a.ToArray());
return s;
}
private void MagicEditor_Load(object sender, EventArgs e)
{
string ext = "._dt";
string textPath = @"E:\Program Files\Joyoland\ed_zero\data\text\";
using (var stream = File.OpenRead(textPath + "t_magic" + ext))
using (var reader = new BinaryReader(stream))
{
ushort end = reader.ReadUInt16();
ushort pos = end;
List<ushort> lp = new List<ushort>();
do
{
lp.Add(pos);
pos = reader.ReadUInt16();
} while (stream.Position < end);
//lp.Add(pos);
foreach (var p in lp)
{
Magic magic = new Magic();
stream.Seek(p, SeekOrigin.Begin);
byte[] buffer = new byte[Marshal.SizeOf(typeof(MagicField))];
stream.Read(buffer, 0, buffer.Length);
var handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
try
{
magic.Field = (MagicField)
Marshal.PtrToStructure(Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0), typeof(MagicField));
}
finally
{
handle.Free();
}
if (magic.Field.Type == 0) continue;
stream.Seek(magic.Field.Str1, SeekOrigin.Begin);
magic.Name = ReadString(stream);
stream.Seek(magic.Field.Str2, SeekOrigin.Begin);
magic.Description = ReadString(stream);
listBox1.Items.Add(magic);
}
}
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
propertyGrid1.SelectedObject = listBox1.SelectedItem;
}
private void MagicEditor_FormClosing(object sender, FormClosingEventArgs e)
{
}
}
}