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

Prevent multiples crash cases in several methods #3562

Merged
merged 1 commit into from
Aug 15, 2021
Merged
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
69 changes: 68 additions & 1 deletion src/luascript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7259,6 +7259,12 @@ int LuaScriptInterface::luaCreatureCanSeeCreature(lua_State* L)
const Creature* creature = getUserdata<const Creature>(L, 1);
if (creature) {
const Creature* otherCreature = getCreature(L, 2);
if (!otherCreature) {
reportErrorFunc(L, getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND));
pushBoolean(L, false);
return 1;
}

pushBoolean(L, creature->canSeeCreature(otherCreature));
} else {
lua_pushnil(L);
Expand Down Expand Up @@ -7334,6 +7340,12 @@ int LuaScriptInterface::luaCreatureSetTarget(lua_State* L)
Creature* creature = getUserdata<Creature>(L, 1);
if (creature) {
Creature* target = getCreature(L, 2);
if (!target) {
reportErrorFunc(L, getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND));
pushBoolean(L, false);
return 1;
}

pushBoolean(L, creature->setAttackedCreature(target));
} else {
lua_pushnil(L);
Expand Down Expand Up @@ -7366,6 +7378,12 @@ int LuaScriptInterface::luaCreatureSetFollowCreature(lua_State* L)
Creature* creature = getUserdata<Creature>(L, 1);
if (creature) {
Creature* followCreature = getCreature(L, 2);
if (!followCreature) {
reportErrorFunc(L, getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND));
pushBoolean(L, false);
return 1;
}

pushBoolean(L, creature->setFollowCreature(followCreature));
} else {
lua_pushnil(L);
Expand Down Expand Up @@ -10275,6 +10293,12 @@ int LuaScriptInterface::luaMonsterIsTarget(lua_State* L)
Monster* monster = getUserdata<Monster>(L, 1);
if (monster) {
const Creature* creature = getCreature(L, 2);
if (!creature) {
reportErrorFunc(L, getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND));
pushBoolean(L, false);
return 1;
}

pushBoolean(L, monster->isTarget(creature));
} else {
lua_pushnil(L);
Expand All @@ -10288,6 +10312,12 @@ int LuaScriptInterface::luaMonsterIsOpponent(lua_State* L)
Monster* monster = getUserdata<Monster>(L, 1);
if (monster) {
const Creature* creature = getCreature(L, 2);
if (!creature) {
reportErrorFunc(L, getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND));
pushBoolean(L, false);
return 1;
}

pushBoolean(L, monster->isOpponent(creature));
} else {
lua_pushnil(L);
Expand All @@ -10301,6 +10331,12 @@ int LuaScriptInterface::luaMonsterIsFriend(lua_State* L)
Monster* monster = getUserdata<Monster>(L, 1);
if (monster) {
const Creature* creature = getCreature(L, 2);
if (!creature) {
reportErrorFunc(L, getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND));
pushBoolean(L, false);
return 1;
}

pushBoolean(L, monster->isFriend(creature));
} else {
lua_pushnil(L);
Expand All @@ -10314,6 +10350,12 @@ int LuaScriptInterface::luaMonsterAddFriend(lua_State* L)
Monster* monster = getUserdata<Monster>(L, 1);
if (monster) {
Creature* creature = getCreature(L, 2);
if (!creature) {
reportErrorFunc(L, getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND));
pushBoolean(L, false);
return 1;
}

monster->addFriend(creature);
pushBoolean(L, true);
} else {
Expand All @@ -10328,6 +10370,12 @@ int LuaScriptInterface::luaMonsterRemoveFriend(lua_State* L)
Monster* monster = getUserdata<Monster>(L, 1);
if (monster) {
Creature* creature = getCreature(L, 2);
if (!creature) {
reportErrorFunc(L, getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND));
pushBoolean(L, false);
return 1;
}

monster->removeFriend(creature);
pushBoolean(L, true);
} else {
Expand Down Expand Up @@ -10379,6 +10427,12 @@ int LuaScriptInterface::luaMonsterAddTarget(lua_State* L)
}

Creature* creature = getCreature(L, 2);
if (!creature) {
reportErrorFunc(L, getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND));
pushBoolean(L, false);
return 1;
}

bool pushFront = getBoolean(L, 3, false);
monster->addTarget(creature, pushFront);
pushBoolean(L, true);
Expand All @@ -10394,7 +10448,14 @@ int LuaScriptInterface::luaMonsterRemoveTarget(lua_State* L)
return 1;
}

monster->removeTarget(getCreature(L, 2));
Creature* creature = getCreature(L, 2);
if (!creature) {
reportErrorFunc(L, getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND));
pushBoolean(L, false);
return 1;
}

monster->removeTarget(creature);
pushBoolean(L, true);
return 1;
}
Expand Down Expand Up @@ -10438,6 +10499,12 @@ int LuaScriptInterface::luaMonsterSelectTarget(lua_State* L)
Monster* monster = getUserdata<Monster>(L, 1);
if (monster) {
Creature* creature = getCreature(L, 2);
if (!creature) {
reportErrorFunc(L, getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND));
pushBoolean(L, false);
return 1;
}

pushBoolean(L, monster->selectTarget(creature));
} else {
lua_pushnil(L);
Expand Down