Commit 16a4f5cb authored by nanahira's avatar nanahira

Merge branch 'master' of github.com:moecube/ygopro-core

parents 9fd65875 31785ae6
...@@ -30,7 +30,6 @@ typedef signed char int8; ...@@ -30,7 +30,6 @@ typedef signed char int8;
#define TRUE 1 #define TRUE 1
#define FALSE 0 #define FALSE 0
#define SIZE_MESSAGE_BUFFER 0x2000 #define SIZE_MESSAGE_BUFFER 0x2000
#define SIZE_QUERY_BUFFER 0x4000
#define PROCESSOR_BUFFER_LEN 0x0fffffff #define PROCESSOR_BUFFER_LEN 0x0fffffff
#define PROCESSOR_FLAG 0xf0000000 #define PROCESSOR_FLAG 0xf0000000
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
* Author: Argon * Author: Argon
*/ */
#include <cstring>
#include "duel.h" #include "duel.h"
#include "interpreter.h" #include "interpreter.h"
#include "field.h" #include "field.h"
...@@ -13,6 +14,14 @@ ...@@ -13,6 +14,14 @@
#include "group.h" #include "group.h"
#include "ocgapi.h" #include "ocgapi.h"
inline void write_buffer_vector(std::vector<byte>& buffer, const void* data, int size) {
if (size > 0) {
const auto len = buffer.size();
buffer.resize(len + size);
std::memcpy(&buffer[len], data, size);
}
}
duel::duel() { duel::duel() {
lua = new interpreter(this); lua = new interpreter(this);
game_field = new field(this); game_field = new field(this);
......
...@@ -20,14 +20,6 @@ class effect; ...@@ -20,14 +20,6 @@ class effect;
class field; class field;
class interpreter; class interpreter;
inline void write_buffer_vector(std::vector<byte>& buffer, const void* data, int size) {
if (size > 0) {
const auto len = buffer.size();
buffer.resize(len + size);
std::memcpy(&buffer[len], data, size);
}
}
class duel { class duel {
public: public:
using card_set = std::set<card*, card_sort>; using card_set = std::set<card*, card_sort>;
......
...@@ -27,43 +27,8 @@ bool is_continuous_event(uint32 code) { ...@@ -27,43 +27,8 @@ bool is_continuous_event(uint32 code) {
} }
effect::effect(duel* pd) { effect::effect(duel* pd) {
ref_handle = 0;
pduel = pd; pduel = pd;
owner = 0;
handler = 0;
description = 0;
effect_owner = PLAYER_NONE;
card_type = 0;
active_type = 0;
active_location = 0;
active_sequence = 0;
active_handler = 0;
id = 0;
code = 0;
type = 0;
flag[0] = 0;
flag[1] = 0;
copy_id = 0;
range = 0;
s_range = 0;
o_range = 0;
count_limit = 0;
count_limit_max = 0;
reset_count = 0;
reset_flag = 0;
count_code = 0;
category = 0;
label.reserve(4); label.reserve(4);
label_object = 0;
hint_timing[0] = 0;
hint_timing[1] = 0;
status = 0;
condition = 0;
cost = 0;
target = 0;
value = 0;
operation = 0;
cost_checked = FALSE;
} }
int32 effect::is_disable_related() { int32 effect::is_disable_related() {
if (code == EFFECT_IMMUNE_EFFECT || code == EFFECT_DISABLE || code == EFFECT_CANNOT_DISABLE || code == EFFECT_FORBIDDEN) if (code == EFFECT_IMMUNE_EFFECT || code == EFFECT_DISABLE || code == EFFECT_CANNOT_DISABLE || code == EFFECT_FORBIDDEN)
......
...@@ -27,41 +27,41 @@ enum effect_flag2 : uint32; ...@@ -27,41 +27,41 @@ enum effect_flag2 : uint32;
class effect { class effect {
public: public:
int32 ref_handle; int32 ref_handle{ 0 };
duel* pduel; duel* pduel{ nullptr };
card* owner; card* owner{ nullptr };
card* handler; card* handler{ nullptr };
uint8 effect_owner; uint8 effect_owner{ PLAYER_NONE };
uint32 description; uint32 description{ 0 };
uint32 code; uint32 code{ 0 };
uint32 flag[2]; uint32 flag[2]{ 0 };
uint32 id; uint32 id{ 0 };
uint16 type; uint16 type{ 0 };
uint16 copy_id; uint16 copy_id{ 0 };
uint16 range; uint16 range{ 0 };
uint16 s_range; uint16 s_range{ 0 };
uint16 o_range; uint16 o_range{ 0 };
uint8 count_limit; uint8 count_limit{ 0 };
uint8 count_limit_max; uint8 count_limit_max{ 0 };
uint16 reset_count; uint16 reset_count{ 0 };
uint32 reset_flag; uint32 reset_flag{ 0 };
uint32 count_code; uint32 count_code{ 0 };
uint32 category; uint32 category{ 0 };
uint32 hint_timing[2]; uint32 hint_timing[2]{ 0 };
uint32 card_type; uint32 card_type{ 0 };
uint32 active_type; uint32 active_type{ 0 };
uint16 active_location; uint16 active_location{ 0 };
uint16 active_sequence; uint16 active_sequence{ 0 };
card* active_handler; card* active_handler{ nullptr };
uint16 status; uint16 status{ 0 };
std::vector<uint32> label; std::vector<uint32> label;
int32 label_object; int32 label_object{ 0 };
int32 condition; int32 condition{ 0 };
int32 cost; int32 cost{ 0 };
int32 target; int32 target{ 0 };
int32 value; int32 value{ 0 };
int32 operation; int32 operation{ 0 };
uint8 cost_checked; uint8 cost_checked{ FALSE };
explicit effect(duel* pd); explicit effect(duel* pd);
~effect() = default; ~effect() = default;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
* Author: Argon * Author: Argon
*/ */
#include <cstring>
#include "duel.h" #include "duel.h"
#include "group.h" #include "group.h"
#include "card.h" #include "card.h"
...@@ -17,7 +18,7 @@ interpreter::interpreter(duel* pd): coroutines(256) { ...@@ -17,7 +18,7 @@ interpreter::interpreter(duel* pd): coroutines(256) {
lua_state = luaL_newstate(); lua_state = luaL_newstate();
current_state = lua_state; current_state = lua_state;
pduel = pd; pduel = pd;
memcpy(lua_getextraspace(lua_state), &pd, LUA_EXTRASPACE); //set_duel_info std::memcpy(lua_getextraspace(lua_state), &pd, LUA_EXTRASPACE); //set_duel_info
no_action = 0; no_action = 0;
call_depth = 0; call_depth = 0;
disable_action_check = 0; disable_action_check = 0;
...@@ -758,6 +759,6 @@ int32 interpreter::get_function_handle(lua_State* L, int32 index) { ...@@ -758,6 +759,6 @@ int32 interpreter::get_function_handle(lua_State* L, int32 index) {
} }
duel* interpreter::get_duel_info(lua_State * L) { duel* interpreter::get_duel_info(lua_State * L) {
duel* pduel; duel* pduel;
memcpy(&pduel, lua_getextraspace(L), LUA_EXTRASPACE); std::memcpy(&pduel, lua_getextraspace(L), LUA_EXTRASPACE);
return pduel; return pduel;
} }
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#include <list> #include <list>
#include <vector> #include <vector>
#include <cstdio> #include <cstdio>
#include <cstring>
class card; class card;
class effect; class effect;
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* Author: Argon * Author: Argon
*/ */
#include <string.h> #include <cstring>
#include "scriptlib.h" #include "scriptlib.h"
#include "duel.h" #include "duel.h"
#include "field.h" #include "field.h"
...@@ -177,7 +177,7 @@ int32 scriptlib::debug_set_ai_name(lua_State *L) { ...@@ -177,7 +177,7 @@ int32 scriptlib::debug_set_ai_name(lua_State *L) {
duel* pduel = interpreter::get_duel_info(L); duel* pduel = interpreter::get_duel_info(L);
pduel->write_buffer8(MSG_AI_NAME); pduel->write_buffer8(MSG_AI_NAME);
const char* pstr = lua_tostring(L, 1); const char* pstr = lua_tostring(L, 1);
int len = (int)strlen(pstr); int len = (int)std::strlen(pstr);
if(len > 100) if(len > 100)
len = 100; len = 100;
pduel->write_buffer16(len); pduel->write_buffer16(len);
...@@ -193,7 +193,7 @@ int32 scriptlib::debug_show_hint(lua_State *L) { ...@@ -193,7 +193,7 @@ int32 scriptlib::debug_show_hint(lua_State *L) {
duel* pduel = interpreter::get_duel_info(L); duel* pduel = interpreter::get_duel_info(L);
pduel->write_buffer8(MSG_SHOW_HINT); pduel->write_buffer8(MSG_SHOW_HINT);
const char* pstr = lua_tostring(L, 1); const char* pstr = lua_tostring(L, 1);
int len = (int)strlen(pstr); int len = (int)std::strlen(pstr);
if(len > 1024) if(len > 1024)
len = 1024; len = 1024;
pduel->write_buffer16(len); pduel->write_buffer16(len);
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#ifndef MTRANDOM_H_ #ifndef MTRANDOM_H_
#define MTRANDOM_H_ #define MTRANDOM_H_
#include <cstdint>
#include <random> #include <random>
class mt19937 { class mt19937 {
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
* Created on: 2010-5-2 * Created on: 2010-5-2
* Author: Argon * Author: Argon
*/ */
#include <stdio.h> #include <cstdio>
#include <string.h> #include <cstring>
#include "ocgapi.h" #include "ocgapi.h"
#include "duel.h" #include "duel.h"
#include "card.h" #include "card.h"
...@@ -41,11 +41,11 @@ uint32 handle_message(void* pduel, uint32 msg_type) { ...@@ -41,11 +41,11 @@ uint32 handle_message(void* pduel, uint32 msg_type) {
} }
byte* default_script_reader(const char* script_name, int* slen) { byte* default_script_reader(const char* script_name, int* slen) {
FILE *fp; FILE *fp;
fp = fopen(script_name, "rb"); fp = std::fopen(script_name, "rb");
if (!fp) if (!fp)
return 0; return 0;
int len = (int)fread(buffer, 1, sizeof(buffer), fp); int len = (int)fread(buffer, 1, sizeof(buffer), fp);
fclose(fp); std::fclose(fp);
if(len >= sizeof(buffer)) if(len >= sizeof(buffer))
return 0; return 0;
*slen = len; *slen = len;
...@@ -121,7 +121,7 @@ extern "C" DECL_DLLEXPORT void set_player_info(intptr_t pduel, int32 playerid, i ...@@ -121,7 +121,7 @@ extern "C" DECL_DLLEXPORT void set_player_info(intptr_t pduel, int32 playerid, i
pd->game_field->player[playerid].draw_count = drawcount; pd->game_field->player[playerid].draw_count = drawcount;
} }
extern "C" DECL_DLLEXPORT void get_log_message(intptr_t pduel, byte* buf) { extern "C" DECL_DLLEXPORT void get_log_message(intptr_t pduel, byte* buf) {
strcpy((char*)buf, ((duel*)pduel)->strbuffer); std::strcpy((char*)buf, ((duel*)pduel)->strbuffer);
} }
extern "C" DECL_DLLEXPORT int32 get_message(intptr_t pduel, byte* buf) { extern "C" DECL_DLLEXPORT int32 get_message(intptr_t pduel, byte* buf) {
int32 len = ((duel*)pduel)->read_buffer(buf); int32 len = ((duel*)pduel)->read_buffer(buf);
......
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