Skip to content

Commit

Permalink
Merge pull request #12 from ClonkAndre/dev
Browse files Browse the repository at this point in the history
Updated source code to v1.1
  • Loading branch information
ClonkAndre authored Feb 12, 2024
2 parents dc1d4e2 + 58dd6cb commit 11a7bfb
Show file tree
Hide file tree
Showing 37 changed files with 882 additions and 201 deletions.
17 changes: 13 additions & 4 deletions IVSDKDotNet/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

#include "IVSDK.cpp"

#pragma region Variables
static HANDLE managedThreadHandle;
#pragma endregion

#pragma region Events
void ScriptLoop()
{
Expand Down Expand Up @@ -53,23 +57,28 @@ void IngameStartupEvent()
DWORD WINAPI ManagedEntryPoint(HMODULE hModule)
{
// Initialize IV-SDK .NET
CLR::CLRBridge::Initialize((int)plugin::gameVer, AddressSetter::gBaseAddress);
CLR::CLRBridge::Initialize((uint32_t)plugin::gameVer, AddressSetter::gBaseAddress);

// Keep the plugin alive. I guess.
while (true)
while (!CLR::CLRBridge::CanTerminate)
{
Sleep(1000);
}

FreeLibraryAndExitThread(hModule, 0);
return 0;
}

// IV-SDK Stuff
void plugin::gameStartupEvent()
{
// Force english culture of current thread
System::Globalization::CultureInfo^ cultureInfo = gcnew System::Globalization::CultureInfo("en-US");
System::Threading::Thread::CurrentThread->CurrentCulture = cultureInfo;
System::Threading::Thread::CurrentThread->CurrentUICulture = cultureInfo;

// Launch a thread to get a managed entry point and to keep the plugin alive
HANDLE managedThreadHandle = CreateThread(nullptr, 0, (LPTHREAD_START_ROUTINE)&ManagedEntryPoint, GetCurrentModule(), 0, nullptr);
managedThreadHandle = CreateThread(nullptr, 0, (LPTHREAD_START_ROUTINE)&ManagedEntryPoint, GetCurrentModule(), 0, nullptr);

// Subscribe to IV-SDK Events
plugin::processScriptsEvent::Add(ScriptLoop);
Expand Down
4 changes: 2 additions & 2 deletions IVSDKDotNetWrapper/AssemblyInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ using namespace System::Security::Permissions;
[assembly:AssemblyConfigurationAttribute(L"")];
[assembly:AssemblyCompanyAttribute(L"ItsClonkAndre")];
[assembly:AssemblyProductAttribute(L"IVSDKDotNetWrapper")];
[assembly:AssemblyCopyrightAttribute(L"Copyright (c) ItsClonkAndre 2022 - 2023")];
[assembly:AssemblyCopyrightAttribute(L"Copyright (c) ItsClonkAndre 2022 - 2024")];
[assembly:AssemblyTrademarkAttribute(L"")];
[assembly:AssemblyCultureAttribute(L"")];

[assembly:AssemblyVersionAttribute(L"1.0.0.0")];
[assembly:AssemblyVersionAttribute(L"1.1.0.0")];

[assembly:ComVisible(false)];
16 changes: 11 additions & 5 deletions IVSDKDotNetWrapper/CLRBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ LRESULT __stdcall WndProcHook(const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
namespace CLR
{

void CLRBridge::Initialize(int version, uint32_t baseAddress)
void CLRBridge::Initialize(uint32_t version, uint32_t baseAddress)
{
if (CLRBridge::IsBridgeDisabled)
return;
Expand All @@ -57,12 +57,17 @@ namespace CLR
// Initialize logger
Logger::Initialize();

// Force english culture of current thread
System::Globalization::CultureInfo^ cultureInfo = gcnew System::Globalization::CultureInfo("en-US");
System::Threading::Thread::CurrentThread->CurrentCulture = cultureInfo;
System::Threading::Thread::CurrentThread->CurrentUICulture = cultureInfo;

// Print about text to console
#if _DEBUG
Logger::Log(String::Format("IV-SDK .NET DEBUG version {0} by ItsClonkAndre", Version));

// Launch debugger
Debugger::Launch();
//Debugger::Launch();
#else
Logger::Log(String::Format("IV-SDK .NET Release version {0} by ItsClonkAndre", Version));
#endif
Expand All @@ -86,14 +91,13 @@ namespace CLR
}

// Initialize Memory Access stuff
//AddressSetter::Initialise(version, baseAddress);
MemoryAccess::Initialise(version, baseAddress);

// Get the GTA IV Process
Process^ gtaProcess = Process::GetCurrentProcess();
TheGTAProcess = Process::GetCurrentProcess();

// Wait till process has a MainWindowHandle and for g_pDirect3DDevice to return a valid pointer
while (gtaProcess->MainWindowHandle == IntPtr::Zero)
while (TheGTAProcess->MainWindowHandle == IntPtr::Zero)
Sleep(100);
while (rage::g_pDirect3DDevice == nullptr)
Sleep(100);
Expand Down Expand Up @@ -304,6 +308,8 @@ namespace CLR
ImGuiDraw::UninitializeImGui();

Logger::LogDebug("Cleanup finished!");

CanTerminate = true;
}

// Internal Events
Expand Down
31 changes: 27 additions & 4 deletions IVSDKDotNetWrapper/CLRBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ namespace CLR
{
public:

// If set to true, communication between IVSDKDotNet.asi and IVSDKDotNetWrapper.dll is disabled.
// This is usually only set to true if an error occured while trying to load the IV-SDK .NET Manager.
/// <summary>
/// If set to true, communication between IVSDKDotNet.asi and IVSDKDotNetWrapper.dll is disabled.
/// This is usually only set to true if an error occured while trying to load the IV-SDK .NET Manager.
/// </summary>
static property bool IsBridgeDisabled
{
public:
Expand All @@ -29,6 +31,23 @@ namespace CLR
}
}

/// <summary>
/// Tells the IVSDKDotNet.asi that it can free its library and exit the thread.
/// </summary>
static property bool CanTerminate
{
public:
bool get()
{
return m_bCanTerminate;
}
internal:
void set(bool value)
{
m_bCanTerminate = value;
}
}

/// <summary>
/// Gets the current version of IV-SDK .NET
/// </summary>
Expand Down Expand Up @@ -162,8 +181,11 @@ namespace CLR
}
}

public:
static System::Diagnostics::Process^ TheGTAProcess;

public:
static void Initialize(int version, uint32_t baseAddress);
static void Initialize(uint32_t version, uint32_t baseAddress);

static void InvokeTickEvents();
static void InvokeGameLoadEvents();
Expand All @@ -183,8 +205,9 @@ namespace CLR

private:
static bool m_bIsBridgeDisabled = false;
static bool m_bCanTerminate = false;

static String^ m_sVersion = "1.0";
static String^ m_sVersion = "1.1";
static String^ m_sLogFileName;
static String^ m_sIVSDKDotNetPath;
static String^ m_sIVSDKDotNetBinaryPath;
Expand Down
11 changes: 11 additions & 0 deletions IVSDKDotNetWrapper/IVCam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ namespace IVSDKDotNet
}

// - - - Methods / Functions - - -
IVCam^ IVCam::FromUIntPtr(UIntPtr ptr)
{
UINTPTR_ZERO_CHECK_WITH_RETURN(ptr, nullptr);
return gcnew IVCam((CCam*)ptr.ToPointer());
}
UIntPtr IVCam::GetUIntPtr()
{
NULLPTR_CHECK_WITH_RETURN(NativeCam, UIntPtr::Zero);
return UIntPtr(NativeCam);
}

IVCam^ IVCam::GetCamOfType(int type, int unk)
{
NULLPTR_CHECK_WITH_RETURN(NativeCam, nullptr);
Expand Down
4 changes: 4 additions & 0 deletions IVSDKDotNetWrapper/IVCam.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ namespace IVSDKDotNet
}
}

public:
static IVCam^ FromUIntPtr(UIntPtr ptr);
UIntPtr GetUIntPtr();

public:
IVCam^ GetCamOfType(int type, int unk);
IVCam^ Activate();
Expand Down
17 changes: 17 additions & 0 deletions IVSDKDotNetWrapper/IVGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,23 @@ namespace IVSDKDotNet
}
}

/// <summary>
/// Gets the bounds of the GTA IV window.
/// </summary>
static property System::Drawing::Rectangle Bounds
{
public:
System::Drawing::Rectangle get()
{
RECT rect;

if (GetWindowRect((HWND)CLR::CLRBridge::TheGTAProcess->MainWindowHandle.ToInt32(), &rect))
return System::Drawing::Rectangle(rect.left, rect.top, rect.right, rect.bottom);

return System::Drawing::Rectangle::Empty;
}
}

public:
/// <summary>
/// Undocumented.
Expand Down
13 changes: 13 additions & 0 deletions IVSDKDotNetWrapper/IVObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,23 @@

namespace IVSDKDotNet
{

// - - - Constructor - - -
IVObject::IVObject(CObject* nativePtr) : IVPhysical(nativePtr)
{
NULLPTR_CHECK(nativePtr);
NativeObject = nativePtr;
}

// - - - Methods / Functions - - -
IVObject^ IVObject::FromUIntPtr(UIntPtr ptr)
{
UINTPTR_ZERO_CHECK_WITH_RETURN(ptr, nullptr);
return gcnew IVObject((CObject*)ptr.ToPointer());
}
UIntPtr IVObject::GetUIntPtr()
{
return UIntPtr(NativeObject);
}

}
4 changes: 4 additions & 0 deletions IVSDKDotNetWrapper/IVObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ namespace IVSDKDotNet
}
}

public:
static IVObject^ FromUIntPtr(UIntPtr ptr);
UIntPtr GetUIntPtr();

internal:
IVObject(CObject* nativePtr);

Expand Down
14 changes: 14 additions & 0 deletions IVSDKDotNetWrapper/IVPedComponentModels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,24 @@

namespace IVSDKDotNet
{

// - - - Constructor - - -
IVPedComponentModels::IVPedComponentModels(tPedComponentModels* nativePtr)
{
NULLPTR_CHECK(nativePtr);
NativePedComponentModels = nativePtr;
}

// - - - Methods / Functions - - -
IVPedComponentModels^ IVPedComponentModels::FromUIntPtr(UIntPtr ptr)
{
UINTPTR_ZERO_CHECK_WITH_RETURN(ptr, nullptr);
return gcnew IVPedComponentModels((tPedComponentModels*)ptr.ToPointer());
}
UIntPtr IVPedComponentModels::GetUIntPtr()
{
NULLPTR_CHECK_WITH_RETURN(NativePedComponentModels, UIntPtr::Zero);
return UIntPtr(NativePedComponentModels);
}

}
4 changes: 4 additions & 0 deletions IVSDKDotNetWrapper/IVPedComponentModels.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ namespace IVSDKDotNet
}
}

public:
static IVPedComponentModels^ FromUIntPtr(UIntPtr ptr);
UIntPtr GetUIntPtr();

internal:
IVPedComponentModels(tPedComponentModels* nativePtr);

Expand Down
14 changes: 14 additions & 0 deletions IVSDKDotNetWrapper/IVPedDrawableInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,24 @@

namespace IVSDKDotNet
{

// - - - Constructor - - -
IVPedDrawableInfo::IVPedDrawableInfo(tPedDrawableInfo* nativePtr)
{
NULLPTR_CHECK(nativePtr);
NativePedDrawableInfo = nativePtr;
}

// - - - Methods / Functions - - -
IVPedDrawableInfo^ IVPedDrawableInfo::FromUIntPtr(UIntPtr ptr)
{
UINTPTR_ZERO_CHECK_WITH_RETURN(ptr, nullptr);
return gcnew IVPedDrawableInfo((tPedDrawableInfo*)ptr.ToPointer());
}
UIntPtr IVPedDrawableInfo::GetUIntPtr()
{
NULLPTR_CHECK_WITH_RETURN(NativePedDrawableInfo, UIntPtr::Zero)
return UIntPtr(NativePedDrawableInfo);
}

}
4 changes: 4 additions & 0 deletions IVSDKDotNetWrapper/IVPedDrawableInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ namespace IVSDKDotNet
}
}

public:
static IVPedDrawableInfo^ FromUIntPtr(UIntPtr ptr);
UIntPtr GetUIntPtr();

internal:
IVPedDrawableInfo(tPedDrawableInfo* nativePtr);

Expand Down
12 changes: 12 additions & 0 deletions IVSDKDotNetWrapper/IVPlayerInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ namespace IVSDKDotNet
NULLPTR_CHECK(NativePlayerInfo);
NativePlayerInfo->KillPlayerOutsideWorld();
}

IVPlayerInfo^ IVPlayerInfo::FromUIntPtr(UIntPtr ptr)
{
UINTPTR_ZERO_CHECK_WITH_RETURN(ptr, nullptr);
return gcnew IVPlayerInfo((CPlayerInfo*)ptr.ToPointer());
}
UIntPtr IVPlayerInfo::GetUIntPtr()
{
NULLPTR_CHECK_WITH_RETURN(NativePlayerInfo, UIntPtr::Zero);
return UIntPtr(NativePlayerInfo);
}

bool IVPlayerInfo::IsPlayerActive(int id)
{
return CPlayerInfo::IsPlayerActive(id);
Expand Down
4 changes: 4 additions & 0 deletions IVSDKDotNetWrapper/IVPlayerInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ namespace IVSDKDotNet
public:
void KillPlayerOutsideWorld();

public:
static IVPlayerInfo^ FromUIntPtr(UIntPtr ptr);
UIntPtr GetUIntPtr();

public:
static bool IsPlayerActive(int id);
static IVPlayerInfo^ GetPlayerInfo(uint32_t nPlayerId);
Expand Down
25 changes: 25 additions & 0 deletions IVSDKDotNetWrapper/IVShadows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,32 @@

namespace IVSDKDotNet
{

// - - - Methods / Functions - - -
void IVShadows::StoreStaticShadowOriginal(uint32_t a1, uint32_t a2, uint32_t nFlags, Vector3 pVec1, Vector3 pVec2, Vector3 vPos, Color vColor, float fIntensity, uint32_t texHash, uint32_t txdSlot, float fRange, float a12, float a13, uint32_t a14, uint32_t a15, uint32_t nID)
{
CVector v1;
v1.x = 0.0F;
v1.y = 0.0F;
v1.z = -1.0F;

CVector v2;
v2.x = 0.0F;
v2.y = 1.0F;
v2.z = 0.0F;

CVector v3Pos;
v3Pos.x = vPos.X;
v3Pos.y = vPos.Y;
v3Pos.z = vPos.Z;

CVector v4Color;
v4Color.x = vColor.R;
v4Color.y = vColor.G;
v4Color.z = vColor.B;

CShadows::StoreStaticShadow(a1, a2, nFlags, &v1, &v2, &v3Pos, &v4Color, fIntensity, texHash, txdSlot, fRange, a12, a13, a14, a15, nID);
}
void IVShadows::StoreStaticShadowAdvanced(uint32_t a1, uint32_t a2, bool castShadows, Vector3 pVec1, Vector3 pVec2, Vector3 vPos, Color vColor, float fIntensity, uint32_t texHash, uint32_t txdSlot, float fRange, float a12, float a13, uint32_t a14, uint32_t a15, uint32_t nID)
{
CVector v1;
Expand Down
Loading

0 comments on commit 11a7bfb

Please sign in to comment.