Fixed the game printing an incorrect item name in some cases

Minor fixes in Graphics.cpp and InputFuncs.cpp.
This commit is contained in:
NovaRain
2022-02-13 07:46:55 +08:00
parent 8b858b6cb9
commit 42afaa46ed
6 changed files with 36 additions and 25 deletions
@@ -509,6 +509,7 @@ FUNC(proto_dude_update_gender_, 0x49F984)
FUNC(proto_get_msg_info_, 0x49EAA4) FUNC(proto_get_msg_info_, 0x49EAA4)
FUNC(proto_list_str_, 0x49E758) FUNC(proto_list_str_, 0x49E758)
FUNC(proto_make_path_, 0x49E270) FUNC(proto_make_path_, 0x49E270)
FUNC(proto_name_, 0x49EAFC)
FUNC(proto_ptr_, 0x4A2108) // eax - PID, edx - int** - pointer to a pointer to a proto struct FUNC(proto_ptr_, 0x4A2108) // eax - PID, edx - int** - pointer to a pointer to a proto struct
FUNC(pushLongStack_, 0x46736C) FUNC(pushLongStack_, 0x46736C)
FUNC(qsort_, 0x4F05B6) FUNC(qsort_, 0x4F05B6)
+1
View File
@@ -116,6 +116,7 @@
#define FO_VAR_gmovie_played_list 0x596C78 #define FO_VAR_gmovie_played_list 0x596C78
#define FO_VAR_GNW_win_init_flag 0x51E3E0 #define FO_VAR_GNW_win_init_flag 0x51E3E0
#define FO_VAR_GNW95_hDDrawLib 0x51E44C #define FO_VAR_GNW95_hDDrawLib 0x51E44C
#define FO_VAR_GNW95_hwnd 0x51E434 // main hwnd window
#define FO_VAR_GNW95_isActive 0x51E444 #define FO_VAR_GNW95_isActive 0x51E444
#define FO_VAR_GNW95_repeat_delay 0x51E240 #define FO_VAR_GNW95_repeat_delay 0x51E240
#define FO_VAR_GNW95_repeat_rate 0x51E23C #define FO_VAR_GNW95_repeat_rate 0x51E23C
+5
View File
@@ -459,6 +459,11 @@ HRESULT __stdcall FakeDirectInputCreate(HINSTANCE a, DWORD b, IDirectInputA** c,
HRESULT hr = proc(a, b, c, d); HRESULT hr = proc(a, b, c, d);
if (FAILED(hr)) return hr; if (FAILED(hr)) return hr;
// Prevent "Failure initializing input devices" error
if (sfall::Graphics::IsWindowedMode && !sfall::backgroundMouse) {
SetForegroundWindow((HWND)fo::var::getInt(FO_VAR_GNW95_hwnd));
}
*c = (IDirectInputA*)new sfall::FakeDirectInput(*c); *c = (IDirectInputA*)new sfall::FakeDirectInput(*c);
sfall::keyboardLayout = GetKeyboardLayout(0); sfall::keyboardLayout = GetKeyboardLayout(0);
+22 -17
View File
@@ -34,12 +34,16 @@
namespace sfall namespace sfall
{ {
#define UNUSEDFUNCTION { return DDERR_GENERIC; }
#define SAFERELEASE(a) { if (a) { a->Release(); a = nullptr; } }
//typedef HRESULT (__stdcall *DDrawCreateProc)(void*, IDirectDraw**, void*); //typedef HRESULT (__stdcall *DDrawCreateProc)(void*, IDirectDraw**, void*);
//typedef IDirect3D9* (__stdcall *D3DCreateProc)(UINT version); //typedef IDirect3D9* (__stdcall *D3DCreateProc)(UINT version);
#define UNUSEDFUNCTION { return DDERR_GENERIC; }
#define SAFERELEASE(a) { if (a) { a->Release(); a = nullptr; } }
#define ShowMessageBox(text) ShowWindow(window, SW_MINIMIZE); \
MessageBoxA(window, text, "sfall DirectX 9", MB_TASKMODAL | MB_ICONWARNING); \
ShowWindow(window, SW_RESTORE)
#if !(NDEBUG) && !(_DEBUG) #if !(NDEBUG) && !(_DEBUG)
static LPD3DXFONT font; static LPD3DXFONT font;
static RECT fontPosition; static RECT fontPosition;
@@ -62,6 +66,7 @@ static DWORD gHeight;
DWORD Graphics::GPUBlt; DWORD Graphics::GPUBlt;
DWORD Graphics::mode; DWORD Graphics::mode;
bool Graphics::IsWindowedMode;
bool Graphics::PlayAviMovie = false; bool Graphics::PlayAviMovie = false;
bool Graphics::AviMovieWidthFit = false; bool Graphics::AviMovieWidthFit = false;
@@ -204,19 +209,14 @@ static void ResetDevice(bool create) {
DWORD mThreadFlags = (dShowMovies) ? D3DCREATE_MULTITHREADED : 0; DWORD mThreadFlags = (dShowMovies) ? D3DCREATE_MULTITHREADED : 0;
dlog("Creating D3D9 Device...", DL_MAIN); dlog("Creating D3D9 Device...", DL_MAIN);
if (FAILED(d3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window, D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE | mThreadFlags, &params, &d3d9Device))) { //D3DCREATE_PUREDEVICE if (FAILED(d3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window, D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE | mThreadFlags, &params, &d3d9Device))) { // D3DCREATE_PUREDEVICE
if (FAILED(d3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window, D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE | mThreadFlags, &params, &d3d9Device))) { if (FAILED(d3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window, D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE | mThreadFlags, &params, &d3d9Device))) {
d3d9Device = nullptr; d3d9Device = nullptr;
dlogr(" Failed!", DL_MAIN); dlogr(" Failed!", DL_MAIN);
return; return;
} }
software = true; software = true;
if (params.Windowed) { ShowMessageBox("Failed to create hardware vertex processing device.\nUsing software vertex processing instead.");
MessageBoxA(window, "Failed to create hardware vertex processing device.\nUsing software vertex processing instead.",
"sfall DirectX 9", MB_TASKMODAL | MB_ICONWARNING);
} else {
dlogr(" Failed to create hardware vertex processing device.\nUsing software vertex processing instead.", DL_MAIN);
}
} }
D3DCAPS9 caps; D3DCAPS9 caps;
@@ -245,8 +245,7 @@ static void ResetDevice(bool create) {
textureFormat = (A8IsSupported) ? D3DFMT_A8 : D3DFMT_L8; // D3DFMT_A8 - not supported on some older video cards textureFormat = (A8IsSupported) ? D3DFMT_A8 : D3DFMT_L8; // D3DFMT_A8 - not supported on some older video cards
} else { } else {
MessageBoxA(window, "Failed to create shader effects.\nSwitching to CPU for the palette conversion.", ShowMessageBox("Failed to create shader effects.\nSwitching to CPU for the palette conversion.");
"sfall DirectX 9", MB_TASKMODAL | MB_ICONWARNING);
if (mainTex) SAFERELEASE(mainTex); // release D3DFMT_A8 format texture if (mainTex) SAFERELEASE(mainTex); // release D3DFMT_A8 format texture
Graphics::GPUBlt = 0; Graphics::GPUBlt = 0;
A8IsSupported = false; A8IsSupported = false;
@@ -256,9 +255,8 @@ static void ResetDevice(bool create) {
if (!A8IsSupported && d3d9Device->CreateTexture(ResWidth, ResHeight, 1, 0, textureFormat, D3DPOOL_SYSTEMMEM, &mainTex, 0) != D3D_OK) { if (!A8IsSupported && d3d9Device->CreateTexture(ResWidth, ResHeight, 1, 0, textureFormat, D3DPOOL_SYSTEMMEM, &mainTex, 0) != D3D_OK) {
textureFormat = D3DFMT_X8R8G8B8; textureFormat = D3DFMT_X8R8G8B8;
d3d9Device->CreateTexture(ResWidth, ResHeight, 1, 0, textureFormat, D3DPOOL_SYSTEMMEM, &mainTex, 0); d3d9Device->CreateTexture(ResWidth, ResHeight, 1, 0, textureFormat, D3DPOOL_SYSTEMMEM, &mainTex, 0);
MessageBoxA(window, "Texture format error.\nGPU does not support the D3DFMT_L8 texture format.\nNow CPU is used to convert the palette.\n" ShowMessageBox("Texture format error.\nGPU does not support the D3DFMT_L8 texture format.\nNow CPU is used to convert the palette.\n"
"Set 'GPUBlt' option to CPU to bypass this warning message.", "Set 'GPUBlt' option to CPU to bypass this warning message.");
"sfall DirectX 9", MB_TASKMODAL | MB_ICONWARNING);
Graphics::GPUBlt = 0; Graphics::GPUBlt = 0;
} }
if (Graphics::GPUBlt == 0) palette = new PALCOLOR[256]; if (Graphics::GPUBlt == 0) palette = new PALCOLOR[256];
@@ -977,7 +975,7 @@ public:
ULONG __stdcall AddRef() { return ++Refs; } ULONG __stdcall AddRef() { return ++Refs; }
ULONG __stdcall Release() { // called from game on exit ULONG __stdcall Release() { // called from GNW95_reset_mode_ (on game exit)
if (!--Refs) { if (!--Refs) {
ScriptShaders::Release(); ScriptShaders::Release();
@@ -1038,7 +1036,13 @@ public:
HRESULT __stdcall GetScanLine(LPDWORD) { UNUSEDFUNCTION; } HRESULT __stdcall GetScanLine(LPDWORD) { UNUSEDFUNCTION; }
HRESULT __stdcall GetVerticalBlankStatus(LPBOOL) { UNUSEDFUNCTION; } HRESULT __stdcall GetVerticalBlankStatus(LPBOOL) { UNUSEDFUNCTION; }
HRESULT __stdcall Initialize(GUID *) { UNUSEDFUNCTION; } HRESULT __stdcall Initialize(GUID *) { UNUSEDFUNCTION; }
HRESULT __stdcall RestoreDisplayMode() { return DD_OK; }
HRESULT __stdcall RestoreDisplayMode() { // called from GNW95_reset_mode_
#ifdef NDEBUG
ShowWindow(window, SW_HIDE);
#endif
return DD_OK;
}
HRESULT __stdcall SetCooperativeLevel(HWND a, DWORD b) { // called 0x4CB005 GNW95_init_DirectDraw_ HRESULT __stdcall SetCooperativeLevel(HWND a, DWORD b) { // called 0x4CB005 GNW95_init_DirectDraw_
window = a; window = a;
@@ -1467,6 +1471,7 @@ void Graphics::init() {
if (Graphics::mode < 4 || Graphics::mode > 6) { if (Graphics::mode < 4 || Graphics::mode > 6) {
Graphics::mode = 0; Graphics::mode = 0;
} }
IsWindowedMode = (mode > 4);
if (Graphics::mode) { if (Graphics::mode) {
dlog("Applying DX9 graphics patch.", DL_INIT); dlog("Applying DX9 graphics patch.", DL_INIT);
+1
View File
@@ -37,6 +37,7 @@ public:
static DWORD mode; static DWORD mode;
static DWORD GPUBlt; static DWORD GPUBlt;
static bool IsWindowedMode;
static long GetGameWidthRes(); static long GetGameWidthRes();
static long GetGameHeightRes(); static long GetGameHeightRes();
+6 -8
View File
@@ -1059,7 +1059,7 @@ void ObjectName::SetName(long sid, const char* name) {
const char* __stdcall ObjectName::GetName(fo::GameObject* object) { const char* __stdcall ObjectName::GetName(fo::GameObject* object) {
if (!overrideScrName.empty()) { if (!overrideScrName.empty()) {
std::tr1::unordered_map<int, std::string>::iterator name = overrideScrName.find(object->scriptId); std::tr1::unordered_map<int, std::string>::iterator &name = overrideScrName.find(object->scriptId);
if (name != overrideScrName.cend()) { if (name != overrideScrName.cend()) {
return (name->second.length() > 0) return (name->second.length() > 0)
? name->second.c_str() ? name->second.c_str()
@@ -1121,14 +1121,12 @@ static void __declspec(naked) critter_name_hack_end() {
} }
} }
static void __declspec(naked) object_name_hook() { static void __declspec(naked) item_name_hook() {
using namespace fo::Fields;
__asm { __asm {
mov edx, [eax + protoId]; cmp eax, lastItemPid;
cmp edx, lastItemPid;
je getLast; je getLast;
mov lastItemPid, edx; mov lastItemPid, eax;
jmp fo::funcoffs::item_name_; jmp fo::funcoffs::proto_name_;
getLast: getLast:
mov eax, ds:[FO_VAR_name_item]; mov eax, ds:[FO_VAR_name_item];
retn; retn;
@@ -1219,7 +1217,7 @@ void ScriptExtender::init() {
// Tweak for quickly getting last object name // Tweak for quickly getting last object name
MakeCall(0x42D0C4, critter_name_hack_check, 1); MakeCall(0x42D0C4, critter_name_hack_check, 1);
MakeCall(0x42D12A, critter_name_hack_end); MakeCall(0x42D12A, critter_name_hack_end);
HookCall(0x48C901, object_name_hook); HookCall(0x477AE7, item_name_hook);
} }
} }