Commit 5b8143f3 authored by 神楽坂玲奈's avatar 神楽坂玲奈

init

parent aeba26e8
[submodule "ocgcore"]
path = ocgcore
url = https://github.com/Fluorohydride/ygopro-core.git
[submodule "script"] [submodule "script"]
path = script path = script
url = https://github.com/Fluorohydride/ygopro-scripts.git url = https://github.com/Fluorohydride/ygopro-scripts.git
[submodule "pics"]
path = pics
url = https://github.com/mycard/ygopro-images
branch = zh-CN
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_GUI_BUTTON_H_INCLUDED__
#define __C_GUI_BUTTON_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_GUI_
#include "IGUIButton.h"
#include "IGUISpriteBank.h"
#include "SColor.h"
namespace irr
{
namespace gui
{
class CGUIButton : public IGUIButton
{
public:
//! constructor
CGUIButton(IGUIEnvironment* environment, IGUIElement* parent,
s32 id, core::rect<s32> rectangle, bool noclip=false);
//! destructor
virtual ~CGUIButton();
//! called if an event happened.
virtual bool OnEvent(const SEvent& event);
//! draws the element and its children
virtual void draw();
//! sets another skin independent font. if this is set to zero, the button uses the font of the skin.
virtual void setOverrideFont(IGUIFont* font=0);
//! Gets the override font (if any)
virtual IGUIFont* getOverrideFont() const;
//! Get the font which is used right now for drawing
virtual IGUIFont* getActiveFont() const;
//! Sets an image which should be displayed on the button when it is in normal state.
virtual void setImage(video::ITexture* image=0);
//! Sets an image which should be displayed on the button when it is in normal state.
virtual void setImage(video::ITexture* image, const core::rect<s32>& pos);
//! Sets an image which should be displayed on the button when it is in pressed state.
virtual void setPressedImage(video::ITexture* image=0);
//! Sets an image which should be displayed on the button when it is in pressed state.
virtual void setPressedImage(video::ITexture* image, const core::rect<s32>& pos);
//! Sets the sprite bank used by the button
virtual void setSpriteBank(IGUISpriteBank* bank=0);
//! Sets the animated sprite for a specific button state
/** \param index: Number of the sprite within the sprite bank, use -1 for no sprite
\param state: State of the button to set the sprite for
\param index: The sprite number from the current sprite bank
\param color: The color of the sprite
*/
virtual void setSprite(EGUI_BUTTON_STATE state, s32 index,
video::SColor color=video::SColor(255,255,255,255), bool loop=false);
//! Sets if the button should behave like a push button. Which means it
//! can be in two states: Normal or Pressed. With a click on the button,
//! the user can change the state of the button.
virtual void setIsPushButton(bool isPushButton=true);
//! Checks whether the button is a push button
virtual bool isPushButton() const;
//! Sets the pressed state of the button if this is a pushbutton
virtual void setPressed(bool pressed=true);
//! Returns if the button is currently pressed
virtual bool isPressed() const;
//! Sets if the button should use the skin to draw its border
virtual void setDrawBorder(bool border=true);
//! Checks if the button face and border are being drawn
virtual bool isDrawingBorder() const;
//! Sets if the alpha channel should be used for drawing images on the button (default is false)
virtual void setUseAlphaChannel(bool useAlphaChannel=true);
//! Checks if the alpha channel should be used for drawing images on the button
virtual bool isAlphaChannelUsed() const;
//! Sets if the button should scale the button images to fit
virtual void setScaleImage(bool scaleImage=true);
//! Checks whether the button scales the used images
virtual bool isScalingImage() const;
//! Writes attributes of the element.
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const;
//! Reads attributes of the element
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options);
protected:
struct ButtonSprite
{
s32 Index;
video::SColor Color;
bool Loop;
};
ButtonSprite ButtonSprites[EGBS_COUNT];
IGUISpriteBank* SpriteBank;
IGUIFont* OverrideFont;
video::ITexture* Image;
video::ITexture* PressedImage;
core::rect<s32> ImageRect;
core::rect<s32> PressedImageRect;
u32 ClickTime, HoverTime, FocusTime;
bool IsPushButton;
bool Pressed;
bool UseAlphaChannel;
bool DrawBorder;
bool ScaleImage;
};
} // end namespace gui
} // end namespace irr
#endif // _IRR_COMPILE_WITH_GUI_
#endif // __C_GUI_BUTTON_H_INCLUDED__
#ifdef _MSC_VER
#pragma warning(disable: 4244)
#endif
#include "CGUIImageButton.h"
namespace irr {
namespace gui {
void Draw2DImageRotation(video::IVideoDriver* driver, video::ITexture* image, core::rect<s32> sourceRect,
core::position2d<s32> position, core::position2d<s32> rotationPoint, f32 rotation, core::vector2df scale, bool useAlphaChannel, video::SColor color) {
irr::video::SMaterial material;
irr::core::matrix4 oldProjMat = driver->getTransform(irr::video::ETS_PROJECTION);
driver->setTransform(irr::video::ETS_PROJECTION, irr::core::matrix4());
irr::core::matrix4 oldViewMat = driver->getTransform(irr::video::ETS_VIEW);
driver->setTransform(irr::video::ETS_VIEW, irr::core::matrix4());
irr::core::vector2df corner[4];
corner[0] = irr::core::vector2df(position.X, position.Y);
corner[1] = irr::core::vector2df(position.X + sourceRect.getWidth() * scale.X, position.Y);
corner[2] = irr::core::vector2df(position.X, position.Y + sourceRect.getHeight() * scale.Y);
corner[3] = irr::core::vector2df(position.X + sourceRect.getWidth() * scale.X, position.Y + sourceRect.getHeight() * scale.Y);
if (rotation != 0.0f) {
for (int x = 0; x < 4; x++)
corner[x].rotateBy(rotation, irr::core::vector2df(rotationPoint.X, rotationPoint.Y));
}
irr::core::vector2df uvCorner[4];
uvCorner[0] = irr::core::vector2df(sourceRect.UpperLeftCorner.X, sourceRect.UpperLeftCorner.Y);
uvCorner[1] = irr::core::vector2df(sourceRect.LowerRightCorner.X, sourceRect.UpperLeftCorner.Y);
uvCorner[2] = irr::core::vector2df(sourceRect.UpperLeftCorner.X, sourceRect.LowerRightCorner.Y);
uvCorner[3] = irr::core::vector2df(sourceRect.LowerRightCorner.X, sourceRect.LowerRightCorner.Y);
for (int x = 0; x < 4; x++) {
float uvX = uvCorner[x].X / (float)image->getOriginalSize().Width;
float uvY = uvCorner[x].Y / (float)image->getOriginalSize().Height;
uvCorner[x] = irr::core::vector2df(uvX, uvY);
}
irr::video::S3DVertex vertices[4];
irr::u16 indices[6] = { 0, 1, 2, 3, 2, 1 };
float screenWidth = driver->getScreenSize().Width;
float screenHeight = driver->getScreenSize().Height;
for (int x = 0; x < 4; x++) {
float screenPosX = ((corner[x].X / screenWidth) - 0.5f) * 2.0f;
float screenPosY = ((corner[x].Y / screenHeight) - 0.5f) * -2.0f;
vertices[x].Pos = irr::core::vector3df(screenPosX, screenPosY, 1);
vertices[x].TCoords = uvCorner[x];
vertices[x].Color = color;
}
material.Lighting = false;
material.ZWriteEnable = false;
material.TextureLayer[0].Texture = image;
if (useAlphaChannel)
material.MaterialType = irr::video::EMT_TRANSPARENT_ALPHA_CHANNEL;
else material.MaterialType = irr::video::EMT_SOLID;
driver->setMaterial(material);
driver->drawIndexedTriangleList(&vertices[0], 4, &indices[0], 2);
driver->setTransform(irr::video::ETS_PROJECTION, oldProjMat);
driver->setTransform(irr::video::ETS_VIEW, oldViewMat);
}
void Draw2DImageQuad(video::IVideoDriver* driver, video::ITexture* image, core::rect<s32> sourceRect,
core::position2d<s32> corner[4], bool useAlphaChannel, video::SColor color) {
irr::video::SMaterial material;
irr::core::matrix4 oldProjMat = driver->getTransform(irr::video::ETS_PROJECTION);
driver->setTransform(irr::video::ETS_PROJECTION, irr::core::matrix4());
irr::core::matrix4 oldViewMat = driver->getTransform(irr::video::ETS_VIEW);
driver->setTransform(irr::video::ETS_VIEW, irr::core::matrix4());
irr::core::vector2df uvCorner[4];
uvCorner[0] = irr::core::vector2df(sourceRect.UpperLeftCorner.X, sourceRect.UpperLeftCorner.Y);
uvCorner[1] = irr::core::vector2df(sourceRect.LowerRightCorner.X, sourceRect.UpperLeftCorner.Y);
uvCorner[2] = irr::core::vector2df(sourceRect.UpperLeftCorner.X, sourceRect.LowerRightCorner.Y);
uvCorner[3] = irr::core::vector2df(sourceRect.LowerRightCorner.X, sourceRect.LowerRightCorner.Y);
for (int x = 0; x < 4; x++) {
float uvX = uvCorner[x].X / (float)image->getOriginalSize().Width;
float uvY = uvCorner[x].Y / (float)image->getOriginalSize().Height;
uvCorner[x] = irr::core::vector2df(uvX, uvY);
}
irr::video::S3DVertex vertices[4];
irr::u16 indices[6] = { 0, 1, 2, 3, 2, 1 };
float screenWidth = driver->getScreenSize().Width;
float screenHeight = driver->getScreenSize().Height;
for (int x = 0; x < 4; x++) {
float screenPosX = ((corner[x].X / screenWidth) - 0.5f) * 2.0f;
float screenPosY = ((corner[x].Y / screenHeight) - 0.5f) * -2.0f;
vertices[x].Pos = irr::core::vector3df(screenPosX, screenPosY, 1);
vertices[x].TCoords = uvCorner[x];
vertices[x].Color = color;
}
material.Lighting = false;
material.ZWriteEnable = false;
material.TextureLayer[0].Texture = image;
if (useAlphaChannel)
material.MaterialType = irr::video::EMT_TRANSPARENT_ALPHA_CHANNEL;
else material.MaterialType = irr::video::EMT_SOLID;
driver->setMaterial(material);
driver->drawIndexedTriangleList(&vertices[0], 4, &indices[0], 2);
driver->setTransform(irr::video::ETS_PROJECTION, oldProjMat);
driver->setTransform(irr::video::ETS_VIEW, oldViewMat);
}
CGUIImageButton::CGUIImageButton(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle)
: CGUIButton(environment, parent, id, rectangle) {
isDrawImage = true;
imageRotation = 0.0f;
imageScale = core::vector2df(1.0f, 1.0f);
}
CGUIImageButton* CGUIImageButton::addImageButton(IGUIEnvironment *env, const core::rect<s32>& rectangle, IGUIElement* parent, s32 id) {
CGUIImageButton* button = new CGUIImageButton(env, parent ? parent : 0, id, rectangle);
button->drop();
return button;
}
void CGUIImageButton::draw() {
if (!IsVisible)
return;
IGUISkin* skin = Environment->getSkin();
video::IVideoDriver* driver = Environment->getVideoDriver();
core::position2di center = AbsoluteRect.getCenter();
core::position2di pos = center;
pos.X -= (s32)(ImageRect.getWidth() * imageScale.X * 0.5f);
pos.Y -= (s32)(ImageRect.getHeight() * imageScale.Y * 0.5f);
if(Pressed) {
pos.X += 1;
pos.Y += 1;
center.X += 1;
center.Y += 1;
if (DrawBorder)
skin->draw3DButtonPanePressed(this, AbsoluteRect, &AbsoluteClippingRect);
} else {
if (DrawBorder)
skin->draw3DButtonPaneStandard(this, AbsoluteRect, &AbsoluteClippingRect);
}
if(Image && isDrawImage)
irr::gui::Draw2DImageRotation(driver, Image, ImageRect, pos, center, imageRotation, imageScale);
IGUIElement::draw();
}
void CGUIImageButton::setDrawImage(bool b) {
isDrawImage = b;
}
void CGUIImageButton::setImageRotation(f32 r) {
imageRotation = r;
}
void CGUIImageButton::setImageScale(core::vector2df s) {
imageScale = s;
}
IGUIFont* CGUIImageButton::getOverrideFont( void ) const
{
IGUISkin* skin = Environment->getSkin();
if (!skin)
return NULL;
return skin->getFont();
}
IGUIFont* CGUIImageButton::getActiveFont() const
{
IGUISkin* skin = Environment->getSkin();
if (!skin)
return NULL;
return skin->getFont();
}
}
}
#ifndef _C_GUI_IMAGE_BUTTON_H_
#define _C_GUI_IMAGE_BUTTON_H_
#include <irrlicht.h>
#include "CGUIButton.h"
namespace irr {
namespace gui {
void Draw2DImageRotation(video::IVideoDriver* driver, video::ITexture* image, core::rect<s32> sourceRect,
core::position2d<s32> position, core::position2d<s32> rotationPoint, f32 rotation = 0.0f,
core::vector2df scale = core::vector2df(1.0, 1.0), bool useAlphaChannel = true, video::SColor color = 0xffffffff);
void Draw2DImageQuad(video::IVideoDriver* driver, video::ITexture* image, core::rect<s32> sourceRect,
core::position2d<s32> corner[4], bool useAlphaChannel = true, video::SColor color = 0xffffffff);
class CGUIImageButton : public CGUIButton {
public:
CGUIImageButton(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle);
static CGUIImageButton* addImageButton(IGUIEnvironment *env, const core::rect<s32>& rectangle, IGUIElement* parent, s32 id);
virtual void draw();
virtual void setDrawImage(bool b);
virtual void setImageRotation(f32 r);
virtual void setImageScale(core::vector2df s);
virtual IGUIFont* getOverrideFont(void) const;
virtual IGUIFont* getActiveFont() const;
private:
bool isDrawImage;
f32 imageRotation;
core::vector2df imageScale;
};
}
}
#endif //_C_GUI_IMAGE_BUTTON_H_
This diff is collapsed.
This diff is collapsed.
#ifndef BUFFERIO_H
#define BUFFERIO_H
#ifdef _MSC_VER
#pragma warning(disable: 4244)
#endif
class BufferIO {
public:
inline static int ReadInt32(char*& p) {
int ret = *(int*)p;
p += 4;
return ret;
}
inline static short ReadInt16(char*& p) {
short ret = *(short*)p;
p += 2;
return ret;
}
inline static char ReadInt8(char*& p) {
char ret = *(char*)p;
p++;
return ret;
}
inline static unsigned char ReadUInt8(char*& p) {
unsigned char ret = *(unsigned char*)p;
p++;
return ret;
}
inline static void WriteInt32(char*& p, int val) {
(*(int*)p) = val;
p += 4;
}
inline static void WriteInt16(char*& p, short val) {
(*(short*)p) = val;
p += 2;
}
inline static void WriteInt8(char*& p, char val) {
*p = val;
p++;
}
template<typename T1, typename T2>
inline static int CopyWStr(T1* src, T2* pstr, int bufsize) {
int l = 0;
while(src[l] && l < bufsize - 1) {
pstr[l] = src[l];
l++;
}
pstr[l] = 0;
return l;
}
template<typename T1, typename T2>
inline static int CopyWStrRef(T1* src, T2*& pstr, int bufsize) {
int l = 0;
while(src[l] && l < bufsize - 1) {
pstr[l] = src[l];
l++;
}
pstr += l;
*pstr = 0;
return l;
}
static int EncodeUTF8(const wchar_t * wsrc, char * str) {
char* pstr = str;
while(*wsrc != 0) {
if(*wsrc < 0x80) {
*str = *wsrc;
++str;
} else if(*wsrc < 0x800) {
str[0] = ((*wsrc >> 6) & 0x1f) | 0xc0;
str[1] = ((*wsrc) & 0x3f) | 0x80;
str += 2;
} else {
str[0] = ((*wsrc >> 12) & 0xf) | 0xe0;
str[1] = ((*wsrc >> 6) & 0x3f) | 0x80;
str[2] = ((*wsrc) & 0x3f) | 0x80;
str += 3;
}
wsrc++;
}
*str = 0;
return str - pstr;
}
static int DecodeUTF8(const char * src, wchar_t * wstr) {
const char* p = src;
wchar_t* wp = wstr;
while(*p != 0) {
if((*p & 0x80) == 0) {
*wp = *p;
p++;
} else if((*p & 0xe0) == 0xc0) {
*wp = (((int)p[0] & 0x1f) << 6) | ((int)p[1] & 0x3f);
p += 2;
} else if((*p & 0xf0) == 0xe0) {
*wp = (((int)p[0] & 0xf) << 12) | (((int)p[1] & 0x3f) << 6) | ((int)p[2] & 0x3f);
p += 3;
} else if((*p & 0xf8) == 0xf0) {
*wp = (((int)p[0] & 0x7) << 18) | (((int)p[1] & 0x3f) << 12) | (((int)p[2] & 0x3f) << 6) | ((int)p[3] & 0x3f);
p += 4;
} else
p++;
wp++;
}
*wp = 0;
return wp - wstr;
}
static int GetVal(const wchar_t* pstr) {
int ret = 0;
while(*pstr >= L'0' && *pstr <= L'9') {
ret = ret * 10 + (*pstr - L'0');
pstr++;
}
return ret;
}
};
#endif //BUFFERIO_H
#include "client_card.h"
#include "client_field.h"
#include "game.h"
namespace ygo {
ClientCard::ClientCard() {
curAlpha = 255;
dAlpha = 0;
aniFrame = 0;
is_moving = false;
is_fading = false;
is_hovered = false;
is_selectable = false;
is_selected = false;
is_showequip = false;
is_showtarget = false;
is_highlighting = false;
is_disabled = false;
is_reversed = false;
is_conti = false;
cmdFlag = 0;
code = 0;
chain_code = 0;
type = 0;
alias = 0;
level = 0;
rank = 0;
race = 0;
attribute = 0;
attack = 0;
defence = 0;
base_attack = 0;
base_defence = 0;
lscale = 0;
rscale = 0;
cHint = 0;
chValue = 0;
atkstring[0] = 0;
defstring[0] = 0;
lvstring[0] = 0;
rscstring[0] = 0;
lscstring[0] = 0;
overlayTarget = 0;
equipTarget = 0;
}
void ClientCard::SetCode(int code) {
if((location == LOCATION_HAND) && (this->code != (unsigned int)code)) {
this->code = code;
mainGame->dField.MoveCard(this, 5);
} else
this->code = code;
}
void ClientCard::UpdateInfo(char* buf) {
int flag = BufferIO::ReadInt32(buf);
if(flag == 0)
return;
int pdata;
if(flag & QUERY_CODE) {
pdata = BufferIO::ReadInt32(buf);
if((location == LOCATION_HAND) && ((unsigned int)pdata != code)) {
code = pdata;
mainGame->dField.MoveCard(this, 5);
} else
code = pdata;
}
if(flag & QUERY_POSITION) {
pdata = BufferIO::ReadInt32(buf);
position = (pdata >> 24) & 0xff;
}
if(flag & QUERY_ALIAS)
alias = BufferIO::ReadInt32(buf);
if(flag & QUERY_TYPE)
type = BufferIO::ReadInt32(buf);
if(flag & QUERY_LEVEL) {
pdata = BufferIO::ReadInt32(buf);
if(level != (unsigned int)pdata) {
level = pdata;
myswprintf(lvstring, L"L%d", level);
}
}
if(flag & QUERY_RANK) {
pdata = BufferIO::ReadInt32(buf);
if(pdata && rank != (unsigned int)pdata) {
rank = pdata;
myswprintf(lvstring, L"R%d", rank);
}
}
if(flag & QUERY_ATTRIBUTE)
attribute = BufferIO::ReadInt32(buf);
if(flag & QUERY_RACE)
race = BufferIO::ReadInt32(buf);
if(flag & QUERY_ATTACK) {
attack = BufferIO::ReadInt32(buf);
if(attack < 0) {
atkstring[0] = '?';
atkstring[1] = 0;
} else
myswprintf(atkstring, L"%d", attack);
}
if(flag & QUERY_DEFENCE) {
defence = BufferIO::ReadInt32(buf);
if(defence < 0) {
defstring[0] = '?';
defstring[1] = 0;
} else
myswprintf(defstring, L"%d", defence);
}
if(flag & QUERY_BASE_ATTACK)
base_attack = BufferIO::ReadInt32(buf);
if(flag & QUERY_BASE_DEFENCE)
base_defence = BufferIO::ReadInt32(buf);
if(flag & QUERY_REASON)
reason = BufferIO::ReadInt32(buf);
if(flag & QUERY_EQUIP_CARD) {
int c = BufferIO::ReadInt8(buf);
int l = BufferIO::ReadInt8(buf);
int s = BufferIO::ReadInt8(buf);
BufferIO::ReadInt8(buf);
ClientCard* ecard = mainGame->dField.GetCard(c, l, s);
equipTarget = ecard;
ecard->equipped.insert(this);
}
if(flag & QUERY_TARGET_CARD) {
int count = BufferIO::ReadInt32(buf);
for(int i = 0; i < count; ++i) {
int c = BufferIO::ReadInt8(buf);
int l = BufferIO::ReadInt8(buf);
int s = BufferIO::ReadInt8(buf);
BufferIO::ReadInt8(buf);
ClientCard* tcard = mainGame->dField.GetCard(c, l, s);
cardTarget.insert(tcard);
tcard->ownerTarget.insert(this);
}
}
if(flag & QUERY_OVERLAY_CARD) {
int count = BufferIO::ReadInt32(buf);
for(int i = 0; i < count; ++i) {
overlayed[i]->SetCode(BufferIO::ReadInt32(buf));
}
}
if(flag & QUERY_COUNTERS) {
int count = BufferIO::ReadInt32(buf);
for(int i = 0; i < count; ++i) {
int ctype = BufferIO::ReadInt16(buf);
int ccount = BufferIO::ReadInt16(buf);
counters[ctype] = ccount;
}
}
if(flag & QUERY_OWNER)
owner = BufferIO::ReadInt32(buf);
if(flag & QUERY_IS_DISABLED)
is_disabled = BufferIO::ReadInt32(buf);
if(flag & QUERY_IS_PUBLIC)
is_public = BufferIO::ReadInt32(buf);
if(flag & QUERY_LSCALE) {
pdata = BufferIO::ReadInt32(buf);
if(pdata && lscale != (unsigned int)pdata) {
lscale = pdata;
myswprintf(lscstring, L"%d", lscale);
}
}
if(flag & QUERY_RSCALE) {
pdata = BufferIO::ReadInt32(buf);
if(pdata && rscale != (unsigned int)pdata) {
rscale = pdata;
myswprintf(rscstring, L"%d", rscale);
}
}
}
void ClientCard::ClearTarget() {
for(auto cit = cardTarget.begin(); cit != cardTarget.end(); ++cit) {
if(is_showtarget)
(*cit)->is_showtarget = false;
(*cit)->ownerTarget.erase(this);
}
for(auto cit = ownerTarget.begin(); cit != ownerTarget.end(); ++cit) {
if(is_showtarget)
(*cit)->is_showtarget = false;
(*cit)->cardTarget.erase(this);
}
cardTarget.clear();
ownerTarget.clear();
}
bool ClientCard::client_card_sort(ClientCard* c1, ClientCard* c2) {
int32 cp1 = c1->overlayTarget ? c1->overlayTarget->controler : c1->controler;
int32 cp2 = c2->overlayTarget ? c2->overlayTarget->controler : c2->controler;
if(cp1 != cp2)
return cp1 < cp2;
if(c1->location != c2->location)
return c1->location < c2->location;
if(c1->location & LOCATION_OVERLAY)
if(c1->overlayTarget != c2->overlayTarget)
return c1->overlayTarget->sequence < c2->overlayTarget->sequence;
else return c1->sequence < c2->sequence;
else {
if(c1->location & 0x71)
return c1->sequence > c2->sequence;
else
return c1->sequence < c2->sequence;
}
}
bool ClientCard::deck_sort_lv(code_pointer p1, code_pointer p2) {
if((p1->second.type & 0x7) != (p2->second.type & 0x7))
return (p1->second.type & 0x7) < (p2->second.type & 0x7);
if((p1->second.type & 0x7) == 1) {
int type1 = (p1->second.type & 0x8020c0) ? (p1->second.type & 0x8020c1) : (p1->second.type & 0x31);
int type2 = (p2->second.type & 0x8020c0) ? (p2->second.type & 0x8020c1) : (p2->second.type & 0x31);
if(type1 != type2)
return type1 < type2;
if(p1->second.level != p2->second.level)
return p1->second.level > p2->second.level;
if(p1->second.attack != p2->second.attack)
return p1->second.attack > p2->second.attack;
if(p1->second.defence != p2->second.defence)
return p1->second.defence > p2->second.defence;
else return p1->first < p2->first;
}
if((p1->second.type & 0xfffffff8) != (p2->second.type & 0xfffffff8))
return (p1->second.type & 0xfffffff8) < (p2->second.type & 0xfffffff8);
return p1->first < p2->first;
}
}
#ifndef CLIENT_CARD_H
#define CLIENT_CARD_H
#include "config.h"
#include <vector>
#include <set>
#include <unordered_map>
namespace ygo {
struct CardData {
unsigned int code;
unsigned int alias;
unsigned long long setcode;
unsigned int type;
unsigned int level;
unsigned int attribute;
unsigned int race;
int attack;
int defence;
unsigned int lscale;
unsigned int rscale;
};
struct CardDataC {
unsigned int code;
unsigned int alias;
unsigned long long setcode;
unsigned int type;
unsigned int level;
unsigned int attribute;
unsigned int race;
int attack;
int defence;
unsigned int lscale;
unsigned int rscale;
unsigned int ot;
unsigned int category;
};
struct CardString {
wchar_t* name;
wchar_t* text;
wchar_t* desc[16];
};
typedef std::unordered_map<unsigned int, CardDataC>::iterator code_pointer;
class ClientCard {
public:
irr::video::ITexture* curTexture;
irr::core::matrix4 mTransform;
irr::core::vector3df curPos;
irr::core::vector3df curRot;
irr::core::vector3df dPos;
irr::core::vector3df dRot;
u32 curAlpha;
u32 dAlpha;
u32 aniFrame;
bool is_moving;
bool is_fading;
bool is_hovered;
bool is_selectable;
bool is_selected;
bool is_showequip;
bool is_showtarget;
bool is_highlighting;
bool is_reversed;
bool is_conti;
u32 code;
u32 chain_code;
u32 alias;
u32 type;
u32 level;
u32 rank;
u32 attribute;
u32 race;
s32 attack;
s32 defence;
s32 base_attack;
s32 base_defence;
u32 lscale;
u32 rscale;
u32 reason;
u32 select_seq;
u8 owner;
u8 controler;
u8 location;
u8 sequence;
u8 position;
u8 is_disabled;
u8 is_public;
u8 cHint;
u32 chValue;
u32 opParam;
u32 symbol;
u32 cmdFlag;
ClientCard* overlayTarget;
std::vector<ClientCard*> overlayed;
ClientCard* equipTarget;
std::set<ClientCard*> equipped;
std::set<ClientCard*> cardTarget;
std::set<ClientCard*> ownerTarget;
std::map<int, int> counters;
std::map<int, int> desc_hints;
wchar_t atkstring[16];
wchar_t defstring[16];
wchar_t lvstring[16];
wchar_t lscstring[16];
wchar_t rscstring[16];
ClientCard();
void SetCode(int code);
void UpdateInfo(char* buf);
void ClearTarget();
static bool client_card_sort(ClientCard* c1, ClientCard* c2);
static bool deck_sort_lv(code_pointer l1, code_pointer l2);
};
}
#endif //CLIENT_CARD_H
This diff is collapsed.
#ifndef CLIENT_FIELD_H
#define CLIENT_FIELD_H
#include "config.h"
#include <vector>
namespace ygo {
class ClientCard;
struct ChainInfo{
irr::core::vector3df chain_pos;
ClientCard* chain_card;
int code;
int desc;
int controler;
int location;
int sequence;
bool solved;
};
class ClientField: public irr::IEventReceiver {
public:
std::vector<ClientCard*> deck[2];
std::vector<ClientCard*> hand[2];
std::vector<ClientCard*> mzone[2];
std::vector<ClientCard*> szone[2];
std::vector<ClientCard*> grave[2];
std::vector<ClientCard*> remove[2];
std::vector<ClientCard*> extra[2];
std::set<ClientCard*> overlay_cards;
std::vector<ClientCard*> summonable_cards;
std::vector<ClientCard*> spsummonable_cards;
std::vector<ClientCard*> msetable_cards;
std::vector<ClientCard*> ssetable_cards;
std::vector<ClientCard*> reposable_cards;
std::vector<ClientCard*> activatable_cards;
std::vector<ClientCard*> attackable_cards;
std::vector<ClientCard*> conti_cards;
std::vector<int> activatable_descs;
std::vector<int> select_options;
std::vector<ChainInfo> chains;
int extra_p_count[2];
size_t selected_option;
ClientCard* attacker;
ClientCard* attack_target;
int disabled_field;
int selectable_field;
int selected_field;
int select_min;
int select_max;
int must_select_count;
int select_sumval;
int select_cancelable;
int select_mode;
bool select_ready;
int announce_count;
int declarable_type;
int select_counter_count;
int select_counter_type;
std::vector<ClientCard*> selectable_cards;
std::vector<ClientCard*> selected_cards;
std::set<ClientCard*> selectsum_cards;
std::vector<ClientCard*> selectsum_all;
std::vector<ClientCard*> display_cards;
std::vector<int> sort_list;
bool grave_act;
bool remove_act;
bool deck_act;
bool extra_act;
bool pzone_act[2];
bool chain_forced;
ChainInfo current_chain;
bool last_chain;
bool deck_reversed;
ClientField();
void Clear();
void Initial(int player, int deckc, int extrac);
ClientCard* GetCard(int controler, int location, int sequence, int sub_seq = 0);
void AddCard(ClientCard* pcard, int controler, int location, int sequence);
ClientCard* RemoveCard(int controler, int location, int sequence);
void UpdateCard(int controler, int location, int sequence, char* data);
void UpdateFieldCard(int controler, int location, char* data);
void ClearCommandFlag();
void ClearSelect();
void ClearChainSelect();
void ShowSelectCard(bool buttonok = false, bool chain = false);
void ShowChainCard();
void ShowLocationCard();
void ReplaySwap();
void RefreshAllCards();
void GetChainLocation(int controler, int location, int sequence, irr::core::vector3df* t);
void GetCardLocation(ClientCard* pcard, irr::core::vector3df* t, irr::core::vector3df* r, bool setTrans = false);
void MoveCard(ClientCard* pcard, int frame);
void FadeCard(ClientCard* pcard, int alpha, int frame);
bool CheckSelectSum();
bool check_min(std::set<ClientCard*>& left, std::set<ClientCard*>::iterator index, int min, int max);
bool check_sel_sum_s(const std::set<ClientCard*>& left, int index, int acc);
void check_sel_sum_t(const std::set<ClientCard*>& left, int acc);
bool check_sum(std::set<ClientCard*>::const_iterator index, std::set<ClientCard*>::const_iterator end, int acc, int count);
void UpdateDeclarableCode();
irr::gui::IGUIElement* panel;
std::vector<int> ancard;
int hovered_controler;
int hovered_location;
size_t hovered_sequence;
int command_controler;
int command_location;
size_t command_sequence;
ClientCard* hovered_card;
ClientCard* clicked_card;
ClientCard* command_card;
ClientCard* highlighting_card;
int list_command;
wchar_t formatBuffer[2048];
virtual bool OnEvent(const irr::SEvent& event);
void GetHoverField(int x, int y);
void ShowMenu(int flag, int x, int y);
void SetResponseSelectedCards() const;
};
}
//special cards
#define CARD_MARINE_DOLPHIN 78734254
#define CARD_TWINKLE_MOSS 13857930
#endif //CLIENT_FIELD_H
#ifndef __CONFIG_H
#define __CONFIG_H
#pragma once
#define _IRR_STATIC_LIB_
#define _IRR_COMPILE_WITH_DX9_DEV_PACK
#ifdef _WIN32
#include <WinSock2.h>
#include <windows.h>
#ifdef _MSC_VER
#define myswprintf _swprintf
#else
#define myswprintf swprintf
#endif
#define socklen_t int
#else //_WIN32
#include <errno.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
#define SD_BOTH 2
#define SOCKET int
#define closesocket close
#define INVALID_SOCKET -1
#define SOCKET_ERROR -1
#define SOCKADDR_IN sockaddr_in
#define SOCKADDR sockaddr
#define SOCKET_ERRNO() (errno)
#include <wchar.h>
#define myswprintf(buf, fmt, ...) swprintf(buf, 4096, fmt, ##__VA_ARGS__)
inline int _wtoi(const wchar_t * s) {
wchar_t * endptr;
return (int)wcstol(s, &endptr, 10);
}
#endif
#include <irrlicht.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "CGUITTFont.h"
#include "CGUIImageButton.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <time.h>
#include "bufferio.h"
#include "mymutex.h"
#include "mysignal.h"
#include "mythread.h"
#include "../ocgcore/ocgapi.h"
#include "../ocgcore/card.h"
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
extern const unsigned short PRO_VERSION;
extern int enable_log;
extern bool exit_on_return;
#endif
#include "data_manager.h"
#include <stdio.h>
namespace ygo {
const wchar_t* DataManager::unknown_string = L"???";
wchar_t DataManager::strBuffer[2048];
DataManager dataManager;
bool DataManager::LoadDB(const char* file) {
sqlite3* pDB;
if(sqlite3_open(file, &pDB) != SQLITE_OK)
return Error(pDB);
sqlite3_stmt* pStmt;
const char* sql = "select * from datas,texts where datas.id=texts.id";
if(sqlite3_prepare_v2(pDB, sql, -1, &pStmt, 0) != SQLITE_OK)
return Error(pDB);
CardDataC cd;
CardString cs;
for(int i = 0; i < 16; ++i) cs.desc[i] = 0;
int step = 0, len = 0;
do {
step = sqlite3_step(pStmt);
if(step == SQLITE_BUSY || step == SQLITE_ERROR || step == SQLITE_MISUSE)
return Error(pDB, pStmt);
else if(step == SQLITE_ROW) {
cd.code = sqlite3_column_int(pStmt, 0);
cd.ot = sqlite3_column_int(pStmt, 1);
cd.alias = sqlite3_column_int(pStmt, 2);
cd.setcode = sqlite3_column_int64(pStmt, 3);
cd.type = sqlite3_column_int(pStmt, 4);
cd.attack = sqlite3_column_int(pStmt, 5);
cd.defence = sqlite3_column_int(pStmt, 6);
unsigned int level = sqlite3_column_int(pStmt, 7);
cd.level = level & 0xff;
cd.lscale = (level >> 24) & 0xff;
cd.rscale = (level >> 16) & 0xff;
cd.race = sqlite3_column_int(pStmt, 8);
cd.attribute = sqlite3_column_int(pStmt, 9);
cd.category = sqlite3_column_int(pStmt, 10);
_datas.insert(std::make_pair(cd.code, cd));
len = BufferIO::DecodeUTF8((const char*)sqlite3_column_text(pStmt, 12), strBuffer);
if(len) {
cs.name = new wchar_t[len + 1];
memcpy(cs.name, strBuffer, (len + 1)*sizeof(wchar_t));
} else cs.name = 0;
len = BufferIO::DecodeUTF8((const char*)sqlite3_column_text(pStmt, 13), strBuffer);
if(len) {
cs.text = new wchar_t[len + 1];
memcpy(cs.text, strBuffer, (len + 1)*sizeof(wchar_t));
} else {
cs.text = new wchar_t[1];
cs.text[0] = 0;
}
for(int i = 14; i < 30; ++i) {
len = BufferIO::DecodeUTF8((const char*)sqlite3_column_text(pStmt, i), strBuffer);
if(len) {
cs.desc[i - 14] = new wchar_t[len + 1];
memcpy(cs.desc[i - 14], strBuffer, (len + 1)*sizeof(wchar_t));
} else cs.desc[i - 14] = 0;
}
_strings.insert(std::make_pair(cd.code, cs));
}
} while(step != SQLITE_DONE);
sqlite3_finalize(pStmt);
sqlite3_close(pDB);
return true;
}
bool DataManager::LoadStrings(const char* file) {
FILE* fp = fopen(file, "r");
if(!fp)
return false;
for(int i = 0; i < 2048; ++i)
_sysStrings[i] = 0;
char linebuf[256];
char strbuf[256];
int value;
fseek(fp, 0, SEEK_END);
int fsize = ftell(fp);
fseek(fp, 0, SEEK_SET);
fgets(linebuf, 256, fp);
while(ftell(fp) < fsize) {
fgets(linebuf, 256, fp);
if(linebuf[0] != '!')
continue;
sscanf(linebuf, "!%s", strbuf);
if(!strcmp(strbuf, "system")) {
sscanf(&linebuf[7], "%d %240[^\n]", &value, strbuf);
int len = BufferIO::DecodeUTF8(strbuf, strBuffer);
wchar_t* pbuf = new wchar_t[len + 1];
wcscpy(pbuf, strBuffer);
_sysStrings[value] = pbuf;
} else if(!strcmp(strbuf, "victory")) {
sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf);
int len = BufferIO::DecodeUTF8(strbuf, strBuffer);
wchar_t* pbuf = new wchar_t[len + 1];
wcscpy(pbuf, strBuffer);
_victoryStrings[value] = pbuf;
} else if(!strcmp(strbuf, "counter")) {
sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf);
int len = BufferIO::DecodeUTF8(strbuf, strBuffer);
wchar_t* pbuf = new wchar_t[len + 1];
wcscpy(pbuf, strBuffer);
_counterStrings[value] = pbuf;
} else if(!strcmp(strbuf, "setname")) {
sscanf(&linebuf[8], "%x %240[^\t\n]", &value, strbuf);//using tab for comment
int len = BufferIO::DecodeUTF8(strbuf, strBuffer);
wchar_t* pbuf = new wchar_t[len + 1];
wcscpy(pbuf, strBuffer);
_setnameStrings[value] = pbuf;
}
}
fclose(fp);
for(int i = 0; i < 255; ++i)
myswprintf(numStrings[i], L"%d", i);
return true;
}
bool DataManager::Error(sqlite3* pDB, sqlite3_stmt* pStmt) {
BufferIO::DecodeUTF8(sqlite3_errmsg(pDB), strBuffer);
if(pStmt)
sqlite3_finalize(pStmt);
sqlite3_close(pDB);
return false;
}
bool DataManager::GetData(int code, CardData* pData) {
auto cdit = _datas.find(code);
if(cdit == _datas.end())
return false;
if(pData)
*pData = *((CardData*)&cdit->second);
return true;
}
code_pointer DataManager::GetCodePointer(int code) {
return _datas.find(code);
}
bool DataManager::GetString(int code, CardString* pStr) {
auto csit = _strings.find(code);
if(csit == _strings.end()) {
pStr->name = (wchar_t*)unknown_string;
pStr->text = (wchar_t*)unknown_string;
return false;
}
*pStr = csit->second;
return true;
}
const wchar_t* DataManager::GetName(int code) {
auto csit = _strings.find(code);
if(csit == _strings.end())
return unknown_string;
if(csit->second.name)
return csit->second.name;
return unknown_string;
}
const wchar_t* DataManager::GetText(int code) {
auto csit = _strings.find(code);
if(csit == _strings.end())
return unknown_string;
if(csit->second.text)
return csit->second.text;
return unknown_string;
}
const wchar_t* DataManager::GetDesc(int strCode) {
if(strCode < 10000)
return GetSysString(strCode);
int code = strCode >> 4;
int offset = strCode & 0xf;
auto csit = _strings.find(code);
if(csit == _strings.end())
return unknown_string;
if(csit->second.desc[offset])
return csit->second.desc[offset];
return unknown_string;
}
const wchar_t* DataManager::GetSysString(int code) {
if(code < 0 || code >= 2048 || _sysStrings[code] == 0)
return unknown_string;
return _sysStrings[code];
}
const wchar_t* DataManager::GetVictoryString(int code) {
auto csit = _victoryStrings.find(code);
if(csit == _victoryStrings.end())
return unknown_string;
return csit->second;
}
const wchar_t* DataManager::GetCounterName(int code) {
auto csit = _counterStrings.find(code);
if(csit == _counterStrings.end())
return unknown_string;
return csit->second;
}
const wchar_t* DataManager::GetSetName(int code) {
auto csit = _setnameStrings.find(code);
if(csit == _setnameStrings.end())
return NULL;
return csit->second;
}
unsigned int DataManager::GetSetCode(const wchar_t* setname) {
for(auto csit = _setnameStrings.begin(); csit != _setnameStrings.end(); ++csit)
if(wcscmp(csit->second, setname) == 0)
return csit->first;
return 0;
}
const wchar_t* DataManager::GetNumString(int num, bool bracket) {
if(!bracket)
return numStrings[num];
wchar_t* p = numBuffer;
*p++ = L'(';
BufferIO::CopyWStrRef(numStrings[num], p, 4);
*p = L')';
*++p = 0;
return numBuffer;
}
const wchar_t* DataManager::FormatLocation(int location, int sequence) {
if(location == 0x8) {
if(sequence < 5)
return GetSysString(1003);
else if(sequence == 5)
return GetSysString(1008);
else
return GetSysString(1009);
}
int filter = 1, i = 1000;
while(filter != location) {
filter <<= 1;
i++;
}
if(filter == location)
return GetSysString(i);
else
return unknown_string;
}
const wchar_t* DataManager::FormatAttribute(int attribute) {
wchar_t* p = attBuffer;
int filter = 1, i = 1010;
for(; filter != 0x80; filter <<= 1, ++i) {
if(attribute & filter) {
BufferIO::CopyWStrRef(GetSysString(i), p, 16);
*p = L'|';
*++p = 0;
}
}
if(p != attBuffer)
*(p - 1) = 0;
else
return unknown_string;
return attBuffer;
}
const wchar_t* DataManager::FormatRace(int race) {
wchar_t* p = racBuffer;
int filter = 1, i = 1020;
for(; filter != 0x1000000; filter <<= 1, ++i) {
if(race & filter) {
BufferIO::CopyWStrRef(GetSysString(i), p, 16);
*p = L'|';
*++p = 0;
}
}
if(p != racBuffer)
*(p - 1) = 0;
else
return unknown_string;
return racBuffer;
}
const wchar_t* DataManager::FormatType(int type) {
wchar_t* p = tpBuffer;
int filter = 1, i = 1050;
for(; filter != 0x2000000; filter <<= 1, ++i) {
if(type & filter) {
BufferIO::CopyWStrRef(GetSysString(i), p, 16);
*p = L'|';
*++p = 0;
}
}
if(p != tpBuffer)
*(p - 1) = 0;
else
return unknown_string;
return tpBuffer;
}
const wchar_t* DataManager::FormatSetName(unsigned long long setcode) {
wchar_t* p = scBuffer;
for(int i = 0; i < 4; ++i) {
const wchar_t* setname = GetSetName((setcode >> i * 16) & 0xffff);
if(setname) {
BufferIO::CopyWStrRef(setname, p, 16);
*p = L'|';
*++p = 0;
}
}
if(p != scBuffer)
*(p - 1) = 0;
else
return unknown_string;
return scBuffer;
}
int DataManager::CardReader(int code, void* pData) {
if(!dataManager.GetData(code, (CardData*)pData))
memset(pData, 0, sizeof(CardData));
return 0;
}
}
#ifndef DATAMANAGER_H
#define DATAMANAGER_H
#include "config.h"
#include "sqlite3.h"
#include "client_card.h"
#include <unordered_map>
namespace ygo {
class DataManager {
public:
DataManager(): _datas(8192), _strings(8192) {}
bool LoadDB(const char* file);
bool LoadStrings(const char* file);
bool Error(sqlite3* pDB, sqlite3_stmt* pStmt = 0);
bool GetData(int code, CardData* pData);
code_pointer GetCodePointer(int code);
bool GetString(int code, CardString* pStr);
const wchar_t* GetName(int code);
const wchar_t* GetText(int code);
const wchar_t* GetDesc(int strCode);
const wchar_t* GetSysString(int code);
const wchar_t* GetVictoryString(int code);
const wchar_t* GetCounterName(int code);
const wchar_t* GetSetName(int code);
unsigned int GetSetCode(const wchar_t* setname);
const wchar_t* GetNumString(int num, bool bracket = false);
const wchar_t* FormatLocation(int location, int sequence);
const wchar_t* FormatAttribute(int attribute);
const wchar_t* FormatRace(int race);
const wchar_t* FormatType(int type);
const wchar_t* FormatSetName(unsigned long long setcode);
std::unordered_map<unsigned int, CardDataC> _datas;
std::unordered_map<unsigned int, CardString> _strings;
std::unordered_map<unsigned int, wchar_t*> _counterStrings;
std::unordered_map<unsigned int, wchar_t*> _victoryStrings;
std::unordered_map<unsigned int, wchar_t*> _setnameStrings;
wchar_t* _sysStrings[2048];
wchar_t numStrings[256][4];
wchar_t numBuffer[6];
wchar_t attBuffer[128];
wchar_t racBuffer[128];
wchar_t tpBuffer[128];
wchar_t scBuffer[128];
static wchar_t strBuffer[2048];
static const wchar_t* unknown_string;
static int CardReader(int, void*);
};
extern DataManager dataManager;
}
#endif // DATAMANAGER_H
This diff is collapsed.
#ifndef DECK_CON_H
#define DECK_CON_H
#include "config.h"
#include <unordered_map>
#include <vector>
#include "client_card.h"
namespace ygo {
class DeckBuilder: public irr::IEventReceiver {
public:
virtual bool OnEvent(const irr::SEvent& event);
void FilterCards();
long long filter_effect;
unsigned int filter_type;
unsigned int filter_type2;
unsigned int filter_attrib;
unsigned int filter_race;
unsigned int filter_atktype;
int filter_atk;
unsigned int filter_deftype;
int filter_def;
unsigned int filter_lvtype;
unsigned int filter_lv;
int filter_lm;
int hovered_code;
int hovered_pos;
int hovered_seq;
int click_pos;
bool is_draging;
int dragx;
int dragy;
size_t pre_mainc;
size_t pre_extrac;
size_t pre_sidec;
code_pointer draging_pointer;
std::unordered_map<int, int>* filterList;
std::vector<code_pointer> results;
wchar_t result_string[8];
};
}
#endif //DECK_CON
This diff is collapsed.
#ifndef DECKMANAGER_H
#define DECKMANAGER_H
#include "config.h"
#include "client_card.h"
#include <unordered_map>
#include <vector>
namespace ygo {
struct LFList {
unsigned int hash;
wchar_t listName[20];
std::unordered_map<int, int>* content;
};
struct Deck {
std::vector<code_pointer> main;
std::vector<code_pointer> extra;
std::vector<code_pointer> side;
Deck() {}
Deck(const Deck& ndeck) {
main = ndeck.main;
extra = ndeck.extra;
side = ndeck.side;
}
void clear() {
main.clear();
extra.clear();
side.clear();
}
};
class DeckManager {
public:
Deck current_deck;
std::vector<LFList> _lfList;
void LoadLFList();
wchar_t* GetLFListName(int lfhash);
int CheckLFList(Deck& deck, int lfhash, bool allow_ocg, bool allow_tcg);
void LoadDeck(Deck& deck, int* dbuf, int mainc, int sidec);
bool LoadSide(Deck& deck, int* dbuf, int mainc, int sidec);
bool LoadDeck(const wchar_t* file);
bool SaveDeck(Deck& deck, const wchar_t* name);
};
extern DeckManager deckManager;
}
#endif //DECKMANAGER_H
This diff is collapsed.
This diff is collapsed.
#ifndef DUELCLIENT_H
#define DUELCLIENT_H
#include "config.h"
#include <vector>
#include <set>
#include <event2/event.h>
#include <event2/listener.h>
#include <event2/bufferevent.h>
#include <event2/buffer.h>
#include <event2/thread.h>
#include "network.h"
#include "data_manager.h"
#include "deck_manager.h"
#include "../ocgcore/mtrandom.h"
namespace ygo {
class DuelClient {
private:
static unsigned int connect_state;
static unsigned char response_buf[64];
static unsigned char response_len;
static unsigned int watching;
static unsigned char selftype;
static bool is_host;
static event_base* client_base;
static bufferevent* client_bev;
static char duel_client_read[0x2000];
static char duel_client_write[0x2000];
static bool is_closing;
static int select_hint;
static wchar_t event_string[256];
static mtrandom rnd;
public:
static bool StartClient(unsigned int ip, unsigned short port, bool create_game = true);
static void ConnectTimeout(evutil_socket_t fd, short events, void* arg);
static void StopClient(bool is_exiting = false);
static void ClientRead(bufferevent* bev, void* ctx);
static void ClientEvent(bufferevent *bev, short events, void *ctx);
static int ClientThread(void* param);
static void HandleSTOCPacketLan(char* data, unsigned int len);
static int ClientAnalyze(char* msg, unsigned int len);
static void SetResponseI(int respI);
static void SetResponseB(unsigned char* respB, unsigned char len);
static void SendResponse();
static void SendPacketToServer(unsigned char proto) {
char* p = duel_client_write;
BufferIO::WriteInt16(p, 1);
BufferIO::WriteInt8(p, proto);
bufferevent_write(client_bev, duel_client_write, 3);
}
template<typename ST>
static void SendPacketToServer(unsigned char proto, ST& st) {
char* p = duel_client_write;
BufferIO::WriteInt16(p, 1 + sizeof(ST));
BufferIO::WriteInt8(p, proto);
memcpy(p, &st, sizeof(ST));
bufferevent_write(client_bev, duel_client_write, sizeof(ST) + 3);
}
static void SendBufferToServer(unsigned char proto, void* buffer, size_t len) {
char* p = duel_client_write;
BufferIO::WriteInt16(p, 1 + len);
BufferIO::WriteInt8(p, proto);
memcpy(p, buffer, len);
bufferevent_write(client_bev, duel_client_write, len + 3);
}
protected:
static bool is_refreshing;
static int match_kill;
static event* resp_event;
static std::set<unsigned int> remotes;
public:
static std::vector<HostPacket> hosts;
static void BeginRefreshHost();
static int RefreshThread(void* arg);
static void BroadcastReply(evutil_socket_t fd, short events, void* arg);
};
}
#endif //DUELCLIENT_H
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
project "clzma"
kind "StaticLib"
files { "**.c", "**.h" }
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Subproject commit 0a34f5dcb88617fb60902377193403947059ca90
Subproject commit 7a989d5606857aa3c68d8d25d257b0047da103c4
This diff is collapsed.
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