From 38a13868f0e1ed0673a78889363a654bd2226462 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Sun, 2 Jul 2017 03:18:38 -0700 Subject: [PATCH] Compile fixes, and initial asset name parser --- .gitmodules | 3 + CMakeLists.txt | 1 + Runtime/Character/CAnimTreeTimeScale.cpp | 6 +- Runtime/Character/CAnimTreeTimeScale.hpp | 4 +- .../Character/CConstantAnimationTimeScale.cpp | 19 - .../Character/CConstantAnimationTimeScale.hpp | 22 - .../Character/CLinearAnimationTimeScale.cpp | 0 .../Character/CLinearAnimationTimeScale.hpp | 31 -- Runtime/Character/CMakeLists.txt | 2 - Runtime/Character/CTimeScaleFunctions.cpp | 30 +- Runtime/Character/CTimeScaleFunctions.hpp | 26 +- Runtime/Graphics/IWeaponRenderer.hpp | 2 +- Runtime/Weapon/CGunController.cpp | 55 +++ Runtime/World/CStateMachine.hpp | 2 +- amuse | 2 +- assetnameparser/CMakeLists.txt | 15 + assetnameparser/main.cpp | 413 ++++++++++++++++++ assetnameparser/tinyxml2 | 1 + hecl | 2 +- mpcksum/CMakeLists.txt | 2 +- visigen/CMakeLists.txt | 2 +- 21 files changed, 528 insertions(+), 112 deletions(-) delete mode 100644 Runtime/Character/CConstantAnimationTimeScale.cpp delete mode 100644 Runtime/Character/CConstantAnimationTimeScale.hpp delete mode 100644 Runtime/Character/CLinearAnimationTimeScale.cpp delete mode 100644 Runtime/Character/CLinearAnimationTimeScale.hpp create mode 100644 assetnameparser/CMakeLists.txt create mode 100644 assetnameparser/main.cpp create mode 160000 assetnameparser/tinyxml2 diff --git a/.gitmodules b/.gitmodules index b4001e001..2e6ed468a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -16,3 +16,6 @@ [submodule "jbus"] path = jbus url = https://github.com/AxioDL/jbus.git +[submodule "assetnameparser/tinyxml2"] + path = assetnameparser/tinyxml2 + url = https://github.com/leethomason/tinyxml2.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 84b8215be..01fea35fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,6 +106,7 @@ add_subdirectory(amuse) add_subdirectory(specter) set(SPECTER_INCLUDE_DIR specter/include specter/freetype2/include) add_subdirectory(nod) +add_subdirectory(assetnameparser) set(NOD_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/nod/include) add_definitions(-DZE_ATHENA_TYPES=1) set(ZEUS_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/specter/zeus/include) diff --git a/Runtime/Character/CAnimTreeTimeScale.cpp b/Runtime/Character/CAnimTreeTimeScale.cpp index eed4f226a..a54c27a05 100644 --- a/Runtime/Character/CAnimTreeTimeScale.cpp +++ b/Runtime/Character/CAnimTreeTimeScale.cpp @@ -22,13 +22,13 @@ CCharAnimTime CAnimTreeTimeScale::GetRealLifeTime(const CCharAnimTime& time) con if (x28_ > CCharAnimTime()) { if (tmp < CCharAnimTime(x28_ * x20_)) - return x18_timeScale->TimeScaleIntegral(x20_, x20_ + tmp); + return x18_timeScale->VTimeScaleIntegral(x20_, x20_ + tmp); else { - CCharAnimTime integral = x18_timeScale->TimeScaleIntegral(x20_, x28_); + CCharAnimTime integral = x18_timeScale->VTimeScaleIntegral(x20_, x28_); if (integral > tmp) - return x18_timeScale->FindUpperLimit(x20_, tmp) * x20_; + return x18_timeScale->VFindUpperLimit(x20_, tmp) * x20_; else return integral + (integral * tmp); } diff --git a/Runtime/Character/CAnimTreeTimeScale.hpp b/Runtime/Character/CAnimTreeTimeScale.hpp index 17bba2f38..85d9134ff 100644 --- a/Runtime/Character/CAnimTreeTimeScale.hpp +++ b/Runtime/Character/CAnimTreeTimeScale.hpp @@ -2,14 +2,14 @@ #define __URDE_CANIMTREETIMESCALE_HPP__ #include "CAnimTreeSingleChild.hpp" -#include "CConstantAnimationTimeScale.hpp" +#include "CTimeScaleFunctions.hpp" namespace urde { class CAnimTreeTimeScale : public CAnimTreeSingleChild { - std::unique_ptr x18_timeScale; + std::shared_ptr x18_timeScale; CCharAnimTime x20_; CCharAnimTime x28_; public: diff --git a/Runtime/Character/CConstantAnimationTimeScale.cpp b/Runtime/Character/CConstantAnimationTimeScale.cpp deleted file mode 100644 index 1113e0475..000000000 --- a/Runtime/Character/CConstantAnimationTimeScale.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "CConstantAnimationTimeScale.hpp" - -namespace urde -{ - -float CConstantAnimationTimeScale::VTimeScaleIntegral(const float& a, const float& b) const { return (b - a) * x4_; } -float CConstantAnimationTimeScale::VFindUpperLimit(const float& a, const float& b) const { return (b / x4_) + a; } - -std::unique_ptr CConstantAnimationTimeScale::VClone() const -{ - return std::make_unique(x4_); -} - -std::unique_ptr CConstantAnimationTimeScale::VGetFunctionMirrored(const float&) const -{ - return Clone(); -} - -} diff --git a/Runtime/Character/CConstantAnimationTimeScale.hpp b/Runtime/Character/CConstantAnimationTimeScale.hpp deleted file mode 100644 index aacdaad22..000000000 --- a/Runtime/Character/CConstantAnimationTimeScale.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef __URDE_CONSTANTANIMATIONTIMESCALE_HPP__ -#define __URDE_CONSTANTANIMATIONTIMESCALE_HPP__ - -#include "IVaryingAnimationTimeScale.hpp" - -namespace urde -{ -class CConstantAnimationTimeScale : public IVaryingAnimationTimeScale -{ -private: - float x4_; -public: - CConstantAnimationTimeScale(float f) : x4_(f) {} - - u32 GetType() const { return 0; } - float VTimeScaleIntegral(const float &, const float &) const; - float VFindUpperLimit(const float &, const float &) const; - std::unique_ptr VClone() const; - std::unique_ptr VGetFunctionMirrored(const float &) const; -}; -} -#endif // __URDE_CONSTANTANIMATIONTIMESCALE_HPP__ diff --git a/Runtime/Character/CLinearAnimationTimeScale.cpp b/Runtime/Character/CLinearAnimationTimeScale.cpp deleted file mode 100644 index e69de29bb..000000000 diff --git a/Runtime/Character/CLinearAnimationTimeScale.hpp b/Runtime/Character/CLinearAnimationTimeScale.hpp deleted file mode 100644 index a11e8ae75..000000000 --- a/Runtime/Character/CLinearAnimationTimeScale.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef __URDE_CLINEARANIMATIONTIMESCALE_HPP__ -#define __URDE_CLINEARANIMATIONTIMESCALE_HPP__ - -#include "IVaryingAnimationTimeScale.hpp" - -namespace urde -{ -class CLinearAnimationTimeScale : public IVaryingAnimationTimeScale -{ -public: - class CFunctionDescription - { - public: - CFunctionDescription(const float&, const float&, const float&); - CFunctionDescription FunctionMirroredAround(const float&) const; - }; - -private: -public: - CLinearAnimationTimeScale(const CCharAnimTime&, float, const CCharAnimTime&, float); - u32 GetType() const { return 1; } - float VTimeScaleIntegral(const float &, const float &) const { return 0.f; } - float VFindUpperLimit(const float &, const float &) const { return 0.f; } - std::unique_ptr VClone() { return {}; } - std::unique_ptr VGetFunctionMirrored(const float &) const { return {}; } - float TimeScaleIntegralWithSortedLimits(const CFunctionDescription&, const float&, const float&); - float GetScale(const CFunctionDescription&, const float&); -}; -} - -#endif // __URDE_CLINEARANIMATIONTIMESCALE_HPP__ diff --git a/Runtime/Character/CMakeLists.txt b/Runtime/Character/CMakeLists.txt index e17cf8c8d..7cf69f732 100644 --- a/Runtime/Character/CMakeLists.txt +++ b/Runtime/Character/CMakeLists.txt @@ -8,8 +8,6 @@ set(CHARACTER_SOURCES IMetaAnim.hpp IMetaAnim.cpp IMetaTrans.hpp IVaryingAnimationTimeScale.hpp - CLinearAnimationTimeScale.hpp CLinearAnimationTimeScale.cpp - CConstantAnimationTimeScale.hpp CConstantAnimationTimeScale.cpp CAnimationDatabase.hpp CAnimationDatabaseGame.hpp CAnimationDatabaseGame.cpp CTransitionDatabase.hpp diff --git a/Runtime/Character/CTimeScaleFunctions.cpp b/Runtime/Character/CTimeScaleFunctions.cpp index 58544a592..47a3e1409 100644 --- a/Runtime/Character/CTimeScaleFunctions.cpp +++ b/Runtime/Character/CTimeScaleFunctions.cpp @@ -9,41 +9,39 @@ std::shared_ptr IVaryingAnimationTimeScale::Clone() return VClone(); } -void CConstantAnimationTimeScale::VTimeScaleIntegral(const float&, const float&) const -{ -} - -void CConstantAnimationTimeScale::VFindUpperLimit(const float&, const float&) const -{ -} +float CConstantAnimationTimeScale::VTimeScaleIntegral(const float& a, const float& b) const { return (b - a) * x4_; } +float CConstantAnimationTimeScale::VFindUpperLimit(const float& a, const float& b) const { return (b / x4_) + a; } std::shared_ptr CConstantAnimationTimeScale::VClone() const { - return {}; + CConstantAnimationTimeScale* ret = new CConstantAnimationTimeScale(x4_); + return std::shared_ptr(ret); } -std::shared_ptr -CConstantAnimationTimeScale::VGetFunctionMirrored(const float&) const +std::shared_ptr CConstantAnimationTimeScale::VGetFunctionMirrored(const float&) const { - return {}; + return Clone(); } - -void CLinearAnimationTimeScale::VTimeScaleIntegral(const float&, const float&) const +float CLinearAnimationTimeScale::VTimeScaleIntegral(const float&, const float&) const { + return 0.f; } -void CLinearAnimationTimeScale::TimeScaleIntegralWithSortedLimits(const CFunctionDescription& desc, +float CLinearAnimationTimeScale::TimeScaleIntegralWithSortedLimits(const CFunctionDescription& desc, const float&, const float&) { + return 0.f; } -void CLinearAnimationTimeScale::VFindUpperLimit(const float&, const float&) const +float CLinearAnimationTimeScale::VFindUpperLimit(const float&, const float&) const { + return 0.f; } -void CLinearAnimationTimeScale::FindUpperLimitFromRoot(const CFunctionDescription& desc, +float CLinearAnimationTimeScale::FindUpperLimitFromRoot(const CFunctionDescription& desc, const float&, const float&) { + return 0.f; } std::shared_ptr CLinearAnimationTimeScale::VClone() const diff --git a/Runtime/Character/CTimeScaleFunctions.hpp b/Runtime/Character/CTimeScaleFunctions.hpp index 78036f3e6..c1e5dba0e 100644 --- a/Runtime/Character/CTimeScaleFunctions.hpp +++ b/Runtime/Character/CTimeScaleFunctions.hpp @@ -17,21 +17,25 @@ class IVaryingAnimationTimeScale public: virtual ~IVaryingAnimationTimeScale() = default; virtual EVaryingAnimationTimeScaleType GetType() const=0; - virtual void VTimeScaleIntegral(const float&, const float&) const=0; - virtual void VFindUpperLimit(const float&, const float&) const=0; + virtual float VTimeScaleIntegral(const float&, const float&) const=0; + virtual float VFindUpperLimit(const float&, const float&) const=0; virtual std::shared_ptr VClone() const=0; virtual std::shared_ptr VGetFunctionMirrored(const float&) const=0; std::shared_ptr Clone() const; }; -class CConstantAnimationTimeScale : public IVaryingAnimationTimeScale +class CConstantAnimationTimeScale : public IVaryingAnimationTimeScale { +private: + float x4_; public: - EVaryingAnimationTimeScaleType GetType() const {return EVaryingAnimationTimeScaleType::Constant;} - void VTimeScaleIntegral(const float&, const float&) const; - void VFindUpperLimit(const float&, const float&) const; + CConstantAnimationTimeScale(float f) : x4_(f) {} + + EVaryingAnimationTimeScaleType GetType() const { return EVaryingAnimationTimeScaleType::Constant; } + float VTimeScaleIntegral(const float &, const float &) const; + float VFindUpperLimit(const float &, const float &) const; std::shared_ptr VClone() const; - std::shared_ptr VGetFunctionMirrored(const float&) const; + std::shared_ptr VGetFunctionMirrored(const float &) const; }; class CLinearAnimationTimeScale : public IVaryingAnimationTimeScale @@ -46,10 +50,10 @@ public: }; EVaryingAnimationTimeScaleType GetType() const {return EVaryingAnimationTimeScaleType::Linear;} - void VTimeScaleIntegral(const float&, const float&) const; - void TimeScaleIntegralWithSortedLimits(const CFunctionDescription& desc, const float&, const float&); - void VFindUpperLimit(const float&, const float&) const; - void FindUpperLimitFromRoot(const CFunctionDescription& desc, const float&, const float&); + float VTimeScaleIntegral(const float&, const float&) const; + float TimeScaleIntegralWithSortedLimits(const CFunctionDescription& desc, const float&, const float&); + float VFindUpperLimit(const float&, const float&) const; + float FindUpperLimitFromRoot(const CFunctionDescription& desc, const float&, const float&); std::shared_ptr VClone() const; std::shared_ptr VGetFunctionMirrored(const float&) const; }; diff --git a/Runtime/Graphics/IWeaponRenderer.hpp b/Runtime/Graphics/IWeaponRenderer.hpp index 3f414ef4a..c3fd7c879 100644 --- a/Runtime/Graphics/IWeaponRenderer.hpp +++ b/Runtime/Graphics/IWeaponRenderer.hpp @@ -9,7 +9,7 @@ class IWeaponRenderer { public: virtual ~IWeaponRenderer() = default; - virtual void AddParticleGen(const CParticleGen&); + virtual void AddParticleGen(const CParticleGen&)=0; }; class CDefaultWeaponRenderer : public IWeaponRenderer diff --git a/Runtime/Weapon/CGunController.cpp b/Runtime/Weapon/CGunController.cpp index fd7ebcb24..e811c93e9 100644 --- a/Runtime/Weapon/CGunController.cpp +++ b/Runtime/Weapon/CGunController.cpp @@ -6,6 +6,56 @@ namespace urde { +void CGunController::UnLoadFidget() +{ + +} + +void CGunController::LoadFidgetAnimAsync(CStateManager &, s32, s32, s32) +{ + +} + +void CGunController::GetFreeLookSetId() const +{ + +} + +bool CGunController::IsFidgetLoaded() const +{ + return false; +} + +bool CGunController::IsComboOver() const +{ + return true; +} + +void CGunController::EnterFreeLook(CStateManager &, s32, s32) +{ + +} + +void CGunController::EnterComboFire(CStateManager &, s32) +{ + +} + +void CGunController::EnterFidget(CStateManager &, s32, s32, s32) +{ + +} + +void CGunController::EnterStruck(CStateManager &, float) +{ + +} + +void CGunController::EnterIdle(CStateManager &) +{ + +} + bool CGunController::Update(float dt, CStateManager& mgr) { CAnimData& animData = *x0_modelData.AnimationData(); @@ -51,6 +101,11 @@ bool CGunController::Update(float dt, CStateManager& mgr) return true; } +void CGunController::ReturnToDefault(CStateManager &, float) +{ + +} + void CGunController::ReturnToBasePosition(CStateManager& mgr, float) { const CPASDatabase& pasDatabase = x0_modelData.AnimationData()->GetCharacterInfo().GetPASDatabase(); diff --git a/Runtime/World/CStateMachine.hpp b/Runtime/World/CStateMachine.hpp index 008d44fa7..d1c3fda30 100644 --- a/Runtime/World/CStateMachine.hpp +++ b/Runtime/World/CStateMachine.hpp @@ -51,7 +51,7 @@ public: s32 GetNumTriggers() const; CAiTrigger& GetTrig(s32) const; - const char* GetName() const; + const char* GetName() const { return x4_name; } void SetTriggers(CAiTrigger* triggers); void SetNumTriggers(s32 numTriggers) { x2c_numTriggers = numTriggers; } void CallFunc(CStateManager& mgr, CAi& ai, EStateMsg msg, float delta) const diff --git a/amuse b/amuse index 4e7c31849..0bace131e 160000 --- a/amuse +++ b/amuse @@ -1 +1 @@ -Subproject commit 4e7c31849d5c9e1e274fa86fc74d3cbecf9e11de +Subproject commit 0bace131e877b24f29924b7d6887100e81461b48 diff --git a/assetnameparser/CMakeLists.txt b/assetnameparser/CMakeLists.txt new file mode 100644 index 000000000..10ab0e31c --- /dev/null +++ b/assetnameparser/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR) # because of CMAKE_CXX_STANDARD +add_subdirectory(tinyxml2) +add_executable(assetnameparser "main.cpp") +include_directories(${LOGVISOR_INCLUDE_DIR}) + +set(AN_PARSER_LIBS "") +if (UNIX) + list(APPEND AN_PARSER_LIBS pthread) + if(UNIX AND ${CMAKE_SYSTEM_NAME} MATCHES "Linux") + list(APPEND AN_PARSER_LIBS dl) + endif() +endif() + + +target_link_libraries(assetnameparser tinyxml2 logvisor ${AN_PARSER_LIBS}) diff --git a/assetnameparser/main.cpp b/assetnameparser/main.cpp new file mode 100644 index 000000000..401ac208c --- /dev/null +++ b/assetnameparser/main.cpp @@ -0,0 +1,413 @@ +#include +#include +#include +#include "tinyxml2/tinyxml2.h" +#include "logvisor/logvisor.hpp" + +#ifndef _WIN32 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#else +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN 1 +#endif +#ifndef NOMINMAX +#define NOMINMAX +#endif +#include +#include +#include "winsupport.hpp" +#if UNICODE +#define IS_UCS2 1 +#endif +#endif + + +static logvisor::Module Log("AssetNameParser"); +// TODO: Clean this up +#undef bswap16 +#undef bswap32 +#undef bswap64 + +/* Type-sensitive byte swappers */ +template +static inline T bswap16(T val) +{ +#if __GNUC__ + return __builtin_bswap16(val); +#elif _WIN32 + return _byteswap_ushort(val); +#else + return (val = (val << 8) | ((val >> 8) & 0xFF)); +#endif +} + +template +static inline T bswap32(T val) +{ +#if __GNUC__ + return __builtin_bswap32(val); +#elif _WIN32 + return _byteswap_ulong(val); +#else + val = (val & 0x0000FFFF) << 16 | (val & 0xFFFF0000) >> 16; + val = (val & 0x00FF00FF) << 8 | (val & 0xFF00FF00) >> 8; + return val; +#endif +} + +template +static inline T bswap64(T val) +{ +#if __GNUC__ + return __builtin_bswap64(val); +#elif _WIN32 + return _byteswap_uint64(val); +#else + return ((val & 0xFF00000000000000ULL) >> 56) | + ((val & 0x00FF000000000000ULL) >> 40) | + ((val & 0x0000FF0000000000ULL) >> 24) | + ((val & 0x000000FF00000000ULL) >> 8) | + ((val & 0x00000000FF000000ULL) << 8) | + ((val & 0x0000000000FF0000ULL) << 24) | + ((val & 0x000000000000FF00ULL) << 40) | + ((val & 0x00000000000000FFULL) << 56); +#endif +} + + +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +static inline int16_t SBig(int16_t val) {return bswap16(val);} +static inline uint16_t SBig(uint16_t val) {return bswap16(val);} +static inline int32_t SBig(int32_t val) {return bswap32(val);} +static inline uint32_t SBig(uint32_t val) {return bswap32(val);} +static inline int64_t SBig(int64_t val) {return bswap64(val);} +static inline uint64_t SBig(uint64_t val) {return bswap64(val);} +static inline float SBig(float val) +{ + int32_t ival = bswap32(*((int32_t*)(&val))); + return *((float*)(&ival)); +} +static inline double SBig(double val) +{ + int64_t ival = bswap64(*((int64_t*)(&val))); + return *((double*)(&ival)); +} +#ifndef SBIG +#define SBIG(q) ( ( (q) & 0x000000FF ) << 24 | ( (q) & 0x0000FF00 ) << 8 \ + | ( (q) & 0x00FF0000 ) >> 8 | ( (q) & 0xFF000000 ) >> 24 ) +#endif + +static inline int16_t SLittle(int16_t val) {return val;} +static inline uint16_t SLittle(uint16_t val) {return val;} +static inline int32_t SLittle(int32_t val) {return val;} +static inline uint32_t SLittle(uint32_t val) {return val;} +static inline int64_t SLittle(int64_t val) {return val;} +static inline uint64_t SLittle(uint64_t val) {return val;} +static inline float SLittle(float val) {return val;} +static inline double SLittle(double val) {return val;} +#ifndef SLITTLE +#define SLITTLE(q) (q) +#endif +#else +static inline int16_t SLittle(int16_t val) {return bswap16(val);} +static inline uint16_t SLittle(uint16_t val) {return bswap16(val);} +static inline int32_t SLittle(int32_t val) {return bswap32(val);} +static inline uint32_t SLittle(uint32_t val) {return bswap32(val);} +static inline int64_t SLittle(int64_t val) {return bswap64(val);} +static inline uint64_t SLittle(uint64_t val) {return bswap64(val);} +static inline float SLittle(float val) +{ + int32_t ival = bswap32(*((int32_t*)(&val))); + return *((float*)(&ival)); +} +static inline double SLittle(double val) +{ + int64_t ival = bswap64(*((int64_t*)(&val))); + return *((double*)(&ival)); +} +#ifndef SLITTLE +#define SLITTLE(q) ( ( (q) & 0x000000FF ) << 24 | ( (q) & 0x0000FF00 ) << 8 \ + | ( (q) & 0x00FF0000 ) >> 8 | ( (q) & 0xFF000000 ) >> 24 ) +#endif + +static inline int16_t SBig(int16_t val) {return val;} +static inline uint16_t SBig(uint16_t val) {return val;} +static inline int32_t SBig(int32_t val) {return val;} +static inline uint32_t SBig(uint32_t val) {return val;} +static inline int64_t SBig(int64_t val) {return val;} +static inline uint64_t SBig(uint64_t val) {return val;} +static inline float SBig(float val) {return val;} +static inline double SBig(double val) {return val;} +#ifndef SBIG +#define SBIG(q) (q) +#endif +#endif + +class FourCC +{ +protected: + union + { + char fcc[4]; + uint32_t num; + }; +public: + FourCC() /* Sentinel FourCC */ + : num(0) {} + FourCC(const FourCC& other) + {num = other.num;} + FourCC(const char* name) + : num(*(uint32_t*)name) {} + FourCC(uint32_t n) + : num(n) {} + bool operator==(const FourCC& other) const {return num == other.num;} + bool operator!=(const FourCC& other) const {return num != other.num;} + bool operator==(const char* other) const {return num == *(uint32_t*)other;} + bool operator!=(const char* other) const {return num != *(uint32_t*)other;} + bool operator==(int32_t other) const { return num == other;} + bool operator!=(int32_t other) const { return num != other;} + bool operator==(uint32_t other) const {return num == other;} + bool operator!=(uint32_t other) const {return num != other;} + std::string toString() const {return std::string(fcc, 4);} + uint32_t toUint32() const {return num;} + operator uint32_t() const {return num;} +}; + +struct SAsset +{ + FourCC type; + uint64_t id; + std::string name; + std::string dir; +}; + +enum class FileLockType +{ + None = 0, + Read, + Write +}; + +#if IS_UCS2 +typedef wchar_t SystemChar; +static inline size_t StrLen(const SystemChar* str) { return wcslen(str); } +typedef std::wstring SystemString; +static inline void ToLower(SystemString& str) { std::transform(str.begin(), str.end(), str.begin(), towlower); } +static inline void ToUpper(SystemString& str) { std::transform(str.begin(), str.end(), str.begin(), towupper); } +class SystemUTF8View +{ + std::string m_utf8; + +public: + explicit SystemUTF8View(const SystemString& str) : m_utf8(WideToUTF8(str)) {} + operator const std::string&() const { return m_utf8; } + const std::string& str() const { return m_utf8; } + const char* c_str() const { return m_utf8.c_str(); } + std::string operator+(const std::string& other) const { return m_utf8 + other; } + std::string operator+(const char* other) const { return m_utf8 + other; } +}; +inline std::string operator+(const std::string& lhs, const SystemUTF8View& rhs) { return lhs + std::string(rhs); } +inline std::string operator+(const char* lhs, const SystemUTF8View& rhs) { return lhs + std::string(rhs); } +class SystemStringView +{ + std::wstring m_sys; + +public: + explicit SystemStringView(const std::string& str) : m_sys(UTF8ToWide(str)) {} + operator const std::wstring&() const { return m_sys; } + const std::wstring& sys_str() const { return m_sys; } + const SystemChar* c_str() const { return m_sys.c_str(); } + std::wstring operator+(const std::wstring& other) const { return m_sys + other; } + std::wstring operator+(const wchar_t* other) const { return m_sys + other; } +}; +inline std::wstring operator+(const std::wstring& lhs, const SystemStringView& rhs) { return lhs + std::wstring(rhs); } +inline std::wstring operator+(const wchar_t* lhs, const SystemStringView& rhs) { return lhs + std::wstring(rhs); } +#ifndef _S +#define _S(val) L##val +#endif +typedef struct _stat Sstat; +#else +typedef char SystemChar; +static inline size_t StrLen(const SystemChar* str) { return strlen(str); } +typedef std::string SystemString; +class SystemUTF8View +{ + const std::string& m_utf8; + +public: + explicit SystemUTF8View(const SystemString& str) : m_utf8(str) {} + operator const std::string&() const { return m_utf8; } + const std::string& str() const { return m_utf8; } + const char* c_str() const { return m_utf8.c_str(); } + std::string operator+(const std::string& other) const { return std::string(m_utf8) + other; } + std::string operator+(const char* other) const { return std::string(m_utf8) + other; } +}; +inline std::string operator+(const std::string& lhs, const SystemUTF8View& rhs) { return lhs + std::string(rhs); } +inline std::string operator+(const char* lhs, const SystemUTF8View& rhs) { return lhs + std::string(rhs); } +class SystemStringView +{ + const std::string& m_sys; + +public: + explicit SystemStringView(const std::string& str) : m_sys(str) {} + operator const std::string&() const { return m_sys; } + const std::string& sys_str() const { return m_sys; } + const SystemChar* c_str() const { return m_sys.c_str(); } + std::string operator+(const std::string& other) const { return m_sys + other; } + std::string operator+(const char* other) const { return m_sys + other; } +}; +inline std::string operator+(const std::string& lhs, const SystemStringView& rhs) { return lhs + std::string(rhs); } +inline std::string operator+(const char* lhs, const SystemStringView& rhs) { return lhs + std::string(rhs); } +#ifndef _S +#define _S(val) val +#endif +typedef struct stat Sstat; +#endif + +static inline int StrCmp(const SystemChar* str1, const SystemChar* str2) +{ +#if IS_UCS2 + return wcscmp(str1, str2); +#else + return strcmp(str1, str2); +#endif +} + +static inline FILE* Fopen(const SystemChar* path, const SystemChar* mode, FileLockType lock = FileLockType::None) +{ +#if IS_UCS2 + FILE* fp = _wfopen(path, mode); + if (!fp) + return nullptr; +#else + FILE* fp = fopen(path, mode); + if (!fp) + return nullptr; +#endif + + if (lock != FileLockType::None) + { +#if _WIN32 + OVERLAPPED ov = {}; + LockFileEx((HANDLE)(uintptr_t)_fileno(fp), (lock == FileLockType::Write) ? LOCKFILE_EXCLUSIVE_LOCK : 0, 0, 0, 1, + &ov); +#else + if (flock(fileno(fp), ((lock == FileLockType::Write) ? LOCK_EX : LOCK_SH) | LOCK_NB)) + fprintf(stderr, "flock %s: %s", path, strerror(errno)); +#endif + } + + return fp; +} + + +#if _WIN32 +int wmain(int argc, const wchar_t* argv[]) +#else +int main(int argc, const char* argv[]) +#endif +{ + logvisor::RegisterStandardExceptions(); + logvisor::RegisterConsoleLogger(); + if (argc < 3) + { + Log.report(logvisor::Error, _S("Usage: %s "), argv[0]); + return 1; + } + + SystemString inPath = argv[1]; + SystemString outPath = argv[2]; + + tinyxml2::XMLDocument doc; + std::vector assets; + FILE* docF = Fopen(inPath.c_str(), _S("rb")); + if (!doc.LoadFile(docF)) + { + const tinyxml2::XMLElement* elm = doc.RootElement(); + if (strcmp(elm->Name(), "AssetNameMap")) + { + Log.report(logvisor::Fatal, _S("Invalid database supplied")); + return 1; + } + + elm = elm->FirstChildElement("AssetNameMap"); + if (elm == nullptr) + { + Log.report(logvisor::Fatal, _S("Malformed AssetName database")); + return 1; + } + + elm = elm->FirstChildElement("Asset"); + + while (elm) + { + const tinyxml2::XMLElement* keyElm = elm->FirstChildElement("Key"); + const tinyxml2::XMLElement* valueElm = elm->FirstChildElement("Value"); + + if (!keyElm || !valueElm) + { + Log.report(logvisor::Fatal, _S("Malformed Asset entry, [Key,Value] required")); + return 0; + } + + const tinyxml2::XMLElement* nameElm = valueElm->FirstChildElement("Name"); + const tinyxml2::XMLElement* dirElm = valueElm->FirstChildElement("Directory"); + const tinyxml2::XMLElement* typeElm = valueElm->FirstChildElement("Type"); + + if (!nameElm || !dirElm || ! typeElm) + { + Log.report(logvisor::Fatal, _S("Malformed Value entry, [Name,Directory,Type] required")); + return 0; + } + assets.emplace_back(); + SAsset& asset = assets.back(); + asset.type = typeElm->GetText(); + asset.id = strtoull(keyElm->GetText(), nullptr, 16); + asset.name = nameElm->GetText(); + asset.dir = dirElm->GetText(); + elm = elm->NextSiblingElement("Asset"); + } + + FILE* f = Fopen(outPath.c_str(), _S("wb")); + if (!f) + { + Log.report(logvisor::Fatal, _S("Unable to open destination")); + return 0; + } + + uint32_t assetCount = SBig(uint32_t(assets.size())); + FourCC sentinel(SBIG('AIDM')); + fwrite(&sentinel, 1, 4, f); + fwrite(&assetCount, 1, 4, f); + for (const SAsset& asset : assets) + { + fwrite(&asset.type, 1, 4, f); + uint64_t id = SBig(asset.id); + fwrite(&id, 1, 8, f); + uint32_t tmp = SBig(uint32_t(asset.name.length())); + fwrite(&tmp, 1, 4, f); + fwrite(asset.name.c_str(), 1, SBig(tmp), f); + tmp = SBig(uint32_t(asset.dir.length())); + fwrite(&tmp, 1, 4, f); + fwrite(asset.dir.c_str(), 1, SBig(tmp), f); + } + fflush(f); + fclose(f); + fclose(docF); + return 0; + } + + if (docF) + fclose(docF); + + Log.report(logvisor::Fatal, _S("failed to load")); + return 1; +} diff --git a/assetnameparser/tinyxml2 b/assetnameparser/tinyxml2 new file mode 160000 index 000000000..c1f1de724 --- /dev/null +++ b/assetnameparser/tinyxml2 @@ -0,0 +1 @@ +Subproject commit c1f1de724f5b1b82dca54c9ce6cc3ba130243949 diff --git a/hecl b/hecl index da67582f2..4a3865ec8 160000 --- a/hecl +++ b/hecl @@ -1 +1 @@ -Subproject commit da67582f23559060c842c7daa75bec31efbc816f +Subproject commit 4a3865ec8abe1e2c92dd2d4b70e0cb5039efdf38 diff --git a/mpcksum/CMakeLists.txt b/mpcksum/CMakeLists.txt index 652450238..cc7120f97 100644 --- a/mpcksum/CMakeLists.txt +++ b/mpcksum/CMakeLists.txt @@ -4,4 +4,4 @@ add_executable(mpcksum main.cpp) target_link_libraries(mpcksum - athena-core z lzo2) + athena-core athena-libyaml z lzo2) diff --git a/visigen/CMakeLists.txt b/visigen/CMakeLists.txt index 24c3be161..e38ca1a81 100644 --- a/visigen/CMakeLists.txt +++ b/visigen/CMakeLists.txt @@ -23,7 +23,7 @@ endif() add_executable(visigen ${PLAT_SRCS} VISIRenderer.cpp VISIRenderer.hpp VISIBuilder.cpp VISIBuilder.hpp) -target_link_libraries(visigen logvisor athena-core zeus glew xxhash ${BOO_SYS_LIBS}) +target_link_libraries(visigen logvisor athena-core athena-libyaml zeus glew xxhash ${ZLIB_LIBRARIES} ${LZO_LIB} ${BOO_SYS_LIBS}) add_custom_command(TARGET visigen POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $ $)