about summary refs log tree commit diff stats
path: root/data/maps/four_rooms/rooms/Synonyms Room.txtpb
Commit message (Expand)AuthorAgeFilesLines
* Assigned IDs for four_roomsStar Rauchenberger2025-08-071-2/+2
* Added four_roomsStar Rauchenberger2025-08-071-0/+63
revision' href='/witness-tutorializer/blame/WitnessRandomizer/Memory.h?h=tutorial-v0.2.0&id=04a162151d63e73f11033a269de4155951db9751'>^
1f20774 ^
d5d5868 ^

922dbb0 ^
1f20774 ^
922dbb0 ^


d5d5868 ^
922dbb0 ^
4edd6ab ^
d5d5868 ^


922dbb0 ^

1f20774 ^
922dbb0 ^

d5d5868 ^
922dbb0 ^
d5d5868 ^
5fb764e ^
d5d5868 ^


1f20774 ^
2473736 ^
1d4763b ^
1f20774 ^

d5d5868 ^
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














                                                           


                                                        
                         
                                                                                   

                                      
                                         
                                                                                                                        


                                            
                 
                             
                          


                          

                                                                                     
                                                                                                                              

                                       
                 
                             
         
 


                          
                                                      
 
                                                          

                                   
 
#pragma once
#include <vector>
#include <map>
#include <windows.h>

// https://github.com/erayarslan/WriteProcessMemory-Example
// http://stackoverflow.com/q/32798185
// http://stackoverflow.com/q/36018838
// http://stackoverflow.com/q/1387064
class Memory
{
public:
	Memory(const std::string& processName);
	~Memory();

	Memory(const Memory& memory) = delete;
	Memory& operator=(const Memory& other) = delete;

	template<class T>
	std::vector<T> ReadData(const std::vector<int>& offsets, size_t numItems) {
		std::vector<T> data;
		data.resize(numItems);
		for (int i=0; i<5; i++) {
			if (ReadProcessMemory(_handle, ComputeOffset(offsets), &data[0], sizeof(T) * numItems, nullptr))
			{
				return data;
			}
		}
		ThrowError();
		return {};
	}

	template <class T>
	void WriteData(const std::vector<int>& offsets, const std::vector<T>& data) {
		for (int i=0; i<5; i++) {
			if (WriteProcessMemory(_handle, ComputeOffset(offsets), &data[0], sizeof(T) * data.size(), nullptr)) {
				return;
			}
		}
		ThrowError();
	}

private:
	void ThrowError();

	void* ComputeOffset(std::vector<int> offsets);

	std::map<uintptr_t, uintptr_t> _computedAddresses;
	uintptr_t _baseAddress = 0;
	HANDLE _handle = nullptr;
};