File: MemoryWatcher.h

package info (click to toggle)
dolphin-emu 5.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 29,052 kB
  • sloc: cpp: 213,146; java: 6,252; asm: 2,277; xml: 1,998; ansic: 1,514; python: 462; sh: 279; pascal: 247; makefile: 124; perl: 97
file content (47 lines) | stat: -rw-r--r-- 1,356 bytes parent folder | download | duplicates (2)
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
// Copyright 2015 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#pragma once

#include <map>
#include <vector>
#include <sys/socket.h>
#include <sys/un.h>

// MemoryWatcher reads a file containing in-game memory addresses and outputs
// changes to those memory addresses to a unix domain socket as the game runs.
//
// The input file is a newline-separated list of hex memory addresses, without
// the "0x". To follow pointers, separate addresses with a space. For example,
// "ABCD EF" will watch the address at (*0xABCD) + 0xEF.
// The output to the socket is two lines. The first is the address from the
// input file, and the second is the new value in hex.
class MemoryWatcher final
{
public:
	MemoryWatcher();
	~MemoryWatcher();
	void Step();

	static void Init();
	static void Shutdown();

private:
	bool LoadAddresses(const std::string& path);
	bool OpenSocket(const std::string& path);

	void ParseLine(const std::string& line);
	u32 ChasePointer(const std::string& line);
	std::string ComposeMessage(const std::string& line, u32 value);

	bool m_running;

	int m_fd;
	sockaddr_un m_addr;

	// Address as stored in the file -> list of offsets to follow
	std::map<std::string, std::vector<u32>> m_addresses;
	// Address as stored in the file -> current value
	std::map<std::string, u32> m_values;
};