An introduction to SQL Query Hooking.

Page 1 of 3 123 LastLast
Results 1 to 25 of 69
  1. #1
    boo General is offline
    MemberRank
    Sep 2006 Join Date
    at homeLocation
    2,269Posts

    An introduction to SQL Query Hooking.

    Hey, I want to learn you all something that I've been using for a while now. I already released the list of DBServer queries (http://forum.ragezone.com/f315/list-...ueries-524196/) but nobody really cares about it since they don't know what they can do with it.

    Well, the possibilities are unlimited. That's why I'm going to give you a (very) small example of what it can do.

    The key to query hooking is "Stored Procedures", a method in SQL to do multiple actions/queries with 1 command.

    In this example, we are going to make a talisman that makes an item bound on succes.

    Stored Procedure
    Go to enterprise manager -> databases -> kal_db -> Stored Procedures -> right click -> "New stored procedure"

    Paste this into the window:
    PHP Code:
    CREATE PROCEDURE SetPrefix

    @prefix int,
    @
    iid int

    AS

    IF  (@
    prefix 150)
    begin
    --do a special thinglike make bound
    UPDATE  
    [ItemSET Info = (Info|128WHERE IID = @iid
    end
    ELSE
    begin
    -- do  the normal query
    UPDATE Item SET 
    [Prefix] = @prefix WHERE [IID] =  @iid
    end 
    Press OK

    Screenshot:



    DB Server
    Now, we need the DBServer.exe to run this SP instead of the usual query hexed within it.

    Open DBSvr.exe with a hex editor, find
    Code:
    UPDATE Item SET [Prefix] = %d WHERE [IID] = %d
    Put your cursor before UPDATE and start typing
    Code:
    EXEC SetPrefix %d,%d
    Make sure you fill the old text up with 00 bytes (put your cursor in the hex part or your editor

    Screenshot:


    Using ingame
    How to use it ingame? Make a talisman with success prefix 150. Don't forget to dd them in prefix.txt and prefix.dat client sided, but I assume you all know how to add a new talisman.

    When the talisman succeeds, your item will be bound on relog.

    You can imagine the power of Stored procedures now. This is also how SwordOnline fixed the imperial stats bug, made bof with talismans and many more. We have over 30 stored procedures and hooked queries.

    Kind regards


  2. #2
    Account Upgraded | Title Enabled! Momo5000 is offline
    MemberRank
    Oct 2007 Join Date
    NarootuhLocation
    299Posts

    Re: An introduction to SQL Query Hooking.

    Wow ty Bjorn, i love you :D

  3. #3
    Account Upgraded | Title Enabled! Tommy1 is offline
    MemberRank
    Mar 2009 Join Date
    Earth/France/Paris/Montparna/Home/Room/ Iam not here.Location
    335Posts

    Re: An introduction to SQL Query Hooking.

    Thanks alot Bjorn , also we can do it without talisman isnt it?

    You can imagine the power of Stored procedures now. This is also how SwordOnline fixed the imperial stats bug, made bof with talismans and many more. We have over 30 stored procedures and hooked queries.

    Kind regards
    Wow , soon i will try the bof thing

  4. #4
    Member exe08 is offline
    MemberRank
    Jan 2009 Join Date
    96Posts

    Re: An introduction to SQL Query Hooking.

    Sry for this stupid question, but how i can make 00-Bytes? Because of the different length.

    Thanks for every answer. :P

    greetz exe

    /edit: nvm, i found it out by myself. ;)

    /edit2: Thank you very much for tis information. But is there a possebility to make an item which can be used on armor, weapons and accessoires? Atm it is more like top, tow, toi, isn

  5. #5
    Account Upgraded | Title Enabled! 2Kxx is offline
    MemberRank
    Feb 2008 Join Date
    Sweden..Location
    1,194Posts

    Re: An introduction to SQL Query Hooking.

    really usefull release bjorn!
    +1

  6. #6
    Account Upgraded | Title Enabled! _Varis_ is offline
    MemberRank
    May 2008 Join Date
    479Posts

    Re: An introduction to SQL Query Hooking.

    Great release.

    -V

  7. #7
    Kal Craker cristy_abaddon is offline
    MemberRank
    Apr 2006 Join Date
    acasaLocation
    859Posts

    Re: An introduction to SQL Query Hooking.

    great tutorial and thanks for the list
    did not know about it till now :|

  8. #8
    Apprentice YourFear11 is offline
    MemberRank
    Jan 2009 Join Date
    13Posts

    Re: An introduction to SQL Query Hooking.

    thx Bjorn but i have one question ^^
    maybe i'm dump but nvm :P
    How to make 2 talizmans with bound function?
    Here is "CREATE PROCEDURE SetPrefix", ok i can't make next procedure with this name, and here my question if i change name on SetPrefix2 or something like that how can i add next function to DBserver?
    You changed UPDATE on "EXEC SetPrefix %d,%d" it's possible to add next one?

  9. #9
    Member exe08 is offline
    MemberRank
    Jan 2009 Join Date
    96Posts

    Re: An introduction to SQL Query Hooking.

    What you would like to do?
    Make 1 bound tali for weapons, 1 bound tali for armor? If yes you don

  10. #10
    Apprentice YourFear11 is offline
    MemberRank
    Jan 2009 Join Date
    13Posts

    Re: An introduction to SQL Query Hooking.

    ehh look in DBserver we have atm this:
    Code:
    EXEC SetPrefix %d,%d
    DBserver reading only procedure SetPrefix and my question is how to add next one if i need 2 toi's with bound function for example King and Legendary

    I think you need 2 procedure too if you trying to make bound and unbound :P
    in first procedure changing prefix on 128, and in 2nd procedure changing prefix on 0.

  11. #11
    Kal Craker cristy_abaddon is offline
    MemberRank
    Apr 2006 Join Date
    acasaLocation
    859Posts

    Re: An introduction to SQL Query Hooking.

    PHP Code:
    CREATE PROCEDURE SetPrefix

    @prefix int,
    @
    iid int

    AS

    IF  (@
    prefix 151)
    begin
    --do a special thinglike make bound
    UPDATE  
    [ItemSET Info = (Info|0WHERE IID = @iid
    end
    ELSEIF (@prefix 152)
    begin
    --do a special thinglike make bound
    UPDATE  
    [ItemSET Info = (Info|0WHERE IID = @iid
    end
    ELSE
    begin
    -- do  the normal query
    UPDATE Item SET 
    [Prefix] = @prefix WHERE [IID] =  @iid
    end 
    here it is how to do for multiple items

  12. #12
    Member exe08 is offline
    MemberRank
    Jan 2009 Join Date
    96Posts

    Re: An introduction to SQL Query Hooking.

    Ok i see, i need to change something for SetPrefix2 in db ...
    But what? >.< ^^

    I used SetPrefix for unbound, its sure that i need 2 procedures here. ;)

    But i don

  13. #13
    boo General is offline
    MemberRank
    Sep 2006 Join Date
    at homeLocation
    2,269Posts

    Re: An introduction to SQL Query Hooking.

    Code:
    CREATE PROCEDURE SetPrefix
    
    @prefix int,
    @iid int
    
    AS
    
    IF  (@prefix = 150) --bound prefix
    begin
    --do a special thing, like make bound
    UPDATE  [Item] SET Info = (Info|128) WHERE IID = @iid
    end
    ELSE IF  (@prefix = 151) --unbound prefix
    begin
    --do a special thing, like make unbound
    UPDATE  [Item] SET Info = Info - (Info&128) WHERE IID = @iid
    end
    ELSE
    begin
    -- do  the normal query
    UPDATE Item SET [Prefix] = @prefix WHERE [IID] =  @iid
    end
    you cannot make a new procedure for it, since 1 stored proceure = 1 db query in DBServer.exe

    so you have to make an extra "'hook" for it within the SP

    this way you can do "actions" before doing the real query.

    It's an introduction guide, there are much more things you can do... like

    after AS:

    DECLARE @pid int
    SET @pid = (SELECT PID FROM Item WHERE IID = @iid)
    Print 'Item with IID '+@iid+' belongs to player with PID '+@pid+'

    or something similar :)

  14. #14
    Member exe08 is offline
    MemberRank
    Jan 2009 Join Date
    96Posts

    Re: An introduction to SQL Query Hooking.

    Thank you very much, Bjorn! It works perfect, of course. ;)

    I

  15. #15
    Kal Craker cristy_abaddon is offline
    MemberRank
    Apr 2006 Join Date
    acasaLocation
    859Posts

    Re: An introduction to SQL Query Hooking.

    you want to make a new item (something like polishing stone) to make other items bound?

  16. #16
    Member exe08 is offline
    MemberRank
    Jan 2009 Join Date
    96Posts

    Re: An introduction to SQL Query Hooking.

    Right. I don

  17. #17
    Kal Craker cristy_abaddon is offline
    MemberRank
    Apr 2006 Join Date
    acasaLocation
    859Posts

    Re: An introduction to SQL Query Hooking.

    hmm in theory it should be very possible
    i just looked into inititem.txt
    and it should be possible with little changes
    PHP Code:
    (item(name 681)(Index 481)(Image "shop015")(desc 228)(class general charm)(code 3 7 21 0)(country 0 2)(use 1)(plural 1)(buy 150000)(specialty(protect))) // polish
    (item(name 531)(Index 332)(Image "item017")(class general charm)(code 3 5 12 0)(country 0 1 2)(use 1)(plural 1)(buy 0)(sell 1500)(specialty(Changeprefix weapon 29 90 85 91))) // talisman 
    just add new prefixes and everything is done ;)

    a "hybrid" :P which is a normal tali ^_^

    PHP Code:
    (item    (name 531)        (Index 332)    (Image "item017")            (class general charm)    (code 3 5 12 0)    (country 0 1 2)            (use 1)    (plural 1)                                (buy 0)    (sell 1500)                    (specialty                                                                                                                (Changeprefix weapon     100 200 )                        )        ) 
    Where 100 is the tali % chance
    and 200 the prefix
    hope im right didn't work with kal files for long time
    and this is just 1 part talisman not with 2 parts

    and for removing the bound you could make a new talisman with
    PHP Code:
    (Changeprefix weapon     100 0 
    and put a rule in stored procedure
    if (x == 0) then blablabla

    hope you understood

    if by chance you test this tell me if it does work ^_^

  18. #18
    Member exe08 is offline
    MemberRank
    Jan 2009 Join Date
    96Posts

    Re: An introduction to SQL Query Hooking.

    Bjorn already posted a way to unbound, just add something at SetPrefix procedure and add prefix 151.

    I already got that what you called "hybrid". The problem is, that it is just working on weapon: (changeprefix weapon). You can also make (cahngeprefix defense) for armor, but i would like to have something i can use on both things. ^^

    just (changeprefix) isn

  19. #19
    boo General is offline
    MemberRank
    Sep 2006 Join Date
    at homeLocation
    2,269Posts

    Re: An introduction to SQL Query Hooking.

    1 item for weap+armor? afaik that's impossible... the codes in inititem stand for the 'kind' of item

    (class general charm)(code 3 7 21 0)
    (class general charm)(code 3 5 12 0)

    7 21 means it will polish
    5 12 means it will update weapon prefix

    you can try to mess with it, but it's ver time consuming to test those codes...

  20. #20
    Account Upgraded | Title Enabled! Tommy1 is offline
    MemberRank
    Mar 2009 Join Date
    Earth/France/Paris/Montparna/Home/Room/ Iam not here.Location
    335Posts

    Re: An introduction to SQL Query Hooking.

    Bjorn , it will clean the weapon/armor state?

    Ex: if the weapon already kings / it will remove the kings and bound it?

  21. #21
    Member exe08 is offline
    MemberRank
    Jan 2009 Join Date
    96Posts

    Re: An introduction to SQL Query Hooking.

    Hmm ok thanks for this answer.

    I got another question:

    Why an item that i get ingame with /get xxx 150 do not change to bound after relog. :P

    greetz exe

  22. #22
    boo General is offline
    MemberRank
    Sep 2006 Join Date
    at homeLocation
    2,269Posts

    Re: An introduction to SQL Query Hooking.

    @tommy it doesnt actually do the talisman on it, it hooks and changes the purpose of the query.

    so stats will be kept as they are

  23. #23
    Member exe08 is offline
    MemberRank
    Jan 2009 Join Date
    96Posts

    Re: An introduction to SQL Query Hooking.

    What kind of script language is that stored procedure? I would like to understand the commands and try to write something by myself. Is there anywhere something to look up commands etc.?


    greetz exe

  24. #24
    Account Upgraded | Title Enabled! _Varis_ is offline
    MemberRank
    May 2008 Join Date
    479Posts

    Re: An introduction to SQL Query Hooking.

    It's SQL.

    -V

  25. #25
    boo General is offline
    MemberRank
    Sep 2006 Join Date
    at homeLocation
    2,269Posts

    Re: An introduction to SQL Query Hooking.

    look at the existing SP's to learn more!



Page 1 of 3 123 LastLast

Advertisement