Вопрос Lua values in LW

Начинающий
Статус
Оффлайн
Регистрация
4 Янв 2020
Сообщения
34
Реакции[?]
4
Поинты[?]
0
Hi, i tried saphire source based on lw with basically same api, nothing has been changed.
What happens is no matter what global you use, you always get this type of error:

Lua error: rgb_line.lua:1: attempt to index a nil value (global 'menu')
stack traceback:rgb_line.lua:1: in main chunk

Clua.cpp:
C++:
void c_lua::initialize()
{
    lua = sol::state(sol::c_call<decltype(&lua_panic), &lua_panic>);
    lua.open_libraries(sol::lib::base, sol::lib::string, sol::lib::math, sol::lib::table, sol::lib::debug, sol::lib::package);

    lua[crypt_str("collectgarbage")] = sol::nil;
    lua[crypt_str("dofilsse")] = sol::nil;
    lua[crypt_str("load")] = sol::nil;
    lua[crypt_str("loadfile")] = sol::nil;
    lua[crypt_str("pcall")] = sol::nil;
    lua[crypt_str("print")] = sol::nil;
    lua[crypt_str("xpcall")] = sol::nil;
    lua[crypt_str("getmetatable")] = sol::nil;
    lua[crypt_str("setmetatable")] = sol::nil;
    lua[crypt_str("__nil_callback")] = [](){};
    
    lua.new_enum(crypt_str("key_binds"),
        crypt_str("legit_automatic_fire"), 0,
        crypt_str("legit_enable"), 1,
        crypt_str("double_tap"), 2,
        crypt_str("safe_points"), 3,
        crypt_str("damage_override"), 4,
        crypt_str("hide_shots"), 12,
        crypt_str("manual_back"), 13,
        crypt_str("manual_left"), 14,
        crypt_str("manual_right"), 15,
        crypt_str("flip_desync"), 16,
        crypt_str("thirdperson"), 17,
        crypt_str("automatic_peek"), 18,
        crypt_str("edge_jump"), 19,
        crypt_str("fakeduck"), 20,
        crypt_str("slowwalk"), 21,
        crypt_str("body_aim"), 22
    );
    
    lua.new_enum(crypt_str("key_bind_mode"),
        crypt_str("hold"), 0,
        crypt_str("toggle"), 1
    );
    
    lua.new_usertype<entity_t>(crypt_str("entity"), // new
        (std::string)crypt_str("get_prop_int"), &entity_t::GetPropInt,
        (std::string)crypt_str("get_prop_float"), &entity_t::GetPropFloat,
        (std::string)crypt_str("get_prop_bool"), &entity_t::GetPropBool,
        (std::string)crypt_str("get_prop_string"), &entity_t::GetPropString,
        (std::string)crypt_str("set_prop_int"), &entity_t::SetPropInt,
        (std::string)crypt_str("set_prop_float"), &entity_t::SetPropFloat,
        (std::string)crypt_str("set_prop_bool"), &entity_t::SetPropBool       
    );
    
    lua.new_usertype <Color> (crypt_str("color"), sol::constructors <Color(), Color(int, int, int), Color(int, int, int, int)> (),
        (std::string)crypt_str("r"), &Color::r,
        (std::string)crypt_str("g"), &Color::g,
        (std::string)crypt_str("b"), &Color::b,
        (std::string)crypt_str("a"), &Color::a
    );
    
    lua.new_usertype <Vector> (crypt_str("vector"), sol::constructors <Vector(), Vector(float, float, float)> (),
        (std::string)crypt_str("x"), &Vector::x,
        (std::string)crypt_str("y"), &Vector::y,
        (std::string)crypt_str("z"), &Vector::z,
        (std::string)crypt_str("length"), &Vector::Length,
        (std::string)crypt_str("length_sqr"), &Vector::LengthSqr,
        (std::string)crypt_str("length_2d"), &Vector::Length2D,
        (std::string)crypt_str("length_2d_sqr"), &Vector::Length2DSqr,
        (std::string)crypt_str("is_zero"), &Vector::IsZero,
        (std::string)crypt_str("is_valid"), &Vector::IsValid,
        (std::string)crypt_str("zero"), &Vector::Zero,
        (std::string)crypt_str("dist_to"), &Vector::DistTo,
        (std::string)crypt_str("dist_to_sqr"), &Vector::DistToSqr,
        (std::string)crypt_str("cross_product"), &Vector::Cross,
        (std::string)crypt_str("normalize"), &Vector::Normalize
    );
    
lua.new_usertype <player_info_t> (crypt_str("player_info"),
(std::string)crypt_str("bot"), &player_info_t::fakeplayer,
(std::string)crypt_str("name"), &player_info_t::szName,
(std::string)crypt_str("steam_id"), &player_info_t::szSteamID
    //
    //);
    //
    lua.new_usertype <IGameEvent> (crypt_str("game_event"),
        (std::string)crypt_str("get_bool"), &IGameEvent::GetBool,
        (std::string)crypt_str("get_int"), &IGameEvent::GetInt,
        (std::string)crypt_str("get_float"), &IGameEvent::GetFloat,
        (std::string)crypt_str("get_string"), &IGameEvent::GetString,
        (std::string)crypt_str("set_bool"), &IGameEvent::SetBool,
        (std::string)crypt_str("set_int"), &IGameEvent::SetInt,
        (std::string)crypt_str("set_float"), &IGameEvent::SetFloat,
        (std::string)crypt_str("set_string"), &IGameEvent::SetString
    );
    
    lua.new_enum(crypt_str("hitboxes"),
        crypt_str("head"), HITBOX_HEAD,
        crypt_str("neck"), HITBOX_NECK,
        crypt_str("pelvis"), HITBOX_PELVIS,
        crypt_str("stomach"), HITBOX_STOMACH,
        crypt_str("lower_chest"), HITBOX_LOWER_CHEST,
        crypt_str("chest"), HITBOX_CHEST,
        crypt_str("upper_chest"), HITBOX_UPPER_CHEST,
        crypt_str("right_thigh"), HITBOX_RIGHT_THIGH,
        crypt_str("left_thigh"), HITBOX_LEFT_THIGH,
        crypt_str("right_calf"), HITBOX_RIGHT_CALF,
        crypt_str("left_calf"), HITBOX_LEFT_CALF,
        crypt_str("right_foot"), HITBOX_RIGHT_FOOT,
        crypt_str("left_foot"), HITBOX_LEFT_FOOT,
        crypt_str("right_hand"), HITBOX_RIGHT_HAND,
        crypt_str("left_hand"), HITBOX_LEFT_HAND,
        crypt_str("right_upper_arm"), HITBOX_RIGHT_UPPER_ARM,
        crypt_str("right_forearm"), HITBOX_RIGHT_FOREARM,
        crypt_str("left_upper_arm"), HITBOX_LEFT_UPPER_ARM,
        crypt_str("left_forearm"), HITBOX_LEFT_FOREARM
    );
    
    lua.new_usertype <player_t> (crypt_str("player"), sol::base_classes, sol::bases<entity_t>(), //new
        (std::string)crypt_str("get_index"), &player_t::EntIndex,
        (std::string)crypt_str("get_dormant"), &player_t::IsDormant,
        (std::string)crypt_str("get_team"), &player_t::m_iTeamNum,
        (std::string)crypt_str("get_alive"), &player_t::is_alive,
        (std::string)crypt_str("get_velocity"), &player_t::m_vecVelocity,
        (std::string)crypt_str("get_origin"), &player_t::GetAbsOrigin,
        (std::string)crypt_str("get_angles"), &player_t::m_angEyeAngles,
        (std::string)crypt_str("get_hitbox_position"), &player_t::hitbox_position,
        (std::string)crypt_str("has_helmet"), &player_t::m_bHasHelmet,
        (std::string)crypt_str("has_heavy_armor"), &player_t::m_bHasHeavyArmor,
        (std::string)crypt_str("is_scoped"), &player_t::m_bIsScoped,
        (std::string)crypt_str("get_health"), &player_t::m_iHealth
    );
    
    lua.new_usertype <weapon_t> (crypt_str("weapon"), sol::base_classes, sol::bases<entity_t>(),
        (std::string)crypt_str("is_empty"), &weapon_t::is_empty,
        (std::string)crypt_str("can_fire"), &weapon_t::can_fire,
        (std::string)crypt_str("is_non_aim"), &weapon_t::is_non_aim,
        (std::string)crypt_str("can_double_tap"), &weapon_t::can_double_tap,
        (std::string)crypt_str("get_name"), &weapon_t::get_name,
        (std::string)crypt_str("get_inaccuracy"), &weapon_t::get_inaccuracy,
        (std::string)crypt_str("get_spread"), &weapon_t::get_spread
    );
    
    lua.new_enum(crypt_str("buttons"),
        crypt_str("in_attack"), IN_ATTACK,
        crypt_str("in_jump"), IN_JUMP,
        crypt_str("in_duck"), IN_DUCK,
        crypt_str("in_forward"), IN_FORWARD,
        crypt_str("in_back"), IN_BACK,
        crypt_str("in_use"), IN_USE,
        crypt_str("in_cancel"), IN_CANCEL,
        crypt_str("in_left"), IN_LEFT,
        crypt_str("in_right"), IN_RIGHT,
        crypt_str("in_moveleft"), IN_MOVELEFT,
        crypt_str("in_moveright"), IN_MOVERIGHT,
        crypt_str("in_attack2"), IN_ATTACK2,
        crypt_str("in_run"), IN_RUN,
        crypt_str("in_reload"), IN_RELOAD,
        crypt_str("in_alt1"), IN_ALT1,
        crypt_str("in_alt2"), IN_ALT2,
        crypt_str("in_score"), IN_SCORE,
        crypt_str("in_speed"), IN_SPEED,
        crypt_str("in_walk"), IN_WALK,
        crypt_str("in_zoom"), IN_ZOOM,
        crypt_str("in_weapon1"), IN_WEAPON1,
        crypt_str("in_weapon2"), IN_WEAPON2,
        crypt_str("in_bullrush"), IN_BULLRUSH,
        crypt_str("in_grenade1"), IN_GRENADE1,
        crypt_str("in_grenade2"), IN_GRENADE2,
        crypt_str("in_lookspin"), IN_LOOKSPIN
    );
    
    lua.new_usertype <shot_info> (crypt_str("shot_info"), sol::constructors <> (),
        (std::string)crypt_str("target_name"), &shot_info::target_name,
        (std::string)crypt_str("result"), &shot_info::result,
        (std::string)crypt_str("client_hitbox"), &shot_info::client_hitbox,
        (std::string)crypt_str("server_hitbox"), &shot_info::server_hitbox,
        (std::string)crypt_str("client_damage"), &shot_info::client_damage,
        (std::string)crypt_str("server_damage"), &shot_info::server_damage,
        (std::string)crypt_str("hitchance"), &shot_info::hitchance,
        (std::string)crypt_str("backtrack_ticks"), &shot_info::backtrack_ticks,
        (std::string)crypt_str("aim_point"), &shot_info::aim_point
    );
    
    auto client = lua.create_table();
    client[crypt_str("add_callback")] = ns_client::add_callback;
    client[crypt_str("load_script")] = ns_client::load_script;
    client[crypt_str("unload_script")] = ns_client::unload_script;
    client[crypt_str("log")] = ns_client::log;
    
    auto menu = lua.create_table();
    menu[crypt_str("next_line")] = ns_menu::next_line;
    menu[crypt_str("add_check_box")] = ns_menu::add_check_box;
    menu[crypt_str("add_combo_box")] = ns_menu::add_combo_box;
    menu[crypt_str("add_slider_int")] = ns_menu::add_slider_int;
    menu[crypt_str("add_slider_float")] = ns_menu::add_slider_float;
    menu[crypt_str("add_color_picker")] = ns_menu::add_color_picker;
    menu[crypt_str("get_bool")] = ns_menu::get_bool;
    menu[crypt_str("get_int")] = ns_menu::get_int;
    menu[crypt_str("get_float")] = ns_menu::get_float;
    menu[crypt_str("get_color")] = ns_menu::get_color;
    menu[crypt_str("get_key_bind_state")] = ns_menu::get_key_bind_state;
    menu[crypt_str("get_key_bind_mode")] = ns_menu::get_key_bind_mode;
    menu[crypt_str("set_bool")] = ns_menu::set_bool;
    menu[crypt_str("set_int")] = ns_menu::set_int;
    menu[crypt_str("set_float")] = ns_menu::set_float;
    menu[crypt_str("set_color")] = ns_menu::set_color;
    
    auto globals = lua.create_table();
    globals[crypt_str("get_framerate")] = ns_globals::get_framerate;
    globals[crypt_str("get_ping")] = ns_globals::get_ping;
    globals[crypt_str("get_server_address")] = ns_globals::get_server_address;
    globals[crypt_str("get_time")] = ns_globals::get_time;
    globals[crypt_str("get_username")] = ns_globals::get_username;
    globals[crypt_str("get_realtime")] = ns_globals::get_realtime;
    globals[crypt_str("get_curtime")] = ns_globals::get_curtime;
    globals[crypt_str("get_frametime")] = ns_globals::get_frametime;
    globals[crypt_str("get_tickcount")] = ns_globals::get_tickcount;
    globals[crypt_str("get_framecount")] = ns_globals::get_framecount;
    globals[crypt_str("get_intervalpertick")] = ns_globals::get_intervalpertick;
    globals[crypt_str("get_maxclients")] = ns_globals::get_maxclients;
    
    auto engine = lua.create_table();
    engine[crypt_str("get_screen_width")] = ns_engine::get_screen_width;
    engine[crypt_str("get_screen_height")] = ns_engine::get_screen_height;
    engine[crypt_str("get_level_name")] = ns_engine::get_level_name;
    engine[crypt_str("get_level_name_short")] = ns_engine::get_level_name_short;
    engine[crypt_str("get_local_player_index")] = ns_engine::get_local_player_index;
    engine[crypt_str("get_map_group_name")] = ns_engine::get_map_group_name;
    engine[crypt_str("get_player_for_user_id")] = ns_engine::get_player_for_user_id;
    engine[crypt_str("get_player_info")] = ns_engine::get_player_info;
    engine[crypt_str("get_view_angles")] = ns_engine::get_view_angles;
    engine[crypt_str("is_connected")] = ns_engine::is_connected;
    engine[crypt_str("is_hltv")] = ns_engine::is_hltv;
    engine[crypt_str("is_in_game")] = ns_engine::is_in_game;
    engine[crypt_str("is_paused")] = ns_engine::is_paused;
    engine[crypt_str("is_playing_demo")] = ns_engine::is_playing_demo;
    engine[crypt_str("is_recording_demo")] = ns_engine::is_recording_demo;
    engine[crypt_str("is_taking_screenshot")] = ns_engine::is_taking_screenshot;
    engine[crypt_str("set_view_angles")] = ns_engine::set_view_angles;
    
    auto render = lua.create_table();
    render[crypt_str("world_to_screen")] = ns_render::world_to_screen;
    render[crypt_str("get_text_width")] = ns_render::get_text_width;
    render[crypt_str("create_font")] = ns_render::create_font;
    render[crypt_str("draw_text")] = ns_render::draw_text;
    render[crypt_str("draw_text_centered")] = ns_render::draw_text_centered;
    render[crypt_str("draw_line")] = ns_render::draw_line;
    render[crypt_str("draw_rect")] = ns_render::draw_rect;
    render[crypt_str("draw_rect_filled")] = ns_render::draw_rect_filled;
    render[crypt_str("draw_rect_filled_gradient")] = ns_render::draw_rect_filled_gradient;
    render[crypt_str("draw_circle")] = ns_render::draw_circle;
    render[crypt_str("draw_circle_filled")] = ns_render::draw_circle_filled;
    render[crypt_str("draw_triangle")] = ns_render::draw_triangle;
    
    auto console = lua.create_table();
    console[crypt_str("execute")] = ns_console::execute;
    console[crypt_str("get_int")] = ns_console::get_int;
    console[crypt_str("get_float")] = ns_console::get_float;
    console[crypt_str("get_string")] = ns_console::get_string;
    console[crypt_str("set_int")] = ns_console::set_int;
    console[crypt_str("set_float")] = ns_console::set_float;
    console[crypt_str("set_string")] = ns_console::set_string;
    
auto events = lua.create_table(); -V688
    events[crypt_str("register_event")] = ns_events::register_event;
    
    auto entitylist = lua.create_table();
    entitylist[crypt_str("get_local_player")] = ns_entitylist::get_local_player;
    entitylist[crypt_str("get_player_by_index")] = ns_entitylist::get_player_by_index;
    entitylist[crypt_str("get_weapon_by_player")] = ns_entitylist::get_weapon_by_player;
    
    auto cmd = lua.create_table();
    cmd[crypt_str("get_send_packet")] = ns_cmd::get_send_packet;
    cmd[crypt_str("set_send_packet")] = ns_cmd::set_send_packet;
    cmd[crypt_str("get_choke")] = ns_cmd::get_choke;
    cmd[crypt_str("get_button_state")] = ns_cmd::get_button_state;
    cmd[crypt_str("set_button_state")] = ns_cmd::set_button_state;
    
    auto utils = lua.create_table();//new
    utils[crypt_str("find_signature")] = ns_utils::find_signature;//new
    
    auto indicators = lua.create_table();//new
    indicators[crypt_str("add")] = ns_indicator::add_indicator;//new
    indicators[crypt_str("add_position")] = ns_indicator::add_indicator_with_pos;//new
    
    auto http = lua.create_table();//new
    http[crypt_str("get")] = ns_http::get;//new
    http[crypt_str("post")] = ns_http::post;//new
    
    auto file = lua.create_table();//new
file[crypt_str("append")] = ns_file::append; new
    file[crypt_str("write")] = ns_file::write;//new
    file[crypt_str("read")] = ns_file::read;//new
    
    lua[crypt_str("client")] = client;
    lua[crypt_str("menu")] = menu;
    lua[crypt_str("globals")] = globals;
    lua[crypt_str("engine")] = engine;
    lua[crypt_str("render")] = render;
    lua[crypt_str("console")] = console;
    lua[crypt_str("events")] = events;
    lua[crypt_str("entitylist")] = entitylist;
    lua[crypt_str("cmd")] = cmd;
    lua[crypt_str("utils")] = utils;//new
    lua[crypt_str("indicators")] = indicators;//new
    lua[crypt_str("http")] = http;//new
    lua[crypt_str("file")] = file;//new

    refresh_scripts();
}
Clua.h:
C++:
class c_lua : public singleton <c_lua>
{
public:
    void initialize();
    void refresh_scripts();

    void load_script(int id);
    void unload_script(int id);

    void reload_all_scripts();
    void unload_all_scripts();

    int get_script_id(const std::string& name);
    int get_script_id_by_path(const std::string& path);

    std::vector <bool> loaded;
    std::vector <std::string> scripts;
    std::vector <std::vector <std::pair <std::string, menu_item>>> items;
    std::unordered_map <int, std::unordered_map <std::string, sol::protected_function>> events;

    c_lua_hookManager hooks;
private:
    std::string get_script_path(const std::string& name);
    std::string get_script_path(int id);

    std::vector <std::filesystem::path> pathes;
};
 
Сверху Снизу