From 6960a1a68243d813b10b1b1dd74c16446953cead Mon Sep 17 00:00:00 2001 From: Alex King <89047260+Kinglykrab@users.noreply.github.com> Date: Thu, 30 Mar 2023 06:02:53 -0400 Subject: [PATCH] [Bug Fix] Fix issues with Lua tables not starting at index 1 (#3160) * [Bug Fix] Fix issues with Lua tables not starting at index 1 # Notes - This would cause the first item in the table to be inaccessible since Lua tables start at index `1` instead of index `0`. - All other spots using Lua tables have their indexes starting at `1`. * Update lua_general.cpp --- zone/lua_client.cpp | 4 ++-- zone/lua_general.cpp | 6 +++--- zone/lua_mob.cpp | 2 +- zone/lua_object.cpp | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/zone/lua_client.cpp b/zone/lua_client.cpp index 1540bceb4..f24c04f12 100644 --- a/zone/lua_client.cpp +++ b/zone/lua_client.cpp @@ -2828,7 +2828,7 @@ luabind::object Lua_Client::GetPEQZoneFlags(lua_State* L) { if (d_) { auto self = reinterpret_cast(d_); auto l = self->GetPEQZoneFlags(); - auto i = 0; + auto i = 1; for (const auto& f : l) { t[i] = f; i++; @@ -2843,7 +2843,7 @@ luabind::object Lua_Client::GetZoneFlags(lua_State* L) { if (d_) { auto self = reinterpret_cast(d_); auto l = self->GetZoneFlags(); - auto i = 0; + auto i = 1; for (const auto& f : l) { t[i] = f; i++; diff --git a/zone/lua_general.cpp b/zone/lua_general.cpp index 366195e2e..7208ae30f 100644 --- a/zone/lua_general.cpp +++ b/zone/lua_general.cpp @@ -1017,7 +1017,7 @@ luabind::adl::object lua_get_instance_ids(lua_State* L, std::string zone_name) { auto instance_ids = quest_manager.GetInstanceIDs(zone_name); for (int i = 0; i < instance_ids.size(); i++) { - ret[i] = instance_ids[i]; + ret[i + 1] = instance_ids[i]; } return ret; @@ -1028,7 +1028,7 @@ luabind::adl::object lua_get_instance_ids_by_char_id(lua_State* L, std::string z auto instance_ids = quest_manager.GetInstanceIDs(zone_name, character_id); for (int i = 0; i < instance_ids.size(); i++) { - ret[i] = instance_ids[i]; + ret[i + 1] = instance_ids[i]; } return ret; @@ -4182,7 +4182,7 @@ luabind::scope lua_register_general() { luabind::def("get_instance_id", &lua_get_instance_id), luabind::def("get_instance_id_by_char_id", &lua_get_instance_id_by_char_id), luabind::def("get_instance_ids", &lua_get_instance_ids), - luabind::def("get_instance_ids_by_char_id", &lua_get_instance_id_by_char_id), + luabind::def("get_instance_ids_by_char_id", &lua_get_instance_ids_by_char_id), luabind::def("get_instance_timer", &lua_get_instance_timer), luabind::def("get_instance_timer_by_id", &lua_get_instance_timer_by_id), luabind::def("get_instance_version_by_id", &lua_get_instance_version_by_id), diff --git a/zone/lua_mob.cpp b/zone/lua_mob.cpp index 3fff021d6..1720776d1 100644 --- a/zone/lua_mob.cpp +++ b/zone/lua_mob.cpp @@ -2709,7 +2709,7 @@ luabind::object Lua_Mob::GetEntityVariables(lua_State* L) { if (d_) { auto self = reinterpret_cast(d_); auto l = self->GetEntityVariables(); - auto i = 0; + auto i = 1; for (const auto& v : l) { t[i] = v; i++; diff --git a/zone/lua_object.cpp b/zone/lua_object.cpp index d5870a800..6ebae11f3 100644 --- a/zone/lua_object.cpp +++ b/zone/lua_object.cpp @@ -173,7 +173,7 @@ luabind::object Lua_Object::GetEntityVariables(lua_State* L) { if (d_) { auto self = reinterpret_cast(d_); auto l = self->GetEntityVariables(); - auto i = 0; + auto i = 1; for (const auto& v : l) { t[i] = v; i++;