parent
4e03b15b27
commit
d8cc37afdb
@ -1,64 +0,0 @@
|
||||
#include "creature.h"
|
||||
#include "tibiadat.h"
|
||||
#include "graphics/graphics.h"
|
||||
#include <graphics/framebuffer.h>
|
||||
#include "game.h"
|
||||
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#include <GL/glext.h>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// OW BART TEM COMO USAR 2 FRAMEBUFFER?
|
||||
// SERIA O IDEAL PARA DESENHAR A COR DOS BONEQUIN.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Creature::Creature()
|
||||
{
|
||||
m_type = Thing::TYPE_CREATURE;
|
||||
}
|
||||
|
||||
ThingAttributes *Creature::getAttributes()
|
||||
{
|
||||
return g_tibiaDat.getCreatureAttributes(m_outfit.type);
|
||||
}
|
||||
|
||||
void Creature::draw(int x, int y)
|
||||
{
|
||||
//ThingAttributes *creatureAttributes = getAttributes();
|
||||
int anim = 0;
|
||||
|
||||
// draw outfit
|
||||
internalDraw(x, y, 0, m_direction, 0, 0, anim);
|
||||
|
||||
// draw addons
|
||||
//for(int a = 0; a < m_outfit.addons; ++a) {
|
||||
//internalDraw(x, y, 0, m_direction, m_outfit.addons & (1 << a), 0, anim);
|
||||
//}
|
||||
//glPushAttrib(GL_CURRENT_BIT | GL_COLOR_BUFFER_BIT);
|
||||
|
||||
//glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
//Color colors[4] = {Color::yellow, Color::red, Color::green, Color::blue};
|
||||
|
||||
//for(int i = 0; i < 4; ++i) {
|
||||
|
||||
|
||||
/*g_graphics.bindColor(colors[i]);
|
||||
internalDraw(creatureAttributes->width*32 - 32, creatureAttributes->height*32 - 32, 1, m_direction, 0, 0, 0);
|
||||
framebuffer.unbind();
|
||||
|
||||
|
||||
g_graphics.bindColor(Color::green);*/
|
||||
//framebuffer.draw(x, y, creatureAttributes->width*32, creatureAttributes->height*32);
|
||||
//}
|
||||
//glPopAttrib();
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
#ifndef CREATURE_H
|
||||
#define CREATURE_H
|
||||
|
||||
#include <global.h>
|
||||
#include "thing.h"
|
||||
|
||||
struct Outfit
|
||||
{
|
||||
uint16 type;
|
||||
uint8 head;
|
||||
uint8 body;
|
||||
uint8 legs;
|
||||
uint8 feet;
|
||||
uint8 addons;
|
||||
};
|
||||
|
||||
class Creature;
|
||||
typedef std::shared_ptr<Creature> CreaturePtr;
|
||||
|
||||
class Creature : public Thing
|
||||
{
|
||||
public:
|
||||
Creature();
|
||||
|
||||
virtual ThingAttributes *getAttributes();
|
||||
void draw(int x, int y);
|
||||
|
||||
void setName(const std::string& name) { m_name = name; }
|
||||
std::string getName() { return m_name; }
|
||||
|
||||
void setHealthPercent(uint8 healthPercent) { m_healthPercent = healthPercent; }
|
||||
uint8 getHealthPercent() { return m_healthPercent; }
|
||||
|
||||
void setDirection(Direction direction) { m_direction = direction; }
|
||||
Direction getDirection() { return m_direction; }
|
||||
|
||||
void setOutfit(const Outfit& outfit) { m_outfit = outfit; }
|
||||
Outfit getOutfit() { return m_outfit; }
|
||||
|
||||
virtual Creature *getCreature() { return this; }
|
||||
virtual const Creature *getCreature() const { return this; }
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
uint8 m_healthPercent;
|
||||
Direction m_direction;
|
||||
Outfit m_outfit;
|
||||
|
||||
};
|
||||
|
||||
#endif // CREATURE_H
|
@ -1,18 +0,0 @@
|
||||
#include "effect.h"
|
||||
#include "tibiadat.h"
|
||||
|
||||
Effect::Effect()
|
||||
{
|
||||
m_type = Thing::TYPE_EFFECT;
|
||||
}
|
||||
|
||||
ThingAttributes *Effect::getAttributes()
|
||||
{
|
||||
return g_tibiaDat.getEffectAttributes(m_id);
|
||||
}
|
||||
|
||||
void Effect::draw(int x, int y)
|
||||
{
|
||||
int anim = 0;
|
||||
internalDraw(x, y, 0, 0, 0, 0, anim);
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
#ifndef EFFECT_H
|
||||
#define EFFECT_H
|
||||
|
||||
#include <global.h>
|
||||
#include "thing.h"
|
||||
|
||||
class Effect;
|
||||
typedef std::shared_ptr<Effect> EffectPtr;
|
||||
|
||||
class Effect : public Thing
|
||||
{
|
||||
public:
|
||||
Effect();
|
||||
|
||||
virtual ThingAttributes *getAttributes();
|
||||
void draw(int x, int y);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif // EFFECT_H
|
@ -0,0 +1,9 @@
|
||||
#ifndef FRAMEWORK_CORE_DECLARATIONS_H
|
||||
#define FRAMEWORK_CORE_DECLARATIONS_H
|
||||
|
||||
#include <framework/global.h>
|
||||
|
||||
class Module;
|
||||
typedef std::shared_ptr<Module> ModulePtr;
|
||||
|
||||
#endif
|
@ -1,7 +1,7 @@
|
||||
#ifndef GRAPHICSDECLARATIONS_H
|
||||
#define GRAPHICSDECLARATIONS_H
|
||||
#ifndef FRAMEWORK_GRAPHICS_DECLARATIONS_H
|
||||
#define FRAMEWORK_GRAPHICS_DECLARATIONS_H
|
||||
|
||||
#include <global.h>
|
||||
#include <framework/global.h>
|
||||
|
||||
class Texture;
|
||||
class Font;
|
@ -1,10 +1,11 @@
|
||||
#ifndef LUADECLARATIONS_H
|
||||
#define LUADECLARATIONS_H
|
||||
#ifndef FRAMEWORK_LUA_DECLARATIONS_H
|
||||
#define FRAMEWORK_LUA_DECLARATIONS_H
|
||||
|
||||
#include <global.h>
|
||||
#include <framework/global.h>
|
||||
|
||||
class LuaInterface;
|
||||
class LuaObject;
|
||||
|
||||
typedef std::function<int(LuaInterface*)> LuaCppFunction;
|
||||
typedef std::unique_ptr<LuaCppFunction> LuaCppFunctionPtr;
|
||||
typedef std::shared_ptr<LuaObject> LuaObjectPtr;
|
@ -0,0 +1,17 @@
|
||||
#ifndef FRAMEWORK_NET_DECLARATIONS_H
|
||||
#define FRAMEWORK_NET_DECLARATIONS_H
|
||||
|
||||
#include <framework/global.h>
|
||||
#include <boost/asio.hpp>
|
||||
|
||||
namespace asio = boost::asio;
|
||||
|
||||
class Connection;
|
||||
class InputMessage;
|
||||
class OutputMessage;
|
||||
class Protocol;
|
||||
|
||||
typedef std::shared_ptr<Connection> ConnectionPtr;
|
||||
typedef std::shared_ptr<Protocol> ProtocolPtr;
|
||||
|
||||
#endif
|
@ -1,31 +0,0 @@
|
||||
#ifndef NETDECLARATIONS_H
|
||||
#define NETDECLARATIONS_H
|
||||
|
||||
#include <global.h>
|
||||
#include <boost/asio.hpp>
|
||||
|
||||
namespace asio = boost::asio;
|
||||
|
||||
class Connection;
|
||||
class InputMessage;
|
||||
class OutputMessage;
|
||||
class Protocol;
|
||||
|
||||
typedef std::shared_ptr<Connection> ConnectionPtr;
|
||||
typedef std::shared_ptr<Protocol> ProtocolPtr;
|
||||
|
||||
#define CIPSOFT_PUBLIC_RSA "1321277432058722840622950990822933849527763264961655079678763618" \
|
||||
"4334395343554449668205332383339435179772895415509701210392836078" \
|
||||
"6959821132214473291575712138800495033169914814069637740318278150" \
|
||||
"2907336840325241747827401343576296990629870233111328210165697754" \
|
||||
"88792221429527047321331896351555606801473202394175817"
|
||||
|
||||
|
||||
#define OTSERV_PUBLIC_RSA "1091201329673994292788609605089955415282375029027981291234687579" \
|
||||
"3726629149257644633073969600111060390723088861007265581882535850" \
|
||||
"3429057592827629436413108566029093628212635953836686562675849720" \
|
||||
"6207862794310902180176810615217550567108238764764442605581471797" \
|
||||
"07119674283982419152118103759076030616683978566631413"
|
||||
|
||||
|
||||
#endif
|
@ -1,7 +1,7 @@
|
||||
#ifndef OTMLDECLARATIONS_H
|
||||
#define OTMLDECLARATIONS_H
|
||||
#ifndef FRAMEWORK_OTML_DECLARATIONS_H
|
||||
#define FRAMEWORK_OTML_DECLARATIONS_H
|
||||
|
||||
#include <global.h>
|
||||
#include <framework/global.h>
|
||||
|
||||
class OTMLNode;
|
||||
class OTMLDocument;
|
@ -1,46 +0,0 @@
|
||||
#ifndef OTMLNODEEXT_H
|
||||
#define OTMLNODEEXT_H
|
||||
|
||||
#include <util/point.h>
|
||||
#include <util/color.h>
|
||||
#include <util/rect.h>
|
||||
#include <util/size.h>
|
||||
|
||||
//inline bool from_otmlnode(const OTMLNodePtr& node, Color& color)
|
||||
//{
|
||||
//int r, g, b, a;
|
||||
//r = node->readAt<int>(0);
|
||||
//g = node->readAt<int>(1);
|
||||
//b = node->readAt<int>(2);
|
||||
//a = 255;
|
||||
//if(node->hasChild(3))
|
||||
//a = node->readAt<int>(3);
|
||||
//return true;
|
||||
//}
|
||||
|
||||
//template <class T>
|
||||
//bool from_otmlnode(const OTMLNodePtr& node, TPoint<T>& point)
|
||||
//{
|
||||
//point.x = node->readAt<T>(0);
|
||||
//point.y = node->readAt<T>(1);
|
||||
//return true;
|
||||
//}
|
||||
|
||||
//template <class T>
|
||||
//bool from_otmlnode(const OTMLNodePtr& node, TSize<T>& size)
|
||||
//{
|
||||
//size.setSize(node->readAt<T>(0), node->readAt<T>(1));
|
||||
//return true;
|
||||
//}
|
||||
|
||||
//template <class T>
|
||||
//bool from_otmlnode(const OTMLNodePtr& node, TRect<T>& rect)
|
||||
//{
|
||||
//rect.setRect(node->readAt<int>(0),
|
||||
//node->readAt<int>(1),
|
||||
//node->readAt<int>(2),
|
||||
//node->readAt<int>(3));
|
||||
//return true;
|
||||
//}
|
||||
|
||||
#endif
|
@ -1,6 +0,0 @@
|
||||
#ifndef PCH_H
|
||||
#define PCH_H
|
||||
|
||||
#include "global.h"
|
||||
|
||||
#endif
|
@ -1,7 +1,7 @@
|
||||
#ifndef PLATFORM_H
|
||||
#define PLATFORM_H
|
||||
|
||||
#include <global.h>
|
||||
#include <framework/global.h>
|
||||
|
||||
class PlatformListener;
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef INPUTEVENT_H
|
||||
#define INPUTEVENT_H
|
||||
|
||||
#include <global.h>
|
||||
#include <framework/global.h>
|
||||
|
||||
enum InputKeyCode {
|
||||
KC_UNKNOWN = 0x00,
|
@ -1,7 +1,7 @@
|
||||
#ifndef PLATFORMLISTENER_H
|
||||
#define PLATFORMLISTENER_H
|
||||
|
||||
#include "inputevent.h"
|
||||
#include "platformevent.h"
|
||||
|
||||
class PlatformListener
|
||||
{
|
@ -0,0 +1,50 @@
|
||||
#ifndef FRAMEWORK_UI_CONST_H
|
||||
#define FRAMEWORK_UI_CONST_H
|
||||
|
||||
// namespace ui {
|
||||
|
||||
enum UIWidgetType {
|
||||
UITypeWidget = 0,
|
||||
UITypeLabel,
|
||||
UITypeButton,
|
||||
UITypeLineEdit,
|
||||
UITypeWindow,
|
||||
UITypeList
|
||||
};
|
||||
|
||||
enum FocusReason {
|
||||
MouseFocusReason = 0,
|
||||
TabFocusReason,
|
||||
ActiveFocusReason,
|
||||
OtherFocusReason
|
||||
};
|
||||
|
||||
enum MouseButton {
|
||||
MouseNoButton = 0,
|
||||
MouseLeftButton,
|
||||
MouseRightButton,
|
||||
MouseMidButton
|
||||
};
|
||||
|
||||
enum MouseWheelDirection {
|
||||
MouseNoWheel = 0,
|
||||
MouseWheelUp,
|
||||
MouseWheelDown
|
||||
};
|
||||
|
||||
enum KeyboardModifier {
|
||||
KeyboardNoModifier = 0,
|
||||
KeyboardCtrlModifier = 1,
|
||||
KeyboardAltModifier = 2,
|
||||
KeyboardShiftModifier = 4
|
||||
};
|
||||
|
||||
enum ButtonState {
|
||||
ButtonUp = 0,
|
||||
ButtonDown,
|
||||
ButtonHover
|
||||
};
|
||||
|
||||
// }
|
||||
|
||||
#endif
|
@ -0,0 +1,29 @@
|
||||
#ifndef FRAMEWORK_UI_DECLARATIONS_H
|
||||
#define FRAMEWORK_UI_DECLARATIONS_H
|
||||
|
||||
#include <framework/global.h>
|
||||
#include "const.h"
|
||||
|
||||
class UIManager;
|
||||
class UILayout;
|
||||
class UIAnchorLayout;
|
||||
class UIStyle;
|
||||
class UIWidget;
|
||||
class UILabel;
|
||||
class UIButton;
|
||||
class UILineEdit;
|
||||
class UIWindow;
|
||||
|
||||
typedef std::shared_ptr<UIWidget> UIWidgetPtr;
|
||||
typedef std::weak_ptr<UIWidget> UIWidgetWeakPtr;
|
||||
typedef std::deque<UIWidgetPtr> UIWidgetList;
|
||||
|
||||
typedef std::shared_ptr<UILayout> UILayoutPtr;
|
||||
typedef std::shared_ptr<UIAnchorLayout> UIAnchorLayoutPtr;
|
||||
typedef std::shared_ptr<UIStyle> UIStylePtr;
|
||||
typedef std::shared_ptr<UILabel> UILabelPtr;
|
||||
typedef std::shared_ptr<UIButton> UIButtonPtr;
|
||||
typedef std::shared_ptr<UILineEdit> UILineEditPtr;
|
||||
typedef std::shared_ptr<UIWindow> UIWindowPtr;
|
||||
|
||||
#endif
|
@ -1,70 +0,0 @@
|
||||
#ifndef UIDECLARATIONS_H
|
||||
#define UIDECLARATIONS_H
|
||||
|
||||
#include <global.h>
|
||||
|
||||
class UIManager;
|
||||
class UILayout;
|
||||
class UIAnchorLayout;
|
||||
class UIStyle;
|
||||
class UIWidget;
|
||||
class UILabel;
|
||||
class UIButton;
|
||||
class UILineEdit;
|
||||
class UIWindow;
|
||||
|
||||
typedef std::shared_ptr<UIWidget> UIWidgetPtr;
|
||||
typedef std::weak_ptr<UIWidget> UIWidgetWeakPtr;
|
||||
typedef std::deque<UIWidgetPtr> UIWidgetList;
|
||||
|
||||
typedef std::shared_ptr<UILayout> UILayoutPtr;
|
||||
typedef std::shared_ptr<UIAnchorLayout> UIAnchorLayoutPtr;
|
||||
typedef std::shared_ptr<UIStyle> UIStylePtr;
|
||||
typedef std::shared_ptr<UILabel> UILabelPtr;
|
||||
typedef std::shared_ptr<UIButton> UIButtonPtr;
|
||||
typedef std::shared_ptr<UILineEdit> UILineEditPtr;
|
||||
typedef std::shared_ptr<UIWindow> UIWindowPtr;
|
||||
|
||||
enum UIWidgetType {
|
||||
UITypeWidget = 0,
|
||||
UITypeLabel,
|
||||
UITypeButton,
|
||||
UITypeLineEdit,
|
||||
UITypeWindow,
|
||||
UITypeList
|
||||
};
|
||||
|
||||
enum FocusReason {
|
||||
MouseFocusReason = 0,
|
||||
TabFocusReason,
|
||||
ActiveFocusReason,
|
||||
OtherFocusReason
|
||||
};
|
||||
|
||||
enum MouseButton {
|
||||
MouseNoButton = 0,
|
||||
MouseLeftButton,
|
||||
MouseRightButton,
|
||||
MouseMidButton
|
||||
};
|
||||
|
||||
enum MouseWheelDirection {
|
||||
MouseNoWheel = 0,
|
||||
MouseWheelUp,
|
||||
MouseWheelDown
|
||||
};
|
||||
|
||||
enum KeyboardModifier {
|
||||
KeyboardNoModifier = 0,
|
||||
KeyboardCtrlModifier = 1,
|
||||
KeyboardAltModifier = 2,
|
||||
KeyboardShiftModifier = 4
|
||||
};
|
||||
|
||||
enum ButtonState {
|
||||
ButtonUp = 0,
|
||||
ButtonDown,
|
||||
ButtonHover
|
||||
};
|
||||
|
||||
#endif
|
@ -0,0 +1,32 @@
|
||||
#include "uilist.h"
|
||||
|
||||
UIList::UIList() : UIWidget(UITypeList)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void UIList::loadStyleFromOTML(const OTMLNodePtr& styleNode)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void UIList::render()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void UIList::onKeyPress(UIKeyEvent& event)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void UIList::onMousePress(UIMouseEvent& event)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void UIList::onMouseMove(UIMouseEvent& event)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
#ifndef UILIST_H
|
||||
#define UILIST_H
|
||||
|
||||
#include "uiwidget.h"
|
||||
|
||||
class UIList : public UIWidget
|
||||
{
|
||||
public:
|
||||
UIList();
|
||||
|
||||
virtual void loadStyleFromOTML(const OTMLNodePtr& styleNode);
|
||||
virtual void render();
|
||||
|
||||
protected:
|
||||
virtual void onKeyPress(UIKeyEvent& event);
|
||||
virtual void onMousePress(UIMouseEvent& event);
|
||||
virtual void onMouseMove(UIMouseEvent& event);
|
||||
|
||||
private:
|
||||
std::list<std::string> m_items;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,194 +0,0 @@
|
||||
#ifndef AUXILIARY_H
|
||||
#define AUXILIARY_H
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <exception>
|
||||
#include <cxxabi.h>
|
||||
|
||||
/// Namespace that contains auxiliary functions and templates
|
||||
namespace aux {
|
||||
/// Fill an ostream by concatenating args
|
||||
/// Usage:
|
||||
/// aux::fill_ostream(stream, a1, a2, ..., aN);
|
||||
inline void fill_ostream(std::ostringstream&) { }
|
||||
template<class T, class... Args>
|
||||
void fill_ostream(std::ostringstream& stream, const T& first, const Args&... rest) {
|
||||
stream << first;
|
||||
fill_ostream(stream, rest...);
|
||||
}
|
||||
|
||||
/// Makes a std::string by concatenating args
|
||||
/// Usage:
|
||||
/// std::string str = aux::make_string(a1, a2, ..., aN);
|
||||
template<class... T>
|
||||
std::string make_string(const T&... args) {
|
||||
std::ostringstream buf;
|
||||
fill_ostream(buf, args...);
|
||||
return buf.str();
|
||||
}
|
||||
|
||||
// used by dumper
|
||||
struct dump_util {
|
||||
~dump_util() { std::cout << std::endl; }
|
||||
template<class T>
|
||||
dump_util& operator<<(const T& v) {
|
||||
std::cout << v << " ";
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
/// Utility for dumping variables
|
||||
/// Usage:
|
||||
/// aux::dump << v1, v2, ..., vN;
|
||||
static const struct dumper {
|
||||
dumper() { }
|
||||
template<class T>
|
||||
dump_util operator<<(const T& v) const {
|
||||
dump_util d;
|
||||
d << v;
|
||||
return d;
|
||||
}
|
||||
} dump;
|
||||
|
||||
/// Utility for printing messages into stdout
|
||||
/// Usage:
|
||||
/// aux::print(v1, v2, ..., vN);
|
||||
template<class... T>
|
||||
void print(const T&... args) {
|
||||
std::ostringstream buf;
|
||||
fill_ostream(buf, args...);
|
||||
std::cout << buf.str();
|
||||
}
|
||||
|
||||
/// Same as aux::print but adds a new line at the end
|
||||
template<class... T>
|
||||
void println(const T&... args) {
|
||||
print(args...);
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
/// Demangle names for GNU g++ compiler
|
||||
inline std::string demangle_name(const char* name) {
|
||||
size_t len;
|
||||
int status;
|
||||
std::string ret;
|
||||
char* demangled = abi::__cxa_demangle(name, 0, &len, &status);
|
||||
if(demangled) {
|
||||
ret = demangled;
|
||||
free(demangled);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// Returns the name of a type
|
||||
/// e.g. aux::demangle_type<Foo*>() returns a string containing 'Foo*'
|
||||
template<typename T>
|
||||
std::string demangle_type() {
|
||||
return demangle_name(typeid(T).name());
|
||||
}
|
||||
|
||||
/// Cast a type to another type
|
||||
/// @return whether the conversion was successful or not
|
||||
template<typename T, typename R>
|
||||
bool cast(const T& in, R& out) {
|
||||
std::stringstream ss;
|
||||
ss << in;
|
||||
ss >> out;
|
||||
return !!ss && ss.eof();
|
||||
}
|
||||
|
||||
// cast a type to string
|
||||
template<typename T>
|
||||
bool cast(const T& in, std::string& out) {
|
||||
std::stringstream ss;
|
||||
ss << in;
|
||||
out = ss.str();
|
||||
return true;
|
||||
}
|
||||
|
||||
// cast string to string
|
||||
template<>
|
||||
inline bool cast(const std::string& in, std::string& out) {
|
||||
out = in;
|
||||
return true;
|
||||
}
|
||||
|
||||
// special cast from string to boolean
|
||||
template<>
|
||||
inline bool cast(const std::string& in, bool& b) {
|
||||
static std::string validNames[2][4] = {{"true","yes","on","1"}, {"false","no","off","0"}};
|
||||
bool ret = false;
|
||||
for(int i=0;i<4;++i) {
|
||||
if(in == validNames[0][i]) {
|
||||
b = true;
|
||||
ret = true;
|
||||
break;
|
||||
} else if(in == validNames[1][i]) {
|
||||
b = false;
|
||||
ret = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// special cast from boolean to string
|
||||
template<>
|
||||
inline bool cast(const bool& in, std::string& out) {
|
||||
out = (in ? "true" : "false");
|
||||
return true;
|
||||
}
|
||||
|
||||
// used by safe_cast
|
||||
class bad_cast : public std::bad_cast {
|
||||
public:
|
||||
virtual ~bad_cast() throw() { }
|
||||
template<class T, class R>
|
||||
void setWhat() {
|
||||
m_what = make_string("failed to cast value of type '", demangle_type<T>(),
|
||||
"' to type '", demangle_type<R>(), "'");
|
||||
}
|
||||
virtual const char* what() { return m_what.c_str(); }
|
||||
private:
|
||||
std::string m_what;
|
||||
};
|
||||
|
||||
/// Cast a type to another type, any error throws a aux::bad_cast_exception
|
||||
/// Usage:
|
||||
/// R r = aux::safe_cast<R>(t);
|
||||
template<typename R, typename T>
|
||||
R safe_cast(const T& t) {
|
||||
R r;
|
||||
if(!cast(t, r)) {
|
||||
bad_cast e;
|
||||
e.setWhat<T,R>();
|
||||
throw e;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/// Cast a type to another type, cast errors are ignored
|
||||
/// Usage:
|
||||
/// R r = aux::unsafe_cast<R>(t);
|
||||
template<typename R, typename T>
|
||||
R unsafe_cast(const T& t) {
|
||||
R r;
|
||||
try {
|
||||
r = safe_cast<R,T>(t);
|
||||
} catch(bad_cast& e) {
|
||||
println(e.what());
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
// an empty string to use anywhere needed
|
||||
const static std::string empty_string;
|
||||
}
|
||||
|
||||
// shortcut for aux::dump
|
||||
const static aux::dumper& dump = aux::dump;
|
||||
|
||||
#endif
|
@ -0,0 +1,195 @@
|
||||
#ifndef TOOLS_H
|
||||
#define TOOLS_H
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <exception>
|
||||
#include <cxxabi.h>
|
||||
|
||||
namespace fw {
|
||||
|
||||
/// Fill an ostream by concatenating args
|
||||
/// Usage:
|
||||
/// fw::fill_ostream(stream, a1, a2, ..., aN);
|
||||
inline void fill_ostream(std::ostringstream&) { }
|
||||
template<class T, class... Args>
|
||||
void fill_ostream(std::ostringstream& stream, const T& first, const Args&... rest) {
|
||||
stream << first;
|
||||
fill_ostream(stream, rest...);
|
||||
}
|
||||
|
||||
/// Makes a std::string by concatenating args
|
||||
/// Usage:
|
||||
/// std::string str = fw::mkstr(a1, a2, ..., aN);
|
||||
template<class... T>
|
||||
std::string mkstr(const T&... args) {
|
||||
std::ostringstream buf;
|
||||
fill_ostream(buf, args...);
|
||||
return buf.str();
|
||||
}
|
||||
|
||||
// used by dumper
|
||||
struct dump_util {
|
||||
~dump_util() { std::cout << std::endl; }
|
||||
template<class T>
|
||||
dump_util& operator<<(const T& v) {
|
||||
std::cout << v << " ";
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
/// Utility for dumping variables
|
||||
/// Usage:
|
||||
/// fw::dump << v1, v2, ..., vN;
|
||||
struct dumper {
|
||||
dumper() { }
|
||||
template<class T>
|
||||
dump_util operator<<(const T& v) const {
|
||||
dump_util d;
|
||||
d << v;
|
||||
return d;
|
||||
}
|
||||
};
|
||||
|
||||
/// Utility for printing messages into stdout
|
||||
/// Usage:
|
||||
/// fw::print(v1, v2, ..., vN);
|
||||
template<class... T>
|
||||
void print(const T&... args) {
|
||||
std::ostringstream buf;
|
||||
fill_ostream(buf, args...);
|
||||
std::cout << buf.str();
|
||||
}
|
||||
|
||||
/// Same as fw::print but adds a new line at the end
|
||||
template<class... T>
|
||||
void println(const T&... args) {
|
||||
print(args...);
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
/// Demangle names for GNU g++ compiler
|
||||
inline std::string demangle_name(const char* name) {
|
||||
size_t len;
|
||||
int status;
|
||||
std::string ret;
|
||||
char* demangled = abi::__cxa_demangle(name, 0, &len, &status);
|
||||
if(demangled) {
|
||||
ret = demangled;
|
||||
free(demangled);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// Returns the name of a type
|
||||
/// e.g. fw::demangle_type<Foo*>() returns a string containing 'Foo*'
|
||||
template<typename T>
|
||||
std::string demangle_type() {
|
||||
return demangle_name(typeid(T).name());
|
||||
}
|
||||
|
||||
/// Cast a type to another type
|
||||
/// @return whether the conversion was successful or not
|
||||
template<typename T, typename R>
|
||||
bool cast(const T& in, R& out) {
|
||||
std::stringstream ss;
|
||||
ss << in;
|
||||
ss >> out;
|
||||
return !!ss && ss.eof();
|
||||
}
|
||||
|
||||
// cast a type to string
|
||||
template<typename T>
|
||||
bool cast(const T& in, std::string& out) {
|
||||
std::stringstream ss;
|
||||
ss << in;
|
||||
out = ss.str();
|
||||
return true;
|
||||
}
|
||||
|
||||
// cast string to string
|
||||
template<>
|
||||
inline bool cast(const std::string& in, std::string& out) {
|
||||
out = in;
|
||||
return true;
|
||||
}
|
||||
|
||||
// special cast from string to boolean
|
||||
template<>
|
||||
inline bool cast(const std::string& in, bool& b) {
|
||||
static std::string validNames[2][4] = {{"true","yes","on","1"}, {"false","no","off","0"}};
|
||||
bool ret = false;
|
||||
for(int i=0;i<4;++i) {
|
||||
if(in == validNames[0][i]) {
|
||||
b = true;
|
||||
ret = true;
|
||||
break;
|
||||
} else if(in == validNames[1][i]) {
|
||||
b = false;
|
||||
ret = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// special cast from boolean to string
|
||||
template<>
|
||||
inline bool cast(const bool& in, std::string& out) {
|
||||
out = (in ? "true" : "false");
|
||||
return true;
|
||||
}
|
||||
|
||||
// used by safe_cast
|
||||
class bad_cast : public std::bad_cast {
|
||||
public:
|
||||
virtual ~bad_cast() throw() { }
|
||||
template<class T, class R>
|
||||
void setWhat() {
|
||||
m_what = mkstr("failed to cast value of type '", demangle_type<T>(),
|
||||
"' to type '", demangle_type<R>(), "'");
|
||||
}
|
||||
virtual const char* what() { return m_what.c_str(); }
|
||||
private:
|
||||
std::string m_what;
|
||||
};
|
||||
|
||||
/// Cast a type to another type, any error throws a fw::bad_cast_exception
|
||||
/// Usage:
|
||||
/// R r = fw::safe_cast<R>(t);
|
||||
template<typename R, typename T>
|
||||
R safe_cast(const T& t) {
|
||||
R r;
|
||||
if(!cast(t, r)) {
|
||||
bad_cast e;
|
||||
e.setWhat<T,R>();
|
||||
throw e;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/// Cast a type to another type, cast errors are ignored
|
||||
/// Usage:
|
||||
/// R r = fw::unsafe_cast<R>(t);
|
||||
template<typename R, typename T>
|
||||
R unsafe_cast(const T& t) {
|
||||
R r;
|
||||
try {
|
||||
r = safe_cast<R,T>(t);
|
||||
} catch(bad_cast& e) {
|
||||
println(e.what());
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
// an empty string to use anywhere needed
|
||||
const static std::string empty_string;
|
||||
|
||||
}
|
||||
|
||||
// shortcut for fw::dump
|
||||
const static fw::dumper dump;
|
||||
|
||||
#endif
|
@ -1,9 +1,14 @@
|
||||
#ifndef TRANSLATOR_H
|
||||
#define TRANSLATOR_H
|
||||
|
||||
#include <const.h>
|
||||
#include "../const.h"
|
||||
#include <string>
|
||||
|
||||
AlignmentFlag parseAlignment(std::string aligment);
|
||||
AnchorPoint parseAnchorPoint(const std::string& anchorPoint);
|
||||
namespace fw {
|
||||
|
||||
AlignmentFlag translateAlignment(std::string aligment);
|
||||
AnchorPoint translateAnchorPoint(const std::string& anchorPoint);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,8 +0,0 @@
|
||||
#include "game.h"
|
||||
|
||||
Game g_game;
|
||||
|
||||
Game::Game()
|
||||
{
|
||||
m_online = false;
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
#ifndef GAME_H
|
||||
#define GAME_H
|
||||
|
||||
#include <global.h>
|
||||
#include "map.h"
|
||||
#include "player.h"
|
||||
#include "protocolgame.h"
|
||||
|
||||
class Game
|
||||
{
|
||||
public:
|
||||
Game();
|
||||
|
||||
void setProtocol(ProtocolGamePtr protocolGame) { m_protocolGame = protocolGame; }
|
||||
ProtocolGamePtr getProtocol() { return m_protocolGame; }
|
||||
|
||||
Map *getMap() { return &m_map; }
|
||||
Player *getPlayer() { return &m_player; }
|
||||
|
||||
void setOnline(bool online) { m_online = online; }
|
||||
bool getOnline() { return m_online; }
|
||||
|
||||
private:
|
||||
Map m_map;
|
||||
Player m_player;
|
||||
ProtocolGamePtr m_protocolGame;
|
||||
bool m_online;
|
||||
|
||||
};
|
||||
|
||||
extern Game g_game;
|
||||
|
||||
#endif // GAME_H
|
@ -1,35 +0,0 @@
|
||||
#include "item.h"
|
||||
#include "tibiadat.h"
|
||||
#include "tibiaspr.h"
|
||||
#include <graphics/graphics.h>
|
||||
#include "thing.h"
|
||||
|
||||
Item::Item()
|
||||
{
|
||||
m_type = Thing::TYPE_ITEM;
|
||||
}
|
||||
|
||||
ThingAttributes *Item::getAttributes()
|
||||
{
|
||||
return g_tibiaDat.getItemAttributes(m_id);
|
||||
}
|
||||
|
||||
void Item::draw(int x, int y)
|
||||
{
|
||||
ThingAttributes *itemAttributes = getAttributes();
|
||||
|
||||
int xdiv = 0, ydiv = 0, zdiv = 0, anim = 0;
|
||||
|
||||
if(itemAttributes->group == THING_GROUP_SPLASH || itemAttributes->group == THING_GROUP_FLUID || itemAttributes->stackable) {
|
||||
//cDivX = subType % itemAttributes->xdiv;
|
||||
//cDivY = subType / itemAttributes->xdiv;
|
||||
}
|
||||
else if(!itemAttributes->moveable) {
|
||||
xdiv = m_position.x % itemAttributes->xdiv;
|
||||
ydiv = m_position.y % itemAttributes->ydiv;
|
||||
zdiv = m_position.z % itemAttributes->zdiv;
|
||||
}
|
||||
|
||||
for(int b = 0; b < itemAttributes->blendframes; b++)
|
||||
internalDraw(x, y, b, xdiv, ydiv, zdiv, anim);
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
#ifndef ITEM_H
|
||||
#define ITEM_H
|
||||
|
||||
#include <global.h>
|
||||
#include "thing.h"
|
||||
|
||||
class Item;
|
||||
typedef std::shared_ptr<Item> ItemPtr;
|
||||
|
||||
class Item : public Thing
|
||||
{
|
||||
public:
|
||||
Item();
|
||||
|
||||
virtual ThingAttributes *getAttributes();
|
||||
void draw(int x, int y);
|
||||
|
||||
void setCount(uint8 count) { m_count = count; }
|
||||
|
||||
virtual Item* getItem() { return this; }
|
||||
virtual const Item* getItem() const { return this; }
|
||||
|
||||
private:
|
||||
uint8 m_count;
|
||||
};
|
||||
|
||||
#endif // ITEM_H
|
@ -1,75 +0,0 @@
|
||||
#include "map.h"
|
||||
#include "game.h"
|
||||
#include <graphics/graphics.h>
|
||||
#include <graphics/framebuffer.h>
|
||||
|
||||
void Map::draw(int x, int y)
|
||||
{
|
||||
if(!m_framebuffer)
|
||||
m_framebuffer = FrameBufferPtr(new FrameBuffer(15*32, 11*32));
|
||||
|
||||
g_graphics.bindColor(Color::white);
|
||||
m_framebuffer->bind();
|
||||
|
||||
Position *playerPos = g_game.getPlayer()->getPosition();
|
||||
|
||||
// player is above 7
|
||||
if(playerPos->z <= 7) {
|
||||
|
||||
// player pos it 8-6. check if we can draw upper floors.
|
||||
bool draw = true;
|
||||
for(int jz = 6; jz >= 0; --jz) {
|
||||
Position coverPos = Position(playerPos->x-(6-jz), playerPos->y-(6-jz), jz);
|
||||
if(m_tiles[coverPos]) {
|
||||
if(m_tiles[coverPos]->getStackSize() > 0 && jz < playerPos->z) {
|
||||
draw = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int iz = 7; iz > 0; --iz) {
|
||||
|
||||
// +1 in draws cause 64x64 items may affect view.
|
||||
for(int ix = -7; ix < + 8+7; ++ix) {
|
||||
for(int iy = -5; iy < + 6+7; ++iy) {
|
||||
Position itemPos = Position(playerPos->x + ix, playerPos->y + iy, iz);
|
||||
//Position drawPos = Position(ix + 8, iy - playerPos->y + 6, iz);
|
||||
//logDebug("x: ", relativePos.x, " y: ", relativePos.y, " z: ", (int)relativePos.z);
|
||||
if(m_tiles[itemPos])
|
||||
m_tiles[itemPos]->draw((ix + 7 - (7-iz))*32, (iy + 5 - (7-iz))*32);
|
||||
}
|
||||
}
|
||||
|
||||
if(!draw)
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// draw effects
|
||||
for(auto it = m_effects.begin(), end = m_effects.end(); it != end; ++it) {
|
||||
Position *effectPos = (*it)->getPosition();
|
||||
(*it)->draw((effectPos->x - playerPos->x + 7) * 32, (effectPos->y - playerPos->y + 5) * 32);
|
||||
}
|
||||
|
||||
// debug draws
|
||||
g_graphics.drawBoundingRect(Rect(7*32, 5*32, 32, 32), Color::red);
|
||||
|
||||
m_framebuffer->unbind();
|
||||
|
||||
m_framebuffer->draw(x, y, g_graphics.getScreenSize().width(), g_graphics.getScreenSize().height());
|
||||
}
|
||||
|
||||
void Map::addThing(ThingPtr thing, uint8 stackpos)
|
||||
{
|
||||
if(thing->getType() == Thing::TYPE_ITEM || thing->getType() == Thing::TYPE_CREATURE) {
|
||||
if(!m_tiles[*thing->getPosition()]) {
|
||||
m_tiles[*thing->getPosition()] = TilePtr(new Tile());
|
||||
}
|
||||
|
||||
m_tiles[*thing->getPosition()]->addThing(thing, stackpos);
|
||||
}
|
||||
else if(thing->getType() == Thing::TYPE_EFFECT) {
|
||||
m_effects.push_back(thing);
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
#ifndef MAP_H
|
||||
#define MAP_H
|
||||
|
||||
#include "position.h"
|
||||
#include "tile.h"
|
||||
#include "effect.h"
|
||||
#include <graphics/graphicsdeclarations.h>
|
||||
#include <unordered_map>
|
||||
|
||||
class Map
|
||||
{
|
||||
public:
|
||||
void addThing(ThingPtr thing, uint8 stackpos = 0);
|
||||
|
||||
void draw(int x, int y);
|
||||
|
||||
FrameBufferPtr getFramebuffer() { return m_framebuffer; }
|
||||
|
||||
private:
|
||||
std::unordered_map<Position, TilePtr, PositionHash> m_tiles;
|
||||
std::list<ThingPtr> m_effects;
|
||||
|
||||
FrameBufferPtr m_framebuffer;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,278 +0,0 @@
|
||||
#include "otclient.h"
|
||||
|
||||
#include <core/modulemanager.h>
|
||||
#include <core/configmanager.h>
|
||||
#include <core/resourcemanager.h>
|
||||
#include <core/eventdispatcher.h>
|
||||
#include <luascript/luainterface.h>
|
||||
#include <core/platform.h>
|
||||
#include <graphics/graphics.h>
|
||||
#include <graphics/fontmanager.h>
|
||||
#include <ui/uimanager.h>
|
||||
#include <ui/uiwidget.h>
|
||||
#include <net/connection.h>
|
||||
|
||||
#include "protocolgame.h"
|
||||
#include "game.h"
|
||||
#include "map.h"
|
||||
|
||||
#define POLL_CYCLE_DELAY 10
|
||||
|
||||
OTClient g_client;
|
||||
|
||||
void OTClient::init(std::vector<std::string> args)
|
||||
{
|
||||
m_running = false;
|
||||
m_stopping = false;
|
||||
|
||||
// print client information
|
||||
logInfo("OTClient 0.2.0");
|
||||
|
||||
// initialize platform related stuff
|
||||
g_platform.init(this, "OTClient");
|
||||
|
||||
// initialize script environment
|
||||
g_lua.init();
|
||||
|
||||
// register otclient lua functions
|
||||
registerLuaFunctions();
|
||||
|
||||
// initialize resources
|
||||
g_resources.init(args[0].c_str());
|
||||
|
||||
// load configurations
|
||||
loadConfigurations();
|
||||
|
||||
// create the client window
|
||||
g_platform.createWindow(g_configs.get("window x"), g_configs.get("window y"),
|
||||
g_configs.get("window width"), g_configs.get("window height"),
|
||||
550, 450,
|
||||
g_configs.get("window maximized"));
|
||||
g_platform.setWindowTitle("OTClient");
|
||||
|
||||
// initialize graphics
|
||||
g_graphics.init();
|
||||
|
||||
// initialize event dispatcher
|
||||
g_dispatcher.init();
|
||||
|
||||
// initialize network
|
||||
//g_network.init();
|
||||
|
||||
// initialize the ui
|
||||
g_ui.init();
|
||||
|
||||
// discover and load modules
|
||||
g_modules.discoverAndLoadModules();
|
||||
|
||||
// now that everything is initialized, setup configurations
|
||||
setupConfigurations();
|
||||
|
||||
// now that everything is loaded, show the window
|
||||
g_platform.showWindow();
|
||||
}
|
||||
|
||||
void OTClient::run()
|
||||
{
|
||||
std::string fpsText;
|
||||
Size fpsTextSize;
|
||||
FontPtr defaultFont = g_fonts.getDefaultFont();
|
||||
int frameTicks = g_platform.getTicks();
|
||||
int lastFpsTicks = frameTicks;
|
||||
int lastPollTicks = frameTicks;
|
||||
int frameCount = 0;
|
||||
|
||||
m_stopping = false;
|
||||
m_running = true;
|
||||
|
||||
if(g_ui.getRootWidget()->getChildCount() == 0) {
|
||||
logError("ERROR: there is no root widgets to display, the app will close");
|
||||
m_stopping = true;
|
||||
}
|
||||
|
||||
// run the first poll
|
||||
poll();
|
||||
|
||||
while(!m_stopping) {
|
||||
frameTicks = g_platform.getTicks();
|
||||
|
||||
// calculate fps
|
||||
frameCount++;
|
||||
if(frameTicks - lastFpsTicks >= 1000) {
|
||||
fpsText = aux::make_string("FPS: ", frameCount);
|
||||
fpsTextSize = defaultFont->calculateTextRectSize(fpsText);
|
||||
frameCount = 0;
|
||||
lastFpsTicks = frameTicks;
|
||||
}
|
||||
|
||||
// poll events every POLL_CYCLE_DELAY
|
||||
// this delay exists to avoid massive polling thus increasing framerate
|
||||
if(frameTicks - lastPollTicks >= POLL_CYCLE_DELAY) {
|
||||
poll();
|
||||
lastPollTicks = frameTicks;
|
||||
}
|
||||
|
||||
// only render when the windows is visible
|
||||
if(g_platform.isWindowVisible()) {
|
||||
// render begin
|
||||
g_graphics.beginRender();
|
||||
|
||||
// render everything
|
||||
render();
|
||||
|
||||
// render fps
|
||||
defaultFont->renderText(fpsText, Point(g_graphics.getScreenSize().width() - fpsTextSize.width() - 10, 10));
|
||||
|
||||
// render end
|
||||
g_graphics.endRender();
|
||||
|
||||
// swap the old buffer with the new rendered
|
||||
g_platform.swapBuffers();
|
||||
} else {
|
||||
// sleeps until next poll to avoid massive cpu usage
|
||||
g_platform.sleep(POLL_CYCLE_DELAY+1);
|
||||
}
|
||||
}
|
||||
|
||||
m_stopping = false;
|
||||
m_running = false;
|
||||
}
|
||||
|
||||
void OTClient::terminate()
|
||||
{
|
||||
// hide the window because there is no render anymore
|
||||
g_platform.hideWindow();
|
||||
|
||||
// run modules unload event
|
||||
g_modules.unloadModules();
|
||||
|
||||
// terminate ui
|
||||
g_ui.terminate();
|
||||
|
||||
// release remaining lua object references
|
||||
g_lua.collectGarbage();
|
||||
|
||||
// poll remaining events
|
||||
poll();
|
||||
|
||||
// terminate network
|
||||
//g_network.terminate();
|
||||
|
||||
// terminate dispatcher
|
||||
g_dispatcher.terminate();
|
||||
|
||||
// terminate graphics
|
||||
g_graphics.terminate();
|
||||
|
||||
// save configurations
|
||||
saveConfigurations();
|
||||
|
||||
// release resources
|
||||
g_resources.terminate();
|
||||
|
||||
// terminate script environment
|
||||
g_lua.terminate();
|
||||
|
||||
// end platform related stuff
|
||||
g_platform.terminate();
|
||||
|
||||
}
|
||||
|
||||
void OTClient::exit()
|
||||
{
|
||||
// stops the main loop
|
||||
m_stopping = true;
|
||||
}
|
||||
|
||||
void OTClient::poll()
|
||||
{
|
||||
// poll platform events
|
||||
g_platform.poll();
|
||||
|
||||
// poll network events
|
||||
//g_network.poll();
|
||||
Connection::poll();
|
||||
|
||||
// poll dispatcher events
|
||||
g_dispatcher.poll();
|
||||
}
|
||||
|
||||
void OTClient::render()
|
||||
{
|
||||
if(g_game.getOnline())
|
||||
g_game.getMap()->draw(0, 0);
|
||||
|
||||
// everything is rendered by UI components
|
||||
g_ui.render();
|
||||
}
|
||||
|
||||
void OTClient::loadConfigurations()
|
||||
{
|
||||
// default window size
|
||||
int defWidth = 550;
|
||||
int defHeight = 450;
|
||||
|
||||
// sets default window configuration
|
||||
g_configs.set("window x", (g_platform.getDisplayWidth() - defWidth)/2);
|
||||
g_configs.set("window y", (g_platform.getDisplayHeight() - defHeight)/2);
|
||||
g_configs.set("window width", defWidth);
|
||||
g_configs.set("window height", defHeight);
|
||||
g_configs.set("window maximized", false);
|
||||
g_configs.set("vsync", true);
|
||||
|
||||
// loads user configuration
|
||||
if(!g_configs.load("config.otml"))
|
||||
logInfo("Using default configurations.");
|
||||
}
|
||||
|
||||
void OTClient::setupConfigurations()
|
||||
{
|
||||
// activate vertical synchronization?
|
||||
g_platform.setVerticalSync(g_configs.get("vsync"));
|
||||
}
|
||||
|
||||
void OTClient::saveConfigurations()
|
||||
{
|
||||
g_configs.set("window x", g_platform.getWindowX());
|
||||
g_configs.set("window y", g_platform.getWindowY());
|
||||
g_configs.set("window width", g_platform.getWindowWidth());
|
||||
g_configs.set("window height", g_platform.getWindowHeight());
|
||||
g_configs.set("window maximized", g_platform.isWindowMaximized());
|
||||
|
||||
// saves user configuration
|
||||
if(!g_configs.save())
|
||||
logError("ERROR: configurations are lost because it couldn't be saved");
|
||||
}
|
||||
|
||||
void OTClient::onClose()
|
||||
{
|
||||
if(m_onCloseCallback)
|
||||
m_onCloseCallback();
|
||||
else
|
||||
exit();
|
||||
}
|
||||
|
||||
void OTClient::onResize(const Size& size)
|
||||
{
|
||||
g_graphics.resize(size);
|
||||
g_ui.resize(size);
|
||||
}
|
||||
|
||||
void OTClient::onInputEvent(const InputEvent& event)
|
||||
{
|
||||
g_ui.inputEvent(event);
|
||||
|
||||
ProtocolGamePtr protocol = g_game.getProtocol();
|
||||
if(protocol) {
|
||||
if(event.type == EventKeyDown) {
|
||||
if(event.keycode == KC_UP)
|
||||
protocol->sendWalkNorth();
|
||||
if(event.keycode == KC_RIGHT)
|
||||
protocol->sendWalkEast();
|
||||
if(event.keycode == KC_DOWN)
|
||||
protocol->sendWalkSouth();
|
||||
if(event.keycode == KC_LEFT)
|
||||
protocol->sendWalkWest();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
#ifndef OTCLIENT_H
|
||||
#define OTCLIENT_H
|
||||
|
||||
#include <core/platformlistener.h>
|
||||
|
||||
class OTClient : public PlatformListener
|
||||
{
|
||||
public:
|
||||
/// Where everything begins...
|
||||
void init(std::vector<std::string> args);
|
||||
/// Main loop
|
||||
void run();
|
||||
/// Called when the client is terminating
|
||||
void terminate();
|
||||
|
||||
/// Stop running
|
||||
void exit();
|
||||
/// Poll platform, dispatcher and network events
|
||||
void poll();
|
||||
/// Render each frame
|
||||
void render();
|
||||
|
||||
/// Fired when user tryes to close the window
|
||||
void onClose();
|
||||
/// Fired when user resize the window
|
||||
void onResize(const Size& size);
|
||||
/// Fired on an user input event
|
||||
void onInputEvent(const InputEvent& event);
|
||||
|
||||
bool isRunning() const { return m_running; }
|
||||
|
||||
void setOnClose(const SimpleCallback& onCloseCallback) { m_onCloseCallback = onCloseCallback; }
|
||||
SimpleCallback getOnClose() const { return m_onCloseCallback; }
|
||||
|
||||
private:
|
||||
/// Set default configurations and load the user configurations
|
||||
void loadConfigurations();
|
||||
/// Use the loaded configurations to setup other classes
|
||||
void setupConfigurations();
|
||||
void saveConfigurations();
|
||||
|
||||
void registerLuaFunctions();
|
||||
|
||||
bool m_running;
|
||||
bool m_stopping;
|
||||
|
||||
SimpleCallback m_onCloseCallback;
|
||||
};
|
||||
|
||||
extern OTClient g_client;
|
||||
|
||||
#endif
|
@ -1,25 +0,0 @@
|
||||
#include "otclient.h"
|
||||
#include <luascript/luainterface.h>
|
||||
|
||||
#include "tibiadat.h"
|
||||
#include "tibiaspr.h"
|
||||
#include "protocollogin.h"
|
||||
#include "protocolgame.h"
|
||||
|
||||
void OTClient::registerLuaFunctions()
|
||||
{
|
||||
// easy typing _1, _2, ...
|
||||
using namespace std::placeholders;
|
||||
|
||||
g_lua.bindGlobalFunction("exit", std::bind(&OTClient::exit, &g_client));
|
||||
g_lua.bindGlobalFunction("setOnClose", std::bind(&OTClient::setOnClose, &g_client, _1));
|
||||
g_lua.bindGlobalFunction("importDat", std::bind(&TibiaDat::load, &g_tibiaDat, _1));
|
||||
g_lua.bindGlobalFunction("importSpr", std::bind(&TibiaSpr::load, &g_tibiaSpr, _1));
|
||||
|
||||
g_lua.registerClass<ProtocolLogin, Protocol>();
|
||||
g_lua.bindClassStaticFunction<ProtocolLogin>("create", &ProtocolLogin::create);
|
||||
g_lua.bindClassMemberFunction("login", &ProtocolLogin::login);
|
||||
g_lua.bindClassMemberFunction("cancel", &ProtocolLogin::cancel);
|
||||
|
||||
g_lua.registerClass<ProtocolGame, Protocol>();
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
#ifndef PCH_H
|
||||
#define PCH_H
|
||||
|
||||
#include "framework/global.h"
|
||||
#include "otclient/global.h"
|
||||
|
||||
#endif
|
@ -1,22 +0,0 @@
|
||||
#ifndef PLAYER_H
|
||||
#define PLAYER_H
|
||||
|
||||
#include "creature.h"
|
||||
|
||||
class Player : public Creature
|
||||
{
|
||||
public:
|
||||
void setDrawSpeed(uint16 drawSpeed) { m_drawSpeed = drawSpeed; }
|
||||
uint16 getDrawSpeed() { return m_drawSpeed; }
|
||||
|
||||
void setCanReportBugs(uint8 canReportBugs) { m_canReportBugs = (canReportBugs != 0); }
|
||||
bool getCanReportBugs() { return m_canReportBugs; }
|
||||
|
||||
private:
|
||||
|
||||
uint16 m_drawSpeed;
|
||||
bool m_canReportBugs;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
@ -1,38 +0,0 @@
|
||||
#ifndef POSITION_H
|
||||
#define POSITION_H
|
||||
|
||||
#include <global.h>
|
||||
|
||||
enum Direction
|
||||
{
|
||||
DIRECTION_NORTH,
|
||||
DIRECTION_EAST,
|
||||
DIRECTION_SOUTH,
|
||||
DIRECTION_WEST
|
||||
};
|
||||
|
||||
class Position
|
||||
{
|
||||
public:
|
||||
Position(uint16 x = 0, uint16 y = 0, uint8 z = 0) {
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->z = z;
|
||||
}
|
||||
|
||||
bool operator==(const Position& other) const { return other.x == x && other.y == y && other.z == z; }
|
||||
const Position operator+(const Position& other) const { return Position(other.x + x, other.y + y, other.z + z); }
|
||||
const Position operator-(const Position& other) const { return Position(other.x - x, other.y - y, other.z - z); }
|
||||
|
||||
uint16 x, y;
|
||||
uint8 z;
|
||||
};
|
||||
|
||||
struct PositionHash : public std::unary_function<Position, size_t>
|
||||
{
|
||||
size_t operator()(const Position& pos) const {
|
||||
return ((((pos.x * 65536) + pos.y) * 15) + pos.z) % (1 * 1000000);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
@ -1,99 +0,0 @@
|
||||
#include "protocolgame.h"
|
||||
#include "game.h"
|
||||
#include <net/rsa.h>
|
||||
|
||||
ProtocolGame::ProtocolGame()
|
||||
{
|
||||
m_checksumEnabled = false;
|
||||
g_game.setProtocol(ProtocolGamePtr(this));
|
||||
}
|
||||
|
||||
ProtocolGame::~ProtocolGame()
|
||||
{
|
||||
sendLogout();
|
||||
g_game.setProtocol(NULL);
|
||||
}
|
||||
|
||||
void ProtocolGame::login(const std::string& accountName, const std::string& accountPassword, uint32 ip, uint16 port, const std::string& characterName)
|
||||
{
|
||||
if(accountName.empty() || accountPassword.empty()) {
|
||||
callLuaField("onError", "You must enter an account name and password.");
|
||||
return;
|
||||
}
|
||||
|
||||
m_accountName = accountName;
|
||||
m_accountPassword = accountPassword;
|
||||
m_characterName = characterName;
|
||||
|
||||
char host[16];
|
||||
sprintf(host, "%d.%d.%d.%d", (uint8)ip, (uint8)(ip >> 8), (uint8)(ip >> 16), (uint8)(ip >> 24));
|
||||
|
||||
connect(host, port);
|
||||
}
|
||||
|
||||
void ProtocolGame::onConnect()
|
||||
{
|
||||
recv();
|
||||
}
|
||||
|
||||
void ProtocolGame::sendLoginPacket(uint32 timestamp, uint8 unknown)
|
||||
{
|
||||
OutputMessage oMsg;
|
||||
|
||||
oMsg.addU8(0x0A); // Protocol id
|
||||
oMsg.addU16(0x02); // OS
|
||||
oMsg.addU16(862); // Client version
|
||||
|
||||
oMsg.addU8(0); // First RSA byte must be 0x00 // 1
|
||||
|
||||
// Generete xtea key.
|
||||
m_xteaKey[0] = 432324;
|
||||
m_xteaKey[1] = 24324;
|
||||
m_xteaKey[2] = 423432;
|
||||
m_xteaKey[3] = 234324;
|
||||
|
||||
// Add xtea key
|
||||
oMsg.addU32(m_xteaKey[0]); // 5
|
||||
oMsg.addU32(m_xteaKey[1]); // 9
|
||||
oMsg.addU32(m_xteaKey[2]); // 13
|
||||
oMsg.addU32(m_xteaKey[3]); // 17
|
||||
|
||||
oMsg.addU8(0); // is gm set?
|
||||
oMsg.addString(m_accountName); // Account Name // 20
|
||||
oMsg.addString(m_characterName); // Character Name // 22
|
||||
oMsg.addString(m_accountPassword); // Password // 24
|
||||
|
||||
oMsg.addU32(timestamp); // 28
|
||||
oMsg.addU8(unknown); // 29
|
||||
|
||||
// Packet data must have since byte 0, start, 128 bytes
|
||||
oMsg.addPaddingBytes(128 - (29 + m_accountName.length() + m_characterName.length() + m_accountPassword.length()));
|
||||
|
||||
// Encrypt msg with RSA
|
||||
if(!Rsa::encrypt((char*)oMsg.getBuffer() + 6 + oMsg.getMessageSize() - 128, 128, OTSERV_PUBLIC_RSA))
|
||||
return;
|
||||
|
||||
send(oMsg);
|
||||
|
||||
m_xteaEncryptionEnabled = true;
|
||||
|
||||
recv();
|
||||
}
|
||||
|
||||
void ProtocolGame::onRecv(InputMessage& inputMessage)
|
||||
{
|
||||
static bool firstRecv = true;
|
||||
if(firstRecv) {
|
||||
inputMessage.skipBytes(3);
|
||||
uint32 timestamp = inputMessage.getU32();
|
||||
uint8 unknown = inputMessage.getU8();
|
||||
|
||||
m_checksumEnabled = true;
|
||||
sendLoginPacket(timestamp, unknown);
|
||||
|
||||
firstRecv = false;
|
||||
}
|
||||
else {
|
||||
parseMessage(inputMessage);
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue