[Script]: Add method to clear text in HudElems (#604)

This commit is contained in:
Edo
2022-11-27 19:20:07 +00:00
committed by GitHub
parent 3b8aa2563b
commit 49d5e84372
19 changed files with 135 additions and 30 deletions

View File

@ -39,7 +39,7 @@ namespace Assets
xanim->names = builder->getAllocator()->allocateArray<unsigned short>(xanim->boneCount[Game::PART_TYPE_ALL]);
for (int i = 0; i < xanim->boneCount[Game::PART_TYPE_ALL]; ++i)
{
xanim->names[i] = Game::SL_GetString(reader.readCString(), 0);
xanim->names[i] = static_cast<std::uint16_t>(Game::SL_GetString(reader.readCString(), 0));
}
}
@ -49,7 +49,7 @@ namespace Assets
for (int i = 0; i < xanim->notifyCount; ++i)
{
xanim->notify[i].name = Game::SL_GetString(reader.readCString(), 0);
xanim->notify[i].name = static_cast<std::uint16_t>(Game::SL_GetString(reader.readCString(), 0));
}
}

View File

@ -128,7 +128,7 @@ namespace Assets
for (char i = 0; i < asset->numBones; ++i)
{
asset->boneNames[i] = Game::SL_GetString(reader.readCString(), 0);
asset->boneNames[i] = static_cast<std::uint16_t>(Game::SL_GetString(reader.readCString(), 0));
}
}

View File

@ -96,13 +96,13 @@ namespace Components
{
Game::Scr_AddString("autoassign");
Game::Scr_AddString("team_marinesopfor");
Game::Scr_Notify(ent, Game::SL_GetString("menuresponse", 0), 2);
Game::Scr_Notify(ent, static_cast<std::uint16_t>(Game::SL_GetString("menuresponse", 0)), 2);
Scheduler::Once([ent]
{
Game::Scr_AddString(Utils::String::VA("class%u", Utils::Cryptography::Rand::GenerateInt() % 5u));
Game::Scr_AddString("changeclass");
Game::Scr_Notify(ent, Game::SL_GetString("menuresponse", 0), 2);
Game::Scr_Notify(ent, static_cast<std::uint16_t>(Game::SL_GetString("menuresponse", 0)), 2);
}, Scheduler::Pipeline::SERVER, 1s);
}, Scheduler::Pipeline::SERVER, 1s);

View File

@ -73,7 +73,7 @@ namespace Components
Game::Scr_AddEntity(player);
Game::Scr_AddString(text + msgIndex);
Game::Scr_NotifyLevel(Game::SL_GetString("say", 0), 2);
Game::Scr_NotifyLevel(static_cast<std::uint16_t>(Game::SL_GetString("say", 0)), 2);
return text;
}

View File

@ -78,19 +78,19 @@ namespace Components
Utils::Memory::Allocator allocator;
if (!this->exists()) return std::string();
int position = Game::FS_FTell(this->handle);
const auto position = Game::FS_FTell(this->handle);
this->seek(0, Game::FS_SEEK_SET);
char* buffer = allocator.allocateArray<char>(this->size);
if (!this->read(buffer, this->size))
{
this->seek(position, Game::FS_SEEK_SET);
return std::string();
return {};
}
this->seek(position, Game::FS_SEEK_SET);
return std::string(buffer, this->size);
return {buffer, static_cast<std::size_t>(this->size)};
}
bool FileSystem::FileReader::read(void* buffer, size_t _size)

View File

@ -4,6 +4,7 @@
#include "IO.hpp"
#include "Script.hpp"
#include "ScriptExtension.hpp"
#include "ScriptPatches.hpp"
#include "ScriptStorage.hpp"
namespace Components
@ -14,6 +15,7 @@ namespace Components
Loader::Register(new IO());
Loader::Register(new Script());
Loader::Register(new ScriptExtension());
Loader::Register(new ScriptPatches());
Loader::Register(new ScriptStorage());
}
}

View File

@ -126,7 +126,7 @@ namespace Components
}
}
const auto p = "scriptdata" / std::filesystem::path(path);
const auto p = "scriptdata"s / std::filesystem::path(path);
const auto folder = p.parent_path().string();
const auto file = p.filename().string();
Game::Scr_AddInt(FileSystem::_DeleteFile(folder, file));

View File

@ -0,0 +1,36 @@
#include <STDInclude.hpp>
#include "ScriptPatches.hpp"
#include "Script.hpp"
using namespace Utils::String;
namespace Components
{
constexpr auto offset = 511;
Game::game_hudelem_s* ScriptPatches::HECmd_GetHudElem(Game::scr_entref_t entref)
{
if (entref.classnum != 1)
{
Game::Scr_ObjectError("not a hud element");
return nullptr;
}
assert(entref.entnum < 1024);
return &Game::g_hudelems[entref.entnum];
}
ScriptPatches::ScriptPatches()
{
Script::AddMethod("ClearHudText", [](Game::scr_entref_t entref) -> void
{
auto* hud = HECmd_GetHudElem(entref);
// Frees config string up
if ((hud->elem).text)
{
Game::SV_SetConfigstring((hud->elem).text + offset, nullptr);
}
});
}
}

View File

@ -0,0 +1,13 @@
#pragma once
namespace Components
{
class ScriptPatches : public Component
{
public:
ScriptPatches();
private:
static Game::game_hudelem_s* HECmd_GetHudElem(Game::scr_entref_t entref);
};
}

View File

@ -576,7 +576,7 @@ namespace Components
int ZoneBuilder::Zone::addScriptString(const std::string& str)
{
return this->addScriptString(Game::SL_GetString(str.data(), 0));
return this->addScriptString(static_cast<std::uint16_t>(Game::SL_GetString(str.data(), 0)));
}
// Mark a scriptString for writing and map it.