[Feature] Add RegisterBug LuaMod (#4209)

* Add RegisterBug LuaMod

* Add missing header

* Add missing header to lua_mod

* Fix RegisterBug ignore_default

* Fix ignore_default

* Fix formatting
This commit is contained in:
Xackery 2024-03-30 08:45:37 -07:00 committed by GitHub
parent df1dc5d1e4
commit e19f72f021
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 94 additions and 1 deletions

View File

@ -57,6 +57,7 @@ extern volatile bool RunLoops;
#include "queryserv.h"
#include "mob_movement_manager.h"
#include "cheat_manager.h"
#include "lua_parser.h"
#include "../common/repositories/character_alternate_abilities_repository.h"
#include "../common/repositories/account_flags_repository.h"
@ -11647,6 +11648,14 @@ void Client::RegisterBug(BugReport_Struct* r) {
b.bug_report = r->bug_report;
b.system_info = r->system_info;
#ifdef LUA_EQEMU
bool ignore_default = false;
LuaParser::Instance()->RegisterBug(this, b, ignore_default);
if (ignore_default) {
return;
}
#endif
auto n = BugReportsRepository::InsertOne(database, b);
if (!n.id) {
Message(Chat::White, "Failed to created your bug report."); // Client sends success message

View File

@ -37,6 +37,7 @@ void LuaMod::Init()
m_has_get_experience_for_kill = parser_->HasFunction("GetExperienceForKill", package_name_);
m_has_common_outgoing_hit_success = parser_->HasFunction("CommonOutgoingHitSuccess", package_name_);
m_has_calc_spell_effect_value_formula = parser_->HasFunction("CalcSpellEffectValue_formula", package_name_);
m_has_register_bug = parser_->HasFunction("RegisterBug", package_name_);
}
void PutDamageHitInfo(lua_State *L, luabind::adl::object &e, DamageHitInfo &hit) {
@ -678,4 +679,74 @@ void LuaMod::CalcSpellEffectValue_formula(Mob *self, uint32 formula, int64 base_
}
}
void LuaMod::RegisterBug(Client *self, BaseBugReportsRepository::BugReports bug, bool &ignore_default)
{
int start = lua_gettop(L);
try {
if (!m_has_register_bug) {
return;
}
lua_getfield(L, LUA_REGISTRYINDEX, package_name_.c_str());
lua_getfield(L, -1, "RegisterBug");
Lua_Client l_self(self);
luabind::adl::object e = luabind::newtable(L);
e["self"] = l_self;
e["zone"] = bug.zone;
e["client_version_id"] = bug.client_version_id;
e["client_version_name"] = bug.client_version_name;
e["account_id"] = bug.account_id;
e["character_id"] = bug.character_id;
e["character_name"] = bug.character_name;
e["reporter_spoof"] = bug.reporter_spoof;
e["category_id"] = bug.category_id;
e["category_name"] = bug.category_name;
e["reporter_name"] = bug.reporter_name;
e["ui_path"] = bug.ui_path;
e["pos_x"] = bug.pos_x;
e["pos_y"] = bug.pos_y;
e["pos_z"] = bug.pos_z;
e["heading"] = bug.heading;
e["time_played"] = bug.time_played;
e["target_id"] = bug.target_id;
e["target_name"] = bug.target_name;
e["optional_info_mask"] = bug.optional_info_mask;
e["_can_duplicate"] = bug._can_duplicate;
e["_crash_bug"] = bug._crash_bug;
e["_target_info"] = bug._target_info;
e["_character_flags"] = bug._character_flags;
e["_unknown_value"] = bug._unknown_value;
e["bug_report"] = bug.bug_report;
e["system_info"] = bug.system_info;
e.push(L);
if (lua_pcall(L, 1, 1, 0)) {
std::string error = lua_tostring(L, -1);
parser_->AddError(error);
lua_pop(L, 2);
return;
}
if (lua_type(L, -1) == LUA_TTABLE) {
luabind::adl::object ret(luabind::from_stack(L, -1));
auto ignore_default_obj = ret["ignore_default"];
if (luabind::type(ignore_default_obj) == LUA_TBOOLEAN) {
ignore_default = ignore_default || luabind::object_cast<bool>(ignore_default_obj);
}
}
}
catch (std::exception &ex) {
parser_->AddError(ex.what());
}
int end = lua_gettop(L);
int n = end - start;
if (n > 0) {
lua_pop(L, n);
}
}
#endif

View File

@ -1,6 +1,7 @@
#pragma once
#include <string>
#include "../common/repositories/bug_reports_repository.h"
struct lua_State;
@ -27,6 +28,7 @@ public:
void GetEXPForLevel(Client *self, uint16 level, uint32 &returnValue, bool &ignoreDefault);
void GetExperienceForKill(Client *self, Mob *against, uint64 &returnValue, bool &ignoreDefault);
void CalcSpellEffectValue_formula(Mob *self, uint32 formula, int64 base_value, int64 max_value, int caster_level, uint16 spell_id, int ticsremaining, int64 &returnValue, bool &ignoreDefault);
void RegisterBug(Client *self, BaseBugReportsRepository::BugReports bug, bool &ignore_default);
private:
LuaParser *parser_;
lua_State *L;
@ -42,4 +44,5 @@ private:
bool m_has_get_exp_for_level;
bool m_has_get_experience_for_kill;
bool m_has_calc_spell_effect_value_formula;
bool m_has_register_bug;
};

View File

@ -1588,6 +1588,13 @@ int64 LuaParser::CalcSpellEffectValue_formula(Mob *self, uint32 formula, int64 b
return retval;
}
void LuaParser::RegisterBug(Client *self, BaseBugReportsRepository::BugReports bug, bool &ignore_default)
{
for (auto &mod : mods_) {
mod.RegisterBug(self, bug, ignore_default);
}
}
int LuaParser::EventBot(
QuestEventID evt,
Bot *bot,

View File

@ -12,6 +12,8 @@
#include "zone_config.h"
#include "lua_mod.h"
#include "../common/repositories/bug_reports_repository.h"
extern const ZoneConfig *Config;
struct lua_State;
@ -196,7 +198,8 @@ public:
uint32 GetEXPForLevel(Client *self, uint16 level, bool &ignoreDefault);
uint64 GetExperienceForKill(Client *self, Mob *against, bool &ignoreDefault);
int64 CalcSpellEffectValue_formula(Mob *self, uint32 formula, int64 base_value, int64 max_value, int caster_level, uint16 spell_id, int ticsremaining, bool &ignoreDefault);
void RegisterBug(Client *self, BaseBugReportsRepository::BugReports bug, bool &ignore_default);
private:
LuaParser();
LuaParser(const LuaParser&);