l0m_

Untitled

Nov 15th, 2021 (edited)
666
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.64 KB | None | 0 0
  1. /*
  2. * FortConsole by Makks
  3. * Build with debug configuration for nerd stuff.
  4. */
  5.  
  6. #ifdef WIN32
  7. #error x86 is not supported, please compile in x64
  8. #endif
  9.  
  10. #define _CRT_SECURE_NO_WARNINGS
  11.  
  12. #include "enums.h"
  13. #include "memory.h"
  14. #include <stdio.h>
  15. #include <iostream>
  16. #include <string>
  17.  
  18. HMODULE handle;
  19. uintptr_t moduleBase = (uintptr_t)GetModuleHandle(nullptr);
  20.  
  21. struct UObject;
  22.  
  23. struct UClass;
  24.  
  25. struct UPackage;
  26.  
  27. struct UConsole;
  28.  
  29. struct FString;
  30.  
  31. struct UGameViewportClient
  32. {
  33.     char unknown1[0x40];
  34.     UConsole* ViewportConsole;
  35. };
  36.  
  37. struct UEngine
  38. {
  39.     char unknown1[0xF8];
  40.     UClass* ConsoleClass;
  41.     char unknown2[0x688];
  42.     UGameViewportClient* GameViewportClient;
  43. };
  44.  
  45. #ifdef _DEBUG
  46. #define DEBUG_LOG(input, ...) printf(input, __VA_ARGS__);
  47. #else
  48. #define DEBUG_LOG(input, ...)
  49. #endif
  50.  
  51. #define VALIDATE_ADDRESS(address, error) \
  52.     if (!address) { \
  53.         MessageBox(0, (LPCWSTR)error, L"FortConsole", MB_OK); \
  54.         FreeLibraryAndExitThread((HMODULE)param, 0); \
  55.         return 0; \
  56.     }
  57.  
  58. UEngine* GEngine;
  59.  
  60. /*
  61. typedef UObject* (__fastcall* f_StaticConstructObject_Internal)(
  62.     UClass* Class,
  63.     UObject* InOuter,
  64.     void* Name,
  65.     int SetFlags,
  66.     unsigned int InternalSetFlags,
  67.     UObject* Template,
  68.     bool  bCopyTransientsFromClassDefaults,
  69.     void* InstanceGraph,
  70.     bool  bAssumeTemplateIsArchetype
  71. );
  72.  
  73. static f_StaticConstructObject_Internal StaticConstructObject_Internal;
  74. */
  75. template<class T>
  76. struct TArray
  77. {
  78.     T* Data;
  79.     int Count;
  80.     int Max;
  81. };
  82.  
  83. struct FString : public TArray<wchar_t>
  84. {
  85.     inline const wchar_t* c_str() const
  86.     {
  87.         return Data;
  88.     }
  89.  
  90.     std::string ToString() const
  91.     {
  92.         const auto length = std::wcslen(Data);
  93.  
  94.         std::string str(length, '\0');
  95.  
  96.         std::use_facet<std::ctype<wchar_t>>(std::locale()).narrow(Data, Data + length, '?', &str[0]);
  97.  
  98.         return str;
  99.     }
  100. };
  101.  
  102. void* Result;
  103.  
  104. typedef FString* (__fastcall* fGetEngineVersion)
  105. (
  106.     void* Result
  107.     );
  108.  
  109. static fGetEngineVersion GetEngineVersion;
  110.  
  111. struct FStaticConstructObjectParameters
  112. {
  113.     /** The class of the object to create */
  114.     const UClass* Class = {};
  115.  
  116.     /** The object to create this object within (the Outer property for the new object will be set to the value specified here). */
  117.     UObject* Outer = {};
  118.  
  119.     /** The name to give the new object.If no value(NAME_None) is specified, the object will be given a unique name in the form of ClassName_#. */
  120.     void* Name = {};
  121.  
  122.     /** The ObjectFlags to assign to the new object. some flags can affect the behavior of constructing the object. */
  123.     int SetFlags = {};
  124.  
  125.     /** The InternalObjectFlags to assign to the new object. some flags can affect the behavior of constructing the object. */
  126.     unsigned int InternalSetFlags = {};
  127.  
  128.     /** If true, copy transient from the class defaults instead of the pass in archetype ptr(often these are the same) */
  129.     bool bCopyTransientsFromClassDefaults = false;
  130.  
  131.     /** If true, Template is guaranteed to be an archetype */
  132.     bool bAssumeTemplateIsArchetype = false;
  133.  
  134.     /**
  135.      * If specified, the property values from this object will be copied to the new object, and the new object's ObjectArchetype value will be set to this object.
  136.      * If nullptr, the class default object is used instead.
  137.      */
  138.     UObject* Template = nullptr;
  139.  
  140.     /** Contains the mappings of instanced objects and components to their templates */
  141.     void* InstanceGraph = nullptr;
  142.  
  143.     /** Assign an external Package to the created object if non-null */
  144.     UPackage* ExternalPackage = nullptr;
  145.  
  146.     FStaticConstructObjectParameters() {};
  147. };
  148.  
  149. typedef UObject* (__fastcall* fStaticConstructObject_Internal)
  150. (
  151.     const FStaticConstructObjectParameters&
  152. );
  153. static fStaticConstructObject_Internal StaticConstructObject_Internal;
  154.  
  155. std::string text;
  156.  
  157. DWORD WINAPI MainThread(LPVOID param)
  158. {
  159. #ifdef _DEBUG
  160.     AllocConsole();
  161. #pragma warning( push )
  162. #pragma warning( disable : 6031 )
  163.     freopen("CONOUT$", "w", stdout);
  164. #pragma warning( pop )
  165. #endif
  166.  
  167.     handle = (HMODULE)param;
  168.  
  169.     const char* comboPattern = "48 83 3D ?? ?? ?? ?? ?? 0F 84 ?? ?? ?? ?? 48 8D 54 24 ?? 48 89 5C 24 ?? 48 8D 4D A0";
  170.     //uintptr_t GEngine_Address = (uintptr_t)Memory::ScanIn(comboPattern, (char*)moduleBase);
  171.     uintptr_t GEngine_Address = moduleBase + 0x561F6A8;
  172.    
  173.     GEngine = (UEngine*) GEngine_Address;
  174.  
  175.     VALIDATE_ADDRESS(GEngine_Address, L"Failed to find GEngine.");
  176.    
  177.     DEBUG_LOG("GEngine: %p\n", GEngine);
  178.     DEBUG_LOG("Console Class: %p\n", GEngine->ConsoleClass);
  179.     DEBUG_LOG("Game Viewport Client: %p\n", GEngine->GameViewportClient);
  180.  
  181.     const char* scoifullcombo = "48 89 5C 24 ?? 48 89 6C 24 ?? 48 89 74 24 ?? 57 41 56 41 57 48 81 EC ?? ?? ?? ?? 48 8B 05 ?? ?? ?? ?? 48 33 C4 48 89 84 24 ?? ?? ?? ?? 48 8B 31 48 8B D9";
  182.     uintptr_t SCOIAddress = (uintptr_t)Memory::ScanIn(scoifullcombo, (char*)moduleBase);
  183.     VALIDATE_ADDRESS(SCOIAddress, L"Failed to find StaticConstructObject_Internal.");
  184.  
  185.     StaticConstructObject_Internal = reinterpret_cast<fStaticConstructObject_Internal>(SCOIAddress);
  186.  
  187.     DEBUG_LOG("StaticConstructObject_Internal: %p\n", StaticConstructObject_Internal);
  188.    
  189.     FStaticConstructObjectParameters Params;
  190.     Params.Class = GEngine->ConsoleClass;
  191.     Params.Outer = reinterpret_cast<UObject*>(GEngine->GameViewportClient);
  192.     Params.Name = nullptr;
  193.     Params.SetFlags = 0;
  194.     Params.InternalSetFlags = 0;
  195.     Params.Template = nullptr;
  196.     Params.bCopyTransientsFromClassDefaults = false;
  197.     Params.InstanceGraph = nullptr;
  198.     Params.bAssumeTemplateIsArchetype = false;
  199.     Params.ExternalPackage = nullptr;
  200.     //return reinterpret_cast<UConsole*>(StaticConstructObject_Internal(ConsoleClass, outer, nullptr, 0, 0, nullptr, false, nullptr, false));// , nullptr));
  201.     UConsole* Console = reinterpret_cast<UConsole*>(StaticConstructObject_Internal(Params));
  202.  
  203.     /*
  204.     UConsole* Console = reinterpret_cast<UConsole*>(StaticConstructObject_Internal(
  205.         GEngine->ConsoleClass,
  206.         reinterpret_cast<UObject*>(GEngine->GameViewportClient),
  207.         nullptr,
  208.         EObjectFlags::RF_NoFlags,
  209.         EInternalObjectFlags::None,
  210.         nullptr,
  211.         false,
  212.         nullptr,
  213.         false
  214.     ));
  215.     */
  216.  
  217.     GEngine->GameViewportClient->ViewportConsole = Console;
  218.    
  219.    
  220.     FreeLibraryAndExitThread((HMODULE)param, 0);
  221.     return 0;
  222. }
  223.  
  224. BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
  225. {
  226.     switch (dwReason)
  227.     {
  228.     case DLL_PROCESS_ATTACH:
  229.         CreateThread(0, 0, MainThread, hModule, 0, 0);
  230.         break;
  231.     }
  232.     return TRUE;
  233. }
  234.  
Add Comment
Please, Sign In to add comment