need explaination for a piece of vb

ResourcefulDB
ResourcefulDB used Ask the Experts™
on
hi all, here is a  piece of script for a game bot. please help me to understand what it does.

function NTP_BOSwitch()
{
	if(_NTP_HaveCTA < 0)
	{
		var _weapon;

		_NTP_HaveCTA = 0;

		_weapon = me.GetItems();

		if(_weapon)
		{
			for(var i = 0 ; i < _weapon.length ; i++)
			{
				if(_weapon[i].mode == 1 && (_weapon[i].itemflag&0x4000000) && _weapon[i].itemprefix == 0x5027)
				{
					if(_weapon[i].itemloc == 4 || _weapon[i].itemloc == 5)
						_NTP_HaveCTA = 1;
					else
						_NTP_HaveCTA = 2;

					break;
				}
			}
		}
	}

	if(_NTP_HaveCTA > 0)
		return NTC_SwapWeapons(_NTP_HaveCTA-1);

	return false;
}

Open in new window

Thanks,
RDB
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
please help, the original code was not documented.
Most Valuable Expert 2013

Commented:
Looks like a WOW script
0x5027 is Bone Armor so looks like it polls your inventory to see if you have Bone Armor and then equips if you don't have it it loops until you do.
Is this it or is it part of a larger (presumably Necro) script?
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009

Commented:
That's certainly not VB...

...and I'm pretty certain no one will be able to help you decipher what this code is doing as it is comparing against numeric values which have no context outside of the application itself!

At a high level it is iterating over the items looking for something that meets this criteria:

    if(_weapon[i].mode == 1 && (_weapon[i].itemflag&0x4000000) && _weapon[i].itemprefix == 0x5027)

If one is found then _NTP_HaveCTA is set to 1 or 2 based on this conditional check:

        if(_weapon[i].itemloc == 4 || _weapon[i].itemloc == 5)

At this point the loop is stopped and either false is returned or the weapon is apparently swapped by making a call to NTC_SwapWeapons():

        if(_NTP_HaveCTA > 0)
            return NTC_SwapWeapons(_NTP_HaveCTA-1);

      return false;

*Again, this code is really meaningless unless you know what the numeric constants represent in the context of the game...
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009

Commented:
Looks like MASQUERAID might know what it is...good luck!  =D

Author

Commented:
it is a diablo 2 script. a char can equip two set of weapon in d2. let us call them set 1 and set 2.

this code is supposed to determine if a certain weapon in set 2. if it does, then do a swap to equip set 2.

What I donot understand is a lot of about syntax. e.g.

1. what does line 5 do?
2. what is _weapon.length? where does it come from, i guess it is from line 9.
3. As MASQUERAID pointed out "0x5027 is Bone Armor ", where do we get this information, I am not sure if 0x5027 is really bone armor or part of other item.
4. line 15 got a lot of things there to identify, it got .mode, .itemflag, .itemprefix. where do we find all those things in our game folder?

thanks,
RDB
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009

Commented:
Line 5:

            var _weapon;

Declares a variable called "_weapon".

Looks like the GetItems() function returns an Array or a Collection of some kind.  "weapon.length" is returning the number of items in the array so that the "i" variable will go from 0 (zero) to the the length of the array minus 1 (one).

Anyone with a little programming experience should be able to understand this...  =\

As for the rest, does Diablo 2 have any kind of documented SDK (Software Development Kit)?

Top Expert 2010

Commented:

<< As for the rest, does Diablo 2 have any kind of documented SDK (Software Development Kit)? >> 
LOL.. I doubt it especially not from the developers anyway but I'm sure a bunch of hackers make there own SDK for the game =)

No this is purely against the terms of these games as far as I know... Basically it's reading the thread local storage of the in game memory which can get your account banned if the "warden" finds out =)
These bots start by enabling SeDebugPrivilege then either use ReadProcessMemory() or Inject a DLL hook into the process to read it's memory. They find the thread local storage slot that has the specific memory for the games internal data structure like objects,players,game fields. These are located at specific offset and generally the address changes when the game is updated or patched.
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009

Commented:
Hehe...I figured as much, but it's been years since I played Diablo 2.  Wasn't sure if there were any "sanctioned" mod servers running these days...  =D
Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009

Commented:
Good grief...time flies!  It's been a decade since DII was released...
Top Expert 2010

Commented:
LOL.. I can say the same about a game I used to play on the zone.com when it was around called Age Of Empires .. Even worst if I try to play the game on the this monitor it doesn't support anything above 1024x resolution pretty old!
Top Expert 2010
Commented:
Here is wiki about the (Warden)
http://en.wikipedia.org/wiki/Warden_(software)

Author

Commented:
Thanks for the infor and the link. very helpful.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial