Last active
March 29, 2018 19:56
-
-
Save Tarmean/0aef62ac46f3c74bc70da10ef4f53ddf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct Weapon { | |
| void* head; | |
| void* tail; | |
| }; | |
| int getweaponname(lua_State* L) { | |
| int*** userdata = (int***)lua_touserdata(L, 1); | |
| luaL_argcheck(L, userdata != NULL, 1, "`pawn' expected"); | |
| size_t idx = luaL_checkint(L, 2); | |
| // we go userdata -> luabind data -> pawn struct -> weapon vec | |
| void* weapon_vec_addr = &userdata[0][2][1]; | |
| std::vector<Weapon>* weapon_vector = static_cast<std::vector<Weapon>*>(weapon_vec_addr); | |
| if (idx >= weapon_vector->size()) { | |
| lua_pushnil(L); | |
| return 1; | |
| } | |
| void* weapon_addr = (*weapon_vector)[idx].tail; | |
| void* string_addr = (void*)((int)weapon_addr + 0xc0); | |
| std::basic_string<char>* name = static_cast<std::basic_string<char>*>(string_addr); | |
| lua_pushstring(L, name->c_str()); | |
| return 1; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment