Code cleanup and edits according to dev branch

This commit is contained in:
NovaRain
2021-12-19 08:45:26 +08:00
parent b187c8359b
commit 97f3d3eb5f
4 changed files with 51 additions and 60 deletions
+3 -3
View File
@@ -434,7 +434,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;
@@ -444,12 +444,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;
+26 -45
View File
@@ -56,11 +56,7 @@ DWORD Graphics::mode;
bool Graphics::PlayAviMovie = false;
bool Graphics::AviMovieWidthFit = false;
//static DWORD yoffset;
//static DWORD xoffset;
static 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;
@@ -181,12 +177,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;
@@ -254,7 +248,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);
@@ -324,8 +317,6 @@ static DWORD lastTime = GetTickCount();
static long frameCount;
static long elapsedTime;
static long fps;
//static long palCounter;
//static long lockCounter;
static void CalcFPS() {
frameCount++;
@@ -542,26 +533,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));
@@ -648,15 +639,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;
@@ -693,7 +681,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();
@@ -735,7 +722,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;
}
@@ -778,8 +764,6 @@ public:
}
if (DeviceLost) return DD_OK;
//mainTexLock = true;
D3DLOCKED_RECT dRect;
mainTex->LockRect(0, &dRect, 0, 0);
@@ -800,7 +784,7 @@ public:
mainTex->UnlockRect(0);
d3d9Device->UpdateTexture(mainTex, mainTexD);
//mainTexLock = false;
return DD_OK;
}
@@ -814,11 +798,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);
@@ -856,8 +837,8 @@ public:
}
}
}
/*if (mainTexLock)*/ mainTex->UnlockRect(0);
//mainTexLock = false;
mainTex->UnlockRect(0);
d3d9Device->UpdateTexture(mainTex, mainTexD);
if (!IsPlayMovie && !Graphics::PlayAviMovie) {
@@ -907,7 +888,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;
@@ -940,6 +920,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)
}
+13 -7
View File
@@ -32,8 +32,14 @@ namespace sfall
typedef int (__stdcall *functype)();
static const DWORD Tiles_0E[] = {
0x484255, 0x48429D, 0x484377, 0x484385, 0x48A897, 0x48A89A, 0x4B2231,
0x4B2374, 0x4B2381, 0x4B2480, 0x4B248D, 0x4B2A7C, 0x4B2BDA,
0x484255, 0x48429D, // square_reset_
0x484377, 0x484385, // square_load_
0x48A897, 0x48A89A, // obj_move_to_tile_
0x4B2231, // square_render_roof_
0x4B2374, 0x4B2381, // roof_fill_on_
0x4B2480, 0x4B248D, // tile_fill_roof_
0x4B2A7C, // square_render_floor_
0x4B2BDA, // square_roof_intersect_
};
static const DWORD Tiles_3F[] = {
@@ -289,11 +295,11 @@ static void __declspec(naked) art_get_name_hack() {
sar eax, 24;
cmp eax, OBJ_TYPE_TILE;
jne end;
mov esi, edx;
mov ebp, edx;
and esi, 0x3FFF;
mov esi, edx;
and ebp, 0xC000;
sar ebp, 0x0E;
and esi, 0x3FFF;
sar ebp, 14;
end:
test esi, esi;
retn;
@@ -317,8 +323,8 @@ void Tiles::init() {
SafeWriteBatch<BYTE>(0x40, Tiles_40);
SafeWriteBatch<BYTE>(0xC0, Tiles_C0);
if (hrpVersionValid) { // Check HRP 4.1.8
SafeWrite8(HRPAddress(0x1000E1C0), 0x40);
SafeWrite8(HRPAddress(0x1000E1DA), 0x3F);
SafeWrite8(HRPAddress(0x1000E1C0), 0x40); // 4000 > 16384
SafeWrite8(HRPAddress(0x1000E1DA), 0x3F); // and esi, 0x3FFF
}
dlogr(" Done", DL_INIT);
}
+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() {