forked from tspivey/yugioh-game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathduel_build.py
73 lines (72 loc) · 2.34 KB
/
duel_build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from cffi import FFI
ffibuilder = FFI()
ffibuilder.set_source("_duel",
r"""
#include "ocgapi.h"
#include "card.h"
#include <vector>
int32 is_declarable(card_data const& cd, const std::vector<uint32>& opcode);
int32 declarable(card_data *cd, int32 size, uint32 *array) {
std::vector<uint32> v;
for (int i=0; i < size; i++) {
v.push_back(array[i]);
}
return is_declarable(*cd, v);
}
""",
libraries = ['ygo'],
library_dirs=['.'],
source_extension='.cpp',
include_dirs=['../ygopro-core'],
extra_compile_args=['-std=c++0x'],
extra_link_args=['-Wl,-rpath,.'],
)
ffibuilder.cdef("""
typedef long ptr;
typedef uint32_t uint32;
typedef int32_t int32;
typedef uint8_t uint8;
typedef int32_t int32;
typedef uint8_t byte;
typedef uint64_t uint64;
struct card_data {
uint32 code;
uint32 alias;
uint64 setcode;
uint32 type;
uint32 level;
uint32 attribute;
uint32 race;
int32 attack;
int32 defense;
uint32 lscale;
uint32 rscale;
uint32 link_marker;
...;
};
extern "Python" uint32 card_reader_callback(uint32, struct card_data *);
typedef uint32 (*card_reader)(uint32, struct card_data*);
void set_card_reader(card_reader f);
typedef byte* (*script_reader)(const char*, int*);
typedef uint32 (*message_handler)(void*, uint32);
extern "Python" uint32 message_handler_callback (void *, int32);
void set_message_handler(message_handler f);
extern "Python" byte *script_reader_callback(const char *, int *);
void set_script_reader(script_reader f);
ptr create_duel(uint32_t seed);
void start_duel(ptr pduel, int32 options);
void end_duel(ptr pduel);
void get_log_message(ptr pduel, byte* buf);
int32 get_message(ptr pduel, byte* buf);
int32 process(ptr pduel);
void new_card(ptr pduel, uint32 code, uint8 owner, uint8 playerid, uint8 location, uint8 sequence, uint8 position);
void set_player_info(ptr pduel, int32 playerid, int32 lp, int32 startcount, int32 drawcount);
void set_responsei(ptr pduel, int32 value);
void set_responseb(ptr pduel, byte *value);
int32 query_card(ptr pduel, uint8 playerid, uint8 location, uint8 sequence, int32 query_flag, byte* buf, int32 use_cache);
int32 query_field_count(ptr pduel, uint8 playerid, uint8 location);
int32 query_field_card(ptr pduel, uint8 playerid, uint8 location, int32 query_flag, byte* buf, int32 use_cache);
int32 declarable(struct card_data *cd, int32 size, uint32 *array);
""")
if __name__ == "__main__":
ffibuilder.compile(verbose=True)