fixes and little changes

This commit is contained in:
m 2022-10-26 22:22:45 -05:00
parent 9bd419a7cb
commit 40d2b3de66
5 changed files with 51 additions and 47 deletions

View File

@ -33,11 +33,6 @@ namespace gsc
namespace
{
struct gsc_error : public std::runtime_error
{
using std::runtime_error::runtime_error;
};
std::unordered_map<std::uint32_t, script_function> functions;
std::unordered_map<std::uint32_t, script_method> methods;
@ -264,6 +259,11 @@ namespace gsc
}
console::info("%s\n", buffer.data());
}
scripting::script_value typeof(const function_args& args)
{
return args[0].type_name();
}
}
namespace function
@ -365,6 +365,15 @@ namespace gsc
utils::hook::call(SELECT_VALUE(0x3CC9F3_b, 0x513A53_b), vm_error_stub);
if (game::environment::is_dedi())
{
function::add("isusingmatchrulesdata", [](const function_args& args)
{
// return 0 so the game doesn't override the cfg
return 0;
});
}
function::add("print", [](const function_args& args)
{
print(args);
@ -457,12 +466,6 @@ namespace gsc
return scripting::script_value{};
});
function::add("isusingmatchrulesdata", [](const function_args& args)
{
// return 0 so the game doesn't override the cfg
return 0;
});
function::add("say", [](const function_args& args)
{
const auto message = args[0].as<std::string>();
@ -471,6 +474,9 @@ namespace gsc
return scripting::script_value{};
});
function::add("typeof", typeof);
function::add("type", typeof);
method::add("tell", [](const game::scr_entref_t ent, const function_args& args)
{
if (ent.classnum != 0)

View File

@ -20,7 +20,7 @@ namespace io
{
namespace
{
bool use_root_folder = false;
bool allow_root_io = false;
void check_path(const std::filesystem::path& path)
{
@ -34,7 +34,7 @@ namespace io
{
check_path(path);
if (use_root_folder)
if (allow_root_io)
{
static const auto fs_base_game = game::Dvar_FindVar("fs_basepath");
const std::filesystem::path fs_base_game_path(fs_base_game->current.string);
@ -69,10 +69,10 @@ namespace io
public:
void post_unpack() override
{
use_root_folder = utils::flags::has_flag("io_game_dir");
if (use_root_folder)
allow_root_io = utils::flags::has_flag("allow_root_io");
if (allow_root_io)
{
console::warn("GSC has access to your game folder. To prevent possible malicious code, remove the '-io_game_dir' launch flag.");
console::warn("GSC has access to your game folder. Remove the '-allow_root_io' launch parameter to disable this feature.");
}
gsc::function::add("fileexists", [](const gsc::function_args& args)

View File

@ -94,7 +94,7 @@ namespace json
case (game::SCRIPT_FUNCTION):
return _value.as<scripting::function>().get_name();
default:
return "[unknown type]";
return utils::string::va("[%s]", _value.type_name().data());
};
}

View File

@ -30,20 +30,19 @@ namespace scripting
{11, "builtin method"},
{12, "stack"},
{13, "animation"},
{14, "developer codepos"}, // this exists on H1 but not IW6 (also not sure if past here may be correct)
{15, "pre animation"},
{16, "thread"},
{17, "notify thread"},
{18, "time thread"},
{19, "child thread"},
{20, "struct"},
{21, "removed entity"},
{22, "entity"},
{23, "array"},
{24, "removed thread"},
{25, "<free>"}, // VAR_COUNT is 25 on H1, but 24 on IW6
{26, "thread list"},
{27, "endon list"},
{14, "pre animation"},
{15, "thread"},
{16, "notify thread"},
{17, "time thread"},
{18, "child thread"},
{19, "struct"},
{20, "removed entity"},
{21, "entity"},
{22, "array"},
{23, "removed thread"},
{24, "<free>"},
{25, "thread list"},
{26, "endon list"},
};
std::string get_typename(const game::VariableValue& value)

View File

@ -56,22 +56,21 @@ namespace game
VAR_BUILTIN_METHOD = 0xB,
VAR_STACK = 0xC,
VAR_ANIMATION = 0xD,
VAR_DEVELOPER_CODEPOS = 0xE,
VAR_PRE_ANIMATION = 0xF,
VAR_THREAD = 0x10,
VAR_NOTIFY_THREAD = 0x11,
VAR_TIME_THREAD = 0x12,
VAR_CHILD_THREAD = 0x13,
VAR_OBJECT = 0x14,
VAR_DEAD_ENTITY = 0x15,
VAR_ENTITY = 0x16,
VAR_ARRAY = 0x17,
VAR_DEAD_THREAD = 0x18,
VAR_COUNT = 0x19,
VAR_FREE = 0x19,
VAR_THREAD_LIST = 0x1A,
VAR_ENDON_LIST = 0x1B,
VAR_TOTAL_COUNT = 0x1C,
VAR_PRE_ANIMATION = 0xE,
VAR_THREAD = 0xF,
VAR_NOTIFY_THREAD = 0x10,
VAR_TIME_THREAD = 0x11,
VAR_CHILD_THREAD = 0x12,
VAR_OBJECT = 0x13,
VAR_DEAD_ENTITY = 0x14,
VAR_ENTITY = 0x15,
VAR_ARRAY = 0x16,
VAR_DEAD_THREAD = 0x17,
VAR_COUNT = 0x18,
VAR_FREE = 0x18,
VAR_THREAD_LIST = 0x19,
VAR_ENDON_LIST = 0x1A,
VAR_TOTAL_COUNT = 0x1B,
};
struct VariableStackBuffer