COPS v7 Emulator (v5065 C++/Qt4)

02/06/2014 23:24 CptSky#1
I worked a bit on a C++ emulator for the game Era of Faith, but decided to just retire myself from everything related to TQ. Anyway, I wasn't really developing actively anyway.

I decided to release the C++ emulator (not enough good references in this language), but EoF is not really known, so a CO2 fork is more appropriate. I took some time to fork my project for the patch 5065 and implement few other features to be considered fine enough to be a base.

This emulator is released under a 4-clause BSD license. Meaning that you're free to do whatever you want with this source, but it must keep the original license somewhere for paternity. When using this source, you must specify that you used software developed by « Jean-Philippe Boivin » (CptSky is okay too). Leechers won't probably respect the license which only state to give credits, but eh, at least I tried ;)

Check the LICENSE file for more information about third party modules.

Code:
                               COPS v7 Emulator
                               ----------------

                   Copyright (C) 2012 - 2014 Jean-Philippe Boivin
              https://bitbucket.org/jpboivin/cops-v7-emulator/overview

Overview
--------

COPS v7 Emulator is a fork of Faith Emulator, a C++ emulator of the MMORPG
Era of Faith. COPS v7 Emulator is a fork targeting the MMORPG Conquer Online,
at the patch 5065.

The emulator is developed in C++ with Qt4 / Qt5.
N.B. The QMySQL driver must be build to use the QSQL module properly.

Features
--------

COPS v7 Emulator is currently released as a base source. Most functionalities
are not implemented or completed. However, some features have special and
interesting implementation.

+ Support any POSIX and/or WinAPI operating system with Qt
+ Support any architecture (little endian & big endian | 32 bit & 64 bit)
+ Separate worker for logging (see zfserv.log)
+ Self destructed environment (useful for singletons)
+ MySQL5 database based on the official one

+ Security module
  - Custom implementations for:
    * TQ's custom cipher
    * Blowfish (CFB64)
    * RC5 (32/12/16)
    * Diffie-Hellman exchange

+ Map module
  - Parallel loading of Data Map (DMap) files
    * MapManager will detect the number of physical cores and spawn an appropriate
      amount of worker to load DMaps in parallel.
      e.g. On two PowerPC 970MP (dual core) @ 2.5 GHz, 4 workers will be spawn and
           it will takes less than 30s to load all DMap of a 5065 client.
  - Compressed data when unused
    * Each GameMap will detect when no player will be on the map, and than pack
      the data using the LZ4 algorithm and unpack the data when required.
      e.g. With a PowerPC (64 bit), at idle, the emulator will require less than
           10 MB of RAM to keep all DMap of a 5065 client in memory.
  - Shared data among all GameMaps

+ Script module
  - Shared Lua VM for executing scripts
  - Exposed accessors for the player informations
  - Exposed specialized functions (e.g. text(), link())

+ Generator module
  - Based on TQ's one, using the official spawns will result in the same in-game spawns

+ Character creation
+ Character loading / saving
+ Direction / Emotion / Pk Mode
+ Walking / Jumping
+ Portals
+ Points allocation
+ Talking to NPCs [Incomplete]
+ Screen system [Incomplete]

+ Item features
  - Buying items from NPCs
  - Selling items to NPCs
  - Repairing items
  - Using / eating items
  - Equiping items
  - Real item ID generation for monsters [Incomplete]

Documentation about the emulator can be generated with dOxygen.
To generate the documentation, please in the root folder of the source,
and call dOxygen with Doxyfile.

Supported systems
-----------------

The emulator has been tested on the following platforms:
- Windows XP Professional (SP2)
  + x86_64 [Will compile, untested otherwise]
- Mac OS X Leopard (10.5.8)
  + ppc, ppc64
- Mac OS X Mavericks (10.9.2)
  + (x86), x86_x64
- Debian Lenny (5.0)
  + ARM (armel)

The emulator has been tested with Qt 4.6.3, 4.8.4 & 5.2.1.

However, the emulator should work without any modification on any
POSIX-compliant system (Mac OS X, *NIX, GNU/Linux, etc) and on any
WinAPI system.

N.B. This emulator uses the Windows API and/or the POSIX API and/or the Qt API.
Changelists:

Version 0.1 bug-fixes for Mac OS X.
02/06/2014 23:46 Spirited#2
*High fives*
02/07/2014 00:11 turk55#3
Zero experience in C++ here but gave you a thank for the great effort.
02/07/2014 00:14 CptSky#4
Quote:
Originally Posted by turk55 View Post
Zero experience in C++ here but gave you a thank for the great effort.
It's never too late to learn a new language ;)
02/07/2014 00:33 turk55#5
Quote:
Originally Posted by CptSky View Post
It's never too late to learn a new language ;)
Yeap, but requires time and that is something I barelly have at the moment. :P
02/08/2014 03:54 Arco.#6
Great release jp
02/20/2014 04:10 CptSky#7
Seems to be an issue with VS 2012. Anyone can confirm ?
02/20/2014 21:22 SteveRambo#8
This is definitely some of the most beautiful code I've seen here on epvp. Good job.
03/09/2014 17:15 CptSky#9
The atomic increment won't work on older versions of OS X (probably due to the deprecated version of GCC), I recommend editing the macro to :

Code:
#ifdef __APPLE__
#include <libkern/OSAtomic.h>
#endif // atomics


#if defined(__APPLE__)
#   if defined(TARGET_INSTR_X86_64) || defined(TARGET_INSTR_PPC64)
#       define atomic_inc(ptr) OSAtomicIncrement64Barrier(((volatile int64_t*)ptr))
#   else
#       define atomic_inc(ptr) OSAtomicIncrement32Barrier(((volatile int32_t*)ptr))
#   endif
#elif defined (_WIN32)
#   define atomic_inc(ptr) InterlockedIncrement((ptr))
#elif defined(__GNUC__)
#   define atomic_inc(ptr) (__sync_fetch_and_add((ptr), 1) + 1)
#else
#   error "Need some more porting work for atomic_inc."
#endif
04/17/2014 06:32 atef201080#10
can't compile on QT version 5.2.1
screenshot > [Only registered and activated users can see links. Click Here To Register...]
(QT newbie)
04/17/2014 09:13 Spirited#11
Quote:
Originally Posted by atef201080 View Post
can't compile on QT version 5.2.1
screenshot > [Only registered and activated users can see links. Click Here To Register...]
(QT newbie)
Which is why you compile it with the correct version of QT.
04/17/2014 15:37 atef201080#12
Quote:
Originally Posted by Spirited View Post
Which is why you compile it with the correct version of QT.
i think latest version is better and I'll find better features and more stability I've googled the error and found its linker issue.
-----------
after downloading QT 4 and searching for Mingw 4.4 for hours and installing it
i get the same errors when compiling :D
[Only registered and activated users can see links. Click Here To Register...]
----------
adding
Code:
LIBS += -lwinmm
at .pro file fixed it with QT latest version...
04/17/2014 18:41 CptSky#13
Yes, if using MinGW, VS extensions are not supported, so winmm is not linked.

For the error of sync_fetch_add, you should change the macro in common.h to :

Code:
#if defined(__APPLE__)
#   if defined(TARGET_INSTR_X86_64) || defined(TARGET_INSTR_PPC64)
#       define atomic_inc(ptr) OSAtomicIncrement64Barrier(((volatile int64_t*)ptr))
#   else
#       define atomic_inc(ptr) OSAtomicIncrement32Barrier(((volatile int32_t*)ptr))
#   endif
#elif defined (_WIN32)
#   define atomic_inc(ptr) InterlockedIncrement((ptr))
#elif defined(__GNUC__)
#   define atomic_inc(ptr) (__sync_fetch_and_add((ptr), 1) + 1)
#else
#   error "Need some more porting work for atomic_inc."
#endif
04/18/2014 04:00 atef201080#14
Another error...
Quote:
D/[..\COPSv7\src\Database\database.cpp:loadAllMaps(): 497] Executing SQL: SELECT `id`, `doc_id`, `type`, `weather`, `portal_x`, `portal_y`, `reborn_map`, `reborn_portal`, `light` FROM `map`
E/[..\COPSv7\src\Database\database.cpp:loadAllMaps(): 532] Failed to execute the following cmd : "SELECT `id`, `doc_id`, `type`, `weather`, `portal_x`, `portal_y`, `reborn_map`, `reborn_portal`, `light` FROM `map`"
Error: Using unsupported buffer type: 3 (parameter: 3) QMYSQL3: Unable to bind outvalues
04/18/2014 17:41 CptSky#15
Quote:
Originally Posted by atef201080 View Post
Another error...
You're using a MySQL 3 driver... You must build the MySQL 5 driver.