Commit 31ef3c26 authored by nanahira's avatar nanahira

Merge branch 'master' of github.com:Fluorohydride/ygopro-core into develop

parents e883e2d8 1bde2fb4
......@@ -504,11 +504,6 @@ uint32_t card::get_another_code() {
return otcode;
return 0;
}
inline bool check_setcode(uint16_t setcode, uint32_t value) {
const uint32_t settype = value & 0x0fffU;
const uint32_t setsubtype = value & 0xf000U;
return (setcode & 0x0fffU) == settype && (setcode & setsubtype) == setsubtype;
}
int32_t card::is_set_card(uint32_t set_code) {
uint32_t code1 = get_code();
card_data dat1;
......
......@@ -24,6 +24,33 @@ const std::unordered_map<uint32_t, uint32_t> second_code = {
{CARD_HERMOS, 10000070u},
};
inline bool check_setcode(uint16_t setcode, uint32_t value) {
const uint32_t settype = value & 0x0fffU;
const uint32_t setsubtype = value & 0xf000U;
return setcode && (setcode & 0x0fffU) == settype && (setcode & setsubtype) == setsubtype;
}
inline void write_setcode(uint16_t list[], uint64_t value) {
if (!list)
return;
int len = 0;
while (value) {
if (value & 0xffff) {
list[len] = value & 0xffff;
++len;
}
value >>= 16;
}
if (len < SIZE_SETCODE)
std::memset(list + len, 0, (SIZE_SETCODE - len) * sizeof(uint16_t));
}
inline bool is_alternative(uint32_t code, uint32_t alias) {
if (code == CARD_BLACK_LUSTER_SOLDIER2)
return false;
return alias && (alias < code + CARD_ARTWORK_VERSIONS_OFFSET) && (code < alias + CARD_ARTWORK_VERSIONS_OFFSET);
}
struct card_data {
uint32_t code{};
uint32_t alias{};
......@@ -43,38 +70,17 @@ struct card_data {
}
bool is_setcode(uint32_t value) const {
const uint16_t settype = value & 0x0fff;
const uint16_t setsubtype = value & 0xf000;
for (auto& x : setcode) {
if ((x & 0x0fff) == settype && (x & setsubtype) == setsubtype)
return true;
if (!x)
return false;
if (check_setcode(x, value))
return true;
}
return false;
}
bool is_alternative() const {
if (code == CARD_BLACK_LUSTER_SOLDIER2)
return false;
return alias && (alias < code + CARD_ARTWORK_VERSIONS_OFFSET) && (code < alias + CARD_ARTWORK_VERSIONS_OFFSET);
}
void set_setcode(uint64_t value) {
int ctr = 0;
while (value) {
if (value & 0xffff) {
setcode[ctr] = value & 0xffff;
++ctr;
}
value >>= 16;
}
if (ctr < SIZE_SETCODE)
std::memset(setcode + ctr, 0, (SIZE_SETCODE - ctr) * sizeof(uint16_t));
}
uint32_t get_original_code() const {
return is_alternative() ? alias : code;
return is_alternative(code, alias) ? alias : code;
}
};
......
......@@ -16,7 +16,7 @@
#include "buffer.h"
duel::duel() {
lua = new interpreter(this);
lua = new interpreter(this, false);
game_field = new field(this);
game_field->temp_card = new_card(TEMP_CARD_ID);
game_field->rose_card = 0;
......
......@@ -14,7 +14,7 @@
#include "ocgapi.h"
#include "interpreter.h"
interpreter::interpreter(duel* pd): coroutines(256) {
interpreter::interpreter(duel* pd, bool enable_unsafe_libraries): coroutines(256) {
mem_tracker = new LuaMemTracker(YGOPRO_LUA_MEMORY_SIZE);
lua_state = lua_newstate(LuaMemTracker::AllocThunk, mem_tracker);
current_state = lua_state;
......@@ -39,6 +39,20 @@ interpreter::interpreter(duel* pd): coroutines(256) {
lua_pop(lua_state, 1);
luaL_requiref(lua_state, "coroutine", luaopen_coroutine, 1);
lua_pop(lua_state, 1);
if (enable_unsafe_libraries) {
luaL_requiref(lua_state, "io", luaopen_io, 1);
lua_pop(lua_state, 1);
}
auto nil_out = [&](const char* name) {
lua_pushnil(lua_state);
lua_setglobal(lua_state, name);
};
nil_out("collectgarbage");
if (!enable_unsafe_libraries) {
nil_out("dofile");
nil_out("loadfile");
}
#endif
//open all libs
......
......@@ -57,7 +57,7 @@ public:
int32_t preloaded;
LuaMemTracker* mem_tracker = nullptr;
explicit interpreter(duel* pd);
explicit interpreter(duel* pd, bool enable_unsafe_libraries);
~interpreter();
void register_card(card* pcard);
......
......@@ -4839,7 +4839,7 @@ int32_t scriptlib::duel_is_player_can_spsummon_monster(lua_State * L) {
dat.code = code;
dat.alias = 0;
if(lua_gettop(L) >= 3 && !lua_isnil(L, 3))
dat.set_setcode((uint64_t)lua_tointeger(L, 3));
write_setcode(dat.setcode, lua_tointeger(L, 3));
if(lua_gettop(L) >= 4 && !lua_isnil(L, 4))
dat.type = (uint32_t)lua_tointeger(L, 4);
if(lua_gettop(L) >= 5 && !lua_isnil(L, 5))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment