-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAnimationCopyTool.cs
More file actions
232 lines (168 loc) · 8.17 KB
/
AnimationCopyTool.cs
File metadata and controls
232 lines (168 loc) · 8.17 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
231
232
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CustomActorToolkit
{
public partial class CopyAnimationsForm : Form
{
List<byte> SourceZobj = new List<byte>();
List<byte> TargetZobj = new List<byte>();
string TargetZobjFilename = "";
List<Animation> SourceAnimations = new List<Animation>();
List<Animation> TargetAnimations = new List<Animation>();
public CopyAnimationsForm()
{
InitializeComponent();
}
private void SourceButton_Click(object sender, EventArgs e)
{
openFileDialog1.FileName = "";
openFileDialog1.Filter = "ZObj Files (*.zobj*)|*.zobj*";
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
SourceZobj = new List<byte>(File.ReadAllBytes(openFileDialog1.FileName));
SourceFilename.Text = openFileDialog1.FileName;
UpdateListbox(SourceZobj, ref SourceAnimations, ref SourceListBox);
if (TargetZobj.Count > 0) MoveButton.Enabled = true;
}
}
private void TargetButton_Click(object sender, EventArgs e)
{
openFileDialog1.FileName = "";
openFileDialog1.Filter = "ZObj Files (*.zobj*)|*.zobj*";
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
TargetZobj = new List<byte>(File.ReadAllBytes(openFileDialog1.FileName));
TargetFilename.Text = openFileDialog1.FileName;
UpdateListbox(TargetZobj, ref TargetAnimations, ref TargetListBox);
if (SourceZobj.Count > 0) MoveButton.Enabled = true;
}
}
private void UpdateListbox(List<byte> zobjlist, ref List<Animation> animations, ref ListBox listbox)
{
// ADD BANK SUPPORT
byte[] zobj = zobjlist.ToArray();
animations.Clear();
listbox.Items.Clear();
for (int ii = 0; ii < zobj.Length; ii += 4)
{
if (!(ii + 4 > zobj.GetUpperBound(0)))
{
if (zobj[ii + 2] == 0x00 && zobj[ii + 3] == 0x00 && zobj[ii + 4] == 0x06 && zobj[ii + 8] == 0x06 && zobj[ii + 14] == 0x00 && zobj[ii + 15] == 0x00)
{
// Console.WriteLine(string.Format("{0:D4} Frames, 06{1:X6}", frames, ii));
int animrotvaloffset = Helpers.Read24S(zobjlist, ii + 5);
int animrotindexoffset = Helpers.Read24S(zobjlist, ii + 9);
ushort frames = Helpers.Read16(zobjlist, ii);
// if (animrotindexoffset < animrotvaloffset) animrotvaloffset = animrotindexoffset;
animations.Add(new Animation((uint) animrotvaloffset, (uint) animrotindexoffset, (uint) ii, frames));
}
}
}
if (animations.Count == 0)
{
MessageBox.Show("No animations found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
foreach (Animation anim in animations)
{
listbox.Items.Add(anim.headeroffset.ToString("X8") + " (frames: " + anim.frames + ")");
}
if (listbox.SelectionMode != SelectionMode.None) listbox.SelectedIndex = 0;
}
}
private void MoveButton_Click(object sender, EventArgs e)
{
if (SourceAnimations[SourceListBox.SelectedIndex].moved)
{
MessageBox.Show("You already copied this animation!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
List<byte> animdata = new List<byte>();
uint startoffset = Math.Min(SourceAnimations[SourceListBox.SelectedIndex].headeroffset, SourceAnimations[SourceListBox.SelectedIndex].rotindexoffset);
startoffset = Math.Min(startoffset, SourceAnimations[SourceListBox.SelectedIndex].rotvaloffset);
uint endoffset = SourceAnimations[SourceListBox.SelectedIndex].headeroffset + 0x10;
for (uint i = startoffset; i < endoffset; i++)
{
animdata.Add(SourceZobj[(int) i]);
}
uint newoffset = (uint) TargetZobj.Count;
uint newheader = SourceAnimations[SourceListBox.SelectedIndex].headeroffset - startoffset + newoffset;
uint newrotvaloffset = SourceAnimations[SourceListBox.SelectedIndex].rotvaloffset - startoffset + newoffset;
uint newrotindexoffset = SourceAnimations[SourceListBox.SelectedIndex].rotindexoffset - startoffset + newoffset;
TargetZobj.AddRange(animdata);
Helpers.Overwrite32(ref TargetZobj, (int) newheader + 0x4, 0x06000000 + newrotvaloffset);
Helpers.Overwrite32(ref TargetZobj, (int)newheader + 0x8, 0x06000000 + newrotindexoffset);
TargetListBox.Items.Add(newheader.ToString("X8") + " (frames: " + SourceAnimations[SourceListBox.SelectedIndex].frames + ")");
SourceAnimations[SourceListBox.SelectedIndex].moved = true;
SaveButton.Enabled = true;
SaveAsButton.Enabled = true;
}
private void SaveButton_Click(object sender, EventArgs e)
{
if (MainForm.IsFileLocked(TargetFilename.Text))
MessageBox.Show("Zobj is in use... try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
else
{
BinaryWriter BWS = new BinaryWriter(File.OpenWrite(TargetFilename.Text));
BWS.Seek(0, SeekOrigin.Begin);
while(TargetZobj.Count % 0x10 != 0)
TargetZobj.Add(0);
BWS.Write(TargetZobj.ToArray());
BWS.Close();
MessageBox.Show("Done!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void SaveAsButton_Click(object sender, EventArgs e)
{
saveFileDialog1.CheckFileExists = false;
saveFileDialog1.Filter = "wavefront obj file (*.obj)|*.obj|All Files (*.*)|*.*";
saveFileDialog1.CreatePrompt = true;
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
if (MainForm.IsFileLocked(saveFileDialog1.FileName))
MessageBox.Show("File is in use... try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
else
{
BinaryWriter BWS = new BinaryWriter(File.OpenWrite(saveFileDialog1.FileName));
BWS.Seek(0, SeekOrigin.Begin);
while (TargetZobj.Count % 0x10 != 0)
TargetZobj.Add(0);
BWS.Write(TargetZobj.ToArray());
BWS.Close();
MessageBox.Show("Done!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
private void CopyAnimationsForm_FormClosed(object sender, FormClosedEventArgs e)
{
this.Close();
}
private void SourceListBox_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
public class Animation
{
public ushort frames;
public uint rotvaloffset;
public uint rotindexoffset;
public uint headeroffset;
public bool moved = false;
public Animation(uint rotvaloffset, uint rotindexoffset, uint headeroffset, ushort frames)
{
this.rotvaloffset = rotvaloffset;
this.rotindexoffset = rotindexoffset;
this.headeroffset = headeroffset;
this.frames = frames;
}
}
}