Commit 63d9a249 authored by nanahira's avatar nanahira

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

parents 76b4b3ad 1aed2254
......@@ -62,6 +62,8 @@ Get all cards in some location.
- `int32_t preload_script(intptr_t pduel, const char* script_name);`
- `byte* default_script_reader(const char* script_name, int* len);`
The default script reader using `fread`.
# Lua functions
- `libcard.cpp`
......
......@@ -12,7 +12,8 @@ inline void buffer_read_block(unsigned char*& p, void* dest, size_t size) {
template<typename T>
inline T buffer_read(unsigned char*& p) {
T ret{};
buffer_read_block(p, &ret, sizeof(T));
std::memcpy(&ret, p, sizeof(T));
p += sizeof(T);
return ret;
}
......@@ -22,7 +23,8 @@ inline void buffer_write_block(unsigned char*& p, const void* src, size_t size)
}
template<typename T>
inline void buffer_write(unsigned char*& p, T value) {
buffer_write_block(p, &value, sizeof(T));
std::memcpy(p, &value, sizeof(T));
p += sizeof(T);
}
inline void vector_write_block(std::vector<unsigned char>& buffer, const void* src, size_t size) {
......
......@@ -505,9 +505,9 @@ uint32_t card::get_another_code() {
return 0;
}
inline bool check_setcode(uint16_t setcode, uint32_t value) {
uint32_t settype = value & 0x0fffU;
uint32_t setsubtype = value & 0xf000U;
return (setcode & 0x0fffU) == settype && (setcode & 0xf000U & setsubtype) == setsubtype;
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();
......
#ifndef CARD_DATA_H_
#define CARD_DATA_H_
#include <cstring>
#include <unordered_map>
#include "common.h"
......@@ -38,26 +39,14 @@ struct card_data {
uint32_t link_marker{};
void clear() {
code = 0;
alias = 0;
for (auto& x : setcode)
x = 0;
type = 0;
level = 0;
attribute = 0;
race = 0;
attack = 0;
defense = 0;
lscale = 0;
rscale = 0;
link_marker = 0;
std::memset(this, 0, sizeof(card_data));
}
bool is_setcode(uint32_t value) const {
uint16_t settype = value & 0x0fff;
uint16_t setsubtype = value & 0xf000;
const uint16_t settype = value & 0x0fff;
const uint16_t setsubtype = value & 0xf000;
for (auto& x : setcode) {
if ((x & 0x0fff) == settype && (x & 0xf000 & setsubtype) == setsubtype)
if ((x & 0x0fff) == settype && (x & setsubtype) == setsubtype)
return true;
if (!x)
return false;
......@@ -80,8 +69,8 @@ struct card_data {
}
value >>= 16;
}
for (int i = ctr; i < SIZE_SETCODE; ++i)
setcode[i] = 0;
if (ctr < SIZE_SETCODE)
std::memset(setcode + ctr, 0, (SIZE_SETCODE - ctr) * sizeof(uint16_t));
}
uint32_t get_original_code() const {
......
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