valdirk2 83 Posted October 15, 2020 Share Posted October 15, 2020 (edited) Well, first I had a BUG on a client, if there were a lot of items on the floor, I kept pressing Z to pick up the items, until suddenly he stopped picking up. Then, I found that the function that maps the items that were nearby simply sent the package to pick up an item that was too far away and ignored those that were really close. I searched a lot on google for a solution, I saw two or three post with this same bug, but without solution. I know almost nothing about C ++, but I managed and managed to solve it. If anyone has an idea, or any better way to resolve it, please leave your idea. So what did I do? Spoiler locale_inc.h Add: #define ENABLE_FIX_PICKITEM PythonItem.cpp Search and replace the entire function: bool CPythonItem::GetCloseItem(const TPixelPosition & c_rPixelPosition, DWORD * pdwItemID, DWORD dwDistance) { DWORD dwCloseItemID = 0; DWORD dwCloseItemDistance = 1000 * 1000; TGroundItemInstanceMap::iterator i; for (i = m_GroundItemInstanceMap.begin(); i != m_GroundItemInstanceMap.end(); ++i) { TGroundItemInstance * pInstance = i->second; DWORD dwxDistance = DWORD(c_rPixelPosition.x-pInstance->v3EndPosition.x); DWORD dwyDistance = DWORD(c_rPixelPosition.y-(-pInstance->v3EndPosition.y)); DWORD dwDistance = DWORD(dwxDistance*dwxDistance + dwyDistance*dwyDistance); if (dwxDistance*dwxDistance + dwyDistance*dwyDistance < dwCloseItemDistance) { dwCloseItemID = i->first; dwCloseItemDistance = dwDistance; } } if (dwCloseItemDistance>float(dwDistance)*float(dwDistance)) return false; *pdwItemID=dwCloseItemID; return true; } for this: #ifdef ENABLE_FIX_PICKITEM int DISTANCE_APPROX(int dx, int dy) { int min, max; if (dx < 0) dx = -dx; if (dy < 0) dy = -dy; if (dx < dy) { min = dx; max = dy; } else { min = dy; max = dx; } // coefficients equivalent to ( 123/128 * max ) and ( 51/128 * min ) return (((max << 8) + (max << 3) - (max << 4) - (max << 1) + (min << 7) - (min << 5) + (min << 3) - (min << 1)) >> 8); } bool CPythonItem::GetCloseItem(const TPixelPosition& c_rPixelPosition, DWORD* pdwItemID, DWORD dwDistance) { DWORD dwCloseItemID = 0; DWORD dwCloseItemDistance = 0; int aproMin = 0; TGroundItemInstanceMap::iterator i; for (i = m_GroundItemInstanceMap.begin(); i != m_GroundItemInstanceMap.end(); ++i) { TGroundItemInstance* pInstance = i->second; int iDist = DISTANCE_APPROX((int)c_rPixelPosition.x - (int)pInstance->v3EndPosition.x, (int)c_rPixelPosition.y - (-(int)pInstance->v3EndPosition.y)); if (aproMin == 0) aproMin = iDist; if (aproMin >= iDist) { aproMin = iDist; dwCloseItemID = i->first; dwCloseItemDistance = iDist; } } if (dwCloseItemDistance > 300) return false; *pdwItemID = dwCloseItemID; return true; } #else bool CPythonItem::GetCloseItem(const TPixelPosition& c_rPixelPosition, DWORD* pdwItemID, DWORD dwDistance) { DWORD dwCloseItemID = 0; DWORD dwCloseItemDistance = 1000 * 1000; TGroundItemInstanceMap::iterator i; for (i = m_GroundItemInstanceMap.begin(); i != m_GroundItemInstanceMap.end(); ++i) { TGroundItemInstance* pInstance = i->second; DWORD dwxDistance = DWORD(c_rPixelPosition.x - pInstance->v3EndPosition.x); DWORD dwyDistance = DWORD(c_rPixelPosition.y - (-pInstance->v3EndPosition.y)); DWORD dwDistance = DWORD(dwxDistance * dwxDistance + dwyDistance * dwyDistance); if (dwxDistance * dwxDistance + dwyDistance * dwyDistance < dwCloseItemDistance) { dwCloseItemID = i->first; dwCloseItemDistance = dwDistance; } } if (dwCloseItemDistance > float(dwDistance) * float(dwDistance)) return false; *pdwItemID = dwCloseItemID; return true; } #endif With that he will always pick the item that is at a closer average distance, different from the other function that I did not understand well how it worked... As I said, I am very lay with C ++, but there is a solution to a bug that I solved. Edited October 18, 2020 by valdirk2 Fixing tutorial 1 2 2 4 Link to comment Share on other sites More sharing options...
Active Member Volvox 1510 Posted October 15, 2020 Active Member Share Posted October 15, 2020 hehe nice stolen from Lead 1 1 1 Link to comment Share on other sites More sharing options...
Contributor MrQuin 6402 Posted October 15, 2020 Contributor Share Posted October 15, 2020 (edited) So you did some reverse engineering to find the problem then you searched for the fix in google Edited August 25, 2022 by Metin2 Dev Core X - External 2 Internal 3 My only accounts are here and on M2D, Don't trust anyone else from other shitty sites. Link to comment Share on other sites More sharing options...
valdirk2 83 Posted October 15, 2020 Author Share Posted October 15, 2020 Where is this fix? I spent two hours searching on google and didn't find any correction, if someone did a fix better than mine, I definitely want to use it. Link to comment Share on other sites More sharing options...
LordZiege 279 Posted October 15, 2020 Share Posted October 15, 2020 2 hours ago, valdirk2 said: Where is this fix? I spent two hours searching on google and didn't find any correction, if someone did a fix better than mine, I definitely want to use it. It is not your fix wtf 1 Link to comment Share on other sites More sharing options...
Active Member Volvox 1510 Posted October 15, 2020 Active Member Share Posted October 15, 2020 2 hours ago, valdirk2 said: Where is this fix? I spent two hours searching on google and didn't find any correction, if someone did a fix better than mine, I definitely want to use it. Whats wrong with you ? Lead @ another famous Metin2 Forum did create this code. Pay him respect with a mention or i report your "fix" for being stolen 1 Link to comment Share on other sites More sharing options...
LordZiege 279 Posted October 15, 2020 Share Posted October 15, 2020 also ask for a fix 17 hours ago, so its not your fix, only stealer. 1 3 Link to comment Share on other sites More sharing options...
Lead0b110010100 15 Posted November 2, 2020 Share Posted November 2, 2020 Hey Lead here from the other board. I don't think he has stolen it from me, maybe he got the idea from there and then coded it himself. I would recognize my own code style if he had really copied it one for one. 3 Link to comment Share on other sites More sharing options...
valdirk2 83 Posted November 3, 2020 Author Share Posted November 3, 2020 On 11/1/2020 at 10:11 PM, Lead0b110010100 said: Hey Lead here from the other board. I don't think he has stolen it from me, maybe he got the idea from there and then coded it himself. I would recognize my own code style if he had really copied it one for one. I didn't really copy it, I spent hours researching some fix about it ... and I didn't find it, and if I had found it I would have saved myself 4 hours trying to solve it hahahaha But if you had the same idea as me, I believe I'm on the right path xD 2 Link to comment Share on other sites More sharing options...
nyland 4 Posted April 24, 2021 Share Posted April 24, 2021 (edited) too much noise for little things... Edited April 24, 2021 by nyland 2 Link to comment Share on other sites More sharing options...
Recommended Posts