more adaption for x64

This commit is contained in:
Zero Fanker 2024-04-11 19:51:38 -04:00
parent 3e334ca731
commit 9235ac60c1
16 changed files with 214 additions and 234 deletions

View file

@ -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

View file

@ -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)

View file

@ -48,7 +48,7 @@ public:
m_mix_expansion = true;
}
int get_c_files() const
auto get_c_files() const
{
return m_index.size();
}

View file

@ -377,45 +377,47 @@ static void write_v80(byte v, int count, byte*& d)
}
}
#include <cstdint>
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<byte>(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<byte>(*s_ptr);
goto next_s;
end0:
mov edi, cb_p
mov [edi], ecx
pop edi
pop esi
}
edi_ptr = reinterpret_cast<byte*>(& 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<unsigned char>(*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<const int16_t*>(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<unsigned char>(*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<const int16_t*>(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<size_t>(r_end - r, 8192);
t_pack_section_header& header = *reinterpret_cast<t_pack_section_header*>(w);
w += sizeof(t_pack_section_header);
w += header.size_in = format == 80 ? encode80(r, w, cb_section) : encode5s(r, w, cb_section);

View file

@ -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;
}

View file

@ -32,7 +32,7 @@ private:
return reinterpret_cast<const char*>(m_data.data());
}
int size() const
auto size() const
{
return m_data.size();
}

View file

@ -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

View file

@ -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()) {

View file

@ -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<CString, int, SortDummy> value_pos{};
map<CString, int64_t, SortDummy> value_pos{};
vector<std::pair<CString, CString>> value_pairs{};// sequenced
mutable bool isRegistry{false};
};

View file

@ -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)

View file

@ -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}}

View file

@ -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();

View file

@ -4,7 +4,7 @@
<Import Project="$(MSBuildThisFileDirectory)/Common.props" />
</ImportGroup>
<PropertyGroup>
<XccVcpkgDirTriplet>$(XccDir)\vcpkg_installed\x86-windows\x86-windows</XccVcpkgDirTriplet>
<XccVcpkgDirTriplet>$(XccDir)\vcpkg_installed\$(Platform)-windows\$(Platform)-windows</XccVcpkgDirTriplet>
<XccVcpkgDir>$(XccVcpkgDirTriplet)\debug</XccVcpkgDir>
</PropertyGroup>
<PropertyGroup Label="UserMacros" />

View file

@ -4,7 +4,7 @@
<Import Project="$(MSBuildThisFileDirectory)/Common.props" />
</ImportGroup>
<PropertyGroup>
<XccVcpkgDirTriplet>$(XccDir)\vcpkg_installed\x86-windows\x86-windows</XccVcpkgDirTriplet>
<XccVcpkgDirTriplet>$(XccDir)\vcpkg_installed\$(Platform)-windows\$(Platform)-windows</XccVcpkgDirTriplet>
<XccVcpkgDir>$(XccVcpkgDirTriplet)</XccVcpkgDir>
</PropertyGroup>
<PropertyGroup Label="UserMacros" />

View file

@ -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<int>(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<BYTE>& dest)
size_t DecodeBase64(const char* sp, std::vector<BYTE>& dest)
{
auto len = strlen(reinterpret_cast<const char*>(sp));
auto res = decode64(data_ref(sp, len));

View file

@ -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<BYTE>& dest);
size_t DecodeBase64(const char* sp, std::vector<BYTE>& dest);
// format 80