Created
March 28, 2018 20:57
-
-
Save Tarmean/9610d79e54b982ffacd266344403e782 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
| int getweaponname(lua_State* L) { | |
| int** userdata = (int**)lua_touserdata(L, 1); | |
| int idx = luaL_checkint(L, 2); | |
| luaL_argcheck(L, userdata != NULL, 1, "`pawn' expected"); | |
| int* pawn = (int*)userdata[0][2]; | |
| int* weapon_arr_start = (int*)pawn[1]; | |
| int* weapon_arr_end = (int*)pawn[2]; | |
| int* weapon_addr = weapon_arr_start + 2 * idx; | |
| if (weapon_addr < weapon_arr_start || weapon_addr >= weapon_arr_end) { | |
| return luaL_error(L, "weapon index %d out of bounds", idx); | |
| } | |
| int* weapon = (int*)*weapon_addr; | |
| int kind = weapon[5]; | |
| if (kind == 15) { | |
| char* name = (char*)weapon; | |
| lua_pushstring(L, name); | |
| return 1; | |
| } | |
| else if (kind == 31) { | |
| char* name = *(char**)weapon; | |
| lua_pushstring(L, name); | |
| return 1; | |
| } | |
| else { | |
| return luaL_error(L, "weapon kind thingy %d unknown!", kind); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment