From 51ee5feb78d470cb8aa9d3a3cf7aafdca3add12f Mon Sep 17 00:00:00 2001 From: mq1n Date: Mon, 22 Sep 2025 11:25:58 +0300 Subject: [PATCH 1/3] fixed some crashes --- src/EffectLib/EffectElementBaseInstance.cpp | 8 ++++++++ src/EterBase/lzo.cpp | 16 ++++------------ src/EterLib/GrpObjectInstance.cpp | 14 ++++++++++++-- src/EterLib/IME.cpp | 3 ++- src/UserInterface/PythonSkill.cpp | 2 +- 5 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/EffectLib/EffectElementBaseInstance.cpp b/src/EffectLib/EffectElementBaseInstance.cpp index 80f64aa..2e42266 100644 --- a/src/EffectLib/EffectElementBaseInstance.cpp +++ b/src/EffectLib/EffectElementBaseInstance.cpp @@ -90,6 +90,14 @@ void CEffectElementBaseInstance::Destroy() } CEffectElementBaseInstance::CEffectElementBaseInstance() + : mc_pmatLocal(nullptr) + , m_isActive(false) + , m_fLocalTime(0.0f) + , m_dwStartTime(0) + , m_fElapsedTime(0.0f) + , m_fRemainingTime(0.0f) + , m_bStart(false) + , m_pBase(nullptr) { } CEffectElementBaseInstance::~CEffectElementBaseInstance() diff --git a/src/EterBase/lzo.cpp b/src/EterBase/lzo.cpp index 2cbb903..2b7454a 100644 --- a/src/EterBase/lzo.cpp +++ b/src/EterBase/lzo.cpp @@ -216,22 +216,14 @@ public: public: DecryptBuffer(unsigned size) { - static unsigned count = 0; - static unsigned sum = 0; - static unsigned maxSize = 0; - - sum += size; - count++; - - maxSize = std::max(size, maxSize); if (size >= LOCAL_BUF_SIZE) { m_buf = new char[size]; - dbg_printf("DecryptBuffer - AllocHeap %d max(%d) ave(%d)\n", size, maxSize/1024, sum/count); + dbg_printf("DecryptBuffer - AllocHeap %d\n", size); } else { - dbg_printf("DecryptBuffer - AllocStack %d max(%d) ave(%d)\n", size, maxSize/1024, sum/count); + dbg_printf("DecryptBuffer - AllocStack %d\n", size); m_buf = m_local_buf; } } @@ -239,12 +231,12 @@ public: { if (m_local_buf != m_buf) { - dbg_printf("DecruptBuffer - FreeHeap\n"); + dbg_printf("DecryptBuffer - FreeHeap\n"); delete [] m_buf; } else { - dbg_printf("DecruptBuffer - FreeStack\n"); + dbg_printf("DecryptBuffer - FreeStack\n"); } } void* GetBufferPtr() diff --git a/src/EterLib/GrpObjectInstance.cpp b/src/EterLib/GrpObjectInstance.cpp index 65af030..6e9ba11 100644 --- a/src/EterLib/GrpObjectInstance.cpp +++ b/src/EterLib/GrpObjectInstance.cpp @@ -20,7 +20,7 @@ void CGraphicObjectInstance::Clear() m_isVisible = TRUE; m_v3Position.x = m_v3Position.y = m_v3Position.z = 0.0f; - m_v3Scale.x = m_v3Scale.y = m_v3Scale.z = 0.0f; + m_v3Scale.x = m_v3Scale.y = m_v3Scale.z = 1.0f; //m_fRotation = 0.0f; m_fYaw = m_fPitch = m_fRoll = 0.0f; D3DXMatrixIdentity(&m_worldMatrix); @@ -278,12 +278,22 @@ void CGraphicObjectInstance::Initialize() m_BlockCamera = false; m_v3Position.x = m_v3Position.y = m_v3Position.z = 0.0f; - m_v3Scale.x = m_v3Scale.y = m_v3Scale.z = 0.0f; + m_v3Scale.x = m_v3Scale.y = m_v3Scale.z = 1.0f; m_fYaw = m_fPitch = m_fRoll = 0.0f; D3DXMatrixIdentity(&m_worldMatrix); D3DXMatrixIdentity(&m_mRotation); + m_v3TBBoxMin = D3DXVECTOR3(0.0f, 0.0f, 0.0f); + m_v3TBBoxMax = D3DXVECTOR3(0.0f, 0.0f, 0.0f); + m_v3BBoxMin = D3DXVECTOR3(0.0f, 0.0f, 0.0f); + m_v3BBoxMax = D3DXVECTOR3(0.0f, 0.0f, 0.0f); + + for (int i = 0; i < 8; ++i) + m_v4TBBox[i] = D3DXVECTOR4(0.0f, 0.0f, 0.0f, 0.0f); + + memset(m_abyPortalID, 0, sizeof(m_abyPortalID)); + ClearCollision(); OnInitialize(); } diff --git a/src/EterLib/IME.cpp b/src/EterLib/IME.cpp index 781564b..57e0f8c 100644 --- a/src/EterLib/IME.cpp +++ b/src/EterLib/IME.cpp @@ -830,7 +830,8 @@ void CIME::DelCurPos() if (ms_curpos < ms_lastpos) { int eraseCount = FindColorTagEndPosition(m_wText + ms_curpos, ms_lastpos - ms_curpos) + 1; - wcscpy(m_wText + ms_curpos, m_wText + ms_curpos + eraseCount); + size_t remainingChars = ms_lastpos - ms_curpos - eraseCount + 1; // +1 for null terminator + wmemmove(m_wText + ms_curpos, m_wText + ms_curpos + eraseCount, remainingChars); // wcscpy > wmemmove to handle overlapping memory ms_lastpos -= eraseCount; ms_curpos = std::min(ms_lastpos, ms_curpos); } diff --git a/src/UserInterface/PythonSkill.cpp b/src/UserInterface/PythonSkill.cpp index 3e4ad98..b5d2eb2 100644 --- a/src/UserInterface/PythonSkill.cpp +++ b/src/UserInterface/PythonSkill.cpp @@ -71,7 +71,7 @@ void string_replace_word(const char* base, int base_len, const char* src, int sr int cur = 0; while (cur < base_len) { - if (memcmp(base + cur, src, src_len) == 0) + if (cur + src_len <= base_len && memcmp(base + cur, src, src_len) == 0) { result.append(base + prev, cur - prev); result.append(dst, dst_len); From acaaf6fc91eb968110ef42fbfff6e27c21949aad Mon Sep 17 00:00:00 2001 From: mq1n Date: Mon, 22 Sep 2025 11:27:05 +0300 Subject: [PATCH 2/3] ASan support added --- CMakeLists.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2732f64..8002fae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,9 @@ project(m2dev-client-src) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) +# ASan support +option(ENABLE_ASAN "Enable AddressSanitizer" OFF) + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/buildtool" @@ -28,6 +31,19 @@ add_compile_options( $<$:/wd4996> ) +# ASan flags +if(ENABLE_ASAN) + if(MSVC) + add_compile_options(/fsanitize=address) + add_link_options(/fsanitize=address) + add_definitions(-D_DISABLE_VECTOR_ANNOTATION) + add_definitions(-D_DISABLE_STRING_ANNOTATION) + else() + add_compile_options(-fsanitize=address -fno-omit-frame-pointer) + add_link_options(-fsanitize=address) + endif() +endif() + add_definitions(-DNOMINMAX) add_definitions(-DWIN32_LEAN_AND_MEAN) add_definitions(-D_CRT_SECURE_NO_WARNINGS) From 082d8fb3a63e5af327735fbda35296611490d985 Mon Sep 17 00:00:00 2001 From: mq1n Date: Mon, 22 Sep 2025 12:32:03 +0300 Subject: [PATCH 3/3] GitHub actions workflow added --- .github/workflows/main.yml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..dfd6770 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,35 @@ +name: build + +on: + push: + branches: + - main + +jobs: + win: + name: "Windows Build" + runs-on: windows-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Build project + id: build_project + shell: pwsh + working-directory: ${{ github.workspace }} + run: | + mkdir build + cd build + cmake .. + cmake --build . --config RelWithDebInfo + + - name: Collect outputs + run: | + mkdir _output + cp build/bin/* _output + + - name: Upload + uses: actions/upload-artifact@v4 + with: + name: output_win + path: _output