Skip to content

Commit

Permalink
Revert "Merge Legitimacy checking process overhaul (mr-659)"
Browse files Browse the repository at this point in the history
This reverts commit 9615536, reversing
changes made to 1035d9b.
  • Loading branch information
prikolium-cfx committed Jan 31, 2025
1 parent 9615536 commit 4fb2fba
Show file tree
Hide file tree
Showing 817 changed files with 330,347 additions and 96,734 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ data/shared/citizen/scripting/lua/graph.lua linguist-vendored
data/shared/citizen/scripting/lua/json.lua linguist-vendored

code/client/clrref/System.Drawing.cs linguist-vendored
code/components/ros-patches-five/include/EntitlementTables_*.h linguist-vendored
code/client/clrcore/External/* linguist-vendored
code/tools/dbg/pe*/** linguist-vendored

Expand Down
4 changes: 2 additions & 2 deletions code/client/citicore/ComponentLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void ComponentLoader::InitializeWithString(std::string_view cacheBuf)
if (wcsstr(moduleName, L"_ROS"))
{
neededComponentsList = {
L"legitimacy",
L"ros-patches-five",
L"net-http-server",
L"net-tcp-server",
L"net-base",
Expand Down Expand Up @@ -282,7 +282,7 @@ static void LoadDependencies(ComponentLoader* loader, fwRefContainer<ComponentDa
}
}

if (!match && dependency.GetCategory() != "vendor" && dependency.GetCategory() != "legitimacy")
if (!match && dependency.GetCategory() != "vendor")
{
FatalError("Unable to resolve dependency for %s.\n", dependency.GetString().c_str());
}
Expand Down
2 changes: 1 addition & 1 deletion code/client/citicore/DllGameComponent.Win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Component* DllGameComponent::CreateComponent()
// sanity check
if (m_path == L"adhesive.dll" && errorCode == ERROR_PROC_NOT_FOUND)
{
HMODULE rosFive = GetModuleHandle(L"legitimacy.dll");
HMODULE rosFive = GetModuleHandle(L"ros-patches-five.dll");

if (rosFive)
{
Expand Down
6 changes: 5 additions & 1 deletion code/client/citicore/EarlyMode.Win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ extern "C" DLL_EXPORT void EarlyMode_Init()
std::vector<fwRefContainer<Component>> components;

for (auto compName : {
"legitimacy",
#ifdef IS_RDR3
"ros-patches:rdr3",
#else
"ros-patches:five",
#endif
"adhesive" })
{
fwRefContainer<ComponentData> cliComponent = loader->LoadComponent(compName);
Expand Down
10 changes: 0 additions & 10 deletions code/client/citicore/FileMapping.Win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,6 @@ static std::wstring MapRedirectedFilename(const wchar_t* origFileName)
{
//trace("map %s\n", ToNarrow(origFileName));

if (wcsstr(origFileName, L"title.rgl") != nullptr)
{
return origFileName;
}

for (const auto& fileName : g_socialClubDlls)
{
if (StrStrIW(origFileName, fileName.c_str()) != NULL)
Expand Down Expand Up @@ -268,11 +263,6 @@ static std::wstring MapRedirectedNtFilename(const wchar_t* origFileName)

static bool IsMappedFilename(const std::wstring& fileName)
{
if (fileName.find(L"title.rgl") != std::wstring::npos)
{
return false;
}

if (fileName.find(L"Files\\Rockstar Games\\Social Club") != std::string::npos ||
fileName.find(g_scFilesRoot) != std::string::npos ||
// weird case: some users have SHGetFolderPathW fail only sometimes into returning "X:\\" with a double backslash
Expand Down
116 changes: 116 additions & 0 deletions code/client/citicore/PatternCache.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* This file is part of the CitizenFX project - http://citizen.re/
*
* See LICENSE and MENTIONS in the root of the source tree for information
* regarding licensing.
*/

#include "StdInc.h"

#if defined(GTA_FIVE) || defined(IS_RDR3)
#include <Hooking.h>

static uintptr_t g_currentStub = hook::exe_end();

extern "C"
{
DLL_EXPORT void* AllocateStubMemoryImpl(size_t size)
{
// Try and pick a sensible alignment
size_t alignMask = ((size > 64) ? 16 : 8) - 1;

g_currentStub = (g_currentStub + alignMask) & ~alignMask;

char* code = (char*)g_currentStub + hook::baseAddressDifference;

DWORD oldProtect;
VirtualProtect(code, size, PAGE_EXECUTE_READWRITE, &oldProtect);

g_currentStub += size;

return code;
}

DLL_EXPORT void* AllocateFunctionStubImpl(void* function, int type)
{
char* code = (char*) AllocateStubMemoryImpl(20);

DWORD oldProtect;
VirtualProtect(code, 15, PAGE_EXECUTE_READWRITE, &oldProtect);

*(uint8_t*)code = 0x48;
*(uint8_t*)(code + 1) = 0xb8 | type;

*(uint64_t*)(code + 2) = (uint64_t)function;

*(uint16_t*)(code + 10) = 0xE0FF | (type << 8);

*(uint64_t*)(code + 12) = 0xCCCCCCCCCCCCCCCC;

g_currentStub += 20;

return code;
}


}
#endif

#ifndef IS_FXSERVER
#include "CrossBuildRuntime.h"
#include <Hooking.Patterns.h>

static std::multimap<uint64_t, uintptr_t> g_hints;

extern "C" CORE_EXPORT auto CoreGetPatternHints()
{
return &g_hints;
}

static InitFunction initFunction([]()
{
#ifndef GTA_NY
if (wcsstr(GetCommandLineW(), L"_ROSLauncher") || wcsstr(GetCommandLineW(), L"_ROSService"))
{
if (getenv("CitizenFX_ToolMode"))
{
g_currentStub = 0x140000000 + 0x0339A600;
}
}
#endif

// don't load hints for chromebrowser subprocess
if (wcsstr(GetCommandLineW(), L"_ChromeBrowser"))
{
return;
}

std::wstring hintsFile = MakeRelativeCitPath(ToWide(fmt::sprintf("data\\cache\\hints_%s.dat", xbr::GetCurrentGameBuildString())));
FILE* hints = _wfopen(hintsFile.c_str(), L"rb");
size_t numHints = 0;

if (hints)
{
while (!feof(hints))
{
uint64_t hash;
uintptr_t hint;

fread(&hash, 1, sizeof(hash), hints);
fread(&hint, 1, sizeof(hint), hints);

hook::pattern::hint(hash, hint);

numHints++;
}

fclose(hints);
}

// over 48k hints? that might be anomalous: regenerate them
if (numHints > (48 * 1024))
{
_wunlink(hintsFile.c_str());
}
});
#endif
57 changes: 0 additions & 57 deletions code/client/citicore/StubAllocators.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion code/client/launcher/DisableNVSP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static std::optional<NvidiaConnectionInfo> GetNvidiaStateNew()
std::optional<NvidiaConnectionInfo> rv;
auto fileMapping = OpenFileMappingW(FILE_MAP_READ, FALSE, L"{8BA1E16C-FC54-4595-9782-E370A5FBE8DA}");

if (fileMapping)
if (fileMapping != 0 && fileMapping != INVALID_HANDLE_VALUE)
{
const void* data = MapViewOfFile(fileMapping, FILE_MAP_READ, 0, 0, 0);

Expand Down
2 changes: 1 addition & 1 deletion code/client/launcher/DisableSteamInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ bool IsSteamRunning()
{
HANDLE steamProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid);

if (steamProcess)
if (steamProcess != INVALID_HANDLE_VALUE)
{
wchar_t imageName[512] = { 0 };
GetProcessImageFileNameW(steamProcess, imageName, std::size(imageName));
Expand Down
9 changes: 2 additions & 7 deletions code/client/launcher/ExecutableLoader.Snapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,9 @@ inline static uintptr_t GetLauncherTriggerEP()
{
if (getenv("CitizenFX_ToolMode"))
{
LPWSTR commandLine = GetCommandLineW();

// Case insensitive: name must match newCommandLine in LoopbackTcpServer
if (wcsstr(commandLine, L"Launcher.exe") != nullptr && wcsstr(commandLine, L"ros:legit") == nullptr)
if (wcsstr(GetCommandLineW(), L"launcher.exe"))
{
// Launcher.exe with
// sha1 = f259de45c50f399d3e278fd39401ef51a3cc031a
// sha256 = 0dbf58119cdd2d67e6ecee1e31be3f19827444df978f7df747064a870736bce4
// launcher.exe with sha256 hash 0dbf58119cdd2d67e6ecee1e31be3f19827444df978f7df747064a870736bce4
return 0x14020b70c;
}
}
Expand Down
2 changes: 0 additions & 2 deletions code/client/launcher/LauncherConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@
#define CONTENT_NAME "paynefx"
#define GAME_EXECUTABLE L"MaxPayne3.exe"
#elif defined(GTA_FIVE)
#define PRODUCT_ID CfxState::ProductID::FIVEM
#define PRODUCT_NAME L"FiveM"
#define GAME_EXECUTABLE L"GTA5.exe"
#define CONTENT_NAME "fivereborn"
#define LINK_PROTOCOL L"fivem"
#elif defined(IS_RDR3)
#define PRODUCT_ID CfxState::ProductID::REDM
#define PRODUCT_NAME L"RedM"
#define CONTENT_NAME "redm"
#define GAME_EXECUTABLE L"RDR2.exe"
Expand Down
6 changes: 1 addition & 5 deletions code/client/launcher/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,11 @@ int RealMain()

// initialize our initState instance
// this needs to be before *any* MakeRelativeCitPath use in main process
auto initState = CfxState::Get();
HostSharedData<CfxState> initState("CfxInitState");

// set link protocol, e.g. fivem or redm
initState->SetLinkProtocol(LINK_PROTOCOL);

// set product ID
initState->SetProductID(PRODUCT_ID);

// path environment appending of our primary directories
static wchar_t pathBuf[32768];
GetEnvironmentVariable(L"PATH", pathBuf, std::size(pathBuf));
Expand Down Expand Up @@ -422,7 +419,6 @@ int RealMain()
#endif

// crossbuildruntime is safe from this point on
initState->SetGameBuild(xbr::GetGameBuild());

// try loading TLS DLL a second time, and ensure it *is* loaded
#if !defined(GTA_NY) && defined(LAUNCHER_PERSONALITY_GAME)
Expand Down
5 changes: 0 additions & 5 deletions code/client/launcher/MiniDump.Shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ extern "C" DLL_EXPORT bool InitializeExceptionHandler()
wchar_t commandLine[MAX_PATH * 8];
if (_snwprintf(commandLine, _countof(commandLine), L"\"%s\" -dumpserver:%i -parentpid:%i", applicationName, (int)initEvent, hostData->GetInitialPid()) >= _countof(commandLine))
{
CloseHandle(initEvent);
return false;
}

Expand All @@ -288,10 +287,6 @@ extern "C" DLL_EXPORT bool InitializeExceptionHandler()
trace("Could not register with breakpad server.\n");
}
}

// #TODO: Convention required for handle passed to CreateProcess as a
// argument pointer.
//CloseHandle(initEvent);
}

if (isDebugged)
Expand Down
Loading

0 comments on commit 4fb2fba

Please sign in to comment.