Skip to content

Commit

Permalink
Merge branch 'master' into nitro
Browse files Browse the repository at this point in the history
  • Loading branch information
Proxy-99 authored Feb 19, 2025
2 parents e8967fc + 7763da4 commit cd5a83b
Show file tree
Hide file tree
Showing 528 changed files with 118,486 additions and 100,201 deletions.
13 changes: 7 additions & 6 deletions Client/ceflauncher/Main.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
/*****************************************************************************
*
* PROJECT: Multi Theft Auto v1.0
* (Shared logic for modifications)
* PROJECT: Multi Theft Auto
* LICENSE: See LICENSE in the top level directory
* FILE: ceflauncher/Main.cpp
* PURPOSE: CEF launcher entry point
*
* Multi Theft Auto is available from https://multitheftauto.com/
*
*****************************************************************************/
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <string>

/*
IMPORTANT
Expand All @@ -24,7 +22,10 @@

int _declspec(dllimport) InitCEF();

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdShow, int nCmdShow)
using HINSTANCE = struct HINSTANCE__*;
using LPSTR = char*;

int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdShow, int nCmdShow)
{
return InitCEF();
}
4 changes: 0 additions & 4 deletions Client/ceflauncher/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@ project "CEFLauncher"
kind "WindowedApp"
targetname "CEFLauncher"
targetdir(buildpath("mta/cef"))

includedirs { "../sdk" }

links { "CEFLauncher DLL"}
entrypoint "WinMainCRTStartup"

vpaths {
["Headers/*"] = "**.h",
["Sources/*"] = "**.cpp",
["*"] = "premake5.lua"
}


files {
"premake5.lua",
"*.h",
Expand Down
21 changes: 19 additions & 2 deletions Client/ceflauncher_DLL/Main.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/*****************************************************************************
*
* PROJECT: Multi Theft Auto v1.0
* (Shared logic for modifications)
* PROJECT: Multi Theft Auto
* LICENSE: See LICENSE in the top level directory
* FILE: ceflauncher/Main.cpp
* PURPOSE: CEF launcher entry point
*
* Multi Theft Auto is available from https://multitheftauto.com/
*
*****************************************************************************/

#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <delayimp.h>
Expand Down Expand Up @@ -44,5 +46,20 @@ int _declspec(dllexport) InitCEF()
sandboxInfo = scopedSandbox.sandbox_info();
#endif

if (HANDLE job = CreateJobObjectW(nullptr, nullptr); job != nullptr)
{
JOBOBJECT_EXTENDED_LIMIT_INFORMATION limits{};
limits.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;

if (SetInformationJobObject(job, JobObjectExtendedLimitInformation, &limits, sizeof(limits)))
{
AssignProcessToJobObject(job, GetCurrentProcess());
}
else
{
CloseHandle(job);
}
}

return CefExecuteProcess(mainArgs, app, sandboxInfo);
}
6 changes: 0 additions & 6 deletions Client/core/CCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ CCore::CCore()
m_pMouseControl = new CMouseControl();

// Create our hook objects.
// m_pFileSystemHook = new CFileSystemHook ( );
m_pDirect3DHookManager = new CDirect3DHookManager();
m_pDirectInputHookManager = new CDirectInputHookManager();
m_pMessageLoopHook = new CMessageLoopHook();
Expand Down Expand Up @@ -210,7 +209,6 @@ CCore::~CCore()

// Delete hooks.
delete m_pSetCursorPosHook;
// delete m_pFileSystemHook;
delete m_pDirect3DHookManager;
delete m_pDirectInputHookManager;

Expand Down Expand Up @@ -839,12 +837,8 @@ void CCore::ApplyHooks()
// Create our hooks.
m_pDirectInputHookManager->ApplyHook();
// m_pDirect3DHookManager->ApplyHook ( );
// m_pFileSystemHook->ApplyHook ( );
m_pSetCursorPosHook->ApplyHook();

// Redirect basic files.
// m_pFileSystemHook->RedirectFile ( "main.scm", "../../mta/gtafiles/main.scm" );

// Remove useless DirectPlay dependency (dpnhpast.dll) @ 0x745701
// We have to patch here as multiplayer_sa and game_sa are loaded too late
DetourLibraryFunction("kernel32.dll", "LoadLibraryA", Win32LoadLibraryA, SkipDirectPlay_LoadLibraryA);
Expand Down
3 changes: 1 addition & 2 deletions Client/core/CCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,7 @@ class CCore : public CCoreInterface, public CSingleton<CCore>
CMessageLoopHook* m_pMessageLoopHook;
CDirectInputHookManager* m_pDirectInputHookManager;
CDirect3DHookManager* m_pDirect3DHookManager;
// CFileSystemHook * m_pFileSystemHook;
CSetCursorPosHook* m_pSetCursorPosHook;
CSetCursorPosHook* m_pSetCursorPosHook;

bool m_bLastFocused;
int m_iUnminimizeFrameCounter;
Expand Down
50 changes: 50 additions & 0 deletions Client/game_sa/CDirectorySA.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*****************************************************************************
*
* PROJECT: Multi Theft Auto
* LICENSE: See LICENSE in the top level directory
* FILE: game_sa/CDirectorySA.cpp
*
* Multi Theft Auto is available from https://www.multitheftauto.com/
*
*****************************************************************************/

#include "StdInc.h"
#include "CDirectorySA.h"

DirectoryInfoSA* CDirectorySAInterface::GetModelEntry(std::uint16_t modelId)
{
if (m_nNumEntries <= 0)
return nullptr;

DirectoryInfoSA* entry = m_pEntries + modelId;

if (!entry)
return nullptr;

return entry;
}

bool CDirectorySAInterface::SetModelStreamingSize(std::uint16_t modelId, std::uint16_t size)
{
DirectoryInfoSA* entry = GetModelEntry(modelId);

if (!entry)
return false;

if (entry->m_nStreamingSize == size)
return false;

entry->m_nStreamingSize = size;
return true;
}


std::uint16_t CDirectorySAInterface::GetModelStreamingSize(std::uint16_t modelId)
{
DirectoryInfoSA* entry = GetModelEntry(modelId);

if (!entry)
return 0;

return entry->m_nStreamingSize;
}
33 changes: 33 additions & 0 deletions Client/game_sa/CDirectorySA.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*****************************************************************************
*
* PROJECT: Multi Theft Auto
* LICENSE: See LICENSE in the top level directory
* FILE: game_sa/CDirectorySA.h
*
* Multi Theft Auto is available from https://www.multitheftauto.com/
*
*****************************************************************************/

#pragma once

struct DirectoryInfoSA
{
std::uint32_t m_nOffset;
std::uint16_t m_nStreamingSize;
std::uint16_t m_nSizeInArchive;
char m_szName[24];
};

class CDirectorySAInterface
{
public:
DirectoryInfoSA* GetModelEntry(std::uint16_t modelId);
bool SetModelStreamingSize(std::uint16_t modelId, std::uint16_t size);
std::uint16_t GetModelStreamingSize(std::uint16_t modelId);

private:
DirectoryInfoSA* m_pEntries{};
std::uint32_t m_nCapacity{};
std::uint32_t m_nNumEntries{};
bool m_bOwnsEntries{};
};
48 changes: 0 additions & 48 deletions Client/game_sa/CFireSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
#include "CFireSA.h"
#include "CGameSA.h"
#include "CPoolsSA.h"
#include <game/CTaskManager.h>
#include <game/TaskTypes.h>

extern CGameSA* pGame;

Expand Down Expand Up @@ -211,49 +209,3 @@ void CFireSA::SetNumGenerationsAllowed(char generations)
{
internalInterface->nNumGenerationsAllowed = generations;
}

////////////////////////////////////////////////////////////////////////
// CFire::Extinguish
//
// Fix GH #3249 (PLAYER_ON_FIRE task is not aborted after the fire is extinguished)
////////////////////////////////////////////////////////////////////////
static void AbortFireTask(CEntitySAInterface* entityOnFire, DWORD returnAddress)
{
// We can't and shouldn't remove the task if we're in CTaskSimplePlayerOnFire::ProcessPed. Otherwise we will crash.
if (returnAddress == 0x633783)
return;

auto ped = pGame->GetPools()->GetPed(reinterpret_cast<DWORD*>(entityOnFire));
if (!ped || !ped->pEntity)
return;

CTaskManager* taskManager = ped->pEntity->GetPedIntelligence()->GetTaskManager();
if (!taskManager)
return;

taskManager->RemoveTaskSecondary(TASK_SECONDARY_PARTIAL_ANIM, TASK_SIMPLE_PLAYER_ON_FIRE);
}

#define HOOKPOS_CFire_Extinguish 0x539429
#define HOOKSIZE_CFire_Extinguish 6
static constexpr std::uintptr_t CONTINUE_CFire_Extinguish = 0x53942F;
static void _declspec(naked) HOOK_CFire_Extinguish()
{
_asm
{
mov [eax+730h], edi
mov ebx, [esp+8]

push ebx
push eax
call AbortFireTask
add esp, 8

jmp CONTINUE_CFire_Extinguish
}
}

void CFireSA::StaticSetHooks()
{
EZHookInstall(CFire_Extinguish);
}
2 changes: 0 additions & 2 deletions Client/game_sa/CFireSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,4 @@ class CFireSA : public CFire
void SetStrength(float fStrength);
void SetNumGenerationsAllowed(char generations);
CFireSAInterface* GetInterface() { return internalInterface; }

static void StaticSetHooks();
};
1 change: 0 additions & 1 deletion Client/game_sa/CGameSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ CGameSA::CGameSA()
CVehicleSA::StaticSetHooks();
CCheckpointSA::StaticSetHooks();
CHudSA::StaticSetHooks();
CFireSA::StaticSetHooks();
CPtrNodeSingleLinkPoolSA::StaticSetHooks();
}
catch (const std::bad_alloc& e)
Expand Down
92 changes: 43 additions & 49 deletions Client/game_sa/CHandlingManagerSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ const CBikeHandlingEntry* CHandlingManagerSA::GetOriginalBikeHandlingData(std::u
}

// Return the handling manager id
eHandlingTypes CHandlingManagerSA::GetHandlingID(std::uint32_t model) const noexcept
eHandlingTypes CHandlingManagerSA::GetHandlingID(std::uint32_t model) noexcept
{
switch (model)
{
Expand Down Expand Up @@ -9125,53 +9125,47 @@ void CHandlingManagerSA::InitializeDefaultHandlings() noexcept
m_OriginalBikeHandlingData[13].iVehicleID = 214;
}

void CHandlingManagerSA::CheckSuspensionChanges(const CHandlingEntry* const pEntry) const noexcept
void CHandlingManagerSA::CheckSuspensionChanges(const CHandlingEntry* const entry) const noexcept
{
try
{
// Valid?
if (!pEntry)
return;

// Grab us a multiplayer_sa pointer
const CMultiplayer* const pMultiplayer = g_pCore->GetMultiplayer();
if (!pMultiplayer)
return;

// Get Handling ID
const eHandlingTypes eHandling = pEntry->GetVehicleID();
if (eHandling >= HT_MAX)
return;

const auto& entries = m_OriginalEntries[eHandling];
if (!entries)
return;

// Default bChanged to false
bool bChanged = false;

// Set bChanged to true if we find ANY change.
if (pEntry->GetSuspensionAntiDiveMultiplier() != entries->GetSuspensionAntiDiveMultiplier())
bChanged = true;
else if (pEntry->GetSuspensionDamping() != entries->GetSuspensionDamping())
bChanged = true;
else if (pEntry->GetSuspensionForceLevel() != entries->GetSuspensionForceLevel())
bChanged = true;
else if (pEntry->GetSuspensionFrontRearBias() != entries->GetSuspensionFrontRearBias())
bChanged = true;
else if (pEntry->GetSuspensionHighSpeedDamping() != entries->GetSuspensionHighSpeedDamping())
bChanged = true;
else if (pEntry->GetSuspensionLowerLimit() != entries->GetSuspensionLowerLimit())
bChanged = true;
else if (pEntry->GetSuspensionUpperLimit() != entries->GetSuspensionUpperLimit())
bChanged = true;

if (!bChanged)
return;

pMultiplayer->UpdateVehicleSuspension();
}
catch (...)
{
}
// Valid?
if (!entry)
return;

// Grab us a multiplayer pointer
const CMultiplayer* const multiplayer = g_pCore->GetMultiplayer();
if (!multiplayer)
return;

// Get handling type
const eHandlingTypes handlingType = entry->GetVehicleID();
if (handlingType >= HT_MAX)
return;

const auto& entries = m_OriginalEntries[handlingType];
if (!entries)
return;

// Not changed default
bool isChanged = false;

// Find changes
if (entry->GetSuspensionAntiDiveMultiplier() != entries->GetSuspensionAntiDiveMultiplier())
isChanged = true;
else if (entry->GetSuspensionDamping() != entries->GetSuspensionDamping())
isChanged = true;
else if (entry->GetSuspensionForceLevel() != entries->GetSuspensionForceLevel())
isChanged = true;
else if (entry->GetSuspensionFrontRearBias() != entries->GetSuspensionFrontRearBias())
isChanged = true;
else if (entry->GetSuspensionHighSpeedDamping() != entries->GetSuspensionHighSpeedDamping())
isChanged = true;
else if (entry->GetSuspensionLowerLimit() != entries->GetSuspensionLowerLimit())
isChanged = true;
else if (entry->GetSuspensionUpperLimit() != entries->GetSuspensionUpperLimit())
isChanged = true;

if (!isChanged)
return;

multiplayer->UpdateVehicleSuspension();
}
Loading

0 comments on commit cd5a83b

Please sign in to comment.