--- /dev/null
+%alltop{
+/*
+ * upkg: tool for manipulating Unreal Tournament packages.
+ * Copyright © 2011 Nick Bowler
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+%}
+
+%{
+#include <stdio.h>
+#include <stdlib.h>
+%}
+
+%h{
+#include <uobject/uobject.h>
+
+/* Hack to work around broken type parsing in GOB2. */
+typedef unsigned char engine_palette_rgba[4];
+%}
+
+class Engine:Palette from U:Object (dynamic)
+{
+ public unsigned entries = 0;
+ public engine_palette_rgba *rgba = NULL;
+
+ override (U:Object) int deserialize(U:Object *uo)
+ {
+ struct upkg_file *f = uo->pkg_file;
+ Self *self = SELF(uo);
+ unsigned char buf[16];
+ size_t rc, buflen;
+ long entries;
+
+ PARENT_HANDLER(uo);
+
+ buflen = upkg_export_read(f, buf, sizeof buf);
+ rc = upkg_decode_index(&entries, buf, buflen);
+ if (rc == 0 || entries < 0)
+ return -1;
+ self->entries = entries;
+
+ upkg_export_seek(f, rc, SEEK_SET);
+ buflen = entries * sizeof self->rgba[0];
+ self->rgba = malloc(buflen);
+ if (!self->rgba)
+ return -1;
+
+ rc = upkg_export_read(f, self->rgba, buflen);
+ if (rc != buflen) {
+ free(self->rgba);
+ return -1;
+ }
+
+ printf("palette: %u entries\n", self->entries);
+ return 0;
+ }
+}