summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2006-05-01 21:45:35 +0000
committerDarkvater <darkvater@openttd.org>2006-05-01 21:45:35 +0000
commitc0cf93a9b070c5b11effd88d8e71e2b2017c2ae6 (patch)
treeaa885daf9839bb346d48856fdd871caa29e36614
parent22fd1a348e4f34018a100ab992b79d09ef1c6d26 (diff)
downloadopenttd-c0cf93a9b070c5b11effd88d8e71e2b2017c2ae6.tar.xz
(svn r4654) - Fix [NewGRF]: Properly read in the GRFID. This fixes GRFID checking and activation/deactivation. Do swap the GRFID for displaying purposes.
-rw-r--r--newgrf.c40
-rw-r--r--settings_gui.c2
2 files changed, 13 insertions, 29 deletions
diff --git a/newgrf.c b/newgrf.c
index e52848941..83994b5dd 100644
--- a/newgrf.c
+++ b/newgrf.c
@@ -149,12 +149,8 @@ static inline byte grf_load_byte(byte **buf)
static uint16 grf_load_word(byte **buf)
{
- uint16 val;
- byte *p = *buf;
- val = p[0];
- val |= p[1] << 8;
- *buf = p + 2;
- return val;
+ uint16 val = grf_load_byte(buf);
+ return val | (grf_load_byte(buf) << 8);
}
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)
{
- uint32 val;
- byte *p = *buf;
- val = p[0];
- val |= p[1] << 8;
- val |= p[2] << 16;
- val |= p[3] << 24;
- *buf = p + 4;
- return val;
+ uint32 val = grf_load_word(buf);
+ return val | (grf_load_word(buf) << 16);
}
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) {
case 0x08: /* Class ID */
FOR_EACH_OBJECT {
- uint32 classid;
-
- /* classid, for a change, is big-endian */
- classid = *(buf++) << 24;
- classid |= *(buf++) << 16;
- classid |= *(buf++) << 8;
- classid |= *(buf++);
-
+ /* Swap classid because we read it in BE meaning WAYP or DFLT */
+ uint32 classid = BSWAP32(grf_load_dword(&buf));
statspec[i].sclass = AllocateStationClass(classid);
}
break;
@@ -2134,19 +2118,19 @@ static void GRFInfo(byte *buf, int len)
const char *name;
const char *info;
- check_length(len, 8, "GRFInfo");
- version = buf[1];
- /* this is de facto big endian - grf_load_dword() unsuitable */
- grfid = buf[2] << 24 | buf[3] << 16 | buf[4] << 8 | buf[5];
- name = (const char*)(buf + 6);
+ check_length(len, 8, "GRFInfo"); buf++;
+ version = grf_load_byte(buf);
+ grfid = grf_load_dword(&buf);
+ name = (const char*)buf;
info = name + strlen(name) + 1;
_cur_grffile->grfid = grfid;
_cur_grffile->grf_version = version;
_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",
- _cur_grffile->filename, version, grfid, name, info);
+ _cur_grffile->filename, version, BSWAP32(grfid), name, info);
}
/* Action 0x0A */
diff --git a/settings_gui.c b/settings_gui.c
index 2678f5eb0..47f0b37c5 100644
--- a/settings_gui.c
+++ b/settings_gui.c
@@ -957,7 +957,7 @@ static void NewgrfWndProc(Window *w, WindowEvent *e)
// draw grf id
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);
}
} break;