From efd49962d281c1c32aff300cd7fb5f9e24c28571 Mon Sep 17 00:00:00 2001 From: aap Date: Mon, 20 Jul 2020 19:32:20 +0200 Subject: avoid UB --- src/core/Camera.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/core') diff --git a/src/core/Camera.cpp b/src/core/Camera.cpp index 340dbaee..44749fd7 100644 --- a/src/core/Camera.cpp +++ b/src/core/Camera.cpp @@ -3622,7 +3622,7 @@ bool CCamera::IsPointVisible(const CVector ¢er, const CMatrix *mat) { RwV3d c; - c = *(RwV3d*)¢er; + c = center; RwV3dTransformPoints(&c, &c, 1, &mat->m_matrix); if(c.y < CDraw::GetNearClipZ()) return false; if(c.y > CDraw::GetFarClipZ()) return false; @@ -3637,7 +3637,7 @@ bool CCamera::IsSphereVisible(const CVector ¢er, float radius, const CMatrix *mat) { RwV3d c; - c = *(RwV3d*)¢er; + c = center; RwV3dTransformPoints(&c, &c, 1, &mat->m_matrix); if(c.y + radius < CDraw::GetNearClipZ()) return false; if(c.y - radius > CDraw::GetFarClipZ()) return false; -- cgit v1.2.3 From 70df13f9d34fd855b78f74d7f1da8423241f8b01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Mon, 20 Jul 2020 22:47:41 +0300 Subject: Fixes from miami --- src/core/Frontend.cpp | 18 +++++++++--------- src/core/Frontend.h | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'src/core') diff --git a/src/core/Frontend.cpp b/src/core/Frontend.cpp index e67e939a..6e4e8917 100644 --- a/src/core/Frontend.cpp +++ b/src/core/Frontend.cpp @@ -956,10 +956,10 @@ CMenuManager::Draw() CFont::SetDropShadowPosition(0); if (!CheckHover(MENU_X(30.0f), MENU_X(30.0f) + CFont::GetStringWidth(backTx), SCREEN_SCALE_FROM_BOTTOM(125.0f), SCREEN_SCALE_FROM_BOTTOM(105.0f))) { m_nHoverOption = HOVEROPTION_NOT_HOVERING; - m_nCurrOption = m_nPrevOption = 0; + m_nCurrOption = m_nOptionMouseHovering = 0; } else { m_nHoverOption = HOVEROPTION_RANDOM_ITEM; - m_nCurrOption = m_nPrevOption = 1; + m_nCurrOption = m_nOptionMouseHovering = 1; } return; } @@ -1256,7 +1256,7 @@ CMenuManager::Draw() static int oldOption = -99; static int oldScreen = m_nCurrScreen; - m_nPrevOption = rowToCheck; + m_nOptionMouseHovering = rowToCheck; if (m_nMouseOldPosX != m_nMousePosX || m_nMouseOldPosY != m_nMousePosY) { m_nCurrOption = rowToCheck; m_bShowMouse = true; @@ -1980,10 +1980,10 @@ CMenuManager::DrawControllerSetupScreen() float curOptY = i * rowHeight + yStart; if (m_nMousePosY > MENU_Y(curOptY) && m_nMousePosY < MENU_Y(rowHeight + curOptY)) { - if (m_nPrevOption != i && m_nCurrExLayer == HOVEROPTION_LIST) + if (m_nOptionMouseHovering != i && m_nCurrExLayer == HOVEROPTION_LIST) DMAudio.PlayFrontEndSound(SOUND_FRONTEND_MENU_NAVIGATION, 0); - m_nPrevOption = i; + m_nOptionMouseHovering = i; if (m_nMouseOldPosX != m_nMousePosX || m_nMouseOldPosY != m_nMousePosY) { m_nCurrExLayer = HOVEROPTION_LIST; m_nSelectedListRow = i; @@ -2694,7 +2694,7 @@ CMenuManager::DrawPlayerSetupScreen() if (m_nMousePosX > MENU_X_LEFT_ALIGNED(PLAYERSETUP_LIST_LEFT) && m_nMousePosX < MENU_X_RIGHT_ALIGNED(PLAYERSETUP_LIST_RIGHT)) { if (m_nMousePosY > MENU_Y(rowStartY) && m_nMousePosY < MENU_Y(rowEndY)) { - m_nPrevOption = rowIdx; + m_nOptionMouseHovering = rowIdx; if (m_nMouseOldPosX != m_nMousePosX || m_nMouseOldPosY != m_nMousePosY) { m_nCurrExLayer = HOVEROPTION_LIST; } @@ -4025,7 +4025,7 @@ CMenuManager::ProcessButtonPresses(void) if (aScreens[m_nCurrScreen].m_aEntries[m_nCurrOption].m_Action == MENUACTION_RESUME && #endif (m_nHoverOption == HOVEROPTION_RANDOM_ITEM)) { - m_nCurrOption = m_nPrevOption; + m_nCurrOption = m_nOptionMouseHovering; optionSelected = true; } } else if (CPad::GetPad(0)->GetLeftMouseJustDown()) { @@ -4039,7 +4039,7 @@ CMenuManager::ProcessButtonPresses(void) OutputDebugString("FRONTEND RADIO STATION CHANGED"); } else if (m_nHoverOption == HOVEROPTION_RANDOM_ITEM && aScreens[m_nCurrScreen].m_aEntries[m_nCurrOption].m_Action != MENUACTION_RESUME) { - m_nCurrOption = m_nPrevOption; + m_nCurrOption = m_nOptionMouseHovering; optionSelected = true; } #else @@ -4126,7 +4126,7 @@ CMenuManager::ProcessButtonPresses(void) break; case HOVEROPTION_RANDOM_ITEM: if (((m_nCurrOption != 0) || (m_nCurrScreen != MENUPAGE_PAUSE_MENU)) { - m_nCurrOption = m_nPrevOption; + m_nCurrOption = m_nOptionMouseHovering; optionSelected = true; } break; diff --git a/src/core/Frontend.h b/src/core/Frontend.h index 758e29aa..7b0e2f4b 100644 --- a/src/core/Frontend.h +++ b/src/core/Frontend.h @@ -518,7 +518,7 @@ public: int32 m_nHoverOption; int32 m_nCurrScreen; int32 m_nCurrOption; - int32 m_nPrevOption; + int32 m_nOptionMouseHovering; int32 m_nPrevScreen; uint32 field_558; int32 m_nCurrSaveSlot; -- cgit v1.2.3 From 7d51995640c6ad822c983249acf7aa765aa055b8 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Wed, 22 Jul 2020 03:23:12 +0300 Subject: Remove hacky way of injecting PS2 matfx on RW 3.3, remove static patcher --- src/core/Game.cpp | 6 +++ src/core/patcher.cpp | 94 --------------------------------- src/core/patcher.h | 144 --------------------------------------------------- src/core/re3.cpp | 1 - 4 files changed, 6 insertions(+), 239 deletions(-) delete mode 100644 src/core/patcher.cpp delete mode 100644 src/core/patcher.h (limited to 'src/core') diff --git a/src/core/Game.cpp b/src/core/Game.cpp index fe073d29..f6275133 100644 --- a/src/core/Game.cpp +++ b/src/core/Game.cpp @@ -149,6 +149,10 @@ CGame::InitialiseOnceBeforeRW(void) return true; } +#if !defined(LIBRW) && defined(PS2_MATFX) +void ReplaceMatFxCallback(); +#endif + bool CGame::InitialiseRenderWare(void) { @@ -199,6 +203,8 @@ CGame::InitialiseRenderWare(void) #else rw::MatFX::modulateEnvMap = false; #endif +#elif defined(PS2_MATFX) + ReplaceMatFxCallback(); #endif CFont::Initialise(); diff --git a/src/core/patcher.cpp b/src/core/patcher.cpp deleted file mode 100644 index 83e06886..00000000 --- a/src/core/patcher.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#define WITHWINDOWS -#include "common.h" -#include "patcher.h" - -#include -#include - -StaticPatcher *StaticPatcher::ms_head; - -StaticPatcher::StaticPatcher(Patcher func) - : m_func(func) -{ - m_next = ms_head; - ms_head = this; -} - -void -StaticPatcher::Apply() -{ - StaticPatcher *current = ms_head; - while(current){ - current->Run(); - current = current->m_next; - } - ms_head = nil; -} -#ifdef _WIN32 -std::vector usedAddresses; - -static DWORD protect[2]; -static uint32 protect_address; -static uint32 protect_size; - -void -Protect_internal(uint32 address, uint32 size) -{ - protect_address = address; - protect_size = size; - VirtualProtect((void*)address, size, PAGE_EXECUTE_READWRITE, &protect[0]); -} - -void -Unprotect_internal(void) -{ - VirtualProtect((void*)protect_address, protect_size, protect[0], &protect[1]); -} - -void -InjectHook_internal(uint32 address, uint32 hook, int type) -{ - if(std::any_of(usedAddresses.begin(), usedAddresses.end(), - [address](uint32 value) { return value == address; })) { - debug("Used address %#06x twice when injecting hook\n", address); - } - - usedAddresses.push_back(address); - - - switch(type){ - case PATCH_JUMP: - VirtualProtect((void*)address, 5, PAGE_EXECUTE_READWRITE, &protect[0]); - *(uint8*)address = 0xE9; - break; - case PATCH_CALL: - VirtualProtect((void*)address, 5, PAGE_EXECUTE_READWRITE, &protect[0]); - *(uint8*)address = 0xE8; - break; - default: - VirtualProtect((void*)(address + 1), 4, PAGE_EXECUTE_READWRITE, &protect[0]); - break; - } - - *(ptrdiff_t*)(address + 1) = hook - address - 5; - if(type == PATCH_NOTHING) - VirtualProtect((void*)(address + 1), 4, protect[0], &protect[1]); - else - VirtualProtect((void*)address, 5, protect[0], &protect[1]); -} -#else -void -Protect_internal(uint32 address, uint32 size) -{ -} - -void -Unprotect_internal(void) -{ -} - -void -InjectHook_internal(uint32 address, uint32 hook, int type) -{ -} -#endif diff --git a/src/core/patcher.h b/src/core/patcher.h deleted file mode 100644 index 2722b6fd..00000000 --- a/src/core/patcher.h +++ /dev/null @@ -1,144 +0,0 @@ -#pragma once - -#define WRAPPER __declspec(naked) -#define DEPRECATED __declspec(deprecated) -#define EAXJMP(a) { _asm mov eax, a _asm jmp eax } -#define VARJMP(a) { _asm jmp a } -#define WRAPARG(a) UNREFERENCED_PARAMETER(a) - -#include //memset - -enum -{ - PATCH_CALL, - PATCH_JUMP, - PATCH_NOTHING, -}; - -enum -{ - III_10 = 1, - III_11, - III_STEAM, - VC_10, - VC_11, - VC_STEAM -}; - -extern int gtaversion; - -class StaticPatcher -{ -private: - using Patcher = void(*)(); - - Patcher m_func; - StaticPatcher *m_next; - static StaticPatcher *ms_head; - - void Run() { m_func(); } -public: - StaticPatcher(Patcher func); - static void Apply(); -}; - -template -inline T AddressByVersion(uint32_t addressIII10, uint32_t addressIII11, uint32_t addressIIISteam, uint32_t addressvc10, uint32_t addressvc11, uint32_t addressvcSteam) -{ - if(gtaversion == -1){ - if(*(uint32_t*)0x5C1E75 == 0xB85548EC) gtaversion = III_10; - else if(*(uint32_t*)0x5C2135 == 0xB85548EC) gtaversion = III_11; - else if(*(uint32_t*)0x5C6FD5 == 0xB85548EC) gtaversion = III_STEAM; - else if(*(uint32_t*)0x667BF5 == 0xB85548EC) gtaversion = VC_10; - else if(*(uint32_t*)0x667C45 == 0xB85548EC) gtaversion = VC_11; - else if(*(uint32_t*)0x666BA5 == 0xB85548EC) gtaversion = VC_STEAM; - else gtaversion = 0; - } - switch(gtaversion){ - case III_10: - return (T)addressIII10; - case III_11: - return (T)addressIII11; - case III_STEAM: - return (T)addressIIISteam; - case VC_10: - return (T)addressvc10; - case VC_11: - return (T)addressvc11; - case VC_STEAM: - return (T)addressvcSteam; - default: - return (T)0; - } -} - -inline bool -is10(void) -{ - return gtaversion == III_10 || gtaversion == VC_10; -} - -inline bool -isIII(void) -{ - return gtaversion >= III_10 && gtaversion <= III_STEAM; -} - -inline bool -isVC(void) -{ - return gtaversion >= VC_10 && gtaversion <= VC_STEAM; -} - -#define PTRFROMCALL(addr) (uint32_t)(*(uint32_t*)((uint32_t)addr+1) + (uint32_t)addr + 5) -#define INTERCEPT(saved, func, a) \ -{ \ - saved = PTRFROMCALL(a); \ - InjectHook(a, func); \ -} - -void InjectHook_internal(uint32 address, uint32 hook, int type); -void Protect_internal(uint32 address, uint32 size); -void Unprotect_internal(void); - -template inline void -Patch(AT address, T value) -{ - Protect_internal((uint32)address, sizeof(T)); - *(T*)address = value; - Unprotect_internal(); -} - -template inline void -Nop(AT address, unsigned int nCount) -{ - Protect_internal((uint32)address, nCount); - memset((void*)address, 0x90, nCount); - Unprotect_internal(); -} - -template inline void -InjectHook(uintptr_t address, T hook, unsigned int nType = PATCH_NOTHING) -{ - InjectHook_internal(address, reinterpret_cast((void *&)hook), nType); -} - -inline void ExtractCall(void *dst, uint32_t a) -{ - *(uint32_t*)dst = (uint32_t)(*(uint32_t*)(a+1) + a + 5); -} -template -inline void InterceptCall(void *dst, T func, uint32_t a) -{ - ExtractCall(dst, a); - InjectHook(a, func); -} -template -inline void InterceptVmethod(void *dst, T func, uint32_t a) -{ - *(uint32_t*)dst = *(uint32_t*)a; - Patch(a, func); -} - -#define STARTPATCHES static StaticPatcher Patcher([](){ -#define ENDPATCHES }); diff --git a/src/core/re3.cpp b/src/core/re3.cpp index d6319f3a..8c0020d0 100644 --- a/src/core/re3.cpp +++ b/src/core/re3.cpp @@ -2,7 +2,6 @@ #define WITHWINDOWS #include "common.h" #include "crossplatform.h" -#include "patcher.h" #include "Renderer.h" #include "Credits.h" #include "Camera.h" -- cgit v1.2.3