Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Commit

Permalink
add convar getstring and getint
Browse files Browse the repository at this point in the history
  • Loading branch information
huoji120 committed Oct 14, 2023
1 parent 99a2810 commit 074d32b
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions csgo2/script_apis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,8 @@ auto luaApi_HttpAsyncGet(lua_State* luaVm) -> int {
const auto theCtx = reinterpret_cast<_ctx*>(ctx);
std::string response;
auto httpCode =
Server::HttpGet(*theCtx->url.get(), response, *theCtx->header.get(),theCtx->timeOut);
Server::HttpGet(*theCtx->url.get(), response,
*theCtx->header.get(), theCtx->timeOut);
ScriptCallBacks::luaCall_onHttpRequest(
*theCtx->url.get(), *theCtx->metadata.get(),
response.c_str(), httpCode);
Expand All @@ -871,7 +872,44 @@ auto luaApi_HttpAsyncGet(lua_State* luaVm) -> int {
lua_pop(luaVm, 4);
return 0;
}
auto luaApi_GetConVarString(lua_State* luaVm) -> int {
// param: convarObject:int
ConVarHandle theConvarHandle{};
theConvarHandle.Set(lua_tointeger(luaVm, 1));
std::string value;
if (theConvarHandle.IsValid()) {
const auto convarData =
Offset::InterFaces::IVEngineCvar->GetConVar(theConvarHandle);
const auto address = convarData->values;
const auto valueData = reinterpret_cast<char*>(address);
value = convarData ? std::string(valueData) : "";
}
lua_pop(luaVm, 1);
lua_pushstring(luaVm, value.c_str());

return 1;
}
auto luaApi_GetConVarInt(lua_State* luaVm) -> int {
// param: convarObject:int
ConVarHandle theConvarHandle{};
theConvarHandle.Set(lua_tointeger(luaVm, 1));
int value = -1;
if (theConvarHandle.IsValid()) {
const auto convarData =
Offset::InterFaces::IVEngineCvar->GetConVar(theConvarHandle);
value = reinterpret_cast<int>(convarData->values);
}
lua_pop(luaVm, 1);
lua_pushinteger(luaVm, value);
return 1;
}
auto luaApi_GetConVarObject(lua_State* luaVm) -> int {
// param: name:string
const auto name = lua_tostring(luaVm, 1);
lua_pushnumber(luaVm,
Offset::InterFaces::IVEngineCvar->FindConVar(name).Get());
return 1;
}
auto initFunciton(lua_State* luaVm) -> void {
lua_register(luaVm, "ListenToGameEvent", luaApi_ListenToGameEvent);
lua_register(luaVm, "luaApi_SetPlayerCurrentWeaponAmmo",
Expand Down Expand Up @@ -921,8 +959,10 @@ auto initFunciton(lua_State* luaVm) -> void {
lua_register(luaVm, "luaApi_HttpPost", luaApi_HttpPost);
lua_register(luaVm, "luaApi_HttpAsyncGet", luaApi_HttpAsyncGet);
lua_register(luaVm, "luaApi_HttpAsyncPost", luaApi_HttpAsyncPost);
lua_register(luaVm, "luaApi_GetConVarObject", luaApi_GetConVarObject);

lua_register(luaVm, "luaApi_GetPlayerSteamId", luaApi_GetPlayerSteamId);
lua_register(luaVm, "luaApi_GetConVarString", luaApi_GetConVarString);
lua_register(luaVm, "luaApi_GetConVarInt", luaApi_GetConVarInt);
// lua_register(luaVm, "luaApi_TeleportPlayer", luaApi_TeleportPlayer);

luabridge::getGlobalNamespace(luaVm)
Expand Down

0 comments on commit 074d32b

Please sign in to comment.