mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
100 lines
2.9 KiB
C++
100 lines
2.9 KiB
C++
/*
|
|
* sfall
|
|
* Copyright (C) 2010 The sfall team
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
//#define WIN32_LEAN_AND_MEAN
|
|
#include <Windows.h>
|
|
#include "SafeWrite.h"
|
|
#include "Logging.h"
|
|
#if (_MSC_VER < 1600)
|
|
#include "Cpp11_emu.h"
|
|
#endif
|
|
|
|
struct ddrawDll {
|
|
HMODULE dll;
|
|
FARPROC DirectDrawEnumerateExA;
|
|
FARPROC DirectDrawCreate;
|
|
FARPROC DirectDrawCreateEx;
|
|
FARPROC AcquireDDThreadLock;
|
|
FARPROC ReleaseDDThreadLock;
|
|
FARPROC CheckFullscreen;
|
|
FARPROC CompleteCreateSysmemSurface;
|
|
FARPROC D3DParseUnknownCommand;
|
|
FARPROC DDGetAttachedSurfaceLcl;
|
|
FARPROC DDInternalLock;
|
|
FARPROC DDInternalUnlock;
|
|
FARPROC DSoundHelp;
|
|
FARPROC DirectDrawCreateClipper;
|
|
FARPROC DirectDrawEnumerateA;
|
|
FARPROC DirectDrawEnumerateExW;
|
|
FARPROC DirectDrawEnumerateW;
|
|
//FARPROC DllCanUnloadNow;
|
|
//FARPROC DllGetClassObject;
|
|
FARPROC GetDDSurfaceLocal;
|
|
FARPROC GetOLEThunkData;
|
|
FARPROC GetSurfaceFromDC;
|
|
FARPROC RegisterSpecialCase;
|
|
};
|
|
|
|
// global flag, indicating that debugging features of Sfall are enabled
|
|
#ifndef NO_SFALL_DEBUG
|
|
extern bool IsDebug;
|
|
#else
|
|
#define IsDebug false
|
|
#endif
|
|
|
|
// Macros for quick replacement of pushad/popad assembler opcodes
|
|
#define pushadc __asm push eax __asm push edx __asm push ecx
|
|
#define popadc __asm pop ecx __asm pop edx __asm pop eax
|
|
|
|
extern char ini[65];
|
|
extern char translationIni[65];
|
|
extern DWORD modifiedIni;
|
|
|
|
extern char dmModelName[65];
|
|
extern char dfModelName[65];
|
|
|
|
void RemoveSavFiles();
|
|
void ClearSavPrototypes();
|
|
|
|
template<typename T>
|
|
T SimplePatch(DWORD addr, const char* iniSection, const char* iniKey, T defaultValue, T minValue = 0, T maxValue = INT_MAX)
|
|
{
|
|
return SimplePatch<T>(&addr, 1, iniSection, iniKey, defaultValue, minValue, maxValue);
|
|
}
|
|
|
|
template<typename T>
|
|
T SimplePatch(DWORD *addrs, int numAddrs, const char* iniSection, const char* iniKey, T defaultValue, T minValue = 0, T maxValue = INT_MAX)
|
|
{
|
|
T value;
|
|
char msg[255];
|
|
value = (T)GetPrivateProfileIntA(iniSection, iniKey, defaultValue, ini);
|
|
if (value != defaultValue) {
|
|
if (value < minValue)
|
|
value = minValue;
|
|
else if (value > maxValue)
|
|
value = maxValue;
|
|
_snprintf_s(msg, sizeof(msg), _TRUNCATE, "Applying patch: %s = %d.", iniKey, value);
|
|
dlog((const char *)msg, DL_INIT);
|
|
for (int i=0; i<numAddrs; i++)
|
|
SafeWrite<T>(addrs[i], (T)value);
|
|
dlogr(" Done", DL_INIT);
|
|
}
|
|
return value;
|
|
} |