fix(hasher): USE OPENSSL

This commit is contained in:
Mohamed Ashraf 2026-03-02 23:52:30 +04:00
parent a7a1ceed39
commit 2e34f54ba7
3 changed files with 30 additions and 4 deletions

View file

@ -1,6 +1,12 @@
#include "stdafx.h" #include "stdafx.h"
#if defined(_WIN32)
#include <xhash> #include <xhash>
#else
#include <openssl/md5.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#endif // _WIN32
#include "Hasher.h" #include "Hasher.h"
Hasher::Hasher(wstring &salt) Hasher::Hasher(wstring &salt)
@ -10,6 +16,7 @@ Hasher::Hasher(wstring &salt)
wstring Hasher::getHash(wstring &name) wstring Hasher::getHash(wstring &name)
{ {
#if defined(_WIN32)
// 4J Stu - Removed try/catch // 4J Stu - Removed try/catch
//try { //try {
wstring s = wstring( salt ).append( name ); wstring s = wstring( salt ).append( name );
@ -25,4 +32,21 @@ wstring Hasher::getHash(wstring &name)
//{ //{
// throw new RuntimeException(e); // throw new RuntimeException(e);
//} //}
#else
// adapted from a SSL example
std::wstring combined = salt + name;
std::string combined_str(combined.begin(), combined.end());
unsigned char result[MD5_DIGEST_LENGTH];
MD5_CTX md5_ctx;
MD5_Init(&md5_ctx);
MD5_Update(&md5_ctx, combined_str.c_str(), combined_str.size());
MD5_Final(result, &md5_ctx);
std::stringstream ss;
for (int i = 0; i < MD5_DIGEST_LENGTH; i++)
{
ss << std::setw(2) << std::setfill('0') << std::hex << (int)result[i];
}
std::string hash_str = ss.str();
return std::wstring(hash_str.begin(), hash_str.end());
#endif
} }

View file

@ -4,6 +4,7 @@
#include "net.minecraft.world.food.h" #include "net.minecraft.world.food.h"
#include "net.minecraft.world.effect.h" #include "net.minecraft.world.effect.h"
#include "SharedConstants.h" #include "SharedConstants.h"
#include "../Minecraft.Client/Windows64Media/strings.h"
MobEffect *MobEffect::effects[NUM_EFFECTS]; MobEffect *MobEffect::effects[NUM_EFFECTS];

View file

@ -1,5 +1,6 @@
#include "stdafx.h" #include "stdafx.h"
#include "net.minecraft.world.effect.h" #include "net.minecraft.world.effect.h"
#include "../Minecraft.Client/Windows64/Windows64_App.h"
void MobEffectInstance::_init(int id, int duration, int amplifier) void MobEffectInstance::_init(int id, int duration, int amplifier)
{ {