-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathFlags.cs
70 lines (57 loc) · 1.9 KB
/
Flags.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace AtlusScriptGUI
{
// Adapted from Lipsum
public class Flag
{
public static int[] sVanillaBits = { 0, 2048, 4096, 8192, 8448, 8704, 8960 };
public static int[] sRoyalBits = { 0, 3072, 6144, 11264, 11776, 12288, 12800 };
public static int ConvertToRoyal(int flag)
{
var section = -1;
var section_flag = 0;
// convert
for (var i = 1; i < sVanillaBits.Length; i++)
{
if (flag < sVanillaBits[i])
{
section = i - 1;
section_flag = flag - sVanillaBits[i - 1];
break;
}
}
var result = sRoyalBits[section] + section_flag;
// flag val exceeded max val in source array
if (section < 0) return -1;
// overflowed to next section after conversion
if (result > sRoyalBits[section + 1]) return -1;
return result;
}
public static int ConvertToVanilla(int flag)
{
var section = -1;
var section_flag = 0;
// convert
for (var i = 1; i < sRoyalBits.Length; i++)
{
if (flag < sRoyalBits[i])
{
section = i - 1;
section_flag = flag - sRoyalBits[i - 1];
break;
}
}
var result = sVanillaBits[section] + section_flag;
// flag val exceeded max val in source array
if (section < 0) return -1;
// overflowed to next section after conversion
if (result > sVanillaBits[section + 1]) return -1;
return result;
}
}
}