├── LICENSE ├── README.md └── src ├── ad2d.cpp ├── ad2d.h ├── adal.cpp ├── adal.h ├── allocator.cpp ├── allocator.h ├── backtrace.cpp ├── backtrace.h ├── battle.cpp ├── battle.h ├── bot.cpp ├── bot.h ├── channel.cpp ├── channel.h ├── const.h ├── container.cpp ├── container.h ├── cooldowns.cpp ├── cooldowns.h ├── craftbox.cpp ├── craftbox.h ├── creature.cpp ├── creature.h ├── distance.cpp ├── distance.h ├── empty.cpp ├── empty.h ├── filemanager.cpp ├── filemanager.h ├── game.cpp ├── game.h ├── glext.h ├── guimanager.cpp ├── guimanager.h ├── icons.cpp ├── icons.h ├── iniloader.cpp ├── iniloader.h ├── input.cpp ├── input.h ├── item.cpp ├── item.h ├── light.cpp ├── light.h ├── logger.cpp ├── logger.h ├── luascript.cpp ├── luascript.h ├── magiceffect.cpp ├── magiceffect.h ├── main.cpp ├── map.cpp ├── map.h ├── messages.cpp ├── messages.h ├── minimap.cpp ├── minimap.h ├── mthread.cpp ├── mthread.h ├── network.cpp ├── network.h ├── particle.cpp ├── particle.h ├── player.cpp ├── player.h ├── position.cpp ├── position.h ├── protocol.cpp ├── protocol.h ├── protocol822.cpp ├── protocol822.h ├── protocol840.cpp ├── protocol840.h ├── protocol842.cpp ├── protocol842.h ├── protocol850.cpp ├── protocol850.h ├── protocol854.cpp ├── protocol854.h ├── protocol860.cpp ├── protocol860.h ├── protocol870.cpp ├── protocol870.h ├── protocol910.cpp ├── protocol910.h ├── questlog.cpp ├── questlog.h ├── realtime.cpp ├── realtime.h ├── rsa.cpp ├── rsa.h ├── servers.cpp ├── servers.h ├── shop.cpp ├── shop.h ├── sound.cpp ├── sound.h ├── status.cpp ├── status.h ├── text.cpp ├── text.h ├── thing.cpp ├── thing.h ├── tools.cpp ├── tools.h ├── trade.cpp ├── trade.h ├── updater.cpp ├── updater.h ├── versioner.cpp ├── versioner.h ├── viplist.cpp ├── viplist.h ├── window.cpp └── window.h /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Nakeib 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RonClient 2 | RonClient is an open-source RPG client written in C++ using WinAPI. It was developed to be used with Open Tibia Server protocol, but it is possible to adapt the client to any other protocol. 3 | 4 | Features 5 | -------- 6 | 7 | 1) DirectX9 and OpenGL graphics libraries. 8 | 2) Lua scripts engine integrated. 9 | 3) Configurable GUI with possibility to customize using lua scripting. 10 | 4) Built-in Tibia protocols (822, 840, 842, 850, 854, 860, 870, 910). 11 | 5) Customizable extended protocol using lua scripting. 12 | 6) In game sounds triggered on effects, different background music during the day, night and under the ground. 13 | 7) Particles triggered on effects. 14 | 8) Auto updater 15 | 16 | Dependencies 17 | ------------ 18 | 19 | - alut 20 | - bfd 21 | - bgd 22 | - boost_regex 23 | - boost_system 24 | - boost_thread 25 | - d3d9 26 | - d3dx9 27 | - glaux 28 | - glu32 29 | - gmp 30 | - iberty 31 | - iconv 32 | - intl 33 | - imagehlp 34 | - lua (5.1) 35 | - lzma920 36 | - mpg123 37 | - openal32 38 | - opengl32 39 | - ws2_32 40 | - wsock2 41 | - winmm 42 | -------------------------------------------------------------------------------- /src/ad2d.h: -------------------------------------------------------------------------------- 1 | // Module: 2D graphics 2 | // Company: RonIT 3 | // Coder: Adam Czupryna 4 | 5 | 6 | #ifndef _AD2D_H 7 | #define _AD2D_H 8 | 9 | #define GL_GLEXT_PROTOTYPES 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | #include 19 | #include "glext.h" 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #pragma comment(lib,"opengl32.lib") 26 | #pragma comment(lib,"glu32.lib") 27 | #pragma comment(lib,"glaux.lib") 28 | #pragma comment(lib,"libbgd.lib") 29 | 30 | #pragma comment(lib, "d3d9.lib") 31 | 32 | 33 | class AD2D_Window; 34 | class AD2D_Viewport; 35 | class AD2D_Image; 36 | 37 | 38 | enum APIMode { 39 | API_OPENGL = 0, 40 | API_DIRECT3D = 1, 41 | }; 42 | 43 | 44 | enum BLEND { 45 | BLEND_NONE = 0, 46 | BLEND_ZERO = 1, 47 | BLEND_ONE = 2, 48 | BLEND_SRCCOLOR = 3, 49 | BLEND_INVSRCCOLOR = 4, 50 | BLEND_SRCALPHA = 5, 51 | BLEND_INVSRCALPHA = 6, 52 | BLEND_DSTCOLOR = 7, 53 | BLEND_INVDSTCOLOR = 8, 54 | BLEND_DSTALPHA = 9, 55 | BLEND_INVDSTALPHA = 10, 56 | }; 57 | 58 | 59 | struct COLOR { 60 | float red; 61 | float green; 62 | float blue; 63 | float alpha; 64 | 65 | COLOR() { red = 0.0f; green = 0.0f; blue = 0.0f; alpha = 0.0f; } 66 | COLOR(float r, float g, float b, float a = 1.0f) : red(r), green(g), blue(b), alpha(a) { }; 67 | }; 68 | 69 | struct D3DCUSTOMVERTEX { 70 | FLOAT x, y, z, rhw; 71 | DWORD color; 72 | FLOAT u, v; 73 | }; 74 | 75 | 76 | class AD2D_Image { 77 | private: 78 | unsigned short realWidth; 79 | unsigned short realHeight; 80 | unsigned short virtualWidth; 81 | unsigned short virtualHeight; 82 | 83 | float TexOffsetX; 84 | float TexOffsetY; 85 | 86 | public: 87 | GLuint texture; 88 | LPDIRECT3DTEXTURE9 textureD3D; 89 | LPDIRECT3DSURFACE9 surfaceD3D; 90 | 91 | public: 92 | AD2D_Image(); 93 | ~AD2D_Image(); 94 | 95 | void AdjustSize(unsigned short width, unsigned short height); 96 | 97 | void Create(unsigned short width, unsigned short height, GLuint texdata); 98 | void Create(unsigned short width, unsigned short height, LPDIRECT3DTEXTURE9 texdata); 99 | void Create(unsigned short width, unsigned short height, unsigned char* data); 100 | void CreateBMP(const char* path); 101 | void CreateBMP_(unsigned char* data, long int size); 102 | void CreatePNG(const char* path); 103 | void CreatePNG_(unsigned char* data, long int size); 104 | void CreateGNP(const char* path); 105 | void CreateGNP_(unsigned char* data, long int size); 106 | void CreateAlphaMask(unsigned char r, unsigned char g, unsigned char b, unsigned char tolerance); 107 | void Update(unsigned char* data); 108 | unsigned char* GetData(unsigned char* data); 109 | 110 | unsigned short GetWidth(); 111 | unsigned short GetHeight(); 112 | 113 | friend class AD2D_Window; 114 | friend class AD2D_Font; 115 | }; 116 | 117 | class AD2D_Font : public AD2D_Image { 118 | private: 119 | unsigned short realSize; 120 | std::map widthMap; 121 | 122 | public: 123 | void ReadWidthMap(const char* path); 124 | void ReadWidthMap_(unsigned char* data, long int size); 125 | int GetCharWidth(unsigned char key); 126 | float GetCharWidth(unsigned char key, float fontSize); 127 | float GetTextWidth(std::string text, float fontSize); 128 | int GetTextWidthCharNumber(std::string text, float fontSize, float width); 129 | 130 | friend class AD2D_Window; 131 | }; 132 | 133 | 134 | class AD2D_Viewport { 135 | public: 136 | int startX; 137 | int startY; 138 | int width; 139 | int height; 140 | 141 | public: 142 | AD2D_Viewport(); 143 | void Create(int tX, int tY, int bX, int bY); 144 | 145 | bool operator==(AD2D_Viewport& vp); 146 | bool operator!=(AD2D_Viewport& vp); 147 | 148 | friend class AD2D_Window; 149 | }; 150 | 151 | 152 | class AD2D_Window { 153 | private: 154 | HWND* _HWND; 155 | HDC _HDC; 156 | HGLRC _HRC; 157 | 158 | LPDIRECT3D9 _D3D; 159 | LPDIRECT3DDEVICE9 _D3DDEV; 160 | LPDIRECT3DVERTEXBUFFER9 _D3DVB; 161 | LPDIRECT3DSWAPCHAIN9 _D3DSwapChain; 162 | LPDIRECT3DSURFACE9 _D3DBackBuffer; 163 | 164 | int _PosX; 165 | int _PosY; 166 | unsigned short _ResX; 167 | unsigned short _ResY; 168 | unsigned char _BPP; 169 | 170 | bool _minimized; 171 | bool _maximized; 172 | 173 | AD2D_Viewport _currentViewport; 174 | 175 | public: 176 | static COLOR _currentColor; 177 | 178 | static APIMode _mode; 179 | static AD2D_Window* _window; 180 | 181 | public: 182 | AD2D_Window(); 183 | AD2D_Window(HWND& hWnd, int PosX, int PosY, unsigned short ResX, unsigned short ResY, unsigned char BPP, APIMode mode = API_OPENGL); 184 | ~AD2D_Window(); 185 | 186 | void Create(HWND& hWnd, int PosX, int PosY, unsigned short ResX, unsigned short ResY, unsigned char BPP, APIMode mode = API_OPENGL); 187 | void Release(); 188 | 189 | HDC GetHDC(); 190 | HGLRC GetHRC(); 191 | LPDIRECT3D9 GetD3D(); 192 | LPDIRECT3DDEVICE9 GetD3DDEV(); 193 | LPDIRECT3DVERTEXBUFFER9 GetD3DVB(); 194 | LPDIRECT3DSURFACE9 GetD3DBackBuffer(); 195 | 196 | void SetMaximized(bool state); 197 | bool GetMaximized(); 198 | void SetMinimized(bool state); 199 | bool GetMinimized(); 200 | 201 | static AD2D_Window* GetPointer(); 202 | 203 | POINT GetWindowPos(); 204 | POINT GetWindowSize(); 205 | void MoveWindow(int PosX, int PosY); 206 | void ResizeWindow(unsigned short ResX, unsigned short ResY); 207 | 208 | void SetViewport(int startX, int startY, int width, int height); 209 | void SetViewport(AD2D_Viewport& viewport); 210 | AD2D_Viewport GetCurrentViewport(); 211 | void PutPoint(float x, float y, float size = 1.0f); 212 | void PutLine(float x1, float y1, float x2, float y2, float size = 1.0f); 213 | void PutRect(float x1, float y1, float x2, float y2); 214 | void PutImage(int x, int y, AD2D_Image& image, unsigned int sampler = 0); 215 | void PutImage(float xs, float ys, float xf, float yf, AD2D_Image& image, unsigned int sampler = 0); 216 | void RotImage(float x, float y, float rad, float zoom, AD2D_Image& image, unsigned int sampler = 0); 217 | void Print(float x, float y, float size, AD2D_Font& font, const char* str, bool border = false); 218 | void PPrint(float x, float y, float size, AD2D_Font& font, const char* str, bool border = false, ...); 219 | void CPrint(float x, float y, float size, AD2D_Font& font, const char* str, const char* color, bool border = false); 220 | void ClearBuffers(); 221 | void SwapBuffers(); 222 | 223 | void ScreenShot(const char* path); 224 | 225 | static void SetBlendFunc(int BlendSrc, int BlendDst); 226 | static void SetColor(float R, float G, float B, float alpha = 1.0f); 227 | static COLOR GetColor(); 228 | static void SetColorSTD(unsigned char color, float alpha = 1.0f); 229 | static COLOR ConvertColorSTD(unsigned char color); 230 | 231 | static COLOR STD2RGB(unsigned char color); 232 | }; 233 | 234 | 235 | #endif 236 | -------------------------------------------------------------------------------- /src/adal.cpp: -------------------------------------------------------------------------------- 1 | #ifndef NO_SOUND 2 | 3 | #include "adal.h" 4 | 5 | #include "allocator.h" 6 | 7 | #include "tools.h" 8 | 9 | 10 | // ---- ADAL_System ---- // 11 | 12 | ADAL_System::ADAL_System() { 13 | alutInit(NULL,0); 14 | alGetError(); 15 | 16 | SetListenerGain(1.0f); 17 | SetListenerPosition(0.0f, 0.0f, 0.0f); 18 | SetListenerVelocity(0.0f, 0.0f, 0.0f); 19 | SetListenerOrientation(0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f); 20 | } 21 | 22 | ADAL_System::~ADAL_System() { 23 | alutExit(); 24 | } 25 | 26 | void ADAL_System::SetListenerGain(ALfloat g) { 27 | gain = g; 28 | 29 | alListenerf(AL_GAIN, gain); 30 | } 31 | 32 | void ADAL_System::SetListenerPosition(ALfloat x, ALfloat y, ALfloat z) { 33 | listenerPosition[0] = x; 34 | listenerPosition[1] = y; 35 | listenerPosition[2] = z; 36 | 37 | alListenerfv(AL_POSITION, listenerPosition); 38 | } 39 | 40 | void ADAL_System::SetListenerVelocity(ALfloat x, ALfloat y, ALfloat z) { 41 | listenerVelocity[0] = x; 42 | listenerVelocity[1] = y; 43 | listenerVelocity[2] = z; 44 | 45 | alListenerfv(AL_VELOCITY, listenerVelocity); 46 | } 47 | 48 | void ADAL_System::SetListenerOrientation(ALfloat ax, ALfloat ay, ALfloat az, ALfloat bx, ALfloat by, ALfloat bz) { 49 | listenerOrientation[0] = ax; 50 | listenerOrientation[1] = ay; 51 | listenerOrientation[2] = az; 52 | listenerOrientation[3] = bx; 53 | listenerOrientation[4] = by; 54 | listenerOrientation[5] = bz; 55 | 56 | alListenerfv(AL_ORIENTATION, listenerOrientation); 57 | } 58 | 59 | 60 | // ---- ADAL_Sample ---- // 61 | 62 | ADAL_Sample::ADAL_Sample() { 63 | buffer = 0; 64 | } 65 | 66 | ADAL_Sample::~ADAL_Sample() { 67 | if (buffer) 68 | alDeleteBuffers(1, &buffer); 69 | } 70 | 71 | void ADAL_Sample::Create(ALenum format, ALsizei size, ALsizei freq, ALvoid* data) { 72 | if (buffer) 73 | alDeleteBuffers(1, &buffer); 74 | 75 | alGenBuffers(1, &buffer); 76 | alBufferData(buffer, format, data, size, freq); 77 | } 78 | 79 | void ADAL_Sample::CreateWAV(const char* path) { 80 | ALenum format; 81 | ALsizei size; 82 | ALsizei freq; 83 | ALvoid* data; 84 | ALboolean loop; 85 | 86 | alutLoadWAVFile((ALbyte*)path, &format, &data, &size, &freq, &loop); 87 | Create(format, size, freq, data); 88 | alutUnloadWAV(format, data, size, freq); 89 | } 90 | 91 | void ADAL_Sample::CreateWAV_(unsigned char* data, long int size) { 92 | if (!data) 93 | return; 94 | 95 | ALenum format; 96 | ALsizei wsize; 97 | ALsizei freq; 98 | ALvoid* wdata; 99 | ALboolean loop; 100 | 101 | alutLoadWAVMemory((ALbyte*)buffer, &format, &wdata, &wsize, &freq, &loop); 102 | Create(format, wsize, freq, wdata); 103 | alutUnloadWAV(format, wdata, wsize, freq); 104 | 105 | delete[] data; 106 | } 107 | 108 | void ADAL_Sample::CreateMP3(const char* path) { 109 | int error = MPG123_OK; 110 | mpg123_handle *mh = NULL; 111 | 112 | error = mpg123_init(); 113 | mh = mpg123_new(NULL, &error); 114 | error = mpg123_open(mh, path); 115 | 116 | int channels; 117 | int encoding; 118 | long freq; 119 | mpg123_getformat(mh, &freq, &channels, &encoding); 120 | size_t size = mpg123_length(mh); 121 | 122 | size_t blocksize = mpg123_outblock(mh); 123 | 124 | unsigned char* data = new unsigned char[size * channels * 2]; 125 | unsigned char* block = new unsigned char[blocksize]; 126 | 127 | size_t done = 0; 128 | size_t read = 0; 129 | do { 130 | error = mpg123_read(mh, block, blocksize, &read); 131 | if (done + read > size * channels * 2) 132 | read = (size * channels * 2) - done; 133 | memcpy(data + done, block, read); 134 | done += read; 135 | } while(error != MPG123_DONE); 136 | size = done; 137 | 138 | delete[] block; 139 | 140 | ALenum format; 141 | if (channels == 1) 142 | format = AL_FORMAT_MONO16; 143 | else 144 | format = AL_FORMAT_STEREO16; 145 | 146 | Create(format, (ALsizei)size, (ALsizei)freq, (ALvoid*)data); 147 | 148 | delete[] data; 149 | 150 | mpg123_close(mh); 151 | mpg123_delete(mh); 152 | mpg123_exit(); 153 | } 154 | 155 | void ADAL_Sample::CreateMP3_(unsigned char* data, long int size) { 156 | if (!data) 157 | return; 158 | 159 | int error = MPG123_OK; 160 | mpg123_handle *mh = NULL; 161 | 162 | error = mpg123_init(); 163 | mh = mpg123_new(NULL, &error); 164 | mpg123_open_feed(mh); 165 | mpg123_feed(mh, data, size); 166 | 167 | size_t bufferSize = 1048576; 168 | unsigned char* wdata = new unsigned char[bufferSize]; 169 | unsigned char* block = new unsigned char[4096]; 170 | 171 | size_t done = 0; 172 | size_t read = 0; 173 | do { 174 | error = mpg123_decode(mh, NULL, 0, block, 4096, &read); 175 | if (done + read > bufferSize) { 176 | bufferSize *= 10; 177 | unsigned char* newData = new unsigned char[bufferSize]; 178 | memcpy(newData, wdata, done); 179 | delete[] wdata; 180 | wdata = newData; 181 | } 182 | memcpy(wdata + done, block, read); 183 | done += read; 184 | } while(error != MPG123_NEED_MORE); 185 | 186 | delete[] block; 187 | 188 | delete[] data; 189 | 190 | int channels; 191 | int encoding; 192 | long freq; 193 | mpg123_getformat(mh, &freq, &channels, &encoding); 194 | 195 | ALenum format; 196 | if (channels == 1) 197 | format = AL_FORMAT_MONO16; 198 | else 199 | format = AL_FORMAT_STEREO16; 200 | 201 | Create(format, (ALsizei)done, (ALsizei)freq, (ALvoid*)wdata); 202 | 203 | delete[] wdata; 204 | 205 | mpg123_close(mh); 206 | mpg123_delete(mh); 207 | mpg123_exit(); 208 | } 209 | 210 | 211 | // ---- ADAL_Sound ---- // 212 | 213 | ADAL_Sound::ADAL_Sound() { 214 | source = 0; 215 | 216 | position[0] = 0.0f; 217 | position[1] = 0.0f; 218 | position[2] = 0.0f; 219 | 220 | velocity[0] = 0.0f; 221 | velocity[1] = 0.0f; 222 | velocity[2] = 0.0f; 223 | } 224 | 225 | ADAL_Sound::~ADAL_Sound() { 226 | if (source) 227 | alDeleteSources(1, &source); 228 | } 229 | 230 | bool ADAL_Sound::Create(ADAL_Sample sample, ALfloat pitch, ALfloat gain, ALboolean loop) { 231 | if (source) 232 | alDeleteSources(1, &source); 233 | 234 | alGenSources(1, &source); 235 | if (!source) 236 | return false; 237 | 238 | alSourcei(source, AL_BUFFER, sample.buffer); 239 | alSourcef(source, AL_PITCH, pitch); 240 | alSourcef(source, AL_GAIN, gain); 241 | alSourcefv(source, AL_POSITION, position); 242 | alSourcefv(source, AL_VELOCITY, velocity); 243 | alSourcef(source, AL_ROLLOFF_FACTOR, 0.5f); 244 | alSourcei(source, AL_LOOPING, loop); 245 | 246 | return true; 247 | } 248 | 249 | void ADAL_Sound::SetGain(ALfloat gain) { 250 | alSourcef(source, AL_GAIN, gain); 251 | } 252 | 253 | void ADAL_Sound::SetPosition(ALfloat x, ALfloat y, ALfloat z) { 254 | position[0] = x; 255 | position[1] = y; 256 | position[2] = z; 257 | 258 | alSourcefv(source, AL_POSITION, position); 259 | } 260 | 261 | void ADAL_Sound::SetVelocity(ALfloat x, ALfloat y, ALfloat z) { 262 | velocity[0] = x; 263 | velocity[1] = y; 264 | velocity[2] = z; 265 | 266 | alSourcefv(source, AL_VELOCITY, velocity); 267 | } 268 | 269 | ALuint ADAL_Sound::GetBuffer() { 270 | ALint buffer; 271 | alGetSourcei(source, AL_BUFFER, &buffer); 272 | 273 | return buffer; 274 | } 275 | 276 | bool ADAL_Sound::IsPlaying() { 277 | ALint state; 278 | alGetSourcei(source, AL_SOURCE_STATE, &state); 279 | 280 | if (state == AL_PLAYING) 281 | return true; 282 | 283 | return false; 284 | } 285 | 286 | void ADAL_Sound::Play() { 287 | alSourcePlay(source); 288 | } 289 | 290 | void ADAL_Sound::Stop() { 291 | alSourceStop(source); 292 | } 293 | 294 | void ADAL_Sound::WaitTillPlaying(int checkInterval) { 295 | ALint state = AL_PLAYING; 296 | do { 297 | Sleep(checkInterval); 298 | alGetSourcei(source, AL_SOURCE_STATE, &state); 299 | } while(state == AL_PLAYING); 300 | } 301 | 302 | #endif //NO_SOUND 303 | -------------------------------------------------------------------------------- /src/adal.h: -------------------------------------------------------------------------------- 1 | #ifndef NO_SOUND 2 | 3 | #ifndef _ADAL_H 4 | #define _ADAL_H 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | class ADAL_Sample; 16 | class ADAL_Sound; 17 | 18 | class ADAL_System { 19 | private: 20 | ALfloat gain; 21 | ALfloat listenerPosition[3]; 22 | ALfloat listenerVelocity[3]; 23 | ALfloat listenerOrientation[6]; 24 | 25 | public: 26 | ADAL_System(); 27 | ~ADAL_System(); 28 | 29 | void SetListenerGain(ALfloat gain); 30 | void SetListenerPosition(ALfloat x, ALfloat y, ALfloat z); 31 | void SetListenerVelocity(ALfloat x, ALfloat y, ALfloat z); 32 | void SetListenerOrientation(ALfloat ax, ALfloat ay, ALfloat az, ALfloat bx, ALfloat by, ALfloat bz); 33 | }; 34 | 35 | 36 | class ADAL_Sample { 37 | private: 38 | ALuint buffer; 39 | 40 | public: 41 | ADAL_Sample(); 42 | ~ADAL_Sample(); 43 | 44 | void Create(ALenum format, ALsizei size, ALsizei freq, ALvoid* data); 45 | void CreateWAV(const char* path); 46 | void CreateWAV_(unsigned char* data, long int size); 47 | void CreateMP3(const char* path); 48 | void CreateMP3_(unsigned char* data, long int size); 49 | 50 | friend class ADAL_Sound; 51 | }; 52 | 53 | 54 | class ADAL_Sound { 55 | private: 56 | ALuint source; 57 | 58 | ALfloat position[3]; 59 | ALfloat velocity[3]; 60 | 61 | public: 62 | ADAL_Sound(); 63 | ~ADAL_Sound(); 64 | 65 | bool Create(ADAL_Sample sample, ALfloat pitch, ALfloat gain, ALboolean loop); 66 | 67 | void SetGain(ALfloat gain); 68 | void SetPosition(ALfloat x, ALfloat y, ALfloat z); 69 | void SetVelocity(ALfloat x, ALfloat y, ALfloat z); 70 | 71 | ALuint GetBuffer(); 72 | bool IsPlaying(); 73 | 74 | void Play(); 75 | void Stop(); 76 | 77 | void WaitTillPlaying(int checkInterval); 78 | }; 79 | 80 | #endif 81 | 82 | #endif //NO_SOUND 83 | -------------------------------------------------------------------------------- /src/allocator.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #include "allocator.h" 6 | #include "tools.h" 7 | 8 | #ifndef NO_ALLOCATOR 9 | 10 | MUTEX Allocator::lockAllocator; 11 | MemoryMap Allocator::memoryMap; 12 | MemoryMap Allocator::violationMap; 13 | 14 | 15 | std::string Allocator::MemoryDump() { 16 | LOCKCLASS lockClass(Allocator::lockAllocator); 17 | 18 | std::string memoryDump; 19 | 20 | MemoryMap::iterator it = memoryMap.begin(); 21 | for (it; it != memoryMap.end(); it++) 22 | memoryDump += "Pointer: 0x" + value2str((uint32_t)it->first, true) + ", File: " + CutDirectory(it->second.first) + " (" + value2str(it->second.second) +")\n"; 23 | 24 | return memoryDump; 25 | } 26 | 27 | 28 | void* operator new(size_t bytes, const char* function, uint16_t line) throw(std::bad_alloc) { 29 | LOCKCLASS lockClass(Allocator::lockAllocator); 30 | void* ptr = ::operator new(bytes); 31 | MemoryMap::iterator it = Allocator::memoryMap.find(ptr); 32 | if (it != Allocator::memoryMap.end()) 33 | Logger::AddLog(std::string(function) + " [" + value2str(line) + "]", std::string("New violation (") + value2str((unsigned long)ptr, true) + ")", LOG_WARNING); 34 | Allocator::memoryMap[ptr] = std::pair(function, line); 35 | return ptr; 36 | } 37 | 38 | void* operator new[](size_t bytes, const char* function, uint16_t line) throw(std::bad_alloc) { 39 | LOCKCLASS lockClass(Allocator::lockAllocator); 40 | void* ptr = ::operator new[](bytes); 41 | MemoryMap::iterator it = Allocator::memoryMap.find(ptr); 42 | if (it != Allocator::memoryMap.end()) 43 | Logger::AddLog(std::string(function) + " [" + value2str(line) + "]", std::string("New array violation (") + value2str((unsigned long)ptr, true) + ")", LOG_WARNING); 44 | Allocator::memoryMap[ptr] = std::pair(function, line); 45 | return ptr; 46 | } 47 | 48 | #else 49 | 50 | void* operator new(size_t bytes, const char* function, uint16_t line) throw(std::bad_alloc) { 51 | return ::operator new(bytes); 52 | } 53 | 54 | void* operator new[](size_t bytes, const char* function, uint16_t line) throw(std::bad_alloc) { 55 | return ::operator new[](bytes); 56 | } 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /src/allocator.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __ALLOCATOR_H 6 | #define __ALLOCATOR_H 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "logger.h" 15 | #include "mthread.h" 16 | #include "realtime.h" 17 | #include "tools.h" 18 | 19 | #define M_PLACE __FILE__, __LINE__ 20 | 21 | #ifndef NO_ALLOCATOR 22 | 23 | 24 | typedef std::map > MemoryMap; 25 | 26 | 27 | class Allocator { 28 | public: 29 | static MUTEX lockAllocator; 30 | static MemoryMap memoryMap; 31 | static MemoryMap violationMap; 32 | 33 | public: 34 | static std::string MemoryDump(); 35 | }; 36 | 37 | 38 | void* operator new(size_t bytes, const char* function, uint16_t line) throw(std::bad_alloc); 39 | void* operator new[](size_t bytes, const char* function, uint16_t line) throw(std::bad_alloc); 40 | 41 | 42 | template 43 | void delete_debug(T* ptr, const char* function, uint16_t line) { 44 | Allocator::lockAllocator.lock(); 45 | MemoryMap::iterator it = Allocator::memoryMap.find((void*)ptr); 46 | if (it != Allocator::memoryMap.end()) { 47 | Allocator::memoryMap.erase(it); 48 | Allocator::lockAllocator.unlock(); 49 | delete ptr; 50 | } 51 | else { 52 | Allocator::violationMap[(void*)ptr] = std::pair(function, line); 53 | Logger::AddLog(std::string(function) + " [" + value2str(line) + "]", std::string("Delete debug violation (0x") + value2str((unsigned long)ptr, true) + ")", LOG_WARNING); 54 | Allocator::lockAllocator.unlock(); 55 | } 56 | } 57 | 58 | template 59 | void delete_debug_array(T* ptr, const char* function, uint16_t line) { 60 | Allocator::lockAllocator.lock(); 61 | MemoryMap::iterator it = Allocator::memoryMap.find((void*)ptr); 62 | if (it != Allocator::memoryMap.end()) { 63 | Allocator::memoryMap.erase(it); 64 | Allocator::lockAllocator.unlock(); 65 | delete ptr; 66 | } 67 | else { 68 | Allocator::violationMap[(void*)ptr] = std::pair(function, line); 69 | Logger::AddLog(std::string(function) + " [" + value2str(line) + "]", std::string("Delete debug array violation (0x") + value2str((unsigned long)ptr, true) + ")", LOG_WARNING); 70 | Allocator::lockAllocator.unlock(); 71 | } 72 | } 73 | 74 | #else 75 | 76 | void* operator new(size_t bytes, const char* function, uint16_t line) throw(std::bad_alloc); 77 | void* operator new[](size_t bytes, const char* function, uint16_t line) throw(std::bad_alloc); 78 | 79 | 80 | template 81 | void delete_debug(T* ptr, const char* function, uint16_t line) { 82 | delete ptr; 83 | } 84 | 85 | template 86 | void delete_debug_array(T* ptr, const char* function, uint16_t line) { 87 | delete[] ptr; 88 | } 89 | 90 | #endif 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /src/backtrace.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #include "backtrace.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include "tools.h" 19 | 20 | #define BUFFER_MAX (16*1024) 21 | 22 | boost::function _exceptionFunction = NULL; 23 | 24 | struct bfd_ctx { 25 | bfd * handle; 26 | asymbol ** symbol; 27 | }; 28 | 29 | struct bfd_set { 30 | char * name; 31 | struct bfd_ctx * bc; 32 | struct bfd_set *next; 33 | }; 34 | 35 | struct find_info { 36 | asymbol **symbol; 37 | bfd_vma counter; 38 | const char *file; 39 | const char *func; 40 | unsigned line; 41 | }; 42 | 43 | struct output_buffer { 44 | char * buf; 45 | size_t sz; 46 | size_t ptr; 47 | }; 48 | 49 | 50 | static void 51 | output_init(struct output_buffer *ob, char * buf, size_t sz) 52 | { 53 | ob->buf = buf; 54 | ob->sz = sz; 55 | ob->ptr = 0; 56 | ob->buf[0] = '\0'; 57 | } 58 | 59 | static void 60 | output_print(struct output_buffer *ob, const char * format, ...) 61 | { 62 | if (ob->sz == ob->ptr) 63 | return; 64 | ob->buf[ob->ptr] = '\0'; 65 | va_list ap; 66 | va_start(ap,format); 67 | vsnprintf(ob->buf + ob->ptr , ob->sz - ob->ptr , format, ap); 68 | va_end(ap); 69 | 70 | ob->ptr = strlen(ob->buf + ob->ptr) + ob->ptr; 71 | } 72 | 73 | static void 74 | lookup_section(bfd *abfd, asection *sec, void *opaque_data) 75 | { 76 | struct find_info *data = (find_info*)opaque_data; 77 | 78 | if (data->func) 79 | return; 80 | 81 | if (!(bfd_get_section_flags(abfd, sec) & SEC_ALLOC)) 82 | return; 83 | 84 | bfd_vma vma = bfd_get_section_vma(abfd, sec); 85 | if (data->counter < vma || vma + bfd_get_section_size(sec) <= data->counter) 86 | return; 87 | 88 | bfd_find_nearest_line(abfd, sec, data->symbol, data->counter - vma, &(data->file), &(data->func), &(data->line)); 89 | } 90 | 91 | static void 92 | find(struct bfd_ctx * b, DWORD offset, const char **file, const char **func, unsigned *line) 93 | { 94 | struct find_info data; 95 | data.func = NULL; 96 | data.symbol = b->symbol; 97 | data.counter = offset; 98 | data.file = NULL; 99 | data.func = NULL; 100 | data.line = 0; 101 | 102 | bfd_map_over_sections(b->handle, &lookup_section, &data); 103 | if (file) { 104 | *file = data.file; 105 | } 106 | if (func) { 107 | *func = data.func; 108 | } 109 | if (line) { 110 | *line = data.line; 111 | } 112 | } 113 | 114 | static int 115 | init_bfd_ctx(struct bfd_ctx *bc, const char * procname, struct output_buffer *ob) 116 | { 117 | bc->handle = NULL; 118 | bc->symbol = NULL; 119 | 120 | bfd *b = bfd_openr(procname, 0); 121 | if (!b) { 122 | output_print(ob,"Failed to open bfd from (%s)\n" , CutDirectory(procname).c_str()); 123 | return 1; 124 | } 125 | 126 | int r1 = bfd_check_format(b, bfd_object); 127 | int r2 = bfd_check_format_matches(b, bfd_object, NULL); 128 | int r3 = bfd_get_file_flags(b) & HAS_SYMS; 129 | 130 | if (!(r1 && r2 && r3)) { 131 | bfd_close(b); 132 | output_print(ob,"Failed to init bfd from (%s)\n", CutDirectory(procname).c_str()); 133 | return 1; 134 | } 135 | 136 | void *symbol_table; 137 | 138 | unsigned dummy = 0; 139 | if (bfd_read_minisymbols(b, FALSE, &symbol_table, &dummy) == 0) { 140 | if (bfd_read_minisymbols(b, TRUE, &symbol_table, &dummy) < 0) { 141 | free(symbol_table); 142 | bfd_close(b); 143 | output_print(ob,"Failed to read symbols from (%s)\n", CutDirectory(procname).c_str()); 144 | return 1; 145 | } 146 | } 147 | 148 | bc->handle = b; 149 | bc->symbol = (asymbol**)symbol_table; 150 | 151 | return 0; 152 | } 153 | 154 | static void 155 | close_bfd_ctx(struct bfd_ctx *bc) 156 | { 157 | if (bc) { 158 | if (bc->symbol) { 159 | free(bc->symbol); 160 | } 161 | if (bc->handle) { 162 | bfd_close(bc->handle); 163 | } 164 | } 165 | } 166 | 167 | static struct bfd_ctx * 168 | get_bc(struct output_buffer *ob , struct bfd_set *set , const char *procname) 169 | { 170 | while(set->name) { 171 | if (strcmp(set->name , procname) == 0) { 172 | return set->bc; 173 | } 174 | set = set->next; 175 | } 176 | struct bfd_ctx bc; 177 | if (init_bfd_ctx(&bc, procname , ob)) { 178 | return NULL; 179 | } 180 | set->next = (bfd_set*)calloc(1, sizeof(*set)); 181 | set->bc = (bfd_ctx*)malloc(sizeof(struct bfd_ctx)); 182 | memcpy(set->bc, &bc, sizeof(bc)); 183 | set->name = strdup(procname); 184 | 185 | return set->bc; 186 | } 187 | 188 | static void 189 | release_set(struct bfd_set *set) 190 | { 191 | while(set) { 192 | struct bfd_set * temp = set->next; 193 | free(set->name); 194 | close_bfd_ctx(set->bc); 195 | free(set); 196 | set = temp; 197 | } 198 | } 199 | 200 | static void 201 | _backtrace(struct output_buffer *ob, struct bfd_set *set, int depth , LPCONTEXT context) 202 | { 203 | char procname[MAX_PATH]; 204 | GetModuleFileNameA(NULL, procname, sizeof procname); 205 | 206 | struct bfd_ctx *bc = NULL; 207 | 208 | STACKFRAME frame; 209 | memset(&frame,0,sizeof(frame)); 210 | 211 | frame.AddrPC.Offset = context->Eip; 212 | frame.AddrPC.Mode = AddrModeFlat; 213 | frame.AddrStack.Offset = context->Esp; 214 | frame.AddrStack.Mode = AddrModeFlat; 215 | frame.AddrFrame.Offset = context->Ebp; 216 | frame.AddrFrame.Mode = AddrModeFlat; 217 | 218 | HANDLE process = GetCurrentProcess(); 219 | HANDLE thread = GetCurrentThread(); 220 | 221 | char symbol_buffer[sizeof(IMAGEHLP_SYMBOL) + 255]; 222 | char module_name_raw[MAX_PATH]; 223 | 224 | while(StackWalk(IMAGE_FILE_MACHINE_I386, 225 | process, 226 | thread, 227 | &frame, 228 | context, 229 | 0, 230 | SymFunctionTableAccess, 231 | SymGetModuleBase, 0)) { 232 | 233 | --depth; 234 | if (depth < 0) 235 | break; 236 | 237 | IMAGEHLP_SYMBOL *symbol = (IMAGEHLP_SYMBOL *)symbol_buffer; 238 | symbol->SizeOfStruct = (sizeof *symbol) + 255; 239 | symbol->MaxNameLength = 254; 240 | 241 | DWORD module_base = SymGetModuleBase(process, frame.AddrPC.Offset); 242 | 243 | const char * module_name = "[unknown module]"; 244 | if (module_base && 245 | GetModuleFileNameA((HINSTANCE)module_base, module_name_raw, MAX_PATH)) { 246 | module_name = module_name_raw; 247 | bc = get_bc(ob, set, module_name); 248 | } 249 | 250 | const char * file = NULL; 251 | const char * func = NULL; 252 | unsigned line = 0; 253 | 254 | if (bc) { 255 | find(bc,frame.AddrPC.Offset,&file,&func,&line); 256 | } 257 | 258 | if (file == NULL) { 259 | DWORD dummy = 0; 260 | if (SymGetSymFromAddr(process, frame.AddrPC.Offset, &dummy, symbol)) { 261 | file = symbol->Name; 262 | } 263 | else { 264 | file = "[unknown file]"; 265 | } 266 | } 267 | if (func == NULL) { 268 | output_print(ob,"0x%x : %s : %s \n", 269 | frame.AddrPC.Offset, 270 | CutDirectory(module_name).c_str(), 271 | CutDirectory(file).c_str()); 272 | } 273 | else { 274 | output_print(ob,"0x%x : %s : %s (%d) : in function (%s) \n", 275 | frame.AddrPC.Offset, 276 | CutDirectory(module_name).c_str(), 277 | CutDirectory(file).c_str(), 278 | line, 279 | func); 280 | } 281 | } 282 | } 283 | 284 | extern char* backtrace_output = NULL; 285 | extern LPEXCEPTION_POINTERS exceptionInfo = NULL; 286 | static LPTOP_LEVEL_EXCEPTION_FILTER g_prev = NULL; 287 | 288 | static LONG WINAPI 289 | exception_filter(LPEXCEPTION_POINTERS info) 290 | { 291 | struct output_buffer ob; 292 | output_init(&ob, backtrace_output, BUFFER_MAX); 293 | 294 | if (!SymInitialize(GetCurrentProcess(), 0, TRUE)) { 295 | output_print(&ob,"Failed to init symbol context\n"); 296 | } 297 | else { 298 | bfd_init(); 299 | struct bfd_set *set = (bfd_set*)calloc(1,sizeof(*set)); 300 | _backtrace(&ob , set , 128 , info->ContextRecord); 301 | release_set(set); 302 | 303 | SymCleanup(GetCurrentProcess()); 304 | } 305 | 306 | fputs(backtrace_output , stderr); 307 | 308 | exceptionInfo = info; 309 | if (_exceptionFunction) 310 | _exceptionFunction(); 311 | 312 | exit(1); 313 | 314 | return 0; 315 | } 316 | 317 | void backtrace_register(boost::function exceptionFunction) 318 | { 319 | _exceptionFunction = exceptionFunction; 320 | 321 | if (backtrace_output == NULL) { 322 | backtrace_output = (char*)malloc(BUFFER_MAX); 323 | g_prev = SetUnhandledExceptionFilter(exception_filter); 324 | } 325 | } 326 | 327 | void backtrace_unregister() 328 | { 329 | if (backtrace_output) { 330 | free(backtrace_output); 331 | SetUnhandledExceptionFilter(g_prev); 332 | g_prev = NULL; 333 | backtrace_output = NULL; 334 | } 335 | } 336 | -------------------------------------------------------------------------------- /src/backtrace.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __BACKTRACE_H_ 6 | #define __BACKTRACE_H_ 7 | 8 | #include 9 | 10 | #include 11 | 12 | extern char* backtrace_output; 13 | extern LPEXCEPTION_POINTERS exceptionInfo; 14 | 15 | void backtrace_register(boost::function exceptionFunction); 16 | void backtrace_unregister(); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /src/battle.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #include "battle.h" 6 | 7 | #include "allocator.h" 8 | #include "creature.h" 9 | #include "icons.h" 10 | #include "logger.h" 11 | #include "player.h" 12 | #include "window.h" 13 | #include "tools.h" 14 | 15 | 16 | // ---- Battle ---- // 17 | 18 | MUTEX Battle::lockBattle; 19 | 20 | 21 | 22 | Battle::Battle() { 23 | container = NULL; 24 | } 25 | 26 | Battle::~Battle() { 27 | } 28 | 29 | void Battle::AddCreature(Creature* creature) { 30 | LOCKCLASS lockClass(lockBattle); 31 | 32 | Creature* playerCreature = Creature::GetFromKnown(Player::GetCreatureID()); 33 | if (!creature || (creature == playerCreature)) 34 | return; 35 | 36 | std::list::iterator it = std::find(battle.begin(), battle.end(), creature); 37 | if (it == battle.end()) 38 | battle.push_back(creature); 39 | } 40 | 41 | void Battle::RemoveCreature(Creature* creature) { 42 | LOCKCLASS lockClass(lockBattle); 43 | 44 | Creature* playerCreature = Creature::GetFromKnown(Player::GetCreatureID()); 45 | if (!creature || (creature == playerCreature)) 46 | return; 47 | 48 | std::list::iterator it = std::find(battle.begin(), battle.end(), creature); 49 | if (it != battle.end()) 50 | battle.erase(it); 51 | } 52 | 53 | Creature* Battle::GetCreature(int number) { 54 | LOCKCLASS lockClass(lockBattle); 55 | 56 | Creature* creature = NULL; 57 | if (number >= battle.size()) 58 | return creature; 59 | 60 | std::list::iterator it = battle.begin(); 61 | for (it; it != battle.end() && number > 0; it++, number--); 62 | 63 | if (it != battle.end()) 64 | creature = *it; 65 | 66 | return creature; 67 | } 68 | 69 | std::list Battle::GetCreatures() { 70 | LOCKCLASS lockClass(lockBattle); 71 | 72 | return battle; 73 | } 74 | 75 | void Battle::ClearBattle() { 76 | LOCKCLASS lockClass(lockBattle); 77 | 78 | battle.clear(); 79 | } 80 | 81 | int Battle::GetSize() { 82 | LOCKCLASS lockClass(lockBattle); 83 | 84 | return battle.size(); 85 | } 86 | 87 | 88 | void Battle::SetContainer(WindowElementContainer* container) { 89 | LOCKCLASS lockClass(lockBattle); 90 | 91 | this->container = container; 92 | } 93 | 94 | void Battle::UpdateContainer() { 95 | LOCKCLASS lockClass(lockBattle); 96 | 97 | if (!container) 98 | return; 99 | 100 | container->DeleteAllElements(); 101 | 102 | Window* window = container->GetWindow(); 103 | WindowTemplate* wndTemplate = window->GetWindowTemplate(); 104 | window->SetActiveElement(NULL); 105 | 106 | POINT size = window->GetSize(true); 107 | 108 | int posY = 0; 109 | std::list::iterator it = battle.begin(); 110 | for (it; it != battle.end(); it++) { 111 | Creature* creature = *it; 112 | 113 | Creature* newCreature = new(M_PLACE) Creature(creature); 114 | newCreature->direction = SOUTH; 115 | newCreature->step = 0.0f; 116 | 117 | WindowElementItemContainer* itemCont = new(M_PLACE) WindowElementItemContainer; 118 | itemCont->Create(0, 5, posY, 20, 20, NULL, wndTemplate); 119 | itemCont->SetCreature(newCreature); 120 | 121 | int offset = 0; 122 | int sk = newCreature->GetSkull(); 123 | int sh = newCreature->GetShield(); 124 | AD2D_Image* skull = (sk != 0 ? Icons::GetSkullIcon(sk) : NULL); 125 | AD2D_Image* shield = (sh != 0 ? Icons::GetShieldIcon(sh) : NULL); 126 | 127 | if (skull) { 128 | WindowElementImage* skullImage = new(M_PLACE) WindowElementImage; 129 | skullImage->Create(0, 25 + offset, posY, 12, 12, skull, wndTemplate); 130 | offset += 14; 131 | 132 | container->AddElement(skullImage); 133 | } 134 | 135 | if (shield) { 136 | WindowElementImage* shieldImage = new(M_PLACE) WindowElementImage; 137 | shieldImage->Create(0, 25 + offset, posY, 12, 12, shield, wndTemplate); 138 | offset += 14; 139 | 140 | container->AddElement(shieldImage); 141 | } 142 | 143 | 144 | WindowElementText* text = new(M_PLACE) WindowElementText; 145 | text->Create(0, 25 + offset, posY, 0xFFFF, wndTemplate); 146 | text->SetText(creature->GetName()); 147 | text->SetColor(0.8f, 0.8f, 0.8f); 148 | text->SetBorder(1); 149 | posY += 15; 150 | 151 | WindowElementSkillBar* bar = new(M_PLACE) WindowElementSkillBar; 152 | bar->Create(0, 25, posY, size.x - 51, 5, TypePointer("uint8", (void*)creature->GetHealthPtr()), wndTemplate); 153 | bar->SetColor(boost::bind(RT_ConvertColorHP, creature->GetHealthPtr())); 154 | bar->SetLocks(true, false); 155 | posY += 15; 156 | 157 | WindowElementBattle* batt = new(M_PLACE) WindowElementBattle; 158 | batt->Create(0, 0, posY - 30, size.x, 30, false, false, wndTemplate); 159 | batt->SetCreatureID(creature->GetID()); 160 | batt->SetLocks(true, false); 161 | 162 | container->AddElement(itemCont); 163 | container->AddElement(text); 164 | container->AddElement(bar); 165 | container->AddElement(batt); 166 | } 167 | 168 | container->SetIntSize(0, posY); 169 | } 170 | -------------------------------------------------------------------------------- /src/battle.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __BATTLE_H_ 6 | #define __BATTLE_H_ 7 | 8 | #include 9 | 10 | #include "mthread.h" 11 | 12 | 13 | class Creature; 14 | class WindowElementContainer; 15 | 16 | 17 | class Battle { 18 | private: 19 | WindowElementContainer* container; 20 | 21 | public: 22 | std::list battle; 23 | 24 | static MUTEX lockBattle; 25 | 26 | public: 27 | Battle(); 28 | ~Battle(); 29 | 30 | void AddCreature(Creature* creature); 31 | void RemoveCreature(Creature* creature); 32 | Creature* GetCreature(int number); 33 | std::list GetCreatures(); 34 | void ClearBattle(); 35 | 36 | void SetContainer(WindowElementContainer* container); 37 | void UpdateContainer(); 38 | 39 | int GetSize(); 40 | }; 41 | 42 | #endif //__BATTLE_H_ 43 | -------------------------------------------------------------------------------- /src/bot.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __BOT_H_ 6 | #define __BOT_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "mthread.h" 12 | #include "luascript.h" 13 | #include "tools.h" 14 | 15 | 16 | typedef std::list BotArguments; 17 | typedef std::list PlayersList; 18 | 19 | 20 | struct HealingStruct { 21 | bool selfHealing; 22 | bool friendHealing; 23 | unsigned char minSelfHealth; 24 | unsigned char minFriendHealth; 25 | 26 | unsigned short itemID; 27 | unsigned char itemSubType; 28 | std::string selfHealWords; 29 | std::string friendHealWords; 30 | 31 | HealingStruct() { 32 | selfHealing = false; 33 | friendHealing = false; 34 | minSelfHealth = 0; 35 | minFriendHealth = 0; 36 | itemID = 0; 37 | itemSubType = 0; 38 | } 39 | }; 40 | 41 | struct ManaRefillStruct { 42 | bool manaRefill; 43 | unsigned char manaStart; 44 | unsigned char manaFinish; 45 | 46 | unsigned short itemID; 47 | unsigned char itemSubType; 48 | 49 | ManaRefillStruct() { 50 | manaRefill = false; 51 | manaStart = 0; 52 | manaFinish = 100; 53 | itemID = 0; 54 | itemSubType = 0; 55 | } 56 | }; 57 | 58 | struct AimBotStruct { 59 | bool aimBot; 60 | 61 | bool autoTargeting; 62 | 63 | unsigned short itemID; 64 | unsigned char itemSubType; 65 | std::string offensiveWords; 66 | 67 | AimBotStruct() { 68 | aimBot = false; 69 | autoTargeting = false; 70 | itemID = 0; 71 | itemSubType = 0; 72 | } 73 | }; 74 | 75 | struct CaveBotStruct { 76 | bool caveBot; 77 | bool checkBody; 78 | bool moveToBody; 79 | bool eatFood; 80 | bool takeLoot; 81 | 82 | std::list foodList; 83 | std::list lootList; 84 | 85 | unsigned char lootBag; 86 | 87 | CaveBotStruct() { 88 | caveBot = false; 89 | checkBody = false; 90 | moveToBody = false; 91 | eatFood = false; 92 | takeLoot = false; 93 | lootBag = 0; 94 | } 95 | }; 96 | 97 | struct ScriptsBotStruct { 98 | bool scriptsState[8]; 99 | std::string filenames[8]; 100 | 101 | ScriptsBotStruct() { 102 | memset(scriptsState, 0, 8); 103 | } 104 | }; 105 | 106 | 107 | class Bot { 108 | private: 109 | static PlayersList friends; 110 | static PlayersList enemies; 111 | 112 | static HealingStruct dataHealing; 113 | static ManaRefillStruct dataManaRefill; 114 | static AimBotStruct dataAimBot; 115 | static CaveBotStruct dataCaveBot; 116 | static ScriptsBotStruct dataScriptsBot; 117 | 118 | static LuaScript luaScriptHealing; 119 | static LuaScript luaScriptManaRefill; 120 | static LuaScript luaScriptAimBot; 121 | static LuaScript luaScriptCaveBot; 122 | static LuaScript luaScriptsBot[8]; 123 | 124 | public: 125 | static bool enabled; 126 | static MUTEX lockBot; 127 | 128 | public: 129 | static void SaveBot(std::string path); 130 | static void LoadBot(std::string path); 131 | static void ReleaseBot(); 132 | 133 | static void Stop(); 134 | static void Run(); 135 | static void Restart(); 136 | 137 | static void SetHealingData(HealingStruct hs); 138 | static HealingStruct GetHealingData(); 139 | 140 | static void SetManaRefillData(ManaRefillStruct ms); 141 | static ManaRefillStruct GetManaRefillData(); 142 | 143 | static void SetAimBotData(AimBotStruct as); 144 | static AimBotStruct GetAimBotData(); 145 | 146 | static void SetCaveBotData(CaveBotStruct cs); 147 | static CaveBotStruct GetCaveBotData(); 148 | 149 | static void SetScriptsBotData(ScriptsBotStruct cs); 150 | static ScriptsBotStruct GetScriptsBotData(); 151 | 152 | static void AddFriend(std::string name); 153 | static PlayersList GetFriends(); 154 | static void RemoveFriend(std::string name); 155 | static void ClearFriends(); 156 | 157 | static void AddEnemie(std::string name); 158 | static PlayersList GetEnemies(); 159 | static void RemoveEnemie(std::string name); 160 | static void ClearEnemies(); 161 | 162 | //Lua functions 163 | static int LuaGetFriends(lua_State* L); 164 | static int LuaGetEnemies(lua_State* L); 165 | 166 | static void LuaRegisterFunctions(lua_State* L); 167 | }; 168 | 169 | #endif //__BOT_H_ 170 | -------------------------------------------------------------------------------- /src/channel.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __CHANNEL_H_ 6 | #define __CHANNEL_H_ 7 | 8 | #include 9 | 10 | #include "luascript.h" 11 | #include "mthread.h" 12 | #include "window.h" 13 | 14 | 15 | enum Channels { 16 | CHANNEL_NPC = 0xFFFC, 17 | CHANNEL_SERVER_LOG = 0xFFFD, 18 | CHANNEL_DEFAULT = 0xFFFE, 19 | CHANNEL_PRIVATE = 0xFFFF, 20 | }; 21 | 22 | typedef TextString ChatMessage; 23 | typedef std::pair ChatCreatureMessage; 24 | typedef std::pair ChatMessageType; 25 | typedef std::map ChatMessagesMap; 26 | typedef std::list ChatUsers; 27 | 28 | class Channel { 29 | private: 30 | unsigned short id; 31 | std::string name; 32 | 33 | void* button; 34 | void* textarea; 35 | void* memo; 36 | 37 | ChatUsers users; 38 | ChatUsers invited; 39 | 40 | ChatMessagesMap messages; 41 | 42 | static std::map channels; 43 | static std::map privates; 44 | static MUTEX channelsLock; 45 | 46 | public: 47 | Channel(); 48 | Channel(unsigned short id, std::string name); 49 | ~Channel(); 50 | 51 | unsigned short GetID(); 52 | void SetName(std::string name); 53 | std::string GetName(); 54 | unsigned int GetSize(); 55 | 56 | void SetButton(void* button); 57 | void* GetButton(); 58 | void SetTextarea(void* textarea); 59 | void* GetTextarea(); 60 | void SetMemo(void* memo); 61 | void* GetMemo(); 62 | 63 | void AddMessage(time_t time, std::string creatureName, TextString text); 64 | ChatMessageType GetMessage(unsigned int number); 65 | void ClearMessages(); 66 | 67 | void AddUser(std::string user); 68 | void AddInvited(std::string user); 69 | ChatUsers GetUsers(); 70 | ChatUsers GetInvited(); 71 | void ClearUsers(); 72 | void ClearInvited(); 73 | 74 | static void AddChannel(Channel* channel, bool isPrivate = false); 75 | static Channel* GetChannel(unsigned short channelID); 76 | static Channel* GetChannel(std::string channelName); 77 | static Channel* GetChannel(void* textarea, void* button = NULL, void* memo = NULL); 78 | static std::map GetChannels(); 79 | static void RemoveChannel(unsigned short channelID); 80 | static void RemoveChannel(std::string channelName); 81 | 82 | static void ClearChannels(); 83 | 84 | //Lua functions 85 | static int LuaOpenChannel(lua_State* L); 86 | static int LuaChannelAddMessage(lua_State* L); 87 | 88 | static void LuaRegisterFunctions(lua_State* L); 89 | }; 90 | 91 | #endif //__CHANNEL_H_ 92 | -------------------------------------------------------------------------------- /src/container.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __CONTAINER_H_ 6 | #define __CONTAINER_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "item.h" 13 | #include "logger.h" 14 | #include "luascript.h" 15 | #include "mthread.h" 16 | 17 | 18 | enum CONTAINER { 19 | CONTAINER_FREE = 0xFC, 20 | CONTAINER_EQUIPMENT = 0xFD, 21 | CONTAINER_TRADE = 0xFE, 22 | CONTAINER_INVENTORY = 0xFF, 23 | }; 24 | 25 | 26 | class Container { 27 | private: 28 | unsigned char index; 29 | 30 | unsigned short id; 31 | std::string name; 32 | 33 | unsigned short places; 34 | std::vector items; 35 | 36 | bool child; 37 | 38 | static std::map containers; 39 | static unsigned char lastIndex; 40 | 41 | public: 42 | static MUTEX lockContainer; 43 | 44 | public: 45 | Container(unsigned char index, unsigned short id, std::string name, unsigned short places, bool child); 46 | ~Container(); 47 | 48 | void AddItem(Item* item, bool pushBack = false); 49 | void TransformItem(unsigned short slot, Item* item); 50 | void RemoveItem(unsigned short slot); 51 | Item* GetItem(unsigned short slot); 52 | bool IsItemInContainer(unsigned short itemID, unsigned char itemSubType); 53 | 54 | unsigned char GetIndex(); 55 | std::string GetName(); 56 | unsigned short GetID(); 57 | unsigned short GetPlaces(); 58 | unsigned short GetSize(); 59 | bool IsChild(); 60 | 61 | static unsigned char GetFreeIndex(); 62 | 63 | static void AddContainer(Container* container); 64 | static Container* GetContainer(unsigned char index); 65 | static std::list GetContainers(); 66 | static void RemoveContainer(unsigned char index); 67 | 68 | static unsigned char GetLastIndex(); 69 | static void ResetLastIndex(); 70 | 71 | //Lua functions 72 | static int LuaGetContainer(lua_State* L); 73 | static int LuaContainerGetLastIndex(lua_State* L); 74 | static int LuaContainerResetLastIndex(lua_State* L); 75 | static int LuaContainerGetPlaces(lua_State* L); 76 | static int LuaContainerGetSize(lua_State* L); 77 | static int LuaContainerGetItem(lua_State* L); 78 | static int LuaIsContainer(lua_State* L); 79 | static int LuaHasParent(lua_State* L); 80 | 81 | static void LuaRegisterFunctions(lua_State* L); 82 | }; 83 | 84 | #endif //__CONTAINER_H_ 85 | -------------------------------------------------------------------------------- /src/cooldowns.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __COOLDOWNS_H_ 6 | #define __COOLDOWNS_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "game.h" 12 | #include "luascript.h" 13 | #include "mthread.h" 14 | #include "realtime.h" 15 | 16 | 17 | class Game; 18 | 19 | class WindowElementContainer; 20 | 21 | 22 | class Cooldown { 23 | private: 24 | time_lt castTime; 25 | unsigned int period; 26 | 27 | std::string comment; 28 | 29 | public: 30 | Cooldown(); 31 | ~Cooldown(); 32 | 33 | void Cast(unsigned int period); 34 | bool CanCast(); 35 | 36 | void SetComment(std::string text); 37 | std::string GetComment(); 38 | 39 | friend class Cooldowns; 40 | }; 41 | 42 | 43 | typedef std::map CooldownMap; 44 | 45 | class Cooldowns { 46 | private: 47 | WindowElementContainer* containerGroup; 48 | WindowElementContainer* containerSpell; 49 | 50 | static CooldownMap groupCooldowns; 51 | static CooldownMap spellCooldowns; 52 | 53 | static int threads; 54 | static MUTEX lockCooldowns; 55 | 56 | public: 57 | Cooldowns(); 58 | ~Cooldowns(); 59 | 60 | void CastGroup(unsigned char id, unsigned int period); 61 | void CastSpell(unsigned char id, unsigned int period); 62 | 63 | void AddCooldown(unsigned char id, Cooldown* cooldown); 64 | void RemoveCooldown(unsigned char id); 65 | void ClearCooldowns(); 66 | Cooldown* GetGroupCooldown(unsigned char id); 67 | Cooldown* GetCooldown(unsigned char id); 68 | 69 | static void CheckCooldowns(Game* game); 70 | 71 | void SetContainerGroup(WindowElementContainer* container); 72 | void SetContainerSpell(WindowElementContainer* container); 73 | void UpdateContainerGroup(); 74 | void UpdateContainerSpell(); 75 | 76 | //Lua functions 77 | static int LuaNewCooldown(lua_State* L); 78 | static int LuaDeleteCooldown(lua_State* L); 79 | static int LuaAddCooldown(lua_State* L); 80 | static int LuaRemoveCooldown(lua_State* L); 81 | static int LuaCastCooldown(lua_State* L); 82 | static int LuaCastCooldownGroup(lua_State* L); 83 | 84 | static void LuaRegisterFunctions(lua_State* L); 85 | }; 86 | 87 | #endif //__COOLDOWNS_H_ 88 | -------------------------------------------------------------------------------- /src/craftbox.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #include "craftbox.h" 6 | 7 | #include "allocator.h" 8 | #include "window.h" 9 | 10 | 11 | // ---- CraftBox ---- // 12 | 13 | MUTEX CraftBox::lockCraftBox; 14 | 15 | 16 | CraftBox::CraftBox() { 17 | container = NULL; 18 | } 19 | 20 | CraftBox::~CraftBox() { } 21 | 22 | 23 | void CraftBox::AddCraftElement(CraftElement craftElement, CraftList craftList) { 24 | LOCKCLASS lockClass(lockCraftBox); 25 | 26 | crafts[craftElement] = craftList; 27 | } 28 | 29 | void CraftBox::ClearCraftBox() { 30 | LOCKCLASS lockClass(lockCraftBox); 31 | 32 | crafts.clear(); 33 | } 34 | 35 | CraftMap CraftBox::GetCraftElements() { 36 | LOCKCLASS lockClass(lockCraftBox); 37 | 38 | return crafts; 39 | } 40 | 41 | 42 | void CraftBox::SetContainer(WindowElementContainer* container) { 43 | LOCKCLASS lockClass(lockCraftBox); 44 | 45 | this->container = container; 46 | } 47 | 48 | WindowElementContainer* CraftBox::GetContainer() { 49 | LOCKCLASS lockClass(lockCraftBox); 50 | 51 | return container; 52 | } 53 | 54 | 55 | void CraftBox::UpdateContainer(WindowElementItemContainer* itemContainer) { 56 | LOCKCLASS lockClass1(Windows::lockWindows); 57 | LOCKCLASS lockClass2(lockCraftBox); 58 | 59 | if (!container) 60 | return; 61 | 62 | container->DeleteAllElements(); 63 | 64 | if (!itemContainer) 65 | return; 66 | 67 | Window* window = container->GetWindow(); 68 | WindowTemplate* wndTemplate = window->GetWindowTemplate(); 69 | 70 | Item* item = itemContainer->GetItem(); 71 | if (!item) 72 | return; 73 | 74 | CraftElement craftElement(item->GetID(), item->GetCount()); 75 | CraftMap::iterator it = crafts.find(craftElement); 76 | if (it == crafts.end()) 77 | return; 78 | 79 | CraftList craftList = it->second; 80 | int count = 0; 81 | for (CraftList::iterator lit = craftList.begin(); lit != craftList.end(); lit++) { 82 | Item* item = new(M_PLACE) Item; 83 | item->SetID(lit->first); 84 | item->SetCount(lit->second); 85 | 86 | WindowElementItemContainer* itemCont = new(M_PLACE) WindowElementItemContainer; 87 | itemCont->Create(0, count * 32, 0, 32, 32, NULL, wndTemplate); 88 | itemCont->SetItem(item); 89 | container->AddElement(itemCont); 90 | 91 | count++; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/craftbox.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __CRAFTBOX_H_ 6 | #define __CRAFTBOX_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "mthread.h" 12 | 13 | 14 | class WindowElementContainer; 15 | class WindowElementItemContainer; 16 | 17 | 18 | typedef std::pair CraftElement; 19 | typedef std::list CraftList; 20 | typedef std::map CraftMap; 21 | 22 | 23 | class CraftBox { 24 | private: 25 | WindowElementContainer* container; 26 | 27 | CraftMap crafts; 28 | 29 | static MUTEX lockCraftBox; 30 | 31 | public: 32 | CraftBox(); 33 | ~CraftBox(); 34 | 35 | void AddCraftElement(CraftElement craftElement, CraftList craftList); 36 | void ClearCraftBox(); 37 | 38 | CraftMap GetCraftElements(); 39 | 40 | void SetContainer(WindowElementContainer* container); 41 | WindowElementContainer* GetContainer(); 42 | 43 | void UpdateContainer(WindowElementItemContainer* itemContainer); 44 | }; 45 | 46 | 47 | #endif //__CRAFTBOX_H_ 48 | -------------------------------------------------------------------------------- /src/creature.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __CREATURE_H_ 6 | #define __CREATURE_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "ad2d.h" 13 | #include "const.h" 14 | #include "container.h" 15 | #include "item.h" 16 | #include "logger.h" 17 | #include "luascript.h" 18 | #include "map.h" 19 | #include "mthread.h" 20 | #include "position.h" 21 | #include "realtime.h" 22 | #include "thing.h" 23 | 24 | class Battle; 25 | class Map; 26 | 27 | typedef std::set LoadedSet; 28 | 29 | class OutfitType { 30 | public: 31 | unsigned short lookType; 32 | unsigned char lookAddons; 33 | std::string name; 34 | 35 | public: 36 | OutfitType(); 37 | ~OutfitType(); 38 | }; 39 | 40 | class Outfit { 41 | public: 42 | unsigned short lookType; 43 | unsigned short lookTypeEx; 44 | unsigned char lookHead; 45 | unsigned char lookBody; 46 | unsigned char lookLegs; 47 | unsigned char lookFeet; 48 | unsigned char lookAddons; 49 | unsigned short lookMount; 50 | 51 | public: 52 | Outfit(); 53 | ~Outfit(); 54 | 55 | static void SetTemplateColor(COLOR currentColor, int index); 56 | }; 57 | 58 | 59 | class Creature : public Thing { 60 | private: 61 | unsigned int id; 62 | std::string name; 63 | 64 | unsigned char health; 65 | Direction direction; 66 | Direction lastMove; 67 | 68 | Outfit outfit; 69 | 70 | unsigned char lightLevel; 71 | unsigned char lightColor; 72 | unsigned short speed; 73 | 74 | unsigned char skull; 75 | unsigned char shield; 76 | 77 | unsigned char war; 78 | 79 | unsigned int shine; 80 | 81 | bool blocking; 82 | bool ignored; 83 | 84 | time_lt squareTime; 85 | unsigned char squareColor; 86 | 87 | time_lt equipmentTime; 88 | Container* equipment; 89 | 90 | static std::map ignoredCreatures; 91 | static std::map knownCreatures; 92 | 93 | public: 94 | static MUTEX lockCreature; 95 | 96 | static LoadedSet loadedLooktypes; 97 | 98 | public: 99 | Creature(); 100 | Creature(Creature* creature); 101 | virtual ~Creature(); 102 | 103 | void Clear(); 104 | 105 | void SetID(unsigned int id); 106 | unsigned int GetID(); 107 | void SetShine(unsigned int shine); 108 | unsigned int GetShine(); 109 | 110 | bool IsPlayer(); 111 | bool IsNPC(); 112 | bool IsMonster(); 113 | 114 | void SetName(std::string name); 115 | std::string GetName(); 116 | std::string* GetNamePtr(); 117 | 118 | void SetHealth(unsigned char health); 119 | unsigned char GetHealth(); 120 | unsigned char* GetHealthPtr(); 121 | 122 | void SetDirection(Direction direction); 123 | Direction GetDirection(); 124 | 125 | void SetLastMove(Direction direction); 126 | Direction GetLastMove(); 127 | 128 | void SetOutfit(Outfit outfit); 129 | Outfit GetOutfit(); 130 | 131 | void SetLight(unsigned char lightColor, unsigned char lightLevel); 132 | unsigned char GetLightLevel(); 133 | unsigned char GetLightColor(); 134 | 135 | void SetSpeed(unsigned short speed); 136 | unsigned short GetSpeed(); 137 | 138 | void SetSkull(unsigned char skull); 139 | unsigned char GetSkull(); 140 | 141 | void SetShield(unsigned char shield); 142 | unsigned char GetShield(); 143 | 144 | void SetWar(unsigned char war); 145 | unsigned char GetWar(); 146 | 147 | void SetBlocking(bool blocking); 148 | bool GetBlocking(); 149 | 150 | void SetStep(float step); 151 | float GetStep(); 152 | 153 | void SetSquare(time_lt time, unsigned char color); 154 | time_lt GetSquareTime(); 155 | unsigned char GetSquareColor(); 156 | 157 | void SetEquipment(time_lt time, Container* container); 158 | time_lt GetEquipmentTime(); 159 | Container* GetEquipment(); 160 | 161 | ItemType* operator()(); 162 | 163 | void GetStepOffset(float& x, float& y); 164 | 165 | void PrintCreature(AD2D_Window* gfx, Position pos, float x, float y, float width, float height, bool ignoreColors = false); 166 | void PrintDetails(AD2D_Window* gfx, AD2D_Font* font, Position pos, float x, float y, float width, float height, int name, int hp, int mana, bool attacked, bool followed, bool selected); 167 | void PrintIcons(AD2D_Window* gfx, Position pos, float x, float y, float width, float height); 168 | void PrintEquipment(AD2D_Window* gfx, Position pos, float x, float y, float width, float height); 169 | void PrintCreatureShine(AD2D_Window* gfx, Position pos, float x, float y, float width, float height, unsigned int shine); 170 | 171 | static void Ignore(std::string creatureName); 172 | static void Unignore(std::string creatureName); 173 | static bool IsIgnored(std::string creatureName); 174 | 175 | static void CheckCreatures(Map* map, float factor); 176 | static void AddToKnown(Creature* creature); 177 | static Creature* GetFromKnown(unsigned int id); 178 | static std::list GetCreaturesList(); 179 | static void RemoveFromKnown(unsigned int id); 180 | static void DeleteKnown(); 181 | 182 | //Lua functions 183 | static int LuaSetCreatureName(lua_State* L); 184 | static int LuaGetCreatureID(lua_State* L); 185 | static int LuaSetCreatureShine(lua_State* L); 186 | static int LuaGetCreatureShine(lua_State* L); 187 | static int LuaGetCreatureName(lua_State* L); 188 | static int LuaGetCreaturePosition(lua_State* L); 189 | static int LuaGetCreatureHealth(lua_State* L); 190 | static int LuaGetCreatureSkull(lua_State* L); 191 | static int LuaGetCreatureShield(lua_State* L); 192 | static int LuaGetCreatureWar(lua_State* L); 193 | static int LuaGetCreatureStep(lua_State* L); 194 | 195 | 196 | static void LuaRegisterFunctions(lua_State* L); 197 | 198 | friend class Battle; 199 | }; 200 | 201 | #endif //__CREATURE_H_ 202 | -------------------------------------------------------------------------------- /src/distance.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #include 6 | 7 | #include "distance.h" 8 | 9 | #include "allocator.h" 10 | #include "logger.h" 11 | 12 | 13 | // ---- Distance ---- // 14 | 15 | DistancesList Distance::distances; 16 | 17 | int Distance::threads = 0; 18 | MUTEX Distance::lockDistance; 19 | 20 | 21 | Distance::Distance(unsigned short lookType, Position fromPos, Position toPos) { 22 | this->pos = fromPos; 23 | this->newPos = toPos; 24 | 25 | this->maxLiveTime = (int)(sqrt(pow(toPos.x - fromPos.x, 2) + pow(toPos.y - fromPos.y, 2)) * 50); 26 | this->liveTime = 0; 27 | 28 | ItemType* iType = Item::GetItemType(Item::GetItemsCount() + Item::GetCreaturesCount() + Item::GetEffectsCount() + lookType); 29 | if (iType && iType->light && iType->lightColor > 0 && iType->lightRadius > 0) 30 | light = new(M_PLACE) DynamicDistanceLight(this, iType->lightColor, iType->lightRadius); 31 | 32 | this->iType = iType; 33 | 34 | LOCKCLASS lockClass(lockDistance); 35 | 36 | distances.push_back(this); 37 | } 38 | 39 | Distance::~Distance() { 40 | if (light) 41 | delete_debug(light, M_PLACE); 42 | } 43 | 44 | unsigned short Distance::GetMaxLiveTime() { 45 | return maxLiveTime; 46 | } 47 | 48 | unsigned short Distance::GetLiveTime() { 49 | return liveTime; 50 | } 51 | 52 | ItemType* Distance::GetItemType() { 53 | return iType; 54 | } 55 | 56 | Position Distance::GetFromPosition() { 57 | return pos; 58 | } 59 | 60 | Position Distance::GetToPosition() { 61 | return newPos; 62 | } 63 | 64 | void Distance::PrintDistance(AD2D_Window* gfx, float x, float y, float width, float height) { 65 | if (!iType) 66 | return; 67 | 68 | int dx = (newPos.x - pos.x); 69 | int dy = (newPos.y - pos.y); 70 | 71 | int direction; 72 | if (dx < 0 && dy < 0) direction = 0; 73 | else if (dx < 0 && dy == 0) direction = 1; 74 | else if (dx < 0 && dy > 0) direction = 2; 75 | else if (dx == 0 && dy < 0) direction = 3; 76 | else if (dx == 0 && dy == 0) direction = 4; 77 | else if (dx == 0 && dy > 0) direction = 5; 78 | else if (dx > 0 && dy < 0) direction = 6; 79 | else if (dx > 0 && dy == 0) direction = 7; 80 | else if (dx > 0 && dy > 0) direction = 8; 81 | 82 | int xOffset = (direction / iType->m_ydiv) % iType->m_xdiv; 83 | int yOffset = direction % iType->m_xdiv; 84 | 85 | int anim = (RealTime::getTime() / 50) % iType->m_anim; 86 | 87 | AD2D_Image* image = NULL; 88 | for (int pb = 0; pb < iType->m_blend; pb++) 89 | for (int px = 0; px < iType->m_width; px++) 90 | for (int py = 0; py < iType->m_height; py++) { 91 | float mx = x - px * width; 92 | float my = y - py * height; 93 | 94 | int offset = px + (py * iType->m_width) + 95 | (pb * iType->m_width * iType->m_height) + 96 | (xOffset * iType->m_width * iType->m_height * iType->m_blend) + 97 | (yOffset * iType->m_width * iType->m_height * iType->m_blend * iType->m_xdiv) + 98 | (anim * iType->m_width * iType->m_height * iType->m_blend * iType->m_xdiv * iType->m_ydiv); 99 | if (offset < iType->m_sprNum) 100 | image = Sprites::GetSprite(iType->m_sprPtr[offset]); 101 | 102 | if (image) { 103 | gfx->PutImage(mx, my, mx + width, my + height, *image); 104 | } 105 | } 106 | } 107 | 108 | 109 | void Distance::RemoveDistance(Distance* dist) { 110 | LOCKCLASS lockClass(lockDistance); 111 | 112 | if (!dist) { 113 | Logger::AddLog("Distance::RemoveDistance()", "Pointer to distance is NULL!", LOG_WARNING); 114 | return; 115 | } 116 | 117 | DistancesList::iterator it = std::find(distances.begin(), distances.end(), dist); 118 | if (it != distances.end()) { 119 | distances.erase(it); 120 | delete_debug(dist, M_PLACE); 121 | } 122 | else 123 | Logger::AddLog("Distance::RemoveDistance()", "Distance not in list!", LOG_WARNING); 124 | } 125 | 126 | void Distance::ClearDistances() { 127 | LOCKCLASS lockClass(lockDistance); 128 | 129 | DistancesList::iterator it = distances.begin(); 130 | for (it; it != distances.end(); it++) { 131 | Distance* dist = *it; 132 | delete_debug(dist, M_PLACE); 133 | } 134 | distances.clear(); 135 | } 136 | 137 | void Distance::CheckDistances(Game* game) { 138 | if (threads > 0) 139 | return; 140 | 141 | threads++; 142 | 143 | while(game->GetGameState() == GAME_LOGGEDTOGAME) { 144 | lockDistance.lock(); 145 | 146 | DistancesList toDelete; 147 | 148 | DistancesList::iterator it = distances.begin(); 149 | for (it; it != distances.end(); it++) { 150 | Distance* dist = *it; 151 | if (dist) { 152 | dist->liveTime += 25; 153 | if (dist->liveTime >= dist->maxLiveTime) 154 | toDelete.push_back(dist); 155 | } 156 | } 157 | 158 | it = toDelete.begin(); 159 | for (it; it != toDelete.end(); it++) { 160 | Distance* dist = *it; 161 | RemoveDistance(dist); 162 | } 163 | 164 | lockDistance.unlock(); 165 | Sleep(25); 166 | } 167 | 168 | ClearDistances(); 169 | 170 | threads--; 171 | } 172 | 173 | void Distance::PrintDistances(AD2D_Window* gfx, Position pos, unsigned char z, float x, float y, float width, float height) { 174 | LOCKCLASS lockClass(lockDistance); 175 | 176 | DistancesList::iterator it = distances.begin(); 177 | for (it; it != distances.end(); it++) { 178 | Distance* dist = *it; 179 | if (dist && dist->pos.z == z) { 180 | int offset = dist->pos.z - pos.z; 181 | 182 | int dx = (dist->newPos.x - dist->pos.x); 183 | int dy = (dist->newPos.y - dist->pos.y); 184 | 185 | float step = 1.0f - (float)(dist->maxLiveTime - dist->liveTime) / dist->maxLiveTime; 186 | float px = x + (((float)(dist->pos.x - pos.x + offset) + (float)dx * step) * width); 187 | float py = y + (((float)(dist->pos.y - pos.y + offset) + (float)dy * step) * height); 188 | 189 | dist->PrintDistance(gfx, px, py, width, height); 190 | } 191 | } 192 | } 193 | -------------------------------------------------------------------------------- /src/distance.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __DISTANCE_H_ 6 | #define __DISTANCE_H_ 7 | 8 | #include 9 | 10 | #include "ad2d.h" 11 | #include "game.h" 12 | #include "item.h" 13 | #include "mthread.h" 14 | #include "position.h" 15 | #include "thing.h" 16 | 17 | 18 | class Game; 19 | 20 | class Distance; 21 | 22 | 23 | typedef std::list DistancesList; 24 | 25 | class Distance : public Thing { 26 | private: 27 | ItemType* iType; 28 | 29 | unsigned short maxLiveTime; 30 | unsigned short liveTime; 31 | 32 | static DistancesList distances; 33 | 34 | static int threads; 35 | static MUTEX lockDistance; 36 | 37 | public: 38 | Distance(unsigned short lookType, Position fromPos, Position toPos); 39 | ~Distance(); 40 | 41 | unsigned short GetMaxLiveTime(); 42 | unsigned short GetLiveTime(); 43 | 44 | ItemType* GetItemType(); 45 | Position GetFromPosition(); 46 | Position GetToPosition(); 47 | 48 | void PrintDistance(AD2D_Window* gfx, float x, float y, float width, float height); 49 | 50 | static void RemoveDistance(Distance* dist); 51 | static void ClearDistances(); 52 | 53 | static void CheckDistances(Game* game); 54 | static void PrintDistances(AD2D_Window* gfx, Position pos, unsigned char z, float x, float y, float width, float height); 55 | }; 56 | 57 | #endif //__DISTANCE_H_ 58 | -------------------------------------------------------------------------------- /src/empty.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #include "empty.h" 6 | 7 | 8 | // ---- Empty ---- // 9 | -------------------------------------------------------------------------------- /src/empty.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __EMPTY_H_ 6 | #define __EMPTY_H_ 7 | 8 | 9 | 10 | #endif //__EMPTY_H_ 11 | -------------------------------------------------------------------------------- /src/filemanager.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __FILEMANAGER_H_ 6 | #define __FILEMANAGER_H_ 7 | 8 | 9 | #include 10 | #include 11 | 12 | #include "mthread.h" 13 | 14 | 15 | struct FileInfo { 16 | long int fileSize; 17 | long int fileSizeCompressed; 18 | 19 | std::string pakFile; 20 | long int pakHeader; 21 | long int pakHandler; 22 | uint64_t pakKey; 23 | 24 | FileInfo() { 25 | fileSize = 0; 26 | fileSizeCompressed = 0; 27 | pakFile = ""; 28 | pakHandler = 0; 29 | pakKey = 0; 30 | }; 31 | 32 | FileInfo(long int fSize, long int fSizeC) { 33 | fileSize = fSize; 34 | fileSizeCompressed = fSizeC; 35 | pakFile = ""; 36 | pakHandler = 0; 37 | pakKey = 0; 38 | }; 39 | 40 | FileInfo(std::string pFile, long int fSize, long int fSizeC, long int pHandler, uint64_t pKey) { 41 | fileSize = fSize; 42 | fileSizeCompressed = fSizeC; 43 | pakFile = pFile; 44 | pakHandler = pHandler; 45 | pakKey = pKey; 46 | } 47 | }; 48 | 49 | typedef std::map FilesTree; 50 | 51 | 52 | class FileManager { 53 | private: 54 | FilesTree files; 55 | 56 | MUTEX lockFiles; 57 | 58 | public: 59 | static FileManager* fileManager; 60 | 61 | public: 62 | FileManager(); 63 | ~FileManager(); 64 | 65 | void MakeFilesTree(std::string directory = "."); 66 | void MakeFilesTreeFromPAK(std::string path, std::string directory); 67 | 68 | void AddToTree(std::string fileName); 69 | 70 | void CompilePAK(std::string directory, std::string pakFileName, uint64_t key); 71 | void ExtractPAK(std::string pakFileName, std::string directory); 72 | 73 | FILE* OpenFile(std::string fileName); 74 | unsigned char* GetFileData(std::string fileName); 75 | long int GetFileSize(std::string fileName); 76 | //long int Tell(std::string fileName, FILE* file); 77 | FileInfo GetFileInfo(std::string fileName); 78 | 79 | static std::string FixFileName(std::string fileName); 80 | 81 | static void Encode(unsigned char* data, long int size, uint64_t key); 82 | static void Decode(unsigned char* data, long int size, uint64_t key); 83 | 84 | static void Compress(std::vector &outBuf, unsigned char *inBuf, size_t inSize); 85 | static void Uncompress(std::vector &outBuf, unsigned char *inBuf, size_t inSize); 86 | }; 87 | 88 | #endif //__FILEMANAGER_H_ 89 | -------------------------------------------------------------------------------- /src/guimanager.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __GUIMANAGER_H_ 6 | #define __GUIMANAGER_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "input.h" 12 | #include "luascript.h" 13 | #include "mthread.h" 14 | 15 | 16 | class Window; 17 | 18 | class GUIConnection; 19 | class GUIManager; 20 | 21 | 22 | enum GUI_ACTIONS { 23 | GUIACTION_NONE = 0, 24 | GUIACTION_MOVE_TOP = 1, 25 | GUIACTION_MOVE_BOTTOM = 2, 26 | GUIACTION_MOVE_LEFT = 3, 27 | GUIACTION_MOVE_RIGHT = 4, 28 | GUIACTION_RESIZE_TOP = 5, 29 | GUIACTION_RESIZE_BOTTOM = 6, 30 | GUIACTION_RESIZE_LEFT = 7, 31 | GUIACTION_RESIZE_RIGHT = 8, 32 | GUIACTION_MINIMIZE = 9, 33 | }; 34 | 35 | 36 | typedef std::map GUIActionMap; 37 | typedef std::map GUIWindowActionsMap; 38 | 39 | class GUIConnection { 40 | private: 41 | Window* wnd1; 42 | Window* wnd2; 43 | 44 | GUIWindowActionsMap actions; 45 | 46 | public: 47 | GUIConnection(); 48 | GUIConnection(Window* w1, Window* w2); 49 | ~GUIConnection(); 50 | 51 | Window* GetFirstWindow(); 52 | Window* GetSecondWindow(); 53 | Window* GetOtherWindow(Window* wnd); 54 | bool ContainWindow(Window* wnd); 55 | 56 | void SetAction(Window* wnd, GUI_ACTIONS actionMain, GUI_ACTIONS actionOther); 57 | 58 | friend class GUIManager; 59 | }; 60 | 61 | 62 | typedef std::set WindowsSet; 63 | typedef std::set GUIConnectionsSet; 64 | typedef std::map GUIConnectionsMap; 65 | typedef std::map GUISignals; 66 | 67 | 68 | class GUIManager { 69 | private: 70 | WindowsSet windows; 71 | GUIConnectionsMap connectionsMap; 72 | 73 | Signal onResizeMainWindow; 74 | GUISignals onSetPosition; 75 | GUISignals onSetSize; 76 | 77 | LuaScript* guiMaker; 78 | LuaScript* guiKeyChecker; 79 | 80 | public: 81 | MUTEX lockGUIManager; 82 | 83 | public: 84 | GUIManager(); 85 | ~GUIManager(); 86 | 87 | void CleanUp(); 88 | 89 | void AddWindow(Window* wnd); 90 | void RemoveWindow(Window* wnd); 91 | WindowsSet GetWindows(); 92 | void ClearWindows(); 93 | bool ContainWindow(Window* wnd); 94 | 95 | GUIConnection* AddConnection(Window* wnd1, Window* wnd2); 96 | void RemoveConnection(GUIConnection* connection); 97 | void RemoveConnections(Window* wnd); 98 | GUIConnectionsSet GetConnections(Window* wnd); 99 | 100 | void MakeGUI(); 101 | bool CheckGUIKey(Keyboard* keyboard); 102 | 103 | void AddActionOnResizeMainWindow(boost::function func); 104 | void AddActionOnSetPosition(Window* wnd, boost::function func); 105 | void AddActionOnSetSize(Window* wnd, boost::function func); 106 | bool ExecuteOnResizeMainWindow(); 107 | bool ExecuteOnSetPosition(Window* wnd); 108 | bool ExecuteOnSetSize(Window* wnd); 109 | void ClearActionsOnResizeMainWindow(); 110 | void ClearActionsOnSetPosition(Window* wnd); 111 | void ClearActionsOnSetSize(Window* wnd); 112 | 113 | void OnWindowChangePosition(Window* wnd, int dx, int dy, GUIConnection* excludeConnection = NULL); 114 | void OnWindowChangeSize(Window* wnd, int dx, int dy, bool negative, GUIConnection* excludeConnection = NULL); 115 | 116 | //Lua functions 117 | static int LuaGUIAddWindow(lua_State* L); 118 | static int LuaGUIRemoveWindow(lua_State* L); 119 | static int LuaGUIGetWindows(lua_State* L); 120 | static int LuaGUIClearWindows(lua_State* L); 121 | static int LuaGUIContainWindow(lua_State* L); 122 | static int LuaGUIAddConnection(lua_State* L); 123 | static int LuaGUIRemoveConnection(lua_State* L); 124 | static int LuaGUIRemoveConnections(lua_State* L); 125 | static int LuaGUIGetConnections(lua_State* L); 126 | static int LuaGUIAddActionOnResizeMainWindow(lua_State* L); 127 | static int LuaGUIAddActionOnSetPosition(lua_State* L); 128 | static int LuaGUIAddActionOnSetSize(lua_State* L); 129 | 130 | static int LuaGUIConnGetFirstWindow(lua_State* L); 131 | static int LuaGUIConnGetSecondWindow(lua_State* L); 132 | static int LuaGUIConnGetOtherWindow(lua_State* L); 133 | static int LuaGUIConnContainWindow(lua_State* L); 134 | static int LuaGUIConnSetAction(lua_State* L); 135 | 136 | static void LuaRegisterFunctions(lua_State* L); 137 | }; 138 | 139 | #endif //__GUIMANAGER_H_ 140 | -------------------------------------------------------------------------------- /src/icons.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __ICONS_H_ 6 | #define __ICONS_H_ 7 | 8 | #include 9 | 10 | #include "ad2d.h" 11 | #include "luascript.h" 12 | #include "mthread.h" 13 | 14 | typedef std::map IconsMap; 15 | 16 | class Icons { 17 | private: 18 | static AD2D_Image logoIcon; 19 | 20 | static AD2D_Image shinerIcon; 21 | 22 | static AD2D_Image attackIcon; 23 | static AD2D_Image followIcon; 24 | static AD2D_Image selectIcon; 25 | 26 | static AD2D_Image dirArrowIcon; 27 | static AD2D_Image posArrowIcon; 28 | 29 | static AD2D_Image slotIcons[10]; 30 | static AD2D_Image skullIcons[5]; 31 | static AD2D_Image shieldIcons[10]; 32 | static AD2D_Image fightIcons[6]; 33 | static AD2D_Image statusIcons[15]; 34 | static AD2D_Image buttonIcons[1]; 35 | static AD2D_Image* minimapIcons[256]; 36 | static AD2D_Image* waypointIcons[256]; 37 | 38 | static AD2D_Image spellGroupIcons[4]; 39 | static AD2D_Image* spellIcons[256]; 40 | 41 | static IconsMap customIcons; 42 | 43 | static MUTEX lockIcons; 44 | 45 | public: 46 | static std::string logoFilename; 47 | 48 | public: 49 | Icons(); 50 | ~Icons(); 51 | 52 | static void LoadCustomIcon(unsigned int id); 53 | void LoadIcons(const char* path); 54 | 55 | static AD2D_Image* GetLogoIcon(); 56 | static AD2D_Image* GetShinerIcon(); 57 | static AD2D_Image* GetAttackIcon(); 58 | static AD2D_Image* GetFollowIcon(); 59 | static AD2D_Image* GetSelectIcon(); 60 | static AD2D_Image* GetDirArrowIcon(); 61 | static AD2D_Image* GetPosArrowIcon(); 62 | static AD2D_Image* GetSlotIcon(unsigned char slot); 63 | static AD2D_Image* GetSkullIcon(unsigned char skull); 64 | static AD2D_Image* GetShieldIcon(unsigned char shield); 65 | static AD2D_Image* GetFightIcon(unsigned char fight); 66 | static AD2D_Image* GetStatusIcon(unsigned char status); 67 | static AD2D_Image* GetButtonIcon(unsigned char button); 68 | static AD2D_Image* GetMinimapIcon(unsigned char mmap); 69 | static AD2D_Image* GetWaypointIcon(unsigned char wayp); 70 | static AD2D_Image* GetSpellGroupIcon(unsigned char group); 71 | static AD2D_Image* GetSpellIcon(unsigned char spell); 72 | 73 | static AD2D_Image* GetCustomIcon(unsigned int icon); 74 | 75 | //Lua functions 76 | static int LuaGetLogoIcon(lua_State* L); 77 | static int LuaGetAttackIcon(lua_State* L); 78 | static int LuaGetFollowIcon(lua_State* L); 79 | static int LuaGetSelectIcon(lua_State* L); 80 | static int LuaGetDirArrowIcon(lua_State* L); 81 | static int LuaGetPosArrowIcon(lua_State* L); 82 | static int LuaGetSlotIcon(lua_State* L); 83 | static int LuaGetSkullIcon(lua_State* L); 84 | static int LuaGetShieldIcon(lua_State* L); 85 | static int LuaGetFightIcon(lua_State* L); 86 | static int LuaGetStatusIcon(lua_State* L); 87 | static int LuaGetButtonIcon(lua_State* L); 88 | static int LuaGetMinimapIcon(lua_State* L); 89 | static int LuaGetWaypointIcon(lua_State* L); 90 | static int LuaGetSpellGroupIcon(lua_State* L); 91 | static int LuaGetSpellIcon(lua_State* L); 92 | static int LuaGetCustomIcon(lua_State* L); 93 | 94 | static void LuaRegisterFunctions(lua_State* L); 95 | }; 96 | 97 | #endif //__ICONS_H_ 98 | -------------------------------------------------------------------------------- /src/iniloader.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __INILOADER_H_ 6 | #define __INILOADER_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "luascript.h" 14 | 15 | 16 | typedef std::list > > INIEntry; 17 | 18 | class INILoader { 19 | private: 20 | INIEntry entry; 21 | 22 | public: 23 | INILoader(); 24 | ~INILoader(); 25 | 26 | bool OpenFile(std::string path); 27 | bool OpenString(std::string iniString); 28 | bool SaveFile(std::string path); 29 | std::string GetValue(std::string varname, int index = 0); 30 | std::string GetValue(int pos, int index = 0); 31 | void SetValue(std::string varname, std::string value, int index = 0); 32 | 33 | unsigned int GetSize(); 34 | std::string GetVarName(unsigned int pos); 35 | 36 | 37 | //Lua functions 38 | static int LuaNewINILoader(lua_State* L); 39 | static int LuaDeleteINILoader(lua_State* L); 40 | static int LuaOpenFile(lua_State* L); 41 | static int LuaOpenString(lua_State* L); 42 | static int LuaSaveFile(lua_State* L); 43 | static int LuaGetValue(lua_State* L); 44 | static int LuaSetValue(lua_State* L); 45 | static int LuaGetSize(lua_State* L); 46 | static int LuaGetVarName(lua_State* L); 47 | 48 | static void LuaRegisterFunctions(lua_State* L); 49 | }; 50 | 51 | 52 | #endif //__INILOADER_H_ 53 | -------------------------------------------------------------------------------- /src/input.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __INPUT_H_ 6 | #define __INPUT_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "luascript.h" 12 | 13 | 14 | enum MOUSE_BUTTONS { 15 | MOUSE_NONE = 0x000, 16 | MOUSE_LEFT = 0x001, 17 | MOUSE_MIDDLE = 0x002, 18 | MOUSE_RIGHT = 0x004, 19 | MOUSE_LEFT_DBL = 0x008, 20 | MOUSE_MIDDLE_DBL = 0x010, 21 | MOUSE_RIGHT_DBL = 0x020, 22 | MOUSE_OLD_LEFT = 0x040, 23 | MOUSE_OLD_MIDDLE = 0x080, 24 | MOUSE_OLD_RIGHT = 0x100, 25 | MOUSE_OLD_LEFT_DBL = 0x200, 26 | MOUSE_OLD_MIDDLE_DBL = 0x400, 27 | MOUSE_OLD_RIGHT_DBL = 0x800, 28 | }; 29 | 30 | 31 | struct HOLDER { 32 | int posX; 33 | int posY; 34 | unsigned char type; 35 | void* holder; 36 | void* variable; 37 | void* window; 38 | }; 39 | 40 | 41 | class Mouse { 42 | private: 43 | HOLDER holder; 44 | 45 | public: 46 | int curX; 47 | int curY; 48 | int oldCurX; 49 | int oldCurY; 50 | int lockX; 51 | int lockY; 52 | int wheel; 53 | int cursor; 54 | 55 | std::string comment; 56 | 57 | unsigned short buttons; 58 | 59 | public: 60 | Mouse(); 61 | ~Mouse(); 62 | 63 | void SetHolder(int posX, int posY, unsigned char _type, void* _window = NULL, void* _holder = NULL, void* _variable = NULL); 64 | HOLDER GetHolder(); 65 | void SetLock(int posX, int posY); 66 | unsigned short GetButtons(); 67 | void UpdateMouse(MSG& msg); 68 | 69 | void SetMouseCursor(LPCTSTR cursor); 70 | 71 | //Lua functions 72 | static int LuaSetMouseHolder(lua_State* L); 73 | static int LuaGetMouseHolder(lua_State* L); 74 | static int LuaGetMouseButtons(lua_State* L); 75 | static int LuaGetMousePosition(lua_State* L); 76 | 77 | static void LuaRegisterFunctions(lua_State* L); 78 | }; 79 | 80 | 81 | class Keyboard { 82 | public: 83 | bool key[256]; 84 | bool oldKey[256]; 85 | 86 | bool capsLock; 87 | bool numLock; 88 | bool scrollLock; 89 | 90 | int keyChar; 91 | int oldKeyChar; 92 | 93 | public: 94 | Keyboard(); 95 | ~Keyboard(); 96 | 97 | void UpdateKeyboard(MSG& msg); 98 | void UpdateKeyChar(MSG& msg); 99 | 100 | void ResetKeyboardStatus(); 101 | 102 | //Lua functions 103 | static int LuaGetKeyState(lua_State* L); 104 | static int LuaGetCapsLockState(lua_State* L); 105 | static int LuaGetNumLockState(lua_State* L); 106 | static int LuaGetScrollLockState(lua_State* L); 107 | static int LuaGetKeyChar(lua_State* L); 108 | static int LuaGetOldKeyChar(lua_State* L); 109 | 110 | static void LuaRegisterFunctions(lua_State* L); 111 | }; 112 | 113 | #endif //__INPUT_H_ 114 | -------------------------------------------------------------------------------- /src/item.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __ITEM_H_ 6 | #define __ITEM_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "ad2d.h" 13 | #include "logger.h" 14 | #include "luascript.h" 15 | #include "mthread.h" 16 | #include "position.h" 17 | #include "thing.h" 18 | 19 | 20 | typedef std::set ItemsSet; 21 | 22 | 23 | struct ThingData { 24 | Position fromPos; 25 | Position toPos; 26 | unsigned char fromStackPos; 27 | unsigned short itemId; 28 | unsigned char count; 29 | unsigned char* scroll; 30 | 31 | ThingData() { } 32 | ThingData(ThingData* thing) { *this = *thing; } 33 | }; 34 | 35 | struct ColorTemplate { 36 | AD2D_Image* all; 37 | AD2D_Image* head; 38 | AD2D_Image* body; 39 | AD2D_Image* legs; 40 | AD2D_Image* feet; 41 | 42 | ColorTemplate() { 43 | all = NULL; 44 | head = NULL; 45 | body = NULL; 46 | legs = NULL; 47 | feet = NULL; 48 | } 49 | }; 50 | 51 | class Sprites { 52 | private: 53 | static unsigned char* spritesData; 54 | 55 | static std::map handlers; 56 | static std::map sprites; 57 | static std::map templates; 58 | 59 | public: 60 | static std::string version; 61 | 62 | public: 63 | static bool LoadSpritesFromSpr(std::string path, std::string ver); 64 | static bool LoadSprite(unsigned short number, bool colorTemplate = false, bool updateOutfit = false); 65 | static bool UpdateOutfit(AD2D_Image* outfit, ColorTemplate* ct, ColorTemplate* ct_outfit); 66 | static void CreateColorTemplate(unsigned char* data, ColorTemplate* ct); 67 | static void ReleaseSpritesData(); 68 | static void ReleaseSprites(); 69 | 70 | static AD2D_Image* GetSprite(unsigned short number); 71 | static ColorTemplate* GetColorTemplate(unsigned short number, AD2D_Image* outfit = NULL, ColorTemplate* ct = NULL); 72 | }; 73 | 74 | class ItemType { 75 | public: 76 | bool ground; 77 | bool topItem1; 78 | bool topItem2; 79 | bool topItem3; 80 | bool container; 81 | bool stackable; 82 | bool ladder; 83 | bool useable; 84 | bool writeable1; 85 | bool writeable2; 86 | bool fluid; 87 | bool multiType; 88 | bool blocking; 89 | bool notMoveable; 90 | bool blockMissiles; 91 | bool blockPathFind; 92 | bool pickupable; 93 | bool wall; 94 | bool horizontal; 95 | bool vertical; 96 | bool rotateable; 97 | bool light; 98 | bool hole; 99 | bool hasOffset; 100 | bool hasHeight; 101 | bool drawWithHeightOffset; 102 | bool idleAnimated; 103 | bool minimap; 104 | bool action; 105 | bool floorChange; 106 | bool animated; 107 | 108 | unsigned short speed; 109 | unsigned short height; 110 | unsigned short xOffset; 111 | unsigned short yOffset; 112 | unsigned short lightColor; 113 | unsigned short lightRadius; 114 | unsigned short minimapColor; 115 | unsigned short textLength; 116 | unsigned short actionType; 117 | 118 | unsigned char m_width; 119 | unsigned char m_height; 120 | unsigned char m_skip; 121 | unsigned char m_blend; 122 | unsigned char m_xdiv; 123 | unsigned char m_ydiv; 124 | unsigned char m_pos; 125 | unsigned char m_anim; 126 | unsigned short m_sprNum; 127 | unsigned short* m_sprPtr; 128 | 129 | public: 130 | ItemType(); 131 | ~ItemType(); 132 | 133 | friend class Item; 134 | }; 135 | 136 | class Item : public Thing { 137 | public: 138 | unsigned short id; 139 | unsigned char count; 140 | unsigned int shine; 141 | 142 | private: 143 | static std::map items; 144 | 145 | static int itemsCount; 146 | static int creaturesCount; 147 | static int effectsCount; 148 | static int distancesCount; 149 | 150 | public: 151 | static MUTEX lockItem; 152 | 153 | static ItemsSet movingItems; 154 | 155 | static std::string version; 156 | 157 | public: 158 | Item(); 159 | Item(Item* item); 160 | virtual ~Item(); 161 | 162 | void SetID(unsigned short id); 163 | unsigned short GetID(); 164 | void SetCount(unsigned char count); 165 | unsigned char GetCount(); 166 | void SetShine(unsigned int shine); 167 | unsigned int GetShine(); 168 | void SetLight(); 169 | 170 | bool IsGround(); 171 | unsigned char GetTopOrder(); 172 | 173 | ItemType* operator()(); 174 | 175 | static bool LoadItemsFromDatFIRST(std::string path, std::string ver); 176 | static bool LoadItemsFromDatSECOND(std::string path, std::string ver); 177 | static bool LoadItemsFromDatTHIRD(std::string path, std::string ver); 178 | static bool ReleaseItems(); 179 | 180 | static ItemType* GetItemType(unsigned short number); 181 | 182 | static int GetItemsCount() { return itemsCount; }; 183 | static int GetCreaturesCount() { return creaturesCount; }; 184 | static int GetEffectsCount() { return effectsCount; }; 185 | static int GetDistancesCount() { return distancesCount; }; 186 | 187 | void GetStepOffset(float& x, float& y); 188 | 189 | static void AddMovingItem(Item* item); 190 | static void RemoveMovingItem(Item* item); 191 | static void ClearMovingItems(); 192 | 193 | static void CheckMovingItems(float factor); 194 | 195 | void PrintItem(AD2D_Window* gfx, Position pos, float x, float y, float width, float height, int direction); 196 | void PrintItemShine(AD2D_Window* gfx, Position pos, float x, float y, float width, float height, int direction, unsigned int shine); 197 | 198 | //Lua functions 199 | static int LuaSetItemShine(lua_State* L); 200 | static int LuaGetItemShine(lua_State* L); 201 | 202 | static void LuaRegisterFunctions(lua_State* L); 203 | }; 204 | 205 | #endif //__ITEM_H_ 206 | -------------------------------------------------------------------------------- /src/light.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __LIGHT_H_ 6 | #define __LIGHT_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "ad2d.h" 12 | #include "mthread.h" 13 | #include "position.h" 14 | 15 | 16 | class Item; 17 | class Creature; 18 | class MagicEffect; 19 | class Distance; 20 | 21 | class Map; 22 | 23 | class Lights; 24 | 25 | 26 | class Light { 27 | private: 28 | unsigned char color; 29 | unsigned char level; 30 | 31 | public: 32 | Light(unsigned char color, unsigned char level); 33 | virtual ~Light(); 34 | 35 | friend class Lights; 36 | }; 37 | 38 | 39 | class StaticItemLight : public Light { 40 | private: 41 | Item* item; 42 | 43 | public: 44 | StaticItemLight(Item* item, unsigned char color, unsigned char level); 45 | ~StaticItemLight(); 46 | 47 | friend class Lights; 48 | }; 49 | 50 | 51 | class StaticMagicEffectLight : public Light { 52 | private: 53 | MagicEffect* magicEffect; 54 | 55 | public: 56 | StaticMagicEffectLight(MagicEffect* magicEffect, unsigned char color, unsigned char level); 57 | ~StaticMagicEffectLight(); 58 | 59 | friend class Lights; 60 | }; 61 | 62 | 63 | class DynamicCreatureLight : public Light { 64 | private: 65 | Creature* creature; 66 | 67 | public: 68 | DynamicCreatureLight(Creature* creature, unsigned char color, unsigned char level); 69 | ~DynamicCreatureLight(); 70 | 71 | friend class Lights; 72 | }; 73 | 74 | 75 | class DynamicDistanceLight : public Light { 76 | private: 77 | Distance* distance; 78 | 79 | public: 80 | DynamicDistanceLight(Distance* distance, unsigned char color, unsigned char level); 81 | ~DynamicDistanceLight(); 82 | 83 | friend class Lights; 84 | }; 85 | 86 | 87 | typedef unsigned char LightMap[19][15][3]; 88 | 89 | typedef std::list LightsList; 90 | 91 | class Lights { 92 | private: 93 | static unsigned char globalColor; 94 | static unsigned char globalLevel; 95 | 96 | static LightMap staticMap; 97 | static LightMap dynamicMap; 98 | 99 | static LightsList staticLights; 100 | static LightsList dynamicLights; 101 | 102 | static MUTEX lockLights; 103 | 104 | public: 105 | static void SetGlobalColor(unsigned char color); 106 | static unsigned char GetGlobalColor(); 107 | 108 | static void SetGlobalLevel(unsigned char level); 109 | static unsigned char GetGlobalLevel(); 110 | 111 | static void AddStaticLight(Light* light); 112 | static void RemoveStaticLight(Light* light); 113 | 114 | static void AddDynamicLight(Light* light); 115 | static void RemoveDynamicLight(Light* light); 116 | 117 | static int GetStaticLightsCount(); 118 | static int GetDynamicLightsCount(); 119 | 120 | static void UpdateStaticLightMap(Map* map); 121 | static void UpdateDynamicLightMap(Map* map); 122 | 123 | static void PrintLightMap(AD2D_Window* gfx, unsigned char z, float x, float y, float width, float height); 124 | }; 125 | 126 | #endif //__LIGHT_H_ 127 | -------------------------------------------------------------------------------- /src/logger.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __LOGGER_H_ 6 | #define __LOGGER_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "mthread.h" 12 | 13 | 14 | class NetworkMessage; 15 | 16 | 17 | enum LoggingLevel { 18 | LOG_INFO = 0, 19 | LOG_WARNING = 1, 20 | LOG_ERROR = 2, 21 | }; 22 | 23 | 24 | class Logger { 25 | private: 26 | static LoggingLevel level; 27 | 28 | static std::list > functionBacktrace; 29 | static std::list packetBacktrace; 30 | 31 | static std::string sessionName; 32 | static FILE* session; 33 | static MUTEX lockLogger; 34 | 35 | public: 36 | static void OpenSession(); 37 | static void CloseSession(); 38 | static void SetLoggingLevel(LoggingLevel level); 39 | static void AddLog(std::string function, std::string comment, LoggingLevel level = LOG_INFO, NetworkMessage* msg = NULL); 40 | 41 | static void AddFunction(unsigned int func, bool remember = true); 42 | static void AddPacketType(unsigned short type); 43 | 44 | static void AbortFunction(int sigNum); 45 | }; 46 | 47 | 48 | std::string PrintStack(std::string margin = "\t\t"); 49 | std::string PrintExceptionInfo(std::string margin = "\t\t"); 50 | std::string PrintMemoryDump(std::string margin = "\t\t"); 51 | 52 | 53 | #endif //__LOGGER_H_ 54 | -------------------------------------------------------------------------------- /src/luascript.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __LUASCRIPT_H_ 6 | #define __LUASCRIPT_H_ 7 | 8 | 9 | extern "C" { 10 | #include 11 | #include 12 | #include 13 | } 14 | 15 | #include 16 | #include 17 | 18 | #include "mthread.h" 19 | #include "position.h" 20 | #include "tools.h" 21 | 22 | class Game; 23 | 24 | class LuaScript; 25 | 26 | typedef std::set LuaScripts; 27 | typedef std::map LuaStates; 28 | typedef std::list LuaArguments; 29 | typedef std::map LuaGlobals; 30 | typedef std::map > LuaLocks; 31 | typedef std::set LuaFlags; 32 | 33 | typedef std::pair LuaData; 34 | typedef std::map LuaFiles; 35 | 36 | 37 | enum LUA_FLAGS { 38 | LUAFLAG_QUIT = 0x01, 39 | }; 40 | 41 | class LuaScript { 42 | private: 43 | LuaData data; 44 | std::string fileName; 45 | 46 | lua_State* luaState; 47 | bool running; 48 | bool loaded; 49 | 50 | LuaFlags flags; 51 | static LuaGlobals globals; 52 | static LuaLocks locks; 53 | 54 | static LuaFiles files; 55 | static LuaStates states; 56 | static LuaScripts scripts; 57 | 58 | public: 59 | THREAD scriptThread; 60 | MUTEX lockLuaScript; 61 | static MUTEX lockLuaScripts; 62 | static MUTEX lockLuaStates; 63 | static MUTEX lockLuaData; 64 | 65 | public: 66 | LuaScript(); 67 | ~LuaScript(); 68 | 69 | std::string GetFileName() { return fileName; } 70 | 71 | void SetFlag(LUA_FLAGS flag); 72 | void ClearFlag(LUA_FLAGS flag); 73 | bool HasFlag(LUA_FLAGS flag); 74 | 75 | bool OpenScript(std::string path); 76 | bool Execute(std::string func, LuaArguments args, bool threaded = false); 77 | bool CleanUp(); 78 | bool IsExecuting(); 79 | bool IsLoaded(); 80 | 81 | static LuaArguments ConvertArgs(std::string args); 82 | static std::string GetFilePath(std::string scriptName, bool localDir = false); 83 | static bool RunScript(std::string scriptname, std::string function, LuaArguments args, bool threaded, LuaScript* script = NULL); 84 | static bool RunScript(std::string execution, bool threaded, bool local = false, LuaScript* script = NULL); 85 | 86 | //Static globals functions 87 | static void SetGlobal(std::string key, std::string value); 88 | static std::string GetGlobal(std::string key); 89 | 90 | //Static files functions 91 | static void AddFile(std::string path, unsigned char* buffer, long int size); 92 | static LuaData GetFile(std::string path); 93 | static bool RemoveFile(std::string path); 94 | static void ClearFiles(); 95 | 96 | //Static scripts functions 97 | static void AddLuaScript(LuaScript* script); 98 | static void RemoveLuaScript(LuaScript* script); 99 | static void ClearLuaScripts(); 100 | static void CheckLuaScripts(Game* game); 101 | 102 | static void SetLuaScriptState(lua_State* L, LuaScript* script); 103 | static void ClearLuaScriptState(lua_State* L); 104 | static LuaScript* GetLuaScriptState(lua_State* L); 105 | static void ClearLuaScriptStates(); 106 | 107 | //Debug functions 108 | static void CheckLocks(); 109 | static void CheckGlobals(); 110 | 111 | //Static data functions 112 | static double PopNumber(lua_State* L); 113 | static std::string PopString(lua_State* L); 114 | static Position PopPosition(lua_State* L); 115 | static TypePointer PopPointer(lua_State* L); 116 | static TypePointer ReadPointer(lua_State* L, int p); 117 | 118 | static void PushNumber(lua_State* L, double value); 119 | static void PushString(lua_State* L, std::string value); 120 | static void PushPosition(lua_State* L, Position value); 121 | static void PushPointer(lua_State* L, TypePointer value); 122 | 123 | //Static functions 124 | static int LuaSleep(lua_State* L); 125 | static int LuaRun(lua_State* L); 126 | static int LuaLock(lua_State* L); 127 | static int LuaUnlock(lua_State* L); 128 | static int LuaBitTest(lua_State* L); 129 | static int LuaSetFlag(lua_State* L); 130 | static int LuaClearFlag(lua_State* L); 131 | static int LuaHasFlag(lua_State* L); 132 | static int LuaNew(lua_State* L); 133 | static int LuaDelete(lua_State* L); 134 | static int LuaSetDynamic(lua_State* L); 135 | static int LuaGetDynamic(lua_State* L); 136 | static int LuaSetGlobal(lua_State* L); 137 | static int LuaGetGlobal(lua_State* L); 138 | 139 | static void RegisterFunctions(lua_State* L); 140 | }; 141 | 142 | 143 | #endif //__LUASCRIPT_H_ 144 | -------------------------------------------------------------------------------- /src/magiceffect.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #include "magiceffect.h" 6 | 7 | #include "allocator.h" 8 | #include "ad2d.h" 9 | 10 | 11 | // ---- MagicEffect ---- // 12 | 13 | MagicEffectsList MagicEffect::magicEffects; 14 | 15 | int MagicEffect::threads = 0; 16 | MUTEX MagicEffect::lockMagicEffect; 17 | 18 | MagicEffect::MagicEffect() { 19 | this->iType = NULL; 20 | } 21 | 22 | MagicEffect::~MagicEffect() { 23 | if (light) 24 | delete_debug(light, M_PLACE); 25 | } 26 | 27 | bool MagicEffect::Create(unsigned short lookType, Position pos) { 28 | LOCKCLASS lockClass(lockMagicEffect); 29 | 30 | this->pos = pos; 31 | this->anim = 0; 32 | ItemType* iType = Item::GetItemType(Item::GetItemsCount() + Item::GetCreaturesCount() + lookType); 33 | if (iType && iType->light && iType->lightColor > 0 && iType->lightRadius > 0) 34 | light = new(M_PLACE) StaticMagicEffectLight(this, iType->lightColor, iType->lightRadius); 35 | 36 | this->iType = iType; 37 | 38 | bool exist = false; 39 | MagicEffectsList::iterator it = magicEffects.begin(); 40 | for (it; it != magicEffects.end() && !exist; it++) { 41 | MagicEffect* me = *it; 42 | if (me->pos == pos && iType == me->iType && me->anim < 3) 43 | exist = true; 44 | } 45 | 46 | if (!exist) { 47 | magicEffects.push_back(this); 48 | return true; 49 | } 50 | 51 | return false; 52 | } 53 | 54 | ItemType* MagicEffect::GetItemType() { 55 | return iType; 56 | } 57 | 58 | Position MagicEffect::GetPosition() { 59 | return pos; 60 | } 61 | 62 | void MagicEffect::PrintMagicEffect(AD2D_Window* gfx, Position pos, float x, float y, float width, float height) { 63 | if (!iType) 64 | return; 65 | 66 | int xOffset = 0; 67 | int yOffset = 0; 68 | if (iType->m_xdiv > 1 || iType->m_ydiv > 1) { 69 | xOffset = pos.x % iType->m_xdiv; 70 | yOffset = pos.y % iType->m_ydiv; 71 | } 72 | 73 | AD2D_Image* image = NULL; 74 | for (int pb = 0; pb < iType->m_blend; pb++) 75 | for (int px = 0; px < iType->m_width; px++) 76 | for (int py = 0; py < iType->m_height; py++) { 77 | float mx = x - px * width; 78 | float my = y - py * height; 79 | 80 | int offset = px + (py * iType->m_width) + 81 | (pb * iType->m_width * iType->m_height) + 82 | (xOffset * iType->m_width * iType->m_height * iType->m_blend) + 83 | (yOffset * iType->m_width * iType->m_height * iType->m_blend * iType->m_xdiv) + 84 | (anim * iType->m_width * iType->m_height * iType->m_blend * iType->m_xdiv * iType->m_ydiv); 85 | if (offset < iType->m_sprNum) 86 | image = Sprites::GetSprite(iType->m_sprPtr[offset]); 87 | 88 | if (image) { 89 | gfx->PutImage(mx, my, mx + width, my + height, *image); 90 | } 91 | } 92 | } 93 | 94 | void MagicEffect::RemoveMagicEffect(MagicEffect* me) { 95 | LOCKCLASS lockClass(lockMagicEffect); 96 | 97 | if (!me) { 98 | Logger::AddLog("MagicEffect::RemoveMagicEffect()", "Pointer to magic effect is NULL!", LOG_WARNING); 99 | return; 100 | } 101 | 102 | MagicEffectsList::iterator it = std::find(magicEffects.begin(), magicEffects.end(), me); 103 | if (it != magicEffects.end()) { 104 | magicEffects.erase(it); 105 | delete_debug(me, M_PLACE); 106 | } 107 | else 108 | Logger::AddLog("MagicEffect::RemoveMagicEffect()", "Magic effect not in list!", LOG_WARNING); 109 | } 110 | 111 | void MagicEffect::ClearMagicEffects() { 112 | LOCKCLASS lockClass(lockMagicEffect); 113 | 114 | MagicEffectsList::iterator it = magicEffects.begin(); 115 | for (it; it != magicEffects.end(); it++) { 116 | MagicEffect* me = *it; 117 | delete_debug(me, M_PLACE); 118 | } 119 | magicEffects.clear(); 120 | } 121 | 122 | void MagicEffect::CheckMagicEffects(Game* game) { 123 | if (threads > 0) 124 | return; 125 | 126 | threads++; 127 | 128 | int last_size = 0; 129 | 130 | while(game->GetGameState() == GAME_LOGGEDTOGAME) { 131 | lockMagicEffect.lock(); 132 | 133 | MagicEffectsList toDelete; 134 | 135 | int size_before = magicEffects.size(); 136 | 137 | MagicEffectsList::iterator it = magicEffects.begin(); 138 | for (it; it != magicEffects.end(); it++) { 139 | MagicEffect* me = *it; 140 | if (me) { 141 | me->anim++; 142 | if (me->iType && me->anim >= me->iType->m_anim) 143 | toDelete.push_back(me); 144 | } 145 | } 146 | 147 | it = toDelete.begin(); 148 | for (it; it != toDelete.end(); it++) { 149 | MagicEffect* me = *it; 150 | RemoveMagicEffect(me); 151 | } 152 | 153 | int size_after = magicEffects.size(); 154 | 155 | lockMagicEffect.unlock(); 156 | 157 | if (size_before != size_after || size_after != last_size) 158 | Lights::UpdateStaticLightMap(game->GetMap()); 159 | 160 | last_size = size_after; 161 | 162 | Sleep(100); 163 | } 164 | 165 | ClearMagicEffects(); 166 | 167 | threads--; 168 | } 169 | 170 | void MagicEffect::PrintMagicEffects(AD2D_Window* gfx, Position pos, float x, float y, float width, float height) { 171 | LOCKCLASS lockClass(lockMagicEffect); 172 | 173 | MagicEffectsList::iterator it = magicEffects.begin(); 174 | for (it; it != magicEffects.end(); it++) { 175 | MagicEffect* me = *it; 176 | if (me && me->pos == pos) 177 | me->PrintMagicEffect(gfx, pos, x, y, width, height); 178 | } 179 | } 180 | -------------------------------------------------------------------------------- /src/magiceffect.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __MAGICEFFECT_H_ 6 | #define __MAGICEFFECT_H_ 7 | 8 | #include 9 | 10 | #include "ad2d.h" 11 | #include "game.h" 12 | #include "item.h" 13 | #include "mthread.h" 14 | #include "position.h" 15 | #include "thing.h" 16 | 17 | 18 | class Game; 19 | 20 | class MagicEffect; 21 | 22 | 23 | typedef std::list MagicEffectsList; 24 | 25 | class MagicEffect : public Thing { 26 | private: 27 | ItemType* iType; 28 | unsigned short anim; 29 | 30 | static MagicEffectsList magicEffects; 31 | 32 | static int threads; 33 | static MUTEX lockMagicEffect; 34 | 35 | public: 36 | MagicEffect(); 37 | ~MagicEffect(); 38 | 39 | bool Create(unsigned short lookType, Position pos); 40 | 41 | ItemType* GetItemType(); 42 | Position GetPosition(); 43 | 44 | void PrintMagicEffect(AD2D_Window* gfx, Position pos, float x, float y, float width, float height); 45 | 46 | static void RemoveMagicEffect(MagicEffect* me); 47 | static void ClearMagicEffects(); 48 | 49 | static void CheckMagicEffects(Game* game); 50 | static void PrintMagicEffects(AD2D_Window* gfx, Position pos, float x, float y, float width, float height); 51 | }; 52 | 53 | #endif //__MAGICEFFECT_H_ 54 | -------------------------------------------------------------------------------- /src/map.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __MAP_H_ 6 | #define __MAP_H_ 7 | 8 | #include 9 | 10 | #include "ad2d.h" 11 | #include "battle.h" 12 | #include "creature.h" 13 | #include "light.h" 14 | #include "logger.h" 15 | #include "luascript.h" 16 | #include "minimap.h" 17 | #include "mthread.h" 18 | #include "position.h" 19 | #include "thing.h" 20 | #include "window.h" 21 | 22 | class Creature; 23 | class Player; 24 | 25 | class Map; 26 | 27 | 28 | struct AStarNode { 29 | AStarNode* parent; 30 | int F; 31 | int x; 32 | int y; 33 | Direction dir; 34 | }; 35 | 36 | 37 | typedef std::set PositionArrowsSet; 38 | 39 | 40 | class Tile { 41 | private: 42 | std::list things; 43 | std::list downThings; 44 | std::list creatureThings; 45 | std::list topThings; 46 | 47 | std::list tempCreatures; 48 | 49 | public: 50 | bool horizontal; 51 | bool vertical; 52 | Position pos; 53 | 54 | static MUTEX lockTile; 55 | 56 | public: 57 | Tile(); 58 | ~Tile(); 59 | 60 | void AddThing(Thing* thing); 61 | void InsertThing(Thing* thing, unsigned char stackPos = 255); 62 | void RemoveThing(Thing* thing); 63 | void TransformThing(Thing* thing, unsigned char stackPos); 64 | void AddTempCreature(Creature* creature); 65 | void RemoveTempCreature(Creature* creature); 66 | 67 | unsigned char GetSize(); 68 | unsigned char GetDownSize(); 69 | unsigned char GetCreaturesSize(); 70 | unsigned char GetTopSize(); 71 | unsigned char GetTempCreaturesSize(); 72 | 73 | int GetDownHeight(); 74 | 75 | unsigned char GetThingStackPos(Thing* thing); 76 | Thing* GetThingByStackPos(unsigned char stackPos); 77 | Thing* GetDownThingByStackPos(unsigned char stackPos); 78 | Thing* GetCreatureThingByStackPos(unsigned char stackPos); 79 | Thing* GetTopThingByStackPos(unsigned char stackPos); 80 | Creature* GetTempCreatureByStackPos(unsigned char stackPos); 81 | 82 | Thing* GetGroundThing(); 83 | Thing* GetTopTopThing(); 84 | Thing* GetTopCreatureThing(bool tempCreature = false); 85 | Thing* GetTopDownThing(); 86 | Thing* GetMoveableThing(); 87 | Thing* GetUseableThing(bool useWith = false); 88 | 89 | unsigned short GetSpeed(); 90 | unsigned char GetMiniMapColor(); 91 | bool IsBlocking(bool ignoreCreatures = false, bool ignorePathBlock = false); 92 | 93 | bool IsHorizontal(); 94 | bool IsVertical(); 95 | 96 | void SortThings(); 97 | 98 | friend class Map; 99 | }; 100 | 101 | 102 | class Map { 103 | private: 104 | Tile* tiles[18][14][16]; 105 | Position corner; 106 | 107 | MiniMap* minimap; 108 | Battle* battle; 109 | 110 | bool fullZ; 111 | unsigned char fromZ; 112 | unsigned char toZ; 113 | 114 | public: 115 | static MUTEX lockMap; 116 | 117 | static AD2D_Image mapImage; 118 | 119 | static PositionArrowsSet posArrows; 120 | static std::list creatures; 121 | 122 | static bool mapUpdated; 123 | 124 | public: 125 | Map(); 126 | ~Map(); 127 | 128 | void SetMiniMap(MiniMap* minimap); 129 | MiniMap* GetMiniMap(); 130 | void SetBattle(Battle* battle); 131 | Battle* GetBattle(); 132 | 133 | void ChangeMiniMapZoom(float multiplier); 134 | void ResetMiniMapZoom(); 135 | void MoveMiniMapLevel(char step); 136 | void ResetMiniMapLevel(); 137 | void SetMiniMapPix(Position tilePos, Tile* tile); 138 | void UpdateMiniMap(); 139 | void ReadMiniMap(int x = 0, int y = 0, int w = 256, int h = 256); 140 | void WriteMiniMap(); 141 | void CloseMiniMapFile(); 142 | 143 | void AddBattle(Tile* tile); 144 | void RemoveBattle(Tile* tile); 145 | unsigned int GetBattleID(int number); 146 | void ClearBattle(); 147 | void UpdateBattle(); 148 | void UpdateBattleContainer(); 149 | 150 | void SetCorner(Position corner); 151 | Position GetCorner(); 152 | void ClearMap(int sx = 0, int sy = 0, int width = 18, int height = 14, int zFrom = 0, int zTo = 15); 153 | void DeleteMap(int sx = 0, int sy = 0, int width = 18, int height = 14, int zFrom = 0, int zTo = 15); 154 | void MoveMap(int offsetX, int offsetY); 155 | 156 | void SetTile(int x, int y, int z, Tile* tile); 157 | void SetTile(Position pos, Tile* tile); 158 | Tile* GetTile(int x, int y, int z); 159 | Tile* GetTile(Position pos); 160 | 161 | static void SetDirectionPosition(Position pos); 162 | static void AddPositionArrow(Position pos); 163 | static void RemovePositionArrow(Position pos); 164 | static void ClearPositionArrows(); 165 | 166 | void ToggleZ(); 167 | void CalculateZ(Position pos); 168 | POINT GetZ(); 169 | 170 | Tile* GetTopTile(int x, int y, int z_from, int z_to); 171 | bool IsHiddenTile(int x, int y, int z, int z_to); 172 | 173 | void AddTempCreature(Position pos, Creature* creature); 174 | void RemoveTempCreature(Position pos, Creature* creature); 175 | 176 | void FindWay(Player* player, Position to, std::list& list); 177 | 178 | void SortThings(int sx = 0, int sy = 0, int width = 18, int height = 14); 179 | 180 | void RenderMap(AD2D_Window* gfx, Player* player); 181 | void PrintMap(AD2D_Window* gfx, AD2D_Font* font, Player* player, int x, int y, int width, int height); 182 | 183 | //Lua functions 184 | static int LuaGetPathTo(lua_State* L); 185 | static int LuaGetWaypoint(lua_State* L); 186 | static int LuaGetWaypointsSize(lua_State* L); 187 | static int LuaGetItemByStackPos(lua_State* L); 188 | static int LuaGetTopTopItem(lua_State* L); 189 | static int LuaGetTopDownItem(lua_State* L); 190 | static int LuaGetUseableItem(lua_State* L); 191 | static int LuaSetDirectionPosition(lua_State* L); 192 | static int LuaAddPositionArrow(lua_State* L); 193 | static int LuaRemovePositionArrow(lua_State* L); 194 | static int LuaClearPositionArrows(lua_State* L); 195 | 196 | static void LuaRegisterFunctions(lua_State* L); 197 | }; 198 | 199 | #endif //__MAP_H_ 200 | -------------------------------------------------------------------------------- /src/messages.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __MESSAGES_H_ 6 | #define __MESSAGES_H_ 7 | 8 | #include "game.h" 9 | #include "mthread.h" 10 | #include "position.h" 11 | #include "tools.h" 12 | 13 | class Message { 14 | public: 15 | TextString text; 16 | int liveTime; 17 | int maxLiveTime; 18 | 19 | public: 20 | Message(TextString txt, int ltime); 21 | virtual ~Message(); 22 | }; 23 | 24 | 25 | class SystemMessage : public Message { 26 | public: 27 | float posX; 28 | float posY; 29 | 30 | public: 31 | SystemMessage(TextString txt, int ltime, float pX, float pY); 32 | virtual ~SystemMessage(); 33 | }; 34 | 35 | 36 | class TextMessage : public Message { 37 | public: 38 | Position pos; 39 | bool multiLevel; 40 | 41 | public: 42 | TextMessage(TextString txt, int ltime, Position ps, bool mlvl = false); 43 | virtual ~TextMessage(); 44 | }; 45 | 46 | 47 | class AnimatedMessage : public Message { 48 | public: 49 | Position pos; 50 | float offsetX; 51 | float offsetY; 52 | 53 | public: 54 | AnimatedMessage(TextString txt, int ltime, Position ps, float offX = 0, float offY = 0); 55 | virtual ~AnimatedMessage(); 56 | }; 57 | 58 | 59 | typedef std::list MessagesList; 60 | 61 | class Messages { 62 | private: 63 | static MessagesList messages; 64 | 65 | static int threads; 66 | static MUTEX lockMessages; 67 | 68 | public: 69 | Messages(); 70 | ~Messages(); 71 | 72 | static void AddMessage(Message* message); 73 | static void RemoveMessage(Message* message); 74 | static void ClearMessages(); 75 | 76 | static void CheckMessages(Game* game); 77 | static void PrintMessages(AD2D_Window* gfx, AD2D_Font* font, Position pos, unsigned char level, float x, float y, float zoom); 78 | }; 79 | 80 | 81 | #endif //__MESSAGES_H_ 82 | -------------------------------------------------------------------------------- /src/minimap.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __MINIMAP_H_ 6 | #define __MINIMAP_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "ad2d.h" 12 | #include "luascript.h" 13 | #include "mthread.h" 14 | #include "position.h" 15 | #include "realtime.h" 16 | #include "tools.h" 17 | 18 | typedef std::pair Marker; 19 | typedef std::map MarkersMap; 20 | 21 | typedef std::pair Waypoint; 22 | typedef std::pair WaypointElement; 23 | typedef std::list WaypointsList; 24 | 25 | class MiniMap { 26 | private: 27 | AD2D_Image* minimap; 28 | unsigned char* data; 29 | unsigned short* sdata; 30 | 31 | time_lt lastUpdate; 32 | 33 | FILE* wfile; 34 | FILE* rfile; 35 | unsigned int wfileN; 36 | unsigned int rfileN; 37 | unsigned char wdata[12288]; 38 | unsigned char rdata[12288]; 39 | 40 | float cx; 41 | float cy; 42 | char cz; 43 | 44 | float offsetX; 45 | float offsetY; 46 | float zoom; 47 | 48 | MarkersMap markers; 49 | WaypointsList waypoints; 50 | 51 | public: 52 | static bool updateImage; 53 | static MUTEX lockMiniMap; 54 | 55 | public: 56 | MiniMap(); 57 | ~MiniMap(); 58 | 59 | void AddMarker(Position pos, Marker marker); 60 | Marker GetMarker(Position pos); 61 | void RemoveMarker(Position pos); 62 | MarkersMap GetMarkers(); 63 | void ClearMarkers(); 64 | 65 | void AddWaypoint(Position pos, Waypoint waypoint, unsigned short num = 0xFFFF); 66 | Waypoint GetWaypoint(Position pos); 67 | unsigned short GetWaypointNumber(Position pos); 68 | void RemoveWaypoint(Position pos); 69 | WaypointsList GetWaypoints(); 70 | void ClearWaypoints(); 71 | 72 | void FileGetMap(Position corner, int x, int y, int w, int h); 73 | void FileSetPix(Position pix, unsigned char color, unsigned short speed); 74 | void FileFlush(); 75 | void CloseFile(); 76 | 77 | void UpdateImage(); 78 | void ClearImage(); 79 | 80 | void MoveLevel(char step); 81 | void ResetLevel(); 82 | char GetOffsetLevel(); 83 | 84 | void SetZoom(float zoom); 85 | float GetZoom(); 86 | void ChangeZoom(float multiplier); 87 | void ResetZoom(); 88 | void GetOffsetPos(float& x, float& y); 89 | void SetOffsetPos(float x, float y); 90 | 91 | void ClearMiniMap(); 92 | void MoveMiniMap(int dx, int dy); 93 | void SetPix(Position corner, Position pix, unsigned char color, unsigned short speed); 94 | void SetPix(int x, int y, unsigned char color); 95 | unsigned short GetSpeed(int x, int y); 96 | unsigned short GetSpeed(Position corner, Position pix); 97 | 98 | void PrintMiniMap(AD2D_Window* gfx, float width, float height); 99 | 100 | //Lua functions 101 | static int LuaGetMiniMap(lua_State* L); 102 | static int LuaMiniMapChangeLevel(lua_State* L); 103 | static int LuaMiniMapResetLevel(lua_State* L); 104 | static int LuaMiniMapSetZoom(lua_State* L); 105 | static int LuaMiniMapGetZoom(lua_State* L); 106 | static int LuaMiniMapChangeZoom(lua_State* L); 107 | static int LuaMiniMapResetZoom(lua_State* L); 108 | 109 | static void LuaRegisterFunctions(lua_State* L); 110 | }; 111 | 112 | #endif //__MINIMAP_H_ 113 | -------------------------------------------------------------------------------- /src/mthread.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #include "mthread.h" 6 | 7 | #include 8 | 9 | #include "allocator.h" 10 | #include "tools.h" 11 | 12 | 13 | // ---- Signal ---- // 14 | 15 | 16 | Signal::Signal() { } 17 | 18 | Signal::Signal(const Signal& signal) { 19 | this->functions = signal.functions; 20 | } 21 | 22 | Signal::~Signal() { } 23 | 24 | 25 | Functions::iterator Signal::PushFunction(boost::function func) { 26 | LOCKCLASS lockClass(lockSignal); 27 | 28 | Functions::iterator it = functions.end(); 29 | functions.push_back(std::pair, bool>(func, true)); 30 | 31 | return it; 32 | } 33 | 34 | void Signal::BlockFunction(Functions::iterator it) { 35 | LOCKCLASS lockClass(lockSignal); 36 | 37 | if (it != functions.end()) 38 | it->second = false; 39 | } 40 | 41 | void Signal::UnblockFunction(Functions::iterator it) { 42 | LOCKCLASS lockClass(lockSignal); 43 | 44 | if (it != functions.end()) 45 | it->second = true; 46 | } 47 | 48 | bool Signal::IsExecutable() { 49 | LOCKCLASS lockClass(lockSignal); 50 | 51 | bool executable = false; 52 | 53 | Functions::iterator it = functions.begin(); 54 | for (it; it != functions.end(); it++) { 55 | if (it->second) 56 | executable = true; 57 | } 58 | 59 | return executable; 60 | } 61 | 62 | void Signal::Execute(bool deleteAfter) { 63 | LOCKCLASS lockClass(lockSignal); 64 | 65 | Functions funcs = functions; 66 | 67 | int num = 0; 68 | Functions::iterator it = funcs.begin(); 69 | for (it; it != funcs.end(); it++, num++) { 70 | if (it->second) 71 | it->first(); 72 | } 73 | 74 | if (!deleteAfter) 75 | return; 76 | 77 | delete_debug(this, M_PLACE); 78 | } 79 | 80 | void Signal::Clear() { 81 | LOCKCLASS lockClass(lockSignal); 82 | 83 | functions.clear(); 84 | } 85 | 86 | 87 | int Signal::GetSize() { 88 | LOCKCLASS lockClass(lockSignal); 89 | 90 | return functions.size(); 91 | } 92 | 93 | 94 | void Signal::Swap(Signal& signal) { 95 | LOCKCLASS lockClass1(lockSignal); 96 | LOCKCLASS lockClass2(signal.lockSignal); 97 | 98 | Functions funcs = functions; 99 | functions = signal.functions; 100 | signal.functions = funcs; 101 | } 102 | 103 | void Signal::Assign(Signal& signal) { 104 | LOCKCLASS lockClass1(lockSignal); 105 | LOCKCLASS lockClass2(signal.lockSignal); 106 | 107 | functions = signal.functions; 108 | } 109 | -------------------------------------------------------------------------------- /src/mthread.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __MTHREAD_H_ 6 | #define __MTHREAD_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | #define LOCKCLASS boost::recursive_mutex::scoped_lock 14 | 15 | typedef boost::thread THREAD; 16 | typedef boost::recursive_mutex MUTEX; 17 | 18 | typedef std::list, bool> > Functions; 19 | 20 | 21 | class Signal { 22 | public: 23 | Functions functions; 24 | 25 | MUTEX lockSignal; 26 | 27 | public: 28 | Signal(); 29 | Signal(const Signal& signal); 30 | ~Signal(); 31 | 32 | Functions::iterator PushFunction(boost::function func); 33 | void BlockFunction(Functions::iterator it); 34 | void UnblockFunction(Functions::iterator it); 35 | bool IsExecutable(); 36 | void Execute(bool deleteAfter = false); 37 | void Clear(); 38 | 39 | void Swap(Signal& signal); 40 | void Assign(Signal& signal); 41 | 42 | int GetSize(); 43 | }; 44 | 45 | #endif //__MTHREAD_H_ 46 | -------------------------------------------------------------------------------- /src/network.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __NETWORK_H_ 6 | #define __NETWORK_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "logger.h" 14 | #include "mthread.h" 15 | #include "rsa.h" 16 | 17 | #define NETWORKMESSAGE_SIZE 65536 18 | 19 | class Client { 20 | private: 21 | static boost::asio::io_service io_service; 22 | 23 | boost::asio::ip::tcp::socket socket; 24 | boost::asio::deadline_timer deadline; 25 | 26 | std::list > buffer; 27 | bool writing; 28 | 29 | bool connected; 30 | bool connectionProcess; 31 | 32 | static int clients; 33 | 34 | public: 35 | Client(); 36 | ~Client(); 37 | 38 | static void RUN_THREAD(); 39 | 40 | bool checkError(const boost::system::error_code& error); 41 | 42 | bool Connect(const char* host, const char* port); 43 | void onConnect(const boost::system::error_code& error); 44 | void onTimeout(const boost::system::error_code& error); 45 | 46 | bool Connected(); 47 | size_t ReadyToRead(); 48 | 49 | unsigned int syncRead(char* msg, unsigned int size, bool resetOnError = true); 50 | unsigned int syncWrite(const char* msg, unsigned int size, bool resetOnError = true); 51 | void asyncWrite(const char* msg, unsigned int size); 52 | void close(); 53 | 54 | void doAsyncWrite(char* msg, unsigned int size); 55 | void doClose(); 56 | 57 | void onWrite(const boost::system::error_code& error); 58 | }; 59 | 60 | 61 | class NetworkMessage { 62 | private: 63 | unsigned short version; 64 | 65 | char buffer[NETWORKMESSAGE_SIZE]; 66 | size_t buffSize; 67 | size_t readPos; 68 | size_t startPos; 69 | 70 | RSA* rsa; 71 | unsigned int XTEAkey[4]; 72 | 73 | bool cryptoEnable; 74 | 75 | unsigned int adlerChecksum(unsigned char* data, int len); 76 | 77 | public: 78 | NetworkMessage(); 79 | NetworkMessage(unsigned short version); 80 | NetworkMessage(unsigned short version, unsigned int k[4]); 81 | ~NetworkMessage(); 82 | 83 | NetworkMessage* Clone(unsigned short size); 84 | 85 | void Reset(); 86 | void SetRSA(RSA* rsa); 87 | void SetCrypto(bool state, unsigned int k[4]); 88 | 89 | void SendMessage(Client* client, bool login = false); 90 | void ReceiveMessage(Client* client); 91 | 92 | void AddU8(unsigned char data); 93 | void AddU16(unsigned short data); 94 | void AddU32(unsigned int data); 95 | void AddU64(unsigned long data); 96 | void AddString(std::string data); 97 | 98 | void AddHeaderU16(unsigned short data); 99 | void AddHeaderU32(unsigned int data); 100 | 101 | unsigned char GetU8(); 102 | unsigned short GetU16(); 103 | unsigned int GetU32(); 104 | unsigned long GetU64(); 105 | std::string GetString(); 106 | void Skip(unsigned short size); 107 | 108 | unsigned short GetReadPos(); 109 | unsigned short GetSize(); 110 | bool EndOfPacket(); 111 | 112 | bool RSA_encrypt(size_t pos); 113 | bool RSA_decrypt(); 114 | void XTEA_encrypt(); 115 | void XTEA_decrypt(); 116 | 117 | friend class Logger; 118 | }; 119 | 120 | #endif //__NETWORK_H_ 121 | -------------------------------------------------------------------------------- /src/particle.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #include 6 | 7 | #include "particle.h" 8 | 9 | #include "allocator.h" 10 | #include "filemanager.h" 11 | #include "tools.h" 12 | 13 | 14 | // ---- Particle ---- // 15 | 16 | Particle::Particle(ParticleCondition* condition, Position pos) { 17 | this->pos = pos; 18 | 19 | if (condition) { 20 | this->lookType = condition->lookType; 21 | this->maxLiveTime = (rand() % condition->liveTime); 22 | this->speed = (float)(rand() % condition->speed) / 100; 23 | this->color.red = (float)condition->colorR / 255; 24 | this->color.green = (float)condition->colorG / 255; 25 | this->color.blue = (float)condition->colorB / 255; 26 | this->color.alpha = (float)condition->colorA / 255; 27 | } 28 | else { 29 | this->lookType = 0; 30 | this->maxLiveTime = 0; 31 | this->speed = 0; 32 | } 33 | 34 | this->liveTime = 0; 35 | this->direction = (float)(rand() % 36000) / 100; 36 | this->posX = 0; 37 | this->posY = 0; 38 | } 39 | 40 | Particle::~Particle() { } 41 | 42 | void Particle::SetPosition(float x, float y) { 43 | posX = x; 44 | posY = y; 45 | } 46 | 47 | bool Particle::CheckParticle() { 48 | if (liveTime < maxLiveTime) { 49 | posX += speed * sin(direction * 3.1415 / 180) * 2.5f; 50 | posY -= speed * cos(direction * 3.1415 / 180) * 2.5f; 51 | 52 | liveTime += 25; 53 | speed *= (0.99f - 0.025f); 54 | } 55 | 56 | if (liveTime >= maxLiveTime) 57 | return true; 58 | 59 | return false; 60 | } 61 | 62 | 63 | // ---- Particles ---- // 64 | 65 | ParticleImagesMap Particles::images; 66 | ParticleConditionsMap Particles::conditions; 67 | ParticlesMap Particles::particles; 68 | 69 | int Particles::threads = 0; 70 | MUTEX Particles::lockParticles; 71 | 72 | 73 | Particles::Particles() { } 74 | 75 | Particles::~Particles() { 76 | ReleaseParticles(); 77 | } 78 | 79 | void Particles::LoadParticles(std::string path, unsigned short count) { 80 | LOCKCLASS lockClass(lockParticles); 81 | 82 | FileManager* files = FileManager::fileManager; 83 | if (!files) 84 | return; 85 | 86 | for (int i = 0; i < count; i++) { 87 | AD2D_Image* image = NULL; 88 | 89 | std::string filename = path + std::string("particle") + value2str(i) + std::string(".png"); 90 | unsigned char* data = files->GetFileData(filename); 91 | if (data) { 92 | image = new(M_PLACE) AD2D_Image; 93 | image->CreatePNG_(data, files->GetFileSize(filename)); 94 | images[i] = image; 95 | } 96 | } 97 | 98 | for (int i = 0; i < count; i++) { 99 | std::string filename = path + std::string("particle") + value2str(i) + std::string(".ini"); 100 | INILoader iniParticle; 101 | if (iniParticle.OpenFile(filename)) { 102 | ParticleCondition* condition = new(M_PLACE) ParticleCondition; 103 | 104 | condition->count = atoi(iniParticle.GetValue("COUNT").c_str()); 105 | condition->lookType = atoi(iniParticle.GetValue("LOOKTYPE").c_str()); 106 | condition->colorR = atoi(iniParticle.GetValue("COLOR", 0).c_str()); 107 | condition->colorG = atoi(iniParticle.GetValue("COLOR", 1).c_str()); 108 | condition->colorB = atoi(iniParticle.GetValue("COLOR", 2).c_str()); 109 | condition->colorA = atoi(iniParticle.GetValue("COLOR", 3).c_str()); 110 | condition->liveTime = atoi(iniParticle.GetValue("LIVETIME").c_str()); 111 | condition->speed = atoi(iniParticle.GetValue("SPEED").c_str()); 112 | 113 | conditions[i] = condition; 114 | } 115 | } 116 | } 117 | 118 | void Particles::ReleaseParticles() { 119 | LOCKCLASS lockClass(lockParticles); 120 | 121 | if (!images.empty()) { 122 | ParticleImagesMap::iterator it = images.begin(); 123 | for (it; it != images.end(); it++) { 124 | AD2D_Image* image = it->second; 125 | delete_debug(image, M_PLACE); 126 | } 127 | images.clear(); 128 | } 129 | 130 | if (!conditions.empty()) { 131 | ParticleConditionsMap::iterator it = conditions.begin(); 132 | for (it; it != conditions.end(); it++) { 133 | ParticleCondition* condition = it->second; 134 | delete_debug(condition, M_PLACE); 135 | } 136 | conditions.clear(); 137 | } 138 | 139 | ClearParticles(); 140 | } 141 | 142 | AD2D_Image* Particles::GetParticleImage(unsigned short lookType) { 143 | LOCKCLASS lockClass(lockParticles); 144 | 145 | ParticleImagesMap::iterator it = images.find(lookType); 146 | if (it != images.end()) 147 | return it->second; 148 | 149 | return NULL; 150 | } 151 | 152 | ParticleCondition* Particles::GetParticleCondition(unsigned short type) { 153 | LOCKCLASS lockClass(lockParticles); 154 | 155 | ParticleConditionsMap::iterator it = conditions.find(type); 156 | if (it != conditions.end()) 157 | return it->second; 158 | 159 | return NULL; 160 | } 161 | 162 | void Particles::AddParticle(Particle* particle) { 163 | LOCKCLASS lockClass(lockParticles); 164 | 165 | if (!particle) { 166 | Logger::AddLog("Particles::AddParticle()", "Pointer to particle is NULL!", LOG_WARNING); 167 | return; 168 | } 169 | 170 | unsigned char level = particle->pos.z; 171 | ParticlesList::iterator itl = std::find(particles[level].begin(), particles[level].end(), particle); 172 | if (itl != particles[level].end()) { 173 | Logger::AddLog("Particles::AddParticle()", "Particle already in map!", LOG_WARNING); 174 | return; 175 | } 176 | else 177 | particles[level].push_back(particle); 178 | } 179 | 180 | void Particles::RemoveParticle(Particle* particle) { 181 | LOCKCLASS lockClass(lockParticles); 182 | 183 | if (!particle) { 184 | Logger::AddLog("Particles::RemoveParticle()", "Pointer to particle is NULL!", LOG_WARNING); 185 | return; 186 | } 187 | 188 | unsigned char level = particle->pos.z; 189 | ParticlesMap::iterator it = particles.find(level); 190 | if (it != particles.end()) { 191 | ParticlesList::iterator itl = std::find(it->second.begin(), it->second.end(), particle); 192 | if (itl != it->second.end()) { 193 | it->second.erase(itl); 194 | delete_debug(particle, M_PLACE); 195 | } 196 | else 197 | Logger::AddLog("Particles::RemoveParticle()", "Particle not in map!", LOG_WARNING); 198 | } 199 | else 200 | Logger::AddLog("Particles::RemoveParticle()", "Particle not in map!", LOG_WARNING); 201 | } 202 | 203 | void Particles::ClearParticles() { 204 | LOCKCLASS lockClass(lockParticles); 205 | 206 | if (!particles.empty()) { 207 | ParticlesMap::iterator it = particles.begin(); 208 | for (it; it != particles.end(); it++) { 209 | ParticlesList::iterator itl = it->second.begin(); 210 | for (itl; itl != it->second.end(); itl++) { 211 | Particle* particle = *itl; 212 | delete_debug(particle, M_PLACE); 213 | } 214 | it->second.clear(); 215 | } 216 | particles.clear(); 217 | } 218 | } 219 | 220 | void Particles::CheckParticles(Game* game) { 221 | if (threads > 0) 222 | return; 223 | 224 | threads++; 225 | 226 | while(game->GetGameState() == GAME_LOGGEDTOGAME) { 227 | lockParticles.lock(); 228 | 229 | ParticlesMap::iterator it = particles.begin(); 230 | for (it; it != particles.end(); it++) { 231 | ParticlesList toDelete; 232 | 233 | ParticlesList::iterator itl = it->second.begin(); 234 | for (itl; itl != it->second.end(); itl++) { 235 | Particle* particle = *itl; 236 | if (particle->CheckParticle()) 237 | toDelete.push_back(particle); 238 | } 239 | 240 | itl = toDelete.begin(); 241 | for (itl; itl != toDelete.end(); itl++) { 242 | Particle* particle = *itl; 243 | RemoveParticle(particle); 244 | } 245 | } 246 | 247 | lockParticles.unlock(); 248 | Sleep(25); 249 | } 250 | 251 | ClearParticles(); 252 | 253 | threads--; 254 | } 255 | 256 | void Particles::PrintParticles(AD2D_Window* gfx, Position pos, unsigned char level, float x, float y, float zoom) { 257 | LOCKCLASS lockClass(lockParticles); 258 | 259 | ParticlesMap::iterator it = particles.find(level); 260 | if (it != particles.end()) { 261 | COLOR currentColor = AD2D_Window::GetColor(); 262 | 263 | ParticlesList::iterator itl = it->second.begin(); 264 | for (itl; itl != it->second.end(); itl++) { 265 | Particle* particle = *itl; 266 | 267 | int offset = particle->pos.z - pos.z; 268 | 269 | Position relativePos; 270 | relativePos.x = particle->pos.x - pos.x + offset; 271 | relativePos.y = particle->pos.y - pos.y + offset; 272 | relativePos.z = particle->pos.z; 273 | 274 | float px = x + (particle->posX + (relativePos.x * 32 + 16)) * zoom; 275 | float py = y + (particle->posY + (relativePos.y * 32 + 16)) * zoom; 276 | float alpha = (float)(particle->maxLiveTime - particle->liveTime) / particle->maxLiveTime; 277 | 278 | AD2D_Window::SetColor(particle->color.red, particle->color.green, particle->color.blue, particle->color.alpha * alpha); 279 | AD2D_Image* image = GetParticleImage(particle->lookType); 280 | if (image) 281 | gfx->RotImage(px, py, particle->direction, zoom, *image); 282 | } 283 | 284 | AD2D_Window::SetColor(currentColor.red, currentColor.green, currentColor.blue, currentColor.alpha); 285 | } 286 | } 287 | -------------------------------------------------------------------------------- /src/particle.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __PARTICLE_H_ 6 | #define __PARTICLE_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "ad2d.h" 12 | #include "game.h" 13 | #include "iniloader.h" 14 | #include "logger.h" 15 | #include "mthread.h" 16 | #include "position.h" 17 | 18 | 19 | class Game; 20 | 21 | class Particle; 22 | class Particles; 23 | 24 | 25 | struct ParticleCondition { 26 | unsigned short count; 27 | unsigned short lookType; 28 | unsigned short liveTime; 29 | unsigned short speed; 30 | unsigned char colorR; 31 | unsigned char colorG; 32 | unsigned char colorB; 33 | unsigned char colorA; 34 | }; 35 | 36 | class Particle { 37 | private: 38 | unsigned short lookType; 39 | Position pos; 40 | 41 | unsigned short maxLiveTime; 42 | unsigned short liveTime; 43 | float speed; 44 | float posX; 45 | float posY; 46 | float direction; 47 | COLOR color; 48 | 49 | public: 50 | Particle(ParticleCondition* condition, Position pos); 51 | ~Particle(); 52 | 53 | void SetPosition(float x, float y); 54 | 55 | bool CheckParticle(); 56 | 57 | friend class Particles; 58 | }; 59 | 60 | 61 | typedef std::map ParticleImagesMap; 62 | typedef std::map ParticleConditionsMap; 63 | typedef std::list ParticlesList; 64 | typedef std::map ParticlesMap; 65 | 66 | class Particles { 67 | private: 68 | static ParticleImagesMap images; 69 | static ParticleConditionsMap conditions; 70 | static ParticlesMap particles; 71 | 72 | static int threads; 73 | static MUTEX lockParticles; 74 | 75 | public: 76 | Particles(); 77 | ~Particles(); 78 | 79 | void LoadParticles(std::string path, unsigned short count); 80 | void ReleaseParticles(); 81 | 82 | static AD2D_Image* GetParticleImage(unsigned short lookType); 83 | static ParticleCondition* GetParticleCondition(unsigned short type); 84 | 85 | static void AddParticle(Particle* particle); 86 | static void RemoveParticle(Particle* particle); 87 | static void ClearParticles(); 88 | 89 | static void CheckParticles(Game* game); 90 | static void PrintParticles(AD2D_Window* gfx, Position pos, unsigned char level, float x, float y, float zoom); 91 | }; 92 | 93 | #endif //__PARTICLE_H_ 94 | -------------------------------------------------------------------------------- /src/player.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __PLAYER_H_ 6 | #define __PLAYER_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "const.h" 12 | #include "container.h" 13 | #include "creature.h" 14 | #include "logger.h" 15 | #include "luascript.h" 16 | #include "mthread.h" 17 | #include "thing.h" 18 | 19 | 20 | class Creature; 21 | class Map; 22 | 23 | 24 | struct Statistics { 25 | unsigned short health; 26 | unsigned short maxHealth; 27 | unsigned short mana; 28 | unsigned short maxMana; 29 | 30 | double capacity; 31 | unsigned long experience; 32 | 33 | unsigned short level; 34 | unsigned char level_p; 35 | 36 | unsigned short magicLevel; 37 | unsigned char magicLevel_p; 38 | 39 | unsigned char soul; 40 | unsigned short stamina; 41 | 42 | unsigned char skill[7]; 43 | unsigned char skill_p[7]; 44 | }; 45 | 46 | 47 | class Player { 48 | private: 49 | std::list autoPath; 50 | std::vector nextMove; 51 | 52 | unsigned char fightModes; 53 | Statistics statistics; 54 | Container inventory; 55 | 56 | Position directionPos; 57 | Position targetPos; 58 | 59 | MUTEX lockPlayer; 60 | 61 | public: 62 | static unsigned int creatureID; 63 | static unsigned int attackID; 64 | static unsigned int followID; 65 | static unsigned int selectID; 66 | 67 | static bool requestStop; 68 | static bool walking; 69 | 70 | public: 71 | Player(); 72 | ~Player(); 73 | 74 | static void SetCreatureID(unsigned int ID); 75 | static unsigned int GetCreatureID(); 76 | static void SetAttackID(unsigned int creatureID); 77 | static unsigned int GetAttackID(); 78 | static void SetFollowID(unsigned int creatureID); 79 | static unsigned int GetFollowID(); 80 | static void SetSelectID(unsigned int creatureID); 81 | static unsigned int GetSelectID(); 82 | 83 | void SetAutoPath(std::list& list); 84 | std::list GetAutoPath(); 85 | void PopAutoPath(); 86 | int GetAutoPathSize(); 87 | 88 | void SetNextMove(Direction dir); 89 | Direction GetNextMove(); 90 | Direction PopNextMove(); 91 | void ClearMoves(); 92 | 93 | void SetFightMode(bool state, unsigned char num); 94 | bool GetFightMode(unsigned char num); 95 | void SetFightModes(unsigned char fightModes); 96 | unsigned char GetFightModes(); 97 | Statistics* GetStatistics(); 98 | Container* GetInventory(); 99 | Creature* GetCreature(); 100 | 101 | void SetDirectionPos(Position pos); 102 | Position GetDirectionPos(); 103 | 104 | void SetTargetPos(Position pos); 105 | Position GetTargetPos(); 106 | 107 | Position GetPosition(); 108 | void GetStepOffset(float& x, float& y); 109 | 110 | //Lua function 111 | static int LuaGetPlayerPosition(lua_State* L); 112 | static int LuaGetPlayerHealth(lua_State* L); 113 | static int LuaGetPlayerMaxHealth(lua_State* L); 114 | static int LuaGetPlayerHealthP(lua_State* L); 115 | static int LuaGetPlayerMana(lua_State* L); 116 | static int LuaGetPlayerMaxMana(lua_State* L); 117 | static int LuaGetPlayerManaP(lua_State* L); 118 | static int LuaGetPlayerCapacity(lua_State* L); 119 | static int LuaGetPlayerExperience(lua_State* L); 120 | static int LuaGetPlayerLevel(lua_State* L); 121 | static int LuaGetPlayerLevelP(lua_State* L); 122 | static int LuaGetPlayerMagicLevel(lua_State* L); 123 | static int LuaGetPlayerMagicLevelP(lua_State* L); 124 | static int LuaGetPlayerSoul(lua_State* L); 125 | static int LuaGetPlayerStamina(lua_State* L); 126 | static int LuaGetPlayerSkill(lua_State* L); 127 | static int LuaGetPlayerSkillP(lua_State* L); 128 | static int LuaGetPlayerID(lua_State* L); 129 | static int LuaGetPlayerAttackID(lua_State* L); 130 | static int LuaGetPlayerFollowID(lua_State* L); 131 | static int LuaGetPlayerSelectID(lua_State* L); 132 | static int LuaGetPlayerStep(lua_State* L); 133 | static int LuaGetPlayerBattle(lua_State* L); 134 | static int LuaGetPlayerInventory(lua_State* L); 135 | static int LuaGetPlayerInventoryItem(lua_State* L); 136 | static int LuaPlayerCheckItemPresence(lua_State* L); 137 | 138 | static void LuaRegisterFunctions(lua_State* L); 139 | }; 140 | 141 | #endif //__PLAYER_H_ 142 | -------------------------------------------------------------------------------- /src/position.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #include "position.h" 6 | 7 | 8 | // ---- Position ---- // 9 | 10 | Position::Position() { 11 | x = 0; 12 | y = 0; 13 | z = 0; 14 | } 15 | 16 | Position::Position(int x_, int y_, unsigned char z_) : x(x_), y(y_), z(z_) { } 17 | 18 | Position::~Position() { } 19 | 20 | bool Position::operator==(const Position pos) const { 21 | if (this->x == pos.x && this->y == pos.y && this->z == pos.z) 22 | return true; 23 | 24 | return false; 25 | } 26 | 27 | bool Position::operator!=(const Position pos) const { 28 | if (*this == pos) 29 | return false; 30 | 31 | return true; 32 | } 33 | 34 | bool Position::operator<(const Position pos) const { 35 | if (this->z > pos.z) 36 | return false; 37 | else if (this->z == pos.z && this->y > pos.y) 38 | return false; 39 | else if (this->z == pos.z && this->y == pos.y && this->x >= pos.x) 40 | return false; 41 | 42 | return true; 43 | } 44 | 45 | bool Position::operator<=(const Position pos) const { 46 | if (*this == pos || *this < pos) 47 | return true; 48 | 49 | return false; 50 | } 51 | 52 | bool Position::operator>(const Position pos) const { 53 | if (this->z < pos.z) 54 | return false; 55 | else if (this->z == pos.z && this->y < pos.y) 56 | return false; 57 | else if (this->z == pos.z && this->y == pos.y && this->x <= pos.x) 58 | return false; 59 | 60 | return true; 61 | } 62 | 63 | bool Position::operator>=(const Position pos) const { 64 | if (*this == pos || *this > pos) 65 | return true; 66 | 67 | return false; 68 | } 69 | -------------------------------------------------------------------------------- /src/position.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __POSITION_H_ 6 | #define __POSITION_H_ 7 | 8 | class Position { 9 | public: 10 | int x; 11 | int y; 12 | unsigned char z; 13 | 14 | public: 15 | Position(); 16 | Position(int x_, int y_, unsigned char z_); 17 | ~Position(); 18 | 19 | bool operator==(const Position pos) const; 20 | bool operator!=(const Position pos) const; 21 | bool operator<(const Position pos) const; 22 | bool operator<=(const Position pos) const; 23 | bool operator>(const Position pos) const; 24 | bool operator>=(const Position pos) const; 25 | }; 26 | 27 | #endif //__POSITION_H_ 28 | -------------------------------------------------------------------------------- /src/protocol822.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #include "protocol822.h" 6 | 7 | #include "allocator.h" 8 | #include "channel.h" 9 | #include "cooldowns.h" 10 | #include "messages.h" 11 | #include "particle.h" 12 | #include "position.h" 13 | #include "player.h" 14 | #include "questlog.h" 15 | #include "shop.h" 16 | #include "status.h" 17 | #include "text.h" 18 | #include "tools.h" 19 | #include "window.h" 20 | 21 | #ifndef NO_SOUND 22 | #include "adal.h" 23 | #include "sound.h" 24 | #endif 25 | 26 | 27 | // ---- Protocol ---- // 28 | 29 | Protocol822::Protocol822(Game* game) : Protocol(game) { } 30 | 31 | Protocol822::~Protocol822() { 32 | if (client.Connected()) 33 | client.doClose(); 34 | 35 | if (receiveLoop.joinable()) 36 | receiveLoop.join(); 37 | } 38 | 39 | 40 | unsigned short Protocol822::GetVersion() { 41 | return 822; 42 | } 43 | -------------------------------------------------------------------------------- /src/protocol822.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __PROTOCOL822_H_ 6 | #define __PROTOCOL822_H_ 7 | 8 | #include "channel.h" 9 | #include "const.h" 10 | #include "creature.h" 11 | #include "distance.h" 12 | #include "game.h" 13 | #include "item.h" 14 | #include "light.h" 15 | #include "logger.h" 16 | #include "magiceffect.h" 17 | #include "map.h" 18 | #include "mthread.h" 19 | #include "network.h" 20 | #include "protocol.h" 21 | #include "rsa.h" 22 | 23 | class Channel; 24 | class Creature; 25 | class Game; 26 | class Map; 27 | class Outfit; 28 | class Tile; 29 | 30 | class Protocol822 : public Protocol { 31 | public: 32 | Protocol822(Game* game); 33 | virtual ~Protocol822(); 34 | 35 | virtual unsigned short GetVersion(); 36 | }; 37 | 38 | #endif //__PROTOCOL870_H_ 39 | -------------------------------------------------------------------------------- /src/protocol840.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __PROTOCOL840_H_ 6 | #define __PROTOCOL840_H_ 7 | 8 | #include "channel.h" 9 | #include "const.h" 10 | #include "creature.h" 11 | #include "distance.h" 12 | #include "game.h" 13 | #include "item.h" 14 | #include "light.h" 15 | #include "logger.h" 16 | #include "magiceffect.h" 17 | #include "map.h" 18 | #include "mthread.h" 19 | #include "network.h" 20 | #include "protocol.h" 21 | #include "protocol822.h" 22 | #include "rsa.h" 23 | 24 | class Channel; 25 | class Game; 26 | 27 | class Protocol840 : public Protocol822 { 28 | public: 29 | Protocol840(Game* game); 30 | virtual ~Protocol840(); 31 | 32 | virtual unsigned short GetVersion(); 33 | 34 | virtual bool LoginServer(); 35 | virtual bool LoginGame(); 36 | 37 | virtual void SendSay(unsigned char speakClass, Channel* channel, std::string message); 38 | virtual void SendPurchaseShop(unsigned short itemID, unsigned char type, unsigned char count, bool ignoreCap, bool inBackpack); 39 | virtual void ParseShop(NetworkMessage* msg); 40 | virtual void ParseShopSaleItemList(NetworkMessage* msg); 41 | virtual void ParsePlayerStats(NetworkMessage* msg); 42 | virtual void ParseCreatureSpeak(NetworkMessage* msg); 43 | virtual void ParseTextMessage(NetworkMessage* msg); 44 | }; 45 | 46 | #endif //__PROTOCOL870_H_ 47 | -------------------------------------------------------------------------------- /src/protocol842.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #include "protocol842.h" 6 | 7 | #include "allocator.h" 8 | #include "position.h" 9 | #include "player.h" 10 | #include "text.h" 11 | #include "tools.h" 12 | #include "window.h" 13 | 14 | 15 | // ---- Protocol ---- // 16 | 17 | Protocol842::Protocol842(Game* game) : Protocol840(game) { } 18 | 19 | Protocol842::~Protocol842() { 20 | if (client.Connected()) 21 | client.doClose(); 22 | 23 | if (receiveLoop.joinable()) 24 | receiveLoop.join(); 25 | } 26 | 27 | 28 | unsigned short Protocol842::GetVersion() { 29 | return 842; 30 | } 31 | 32 | 33 | bool Protocol842::LoginGame() { 34 | LOCKCLASS lockClass(lockProtocol); 35 | 36 | Host host = game->GetHost(); 37 | Character character = game->GetCharacter(); 38 | 39 | CloseConnection(); 40 | 41 | std::string shost = ConvertIP(character.servIP); 42 | std::string sport = value2str(character.servPort); 43 | 44 | client.Connect(shost.c_str(), sport.c_str()); 45 | if (!client.Connected()) { 46 | Windows* wnds = game->GetWindows(); 47 | wnds->CloseWindows(WND_MESSAGE, true); 48 | wnds->OpenWindow(WND_MESSAGE, Text::GetText("ERROR_MESSAGE_3", Game::options.language).c_str()); 49 | return false; 50 | } 51 | 52 | NetworkMessage nmsg(GetVersion()); 53 | nmsg.ReceiveMessage(&client); 54 | 55 | NetworkMessage msg(GetVersion()); 56 | msg.SetRSA(&rsa); 57 | 58 | msg.AddU8(0x0A); //Login to server info 59 | msg.AddU16(APP_OS); //Client OS 60 | msg.AddU16(GetVersion()); //Version 61 | 62 | RandomizeXTEA(); 63 | msg.AddU32(XTEAkey[0]); 64 | msg.AddU32(XTEAkey[1]); 65 | msg.AddU32(XTEAkey[2]); 66 | msg.AddU32(XTEAkey[3]); 67 | 68 | msg.AddU8(0x00); 69 | 70 | msg.AddString(host.account); 71 | msg.AddString(character.name); 72 | msg.AddString(host.password); 73 | 74 | msg.RSA_encrypt(5); 75 | 76 | msg.SendMessage(&client, true); 77 | 78 | return true; 79 | } 80 | 81 | 82 | void Protocol842::ParseAddThing(NetworkMessage* msg) { 83 | Position pos; 84 | GetPosition(msg, pos); 85 | unsigned char stackPos = msg->GetU8(); 86 | 87 | Thing* thing = NULL; 88 | int skip = 0; 89 | GetThing(msg, thing, skip); 90 | 91 | Map* map = game->GetMap(); 92 | if (!map) { 93 | Logger::AddLog("Protocol::ParseAddThing()", "Pointer to map is NULL!", LOG_ERROR, msg); 94 | return; 95 | } 96 | 97 | LOCKCLASS lockClass1(Map::lockMap); 98 | LOCKCLASS lockClass2(Tile::lockTile); 99 | 100 | Tile* tile = map->GetTile(pos); 101 | if (tile) { 102 | if (thing) { 103 | if (stackPos != 255) 104 | tile->InsertThing(thing, stackPos); 105 | else 106 | tile->AddThing(thing); 107 | 108 | Item* item = dynamic_cast(thing); 109 | Creature* creature = dynamic_cast(thing); 110 | if (item) { 111 | item->SetLight(); 112 | 113 | if ((*item)()) { 114 | if ((*item)()->light) 115 | Lights::UpdateStaticLightMap(map); 116 | if ((*item)()->blocking || (*item)()->blockPathFind) 117 | map->SetMiniMapPix(pos, tile); 118 | } 119 | } 120 | else if (creature) { 121 | Position corner = map->GetCorner(); 122 | Battle* battle = map->GetBattle(); 123 | if (battle && corner.z == pos.z) 124 | battle->AddCreature(creature); 125 | sig.PushFunction(boost::bind(&Map::UpdateBattle, map)); 126 | } 127 | } 128 | tile->SortThings(); 129 | } 130 | else { 131 | Logger::AddLog("Protocol::ParseAddThing()", "Tile is NULL!", LOG_ERROR, msg); 132 | return; 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /src/protocol842.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __PROTOCOL842_H_ 6 | #define __PROTOCOL842_H_ 7 | 8 | #include "const.h" 9 | #include "creature.h" 10 | #include "game.h" 11 | #include "item.h" 12 | #include "light.h" 13 | #include "logger.h" 14 | #include "map.h" 15 | #include "mthread.h" 16 | #include "network.h" 17 | #include "protocol.h" 18 | #include "protocol840.h" 19 | #include "rsa.h" 20 | 21 | class Game; 22 | 23 | class Protocol842 : public Protocol840 { 24 | public: 25 | Protocol842(Game* game); 26 | virtual ~Protocol842(); 27 | 28 | virtual unsigned short GetVersion(); 29 | 30 | virtual bool LoginGame(); 31 | 32 | virtual void ParseAddThing(NetworkMessage* msg); 33 | }; 34 | 35 | #endif //__PROTOCOL870_H_ 36 | -------------------------------------------------------------------------------- /src/protocol850.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #include "protocol850.h" 6 | 7 | #include "allocator.h" 8 | #include "channel.h" 9 | #include "cooldowns.h" 10 | #include "messages.h" 11 | #include "particle.h" 12 | #include "position.h" 13 | #include "player.h" 14 | #include "questlog.h" 15 | #include "shop.h" 16 | #include "status.h" 17 | #include "text.h" 18 | #include "tools.h" 19 | #include "window.h" 20 | 21 | #ifndef NO_SOUND 22 | #include "adal.h" 23 | #include "sound.h" 24 | #endif 25 | 26 | 27 | // ---- Protocol ---- // 28 | 29 | Protocol850::Protocol850(Game* game) : Protocol842(game) { } 30 | 31 | Protocol850::~Protocol850() { 32 | if (client.Connected()) 33 | client.doClose(); 34 | 35 | if (receiveLoop.joinable()) 36 | receiveLoop.join(); 37 | } 38 | 39 | 40 | unsigned short Protocol850::GetVersion() { 41 | return 850; 42 | } 43 | 44 | void Protocol850::ParseViolation(NetworkMessage* msg) { 45 | for (int i = 0; i < 20; i++) 46 | msg->GetU8(); 47 | } 48 | -------------------------------------------------------------------------------- /src/protocol850.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __PROTOCOL850_H_ 6 | #define __PROTOCOL850_H_ 7 | 8 | #include "channel.h" 9 | #include "const.h" 10 | #include "creature.h" 11 | #include "distance.h" 12 | #include "game.h" 13 | #include "item.h" 14 | #include "light.h" 15 | #include "logger.h" 16 | #include "magiceffect.h" 17 | #include "map.h" 18 | #include "mthread.h" 19 | #include "network.h" 20 | #include "protocol.h" 21 | #include "protocol842.h" 22 | #include "rsa.h" 23 | 24 | class Channel; 25 | class Game; 26 | 27 | class Protocol850 : public Protocol842 { 28 | public: 29 | Protocol850(Game* game); 30 | virtual ~Protocol850(); 31 | 32 | virtual unsigned short GetVersion(); 33 | 34 | virtual void ParseViolation(NetworkMessage* msg); 35 | }; 36 | 37 | #endif //__PROTOCOL870_H_ 38 | -------------------------------------------------------------------------------- /src/protocol854.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #include "protocol854.h" 6 | 7 | #include "allocator.h" 8 | #include "channel.h" 9 | #include "cooldowns.h" 10 | #include "messages.h" 11 | #include "particle.h" 12 | #include "position.h" 13 | #include "player.h" 14 | #include "questlog.h" 15 | #include "shop.h" 16 | #include "status.h" 17 | #include "text.h" 18 | #include "tools.h" 19 | #include "window.h" 20 | 21 | #ifndef NO_SOUND 22 | #include "adal.h" 23 | #include "sound.h" 24 | #endif 25 | 26 | 27 | // ---- Protocol ---- // 28 | 29 | Protocol854::Protocol854(Game* game) : Protocol850(game) { } 30 | 31 | Protocol854::~Protocol854() { 32 | if (client.Connected()) 33 | client.doClose(); 34 | 35 | if (receiveLoop.joinable()) 36 | receiveLoop.join(); 37 | } 38 | 39 | 40 | unsigned short Protocol854::GetVersion() { 41 | return 854; 42 | } 43 | 44 | 45 | void Protocol854::GetCreature(NetworkMessage* msg, Creature*& creature, bool known) { 46 | if (known) { 47 | unsigned int creatureID = msg->GetU32(); 48 | 49 | creature = Creature::GetFromKnown(creatureID); 50 | if (!creature) { 51 | Logger::AddLog("Protocol::GetCreature()", "Known creature pointer is NULL!", LOG_ERROR, msg); 52 | return; 53 | } 54 | } 55 | else { 56 | if (!creature) { 57 | Logger::AddLog("Protocol::GetCreature()", "Unknown creature pointer is NULL!", LOG_ERROR, msg); 58 | return; 59 | } 60 | 61 | unsigned int removeID = msg->GetU32(); 62 | unsigned int creatureID = msg->GetU32(); 63 | std::string creatureName = msg->GetString(); 64 | 65 | Creature::RemoveFromKnown(removeID); 66 | creature->SetID(creatureID); 67 | creature->SetName(creatureName); 68 | Creature::AddToKnown(creature); 69 | } 70 | 71 | unsigned char health = msg->GetU8(); 72 | Direction direction = (Direction)msg->GetU8(); 73 | 74 | creature->SetHealth(health); 75 | creature->SetDirection(direction); 76 | 77 | Outfit outfit; 78 | GetOutfit(msg, &outfit); 79 | 80 | creature->SetOutfit(outfit); 81 | 82 | unsigned char lightLevel = msg->GetU8(); 83 | unsigned char lightColor = msg->GetU8(); 84 | 85 | creature->SetLight(lightColor, lightLevel); 86 | 87 | unsigned short speed = msg->GetU16(); 88 | 89 | creature->SetSpeed(speed); 90 | 91 | unsigned char skull = msg->GetU8(); 92 | unsigned char shield = msg->GetU8(); 93 | 94 | creature->SetSkull(skull); 95 | creature->SetShield(shield); 96 | 97 | if (!known) { 98 | unsigned char war = msg->GetU8(); 99 | creature->SetWar(war); 100 | } 101 | 102 | bool blocking = (bool)msg->GetU8(); 103 | 104 | creature->SetBlocking(blocking); 105 | } 106 | -------------------------------------------------------------------------------- /src/protocol854.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __PROTOCOL854_H_ 6 | #define __PROTOCOL854_H_ 7 | 8 | #include "channel.h" 9 | #include "const.h" 10 | #include "creature.h" 11 | #include "distance.h" 12 | #include "game.h" 13 | #include "item.h" 14 | #include "light.h" 15 | #include "logger.h" 16 | #include "magiceffect.h" 17 | #include "map.h" 18 | #include "mthread.h" 19 | #include "network.h" 20 | #include "protocol.h" 21 | #include "protocol850.h" 22 | #include "rsa.h" 23 | 24 | class Creature; 25 | class Game; 26 | 27 | class Protocol854 : public Protocol850 { 28 | public: 29 | Protocol854(Game* game); 30 | virtual ~Protocol854(); 31 | 32 | virtual unsigned short GetVersion(); 33 | 34 | virtual void GetCreature(NetworkMessage* msg, Creature*& creature, bool known); 35 | }; 36 | 37 | #endif //__PROTOCOL870_H_ 38 | -------------------------------------------------------------------------------- /src/protocol860.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #include "protocol860.h" 6 | 7 | #include "allocator.h" 8 | #include "channel.h" 9 | #include "cooldowns.h" 10 | #include "messages.h" 11 | #include "particle.h" 12 | #include "position.h" 13 | #include "player.h" 14 | #include "questlog.h" 15 | #include "shop.h" 16 | #include "status.h" 17 | #include "text.h" 18 | #include "tools.h" 19 | #include "window.h" 20 | 21 | #ifndef NO_SOUND 22 | #include "adal.h" 23 | #include "sound.h" 24 | #endif 25 | 26 | 27 | // ---- Protocol ---- // 28 | 29 | Protocol860::Protocol860(Game* game) : Protocol854(game) { } 30 | 31 | Protocol860::~Protocol860() { 32 | if (client.Connected()) 33 | client.doClose(); 34 | 35 | if (receiveLoop.joinable()) 36 | receiveLoop.join(); 37 | } 38 | 39 | 40 | unsigned short Protocol860::GetVersion() { 41 | return 860; 42 | } 43 | 44 | 45 | void Protocol860::ParseCancelAttack(NetworkMessage* msg) { 46 | unsigned int creatureID = msg->GetU32(); 47 | 48 | Player* player = game->GetPlayer(); 49 | if (player) { 50 | player->SetAttackID(0); 51 | 52 | Player::walking = false; 53 | Player::requestStop = false; 54 | player->SetTargetPos(Position(0, 0, 0)); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/protocol860.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __PROTOCOL860_H_ 6 | #define __PROTOCOL860_H_ 7 | 8 | #include "channel.h" 9 | #include "const.h" 10 | #include "creature.h" 11 | #include "distance.h" 12 | #include "game.h" 13 | #include "item.h" 14 | #include "light.h" 15 | #include "logger.h" 16 | #include "magiceffect.h" 17 | #include "map.h" 18 | #include "mthread.h" 19 | #include "network.h" 20 | #include "protocol.h" 21 | #include "protocol854.h" 22 | #include "rsa.h" 23 | 24 | class Game; 25 | 26 | class Protocol860 : public Protocol854 { 27 | public: 28 | Protocol860(Game* game); 29 | virtual ~Protocol860(); 30 | 31 | virtual unsigned short GetVersion(); 32 | 33 | virtual void ParseCancelAttack(NetworkMessage* msg); 34 | }; 35 | 36 | #endif //__PROTOCOL870_H_ 37 | -------------------------------------------------------------------------------- /src/protocol870.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __PROTOCOL870_H_ 6 | #define __PROTOCOL870_H_ 7 | 8 | #include "channel.h" 9 | #include "const.h" 10 | #include "creature.h" 11 | #include "distance.h" 12 | #include "game.h" 13 | #include "item.h" 14 | #include "light.h" 15 | #include "logger.h" 16 | #include "magiceffect.h" 17 | #include "map.h" 18 | #include "mthread.h" 19 | #include "network.h" 20 | #include "protocol.h" 21 | #include "protocol860.h" 22 | #include "rsa.h" 23 | 24 | class Channel; 25 | class Game; 26 | class Outfit; 27 | 28 | class Protocol870 : public Protocol860 { 29 | public: 30 | Protocol870(Game* game); 31 | virtual ~Protocol870(); 32 | 33 | virtual unsigned short GetVersion(); 34 | 35 | virtual void SendSay(unsigned char speakClass, Channel* channel, std::string message); 36 | virtual void SendSetOutfit(Outfit outfit); 37 | 38 | virtual void ParsePlayerStats(NetworkMessage* msg); 39 | virtual void ParseSpellCooldown(NetworkMessage* msg); 40 | virtual void ParseSpellGroupCooldown(NetworkMessage* msg); 41 | virtual void ParseCreatureSpeak(NetworkMessage* msg); 42 | virtual void ParseTextMessage(NetworkMessage* msg); 43 | virtual void ParseOutfitWindow(NetworkMessage* msg); 44 | 45 | virtual void GetOutfit(NetworkMessage* msg, Outfit* outfit); 46 | }; 47 | 48 | #endif //__PROTOCOL870_H_ 49 | -------------------------------------------------------------------------------- /src/protocol910.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __PROTOCOL910_H_ 6 | #define __PROTOCOL910_H_ 7 | 8 | #include "game.h" 9 | #include "mthread.h" 10 | #include "network.h" 11 | #include "protocol.h" 12 | #include "protocol870.h" 13 | 14 | class Game; 15 | 16 | class Protocol910 : public Protocol870 { 17 | public: 18 | Protocol910(Game* game); 19 | virtual ~Protocol910(); 20 | 21 | virtual unsigned short GetVersion(); 22 | 23 | virtual void SendSay(unsigned char speakClass, Channel* channel, std::string message); 24 | 25 | virtual void ParseShop(NetworkMessage* msg); 26 | virtual void ParsePlayerStats(NetworkMessage* msg); 27 | virtual void ParsePlayerSkills(NetworkMessage* msg); 28 | virtual void ParseOpenChannel(NetworkMessage* msg); 29 | virtual void ParseCreatePrivateChannel(NetworkMessage* msg); 30 | virtual void ParseCreatureSpeak(NetworkMessage* msg); 31 | virtual void ParseTextMessage(NetworkMessage* msg); 32 | 33 | virtual void GetThing(NetworkMessage* msg, Thing*& thing, int& skip); 34 | virtual void GetTileDescription(NetworkMessage* msg, Position pos, Tile*& tile, int& skip); 35 | virtual void GetCreature(NetworkMessage* msg, Creature*& creature, bool known); 36 | }; 37 | 38 | #endif //__PROTOCOL870_H_ 39 | -------------------------------------------------------------------------------- /src/questlog.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #include "questlog.h" 6 | 7 | #include "allocator.h" 8 | 9 | 10 | // ---- QuestLog ---- // 11 | 12 | QuestLog::QuestLog() { } 13 | 14 | QuestLog::~QuestLog() { } 15 | 16 | void QuestLog::AddQuest(unsigned short id, Quest quest) { 17 | LOCKCLASS lockClass(lockQuestLog); 18 | 19 | quests[id] = quest; 20 | } 21 | 22 | QuestPair QuestLog::GetQuestByNumber(int number) { 23 | LOCKCLASS lockClass(lockQuestLog); 24 | 25 | int i = 0; 26 | 27 | QuestsMap::iterator it = quests.begin(); 28 | for (it, i; it != quests.end(); it++, i++) { 29 | if (i == number) 30 | return QuestPair(it->first, it->second); 31 | } 32 | 33 | return QuestPair(0, Quest()); 34 | } 35 | 36 | QuestsMap QuestLog::GetQuests() { 37 | LOCKCLASS lockClass(lockQuestLog); 38 | 39 | return quests; 40 | } 41 | 42 | void QuestLog::ClearQuests() { 43 | LOCKCLASS lockClass(lockQuestLog); 44 | 45 | quests.clear(); 46 | } 47 | 48 | void QuestLog::AddMission(Mission mission) { 49 | LOCKCLASS lockClass(lockQuestLog); 50 | 51 | missions.push_back(mission); 52 | } 53 | 54 | MissionsList QuestLog::GetMissions() { 55 | LOCKCLASS lockClass(lockQuestLog); 56 | 57 | return missions; 58 | } 59 | 60 | Mission QuestLog::GetMissionByNumber(int number) { 61 | LOCKCLASS lockClass(lockQuestLog); 62 | 63 | int i = 0; 64 | 65 | MissionsList::iterator it = missions.begin(); 66 | for (it, i; it != missions.end(); it++, i++) { 67 | if (i == number) 68 | return *it; 69 | } 70 | 71 | return Mission(); 72 | } 73 | 74 | void QuestLog::ClearMissions() { 75 | LOCKCLASS lockClass(lockQuestLog); 76 | 77 | missions.clear(); 78 | } 79 | -------------------------------------------------------------------------------- /src/questlog.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __QUESTLOG_H_ 6 | #define __QUESTLOG_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "mthread.h" 13 | 14 | 15 | struct Quest { 16 | std::string name; 17 | bool completed; 18 | 19 | Quest() { 20 | name = ""; 21 | completed = false; 22 | } 23 | }; 24 | 25 | struct Mission { 26 | std::string name; 27 | std::string description; 28 | 29 | Mission() { 30 | name = ""; 31 | description = ""; 32 | } 33 | }; 34 | 35 | 36 | typedef std::pair QuestPair; 37 | typedef std::map QuestsMap; 38 | typedef std::list MissionsList; 39 | 40 | class QuestLog { 41 | private: 42 | QuestsMap quests; 43 | MissionsList missions; 44 | 45 | MUTEX lockQuestLog; 46 | 47 | public: 48 | QuestLog(); 49 | ~QuestLog(); 50 | 51 | void AddQuest(unsigned short id, Quest quest); 52 | QuestPair GetQuestByNumber(int number); 53 | QuestsMap GetQuests(); 54 | void ClearQuests(); 55 | 56 | void AddMission(Mission mission); 57 | Mission GetMissionByNumber(int number); 58 | MissionsList GetMissions(); 59 | void ClearMissions(); 60 | }; 61 | 62 | 63 | #endif //__QUESTLOG_H_ 64 | -------------------------------------------------------------------------------- /src/realtime.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #include "realtime.h" 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include "luascript.h" 12 | 13 | 14 | time_lt RealTime::time = 0; 15 | MUTEX RealTime::lockRealTime; 16 | 17 | 18 | // ---- FPS ---- // 19 | 20 | FPS::FPS() { 21 | length = 0; 22 | } 23 | 24 | FPS::~FPS() { 25 | data.clear(); 26 | } 27 | 28 | void FPS::Create(unsigned short size) { 29 | length = size; 30 | } 31 | 32 | void FPS::Insert(float fps) { 33 | if (data.size() >= length) 34 | data.erase(data.begin()); 35 | data.push_back((unsigned int)(fps * 1000)); 36 | } 37 | 38 | float FPS::Return() { 39 | if (data.size() == 0) 40 | return 0; 41 | 42 | unsigned int fps = 0; 43 | for (std::list::iterator it = data.begin(); it != data.end(); it++) 44 | fps += *it; 45 | fps /= data.size(); 46 | 47 | return float((float)fps / 1000); 48 | } 49 | 50 | float FPS::GetPeriod() { 51 | return float(1000.0f / Return()); 52 | } 53 | 54 | 55 | // ---- RealTime ---- // 56 | 57 | RealTime::RealTime() { 58 | currTime = 0; 59 | prevTime = 0; 60 | 61 | Calculate(); 62 | } 63 | 64 | RealTime::~RealTime() { 65 | } 66 | 67 | void RealTime::Calculate() { 68 | _timeb t; 69 | _ftime(&t); 70 | 71 | prevTime = currTime; 72 | currTime = (time_lt)t.time * 1000 + (time_t)t.millitm; 73 | 74 | factor = float(currTime - prevTime) / float(1000); 75 | fps = 1000.0f / (float)(currTime - prevTime); 76 | 77 | LOCKCLASS lockClass(lockRealTime); 78 | 79 | RealTime::time = currTime; 80 | } 81 | 82 | int RealTime::getPeriod() { 83 | time_lt period = currTime - prevTime; 84 | return (int)period; 85 | } 86 | 87 | float RealTime::getFactor() { 88 | return factor; 89 | } 90 | 91 | float RealTime::getFPS() { 92 | return fps; 93 | } 94 | 95 | time_lt RealTime::getTime() { 96 | LOCKCLASS lockClass(lockRealTime); 97 | 98 | return RealTime::time; 99 | } 100 | 101 | 102 | //Lua functions 103 | 104 | int RealTime::LuaGetTime(lua_State* L) { 105 | LuaScript::PushNumber(L, getTime()); 106 | return 1; 107 | } 108 | 109 | 110 | void RealTime::LuaRegisterFunctions(lua_State* L) { 111 | //getTime() 112 | lua_register(L, "getTime", RealTime::LuaGetTime); 113 | } 114 | -------------------------------------------------------------------------------- /src/realtime.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __REALTIME_H_ 6 | #define __REALTIME_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "luascript.h" 13 | #include "mthread.h" 14 | 15 | typedef unsigned long long int time_lt; 16 | 17 | class FPS { 18 | private: 19 | unsigned short length; 20 | std::list data; 21 | 22 | public: 23 | FPS(); 24 | ~FPS(); 25 | 26 | void Create(unsigned short size); 27 | void Insert(float fps); 28 | float Return(); 29 | float GetPeriod(); 30 | }; 31 | 32 | class RealTime { 33 | private: 34 | time_lt currTime; 35 | time_lt prevTime; 36 | float factor; 37 | float fps; 38 | 39 | static time_lt time; 40 | static MUTEX lockRealTime; 41 | 42 | public: 43 | RealTime(); 44 | ~RealTime(); 45 | 46 | void Calculate(); 47 | int getPeriod(); 48 | float getFactor(); 49 | float getFPS(); 50 | 51 | static time_lt getTime(); 52 | 53 | //Lua functions 54 | static int LuaGetTime(lua_State* L); 55 | 56 | static void LuaRegisterFunctions(lua_State* L); 57 | }; 58 | 59 | #endif //__REALTIME_H_ 60 | -------------------------------------------------------------------------------- /src/rsa.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #include "rsa.h" 6 | #include 7 | #include 8 | 9 | RSA::RSA() 10 | { 11 | m_keySet = false; 12 | mpz_init2(m_p, 1024); 13 | mpz_init2(m_q, 1024); 14 | mpz_init2(m_d, 1024); 15 | mpz_init2(m_u, 1024); 16 | mpz_init2(m_dp, 1024); 17 | mpz_init2(m_dq, 1024); 18 | mpz_init2(m_mod, 1024); 19 | } 20 | 21 | RSA::~RSA() 22 | { 23 | mpz_clear(m_p); 24 | mpz_clear(m_q); 25 | mpz_clear(m_d); 26 | mpz_clear(m_u); 27 | mpz_clear(m_dp); 28 | mpz_clear(m_dq); 29 | mpz_clear(m_mod); 30 | } 31 | 32 | bool RSA::setKey(const std::string& file) 33 | { 34 | LOCKCLASS lockClass(lockRsa); 35 | //loads p,q and d from a file 36 | FILE* f = fopen(file.c_str(), "r"); 37 | if(!f){ 38 | return false; 39 | } 40 | 41 | char p[512]; 42 | char q[512]; 43 | char d[512]; 44 | fgets(p, 512, f); 45 | fgets(q, 512, f); 46 | fgets(d, 512, f); 47 | setKey(p, q, d); 48 | return true; 49 | } 50 | 51 | void RSA::setKey(const char* p, const char* q, const char* d) 52 | { 53 | LOCKCLASS lockClass(lockRsa); 54 | 55 | mpz_set_str(m_p, p, 10); 56 | mpz_set_str(m_q, q, 10); 57 | mpz_set_str(m_d, d, 10); 58 | 59 | mpz_t pm1,qm1; 60 | mpz_init2(pm1,520); 61 | mpz_init2(qm1,520); 62 | 63 | mpz_sub_ui(pm1, m_p, 1); 64 | mpz_sub_ui(qm1, m_q, 1); 65 | mpz_invert(m_u, m_p, m_q); 66 | mpz_mod(m_dp, m_d, pm1); 67 | mpz_mod(m_dq, m_d, qm1); 68 | 69 | mpz_mul(m_mod, m_p, m_q); 70 | 71 | mpz_clear(pm1); 72 | mpz_clear(qm1); 73 | } 74 | 75 | bool RSA::encrypt(char* msg, int32_t size) 76 | { 77 | LOCKCLASS lockClass(lockRsa); 78 | 79 | mpz_t plain, c; 80 | mpz_init2(plain, 1024); 81 | mpz_init2(c, 1024); 82 | 83 | mpz_t e; 84 | mpz_init(e); 85 | mpz_set_ui(e, 65537); 86 | 87 | mpz_import(plain, 128, 1, 1, 0, 0, msg); 88 | mpz_powm(c, plain, e, m_mod); 89 | 90 | size_t count = (mpz_sizeinbase(c, 2) + 7)/8; 91 | memset(msg, 0, 128 - count); 92 | mpz_export(&msg[128 - count], NULL, 1, 1, 0, 0, c); 93 | 94 | mpz_clear(c); 95 | mpz_clear(plain); 96 | mpz_clear(e); 97 | return true; 98 | } 99 | 100 | bool RSA::decrypt(char* msg, int32_t size) 101 | { 102 | LOCKCLASS lockClass(lockRsa); 103 | 104 | mpz_t c,v1,v2,u2,tmp; 105 | mpz_init2(c, 1024); 106 | mpz_init2(v1, 1024); 107 | mpz_init2(v2, 1024); 108 | mpz_init2(u2, 1024); 109 | mpz_init2(tmp, 1024); 110 | 111 | mpz_import(c, 128, 1, 1, 0, 0, msg); 112 | 113 | mpz_mod(tmp, c, m_p); 114 | mpz_powm(v1, tmp, m_dp, m_p); 115 | mpz_mod(tmp, c, m_q); 116 | mpz_powm(v2, tmp, m_dq, m_q); 117 | mpz_sub(u2, v2, v1); 118 | mpz_mul(tmp, u2, m_u); 119 | mpz_mod(u2, tmp, m_q); 120 | if(mpz_cmp_si(u2, 0) < 0){ 121 | mpz_add(tmp, u2, m_q); 122 | mpz_set(u2, tmp); 123 | } 124 | mpz_mul(tmp, u2, m_p); 125 | mpz_set_ui(c, 0); 126 | mpz_add(c, v1, tmp); 127 | 128 | size_t count = (mpz_sizeinbase(c, 2) + 7)/8; 129 | memset(msg, 0, 128 - count); 130 | mpz_export(&msg[128 - count], NULL, 1, 1, 0, 0, c); 131 | 132 | mpz_clear(c); 133 | mpz_clear(v1); 134 | mpz_clear(v2); 135 | mpz_clear(u2); 136 | mpz_clear(tmp); 137 | 138 | return true; 139 | } 140 | 141 | int32_t RSA::getKeySize() 142 | { 143 | LOCKCLASS lockClass(lockRsa); 144 | 145 | size_t count = (mpz_sizeinbase(m_mod, 2) + 7)/8; 146 | int32_t a = count/128; 147 | return a*128; 148 | } 149 | 150 | void RSA::getPublicKey(char* buffer) 151 | { 152 | LOCKCLASS lockClass(lockRsa); 153 | 154 | size_t count = (mpz_sizeinbase(m_mod, 2) + 7)/8; 155 | memset(buffer, 0, 128 - count); 156 | mpz_export(&buffer[128 - count], NULL, 1, 1, 0, 0, m_mod); 157 | } 158 | -------------------------------------------------------------------------------- /src/rsa.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __RSA_H_ 6 | #define __RSA_H_ 7 | 8 | #include "gmp.h" 9 | #include "mthread.h" 10 | 11 | class RSA{ 12 | public: 13 | RSA(); 14 | ~RSA(); 15 | void setKey(const char* p, const char* q, const char* d); 16 | bool setKey(const std::string& file); 17 | bool encrypt(char* msg, int32_t size); 18 | bool decrypt(char* msg, int32_t size); 19 | 20 | int32_t getKeySize(); 21 | void getPublicKey(char* buffer); 22 | 23 | public: 24 | 25 | MUTEX lockRsa; 26 | 27 | bool m_keySet; 28 | 29 | //use only GMP 30 | mpz_t m_p, m_q, m_u, m_d, m_dp, m_dq, m_mod; 31 | }; 32 | 33 | #endif //__RSA_H_ 34 | -------------------------------------------------------------------------------- /src/servers.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __SERVERS_H_ 6 | #define __SERVERS_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "mthread.h" 12 | 13 | 14 | class WindowElementContainer; 15 | class WindowElementMemo; 16 | class WindowElementTableMemo; 17 | 18 | 19 | struct Server { 20 | std::string name; 21 | std::string host; 22 | std::string port; 23 | std::string protocol; 24 | std::string updateURL; 25 | std::string websiteURL; 26 | std::string createAccountURL; 27 | bool promoted; 28 | }; 29 | 30 | 31 | typedef std::vector ServersList; 32 | 33 | 34 | class Servers { 35 | private: 36 | WindowElementContainer* tabContainer; 37 | WindowElementContainer* onlineContainer; 38 | WindowElementContainer* favoritesContainer; 39 | WindowElementContainer* websitesContainer; 40 | 41 | ServersList onlineServers; 42 | ServersList favoritesServers; 43 | ServersList websitesServers; 44 | 45 | public: 46 | MUTEX lockServers; 47 | 48 | public: 49 | Servers(); 50 | ~Servers(); 51 | 52 | void LoadFavorites(); 53 | void SaveFavorites(); 54 | 55 | void LoadWebsites(); 56 | 57 | void AddOnlineServer(Server server); 58 | void RemoveOnlineServer(int num); 59 | void ClearOnlineServers(); 60 | Server GetOnlineServer(int num); 61 | 62 | void AddFavoriteServer(Server server); 63 | void RemoveFavoriteServer(int num); 64 | void MoveFavoriteServer(int num, int step); 65 | void ClearFavoriteServers(); 66 | Server GetFavoriteServer(int num); 67 | int GetFavoriteNum(std::string name); 68 | void SortFavorites(int column); 69 | 70 | void AddWebsiteServer(Server server); 71 | void RemoveWebsiteServer(int num); 72 | void ClearWebsiteServers(); 73 | Server GetWebsiteServer(int num); 74 | 75 | void SetContainers(WindowElementContainer* tabContainer, WindowElementContainer* onlineContainer, WindowElementContainer* favoritesContainer, WindowElementContainer* websitesContainer); 76 | void UpdateContainers(std::vector pointers); 77 | void UpdateFavoritesMemo(WindowElementTableMemo* memo); 78 | }; 79 | 80 | 81 | #endif //__SERVERS_H_ 82 | -------------------------------------------------------------------------------- /src/shop.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #include "shop.h" 6 | 7 | #include 8 | 9 | #include "allocator.h" 10 | #include "window.h" 11 | 12 | 13 | // ---- Shop ---- // 14 | 15 | Shop::Shop() { 16 | memo = NULL; 17 | purchase = true; 18 | money = 0; 19 | 20 | ignoreCap = false; 21 | inBackpack = false; 22 | } 23 | 24 | Shop::~Shop() { } 25 | 26 | 27 | void Shop::SetName(std::string name) { 28 | this->name = name; 29 | } 30 | 31 | std::string Shop::GetName() { 32 | return name; 33 | } 34 | 35 | 36 | void Shop::SetMemo(WindowElementMemo* memo) { 37 | LOCKCLASS lockClass(lockShop); 38 | 39 | this->memo = memo; 40 | } 41 | 42 | WindowElementMemo* Shop::GetMemo() { 43 | LOCKCLASS lockClass(lockShop); 44 | 45 | return memo; 46 | } 47 | 48 | void Shop::SetPurchase(bool state) { 49 | LOCKCLASS lockClass(lockShop); 50 | 51 | purchase = state; 52 | } 53 | 54 | 55 | void Shop::SetMoney(unsigned int value) { 56 | LOCKCLASS lockClass(lockShop); 57 | 58 | money = value; 59 | } 60 | 61 | unsigned int Shop::GetMoney() { 62 | LOCKCLASS lockClass(lockShop); 63 | 64 | return money; 65 | } 66 | 67 | unsigned int* Shop::GetMoneyPtr() { 68 | LOCKCLASS lockClass(lockShop); 69 | 70 | return &money; 71 | } 72 | 73 | 74 | void Shop::SetIgnoreCap(bool state) { 75 | LOCKCLASS lockClass(lockShop); 76 | 77 | ignoreCap = state; 78 | } 79 | 80 | bool Shop::GetIgnoreCap() { 81 | LOCKCLASS lockClass(lockShop); 82 | 83 | return ignoreCap; 84 | } 85 | 86 | 87 | void Shop::SetInBackpack(bool state) { 88 | LOCKCLASS lockClass(lockShop); 89 | 90 | inBackpack = state; 91 | } 92 | 93 | bool Shop::GetInBackpack() { 94 | LOCKCLASS lockClass(lockShop); 95 | 96 | return inBackpack; 97 | } 98 | 99 | 100 | void Shop::AddShopDetailItem(ShopDetailItem item) { 101 | LOCKCLASS lockClass(lockShop); 102 | 103 | itemsList.push_back(item); 104 | } 105 | 106 | ShopDetailItem Shop::GetShopDetailItemByID(unsigned short itemID, unsigned char count) { 107 | LOCKCLASS lockClass(lockShop); 108 | 109 | ShopDetailItemsList::iterator it = itemsList.begin(); 110 | for (it; it != itemsList.end(); it++) 111 | if (itemID == it->itemID && count == it->count) 112 | return *it; 113 | 114 | ShopDetailItem item; 115 | memset(&item, 0, sizeof(item)); 116 | 117 | return item; 118 | } 119 | 120 | ShopDetailItemsList Shop::GetShopDetailItems() { 121 | LOCKCLASS lockClass(lockShop); 122 | 123 | return itemsList; 124 | } 125 | 126 | void Shop::ClearShopDetailItems() { 127 | LOCKCLASS lockClass(lockShop); 128 | 129 | itemsList.clear(); 130 | } 131 | 132 | 133 | void Shop::AddPurchaseItem(ShopItem item) { 134 | LOCKCLASS lockClass(lockShop); 135 | 136 | purchaseList.push_back(item); 137 | } 138 | 139 | ShopItem Shop::GetPurchaseItem(int number) { 140 | LOCKCLASS lockClass(lockShop); 141 | 142 | ShopItemsList::iterator it = purchaseList.begin(); 143 | for (it, number; it != purchaseList.end() && number >= 0; it++, number--) 144 | if (number == 0) 145 | return *it; 146 | 147 | ShopItem item; 148 | memset(&item, 0, sizeof(item)); 149 | 150 | return item; 151 | } 152 | 153 | ShopItemsList Shop::GetPurchaseItems() { 154 | LOCKCLASS lockClass(lockShop); 155 | 156 | return purchaseList; 157 | } 158 | 159 | void Shop::ClearPurchaseItems() { 160 | LOCKCLASS lockClass(lockShop); 161 | 162 | purchaseList.clear(); 163 | } 164 | 165 | 166 | void Shop::AddSaleItem(ShopItem item) { 167 | LOCKCLASS lockClass(lockShop); 168 | 169 | saleList.push_back(item); 170 | } 171 | 172 | void Shop::UpdateSaleItem(ShopItem item) { 173 | LOCKCLASS lockClass(lockShop); 174 | 175 | ShopItemsList::iterator it = saleList.begin(); 176 | for (it; it != saleList.end(); it++) { 177 | ShopItem sitem = *it; 178 | if (sitem.itemID == item.itemID) 179 | it->amount = item.amount; 180 | } 181 | } 182 | 183 | void Shop::ClearSaleItemsAmount() { 184 | LOCKCLASS lockClass(lockShop); 185 | 186 | ShopItemsList::iterator it = saleList.begin(); 187 | for (it; it != saleList.end(); it++) 188 | it->amount = 0; 189 | } 190 | 191 | ShopItem Shop::GetSaleItem(int number) { 192 | LOCKCLASS lockClass(lockShop); 193 | 194 | ShopItemsList::iterator it = saleList.begin(); 195 | for (it, number; it != saleList.end() && number >= 0; it++, number--) 196 | if (number == 0) 197 | return *it; 198 | 199 | ShopItem item; 200 | memset(&item, 0, sizeof(item)); 201 | 202 | return item; 203 | } 204 | 205 | ShopItemsList Shop::GetSaleItems() { 206 | LOCKCLASS lockClass(lockShop); 207 | 208 | return saleList; 209 | } 210 | 211 | void Shop::ClearSaleItems() { 212 | LOCKCLASS lockClass(lockShop); 213 | 214 | saleList.clear(); 215 | } 216 | 217 | 218 | void Shop::UpdateMemo() { 219 | LOCKCLASS lockClass1(Windows::lockWindows); 220 | LOCKCLASS lockClass2(lockShop); 221 | 222 | if (!memo) 223 | return; 224 | 225 | int option = memo->GetOption(); 226 | 227 | memo->Clear(); 228 | if (purchase) { 229 | ShopItemsList purchaseItems = GetPurchaseItems(); 230 | ShopItemsList::iterator it = purchaseItems.begin(); 231 | for (it; it != purchaseItems.end(); it++) { 232 | ShopItem purchaseItem = *it; 233 | 234 | ShopDetailItem item = GetShopDetailItemByID(purchaseItem.itemID, purchaseItem.count); 235 | std::string text = item.name + " / " + value2str(item.buyPrice) + " gp / " + float2str((float)item.weight / 100) + "oz."; 236 | 237 | memo->AddElement(text); 238 | } 239 | } 240 | else { 241 | ShopItemsList saleItems = GetSaleItems(); 242 | ShopItemsList::iterator it = saleItems.begin(); 243 | for (it; it != saleItems.end(); it++) { 244 | ShopItem saleItem = *it; 245 | 246 | ShopDetailItem item = GetShopDetailItemByID(saleItem.itemID, saleItem.count); 247 | std::string text = item.name + " / " + value2str(item.sellPrice) + " gp / " + float2str((float)item.weight / 100) + "oz."; 248 | 249 | memo->AddElement(text, saleItem.amount > 0); 250 | } 251 | } 252 | 253 | memo->SetOption(option); 254 | } 255 | -------------------------------------------------------------------------------- /src/shop.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __SHOP_H_ 6 | #define __SHOP_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "mthread.h" 12 | 13 | 14 | class WindowElementMemo; 15 | 16 | 17 | struct ShopDetailItem { 18 | unsigned short itemID; 19 | unsigned char count; 20 | std::string name; 21 | unsigned int weight; 22 | int buyPrice; 23 | int sellPrice; 24 | }; 25 | 26 | struct ShopItem { 27 | unsigned short itemID; 28 | unsigned char count; 29 | unsigned char amount; 30 | }; 31 | 32 | 33 | typedef std::list ShopDetailItemsList; 34 | typedef std::list ShopItemsList; 35 | 36 | class Shop { 37 | private: 38 | WindowElementMemo* memo; 39 | bool purchase; 40 | 41 | std::string name; 42 | 43 | ShopDetailItemsList itemsList; 44 | ShopItemsList purchaseList; 45 | ShopItemsList saleList; 46 | 47 | unsigned int money; 48 | 49 | bool ignoreCap; 50 | bool inBackpack; 51 | 52 | MUTEX lockShop; 53 | 54 | public: 55 | Shop(); 56 | ~Shop(); 57 | 58 | void SetName(std::string name); 59 | std::string GetName(); 60 | 61 | void SetMemo(WindowElementMemo* memo); 62 | WindowElementMemo* GetMemo(); 63 | void SetPurchase(bool state); 64 | 65 | void SetMoney(unsigned int value); 66 | unsigned int GetMoney(); 67 | unsigned int* GetMoneyPtr(); 68 | 69 | void SetIgnoreCap(bool state); 70 | bool GetIgnoreCap(); 71 | 72 | void SetInBackpack(bool state); 73 | bool GetInBackpack(); 74 | 75 | void AddShopDetailItem(ShopDetailItem item); 76 | ShopDetailItem GetShopDetailItemByID(unsigned short itemID, unsigned char count); 77 | ShopDetailItemsList GetShopDetailItems(); 78 | void ClearShopDetailItems(); 79 | 80 | void AddPurchaseItem(ShopItem item); 81 | ShopItem GetPurchaseItem(int number); 82 | ShopItemsList GetPurchaseItems(); 83 | void ClearPurchaseItems(); 84 | 85 | void AddSaleItem(ShopItem item); 86 | void UpdateSaleItem(ShopItem item); 87 | void ClearSaleItemsAmount(); 88 | ShopItem GetSaleItem(int number); 89 | ShopItemsList GetSaleItems(); 90 | void ClearSaleItems(); 91 | 92 | void UpdateMemo(); 93 | }; 94 | 95 | #endif //__SHOP_H_ 96 | -------------------------------------------------------------------------------- /src/sound.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef NO_SOUND 6 | 7 | #ifndef __SOUNDS_H_ 8 | #define __SOUNDS_H_ 9 | 10 | #include 11 | 12 | #include "adal.h" 13 | #include "luascript.h" 14 | #include "mthread.h" 15 | #include "realtime.h" 16 | #include "tools.h" 17 | 18 | class Game; 19 | 20 | 21 | enum SAMPLE_CLASS { 22 | SAMPLE_BACKGROUND = 0, 23 | SAMPLE_EFFECT = 1, 24 | SAMPLE_DISTANCE = 2, 25 | SAMPLE_SYSTEM = 3, 26 | SAMPLE_CUSTOM = 4, 27 | }; 28 | 29 | typedef std::map SoundsCount; 30 | typedef std::map SamplesMap; 31 | typedef std::list SoundsList; 32 | 33 | class SFX_System { 34 | private: 35 | ADAL_System* sfx; 36 | 37 | float musicGain; 38 | float soundGain; 39 | 40 | SamplesMap backgroundSamples; 41 | SamplesMap effectSamples; 42 | SamplesMap distanceSamples; 43 | SamplesMap systemSamples; 44 | SamplesMap customSamples; 45 | 46 | unsigned int backgroundSample; 47 | ADAL_Sound backgroundSound; 48 | 49 | static SoundsList sounds; 50 | 51 | public: 52 | static SoundsCount counter; 53 | 54 | static int threads; 55 | static MUTEX lockSounds; 56 | 57 | public: 58 | SFX_System(); 59 | ~SFX_System(); 60 | 61 | void SetGains(float music, float sound); 62 | 63 | void LoadSample(SAMPLE_CLASS sClass, unsigned int id); 64 | void ReleaseSamples(); 65 | 66 | void PlayBackgroundSound(SAMPLE_CLASS sc, unsigned int id); 67 | void StopBackgroundSound(); 68 | void SetBackgroundSoundGain(float gain); 69 | unsigned int GetBackgroundSample(); 70 | 71 | void PlaySystemSound(SAMPLE_CLASS sc, unsigned int id); 72 | void PlayGameSound(SAMPLE_CLASS sc, unsigned int id, float x, float y, float z); 73 | void PlayCustomSound(SAMPLE_CLASS sc, unsigned int id, float volume, float offset); 74 | 75 | static bool AddSound(ADAL_Sound* sound); 76 | static void RemoveSound(ADAL_Sound* sound); 77 | static void ClearSounds(); 78 | static void CheckSounds(Game* game); 79 | 80 | //Lua functions 81 | static int LuaPlayBackgroundSound(lua_State* L); 82 | static int LuaStopBackgroundSound(lua_State* L); 83 | static int LuaPlaySystemSound(lua_State* L); 84 | static int LuaPlayEffectSound(lua_State* L); 85 | static int LuaPlayDistanceSound(lua_State* L); 86 | static int LuaPlayCustomSound(lua_State* L); 87 | 88 | static void LuaRegisterFunctions(lua_State* L); 89 | }; 90 | 91 | #endif //__SOUNDS_H_ 92 | 93 | #endif //NO_SOUND 94 | -------------------------------------------------------------------------------- /src/status.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #include "status.h" 6 | 7 | #include "allocator.h" 8 | #include "icons.h" 9 | #include "window.h" 10 | 11 | 12 | // ---- Status ---- // 13 | 14 | MUTEX Status::lockStatus; 15 | 16 | 17 | Status::Status() { 18 | icons = 0; 19 | container = NULL; 20 | } 21 | 22 | Status::~Status() { } 23 | 24 | void Status::SetIcons(unsigned short icons) { 25 | this->icons = icons; 26 | } 27 | 28 | unsigned short Status::GetIcons() { 29 | return icons; 30 | } 31 | 32 | void Status::SetPeriod(unsigned char id, unsigned int period) { 33 | LOCKCLASS lockClass(lockStatus); 34 | 35 | time_lt now = RealTime::getTime(); 36 | 37 | std::map::iterator it = times.find(id); 38 | if (it != times.end()) { 39 | StatusTime stime = it->second; 40 | if (abs((long)(stime.first + stime.second) - (long)(now + period)) > 1000) 41 | times[id] = StatusTime(now, period); 42 | } 43 | else 44 | times[id] = StatusTime(now, period); 45 | } 46 | 47 | 48 | void Status::SetContainer(WindowElementContainer* container) { 49 | LOCKCLASS lockClass(lockStatus); 50 | 51 | this->container = container; 52 | } 53 | 54 | void Status::UpdateContainer() { 55 | LOCKCLASS lockClass1(Windows::lockWindows); 56 | LOCKCLASS lockClass2(lockStatus); 57 | 58 | if (!container) 59 | return; 60 | 61 | container->DeleteAllElements(); 62 | 63 | Window* window = container->GetWindow(); 64 | WindowTemplate* wndTemplate = window->GetWindowTemplate(); 65 | window->SetActiveElement(NULL); 66 | 67 | POINT size_int = window->GetWindowContainer()->GetIntSize(); 68 | POINT size_ext = container->GetIntSize(); 69 | 70 | int num = 0; 71 | for (int i = 0; i < 15; i++) { 72 | if (icons & (1 << i)) { 73 | StatusTime stime(0, 0); 74 | std::map::iterator it = times.find(i + 1); 75 | if (it != times.end()) 76 | stime = it->second; 77 | 78 | AD2D_Image* image = Icons::GetStatusIcon(i + 1); 79 | 80 | WindowElementCooldown* wstatus = new(M_PLACE) WindowElementCooldown; 81 | wstatus->Create(0, 0, num * 32, 32, 32, wndTemplate); 82 | wstatus->SetCast(stime.first, stime.second); 83 | wstatus->SetIcon(image); 84 | 85 | container->AddElement(wstatus); 86 | num++; 87 | } 88 | } 89 | 90 | container->SetPosition(0, size_int.y - num * 32); 91 | container->SetSize(32, num * 32); 92 | } 93 | -------------------------------------------------------------------------------- /src/status.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __STATUS_H_ 6 | #define __STATUS_H_ 7 | 8 | #include 9 | 10 | #include "mthread.h" 11 | #include "realtime.h" 12 | 13 | 14 | class WindowElementContainer; 15 | 16 | 17 | typedef std::pair StatusTime; 18 | 19 | class Status { 20 | private: 21 | WindowElementContainer* container; 22 | 23 | unsigned short icons; 24 | std::map times; 25 | 26 | static MUTEX lockStatus; 27 | 28 | public: 29 | Status(); 30 | ~Status(); 31 | 32 | void SetIcons(unsigned short icons); 33 | unsigned short GetIcons(); 34 | 35 | void SetPeriod(unsigned char id, unsigned int period); 36 | 37 | void SetContainer(WindowElementContainer* container); 38 | void UpdateContainer(); 39 | }; 40 | 41 | 42 | #endif //__STATUS_H_ 43 | -------------------------------------------------------------------------------- /src/text.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #include "text.h" 6 | 7 | #include "allocator.h" 8 | #include "game.h" 9 | #include "luascript.h" 10 | #include "tools.h" 11 | 12 | 13 | // ---- Languages ---- // 14 | 15 | std::list Languages::languages; 16 | bool Languages::loaded = false; 17 | 18 | MUTEX Languages::languagesLock; 19 | 20 | 21 | std::list Languages::GetLanguages() { 22 | LOCKCLASS lockClass(languagesLock); 23 | 24 | if (!loaded) { 25 | languages.clear(); 26 | 27 | INILoader iniLoader; 28 | iniLoader.OpenFile("text.ini"); 29 | 30 | unsigned char num = atoi(iniLoader.GetValue("LANGUAGES").c_str()); 31 | for (int i = 0; i < num; i++) { 32 | std::string type = "LANGUAGE_" + value2str(i); 33 | std::string language = iniLoader.GetValue(type); 34 | if (language != "") 35 | languages.push_back(language); 36 | } 37 | 38 | loaded = true; 39 | } 40 | 41 | return languages; 42 | } 43 | 44 | 45 | // ---- Text ---- // 46 | 47 | INILoader Text::iniLoader; 48 | bool Text::loaded = false; 49 | 50 | MUTEX Text::textLock; 51 | 52 | 53 | std::string Text::GetText(std::string type, unsigned char lang) { 54 | LOCKCLASS lockClass(textLock); 55 | 56 | if (!loaded) { 57 | iniLoader.OpenFile("text.ini"); 58 | loaded = true; 59 | } 60 | 61 | std::string ret = iniLoader.GetValue(type, lang); 62 | 63 | return ret; 64 | } 65 | 66 | 67 | //Lua functions 68 | 69 | int Text::LuaGetText(lua_State* L) { 70 | std::string type = LuaScript::PopString(L); 71 | 72 | std::string text = GetText(type, Game::options.language); 73 | 74 | LuaScript::PushString(L, text); 75 | return 1; 76 | } 77 | 78 | void Text::LuaRegisterFunctions(lua_State* L) { 79 | //getText(keyStr) : textStr 80 | lua_register(L, "getText", Text::LuaGetText); 81 | } 82 | -------------------------------------------------------------------------------- /src/text.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __TEXT_H_ 6 | #define __TEXT_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "iniloader.h" 12 | #include "luascript.h" 13 | #include "mthread.h" 14 | 15 | class Languages { 16 | private: 17 | static std::list languages; 18 | static bool loaded; 19 | 20 | static MUTEX languagesLock; 21 | 22 | public: 23 | static std::list GetLanguages(); 24 | }; 25 | 26 | class Text { 27 | private: 28 | static INILoader iniLoader; 29 | static bool loaded; 30 | 31 | static MUTEX textLock; 32 | 33 | public: 34 | static std::string GetText(std::string type, unsigned char lang); 35 | 36 | //Lua functions 37 | static int LuaGetText(lua_State* L); 38 | 39 | static void LuaRegisterFunctions(lua_State* L); 40 | }; 41 | 42 | #endif //__TEXT_H_ 43 | -------------------------------------------------------------------------------- /src/thing.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #include "thing.h" 6 | 7 | #include "allocator.h" 8 | #include "magiceffect.h" 9 | 10 | 11 | // ---- Thing ---- // 12 | 13 | Thing::Thing() { 14 | light = NULL; 15 | newPos = Position(0, 0, 0); 16 | pos = Position(0, 0, 0); 17 | oldPos = Position(0, 0, 0); 18 | 19 | step = 0.0f; 20 | } 21 | 22 | Thing::~Thing() { } 23 | -------------------------------------------------------------------------------- /src/thing.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __THING_H_ 6 | #define __THING_H_ 7 | 8 | #include "light.h" 9 | #include "logger.h" 10 | #include "position.h" 11 | 12 | 13 | class Thing { 14 | public: 15 | Light* light; 16 | Position newPos; 17 | Position pos; 18 | Position oldPos; 19 | 20 | float step; 21 | 22 | public: 23 | Thing(); 24 | virtual ~Thing(); 25 | }; 26 | 27 | #endif //__THING_H_ 28 | -------------------------------------------------------------------------------- /src/tools.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __TOOLS_H_ 6 | #define __TOOLS_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include "ad2d.h" 19 | #include "const.h" 20 | 21 | class TypePointer { 22 | public: 23 | std::string type; 24 | void* ptr; 25 | 26 | public: 27 | TypePointer() { type = ""; ptr = NULL; } 28 | TypePointer(std::string type) { this->type = type; this->ptr = NULL; } 29 | TypePointer(std::string type, void* ptr) { this->type = type; this->ptr = ptr; } 30 | 31 | void SetValue(std::string data); 32 | std::string GetValue(int precision = 2); 33 | }; 34 | 35 | 36 | class TextString { 37 | public: 38 | std::string text; 39 | std::string color; 40 | 41 | TextString() { text = ""; color = ""; } 42 | TextString(const TextString& txt) : text(txt.text), color(txt.color) { } 43 | TextString(std::string txt, unsigned char col = 215) : text(txt) { color.insert(0, txt.length(), col); } 44 | TextString(std::string txt, std::string col) : text(txt), color(col) { } 45 | }; 46 | 47 | POINT doPOINT(int x, int y); 48 | bool operator==(POINT a, POINT b); 49 | bool operator!=(POINT a, POINT b); 50 | bool operator<(POINT a, POINT b); 51 | bool operator<=(POINT a, POINT b); 52 | bool operator>(POINT a, POINT b); 53 | bool operator>=(POINT a, POINT b); 54 | 55 | typedef std::vector > DividedText; 56 | 57 | bool IsSpecialChar(unsigned char ch); 58 | 59 | std::string ConvertIP(unsigned int ip); 60 | TextString ScrollText(TextString txt, AD2D_Font* font, unsigned short fontSize, int length, int offset = 0); 61 | TextString ScrollText(TextString txt, int length, int offset = 0); 62 | DividedText DivideText(TextString txt); 63 | TextString SetTextColorMap(std::string txt, unsigned char color1, unsigned char color2); 64 | std::string value2str(int64_t value, bool hex = false, int chars = 0); 65 | std::string float2str(double value, int precision = 2); 66 | std::string time2str(time_t time, bool year = true, bool month = true, bool day = true, bool hour = false, bool minute = false, bool second = false, const char* separator = ":"); 67 | std::string tolower(std::string text); 68 | bool CheckChecksumFile(const char* path, unsigned long checksum); 69 | bool CheckChecksum(std::string str, unsigned long checksum); 70 | 71 | uint32_t MakeChecksum(std::string str); 72 | 73 | unsigned char ConvertSpeakClasses(unsigned char speakClass, unsigned short version); 74 | 75 | COLOR ConvertColorSTD(unsigned char color); 76 | 77 | COLOR RT_ConvertColorHP(unsigned char* hp); 78 | COLOR RT_ConvertColorButton(unsigned long time, float r, float g, float b, float a); 79 | 80 | void RemoveEx(std::string directory); 81 | void CreateDirectoryEx(std::string directory); 82 | std::string CutDirectory(std::string name); 83 | 84 | #endif //__TOOLS_H_ 85 | -------------------------------------------------------------------------------- /src/trade.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #include "trade.h" 6 | 7 | #include "allocator.h" 8 | #include "window.h" 9 | 10 | 11 | // ---- Trade ---- // 12 | 13 | Trade::Trade() { 14 | tradeP1 = NULL; 15 | tradeP2 = NULL; 16 | } 17 | 18 | Trade::~Trade() { } 19 | 20 | void Trade::SetContainerP1(Container* container) { 21 | LOCKCLASS lockClass(lockTrade); 22 | 23 | tradeP1 = container; 24 | } 25 | 26 | Container* Trade::GetContainerP1() { 27 | LOCKCLASS lockClass(lockTrade); 28 | 29 | return tradeP1; 30 | } 31 | 32 | void Trade::SetContainerP2(Container* container) { 33 | LOCKCLASS lockClass(lockTrade); 34 | 35 | tradeP2 = container; 36 | } 37 | 38 | Container* Trade::GetContainerP2() { 39 | LOCKCLASS lockClass(lockTrade); 40 | 41 | return tradeP2; 42 | } 43 | 44 | 45 | void Trade::SetButton(WindowElementButton* button) { 46 | LOCKCLASS lockClass(lockTrade); 47 | 48 | this->button = button; 49 | } 50 | 51 | void Trade::SetButtonVisibility(bool state) { 52 | LOCKCLASS lockClass1(Windows::lockWindows); 53 | LOCKCLASS lockClass2(lockTrade); 54 | 55 | if (button) 56 | button->SetVisible(state); 57 | } 58 | 59 | void Trade::SetContainer(WindowElementContainer* container) { 60 | LOCKCLASS lockClass(lockTrade); 61 | 62 | this->container = container; 63 | } 64 | 65 | void Trade::UpdateContainer() { 66 | LOCKCLASS lockClass1(Windows::lockWindows); 67 | LOCKCLASS lockClass2(lockTrade); 68 | 69 | if (!container) 70 | return; 71 | 72 | container->DeleteAllElements(); 73 | 74 | Window* window = container->GetWindow(); 75 | WindowTemplate* wndTemplate = window->GetWindowTemplate(); 76 | window->SetActiveElement(NULL); 77 | 78 | POINT size_ext = container->GetIntSize(); 79 | 80 | if (tradeP1 && tradeP2) 81 | SetButtonVisibility(true); 82 | 83 | WindowElementContainer* cont = new(M_PLACE) WindowElementContainer; 84 | cont->Create(0, 0, 28, size_ext.x, size_ext.y - 28, true, true, wndTemplate); 85 | cont->SetScroll(true); 86 | cont->SetScrollAlwaysVisible(false, true); 87 | cont->SetLocks(false, true); 88 | POINT size = cont->GetIntSize(); 89 | 90 | int height = 0; 91 | if (tradeP1) { 92 | WindowElementText* text = new(M_PLACE) WindowElementText; 93 | text->Create(0, 5, 0, 0xFFFF, wndTemplate); 94 | text->SetText(tradeP1->GetName()); 95 | text->SetBorder(1); 96 | text->SetColor(0.8f, 0.8f, 0.8f); 97 | container->AddElement(text); 98 | 99 | int places = tradeP1->GetPlaces(); 100 | for (int i = 0; i < places; i++) { 101 | Item* item = tradeP1->GetItem(i); 102 | 103 | int posX = (i % 2) * 32; 104 | int posY = (i / 2) * 32; 105 | WindowElementItemContainer* itemCont = new(M_PLACE) WindowElementItemContainer; 106 | itemCont->Create(0, 5 + posX, 5 + posY, 32, 32, tradeP1, wndTemplate); 107 | itemCont->SetSlot(i); 108 | 109 | cont->AddElement(itemCont); 110 | } 111 | 112 | int _height = 10 + (places / 2) * 32 + (places % 2 > 0 ? 32 : 0); 113 | if (height <_height) 114 | height = _height; 115 | } 116 | 117 | if (tradeP2) { 118 | int offset = wndTemplate->GetFont()->GetTextWidth(tradeP2->GetName(), 14) + 5; 119 | 120 | WindowElementText* text = new(M_PLACE) WindowElementText; 121 | text->Create(0, size_ext.x - offset, 14, 0xFFFF, wndTemplate); 122 | text->SetText(tradeP2->GetName()); 123 | text->SetBorder(1); 124 | text->SetColor(0.8f, 0.8f, 0.8f); 125 | container->AddElement(text); 126 | 127 | int places = tradeP2->GetPlaces(); 128 | for (int i = 0; i < places; i++) { 129 | Item* item = tradeP2->GetItem(i); 130 | 131 | int posX = (i % 2) * 32; 132 | int posY = (i / 2) * 32; 133 | WindowElementItemContainer* itemCont = new(M_PLACE) WindowElementItemContainer; 134 | itemCont->Create(0, size.x - 69 + posX, 5 + posY, 32, 32, tradeP2, wndTemplate); 135 | itemCont->SetSlot(i); 136 | 137 | cont->AddElement(itemCont); 138 | } 139 | 140 | int _height = 10 + (places / 2) * 32 + (places % 2 > 0 ? 32 : 0); 141 | if (height <_height) 142 | height = _height; 143 | } 144 | 145 | cont->SetIntSize(0, height); 146 | 147 | container->AddElement(cont); 148 | } 149 | -------------------------------------------------------------------------------- /src/trade.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __TRADE_H_ 6 | #define __TRADE_H_ 7 | 8 | #include "container.h" 9 | #include "mthread.h" 10 | 11 | 12 | class WindowElementContainer; 13 | class WindowElementButton; 14 | 15 | 16 | class Trade { 17 | private: 18 | WindowElementContainer* container; 19 | WindowElementButton* button; 20 | 21 | Container* tradeP1; 22 | Container* tradeP2; 23 | 24 | MUTEX lockTrade; 25 | 26 | public: 27 | Trade(); 28 | ~Trade(); 29 | 30 | void SetContainerP1(Container* container); 31 | Container* GetContainerP1(); 32 | void SetContainerP2(Container* container); 33 | Container* GetContainerP2(); 34 | 35 | void SetButton(WindowElementButton* button); 36 | void SetButtonVisibility(bool state); 37 | 38 | void SetContainer(WindowElementContainer* container); 39 | void UpdateContainer(); 40 | }; 41 | 42 | #endif //__TRADE_H_ 43 | -------------------------------------------------------------------------------- /src/updater.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __UPDATER_H_ 6 | #define __UPDATER_H_ 7 | 8 | #include 9 | 10 | #include "mthread.h" 11 | #include "network.h" 12 | 13 | 14 | class WindowElementContainer; 15 | 16 | 17 | class Updater { 18 | private: 19 | Client httpClient; 20 | 21 | WindowElementContainer* container; 22 | 23 | Signal signal; 24 | THREAD thread; 25 | 26 | public: 27 | static bool running; 28 | static bool completed; 29 | 30 | static MUTEX lockUpdater; 31 | 32 | public: 33 | Updater(); 34 | ~Updater(); 35 | 36 | void StartUpdating(std::string server, std::string location, std::string directory, bool checkVersion); 37 | void StopUpdating(); 38 | void UpdateLoop(std::string server, std::string location, std::string directory, bool checkVersion); 39 | void SignalAddFunction(boost::function f); 40 | void SignalExecute(); 41 | void SignalClear(); 42 | 43 | void IncCounter(std::string server); 44 | void SendErrorReport(std::string server, std::string player, std::string* titlePtr, std::string* descPtr); 45 | bool CheckFile(std::string server, std::string location, std::string filename); 46 | bool DownloadFile(std::string server, std::string location, std::string directory, std::string filename, unsigned long* downloaded, unsigned char* progress); 47 | 48 | void SetContainer(WindowElementContainer* container); 49 | void UpdateContainer(std::string filename, unsigned long* downloaded, unsigned char* progress); 50 | }; 51 | 52 | #endif //__UPDATER_H_ 53 | -------------------------------------------------------------------------------- /src/versioner.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #include "versioner.h" 6 | 7 | #include 8 | 9 | #include "allocator.h" 10 | #include "iniloader.h" 11 | #include "tools.h" 12 | 13 | 14 | // ---- Versioner ---- // 15 | 16 | std::map Versioner::files; 17 | 18 | MUTEX Versioner::lockVersioner; 19 | 20 | 21 | void Versioner::UpdateFilesList(std::string startDir, std::string directory) { 22 | LOCKCLASS lockClass(lockVersioner); 23 | 24 | if (directory.length() == 0) { 25 | files.clear(); 26 | directory = startDir; 27 | } 28 | 29 | INILoader iniLoader; 30 | iniLoader.OpenFile(startDir + "/version.ini"); 31 | 32 | DIR *dp, *child_dp; 33 | struct dirent *dirp; 34 | 35 | if((dp = opendir(directory.c_str())) == NULL) 36 | return; 37 | 38 | while ((dirp = readdir(dp)) != NULL) { 39 | if (std::string(dirp->d_name) == "." || std::string(dirp->d_name) == "..") 40 | continue; 41 | 42 | std::string fullpath = std::string(directory + "/" + dirp->d_name).substr(2, std::string::npos); 43 | std::string filename = std::string(directory + "/" + dirp->d_name).substr(startDir.length() + 1, std::string::npos); 44 | 45 | child_dp = opendir(fullpath.c_str()); 46 | 47 | int ver = 0; 48 | if (atoi(iniLoader.GetValue("RONCLIENT_UPDATER").c_str()) != 0) 49 | ver = atoi(iniLoader.GetValue(filename, 0).c_str()); 50 | else 51 | ver = atoi(iniLoader.GetValue(filename, 1).c_str()); 52 | 53 | files[fullpath] = ver; 54 | 55 | if (child_dp) { 56 | UpdateFilesList(startDir, directory + "/" + dirp->d_name); 57 | closedir(child_dp); 58 | } 59 | } 60 | closedir(dp); 61 | } 62 | 63 | bool Versioner::IsFileOnList(std::string filename) { 64 | LOCKCLASS lockClass(lockVersioner); 65 | 66 | std::map::iterator it = files.find(filename); 67 | if (it != files.end()) 68 | return true; 69 | 70 | return false; 71 | } 72 | 73 | int Versioner::GetFileVersion(std::string filename) { 74 | LOCKCLASS lockClass(lockVersioner); 75 | 76 | std::map::iterator it = files.find(filename); 77 | if (it != files.end()) 78 | return it->second; 79 | 80 | return 0; 81 | } 82 | 83 | void Versioner::ConvertOldToNewVersion(std::string filename) { 84 | LOCKCLASS lockClass(lockVersioner); 85 | 86 | INILoader iniLoader; 87 | if (!iniLoader.OpenFile(filename)) 88 | return; 89 | 90 | if (atoi(iniLoader.GetValue("RONCLIENT_UPDATER").c_str()) != 0) 91 | return; 92 | 93 | INILoader iniLoaderNew; 94 | iniLoaderNew.SetValue("RONCLIENT_UPDATER", "1"); 95 | 96 | int i = 0; 97 | std::string key; 98 | while((key = iniLoader.GetVarName(i)) != "") { 99 | std::string value = iniLoader.GetValue(i, 0); 100 | std::string value2 = iniLoader.GetValue(i, 1); 101 | if (value2 == "") 102 | value2 = "0"; 103 | 104 | if (key == "VERSION") 105 | iniLoaderNew.SetValue("VERSION", value); 106 | else if (key != "RONCLIENT_UPDATER") { 107 | if (value == "DIR") 108 | iniLoaderNew.SetValue(key, value); 109 | else if (value != "DEL") 110 | iniLoaderNew.SetValue(key, value2); 111 | } 112 | i++; 113 | } 114 | 115 | iniLoaderNew.SaveFile(filename); 116 | } 117 | -------------------------------------------------------------------------------- /src/versioner.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __VERSIONER_H_ 6 | #define __VERSIONER_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "mthread.h" 12 | 13 | 14 | class Versioner { 15 | public: 16 | static std::map files; 17 | 18 | static MUTEX lockVersioner; 19 | 20 | public: 21 | static void UpdateFilesList(std::string startDir = ".", std::string directory = ""); 22 | static bool IsFileOnList(std::string filename); 23 | static int GetFileVersion(std::string filename); 24 | static void ConvertOldToNewVersion(std::string filename); 25 | }; 26 | 27 | #endif //__VERSIONER_H_ 28 | -------------------------------------------------------------------------------- /src/viplist.cpp: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #include "viplist.h" 6 | 7 | #include "allocator.h" 8 | #include "creature.h" 9 | #include "window.h" 10 | #include "tools.h" 11 | 12 | 13 | // ---- VIPList ---- // 14 | 15 | VIPList::VIPList() { 16 | container = NULL; 17 | } 18 | 19 | VIPList::~VIPList() { } 20 | 21 | void VIPList::AddCreature(unsigned int creatureID, std::string creatureName, bool online) { 22 | LOCKCLASS lockClass(lockVIPList); 23 | 24 | if (online) { 25 | std::map::iterator it = viplist_online.find(creatureID); 26 | if (it == viplist_online.end()) 27 | viplist_online[creatureID] = creatureName; 28 | } 29 | else { 30 | std::map::iterator it = viplist_offline.find(creatureID); 31 | if (it == viplist_offline.end()) 32 | viplist_offline[creatureID] = creatureName; 33 | } 34 | } 35 | 36 | void VIPList::LoginCreature(unsigned int creatureID) { 37 | LOCKCLASS lockClass(lockVIPList); 38 | 39 | std::map::iterator it = viplist_offline.find(creatureID); 40 | if (it != viplist_offline.end()) { 41 | AddCreature(it->first, it->second, true); 42 | viplist_offline.erase(it); 43 | } 44 | } 45 | 46 | void VIPList::LogoutCreature(unsigned int creatureID) { 47 | LOCKCLASS lockClass(lockVIPList); 48 | 49 | std::map::iterator it = viplist_online.find(creatureID); 50 | if (it != viplist_online.end()) { 51 | AddCreature(it->first, it->second, false); 52 | viplist_online.erase(it); 53 | } 54 | } 55 | 56 | void VIPList::RemoveCreature(unsigned int creatureID) { 57 | LOCKCLASS lockClass(lockVIPList); 58 | 59 | std::map::iterator it = viplist_offline.find(creatureID); 60 | if (it != viplist_offline.end()) 61 | viplist_offline.erase(it); 62 | 63 | it = viplist_online.find(creatureID); 64 | if (it != viplist_online.end()) 65 | viplist_online.erase(it); 66 | } 67 | 68 | void VIPList::ClearVIPList() { 69 | LOCKCLASS lockClass(lockVIPList); 70 | 71 | viplist_offline.clear(); 72 | viplist_online.clear(); 73 | } 74 | 75 | unsigned int VIPList::GetCreatureID(std::string creatureName) { 76 | LOCKCLASS lockClass(lockVIPList); 77 | 78 | std::map::iterator it = viplist_offline.begin(); 79 | for (it; it != viplist_offline.end(); it++) { 80 | if (it->second == creatureName) 81 | return it->first; 82 | } 83 | 84 | it = viplist_online.begin(); 85 | for (it; it != viplist_online.end(); it++) { 86 | if (it->second == creatureName) 87 | return it->first; 88 | } 89 | 90 | return 0; 91 | } 92 | 93 | std::string VIPList::GetCreatureName(unsigned int creatureID) { 94 | LOCKCLASS lockClass(lockVIPList); 95 | 96 | std::map::iterator it = viplist_offline.find(creatureID); 97 | if (it != viplist_offline.end()) 98 | return it->second; 99 | 100 | it = viplist_online.find(creatureID); 101 | if (it != viplist_online.end()) 102 | return it->second; 103 | 104 | return ""; 105 | } 106 | 107 | void VIPList::SetContainer(WindowElementContainer* container) { 108 | LOCKCLASS lockClass(lockVIPList); 109 | 110 | this->container = container; 111 | } 112 | 113 | void VIPList::UpdateContainer() { 114 | LOCKCLASS lockClass1(Windows::lockWindows); 115 | LOCKCLASS lockClass2(lockVIPList); 116 | 117 | if (!container) 118 | return; 119 | 120 | container->DeleteAllElements(); 121 | 122 | Window* window = container->GetWindow(); 123 | window->SetActiveElement(NULL); 124 | 125 | POINT size = window->GetSize(true); 126 | 127 | WindowElementVIP* vip = new(M_PLACE) WindowElementVIP; 128 | vip->Create(0, 0, 0, 0xFFFF, 0xFFFF, false, false, window->GetWindowTemplate()); 129 | vip->SetVIPList(this); 130 | vip->SetCreatureID(0x00); 131 | window->AddElement(vip); 132 | 133 | std::map s_online; 134 | std::map s_offline; 135 | 136 | std::map::iterator _it = viplist_online.begin(); 137 | for (_it; _it != viplist_online.end(); _it++) 138 | s_online[_it->second] = _it->first; 139 | 140 | _it = viplist_offline.begin(); 141 | for (_it; _it != viplist_offline.end(); _it++) 142 | s_offline[_it->second] = _it->first; 143 | 144 | int posY = 0; 145 | std::map::iterator it = s_online.begin(); 146 | for (it; it != s_online.end(); it++) { 147 | std::string creatureName = it->first; 148 | unsigned int creatureID = it->second; 149 | 150 | WindowElementText* text = new(M_PLACE) WindowElementText; 151 | text->Create(0, 5, posY, 0xFFFF, window->GetWindowTemplate()); 152 | text->SetText(creatureName); 153 | text->SetColor(0.0f, 1.0f, 0.0f); 154 | text->SetBorder(1); 155 | posY += 15; 156 | 157 | WindowElementVIP* vip = new(M_PLACE) WindowElementVIP; 158 | vip->Create(0, 0, posY - 15, 0xFFFF, 15, false, false, window->GetWindowTemplate()); 159 | vip->SetVIPList(this); 160 | vip->SetCreatureID(creatureID); 161 | 162 | container->AddElement(text); 163 | container->AddElement(vip); 164 | } 165 | 166 | it = s_offline.begin(); 167 | for (it; it != s_offline.end(); it++) { 168 | std::string creatureName = it->first; 169 | unsigned int creatureID = it->second; 170 | 171 | WindowElementText* text = new(M_PLACE) WindowElementText; 172 | text->Create(0, 5, posY, 0xFFFF, window->GetWindowTemplate()); 173 | text->SetText(creatureName); 174 | text->SetColor(0.8f, 0.0f, 0.0f); 175 | text->SetBorder(1); 176 | posY += 15; 177 | 178 | WindowElementVIP* vip = new(M_PLACE) WindowElementVIP; 179 | vip->Create(0, 0, posY - 15, 0xFFFF, 15, false, false, window->GetWindowTemplate()); 180 | vip->SetVIPList(this); 181 | vip->SetCreatureID(creatureID); 182 | 183 | container->AddElement(text); 184 | container->AddElement(vip); 185 | } 186 | 187 | container->SetIntSize(0, posY); 188 | } 189 | -------------------------------------------------------------------------------- /src/viplist.h: -------------------------------------------------------------------------------- 1 | /* -------------------------------------------------------------------------- */ 2 | /* ------------- RonClient --- Oficial client for RonOTS servers ------------ */ 3 | /* -------------------------------------------------------------------------- */ 4 | 5 | #ifndef __VIPLIST_H_ 6 | #define __VIPLIST_H_ 7 | 8 | #include 9 | #include 10 | 11 | #include "mthread.h" 12 | 13 | 14 | class WindowElementContainer; 15 | 16 | 17 | class VIPList { 18 | private: 19 | WindowElementContainer* container; 20 | 21 | public: 22 | std::map viplist_offline; 23 | std::map viplist_online; 24 | 25 | MUTEX lockVIPList; 26 | 27 | public: 28 | VIPList(); 29 | ~VIPList(); 30 | 31 | void AddCreature(unsigned int creatureID, std::string creatureName, bool online); 32 | void LoginCreature(unsigned int creatureID); 33 | void LogoutCreature(unsigned int creatureID); 34 | void RemoveCreature(unsigned int creatureID); 35 | void ClearVIPList(); 36 | 37 | unsigned int GetCreatureID(std::string creatureName); 38 | std::string GetCreatureName(unsigned int creatureID); 39 | 40 | void SetContainer(WindowElementContainer* container); 41 | void UpdateContainer(); 42 | 43 | int GetSize(); 44 | }; 45 | 46 | #endif //__VIPLIST_H_ 47 | --------------------------------------------------------------------------------