0

I'm trying to expand my C++ game hacking skills as when I was starting (2 years ago) I made a bad decision: continue in game hacking with vb.net instead of learning c++ (as I had some vb.net knowledge and 0 knowledge with other languages)

So, now as the very first steps I have to create my toolkit, where I will be using my own templates:

  • Nathalib.h (my template with all common functions for game hacking).
#pragma once
#include <iostream>
#include <Windows.h>
#include <string>

#include <TlHelp32.h>
#include <stdio.h>

using namespace std;

DWORD ProcessID;

int FindProcessByName(string name)
{
    HWND hwnd = FindWindowA(0, name);
    GetWindowThreadProcessId(hwnd, &ProcessID);

    if (hwnd)
    {
        return ProcessID;
    }
    else
    {
        return 0;
    }
}
  • Hack.cpp (obviously the cheat, will be different for every game).
#pragma once
#include "pch.h"
#include <iostream>
#include <Windows.h>
#include <string>
#include <Nathalib.h>
using namespace std;

int main()
{
  While(True)
  {    
    cout << FindProcessByName("Calculator") << endl;
    getchar();
    cout << "-----------------------------------" << endl << endl;
  }
  return 0;
}
  • Target.cpp (as we're not bad boys, I must provide my own target).
#include "pch.h"
#include <iostream>
#include <Windows.h>
#include <string>
using namespace std;
#define CHAR_ARRAY_SIZE 128

int main()
{
    int varInt = 123456;
    string varString = "DefaultString";
    char arrChar[CHAR_ARRAY_SIZE] = "Long char array right there ->";
    int * ptr2int;
    ptr2int = &varInt;
    int ** ptr2ptr;
    ptr2ptr = &ptr2int;
    int *** ptr2ptr2;
    ptr2ptr2 = &ptr2ptr;

    while(True) {
        cout << "Process ID: " << GetCurrentProcessId() << endl;

        cout << "varInt (0x" << &varInt << ") = " << varInt << endl;
        cout << "varString (0x" << &varString << ") = " << varString << endl;
        cout << "varChar (0x" << &arrChar << ") = " << arrChar << endl;

        cout << "ptr2int (0x" << hex << &ptr2int << ") = " << ptr2int << endl;
        cout << "ptr2ptr (0x" << hex << &ptr2ptr << ") = " << ptr2ptr << endl;
        cout << "ptr2ptr2 (0x" << hex << &ptr2ptr2 << ") = " << ptr2ptr2 << endl;

        cout << "Press ENTER to print again." << endl;
        getchar();
        cout << "-----------------------------------" << endl << endl;
    }

    return 0;
}

I don't know why the header file is not being recognized.

  1. This is the correct way to include header files? Should I create a namespace/class/object for calling it?
  2. It's the correct way creating a header file? Or I should create another kind of project/resource for this purpose?
  3. How should I call my library methods? Like LibraryName.MethodName?

I just come from other languages and some ideas/features are not available in the other languages (that's why I'm interested in this one)

If there's something I forgot to add, please tell me and I will update

Thanks

5
  • 1
    What do you mean by "the header file is not being recognized"? Do you get compiler errors? Other problems? What compiler and IDE or build system (if any) are you using? Commented May 17, 2019 at 11:34
  • 1
    There is nothing wrong with VB.NET, it is a well-supported first-class citizen language and a perfectly fine programming language on a perfectly fine platform (the .NET virtual machine). Since you already have some experience with .NET-isms, you may want to consider learning C# or F#. If you really want to learn C++, I recommend a good book: stackoverflow.com/questions/388242/… Commented May 17, 2019 at 11:49
  • You should never place a using namespace in a header and especially not one for std. And function definitions in a header have to be inline. Commented May 17, 2019 at 11:54
  • First of all, I think I learned enough from VB.NET, that gave me the knowledge to understand C# without any problem. I'm very happy with VB.NET and I love it, but it's time to learn new things, and I want to learn different things, C# is very similar to VB.NET so it's nothing new for me at all. When I started in programming I made a little C course, where I just learned to declare and use variables, math, comparisons and all this very basic stuff, never went into multi level pointers and all this stuff, so it's my opportunity to start again now that I'm better programmer Commented May 17, 2019 at 12:09
  • And just to clarify why I stopped at C, I was very newbie and didn't know how to search libraries or functions that I didn't know (like pinvoke or anything that doesn't exist in stdio.h), at VB.NET I started to add libraries/nuggets and make cool things, at the start I thought C was a very limited language where you can only define types and move it's data, but now I know I was limited but not the language :) I don't want to fully explain my life, but I want people to understand why I'm asking this things Commented May 17, 2019 at 12:15

4 Answers 4

4

There are multiple errors - please check your textbook.

  1. You include your own headers with #include "". System headers are included with #include<>
  2. The header file generally contains function declarations. Function bodies go into the corresponding .cpp file.
  3. You call your library functions by their name. If they're in a namespace, that might mean the format is namespacename::functionname(arguments).
Sign up to request clarification or add additional context in comments.

3 Comments

Hello, thanks my friend. I see I had to use #include "".
I'm not understanding the 2nd part, how can I declare a function in a header and write the body in the cpp? I don't see how to setup a connection so the function knows where the body is... maybe you could give an example?
@kuhi: That's why I say to check your textbook. This will be one of the very first chapters.
0

There are two ways to include headers, using "" or <>

  • with <> the file will be searched in the system search path (which is not the $PATH variabel, but the list of paths provided with `-I' together with standard headers already known by compiler) and included if found
  • with "" the file will be search in the current folder and in the system search path

Assuming your header is in th esame folder of hack.cpp, you should use

#include "Nathalib.h"

Comments

0

First off, your header lacks include guards, #pragma once only works with msvc++. Your header file is probably not in PATH, so you need to specify it's path relative to your project. If your header file is in the same root as your cpp file, all you need to do is change the include statement for that header file to #include "Nathalib.h" otherwise you'll have to specify the relative path.

1 Comment

#pragma once is supported by gcc, clang and msvc (and probably more). So it should be save to use in most situations. The downside is that it’s sadly not part of the standard.
0

To add to other aswers- why you should put declaration of function in .h file, while its definition to .cpp file: Writing function definition in header files in C++

I suggest to find some c++ tutorials for example: http://www.tutorialspoint.com/cplusplus/cpp_functions.htm You should learn tutorials first, making some exercises on simply code. Personally I prefer check then most simply code for new programming construct. Then more complicated. After such learning you may use for reference also : http://www.cplusplus.com and https://en.cppreference.com/w/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.