C++: Add il2cppi_to_string() helpers
Refactor other helper names to il2cppi_*
This commit is contained in:
@@ -91,22 +91,24 @@ namespace Il2CppInspector.Properties {
|
|||||||
/// Looks up a localized string similar to // Generated C++ file by Il2CppInspector - http://www.djkaty.com - https://github.com/djkaty
|
/// Looks up a localized string similar to // Generated C++ file by Il2CppInspector - http://www.djkaty.com - https://github.com/djkaty
|
||||||
///// Helper functions
|
///// Helper functions
|
||||||
///
|
///
|
||||||
|
///#include "pch-il2cpp.h"
|
||||||
|
///
|
||||||
///#define WIN32_LEAN_AND_MEAN
|
///#define WIN32_LEAN_AND_MEAN
|
||||||
///#include <windows.h>
|
///#include <windows.h>
|
||||||
///#include <string>
|
///#include <string>
|
||||||
|
///#include <codecvt>
|
||||||
///#include "helpers.h"
|
///#include "helpers.h"
|
||||||
///
|
///
|
||||||
///// Log file location
|
///// Log file location
|
||||||
///extern const LPCWSTR LOG_FILE;
|
///extern const LPCWSTR LOG_FILE;
|
||||||
///
|
///
|
||||||
///// Helper function to get the module base address
|
///// Helper function to get the module base address
|
||||||
///uintptr_t GetBaseAddress() {
|
///uintptr_t il2cppi_get_base_address() {
|
||||||
/// return (uintptr_t) GetModuleHandleW(L"GameAssembly.dll");
|
/// return (uintptr_t) GetModuleHandleW(L"GameAssembly.dll");
|
||||||
///}
|
///}
|
||||||
///
|
///
|
||||||
///// Helper function to append text to a file
|
///// Helper function to append text to a file
|
||||||
///void LogWrite(std::string text) {
|
///void il2cppi_l [rest of string was truncated]";.
|
||||||
/// HANDLE hfile = CreateFileW(LOG [rest of string was truncated]";.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static string Cpp_HelpersCpp {
|
internal static string Cpp_HelpersCpp {
|
||||||
get {
|
get {
|
||||||
@@ -125,16 +127,15 @@ namespace Il2CppInspector.Properties {
|
|||||||
///#include <iomanip>
|
///#include <iomanip>
|
||||||
///
|
///
|
||||||
///// Helper function to get the module base address
|
///// Helper function to get the module base address
|
||||||
///uintptr_t GetBaseAddress();
|
///uintptr_t il2cppi_get_base_address();
|
||||||
///
|
///
|
||||||
///// Helper function to append text to a file
|
///// Helper function to append text to a file
|
||||||
///void LogWrite(std::string text);
|
///void il2cppi_log_write(std::string text);
|
||||||
///
|
///
|
||||||
///// Helper function to open a new console window and redirect stdout there
|
///// Helper function to open a new console window and redirect stdout there
|
||||||
///void NewConsole();
|
///void il2cppi_new_console();
|
||||||
///
|
///
|
||||||
///// Helper function to convert a pointer to hex
|
///// Helper function to convert Il2CppString to st [rest of string was truncated]";.
|
||||||
///template<t [rest of string was truncated]";.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static string Cpp_HelpersH {
|
internal static string Cpp_HelpersH {
|
||||||
get {
|
get {
|
||||||
@@ -164,7 +165,7 @@ namespace Il2CppInspector.Properties {
|
|||||||
///// Application-specific functions
|
///// Application-specific functions
|
||||||
///#define DO_APP_FUNC(a, r, n, p) extern r (*n) p
|
///#define DO_APP_FUNC(a, r, n, p) extern r (*n) p
|
||||||
///namespace app {
|
///namespace app {
|
||||||
/// #incl [rest of string was truncated]";.
|
/// #include "il2cpp-functions [rest of string was truncated]";.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static string Cpp_Il2CppAppDataH {
|
internal static string Cpp_Il2CppAppDataH {
|
||||||
get {
|
get {
|
||||||
@@ -195,7 +196,7 @@ namespace Il2CppInspector.Properties {
|
|||||||
///#undef DO_APP_FUNC
|
///#undef DO_APP_FUNC
|
||||||
///
|
///
|
||||||
///// TypeInfo pointers
|
///// TypeInfo pointers
|
||||||
///# [rest of string was truncated]";.
|
///#define DO_TYPEDEF(a, n [rest of string was truncated]";.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static string Cpp_Il2CppInitCpp {
|
internal static string Cpp_Il2CppInitCpp {
|
||||||
get {
|
get {
|
||||||
@@ -284,7 +285,7 @@ namespace Il2CppInspector.Properties {
|
|||||||
///#ifndef PCH_IL2CPP_H
|
///#ifndef PCH_IL2CPP_H
|
||||||
///#define PCH_IL2CPP_H
|
///#define PCH_IL2CPP_H
|
||||||
///
|
///
|
||||||
///// add headers [rest of string was truncated]";.
|
///// add headers that you [rest of string was truncated]";.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static string Cpp_PCHIl2CppH {
|
internal static string Cpp_PCHIl2CppH {
|
||||||
get {
|
get {
|
||||||
@@ -306,7 +307,8 @@ namespace Il2CppInspector.Properties {
|
|||||||
/// <Filter>framework</Filter>
|
/// <Filter>framework</Filter>
|
||||||
/// </ClCompile>
|
/// </ClCompile>
|
||||||
/// <ClCompile Include="framework\il2cpp-init.cpp">
|
/// <ClCompile Include="framework\il2cpp-init.cpp">
|
||||||
/// <Filter>framework< [rest of string was truncated]";.
|
/// <Filter>framework</Filter>
|
||||||
|
/// [rest of string was truncated]";.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static string CppProjFilters {
|
internal static string CppProjFilters {
|
||||||
get {
|
get {
|
||||||
@@ -326,7 +328,7 @@ namespace Il2CppInspector.Properties {
|
|||||||
/// <Configuration>Release</Configuration>
|
/// <Configuration>Release</Configuration>
|
||||||
/// <Platform>Win32</Platform>
|
/// <Platform>Win32</Platform>
|
||||||
/// </ProjectConfiguration>
|
/// </ProjectConfiguration>
|
||||||
/// <ProjectCon [rest of string was truncated]";.
|
/// <ProjectConfiguration [rest of string was truncated]";.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static string CppProjTemplate {
|
internal static string CppProjTemplate {
|
||||||
get {
|
get {
|
||||||
|
|||||||
@@ -150,21 +150,24 @@ BOOL APIENTRY DllMain( HMODULE hModule,
|
|||||||
<value>// Generated C++ file by Il2CppInspector - http://www.djkaty.com - https://github.com/djkaty
|
<value>// Generated C++ file by Il2CppInspector - http://www.djkaty.com - https://github.com/djkaty
|
||||||
// Helper functions
|
// Helper functions
|
||||||
|
|
||||||
|
#include "pch-il2cpp.h"
|
||||||
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <codecvt>
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
|
|
||||||
// Log file location
|
// Log file location
|
||||||
extern const LPCWSTR LOG_FILE;
|
extern const LPCWSTR LOG_FILE;
|
||||||
|
|
||||||
// Helper function to get the module base address
|
// Helper function to get the module base address
|
||||||
uintptr_t GetBaseAddress() {
|
uintptr_t il2cppi_get_base_address() {
|
||||||
return (uintptr_t) GetModuleHandleW(L"GameAssembly.dll");
|
return (uintptr_t) GetModuleHandleW(L"GameAssembly.dll");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function to append text to a file
|
// Helper function to append text to a file
|
||||||
void LogWrite(std::string text) {
|
void il2cppi_log_write(std::string text) {
|
||||||
HANDLE hfile = CreateFileW(LOG_FILE, FILE_APPEND_DATA, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
HANDLE hfile = CreateFileW(LOG_FILE, FILE_APPEND_DATA, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||||
|
|
||||||
if (hfile == INVALID_HANDLE_VALUE)
|
if (hfile == INVALID_HANDLE_VALUE)
|
||||||
@@ -177,9 +180,21 @@ void LogWrite(std::string text) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Helper function to open a new console window and redirect stdout there
|
// Helper function to open a new console window and redirect stdout there
|
||||||
void NewConsole() {
|
void il2cppi_new_console() {
|
||||||
AllocConsole();
|
AllocConsole();
|
||||||
freopen_s((FILE**) stdout, "CONOUT$", "w", stdout);
|
freopen_s((FILE**) stdout, "CONOUT$", "w", stdout);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to convert Il2CppString to std::string
|
||||||
|
std::string il2cppi_to_string(Il2CppString* str) {
|
||||||
|
std::u16string u16(reinterpret_cast<const char16_t*>(str->chars));
|
||||||
|
return std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>{}.to_bytes(u16);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to convert System.String to std::string
|
||||||
|
std::string il2cppi_to_string(app::String* str) {
|
||||||
|
std::u16string u16(reinterpret_cast<const char16_t*>(&str->fields.m_firstChar));
|
||||||
|
return std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>{}.to_bytes(u16);
|
||||||
}</value>
|
}</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="Cpp-HelpersH" xml:space="preserve">
|
<data name="Cpp-HelpersH" xml:space="preserve">
|
||||||
@@ -193,13 +208,19 @@ void NewConsole() {
|
|||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
// Helper function to get the module base address
|
// Helper function to get the module base address
|
||||||
uintptr_t GetBaseAddress();
|
uintptr_t il2cppi_get_base_address();
|
||||||
|
|
||||||
// Helper function to append text to a file
|
// Helper function to append text to a file
|
||||||
void LogWrite(std::string text);
|
void il2cppi_log_write(std::string text);
|
||||||
|
|
||||||
// Helper function to open a new console window and redirect stdout there
|
// Helper function to open a new console window and redirect stdout there
|
||||||
void NewConsole();
|
void il2cppi_new_console();
|
||||||
|
|
||||||
|
// Helper function to convert Il2CppString to std::string
|
||||||
|
std::string il2cppi_to_string(Il2CppString* str);
|
||||||
|
|
||||||
|
// Helper function to convert System.String to std::string
|
||||||
|
std::string il2cppi_to_string(app::String* str);
|
||||||
|
|
||||||
// Helper function to convert a pointer to hex
|
// Helper function to convert a pointer to hex
|
||||||
template<typename T> std::string to_hex_string(T i) {
|
template<typename T> std::string to_hex_string(T i) {
|
||||||
@@ -237,11 +258,11 @@ extern const LPCWSTR LOG_FILE = L"il2cpp-log.txt";
|
|||||||
// Custom injected code entry point
|
// Custom injected code entry point
|
||||||
void Run()
|
void Run()
|
||||||
{
|
{
|
||||||
// If you would like to write to a log file, specify the name above and use LogWrite()
|
// If you would like to write to a log file, specify the name above and use il2cppi_log_write()
|
||||||
// LogWrite("Startup");
|
// il2cppi_log_write("Startup");
|
||||||
|
|
||||||
// If you would like to output to a new console window, use NewConsole() to open one and redirect stdout
|
// If you would like to output to a new console window, use il2cppi_new_console() to open one and redirect stdout
|
||||||
// NewConsole();
|
// il2cppi_new_console();
|
||||||
|
|
||||||
// Place your custom code here
|
// Place your custom code here
|
||||||
}</value>
|
}</value>
|
||||||
@@ -1198,7 +1219,7 @@ namespace app {
|
|||||||
void init_il2cpp()
|
void init_il2cpp()
|
||||||
{
|
{
|
||||||
// Get base address of IL2CPP module
|
// Get base address of IL2CPP module
|
||||||
uintptr_t baseAddress = GetBaseAddress();
|
uintptr_t baseAddress = il2cppi_get_base_address();
|
||||||
|
|
||||||
using namespace app;
|
using namespace app;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user