From 9235ac60c19b2473dc8cb0cccb1884e8d79fc941 Mon Sep 17 00:00:00 2001 From: Zero Fanker Date: Thu, 11 Apr 2024 19:51:38 -0400 Subject: [PATCH] more adaption for x64 --- 3rdParty/xcc/misc/blowfish.cpp | 12 +- 3rdParty/xcc/misc/cc_structures.h | 15 +- 3rdParty/xcc/misc/mix_file.h | 2 +- 3rdParty/xcc/misc/shp_decode.cpp | 348 +++++++++--------- 3rdParty/xcc/misc/tmp_ts_file.h | 4 +- 3rdParty/xcc/misc/virtual_tfile.h | 2 +- MissionEditor.sln | 4 +- MissionEditor/IniFile.cpp | 6 +- MissionEditor/IniFile.h | 6 +- MissionEditor/InputBox.cpp | 23 +- MissionEditor/InputBox.h | 3 +- MissionEditor/MapData.cpp | 10 +- MissionEditor/PropertySheets/Debug.props | 2 +- MissionEditor/PropertySheets/Release.props | 2 +- MissionEditorPackLib/MissionEditorPackLib.cpp | 7 +- MissionEditorPackLib/MissionEditorPackLib.h | 2 +- 16 files changed, 214 insertions(+), 234 deletions(-) diff --git a/3rdParty/xcc/misc/blowfish.cpp b/3rdParty/xcc/misc/blowfish.cpp index 9e1833c..37f75e5 100644 --- a/3rdParty/xcc/misc/blowfish.cpp +++ b/3rdParty/xcc/misc/blowfish.cpp @@ -385,15 +385,9 @@ void Cblowfish::decipher(uint32_t& xl, uint32_t& xr) const static uint32_t reverse(uint32_t v) { - _asm - { - mov eax, v - xchg al, ah - rol eax, 16 - xchg al, ah - mov v, eax - } - return v; + uint32_t result = ((v & 0x00FF00FF) << 8) | ((v & 0xFF00FF00) >> 8); + result = (result << 16) | (result >> 16); + return result; } void Cblowfish::encipher(const void* s, void* d, int size) const diff --git a/3rdParty/xcc/misc/cc_structures.h b/3rdParty/xcc/misc/cc_structures.h index 2e93ff5..ff3ac5d 100644 --- a/3rdParty/xcc/misc/cc_structures.h +++ b/3rdParty/xcc/misc/cc_structures.h @@ -43,17 +43,12 @@ enum t_game const char* game_name[]; -inline __int32 reverse(__int32 v) + +static int32_t reverse(int32_t v) { - _asm - { - mov eax, v - xchg al, ah - rol eax, 16 - xchg al, ah - mov v, eax - } - return v; + uint32_t result = ((v & 0x00FF00FF) << 8) | ((v & 0xFF00FF00) >> 8); + result = (result << 16) | (result >> 16); + return result; } #pragma pack(push, 1) diff --git a/3rdParty/xcc/misc/mix_file.h b/3rdParty/xcc/misc/mix_file.h index fbf6681..cb11e7b 100644 --- a/3rdParty/xcc/misc/mix_file.h +++ b/3rdParty/xcc/misc/mix_file.h @@ -48,7 +48,7 @@ public: m_mix_expansion = true; } - int get_c_files() const + auto get_c_files() const { return m_index.size(); } diff --git a/3rdParty/xcc/misc/shp_decode.cpp b/3rdParty/xcc/misc/shp_decode.cpp index e78be75..fd1402d 100644 --- a/3rdParty/xcc/misc/shp_decode.cpp +++ b/3rdParty/xcc/misc/shp_decode.cpp @@ -377,45 +377,47 @@ static void write_v80(byte v, int count, byte*& d) } } +#include + void get_same(const byte* s, const byte* r, const byte* s_end, byte*& p, int& cb_p) { - _asm - { - push esi - push edi - mov eax, s_end - mov ebx, s - xor ecx, ecx - mov edi, p - mov [edi], ecx - dec ebx + const byte* s_end_ptr = s_end; + const byte* s_ptr = s; + int ecx_value = 0; + byte* edi_ptr = p; + *edi_ptr = static_cast(ecx_value); + s_ptr--; + next_s: - inc ebx - xor edx, edx - mov esi, r - mov edi, ebx - cmp edi, esi - jnb end0 + s_ptr++; + int edx_value = 0; + const byte* esi_ptr = r; + const byte* edi_val = s_ptr; + if (edi_val >= esi_ptr) + goto end0; + next0: - inc edx - cmp esi, eax - jnb end_line - cmpsb - je next0 + edx_value++; + if (esi_ptr >= s_end_ptr) + goto end_line; + + if (*esi_ptr == *s_ptr) + goto next0; + end_line: - dec edx - cmp edx, ecx - jl next_s - mov ecx, edx - mov edi, p - mov [edi], ebx - jmp next_s + edx_value--; + if (edx_value < ecx_value) + goto next_s; + + ecx_value = edx_value; + edi_ptr = p; + *edi_ptr = static_cast(*s_ptr); + goto next_s; + end0: - mov edi, cb_p - mov [edi], ecx - pop edi - pop esi - } + edi_ptr = reinterpret_cast(& cb_p); + *edi_ptr = ecx_value; + // Restore registers } static void write80_c0(byte*& w, int count, int p) @@ -617,162 +619,144 @@ int decode80c(const byte image_in[], byte image_out[], int cb_in) return (w - image_out); } -int decode80(const byte image_in[], byte image_out[]) +int __fastcall decode80(const byte image_in[], byte image_out[]) { - int cb_out; - /* - 0 copy 0cccpppp p - 1 copy 10cccccc - 2 copy 11cccccc p p - 3 fill 11111110 c c v - 4 copy 11111111 c c p p - */ - - _asm + byte* i; // edi + unsigned int v4; // eax + const byte* v5; // esi + unsigned int v6; // ecx + int v7; // eax + const byte* v8; // edx + byte* v9; // esi + unsigned int v10; // ecx + unsigned int v11; // eax + const byte* v12; // esi + unsigned int v13; // ecx + char v14; // al + + for (i = image_out; ; i += v10) { - push esi - push edi - mov ax, ds - mov es, ax - mov esi, image_in - mov edi, image_out -next0: - xor eax, eax - lodsb - mov ecx, eax - test eax, 0x80 - jnz c1c - shr ecx, 4 - add ecx, 3 - and eax, 0xf - shl eax, 8 - lodsb - mov edx, esi - mov esi, edi - sub esi, eax - jmp copy_from_destination -c1c: - and ecx, 0x3f - test eax, 0x40 - jnz c2c - or ecx, ecx - jz end0 - jmp copy_from_source -c2c: - xor eax, eax - lodsw - cmp ecx, 0x3e - je c3 - ja c4 - mov edx, esi - mov esi, image_out - add esi, eax - add ecx, 3 - jmp copy_from_destination -c3: - mov ecx, eax - lodsb - rep stosb - jmp next0 -c4: - mov ecx, eax - lodsw - mov edx, esi - mov esi, image_out - add esi, eax -copy_from_destination: - rep movsb - mov esi, edx - jmp next0 -copy_from_source: - rep movsb - jmp next0 -end0: - sub edi, image_out - mov cb_out, edi - pop edi - pop esi + while (1) + { + v4 = (unsigned __int8)*image_in; + v5 = image_in + 1; + if ((v4 & 0x80) == 0) + { + v6 = (v4 >> 4) + 3; + v7 = (v4 & 0xF) << 8; + v7 |= static_cast(*v5); + v8 = v5 + 1; + v9 = &i[-v7]; + goto copy_from_destination; + } + v10 = v4 & 0x3F; + if ((v4 & 0x40) == 0) + break; + v11 = *(unsigned __int16*)v5; + v12 = v5 + 2; + if (v10 == 62) + { + v13 = v11; + v14 = *v12; + image_in = v12 + 1; + memset(i, v14, v13); + i += v13; + } else + { + if (v10 > 0x3E) + { + v6 = v11; + v11 = *reinterpret_cast(v12); + v8 = v12 + 2; + v9 = &image_out[v11]; + } else + { + v8 = v12; + v9 = &image_out[v11]; + v6 = v10 + 3; + } + copy_from_destination: + memcpy(i, v9, v6); + i += v6; + image_in = v8; + } + } + if ((v4 & 0x3F) == 0) + break; + memcpy(i, v5, v10); + image_in = &v5[v10]; } - return cb_out; + return i - image_out; } -int decode80r(const byte image_in[], byte image_out[]) +int __fastcall decode80r(const byte image_in[], byte image_out[]) { - int cb_out; - /* - 0 copy 0cccpppp p - 1 copy 10cccccc - 2 copy 11cccccc p p - 3 fill 11111110 c c v - 4 copy 11111111 c c p p - */ - - _asm + byte* i; // edi + unsigned int v4; // eax + const byte* v5; // esi + unsigned int v6; // ecx + int v7; // eax + const byte* v8; // edx + byte* v9; // esi + unsigned int v10; // ecx + unsigned int v11; // eax + const byte* v12; // esi + unsigned int v13; // ecx + char v14; // al + + for (i = image_out; ; i += v10) { - push esi - push edi - mov ax, ds - mov es, ax - mov esi, image_in - mov edi, image_out -next0: - xor eax, eax - lodsb - mov ecx, eax - test eax, 0x80 - jnz c1c - shr ecx, 4 - add ecx, 3 - and eax, 0xf - shl eax, 8 - lodsb - mov edx, esi - mov esi, edi - sub esi, eax - jmp copy_from_destination -c1c: - and ecx, 0x3f - test eax, 0x40 - jnz c2c - or ecx, ecx - jz end0 - jmp copy_from_source -c2c: - xor eax, eax - lodsw - cmp ecx, 0x3e - je c3 - ja c4 - mov edx, esi - mov esi, edi - sub esi, eax - add ecx, 3 - jmp copy_from_destination -c3: - mov ecx, eax - lodsb - rep stosb - jmp next0 -c4: - mov ecx, eax - lodsw - mov edx, esi - mov esi, edi - sub esi, eax -copy_from_destination: - rep movsb - mov esi, edx - jmp next0 -copy_from_source: - rep movsb - jmp next0 -end0: - sub edi, image_out - mov cb_out, edi - pop edi - pop esi + while (1) + { + v4 = (unsigned __int8)*image_in; + v5 = image_in + 1; + if ((v4 & 0x80) == 0) + { + v6 = (v4 >> 4) + 3; + v7 = (v4 & 0xF) << 8; + v7 |= static_cast(*v5); + v8 = v5 + 1; + v9 = &i[-v7]; + goto copy_from_destination; + } + v10 = v4 & 0x3F; + if ((v4 & 0x40) == 0) + break; + v11 = *(unsigned __int16*)v5; + v12 = v5 + 2; + if (v10 == 62) + { + v13 = v11; + v14 = *v12; + image_in = v12 + 1; + memset(i, v14, v13); + i += v13; + } else + { + if (v10 > 0x3E) + { + v6 = v11; + v11 = *reinterpret_cast(v12); + v8 = v12 + 2; + v9 = &i[-v11]; + } else + { + v8 = v12; + v9 = &i[-v11]; + v6 = v10 + 3; + } + copy_from_destination: + memcpy(i, v9, v6); + i += v6; + image_in = v8; + } + } + if ((v4 & 0x3F) == 0) + break; + memcpy(i, v5, v10); + image_in = &v5[v10]; } - return cb_out; + return i - image_out; } int decode2(const byte* s, byte* d, int cb_s, const byte* reference_palet) @@ -1167,7 +1151,7 @@ int encode5(const byte* s, byte* d, int cb_s, int format) byte* w = d; while (r < r_end) { - int cb_section = min(r_end - r, 8192); + int cb_section = min(r_end - r, 8192); t_pack_section_header& header = *reinterpret_cast(w); w += sizeof(t_pack_section_header); w += header.size_in = format == 80 ? encode80(r, w, cb_section) : encode5s(r, w, cb_section); diff --git a/3rdParty/xcc/misc/tmp_ts_file.h b/3rdParty/xcc/misc/tmp_ts_file.h index b31f52b..8d6e702 100644 --- a/3rdParty/xcc/misc/tmp_ts_file.h +++ b/3rdParty/xcc/misc/tmp_ts_file.h @@ -183,8 +183,8 @@ public: const byte* get_z_image(int i) const { - int a = get_index()[i] + get_image_header(i)->z_ofs; - int b = get_image(i) + get_cb_diamond() - data(); + auto const a = get_index()[i] + get_image_header(i)->z_ofs; + auto const b = get_image(i) + get_cb_diamond() - data(); assert(a == b); return data() + get_index()[i] + get_image_header(i)->z_ofs; } diff --git a/3rdParty/xcc/misc/virtual_tfile.h b/3rdParty/xcc/misc/virtual_tfile.h index 418be44..812b5aa 100644 --- a/3rdParty/xcc/misc/virtual_tfile.h +++ b/3rdParty/xcc/misc/virtual_tfile.h @@ -32,7 +32,7 @@ private: return reinterpret_cast(m_data.data()); } - int size() const + auto size() const { return m_data.size(); } diff --git a/MissionEditor.sln b/MissionEditor.sln index 4b2facd..592d9e1 100644 --- a/MissionEditor.sln +++ b/MissionEditor.sln @@ -101,8 +101,8 @@ Global {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.Tests FinalAlertDebug YR|x64.Build.0 = Debug|x64 {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.FinalAlertDebug YR|Win32.ActiveCfg = DebugMinimal|Win32 {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.FinalAlertDebug YR|Win32.Build.0 = DebugMinimal|Win32 - {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.FinalAlertDebug YR|x64.ActiveCfg = Debug|x64 - {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.FinalAlertDebug YR|x64.Build.0 = Debug|x64 + {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.FinalAlertDebug YR|x64.ActiveCfg = DebugMinimal|x64 + {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.FinalAlertDebug YR|x64.Build.0 = DebugMinimal|x64 {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.FinalAlertDebug|Win32.ActiveCfg = DebugMinimal|Win32 {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.FinalAlertDebug|Win32.Build.0 = DebugMinimal|Win32 {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.FinalAlertDebug|x64.ActiveCfg = Debug|x64 diff --git a/MissionEditor/IniFile.cpp b/MissionEditor/IniFile.cpp index 5e29d25..8154b2d 100644 --- a/MissionEditor/IniFile.cpp +++ b/MissionEditor/IniFile.cpp @@ -217,9 +217,9 @@ BOOL CIniFile::SaveFile(const std::string& Filename) const } -int CIniFileSection::FindValue(CString val) const noexcept +int64_t CIniFileSection::FindValue(CString val) const noexcept { - for (auto idx = 0; + for (size_t idx = 0; idx < this->value_pairs.size(); ++idx) { if (this->value_pairs[idx].second == val) { @@ -229,7 +229,7 @@ int CIniFileSection::FindValue(CString val) const noexcept return -1; } -int CIniFileSection::FindIndex(const CString& key) const noexcept +int64_t CIniFileSection::FindIndex(const CString& key) const noexcept { auto const it = this->value_pos.find(key); if (it != this->value_pos.end()) { diff --git a/MissionEditor/IniFile.h b/MissionEditor/IniFile.h index d1f0bac..30f17a5 100644 --- a/MissionEditor/IniFile.h +++ b/MissionEditor/IniFile.h @@ -67,8 +67,8 @@ public: ASSERT(index < value_pairs.size()); return this->value_pairs[index]; } - int FindIndex(const CString& key) const noexcept; - int FindValue(CString val) const noexcept; + int64_t FindIndex(const CString& key) const noexcept; + int64_t FindValue(CString val) const noexcept; const CString& operator[](const CString& key) const { return this->GetString(key); @@ -203,7 +203,7 @@ public: } private: - map value_pos{}; + map value_pos{}; vector> value_pairs{};// sequenced mutable bool isRegistry{false}; }; diff --git a/MissionEditor/InputBox.cpp b/MissionEditor/InputBox.cpp index 6ebbf6c..44cd9ce 100644 --- a/MissionEditor/InputBox.cpp +++ b/MissionEditor/InputBox.cpp @@ -44,10 +44,11 @@ CString InputBox(const char* Sentence, const char* Caption) CInputBox inp; inp.SetCaption(Caption); inp.SetSentence(Sentence); - char* res=(char*) inp.DoModal(); - CString cstr=res; - - return cstr; + if (inp.DoModal()) { + return inp.GetResult(); + } + + return ""; } CInputBox::CInputBox(CWnd* pParent /*=NULL*/) @@ -75,22 +76,22 @@ END_MESSAGE_MAP() -void CInputBox::OnOK() +void CInputBox::OnOK() { CString text; GetDlgItem(IDC_VAL)->GetWindowText(text); - if(text.GetLength()==0){EndDialog(NULL);}; + if (text.GetLength() == 0) + EndDialog(false); - char* str; - str=new(char[text.GetLength()]); - strcpy(str, (LPCTSTR)text); - EndDialog((int)str); + m_Result = text; + + EndDialog(true); } void CInputBox::OnCancel() { - EndDialog(NULL); + EndDialog(false); } void CInputBox::SetCaption(CString Caption) diff --git a/MissionEditor/InputBox.h b/MissionEditor/InputBox.h index ddb6bb0..4612833 100644 --- a/MissionEditor/InputBox.h +++ b/MissionEditor/InputBox.h @@ -47,7 +47,7 @@ public: enum { IDD = IDD_INPUTBOX }; //}}AFX_DATA - + const CString& GetResult() const { return m_Result; } // Überschreibungen // Vom Klassen-Assistenten generierte virtuelle Funktionsüberschreibungen //{{AFX_VIRTUAL(CInputBox) @@ -68,6 +68,7 @@ protected: private: CString m_Text; CString m_Caption; + CString m_Result; }; //{{AFX_INSERT_LOCATION}} diff --git a/MissionEditor/MapData.cpp b/MissionEditor/MapData.cpp index 3b0ccf2..da1c130 100644 --- a/MissionEditor/MapData.cpp +++ b/MissionEditor/MapData.cpp @@ -278,7 +278,9 @@ void CMapData::CalcMapRect() m_maprect.right = atoi(custr); cucomma = strchr(&msize[cupos], ','); // we check again... could be there is a new ini format - if (cucomma == NULL) cucomma = (char*)((int)msize + strlen(msize)); + if (cucomma == NULL) { + cucomma = msize + strlen(msize); + } memcpy_s(custr, custr_size, &msize[cupos], (cucomma - msize) - cupos + 1); custr[((cucomma - msize)) - cupos] = 0; cupos = cucomma - msize + 1; @@ -321,7 +323,9 @@ void CMapData::CalcMapRect() cucomma = strchr(&msize[cupos], ','); // we check again... could be there is a new ini format - if (cucomma == NULL) cucomma = (char*)((int)msize + strlen(msize)); + if (cucomma == NULL) { + cucomma = msize + strlen(msize); + } memcpy_s(custr, custr_size, &msize[cupos], (cucomma - msize) - cupos + 1); custr[((cucomma - msize)) - cupos] = 0; cupos = cucomma - msize + 1; @@ -1092,7 +1096,7 @@ void CMapData::Pack(BOOL bCreatePreview, BOOL bCompression) BYTE* hexpacked = NULL; // must be freed! - errstream << "Values allocated. Pointer: " << (int)values << endl; + errstream << "Values allocated. Pointer: " << std::hex << values << endl; errstream.flush(); diff --git a/MissionEditor/PropertySheets/Debug.props b/MissionEditor/PropertySheets/Debug.props index fac5737..3f12aa6 100644 --- a/MissionEditor/PropertySheets/Debug.props +++ b/MissionEditor/PropertySheets/Debug.props @@ -4,7 +4,7 @@ - $(XccDir)\vcpkg_installed\x86-windows\x86-windows + $(XccDir)\vcpkg_installed\$(Platform)-windows\$(Platform)-windows $(XccVcpkgDirTriplet)\debug diff --git a/MissionEditor/PropertySheets/Release.props b/MissionEditor/PropertySheets/Release.props index 0e155dc..6f1c942 100644 --- a/MissionEditor/PropertySheets/Release.props +++ b/MissionEditor/PropertySheets/Release.props @@ -4,7 +4,7 @@ - $(XccDir)\vcpkg_installed\x86-windows\x86-windows + $(XccDir)\vcpkg_installed\$(Platform)-windows\$(Platform)-windows $(XccVcpkgDirTriplet) diff --git a/MissionEditorPackLib/MissionEditorPackLib.cpp b/MissionEditorPackLib/MissionEditorPackLib.cpp index 1c26174..c0ddd39 100644 --- a/MissionEditorPackLib/MissionEditorPackLib.cpp +++ b/MissionEditorPackLib/MissionEditorPackLib.cpp @@ -115,12 +115,13 @@ namespace FSunPackLib std::wstring utf8ToUtf16(const std::string& utf8) { // wstring_convert and codecvt_utf8_utf16 are deprecated in C++17, fallback to Win32 - if (utf8.size() == 0) + auto utf8Count = static_cast(utf8.size()); + if (utf8Count == 0) { // MultiByteToWideChar does not support passing in cbMultiByte == 0 return L""; + } // unterminatedCountWChars will be the count of WChars NOT including the terminating zero (due to passing in utf8.size() instead of -1) - auto utf8Count = utf8.size(); auto unterminatedCountWChars = MultiByteToWideChar(CP_UTF8, MB_PRECOMPOSED | MB_ERR_INVALID_CHARS, utf8.data(), utf8Count, nullptr, 0); if (unterminatedCountWChars == 0) { @@ -287,7 +288,7 @@ namespace FSunPackLib return true; } - int DecodeBase64(const char* sp, std::vector& dest) + size_t DecodeBase64(const char* sp, std::vector& dest) { auto len = strlen(reinterpret_cast(sp)); auto res = decode64(data_ref(sp, len)); diff --git a/MissionEditorPackLib/MissionEditorPackLib.h b/MissionEditorPackLib/MissionEditorPackLib.h index 0e7a50a..dac3524 100644 --- a/MissionEditorPackLib/MissionEditorPackLib.h +++ b/MissionEditorPackLib/MissionEditorPackLib.h @@ -109,7 +109,7 @@ sp - source poINTer dp - dest buffer (should be as large as sp) Returns the hex data length */ - int DecodeBase64(const char* sp, std::vector& dest); + size_t DecodeBase64(const char* sp, std::vector& dest); // format 80