Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add RegisterBug LuaMod #4209

Merged
merged 6 commits into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions zone/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
71 changes: 71 additions & 0 deletions zone/lua_mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
3 changes: 3 additions & 0 deletions zone/lua_mod.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <string>
#include "../common/repositories/bug_reports_repository.h"

struct lua_State;

Expand All @@ -27,6 +28,7 @@ class LuaMod
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;
Expand All @@ -42,4 +44,5 @@ class LuaMod
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;
};
7 changes: 7 additions & 0 deletions zone/lua_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1586,6 +1586,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,
Expand Down
5 changes: 4 additions & 1 deletion zone/lua_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -196,7 +198,8 @@ class LuaParser : public QuestInterface {
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&);
Expand Down