]> git.draconx.ca Git - upkg.git/blob - src/upkg.h
f9193c5318c5661dab4d7fd2949d1f6c8a54e215
[upkg.git] / src / upkg.h
1 /*
2  *  upkg: tool for manipulating Unreal Tournament packages.
3  *  Copyright (C) 2009 Nick Bowler
4  *
5  *  This program is free software: you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation, either version 3 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #ifndef UPKG_H_
20 #define UPKG_H_
21
22 #include <stddef.h>
23
24 #define UPKG_FLAG_ALLOW_DOWNLOAD  0x0001
25 #define UPKG_FLAG_CLIENT_OPTIONAL 0x0002
26 #define UPKG_FLAG_SERVER_ONLY     0x0004
27 #define UPKG_FLAG_BROKEN_LINKS    0x0008
28 #define UPKG_FLAG_INSECURE        0x0010
29 #define UPKG_FLAG_REQUIRED        0x8000
30
31 #define UPKG_OBJ_FLAG_TRANSACTIONAL    0x00000001
32 #define UPKG_OBJ_FLAG_UNREACHABLE      0x00000002
33 #define UPKG_OBJ_FLAG_PUBLIC           0x00000004
34 #define UPKG_OBJ_FLAG_TAG_IMPORT       0x00000008
35 #define UPKG_OBJ_FLAG_TAG_EXPORT       0x00000010
36 #define UPKG_OBJ_FLAG_SOURCE_MODIFIED  0x00000020
37 #define UPKG_OBJ_FLAG_TAG_GARBAGE      0x00000040
38 #define UPKG_OBJ_FLAG_NEED_LOAD        0x00000200
39 #define UPKG_OBJ_FLAG_HIGHLIGHT_NAME   0x00000400
40 #define UPKG_OBJ_FLAG_IN_SINGULAR_FUNC 0x00000800
41 #define UPKG_OBJ_FLAG_SUPPRESSED       0x00001000
42 #define UPKG_OBJ_FLAG_IN_END_STATE     0x00002000
43 #define UPKG_OBJ_FLAG_TRANSIENT        0x00004000
44 #define UPKG_OBJ_FLAG_PRELOADING       0x00008000
45 #define UPKG_OBJ_FLAG_LOAD_FOR_CLIENT  0x00010000
46 #define UPKG_OBJ_FLAG_LOAD_FOR_SERVER  0x00020000
47 #define UPKG_OBJ_FLAG_LOAD_FOR_EDIT    0x00040000
48 #define UPKG_OBJ_FLAG_STANDALONE       0x00080000
49 #define UPKG_OBJ_FLAG_NOT_FOR_CLIENT   0x00100000
50 #define UPKG_OBJ_FLAG_NOT_FOR_SERVER   0x00200000
51 #define UPKG_OBJ_FLAG_NOT_FOR_EDIT     0x00400000
52 #define UPKG_OBJ_FLAG_DESTROYED        0x00800000
53 #define UPKG_OBJ_FLAG_NEED_POST_LOAD   0x01000000
54 #define UPKG_OBJ_FLAG_HAS_STACK        0x02000000
55 #define UPKG_OBJ_FLAG_NATIVE           0x04000000
56 #define UPKG_OBJ_FLAG_MARKED           0x08000000
57 #define UPKG_OBJ_FLAG_ERROR_SHUTDOWN   0x10000000
58 #define UPKG_OBJ_FLAG_DEBUG_POST_LOAD  0x20000000
59 #define UPKG_OBJ_FLAG_DEBUG_SERIALIZE  0x40000000
60 #define UPKG_OBJ_FLAG_DEBUG_DESTROY    0x80000000
61
62 #define UPKG_HDR_MAGIC 0x9e2a83c1
63 #define UPKG_HDR_SIZE  36
64
65 struct upkg_file_ops {
66         size_t (*read)(void *buf, size_t size, void *handle);
67         int    (*seek)(void *handle, long offset, int whence);
68         long   (*tell)(void *handle);
69         int    (*eof) (void *handle);
70 };
71
72 struct upkg {
73         unsigned version, license;
74         unsigned char guid[16];
75         unsigned long flags;
76
77         unsigned long name_count, export_count, import_count;
78
79         struct upkg_private *priv;
80 };
81
82 struct upkg_export {
83         const char *name;
84         unsigned long flags;
85 };
86
87 struct upkg_file {
88         const char *name;
89
90         int eof;
91
92         struct upkg *pkg;
93         unsigned long base, offset, len;
94 };
95
96 /* Default I/O operations for ordinary files. */
97 extern const struct upkg_file_ops upkg_default_fops;
98
99 struct upkg *upkg_open(void *handle, const struct upkg_file_ops *fops,
100                        int (*destructor)(void *handle));
101 struct upkg *upkg_fopen(const char *path);
102 int upkg_close(struct upkg *pkg);
103
104 const char *upkg_get_name(struct upkg *pkg, unsigned long idx);
105 const struct upkg_export *upkg_get_export(struct upkg *pkg, unsigned long idx);
106
107 long upkg_export_find(struct upkg *pkg, long parent, const char *name);
108
109 const char *upkg_export_class(struct upkg *pkg, unsigned long idx,
110                               const char **package);
111
112 struct upkg_file *upkg_export_open(struct upkg *pkg, unsigned long idx);
113 size_t upkg_export_read(struct upkg_file *f, void *buf, size_t n);
114 int    upkg_export_seek(struct upkg_file *f, long offset, int whence);
115 long   upkg_export_tell(struct upkg_file *f);
116 void   upkg_export_close(struct upkg_file *f);
117
118 size_t upkg_decode_index(long *val, unsigned char *bytes, size_t n);
119
120 #endif