How do I send orders to units without a desync?

This is a discussion on How do I send orders to units without a desync? within the Starcraft 2 Coding board part of the Starcraft 2 forum category; Ok, so I'm working on a bot for micromanaging units. And I was wondering how to have it give orders ...

Page 1 of 2 12 LastLast
Results 1 to 10 of 20
  1. #1
    Mr Nukealizer's Avatar
    Mr Nukealizer is offline I ♥ ¡ǝʞɐↄǝZǝǝчƆ

    Array
    Join Date
    Jan 2011
    Posts
    860
    Rep Power
    5
    Reputation
    498

    Question How do I send orders to units without a desync?

    Ok, so I'm working on a bot for micromanaging units. And I was wondering how to have it give orders without using the mouse or keyboard or going out of sync. I don't care what it looks like in a replay, as long as it doesn't cause a desync or get detected by Warden. I'm currently trying to make it work as an external program, but I don't mind if I have to inject some code to make this work. My idea of what needs happen is to have it call some function in the game that is normally triggered by user input, or change some memory location that stores the current order. But if I'm wrong, please tell me.

    Last edited by Mr Nukealizer; 11-05-2011 at 03:27 AM.
    I'm here to learn, have fun, and help others learn and have fun.

  2. #2
    longx is offline |_e4|2n3r


    Array
    Join Date
    Aug 2010
    Posts
    656
    Rep Power
    5
    Reputation
    593
    Yes best way is via function calling

    First you need to find the function you want to use, then figure out function types and parameters, then write the codes to call them, then compile the DLL, and lastly inject the DLL into the sc2 process to use it

    oh and since it's internal you need to make sure you are safe from Warden, although if you do not modify any offsets and don't make any hooks and keep it private then you should be safe.

  3. The Following User Says Thank You to longx For This Useful Post:


  4. #3
    Mr Nukealizer's Avatar
    Mr Nukealizer is offline I ♥ ¡ǝʞɐↄǝZǝǝчƆ

    Array
    Join Date
    Jan 2011
    Posts
    860
    Rep Power
    5
    Reputation
    498
    Quote Originally Posted by longx View Post
    Yes best way is via function calling

    First you need to find the function you want to use, then figure out function types and parameters, then write the codes to call them, then compile the DLL, and lastly inject the DLL into the sc2 process to use it

    oh and since it's internal you need to make sure you are safe from Warden, although if you do not modify any offsets and don't make any hooks and keep it private then you should be safe.
    Ok, thanks for confirming my thoughts. Now I still need to figure out what function... Which would have been much easier if not for the update right when I was getting close
    I'm here to learn, have fun, and help others learn and have fun.

  5. #4
    longx is offline |_e4|2n3r


    Array
    Join Date
    Aug 2010
    Posts
    656
    Rep Power
    5
    Reputation
    593
    someone once taught me to make use of sc2's own galaxy documentations, for example like this file:

    [C] Starcraft 2 natives.galaxy [patch 1.4] - Pastebin.com

    (you can use MPQ editor to retrieve the latest version yourself)

    in the above file you can see there is:

    Code:
    1. // Unit orders
    2. const int c_orderQueueReplace = 0;
    3. const int c_orderQueueAddToEnd = 1;
    4. const int c_orderQueueAddToFront = 2;
    5. native order UnitOrder (unit inUnit, int inIndex);
    6. native int UnitOrderCount (unit inUnit);
    7. native bool UnitOrderHasAbil (unit inUnit, string abilLink);
    8. native bool UnitOrderIsValid (unit inUnit, order inOrder);
    9. native bool UnitIsHarvesting (unit inUnit, int inResource);
    10. native bool UnitIssueOrder (unit inUnit, order inOrder, int inQueueType);
    looks like those are galaxy functions deals with issuing orders, now you can go into game code and r/e (reverse engineering) those functions and figure out how it is done

    and here is a GREAT resource on how to dump the galaxy functions, made by crash_man and rolle3k, it gives you the address of each galaxy function that you want to work on:
    http://www.blizzhackers.cc/viewtopic...540e70c8834503

    from there you see:
    Code:
    0x00B89A20->UnitIssueOrder
    so now just go into sc2.exe and study the function at 0xB89A20, see how it's done, and write code to do it yourself

    --this is just one of the many methods to do this, it takes some effort and time and of course also r/e skills, there are few people here are very knowledgeable on this area, if they want to help
    Last edited by longx; 11-09-2011 at 02:53 PM.

  6. The Following 3 Users Say Thank You to longx For This Useful Post:


  7. #5
    Mr Nukealizer's Avatar
    Mr Nukealizer is offline I ♥ ¡ǝʞɐↄǝZǝǝчƆ

    Array
    Join Date
    Jan 2011
    Posts
    860
    Rep Power
    5
    Reputation
    498
    Thanks for the info about the documentation! What MPQ is that in? I was already working on UnitIssueOrder(), but it seems that for the same order, it gets different data for inOrder every time within the same game. However if I start a new game, it gets the same values in the same order. But even if I give it the same data in the same order, the function returns true, but it does nothing. And looking at Order() it appears the input is not a string and int like the trigger editor shows ( Order("stop",0) ), but is actually the output from the last time the function was run.

    EDIT: Also, you have the 1.4.1 offsets. UnitIssueOrder is now 0x00B24420.
    EDIT 2: LOL I think I see the problem now that I look at the documentation......
    EDIT 3: Yes, I see why my approach didn't work. Now the problem seems to be creating a new string in SC2's variable list and possibly keeping it around long enough to get the ability data, then possibly keeping the ability data long enough to use it.
    Last edited by Mr Nukealizer; 11-10-2011 at 01:28 AM.

  8. #6
    ValiantChaos's Avatar
    ValiantChaos is offline Made in China



    Array
    Join Date
    Oct 2010
    Location
    China
    Posts
    921
    Rep Power
    10
    Reputation
    1570
    When searching for something try to use things that you think will be related and close to what your trying to find, my explanation is bad I know, probably don't make sense. Anyways, what longx provided with the galaxy function for UnitIssueOrder is a start, however I probably wouldn't work with that.

    You know when issuing a unit command you get error messages, if you have already found this function or perhaps you should then you can backtrace from there until your out of the error handling stuff and can start checking the functions under the call and where the code would skip and jump over if a unit error message was to appear.

    If you have no luck there maybe search for something else first that you think will help you locate what you need, obviously there is some global command send function for selections, groups, commands, camera movement etc which this SendUnitCommand( ) would also call. So perhaps find one of them other functions first, for select units function start with something like your selection count, search for that with a memory editor tool and set some breakpoints on your results. One of them results is likely to be accessed when you select a unit, so the breakpoint should put you in the select units function and from there do some backtracing until you have the start of function. Once you have that you can start from top and nop a bunch of calls until you narrow it down to the one that has the effect you want, in this case selecting any unit and trying to command it will not work. Now set a breakpoint inside this call at start of function and try to command a unit, it will most likely trigger your debug breakpoint and the calling function will be what your looking for or you may need to step out a few more times.

    ^ That's what I mean by the first part of this post, search for something else first and use that if you think it can help you in locating what you need.

    I can say the function you want is a fastcall and takes a struct for the first arg with all the unit command information which is like 38bytes in length.
    Last edited by ValiantChaos; 11-10-2011 at 06:15 AM.

  9. The Following 6 Users Say Thank You to ValiantChaos For This Useful Post:


  10. #7
    longx is offline |_e4|2n3r


    Array
    Join Date
    Aug 2010
    Posts
    656
    Rep Power
    5
    Reputation
    593
    haha mass NOP FTW


    I should remind you thou, do all the analysis offline (at login screen, select "Play as guest"),
    chances are you will be working at sensitive functions/offsets, and you could well get flagged by warden during r/e

    PS: just by setting up break point you actually make modifications to the memory, e.g. if you put bp at a detected offset you will get banned
    Last edited by longx; 11-10-2011 at 05:13 PM.

  11. The Following 4 Users Say Thank You to longx For This Useful Post:


  12. #8
    ValiantChaos's Avatar
    ValiantChaos is offline Made in China



    Array
    Join Date
    Oct 2010
    Location
    China
    Posts
    921
    Rep Power
    10
    Reputation
    1570
    Suppose you can avoid NOP'ing some calls if the function doesn't appear to be capable of doing what your searching for, and follow the conditional jumps to speed things up. Also don't forgot to adjust the stack if your NOP'ing functions that pushed args onto the stack, probably already knew that but in case you didn't.

  13. The Following 2 Users Say Thank You to ValiantChaos For This Useful Post:


  14. #9
    Mr Nukealizer's Avatar
    Mr Nukealizer is offline I ♥ ¡ǝʞɐↄǝZǝǝчƆ

    Array
    Join Date
    Jan 2011
    Posts
    860
    Rep Power
    5
    Reputation
    498
    Ok, thanks for all the help! When clicking to make a unit move, I have traced from the pointer to a unit's current order all the way up to the main loop. Now I'm planning on doing the same when a trigger makes it move and see what they have in common, then work from there. My main problem is that I'm a bit of a noob to assembly. I'm learning but current I rely quite a bit on the Hex-Rays decompiler in IDA, and it seems to have some issues with function signatures; several functions have been called as void** __stdcall(DWORD,DWORD), yet when I decompile those functions they're int __thiscall(void* this,int a1,int a2) and many other times the return value is not used in the decompiled view, but they obviously use EAX later in the function.
    So what should I do? Should I just try to make sense of it in pure assembly, or is there a way to fix the issues with the decompiler?
    I'm here to learn, have fun, and help others learn and have fun.

  15. #10
    longx is offline |_e4|2n3r


    Array
    Join Date
    Aug 2010
    Posts
    656
    Rep Power
    5
    Reputation
    593
    r/e is a heavily personalized task, since it is not exactly a "textbook" topic so many people just do it with their own methods and tricks, and pick up different things on the road

    i know some people like to use hex-rays to study decompiled function, and some use purely olly, i dont think one is better then another, all have its up and downs

    the guy who showed me how he uses hex-rays, you could double click on variable name (for example, a1, a2) and rename them, and all a1/a2 will be renamed altogether in the code, so your goal is to decode function calls from " __thiscall(void* this,int a1,int a2)" to " __thiscall(void* this,int unit_number,int order_type)", after you figure out what the function parameters are, and then look at how the functions are used, then things will be clear

    curious how VC does his r/e work

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 11
    Last Post: 12-22-2011, 11:39 AM
  2. Units frozed, not moving? can't build units at times?
    By adventweapon in forum Starcraft 2 Hacks
    Replies: 6
    Last Post: 09-22-2011, 07:44 PM
  3. Desync Hack
    By wysoy in forum Starcraft 2 Hacks
    Replies: 38
    Last Post: 05-13-2011, 08:57 PM
  4. [Release] Vuno's Desync Hack
    By Vuno in forum Starcraft 2 Hacks
    Replies: 56
    Last Post: 05-10-2011, 04:31 PM
  5. Desync problems! :[
    By xdennynguyen in forum Warcraft 3 forum
    Replies: 3
    Last Post: 12-03-2009, 03:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •