fnv_1a mmemoryproxy implementation

Newbie Spellweaver
Joined
Jun 7, 2023
Messages
95
Reaction score
69
how to speed up your gunz client

step 1
Code:
#pragma once

#include "MMath.h"
#include <unordered_map>

class MHashContainer
{
    std::unordered_map<void*, DWORD> m_mapHash;

public:
    inline void Add(void* key, DWORD hash)
    {
        m_mapHash[key] = hash;
    }

    inline void Remove(void* key)
    {
        m_mapHash.erase(key);
    }

    inline DWORD Get(void* key)
    {
        auto it = m_mapHash.find(key);
        if (it != m_mapHash.end())
            return it->second;
        return 0;
    }

    void Reserve(size_t capacity)
    {
        m_mapHash.reserve(capacity);
    }
};

extern void (*g_fpOnCrcFail)();
inline MHashContainer* GetHashContainer() noexcept
{
    static MHashContainer* s_instance = []() -> MHashContainer*
        {
            return new MHashContainer();
        }();
    return s_instance;
}

#define PTR_OFFSET 0x66D6

namespace FNV
{
    inline DWORD FNV1a(const BYTE* data, size_t len)
    {
        DWORD hash = 2166136261u;
        for (size_t i = 0; i < len; ++i)
        {
            hash ^= data[i];
            hash *= 16777619u;
        }
        return hash;
    }
}

template <typename T>
class MProtectValue
{
    T m_value;
    DWORD m_cachedHash;

private:
    inline DWORD BuildHash() const
    {
        return FNV::FNV1a((const BYTE*)&m_value, sizeof(T));
    }

public:
    MProtectValue() : m_value(), m_cachedHash(0) {}

    ~MProtectValue()
    {
        MHashContainer* hc = ::GetHashContainer();
        if (hc) {
            hc->Remove(this);
        }
    }

    inline T& Ref() { return m_value; }
    inline const T& Ref() const { return m_value; }

    inline void Set(const T& newVal)
    {
        m_value = newVal;
    }

    bool Set_CheckCrc(const T& newVal)
    {
        CheckCrc();
        m_value = newVal;
        MakeCrc();
        return true;
    }

    inline void Set_MakeCrc(const T& newVal)
    {
        m_value = newVal;
        MakeCrc();
    }

    inline void ShiftHeapPos()
    {
        MakeCrc();
    }

    inline void ShiftHeapPos_CheckCrc()
    {
        CheckCrc();
        MakeCrc();
    }

    inline void MakeCrc()
    {
        m_cachedHash = BuildHash();
        ::GetHashContainer()->Add(this, m_cachedHash);
    }

    inline void CheckCrc()
    {
        if (BuildHash() != m_cachedHash)
            g_fpOnCrcFail();
    }

private:
    MProtectValue(T val) : m_value(val), m_cachedHash(0) {}
    MProtectValue<T>& operator=(int) { return *this; }
};

#define MEMBER_SET_CHECKCRC(PROTECTVALUE, MEMBER, NEWVAL) { \
    PROTECTVALUE.CheckCrc(); \
    PROTECTVALUE.Ref().MEMBER = (NEWVAL); \
    PROTECTVALUE.MakeCrc(); \
}

Code:
#include "stdafx.h"
#include "MMemoryProxy.h"

void (*g_fpOnCrcFail)() = 0;

MHashContainer g_hashContainer;

step 2:
profit
 
I don't see it as a sure thing, but it might work for someone else.
 
I don't see it as a sure thing, but it might work for someone else.
^ is saying that using the old mmemoryproxy that gets shifted every frame wont benefit from using a faster algorithm that also calculates the hash less often
 
^ is saying that using the old mmemoryproxy that gets shifted every frame wont benefit from using a faster algorithm that also calculates the hash less often
You are free to use it if you wish; however, I personally wouldn't, as I have a considerably better alternative. Generally, these types of resources are shared when they are no longer useful, although they can serve as a reference for someone with experience to improve upon them or develop a more efficient solution.
 
You are free to use it if you wish; however, I personally wouldn't, as I have a considerably better alternative. Generally, these types of resources are shared when they are no longer useful, although they can serve as a reference for someone with experience to improve upon them or develop a more efficient solution.
If you have a faster version, why not share it? Ragezone is all about sharing source.
 
what a selfless guy that contributes to the community! this guy surely deserves to criticize others. oh and stop pretending youre not jork
I want to make it clear that I have no connection to you and no interest in associating with you. I don't know you, nor do I consider it necessary to get to know you, and I have no intention of becoming involved.

Regarding the concept of "community" that you mention, from my perspective, GunZ has never had a truly solid community. Trying to build one is valid, but it's not always successful, and in this case, I believe it hasn't been effective. In fact, certain attitudes within the community contribute to the game's lack of growth and positive evolution.

For that reason, I prefer to remain independent and not be part of what I consider a fictitious community with toxic tendencies, one that doesn't offer a clear or constructive direction.

With nothing further to add, I bid you farewell.

Consider this section a memorable demonstration; I don't usually repeat these kinds of interventions, especially when they yield such compelling results. Frankly, I no longer find this particularly entertaining.
 
I want to make it clear that I have no connection to you and no interest in associating with you. I don't know you, nor do I consider it necessary to get to know you, and I have no intention of becoming involved.

Regarding the concept of "community" that you mention, from my perspective, GunZ has never had a truly solid community. Trying to build one is valid, but it's not always successful, and in this case, I believe it hasn't been effective. In fact, certain attitudes within the community contribute to the game's lack of growth and positive evolution.

For that reason, I prefer to remain independent and not be part of what I consider a fictitious community with toxic tendencies, one that doesn't offer a clear or constructive direction.

With nothing further to add, I bid you farewell.

Consider this section a memorable demonstration; I don't usually repeat these kinds of interventions, especially when they yield such compelling results. Frankly, I no longer find this particularly entertaining.
what a great chatgpt essay!
 
Este es un sistema de protección que necesita actualizarse aún más porque, tal como está, puede causar errores; es simple, pero no es un acelerador.
 
That's interesting, but hey, it's the devil's community, everyone's at each other's throats :)
I don't waste my time arguing with NPCs or random weirdos I've never even seen before. I honestly don't know where these people come from.
 
I think you just missed the point, friend 😄. The problem isn’t making the hash faster, it’s avoiding recalculating the hash all the time. When I have time, I’ll show the solution and then contribute it to the community.
 
Back