Commit 03b59cd0 authored by 神楽坂玲奈's avatar 神楽坂玲奈

use intptr_t

parent 1f6e9845
......@@ -57,13 +57,14 @@ uint32 default_card_reader(uint32 code, card_data* data) {
uint32 default_message_handler(void* pduel, uint32 message_type) {
return 0;
}
extern "C" DECL_DLLEXPORT duel* create_duel(uint32 seed) {
extern "C" DECL_DLLEXPORT intptr_t create_duel(uint32 seed) {
duel* pduel = new duel();
duel_set.insert(pduel);
pduel->random.reset(seed);
return pduel;
return (intptr_t)pduel;
}
extern "C" DECL_DLLEXPORT void start_duel(duel* pd, int32 options) {
extern "C" DECL_DLLEXPORT void start_duel(intptr_t pduel, int32 options) {
duel* pd = (duel*)pduel;
pd->game_field->core.duel_options |= options & 0xffff;
int32 duel_rule = options >> 16;
if(duel_rule)
......@@ -102,13 +103,15 @@ extern "C" DECL_DLLEXPORT void start_duel(duel* pd, int32 options) {
}
pd->game_field->add_process(PROCESSOR_TURN, 0, 0, 0, 0, 0);
}
extern "C" DECL_DLLEXPORT void end_duel(duel* pd) {
extern "C" DECL_DLLEXPORT void end_duel(intptr_t pduel) {
duel* pd = (duel*)pduel;
if(duel_set.count(pd)) {
duel_set.erase(pd);
delete pd;
}
}
extern "C" DECL_DLLEXPORT void set_player_info(duel* pd, int32 playerid, int32 lp, int32 startcount, int32 drawcount) {
extern "C" DECL_DLLEXPORT void set_player_info(intptr_t pduel, int32 playerid, int32 lp, int32 startcount, int32 drawcount) {
duel* pd = (duel*)pduel;
if(lp > 0)
pd->game_field->player[playerid].lp = lp;
if(startcount >= 0)
......@@ -116,21 +119,23 @@ extern "C" DECL_DLLEXPORT void set_player_info(duel* pd, int32 playerid, int32 l
if(drawcount >= 0)
pd->game_field->player[playerid].draw_count = drawcount;
}
extern "C" DECL_DLLEXPORT void get_log_message(duel* pduel, byte* buf) {
strcpy((char*)buf, pduel->strbuffer);
extern "C" DECL_DLLEXPORT void get_log_message(intptr_t pduel, byte* buf) {
strcpy((char*)buf, ((duel*)pduel)->strbuffer);
}
extern "C" DECL_DLLEXPORT int32 get_message(duel* pduel, byte* buf) {
int32 len = pduel->read_buffer(buf);
pduel->clear_buffer();
extern "C" DECL_DLLEXPORT int32 get_message(intptr_t pduel, byte* buf) {
int32 len = ((duel*)pduel)->read_buffer(buf);
((duel*)pduel)->clear_buffer();
return len;
}
extern "C" DECL_DLLEXPORT int32 process(duel* pd) {
extern "C" DECL_DLLEXPORT int32 process(intptr_t pduel) {
duel* pd = (duel*)pduel;
int result = pd->game_field->process();
while((result & 0xffff) == 0 && (result & 0xf0000) == 0)
result = pd->game_field->process();
return result;
}
extern "C" DECL_DLLEXPORT void new_card(duel* ptduel, uint32 code, uint8 owner, uint8 playerid, uint8 location, uint8 sequence, uint8 position) {
extern "C" DECL_DLLEXPORT void new_card(intptr_t pduel, uint32 code, uint8 owner, uint8 playerid, uint8 location, uint8 sequence, uint8 position) {
duel* ptduel = (duel*)pduel;
if(ptduel->game_field->is_location_useable(playerid, location, sequence)) {
card* pcard = ptduel->new_card(code);
pcard->owner = owner;
......@@ -146,7 +151,8 @@ extern "C" DECL_DLLEXPORT void new_card(duel* ptduel, uint32 code, uint8 owner,
}
}
}
extern "C" DECL_DLLEXPORT void new_tag_card(duel* ptduel, uint32 code, uint8 owner, uint8 location) {
extern "C" DECL_DLLEXPORT void new_tag_card(intptr_t pduel, uint32 code, uint8 owner, uint8 location) {
duel* ptduel = (duel*)pduel;
if(owner > 1 || !(location & (LOCATION_DECK | LOCATION_EXTRA)))
return;
card* pcard = ptduel->new_card(code);
......@@ -169,9 +175,10 @@ extern "C" DECL_DLLEXPORT void new_tag_card(duel* ptduel, uint32 code, uint8 own
break;
}
}
extern "C" DECL_DLLEXPORT int32 query_card(duel* ptduel, uint8 playerid, uint8 location, uint8 sequence, int32 query_flag, byte* buf, int32 use_cache) {
extern "C" DECL_DLLEXPORT int32 query_card(intptr_t pduel, uint8 playerid, uint8 location, uint8 sequence, int32 query_flag, byte* buf, int32 use_cache) {
if(playerid != 0 && playerid != 1)
return 0;
duel* ptduel = (duel*)pduel;
card* pcard = 0;
location &= 0x7f;
if(location & LOCATION_ONFIELD)
......@@ -201,7 +208,8 @@ extern "C" DECL_DLLEXPORT int32 query_card(duel* ptduel, uint8 playerid, uint8 l
return 4;
}
}
extern "C" DECL_DLLEXPORT int32 query_field_count(duel* ptduel, uint8 playerid, uint8 location) {
extern "C" DECL_DLLEXPORT int32 query_field_count(intptr_t pduel, uint8 playerid, uint8 location) {
duel* ptduel = (duel*)pduel;
if(playerid != 0 && playerid != 1)
return 0;
auto& player = ptduel->game_field->player[playerid];
......@@ -229,9 +237,10 @@ extern "C" DECL_DLLEXPORT int32 query_field_count(duel* ptduel, uint8 playerid,
}
return 0;
}
extern "C" DECL_DLLEXPORT int32 query_field_card(duel* ptduel, uint8 playerid, uint8 location, int32 query_flag, byte* buf, int32 use_cache) {
extern "C" DECL_DLLEXPORT int32 query_field_card(intptr_t pduel, uint8 playerid, uint8 location, int32 query_flag, byte* buf, int32 use_cache) {
if(playerid != 0 && playerid != 1)
return 0;
duel* ptduel = (duel*)pduel;
auto& player = ptduel->game_field->player[playerid];
byte* p = buf;
if(location == LOCATION_MZONE) {
......@@ -275,7 +284,8 @@ extern "C" DECL_DLLEXPORT int32 query_field_card(duel* ptduel, uint8 playerid, u
}
return (int32)(p - buf);
}
extern "C" DECL_DLLEXPORT int32 query_field_info(duel* ptduel, byte* buf) {
extern "C" DECL_DLLEXPORT int32 query_field_info(intptr_t pduel, byte* buf) {
duel* ptduel = (duel*)pduel;
byte* p = buf;
*p++ = MSG_RELOAD_FIELD;
*p++ = ptduel->game_field->core.duel_rule;
......@@ -322,12 +332,12 @@ extern "C" DECL_DLLEXPORT int32 query_field_info(duel* ptduel, byte* buf) {
}
return (int32)(p - buf);
}
extern "C" DECL_DLLEXPORT void set_responsei(duel* pduel, int32 value) {
pduel->set_responsei(value);
extern "C" DECL_DLLEXPORT void set_responsei(intptr_t pduel, int32 value) {
((duel*)pduel)->set_responsei(value);
}
extern "C" DECL_DLLEXPORT void set_responseb(duel* pduel, byte* buf) {
pduel->set_responseb(buf);
extern "C" DECL_DLLEXPORT void set_responseb(intptr_t pduel, byte* buf) {
((duel*)pduel)->set_responseb(buf);
}
extern "C" DECL_DLLEXPORT int32 preload_script(duel* pduel, const char* script, int32 len) {
return pduel->lua->load_script(script);
extern "C" DECL_DLLEXPORT int32 preload_script(intptr_t pduel, const char* script, int32 len) {
return ((duel*)pduel)->lua->load_script(script);
}
......@@ -9,6 +9,8 @@
#define OCGAPI_H_
#include "common.h"
#include <cstdint>
#ifdef WIN32
#define DECL_DLLEXPORT __declspec(dllexport)
#else
......@@ -21,7 +23,6 @@ struct card_info;
class group;
class effect;
class interpreter;
class duel;
typedef byte* (*script_reader)(const char*, int*);
typedef uint32 (*card_reader)(uint32, card_data*);
......@@ -35,22 +36,22 @@ byte* read_script(const char* script_name, int* len);
uint32 read_card(uint32 code, card_data* data);
uint32 handle_message(void* pduel, uint32 message_type);
extern "C" DECL_DLLEXPORT duel* create_duel(uint32 seed);
extern "C" DECL_DLLEXPORT void start_duel(duel* pduel, int32 options);
extern "C" DECL_DLLEXPORT void end_duel(duel* pduel);
extern "C" DECL_DLLEXPORT void set_player_info(duel* pduel, int32 playerid, int32 lp, int32 startcount, int32 drawcount);
extern "C" DECL_DLLEXPORT void get_log_message(duel* pduel, byte* buf);
extern "C" DECL_DLLEXPORT int32 get_message(duel* pduel, byte* buf);
extern "C" DECL_DLLEXPORT int32 process(duel* pduel);
extern "C" DECL_DLLEXPORT void new_card(duel* pduel, uint32 code, uint8 owner, uint8 playerid, uint8 location, uint8 sequence, uint8 position);
extern "C" DECL_DLLEXPORT void new_tag_card(duel* pduel, uint32 code, uint8 owner, uint8 location);
extern "C" DECL_DLLEXPORT int32 query_card(duel* pduel, uint8 playerid, uint8 location, uint8 sequence, int32 query_flag, byte* buf, int32 use_cache);
extern "C" DECL_DLLEXPORT int32 query_field_count(duel* pduel, uint8 playerid, uint8 location);
extern "C" DECL_DLLEXPORT int32 query_field_card(duel* pduel, uint8 playerid, uint8 location, int32 query_flag, byte* buf, int32 use_cache);
extern "C" DECL_DLLEXPORT int32 query_field_info(duel* pduel, byte* buf);
extern "C" DECL_DLLEXPORT void set_responsei(duel* pduel, int32 value);
extern "C" DECL_DLLEXPORT void set_responseb(duel* pduel, byte* buf);
extern "C" DECL_DLLEXPORT int32 preload_script(duel* pduel, const char* script, int32 len);
extern "C" DECL_DLLEXPORT std::intptr_t create_duel(uint32 seed);
extern "C" DECL_DLLEXPORT void start_duel(std::intptr_t pduel, int32 options);
extern "C" DECL_DLLEXPORT void end_duel(std::intptr_t pduel);
extern "C" DECL_DLLEXPORT void set_player_info(std::intptr_t pduel, int32 playerid, int32 lp, int32 startcount, int32 drawcount);
extern "C" DECL_DLLEXPORT void get_log_message(std::intptr_t pduel, byte* buf);
extern "C" DECL_DLLEXPORT int32 get_message(std::intptr_t pduel, byte* buf);
extern "C" DECL_DLLEXPORT int32 process(std::intptr_t pduel);
extern "C" DECL_DLLEXPORT void new_card(std::intptr_t pduel, uint32 code, uint8 owner, uint8 playerid, uint8 location, uint8 sequence, uint8 position);
extern "C" DECL_DLLEXPORT void new_tag_card(std::intptr_t pduel, uint32 code, uint8 owner, uint8 location);
extern "C" DECL_DLLEXPORT int32 query_card(std::intptr_t pduel, uint8 playerid, uint8 location, uint8 sequence, int32 query_flag, byte* buf, int32 use_cache);
extern "C" DECL_DLLEXPORT int32 query_field_count(std::intptr_t pduel, uint8 playerid, uint8 location);
extern "C" DECL_DLLEXPORT int32 query_field_card(std::intptr_t pduel, uint8 playerid, uint8 location, int32 query_flag, byte* buf, int32 use_cache);
extern "C" DECL_DLLEXPORT int32 query_field_info(std::intptr_t pduel, byte* buf);
extern "C" DECL_DLLEXPORT void set_responsei(std::intptr_t pduel, int32 value);
extern "C" DECL_DLLEXPORT void set_responseb(std::intptr_t pduel, byte* buf);
extern "C" DECL_DLLEXPORT int32 preload_script(std::intptr_t pduel, const char* script, int32 len);
byte* default_script_reader(const char* script_name, int* len);
uint32 default_card_reader(uint32 code, card_data* data);
uint32 default_message_handler(void* pduel, uint32 msg_type);
......
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