1. Head to the 33rd Modeling Contest Poll and drink to your heart's desire.
    Dismiss Notice
  2. Choose your means of doom in the 17th Mini Mapping Contest Poll.
    Dismiss Notice
  3. A slave to two rhythms, the 22nd Terraining Contest is here.
    Dismiss Notice
  4. The heavens smile on the old faithful. The 16th Techtree Contest has begun.
    Dismiss Notice
  5. The die is cast - the 6th Melee Mapping Contest results have been announced. Onward to the Hive Cup!
    Dismiss Notice
  6. The glory of the 20th Icon Contest is yours for the taking!
    Dismiss Notice
  7. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Accessing memory from the script - it's time of the revolution

Discussion in 'The Lab' started by leandrotp, May 17, 2016.

  1. ZiBitheWand3r3r

    ZiBitheWand3r3r

    Joined:
    Nov 21, 2012
    Messages:
    913
    Resources:
    15
    Maps:
    7
    Spells:
    8
    Resources:
    15
    Thanks, Ill report how it works on my pc

    edit
    tested all functions from Utils lib except
    GetAbilityCurrentCooldown

    all works fine, no crashes
    Im using Jass NewGen and War3 version 1.27.1.7085

    edit2
    it would be very nice if we have here such a functions (like in MemoryHack) for example
    IsUnitStunned2
    IsAbilityOnCooldown
    GetUnitAttackType1
    GetUnitAttackType2
    GetUnitAttackSpeed
     
    Last edited: Aug 24, 2017
  2. Kazeon

    Kazeon

    Joined:
    Oct 12, 2011
    Messages:
    3,296
    Resources:
    38
    Icons:
    2
    Tools:
    1
    Maps:
    7
    Spells:
    21
    Tutorials:
    3
    JASS:
    4
    Resources:
    38
    @ZiBitheWand3r3r for me the crash only happened when map's loading. If it loads successfully, all functions gonna work fine.
    This is strange, I use the same patch version as you. I tried to paste all the memory hack triggers into an empty map but the crash persists :/

    EDIT:
    I have found the problem. I tried to re-copy-paste all the codes and the crash seems to gone, literally. I took some times to dig in and find out what's the cause. And what I found was weirder than fiction (at least for me):
    - If I do not modify anything in Version libs (other than deleting some debug messages that uses Int2Hex), it works fine.
    - If I removed line:
    call BJDebugMsg("Warning! Unsupported version!\nVersion-specific offsets have not been initialized!")
    in Init function, it results in crash.
    - If I replace it with other function like
    DisplayTimedTextToPlayer
    , it also results in crash.
    - If I add anything to that block like:
    Code (vJASS):

        if i == 2894996 then
            set PatchVersion = "1.28"
            call Init28()
        elseif i == 2889044 then
            set PatchVersion = "1.27b"
            call Init27b()
        elseif i == 2586768 then
            set PatchVersion = "1.27"
            call Init27()
        elseif i == 5205600 then
            set PatchVersion = "1.26"
            call Init26()
        else

    => it also results in crash.

    In short if I modify anything in that function, it will result in crash. I have re-confirmed it over and over again, and that's really what's happening here. I literally have no idea what's going on here.
     
    Last edited: Aug 26, 2017
  3. ZiBitheWand3r3r

    ZiBitheWand3r3r

    Joined:
    Nov 21, 2012
    Messages:
    913
    Resources:
    15
    Maps:
    7
    Spells:
    8
    Resources:
    15
    I did the same 2 steps as you with no crash (tried few times to run war3),
    do you have jass parser file as linked in first post? I do,
    did you move/delete commands
    //# +nosemanticerror
    ?
     
  4. Kazeon

    Kazeon

    Joined:
    Oct 12, 2011
    Messages:
    3,296
    Resources:
    38
    Icons:
    2
    Tools:
    1
    Maps:
    7
    Spells:
    21
    Tutorials:
    3
    JASS:
    4
    Resources:
    38
    Not exactly. I use TH's JNGP.
    Nope. I don't remove anything else than what I mentioned above.
    Anyway the most important thing is, it's now working :grin:
     
  5. leandrotp

    leandrotp

    Joined:
    Jul 30, 2012
    Messages:
    153
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    This is what's going on here:
    Code (vJASS):
    exitwhen pJassContext*65536/65536 == 0x88 and pJassContext>65536 and Memory[pJassContext/4+8] == f+888


    Basically I use VM's instruction pointer (pJassContext/4+8) to verify that the candidate address is really the Jass Context that I want. The problem is, I am comparing that address to an offset from
    function Init
    (f+888). So, if you modify ANYTHING in function Init, that offset will change, and stack searching will fail, causing a crash.

    But don't worry, I've already got a better search method, wait for it in the next hours.
     
  6. Kakerate

    Kakerate

    Joined:
    Oct 18, 2013
    Messages:
    482
    Resources:
    0
    Resources:
    0
    If this much work was going into Memory Hack development, we'd truly have some wonderful things by now.
     
  7. leandrotp

    leandrotp

    Joined:
    Jul 30, 2012
    Messages:
    153
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    Updated Version library, please test the new code. I have removed the debug messages, and I'm no longer using instruction pointer for verification, so you are free to make some edits to the code.

    This is the basis of memory hack, we can do nothing without having the game offsets, and typing them manually every patch is not only tedious, but any map that uses memory hack will have to be manually updated every time. I'm in the process of migrating the whole memory hack to this method, so that manual updates will no longer be necessary, and it will most likely work in all upcoming versions of WC3.
     
  8. Kazeon

    Kazeon

    Joined:
    Oct 12, 2011
    Messages:
    3,296
    Resources:
    38
    Icons:
    2
    Tools:
    1
    Maps:
    7
    Spells:
    21
    Tutorials:
    3
    JASS:
    4
    Resources:
    38
    @leandrotp I see. Looking forward for that update :D
     
  9. leandrotp

    leandrotp

    Joined:
    Jul 30, 2012
    Messages:
    153
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    First step of detection is ready. Jass context and main game class are automatically detected now. Please test the attached map and tell me if it works properly. Soon I will be updating the other libraries to work with this code.
     

    Attached Files:

  10. Kazeon

    Kazeon

    Joined:
    Oct 12, 2011
    Messages:
    3,296
    Resources:
    38
    Icons:
    2
    Tools:
    1
    Maps:
    7
    Spells:
    21
    Tutorials:
    3
    JASS:
    4
    Resources:
    38
    I retried several times. It works, no crash :)
     
  11. ZiBitheWand3r3r

    ZiBitheWand3r3r

    Joined:
    Nov 21, 2012
    Messages:
    913
    Resources:
    15
    Maps:
    7
    Spells:
    8
    Resources:
    15
    I can confirm AddressDetection.w3m works fine.
    All values changes when I restart the map (without restarting game) except Found stack frame of VM
    It prints the same value until I restart whole warcraft-then it changes.
     
  12. Trigger.edge

    Trigger.edge

    Joined:
    Jun 21, 2012
    Messages:
    419
    Resources:
    0
    Resources:
    0
    Great job leandrotp! :D
     
  13. leandrotp

    leandrotp

    Joined:
    Jul 30, 2012
    Messages:
    153
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    New code released. Introduced new functionality to assign bytecode arrays to a trigger, also introduced support for loading saved games.
    Other libraries now work with the automatic detection method, though not all of the functions are available yet.
     
  14. ZiBitheWand3r3r

    ZiBitheWand3r3r

    Joined:
    Nov 21, 2012
    Messages:
    913
    Resources:
    15
    Maps:
    7
    Spells:
    8
    Resources:
    15
    I commented:
    library Version initializer Init requires Memory//, HexNumber
    because I have no HexNumber lib
    game crashes everytime I call GetUnitArmor, GetHeroPrimaryAttribute or IsUnitStunned,
    warcraft ver 1.27.1.7085.
    (I had no problems with previous libraries)
     
    Last edited: Sep 9, 2017
  15. leandrotp

    leandrotp

    Joined:
    Jul 30, 2012
    Messages:
    153
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    Sorry, I forgot to divide GameState by 4 :p

    Code (vJASS):

    function ConvertHandle takes handle h returns integer
        return Memory[Memory[Memory[Memory[GameState/4]/4+7]/4+103]/4 + GetHandleId(h)*3 - 0x2FFFFF]
    endfunction
     
  16. ZiBitheWand3r3r

    ZiBitheWand3r3r

    Joined:
    Nov 21, 2012
    Messages:
    913
    Resources:
    15
    Maps:
    7
    Spells:
    8
    Resources:
    15
    must be something more to fix, it still crashes
     
  17. leandrotp

    leandrotp

    Joined:
    Jul 30, 2012
    Messages:
    153
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    Indeed, there was 1 "Memory[]" read more than the necessary. Now it is working.
    Thanks for reporting, I have changed the library in the OP.
    Code (vJASS):
    function ConvertHandle takes handle h returns integer
        return Memory[Memory[Memory[GameState/4+7]/4+103]/4 + GetHandleId(h)*3 - 0x2FFFFF]
    endfunction
     
  18. Aniki

    Aniki

    Joined:
    Nov 7, 2014
    Messages:
    559
    Resources:
    6
    Tools:
    1
    Maps:
    1
    Spells:
    1
    JASS:
    3
    Resources:
    6
    Library Version's 'integer GameState' variable doesn't seem to get initialized in 1.28.5 (it does in 1.26).
     
  19. ZiBitheWand3r3r

    ZiBitheWand3r3r

    Joined:
    Nov 21, 2012
    Messages:
    913
    Resources:
    15
    Maps:
    7
    Spells:
    8
    Resources:
    15
    yes, it works perfectly for me now, thanks, IsUnitStunned if really cool function ;)
    by the way , I tryed GetUnitFlags(u) game prints 3..4 digit integers. Can you explain what it shows?
     
  20. A Void

    A Void

    Joined:
    Mar 29, 2011
    Messages:
    2,481
    Resources:
    10
    Models:
    2
    Spells:
    1
    Tutorials:
    7
    Resources:
    10
    Can you please provide an older script code for mouse natives? They worked nicely and I can't find the code anymore. No need for any "mouseEnv".