C++ Button and Textbox

Hey I'm new here and I need help with something.
I need help putting a pointer, address, and offset into a button. The button will do action whatever is in the textbox. For example:
I have 100 health in a game. I put 1000 in the textbox and click the button to make it 1000.
Okay so, so far I already have the pointer, address, and offset in the button, but how do I make it so when I input text in the textbox, it activates when I click the button?
Last edited on
What are you writing your game in? What libraries are you using? What do you mean by activating the textbox?
I just explained it above...
"I have 100 health in a game. I put 1000 in the textbox and click the button to make it 1000."
This is my code.
MyForm.h
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#pragma once
#include <Windows.h>

namespace CppWinForm {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for MyForm
	/// </summary>
	public ref class MyForm : public System::Windows::Forms::Form
	{
	public:
		MyForm(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~MyForm()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Button^  button1;
	protected:

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->SuspendLayout();
			// 
			// button1
			// 
			this->button1->Location = System::Drawing::Point(0, 0);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(75, 23);
			this->button1->TabIndex = 0;
			this->button1->Text = L"button1";
			this->button1->UseVisualStyleBackColor = true;
			this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
			// 
			// MyForm
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(284, 262);
			this->Controls->Add(this->button1);
			this->Name = L"MyForm";
			this->Text = L"MyForm";
			this->ResumeLayout(false);

		}
#pragma endregion
	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
		*(DWORD*)(
		*(DWORD*)((int)GetModuleHandle + 0x7AA7F0)
			+ 0x55a8) = 999;
	}
	};
}

MyForm.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "MyForm.h"

using namespace System;
using namespace System::Windows::Forms;
using namespace CppWinForm;

[STAThreadAttribute]

void ShowForm() {
	Application::EnableVisualStyles();
	Application::SetCompatibleTextRenderingDefault(false);
	Application::Run(gcnew MyForm());
}

[STAThread]
void Main(array<String^>^ args)
{
	Application::EnableVisualStyles();
	Application::SetCompatibleTextRenderingDefault(false);

	CppWinForm::MyForm form;
	Application::Run(%form);
}

dllmain.cpp
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
// dllmain.cpp : Defines the entry point for the DLL application.

#include <windows.h>
extern void ShowForm();

void WINAPI MainX()
{
	ShowForm();
}

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
		DisableThreadLibraryCalls(hModule);
		CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)MainX, NULL, 0, 0);
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
	return TRUE;
}

For MyForm.h, I already have the pointer, address, and offset set up. When I click the button, the value should equal to 999 because
"
1
2
3
4
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
		*(DWORD*)(
		*(DWORD*)((int)GetModuleHandle + 0x7AA7F0)
			+ 0x55a8) = 999;
"
I want to know how to put for example:
I put 999 in the textbox. When I click the button, the value goes to 999. If I put 10000 in the textbox, the value goes to 10000.
Last edited on
I think I can chime in here,

Your trying to make a trainer for a game? fair enough they can be quite fun, and I'm sure if you don't know this it won't be for any kind of AAA or reasonably secured online game.

So you have made a winform and have a button. Also a manual entry of the value your patching to your game memory in the onClick event handler.

All you need to do is;
1. create and add a text box (will mostly be very similar to how you created and added your button).
2. In your onClick event handler just replace the 999 value with the textbox->Text member value (of course, converted to int)

Good Luck :)
http://i64.tinypic.com/dylvdw.jpg
1
2
3
4
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
		*(DWORD*)(
		*(DWORD*)((int)GetModuleHandle + 0x7AA7F0)
			+ 0x55a8) = textBox1;

Not sure what to do after this. I'm just a beginner in C++. I started learning a few weeks ago.
Last edited on
After kurokis additions I would assume you would need to grab the text from the text box and then convert that text to an int safely. In most if nto all commercial IDEs there will be a properties box for the textbox object that will list either allowed characters or character sets (ie, numeric only), you could also use a specific number container type like an incrementor box.

Something like this;

Assuming your using standard c++
1
2
3
4
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
		*(DWORD*)(
		*(DWORD*)((int)GetModuleHandle + 0x7AA7F0)
			+ 0x55a8) = atoi(textBox1->Text);

I think this is how you do it.
1
2
3
4
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
		*(DWORD*)(
		*(DWORD*)((int)GetModuleHandle + 0x7AA7F0)
			+ 0x55a8) = (int)GetModuleHandle; textBox1;

Tell me if I'm right.
Last edited on
1
2
3
4
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
		*(DWORD*)(
		*(DWORD*)((int)GetModuleHandle + 0x7AA7F0)
			+ 0x55a8) = atoi(textBox1->Text);

After doing this, I'm getting this error:
"argument of type "System::String ^" is incompatible with parameter of type "const char*"
But, when I tried this:
1
2
3
4
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
		*(DWORD*)(
		*(DWORD*)((int)GetModuleHandle + 0x7AA7F0)
			+ 0x55a8) = (int)GetModuleHandle; textBox1;

I got no errors, but I need to know if my code is right or not.
Last edited on
Topic archived. No new replies allowed.