Skip to content

Commit

Permalink
Added ScriptHookV download on build
Browse files Browse the repository at this point in the history
  • Loading branch information
justalemon committed Sep 7, 2021
1 parent 990f0ee commit ffe2dfe
Show file tree
Hide file tree
Showing 5 changed files with 6,602 additions and 0 deletions.
10 changes: 10 additions & 0 deletions LemonUI.SHV/LemonUI.SHV.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)bin\SHV\</OutDir>
<IncludePath>..\sdk\natives;..\sdk\scripthookv\inc;..\sdk\ikt;$(IncludePath)</IncludePath>
<LibraryPath>..\sdk\scripthookv\lib;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)bin\SHV\</OutDir>
<IncludePath>..\sdk\natives;..\sdk\scripthookv\inc;..\sdk\ikt;$(IncludePath)</IncludePath>
<LibraryPath>..\sdk\scripthookv\lib;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
Expand All @@ -67,6 +71,9 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
</Link>
<PreBuildEvent>
<Command>powershell -Command "Set-Location ..\; .\sdk\download.ps1"</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
Expand All @@ -88,6 +95,9 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableUAC>false</EnableUAC>
</Link>
<PreBuildEvent>
<Command>powershell -Command "Set-Location ..\; .\sdk\download.ps1"</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
2 changes: 2 additions & 0 deletions sdk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
scripthookv/
scripthookv.zip
26 changes: 26 additions & 0 deletions sdk/download.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
$url = "http://www.dev-c.com/files/ScriptHookV_SDK_1.0.617.1a.zip"
$zip = "sdk\\scripthookv.zip"
$out = "sdk\\scripthookv"
$headers = @{
"Referer" = "http://www.dev-c.com"
}

if (!(Test-Path $out))
{
# Create the directory
New-Item -Path "sdk" -Name "scripthookv" -ItemType "directory"

# If the SDK ZIP doesn't exists, download it
if (!(Test-Path $zip))
{
Invoke-WebRequest -Uri $url -OutFile $zip -MaximumRedirection 0 -Headers $headers
}

# Extract the files
Expand-Archive -Path $zip -DestinationPath $out

# Once everything is done, do some cleanup
Remove-Item $zip -ErrorAction Ignore
Remove-Item "$($out)\\inc\\nativeCaller.h" -ErrorAction Ignore
Remove-Item "$($out)\\inc\\natives.h" -ErrorAction Ignore
}
32 changes: 32 additions & 0 deletions sdk/ikt/nativeCaller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// https://github.com/E66666666/GTAVManualTransmission/blob/master/thirdparty/ScriptHookV_SDK/inc/nativeCaller.h

#pragma once

#include "main.h"
#include <utility>

template <typename T>
static inline void nativePush(T val)
{
static_assert(sizeof(T) <= sizeof(UINT64), "Type is too large");
UINT64 val64 = 0;
*reinterpret_cast<T *>(&val64) = val;
nativePush64(val64);
}

template <typename R>
static inline R invoke(UINT64 hash)
{
nativeInit(hash);
return *reinterpret_cast<R *>(nativeCall());
}

template <typename R, class ... Args>
static inline R invoke(UINT64 hash, Args&& ... args)
{
nativeInit(hash);

(nativePush(std::forward<Args>(args)), ...);

return *reinterpret_cast<R*>(nativeCall());
}
Loading

0 comments on commit ffe2dfe

Please sign in to comment.