diff --git a/src/d_net.cpp b/src/d_net.cpp index 80755c90e..0af1bd9c1 100644 --- a/src/d_net.cpp +++ b/src/d_net.cpp @@ -2210,7 +2210,7 @@ void Net_DoCommand (int type, uint8_t **stream, int player) case DEM_SETINV: s = ReadString(stream); i = ReadLong(stream); - cht_SetInv(&players[player], s, i, ReadByte(stream)); + cht_SetInv(&players[player], s, i, !!ReadByte(stream)); break; case DEM_WARPCHEAT: diff --git a/src/gl/textures/gl_texture.cpp b/src/gl/textures/gl_texture.cpp index cc24f054d..539a7c8ff 100644 --- a/src/gl/textures/gl_texture.cpp +++ b/src/gl/textures/gl_texture.cpp @@ -133,9 +133,11 @@ void gl_GenerateGlobalBrightmapFromColormap() if (lump == -1) lump = Wads.CheckNumForName("COLORMAP", ns_colormaps); if (lump == -1) return; FMemLump cmap = Wads.ReadLump(lump); - FMemLump palette = Wads.ReadLump("PLAYPAL"); + uint8_t palbuffer[768]; + ReadPalette(Wads.CheckNumForName("PLAYPAL"), palbuffer); + const unsigned char *cmapdata = (const unsigned char *)cmap.GetMem(); - const unsigned char *paldata = (const unsigned char *)palette.GetMem(); + const uint8_t *paldata = palbuffer; const int black = 0; const int white = ColorMatcher.Pick(255,255,255); diff --git a/src/intermission/intermission.cpp b/src/intermission/intermission.cpp index 0143b3e40..916d1c24d 100644 --- a/src/intermission/intermission.cpp +++ b/src/intermission/intermission.cpp @@ -124,12 +124,13 @@ void DIntermissionScreen::Init(FIntermissionAction *desc, bool first) if (desc->mPalette.IsNotEmpty() && (lumpnum = Wads.CheckNumForFullName(desc->mPalette, true)) > 0) { PalEntry *palette; + uint8_t palbuffer[768]; const uint8_t *orgpal; FMemLump lump; int i; - lump = Wads.ReadLump (lumpnum); - orgpal = (uint8_t *)lump.GetMem(); + ReadPalette(lumpnum, palbuffer); + orgpal = (uint8_t *)palbuffer; palette = screen->GetPalette (); for (i = 256; i > 0; i--, orgpal += 3) { diff --git a/src/v_palette.cpp b/src/v_palette.cpp index 1c13446a8..07d8af86d 100644 --- a/src/v_palette.cpp +++ b/src/v_palette.cpp @@ -306,6 +306,40 @@ static int sortforremap2 (const void *a, const void *b) } } +void ReadPalette(int lumpnum, uint8_t *buffer) +{ + if (lumpnum < 0) + { + I_FatalError("Palette not found"); + } + FMemLump lump = Wads.ReadLump(lumpnum); + uint8_t *lumpmem = (uint8_t*)lump.GetMem(); + memset(buffer, 0, 768); + if (memcmp(lumpmem, "JASC-PAL", 8)) + { + memcpy(buffer, lumpmem, MIN(768, lump.GetSize())); + } + else + { + FScanner sc; + + sc.OpenMem(Wads.GetLumpFullName(lumpnum), (char*)lumpmem, lump.GetSize()); + sc.MustGetString(); + sc.MustGetNumber(); // version - ignore + sc.MustGetNumber(); + int colors = MIN(256, sc.Number) * 3; + for (int i = 0; i < colors; i++) + { + sc.MustGetNumber(); + if (sc.Number < 0 || sc.Number > 255) + { + sc.ScriptError("Color %d value out of range.", sc.Number); + } + buffer[i] = sc.Number; + } + } +} + static bool FixBuildPalette (uint8_t *opal, int lump, bool blood) { if (Wads.LumpLength (lump) < 768) @@ -354,8 +388,7 @@ void InitPalette () if (!usingBuild) { - FWadLump palump = Wads.OpenLumpName ("PLAYPAL"); - palump.Read (pal, 768); + ReadPalette(Wads.CheckNumForName("PLAYPAL"), pal); } GPalette.SetPalette (pal); diff --git a/src/v_palette.h b/src/v_palette.h index 28ced55f3..3f8f00039 100644 --- a/src/v_palette.h +++ b/src/v_palette.h @@ -73,6 +73,7 @@ extern FPalette GPalette; int BestColor (const uint32_t *pal, int r, int g, int b, int first=1, int num=255); void DoBlending (const PalEntry *from, PalEntry *to, int count, int r, int g, int b, int a); +void ReadPalette(int lumpnum, uint8_t *buffer); void InitPalette (); // V_SetBlend() diff --git a/src/win32/st_start.cpp b/src/win32/st_start.cpp index c1556f002..0fb89d581 100644 --- a/src/win32/st_start.cpp +++ b/src/win32/st_start.cpp @@ -52,6 +52,7 @@ #include "s_sound.h" #include "m_argv.h" #include "d_main.h" +#include "v_palette.h" // MACROS ------------------------------------------------------------------ @@ -1452,13 +1453,9 @@ void ST_Util_FreeBitmap (BITMAPINFO *bitmap_info) void ST_Util_BitmapColorsFromPlaypal (BITMAPINFO *bitmap_info) { uint8_t playpal[768]; - int i; - { - FWadLump lumpr = Wads.OpenLumpName ("PLAYPAL"); - lumpr.Read (playpal, 768); - } - for (i = 0; i < 256; ++i) + ReadPalette(Wads.CheckNumForName("PLAYPAL"), playpal); + for (int i = 0; i < 256; ++i) { bitmap_info->bmiColors[i].rgbBlue = playpal[i*3+2]; bitmap_info->bmiColors[i].rgbGreen = playpal[i*3+1];