name hook

Here you can discuss packets, implementation and design, and software related to the packet sniffing and such. This is not the place to post packages for POL, but rather discuss the packet side of them.

Moderator: POL Developer

Post Reply
coltain
Grandmaster Poster
Posts: 159
Joined: Tue Mar 20, 2007 7:17 am
Location: Poland

name hook

Post by coltain »

I hooked a packed:

Code: Select all

Packet 0x1C
{
  Length variable
  SendFunction main/name_hooks:HandleUCNOutgoing
}

Code: Select all

program name_hooks()
  Print( "Podlaczam wychodzace imiona..." );
  return 1;
endprogram

exported function HandleUCNOutgoing(cel, byref packet )
    //here i change existing packet
    return 0;
endfunction
but if I set:

Code: Select all

program name_hooks()
  Print( "Podlaczam wychodzace imiona..." );
  return 1;
endprogram

exported function HandleUCNOutgoing(cel, byref packet )
    //here i change existing packet
   printtextabove(cel,"testing");
    return 0;
endfunction
I get a spam of message testing when a name of a mobile shown (first spam, later 1 name)
Why this is happening???

How to change a packet.GetString(14,30) ??? <- aka name
coltain
Grandmaster Poster
Posts: 159
Joined: Tue Mar 20, 2007 7:17 am
Location: Poland

Re: name hook

Post by coltain »

As I see, this causes lag when a player enters a location filled with mobiles.

Any response?
User avatar
CWO
POL Expert
Posts: 1158
Joined: Sat Feb 04, 2006 5:49 pm
Location: Chicago, IL USA

Re: name hook

Post by CWO »

Depending on how much code you have in it, you would get lag because packethooks are run critical.
Pierce
Forum Regular
Posts: 420
Joined: Thu Feb 02, 2006 8:33 am

Re: name hook

Post by Pierce »

The 0x1C packet sends ASCII text to the client, e.g. normal speech, system messages,
appearing names and a lot more.

By using PrintTextAbove(cel,"testing"); inside the exported function you also send
another new 0x1c packet and that packet again also sends a PrintTextAbove which causes
another new 0x1c packet............. :D
I think it's better you use a Print("Testing"); and watch the console in this special case :D
coltain
Grandmaster Poster
Posts: 159
Joined: Tue Mar 20, 2007 7:17 am
Location: Poland

Re: name hook

Post by coltain »

Thx Pierce

I thought that Printtextabove is send by using "send unicode message packet". I`ll chack it again.

CWO no more code is in it that I presented (reduced all for tests).
Last edited by coltain on Sat Dec 06, 2008 2:25 pm, edited 1 time in total.
coltain
Grandmaster Poster
Posts: 159
Joined: Tue Mar 20, 2007 7:17 am
Location: Poland

Re: name hook

Post by coltain »

Pierce was right, it was my mistake.

I can change a font and color of the string by using packet.SetInt16(offset,value) but can anyone give me an example how to use packet.SetString(offset, string)???

to get a string I use packet.GetString(14,30) but using packet.SetString(14, "Test") doesn`t do anything. Do I have to enlarge the string I want to "put" in to 30 bytes???

I`m kind of new in packets so please... help me... ;)
Pierce
Forum Regular
Posts: 420
Joined: Thu Feb 02, 2006 8:33 am

Re: name hook

Post by Pierce »

May i ask for which purpose you want to change the name in that packet?

You may need to null terminate the string, cause the 30 bytes of the name are
always null terminated to the end of the 30 bytes, as you can see in this example
of a system Message, where the name is "System":

Code: Select all

0000: 1C 4E 00 01 01 01 01 01 01 00 03 B2 00 03 53 79 ->.N............Sy
0010: 73 74 65 6D 00 00 00 00 00 00 00 00 00 00 00 00 ->stem............
0020: 00 00 00 00 00 00 00 00 00 00 00 00 59 6F 75 20 ->............You 
0030: 68 61 76 65 20 65 6E 74 65 72 65 64 20 74 68 65 ->have entered the
0040: 20 41 72 65 61 20 42 42 42 42 42 42 42 00       -> Area BBBBBBB.
You could try a

Code: Select all

packet.SetString(14, "Test", 1)
which set a null terminator after the last "t". I don't know if that works if the
name before your change was quite longer. I think you need to test how the client
reacts on that.
User avatar
CWO
POL Expert
Posts: 1158
Joined: Sat Feb 04, 2006 5:49 pm
Location: Chicago, IL USA

Re: name hook

Post by CWO »

Likely you need to set all 30 bytes in the name to 00 first then packet.setstring()...
Nando
POL Developer
Posts: 282
Joined: Wed Sep 17, 2008 6:53 pm
Contact:

Re: name hook

Post by Nando »

What do you intend to do? Wouldn't it be better to hook the Single Click packet?
coltain
Grandmaster Poster
Posts: 159
Joined: Tue Mar 20, 2007 7:17 am
Location: Poland

Re: name hook

Post by coltain »

I hooked a single click packet and it worked fine untill.. I noticed some side effects.

Players began to loose their backpacks - it simply dissapired from the gump. I presumed that is connected with some core function (open.... or sendview...) to use a container or... some conflict with other packets (eg. packet that blocks removing a backpack)

I want to add something to the character name when its shown, one char "!" or "&" depending on a race.

Or.. When a name is shown - print a char "!" under it (in the next line)
Pierce
Forum Regular
Posts: 420
Joined: Thu Feb 02, 2006 8:33 am

Re: name hook

Post by Pierce »

I've just tested a quick and dirty solution of what you wanted.
Because it was on a test server, i did not change player names.
Instead i change the appearing npc names with that script.
So everything like "Bodo the guard" or "a cow" now appears as "PP" :D
Ah and you need to set the string on position 44 not 14 as you can see.


Code: Select all

program name_hooks()
  Print( "Podlaczam wychodzace imiona..." );
  return 1;
endprogram

exported function HandleUCNOutgoing(cel, byref packet )

 var player;
 var objserial := packet.GetInt32(3);

 if(objserial != 16843009)  // 01 01 01 01 System Messages
  player := SystemFindObjectBySerial(objserial, SYSFIND_SEARCH_OFFLINE_MOBILES); //in case char is disconnected
  if(player)
   if(player.acctname)

   else
    packet.SetString(44, "PP", 1);
   endif
  endif
 endif
 return 0;

endfunction
coltain
Grandmaster Poster
Posts: 159
Joined: Tue Mar 20, 2007 7:17 am
Location: Poland

Re: name hook

Post by coltain »

BYTE[1] cmd
BYTE[2] Packet len
BYTE[4] itemID (FF FF FF FF = system)
BYTE[2] model (item # - FF FF = system)
BYTE[1] Type of Text
BYTE[2] Text Color
BYTE[2] Font
BYTE[30] Name
BYTE[?] Null-Terminated Msg (? = Packet length - 44)

bleh,
*his head hits keyboard*

I took "BYTE[30] Name" for a name of a mobile, not a Name of sender (as I preasume - System in this case)

Didn`t noticed "Null-Terminated Msg" grr - taken it for a null sign to end a message

Thx
coltain
Grandmaster Poster
Posts: 159
Joined: Tue Mar 20, 2007 7:17 am
Location: Poland

Re: name hook

Post by coltain »

This is not good

Well, it works but when somebody says something the thing I added is shown either.

Pol uses this packet to send other messages too so...
Pierce
Forum Regular
Posts: 420
Joined: Thu Feb 02, 2006 8:33 am

Re: name hook

Post by Pierce »

What is the value of "Type of Text" if somebody says something?
Is it also zero or different from that?
coltain
Grandmaster Poster
Posts: 159
Joined: Tue Mar 20, 2007 7:17 am
Location: Poland

Re: name hook

Post by coltain »

POL uses printtextabove function to show the names of incoming creatures...

So If I use this function in any of the script i will show an added thind too.

I think I have to use a cliloc to show it (but the core doesn`t send this packet everytime a mobile enters but only once - with some delay as I preasume).

Btw

Is there a way to enable a ENTEREDAREA event to a player? I tried to do this in a logon.src by starting a script with this code.

Code: Select all

while(kto.ip)
        var ev := os::wait_for_event(10);
        Printtextabove(kto,"Czekam");
        if(ev)
            case(ev.type)
                EVID_ENTEREDAREA:   
                        Printtextabove(kto,"Kogos widze");                
            endcase
        endif
endwhile
but it doesn`t react on events...
User avatar
ncrsn
Grandmaster Poster
Posts: 255
Joined: Fri Feb 10, 2006 12:15 am

Re: name hook

Post by ncrsn »

coltain wrote:POL uses printtextabove function to show the names of incoming creatures...
You DO know that POL doesn't really show names of incoming creatures, it just reacts to client's singleclick packet WHICH is send when new creature appears on the screen IF player has this option turned on?
coltain
Grandmaster Poster
Posts: 159
Joined: Tue Mar 20, 2007 7:17 am
Location: Poland

Re: name hook

Post by coltain »

Yes, POL uses singleclick packet, after clicking a printtextabove function is called (if I`m wrong, tell me), I tried to use singleclick packet but strange things occure. I wrote about it earlier.
Pierce
Forum Regular
Posts: 420
Joined: Thu Feb 02, 2006 8:33 am

Re: name hook

Post by Pierce »

You don't need the single click packet.

Try this one and check if it helps in your case:

Code: Select all


exported function HandleUCNOutgoing(cel, byref packet )

 var player;
 var objserial := packet.GetInt32(3);
 var model := packet.GetInt16(7);
 var type := packet.GetInt8(9);

 var mtype := {400, 401,605,606};

 if(objserial != 16843009)  // 01 01 01 01 System Messages
  if(!(model in mtype))
   player := SystemFindObjectBySerial(objserial, SYSFIND_SEARCH_OFFLINE_MOBILES); //in case char is disconnected
   if(player)
    if(player.acctname)
     packet.SetString(44, "Whatever", 1);
    else
//    packet.SetString(44, "PP", 1);
    endif
   endif
  endif
 endif
 return 0;

endfunction
Post Reply