3 * upkg: tool for manipulating Unreal Tournament packages.
4 * Copyright © 2011, 2020, 2022 Nick Bowler
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
31 #include <uobject/uobject.h>
33 /* Hack to work around broken type parsing in GOB2. */
34 typedef unsigned char engine_palette_rgba[4];
37 class Engine:Palette from U:Object (dynamic)
39 public unsigned entries = 0;
40 public engine_palette_rgba *rgba = NULL destroywith free;
42 override (U:Object) int deserialize(U:Object *uo)
44 struct upkg_file *f = uo->pkg_file;
45 Self *self = SELF(uo);
46 unsigned char buf[16];
52 buflen = upkg_export_read(f, buf, sizeof buf);
53 rc = upkg_decode_index(&entries, buf, buflen);
54 if (rc == 0 || entries < 0)
56 self->entries = entries;
58 if (upkg_export_seek(f, rc, SEEK_SET) != 0)
60 buflen = entries * sizeof self->rgba[0];
61 self->rgba = malloc(buflen);
65 rc = upkg_export_read(f, self->rgba, buflen);