Skip to content

Commit

Permalink
rewrite xmm asm
Browse files Browse the repository at this point in the history
  • Loading branch information
ThirteenAG committed May 23, 2024
1 parent c356baa commit 702e1e3
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 63 deletions.
8 changes: 2 additions & 6 deletions source/LARush.WidescreenFix/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,8 @@ void Init()
{
void operator()(injector::reg_pack& regs)
{
float _xmm1 = 0.0f, _xmm2 = 0.0f;
_asm {movss dword ptr ds : [_xmm1], xmm1}
_asm {movss dword ptr ds : [_xmm2], xmm2}

*(float*)(regs.esi + 0x0C) = _xmm2;
*(float*)(regs.esi + 0x10) = _xmm1;
*(float*)(regs.esi + 0x0C) = regs.xmm2.f32[0];
*(float*)(regs.esi + 0x10) = regs.xmm1.f32[0];

auto ret = *(uint32_t*)(regs.esp + 0x28);
if (ret == ret_551F3B)
Expand Down
6 changes: 2 additions & 4 deletions source/MassEffectTrilogy.FOVFix/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ void InitME1()
f *= 100.0f;
f = AdjustFOV(f, static_cast<float>(nWidth) / static_cast<float>(nHeight));
f /= 100.0f;
_asm {fld dword ptr[f]}
_asm {fstp dword ptr[f]}
*(float*)(regs.esp + 0x00) = f;
}
}; injector::MakeInline<FOVHook>(pattern.get_first(0), pattern.get_first(7));
Expand Down Expand Up @@ -57,7 +55,7 @@ void InitME2()
float f = (*(float *)(regs.ebx + 0x204) - *(float *)(regs.eax + 0x204)) + *(float *)(regs.esi + 0x18);
if (*dword_126A26C == 0 /*|| bIsNotDialogue*/)
f = AdjustFOV(f, static_cast<float>(nWidth) / static_cast<float>(nHeight));
_asm {movss xmm0, dword ptr[f]}
regs.xmm0.f32[0] = f;
//bIsNotDialogue = false;
}
}; injector::MakeInline<FOVHook>(pattern.get_first(0));
Expand Down Expand Up @@ -92,7 +90,7 @@ void InitME3()
void operator()(injector::reg_pack& regs)
{
float f = *(float*)(regs.ecx + 0x70);
_asm {movss xmm0, dword ptr[f]}
regs.xmm0.f32[0] = f;
bIsDialogue2 = (*(uint32_t*)(regs.ecx + 0x70) == 0x4039999A && bIsDialogue1); //2.900000095
}
}; injector::MakeInline<DialogueCheck2>(pattern.get_first(0));
Expand Down
31 changes: 8 additions & 23 deletions source/NFSProStreet.GenericFix/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,25 +692,18 @@ void Init()
// Real-Time Aspect Ratio Calculation
static uint32_t* dword_BBADB4 = *hook::pattern("C7 05 ? ? ? ? 03 00 00 00 89 3D ? ? ? ? 89 3D").get(0).get<uint32_t*>(35); // ResX
static uint32_t* dword_BBADB8 = *hook::pattern("C7 05 ? ? ? ? 03 00 00 00 89 3D ? ? ? ? 89 3D").get(0).get<uint32_t*>(41); // ResY
static float fScreenAspectRatio, temp_xmm0;
static float fScreenAspectRatio;

auto pattern = hook::pattern("F3 0F 10 05 ? ? ? ? F3 0F 11 04 24 D9 04 24 83 C4 0C");
struct AspectRatioHook
{
void operator()(injector::reg_pack& regs)
{
_asm movss dword ptr ds : [temp_xmm0], xmm0 // moves xmm0 to temporary location so contents aren't lost
auto ResX = *(float*)(dword_BBADB4);
auto ResY = *(float*)(dword_BBADB8);
auto esp00 = regs.esp;
fScreenAspectRatio = (ResX / ResY) * 0.5625f;

_asm
{
movss xmm0, dword ptr ds : [temp_xmm0] // restores xmm0
movss dword ptr ds : [esp00], xmm0
fld dword ptr ds : [esp00]
}
auto f = regs.xmm0.f32[0];
_asm { fld dword ptr ds : [f] }
}
}; injector::MakeInline<AspectRatioHook>(pattern.get_first(8), pattern.get_first(16)); // 4BCB35

Expand Down Expand Up @@ -738,19 +731,15 @@ void Init()
{
void operator()(injector::reg_pack& regs)
{
_asm movss dword ptr ds : [temp_xmm0], xmm0 // moves xmm0 to temporary location so contents aren't lost
int ebp08 = *(int*)(regs.ebp + 0x08);
float esp48 = *(float*)(regs.esp + 0x48);

if (ebp08 <= 0x19) // jump if greater than
*(float*)(regs.esp + 0x48) = (esp48 / fScreenAspectRatio);

_asm
{
movss xmm0, dword ptr ds : [temp_xmm0] // restores xmm0
xorps xmm0, xmm0
movss xmm1, dword ptr ds : [dword_9FA868]
}
regs.xmm0.f64[0] = 0.0f;
regs.xmm0.f64[1] = 0.0f;
regs.xmm1.f32[0] = dword_9FA868;
}
}; injector::MakeInline<FOVHook>(pattern.get_first(0), pattern.get_first(11)); // 6FFB1A

Expand Down Expand Up @@ -939,7 +928,7 @@ void Init()
}

*(float*)(regs.esp + 0x14) *= Xscale;
_asm movss xmm0, ds: [Yscale] ;
regs.xmm0.f32[0] = Yscale;
}
}; injector::MakeInline<FEScaleHook>(loc_4B4518, loc_4B4518 + 8);

Expand Down Expand Up @@ -1000,11 +989,7 @@ void Init()
auto GammaFloat = *(float*)(dword_AA9630);
NewBrightness = 100.0f / (GammaInteger * 2.0f);
GammaFloat = NewBrightness;

_asm
{
movss xmm0, [GammaFloat]
}
regs.xmm0.f32[0] = GammaFloat;
}
}; injector::MakeInline<GammaHook>(pattern.count(1).get(0).get<uint32_t>(9), pattern.count(1).get(0).get<uint32_t>(17)); // 4B3E89
}
Expand Down
2 changes: 1 addition & 1 deletion source/NFSUndercover.GenericFix/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ void Init4()
float esp38 = *(float*)(regs.esp + 0x38);
*(float*)(regs.esp + 0x38) = (esp38 * fHudScale);
esp38 = *(float*)(regs.esp + 0x38);
_asm movss xmm0, esp38
regs.xmm0.f32[0] = esp38;
}
}; injector::MakeInline<FOVHook>(pattern.get_first(0), pattern.get_first(6));

Expand Down
4 changes: 2 additions & 2 deletions source/Onimusha3.WidescreenFix/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ void Init()
|| (*(uint32_t*)(0x02ADB7B8 + 0x0) == 100 && *(uint32_t*)(0x02ADB7B8 + 0x8) == 70 && (*(uint32_t*)(0x02ADB7B8 + 0x38) == 524288 || *(uint32_t*)(0x02ADB7B8 + 0x38) == 524296) && (*(uint32_t*)(0x02ADB7B8 + 0xB8) == 65536)) //cutscene fading
|| (*(uint32_t*)(0x02ADB7B8 + 0x0) == 68 && *(uint32_t*)(0x02ADB7B8 + 0x4) == 0 && *(uint32_t*)(0x02ADB7B8 + 0x8) == 6) //player shadow
)
_asm movss xmm5, f2
regs.xmm5.f32[0] = f2;
else
_asm movss xmm5, Screen.f3DHorScale
regs.xmm5.f32[0] = Screen.f3DHorScale;
}
}; injector::MakeInline<Set2DScale>(pattern.get_first(0), pattern.get_first(8));

Expand Down
35 changes: 9 additions & 26 deletions source/SplinterCellDoubleAgent.WidescreenFix/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,9 +627,7 @@ void InitD3DDrv()
*(uint32_t*)(regs.ebx + 0x3C) = regs.edi;
}
}
static float _xmm0 = 0.0f;
_asm movss dword ptr[_xmm0], xmm0
*(float*)(regs.esp + 0x18) = _xmm0;
*(float*)(regs.esp + 0x18) = regs.xmm0.f32[0];
}
}; injector::MakeInline<RenderFilmstrip_Hook3>(pattern.get_first(4), pattern.get_first(10));

Expand Down Expand Up @@ -783,14 +781,8 @@ void InitEngine()
{
void operator()(injector::reg_pack& regs)
{
static const float f1_0 = 1.0f;
_asm
{
movss xmm0, Screen.fHudOffset
subss xmm3, xmm0
addss xmm3, xmm4
movss xmm0, f1_0
}
regs.xmm3.f32[0] -= Screen.fHudOffset;
regs.xmm3.f32[0] += regs.xmm4.f32[0];
}
}; injector::MakeInline<HUDPosHook>(pattern.get_first(0), pattern.get_first(8));

Expand All @@ -799,13 +791,7 @@ void InitEngine()
{
void operator()(injector::reg_pack& regs)
{
auto regs_ecx = regs.ecx;
_asm
{
cvtsi2ss xmm2, regs_ecx
movss xmm2, Screen.fTextScaleX
divss xmm1, xmm2
}
regs.xmm1.f32[0] /= Screen.fTextScaleX;
}
}; injector::MakeInline<TextHook>(pattern.get_first(-4), pattern.get_first(4));

Expand All @@ -817,13 +803,10 @@ void InitEngine()
{
void operator()(injector::reg_pack& regs)
{
auto f3 = 0.0f;
auto f3 = regs.xmm3.f32[0];
auto f4 = *(float*)(regs.esp + 0x24);
auto f5 = 0.0f;
auto f6 = 0.0f;
_asm { movss dword ptr ds : f3, xmm3}
_asm { movss dword ptr ds : f5, xmm5}
_asm { movss dword ptr ds : f6, xmm6}
auto f5 = regs.xmm5.f32[0];
auto f6 = regs.xmm6.f32[0];

if (!*GIsWideScreen && *GIsSameFrontBufferOnNormalTV)
{
Expand Down Expand Up @@ -941,8 +924,8 @@ void InitEchelonMenus()
//auto pattern = hook::module_pattern(GetModuleHandle(L"EchelonMenus"), "83 F8 05 0F 87");
//injector::ReadMemoryRaw(pattern.get_first(3), asm_code, sizeof(asm_code), true);
//injector::MakeNOP(pattern.get_first(3), 13);
keybd_event(VK_RETURN, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0);
keybd_event(VK_RETURN, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
//keybd_event(VK_RETURN, 0x45, KEYEVENTF_EXTENDEDKEY | 0, 0);
//keybd_event(VK_RETURN, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
//injector::WriteMemoryRaw(pattern.get_first(3), asm_code, sizeof(asm_code), true);
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion source/TrueCrimeNewYorkCity.WidescreenFix/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ void Init()
void operator()(injector::reg_pack& regs)
{
Screen.fFieldOfView = *(float*)(regs.ebp + 0x8) * (((4.0f / 3.0f)) / (Screen.fAspectRatio));
_asm movss xmm0, dword ptr[Screen.fFieldOfView]
regs.xmm0.f32[0] = Screen.fFieldOfView;
}
}; injector::MakeInline<FOVHook>(pattern.get_first(0));
}
Expand Down

0 comments on commit 702e1e3

Please sign in to comment.