Code cleanup and edits before merging

This commit is contained in:
NovaRain
2021-12-19 08:42:36 +08:00
parent 53be017f0b
commit 92a24a6112
7 changed files with 76 additions and 83 deletions
+3 -3
View File
@@ -494,7 +494,7 @@ void PrintFloatText(fo::GameObject* object, const char* text, long colorText, lo
// print text to surface
void PrintText(char* displayText, BYTE colorIndex, DWORD xPos, DWORD yPos, DWORD txtWidth, DWORD toWidth, BYTE* toSurface) {
DWORD posOffset = yPos * toWidth + xPos;
DWORD posOffset = (yPos * toWidth) + xPos;
__asm {
xor eax, eax;
mov al, colorIndex;
@@ -504,12 +504,12 @@ void PrintText(char* displayText, BYTE colorIndex, DWORD xPos, DWORD yPos, DWORD
mov eax, toSurface;
mov ecx, toWidth;
add eax, posOffset;
call dword ptr ds:[FO_VAR_text_to_buf];
call dword ptr ds:[FO_VAR_text_to_buf]; // calls FMtext_to_buf_ or GNW_text_to_buf_
}
}
void PrintTextFM(const char* displayText, BYTE colorIndex, DWORD xPos, DWORD yPos, DWORD txtWidth, DWORD toWidth, BYTE* toSurface) {
DWORD posOffset = yPos * toWidth + xPos;
DWORD posOffset = (yPos * toWidth) + xPos;
__asm {
xor eax, eax;
mov al, colorIndex;
+13 -12
View File
@@ -148,17 +148,6 @@ static void __stdcall SplitPrintMessage(char* message, void* printFunc) {
}
}
static void __declspec(naked) sf_display_print_alt() {
__asm {
push ecx;
push fo::funcoffs::display_print_;
push eax; // message
call SplitPrintMessage;
pop ecx;
retn;
}
}
static void __declspec(naked) sf_inven_display_msg() {
__asm {
push ecx;
@@ -170,12 +159,24 @@ static void __declspec(naked) sf_inven_display_msg() {
}
}
static void __declspec(naked) sf_display_print_alt() {
__asm {
push ecx;
push fo::funcoffs::display_print_; // func replaced by HRP
push eax; // message
call SplitPrintMessage;
pop ecx;
retn;
}
}
void Text::init() {
// Support for the newline control character '\n' in the object description in pro_*.msg files
void* printFunc = sf_display_print; // for vanilla and HRP 4.1.8
if (sf::versionCHI || (sf::hrpIsEnabled && !sf::hrpVersionValid)) {
printFunc = sf_display_print_alt;
}
// Support for the newline control character '\n' in the object description in pro_*.msg files
sf::SafeWriteBatch<DWORD>((DWORD)printFunc, {0x46ED87, 0x49AD7A}); // setup_inventory_, obj_examine_
sf::SafeWrite32(0x472F9A, (DWORD)&sf_inven_display_msg); // inven_obj_examine_func_
}
+26 -55
View File
@@ -56,11 +56,7 @@ DWORD Graphics::mode;
bool Graphics::PlayAviMovie = false;
bool Graphics::AviMovieWidthFit = false;
//static DWORD yoffset;
//static DWORD xoffset;
bool DeviceLost = false;
//static bool mainTexLock = false; // for preventing a crash during the locked state of the texture
static char textureFilter; // 1 - auto, 2 - force
static DDSURFACEDESC surfaceDesc;
@@ -139,16 +135,6 @@ static VertexFormat ShaderVertices[] = {
{639.5, 479.5, 0, 1, 1, 1} // 3 - bottom right
};
HWND Graphics::GetFalloutWindowInfo(RECT* rect) {
if (rect) {
rect->left = windowLeft;
rect->top = windowTop;
rect->right = gWidth;
rect->bottom = gHeight;
}
return window;
}
long Graphics::GetGameWidthRes() {
return (fo::var::scr_size.offx - fo::var::scr_size.x) + 1;
}
@@ -195,12 +181,10 @@ static void ResetDevice(bool create) {
GetDisplayMode(dispMode);
params.BackBufferCount = 1;
params.BackBufferFormat = dispMode.Format; // (Graphics::mode != 4) ? D3DFMT_UNKNOWN : D3DFMT_X8R8G8B8;
params.BackBufferFormat = dispMode.Format;
params.BackBufferWidth = gWidth;
params.BackBufferHeight = gHeight;
params.EnableAutoDepthStencil = false;
//params.MultiSampleQuality = 0;
//params.MultiSampleType = D3DMULTISAMPLE_NONE;
params.Windowed = (Graphics::mode != 4);
params.SwapEffect = D3DSWAPEFFECT_DISCARD;
params.hDeviceWindow = window;
@@ -272,7 +256,6 @@ static void ResetDevice(bool create) {
d3d9Device->Reset(&params);
if (gpuBltEffect) gpuBltEffect->OnResetDevice();
ScriptShaders::OnResetDevice();
//mainTexLock = false;
}
d3d9Device->CreateTexture(ResWidth, ResHeight, 1, 0, textureFormat, D3DPOOL_DEFAULT, &mainTexD, 0);
@@ -342,8 +325,6 @@ static DWORD lastTime = GetTickCount();
static long frameCount;
static long elapsedTime;
static long fps;
//static long palCounter;
//static long lockCounter;
static void CalcFPS() {
frameCount++;
@@ -560,26 +541,26 @@ void Graphics::ShowMovieFrame(IDirect3DTexture9* tex) {
d3d9Device->SetRenderTarget(0, backBuffer);
d3d9Device->BeginScene();
//if (!mainTexLock) {
if (ScriptShaders::Count() && Graphics::GPUBlt) {
d3d9Device->SetTexture(0, sTex2);
} else {
d3d9Device->SetTexture(0, mainTexD);
}
d3d9Device->SetStreamSource(0, vertexSfallRes, 0, sizeof(VertexFormat));
// for showing subtitles
if (Graphics::GPUBlt) {
UINT passes;
gpuBltEffect->Begin(&passes, 0);
gpuBltEffect->BeginPass(0);
}
d3d9Device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
if (Graphics::GPUBlt) {
gpuBltEffect->EndPass();
gpuBltEffect->End();
}
//}
if (ScriptShaders::Count() && Graphics::GPUBlt) {
d3d9Device->SetTexture(0, sTex2);
} else {
d3d9Device->SetTexture(0, mainTexD);
}
d3d9Device->SetStreamSource(0, vertexSfallRes, 0, sizeof(VertexFormat));
// for showing subtitles
if (Graphics::GPUBlt) {
UINT passes;
gpuBltEffect->Begin(&passes, 0);
gpuBltEffect->BeginPass(0);
}
d3d9Device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
if (Graphics::GPUBlt) {
gpuBltEffect->EndPass();
gpuBltEffect->End();
}
// for avi movie
d3d9Device->SetTexture(0, movieTex);
d3d9Device->SetStreamSource(0, vertexMovie, 0, sizeof(VertexFormat));
@@ -679,15 +660,12 @@ public:
// called 0x4868DA movie_MVE_ShowFrame_ used for game movies (only for w/o HRP by Mash)
HRESULT __stdcall Blt(LPRECT dst, LPDIRECTDRAWSURFACE b, LPRECT scr, DWORD d, LPDDBLTFX e) {
mveDesc.dwHeight = scr->bottom; //(dst->bottom - dst->top);
mveDesc.lPitch = scr->right; //(dst->right - dst->left);
//xoffset = (ResWidth - mveDesc.lPitch) / 2;
//yoffset = (ResHeight - mveDesc.dwHeight) / 2;
mveDesc.dwHeight = scr->bottom;
mveDesc.lPitch = scr->right;
//dlog_f("\nBlt: [mveDesc: w:%d, h:%d]", DL_INIT, mveDesc.lPitch, mveDesc.dwHeight);
IsPlayMovie = true;
//mainTexLock = true;
BYTE* lockTarget = ((FakeDirectDrawSurface*)b)->lockTarget;
@@ -724,7 +702,6 @@ public:
//mainTexD->GetSurfaceLevel(0, &mSurfD);
//d3d9Device->StretchRect(mSurf, 0, mSurfD, 0, D3DTEXF_LINEAR);
//mainTexLock = false;
//if (Graphics::PlayAviMovie) return DD_OK; // Blt method is not executed during avi playback because the sfShowFrame_ function is blocked
Refresh();
@@ -766,7 +743,6 @@ public:
D3DLOCKED_RECT buf;
if (SUCCEEDED(mainTex->LockRect(0, &buf, lockRect, D3DLOCK_NO_DIRTY_UPDATE))) {
mainTex->AddDirtyRect(lockRect);
//mainTexLock = true;
b->lpSurface = buf.pBits;
b->lPitch = buf.Pitch;
}
@@ -809,8 +785,6 @@ public:
}
if (DeviceLost) return DD_OK;
//mainTexLock = true;
D3DLOCKED_RECT dRect;
mainTex->LockRect(0, &dRect, 0, 0);
@@ -831,7 +805,7 @@ public:
mainTex->UnlockRect(0);
d3d9Device->UpdateTexture(mainTex, mainTexD);
//mainTexLock = false;
return DD_OK;
}
@@ -845,11 +819,8 @@ public:
*/
HRESULT __stdcall Unlock(LPVOID lockSurface) {
if (!isPrimary) return DD_OK;
//lockCounter++;
if (Graphics::GPUBlt == 0) {
//mainTexLock = true;
D3DLOCKED_RECT dRect;
mainTex->LockRect(0, &dRect, lockRect, D3DLOCK_NO_DIRTY_UPDATE);
mainTex->AddDirtyRect(lockRect);
@@ -887,8 +858,8 @@ public:
}
}
}
/*if (mainTexLock)*/ mainTex->UnlockRect(0);
//mainTexLock = false;
mainTex->UnlockRect(0);
d3d9Device->UpdateTexture(mainTex, mainTexD);
if (!IsPlayMovie && !Graphics::PlayAviMovie) {
@@ -938,7 +909,6 @@ public:
*/
HRESULT __stdcall SetEntries(DWORD a, DWORD b, DWORD c, LPPALETTEENTRY d) { // used to set palette for splash screen, fades, subtitles
if (!paletteInit || (long)c <= 0) return DDERR_INVALIDPARAMS;
//palCounter++;
fo::PALETTE* destPal = (fo::PALETTE*)d;
@@ -971,6 +941,7 @@ public:
destPal++;
b++;
} while (--c);
primarySurface->SetPalette(0); // update texture
if (FakeDirectDrawSurface::IsPlayMovie) return DD_OK; // prevents flickering at the beginning of playback (w/o HRP & GPUBlt=2)
}
-1
View File
@@ -59,7 +59,6 @@ public:
static DWORD mode;
static DWORD GPUBlt;
static HWND GetFalloutWindowInfo(RECT* rect);
static long GetGameWidthRes();
static long GetGameHeightRes();
+2 -4
View File
@@ -1053,10 +1053,8 @@ void Interface::init() {
// Transparent/Hidden - will not toggle the mouse cursor when the cursor hovers over a transparent/hidden window
// ScriptWindow - prevents the player from moving when clicking on the window if the 'Transparent' flag is not set
HookCall(0x44B737, gmouse_bk_process_hook);
LoadGameHook::OnBeforeGameInit() += []() {
if (hrpVersionValid) IFACE_BAR_MODE = (GetIntHRPValue(HRP_VAR_IFACE_BAR_MODE) != 0);
HookCall(0x44C018, gmouse_handle_event_hook); // replaces hack function from HRP
};
HookCall(0x44C018, gmouse_handle_event_hook); // replaces hack function from HRP
if (hrpVersionValid) IFACE_BAR_MODE = (GetIntHRPValue(HRP_VAR_IFACE_BAR_MODE) != 0);
}
void Interface::exit() {
+23 -3
View File
@@ -138,7 +138,7 @@ static void __declspec(naked) game_init_databases_hack1() {
mov ecx, [esp + 0x104 + 4]; // path_patches
call RemoveDatabase;
skip:
mov ds:[FO_VAR_master_db_handle], eax; // the pointer of master_patches node will be saved here
mov ds:[FO_VAR_master_db_handle], eax; // the pointer of master_patches node will be saved here
retn;
}
}
@@ -151,8 +151,8 @@ static void __declspec(naked) game_init_databases_hack2() {
mov eax, ds:[FO_VAR_master_db_handle]; // pointer to master_patches node
mov eax, [eax]; // eax = master_patches.path
call fo::funcoffs::xremovepath_;
dec eax; // remove path (critter_patches == master_patches)?
jz end; // Yes (jump if 0)
dec eax; // 1 = remove path (critter_patches == master_patches)?
jz end; // yes (jump if removed)
mov ecx, [esp + 0x104 + 4]; // path_patches
call RemoveDatabase;
end:
@@ -184,6 +184,26 @@ static void __fastcall game_init_databases_hook() { // eax = _master_db_handle
}
master_patches->next = paths; // master_patches.next -> paths
fo::var::paths = master_patches; // set master_patches node at the beginning of the chain of paths
// remove paths that are identical to master_patches (usually the DATA folder)
fo::PathNode* parentPath = fo::var::paths;
paths = parentPath->next;
while (paths) {
if (!paths->isDat && _stricmp(paths->path, fo::var::paths->path) == 0) {
auto nextPaths = paths->next;
__asm {
mov eax, [paths];
call fo::funcoffs::nfree_; // free path string
mov eax, paths;
call fo::funcoffs::nfree_; // free self
}
parentPath->next = nextPaths;
paths = nextPaths;
} else {
parentPath = paths;
paths = paths->next;
}
}
}
/*
static void __fastcall game_init_databases_hook1() {
+9 -5
View File
@@ -20,12 +20,16 @@
extern ddrawDll ddraw;
typedef HRESULT (__stdcall *DDrawCreateProc)(void* a, void* b, void* c);
//typedef HRESULT (__stdcall *DDrawCreateProc)(DWORD a, IDirectDraw* b, DWORD c);
HRESULT __stdcall FakeDirectDrawCreate(void* a, void* b, void* c) {
DDrawCreateProc proc = (DDrawCreateProc)ddraw.DirectDrawCreate;
if (!proc) return -1;
return proc(a, b, c);
//HRESULT __stdcall FakeDirectDrawCreate(DWORD a, IDirectDraw* b, DWORD c) {
// DDrawCreateProc proc = (DDrawCreateProc)ddraw.DirectDrawCreate;
// if (!proc) return -1;
// return proc(a, b, c);
//}
__declspec(naked) void FakeDirectDrawCreate() {
__asm jmp [ddraw.DirectDrawCreate];
}
__declspec(naked) void FakeAcquireDDThreadLock() {