This repository has been archived by the owner on Sep 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Util.bt
159 lines (127 loc) · 3.3 KB
/
Util.bt
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
//------------------------------------------------
//--- 010 Editor v9.0.1 Binary Template
//
// File: Util.bt
// Authors: TKGP
// Version:
// Purpose: Utility types and functions for SoulsTemplates
// Category:
// File Mask:
// ID Bytes:
// History:
//------------------------------------------------
#ifndef _SOULSTEMPLATES_UTIL
#define _SOULSTEMPLATES_UTIL
void Align(int align) {
if (FTell() % align > 0) {
FSkip(align - (FTell() % align));
}
}
void AlignRelative(int base, int align) {
local int offset = (FTell() - base) % align;
if (offset) {
FSkip(align - offset);
}
}
ubyte ReverseBits(ubyte value) {
return
((value & 0b00000001) << 7) |
((value & 0b00000010) << 5) |
((value & 0b00000100) << 3) |
((value & 0b00001000) << 1) |
((value & 0b00010000) >> 1) |
((value & 0b00100000) >> 3) |
((value & 0b01000000) >> 5) |
((value & 0b10000000) >> 7);
}
typedef struct {
float x;
float y;
} Vector2 <read=ReadVector2>;
string ReadVector2(Vector2& vec) {
string str;
SPrintf(str, "<%7.2f, %7.2f>", vec.x, vec.y);
return str;
}
string ReadVector2Fmt(Vector2& vec, int width, int precision) {
string fmt;
SPrintf(fmt, "<%%%d.%df, %%%d.%df>",
width, precision, width, precision);
string str;
return SPrintf(str, fmt, vec.x, vec.y);
}
typedef struct {
float x;
float y;
float z;
} Vector3 <read=ReadVector3>;
string ReadVector3(Vector3& vec) {
string str;
SPrintf(str, "<%7.2f, %7.2f, %7.2f>", vec.x, vec.y, vec.z);
return str;
}
string ReadVector3Fmt(Vector3& vec, int width, int precision) {
string fmt;
SPrintf(fmt, "<%%%d.%df, %%%d.%df, %%%d.%df>",
width, precision, width, precision, width, precision);
string str;
return SPrintf(str, fmt, vec.x, vec.y, vec.z);
}
typedef struct {
float x;
float y;
float z;
float w;
} Vector4 <read=ReadVector4>;
string ReadVector4(Vector4& vec) {
string str;
SPrintf(str, "<%7.2f, %7.2f, %7.2f, %7.2f>", vec.x, vec.y, vec.z, vec.w);
return str;
}
string ReadVector4Fmt(Vector4& vec, int width, int precision) {
string fmt;
SPrintf(fmt, "<%%%d.%df, %%%d.%df, %%%d.%df, %%%d.%df>",
width, precision, width, precision, width, precision, width, precision);
string str;
return SPrintf(str, fmt, vec.x, vec.y, vec.z, vec.w);
}
typedef struct (int longOffset, int unicode) {
if (longOffset)
quad offset <format=hex>;
else
uint offset <format=hex>;
local quad pos <hidden=true> = FTell();
FSeek(offset);
if (unicode)
wstring str;
else
string str;
FSeek(pos);
} OffsetString <read=ReadOffsetString>;
wstring ReadOffsetString(OffsetString& os) {
return os.str;
}
typedef struct {
string str;
} WrappedString <read=ReadWrappedString>;
string ReadWrappedString(WrappedString& ws) {
return ws.str;
}
typedef struct {
wstring str;
} WrappedWString <read=ReadWrappedWString>;
string ReadWrappedWString(WrappedWString& wws) {
return wws.str;
}
typedef struct {
if (VARINT_LONG)
quad val;
else
int val;
} Varint <read=ReadVarint>;
string ReadVarint(Varint& v) {
string s;
SPrintf(s, "%Xh | %d", v.val, v.val);
return s;
}
#endif