Added the API additions from waspsaliva
This commit is contained in:
parent
c1aea404b8
commit
28a560684b
@ -169,6 +169,16 @@ public:
|
||||
|
||||
inline const v3f &getRotation() const { return m_rotation; }
|
||||
|
||||
inline const v3f getAcceleration() const
|
||||
{
|
||||
return m_acceleration;
|
||||
}
|
||||
|
||||
inline const v3f getVelocity() const
|
||||
{
|
||||
return m_velocity;
|
||||
}
|
||||
|
||||
const bool isImmortal();
|
||||
|
||||
scene::ISceneNode *getSceneNode() const;
|
||||
@ -205,6 +215,16 @@ public:
|
||||
return m_is_local_player;
|
||||
}
|
||||
|
||||
inline std::string getName() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
inline bool isPlayer() const
|
||||
{
|
||||
return m_is_player;
|
||||
}
|
||||
|
||||
inline bool isVisible() const
|
||||
{
|
||||
return m_is_visible;
|
||||
@ -278,4 +298,9 @@ public:
|
||||
}
|
||||
|
||||
float m_waiting_for_reattach;
|
||||
|
||||
ObjectProperties *getProperties()
|
||||
{
|
||||
return &m_prop;
|
||||
}
|
||||
};
|
||||
|
@ -48,8 +48,8 @@ void CheatMenu::drawEntry(video::IVideoDriver *driver, std::string name, int num
|
||||
} else {
|
||||
bool is_category = entry_type == CHEAT_MENU_ENTRY_TYPE_CATEGORY;
|
||||
y += m_gap + m_head_height +
|
||||
(number + (is_category ? 0 : m_selected_category)) *
|
||||
(m_entry_height + m_gap);
|
||||
(number + (is_category ? 0 : m_selected_category)) *
|
||||
(m_entry_height + m_gap);
|
||||
x += (is_category ? 0 : m_gap + m_entry_width);
|
||||
if (active)
|
||||
bgcolor = &m_active_bg_color;
|
||||
@ -67,7 +67,7 @@ void CheatMenu::drawEntry(video::IVideoDriver *driver, std::string name, int num
|
||||
m_font->draw(name.c_str(), fontbounds, *fontcolor, false, false);
|
||||
}
|
||||
|
||||
void CheatMenu::draw(video::IVideoDriver* driver, bool show_debug)
|
||||
void CheatMenu::draw(video::IVideoDriver *driver, bool show_debug)
|
||||
{
|
||||
CHEAT_MENU_GET_SCRIPTPTR
|
||||
|
||||
|
@ -22,9 +22,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include "irrlichttypes_extrabloated.h"
|
||||
#include <string>
|
||||
|
||||
#define CHEAT_MENU_GET_SCRIPTPTR \
|
||||
#define CHEAT_MENU_GET_SCRIPTPTR \
|
||||
ClientScripting *script = m_client->getScript(); \
|
||||
if (! script || ! script->m_cheats_loaded) \
|
||||
if (!script || !script->m_cheats_loaded) \
|
||||
return;
|
||||
|
||||
class Client;
|
||||
|
@ -15,7 +15,7 @@ GNU Lesser General Public License for more details.
|
||||
You should have received a copy of the GNU Lesser General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
@ -44,7 +44,7 @@ public:
|
||||
~ScriptApiCheatsCategory();
|
||||
std::string m_name;
|
||||
void read_cheats(lua_State *L);
|
||||
std::vector<ScriptApiCheatsCheat *> m_cheats;
|
||||
std::vector<ScriptApiCheatsCheat *> m_cheats;
|
||||
};
|
||||
|
||||
class ScriptApiCheats : virtual public ScriptApiBase
|
||||
|
@ -287,6 +287,10 @@ void ScriptApiSecurity::initializeSecurityClient()
|
||||
lua_State *L = getStack();
|
||||
int thread = getThread(L);
|
||||
|
||||
// Backup globals to the registry
|
||||
lua_getglobal(L, "_G");
|
||||
lua_rawseti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_GLOBALS_BACKUP);
|
||||
|
||||
// create an empty environment
|
||||
createEmptyEnv(L);
|
||||
|
||||
|
@ -28,6 +28,7 @@ set(common_SCRIPT_LUA_API_SRCS
|
||||
set(client_SCRIPT_LUA_API_SRCS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/l_camera.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/l_client.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/l_clientobject.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/l_localplayer.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/l_mainmenu.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/l_minimap.cpp
|
||||
|
@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include "cpp_api/s_base.h"
|
||||
#include "gettext.h"
|
||||
#include "l_internal.h"
|
||||
#include "l_clientobject.h"
|
||||
#include "lua_api/l_nodemeta.h"
|
||||
#include "gui/mainmenumanager.h"
|
||||
#include "map.h"
|
||||
@ -503,6 +504,26 @@ int ModApiClient::l_drop_selected_item(lua_State *L)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// get_objects_inside_radius(pos, radius)
|
||||
int ModApiClient::l_get_objects_inside_radius(lua_State *L)
|
||||
{
|
||||
ClientEnvironment &env = getClient(L)->getEnv();
|
||||
|
||||
v3f pos = checkFloatPos(L, 1);
|
||||
float radius = readParam<float>(L, 2) * BS;
|
||||
|
||||
std::vector<DistanceSortedActiveObject> objs;
|
||||
env.getActiveObjects(pos, radius, objs);
|
||||
|
||||
int i = 0;
|
||||
lua_createtable(L, objs.size(), 0);
|
||||
for (const auto obj : objs) {
|
||||
ClientObjectRef::create(L, obj.obj); // TODO: getObjectRefOrCreate
|
||||
lua_rawseti(L, -2, ++i);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ModApiClient::Initialize(lua_State *L, int top)
|
||||
{
|
||||
API_FCT(get_current_modname);
|
||||
@ -536,4 +557,5 @@ void ModApiClient::Initialize(lua_State *L, int top)
|
||||
API_FCT(get_inventory);
|
||||
API_FCT(set_keypress);
|
||||
API_FCT(drop_selected_item);
|
||||
API_FCT(get_objects_inside_radius);
|
||||
}
|
||||
|
@ -119,10 +119,13 @@ private:
|
||||
|
||||
// set_keypress(key_setting, pressed)
|
||||
static int l_set_keypress(lua_State *L);
|
||||
|
||||
|
||||
// drop_selected_item()
|
||||
static int l_drop_selected_item(lua_State *L);
|
||||
|
||||
public:
|
||||
// get_objects_inside_radius(pos, radius)
|
||||
static int l_get_objects_inside_radius(lua_State *L);
|
||||
|
||||
public:
|
||||
static void Initialize(lua_State *L, int top);
|
||||
};
|
||||
|
199
src/script/lua_api/l_clientobject.cpp
Normal file
199
src/script/lua_api/l_clientobject.cpp
Normal file
@ -0,0 +1,199 @@
|
||||
/*
|
||||
Dragonfire
|
||||
Copyright (C) 2020 system32
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "lua_api/l_clientobject.h"
|
||||
#include "l_internal.h"
|
||||
#include "common/c_converter.h"
|
||||
#include "client/client.h"
|
||||
#include "object_properties.h"
|
||||
|
||||
// should prob do some more NULL checking
|
||||
|
||||
|
||||
ClientObjectRef *ClientObjectRef::checkobject(lua_State *L, int narg)
|
||||
{
|
||||
luaL_checktype(L, narg, LUA_TUSERDATA);
|
||||
void *userdata = luaL_checkudata(L, narg, className);
|
||||
if (!userdata)
|
||||
luaL_typerror(L, narg, className);
|
||||
return *(ClientObjectRef**)userdata;
|
||||
}
|
||||
|
||||
ClientActiveObject *ClientObjectRef::get_cao(ClientObjectRef *ref)
|
||||
{
|
||||
ClientActiveObject *obj = ref->m_object;
|
||||
return obj;
|
||||
}
|
||||
|
||||
GenericCAO *ClientObjectRef::get_generic_cao(ClientObjectRef *ref, lua_State *L)
|
||||
{
|
||||
ClientActiveObject *obj = get_cao(ref);
|
||||
ClientEnvironment &env = getClient(L)->getEnv();
|
||||
GenericCAO *gcao = env.getGenericCAO(obj->getId());
|
||||
return gcao;
|
||||
}
|
||||
|
||||
int ClientObjectRef::l_get_pos(lua_State *L)
|
||||
{
|
||||
ClientObjectRef *ref = checkobject(L, 1);
|
||||
ClientActiveObject *cao = get_cao(ref);
|
||||
push_v3f(L, cao->getPosition() / BS);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ClientObjectRef::l_get_velocity(lua_State *L)
|
||||
{
|
||||
ClientObjectRef *ref = checkobject(L, 1);
|
||||
GenericCAO *gcao = get_generic_cao(ref, L);
|
||||
push_v3f(L, gcao->getVelocity() / BS);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ClientObjectRef::l_get_acceleration(lua_State *L)
|
||||
{
|
||||
ClientObjectRef *ref = checkobject(L, 1);
|
||||
GenericCAO *gcao = get_generic_cao(ref, L);
|
||||
push_v3f(L, gcao->getAcceleration() / BS);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ClientObjectRef::l_get_rotation(lua_State *L)
|
||||
{
|
||||
ClientObjectRef *ref = checkobject(L, 1);
|
||||
GenericCAO *gcao = get_generic_cao(ref, L);
|
||||
push_v3f(L, gcao->getRotation());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ClientObjectRef::l_is_player(lua_State *L)
|
||||
{
|
||||
ClientObjectRef *ref = checkobject(L, 1);
|
||||
GenericCAO *gcao = get_generic_cao(ref, L);
|
||||
lua_pushboolean(L, gcao->isPlayer());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ClientObjectRef::l_get_name(lua_State *L)
|
||||
{
|
||||
ClientObjectRef *ref = checkobject(L, 1);
|
||||
GenericCAO *gcao = get_generic_cao(ref, L);
|
||||
lua_pushstring(L, gcao->getName().c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ClientObjectRef::l_get_attach(lua_State *L)
|
||||
{
|
||||
ClientObjectRef *ref = checkobject(L, 1);
|
||||
GenericCAO *gcao = get_generic_cao(ref, L);
|
||||
create(L, gcao->getParent());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ClientObjectRef::l_get_nametag(lua_State *L)
|
||||
{
|
||||
ClientObjectRef *ref = checkobject(L, 1);
|
||||
GenericCAO *gcao = get_generic_cao(ref, L);
|
||||
ObjectProperties *props = gcao->getProperties();
|
||||
lua_pushstring(L, props->nametag.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ClientObjectRef::l_get_item_textures(lua_State *L)
|
||||
{
|
||||
ClientObjectRef *ref = checkobject(L, 1);
|
||||
GenericCAO *gcao = get_generic_cao(ref, L);
|
||||
ObjectProperties *props = gcao->getProperties();
|
||||
lua_newtable(L);
|
||||
|
||||
for (std::string &texture : props->textures) {
|
||||
lua_pushstring(L, texture.c_str());
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ClientObjectRef::l_get_max_hp(lua_State *L)
|
||||
{
|
||||
ClientObjectRef *ref = checkobject(L, 1);
|
||||
GenericCAO *gcao = get_generic_cao(ref, L);
|
||||
ObjectProperties *props = gcao->getProperties();
|
||||
lua_pushnumber(L, props->hp_max);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ClientObjectRef::ClientObjectRef(ClientActiveObject *object):
|
||||
m_object(object)
|
||||
{
|
||||
}
|
||||
|
||||
void ClientObjectRef::create(lua_State *L, ClientActiveObject *object)
|
||||
{
|
||||
if (object) {
|
||||
ClientObjectRef *o = new ClientObjectRef(object);
|
||||
*(void **)(lua_newuserdata(L, sizeof(void *))) = o;
|
||||
luaL_getmetatable(L, className);
|
||||
lua_setmetatable(L, -2);
|
||||
}
|
||||
}
|
||||
|
||||
int ClientObjectRef::gc_object(lua_State *L) {
|
||||
ClientObjectRef *obj = *(ClientObjectRef **)(lua_touserdata(L, 1));
|
||||
delete obj;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// taken from LuaLocalPlayer
|
||||
void ClientObjectRef::Register(lua_State *L)
|
||||
{
|
||||
lua_newtable(L);
|
||||
int methodtable = lua_gettop(L);
|
||||
luaL_newmetatable(L, className);
|
||||
int metatable = lua_gettop(L);
|
||||
|
||||
lua_pushliteral(L, "__metatable");
|
||||
lua_pushvalue(L, methodtable);
|
||||
lua_settable(L, metatable); // hide metatable from lua getmetatable()
|
||||
|
||||
lua_pushliteral(L, "__index");
|
||||
lua_pushvalue(L, methodtable);
|
||||
lua_settable(L, metatable);
|
||||
|
||||
lua_pushliteral(L, "__gc");
|
||||
lua_pushcfunction(L, gc_object);
|
||||
lua_settable(L, metatable);
|
||||
|
||||
lua_pop(L, 1); // Drop metatable
|
||||
|
||||
luaL_openlib(L, 0, methods, 0); // fill methodtable
|
||||
lua_pop(L, 1); // Drop methodtable
|
||||
}
|
||||
|
||||
const char ClientObjectRef::className[] = "ClientObjectRef";
|
||||
luaL_Reg ClientObjectRef::methods[] = {
|
||||
luamethod(ClientObjectRef, get_pos),
|
||||
luamethod(ClientObjectRef, get_velocity),
|
||||
luamethod(ClientObjectRef, get_acceleration),
|
||||
luamethod(ClientObjectRef, get_rotation),
|
||||
luamethod(ClientObjectRef, is_player),
|
||||
luamethod(ClientObjectRef, get_name),
|
||||
luamethod(ClientObjectRef, get_attach),
|
||||
luamethod(ClientObjectRef, get_nametag),
|
||||
luamethod(ClientObjectRef, get_item_textures),
|
||||
luamethod(ClientObjectRef, get_max_hp),
|
||||
{0, 0}
|
||||
};
|
77
src/script/lua_api/l_clientobject.h
Normal file
77
src/script/lua_api/l_clientobject.h
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
Dragonfire
|
||||
Copyright (C) 2020 system32
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "lua_api/l_base.h"
|
||||
#include "client/clientobject.h"
|
||||
#include "client/content_cao.h"
|
||||
|
||||
class ClientObjectRef : public ModApiBase
|
||||
{
|
||||
public:
|
||||
ClientObjectRef(ClientActiveObject *object);
|
||||
|
||||
~ClientObjectRef() = default;
|
||||
|
||||
static void Register(lua_State *L);
|
||||
|
||||
static void create(lua_State *L, ClientActiveObject *object);
|
||||
|
||||
static ClientObjectRef *checkobject(lua_State *L, int narg);
|
||||
|
||||
private:
|
||||
ClientActiveObject *m_object = nullptr;
|
||||
static const char className[];
|
||||
static luaL_Reg methods[];
|
||||
|
||||
static ClientActiveObject *get_cao(ClientObjectRef *ref);
|
||||
static GenericCAO *get_generic_cao(ClientObjectRef *ref, lua_State *L);
|
||||
|
||||
static int gc_object(lua_State *L);
|
||||
|
||||
// get_pos(self)
|
||||
// returns: {x=num, y=num, z=num}
|
||||
static int l_get_pos(lua_State *L);
|
||||
|
||||
// get_velocity(self)
|
||||
static int l_get_velocity(lua_State *L);
|
||||
|
||||
// get_acceleration(self)
|
||||
static int l_get_acceleration(lua_State *L);
|
||||
|
||||
// get_rotation(self)
|
||||
static int l_get_rotation(lua_State *L);
|
||||
|
||||
// is_player(self)
|
||||
static int l_is_player(lua_State *L);
|
||||
|
||||
// get_name(self)
|
||||
static int l_get_name(lua_State *L);
|
||||
|
||||
// get_attach(self)
|
||||
static int l_get_attach(lua_State *L);
|
||||
|
||||
// get_nametag(self)
|
||||
static int l_get_nametag(lua_State *L);
|
||||
|
||||
// get_textures(self)
|
||||
static int l_get_item_textures(lua_State *L);
|
||||
|
||||
// get_hp(self)
|
||||
static int l_get_max_hp(lua_State *L);
|
||||
};
|
@ -17,6 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "l_clientobject.h"
|
||||
#include "l_localplayer.h"
|
||||
#include "l_internal.h"
|
||||
#include "lua_api/l_item.h"
|
||||
@ -452,6 +453,17 @@ int LuaLocalPlayer::l_hud_get(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int LuaLocalPlayer::l_get_object(lua_State *L)
|
||||
{
|
||||
LocalPlayer *player = getobject(L, 1);
|
||||
ClientEnvironment &env = getClient(L)->getEnv();
|
||||
ClientActiveObject *obj = env.getGenericCAO(player->getCAO()->getId());
|
||||
|
||||
ClientObjectRef::create(L, obj);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
LuaLocalPlayer *LuaLocalPlayer::checkobject(lua_State *L, int narg)
|
||||
{
|
||||
luaL_checktype(L, narg, LUA_TUSERDATA);
|
||||
@ -546,6 +558,7 @@ const luaL_Reg LuaLocalPlayer::methods[] = {
|
||||
luamethod(LuaLocalPlayer, hud_remove),
|
||||
luamethod(LuaLocalPlayer, hud_change),
|
||||
luamethod(LuaLocalPlayer, hud_get),
|
||||
luamethod(LuaLocalPlayer, get_object),
|
||||
|
||||
{0, 0}
|
||||
};
|
||||
|
@ -111,6 +111,9 @@ private:
|
||||
// hud_get(self, id)
|
||||
static int l_hud_get(lua_State *L);
|
||||
|
||||
// get_object(self)
|
||||
static int l_get_object(lua_State *L);
|
||||
|
||||
LocalPlayer *m_localplayer = nullptr;
|
||||
|
||||
public:
|
||||
|
@ -531,6 +531,8 @@ void ModApiUtil::InitializeClient(lua_State *L, int top)
|
||||
API_FCT(compress);
|
||||
API_FCT(decompress);
|
||||
|
||||
API_FCT(request_insecure_environment);
|
||||
|
||||
API_FCT(encode_base64);
|
||||
API_FCT(decode_base64);
|
||||
|
||||
|
@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include "client/game.h"
|
||||
#include "cpp_api/s_internal.h"
|
||||
#include "lua_api/l_client.h"
|
||||
#include "lua_api/l_clientobject.h"
|
||||
#include "lua_api/l_env.h"
|
||||
#include "lua_api/l_item.h"
|
||||
#include "lua_api/l_itemstackmeta.h"
|
||||
@ -78,6 +79,7 @@ void ClientScripting::InitializeModApi(lua_State *L, int top)
|
||||
LuaCamera::Register(L);
|
||||
ModChannelRef::Register(L);
|
||||
LuaSettings::Register(L);
|
||||
ClientObjectRef::Register(L);
|
||||
|
||||
ModApiItemMod::Initialize(L, top);
|
||||
ModApiUtil::InitializeClient(L, top);
|
||||
|
Loading…
x
Reference in New Issue
Block a user