Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C++] Help me understand a script :]

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
kopelito
Master Cheater
Reputation: 0

Joined: 20 Apr 2007
Posts: 483

PostPosted: Tue Apr 22, 2008 3:10 pm    Post subject: [C++] Help me understand a script :] Reply with quote

Code:
case 0x4B: Mobs::handleSummonBag(this, buf+2); break;
default: break;

void Mobs::handleSummonBag(Player* player, unsigned char* packet)
{
   int itemID = getInt(packet+6);
   if(itemID == 2101001)
   {
      //Crimson Balrog
      spawnMob(player, 8150000);
   }
   if(itemID == 2100008)
   {
      //The Boss
      spawnMob(player, 9400300);
   }
   Inventory::takeItem(player, itemID, 1);


So here are my questions:
1. What is '0x4B'?
2. int itemID = getInt(packet+6);
The why did they use 'int'? also in the 'getInt?

Here are the questions I doubt you'll know how to answer them because you dont play private maplestory..
1. what is purpose of '(this, buf+2);' ?
Also whats the purpose of '(Player* player, unsigned char* packet)'?
why did they put packet+6?

GENERALLY, EXPLAIN ME THE CODE LOL.
Thank you for reading my noobish questions.
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Tue Apr 22, 2008 3:39 pm    Post subject: Reply with quote

0x4B is most likely a packet start. It handles summonbag's

getInt() most likely gets the Integer value from the packet in the array of bytes defined in the function.

this? probly the chosen player. Your most likely switching buf for cases and, and its adding 2 to the buf and then calling the function from the class "Mob"; handleSummonBag(..);

So your switching the packet, if its first byte is 0x4B then handleSummonBag to the chosen player and the byte is the 3rd byte in the array. They are now getting the itemID from the 8th packet (because they had already added 2 to the packet when calling the function, so +6 = 8, +6 is probly there because the item id is located at the 8th byte in the array ) then checking which summon bag was called. Finally it spawn's the mob depending on the itemID.

"Inventory::takeItem(player, itemID, 1);" this is most likely the thing that deletes the item from your inventory.
My guess is that the first parameter is the chosen player, the second is obviously the itemID of the item, and the third parameter is the quanitity.

Hope that helps.

_________________


Last edited by lurc on Tue Apr 22, 2008 4:27 pm; edited 1 time in total
Back to top
View user's profile Send private message
kopelito
Master Cheater
Reputation: 0

Joined: 20 Apr 2007
Posts: 483

PostPosted: Tue Apr 22, 2008 4:10 pm    Post subject: Reply with quote

I have only one thing to say.

THANK YOU SOOO MUCH.

rep for you.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Tue Apr 22, 2008 5:48 pm    Post subject: Reply with quote

Google'd a bit showed this is code from a Maple server.

Code:
case 0x4B: Mobs::handleSummonBag(this, buf+2); break;


Can be found in Player.cpp in:
Code:
void Player::handleRequest(unsigned char* buf, int len)


0x48 is the packet header (id) that is currently being processed. Then using 'this' refers to the current player class object. "(this, buf+2)" is the parameter list for the function handleSummonBag which is found in the Mob class.

getInt() is a function:

Code:
int getInt(unsigned char* buf){
   return buf[0] + buf[1]*0x100 + buf[2]*0x100*0x100 + buf[3]*0x100*0x100*0x100;
}


which can be found inside LoginPacket.cpp I assume the multiplication is for the encryption or what ever.

Quote:
why did they put packet+6?


Because inside the packet data at the offset +6, there is important information that is needed for what ever function is being called. A packet has a 'header' which contains information of what the packet is for. Usually a header consists of nothing more then a few bits of info for the game handler to understand what the packet is for, such as an id, a sender id, and such.

In this case, the item id is at offset +6 inside the packet. So they use packet+6 to get the correct address inside the packet where the id is at.

Think of packet+6 like this:

0x10000 + 6 = 0x10006

0x10000 being the starting address of where the packet is stored in memory at that time.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Symbol
I'm a spammer
Reputation: 0

Joined: 18 Apr 2007
Posts: 5094
Location: Israel.

PostPosted: Wed Apr 23, 2008 3:49 am    Post subject: Reply with quote

Why is there "default: break;"? Confused
And isn't it supposed to summon a few monsters? not only one? I'd just create an xml file with the sack ID and add boolean value "IsSummonSack" and the monsters it summon and chance and then just
if (Drops[something]::IsSummonSack)
{
int rand;
for (int i = 0; i < Drops[something]::Monsters.size(); i++){
rand = rand() & Drops[something]::Monsters[i]->Chance;
for (;rand > 0; rand--)
spawnMob(player, Drops[something]::Monsters[i])
}

Something like this... instead of making a really big switch. (or like you're doing, if else...)
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Wed Apr 23, 2008 7:47 am    Post subject: Reply with quote

he most likely only showed a couple of the spawns's which were bosses.

default: break; just means if none apply break out (just in case)

_________________
Back to top
View user's profile Send private message
Symbol
I'm a spammer
Reputation: 0

Joined: 18 Apr 2007
Posts: 5094
Location: Israel.

PostPosted: Wed Apr 23, 2008 4:56 pm    Post subject: Reply with quote

I know what default: break does, just saying, isn't it usless? switch is like lots of "if"'s:
case 0:
case 1:
case 2:
default:

would look like: (eax = 2)
cmp eax,2
jnz case 1
case 2:
bla bla
jmp out
dec eax
jnz case 0
case 1:
bla bla
jmp out
case 0:
bla bla
jmp out

out:
default:
bla bla
ret

or in this case:
default:
ret

So without default, you can imagine how it will look like.
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Wed Apr 23, 2008 8:01 pm    Post subject: Reply with quote

yes, it wouldn't matter if it hit default, if it got that far it would just fall through.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites