Skip to content

Commit 45b0d8d

Browse files
author
Kaldaien
committed
New injection method
1 parent f3df9c7 commit 45b0d8d

File tree

3 files changed

+33
-561
lines changed

3 files changed

+33
-561
lines changed

installer64.dll

-4.78 MB
Binary file not shown.

nier.cpp

+24-201
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
#include <atlbase.h>
5050

5151

52-
#define FAR_VERSION_NUM L"0.6.2.4"
52+
#define FAR_VERSION_NUM L"0.7.0"
5353
#define FAR_VERSION_STR L"FAR v " FAR_VERSION_NUM
5454

5555
// Block until update finishes, otherwise the update dialog
@@ -321,42 +321,15 @@ SK_FAR_CheckVersion (LPVOID user)
321321
__stdcall
322322
SK_UpdateSoftware (const wchar_t* wszProduct);
323323

324-
if (SK_FetchVersionInfo (L"FAR"))
325-
SK_UpdateSoftware (L"FAR");
324+
if (SK_FetchVersionInfo (L"FAR/dinput8"))
325+
SK_UpdateSoftware (L"FAR/dinput8");
326326

327327
return 0;
328328
}
329329

330330
#include <../depends/include/glm/glm.hpp>
331331

332332

333-
struct far_scatter_param_s
334-
{
335-
union
336-
{
337-
struct
338-
{
339-
float Near_Far_Stepnum [4][4];
340-
float LightColor [4][4];
341-
float LightDirView_Range15 [4];
342-
float ScatterParam_Range7 [4];
343-
};
344-
345-
float data [40];
346-
};
347-
348-
far_scatter_param_s (LPCVOID pData)
349-
{
350-
if (pData != nullptr)
351-
memcpy (&data [0], pData, sizeof far_scatter_param_s);
352-
else
353-
memset (&data [0], 0, sizeof far_scatter_param_s);
354-
}
355-
};
356-
357-
std::map <ID3D11Buffer*, far_scatter_param_s> scatter_buffers;
358-
std::map <ID3D11Buffer*, far_scatter_param_s> scatter_buffers_ovr;
359-
360333
HRESULT
361334
WINAPI
362335
SK_FAR_CreateBuffer (
@@ -439,21 +412,7 @@ SK_FAR_CreateBuffer (
439412
return D3D11Dev_CreateBuffer_Original (This, &new_desc, pInitialData, ppBuffer);
440413
}
441414

442-
HRESULT hr =
443-
D3D11Dev_CreateBuffer_Original (This, pDesc, pInitialData, ppBuffer);
444-
445-
if (SUCCEEDED (hr) && ppBuffer != nullptr)
446-
{
447-
if ( pDesc != nullptr && pDesc->ByteWidth == sizeof (far_scatter_param_s) &&
448-
pDesc->BindFlags & D3D11_BIND_CONSTANT_BUFFER &&
449-
pInitialData )
450-
{
451-
scatter_buffers.emplace (std::make_pair (*ppBuffer, far_scatter_param_s (pInitialData->pSysMem)));
452-
scatter_buffers_ovr.emplace (std::make_pair (*ppBuffer, far_scatter_param_s (pInitialData->pSysMem)));
453-
}
454-
}
455-
456-
return hr;
415+
return D3D11Dev_CreateBuffer_Original (This, pDesc, pInitialData, ppBuffer);
457416
}
458417

459418
HRESULT
@@ -505,20 +464,6 @@ SK_FAR_PSSetConstantBuffers (
505464
_In_ UINT NumBuffers,
506465
_In_opt_ ID3D11Buffer *const *ppConstantBuffers )
507466
{
508-
if (ppConstantBuffers)
509-
{
510-
for (UINT i = 0; i < NumBuffers; i++)
511-
{
512-
if (StartSlot + i == 8)
513-
{
514-
if (scatter_buffers.count (ppConstantBuffers [i]))
515-
{
516-
dll_log.Log (L"NEAT");
517-
}
518-
}
519-
}
520-
}
521-
522467
D3D11_PSSetConstantBuffers_Original (This, StartSlot, NumBuffers, ppConstantBuffers );
523468
}
524469

@@ -537,28 +482,6 @@ extern LPVOID __SK_end_img_addr;
537482
extern void* __stdcall SK_Scan (const uint8_t* pattern, size_t len, const uint8_t* mask);
538483

539484

540-
541-
typedef _Return_type_success_(return >= 0) LONG NTSTATUS;
542-
543-
typedef NTSTATUS (NTAPI *NtQueryTimerResolution_pfn)
544-
(
545-
OUT PULONG MinimumResolution,
546-
OUT PULONG MaximumResolution,
547-
OUT PULONG CurrentResolution
548-
);
549-
550-
typedef NTSTATUS (NTAPI *NtSetTimerResolution_pfn)
551-
(
552-
IN ULONG DesiredResolution,
553-
IN BOOLEAN SetResolution,
554-
OUT PULONG CurrentResolution
555-
);
556-
557-
HMODULE NtDll = 0;
558-
559-
NtQueryTimerResolution_pfn NtQueryTimerResolution = nullptr;
560-
NtSetTimerResolution_pfn NtSetTimerResolution = nullptr;
561-
562485
void
563486
SK_FAR_SetFramerateCap (bool enable)
564487
{
@@ -908,7 +831,7 @@ WINAPI
908831
SK_FAR_OSD_Disclaimer (LPVOID user)
909832
{
910833
while ((volatile bool&)config.osd.show)
911-
Sleep (66);
834+
SleepEx (66, FALSE);
912835

913836
far_osd_disclaimer->set_value (false);
914837
far_osd_disclaimer->store ();
@@ -1026,7 +949,7 @@ STDMETHODCALLTYPE
1026949
SK_FAR_PresentFirstFrame (IDXGISwapChain* pSwapChain, UINT SyncInterval, UINT Flags)
1027950
{
1028951
// Wait for the mod to init, it may be held up during version check
1029-
while (! InterlockedAdd (&__FAR_init, 0)) Sleep (16);
952+
while (! InterlockedAdd (&__FAR_init, 0)) SleepEx (16, FALSE);
1030953

1031954
{
1032955
game_state.enforce_cap = (! far_uncap_fps->get_value ());
@@ -1494,11 +1417,6 @@ SK_FAR_UpdateSubresource (
14941417
_In_ UINT SrcRowPitch,
14951418
_In_ UINT SrcDepthPitch)
14961419
{
1497-
if (scatter_buffers.count ((ID3D11Buffer *)pDstResource))
1498-
{
1499-
memcpy (scatter_buffers.at ((ID3D11Buffer *)pDstResource).data, pSrcData, sizeof (far_scatter_param_s));
1500-
}
1501-
15021420
return D3D11_UpdateSubresource_Original ( This, pDstResource, DstSubresource,
15031421
pDstBox, pSrcData, SrcRowPitch,
15041422
SrcDepthPitch );
@@ -1732,32 +1650,6 @@ SK_FAR_InitPlugin (void)
17321650
{
17331651
SK_SetPluginName (FAR_VERSION_STR);
17341652

1735-
if (NtDll == 0)
1736-
{
1737-
NtDll = LoadLibrary (L"ntdll.dll");
1738-
1739-
NtQueryTimerResolution =
1740-
(NtQueryTimerResolution_pfn)
1741-
GetProcAddress (NtDll, "NtQueryTimerResolution");
1742-
1743-
NtSetTimerResolution =
1744-
(NtSetTimerResolution_pfn)
1745-
GetProcAddress (NtDll, "NtSetTimerResolution");
1746-
1747-
if (NtQueryTimerResolution != nullptr &&
1748-
NtSetTimerResolution != nullptr)
1749-
{
1750-
ULONG min, max, cur;
1751-
NtQueryTimerResolution (&min, &max, &cur);
1752-
dll_log.Log ( L"[ Timing ] Kernel resolution.: %f ms",
1753-
(float)(cur * 100)/1000000.0f );
1754-
NtSetTimerResolution (max, TRUE, &cur);
1755-
dll_log.Log ( L"[ Timing ] New resolution....: %f ms",
1756-
(float)(cur * 100)/1000000.0f );
1757-
1758-
}
1759-
}
1760-
17611653
SK_CreateFuncHook ( L"ID3D11Device::CreateBuffer",
17621654
D3D11Dev_CreateBuffer_Override,
17631655
SK_FAR_CreateBuffer,
@@ -1942,25 +1834,25 @@ typedef void (WINAPI *D3D11_DrawInstancedIndirect_pfn)(
19421834
far_rtss_warned->store ();
19431835
}
19441836

1945-
far_slow_state_cache =
1946-
dynamic_cast <sk::ParameterBool *>
1947-
(far_factory.create_parameter <bool> (L"Disable D3D11.1 Interop Stateblocks"));
1948-
1949-
far_slow_state_cache->register_to_ini ( far_prefs,
1950-
L"FAR.Compatibility",
1951-
L"NoD3D11Interop" );
1952-
1953-
extern bool SK_DXGI_FullStateCache;
1954-
1955-
if (! far_slow_state_cache->load ())
1956-
SK_DXGI_FullStateCache = false;
1957-
else
1958-
SK_DXGI_FullStateCache = far_slow_state_cache->get_value ();
1959-
1960-
config.render.dxgi.full_state_cache = SK_DXGI_FullStateCache;
1837+
//far_slow_state_cache =
1838+
// dynamic_cast <sk::ParameterBool *>
1839+
// (far_factory.create_parameter <bool> (L"Disable D3D11.1 Interop Stateblocks"));
1840+
//
1841+
//far_slow_state_cache->register_to_ini ( far_prefs,
1842+
// L"FAR.Compatibility",
1843+
// L"NoD3D11Interop" );
1844+
//
1845+
//extern bool SK_DXGI_FullStateCache;
1846+
//
1847+
//if (! far_slow_state_cache->load ())
1848+
// SK_DXGI_FullStateCache = false;
1849+
//else
1850+
// SK_DXGI_FullStateCache = far_slow_state_cache->get_value ();
1851+
//
1852+
//config.render.dxgi.full_state_cache = SK_DXGI_FullStateCache;
19611853

1962-
far_slow_state_cache->set_value (SK_DXGI_FullStateCache);
1963-
far_slow_state_cache->store ();
1854+
//far_slow_state_cache->set_value (SK_DXGI_FullStateCache);
1855+
//far_slow_state_cache->store ();
19641856

19651857

19661858
far_osd_disclaimer =
@@ -2436,75 +2328,6 @@ SK_FAR_ControlPanel (void)
24362328
ImGui::TreePop ();
24372329
}
24382330

2439-
if (ImGui::CollapsingHeader ("Light Scattering"))
2440-
{
2441-
static int idx = 0;
2442-
static far_scatter_param_s scatter_data (nullptr);
2443-
static ID3D11Resource* scatter_res = nullptr;
2444-
2445-
ImGui::TreePush ("");
2446-
2447-
if (ImGui::SliderInt ("Scatter Buffer", &idx, 0, scatter_buffers.size ()))
2448-
{
2449-
int scatter_idx = 0;
2450-
2451-
for (auto it : scatter_buffers)
2452-
{
2453-
if (scatter_idx == idx)
2454-
{
2455-
ID3D11DeviceContext* pCtx = nullptr;
2456-
2457-
((ID3D11Device *)SK_GetCurrentRenderBackend ().device)->GetImmediateContext (&pCtx);
2458-
2459-
memcpy (scatter_data.data, it.second.data, sizeof far_scatter_param_s);
2460-
scatter_res = it.first;
2461-
break;
2462-
}
2463-
++scatter_idx;
2464-
}
2465-
}
2466-
2467-
static bool update = false;
2468-
2469-
update |= ImGui::DragFloat4 ("Near_Far_Numsteps [0]", scatter_data.Near_Far_Stepnum [0]);
2470-
update |= ImGui::DragFloat4 ("Near_Far_Numsteps [1]", scatter_data.Near_Far_Stepnum [1]);
2471-
update |= ImGui::DragFloat4 ("Near_Far_Numsteps [2]", scatter_data.Near_Far_Stepnum [2]);
2472-
update |= ImGui::DragFloat4 ("Near_Far_Numsteps [3]", scatter_data.Near_Far_Stepnum [3]);
2473-
2474-
ImGui::Separator ();
2475-
2476-
update |= ImGui::ColorEdit4 ("LightColor [0]", scatter_data.LightColor [0]);
2477-
update |= ImGui::ColorEdit4 ("LightColor [1]", scatter_data.LightColor [1]);
2478-
update |= ImGui::ColorEdit4 ("LightColor [2]", scatter_data.LightColor [2]);
2479-
update |= ImGui::ColorEdit4 ("LightColor [3]", scatter_data.LightColor [3]);
2480-
2481-
ImGui::Separator ();
2482-
2483-
update |= ImGui::DragFloat4 ("LightDirView_Range15", scatter_data.LightDirView_Range15);
2484-
update |= ImGui::DragFloat4 ("ScatterParam_Range7", scatter_data.ScatterParam_Range7);
2485-
2486-
ImGui::Separator ();
2487-
2488-
if (scatter_res && update)
2489-
{
2490-
//if (ImGui::Button ("Update Scatter Buffer"))
2491-
//{
2492-
ID3D11DeviceContext* pCtx = nullptr;
2493-
2494-
((ID3D11Device *)SK_GetCurrentRenderBackend ().device)->GetImmediateContext (&pCtx);
2495-
2496-
for (auto it : scatter_buffers)
2497-
{
2498-
D3D11_UpdateSubresource_Original (pCtx, it.first, 0, nullptr, scatter_data.data, 0, 0);
2499-
}
2500-
2501-
//update = false;
2502-
//}
2503-
}
2504-
2505-
ImGui::TreePop ();
2506-
}
2507-
25082331
if (ImGui::CollapsingHeader ("Framerate", ImGuiTreeNodeFlags_DefaultOpen))
25092332
{
25102333
ImGui::TreePush ("");

0 commit comments

Comments
 (0)