Merge with develop
This commit is contained in:
parent
989569c137
commit
48757c15b7
16 changed files with 585 additions and 279 deletions
|
@ -51,6 +51,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
Q_EXPORT_PLUGIN2(object_viewer_widget_qt, NLQT::CObjectViewerWidget)
|
Q_EXPORT_PLUGIN2(object_viewer_widget_qt, NLQT::CObjectViewerWidget)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(NL_OS_WINDOWS)
|
||||||
|
typedef bool (*winProc)(NL3D::IDriver *driver, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
|
||||||
|
#elif defined(NL_OS_MAC)
|
||||||
|
typedef bool (*cocoaProc)(NL3D::IDriver*, const void* e);
|
||||||
|
#else
|
||||||
|
typedef bool (*x11Proc)(NL3D::IDriver *drv, XEvent *e);
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace NLMISC;
|
using namespace NLMISC;
|
||||||
using namespace NL3D;
|
using namespace NL3D;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
@ -87,13 +95,13 @@ namespace NLQT
|
||||||
|
|
||||||
void CObjectViewerWidget::showEvent ( QShowEvent * event )
|
void CObjectViewerWidget::showEvent ( QShowEvent * event )
|
||||||
{
|
{
|
||||||
if (!_mainTimer->isActive())
|
if (!_mainTimer->isActive())
|
||||||
{
|
{
|
||||||
_mainTimer->start(25);
|
_mainTimer->start(25);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CObjectViewerWidget::setNelContext(NLMISC::INelContext &nelContext)
|
void CObjectViewerWidget::setNelContext(NLMISC::INelContext &nelContext)
|
||||||
{
|
{
|
||||||
_LibContext = new CLibraryContext(nelContext);
|
_LibContext = new CLibraryContext(nelContext);
|
||||||
}
|
}
|
||||||
|
@ -260,7 +268,7 @@ namespace NLQT
|
||||||
// ...
|
// ...
|
||||||
|
|
||||||
// 09. Update Animations (playlists)
|
// 09. Update Animations (playlists)
|
||||||
// - Needs to be either before or after entities, not sure,
|
// - Needs to be either before or after entities, not sure,
|
||||||
// there was a problem with wrong order a while ago!!!
|
// there was a problem with wrong order a while ago!!!
|
||||||
|
|
||||||
|
|
||||||
|
@ -283,7 +291,7 @@ namespace NLQT
|
||||||
|
|
||||||
if (_isGraphicsInitialized && !getDriver()->isLost())
|
if (_isGraphicsInitialized && !getDriver()->isLost())
|
||||||
{
|
{
|
||||||
// 01. Render Driver (background color)
|
// 01. Render Driver (background color)
|
||||||
renderDriver(); // clear all buffers
|
renderDriver(); // clear all buffers
|
||||||
|
|
||||||
// 02. Render Sky (sky scene)
|
// 02. Render Sky (sky scene)
|
||||||
|
@ -428,14 +436,14 @@ namespace NLQT
|
||||||
bool CObjectViewerWidget::loadMesh(const std::string &meshFileName, const std::string &skelFileName)
|
bool CObjectViewerWidget::loadMesh(const std::string &meshFileName, const std::string &skelFileName)
|
||||||
{
|
{
|
||||||
std::string fileName = CFile::getFilenameWithoutExtension(meshFileName);
|
std::string fileName = CFile::getFilenameWithoutExtension(meshFileName);
|
||||||
if ( _Entities.count(fileName) != 0)
|
if ( _Entities.count(fileName) != 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
CPath::addSearchPath(CFile::getPath(meshFileName), false, false);
|
CPath::addSearchPath(CFile::getPath(meshFileName), false, false);
|
||||||
|
|
||||||
// create instance of the mesh character
|
// create instance of the mesh character
|
||||||
UInstance Entity = _Scene->createInstance(meshFileName);
|
UInstance Entity = _Scene->createInstance(meshFileName);
|
||||||
|
|
||||||
CAABBox bbox;
|
CAABBox bbox;
|
||||||
Entity.getShapeAABBox(bbox);
|
Entity.getShapeAABBox(bbox);
|
||||||
setCamera(_Scene, bbox , Entity, true);
|
setCamera(_Scene, bbox , Entity, true);
|
||||||
|
@ -456,7 +464,7 @@ namespace NLQT
|
||||||
entity._FileNameShape = meshFileName;
|
entity._FileNameShape = meshFileName;
|
||||||
entity._FileNameSkeleton = skelFileName;
|
entity._FileNameSkeleton = skelFileName;
|
||||||
entity._Instance = Entity;
|
entity._Instance = Entity;
|
||||||
if (!Skeleton.empty())
|
if (!Skeleton.empty())
|
||||||
{
|
{
|
||||||
entity._Skeleton = Skeleton;
|
entity._Skeleton = Skeleton;
|
||||||
entity._Skeleton.bindSkin (entity._Instance);
|
entity._Skeleton.bindSkin (entity._Instance);
|
||||||
|
@ -735,11 +743,38 @@ namespace NLQT
|
||||||
_Scene->animate ( fdelta);
|
_Scene->animate ( fdelta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_QT5
|
||||||
|
|
||||||
|
bool CObjectViewerWidget::nativeEvent(const QByteArray &eventType, void *message, long *result)
|
||||||
|
{
|
||||||
|
if (getDriver() && getDriver()->isActive())
|
||||||
|
{
|
||||||
|
NL3D::IDriver *driver = dynamic_cast<NL3D::CDriverUser*>(getDriver())->getDriver();
|
||||||
|
if (driver)
|
||||||
|
{
|
||||||
|
// see what to do with result
|
||||||
|
#if defined(NL_OS_WINDOWS)
|
||||||
|
MSG *msg = (MSG*)message;
|
||||||
|
winProc proc = (winProc)driver->getWindowProc();
|
||||||
|
return proc(driver, msg->hwnd, msg->message, msg->wParam, msg->lParam);
|
||||||
|
#elif defined(NL_OS_MAC)
|
||||||
|
cocoaProc proc = (cocoaProc)driver->getWindowProc();
|
||||||
|
return proc(driver, message);
|
||||||
|
#else
|
||||||
|
x11Proc proc = (x11Proc)driver->getWindowProc();
|
||||||
|
return proc(driver, message);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
#if defined(NL_OS_WINDOWS)
|
#if defined(NL_OS_WINDOWS)
|
||||||
|
|
||||||
typedef bool (*winProc)(NL3D::IDriver *driver, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
|
bool CObjectViewerWidget::winEvent(MSG *message, long *result)
|
||||||
|
|
||||||
bool CObjectViewerWidget::winEvent(MSG * message, long * result)
|
|
||||||
{
|
{
|
||||||
if (getDriver() && getDriver()->isActive())
|
if (getDriver() && getDriver()->isActive())
|
||||||
{
|
{
|
||||||
|
@ -756,8 +791,6 @@ namespace NLQT
|
||||||
|
|
||||||
#elif defined(NL_OS_MAC)
|
#elif defined(NL_OS_MAC)
|
||||||
|
|
||||||
typedef bool (*cocoaProc)(NL3D::IDriver*, const void* e);
|
|
||||||
|
|
||||||
bool CObjectViewerWidget::macEvent(EventHandlerCallRef caller, EventRef event)
|
bool CObjectViewerWidget::macEvent(EventHandlerCallRef caller, EventRef event)
|
||||||
{
|
{
|
||||||
if(caller)
|
if(caller)
|
||||||
|
@ -778,8 +811,6 @@ namespace NLQT
|
||||||
|
|
||||||
#elif defined(NL_OS_UNIX)
|
#elif defined(NL_OS_UNIX)
|
||||||
|
|
||||||
typedef bool (*x11Proc)(NL3D::IDriver *drv, XEvent *e);
|
|
||||||
|
|
||||||
bool CObjectViewerWidget::x11Event(XEvent *event)
|
bool CObjectViewerWidget::x11Event(XEvent *event)
|
||||||
{
|
{
|
||||||
if (getDriver() && getDriver()->isActive())
|
if (getDriver() && getDriver()->isActive())
|
||||||
|
@ -796,4 +827,6 @@ namespace NLQT
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
} /* namespace NLQT */
|
} /* namespace NLQT */
|
||||||
|
|
|
@ -33,7 +33,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#include "entity.h"
|
#include "entity.h"
|
||||||
#include "interfaces.h"
|
#include "interfaces.h"
|
||||||
|
|
||||||
namespace NL3D
|
namespace NL3D
|
||||||
{
|
{
|
||||||
class UDriver;
|
class UDriver;
|
||||||
class UScene;
|
class UScene;
|
||||||
|
@ -50,14 +50,14 @@ class QIcon;
|
||||||
namespace NLQT
|
namespace NLQT
|
||||||
@brief namespace NLQT
|
@brief namespace NLQT
|
||||||
*/
|
*/
|
||||||
namespace NLQT
|
namespace NLQT
|
||||||
{
|
{
|
||||||
class CObjectViewerWidget:
|
class CObjectViewerWidget:
|
||||||
public QWidget,
|
public QWidget,
|
||||||
public IObjectViewer
|
public IObjectViewer
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_INTERFACES(NLQT::IObjectViewer)
|
Q_INTERFACES(NLQT::IObjectViewer)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// Default constructor.
|
/// Default constructor.
|
||||||
|
@ -113,7 +113,7 @@ namespace NLQT
|
||||||
/// @param w - width window.
|
/// @param w - width window.
|
||||||
/// @param h - height window.
|
/// @param h - height window.
|
||||||
void setSizeViewport(uint16 w, uint16 h);
|
void setSizeViewport(uint16 w, uint16 h);
|
||||||
|
|
||||||
void setBloomEffect(bool enabled) { _BloomEffect = enabled; }
|
void setBloomEffect(bool enabled) { _BloomEffect = enabled; }
|
||||||
|
|
||||||
/// Select instance from the scene
|
/// Select instance from the scene
|
||||||
|
@ -166,19 +166,25 @@ namespace NLQT
|
||||||
virtual QString name() const {return ("ObjectViewerWidget");}
|
virtual QString name() const {return ("ObjectViewerWidget");}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
#ifdef USE_QT5
|
||||||
|
virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result);
|
||||||
|
#else
|
||||||
|
|
||||||
#if defined(NL_OS_WINDOWS)
|
#if defined(NL_OS_WINDOWS)
|
||||||
virtual bool winEvent(MSG * message, long * result);
|
virtual bool winEvent(MSG * message, long * result);
|
||||||
#elif defined(NL_OS_MAC)
|
#elif defined(NL_OS_MAC)
|
||||||
virtual bool macEvent(EventHandlerCallRef caller, EventRef event);
|
virtual bool macEvent(EventHandlerCallRef caller, EventRef event);
|
||||||
#elif defined(NL_OS_UNIX)
|
#elif defined(NL_OS_UNIX)
|
||||||
virtual bool x11Event(XEvent *event);
|
virtual bool x11Event(XEvent *event);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void updateRender();
|
void updateRender();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/// Update the animation time for Particle System animation.
|
/// Update the animation time for Particle System animation.
|
||||||
/// @param deltaTime - set the manual animation time.
|
/// @param deltaTime - set the manual animation time.
|
||||||
void updateAnimatePS(uint64 deltaTime = 0);
|
void updateAnimatePS(uint64 deltaTime = 0);
|
||||||
|
|
|
@ -56,4 +56,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#include <nel/misc/types_nl.h>
|
#include <nel/misc/types_nl.h>
|
||||||
#include <nel/misc/common.h>
|
#include <nel/misc/common.h>
|
||||||
|
|
||||||
|
#if defined(NL_OS_WINDOWS)
|
||||||
|
#define NOMINMAX
|
||||||
|
#include <Windows.h>
|
||||||
|
#elif defined(NL_OS_MAC)
|
||||||
|
#else
|
||||||
|
#include <X11/Xlib.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -280,11 +280,11 @@ NLMISC_COMMAND(gotoNote, "go to a note", "<id>|<text>")
|
||||||
if(i != 0) tok += " ";
|
if(i != 0) tok += " ";
|
||||||
tok += args[i];
|
tok += args[i];
|
||||||
}
|
}
|
||||||
tok = strlwr(tok);
|
tok = toLower(tok);
|
||||||
list<C3DNotes::CNote>::iterator it;
|
list<C3DNotes::CNote>::iterator it;
|
||||||
for(it = Notes.Notes.begin(); it != Notes.Notes.end(); it++)
|
for(it = Notes.Notes.begin(); it != Notes.Notes.end(); it++)
|
||||||
{
|
{
|
||||||
string note = strlwr((*it).Note);
|
string note = toLower((*it).Note);
|
||||||
if(note.find(tok) != string::npos)
|
if(note.find(tok) != string::npos)
|
||||||
{
|
{
|
||||||
pos = (*it).Position;
|
pos = (*it).Position;
|
||||||
|
|
|
@ -64,8 +64,7 @@ void CAnimationFX::buildTrack(NL3D::UAnimationSet *as)
|
||||||
nlassert(Sheet != NULL);
|
nlassert(Sheet != NULL);
|
||||||
if (!as) return;
|
if (!as) return;
|
||||||
if (Sheet->TrajectoryAnim.empty()) return;
|
if (Sheet->TrajectoryAnim.empty()) return;
|
||||||
std::string animName = Sheet->TrajectoryAnim;
|
std::string animName = NLMISC::toLower(Sheet->TrajectoryAnim);
|
||||||
NLMISC::strlwr(animName);
|
|
||||||
uint id = as->getAnimationIdByName(animName);
|
uint id = as->getAnimationIdByName(animName);
|
||||||
NL3D::UAnimation *anim = NULL;
|
NL3D::UAnimation *anim = NULL;
|
||||||
if (id != NL3D::UAnimationSet::NotFound)
|
if (id != NL3D::UAnimationSet::NotFound)
|
||||||
|
|
|
@ -204,7 +204,7 @@ void CAutomatonStateSheet::build(const NLGEORGES::UFormElm &item, const string &
|
||||||
for(uint mode = 0; mode<MBEHAV::NUMBER_OF_MODES; ++mode)
|
for(uint mode = 0; mode<MBEHAV::NUMBER_OF_MODES; ++mode)
|
||||||
{
|
{
|
||||||
string animset;
|
string animset;
|
||||||
animset = NLMISC::strlwr(MBEHAV::modeToString((MBEHAV::EMode)mode));
|
animset = NLMISC::toLower(MBEHAV::modeToString((MBEHAV::EMode)mode));
|
||||||
if(animset != "unknown_mode")
|
if(animset != "unknown_mode")
|
||||||
{
|
{
|
||||||
string resultTransition;
|
string resultTransition;
|
||||||
|
@ -495,9 +495,9 @@ void CAutomatonListSheet::build(const NLGEORGES::UFormElm &rootList)
|
||||||
for(uint mode = 0; mode<MBEHAV::NUMBER_OF_MODES; ++mode)
|
for(uint mode = 0; mode<MBEHAV::NUMBER_OF_MODES; ++mode)
|
||||||
{
|
{
|
||||||
// Get the Mode Name
|
// Get the Mode Name
|
||||||
string modeName = NLMISC::strlwr(MBEHAV::modeToString((MBEHAV::EMode)mode));
|
string modeName = NLMISC::toLower(MBEHAV::modeToString((MBEHAV::EMode)mode));
|
||||||
// Compute the automaton name
|
// Compute the automaton name
|
||||||
string filename = NLMISC::strlwr(automatonType) + "_" + modeName + ".automaton";
|
string filename = NLMISC::toLower(automatonType) + "_" + modeName + ".automaton";
|
||||||
// Push some information
|
// Push some information
|
||||||
nlinfo("loading automaton '%s'.", filename.c_str());
|
nlinfo("loading automaton '%s'.", filename.c_str());
|
||||||
// Load the automaton's form.
|
// Load the automaton's form.
|
||||||
|
|
|
@ -126,7 +126,7 @@ void CCharacterSheet::readEquipment(const NLGEORGES::UFormElm &form, const strin
|
||||||
string itemName;
|
string itemName;
|
||||||
if(!form.getValueByName(itemName, string(key + ".Item").c_str() ))
|
if(!form.getValueByName(itemName, string(key + ".Item").c_str() ))
|
||||||
debug(NLMISC::toString("Key '%s.Item' not found.", key.c_str()));
|
debug(NLMISC::toString("Key '%s.Item' not found.", key.c_str()));
|
||||||
slot.IdItem = ClientSheetsStrings.add(NLMISC::strlwr(itemName));
|
slot.IdItem = ClientSheetsStrings.add(NLMISC::toLower(itemName));
|
||||||
|
|
||||||
// Get the texture.
|
// Get the texture.
|
||||||
if(!form.getValueByName(slot.Texture, string(key + ".Texture").c_str() ))
|
if(!form.getValueByName(slot.Texture, string(key + ".Texture").c_str() ))
|
||||||
|
@ -221,7 +221,7 @@ void CCharacterSheet::build(const NLGEORGES::UFormElm &item)
|
||||||
if(AnimSetBaseName.empty())
|
if(AnimSetBaseName.empty())
|
||||||
debug("AnimSetBaseName is Empty.");
|
debug("AnimSetBaseName is Empty.");
|
||||||
else
|
else
|
||||||
NLMISC::strlwr(AnimSetBaseName); // Force the CASE in UPPER to not be CASE SENSITIVE.
|
AnimSetBaseName = NLMISC::toLower(AnimSetBaseName); // Force the CASE in UPPER to not be CASE SENSITIVE.
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
debug("Key '3d data.AnimSetBaseName' not found.");
|
debug("Key '3d data.AnimSetBaseName' not found.");
|
||||||
|
@ -235,7 +235,7 @@ void CCharacterSheet::build(const NLGEORGES::UFormElm &item)
|
||||||
debug("Automaton is Empty.");
|
debug("Automaton is Empty.");
|
||||||
// Lower Case
|
// Lower Case
|
||||||
else
|
else
|
||||||
NLMISC::strlwr(Automaton);
|
Automaton = NLMISC::toLower(Automaton);
|
||||||
}
|
}
|
||||||
// Key not Found
|
// Key not Found
|
||||||
else
|
else
|
||||||
|
|
|
@ -177,28 +177,28 @@ void CItemSheet::build(const NLGEORGES::UFormElm &item)
|
||||||
string IconMain;
|
string IconMain;
|
||||||
if(!item.getValueByName (IconMain, "3d.icon"))
|
if(!item.getValueByName (IconMain, "3d.icon"))
|
||||||
debug("key '3d.icon' not found.");
|
debug("key '3d.icon' not found.");
|
||||||
IconMain = strlwr (IconMain);
|
IconMain = toLower(IconMain);
|
||||||
IdIconMain = ClientSheetsStrings.add(IconMain);
|
IdIconMain = ClientSheetsStrings.add(IconMain);
|
||||||
|
|
||||||
// Get the icon associated.
|
// Get the icon associated.
|
||||||
string IconBack;
|
string IconBack;
|
||||||
if(!item.getValueByName (IconBack, "3d.icon background"))
|
if(!item.getValueByName (IconBack, "3d.icon background"))
|
||||||
debug("key '3d.icon background' not found.");
|
debug("key '3d.icon background' not found.");
|
||||||
IconBack = strlwr (IconBack);
|
IconBack = toLower(IconBack);
|
||||||
IdIconBack = ClientSheetsStrings.add(IconBack);
|
IdIconBack = ClientSheetsStrings.add(IconBack);
|
||||||
|
|
||||||
// Get the icon associated.
|
// Get the icon associated.
|
||||||
string IconOver;
|
string IconOver;
|
||||||
if(!item.getValueByName (IconOver, "3d.icon overlay"))
|
if(!item.getValueByName (IconOver, "3d.icon overlay"))
|
||||||
debug("key '3d.icon overlay' not found.");
|
debug("key '3d.icon overlay' not found.");
|
||||||
IconOver = strlwr (IconOver);
|
IconOver = toLower(IconOver);
|
||||||
IdIconOver = ClientSheetsStrings.add(IconOver);
|
IdIconOver = ClientSheetsStrings.add(IconOver);
|
||||||
|
|
||||||
// Get the icon associated.
|
// Get the icon associated.
|
||||||
string IconOver2;
|
string IconOver2;
|
||||||
if(!item.getValueByName (IconOver2, "3d.icon overlay2"))
|
if(!item.getValueByName (IconOver2, "3d.icon overlay2"))
|
||||||
debug("key '3d.icon overlay2' not found.");
|
debug("key '3d.icon overlay2' not found.");
|
||||||
IconOver2 = strlwr (IconOver2);
|
IconOver2 = toLower(IconOver2);
|
||||||
IdIconOver2 = ClientSheetsStrings.add(IconOver2);
|
IdIconOver2 = ClientSheetsStrings.add(IconOver2);
|
||||||
|
|
||||||
// Get Special modulate colors
|
// Get Special modulate colors
|
||||||
|
@ -211,7 +211,7 @@ void CItemSheet::build(const NLGEORGES::UFormElm &item)
|
||||||
string IconText;
|
string IconText;
|
||||||
if(!item.getValueByName (IconText, "3d.text overlay"))
|
if(!item.getValueByName (IconText, "3d.text overlay"))
|
||||||
debug("key '3d.text overlay' not found.");
|
debug("key '3d.text overlay' not found.");
|
||||||
IconText = strlwr (IconText);
|
IconText = toLower(IconText);
|
||||||
IdIconText = ClientSheetsStrings.add(IconText);
|
IdIconText = ClientSheetsStrings.add(IconText);
|
||||||
|
|
||||||
// See if this item can be hiden when equipped
|
// See if this item can be hiden when equipped
|
||||||
|
@ -303,7 +303,7 @@ void CItemSheet::build(const NLGEORGES::UFormElm &item)
|
||||||
debug("key '3d.anim_set' not found.");
|
debug("key '3d.anim_set' not found.");
|
||||||
// Force the CASE in UPPER to not be CASE SENSITIVE.
|
// Force the CASE in UPPER to not be CASE SENSITIVE.
|
||||||
else
|
else
|
||||||
NLMISC::strlwr(AnimSet);
|
AnimSet = NLMISC::toLower(AnimSet);
|
||||||
IdAnimSet = ClientSheetsStrings.add(AnimSet);
|
IdAnimSet = ClientSheetsStrings.add(AnimSet);
|
||||||
|
|
||||||
// Get the Trail Shape
|
// Get the Trail Shape
|
||||||
|
@ -318,28 +318,28 @@ void CItemSheet::build(const NLGEORGES::UFormElm &item)
|
||||||
string Effect1;
|
string Effect1;
|
||||||
if(!item.getValueByName(Effect1, "Effects.Effect1"))
|
if(!item.getValueByName(Effect1, "Effects.Effect1"))
|
||||||
debug("key 'Effects.Effect1' not found.");
|
debug("key 'Effects.Effect1' not found.");
|
||||||
Effect1 = strlwr(Effect1);
|
Effect1 = toLower(Effect1);
|
||||||
IdEffect1 = ClientSheetsStrings.add(Effect1);
|
IdEffect1 = ClientSheetsStrings.add(Effect1);
|
||||||
|
|
||||||
// Get special Effect2
|
// Get special Effect2
|
||||||
string Effect2;
|
string Effect2;
|
||||||
if(!item.getValueByName(Effect2, "Effects.Effect2"))
|
if(!item.getValueByName(Effect2, "Effects.Effect2"))
|
||||||
debug("key 'Effects.Effect2' not found.");
|
debug("key 'Effects.Effect2' not found.");
|
||||||
Effect2 = strlwr(Effect2);
|
Effect2 = toLower(Effect2);
|
||||||
IdEffect2 = ClientSheetsStrings.add(Effect2);
|
IdEffect2 = ClientSheetsStrings.add(Effect2);
|
||||||
|
|
||||||
// Get special Effect3
|
// Get special Effect3
|
||||||
string Effect3;
|
string Effect3;
|
||||||
if(!item.getValueByName(Effect3, "Effects.Effect3"))
|
if(!item.getValueByName(Effect3, "Effects.Effect3"))
|
||||||
debug("key 'Effects.Effect3' not found.");
|
debug("key 'Effects.Effect3' not found.");
|
||||||
Effect3 = strlwr(Effect3);
|
Effect3 = toLower(Effect3);
|
||||||
IdEffect3 = ClientSheetsStrings.add(Effect3);
|
IdEffect3 = ClientSheetsStrings.add(Effect3);
|
||||||
|
|
||||||
// Get special Effect4
|
// Get special Effect4
|
||||||
string Effect4;
|
string Effect4;
|
||||||
if(!item.getValueByName(Effect4, "Effects.Effect4"))
|
if(!item.getValueByName(Effect4, "Effects.Effect4"))
|
||||||
debug("key 'Effects.Effect4' not found.");
|
debug("key 'Effects.Effect4' not found.");
|
||||||
Effect4 = strlwr(Effect4);
|
Effect4 = toLower(Effect4);
|
||||||
IdEffect4 = ClientSheetsStrings.add(Effect4);
|
IdEffect4 = ClientSheetsStrings.add(Effect4);
|
||||||
|
|
||||||
// Get its bulk
|
// Get its bulk
|
||||||
|
|
|
@ -110,28 +110,28 @@ void COutpostBuildingSheet::build(const NLGEORGES::UFormElm &root)
|
||||||
string IconMain;
|
string IconMain;
|
||||||
if(!root.getValueByName (IconMain, "icon"))
|
if(!root.getValueByName (IconMain, "icon"))
|
||||||
debug("key 'icon' not found.");
|
debug("key 'icon' not found.");
|
||||||
IconMain = strlwr (IconMain);
|
IconMain = toLower(IconMain);
|
||||||
IdIconMain = ClientSheetsStrings.add(IconMain);
|
IdIconMain = ClientSheetsStrings.add(IconMain);
|
||||||
|
|
||||||
// Get the icon associated.
|
// Get the icon associated.
|
||||||
string IconBack;
|
string IconBack;
|
||||||
if(!root.getValueByName (IconBack, "icon background"))
|
if(!root.getValueByName (IconBack, "icon background"))
|
||||||
debug("key 'icon background' not found.");
|
debug("key 'icon background' not found.");
|
||||||
IconBack = strlwr (IconBack);
|
IconBack = toLower(IconBack);
|
||||||
IdIconBack = ClientSheetsStrings.add(IconBack);
|
IdIconBack = ClientSheetsStrings.add(IconBack);
|
||||||
|
|
||||||
// Get the icon associated.
|
// Get the icon associated.
|
||||||
string IconOver;
|
string IconOver;
|
||||||
if(!root.getValueByName (IconOver, "icon overlay"))
|
if(!root.getValueByName (IconOver, "icon overlay"))
|
||||||
debug("key 'icon overlay' not found.");
|
debug("key 'icon overlay' not found.");
|
||||||
IconOver = strlwr (IconOver);
|
IconOver = toLower(IconOver);
|
||||||
IdIconOver = ClientSheetsStrings.add(IconOver);
|
IdIconOver = ClientSheetsStrings.add(IconOver);
|
||||||
|
|
||||||
// Get the icon text associated.
|
// Get the icon text associated.
|
||||||
string IconText;
|
string IconText;
|
||||||
if(!root.getValueByName (IconText, "text overlay"))
|
if(!root.getValueByName (IconText, "text overlay"))
|
||||||
debug("key 'text overlay' not found.");
|
debug("key 'text overlay' not found.");
|
||||||
IconText = strlwr (IconText);
|
IconText = toLower(IconText);
|
||||||
IdIconText = ClientSheetsStrings.add(IconText);
|
IdIconText = ClientSheetsStrings.add(IconText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ void CPlayerSheet::build(const NLGEORGES::UFormElm &item)
|
||||||
debug("Key 'AnimSetBaseName' not found.");
|
debug("Key 'AnimSetBaseName' not found.");
|
||||||
// Force the CASE in UPPER to not be CASE SENSITIVE.
|
// Force the CASE in UPPER to not be CASE SENSITIVE.
|
||||||
else
|
else
|
||||||
NLMISC::strlwr(AnimSetBaseName);
|
AnimSetBaseName = NLMISC::toLower(AnimSetBaseName);
|
||||||
|
|
||||||
// Load Lod character name
|
// Load Lod character name
|
||||||
if(!item.getValueByName(LodCharacterName, "LodCharacterName"))
|
if(!item.getValueByName(LodCharacterName, "LodCharacterName"))
|
||||||
|
@ -240,7 +240,7 @@ void CPlayerSheet::CEquipment::build(const std::string &key,const NLGEORGES::UFo
|
||||||
if(!item.getValueByName(itemName, string(key + ".Item").c_str() ))
|
if(!item.getValueByName(itemName, string(key + ".Item").c_str() ))
|
||||||
debug(NLMISC::toString("Key '%s.Item' not found.", key.c_str()));
|
debug(NLMISC::toString("Key '%s.Item' not found.", key.c_str()));
|
||||||
else
|
else
|
||||||
Item = NLMISC::strlwr(itemName);
|
Item = NLMISC::toLower(itemName);
|
||||||
|
|
||||||
// Get the color.
|
// Get the color.
|
||||||
if(!item.getValueByName(Color, string(key + ".Color").c_str() ))
|
if(!item.getValueByName(Color, string(key + ".Color").c_str() ))
|
||||||
|
|
|
@ -113,22 +113,22 @@ void CSBrickSheet::build (const NLGEORGES::UFormElm &root)
|
||||||
// read icons
|
// read icons
|
||||||
string Icon;
|
string Icon;
|
||||||
root.getValueByName (Icon, "Client.Icon" );
|
root.getValueByName (Icon, "Client.Icon" );
|
||||||
Icon = strlwr(Icon);
|
Icon = toLower(Icon);
|
||||||
IdIcon = ClientSheetsStrings.add(Icon);
|
IdIcon = ClientSheetsStrings.add(Icon);
|
||||||
|
|
||||||
string IconBack;
|
string IconBack;
|
||||||
root.getValueByName (IconBack, "Client.IconBack" );
|
root.getValueByName (IconBack, "Client.IconBack" );
|
||||||
IconBack = strlwr(IconBack);
|
IconBack = toLower(IconBack);
|
||||||
IdIconBack = ClientSheetsStrings.add(IconBack);
|
IdIconBack = ClientSheetsStrings.add(IconBack);
|
||||||
|
|
||||||
string IconOver;
|
string IconOver;
|
||||||
root.getValueByName (IconOver, "Client.IconOver" );
|
root.getValueByName (IconOver, "Client.IconOver" );
|
||||||
IconOver = strlwr(IconOver);
|
IconOver = toLower(IconOver);
|
||||||
IdIconOver = ClientSheetsStrings.add(IconOver);
|
IdIconOver = ClientSheetsStrings.add(IconOver);
|
||||||
|
|
||||||
string IconOver2;
|
string IconOver2;
|
||||||
root.getValueByName (IconOver2, "Client.IconOver2" );
|
root.getValueByName (IconOver2, "Client.IconOver2" );
|
||||||
IconOver2 = strlwr(IconOver2);
|
IconOver2 = toLower(IconOver2);
|
||||||
IdIconOver2 = ClientSheetsStrings.add(IconOver2);
|
IdIconOver2 = ClientSheetsStrings.add(IconOver2);
|
||||||
|
|
||||||
root.getValueByName (IconColor, "Client.IconColor" );
|
root.getValueByName (IconColor, "Client.IconColor" );
|
||||||
|
@ -381,8 +381,7 @@ void CSBrickSheet::build (const NLGEORGES::UFormElm &root)
|
||||||
for(i=0;i<listBrick.size();i++)
|
for(i=0;i<listBrick.size();i++)
|
||||||
{
|
{
|
||||||
CSheetId sheetId;
|
CSheetId sheetId;
|
||||||
string str= listBrick[i];
|
string str= toLower(listBrick[i]);
|
||||||
strlwr(str);
|
|
||||||
if(str.find(".sbrick")==string::npos)
|
if(str.find(".sbrick")==string::npos)
|
||||||
str+= ".sbrick";
|
str+= ".sbrick";
|
||||||
sheetId.buildSheetId(str);
|
sheetId.buildSheetId(str);
|
||||||
|
|
|
@ -1326,7 +1326,7 @@ NLMISC_COMMAND(ah, "Launch an action handler", "<ActionHandler> <AHparam>")
|
||||||
if (args.size() == 0)
|
if (args.size() == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!ClientCfg.AllowDebugLua && strlwr(args[0]) == "lua")
|
if (!ClientCfg.AllowDebugLua && toLower(args[0]) == "lua")
|
||||||
{
|
{
|
||||||
return false; // not allowed!!
|
return false; // not allowed!!
|
||||||
}
|
}
|
||||||
|
@ -1883,7 +1883,7 @@ NLMISC_COMMAND(pos, "Change the position of the user (in local only)", "<x, y, (
|
||||||
if(args.size() == 1)
|
if(args.size() == 1)
|
||||||
{
|
{
|
||||||
string dest = args[0];
|
string dest = args[0];
|
||||||
newPos = CTeleport::getPos(NLMISC::strlwr(dest));
|
newPos = CTeleport::getPos(NLMISC::toLower(dest));
|
||||||
if(newPos == CTeleport::Unknown)
|
if(newPos == CTeleport::Unknown)
|
||||||
{
|
{
|
||||||
//here we try to teleport to a bot destination
|
//here we try to teleport to a bot destination
|
||||||
|
|
|
@ -3834,7 +3834,7 @@ void CSPhraseManager::computePhraseProgression()
|
||||||
pse.Text= STRING_MANAGER::CStringManagerClient::getSPhraseLocalizedName(CSheetId(pse.ProgressInfo.SheetId));
|
pse.Text= STRING_MANAGER::CStringManagerClient::getSPhraseLocalizedName(CSheetId(pse.ProgressInfo.SheetId));
|
||||||
// avoid mutliple sapce problem
|
// avoid mutliple sapce problem
|
||||||
strFindReplace(pse.Text, " ", "");
|
strFindReplace(pse.Text, " ", "");
|
||||||
// replace each number with 001 format. strlwr
|
// replace each number with 001 format. toLower
|
||||||
for(uint k=0;k<pse.Text.size();k++)
|
for(uint k=0;k<pse.Text.size();k++)
|
||||||
{
|
{
|
||||||
if(pse.Text[k] < 256 && isalpha(pse.Text[k]))
|
if(pse.Text[k] < 256 && isalpha(pse.Text[k]))
|
||||||
|
|
|
@ -48,16 +48,6 @@
|
||||||
#include "nel/misc/big_file.h"
|
#include "nel/misc/big_file.h"
|
||||||
#include "nel/misc/i18n.h"
|
#include "nel/misc/i18n.h"
|
||||||
|
|
||||||
#define RZ_USE_SEVENZIP 1
|
|
||||||
|
|
||||||
// 7 zip includes
|
|
||||||
#ifdef RZ_USE_SEVENZIP
|
|
||||||
#include "seven_zip/7zCrc.h"
|
|
||||||
#include "seven_zip/7zIn.h"
|
|
||||||
#include "seven_zip/7zExtract.h"
|
|
||||||
#include "seven_zip/LzmaDecode.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "game_share/bg_downloader_msg.h"
|
#include "game_share/bg_downloader_msg.h"
|
||||||
|
|
||||||
#include "login_patch.h"
|
#include "login_patch.h"
|
||||||
|
@ -116,57 +106,6 @@ struct EPatchDownloadException : public Exception
|
||||||
|
|
||||||
CPatchManager *CPatchManager::_Instance = NULL;
|
CPatchManager *CPatchManager::_Instance = NULL;
|
||||||
|
|
||||||
#ifdef RZ_USE_SEVENZIP
|
|
||||||
/// Input stream class for 7zip archive
|
|
||||||
class CNel7ZipInStream : public _ISzInStream
|
|
||||||
{
|
|
||||||
NLMISC::IStream *_Stream;
|
|
||||||
|
|
||||||
public:
|
|
||||||
/// Constructor, only allow file stream because 7zip will 'seek' in the stream
|
|
||||||
CNel7ZipInStream(NLMISC::IStream *s)
|
|
||||||
: _Stream(s)
|
|
||||||
{
|
|
||||||
Read = readFunc;
|
|
||||||
Seek = seekFunc;
|
|
||||||
}
|
|
||||||
|
|
||||||
// the read function called by 7zip to read data
|
|
||||||
static SZ_RESULT readFunc(void *object, void *buffer, size_t size, size_t *processedSize)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
CNel7ZipInStream *me = (CNel7ZipInStream*)object;
|
|
||||||
me->_Stream->serialBuffer((uint8*)buffer, (uint)size);
|
|
||||||
*processedSize = size;
|
|
||||||
return SZ_OK;
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
return SZE_FAIL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// the seek function called by seven zip to seek inside stream
|
|
||||||
static SZ_RESULT seekFunc(void *object, CFileSize pos)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
CNel7ZipInStream *me = (CNel7ZipInStream*)object;
|
|
||||||
bool ret= me->_Stream->seek(pos, NLMISC::IStream::begin);
|
|
||||||
if (ret)
|
|
||||||
return SZ_OK;
|
|
||||||
else
|
|
||||||
return SZE_FAIL;
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
return SZE_FAIL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static std::string ClientRootPath;
|
static std::string ClientRootPath;
|
||||||
|
|
||||||
// ****************************************************************************
|
// ****************************************************************************
|
||||||
|
@ -2192,164 +2131,6 @@ void CPatchManager::getCorruptedFileInfo(const SFileToPatch &ftp, ucstring &sTra
|
||||||
toString("%.1f ", (float)ftp.FinalFileSize/1000000.f) + CI18N::get("uiMb") + ")";
|
toString("%.1f ", (float)ftp.FinalFileSize/1000000.f) + CI18N::get("uiMb") + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CPatchManager::unpack7Zip(const std::string &sevenZipFile, const std::string &destFileName)
|
|
||||||
{
|
|
||||||
#ifdef RZ_USE_SEVENZIP
|
|
||||||
nlinfo("Uncompressing 7zip archive '%s' to '%s'", sevenZipFile.c_str(), destFileName.c_str());
|
|
||||||
|
|
||||||
// init seven zip
|
|
||||||
ISzAlloc allocImp;
|
|
||||||
ISzAlloc allocTempImp;
|
|
||||||
CArchiveDatabaseEx db;
|
|
||||||
|
|
||||||
allocImp.Alloc = SzAlloc;
|
|
||||||
allocImp.Free = SzFree;
|
|
||||||
|
|
||||||
allocTempImp.Alloc = SzAllocTemp;
|
|
||||||
allocTempImp.Free = SzFreeTemp;
|
|
||||||
|
|
||||||
InitCrcTable();
|
|
||||||
SzArDbExInit(&db);
|
|
||||||
|
|
||||||
// unpack the file using the 7zip API
|
|
||||||
|
|
||||||
CIFile input(sevenZipFile);
|
|
||||||
CNel7ZipInStream inStr(&input);
|
|
||||||
|
|
||||||
SZ_RESULT res = SzArchiveOpen(&inStr, &db, &allocImp, &allocTempImp);
|
|
||||||
if (res != SZ_OK)
|
|
||||||
{
|
|
||||||
nlerror("Failed to open archive file %s", sevenZipFile.c_str());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (db.Database.NumFiles != 1)
|
|
||||||
{
|
|
||||||
nlerror("Seven zip archive with more than 1 file are unsupported");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
UInt32 blockIndex = 0xFFFFFFFF; /* it can have any value before first call (if outBuffer = 0) */
|
|
||||||
Byte *outBuffer = 0; /* it must be 0 before first call for each new archive. */
|
|
||||||
size_t outBufferSize = 0; /* it can have any value before first call (if outBuffer = 0) */
|
|
||||||
|
|
||||||
size_t offset;
|
|
||||||
size_t outSizeProcessed = 0;
|
|
||||||
|
|
||||||
// get the first file
|
|
||||||
CFileItem *f = db.Database.Files;
|
|
||||||
res = SzExtract(&inStr, &db, 0,
|
|
||||||
&blockIndex, &outBuffer, &outBufferSize,
|
|
||||||
&offset, &outSizeProcessed,
|
|
||||||
&allocImp, &allocTempImp);
|
|
||||||
|
|
||||||
// write the extracted file
|
|
||||||
FILE *outputHandle;
|
|
||||||
UInt32 processedSize;
|
|
||||||
char *fileName = f->Name;
|
|
||||||
size_t nameLen = strlen(f->Name);
|
|
||||||
for (; nameLen > 0; nameLen--)
|
|
||||||
{
|
|
||||||
if (f->Name[nameLen - 1] == '/')
|
|
||||||
{
|
|
||||||
fileName = f->Name + nameLen;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
outputHandle = fopen(destFileName.c_str(), "wb+");
|
|
||||||
if (outputHandle == 0)
|
|
||||||
{
|
|
||||||
nlerror("Can not open output file '%s'", destFileName.c_str());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
processedSize = (UInt32)fwrite(outBuffer + offset, 1, outSizeProcessed, outputHandle);
|
|
||||||
if (processedSize != outSizeProcessed)
|
|
||||||
{
|
|
||||||
nlerror("Failed to write %u char to output file '%s'", outSizeProcessed-processedSize, destFileName.c_str());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
fclose(outputHandle);
|
|
||||||
allocImp.Free(outBuffer);
|
|
||||||
|
|
||||||
// free 7z context
|
|
||||||
SzArDbExFree(&db, allocImp.Free);
|
|
||||||
|
|
||||||
// ok, all is fine, file is unpacked
|
|
||||||
return true;
|
|
||||||
#else
|
|
||||||
return false;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CPatchManager::unpackLZMA(const std::string &lzmaFile, const std::string &destFileName)
|
|
||||||
{
|
|
||||||
#ifdef RZ_USE_SEVENZIP
|
|
||||||
nldebug("unpackLZMA : decompression the lzma file '%s' into output file '%s", lzmaFile.c_str(), destFileName.c_str());
|
|
||||||
CIFile inStream(lzmaFile);
|
|
||||||
uint32 inSize = inStream.getFileSize();
|
|
||||||
auto_ptr<uint8> inBuffer = auto_ptr<uint8>(new uint8[inSize]);
|
|
||||||
inStream.serialBuffer(inBuffer.get(), inSize);
|
|
||||||
|
|
||||||
CLzmaDecoderState state;
|
|
||||||
|
|
||||||
uint8 *pos = inBuffer.get();
|
|
||||||
// read the lzma properties
|
|
||||||
int ret = LzmaDecodeProperties(&state.Properties, (unsigned char*) pos, LZMA_PROPERTIES_SIZE);
|
|
||||||
if (ret != 0)
|
|
||||||
{
|
|
||||||
nlwarning("Failed to decode lzma properies in file '%s'!", lzmaFile.c_str());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inSize < LZMA_PROPERTIES_SIZE + 8)
|
|
||||||
{
|
|
||||||
nlwarning("Invalid file size, too small file '%s'", lzmaFile.c_str());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// alloc the probs, making sure they are deleted in function exit
|
|
||||||
size_t nbProb = LzmaGetNumProbs(&state.Properties);
|
|
||||||
auto_ptr<CProb> probs = auto_ptr<CProb>(new CProb[nbProb]);
|
|
||||||
state.Probs = probs.get();
|
|
||||||
|
|
||||||
pos += LZMA_PROPERTIES_SIZE;
|
|
||||||
|
|
||||||
// read the output file size
|
|
||||||
size_t fileSize = 0;
|
|
||||||
for (int i = 0; i < 8; i++)
|
|
||||||
{
|
|
||||||
//Byte b;
|
|
||||||
if (pos >= inBuffer.get()+inSize)
|
|
||||||
{
|
|
||||||
nlassert(false);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
fileSize |= ((UInt64)*pos++) << (8 * i);
|
|
||||||
}
|
|
||||||
|
|
||||||
SizeT outProcessed = 0;
|
|
||||||
SizeT inProcessed = 0;
|
|
||||||
// allocate the output buffer
|
|
||||||
auto_ptr<uint8> outBuffer = auto_ptr<uint8>(new uint8[fileSize]);
|
|
||||||
// decompress the file in memory
|
|
||||||
ret = LzmaDecode(&state, (unsigned char*) pos, (SizeT)(inSize-(pos-inBuffer.get())), &inProcessed, (unsigned char*)outBuffer.get(), (SizeT)fileSize, &outProcessed);
|
|
||||||
if (ret != 0 || outProcessed != fileSize)
|
|
||||||
{
|
|
||||||
nlwarning("Failed to decode lzma file '%s'", lzmaFile.c_str());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// store on output buffer
|
|
||||||
COFile outStream(destFileName);
|
|
||||||
outStream.serialBuffer(outBuffer.get(), (uint)fileSize);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
#else
|
|
||||||
return false;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// ****************************************************************************
|
// ****************************************************************************
|
||||||
// ****************************************************************************
|
// ****************************************************************************
|
||||||
|
|
482
code/ryzom/client/src/login_patch_seven_zip.cpp
Normal file
482
code/ryzom/client/src/login_patch_seven_zip.cpp
Normal file
|
@ -0,0 +1,482 @@
|
||||||
|
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
|
||||||
|
// Copyright (C) 2010 Winch Gate Property Limited
|
||||||
|
//
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as
|
||||||
|
// published by the Free Software Foundation, either version 3 of the
|
||||||
|
// License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
//
|
||||||
|
// Includes
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "stdpch.h"
|
||||||
|
#include "login_patch.h"
|
||||||
|
|
||||||
|
#define RZ_USE_SEVENZIP 1
|
||||||
|
//#define RZ_USE_NEW_LZMA
|
||||||
|
|
||||||
|
#ifdef RZ_USE_SEVENZIP
|
||||||
|
|
||||||
|
#ifdef RZ_USE_NEW_LZMA
|
||||||
|
|
||||||
|
#include "seven_zip/7z.h"
|
||||||
|
#include "seven_zip/7zAlloc.h"
|
||||||
|
#include "seven_zip/7zBuf.h"
|
||||||
|
#include "seven_zip/7zCrc.h"
|
||||||
|
#include "seven_zip/7zFile.h"
|
||||||
|
#include "seven_zip/7zVersion.h"
|
||||||
|
#include "seven_zip/LzmaDec.h"
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include "seven_zip/7zCrc.h"
|
||||||
|
#include "seven_zip/7zIn.h"
|
||||||
|
#include "seven_zip/7zExtract.h"
|
||||||
|
#include "seven_zip/LzmaDecode.h"
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//
|
||||||
|
// Namespaces
|
||||||
|
//
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace NLMISC;
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef RZ_USE_NEW_LZMA
|
||||||
|
|
||||||
|
/// Input stream class for 7zip archive
|
||||||
|
class CNel7ZipInStream : public ISeekInStream
|
||||||
|
{
|
||||||
|
NLMISC::IStream *_Stream;
|
||||||
|
|
||||||
|
public:
|
||||||
|
/// Constructor, only allow file stream because 7zip will 'seek' in the stream
|
||||||
|
CNel7ZipInStream(NLMISC::IStream *s)
|
||||||
|
: _Stream(s)
|
||||||
|
{
|
||||||
|
Read = readFunc;
|
||||||
|
Seek = seekFunc;
|
||||||
|
}
|
||||||
|
|
||||||
|
// the read function called by 7zip to read data
|
||||||
|
static SRes readFunc(void *object, void *buffer, size_t *size)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
CNel7ZipInStream *me = (CNel7ZipInStream*)object;
|
||||||
|
uint len = (uint)*size;
|
||||||
|
me->_Stream->serialBuffer((uint8*)buffer, len);
|
||||||
|
return SZ_OK;
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
return SZ_ERROR_READ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// the seek function called by seven zip to seek inside stream
|
||||||
|
static SRes seekFunc(void *object, Int64 *pos, ESzSeek origin)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
CNel7ZipInStream *me = (CNel7ZipInStream*)object;
|
||||||
|
sint32 offset = (sint32)*pos;
|
||||||
|
bool ret = me->_Stream->seek(offset, (NLMISC::IStream::TSeekOrigin)origin);
|
||||||
|
|
||||||
|
if (ret)
|
||||||
|
{
|
||||||
|
*pos = (Int64)me->_Stream->getPos();
|
||||||
|
return SZ_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
return SZ_ERROR_READ;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
/// Input stream class for 7zip archive
|
||||||
|
class CNel7ZipInStream : public _ISzInStream
|
||||||
|
{
|
||||||
|
NLMISC::IStream *_Stream;
|
||||||
|
|
||||||
|
public:
|
||||||
|
/// Constructor, only allow file stream because 7zip will 'seek' in the stream
|
||||||
|
CNel7ZipInStream(NLMISC::IStream *s)
|
||||||
|
: _Stream(s)
|
||||||
|
{
|
||||||
|
Read = readFunc;
|
||||||
|
Seek = seekFunc;
|
||||||
|
}
|
||||||
|
|
||||||
|
// the read function called by 7zip to read data
|
||||||
|
static SZ_RESULT readFunc(void *object, void *buffer, size_t size, size_t *processedSize)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
CNel7ZipInStream *me = (CNel7ZipInStream*)object;
|
||||||
|
me->_Stream->serialBuffer((uint8*)buffer, (uint)size);
|
||||||
|
*processedSize = size;
|
||||||
|
return SZ_OK;
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
return SZE_FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// the seek function called by seven zip to seek inside stream
|
||||||
|
static SZ_RESULT seekFunc(void *object, CFileSize pos)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
CNel7ZipInStream *me = (CNel7ZipInStream*)object;
|
||||||
|
bool ret= me->_Stream->seek(pos, NLMISC::IStream::begin);
|
||||||
|
if (ret)
|
||||||
|
return SZ_OK;
|
||||||
|
else
|
||||||
|
return SZE_FAIL;
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
return SZE_FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bool CPatchManager::unpack7Zip(const std::string &sevenZipFile, const std::string &destFileName)
|
||||||
|
{
|
||||||
|
#ifdef RZ_USE_SEVENZIP
|
||||||
|
nlinfo("Uncompressing 7zip archive '%s' to '%s'", sevenZipFile.c_str(), destFileName.c_str());
|
||||||
|
|
||||||
|
// init seven zip
|
||||||
|
ISzAlloc allocImp;
|
||||||
|
allocImp.Alloc = SzAlloc;
|
||||||
|
allocImp.Free = SzFree;
|
||||||
|
|
||||||
|
ISzAlloc allocTempImp;
|
||||||
|
allocTempImp.Alloc = SzAllocTemp;
|
||||||
|
allocTempImp.Free = SzFreeTemp;
|
||||||
|
|
||||||
|
// wrap file in a CIFile
|
||||||
|
CIFile input(sevenZipFile);
|
||||||
|
CNel7ZipInStream inStr(&input);
|
||||||
|
|
||||||
|
#ifdef RZ_USE_NEW_LZMA
|
||||||
|
|
||||||
|
CLookToRead lookStream;
|
||||||
|
lookStream.realStream = &inStr;
|
||||||
|
LookToRead_CreateVTable(&lookStream, False);
|
||||||
|
LookToRead_Init(&lookStream);
|
||||||
|
|
||||||
|
CrcGenerateTable();
|
||||||
|
|
||||||
|
CSzArEx db;
|
||||||
|
SzArEx_Init(&db);
|
||||||
|
|
||||||
|
// unpack the file using the 7zip API
|
||||||
|
SRes res = SzArEx_Open(&db, &lookStream.s, &allocImp, &allocTempImp);
|
||||||
|
|
||||||
|
if (res != SZ_OK)
|
||||||
|
{
|
||||||
|
nlerror("Failed to open archive file %s", sevenZipFile.c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (db.NumFiles != 1)
|
||||||
|
{
|
||||||
|
nlerror("Seven zip archive with more than 1 file are unsupported");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
UInt32 blockIndex = 0xFFFFFFFF; /* it can have any value before first call (if outBuffer = 0) */
|
||||||
|
Byte *outBuffer = 0; /* it must be 0 before first call for each new archive. */
|
||||||
|
size_t outBufferSize = 0; /* it can have any value before first call (if outBuffer = 0) */
|
||||||
|
|
||||||
|
size_t offset;
|
||||||
|
size_t outSizeProcessed = 0;
|
||||||
|
|
||||||
|
// get the first file
|
||||||
|
res = SzArEx_Extract(&db, &lookStream.s, 0,
|
||||||
|
&blockIndex, &outBuffer, &outBufferSize,
|
||||||
|
&offset, &outSizeProcessed,
|
||||||
|
&allocImp, &allocTempImp);
|
||||||
|
|
||||||
|
// get the length of first file
|
||||||
|
size_t nameLen = SzArEx_GetFileNameUtf16(&db, 0, NULL);
|
||||||
|
|
||||||
|
ucstring filename;
|
||||||
|
filename.resize(nameLen);
|
||||||
|
|
||||||
|
// write filename into ucstring
|
||||||
|
SzArEx_GetFileNameUtf16(&db, 0, &filename[0]);
|
||||||
|
|
||||||
|
// write the extracted file
|
||||||
|
FILE *outputHandle = fopen(destFileName.c_str(), "wb+");
|
||||||
|
|
||||||
|
if (outputHandle == 0)
|
||||||
|
{
|
||||||
|
nlerror("Can not open output file '%s'", destFileName.c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
UInt32 processedSize = (UInt32)fwrite(outBuffer + offset, 1, outSizeProcessed, outputHandle);
|
||||||
|
|
||||||
|
if (processedSize != outSizeProcessed)
|
||||||
|
{
|
||||||
|
nlerror("Failed to write %u char to output file '%s'", outSizeProcessed-processedSize, destFileName.c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(outputHandle);
|
||||||
|
|
||||||
|
IAlloc_Free(&allocImp, outBuffer);
|
||||||
|
|
||||||
|
// free 7z context
|
||||||
|
SzArEx_Free(&db, &allocImp);
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
InitCrcTable();
|
||||||
|
|
||||||
|
CArchiveDatabaseEx db;
|
||||||
|
SzArDbExInit(&db);
|
||||||
|
|
||||||
|
// unpack the file using the 7zip API
|
||||||
|
SZ_RESULT res = SzArchiveOpen(&inStr, &db, &allocImp, &allocTempImp);
|
||||||
|
|
||||||
|
if (res != SZ_OK)
|
||||||
|
{
|
||||||
|
nlerror("Failed to open archive file %s", sevenZipFile.c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (db.Database.NumFiles != 1)
|
||||||
|
{
|
||||||
|
nlerror("Seven zip archive with more than 1 file are unsupported");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
UInt32 blockIndex = 0xFFFFFFFF; /* it can have any value before first call (if outBuffer = 0) */
|
||||||
|
Byte *outBuffer = 0; /* it must be 0 before first call for each new archive. */
|
||||||
|
size_t outBufferSize = 0; /* it can have any value before first call (if outBuffer = 0) */
|
||||||
|
|
||||||
|
size_t offset;
|
||||||
|
size_t outSizeProcessed = 0;
|
||||||
|
|
||||||
|
// get the first file
|
||||||
|
CFileItem *f = db.Database.Files;
|
||||||
|
res = SzExtract(&inStr, &db, 0,
|
||||||
|
&blockIndex, &outBuffer, &outBufferSize,
|
||||||
|
&offset, &outSizeProcessed,
|
||||||
|
&allocImp, &allocTempImp);
|
||||||
|
|
||||||
|
// write the extracted file
|
||||||
|
FILE *outputHandle;
|
||||||
|
UInt32 processedSize;
|
||||||
|
char *fileName = f->Name;
|
||||||
|
size_t nameLen = strlen(f->Name);
|
||||||
|
for (; nameLen > 0; nameLen--)
|
||||||
|
{
|
||||||
|
if (f->Name[nameLen - 1] == '/')
|
||||||
|
{
|
||||||
|
fileName = f->Name + nameLen;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
outputHandle = fopen(destFileName.c_str(), "wb+");
|
||||||
|
|
||||||
|
if (outputHandle == 0)
|
||||||
|
{
|
||||||
|
nlerror("Can not open output file '%s'", destFileName.c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
processedSize = (UInt32)fwrite(outBuffer + offset, 1, outSizeProcessed, outputHandle);
|
||||||
|
|
||||||
|
if (processedSize != outSizeProcessed)
|
||||||
|
{
|
||||||
|
nlerror("Failed to write %u char to output file '%s'", outSizeProcessed-processedSize, destFileName.c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(outputHandle);
|
||||||
|
allocImp.Free(outBuffer);
|
||||||
|
|
||||||
|
// free 7z context
|
||||||
|
SzArDbExFree(&db, allocImp.Free);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ok, all is fine, file is unpacked
|
||||||
|
return true;
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CPatchManager::unpackLZMA(const std::string &lzmaFile, const std::string &destFileName)
|
||||||
|
{
|
||||||
|
#ifdef RZ_USE_SEVENZIP
|
||||||
|
nldebug("unpackLZMA : decompression the lzma file '%s' into output file '%s", lzmaFile.c_str(), destFileName.c_str());
|
||||||
|
|
||||||
|
CIFile inStream(lzmaFile);
|
||||||
|
uint32 inSize = inStream.getFileSize();
|
||||||
|
|
||||||
|
#ifdef RZ_USE_NEW_LZMA
|
||||||
|
|
||||||
|
if (inSize < LZMA_PROPS_SIZE + 8)
|
||||||
|
{
|
||||||
|
nlwarning("Invalid file size, too small file '%s'", lzmaFile.c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// read the compressed file in buffer
|
||||||
|
auto_ptr<uint8> inBuffer = auto_ptr<uint8>(new uint8[inSize]);
|
||||||
|
inStream.serialBuffer(inBuffer.get(), inSize);
|
||||||
|
|
||||||
|
uint8 *pos = inBuffer.get();
|
||||||
|
|
||||||
|
pos += LZMA_PROPS_SIZE;
|
||||||
|
|
||||||
|
// read the output file size
|
||||||
|
size_t fileSize = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < 8; ++i)
|
||||||
|
{
|
||||||
|
if (pos >= inBuffer.get()+inSize)
|
||||||
|
{
|
||||||
|
nlassert(false);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
fileSize |= ((UInt64)*pos++) << (8 * i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// allocators
|
||||||
|
ISzAlloc allocImp;
|
||||||
|
allocImp.Alloc = SzAlloc;
|
||||||
|
allocImp.Free = SzFree;
|
||||||
|
|
||||||
|
CLzmaDec state;
|
||||||
|
LzmaDec_Construct(&state);
|
||||||
|
|
||||||
|
// allocate and decode props and probs
|
||||||
|
SRes res = LzmaDec_Allocate(&state, inBuffer.get(), LZMA_PROPS_SIZE, &allocImp);
|
||||||
|
|
||||||
|
if (res != 0)
|
||||||
|
{
|
||||||
|
nlwarning("Failed to decode lzma properies in file '%s'!", lzmaFile.c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// allocate the output buffer
|
||||||
|
auto_ptr<uint8> outBuffer = auto_ptr<uint8>(new uint8[fileSize]);
|
||||||
|
|
||||||
|
// in and out file sizes
|
||||||
|
SizeT outProcessed = fileSize;
|
||||||
|
SizeT inProcessed = (SizeT)(inSize-(pos-inBuffer.get()));
|
||||||
|
|
||||||
|
LzmaDec_Init(&state);
|
||||||
|
|
||||||
|
// decompress the file in memory
|
||||||
|
ELzmaStatus status;
|
||||||
|
res = LzmaDec_DecodeToBuf(&state, (Byte*)outBuffer.get(), &outProcessed, (Byte*)pos, &inProcessed, LZMA_FINISH_ANY, &status);
|
||||||
|
|
||||||
|
// free memory
|
||||||
|
LzmaDec_Free(&state, &allocImp);
|
||||||
|
|
||||||
|
if (res != 0 || outProcessed != fileSize)
|
||||||
|
{
|
||||||
|
nlwarning("Failed to decode lzma file '%s' with status %d", lzmaFile.c_str(), (sint)status);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
auto_ptr<uint8> inBuffer = auto_ptr<uint8>(new uint8[inSize]);
|
||||||
|
inStream.serialBuffer(inBuffer.get(), inSize);
|
||||||
|
|
||||||
|
CLzmaDecoderState state;
|
||||||
|
|
||||||
|
uint8 *pos = inBuffer.get();
|
||||||
|
|
||||||
|
// read the lzma properties
|
||||||
|
int res = LzmaDecodeProperties(&state.Properties, (unsigned char*) pos, LZMA_PROPERTIES_SIZE);
|
||||||
|
if (res != 0)
|
||||||
|
{
|
||||||
|
nlwarning("Failed to decode lzma properies in file '%s'!", lzmaFile.c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inSize < LZMA_PROPERTIES_SIZE + 8)
|
||||||
|
{
|
||||||
|
nlwarning("Invalid file size, too small file '%s'", lzmaFile.c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// alloc the probs, making sure they are deleted in function exit
|
||||||
|
size_t nbProb = LzmaGetNumProbs(&state.Properties);
|
||||||
|
auto_ptr<CProb> probs = auto_ptr<CProb>(new CProb[nbProb]);
|
||||||
|
state.Probs = probs.get();
|
||||||
|
|
||||||
|
pos += LZMA_PROPERTIES_SIZE;
|
||||||
|
|
||||||
|
// read the output file size
|
||||||
|
size_t fileSize = 0;
|
||||||
|
for (int i = 0; i < 8; i++)
|
||||||
|
{
|
||||||
|
if (pos >= inBuffer.get()+inSize)
|
||||||
|
{
|
||||||
|
nlassert(false);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
fileSize |= ((UInt64)*pos++) << (8 * i);
|
||||||
|
}
|
||||||
|
|
||||||
|
SizeT outProcessed = 0;
|
||||||
|
SizeT inProcessed = 0;
|
||||||
|
|
||||||
|
// allocate the output buffer
|
||||||
|
auto_ptr<uint8> outBuffer = auto_ptr<uint8>(new uint8[fileSize]);
|
||||||
|
|
||||||
|
// decompress the file in memory
|
||||||
|
res = LzmaDecode(&state, (unsigned char*) pos, (SizeT)(inSize-(pos-inBuffer.get())), &inProcessed, (unsigned char*)outBuffer.get(), (SizeT)fileSize, &outProcessed);
|
||||||
|
|
||||||
|
if (res != 0 || outProcessed != fileSize)
|
||||||
|
{
|
||||||
|
nlwarning("Failed to decode lzma file '%s'", lzmaFile.c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// store on output buffer
|
||||||
|
COFile outStream(destFileName);
|
||||||
|
outStream.serialBuffer(outBuffer.get(), (uint)fileSize);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
|
@ -97,16 +97,14 @@ void CTeleport::load(const std::string &/* filename */)
|
||||||
string destName;
|
string destName;
|
||||||
if(tpElmt->getValueByName(destName, "name"))
|
if(tpElmt->getValueByName(destName, "name"))
|
||||||
{
|
{
|
||||||
// All in UPPER CASE to not be CASE SENSITIVE.
|
|
||||||
NLMISC::strlwr(destName);
|
|
||||||
|
|
||||||
// Get the position
|
// Get the position
|
||||||
CVector pos;
|
CVector pos;
|
||||||
if(tpElmt->getValueByName(pos.x, "position.X")
|
if(tpElmt->getValueByName(pos.x, "position.X")
|
||||||
&& tpElmt->getValueByName(pos.y, "position.Y")
|
&& tpElmt->getValueByName(pos.y, "position.Y")
|
||||||
&& tpElmt->getValueByName(pos.z, "position.Z"))
|
&& tpElmt->getValueByName(pos.z, "position.Z"))
|
||||||
{
|
{
|
||||||
_Destinations.insert(make_pair(destName, pos));
|
// All in UPPER CASE to not be CASE SENSITIVE.
|
||||||
|
_Destinations.insert(make_pair(NLMISC::toLower(destName), pos));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
nlwarning("CTeleport::load: Cannot find the one of the key 'position.X or Y or Z' for the element %d.", i);
|
nlwarning("CTeleport::load: Cannot find the one of the key 'position.X or Y or Z' for the element %d.", i);
|
||||||
|
|
Loading…
Reference in a new issue