The vendored ocgcore from the Unity repo (Tools/YGOLegacy/ocgcore at dev HEAD). Upstream is nanahira/ygopro-core at 973672dc9ce7cb49f47173277ab1ad0e318b7593; the seven files that differ from it carry the fork's core patches, already applied: 0001 face-down Token setcode, 0004 effect damage step outside a chain, 0008 Sandbox god mode, 0015 tag first seat holds the hand, 0022 attack preview, 0024 attack preview legality. Generated build/ output is left out. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
47 lines
1.2 KiB
C++
47 lines
1.2 KiB
C++
#ifndef CORE_BUFFER_H
|
|
#define CORE_BUFFER_H
|
|
|
|
#include <cstdio>
|
|
#include <cstring>
|
|
#include <vector>
|
|
|
|
inline void buffer_read_block(unsigned char*& p, void* dest, size_t size) {
|
|
std::memcpy(dest, p, size);
|
|
p += size;
|
|
}
|
|
template<typename T>
|
|
inline T buffer_read(unsigned char*& p) {
|
|
T ret{};
|
|
std::memcpy(&ret, p, sizeof(T));
|
|
p += sizeof(T);
|
|
return ret;
|
|
}
|
|
|
|
inline void buffer_write_block(unsigned char*& p, const void* src, size_t size) {
|
|
std::memcpy(p, src, size);
|
|
p += size;
|
|
}
|
|
template<typename T>
|
|
inline void buffer_write(unsigned char*& p, const T& value) {
|
|
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) {
|
|
auto* bytes = static_cast<const unsigned char*>(src);
|
|
buffer.insert(buffer.end(), bytes, bytes + size);
|
|
}
|
|
template<typename T>
|
|
inline void vector_write(std::vector<unsigned char>& buffer, const T& value) {
|
|
vector_write_block(buffer, &value, sizeof(T));
|
|
}
|
|
|
|
inline void vector_fread(std::vector<unsigned char>& buffer, FILE* fp) {
|
|
unsigned char temp[4096]{};
|
|
while (size_t len = std::fread(temp, 1, sizeof temp, fp))
|
|
vector_write_block(buffer, temp, len);
|
|
std::fclose(fp);
|
|
}
|
|
|
|
#endif // !CORE_BUFFER_H
|