150 va_end(va); |
150 va_end(va); |
151 |
151 |
152 DEBUG(grf, severity, "[%s:%d] %s", _cur_grfconfig->filename, _nfo_line, buf); |
152 DEBUG(grf, severity, "[%s:%d] %s", _cur_grfconfig->filename, _nfo_line, buf); |
153 } |
153 } |
154 |
154 |
155 static inline bool check_length(int real, int wanted, const char *str) |
155 static inline bool check_length(size_t real, size_t wanted, const char *str) |
156 { |
156 { |
157 if (real >= wanted) return true; |
157 if (real >= wanted) return true; |
158 grfmsg(0, "%s: Invalid pseudo sprite length %d (expected %d)!", str, real, wanted); |
158 grfmsg(0, "%s: Invalid pseudo sprite length %d (expected %d)!", str, real, wanted); |
159 return false; |
159 return false; |
160 } |
160 } |
2361 if (ignoring) grfmsg(1, "FeatureChangeInfo: Ignoring property 0x%02X of feature 0x%02X (not implemented)", prop, feature); |
2361 if (ignoring) grfmsg(1, "FeatureChangeInfo: Ignoring property 0x%02X of feature 0x%02X (not implemented)", prop, feature); |
2362 } |
2362 } |
2363 } |
2363 } |
2364 |
2364 |
2365 /* Action 0x00 (GLS_SAFETYSCAN) */ |
2365 /* Action 0x00 (GLS_SAFETYSCAN) */ |
2366 static void SafeChangeInfo(byte *buf, int len) |
2366 static void SafeChangeInfo(byte *buf, size_t len) |
2367 { |
2367 { |
2368 if (!check_length(len, 6, "SafeChangeInfo")) return; |
2368 if (!check_length(len, 6, "SafeChangeInfo")) return; |
2369 buf++; |
2369 buf++; |
2370 uint8 feature = grf_load_byte(&buf); |
2370 uint8 feature = grf_load_byte(&buf); |
2371 uint8 numprops = grf_load_byte(&buf); |
2371 uint8 numprops = grf_load_byte(&buf); |
2384 /* Skip remainder of GRF */ |
2384 /* Skip remainder of GRF */ |
2385 _skip_sprites = -1; |
2385 _skip_sprites = -1; |
2386 } |
2386 } |
2387 |
2387 |
2388 /* Action 0x00 (GLS_RESERVE) */ |
2388 /* Action 0x00 (GLS_RESERVE) */ |
2389 static void ReserveChangeInfo(byte *buf, int len) |
2389 static void ReserveChangeInfo(byte *buf, size_t len) |
2390 { |
2390 { |
2391 byte *bufend = buf + len; |
2391 byte *bufend = buf + len; |
2392 |
2392 |
2393 if (!check_length(len, 6, "ReserveChangeInfo")) return; |
2393 if (!check_length(len, 6, "ReserveChangeInfo")) return; |
2394 buf++; |
2394 buf++; |
2480 group->g.result.num_sprites = num_sprites; |
2480 group->g.result.num_sprites = num_sprites; |
2481 return group; |
2481 return group; |
2482 } |
2482 } |
2483 |
2483 |
2484 /* Action 0x01 */ |
2484 /* Action 0x01 */ |
2485 static void NewSpriteSet(byte *buf, int len) |
2485 static void NewSpriteSet(byte *buf, size_t len) |
2486 { |
2486 { |
2487 /* <01> <feature> <num-sets> <num-ent> |
2487 /* <01> <feature> <num-sets> <num-ent> |
2488 * |
2488 * |
2489 * B feature feature to define sprites for |
2489 * B feature feature to define sprites for |
2490 * 0, 1, 2, 3: veh-type, 4: train stations |
2490 * 0, 1, 2, 3: veh-type, 4: train stations |
2516 LoadNextSprite(_cur_spriteid++, _file_index, _nfo_line); |
2516 LoadNextSprite(_cur_spriteid++, _file_index, _nfo_line); |
2517 } |
2517 } |
2518 } |
2518 } |
2519 |
2519 |
2520 /* Action 0x01 (SKIP) */ |
2520 /* Action 0x01 (SKIP) */ |
2521 static void SkipAct1(byte *buf, int len) |
2521 static void SkipAct1(byte *buf, size_t len) |
2522 { |
2522 { |
2523 if (!check_length(len, 4, "SkipAct1")) return; |
2523 if (!check_length(len, 4, "SkipAct1")) return; |
2524 buf++; |
2524 buf++; |
2525 grf_load_byte(&buf); |
2525 grf_load_byte(&buf); |
2526 uint8 num_sets = grf_load_byte(&buf); |
2526 uint8 num_sets = grf_load_byte(&buf); |
2575 |
2575 |
2576 return NewResultSpriteGroup(_cur_grffile->spriteset_start + spriteid * num_sprites, num_sprites); |
2576 return NewResultSpriteGroup(_cur_grffile->spriteset_start + spriteid * num_sprites, num_sprites); |
2577 } |
2577 } |
2578 |
2578 |
2579 /* Action 0x02 */ |
2579 /* Action 0x02 */ |
2580 static void NewSpriteGroup(byte *buf, int len) |
2580 static void NewSpriteGroup(byte *buf, size_t len) |
2581 { |
2581 { |
2582 /* <02> <feature> <set-id> <type/num-entries> <feature-specific-data...> |
2582 /* <02> <feature> <set-id> <type/num-entries> <feature-specific-data...> |
2583 * |
2583 * |
2584 * B feature see action 1 |
2584 * B feature see action 1 |
2585 * B set-id ID of this particular definition |
2585 * B set-id ID of this particular definition |
3265 return; |
3265 return; |
3266 } |
3266 } |
3267 } |
3267 } |
3268 |
3268 |
3269 /* Action 0x04 */ |
3269 /* Action 0x04 */ |
3270 static void FeatureNewName(byte *buf, int len) |
3270 static void FeatureNewName(byte *buf, size_t len) |
3271 { |
3271 { |
3272 /* <04> <veh-type> <language-id> <num-veh> <offset> <data...> |
3272 /* <04> <veh-type> <language-id> <num-veh> <offset> <data...> |
3273 * |
3273 * |
3274 * B veh-type see action 0 (as 00..07, + 0A |
3274 * B veh-type see action 0 (as 00..07, + 0A |
3275 * But IF veh-type = 48, then generic text |
3275 * But IF veh-type = 48, then generic text |
3533 |
3533 |
3534 _skip_sprites = skip_num; |
3534 _skip_sprites = skip_num; |
3535 } |
3535 } |
3536 |
3536 |
3537 /* Action 0x05 (SKIP) */ |
3537 /* Action 0x05 (SKIP) */ |
3538 static void SkipAct5(byte *buf, int len) |
3538 static void SkipAct5(byte *buf, size_t len) |
3539 { |
3539 { |
3540 if (!check_length(len, 2, "SkipAct5")) return; |
3540 if (!check_length(len, 2, "SkipAct5")) return; |
3541 buf++; |
3541 buf++; |
3542 |
3542 |
3543 /* Ignore type byte */ |
3543 /* Ignore type byte */ |
3952 } |
3952 } |
3953 } |
3953 } |
3954 |
3954 |
3955 |
3955 |
3956 /* Action 0x08 (GLS_FILESCAN) */ |
3956 /* Action 0x08 (GLS_FILESCAN) */ |
3957 static void ScanInfo(byte *buf, int len) |
3957 static void ScanInfo(byte *buf, size_t len) |
3958 { |
3958 { |
3959 if (!check_length(len, 8, "Info")) return; |
3959 if (!check_length(len, 8, "Info")) return; |
3960 buf++; |
3960 buf++; |
3961 grf_load_byte(&buf); |
3961 grf_load_byte(&buf); |
3962 uint32 grfid = grf_load_dword(&buf); |
3962 uint32 grfid = grf_load_dword(&buf); |
3979 /* GLS_INFOSCAN only looks for the action 8, so we can skip the rest of the file */ |
3979 /* GLS_INFOSCAN only looks for the action 8, so we can skip the rest of the file */ |
3980 _skip_sprites = -1; |
3980 _skip_sprites = -1; |
3981 } |
3981 } |
3982 |
3982 |
3983 /* Action 0x08 */ |
3983 /* Action 0x08 */ |
3984 static void GRFInfo(byte *buf, int len) |
3984 static void GRFInfo(byte *buf, size_t len) |
3985 { |
3985 { |
3986 /* <08> <version> <grf-id> <name> <info> |
3986 /* <08> <version> <grf-id> <name> <info> |
3987 * |
3987 * |
3988 * B version newgrf version, currently 06 |
3988 * B version newgrf version, currently 06 |
3989 * 4*B grf-id globally unique ID of this .grf file |
3989 * 4*B grf-id globally unique ID of this .grf file |
4003 /* Do swap the GRFID for displaying purposes since people expect that */ |
4003 /* Do swap the GRFID for displaying purposes since people expect that */ |
4004 DEBUG(grf, 1, "GRFInfo: Loaded GRFv%d set %08lX - %s", version, BSWAP32(grfid), name); |
4004 DEBUG(grf, 1, "GRFInfo: Loaded GRFv%d set %08lX - %s", version, BSWAP32(grfid), name); |
4005 } |
4005 } |
4006 |
4006 |
4007 /* Action 0x0A */ |
4007 /* Action 0x0A */ |
4008 static void SpriteReplace(byte *buf, int len) |
4008 static void SpriteReplace(byte *buf, size_t len) |
4009 { |
4009 { |
4010 /* <0A> <num-sets> <set1> [<set2> ...] |
4010 /* <0A> <num-sets> <set1> [<set2> ...] |
4011 * <set>: <num-sprites> <first-sprite> |
4011 * <set>: <num-sprites> <first-sprite> |
4012 * |
4012 * |
4013 * B num-sets How many sets of sprites to replace. |
4013 * B num-sets How many sets of sprites to replace. |
4055 |
4055 |
4056 grfmsg(3, "SkipActA: Skipping %d sprites", _skip_sprites); |
4056 grfmsg(3, "SkipActA: Skipping %d sprites", _skip_sprites); |
4057 } |
4057 } |
4058 |
4058 |
4059 /* Action 0x0B */ |
4059 /* Action 0x0B */ |
4060 static void GRFLoadError(byte *buf, int len) |
4060 static void GRFLoadError(byte *buf, size_t len) |
4061 { |
4061 { |
4062 /* <0B> <severity> <language-id> <message-id> [<message...> 00] [<data...>] 00 [<parnum>] |
4062 /* <0B> <severity> <language-id> <message-id> [<message...> 00] [<data...>] 00 [<parnum>] |
4063 * |
4063 * |
4064 * B severity 00: notice, contine loading grf file |
4064 * B severity 00: notice, contine loading grf file |
4065 * 01: warning, continue loading grf file |
4065 * 01: warning, continue loading grf file |
4165 |
4165 |
4166 _cur_grfconfig->error = error; |
4166 _cur_grfconfig->error = error; |
4167 } |
4167 } |
4168 |
4168 |
4169 /* Action 0x0C */ |
4169 /* Action 0x0C */ |
4170 static void GRFComment(byte *buf, int len) |
4170 static void GRFComment(byte *buf, size_t len) |
4171 { |
4171 { |
4172 /* <0C> [<ignored...>] |
4172 /* <0C> [<ignored...>] |
4173 * |
4173 * |
4174 * V ignored Anything following the 0C is ignored */ |
4174 * V ignored Anything following the 0C is ignored */ |
4175 |
4175 |
4176 if (len == 1) return; |
4176 if (len == 1) return; |
4177 |
4177 |
4178 int text_len = len - 1; |
4178 size_t text_len = len - 1; |
4179 const char *text = (const char*)(buf + 1); |
4179 const char *text = (const char*)(buf + 1); |
4180 grfmsg(2, "GRFComment: %.*s", text_len, text); |
4180 grfmsg(2, "GRFComment: %.*s", text_len, text); |
4181 } |
4181 } |
4182 |
4182 |
4183 /* Action 0x0D (GLS_SAFETYSCAN) */ |
4183 /* Action 0x0D (GLS_SAFETYSCAN) */ |
4184 static void SafeParamSet(byte *buf, int len) |
4184 static void SafeParamSet(byte *buf, size_t len) |
4185 { |
4185 { |
4186 if (!check_length(len, 5, "SafeParamSet")) return; |
4186 if (!check_length(len, 5, "SafeParamSet")) return; |
4187 buf++; |
4187 buf++; |
4188 uint8 target = grf_load_byte(&buf); |
4188 uint8 target = grf_load_byte(&buf); |
4189 |
4189 |
4311 return UINT_MAX; |
4311 return UINT_MAX; |
4312 } |
4312 } |
4313 |
4313 |
4314 |
4314 |
4315 /* Action 0x0D */ |
4315 /* Action 0x0D */ |
4316 static void ParamSet(byte *buf, int len) |
4316 static void ParamSet(byte *buf, size_t len) |
4317 { |
4317 { |
4318 /* <0D> <target> <operation> <source1> <source2> [<data>] |
4318 /* <0D> <target> <operation> <source1> <source2> [<data>] |
4319 * |
4319 * |
4320 * B target parameter number where result is stored |
4320 * B target parameter number where result is stored |
4321 * B operation operation to perform, see below |
4321 * B operation operation to perform, see below |
4602 break; |
4602 break; |
4603 } |
4603 } |
4604 } |
4604 } |
4605 |
4605 |
4606 /* Action 0x0E (GLS_SAFETYSCAN) */ |
4606 /* Action 0x0E (GLS_SAFETYSCAN) */ |
4607 static void SafeGRFInhibit(byte *buf, int len) |
4607 static void SafeGRFInhibit(byte *buf, size_t len) |
4608 { |
4608 { |
4609 /* <0E> <num> <grfids...> |
4609 /* <0E> <num> <grfids...> |
4610 * |
4610 * |
4611 * B num Number of GRFIDs that follow |
4611 * B num Number of GRFIDs that follow |
4612 * D grfids GRFIDs of the files to deactivate */ |
4612 * D grfids GRFIDs of the files to deactivate */ |
4755 grfmsg(6, "FeatureTownName: part %d, total probability %d", i, townname->partlist[id][i].maxprob); |
4755 grfmsg(6, "FeatureTownName: part %d, total probability %d", i, townname->partlist[id][i].maxprob); |
4756 } |
4756 } |
4757 } |
4757 } |
4758 |
4758 |
4759 /* Action 0x10 */ |
4759 /* Action 0x10 */ |
4760 static void DefineGotoLabel(byte *buf, int len) |
4760 static void DefineGotoLabel(byte *buf, size_t len) |
4761 { |
4761 { |
4762 /* <10> <label> [<comment>] |
4762 /* <10> <label> [<comment>] |
4763 * |
4763 * |
4764 * B label The label to define |
4764 * B label The label to define |
4765 * V comment Optional comment - ignored */ |
4765 * V comment Optional comment - ignored */ |
4928 } |
4928 } |
4929 } |
4929 } |
4930 } |
4930 } |
4931 |
4931 |
4932 /* Action 0x12 */ |
4932 /* Action 0x12 */ |
4933 static void LoadFontGlyph(byte *buf, int len) |
4933 static void LoadFontGlyph(byte *buf, size_t len) |
4934 { |
4934 { |
4935 /* <12> <num_def> <font_size> <num_char> <base_char> |
4935 /* <12> <num_def> <font_size> <num_char> <base_char> |
4936 * |
4936 * |
4937 * B num_def Number of definitions |
4937 * B num_def Number of definitions |
4938 * B font_size Size of font (0 = normal, 1 = small, 2 = large) |
4938 * B font_size Size of font (0 = normal, 1 = small, 2 = large) |
4960 } |
4960 } |
4961 } |
4961 } |
4962 } |
4962 } |
4963 |
4963 |
4964 /* Action 0x12 (SKIP) */ |
4964 /* Action 0x12 (SKIP) */ |
4965 static void SkipAct12(byte *buf, int len) |
4965 static void SkipAct12(byte *buf, size_t len) |
4966 { |
4966 { |
4967 /* <12> <num_def> <font_size> <num_char> <base_char> |
4967 /* <12> <num_def> <font_size> <num_char> <base_char> |
4968 * |
4968 * |
4969 * B num_def Number of definitions |
4969 * B num_def Number of definitions |
4970 * B font_size Size of font (0 = normal, 1 = small, 2 = large) |
4970 * B font_size Size of font (0 = normal, 1 = small, 2 = large) |
4990 |
4990 |
4991 grfmsg(3, "SkipAct12: Skipping %d sprites", _skip_sprites); |
4991 grfmsg(3, "SkipAct12: Skipping %d sprites", _skip_sprites); |
4992 } |
4992 } |
4993 |
4993 |
4994 /* Action 0x13 */ |
4994 /* Action 0x13 */ |
4995 static void TranslateGRFStrings(byte *buf, int len) |
4995 static void TranslateGRFStrings(byte *buf, size_t len) |
4996 { |
4996 { |
4997 /* <13> <grfid> <num-ent> <offset> <text...> |
4997 /* <13> <grfid> <num-ent> <offset> <text...> |
4998 * |
4998 * |
4999 * 4*B grfid The GRFID of the file whose texts are to be translated |
4999 * 4*B grfid The GRFID of the file whose texts are to be translated |
5000 * B num-ent Number of strings |
5000 * B num-ent Number of strings |