summaryrefslogtreecommitdiff
path: root/aoe2hd/include/ModuleMemory.h
blob: 2fa258467a886da030deae32b1dc188fecd12981 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef PROCESSMEMORY_H
#define PROCESSMEMORY_H

#include <map>
#include <set>
#include <string>

extern "C" {
#include "native.h"
}


typedef struct target_ptr
{
    unsigned long base;
    unsigned long offset;
    unsigned long ptr;
    bool valid;
    std::string dependency;
    std::set<std::string> children;
} target_ptr;

class ModuleMemory
{
public:
    ModuleMemory(const native_data& nd);
    virtual ~ModuleMemory();
    unsigned long getPtr(const std::string& name);
    unsigned long getPtr(const std::string& name, unsigned long *dest_ptr);
    unsigned long getPtr(const std::string& name, unsigned long base, unsigned long offset);
    unsigned long recheckPtr(const std::string& name);
    void revalidateAllPtr();
    bool ptrSetDependency(const std::string& name, const std::string& dependency);
    bool getData(const std::string& name, void *buffer, unsigned long siz);
    std::string toString();
    std::string toStringStats();
private:
    const native_data& nd;
    std::map<std::string, target_ptr> ptr_map;
    unsigned long ptr_read_count;
    unsigned long ptr_invalid_count;
    bool ptrExists(const std::string& name)
    {
        return ptr_map.find(name) != ptr_map.end();
    }
    bool ptrValid(const std::string& name)
    {
        if (ptrExists(name) && ptr_map[name].valid)
        {
            return true;
        }
        else ++ptr_invalid_count;
        return false;
    }
};

#endif // PROCESSMEMORY_H