1
0
Fork 0

(svn r4654) - Fix [NewGRF]: Properly read in the GRFID. This fixes GRFID checking and activation/deactivation. Do swap the GRFID for displaying purposes.

release/0.5
Darkvater 2006-05-01 21:45:35 +00:00
parent 22fd1a348e
commit c0cf93a9b0
2 changed files with 13 additions and 29 deletions

View File

@ -149,12 +149,8 @@ static inline byte grf_load_byte(byte **buf)
static uint16 grf_load_word(byte **buf) static uint16 grf_load_word(byte **buf)
{ {
uint16 val; uint16 val = grf_load_byte(buf);
byte *p = *buf; return val | (grf_load_byte(buf) << 8);
val = p[0];
val |= p[1] << 8;
*buf = p + 2;
return val;
} }
static uint16 grf_load_extended(byte** buf) static uint16 grf_load_extended(byte** buf)
@ -167,14 +163,8 @@ static uint16 grf_load_extended(byte** buf)
static uint32 grf_load_dword(byte **buf) static uint32 grf_load_dword(byte **buf)
{ {
uint32 val; uint32 val = grf_load_word(buf);
byte *p = *buf; return val | (grf_load_word(buf) << 16);
val = p[0];
val |= p[1] << 8;
val |= p[2] << 16;
val |= p[3] << 24;
*buf = p + 4;
return val;
} }
static uint32 grf_load_var(byte size, byte **buf) static uint32 grf_load_var(byte size, byte **buf)
@ -802,14 +792,8 @@ static bool StationChangeInfo(uint stid, int numinfo, int prop, byte **bufp, int
switch (prop) { switch (prop) {
case 0x08: /* Class ID */ case 0x08: /* Class ID */
FOR_EACH_OBJECT { FOR_EACH_OBJECT {
uint32 classid; /* Swap classid because we read it in BE meaning WAYP or DFLT */
uint32 classid = BSWAP32(grf_load_dword(&buf));
/* classid, for a change, is big-endian */
classid = *(buf++) << 24;
classid |= *(buf++) << 16;
classid |= *(buf++) << 8;
classid |= *(buf++);
statspec[i].sclass = AllocateStationClass(classid); statspec[i].sclass = AllocateStationClass(classid);
} }
break; break;
@ -2134,19 +2118,19 @@ static void GRFInfo(byte *buf, int len)
const char *name; const char *name;
const char *info; const char *info;
check_length(len, 8, "GRFInfo"); check_length(len, 8, "GRFInfo"); buf++;
version = buf[1]; version = grf_load_byte(buf);
/* this is de facto big endian - grf_load_dword() unsuitable */ grfid = grf_load_dword(&buf);
grfid = buf[2] << 24 | buf[3] << 16 | buf[4] << 8 | buf[5]; name = (const char*)buf;
name = (const char*)(buf + 6);
info = name + strlen(name) + 1; info = name + strlen(name) + 1;
_cur_grffile->grfid = grfid; _cur_grffile->grfid = grfid;
_cur_grffile->grf_version = version; _cur_grffile->grf_version = version;
_cur_grffile->flags |= 0x0001; /* set active flag */ _cur_grffile->flags |= 0x0001; /* set active flag */
/* Do swap the GRFID for displaying purposes since people expect that */
DEBUG(grf, 1) ("[%s] Loaded GRFv%d set %08lx - %s:\n%s", DEBUG(grf, 1) ("[%s] Loaded GRFv%d set %08lx - %s:\n%s",
_cur_grffile->filename, version, grfid, name, info); _cur_grffile->filename, version, BSWAP32(grfid), name, info);
} }
/* Action 0x0A */ /* Action 0x0A */

View File

@ -957,7 +957,7 @@ static void NewgrfWndProc(Window *w, WindowEvent *e)
// draw grf id // draw grf id
x = DrawString(5, 209, STR_NEWGRF_GRF_ID, 0); x = DrawString(5, 209, STR_NEWGRF_GRF_ID, 0);
snprintf(_userstring, lengthof(_userstring), "%08X", _sel_grffile->grfid); snprintf(_userstring, lengthof(_userstring), "%08X", BSWAP32(_sel_grffile->grfid));
DrawString(x + 2, 209, STR_SPEC_USERSTRING, 0x01); DrawString(x + 2, 209, STR_SPEC_USERSTRING, 0x01);
} }
} break; } break;