From 77a85e9b4c67e50550fe9c7b28064654e1a1ddf9 Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Sat, 9 Jul 2022 20:06:22 +0200 Subject: [PATCH] Fix: CmdSetAutoReplace didn't validate group type and engine type match (#9950) Basically, you could setup an auto-replace in a group for trains to replace a ship with another ship. Most of the code is surprisingly okay with this, it is only the group statistics that doesn't like this. --- src/autoreplace_cmd.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp index 73f796cb73..654003e39e 100644 --- a/src/autoreplace_cmd.cpp +++ b/src/autoreplace_cmd.cpp @@ -815,6 +815,7 @@ CommandCost CmdSetAutoReplace(DoCommandFlag flags, GroupID id_g, EngineID old_en if (Group::IsValidID(id_g) ? Group::Get(id_g)->owner != _current_company : !IsAllGroupID(id_g) && !IsDefaultGroupID(id_g)) return CMD_ERROR; if (!Engine::IsValidID(old_engine_type)) return CMD_ERROR; + if (Group::IsValidID(id_g) && Group::Get(id_g)->vehicle_type != Engine::Get(old_engine_type)->type) return CMD_ERROR; if (new_engine_type != INVALID_ENGINE) { if (!Engine::IsValidID(new_engine_type)) return CMD_ERROR;