Repository navigation
Expand file tree
/
Copy pathJJ2AnimFile.cs
More file actions
114 lines (94 loc) · 2.87 KB
/
Copy pathJJ2AnimFile.cs
File metadata and controls
114 lines (94 loc) · 2.87 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
//https://www.jazz2online.com/wiki/J2A_File_Format article by Neobeo
using System;
using System.IO;
using System.Threading;
using JJ2AnimLib.JJ2AnimSections;
namespace JJ2AnimLib
{
public class JJ2AnimFile
{
public ALIB_Header Header { get; set; }
public AnimSet[] Sets = new AnimSet[0];
private bool _success = false;
private bool _busy = false;
private Thread _loadThread;
private sbyte _loadPercentage = -1;
public bool Success { get { return _success; } }
public bool Busy { get { return _busy; } }
public sbyte LoadPercentage { get { return _loadPercentage; } }
public JJ2AnimFile()
{
_loadThread = new Thread(ThreadedLoad);
}
public JJ2AnimFile(string file)
{
_loadThread = new Thread(ThreadedLoad);
Load(file);
}
public bool Load(byte[] buff)
{
bool res = false;
_loadPercentage = 0;
Header = new ALIB_Header();
if (Header.Read(buff))
{
if (ReadSets(buff, Header.GetSize))
{
res = true;
}
}
_success = res;
return res;
}
public bool Load(string file)
{
bool res = false;
byte[] buff = File.ReadAllBytes(file);
res = Load(buff);
return res;
}
// untested
public bool LoadAsync(byte[] buff)
{
if(!_busy)
{
_busy = true;
if(_loadThread.ThreadState != ThreadState.Running)
{
_loadThread = new Thread(ThreadedLoad);
_threadBuff = buff;
_loadThread.Start();
return true;
}
else
_busy = false;
}
return false;
}
byte[] _threadBuff;
private void ThreadedLoad()
{
byte[] buff = _threadBuff;
if(buff != null)
{
_threadBuff = null;
Load(buff);
}
_busy = false;
}
private bool ReadSets(byte[] mem, int offset)
{
Sets = new AnimSet[Header.SetCount];
for(int i = 0; i < Sets.Length; i++)
{
Sets[i] = new AnimSet();
if (!Sets[i].Read(mem, Header.SetAddress[i]))
return false;
// address/offset can be calculated manually as: offset += Sets[i].GetSize
// but we will use addresses given in the file instead (Header.SetAddress[i]).
_loadPercentage = (sbyte)(i / (float)Sets.Length * 100);
}
return true;
}
}
}