Skip to content

Commit e671d02

Browse files
committed
Fix an issue with named/brewed/forged items getting saved with the wrong character id
The isue was triggered by the refactoring of old undocumented code that relied on the overflow behavior during assignment from int32 to int16 and from uint16 to int16, and by a subsequent clamping to SMALLINT range operated by the SQL server. Credits: Haru <[email protected]> Fixes #2409 Signed-off-by: Ibrahim Zidan <[email protected]>
1 parent ab81d40 commit e671d02

File tree

4 files changed

+37
-9
lines changed

4 files changed

+37
-9
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#1554760320
2+
3+
-- This file is part of Hercules.
4+
-- http://herc.ws - http://github.com/HerculesWS/Hercules
5+
--
6+
-- Copyright (C) 2013-2019 Hercules Dev Team
7+
--
8+
-- Hercules is free software: you can redistribute it and/or modify
9+
-- it under the terms of the GNU General Public License as published by
10+
-- the Free Software Foundation, either version 3 of the License, or
11+
-- (at your option) any later version.
12+
--
13+
-- This program is distributed in the hope that it will be useful,
14+
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
-- GNU General Public License for more details.
17+
--
18+
-- You should have received a copy of the GNU General Public License
19+
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
21+
UPDATE `auction` SET `card3` = `card2` >> 16, `card2` = `card2` % 65536 WHERE `card2` > 65536 AND (`card0` = 255 OR `card0` = 254);
22+
UPDATE `cart_inventory` SET `card3` = `card2` >> 16, `card2` = `card2` % 65536 WHERE `card2` > 65536 AND (`card0` = 255 OR `card0` = 254);
23+
UPDATE `inventory` SET `card3` = `card2` >> 16, `card2` = `card2` % 65536 WHERE `card2` > 65536 AND (`card0` = 255 OR `card0` = 254);
24+
UPDATE `guild_storage` SET `card3` = `card2` >> 16, `card2` = `card2` % 65536 WHERE `card2` > 65536 AND (`card0` = 255 OR `card0` = 254);
25+
UPDATE `mail` SET `card3` = `card2` >> 16, `card2` = `card2` % 65536 WHERE `card2` > 65536 AND (`card0` = 255 OR `card0` = 254);
26+
UPDATE `rodex_items` SET `card3` = `card2` >> 16, `card2` = `card2` % 65536 WHERE `card2` > 65536 AND (`card0` = 255 OR `card0` = 254);
27+
UPDATE `storage` SET `card3` = `card2` >> 16, `card2` = `card2` % 65536 WHERE `card2` > 65536 AND (`card0` = 255 OR `card0` = 254);

sql-files/upgrades/index.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@
5252
2018-09-01--05-22.sql
5353
2018-12-14--01-02.sql
5454
2018-12-29--07-51.sql
55+
2019-04-08--23-52.sql

src/map/atcommand.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5599,9 +5599,9 @@ static void atcommand_getring(struct map_session_data *sd)
55995599
memset(&item_tmp, 0, sizeof(item_tmp));
56005600
item_tmp.nameid = item_id;
56015601
item_tmp.identify = 1;
5602-
item_tmp.card[0] = 255;
5603-
item_tmp.card[2] = sd->status.partner_id;
5604-
item_tmp.card[3] = sd->status.partner_id >> 16;
5602+
item_tmp.card[0] = CARD0_FORGE;
5603+
item_tmp.card[2] = GetWord(sd->status.partner_id, 0);
5604+
item_tmp.card[3] = GetWord(sd->status.partner_id, 1);
56055605

56065606
if((flag = pc->additem(sd,&item_tmp,1,LOG_TYPE_COMMAND))) {
56075607
clif->additem(sd,0,0,flag);

src/map/script.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8177,12 +8177,12 @@ static BUILDIN(getnameditem)
81778177
}
81788178

81798179
memset(&item_tmp,0,sizeof(item_tmp));
8180-
item_tmp.nameid=nameid;
8181-
item_tmp.amount=1;
8182-
item_tmp.identify=1;
8183-
item_tmp.card[0]=CARD0_CREATE; //we don't use 255! because for example SIGNED WEAPON shouldn't get TOP10 BS Fame bonus [Lupus]
8184-
item_tmp.card[2]=tsd->status.char_id;
8185-
item_tmp.card[3]=tsd->status.char_id >> 16;
8180+
item_tmp.nameid = nameid;
8181+
item_tmp.amount = 1;
8182+
item_tmp.identify = 1;
8183+
item_tmp.card[0] = CARD0_CREATE; //we don't use 255! because for example SIGNED WEAPON shouldn't get TOP10 BS Fame bonus [Lupus]
8184+
item_tmp.card[2] = GetWord(tsd->status.char_id, 0);
8185+
item_tmp.card[3] = GetWord(tsd->status.char_id, 1);
81868186
if(pc->additem(sd,&item_tmp,1,LOG_TYPE_SCRIPT)) {
81878187
script_pushint(st,0);
81888188
return true; //Failed to add item, we will not drop if they don't fit

0 commit comments

Comments
 (0)