Jump to content

Regen's direction integer type fix


Intel

Recommended Posts

  • Premium

So, @ Syreldar was making a quest for a server I am working on and, he noticed that after the value 255, the direction set was not working properly.

For some reason, dir is an int almost everywhere, except his declaration in the struct and the two lua functions.

I understand the int in the spawnmob function as a parameter, for the -1 thing to decide to make it random, but then, it should be a number between 0 and 359 but somehow they decided to go with an 8bits representation number (BYTE)

So here we are fixing another korean mistake..

 

Go to regen.h, and replace:

BYTE    direction;

with
 

uint16_t    direction;

Go to questlua_dungeon.cpp, replace:

BYTE dir = (int) lua_tonumber(L, 4);

with

uint16_t dir = static_cast<uint16_t>(lua_tonumber(L, 4));

both in dungeon_spawn_mob_dir_ac and dungeon_spawn_mob_dir (not needed but for consistency at this point..)

 

Go to char_manager.cpp in:

LPCHARACTER CHARACTER_MANAGER::SpawnMob(DWORD dwVnum, long lMapIndex, long x, long y, long z, bool bSpawnMotion, int iRot, bool bShow) 

add:

    if(iRot > 359){
        iRot = 359;
    }

before

    if (iRot == -1)
        iRot = number(0, 360);

 

and that's it.

  • Metin2 Dev 4
  • Cry 1
  • Lmao 1
  • Good 1
  • Love 2
  • Love 3
Link to comment
Share on other sites

  • Active Member

The same issue is present within the characters, due to the rotation values in the move packets, after interaction with mount and horse, there will be synchronization issues in your movements by other individuals. Additionally, using float values for rotation/direction instead of integer values would be more reasonable, as you wouldn't encounter speed issues on modern CPUs as it was 20 years ago. Thanks for share.

  • Good 1
Link to comment
Share on other sites

  • Forum Moderator

Thank you for share!

BYTE dir = (int) lua_tonumber(L, 4);

I legit sighed. This is exactly what I said on the Discord two days ago, some types and some castings doesn't make a single sense at all. They will assign a BYTE for directions and other important stuff (causing this kind of issue or simply hard future-proof code) while casually assigning a DWORD and other way too big types for a single constant, let's say guild levels or the amount guild members

  • kekw 2
  • Cry 1
  • Good 1

Gurgarath
coming soon

Link to comment
Share on other sites

  • Premium
5 hours ago, Gurgarath said:

Thank you for share!

BYTE dir = (int) lua_tonumber(L, 4);

I legit sighed. This is exactly what I said on the Discord two days ago, some types and some castings doesn't make a single sense at all. They will assign a BYTE for directions and other important stuff (causing this kind of issue or simply hard future-proof code) while casually assigning a DWORD and other way too big types for a single constant, let's say guild levels or the amount guild members

Yeah, I immediately had you and that discussion in mind when I found this lol

 

Syreldar also showed me the directions used for the dungeons in the official. All under 255. Legit multiverses aligned for this thing to never be discovered before lmao

Edited by Intel
  • Metin2 Dev 1
Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.