-
Notifications
You must be signed in to change notification settings - Fork 1
/
pex.h
181 lines (160 loc) · 4.29 KB
/
pex.h
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
/* libpex - C library for reading and writing compiled Papyrus scripts (PEX files)
* Copyright (c) 2017 Oskar Sveinsen
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/*
* #include <stdint.h>
* #include <stdio.h>
*/
#define PEX_GAME_TESV 0x0001
#define PEX_GAME_FO4 0x0002
typedef struct Pex_string {
uint16_t len;
char *c; /* null-terminated */
} Pex_string;
typedef struct Pex_debug_func {
Pex_string *object;
Pex_string *state;
Pex_string *name;
uint8_t type; /* TODO */
uint16_t linec;
uint16_t *linev;
} Pex_debug_func;
typedef struct Pex_debug_group {
Pex_string *object;
Pex_string *name;
Pex_string *docstring;
uint32_t userflags;
uint16_t propc;
Pex_string **propv;
} Pex_debug_group;
typedef struct Pex_debug_struct {
Pex_string *object;
Pex_string *name;
uint16_t memberc;
Pex_string **memberv;
} Pex_debug_struct;
typedef struct Pex_debug {
uint64_t modifytime;
uint16_t funcc;
Pex_debug_func *funcv;
uint16_t groupc;
Pex_debug_group *groupv;
uint16_t structc;
Pex_debug_struct *structv;
} Pex_debug;
typedef struct Pex_userflag {
Pex_string *name;
uint8_t id;
} Pex_userflag;
typedef struct Pex_object_var {
Pex_string *name;
Pex_string *type;
} Pex_object_var;
typedef struct Pex_object_value {
uint8_t type; /* TODO */
union {
Pex_string *s;
int32_t n;
} value;
} Pex_object_value;
typedef struct Pex_object_var_global {
Pex_object_var var;
uint32_t userflags;
Pex_object_value initialvalue;
uint8_t flags;
} Pex_object_var_global;
typedef struct Pex_object_struct_member {
Pex_object_var_global var;
Pex_string *docstring;
} Pex_object_struct_member;
typedef struct Pex_object_struct {
Pex_string *name;
uint16_t memberc;
Pex_object_struct_member *memberv;
} Pex_object_struct;
typedef struct Pex_object_func_code {
uint8_t op;
uint16_t argc;
Pex_object_value *argv;
} Pex_object_func_code;
typedef struct Pex_object_func {
Pex_string *returntype;
Pex_string *docstring;
uint32_t userflags;
uint8_t flags;
uint16_t paramc;
Pex_object_var *paramv;
uint16_t localc;
Pex_object_var *localv;
uint16_t codec;
Pex_object_func_code *codev;
} Pex_object_func;
typedef struct Pex_object_prop {
Pex_object_var var;
Pex_string *docstring;
uint32_t userflags;
uint8_t flags;
Pex_string *autovar;
Pex_object_func *getter;
Pex_object_func *setter;
} Pex_object_prop;
typedef struct Pex_object_state_func {
Pex_string *name;
Pex_object_func func;
} Pex_object_state_func;
typedef struct Pex_object_state {
Pex_string *name;
uint16_t funcc;
Pex_object_state_func *funcv;
} Pex_object_state;
typedef struct Pex_object {
Pex_string *name;
Pex_string *parent;
Pex_string *docstring;
uint8_t flags;
uint32_t userflags;
Pex_string *autostate;
uint16_t structc;
Pex_object_struct *structv;
uint16_t varc;
Pex_object_var *varv;
uint16_t propc;
Pex_object_prop *propv;
uint16_t statec;
Pex_object_state *statev;
} Pex_object;
typedef struct Pex {
uint8_t version_major;
uint8_t version_minor;
uint16_t game;
uint64_t compiletime;
uint16_t stringc;
Pex_string *stringv;
uint16_t debugc;
Pex_debug *debugv;
uint16_t userflagc;
Pex_userflag *userflagv;
uint16_t objectc;
Pex_object *objectv;
} Pex;
int pex_read(Pex *, size_t nitems, FILE *);
int pex_write(Pex *, size_t nitems, FILE *);
int pex_free(Pex *); /* does not free the root Pex object */