Skip to content

Commit

Permalink
Merge pull request #34 from VITALISED/vitalbranch2
Browse files Browse the repository at this point in the history
Add Steam Support
  • Loading branch information
VITALISED authored Dec 17, 2023
2 parents bc7f020 + 23e2464 commit 617ffbd
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 42 deletions.
8 changes: 6 additions & 2 deletions renms/core/warning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@
#include <core/warning.h>

RENMS_HOOK(
cTkFileSystem__IsModded, renms::RelToAbsolute(0x256EC60), bool, (uint64_t thiscall) { return true; });
cTkFileSystem__IsModded, renms::SignatureScan("48 8B 01 48 85 C0 74 ? 0F B6 80 92 26 00 00"), bool,
(uint64_t thiscall) { return true; });

RENMS_HOOK(
cGcApplicationGameModeSelectorState__RenderWarning, renms::RelToAbsolute(0x1BF7E0), void,
cGcApplicationGameModeSelectorState__RenderWarning,
renms::SignatureScan(
"48 8B C4 48 89 58 10 48 89 70 18 55 57 41 56 48 8D 6C 24 90 48 81 EC ? ? ? ? 48 8B 1D ? ? ? ?"),
void,
(uint64_t thiscall, const char *lpacWarningTitle, const char *lpacWarningPress, const char *lStatus1,
char *lStatus2, float lfTimeout) {
return RENMS_CAST(
Expand Down
27 changes: 11 additions & 16 deletions renms/memory/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
* @file memory.h
* @author VITALISED & Contributors
* @since 2023-12-05
*
*
* Copyright (C) 2023 VITALISED & Contributors
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Expand All @@ -41,9 +41,9 @@ inline DWORD_PTR CalculateHalfPointerToFull(
return lpFull + static_cast<DWORD_PTR>(lpHalf + liInstructionOffset + liInstructionLength);
}

inline std::vector<int> *IDAPatternToVec(const char *lpacSig)
inline std::shared_ptr<std::vector<int>> IDAPatternToVec(const char *lpacSig)
{
std::vector<int> *bytes = (std::vector<int> *)malloc(sizeof(std::vector<int>));
std::shared_ptr<std::vector<int>> bytes = std::make_shared<std::vector<int>>();

char *cast = const_cast<char *>(lpacSig);
char *end = const_cast<char *>(lpacSig) + std::strlen(lpacSig);
Expand All @@ -64,7 +64,7 @@ inline std::vector<int> *IDAPatternToVec(const char *lpacSig)
return bytes;
}

inline LPVOID ScanPattern(std::vector<int> *lpPattern)
inline LPVOID ScanPattern(std::shared_ptr<std::vector<int>> lpPattern)
{
const HMODULE module_handle = GetNMSModuleHandle();

Expand All @@ -75,15 +75,10 @@ inline LPVOID ScanPattern(std::vector<int> *lpPattern)
reinterpret_cast<PIMAGE_NT_HEADERS>(reinterpret_cast<std::uint8_t *>(module_handle) + dos_header->e_lfanew);
DWORD size_of_image = nt_headers->OptionalHeader.SizeOfImage;

std::array<int, sizeof(*lpPattern)> pattern_bytes = {};
std::move(lpPattern->begin(), lpPattern->begin() + lpPattern->size(), pattern_bytes.begin());

free(lpPattern);

BYTE *scan_bytes = reinterpret_cast<BYTE *>(module_handle);

size_t s = pattern_bytes.size();
int *d = pattern_bytes.data();
size_t s = lpPattern->size();
int *d = lpPattern->data();

for (DWORD i = 0; i < size_of_image - s; ++i)
{
Expand All @@ -103,9 +98,9 @@ inline LPVOID ScanPattern(std::vector<int> *lpPattern)
return NULL;
}

inline DWORD_PTR SignatureScan(const char *lpacSignature)
inline LPVOID SignatureScan(const char *lpacSignature)
{
return reinterpret_cast<DWORD_PTR>(ScanPattern(IDAPatternToVec(lpacSignature)));
return ScanPattern(IDAPatternToVec(lpacSignature));
}

RENMS_END
7 changes: 4 additions & 3 deletions renms/plugins/fsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ void HandleGcApplicationUpdate(nms::cGcApplication *gApplication)
}

RENMS_HOOK(
cGcApplication__Update, renms::RelToAbsolute(0x19AF10), void, (nms::cGcApplication * thiscall) {
HandleGcApplicationUpdate(GetGcApplication());
return RENMS_CAST(cGcApplication__Update, GetGcApplication());
cGcApplication__Update, renms::SignatureScan("40 53 48 83 EC ? E8 ? ? ? ? 48 89 05 ? ? ? ?"), void,
(nms::cGcApplication * thiscall) {
HandleGcApplicationUpdate(renms_sdk::GetApplication());
return RENMS_CAST(cGcApplication__Update, renms_sdk::GetApplication());
});

RENMS_BEGIN
Expand Down
1 change: 1 addition & 0 deletions renms/plugins/fsm.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <memory/hook.h>
#include <memory/vtable.h>
#include <plugins/api.h>
#include <sdk/core.h>

RENMS_BEGIN

Expand Down
5 changes: 2 additions & 3 deletions sdk/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@

#define RENMS_API extern

#define GCAPPLICATION 0x49707E0
#define GCTEXTCHATMANAGER_SAY 0x806080
#define TKCOMPONENTMANAGER 0x44BE3E0
#define GCAPPLICATION_GOG 0x49707E0
#define GCAPPLICATION_STEAM 0x495EF10

// clang-format off
#define RENMS_SDK_BEGIN namespace renms_sdk {
Expand Down
8 changes: 7 additions & 1 deletion sdk/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ RENMS_SDK_BEGIN

nms::cGcApplication *GetApplication()
{
return reinterpret_cast<nms::cGcApplication *>(RelToAbsolute(GCAPPLICATION));

if (GetModuleHandleA("Galaxy64.dll"))
return reinterpret_cast<nms::cGcApplication *>(RelToAbsolute(GCAPPLICATION_GOG));
if (GetModuleHandleA("steam_api64.dll"))
return reinterpret_cast<nms::cGcApplication *>(RelToAbsolute(GCAPPLICATION_STEAM));

return NULL;
}

// nms::cTkComponentManager* GetComponentManager()
Expand Down
27 changes: 11 additions & 16 deletions sdk/internal/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
* @file memory.h
* @author VITALISED & Contributors
* @since 2023-12-15
*
*
* Copyright (C) 2023 VITALISED & Contributors
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Expand All @@ -41,9 +41,9 @@ inline DWORD_PTR CalculateHalfPointerToFull(
return lpFull + static_cast<DWORD_PTR>(lpHalf + liInstructionOffset + liInstructionLength);
}

inline std::vector<int> *IDAPatternToVec(const char *lpacSig)
inline std::shared_ptr<std::vector<int>> IDAPatternToVec(const char *lpacSig)
{
std::vector<int> *bytes = (std::vector<int> *)malloc(sizeof(std::vector<int>));
std::shared_ptr<std::vector<int>> bytes = std::make_shared<std::vector<int>>();

char *cast = const_cast<char *>(lpacSig);
char *end = const_cast<char *>(lpacSig) + std::strlen(lpacSig);
Expand All @@ -64,7 +64,7 @@ inline std::vector<int> *IDAPatternToVec(const char *lpacSig)
return bytes;
}

inline LPVOID ScanPattern(std::vector<int> *lpPattern)
inline LPVOID ScanPattern(std::shared_ptr<std::vector<int>> lpPattern)
{
const HMODULE module_handle = GetNMSModuleHandle();

Expand All @@ -75,15 +75,10 @@ inline LPVOID ScanPattern(std::vector<int> *lpPattern)
reinterpret_cast<PIMAGE_NT_HEADERS>(reinterpret_cast<std::uint8_t *>(module_handle) + dos_header->e_lfanew);
DWORD size_of_image = nt_headers->OptionalHeader.SizeOfImage;

std::array<int, sizeof(*lpPattern)> pattern_bytes = {};
std::move(lpPattern->begin(), lpPattern->begin() + lpPattern->size(), pattern_bytes.begin());

free(lpPattern);

BYTE *scan_bytes = reinterpret_cast<BYTE *>(module_handle);

size_t s = pattern_bytes.size();
int *d = pattern_bytes.data();
size_t s = lpPattern->size();
int *d = lpPattern->data();

for (DWORD i = 0; i < size_of_image - s; ++i)
{
Expand All @@ -103,9 +98,9 @@ inline LPVOID ScanPattern(std::vector<int> *lpPattern)
return NULL;
}

inline DWORD_PTR SignatureScan(const char *lpacSignature)
inline LPVOID SignatureScan(const char *lpacSignature)
{
return reinterpret_cast<DWORD_PTR>(ScanPattern(IDAPatternToVec(lpacSignature)));
return ScanPattern(IDAPatternToVec(lpacSignature));
}

RENMS_SDK_END
3 changes: 2 additions & 1 deletion sdk/textchat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ void SendTextMessage(nms::cTkFixedString<1121, char> *lsMessage)
nms::cGcApplication *gApplication = GetApplication();

cGcTextChatManager__PostLocalMessage lSayFn =
reinterpret_cast<cGcTextChatManager__PostLocalMessage>(RelToAbsolute(0x806100));
reinterpret_cast<cGcTextChatManager__PostLocalMessage>(SignatureScan(
"48 89 5C 24 08 48 89 6C 24 10 48 89 74 24 18 48 89 7C 24 20 41 56 48 81 EC ? ? ? ? 4D 8B D0"));

nms::cTkFixedString<128, char> lRelevantPlayer = nms::cTkFixedString<128, char>("Explorer");
nms::cTkColour lTransparent = nms::cTkColour(0, 0, 0, 0);
Expand Down

0 comments on commit 617ffbd

Please sign in to comment.