2 * upkg: tool for manipulating Unreal Tournament packages.
3 * Copyright (C) 2009 Nick Bowler
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 2 of the License, or
8 * (at your option) any later version.
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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 /* Integer packing. */
26 #define DEFPACK_BE(bits, type) void pack_ ## bits ## _be ( \
27 unsigned char *out, type v \
30 for (i = 1; i <= bits/8; i++) { \
31 out[bits/8 - i] = v % 256; \
36 #define DEFPACK_LE(bits, type) void pack_ ## bits ## _le ( \
37 unsigned char *out, type v \
40 for (i = 0; i < bits/8; i++) { \
46 DEFPACK_BE(16, unsigned short)
47 DEFPACK_BE(32, unsigned long)
49 DEFPACK_BE(64, unsigned long long)
52 DEFPACK_LE(16, unsigned short)
53 DEFPACK_LE(32, unsigned long)
55 DEFPACK_LE(64, unsigned long long)
58 #define DEFUNPACK_BE(bits, type) type unpack_ ## bits ## _be ( \
63 for (i = 0; i < bits/8; i++) { \
70 #define DEFUNPACK_LE(bits, type) type unpack_ ## bits ## _le ( \
75 for (i = 1; i <= bits/8; i++) { \
77 v += in[bits/8 - i]; \
82 DEFUNPACK_BE(16, unsigned short)
83 DEFUNPACK_BE(32, unsigned long)
85 DEFUNPACK_BE(64, unsigned long long)
88 DEFUNPACK_LE(16, unsigned short)
89 DEFUNPACK_LE(32, unsigned long)
91 DEFUNPACK_LE(64, unsigned long long)