X-Git-Url: https://git.draconx.ca/gitweb/upkg.git/blobdiff_plain/947f12306d4236c63a7f3449191ec8337ee42469..6df203a00536662101ec4a4275ec84baa7527d79:/src/engine/palette.gob diff --git a/src/engine/palette.gob b/src/engine/palette.gob new file mode 100644 index 0000000..4c15c71 --- /dev/null +++ b/src/engine/palette.gob @@ -0,0 +1,69 @@ +%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 . + */ +%} + +%{ +#include +#include +%} + +%h{ +#include + +/* 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; + } +}