Results 1 to 10 of 10
  1. #1
    MeepDarknessMeep's Avatar
    Join Date
    Aug 2012
    Gender
    female
    Posts
    725
    Reputation
    22
    Thanks
    922

    Lua Stack Manipulation

    Hi, I am going to show you how to figure out how to use the stack.


    pretend L was your lua_State pointer, if you do L->luabase, then you get a pointer CBaseLuaInterface class, which contains all of your functions for that state of lua. Why does this matter? If you don't want to be a douche, then you won't use the Gayry (or blackawp) headers, and you will make the headers by yourself, and that was just a headstart in the right direction.

    Stack Manipulation:

    Did you know that you could use the lua stack functions without creating a function? You didn't? Well you don't know much then...
    you can create a hook in C++, and call lua functions to get info you needed. For example, can you not find that pony riders name in darkrp on your esp? It might be because you are using the c++ function that reports their steam name; not their in-game name. There's a fix for that!

    To find a player's name in lua, that is simple:
    Code:
    Entity(entindex):Nick();
    -- or the real way
    FindMetaTable("Player").Nick(Entity(entindex));
    Now we can use the lua stack to get it into c++.
    Code:
    LU->PushSpecial(0); // push the global table
    LU->GetField(-1, "FindMetaTable"); // get FindMetaTable off the global table
    LU->PushString("Player", 0); // push the string Player
    LU->Call(1, 1); // call FindMetaTable with one argument and get one return
    LU->GetField(-1, "Nick"); // get FindMetaTable("Player").Nick
    LU->GetField(-2, "Entity"); // get the entity function off the global table
    LU->PushNumber(ply->entindex()); // push the player's entity index
    LU->Call(1, 1); // pop the entindex and entity function off the table and get the return
    LU->Call(1, 1); // pop the entity and the Nick function off the stack and get the return
    const char* _name = LU->GetString(-1); // get the name from the return
    LU->Pop(2); // pop the table and the return off the stack
    and ta da now you have your in-game name

    Use the stack to your advantage. Good day.
    Last edited by Hunter; 01-18-2016 at 02:59 PM.

  2. The Following 4 Users Say Thank You to MeepDarknessMeep For This Useful Post:

    Doremi Harukaze (01-27-2014),hilo peeps (01-27-2014),Renamon Toast Crunch (01-27-2014),usercmd (02-23-2014)

  3. #2
    Gray's Avatar
    Join Date
    Nov 2012
    Gender
    male
    Location
    Sweden
    Posts
    13,557
    Reputation
    2516
    Thanks
    10,618
    Next time, use different terminology.
    I took the liberty to change some of your foul language.

    Foul language is best kept in the General section.

  4. #3
    Trollaux's Avatar
    Join Date
    Nov 2011
    Gender
    male
    Posts
    2,074
    Reputation
    137
    Thanks
    792
    Awesome.
    Now I just need to learn C++.
    d e a d b o y s
    Quote Originally Posted by Dave84311 View Post
    What do you call a troll with shitty jokes?
    Trollaux
    Quote Originally Posted by Kyeran View Post
    Foot job with lots of oil.
    Quote Originally Posted by Kyeran View Post
    If she's 12, I'm 12.

  5. #4
    Blue Kirby's Avatar
    Join Date
    Apr 2011
    Gender
    male
    Posts
    181
    Reputation
    49
    Thanks
    600
    My Mood
    Psychedelic

    Thumbs down

    Quote Originally Posted by MeepDarknessMeep View Post
    Hi, I am going to show you how to figure out how to use the stack.


    pretend L was your lua_State pointer, if you do L->luabase, then you get a pointer CBaseLuaInterface class, which contains all of your functions for that state of lua. Why does this matter? If you don't want to be a douche, then you won't use the Gayry (or blackawp) headers, and you will make the headers by yourself, and that was just a headstart in the right direction.

    Stack Manipulation:

    Did you know that you could use the lua stack functions without creating a function? You didn't? Well you don't know much then...
    you can create a hook in C++, and call lua functions to get info you needed. For example, can you not find that pony riders name in darkrp on your esp? It might be because you are using the c++ function that reports their steam name; not their in-game name. There's a fix for that!

    To find a player's name in lua, that is simple:
    Code:
    Entity(entindex):Nick();
    -- or the real way
    FindMetaTable("Player").Nick(Entity(entindex));
    Now we can use the lua stack to get it into c++.
    Code:
    LU->PushSpecial(0); // push the global table
    LU->GetField(-1, "FindMetaTable"); // get FindMetaTable off the global table
    LU->PushString("Player", 0); // push the string Player
    LU->Call(1, 1); // call FindMetaTable with one argument and get one return
    LU->GetField(-1, "Nick"); // get FindMetaTable("Player").Nick
    LU->GetField(-2, "Entity"); // get the entity function off the global table
    LU->PushNumber(ply->entindex()); // push the player's entity index
    LU->Call(1, 1); // pop the entindex and entity function off the table and get the return
    LU->Call(1, 1); // pop the entity and the Nick function off the stack and get the return
    const char* _name = LU->GetString(-1); // get the name from the return
    LU->Pop(2); // pop the table and the return off the stack
    and ta da now you have your in-game name

    Use the stack to your advantage. Good day.
    So indirect it's ridiculous. You can just push the registry table onto the stack instead of FindMetaTable. You clearly have no idea how the CLua stack works and you're trying to teach others. All you're doing is teaching bad habits to new coders.

    You could actually reverse engineer how the game uses the Nick function and just call it in C++ without the need for Lua. Stop posting this garbage you clearly stole from the tutorial on the wiki that I wrote.
    Last edited by Blue Kirby; 02-14-2014 at 09:04 AM.

  6. The Following User Says Thank You to Blue Kirby For This Useful Post:

    BIG_BEAR_DOIN_THANGS (02-14-2014)

  7. #5
    leyhorse's Avatar
    Join Date
    Jan 2014
    Gender
    male
    Posts
    104
    Reputation
    10
    Thanks
    6
    My Mood
    Sneaky
    Is it possible to load lua with c++ into gmod so that no bypassed or luau open script is used or needed? Idk if gmod accepts c++ and lua together that way

  8. #6
    MeepDarknessMeep's Avatar
    Join Date
    Aug 2012
    Gender
    female
    Posts
    725
    Reputation
    22
    Thanks
    922
    ...yes that's how all lua is loaded...

    Quote Originally Posted by Blue Kirby View Post
    So indirect it's ridiculous. You can just push the registry table onto the stack instead of FindMetaTable. You clearly have no idea how the CLua stack works and you're trying to teach others. All you're doing is teaching bad habits to new coders.

    You could actually reverse engineer how the game uses the Nick function and just call it in C++ without the need for Lua. Stop posting this garbage you clearly stole from the tutorial on the wiki that I wrote.
    it's called darkrp go try it
    Last edited by MeepDarknessMeep; 04-08-2014 at 06:52 AM.

  9. #7
    leyhorse's Avatar
    Join Date
    Jan 2014
    Gender
    male
    Posts
    104
    Reputation
    10
    Thanks
    6
    My Mood
    Sneaky
    Quote Originally Posted by MeepDarknessMeep View Post
    ...yes that's how all lua is loaded...



    it's called darkrp go try it
    you're talking about by c++? So when opening it via console that is also c++? That means you can manipulate how that loads and use it without needing any bypass?

  10. #8
    MeepDarknessMeep's Avatar
    Join Date
    Aug 2012
    Gender
    female
    Posts
    725
    Reputation
    22
    Thanks
    922
    Quote Originally Posted by leyhorse View Post
    you're talking about by c++? So when opening it via console that is also c++? That means you can manipulate how that loads and use it without needing any bypass?
    no, lua is written in pure lua that's what makes it work

  11. #9
    leyhorse's Avatar
    Join Date
    Jan 2014
    Gender
    male
    Posts
    104
    Reputation
    10
    Thanks
    6
    My Mood
    Sneaky
    Quote Originally Posted by MeepDarknessMeep View Post
    no, lua is written in pure lua that's what makes it work
    so the actual answer to my question is no..

  12. #10
    snipwnage3's Avatar
    Join Date
    Jul 2015
    Gender
    female
    Posts
    75
    Reputation
    10
    Thanks
    84
    Woah c++ looks hard ;(((

Similar Threads

  1. east> b one stack of emps
    By EvieOPness in forum Vindictus Selling / Trading / Buying
    Replies: 0
    Last Post: 09-17-2011, 03:19 PM
  2. waiting for other players stack ..HELP!!!!!!
    By makakas90 in forum Call of Duty Black Ops Help
    Replies: 3
    Last Post: 02-13-2011, 12:33 AM
  3. Fuck Shit Stack
    By Viibez in forum General
    Replies: 15
    Last Post: 12-30-2010, 11:16 AM
  4. Does troll's ult stack with MoM?
    By Wyo in forum General
    Replies: 2
    Last Post: 11-22-2010, 06:10 AM
  5. u think u can stack up
    By dk173 in forum General
    Replies: 5
    Last Post: 03-14-2009, 07:37 PM