mirror of
https://github.com/fedddddd/iw5-gsc-utils.git
synced 2025-04-22 13:45:43 +00:00
Formatting
This commit is contained in:
parent
6b1796fbab
commit
4697f6136b
@ -11,129 +11,129 @@
|
|||||||
|
|
||||||
namespace io
|
namespace io
|
||||||
{
|
{
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
std::string load_path()
|
std::string load_path()
|
||||||
{
|
{
|
||||||
const auto fs_basegame = game::Dvar_FindVar("fs_basegame");
|
const auto fs_basegame = game::Dvar_FindVar("fs_basegame");
|
||||||
|
|
||||||
return fs_basegame->current.string;
|
return fs_basegame->current.string;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string get_path()
|
std::string get_path()
|
||||||
{
|
{
|
||||||
static const auto path = load_path();
|
static const auto path = load_path();
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class component final : public component_interface
|
class component final : public component_interface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void post_unpack() override
|
void post_unpack() override
|
||||||
{
|
{
|
||||||
const auto path = get_path();
|
const auto path = get_path();
|
||||||
std::filesystem::current_path(path);
|
std::filesystem::current_path(path);
|
||||||
|
|
||||||
gsc::function::add("fremove", [](gsc::function_args args)
|
gsc::function::add("fremove", [](gsc::function_args args)
|
||||||
{
|
{
|
||||||
const auto path = args[0].as<const char*>();
|
const auto path = args[0].as<const char*>();
|
||||||
|
|
||||||
const auto result = std::remove(path);
|
const auto result = std::remove(path);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
|
|
||||||
gsc::function::add("fopen", [](gsc::function_args args)
|
gsc::function::add("fopen", [](gsc::function_args args)
|
||||||
{
|
{
|
||||||
const auto* path = args[0].as<const char*>();
|
const auto* path = args[0].as<const char*>();
|
||||||
const auto* mode = args[1].as<const char*>();
|
const auto* mode = args[1].as<const char*>();
|
||||||
|
|
||||||
const auto handle = fopen(path, mode);
|
const auto handle = fopen(path, mode);
|
||||||
|
|
||||||
if (!handle)
|
if (!handle)
|
||||||
{
|
{
|
||||||
printf("fopen: Invalid path\n");
|
printf("fopen: Invalid path\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
return handle;
|
return handle;
|
||||||
});
|
});
|
||||||
|
|
||||||
gsc::function::add("fgetc", [](gsc::function_args args)
|
gsc::function::add("fgetc", [](gsc::function_args args)
|
||||||
{
|
{
|
||||||
const auto handle = args[0].as_ptr<FILE>();
|
const auto handle = args[0].as_ptr<FILE>();
|
||||||
|
|
||||||
const char c = fgetc(handle);
|
const char c = fgetc(handle);
|
||||||
const char str[2] = {c, '\0'};
|
const char str[2] = {c, '\0'};
|
||||||
|
|
||||||
return std::string(str);
|
return std::string(str);
|
||||||
});
|
});
|
||||||
|
|
||||||
gsc::function::add("fgets", [](gsc::function_args args)
|
gsc::function::add("fgets", [](gsc::function_args args)
|
||||||
{
|
{
|
||||||
const auto handle = args[0].as_ptr<FILE>();
|
const auto handle = args[0].as_ptr<FILE>();
|
||||||
const auto n = args[1].as<int>();
|
const auto n = args[1].as<int>();
|
||||||
|
|
||||||
char* buffer = (char*)calloc(n, sizeof(char));
|
char* buffer = (char*)calloc(n, sizeof(char));
|
||||||
|
|
||||||
fgets(buffer, n, handle);
|
fgets(buffer, n, handle);
|
||||||
|
|
||||||
const std::string result = buffer;
|
const std::string result = buffer;
|
||||||
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
|
|
||||||
gsc::function::add("feof", [](gsc::function_args args)
|
gsc::function::add("feof", [](gsc::function_args args)
|
||||||
{
|
{
|
||||||
const auto handle = args[0].as_ptr<FILE>();
|
const auto handle = args[0].as_ptr<FILE>();
|
||||||
return feof(handle);
|
return feof(handle);
|
||||||
});
|
});
|
||||||
|
|
||||||
gsc::function::add("fclose", [](gsc::function_args args)
|
gsc::function::add("fclose", [](gsc::function_args args)
|
||||||
{
|
{
|
||||||
const auto handle = args[0].as_ptr<FILE>();
|
const auto handle = args[0].as_ptr<FILE>();
|
||||||
return fclose(handle);
|
return fclose(handle);
|
||||||
});
|
});
|
||||||
|
|
||||||
gsc::function::add("fputs", [](gsc::function_args args)
|
gsc::function::add("fputs", [](gsc::function_args args)
|
||||||
{
|
{
|
||||||
const auto text = args[0].as<const char*>();
|
const auto text = args[0].as<const char*>();
|
||||||
const auto handle = args[0].as_ptr<FILE>();
|
const auto handle = args[0].as_ptr<FILE>();
|
||||||
|
|
||||||
return fputs(text, handle);
|
return fputs(text, handle);
|
||||||
});
|
});
|
||||||
|
|
||||||
gsc::function::add("fprintf", [](gsc::function_args args)
|
gsc::function::add("fprintf", [](gsc::function_args args)
|
||||||
{
|
{
|
||||||
const auto text = args[0].as<const char*>();
|
const auto text = args[0].as<const char*>();
|
||||||
const auto handle = args[1].as_ptr<FILE>();
|
const auto handle = args[1].as_ptr<FILE>();
|
||||||
|
|
||||||
return fprintf(handle, text);
|
return fprintf(handle, text);
|
||||||
});
|
});
|
||||||
|
|
||||||
gsc::function::add("fread", [](gsc::function_args args)
|
gsc::function::add("fread", [](gsc::function_args args)
|
||||||
{
|
{
|
||||||
const auto handle = args[0].as_ptr<FILE>();
|
const auto handle = args[0].as_ptr<FILE>();
|
||||||
|
|
||||||
fseek(handle, 0, SEEK_END);
|
fseek(handle, 0, SEEK_END);
|
||||||
const auto length = ftell(handle);
|
const auto length = ftell(handle);
|
||||||
|
|
||||||
fseek(handle, 0, SEEK_SET);
|
fseek(handle, 0, SEEK_SET);
|
||||||
char* buffer = (char*)calloc(length, sizeof(char));
|
char* buffer = (char*)calloc(length, sizeof(char));
|
||||||
|
|
||||||
fread(buffer, sizeof(char), length, handle);
|
fread(buffer, sizeof(char), length, handle);
|
||||||
|
|
||||||
const std::string result = buffer;
|
const std::string result = buffer;
|
||||||
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
REGISTER_COMPONENT(io::component)
|
REGISTER_COMPONENT(io::component)
|
Loading…
x
Reference in New Issue
Block a user