diff --git a/mapping/DKII_EXE_v170.sgmap b/mapping/DKII_EXE_v170.sgmap index b370098..7f8be4a 100644 --- a/mapping/DKII_EXE_v170.sgmap +++ b/mapping/DKII_EXE_v170.sgmap @@ -2238,16 +2238,19 @@ struct: id=vtbl_0066C4A4,name=CDefaultPlayerInterface,size=20273,vtable=instance type: kind=struct,id=construct_00402752 field: name=field_1C1F type: kind=int,size=4,signed=True - field: name=gap1C23 - type: kind=array,count=802 + field: name=gap_1C23 + type: kind=array,count=794 type: kind=int,size=1 + field: name=field_1F3D + type: kind=int,size=4,signed=True + field: name=field_1F41 + type: kind=int,size=4,signed=True field: name=f1F45__chatMessageHistoryWindowText type: kind=struct,id=construct_00402752 field: name=f21E0__multiplayerMessageWindowText type: kind=struct,id=construct_00402752 - field: name=gap_247B - type: kind=array,count=4 - type: kind=int,size=1 + field: name=field_247B + type: kind=int,size=4,signed=True field: name=field_247F type: kind=int,size=4 field: name=field_2483 @@ -2264,9 +2267,8 @@ struct: id=vtbl_0066C4A4,name=CDefaultPlayerInterface,size=20273,vtable=instance type: kind=int,size=4 field: name=field_2732 type: kind=int,size=4,signed=True - field: name=f2736_gap - type: kind=array,count=1 - type: kind=int,size=1 + field: name=gap2736 + type: kind=int,size=1 field: name=f2737__options type: kind=struct,id=construct_00402752 field: name=gap_29D2 @@ -3121,7 +3123,7 @@ struct: id=vtbl_0066FD1C,path=dk2/engine/primitive/2d/world,name=CEngineDynamicM type: kind=int,size=4,signed=True field: name=field_48 type: kind=int,size=4,signed=True - field: name=field_4C + field: name=f4C_dflags type: kind=int,size=4,signed=True field: name=field_50 type: kind=int,size=4,signed=True @@ -3481,7 +3483,7 @@ struct: id=instance_0066D1D4,name=CEngineInterface_vtbl,size=272 type: kind=function,declspec=thiscall ret: kind=int,size=4,signed=True arg: kind=ptr - type: kind=struct,id=vtbl_00670574 + type: kind=void arg: kind=int,size=4,signed=True arg: kind=ptr type: kind=struct,id=constructor_005B5270 @@ -17520,7 +17522,7 @@ struct: id=constructor_0057C420,name=MyScaledSurface,size=49 field: name=f8_surfh type: kind=ptr type: kind=struct,id=constructor_00590BF0 - field: name=fC_flags + field: name=fC_drawFlags type: kind=int,size=4 field: name=f10_flags type: kind=int,size=4 @@ -20877,14 +20879,13 @@ struct: id=construct_00402752,name=RtGuiView,size=667 field: name=field_297 type: kind=int,size=4,signed=True struct: id=construct_00586B96,name=SceneObject2E,size=46 - field: name=f0_surfh + field: name=f0_surfh_x4 type: kind=array,count=4 type: kind=ptr type: kind=struct,id=constructor_00590BF0 - field: name=f10_props_flags - type: kind=int,size=4 - field: name=f14_props_reductionLevel_andFlags - type: kind=int,size=4,signed=True + field: name=f10_drawFlags_x2 + type: kind=array,count=2 + type: kind=int,size=4 field: name=f18_lod__triangleCount type: kind=int,size=2 field: name=f1A_numVertsEx @@ -20895,11 +20896,10 @@ struct: id=construct_00586B96,name=SceneObject2E,size=46 type: kind=int,size=1 field: name=f1E_propsCount type: kind=int,size=1 - field: name=f1F_trgObj - type: kind=int,size=1,signed=True,winapi=char - field: name=field_20 - type: kind=int,size=1,signed=True,winapi=char - field: name=field_21 + field: name=f1F_numTextureSamplers_x2 + type: kind=array,count=2 + type: kind=int,size=1,signed=True,winapi=char + field: name=f21_zeroOrM1 type: kind=int,size=1,signed=True,winapi=char field: name=f22_gap type: kind=array,count=2 @@ -20934,13 +20934,13 @@ struct: id=construct_0058F79C,name=SceneObject30,size=48 field: name=f1A_props_surfHeight8_vertices type: kind=int,size=2 field: name=f1C_surfhCount - type: kind=int,size=1,signed=True,winapi=char + type: kind=int,size=1 field: name=f1D_texStageCountArrSize - type: kind=int,size=1,signed=True,winapi=char + type: kind=int,size=1 field: name=f1E_d3dtexStageCount type: kind=array,count=2 type: kind=int,size=1 - field: name=f20_sceneObj2E_f21 + field: name=field_20 type: kind=int,size=1,signed=True,winapi=char field: name=f21_gap type: kind=array,count=3 @@ -20954,14 +20954,6 @@ struct: id=construct_0058F79C,name=SceneObject30,size=48 field: name=f2C_next type: kind=ptr type: kind=struct,id=construct_0058F79C -struct: id=instance_007820B8,name=SceneObject30List,size=12 - field: name=f0_blockSize - type: kind=int,size=4,signed=True - field: name=f4_maxCount - type: kind=int,size=4,signed=True - field: name=f8_arr - type: kind=ptr - type: kind=struct,id=construct_0058F79C struct: id=instance_arr_00769A78,name=ScreenObject,size=16 field: name=f0_centerX type: kind=float,size=4 @@ -21409,9 +21401,9 @@ struct: id=call_new_0059425F,name=SurfHashListItem,size=36 field: name=field_23 type: kind=int,size=1,signed=True,winapi=char struct: id=call_new_00591E8D,name=SurfaceHolder,size=32 - field: name=f0_SceneObject30 + field: name=f0_ToDraw type: kind=ptr - type: kind=struct,id=construct_0058F79C + type: kind=struct,id=list_007820B8 field: name=f4_surfh_first type: kind=ptr type: kind=struct,id=constructor_00590BF0 @@ -21666,6 +21658,47 @@ struct: id=call_new_006367F8,name=ThreadCtx,size=80 field: name=f4C_arg type: kind=ptr type: kind=void +struct: id=list_007820B8,name=ToDraw,size=48 + field: name=f0_holders + type: kind=array,count=4 + type: kind=ptr + type: kind=struct,id=call_new_00591E8D + field: name=f10_drawFlags_x2 + type: kind=array,count=2 + type: kind=int,size=4,signed=True + field: name=f18_totalTriangles + type: kind=int,size=2 + field: name=f1A_totalVertices + type: kind=int,size=2 + field: name=f1C_surfhCount + type: kind=int,size=1 + field: name=f1D_propsCount + type: kind=int,size=1 + field: name=f1E_numTextureSamplers_x2 + type: kind=array,count=2 + type: kind=int,size=1 + field: name=f20_zeroOrM1 + type: kind=int,size=1,signed=True,winapi=char + field: name=f21_gap + type: kind=array,count=3 + type: kind=int,size=1 + field: name=f24_pObj2E + type: kind=ptr + type: kind=struct,id=construct_00586B96 + field: name=f28_next + type: kind=ptr + type: kind=struct,id=list_007820B8 + field: name=f2C_prev_eos + type: kind=ptr + type: kind=struct,id=list_007820B8 +struct: id=instance_007820B8,name=ToDrawList,size=12 + field: name=f0_blockSize + type: kind=int,size=4,signed=True + field: name=f4_maxCount + type: kind=int,size=4,signed=True + field: name=f8_toDrawArr + type: kind=ptr + type: kind=struct,id=list_007820B8 struct: id=use_00577A72,name=Triangle,size=3 field: name=f0_x type: kind=int,size=1 @@ -23057,10 +23090,11 @@ global: va=0040F820,name=sub_40F820,size=439,member_of=vtbl_0066C4A4 ret: kind=void arg: kind=ptr type: kind=struct,id=vtbl_0066C4A4 -global: va=0040F9E0,name=sub_40F9E0,size=174 +global: va=0040F9E0,name=sub_40F9E0,size=174,member_of=vtbl_0066C4A4 type: kind=function,declspec=thiscall ret: kind=int,size=1,signed=True,winapi=char - arg: kind=int,size=4,signed=True + arg: kind=ptr + type: kind=struct,id=vtbl_0066C4A4 arg: kind=int,size=4,signed=True global: va=0040FA90,name=sub_40FA90,size=741,member_of=vtbl_0066C4A4 type: kind=function,declspec=thiscall @@ -23401,10 +23435,11 @@ global: va=00415D30,name=sub_415D30,size=453 type: kind=struct,id=vtbl_0066C4A4 arg: kind=int,size=4,signed=True arg: kind=int,size=4,signed=True -global: va=00415F00,name=sub_415F00,size=363 +global: va=00415F00,name=sub_415F00,size=363,member_of=vtbl_0066C4A4 type: kind=function,declspec=thiscall ret: kind=int,size=4,signed=True - arg: kind=int,size=4,signed=True + arg: kind=ptr + type: kind=struct,id=vtbl_0066C4A4 arg: kind=int,size=1,signed=True,winapi=char global: va=00416070,name=BtnHandler_sub_416070,size=223 type: kind=function,declspec=cdecl @@ -24172,7 +24207,8 @@ global: va=00426070,name=sub_426070,size=123 ret: kind=int,size=4,signed=True arg: kind=int,size=4,signed=True arg: kind=int,size=4,signed=True - arg: kind=int,size=4,signed=True + arg: kind=ptr + type: kind=struct,id=vtbl_0066C4A4 global: va=004260F0,name=sub_4260F0,size=739 type: kind=function,declspec=cdecl ret: kind=void @@ -24765,7 +24801,8 @@ global: va=0042B770,name=sub_42B770,size=66 ret: kind=int,size=4,signed=True arg: kind=int,size=4,signed=True arg: kind=int,size=4 - arg: kind=int,size=4,signed=True + arg: kind=ptr + type: kind=struct,id=vtbl_0066C4A4 global: va=0042B7C0,name=sub_42B7C0,size=392 type: kind=function,declspec=cdecl ret: kind=void @@ -24923,7 +24960,7 @@ global: va=0042CB60,name=sub_42CB60,size=643,member_of=vtbl_0066C4A4 arg: kind=int,size=4,signed=True global: va=0042CDF0,name=createSurfacesForView_42CDF0,size=239,member_of=vtbl_0066C4A4 type: kind=function,declspec=thiscall - ret: kind=int,size=4,signed=True + ret: kind=void arg: kind=ptr type: kind=struct,id=vtbl_0066C4A4 arg: kind=ptr @@ -37417,7 +37454,7 @@ global: va=004C7160,name=fun_4C7160,size=449,member_of=vtbl_0066D99C ret: kind=int,size=4,signed=True arg: kind=ptr type: kind=struct,id=vtbl_0066D99C -global: va=004C7330,name=tickRoomPlacements_bug4,size=5,member_of=vtbl_0066D99C +global: va=004C7330,name=tickRoomPlacements_,size=5,member_of=vtbl_0066D99C type: kind=function,declspec=thiscall ret: kind=void arg: kind=ptr @@ -37432,7 +37469,7 @@ global: va=004C7360,name=fun_4C7360,size=31,member_of=vtbl_0066D99C ret: kind=int,size=4,signed=True arg: kind=ptr type: kind=struct,id=vtbl_0066D99C -global: va=004C7380,name=tickRoomPlacements_bug3,size=1282,member_of=vtbl_0066D99C +global: va=004C7380,name=tickRoomPlacements,size=1282,member_of=vtbl_0066D99C type: kind=function,declspec=thiscall ret: kind=void arg: kind=ptr @@ -50479,9 +50516,9 @@ global: va=005575F0,name=collect_devices_DDEnumDevicesCB,size=548 ret: kind=int,size=4,signed=True arg: kind=ptr type: kind=winapi,name=_GUID,size=16 - arg: kind=ptr,is_const=True + arg: kind=ptr,is_const=True,winapi=LPCSTR type: kind=int,size=1,signed=True,winapi=CHAR,fname=CHAR - arg: kind=ptr,is_const=True + arg: kind=ptr,is_const=True,winapi=LPCSTR type: kind=int,size=1,signed=True,winapi=CHAR,fname=CHAR arg: kind=ptr type: kind=ptr @@ -50777,10 +50814,11 @@ global: va=00559710,name=static_MyGame_Event07_cb,size=45 type: kind=struct,id=construct_0055650F arg: kind=ptr type: kind=struct,id=constructor_00557B70 -global: va=00559740,name=sub_559740,size=47 +global: va=00559740,name=sub_559740,size=47,member_of=constructor_00557B70 type: kind=function,declspec=thiscall ret: kind=int,size=4,signed=True,winapi=BOOL,fname=BOOL - arg: kind=int,size=4,signed=True + arg: kind=ptr + type: kind=struct,id=constructor_00557B70 global: va=00559770,name=MyGame_sub_559770,size=28 type: kind=function,declspec=fastcall ret: kind=int,size=2,signed=True @@ -51914,7 +51952,7 @@ global: va=005620E0,name=sub_5620E0,size=246,member_of=constructor_00554A60 type: kind=struct,id=constructor_00554A60 arg: kind=ptr type: kind=int,size=4 - arg: kind=ptr,is_const=True + arg: kind=ptr,is_const=True,winapi=LPCSTR type: kind=int,size=1,signed=True,winapi=CHAR,fname=CHAR arg: kind=ptr,winapi=HKEY type: kind=winapi,name=HKEY__,size=4 @@ -51932,7 +51970,7 @@ global: va=00562200,name=settings_writeBytes,size=84,member_of=constructor_00554 type: kind=struct,id=constructor_00554A60 arg: kind=ptr type: kind=int,size=4 - arg: kind=ptr,is_const=True + arg: kind=ptr,is_const=True,winapi=LPCSTR type: kind=int,size=1,signed=True,winapi=CHAR,fname=CHAR arg: kind=int,size=4,fname=DWORD arg: kind=ptr @@ -51946,7 +51984,7 @@ global: va=00562260,name=settings_readBytes,size=77,member_of=constructor_00554A type: kind=struct,id=constructor_00554A60 arg: kind=ptr type: kind=int,size=4 - arg: kind=ptr,is_const=True + arg: kind=ptr,is_const=True,winapi=LPCSTR type: kind=int,size=1,signed=True,winapi=CHAR,fname=CHAR arg: kind=ptr type: kind=int,size=1,fname=BYTE @@ -51956,7 +51994,7 @@ global: va=005622B0,name=settings_readBytesCount,size=53,member_of=constructor_0 ret: kind=int,size=4 arg: kind=ptr type: kind=struct,id=constructor_00554A60 - arg: kind=ptr,is_const=True + arg: kind=ptr,is_const=True,winapi=LPCSTR type: kind=int,size=1,signed=True,winapi=CHAR,fname=CHAR global: va=005622F0,name=sub_5622F0,size=171 type: kind=function,declspec=thiscall @@ -51967,7 +52005,7 @@ global: va=005622F0,name=sub_5622F0,size=171 type: kind=winapi,name=HKEY__,size=4 arg: kind=ptr type: kind=int,size=4 - arg: kind=ptr,is_const=True + arg: kind=ptr,is_const=True,winapi=LPCSTR type: kind=int,size=1,signed=True,winapi=CHAR,fname=CHAR arg: kind=int,size=4,signed=True global: va=005623A0,name=sub_5623A0,size=301 @@ -51979,7 +52017,7 @@ global: va=005623A0,name=sub_5623A0,size=301 type: kind=winapi,name=HKEY__,size=4 arg: kind=ptr type: kind=int,size=4 - arg: kind=ptr,is_const=True + arg: kind=ptr,is_const=True,winapi=LPCSTR type: kind=int,size=1,signed=True,winapi=CHAR,fname=CHAR arg: kind=int,size=4,signed=True global: va=005624D0,name=sub_5624D0,size=80 @@ -51991,7 +52029,7 @@ global: va=005624D0,name=sub_5624D0,size=80 type: kind=winapi,name=HKEY__,size=4 arg: kind=ptr type: kind=int,size=4 - arg: kind=ptr,is_const=True + arg: kind=ptr,is_const=True,winapi=LPCSTR type: kind=int,size=1,signed=True,winapi=CHAR,fname=CHAR arg: kind=ptr type: kind=int,size=1,fname=BYTE @@ -52004,7 +52042,7 @@ global: va=00562520,name=sub_562520,size=330 type: kind=winapi,name=HKEY__,size=4 arg: kind=ptr type: kind=int,size=4 - arg: kind=ptr,is_const=True + arg: kind=ptr,is_const=True,winapi=LPCSTR type: kind=int,size=1,signed=True,winapi=CHAR,fname=CHAR arg: kind=ptr type: kind=int,size=1,signed=True,winapi=char @@ -52021,19 +52059,18 @@ global: va=00562670,name=setValue_562670,size=69,member_of=constructor_00554A60 type: kind=winapi,name=HKEY__,size=4 arg: kind=ptr type: kind=int,size=4 - arg: kind=ptr,is_const=True + arg: kind=ptr,is_const=True,winapi=LPCSTR type: kind=int,size=1,signed=True,winapi=CHAR,fname=CHAR arg: kind=int,size=1,fname=BYTE -global: va=005626C0,name=settings_readValue,size=249 +global: va=005626C0,name=settings_readValue,size=249,member_of=constructor_00554A60 type: kind=function,declspec=thiscall ret: kind=ptr type: kind=int,size=4,signed=True arg: kind=ptr - type: kind=ptr,winapi=HKEY - type: kind=winapi,name=HKEY__,size=4 + type: kind=struct,id=constructor_00554A60 arg: kind=ptr - type: kind=int,size=4 - arg: kind=ptr,is_const=True + type: kind=int,size=4,signed=True + arg: kind=ptr,is_const=True,winapi=LPCSTR type: kind=int,size=1,signed=True,winapi=CHAR,fname=CHAR arg: kind=ptr type: kind=int,size=4,fname=DWORD @@ -52045,7 +52082,7 @@ global: va=005627C0,name=sub_5627C0,size=148,member_of=constructor_00554A60 type: kind=struct,id=constructor_00554A60 arg: kind=ptr type: kind=int,size=4 - arg: kind=ptr,is_const=True + arg: kind=ptr,is_const=True,winapi=LPCSTR type: kind=int,size=1,signed=True,winapi=CHAR,fname=CHAR arg: kind=ptr type: kind=ptr,winapi=HKEY @@ -52059,7 +52096,7 @@ global: va=00562860,name=sub_562860,size=156 type: kind=winapi,name=HKEY__,size=4 arg: kind=ptr type: kind=int,size=4 - arg: kind=ptr,is_const=True + arg: kind=ptr,is_const=True,winapi=LPCSTR type: kind=int,size=1,signed=True,winapi=CHAR,fname=CHAR arg: kind=ptr type: kind=ptr,winapi=HKEY @@ -55723,11 +55760,11 @@ global: va=00589C90,name=sub_589C90,size=211 global: va=00589D70,name=sub_589D70,size=18 type: kind=function,declspec=stdcall ret: kind=int,size=4,signed=True -global: va=00589D90,name=addObjectToScene,size=610 +global: va=00589D90,name=addObjectToDraw,size=610 type: kind=function,declspec=cdecl ret: kind=void arg: kind=ptr - type: kind=struct,id=construct_0058F79C + type: kind=struct,id=list_007820B8 global: va=0058A000,name=DrawTriangleList,size=321 type: kind=function,declspec=cdecl ret: kind=int,size=4,signed=True,winapi=HRESULT,fname=HRESULT @@ -56095,11 +56132,11 @@ global: va=0058F510,name=SceneObject2EList_static_destructor,size=18 global: va=0058F530,name=objects30ToDraw_static_destructor,size=18 type: kind=function,declspec=stdcall ret: kind=int,size=4,signed=True -global: va=0058F550,name=SceneObject2EList_SceneObject30List_static_init,size=151 +global: va=0058F550,name=SceneObject2EList_ToDrawList_static_init,size=151 type: kind=function,declspec=stdcall ret: kind=ptr type: kind=struct,id=construct_0058F79C -global: va=0058F5F0,name=SceneObject2EList_SceneObject30List_static_destroy,size=67 +global: va=0058F5F0,name=SceneObject2EList_ToDrawList_static_destroy,size=67 type: kind=function,declspec=stdcall ret: kind=void global: va=0058F640,name=draw3dScene,size=661 @@ -56515,8 +56552,7 @@ global: va=00592950,name=mydd_devTexture_destroy,size=546 ret: kind=void global: va=00592B80,name=renderer_setSurfaceHolder,size=77 type: kind=function,declspec=cdecl - ret: kind=ptr - type: kind=int,size=4 + ret: kind=void arg: kind=ptr type: kind=struct,id=call_new_00591E8D arg: kind=int,size=4,fname=DWORD @@ -57349,7 +57385,7 @@ global: va=0059D010,name=sub_59D010,size=583 ret: kind=ptr type: kind=struct,id=vtbl_0066FD1C arg: kind=ptr - type: kind=int,size=4 + type: kind=struct,id=vtbl_0066D454 arg: kind=ptr type: kind=struct,id=vec_xyz arg: kind=int,size=4,signed=True @@ -57399,9 +57435,10 @@ global: va=0059D420,name=fun_59D420,size=133,member_of=vtbl_00670574 global: va=0059D4B0,name=sub_59D4B0,size=202 type: kind=function,declspec=stdcall ret: kind=int,size=4,signed=True - arg: kind=int,size=4,signed=True arg: kind=ptr - type: kind=int,size=4 + type: kind=struct,id=vtbl_0066D454 + arg: kind=ptr + type: kind=int,size=4,signed=True arg: kind=ptr type: kind=int,size=4 global: va=0059D580,name=fun_59D580,size=33,member_of=vtbl_00670574 @@ -57895,7 +57932,7 @@ global: va=005A5DA0,name=dk2_main,size=1544 ret: kind=int,size=4,signed=True arg: kind=int,size=4,signed=True arg: kind=ptr - type: kind=ptr,is_const=True + type: kind=ptr,is_const=True,winapi=LPCSTR type: kind=int,size=1,signed=True,winapi=CHAR,fname=CHAR global: va=005A63B0,name=parse_command_line,size=2332 type: kind=function,declspec=cdecl @@ -59368,7 +59405,7 @@ global: va=005B3CE0,name=findFile,size=240 type: kind=int,size=4 arg: kind=ptr type: kind=int,size=4,signed=True - arg: kind=ptr,is_const=True + arg: kind=ptr,is_const=True,winapi=LPCSTR type: kind=int,size=1,signed=True,winapi=CHAR,fname=CHAR arg: kind=ptr type: kind=winapi,name=_WIN32_FIND_DATAA,size=320 @@ -59394,9 +59431,9 @@ global: va=005B3E80,name=sub_5B3E80,size=38 type: kind=int,size=4 arg: kind=ptr type: kind=int,size=4 - arg: kind=ptr,is_const=True + arg: kind=ptr,is_const=True,winapi=LPCSTR type: kind=int,size=1,signed=True,winapi=CHAR,fname=CHAR - arg: kind=ptr,is_const=True + arg: kind=ptr,is_const=True,winapi=LPCSTR type: kind=int,size=1,signed=True,winapi=CHAR,fname=CHAR global: va=005B3EB0,name=TbDiscFile_readBytes,size=45 type: kind=function,declspec=cdecl @@ -59804,7 +59841,7 @@ global: va=005B5D70,name=sub_5B5D70,size=130 type: kind=function,declspec=thiscall ret: kind=int,size=4,signed=True arg: kind=ptr - type: kind=winapi,name=_LARGE_INTEGER,size=8 + type: kind=winapi,name=_LARGE_INTEGER,size=8,is_union=True global: va=005B5E00,name=sub_5B5E00,size=109 type: kind=function,declspec=thiscall ret: kind=int,size=4,fname=DWORD @@ -60305,7 +60342,7 @@ global: va=005B8470,name=sub_5B8470,size=57 type: kind=int,size=4 arg: kind=ptr type: kind=int,size=4 - arg: kind=ptr,is_const=True + arg: kind=ptr,is_const=True,winapi=LPCSTR type: kind=int,size=1,signed=True,winapi=CHAR,fname=CHAR arg: kind=ptr type: kind=int,size=1,signed=True,winapi=CHAR,fname=CHAR @@ -60990,7 +61027,7 @@ global: va=005BAE70,name=constructor,size=61,member_of=constructor_005BAE70 type: kind=struct,id=constructor_005BAE70 arg: kind=ptr type: kind=struct,id=constructor_005BAE70 - arg: kind=ptr,is_const=True + arg: kind=ptr,is_const=True,winapi=LPCSTR type: kind=int,size=1,signed=True,winapi=CHAR,fname=CHAR global: va=005BAEB0,name=destroy,size=15,member_of=constructor_005BAE70 type: kind=function,declspec=thiscall @@ -72901,7 +72938,7 @@ global: va=006211C0,name=sub_6211C0,size=8629 arg: kind=ptr type: kind=int,size=2 arg: kind=ptr - type: kind=winapi,name=__m64,size=8 + type: kind=winapi,name=__m64,size=8,is_union=True global: va=00623380,name=sub_623380,size=31 type: kind=function,declspec=thiscall ret: kind=int,size=4,signed=True @@ -73232,7 +73269,7 @@ global: va=00628C70,name=sub_628C70,size=182 type: kind=void arg: kind=ptr type: kind=int,size=4 - arg: kind=ptr,is_const=True + arg: kind=ptr,is_const=True,winapi=LPCSTR type: kind=int,size=1,signed=True,winapi=CHAR,fname=CHAR arg: kind=int,size=4,signed=True global: va=00628D30,name=sub_628D30,size=70 @@ -73750,13 +73787,13 @@ global: va=0062B730,name=sub_62B730,size=45 global: va=0062B760,name=sub_62B760,size=2444 type: kind=function,declspec=cdecl ret: kind=ptr - type: kind=winapi,name=__m64,size=8 + type: kind=winapi,name=__m64,size=8,is_union=True arg: kind=ptr type: kind=int,size=2 arg: kind=ptr type: kind=int,size=2 arg: kind=ptr - type: kind=winapi,name=__m64,size=8 + type: kind=winapi,name=__m64,size=8,is_union=True global: va=0062C0F0,name=sub_62C0F0,size=84 type: kind=function,declspec=thiscall ret: kind=ptr @@ -75995,7 +76032,7 @@ global: va=00636920,name=__endthreadex,size=55 global: va=00636960,name=deleteFile,size=45 type: kind=function,declspec=cdecl ret: kind=int,size=4,signed=True - arg: kind=ptr,is_const=True + arg: kind=ptr,is_const=True,winapi=LPCSTR type: kind=int,size=1,signed=True,winapi=CHAR,fname=CHAR global: va=00636990,name=__wtoi,size=48 type: kind=function,declspec=cdecl @@ -76699,7 +76736,7 @@ global: va=0063C1B0,name=sub_63C1B0,size=549 ret: kind=int,size=4,signed=True arg: kind=int,size=4,winapi=LCID,fname=DWORD arg: kind=int,size=4,fname=DWORD - arg: kind=ptr,is_const=True + arg: kind=ptr,is_const=True,winapi=LPCSTR type: kind=int,size=1,signed=True,winapi=CHAR,fname=CHAR arg: kind=ptr,is_const=True type: kind=int,size=2,winapi=WCHAR,fname=wchar_t @@ -77165,7 +77202,7 @@ global: va=006413A0,name=sub_6413A0,size=312 type: kind=function,declspec=cdecl ret: kind=int,size=4,signed=True arg: kind=int,size=4,fname=DWORD - arg: kind=ptr,is_const=True + arg: kind=ptr,is_const=True,winapi=LPCSTR type: kind=int,size=1,signed=True,winapi=CHAR,fname=CHAR arg: kind=int,size=4,signed=True arg: kind=ptr @@ -77788,38 +77825,38 @@ global: va=00653080,name=mgsr_drawTriangle24_impl5,size=2798 type: kind=function,declspec=cdecl ret: kind=int,size=4,signed=True arg: kind=ptr - type: kind=winapi,name=__m64,size=8 + type: kind=winapi,name=__m64,size=8,is_union=True arg: kind=ptr - type: kind=winapi,name=__m64,size=8 + type: kind=winapi,name=__m64,size=8,is_union=True arg: kind=ptr - type: kind=winapi,name=__m64,size=8 + type: kind=winapi,name=__m64,size=8,is_union=True global: va=00653B6E,name=mgsr_draw_1024tex_to_buf_impl6,size=1898 type: kind=function,declspec=cdecl ret: kind=int,size=4,signed=True arg: kind=ptr - type: kind=winapi,name=__m64,size=8 + type: kind=winapi,name=__m64,size=8,is_union=True arg: kind=ptr - type: kind=winapi,name=__m64,size=8 + type: kind=winapi,name=__m64,size=8,is_union=True arg: kind=ptr - type: kind=winapi,name=__m64,size=8 + type: kind=winapi,name=__m64,size=8,is_union=True global: va=006542E0,name=mgsr_drawTriangle24_impl7,size=2338 type: kind=function,declspec=cdecl ret: kind=int,size=4,signed=True arg: kind=ptr - type: kind=winapi,name=__m64,size=8 + type: kind=winapi,name=__m64,size=8,is_union=True arg: kind=ptr - type: kind=winapi,name=__m64,size=8 + type: kind=winapi,name=__m64,size=8,is_union=True arg: kind=ptr - type: kind=winapi,name=__m64,size=8 + type: kind=winapi,name=__m64,size=8,is_union=True global: va=00654C10,name=mgsr_draw_1024tex_to_buf_impl8,size=1447 type: kind=function,declspec=cdecl ret: kind=int,size=4,signed=True arg: kind=ptr - type: kind=winapi,name=__m64,size=8 + type: kind=winapi,name=__m64,size=8,is_union=True arg: kind=ptr - type: kind=winapi,name=__m64,size=8 + type: kind=winapi,name=__m64,size=8,is_union=True arg: kind=ptr - type: kind=winapi,name=__m64,size=8 + type: kind=winapi,name=__m64,size=8,is_union=True global: va=006551C0,name=mgsr_drawFuns,size=240 type: kind=array,count=60 type: kind=ptr @@ -78346,12 +78383,12 @@ global: va=0066F338,name=Drive,size=4 type: kind=ptr,is_const=True type: kind=int,size=1,signed=True,winapi=char global: va=0066F34C,name=lpSubKey,size=4 - type: kind=ptr,is_const=True + type: kind=ptr,is_const=True,winapi=LPCSTR type: kind=int,size=1,signed=True,winapi=CHAR,fname=CHAR global: va=0066F3AC,name=TbDiscFileStorage_vftable,size=48 type: kind=struct,id=instance_0066F3AC global: va=0066F46C,name=g_pKeyTable,size=4 - type: kind=ptr,is_const=True + type: kind=ptr,is_const=True,winapi=LPCSTR type: kind=int,size=1,signed=True,winapi=CHAR,fname=CHAR global: va=0066F7FC,name=CSoundSystem_vftable,size=128 type: kind=struct,id=instance_0066F7FC @@ -79675,7 +79712,7 @@ global: va=006C3CFC,name=debugStringFun_6C3CFC,size=4 type: kind=ptr type: kind=function,declspec=cdecl ret: kind=int,size=4,signed=True - arg: kind=ptr,is_const=True + arg: kind=ptr,is_const=True,winapi=LPCSTR type: kind=int,size=1,signed=True,winapi=CHAR,fname=CHAR global: va=006C3D30,name=g_confSurfDescArr,size=8 type: kind=array,count=2 @@ -80343,7 +80380,8 @@ global: va=0076AA80,name=DrawTriangleList_lpwIndices,size=6144 global: va=0076C280,name=MyEntryBuf_Triangle24_instance,size=12 type: kind=struct,id=instance_0076C280 global: va=0076C28C,name=g_flexibleVertices,size=4 - type: kind=int,size=4,signed=True + type: kind=ptr + type: kind=void global: va=0076C290,name=DrawTriangleList_dwVertexTypeDesc,size=4 type: kind=int,size=4,signed=True global: va=0076C294,name=mgsr_currentDrawFlags,size=4 @@ -80358,9 +80396,9 @@ global: va=0076C2E4,name=DrawTriangleList_trianglesCount,size=4 global: va=0076C2E8,name=g_lpwTrianglesIndices,size=4 type: kind=ptr type: kind=struct,id=instance_arr_0076AA80 -global: va=0076C2F0,name=lastSceneObject,size=4 +global: va=0076C2F0,name=g_toDraw,size=4 type: kind=ptr - type: kind=struct,id=construct_0058F79C + type: kind=struct,id=list_007820B8 global: va=0076C2F8,name=sceneObj2E_f21_to_triangleIndices,size=4092 type: kind=array,count=1023 type: kind=int,size=4,signed=True @@ -80517,9 +80555,9 @@ global: va=007820A0,name=g_renMode_7820A0,size=4 type: kind=int,size=4,signed=True global: va=007820A8,name=SceneObject2EList_instance,size=12 type: kind=struct,id=instance_007820A8 -global: va=007820B8,name=SceneObject30List_instance,size=12 +global: va=007820B8,name=ToDrawList_instance,size=12 type: kind=struct,id=instance_007820B8 -global: va=007820C4,name=objectsToDraw_count,size=4 +global: va=007820C4,name=SceneObject2E_count,size=4 type: kind=int,size=4 global: va=007820D0,name=mpeg2::_image_buf,size=65536 type: kind=array,count=65536 @@ -80915,7 +80953,7 @@ global: va=007A5698,name=g_argc,size=4 type: kind=int,size=4,signed=True global: va=007A569C,name=g_argv,size=4 type: kind=ptr - type: kind=ptr,is_const=True + type: kind=ptr,is_const=True,winapi=LPCSTR type: kind=int,size=1,signed=True,winapi=CHAR,fname=CHAR global: va=007A56B4,name=g_modFileName,size=4 type: kind=int,size=4,signed=True @@ -80943,9 +80981,9 @@ global: va=007A5C34,name=MessageBoxA_0,size=4 ret: kind=int,size=4,signed=True arg: kind=ptr,winapi=HWND type: kind=winapi,name=HWND__,size=4 - arg: kind=ptr,is_const=True + arg: kind=ptr,is_const=True,winapi=LPCSTR type: kind=int,size=1,signed=True,winapi=CHAR,fname=CHAR - arg: kind=ptr,is_const=True + arg: kind=ptr,is_const=True,winapi=LPCSTR type: kind=int,size=1,signed=True,winapi=CHAR,fname=CHAR arg: kind=int,size=4,fname=UINT global: va=007A5C38,name=GetActiveWindow,size=4 @@ -81194,14 +81232,14 @@ global: va=007A72DC,name=mgsr_dword_7A72DC,size=4 type: kind=int,size=4,signed=True global: va=007A72E0,name=mgsr_qword_7A72E0,size=504 type: kind=array,count=63 - type: kind=winapi,name=__m64,size=8 + type: kind=winapi,name=__m64,size=8,is_union=True global: va=007A74D8,name=mgsr_dword_7A74D8,size=4 type: kind=int,size=4,signed=True global: va=007A74DC,name=mgsr_dword_7A74DC,size=4 type: kind=int,size=4,signed=True global: va=007A74E0,name=mgsr_qword_7A74E0,size=528 type: kind=array,count=66 - type: kind=winapi,name=__m64,size=8 + type: kind=winapi,name=__m64,size=8,is_union=True global: va=007A76F0,name=mgsr_off_7A76F0,size=32 type: kind=array,count=8 type: kind=ptr diff --git a/mapping/ida/sgmap.py b/mapping/ida/sgmap.py index 8f111f6..69b43b7 100644 --- a/mapping/ida/sgmap.py +++ b/mapping/ida/sgmap.py @@ -372,22 +372,26 @@ def get_size(self): class WinapiType(Type): kind = TypeKind.Winapi - def __init__(self, name: str, size: int = None): + def __init__(self, name: str, size: int = None, is_union: bool = False): super().__init__() self.name = name # type: str self.size = size # type: int + self.is_union = is_union def serialize_short(self): yield from super().serialize_short() yield f"name={self.name}" if self.size is not None: yield f"size={self.size}" + if self.is_union: + yield f"is_union={self.is_union}" def deserialize(self, it: ScopeLineIter, short_props: typing.Dict[str, str]): self.name = short_props["name"] size_str = short_props.get("size", None) if size_str is not None: self.size = int(size_str) + self.is_union = short_props.get("is_union", "False").lower() == 'true' @classmethod def create(cls, short_props: typing.Dict[str, str]): diff --git a/mapping/ida/sgmap_ida.py b/mapping/ida/sgmap_ida.py index 75a3208..2e9a4a5 100644 --- a/mapping/ida/sgmap_ida.py +++ b/mapping/ida/sgmap_ida.py @@ -45,7 +45,7 @@ def is_windows_type(tname): '_UNICODE_STRING', '_LIST_ENTRY', '_PROCESSOR_NUMBER', '_LARGE_INTEGER', '_ULARGE_INTEGER', '_CURDIR', '_STRING', 'tWAVEFORMATEX', '_DSCAPS', 'DSCAPS', 'DSBCAPS', '_DSBUFFERDESC', 'WAVEFORMATEX', - 'CHAR', 'char', '_TBYTE', 'WCHAR', 'wchar_t' + 'LPCSTR', 'CHAR', 'char', '_TBYTE', 'WCHAR', 'wchar_t' ]: return True return False @@ -489,7 +489,11 @@ def try_struct(self, tif: idaapi.tinfo_t, tname: str, size: int, winapi: str): if tname == "LPDIDEVICEOBJECTDATA_10": tname = "DIDEVICEOBJECTDATA" print("replace!!") - return sgmap.WinapiType(tname, size) + til = tif.get_til() + is_union = False + if til: + is_union = tif.is_union() + return sgmap.WinapiType(tname, size, is_union) struct_ = self.structs.get_by_name(tname) if struct_ is not None: return sgmap.StructType(struct_) diff --git a/mapping/sgmap/Type.cpp b/mapping/sgmap/Type.cpp index 6737a49..cd7baac 100644 --- a/mapping/sgmap/Type.cpp +++ b/mapping/sgmap/Type.cpp @@ -264,12 +264,13 @@ bool ArrayType::lt(const Type *rhs) const { Type *WinapiType::create(ScopeLineIter &sli, std::map &shortProps, SGMapArena &arena) { - return arena.types.emplace_back(new WinapiType("", 0)).get(); + return arena.types.emplace_back(new WinapiType("", 0, false)).get(); } bool WinapiType::deserialize(ScopeLineIter &sli, std::map &shortProps, SGMapArena &arena) { name = shortProps["name"]; size = getIntOptional(shortProps, "size", 0); + is_union = getBoolOptional(shortProps, "is_union", false); return true; } @@ -280,6 +281,7 @@ size_t WinapiType::calcSize() { bool WinapiType::lt(const Type *rhs) const { const WinapiType *rhsty = (WinapiType *) rhs; if(size != rhsty->size) return size < rhsty->size; + if(is_union != rhsty->is_union) return is_union < rhsty->is_union; return name < rhsty->name; } diff --git a/mapping/sgmap/Type.h b/mapping/sgmap/Type.h index b452500..a291ed9 100644 --- a/mapping/sgmap/Type.h +++ b/mapping/sgmap/Type.h @@ -37,6 +37,9 @@ struct Type { [[nodiscard]] virtual bool link(std::map &structsMap) { return true; } bool operator <(const Type& rhs) const { +// TK_Void == TK_Function in msvc mangling + if(kind == TK_Void && rhs.kind == TK_Function) return false; + if(kind == TK_Function && rhs.kind == TK_Void) return false; if(kind != rhs.kind) return kind < rhs.kind; return lt(&rhs); } @@ -195,8 +198,9 @@ struct WinapiType : public Type { std::string name; size_t size; + bool is_union; - WinapiType(std::string name, size_t size) : Type(TK_Winapi), name(std::move(name)), size(size) {} + WinapiType(std::string name, size_t size, bool is_union) : Type(TK_Winapi), name(std::move(name)), size(size), is_union(is_union) {} ~WinapiType() override = default; [[nodiscard]] static Type *create(ScopeLineIter &sli, std::map &shortProps, SGMapArena &arena); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 191119a..f7b2f1f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,7 +3,6 @@ set(TARGET flame) add_executable(${TARGET} main.cpp dkii_exe_functions.cpp - window_proc_functions.cpp dk2/MyResources.cpp dk2/MyGame.cpp dk2/MyDxMouse.cpp @@ -19,14 +18,39 @@ add_executable(${TARGET} dk2/entities/CCreature.cpp dk2/entities/CPlayer.cpp + dk2/engine/draw_functions.cpp + dk2/engine/window_proc_functions.cpp + dk2/engine/ddraw_functions.cpp + patches/replace_mouse_dinput_to_user32.cpp patches/use_wheel_to_zoom.cpp patches/micro_patches.cpp patches/game_version_patch.cpp + patches/gog_patch_dll/gog_patch_dll.cpp + patches/gog_patch_dll/gog_cfg.cpp + patches/gog_patch_dll/gog_globals.cpp + patches/gog_patch_dll/gog_fake.cpp + patches/gog_patch_dll/gog_exports.cpp + patches/gog_patch_dll/gog_patch.cpp + patches/gog_patch_dll/fake/FakeD3D.cpp + patches/gog_patch_dll/fake/FakeD3D2.cpp + patches/gog_patch_dll/fake/FakeD3D3.cpp + patches/gog_patch_dll/fake/FakeDevice3.cpp + patches/gog_patch_dll/fake/FakeDirectDraw1.cpp + patches/gog_patch_dll/fake/FakeDirectDraw2.cpp + patches/gog_patch_dll/fake/FakeDirectDraw4.cpp + patches/gog_patch_dll/fake/FakeGammaControl.cpp + patches/gog_patch_dll/fake/FakeSurface.cpp + patches/gog_patch_dll/fake/FakeSurface4.cpp + patches/gog_patch_dll/fake/FakeTexture.cpp + patches/gog_patch_dll/fake/FakeViewport3.cpp + patches/gog_patch_dll/fake/FakeZBuffer.cpp + patches/gog_patch_dll/fake/FakeUnknown.cpp + # ${DKII_RESOURCES_FILE} ) -target_include_directories(${TARGET} PRIVATE ${CMAKE_CURRENT_LIST_DIR}) +target_include_directories(${TARGET} PRIVATE ${CMAKE_CURRENT_LIST_DIR} patches/gog_patch_dll) target_compile_definitions(${TARGET} PRIVATE DIRECTINPUT_VERSION=0x0500 DIRECT3D_VERSION=0x0600 @@ -43,7 +67,7 @@ target_link_libraries(${TARGET} PRIVATE winmm dinput_genlib # generated in dinput_dll/genlib ddraw # patch - dont link against gog's PATCH.dll because patch addresses are change after recompilation - # also i fully decompiled gog's PATCH.dll and bundled in project + dxguid imm32 # wsock32 is old link target diff --git a/src/dk2/CDefaultPlayerInterface.cpp b/src/dk2/CDefaultPlayerInterface.cpp index 750a228..ed5cd4a 100644 --- a/src/dk2/CDefaultPlayerInterface.cpp +++ b/src/dk2/CDefaultPlayerInterface.cpp @@ -5,6 +5,7 @@ #include "dk2_functions.h" #include "dk2_globals.h" #include "patches/micro_patches.h" +#include "gog_patch.h" int dk2::CDefaultPlayerInterface::tickKeyboard2() { @@ -22,7 +23,7 @@ int dk2::CDefaultPlayerInterface::tickKeyboard2() { int dwWidth = MyGame_instance.dwWidth; int dwHeight = MyGame_instance.dwHeight; - if(!control_windowed_mode::disable_move_by_mouse) { + if(!control_windowed_mode::enabled) { if ( x < 5 ) this->pushMoveKeyAction(0, 0); if ( x > dwWidth - 5 ) @@ -85,3 +86,36 @@ int dk2::CDefaultPlayerInterface::tickKeyboard2() { v18_try_catch = 2; return this->pushAction(&v17_action); } + + +void dk2::CDefaultPlayerInterface::createSurfacesForView_42CDF0(RtGuiView *view) { + CBridge *f10_c_bridge = this->profiler->c_bridge; + char *rowPos = (char *) view->surf.lpSurface; + int v4_bytesPerPix = view->dwRGBBitCount / 8; + int v13_lineSize = 32 * view->surf.lPitch; + char *v10__allyWindowText = (char *) view->surf.lpSurface; + for(unsigned int y = 0; y < view->height_32blocks; ++y) { + char *linePos = rowPos; + for(unsigned int x = 0; x < view->width_128blocks; ++x) { + int lPitch = view->surf.lPitch; + Pos2i v14_size; + v14_size.x = 128; + v14_size.y = 32; + MySurface v15_surf; + v15_surf.constructor(&v14_size, &view->surf.desc, linePos, lPitch); + int _idx = x + view->width_128blocks * y; + if(gog::RtGuiView_fix::enable) { + if(idx >= 93 && view == &dk2::CDefaultPlayerInterface_instance._allyWindowText) { + idx = 0; + } + } + int _id = view->Arrp31x400_ids[_idx]; + f10_c_bridge->v_f68(_id, &v15_surf, 1); + linePos += v4_bytesPerPix * 128; + } + rowPos = &v10__allyWindowText[v13_lineSize]; + v10__allyWindowText += v13_lineSize; + } +} + + diff --git a/src/dk2/MyDxMouse.cpp b/src/dk2/MyDxMouse.cpp index 2554e08..20613cd 100644 --- a/src/dk2/MyDxMouse.cpp +++ b/src/dk2/MyDxMouse.cpp @@ -10,6 +10,7 @@ #include "dk2/MouseXyzDxAction.h" #include "dk2/MouseRgbDxAction.h" #include "dk2/ControlKeysUpdater.h" +#include "dk2/MyDxKeyboard.h" #include "dk2_functions.h" #include "patches/replace_mouse_dinput_to_user32.h" #include "patches/use_wheel_to_zoom.h" @@ -121,3 +122,11 @@ void dk2::MyDxMouse::handleData(int count) { } } +uint32_t *dk2::MyDxInputManagerCb::onWindowActivated(uint32_t *psatatus, int isActivated) { + this->f54_pdxKeyboard->dx_device.updateWindowActive(isActivated); + if (!replace_mouse_dinput_to_user32::enabled) { + this->f58_pdxmouse->dx_device.updateWindowActive(isActivated); + } + this->updateCoopLevelAndSignal(psatatus); + return psatatus; +} diff --git a/src/dk2/MyGame.cpp b/src/dk2/MyGame.cpp index ff1009f..33c8e69 100644 --- a/src/dk2/MyGame.cpp +++ b/src/dk2/MyGame.cpp @@ -17,8 +17,9 @@ int dk2::MyGame::prepareScreenEx( int isWindowed, int screenSwap, int screenHardware3D) { - if(control_windowed_mode::enabled) { - printf("prepareScreen %p %dx%d %d %d %d %d\n", this, dwWidth, dwHeight, dwRGBBitCount, isWindowed, screenSwap, screenHardware3D); + if (control_windowed_mode::enabled) { + printf("prepareScreen %p %dx%d %d %d %d %d\n", this, dwWidth, dwHeight, dwRGBBitCount, isWindowed, screenSwap, + screenHardware3D); isWindowed = true; // todo: control } int sel_dd_idx = this->selected_dd_idx; @@ -137,12 +138,11 @@ int dk2::MyGame::prepareScreenEx( MyResources_instance.soundCfg.numberOfChannels); MyResources_instance.soundCfg.resolveValues(); } - int screenSwap__1 = screenSwap; this->isWindowed = isWindowed; this->dwWidth = dwWidth; this->dwHeight = dwHeight_; this->dwRGBBitCount = dwRGBBitCount_; - this->_prepareScreen_a6 = screenSwap__1; + this->_prepareScreen_a6 = screenSwap; this->_prepareScreen_a7 = screenHardware3D_; this->f18 = 0; this->collect3dDevices(); @@ -184,3 +184,51 @@ int dk2::MyGame::prepareScreenEx( ij_ImmAssociateContext(HWindow, 0); return 1; } + +namespace dk2 { + void inline_selectDrawEngine(dk2::MyGame *game); +} +int dk2::MyGame::init() { + inline_selectDrawEngine(this); + int status; + if (*MyInputManagerCb_static_initKeyInputs(&status) < 0) { + return 0; + } + int status_; + if (*MyInputManagerCb_static_initCursorInputs(&status_) < 0) { + return 0; + } + if (!this->createWindow(1)) { + return 0; + } + if (!this->prepareScreenEx( + MyResources_instance.video_settings.display_width, + MyResources_instance.video_settings.display_height, + MyResources_instance.video_settings.display_bitnes, + MyResources_instance.video_settings.isWindowed, + MyResources_instance.video_settings.screen_swap, + MyResources_instance.video_settings.screen_hardware3D) + && !this->prepareScreenEx( + 640, + 480, + MyResources_instance.video_settings.display_bitnes, + MyResources_instance.video_settings.isWindowed, + MyResources_instance.video_settings.screen_swap, + MyResources_instance.video_settings.screen_hardware3D)) { + printf("failed to prepare screen\n"); + return 0; + } + setCustomDefWindowProcA((int) myCustomDefWindowProcA); + WinEventHandlers_instance.addHandler( + 0, + (void (__stdcall *)(int, int, void *)) static_MyGame_Event07_cb, + this); + this->fE71 = 0; + this->fE75 = 0; + this->recreateRequest = 0; + this->fE7D = 0; + this->moonAge = calc_moon_age(); + this->f0 = 1; + this->fF51 = 0; + return 1; +} diff --git a/src/dk2/RegKey.cpp b/src/dk2/RegKey.cpp index 92ecf63..b75c4ad 100644 --- a/src/dk2/RegKey.cpp +++ b/src/dk2/RegKey.cpp @@ -3,6 +3,8 @@ // #include "dk2/RegKey.h" #include "patches/micro_patches.h" +#include "gog_cfg.h" +#include "gog_patch.h" unsigned int dk2::RegKey::settings_readBytesCount(LPCSTR lpValueName) { @@ -46,3 +48,44 @@ uint32_t *__thiscall dk2::RegKey::settings_readBytes(uint32_t *pstatus, LPCSTR l return pstatus; } + +int *dk2::RegKey::settings_readValue(int *pstatus, LPCSTR lpValueName, uint32_t *pValue) { + if(gog::RegistryConfig_patch::enable) { + if (gog::cfg::patchRegistryConfig(pstatus, lpValueName, (DWORD *) pValue) != -1) return pstatus; + } + if (!lpValueName || this->key == NULL) { + *pstatus = -1; + return pstatus; + } + DWORD Type = 0; + DWORD value; + DWORD cbData = sizeof(value); + if(RegQueryValueExA(this->key, lpValueName, NULL, &Type, (LPBYTE) &value, &cbData) != ERROR_SUCCESS) { + *pstatus = -1; + return pstatus; + } + signed int v8_type; + if (RegQueryValueExA(this->key, lpValueName, NULL, &Type, NULL, NULL) != ERROR_SUCCESS) { + HKEY tmp; + if (RegOpenKeyA(this->key, lpValueName, &tmp)) { + v8_type = -1; + } else { + RegCloseKey(tmp); + v8_type = -2; + } + } else { + v8_type = Type; + } + if (v8_type == REG_DWORD || v8_type == REG_DWORD_BIG_ENDIAN) { + *pValue = value; + *pstatus = 0; + return pstatus; + } + if (v8_type == REG_LINK) { + *pValue = _byteswap_ulong(value); + *pstatus = 0; + return pstatus; + } + *pstatus = -1; + return pstatus; +} \ No newline at end of file diff --git a/src/dk2/engine/ddraw_functions.cpp b/src/dk2/engine/ddraw_functions.cpp new file mode 100644 index 0000000..de71dd5 --- /dev/null +++ b/src/dk2/engine/ddraw_functions.cpp @@ -0,0 +1,191 @@ +// +// Created by DiaLight on 12.09.2024. +// +#include +#include "dk2_functions.h" +#include "dk2_globals.h" +#include "dk2/DxDeviceInfo.h" +#include "dk2/DxD3dInfo.h" +#include "gog_patch.h" +#include "gog_exports.h" + + +BOOL dk2::collect_devices_DDEnumCB(GUID *lpGUID, const CHAR *driverName, const CHAR *driverDesc, LPVOID a4) { + int device_idx = ddraw_device_count; + DxDeviceInfo *devs; + if ( ddraw_device_count ) { + static_assert(sizeof(DxDeviceInfo) == 0x21A); + devs = (DxDeviceInfo *) realloc(ddraw_devices, sizeof(DxDeviceInfo) * (ddraw_device_count + 1)); + } else { + devs = (DxDeviceInfo *)_malloc_1(538u); + } + ddraw_devices = devs; + int device_offs = device_idx; + if (lpGUID) { + devs[device_idx].pGuid = &devs[device_idx].guid; + ddraw_devices[device_idx].guid = *lpGUID; + } else { + devs[device_idx].pGuid = NULL; + } + lstrcpyA(ddraw_devices[device_offs].desc, driverName); + lstrcpyA(ddraw_devices[device_offs].name, driverDesc); + ddraw_devices[device_offs].modeListCount = 0; + ddraw_devices[device_offs].modeList = NULL; + ddraw_devices[device_offs].infoListCount = 0; + ddraw_devices[device_offs].infoList = NULL; + + LPDIRECTDRAW lpDD; + if(gog::enable) { + fake_DirectDrawCreate(lpGUID, &lpDD, NULL); + } else { + DirectDrawCreate(lpGUID, &lpDD, NULL); + } + + static_assert(sizeof(DDCAPS_DX7) == 380); + ddraw_devices->ddcaps.dwSize = sizeof(DDCAPS_DX7); + lpDD->GetCaps(&ddraw_devices->ddcaps, NULL); + + DxDeviceInfo *ddraw_device = &ddraw_devices[device_offs]; + ddraw_device->dwVendorId = 0; + ddraw_device->dwDeviceId = 0; + + IDirectDraw4 *dd4; + DDDEVICEIDENTIFIER ddDevId; + if (SUCCEEDED(lpDD->QueryInterface(CLSID_IDirectDraw4, (LPVOID *)&dd4)) + && SUCCEEDED(dd4->GetDeviceIdentifier(&ddDevId, 1)) ) { + ddraw_device->dwVendorId = ddDevId.dwVendorId; + ddraw_device->dwDeviceId = ddDevId.dwDeviceId; + dd4->Release(); + } + ddraw_devices[device_offs].isVendor121A = 0; + if ( ddraw_devices[device_offs].dwVendorId == 0x121A ) { + int f212_dwDeviceId = ddraw_devices[device_offs].dwDeviceId; + if ( f212_dwDeviceId == 1 || f212_dwDeviceId == 2 ) { + ddraw_devices[device_offs].isVendor121A = 1; + } + } + IDirect3D *d3d; + lpDD->QueryInterface(CLSID_IDirect3D, (LPVOID *)&d3d); + d3d->EnumDevices((LPD3DENUMDEVICESCALLBACK)collect_devices_DDEnumDevicesCB, (LPVOID)device_idx); + d3d->Release(); + lpDD->Release(); + ++ddraw_device_count; + return 1; +} + +BOOL dk2::collect_displayModes_DDEnumCB(GUID *lpGUID, LPSTR a2, LPSTR a3, HWND hWindow) { + LPDIRECTDRAW lpDD; + if(gog::enable) { + fake_DirectDrawCreate(lpGUID, &lpDD, NULL); + } else { + DirectDrawCreate(lpGUID, &lpDD, NULL); + } + lpDD->SetCooperativeLevel(hWindow, 21); + ddraw_devices[dd_index].modeListCount = 0; + lpDD->EnumDisplayModes(0, NULL, (void *)dd_index, (LPDDENUMMODESCALLBACK)collect_displayModes_DDEnumModesCB); + lpDD->SetCooperativeLevel(hWindow, 8); + lpDD->Release(); + ++dd_index; + return 1; +} + +int *__cdecl dk2::createDirectDrawObject(int *pstatus, GUID *lpGUID, LPDIRECTDRAW *lplpDD) { + HRESULT hresult; + if(gog::enable) { + hresult = fake_DirectDrawCreate(lpGUID, lplpDD, NULL); + } else { + hresult = DirectDrawCreate(lpGUID, lplpDD, NULL); + } + if (hresult != DD_OK) { + *pstatus = -1; + return pstatus; + } + if (hBullfrogWindow) setHWindow(hBullfrogWindow); + *pstatus = 0; + return pstatus; +} + + +int dk2::getDevIdxSupportsLinearPerspective() { + int devCount = ddraw_device_count; + if (ddraw_device_count == 0) { + if(gog::enable) { + fake_DirectDrawEnumerateA((LPDDENUMCALLBACKA) collect_devices_DDEnumCB, NULL); + } else { + DirectDrawEnumerateA((LPDDENUMCALLBACKA) collect_devices_DDEnumCB, NULL); + } + devCount = ddraw_device_count; + } + static_assert(sizeof(DxDeviceInfo) == 0x21A); + for (int i = 0; i < devCount; ++i) { + DxD3dInfo *d3dInfo = ddraw_devices[i].infoList; + if (!d3dInfo) continue; + if (!d3dInfo->hasDesc) continue; + if (!d3dInfo->texCapsAnd1) continue; + if (!d3dInfo->hasZbuffer) continue; + D3DDEVICEDESC devDesc = d3dInfo->devDesc; + if ((devDesc.dpcTriCaps.dwTextureCaps & 1) == 0) continue; + if ((devDesc.dpcTriCaps.dwTextureFilterCaps & 2) == 0) continue; + return i; + } + return -1; +} + + +namespace dk2 { + void inline_selectDrawEngine(dk2::MyGame *game) { + game->dds_count = 0; + if(gog::enable) { + fake_DirectDrawEnumerateA((LPDDENUMCALLBACKA) collect_namesAndDescs_DDEnumCB, game); + if (ddraw_device_count == 0) + fake_DirectDrawEnumerateA((LPDDENUMCALLBACKA) collect_devices_DDEnumCB, NULL); + if (dd_index == 0) + fake_DirectDrawEnumerateA((LPDDENUMCALLBACKA) collect_displayModes_DDEnumCB, getHWindow()); + } else { + DirectDrawEnumerateA((LPDDENUMCALLBACKA) collect_namesAndDescs_DDEnumCB, game); + if (ddraw_device_count == 0) + DirectDrawEnumerateA((LPDDENUMCALLBACKA) collect_devices_DDEnumCB, NULL); + if (dd_index == 0) + DirectDrawEnumerateA((LPDDENUMCALLBACKA) collect_displayModes_DDEnumCB, getHWindow()); + } + int selectedDdIdx = -1; + if (!MyResources_instance.video_settings.cmd_flag_SOFTWARE) { + if (cmd_flag_DDD) { + game->selected_dd_idx = cmd_flag_DDD_value; + return; + } + int devCount = ddraw_device_count; + if (MyResources_instance.video_settings.guid_index < ddraw_device_count + && MyResources_instance.video_settings.guid_index_verifier_working) { + game->selected_dd_idx = MyResources_instance.video_settings.guid_index; + return; + } + if (!ddraw_device_count) { + if(gog::enable) { + fake_DirectDrawEnumerateA((LPDDENUMCALLBACKA) collect_devices_DDEnumCB, 0); + } else { + DirectDrawEnumerateA((LPDDENUMCALLBACKA) collect_devices_DDEnumCB, 0); + } + devCount = ddraw_device_count; + } + if (devCount > 0) { + for (int i = 0; i < ddraw_device_count; ++i) { + if(isDevSupports_D3DPTFILTERCAPS_LINEARMIPNEAREST(i)) { + selectedDdIdx = i; + break; + } + } + } + } + if (selectedDdIdx < 0) { + // software render engine + MyResources_instance.video_settings.setSelected3dEngine(4); + MyResources_instance.video_settings.sub_566E40(0); + game->selected_dd_idx = 0; + } else { + MyResources_instance.video_settings.setSelected3dEngine(2); + MyResources_instance.video_settings.sub_566E40(selectedDdIdx); + game->selected_dd_idx = selectedDdIdx; + } + } +} diff --git a/src/dk2/engine/draw_functions.cpp b/src/dk2/engine/draw_functions.cpp new file mode 100644 index 0000000..95298bf --- /dev/null +++ b/src/dk2/engine/draw_functions.cpp @@ -0,0 +1,66 @@ +// +// Created by DiaLight on 10.09.2024. +// + +#include "dk2_functions.h" +#include "dk2_globals.h" +#include "dk2/Vertex18.h" +#include "dk2/ToDraw.h" +#include "dk2/SurfaceHolder.h" +#include "dk2/CEngineDDSurface.h" +#include "gog_patch.h" + +void dk2::drawTexToSurfTriangles() { + ToDraw *toDraw = g_toDraw; + if ((g_toDraw->drawFlags_x2[0] & 0x200) != 0) { + g_totalVerticesCount += dk2::DrawTriangleList_verticesCount; + g_totalTrianglesCount += dk2::DrawTriangleList_trianglesCount; + return; + } + if (!dk2::DrawTriangleList_verticesCount) return; + int holderIdx = 0; + if (!g_toDraw->propsCount) return; + VerticesData *p_fC_vertices18x2 = dk2::g_vertices; + for(signed int texStageIdx = 0; texStageIdx < g_toDraw->propsCount; ++texStageIdx) { + for(signed int stage = 0; stage < g_toDraw->numTextureSamplers_x2[texStageIdx]; ++stage) { + SurfaceHolder *holder = toDraw->holders[holderIdx]; + renderer_setSurfaceHolder(holder, stage); + toDraw = g_toDraw; + ++holderIdx; + } + if ((mydd_triangles.flags & 1) != 0) { // 3dengine == 4 + mgsr_setDrawFun(toDraw->drawFlags_x2[texStageIdx]); + if (dk2::DrawTriangleList_trianglesCount) { + Vec3s *vertIndexPos = dk2::DrawTriangleList_lpwIndices; + int trianglesLeft = dk2::DrawTriangleList_trianglesCount; + do { + mgsr_drawTriangle24_impl5( + (__m64 *) &p_fC_vertices18x2->vertices18x2[vertIndexPos->x], + (__m64 *) &p_fC_vertices18x2->vertices18x2[vertIndexPos->y], + (__m64 *) &p_fC_vertices18x2->vertices18x2[vertIndexPos->z] + ); + ++vertIndexPos; + --trianglesLeft; + } while (trianglesLeft); + } + _m_empty(); + } else { + DirectDraw_prepareTexture(toDraw->drawFlags_x2[texStageIdx]); + DrawTriangleList(texStageIdx, dk2::DrawTriangleList_trianglesCount, dk2::DrawTriangleList_verticesCount); + } + toDraw = g_toDraw; + ++p_fC_vertices18x2; + } +} + +void __cdecl dk2::renderer_setSurfaceHolder(SurfaceHolder *holder, uint32_t stage) { + if(gog::SurfaceHolder_setTexture_patch::enable) { + if(!holder) return; + } + if ( (mydd_scene.flags & 1) != 0 ) { // 3dengine == 4 + mgsr_lockedBuf_dw256x256 = (uint32_t *) holder->ddsurf->v_lockBuf(); + } else { + mydd_devTexture.d3d3_halDevice->SetTexture(stage, holder->ddsurf->devTex); + if (holder->ddsurf->ddSurf->IsLost()) g_isCurDdSurfLost = 1; + } +} \ No newline at end of file diff --git a/src/window_proc_functions.cpp b/src/dk2/engine/window_proc_functions.cpp similarity index 84% rename from src/window_proc_functions.cpp rename to src/dk2/engine/window_proc_functions.cpp index fa861db..0dc32c4 100644 --- a/src/window_proc_functions.cpp +++ b/src/dk2/engine/window_proc_functions.cpp @@ -2,16 +2,17 @@ // Created by DiaLight on 25.08.2024. // #include -#include #include #include "dk2/MyMouseUpdater.h" -#include "dk2/button/CTextBox.h" #include "dk2/Event0_winShown7.h" #include "dk2_functions.h" #include "dk2_globals.h" #include "patches/replace_mouse_dinput_to_user32.h" #include "patches/micro_patches.h" #include "patches/use_wheel_to_zoom.h" +#include "gog_patch.h" +#include "gog_globals.h" +#include "gog_debug.h" int __cdecl dk2::getCustomDefWindowProcA() { return customDefWindowProcA; @@ -44,10 +45,7 @@ LRESULT dk2::CWindowTest_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) break; } case WM_MOUSEMOVE: { - if(replace_mouse_dinput_to_user32::enabled) { - POINT mousePos = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)}; - replace_mouse_dinput_to_user32::handle_mouse_move(hWnd, mousePos); - } else { + if(!replace_mouse_dinput_to_user32::enabled) { Pos2i pos; pos.x = LOWORD(lParam); pos.y = HIWORD(lParam); @@ -64,6 +62,11 @@ LRESULT dk2::CWindowTest_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) } LRESULT dk2::BullfrogWindow_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { + replace_mouse_dinput_to_user32::emulate_dinput_from_user32(hWnd, Msg, wParam, lParam); + use_wheel_to_zoom::window_proc(hWnd, Msg, wParam, lParam); + fix_keyboard_state_on_alt_tab::window_proc(hWnd, Msg, wParam, lParam); + if(gog::BullfrogWindow_proc_patch::window_proc(hWnd, Msg, wParam, lParam)) + return DefWindowProcA(hWnd, Msg, wParam, lParam); switch (Msg) { case WM_ACTIVATEAPP: g_isWindowActivated = wParam != 0; @@ -95,6 +98,7 @@ LRESULT dk2::BullfrogWindow_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lPar } break; } + if(hide_mouse_cursor_in_window::window_proc(hWnd, Msg, wParam, lParam)) return TRUE; if (auto CustomDefWindowProcA = (CustomDefWindowProcA_t) getCustomDefWindowProcA()) CustomDefWindowProcA(hWnd, Msg, wParam, lParam); diff --git a/src/dkii_exe_functions.cpp b/src/dkii_exe_functions.cpp index 8c3e74f..13bf307 100644 --- a/src/dkii_exe_functions.cpp +++ b/src/dkii_exe_functions.cpp @@ -8,6 +8,8 @@ #include "dk2_globals.h" #include "patches/micro_patches.h" #include "patches/game_version_patch.h" +#include "gog_patch.h" +#include "gog_cfg.h" int32_t dk2::MyGame::isOsCompatible() { @@ -67,6 +69,14 @@ void dk2::resolveDk2HomeDir() { } BOOL __cdecl dk2::parse_command_line(int argc, const char **argv) { + if(gog::parseCommandLine_patch::enable) { + dk2::MyResources_instance.video_settings.cmd_flag_32BITTEXTURES = 1; + dk2::MyResources_instance.video_settings.zbuffer_bitnes = 32; + dk2::MyResources_instance.video_settings.display_bitnes = 32; + if (gog::cfg::iBumpmap) { + dk2::MyResources_instance.video_settings.setBumpMappingEnabled(1); + } + } MyGame_debugMsg(&MyGame_instance, "Cmd Line: "); for (int i = 0; i < argc; ++i) { MyGame_debugMsg(&MyGame_instance, "%s ", argv[i]); diff --git a/src/main.cpp b/src/main.cpp index 659ffbd..5124eb0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,7 @@ #include "dk2_globals.h" #include "dk2/MyMutex.h" #include "patches/micro_patches.h" +#include "gog_patch.h" namespace dk2 { @@ -254,6 +255,7 @@ int dk2::WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, CHAR *lpCmdLine, int main() { // call entry point of DKII.EXE, + if(gog::enable) gog::patch_init(); // initialize its runtime and call dk2::WinMain dk2::dk2_start(); } diff --git a/src/patches/gog_patch_dll/fake/FakeD3D.cpp b/src/patches/gog_patch_dll/fake/FakeD3D.cpp new file mode 100644 index 0000000..3c94698 --- /dev/null +++ b/src/patches/gog_patch_dll/fake/FakeD3D.cpp @@ -0,0 +1,267 @@ +// +// Created by DiaLight on 20.01.2023. +// +#include +#include + +using namespace gog; + +FakeD3D *FakeD3D::instance = nullptr; + +HRESULT FakeD3D::QueryInterface(REFIID riid, LPVOID *ppvObj) { + gog_debug("Unused function called: FakeD3D::QueryInterface"); + return DDERR_GENERIC; +} + +HRESULT FakeD3D::Initialize(REFCLSID) { + gog_debug("Unused function called: FakeD3D::Initialize"); + return DDERR_GENERIC; +} + +typedef struct _D3DDeviceDesc1 { + DWORD dwSize; /* Size of D3DDEVICEDESC2 structure */ + DWORD dwFlags; /* Indicates which fields have valid data */ + D3DCOLORMODEL dcmColorModel; /* Color model of device */ + DWORD dwDevCaps; /* Capabilities of device */ + D3DTRANSFORMCAPS dtcTransformCaps; /* Capabilities of transform */ + BOOL bClipping; /* Device can do 3D clipping */ + D3DLIGHTINGCAPS dlcLightingCaps; /* Capabilities of lighting */ + D3DPRIMCAPS dpcLineCaps; + D3DPRIMCAPS dpcTriCaps; + DWORD dwDeviceRenderBitDepth; /* One of DDBB_8, 16, etc.. */ + DWORD dwDeviceZBufferBitDepth;/* One of DDBD_16, 32, etc.. */ + DWORD dwMaxBufferSize; /* Maximum execute buffer size */ + DWORD dwMaxVertexCount; /* Maximum vertex count */ +} D3DDEVICEDESC1, *LPD3DDEVICEDESC1; +static_assert(sizeof(D3DDEVICEDESC1) == 0xAC); +static_assert(sizeof(D3DDEVICEDESC) == 0xFC); + +HRESULT FakeD3D::EnumDevices(LPD3DENUMDEVICESCALLBACK cb, LPVOID a3) { + D3DDEVICEDESC rampDesc1; + rampDesc1.dwSize = sizeof(D3DDEVICEDESC1); + memset(&rampDesc1.dwFlags, 0, 0xC); + rampDesc1.dtcTransformCaps.dwSize = 8; + rampDesc1.dtcTransformCaps.dwCaps = 0; + rampDesc1.bClipping = 0; + rampDesc1.dlcLightingCaps.dwSize = 0x10; + memset(&rampDesc1.dlcLightingCaps.dwCaps, 0, 0xC); + rampDesc1.dpcLineCaps.dwSize = 0x38; + memset(&rampDesc1.dpcLineCaps.dwMiscCaps, 0, 0x34); + rampDesc1.dpcTriCaps.dwSize = 0x38; + memset(&rampDesc1.dpcTriCaps.dwMiscCaps, 0, 0x44); + + + D3DDEVICEDESC1 rampDesc2; + rampDesc2.dwSize = sizeof(D3DDEVICEDESC1); + rampDesc2.dwFlags = 0x7DF; + rampDesc2.dcmColorModel = 1; + rampDesc2.dwDevCaps = 0x55B; + rampDesc2.dtcTransformCaps.dwSize = 8; + rampDesc2.dtcTransformCaps.dwCaps = 1; + rampDesc2.bClipping = 1; + rampDesc2.dlcLightingCaps.dwSize = 0x10; + rampDesc2.dlcLightingCaps.dwCaps = 0xF; + rampDesc2.dlcLightingCaps.dwLightingModel = 2; + rampDesc2.dlcLightingCaps.dwNumLights = 0; + rampDesc2.dpcLineCaps.dwSize = 0x38; + rampDesc2.dpcLineCaps.dwMiscCaps = 0x70; + rampDesc2.dpcLineCaps.dwRasterCaps = 0x51; + rampDesc2.dpcLineCaps.dwZCmpCaps = 0xFF; + memset(&rampDesc2.dpcLineCaps.dwSrcBlendCaps, 0, 0xC); + rampDesc2.dpcLineCaps.dwShadeCaps = 0xA145; + rampDesc2.dpcLineCaps.dwTextureCaps = 0xB; + rampDesc2.dpcLineCaps.dwTextureFilterCaps = 5; + rampDesc2.dpcLineCaps.dwTextureBlendCaps = 0x42; + rampDesc2.dpcLineCaps.dwTextureAddressCaps = 1; + rampDesc2.dpcLineCaps.dwStippleWidth = 4; + rampDesc2.dpcLineCaps.dwStippleHeight = 4; + rampDesc2.dpcTriCaps.dwSize = 0x38; + rampDesc2.dpcTriCaps.dwMiscCaps = 0x70; + rampDesc2.dpcTriCaps.dwRasterCaps = 0x51; + rampDesc2.dpcTriCaps.dwZCmpCaps = 0xFF; + memset(&rampDesc2.dpcTriCaps.dwSrcBlendCaps, 0, 0xC); + rampDesc2.dpcTriCaps.dwShadeCaps = 0xA145; + rampDesc2.dpcTriCaps.dwTextureCaps = 0xB; + rampDesc2.dpcTriCaps.dwTextureFilterCaps = 5; + rampDesc2.dpcTriCaps.dwTextureBlendCaps = 0x42; + rampDesc2.dpcTriCaps.dwTextureAddressCaps = 1; + rampDesc2.dpcTriCaps.dwStippleWidth = 4; + rampDesc2.dpcTriCaps.dwStippleHeight = 4; + rampDesc2.dwDeviceRenderBitDepth = 0xF00; + rampDesc2.dwDeviceZBufferBitDepth = 0x400; + rampDesc2.dwMaxBufferSize = 0; + rampDesc2.dwMaxVertexCount = 2021; + + + D3DDEVICEDESC1 rgbemuDesc1; + rgbemuDesc1.dwSize = sizeof(D3DDEVICEDESC1); + memset(&rgbemuDesc1.dwFlags, 0, 0xC); + rgbemuDesc1.dtcTransformCaps.dwSize = 8; + rgbemuDesc1.dtcTransformCaps.dwCaps = 0; + rgbemuDesc1.bClipping = 0; + rgbemuDesc1.dlcLightingCaps.dwSize = 0x10; + memset(&rgbemuDesc1.dlcLightingCaps.dwCaps, 0, 0xC); + rgbemuDesc1.dpcLineCaps.dwSize = 0x38; + memset(&rgbemuDesc1.dpcLineCaps.dwMiscCaps, 0, 0x34); + rgbemuDesc1.dpcTriCaps.dwSize = 0x38; + memset(&rgbemuDesc1.dpcTriCaps.dwMiscCaps, 0, 0x44); + + + D3DDEVICEDESC1 rgbemuDesc2; + rgbemuDesc2.dwSize = sizeof(D3DDEVICEDESC1); + rgbemuDesc2.dwFlags = 0x7DF; + rgbemuDesc2.dcmColorModel = 2; + rgbemuDesc2.dwDevCaps = 0x55B; + rgbemuDesc2.dtcTransformCaps.dwSize = 8; + rgbemuDesc2.dtcTransformCaps.dwCaps = 1; + rgbemuDesc2.bClipping = 1; + rgbemuDesc2.dlcLightingCaps.dwSize = 0x10; + rgbemuDesc2.dlcLightingCaps.dwCaps = 0xF; + rgbemuDesc2.dlcLightingCaps.dwLightingModel = 1; + rgbemuDesc2.dlcLightingCaps.dwNumLights = 0; + rgbemuDesc2.dpcLineCaps.dwSize = 0x38; + rgbemuDesc2.dpcLineCaps.dwMiscCaps = 0x70; + rgbemuDesc2.dpcLineCaps.dwRasterCaps = 0x1D1; + rgbemuDesc2.dpcLineCaps.dwZCmpCaps = 0xFF; + memset(&rgbemuDesc2.dpcLineCaps.dwSrcBlendCaps, 0, 0xC); + rgbemuDesc2.dpcLineCaps.dwShadeCaps = 0xCA28A; + rgbemuDesc2.dpcLineCaps.dwTextureCaps = 0xB; + rgbemuDesc2.dpcLineCaps.dwTextureFilterCaps = 0x1F; + rgbemuDesc2.dpcLineCaps.dwTextureBlendCaps = 0x42; + rgbemuDesc2.dpcLineCaps.dwTextureAddressCaps = 1; + rgbemuDesc2.dpcLineCaps.dwStippleWidth = 4; + rgbemuDesc2.dpcLineCaps.dwStippleHeight = 4; + rgbemuDesc2.dpcTriCaps.dwSize = 0x38; + rgbemuDesc2.dpcTriCaps.dwMiscCaps = 0x70; + rgbemuDesc2.dpcTriCaps.dwRasterCaps = 0x1D1; + rgbemuDesc2.dpcTriCaps.dwZCmpCaps = 0xFF; + memset(&rgbemuDesc2.dpcTriCaps.dwSrcBlendCaps, 0, 0xC); + rgbemuDesc2.dpcTriCaps.dwShadeCaps = 0xCA28A; + rgbemuDesc2.dpcTriCaps.dwTextureCaps = 0xB; + rgbemuDesc2.dpcTriCaps.dwTextureFilterCaps = 0x1F; + rgbemuDesc2.dpcTriCaps.dwTextureBlendCaps = 0x42; + rgbemuDesc2.dpcTriCaps.dwTextureAddressCaps = 1; + rgbemuDesc2.dpcTriCaps.dwStippleWidth = 4; + rgbemuDesc2.dpcTriCaps.dwStippleHeight = 4; + rgbemuDesc2.dwDeviceRenderBitDepth = 0xF00; + rgbemuDesc2.dwDeviceZBufferBitDepth = 0x400; + rgbemuDesc2.dwMaxBufferSize = 0; + rgbemuDesc2.dwMaxVertexCount = 2021; + + + D3DDEVICEDESC1 halDesc1; + halDesc1.dwSize = sizeof(D3DDEVICEDESC1); + halDesc1.dwFlags = 0x1FF; + halDesc1.dcmColorModel = 2; + halDesc1.dwDevCaps = 0x61BBEF1; + halDesc1.dtcTransformCaps.dwSize = 8; + halDesc1.dtcTransformCaps.dwCaps = 1; + halDesc1.bClipping = 1; + halDesc1.dlcLightingCaps.dwSize = 0x10; + halDesc1.dlcLightingCaps.dwCaps = 7; + halDesc1.dlcLightingCaps.dwLightingModel = 1; + halDesc1.dlcLightingCaps.dwNumLights = 0; + halDesc1.dpcLineCaps.dwSize = 0x38; + halDesc1.dpcLineCaps.dwMiscCaps = 0x3FAC83; + halDesc1.dpcLineCaps.dwRasterCaps = 0xC7361B3; + halDesc1.dpcLineCaps.dwZCmpCaps = 0xFF; + halDesc1.dpcLineCaps.dwSrcBlendCaps = 0x1FFF; + halDesc1.dpcLineCaps.dwDestBlendCaps = 0x1FFF; + halDesc1.dpcLineCaps.dwAlphaCmpCaps = 0xFF; + halDesc1.dpcLineCaps.dwShadeCaps = 0xC528A; + halDesc1.dpcLineCaps.dwTextureCaps = 0x1EC4D; + halDesc1.dpcLineCaps.dwTextureFilterCaps = 0x703073F; + halDesc1.dpcLineCaps.dwTextureBlendCaps = 0xCF; + halDesc1.dpcLineCaps.dwTextureAddressCaps = 0x3F; + halDesc1.dpcLineCaps.dwStippleWidth = 0; + halDesc1.dpcLineCaps.dwStippleHeight = 0; + halDesc1.dpcTriCaps.dwSize = 0x38; + halDesc1.dpcTriCaps.dwMiscCaps = 0x3FACF3; + halDesc1.dpcTriCaps.dwRasterCaps = 0xC7361B3; + halDesc1.dpcTriCaps.dwZCmpCaps = 0xFF; + halDesc1.dpcTriCaps.dwSrcBlendCaps = 0x1FFF; + halDesc1.dpcTriCaps.dwDestBlendCaps = 0x1FFF; + halDesc1.dpcTriCaps.dwAlphaCmpCaps = 0xFF; + halDesc1.dpcTriCaps.dwShadeCaps = 0xC528A; + halDesc1.dpcTriCaps.dwTextureCaps = 0x1EC4D; + halDesc1.dpcTriCaps.dwTextureFilterCaps = 0x703073F; + halDesc1.dpcTriCaps.dwTextureBlendCaps = 0xCF; + halDesc1.dpcTriCaps.dwTextureAddressCaps = 0x3F; + halDesc1.dpcTriCaps.dwStippleWidth = 0; + halDesc1.dpcTriCaps.dwStippleHeight = 0; + halDesc1.dwDeviceRenderBitDepth = 0x500; + halDesc1.dwDeviceZBufferBitDepth = 0x400; + halDesc1.dwMaxBufferSize = 0; + halDesc1.dwMaxVertexCount = 0x400; + + + D3DDEVICEDESC1 halDEsc2; + halDEsc2.dwSize = sizeof(D3DDEVICEDESC1); + halDEsc2.dwFlags = 0x1F; + halDEsc2.dcmColorModel = 0; + halDEsc2.dwDevCaps = 1; + halDEsc2.dtcTransformCaps.dwSize = 8; + halDEsc2.dtcTransformCaps.dwCaps = 1; + halDEsc2.bClipping = 1; + halDEsc2.dlcLightingCaps.dwSize = 0x10; + halDEsc2.dlcLightingCaps.dwCaps = 0xF; + halDEsc2.dlcLightingCaps.dwLightingModel = 1; + halDEsc2.dlcLightingCaps.dwNumLights = 0; + halDEsc2.dpcLineCaps.dwSize = 0x38; + memset(&halDEsc2.dpcLineCaps.dwMiscCaps, 0, 0x34); + halDEsc2.dpcTriCaps.dwSize = 0x38; + memset(&halDEsc2.dpcTriCaps.dwMiscCaps, 0, 0x40); + halDEsc2.dwMaxVertexCount = 0x400; + + + D3DDEVICEDESC1 desc1; + memcpy(&desc1, &rampDesc1, sizeof(D3DDEVICEDESC1)); + D3DDEVICEDESC desc2; + memcpy(&desc2, &rampDesc2, sizeof(D3DDEVICEDESC1)); + GUID guid; + guid = IID_IDirect3DRampDevice; + if (cb( + &guid, + (LPSTR) "Microsoft Direct3D Mono(Ramp) Software Emulation", + (LPSTR) "Ramp Emulation", + (LPD3DDEVICEDESC) &desc1, &desc2, a3) != DD_FALSE) + return DD_OK; + memcpy(&desc1, &rgbemuDesc1, sizeof(D3DDEVICEDESC1)); + memcpy(&desc2, &rgbemuDesc2, sizeof(D3DDEVICEDESC1)); + guid = IID_IDirect3DRGBDevice; + if (cb( + &guid, + (LPSTR) "Microsoft Direct3D RGB Software Emulation", + (LPSTR) "RGB Emulation", + (LPD3DDEVICEDESC) &desc1, &desc2, a3) != DD_FALSE) + return DD_OK; + memcpy(&desc1, &halDesc1, sizeof(D3DDEVICEDESC1)); + memcpy(&desc2, &halDEsc2, sizeof(D3DDEVICEDESC1)); + guid = IID_IDirect3DHALDevice; + cb( + &guid, + (LPSTR) "Microsoft Direct3D Hardware acceleration through Direct3D HAL", + (LPSTR) "Direct3D HAL", + (LPD3DDEVICEDESC) &desc1, &desc2, a3); + return DD_OK; +} + +HRESULT FakeD3D::CreateLight(LPDIRECT3DLIGHT *, IUnknown *) { + gog_debug("Unused function called: FakeD3D::CreateLight"); + return DDERR_GENERIC; +} + +HRESULT FakeD3D::CreateMaterial(LPDIRECT3DMATERIAL *, IUnknown *) { + gog_debug("Unused function called: FakeD3D::CreateMaterial"); + return DDERR_GENERIC; +} + +HRESULT FakeD3D::CreateViewport(LPDIRECT3DVIEWPORT *, IUnknown *) { + gog_debug("Unused function called: FakeD3D::CreateViewport"); + return DDERR_GENERIC; +} + +HRESULT FakeD3D::FindDevice(LPD3DFINDDEVICESEARCH, LPD3DFINDDEVICERESULT) { + gog_debug("Unused function called: FakeD3D::FindDevice"); + return DDERR_GENERIC; +} diff --git a/src/patches/gog_patch_dll/fake/FakeD3D.h b/src/patches/gog_patch_dll/fake/FakeD3D.h new file mode 100644 index 0000000..7a7fc3c --- /dev/null +++ b/src/patches/gog_patch_dll/fake/FakeD3D.h @@ -0,0 +1,33 @@ +// +// Created by DiaLight on 20.01.2023. +// + +#ifndef EMBER_FAKED3D_H +#define EMBER_FAKED3D_H + +#include +#include + +namespace gog { + + class FakeD3D : public FakeUnknown { + + public: + /*** IUnknown methods ***/ + STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID *ppvObj) override; + + /*** IDirect3D methods ***/ + STDMETHOD(Initialize)(THIS_ REFCLSID) override; + STDMETHOD(EnumDevices)(THIS_ LPD3DENUMDEVICESCALLBACK, LPVOID) override; + STDMETHOD(CreateLight)(THIS_ LPDIRECT3DLIGHT *, IUnknown *) override; + STDMETHOD(CreateMaterial)(THIS_ LPDIRECT3DMATERIAL *, IUnknown *) override; + STDMETHOD(CreateViewport)(THIS_ LPDIRECT3DVIEWPORT *, IUnknown *) override; + STDMETHOD(FindDevice)(THIS_ LPD3DFINDDEVICESEARCH, LPD3DFINDDEVICERESULT) override; + + static FakeD3D *instance; + + }; + +} + +#endif //EMBER_FAKED3D_H diff --git a/src/patches/gog_patch_dll/fake/FakeD3D2.cpp b/src/patches/gog_patch_dll/fake/FakeD3D2.cpp new file mode 100644 index 0000000..4c0f262 --- /dev/null +++ b/src/patches/gog_patch_dll/fake/FakeD3D2.cpp @@ -0,0 +1,354 @@ +// +// Created by DiaLight on 20.01.2023. +// +#include +#include + +using namespace gog; + + +FakeD3D2 *FakeD3D2::instance = nullptr; + +HRESULT FakeD3D2::QueryInterface(const IID &riid, LPVOID *ppvObj) { + gog_debug("Unused function called: FakeD3D2::QueryInterface"); + return DDERR_GENERIC; +} + +typedef struct _D3DDeviceDesc2 { + DWORD dwSize; /* Size of D3DDEVICEDESC2 structure */ + DWORD dwFlags; /* Indicates which fields have valid data */ + D3DCOLORMODEL dcmColorModel; /* Color model of device */ + DWORD dwDevCaps; /* Capabilities of device */ + D3DTRANSFORMCAPS dtcTransformCaps; /* Capabilities of transform */ + BOOL bClipping; /* Device can do 3D clipping */ + D3DLIGHTINGCAPS dlcLightingCaps; /* Capabilities of lighting */ + D3DPRIMCAPS dpcLineCaps; + D3DPRIMCAPS dpcTriCaps; + DWORD dwDeviceRenderBitDepth; /* One of DDBB_8, 16, etc.. */ + DWORD dwDeviceZBufferBitDepth;/* One of DDBD_16, 32, etc.. */ + DWORD dwMaxBufferSize; /* Maximum execute buffer size */ + DWORD dwMaxVertexCount; /* Maximum vertex count */ +#if(DIRECT3D_VERSION >= 0x0500) + // *** New fields for DX5 *** // + + // Width and height caps are 0 for legacy HALs. + DWORD dwMinTextureWidth, dwMinTextureHeight; + DWORD dwMaxTextureWidth, dwMaxTextureHeight; + DWORD dwMinStippleWidth, dwMaxStippleWidth; + DWORD dwMinStippleHeight, dwMaxStippleHeight; +#endif /* DIRECT3D_VERSION >= 0x0500 */ +} D3DDEVICEDESC2, *LPD3DDEVICEDESC2; +static_assert(sizeof(D3DDEVICEDESC2) == 0xCC); +static_assert(sizeof(D3DDEVICEDESC) == 0xFC); + +HRESULT FakeD3D2::EnumDevices(LPD3DENUMDEVICESCALLBACK cb, LPVOID a3) { + D3DDEVICEDESC2 rampDesc2; + rampDesc2.dwSize = sizeof(D3DDEVICEDESC2); + rampDesc2.dwFlags = 0x7DF; + rampDesc2.dcmColorModel = 1; + rampDesc2.dwDevCaps = 1371; + rampDesc2.dtcTransformCaps.dwSize = 8; + rampDesc2.dtcTransformCaps.dwCaps = 1; + rampDesc2.bClipping = 1; + rampDesc2.dlcLightingCaps.dwSize = 0x10; + rampDesc2.dlcLightingCaps.dwCaps = 0xF; + rampDesc2.dlcLightingCaps.dwLightingModel = 2; + rampDesc2.dlcLightingCaps.dwNumLights = 0; + rampDesc2.dpcLineCaps.dwSize = 0x38; + rampDesc2.dpcLineCaps.dwMiscCaps = 0x70; + rampDesc2.dpcLineCaps.dwRasterCaps = 0x51; + rampDesc2.dpcLineCaps.dwZCmpCaps = 0xFF; + memset(&rampDesc2.dpcLineCaps.dwSrcBlendCaps, 0, 0xC); + rampDesc2.dpcLineCaps.dwShadeCaps = 0xA145; + rampDesc2.dpcLineCaps.dwTextureCaps = 0xB; + rampDesc2.dpcLineCaps.dwTextureFilterCaps = 5; + rampDesc2.dpcLineCaps.dwTextureBlendCaps = 0x42; + rampDesc2.dpcLineCaps.dwTextureAddressCaps = 1; + rampDesc2.dpcLineCaps.dwStippleWidth = 4; + rampDesc2.dpcLineCaps.dwStippleHeight = 4; + rampDesc2.dpcTriCaps.dwSize = 0x38; + rampDesc2.dpcTriCaps.dwMiscCaps = 0x70; + rampDesc2.dpcTriCaps.dwRasterCaps = 0x51; + rampDesc2.dpcTriCaps.dwZCmpCaps = 0xFF; + memset(&rampDesc2.dpcTriCaps.dwSrcBlendCaps, 0, 0xC); + rampDesc2.dpcTriCaps.dwShadeCaps = 0xA145; + rampDesc2.dpcTriCaps.dwTextureCaps = 0xB; + rampDesc2.dpcTriCaps.dwTextureFilterCaps = 5; + rampDesc2.dpcTriCaps.dwTextureBlendCaps = 0x42; + rampDesc2.dpcTriCaps.dwTextureAddressCaps = 1; + rampDesc2.dpcTriCaps.dwStippleWidth = 4; + rampDesc2.dpcTriCaps.dwStippleHeight = 4; + rampDesc2.dwDeviceRenderBitDepth = 0xF00; + rampDesc2.dwDeviceZBufferBitDepth = 0x400; + rampDesc2.dwMaxBufferSize = 0; + rampDesc2.dwMaxVertexCount = 2021; + memset(&rampDesc2.dwMinTextureWidth, 0, 0x20); + + + D3DDEVICEDESC2 rgbemuDesc1; + rgbemuDesc1.dwSize = sizeof(D3DDEVICEDESC2); + memset(&rgbemuDesc1.dwFlags, 0, 0xC); + rgbemuDesc1.dtcTransformCaps.dwSize = 8; + rgbemuDesc1.dtcTransformCaps.dwCaps = 0; + rgbemuDesc1.bClipping = 0; + rgbemuDesc1.dlcLightingCaps.dwSize = 0x10; + memset(&rgbemuDesc1.dlcLightingCaps.dwCaps, 0, 0xC); + rgbemuDesc1.dpcLineCaps.dwSize = 0x38; + memset(&rgbemuDesc1.dpcLineCaps.dwMiscCaps, 0, 0x34); + rgbemuDesc1.dpcTriCaps.dwSize = 0x38; + memset(&rgbemuDesc1.dpcTriCaps.dwMiscCaps, 0, 0x64); + + + D3DDEVICEDESC2 rgbemuDesc2; + rgbemuDesc2.dwSize = sizeof(D3DDEVICEDESC2); + rgbemuDesc2.dwFlags = 0x7DF; + rgbemuDesc2.dcmColorModel = 2; + rgbemuDesc2.dwDevCaps = 0x55B; + rgbemuDesc2.dtcTransformCaps.dwSize = 8; + rgbemuDesc2.dtcTransformCaps.dwCaps = 1; + rgbemuDesc2.bClipping = 1; + rgbemuDesc2.dlcLightingCaps.dwSize = 0x10; + rgbemuDesc2.dlcLightingCaps.dwCaps = 0xF; + rgbemuDesc2.dlcLightingCaps.dwLightingModel = 1; + rgbemuDesc2.dlcLightingCaps.dwNumLights = 0; + rgbemuDesc2.dpcLineCaps.dwSize = 0x38; + rgbemuDesc2.dpcLineCaps.dwMiscCaps = 0x70; + rgbemuDesc2.dpcLineCaps.dwRasterCaps = 0x1D1; + rgbemuDesc2.dpcLineCaps.dwZCmpCaps = 0xFF; + memset(&rgbemuDesc2.dpcLineCaps.dwSrcBlendCaps, 0, 0xC); + rgbemuDesc2.dpcLineCaps.dwShadeCaps = 0xCA28A; + rgbemuDesc2.dpcLineCaps.dwTextureCaps = 0xB; + rgbemuDesc2.dpcLineCaps.dwTextureFilterCaps = 0x1F; + rgbemuDesc2.dpcLineCaps.dwTextureBlendCaps = 0x42; + rgbemuDesc2.dpcLineCaps.dwTextureAddressCaps = 1; + rgbemuDesc2.dpcLineCaps.dwStippleWidth = 4; + rgbemuDesc2.dpcLineCaps.dwStippleHeight = 4; + rgbemuDesc2.dpcTriCaps.dwSize = 0x38; + rgbemuDesc2.dpcTriCaps.dwMiscCaps = 0x70; + rgbemuDesc2.dpcTriCaps.dwRasterCaps = 0x1D1; + rgbemuDesc2.dpcTriCaps.dwZCmpCaps = 0xFF; + memset(&rgbemuDesc2.dpcTriCaps.dwSrcBlendCaps, 0, 0xC); + rgbemuDesc2.dpcTriCaps.dwShadeCaps = 0xCA28A; + rgbemuDesc2.dpcTriCaps.dwTextureCaps = 0xB; + rgbemuDesc2.dpcTriCaps.dwTextureFilterCaps = 0x1F; + rgbemuDesc2.dpcTriCaps.dwTextureBlendCaps = 0x42; + rgbemuDesc2.dpcTriCaps.dwTextureAddressCaps = 1; + rgbemuDesc2.dpcTriCaps.dwStippleWidth = 4; + rgbemuDesc2.dpcTriCaps.dwStippleHeight = 4; + rgbemuDesc2.dwDeviceRenderBitDepth = 0xF00; + rgbemuDesc2.dwDeviceZBufferBitDepth = 0x400; + rgbemuDesc2.dwMaxBufferSize = 0; + rgbemuDesc2.dwMaxVertexCount = 2021; + memset(&rgbemuDesc2.dwMinTextureWidth, 0, 0x20); + + + D3DDEVICEDESC2 halDesc1; + halDesc1.dwSize = sizeof(D3DDEVICEDESC2); + halDesc1.dwFlags = 0x1FF; + halDesc1.dcmColorModel = 2; + halDesc1.dwDevCaps = 0x61BBEF1; + halDesc1.dtcTransformCaps.dwSize = 8; + halDesc1.dtcTransformCaps.dwCaps = 1; + halDesc1.bClipping = 1; + halDesc1.dlcLightingCaps.dwSize = 0x10; + halDesc1.dlcLightingCaps.dwCaps = 7; + halDesc1.dlcLightingCaps.dwLightingModel = 1; + halDesc1.dlcLightingCaps.dwNumLights = 0; + halDesc1.dpcLineCaps.dwSize = 0x38; + halDesc1.dpcLineCaps.dwMiscCaps = 0x3FAC83; + halDesc1.dpcLineCaps.dwRasterCaps = 0xC7361B3; + halDesc1.dpcLineCaps.dwZCmpCaps = 0xFF; + halDesc1.dpcLineCaps.dwSrcBlendCaps = 0x1FFF; + halDesc1.dpcLineCaps.dwDestBlendCaps = 0x1FFF; + halDesc1.dpcLineCaps.dwAlphaCmpCaps = 0xFF; + halDesc1.dpcLineCaps.dwShadeCaps = 0xC528A; + halDesc1.dpcLineCaps.dwTextureCaps = 0x1EC4D; + halDesc1.dpcLineCaps.dwTextureFilterCaps = 0x703073F; + halDesc1.dpcLineCaps.dwTextureBlendCaps = 0xCF; + halDesc1.dpcLineCaps.dwTextureAddressCaps = 0x3F; + halDesc1.dpcLineCaps.dwStippleWidth = 0; + halDesc1.dpcLineCaps.dwStippleHeight = 0; + halDesc1.dpcTriCaps.dwSize = 0x38; + halDesc1.dpcTriCaps.dwMiscCaps = 0x3FACF3; + halDesc1.dpcTriCaps.dwRasterCaps = 0xC7361B3; + halDesc1.dpcTriCaps.dwZCmpCaps = 0xFF; + halDesc1.dpcTriCaps.dwSrcBlendCaps = 0x1FFF; + halDesc1.dpcTriCaps.dwDestBlendCaps = 0x1FFF; + halDesc1.dpcTriCaps.dwAlphaCmpCaps = 0xFF; + halDesc1.dpcTriCaps.dwShadeCaps = 0xC528A; + halDesc1.dpcTriCaps.dwTextureCaps = 0x1EC4D; + halDesc1.dpcTriCaps.dwTextureFilterCaps = 0x703073F; + halDesc1.dpcTriCaps.dwTextureBlendCaps = 0xCF; + halDesc1.dpcTriCaps.dwTextureAddressCaps = 0x3F; + halDesc1.dpcTriCaps.dwStippleWidth = 0; + halDesc1.dpcTriCaps.dwStippleHeight = 0; + halDesc1.dwDeviceRenderBitDepth = 0x500; + halDesc1.dwDeviceZBufferBitDepth = 0x400; + halDesc1.dwMaxBufferSize = 0; + halDesc1.dwMaxVertexCount = 0x400; + halDesc1.dwMinTextureWidth = 1; + halDesc1.dwMinTextureHeight = 1; + halDesc1.dwMaxTextureWidth = 0x1000; + halDesc1.dwMaxTextureHeight = 0x1000; + memset(&halDesc1.dwMinStippleWidth, 0, 0x10); + + + D3DDEVICEDESC2 halDesc2; + halDesc2.dwSize = 204; + halDesc2.dwFlags = 31; + halDesc2.dcmColorModel = 0; + halDesc2.dwDevCaps = 1; + halDesc2.dtcTransformCaps.dwSize = 8; + halDesc2.dtcTransformCaps.dwCaps = 1; + halDesc2.bClipping = 1; + halDesc2.dlcLightingCaps.dwSize = 0x10; + halDesc2.dlcLightingCaps.dwCaps = 0xF; + halDesc2.dlcLightingCaps.dwLightingModel = 1; + halDesc2.dlcLightingCaps.dwNumLights = 0; + halDesc2.dpcLineCaps.dwSize = 0x38; + memset(&halDesc2.dpcLineCaps.dwMiscCaps, 0, 0x34); + halDesc2.dpcTriCaps.dwSize = 0x38; + memset(&halDesc2.dpcTriCaps.dwMiscCaps, 0, 0x40); + halDesc2.dwMaxVertexCount = 0x400; + memset(&halDesc2.dwMinTextureWidth, 0, 0x20); + + + D3DDEVICEDESC2 nnxDesc1; + nnxDesc1.dwSize = sizeof(D3DDEVICEDESC2); + memset(&nnxDesc1.dwFlags, 0, 0xC); + nnxDesc1.dtcTransformCaps.dwSize = 8; + nnxDesc1.dtcTransformCaps.dwCaps = 0; + nnxDesc1.bClipping = 0; + nnxDesc1.dlcLightingCaps.dwSize = 0x10; + memset(&nnxDesc1.dlcLightingCaps.dwCaps, 0, 0xC); + nnxDesc1.dpcLineCaps.dwSize = 0x38; + memset(&nnxDesc1.dpcLineCaps.dwMiscCaps, 0, 0x34); + nnxDesc1.dpcTriCaps.dwSize = 0x38; + memset(&nnxDesc1.dpcTriCaps.dwMiscCaps, 0, 0x64); + + + D3DDEVICEDESC2 mmxDesc2; + mmxDesc2.dwSize = sizeof(D3DDEVICEDESC2); + mmxDesc2.dwFlags = 0x7DF; + mmxDesc2.dcmColorModel = 2; + mmxDesc2.dwDevCaps = 0x55B; + mmxDesc2.dtcTransformCaps.dwSize = 8; + mmxDesc2.dtcTransformCaps.dwCaps = 1; + mmxDesc2.bClipping = 1; + mmxDesc2.dlcLightingCaps.dwSize = 0x10; + mmxDesc2.dlcLightingCaps.dwCaps = 0xF; + mmxDesc2.dlcLightingCaps.dwLightingModel = 1; + mmxDesc2.dlcLightingCaps.dwNumLights = 0; + mmxDesc2.dpcLineCaps.dwSize = 0x38; + mmxDesc2.dpcLineCaps.dwMiscCaps = 0x70; + mmxDesc2.dpcLineCaps.dwRasterCaps = 0x1D1; + mmxDesc2.dpcLineCaps.dwZCmpCaps = 0xFF; + memset(&mmxDesc2.dpcLineCaps.dwSrcBlendCaps, 0, 0xC); + mmxDesc2.dpcLineCaps.dwShadeCaps = 0xCA28A; + mmxDesc2.dpcLineCaps.dwTextureCaps = 0xB; + mmxDesc2.dpcLineCaps.dwTextureFilterCaps = 0x1F; + mmxDesc2.dpcLineCaps.dwTextureBlendCaps = 0x42; + mmxDesc2.dpcLineCaps.dwTextureAddressCaps = 1; + mmxDesc2.dpcLineCaps.dwStippleWidth = 4; + mmxDesc2.dpcLineCaps.dwStippleHeight = 4; + mmxDesc2.dpcTriCaps.dwSize = 0x38; + mmxDesc2.dpcTriCaps.dwMiscCaps = 0x70; + mmxDesc2.dpcTriCaps.dwRasterCaps = 0x1D1; + mmxDesc2.dpcTriCaps.dwZCmpCaps = 0xFF; + memset(&mmxDesc2.dpcTriCaps.dwSrcBlendCaps, 0, 0xC); + mmxDesc2.dpcTriCaps.dwShadeCaps = 0xCA28A; + mmxDesc2.dpcTriCaps.dwTextureCaps = 0xB; + mmxDesc2.dpcTriCaps.dwTextureFilterCaps = 0x1F; + mmxDesc2.dpcTriCaps.dwTextureBlendCaps = 0x42; + mmxDesc2.dpcTriCaps.dwTextureAddressCaps = 1; + mmxDesc2.dpcTriCaps.dwStippleWidth = 4; + mmxDesc2.dpcTriCaps.dwStippleHeight = 4; + mmxDesc2.dwDeviceRenderBitDepth = 0xF00; + mmxDesc2.dwDeviceZBufferBitDepth = 0x400; + mmxDesc2.dwMaxBufferSize = 0; + mmxDesc2.dwMaxVertexCount = 2021; + memset(&mmxDesc2.dwMinTextureWidth, 0, 0x20); + + + D3DDEVICEDESC2 rampDesc1; + rampDesc1.dwSize = sizeof(D3DDEVICEDESC2); + memset(&rampDesc1.dwFlags, 0, 0xC); + rampDesc1.dtcTransformCaps.dwSize = 8; + rampDesc1.dtcTransformCaps.dwCaps = 0; + rampDesc1.bClipping = 0; + rampDesc1.dlcLightingCaps.dwSize = 0x10; + memset(&rampDesc1.dlcLightingCaps.dwCaps, 0, 0xC); + rampDesc1.dpcLineCaps.dwSize = 0x38; + memset(&rampDesc1.dpcLineCaps.dwMiscCaps, 0, 0x34); + rampDesc1.dpcTriCaps.dwSize = 0x38; + memset(&rampDesc1.dpcTriCaps.dwMiscCaps, 0, 0x64); + + + D3DDEVICEDESC2 desc1; + memcpy(&desc1, &rampDesc1, sizeof(D3DDEVICEDESC2)); + D3DDEVICEDESC desc2; + memcpy(&desc2, &rampDesc2, sizeof(D3DDEVICEDESC2)); + GUID guid; + guid = IID_IDirect3DRampDevice; + if (cb( + &guid, + (LPSTR) "Microsoft Direct3D Mono(Ramp) Software Emulation", + (LPSTR) "Ramp Emulation", + (LPD3DDEVICEDESC) &desc1, &desc2, a3) != DD_FALSE) + return DD_OK; + + memcpy(&desc1, &rgbemuDesc1, sizeof(D3DDEVICEDESC2)); + memcpy(&desc2, &rgbemuDesc2, sizeof(D3DDEVICEDESC2)); + guid = IID_IDirect3DRGBDevice; + if (cb( + &guid, + (LPSTR) "Microsoft Direct3D RGB Software Emulation", + (LPSTR) "RGB Emulation", + (LPD3DDEVICEDESC) &desc1, &desc2, a3) != DD_FALSE) + return DD_OK; + + memcpy(&desc1, &halDesc1, sizeof(D3DDEVICEDESC2)); + memcpy(&desc2, &halDesc2, sizeof(D3DDEVICEDESC2)); + guid = IID_IDirect3DHALDevice; + if (cb( + &guid, + (LPSTR) "Microsoft Direct3D Hardware acceleration through Direct3D HAL", + (LPSTR) "Direct3D HAL", + (LPD3DDEVICEDESC) &desc1, &desc2, a3) != DD_FALSE) + return DD_OK; + + memcpy(&desc1, &nnxDesc1, sizeof(D3DDEVICEDESC2)); + memcpy(&desc2, &mmxDesc2, sizeof(D3DDEVICEDESC2)); + guid = IID_IDirect3DMMXDevice; + cb( + &guid, + (LPSTR) "Microsoft Direct3D MMX Software Emulation", + (LPSTR) "MMX Emulation", + (LPD3DDEVICEDESC) &desc1, &desc2, a3); + return DD_OK; +} + +HRESULT FakeD3D2::CreateLight(LPDIRECT3DLIGHT *, IUnknown *) { + gog_debug("Unused function called: FakeD3D2::CreateLight"); + return DDERR_GENERIC; +} + +HRESULT FakeD3D2::CreateMaterial(LPDIRECT3DMATERIAL2 *, IUnknown *) { + gog_debug("Unused function called: FakeD3D2::CreateMaterial"); + return DDERR_GENERIC; +} + +HRESULT FakeD3D2::CreateViewport(LPDIRECT3DVIEWPORT2 *, IUnknown *) { + gog_debug("Unused function called: FakeD3D2::CreateViewport"); + return DDERR_GENERIC; +} + +HRESULT FakeD3D2::FindDevice(LPD3DFINDDEVICESEARCH, LPD3DFINDDEVICERESULT) { + gog_debug("Unused function called: FakeD3D2::FindDevice"); + return DDERR_GENERIC; +} + +HRESULT FakeD3D2::CreateDevice(REFCLSID, LPDIRECTDRAWSURFACE, LPDIRECT3DDEVICE2 *) { + gog_debug("Unused function called: FakeD3D2::CreateDevice"); + return DDERR_GENERIC; +} diff --git a/src/patches/gog_patch_dll/fake/FakeD3D2.h b/src/patches/gog_patch_dll/fake/FakeD3D2.h new file mode 100644 index 0000000..e696456 --- /dev/null +++ b/src/patches/gog_patch_dll/fake/FakeD3D2.h @@ -0,0 +1,33 @@ +// +// Created by DiaLight on 20.01.2023. +// + +#ifndef EMBER_FAKED3D2_H +#define EMBER_FAKED3D2_H + +#include +#include + +namespace gog { + + class FakeD3D2 : public FakeUnknown { + + public: + /*** IUnknown methods ***/ + STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) override; + + /*** IDirect3D2 methods ***/ + STDMETHOD(EnumDevices)(THIS_ LPD3DENUMDEVICESCALLBACK,LPVOID) override; + STDMETHOD(CreateLight)(THIS_ LPDIRECT3DLIGHT*,IUnknown*) override; + STDMETHOD(CreateMaterial)(THIS_ LPDIRECT3DMATERIAL2*,IUnknown*) override; + STDMETHOD(CreateViewport)(THIS_ LPDIRECT3DVIEWPORT2*,IUnknown*) override; + STDMETHOD(FindDevice)(THIS_ LPD3DFINDDEVICESEARCH,LPD3DFINDDEVICERESULT) override; + STDMETHOD(CreateDevice)(THIS_ REFCLSID,LPDIRECTDRAWSURFACE,LPDIRECT3DDEVICE2*) override; + + static FakeD3D2 *instance; + + }; + +} + +#endif //EMBER_FAKED3D2_H diff --git a/src/patches/gog_patch_dll/fake/FakeD3D3.cpp b/src/patches/gog_patch_dll/fake/FakeD3D3.cpp new file mode 100644 index 0000000..43055ac --- /dev/null +++ b/src/patches/gog_patch_dll/fake/FakeD3D3.cpp @@ -0,0 +1,83 @@ +// +// Created by DiaLight on 20.01.2023. +// +#include +#include +#include +#include +#include +#include +#include + +using namespace gog; + +FakeD3D3 *FakeD3D3::instance = nullptr; + +HRESULT FakeD3D3::QueryInterface(REFIID riid, LPVOID *ppvObj) { + gog_debug("Unused function called: FakeD3D3::QueryInterface"); + return DDERR_GENERIC; +} + +HRESULT FakeD3D3::EnumDevices(LPD3DENUMDEVICESCALLBACK, LPVOID) { + gog_debug("Unused function called: FakeD3D3::EnumDevices"); + return DDERR_GENERIC; +} + +HRESULT FakeD3D3::CreateLight(LPDIRECT3DLIGHT *, LPUNKNOWN) { + gog_debug("Unused function called: FakeD3D3::CreateLight"); + return DDERR_GENERIC; +} + +HRESULT FakeD3D3::CreateMaterial(LPDIRECT3DMATERIAL3 *, LPUNKNOWN) { + gog_debug("Unused function called: FakeD3D3::CreateMaterial"); + return DDERR_GENERIC; +} + +HRESULT FakeD3D3::CreateViewport(LPDIRECT3DVIEWPORT3 *a2, LPUNKNOWN a3) { + if (a3 != nullptr) { + gog_debug("Assertion failed: FakeD3D3::CreateViewport:1005"); + } + *a2 = FakeViewport3::instance; + return 0; +} + +HRESULT FakeD3D3::FindDevice(LPD3DFINDDEVICESEARCH, LPD3DFINDDEVICERESULT) { + gog_debug("Unused function called: FakeD3D3::FindDevice"); + return DDERR_GENERIC; +} + +HRESULT FakeD3D3::CreateDevice(REFCLSID riid, LPDIRECTDRAWSURFACE4 surf_, LPDIRECT3DDEVICE3 *a4, LPUNKNOWN a5) { + FakeSurface4 *surf = (FakeSurface4 *) surf_; + if (!IsEqualGUID(IID_IDirect3DHALDevice, riid)) gog_debug("Assertion failed: FakeD3D3::CreateDevice:1011"); + if (!surf) gog_debug("Assertion failed: FakeD3D3::CreateDevice:1012"); + if (!a4) gog_debug("Assertion failed: FakeD3D3::CreateDevice:1013"); + if (a5) gog_debug("Assertion failed: FakeD3D3::CreateDevice:1014"); + if (surf->orig() != FakeSurface::instance_cpy->orig()) gog_debug("Assertion failed: FakeD3D3::CreateDevice:1015"); + if (orig::pIDirect3DDevice3) { + gog_debug("Assertion failed: FakeD3D3::CreateDevice:1017"); + } else { + LPDIRECTDRAWSURFACE4 orig_surf = orig::pIDirectDrawSurface4_zbuf; + if (orig::pIDirectDrawSurface4_zbuf == nullptr) orig_surf = surf->orig(); + HRESULT hr = orig::pIDirect3D3->CreateDevice(riid, orig_surf, &orig::pIDirect3DDevice3, NULL); + if (FAILED(hr)) { + gog_debugf("Assertion failed: FakeD3D3::CreateDevice:1021 with HRESULT 0x%x", hr); + } + } + *a4 = new FakeDevice3(); + return DD_OK; +} + +HRESULT FakeD3D3::CreateVertexBuffer(LPD3DVERTEXBUFFERDESC, LPDIRECT3DVERTEXBUFFER *, DWORD, LPUNKNOWN) { + gog_debug("Unused function called: FakeD3D3::CreateVertexBuffer"); + return DDERR_GENERIC; +} + +HRESULT FakeD3D3::EnumZBufferFormats(REFCLSID, LPD3DENUMPIXELFORMATSCALLBACK, LPVOID) { + gog_debug("Unused function called: FakeD3D3::EnumZBufferFormats"); + return DDERR_GENERIC; +} + +HRESULT FakeD3D3::EvictManagedTextures(void) { + gog_debug("Unused function called: FakeD3D3::EvictManagedTextures"); + return DDERR_GENERIC; +} diff --git a/src/patches/gog_patch_dll/fake/FakeD3D3.h b/src/patches/gog_patch_dll/fake/FakeD3D3.h new file mode 100644 index 0000000..d435102 --- /dev/null +++ b/src/patches/gog_patch_dll/fake/FakeD3D3.h @@ -0,0 +1,37 @@ +// +// Created by DiaLight on 20.01.2023. +// + +#ifndef EMBER_FAKED3D3_H +#define EMBER_FAKED3D3_H + +#include +#include + +namespace gog { + + class FakeD3D3 : public FakeUnknown { + + public: + + static FakeD3D3 *instance; + + /*** IUnknown methods ***/ + STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) override; + + /*** IDirect3D3 methods ***/ + STDMETHOD(EnumDevices)(THIS_ LPD3DENUMDEVICESCALLBACK,LPVOID) override; + STDMETHOD(CreateLight)(THIS_ LPDIRECT3DLIGHT*,LPUNKNOWN) override; + STDMETHOD(CreateMaterial)(THIS_ LPDIRECT3DMATERIAL3*,LPUNKNOWN) override; + STDMETHOD(CreateViewport)(THIS_ LPDIRECT3DVIEWPORT3*,LPUNKNOWN) override; + STDMETHOD(FindDevice)(THIS_ LPD3DFINDDEVICESEARCH,LPD3DFINDDEVICERESULT) override; + STDMETHOD(CreateDevice)(THIS_ REFCLSID,LPDIRECTDRAWSURFACE4,LPDIRECT3DDEVICE3*,LPUNKNOWN) override; + STDMETHOD(CreateVertexBuffer)(THIS_ LPD3DVERTEXBUFFERDESC,LPDIRECT3DVERTEXBUFFER*,DWORD,LPUNKNOWN) override; + STDMETHOD(EnumZBufferFormats)(THIS_ REFCLSID,LPD3DENUMPIXELFORMATSCALLBACK,LPVOID) override; + STDMETHOD(EvictManagedTextures)(THIS) override; + + }; + +} + +#endif //EMBER_FAKED3D3_H diff --git a/src/patches/gog_patch_dll/fake/FakeDevice3.cpp b/src/patches/gog_patch_dll/fake/FakeDevice3.cpp new file mode 100644 index 0000000..5dd7523 --- /dev/null +++ b/src/patches/gog_patch_dll/fake/FakeDevice3.cpp @@ -0,0 +1,578 @@ +// +// Created by DiaLight on 20.01.2023. +// +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace gog; + +FakeDevice3::FakeDevice3() { + orig::pIDirect3D3->CreateViewport(&orig::pIDirect3DViewport3, NULL); + DWORD height = g_dwHeight; + DWORD width = g_dwWidth; + D3DVIEWPORT2 viewport; + viewport.dwSize = sizeof(D3DVIEWPORT2); + static_assert(sizeof(D3DVIEWPORT2) == 44); + viewport.dwX = 0; + viewport.dwY = 0; + viewport.dwWidth = g_dwWidth; + viewport.dwHeight = g_dwHeight; + if (cfg::iAntialias && orig::pIDirectDrawSurface4_zbuf) { + width = g_dwWidth * cfg::iAntialias; + height = g_dwHeight * cfg::iAntialias; + viewport.dwWidth = g_dwWidth * cfg::iAntialias; + viewport.dwHeight = g_dwHeight * cfg::iAntialias; + } + viewport.dvClipX = -1.0; + viewport.dvClipY = -((double) (unsigned int) height / (double) (unsigned int) width); + viewport.dvClipWidth = 2.0; + viewport.dvClipHeight = -viewport.dvClipY - viewport.dvClipY; + viewport.dvMinZ = 0.0; + viewport.dvMaxZ = 1.0; + HRESULT hr = orig::pIDirect3DDevice3->AddViewport(orig::pIDirect3DViewport3); + if (FAILED(hr)) { + gog_debugf("Assertion failed: FakeDevice3::FakeDevice3:742 with HRESULT 0x%x", hr); + } + hr = orig::pIDirect3DViewport3->SetViewport2(&viewport); + if (FAILED(hr)) { + gog_debugf("Assertion failed: FakeDevice3::FakeDevice3:744 with HRESULT 0x%x", hr); + } + hr = orig::pIDirect3DDevice3->SetCurrentViewport(orig::pIDirect3DViewport3); + if (FAILED(hr)) { + gog_debugf("Assertion failed: FakeDevice3::FakeDevice3:746 with HRESULT 0x%x", hr); + } + if (cfg::iExtraAntialias) { + hr = orig::pIDirect3DDevice3->SetRenderState((D3DRENDERSTATETYPE) 2, 2); + if (FAILED(hr)) { + gog_debugf("Assertion failed: FakeDevice3::FakeDevice3:750 with HRESULT 0x%x", hr); + } + } + if (!cfg::iAnisotropy) { + hr = orig::pIDirect3DDevice3->SetTextureStageState(0, D3DTSS_MAXANISOTROPY, 16); + if (FAILED(hr)) { + gog_debugf("Assertion failed: FakeDevice3::FakeDevice3:755 with HRESULT 0x%x", hr); + } + } +} + +HRESULT FakeDevice3::QueryInterface(REFIID riid, LPVOID *ppvObj) { + gog_debug("Unused function called: FakeDevice3::QueryInterface"); + return DDERR_GENERIC; +} + +ULONG FakeDevice3::Release(void) { + if (--refs != 0) return refs; + if (orig::pIDirect3DViewport3) { + orig::pIDirect3DViewport3->Release(); + orig::pIDirect3DViewport3 = nullptr; + } + if (orig::pIDirect3DDevice3) { + orig::pIDirect3DDevice3->Release(); + orig::pIDirect3DDevice3 = nullptr; + } + operator delete(this); + return 0; +} + +HRESULT FakeDevice3::GetCaps(LPD3DDEVICEDESC hwDesc, LPD3DDEVICEDESC halDesc) { + D3DDEVICEDESC hwDesc_; + hwDesc_.dwSize = sizeof(D3DDEVICEDESC); + static_assert(sizeof(D3DDEVICEDESC) == 252); + hwDesc_.dwFlags = 0x1FF; + hwDesc_.dcmColorModel = 2; + hwDesc_.dwDevCaps = 0x61BBEF1; + hwDesc_.dtcTransformCaps.dwSize = 8; + hwDesc_.dtcTransformCaps.dwCaps = 1; + hwDesc_.bClipping = 1; + hwDesc_.dlcLightingCaps.dwSize = 16; + hwDesc_.dlcLightingCaps.dwCaps = 7; + hwDesc_.dlcLightingCaps.dwLightingModel = 1; + hwDesc_.dlcLightingCaps.dwNumLights = 0; + hwDesc_.dpcLineCaps.dwSize = 56; + hwDesc_.dpcLineCaps.dwMiscCaps = 0x3FAC83; + hwDesc_.dpcLineCaps.dwRasterCaps = 0xC7361B3; + hwDesc_.dpcLineCaps.dwZCmpCaps = 0xFF; + hwDesc_.dpcLineCaps.dwSrcBlendCaps = 0x1FFF; + hwDesc_.dpcLineCaps.dwDestBlendCaps = 0x1FFF; + hwDesc_.dpcLineCaps.dwAlphaCmpCaps = 0xFF; + hwDesc_.dpcLineCaps.dwShadeCaps = 0xC528A; + hwDesc_.dpcLineCaps.dwTextureCaps = 0x1EC4D; + hwDesc_.dpcLineCaps.dwTextureFilterCaps = 0x703073F; + hwDesc_.dpcLineCaps.dwTextureBlendCaps = 0xCF; + hwDesc_.dpcLineCaps.dwTextureAddressCaps = 0x3F; + hwDesc_.dpcLineCaps.dwStippleWidth = 0; + hwDesc_.dpcLineCaps.dwStippleHeight = 0; + hwDesc_.dpcTriCaps.dwSize = 56; + hwDesc_.dpcTriCaps.dwMiscCaps = 0x3FACF3; + hwDesc_.dpcTriCaps.dwRasterCaps = 0xC7361B3; + hwDesc_.dpcTriCaps.dwZCmpCaps = 0xFF; + hwDesc_.dpcTriCaps.dwSrcBlendCaps = 0x1FFF; + hwDesc_.dpcTriCaps.dwDestBlendCaps = 0x1FFF; + hwDesc_.dpcTriCaps.dwAlphaCmpCaps = 0xFF; + hwDesc_.dpcTriCaps.dwShadeCaps = 0xC528A; + hwDesc_.dpcTriCaps.dwTextureCaps = 0x1EC4D; + hwDesc_.dpcTriCaps.dwTextureFilterCaps = 0x703073F; + hwDesc_.dpcTriCaps.dwTextureBlendCaps = 0xCF; + hwDesc_.dpcTriCaps.dwTextureAddressCaps = 0x3F; + hwDesc_.dpcTriCaps.dwStippleWidth = 0; + hwDesc_.dpcTriCaps.dwStippleHeight = 0; + hwDesc_.dwDeviceRenderBitDepth = 1280; + hwDesc_.dwDeviceZBufferBitDepth = 1024; + hwDesc_.dwMaxBufferSize = 0; + hwDesc_.dwMaxVertexCount = 1024; + hwDesc_.dwMinTextureWidth = 1; + hwDesc_.dwMinTextureHeight = 1; + hwDesc_.dwMaxTextureWidth = 4096; + hwDesc_.dwMaxTextureHeight = 4096; + memset(&hwDesc_.dwMinStippleWidth, 0, 16); + hwDesc_.dwMaxTextureRepeat = 0x2000; + hwDesc_.dwMaxTextureAspectRatio = 0x2000; + hwDesc_.dwMaxAnisotropy = 16; + hwDesc_.dvGuardBandLeft = -32768.0; + hwDesc_.dvGuardBandTop = -32768.0; + hwDesc_.dvGuardBandRight = 32768.0; + hwDesc_.dvGuardBandBottom = 32768.0; + hwDesc_.dvExtentsAdjust = 0.0; + hwDesc_.dwStencilCaps = 0xFF; + hwDesc_.dwFVFCaps = 0x100008; + hwDesc_.dwTextureOpCaps = 0x3FFFFFF; + hwDesc_.wMaxTextureBlendStages = 8; + hwDesc_.wMaxSimultaneousTextures = 8; + if (hwDesc) + memcpy(hwDesc, &hwDesc_, hwDesc->dwSize); + + D3DDEVICEDESC halDesc_; + halDesc_.dwSize = sizeof(D3DDEVICEDESC); + static_assert(sizeof(D3DDEVICEDESC) == 252); + halDesc_.dwFlags = 31; + halDesc_.dcmColorModel = 0; + halDesc_.dwDevCaps = 1; + halDesc_.dtcTransformCaps.dwSize = 8; + halDesc_.dtcTransformCaps.dwCaps = 1; + halDesc_.bClipping = 1; + halDesc_.dlcLightingCaps.dwSize = 16; + halDesc_.dlcLightingCaps.dwCaps = 15; + halDesc_.dlcLightingCaps.dwLightingModel = 1; + halDesc_.dlcLightingCaps.dwNumLights = 0; + halDesc_.dpcLineCaps.dwSize = 56; + memset(&halDesc_.dpcLineCaps.dwMiscCaps, 0, 52); + halDesc_.dpcTriCaps.dwSize = 56; + memset(&halDesc_.dpcTriCaps.dwMiscCaps, 0, 64); + halDesc_.dwMaxVertexCount = 1024; + memset(&halDesc_.dwMinTextureWidth, 0, 80); + if (halDesc) + memcpy(halDesc, &halDesc_, halDesc->dwSize); + return 0; +} + +HRESULT FakeDevice3::GetStats(LPD3DSTATS) { + gog_debug("Unused function called: FakeDevice3::GetStats"); + return DDERR_GENERIC; +} + +HRESULT FakeDevice3::AddViewport(LPDIRECT3DVIEWPORT3) { + return DD_OK; +} + +HRESULT FakeDevice3::DeleteViewport(LPDIRECT3DVIEWPORT3) { + gog_debug("Unused function called: FakeDevice3::DeleteViewport"); + return DDERR_GENERIC; +} + +HRESULT FakeDevice3::NextViewport(LPDIRECT3DVIEWPORT3, LPDIRECT3DVIEWPORT3 *, DWORD) { + gog_debug("Unused function called: FakeDevice3::NextViewport"); + return DDERR_GENERIC; +} + +HRESULT FakeDevice3::EnumTextureFormats(LPD3DENUMPIXELFORMATSCALLBACK cb, LPVOID a3) { + DDPIXELFORMAT pixFormat; + pixFormat.dwFourCC = 0; + pixFormat.dwRGBAlphaBitMask = 0; + pixFormat.dwSize = sizeof(DDPIXELFORMAT); + static_assert(sizeof(DDPIXELFORMAT) == 32); + pixFormat.dwFlags = 0x40; + pixFormat.dwRGBBitCount = 32; + pixFormat.dwBBitMask = 0xFF; + pixFormat.dwGBitMask = 0xFF00; + pixFormat.dwRBitMask = 0xFF0000; + if (cb(&pixFormat, a3) != 1) + return 0; + pixFormat.dwSize = sizeof(DDPIXELFORMAT); + pixFormat.dwFlags = 0x41; + pixFormat.dwRGBBitCount = 32; + pixFormat.dwBBitMask = 0xFF; + pixFormat.dwGBitMask = 0xFF00; + pixFormat.dwRBitMask = 0xFF0000; + pixFormat.dwRGBAlphaBitMask = 0xFF000000; + cb(&pixFormat, a3); + return 0; +} + +HRESULT FakeDevice3::BeginScene(void) { + HRESULT hr; + if (gog::g_isFlip) { + D3DRECT rect; + rect.x1 = 0; + rect.y1 = 0; + rect.x2 = gog::g_dwWidth; + rect.y2 = gog::g_dwHeight; + if (cfg::iAntialias && orig::pIDirectDrawSurface4_zbuf) { + rect.x2 = gog::g_dwWidth * cfg::iAntialias; + rect.y2 = gog::g_dwHeight * cfg::iAntialias; + } + hr = orig::pIDirect3DViewport3->Clear2(1, &rect, 2, 0xFF00FF00, 1.0, 0); + if (FAILED(hr)) gog_debug("Assertion failed: FakeDevice3::BeginScene:837"); + g_isFlip = false; + } + if (orig::pIDirectDrawSurface4_zbuf) { + IDirectDrawSurface4 *f88_orig_surf; + if (g_isAntialiasGt10 && g_dwWidth == 640 && cfg::iAntialias > 1) { + orig::pIDirectDrawSurface4_640x480->Blt(NULL, FakeSurface::instance_cpy->orig(), NULL, 0x1000000, NULL); + f88_orig_surf = orig::pIDirectDrawSurface4_640x480; + } else { + f88_orig_surf = FakeSurface::instance_cpy->orig(); + } + orig::pIDirectDrawSurface4_zbuf->Blt(NULL, f88_orig_surf, NULL, 0x1000000, NULL); + } + g_isSceneDrawing = true; + hr = orig::pIDirect3DDevice3->BeginScene(); + if (FAILED(hr)) { + gog_debugf("Assertion failed: FakeDevice3::BeginScene:849 with HRESULT 0x%x", hr); + return hr; + } + return hr; +} + +HRESULT FakeDevice3::EndScene(void) { + HRESULT hr; + g_isSceneDrawing = false; + hr = orig::pIDirect3DDevice3->EndScene(); + if (FAILED(hr)) { + gog_debugf("Assertion failed: FakeDevice3::EndScene:855 with HRESULT 0x%x", hr); + } + if (!orig::pIDirectDrawSurface4_zbuf) + return hr; + if (g_isAntialiasGt10 && g_dwWidth == 640 && cfg::iAntialias > 1) { + orig::pIDirectDrawSurface4_640x480->Blt(NULL, orig::pIDirectDrawSurface4_zbuf, NULL, 0x1000000, NULL); + FakeSurface::instance_cpy->orig()->Blt(NULL, orig::pIDirectDrawSurface4_640x480, NULL, 0x1000000, NULL); + return hr; + } + FakeSurface::instance_cpy->orig()->Blt(NULL, orig::pIDirectDrawSurface4_zbuf, NULL, 0x1000000, NULL); + return hr; +} + +HRESULT FakeDevice3::GetDirect3D(LPDIRECT3D3 *) { + gog_debug("Unused function called: FakeDevice3::GetDirect3D"); + return DDERR_GENERIC; +} + +HRESULT FakeDevice3::SetCurrentViewport(LPDIRECT3DVIEWPORT3) { + return DD_OK; +} + +HRESULT FakeDevice3::GetCurrentViewport(LPDIRECT3DVIEWPORT3 *) { + gog_debug("Unused function called: FakeDevice3::GetCurrentViewport"); + return DDERR_GENERIC; +} + +HRESULT FakeDevice3::SetRenderTarget(LPDIRECTDRAWSURFACE4, DWORD) { + gog_debug("Unused function called: FakeDevice3::SetRenderTarget"); + return DDERR_GENERIC; +} + +HRESULT FakeDevice3::GetRenderTarget(LPDIRECTDRAWSURFACE4 *) { + gog_debug("Unused function called: FakeDevice3::GetRenderTarget"); + return DDERR_GENERIC; +} + +HRESULT FakeDevice3::Begin(D3DPRIMITIVETYPE, DWORD, DWORD) { + gog_debug("Unused function called: FakeDevice3::Begin"); + return DDERR_GENERIC; +} + +HRESULT FakeDevice3::BeginIndexed(D3DPRIMITIVETYPE, DWORD, LPVOID, DWORD, DWORD) { + gog_debug("Unused function called: FakeDevice3::BeginIndexed"); + return DDERR_GENERIC; +} + +HRESULT FakeDevice3::Vertex(LPVOID) { + gog_debug("Unused function called: FakeDevice3::Vertex"); + return DDERR_GENERIC; +} + +HRESULT FakeDevice3::Index(WORD) { + gog_debug("Unused function called: FakeDevice3::Index"); + return DDERR_GENERIC; +} + +HRESULT FakeDevice3::End(DWORD) { + gog_debug("Unused function called: FakeDevice3::End"); + return DDERR_GENERIC; +} + +HRESULT FakeDevice3::GetRenderState(D3DRENDERSTATETYPE, LPDWORD) { + gog_debug("Unused function called: FakeDevice3::GetRenderState"); + return DDERR_GENERIC; +} + +HRESULT FakeDevice3::SetRenderState(D3DRENDERSTATETYPE stateType, DWORD a3) { + if ( + stateType == D3DRENDERSTATE_DITHERENABLE || + stateType == D3DRENDERSTATE_SUBPIXEL || + stateType == D3DRENDERSTATE_FOGENABLE + ) + return 0; + if (stateType == D3DRENDERSTATE_ANTIALIAS) gog_debug("Assertion failed: FakeDevice3::SetRenderState:879"); + HRESULT hr = orig::pIDirect3DDevice3->SetRenderState(stateType, a3); + if (FAILED(hr)) { + gog_debugf("Assertion failed: FakeDevice3::SetRenderState:887 with HRESULT 0x%x", hr); + } + return hr; +} + +HRESULT FakeDevice3::GetLightState(D3DLIGHTSTATETYPE, LPDWORD) { + gog_debug("Unused function called: FakeDevice3::GetLightState"); + return DDERR_GENERIC; +} + +HRESULT FakeDevice3::SetLightState(D3DLIGHTSTATETYPE, DWORD) { + gog_debug("Unused function called: FakeDevice3::SetLightState"); + return DDERR_GENERIC; +} + +HRESULT FakeDevice3::SetTransform(D3DTRANSFORMSTATETYPE, LPD3DMATRIX) { + gog_debug("Unused function called: FakeDevice3::SetTransform"); + return DDERR_GENERIC; +} + +HRESULT FakeDevice3::GetTransform(D3DTRANSFORMSTATETYPE, LPD3DMATRIX) { + gog_debug("Unused function called: FakeDevice3::GetTransform"); + return DDERR_GENERIC; +} + +HRESULT FakeDevice3::MultiplyTransform(D3DTRANSFORMSTATETYPE, LPD3DMATRIX) { + gog_debug("Unused function called: FakeDevice3::MultiplyTransform"); + return DDERR_GENERIC; +} + +HRESULT FakeDevice3::DrawPrimitive(D3DPRIMITIVETYPE, DWORD, LPVOID, DWORD, DWORD) { + gog_debug("Unused function called: FakeDevice3::DrawPrimitive"); + return DDERR_GENERIC; +} + +namespace dk2 { + + struct Vertex2C { + + /* 0*/ float f0_x; + /* 4*/ float f4_y; + /* 8*/ float f8_z; + /* C*/ float fC_rhv__colorWeight; + /* 10*/ int f10_diffuse; + dk2::TexCoord f14_tex[3]; + }; + static_assert(sizeof(Vertex2C) == 0x2C); + +} +#define Vertex1C_TypeDesc 0x144 +#define Vertex2C_TypeDesc 0x344 + +HRESULT +FakeDevice3::DrawIndexedPrimitive(D3DPRIMITIVETYPE primitive_type, DWORD fvf, LPVOID vertices, DWORD vertex_count, + LPWORD indices, DWORD index_count, DWORD flags) { + if (!g_isSceneDrawing) gog_debug("Assertion failed: FakeDevice3::DrawIndexedPrimitive:914"); + if (primitive_type != D3DPT_TRIANGLELIST) gog_debug("Assertion failed: FakeDevice3::DrawIndexedPrimitive:915"); + if (cfg::iBumpmap) { + if (fvf != Vertex1C_TypeDesc && fvf != Vertex2C_TypeDesc) gog_debug( + "Assertion failed: FakeDevice3::DrawIndexedPrimitive:917"); + } else if (fvf != Vertex1C_TypeDesc) { + gog_debug("Assertion failed: FakeDevice3::DrawIndexedPrimitive:919"); + } + if (!vertices) gog_debug("Assertion failed: FakeDevice3::DrawIndexedPrimitive:921"); + if (!vertex_count) gog_debug("Assertion failed: FakeDevice3::DrawIndexedPrimitive:922"); + if (!indices) gog_debug("Assertion failed: FakeDevice3::DrawIndexedPrimitive:923"); + if (!index_count) gog_debug("Assertion failed: FakeDevice3::DrawIndexedPrimitive:924"); + if (flags != 0x1C) gog_debug("Assertion failed: FakeDevice3::DrawIndexedPrimitive:925"); + + if (fvf == Vertex1C_TypeDesc) { + if (vertex_count) { + dk2::Vertex1C *pos = (dk2::Vertex1C *) vertices; + int vertex_left = vertex_count; + do { + if (pos->z < 0.0 || pos->z > 1.0) gog_debug("Assertion failed: FakeDevice3::DrawIndexedPrimitive:929"); + ++pos; + --vertex_left; + } while (vertex_left); + } + if (cfg::iAntialias && orig::pIDirectDrawSurface4_zbuf) { + unsigned int lastVertesIdx = 0; + if (vertex_count >= 4) { + unsigned int quadsLeft = ((unsigned int) (vertex_count - 4) >> 2) + 1; + dk2::Vertex1C *quad = (dk2::Vertex1C *) vertices; + double dAntialias = (float) cfg::iAntialias; + lastVertesIdx = 4 * quadsLeft; + do { + quad[0].x = dAntialias * quad[0].x; + quad[0].y = dAntialias * quad[0].y; + quad[1].x = dAntialias * quad[1].x; + quad[1].y = dAntialias * quad[1].y; + quad[2].x = dAntialias * quad[2].x; + quad[2].y = dAntialias * quad[2].y; + quad[3].x = dAntialias * quad[3].x; + quad[3].y = dAntialias * quad[3].y; + quad += 4; + --quadsLeft; + } while (quadsLeft); + } + if (lastVertesIdx < vertex_count) { + dk2::Vertex1C *vertex = ((dk2::Vertex1C *) vertices) + lastVertesIdx; + double dAntialias = (float) cfg::iAntialias; + unsigned int vertexLeft = vertex_count - lastVertesIdx; + do { + vertex->x = dAntialias * vertex->x; + vertex->y = dAntialias * vertex->y; + ++vertex; + --vertexLeft; + } while (vertexLeft); + } + } + } else if (cfg::iAntialias && orig::pIDirectDrawSurface4_zbuf) { + unsigned int lastVertexIdx = 0; + if (vertex_count >= 4) { + unsigned int quadsLeft = ((unsigned int) (vertex_count - 4) >> 2) + 1; + dk2::Vertex2C *quad = (dk2::Vertex2C *) vertices; + double dAntialias = (float) cfg::iAntialias; + lastVertexIdx = 4 * quadsLeft; + do { + --quadsLeft; + quad[0].f0_x = dAntialias * quad[0].f0_x; + quad[0].f4_y = dAntialias * quad[0].f4_y; + quad[1].f0_x = dAntialias * quad[1].f0_x; + quad[1].f4_y = dAntialias * quad[1].f4_y; + quad[2].f0_x = dAntialias * quad[2].f0_x; + quad[2].f4_y = dAntialias * quad[2].f4_y; + quad[3].f0_x = dAntialias * quad[3].f0_x; + quad[3].f4_y = dAntialias * quad[3].f4_y; + quad += 4; + } while (quadsLeft); + } + if (lastVertexIdx < vertex_count) { + double dAntialias = (float) cfg::iAntialias; + dk2::Vertex2C *vertex = ((dk2::Vertex2C *) vertices) + lastVertexIdx; + unsigned int vertexLeft = vertex_count - lastVertexIdx; + do { + vertex->f0_x = dAntialias * vertex->f0_x; + vertex->f4_y = dAntialias * vertex->f4_y; + ++vertex; + --vertexLeft; + } while (vertexLeft); + } + } + HRESULT hr; + hr = orig::pIDirect3DDevice3->DrawIndexedPrimitive( + primitive_type, fvf, vertices, vertex_count, indices, index_count, 0x15 + ); + if (FAILED(hr)) { + gog_debugf("Assertion failed: FakeDevice3::DrawIndexedPrimitive:951 with HRESULT 0x%x", hr); + return hr; + } + return hr; +} + +HRESULT FakeDevice3::SetClipStatus(LPD3DCLIPSTATUS) { + gog_debug("Unused function called: FakeDevice3::SetClipStatus"); + return DDERR_GENERIC; +} + +HRESULT FakeDevice3::GetClipStatus(LPD3DCLIPSTATUS) { + gog_debug("Unused function called: FakeDevice3::GetClipStatus"); + return DDERR_GENERIC; +} + +HRESULT FakeDevice3::DrawPrimitiveStrided(D3DPRIMITIVETYPE, DWORD, LPD3DDRAWPRIMITIVESTRIDEDDATA, DWORD, DWORD) { + gog_debug("Unused function called: FakeDevice3::DrawPrimitiveStrided"); + return DDERR_GENERIC; +} + +HRESULT +FakeDevice3::DrawIndexedPrimitiveStrided(D3DPRIMITIVETYPE, DWORD, LPD3DDRAWPRIMITIVESTRIDEDDATA, DWORD, LPWORD, DWORD, + DWORD) { + gog_debug("Unused function called: FakeDevice3::DrawIndexedPrimitiveStrided"); + return DDERR_GENERIC; +} + +HRESULT FakeDevice3::DrawPrimitiveVB(D3DPRIMITIVETYPE, LPDIRECT3DVERTEXBUFFER, DWORD, DWORD, DWORD) { + gog_debug("Unused function called: FakeDevice3::DrawPrimitiveVB"); + return DDERR_GENERIC; +} + +HRESULT FakeDevice3::DrawIndexedPrimitiveVB(D3DPRIMITIVETYPE, LPDIRECT3DVERTEXBUFFER, LPWORD, DWORD, DWORD) { + gog_debug("Unused function called: FakeDevice3::DrawIndexedPrimitiveVB"); + return DDERR_GENERIC; +} + +HRESULT FakeDevice3::ComputeSphereVisibility(LPD3DVECTOR, LPD3DVALUE, DWORD, DWORD, LPDWORD) { + gog_debug("Unused function called: FakeDevice3::ComputeSphereVisibility"); + return DDERR_GENERIC; +} + +HRESULT FakeDevice3::GetTexture(DWORD, LPDIRECT3DTEXTURE2 *) { + gog_debug("Unused function called: FakeDevice3::GetTexture"); + return DDERR_GENERIC; +} + +HRESULT FakeDevice3::SetTexture(DWORD a3, LPDIRECT3DTEXTURE2 tex_) { + auto *tex = (FakeTexture *) tex_; + IDirect3DTexture2 *orig_tex = nullptr; + if (tex) orig_tex = tex->orig(); + HRESULT hr = orig::pIDirect3DDevice3->SetTexture(a3, orig_tex); + if (FAILED(hr)) { + gog_debugf("Assertion failed: FakeDevice3::SetTexture:964 with HRESULT 0x%x", hr); + return hr; + } + return hr; +} + +HRESULT FakeDevice3::GetTextureStageState(DWORD, D3DTEXTURESTAGESTATETYPE, LPDWORD) { + gog_debug("Unused function called: FakeDevice3::GetTextureStageState"); + return DDERR_GENERIC; +} + +HRESULT FakeDevice3::SetTextureStageState(DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value) { + if (cfg::iBumpmap) { + if (Stage != 0 && Stage != 1 && Stage != 2) gog_debug( + "Assertion failed: FakeDevice3::SetTextureStageState:970"); + } else if (Stage != 0) { + gog_debug("Assertion failed: FakeDevice3::SetTextureStageState:972"); + } + switch (Type) { + case D3DTSS_MAXANISOTROPY: gog_debug("Assertion failed: FakeDevice3::SetTextureStageState:975"); + break; + case D3DTSS_MAGFILTER: + if (Value == 2) Value = 5; + break; + case D3DTSS_MINFILTER: + if (Value == 2) Value = 3; + break; + default: + break; + } + HRESULT hr = orig::pIDirect3DDevice3->SetTextureStageState(Stage, Type, Value); + if (FAILED(hr)) { + gog_debugf("Assertion failed: FakeDevice3::SetTextureStageState:984 with HRESULT 0x%x", hr); + return hr; + } + return hr; +} + +HRESULT FakeDevice3::ValidateDevice(LPDWORD) { + gog_debug("Unused function called: FakeDevice3::ValidateDevice"); + return DDERR_GENERIC; +} + diff --git a/src/patches/gog_patch_dll/fake/FakeDevice3.h b/src/patches/gog_patch_dll/fake/FakeDevice3.h new file mode 100644 index 0000000..efe48fd --- /dev/null +++ b/src/patches/gog_patch_dll/fake/FakeDevice3.h @@ -0,0 +1,69 @@ +// +// Created by DiaLight on 20.01.2023. +// + +#ifndef EMBER_FAKEDEVICE3_H +#define EMBER_FAKEDEVICE3_H + +#include +#include + +namespace gog { + + class FakeDevice3 : public FakeUnknown { + + public: + FakeDevice3(); + + /*** IUnknown methods ***/ + STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) override; + STDMETHOD_(ULONG,Release)(THIS) override; + + /*** IDirect3DDevice3 methods ***/ + STDMETHOD(GetCaps)(THIS_ LPD3DDEVICEDESC,LPD3DDEVICEDESC) override; + STDMETHOD(GetStats)(THIS_ LPD3DSTATS) override; + STDMETHOD(AddViewport)(THIS_ LPDIRECT3DVIEWPORT3) override; + STDMETHOD(DeleteViewport)(THIS_ LPDIRECT3DVIEWPORT3) override; + STDMETHOD(NextViewport)(THIS_ LPDIRECT3DVIEWPORT3,LPDIRECT3DVIEWPORT3*,DWORD) override; + STDMETHOD(EnumTextureFormats)(THIS_ LPD3DENUMPIXELFORMATSCALLBACK,LPVOID) override; + STDMETHOD(BeginScene)(THIS) override; + STDMETHOD(EndScene)(THIS) override; + STDMETHOD(GetDirect3D)(THIS_ LPDIRECT3D3*) override; + STDMETHOD(SetCurrentViewport)(THIS_ LPDIRECT3DVIEWPORT3) override; + STDMETHOD(GetCurrentViewport)(THIS_ LPDIRECT3DVIEWPORT3 *) override; + STDMETHOD(SetRenderTarget)(THIS_ LPDIRECTDRAWSURFACE4,DWORD) override; + STDMETHOD(GetRenderTarget)(THIS_ LPDIRECTDRAWSURFACE4 *) override; + STDMETHOD(Begin)(THIS_ D3DPRIMITIVETYPE,DWORD,DWORD) override; + STDMETHOD(BeginIndexed)(THIS_ D3DPRIMITIVETYPE,DWORD,LPVOID,DWORD,DWORD) override; + STDMETHOD(Vertex)(THIS_ LPVOID) override; + STDMETHOD(Index)(THIS_ WORD) override; + STDMETHOD(End)(THIS_ DWORD) override; + STDMETHOD(GetRenderState)(THIS_ D3DRENDERSTATETYPE,LPDWORD) override; + STDMETHOD(SetRenderState)(THIS_ D3DRENDERSTATETYPE,DWORD) override; + STDMETHOD(GetLightState)(THIS_ D3DLIGHTSTATETYPE,LPDWORD) override; + STDMETHOD(SetLightState)(THIS_ D3DLIGHTSTATETYPE,DWORD) override; + STDMETHOD(SetTransform)(THIS_ D3DTRANSFORMSTATETYPE,LPD3DMATRIX) override; + STDMETHOD(GetTransform)(THIS_ D3DTRANSFORMSTATETYPE,LPD3DMATRIX) override; + STDMETHOD(MultiplyTransform)(THIS_ D3DTRANSFORMSTATETYPE,LPD3DMATRIX) override; + STDMETHOD(DrawPrimitive)(THIS_ D3DPRIMITIVETYPE,DWORD,LPVOID,DWORD,DWORD) override; + STDMETHOD(DrawIndexedPrimitive)(THIS_ D3DPRIMITIVETYPE,DWORD,LPVOID,DWORD,LPWORD,DWORD,DWORD) override; + STDMETHOD(SetClipStatus)(THIS_ LPD3DCLIPSTATUS) override; + STDMETHOD(GetClipStatus)(THIS_ LPD3DCLIPSTATUS) override; + STDMETHOD(DrawPrimitiveStrided)(THIS_ D3DPRIMITIVETYPE,DWORD,LPD3DDRAWPRIMITIVESTRIDEDDATA,DWORD,DWORD) override; + STDMETHOD(DrawIndexedPrimitiveStrided)(THIS_ D3DPRIMITIVETYPE,DWORD,LPD3DDRAWPRIMITIVESTRIDEDDATA,DWORD,LPWORD,DWORD,DWORD) override; + STDMETHOD(DrawPrimitiveVB)(THIS_ D3DPRIMITIVETYPE,LPDIRECT3DVERTEXBUFFER,DWORD,DWORD,DWORD) override; + STDMETHOD(DrawIndexedPrimitiveVB)(THIS_ D3DPRIMITIVETYPE,LPDIRECT3DVERTEXBUFFER,LPWORD,DWORD,DWORD) override; + STDMETHOD(ComputeSphereVisibility)(THIS_ LPD3DVECTOR,LPD3DVALUE,DWORD,DWORD,LPDWORD) override; + STDMETHOD(GetTexture)(THIS_ DWORD,LPDIRECT3DTEXTURE2 *) override; + STDMETHOD(SetTexture)(THIS_ DWORD,LPDIRECT3DTEXTURE2) override; + STDMETHOD(GetTextureStageState)(THIS_ DWORD,D3DTEXTURESTAGESTATETYPE,LPDWORD) override; + STDMETHOD(SetTextureStageState)(THIS_ DWORD,D3DTEXTURESTAGESTATETYPE,DWORD) override; + STDMETHOD(ValidateDevice)(THIS_ LPDWORD) override; + + }; + + static_assert(sizeof(FakeDevice3) == 0x8); + +} + +#endif //EMBER_FAKEDEVICE3_H diff --git a/src/patches/gog_patch_dll/fake/FakeDirectDraw1.cpp b/src/patches/gog_patch_dll/fake/FakeDirectDraw1.cpp new file mode 100644 index 0000000..b5c8f8d --- /dev/null +++ b/src/patches/gog_patch_dll/fake/FakeDirectDraw1.cpp @@ -0,0 +1,324 @@ +// +// Created by DiaLight on 20.01.2023. +// +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace gog; + +FakeDirectDraw1 *FakeDirectDraw1::instance = nullptr; + +HRESULT FakeDirectDraw1::QueryInterface(REFIID riid, LPVOID FAR *ppvObj) { + if (IsEqualGUID(IID_IDirectDraw2, riid)) { + *ppvObj = FakeDirectDraw2::instance; + return DD_OK; + } + if (IsEqualGUID(IID_IDirectDraw4, riid)) { + *ppvObj = FakeDirectDraw4::instance; + return DD_OK; + } + if (IsEqualGUID(IID_IDirect3D, riid)) { + *ppvObj = FakeD3D::instance; + return DD_OK; + } + if (IsEqualGUID(IID_IDirect3D2, riid)) { + *ppvObj = FakeD3D2::instance; + return DD_OK; + } + gog_debug("Unused function called: FakeDirectDraw1::QueryInterface"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw1::Compact(void) { + gog_debug("Unused function called: FakeDirectDraw1::Compact"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw1::CreateClipper(DWORD a1, LPDIRECTDRAWCLIPPER *a2, IUnknown *a3) { + gog_debug("Unused function called: FakeDirectDraw1::CreateClipper"); +// return DDERR_GENERIC; + return orig::pIDirectDraw4->CreateClipper(a1, a2, a3); +} + +HRESULT FakeDirectDraw1::CreatePalette(DWORD, LPPALETTEENTRY, LPDIRECTDRAWPALETTE *, IUnknown *) { + gog_debug("Unused function called: FakeDirectDraw1::CreatePalette"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw1::CreateSurface(LPDDSURFACEDESC pDesc, LPDIRECTDRAWSURFACE *ppSurf, IUnknown *a4) { + static_assert(0x40 == DDSD_ZBUFFERBITDEPTH); + if ((pDesc->dwFlags & DDSD_ZBUFFERBITDEPTH) != 0) { + *ppSurf = FakeZBuffer::instance; + return DD_OK; + } + if (pDesc->ddpfPixelFormat.dwFlags == 4) { + return DDERR_INVALIDPIXELFORMAT; + } + *(LPDIRECTDRAWSURFACE2 *) ppSurf = new FakeSurface((LPDDSURFACEDESC2) pDesc); + return DD_OK; +} + +HRESULT FakeDirectDraw1::DuplicateSurface(LPDIRECTDRAWSURFACE, LPDIRECTDRAWSURFACE *) { + gog_debug("Unused function called: FakeDirectDraw1::DuplicateSurface"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw1::EnumDisplayModes(DWORD, LPDDSURFACEDESC pDesc, LPVOID a4, LPDDENUMMODESCALLBACK cb) { + if (pDesc) gog_debug("Assertion failed: FakeDirectDraw1::EnumDisplayModes:1289"); + DDSURFACEDESC desc; + memset(&desc, 0, sizeof(desc)); + desc.dwSize = sizeof(DDSURFACEDESC); + static_assert(sizeof(DDSURFACEDESC) == 108); + desc.ddpfPixelFormat.dwSize = 32; + desc.dwFlags = 0x1006; + desc.ddpfPixelFormat.dwFlags = 0x40; + desc.ddpfPixelFormat.dwRGBBitCount = 32; + desc.ddpfPixelFormat.dwBBitMask = 0xFF; + desc.ddpfPixelFormat.dwGBitMask = 0xFF00; + desc.ddpfPixelFormat.dwRBitMask = 0xFF0000; + desc.dwWidth = 640; + desc.dwHeight = 480; + cb(&desc, a4); + desc.dwWidth = 800; + desc.dwHeight = 600; + cb(&desc, a4); + desc.dwWidth = 1024; + desc.dwHeight = 768; + cb(&desc, a4); + if (cfg::iHighRes) { + desc.dwWidth = 1280; + desc.dwHeight = 1024; + cb(&desc, a4); + desc.dwWidth = 1600; + desc.dwHeight = 1200; + cb(&desc, a4); + } + HKEY phkResult; + LSTATUS iResult; + iResult = RegOpenKeyExA( + HKEY_CURRENT_USER, + "Software\\Bullfrog Productions Ltd\\Dungeon Keeper II\\Configuration\\Video", + 0, 1u, &phkResult); + if (iResult != ERROR_SUCCESS) { + return DD_OK; + } + DWORD size; + size = 4; + DWORD width = 0; + iResult = RegQueryValueExA(phkResult, "Screen Width", NULL, 0, (LPBYTE) &width, (LPDWORD) &size); + if (iResult != ERROR_SUCCESS || width == 0) + return DD_OK; + size = 4; + DWORD height = 0; + iResult = RegQueryValueExA(phkResult, "Screen Height", NULL, 0, (LPBYTE) &height, (LPDWORD) &size); + if (iResult != ERROR_SUCCESS || height == 0) + return DD_OK; + if (width == 640 && height == 480) return DD_OK; + if (width == 800 && height == 600) return DD_OK; + if (width == 1024 && height == 768) return DD_OK; + if (cfg::iHighRes) { + if (width == 1280 && height == 1024) return DD_OK; + if (width == 1600 && height == 1200) return DD_OK; + } + desc.dwHeight = height; + desc.dwWidth = width; + cb(&desc, a4); + return DD_OK; +} + +HRESULT FakeDirectDraw1::EnumSurfaces(DWORD, LPDDSURFACEDESC, LPVOID, LPDDENUMSURFACESCALLBACK) { + gog_debug("Unused function called: FakeDirectDraw1::EnumSurfaces"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw1::FlipToGDISurface(void) { + gog_debug("Unused function called: FakeDirectDraw1::FlipToGDISurface"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw1::GetCaps(LPDDCAPS hwCaps, LPDDCAPS halCaps) { + if (!hwCaps) gog_debug("Assertion failed: FakeDirectDraw1::GetCaps:1370"); + if (halCaps) gog_debug("Assertion failed: FakeDirectDraw1::GetCaps:1371"); + DDCAPS caps; + caps.dwSize = sizeof(DDCAPS); + static_assert(sizeof(DDCAPS) == 380); + caps.dwCaps = 0x95C07FC1; + caps.dwCaps2 = 0x806AB230; + caps.dwCKeyCaps = 0x311; + caps.dwFXCaps = 0x22AD5420; + memset(&caps.dwFXAlphaCaps, 0, 0x29); + caps.dwVidMemTotal = 0xAF42C000; + caps.dwVidMemFree = 0xAEF2C000; + caps.dwMaxVisibleOverlays = 1; + caps.dwCurrVisibleOverlays = 0; + caps.dwNumFourCCCodes = 21; + memset(&caps.dwAlignBoundarySrc, 0, 0x2C); + caps.dwRops[6] = 0x1000; + caps.dwRops[7] = 0; + caps.ddsOldCaps.dwCaps = 0x304672FC; + caps.dwMinOverlayStretch = 0x20; + caps.dwMaxOverlayStretch = 0x7D000; + memset(&caps.dwMinLiveVideoStretch, 0, 0x1C); + caps.dwSVBCaps = 0x40; + memset(&caps.dwSVBCKeyCaps, 0, 0x20); + caps.dwSVBRops[6] = 0x1000; + caps.dwSVBRops[7] = 0; + caps.dwVSBCaps = 0x40; + memset(&caps.dwVSBCKeyCaps, 0, 0x20); + caps.dwVSBRops[6] = 0x1000; + memset(&caps.dwVSBRops[7], 0, 0x3C); + caps.dwNLVBCaps = 0x95C07FC1; + caps.dwNLVBCaps2 = 0x8062B230; + caps.dwNLVBCKeyCaps = 0x311; + caps.dwNLVBFXCaps = 0x22AD5420; + memset(caps.dwNLVBRops, 0, 0x18); + caps.dwNLVBRops[6] = 0x1000; + caps.dwNLVBRops[7] = 0; + caps.ddsCaps.dwCaps = 0x304672FC; + caps.ddsCaps.dwCaps2 = 0x200; + caps.ddsCaps.dwCaps3 = 0; + caps.ddsCaps.dwCaps4 = 0; + memcpy(hwCaps, &caps, hwCaps->dwSize); + return DD_OK; +} + +HRESULT FakeDirectDraw1::GetDisplayMode(LPDDSURFACEDESC desc) { + gog_debug("Unused function called: FakeDirectDraw1::GetDisplayMode"); +// return DDERR_GENERIC; + return orig::pIDirectDraw4->GetDisplayMode((LPDDSURFACEDESC2) desc); +} + +HRESULT FakeDirectDraw1::GetFourCCCodes(LPDWORD, LPDWORD) { + gog_debug("Unused function called: FakeDirectDraw1::GetFourCCCodes"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw1::GetGDISurface(LPDIRECTDRAWSURFACE *) { + gog_debug("Unused function called: FakeDirectDraw1::GetGDISurface"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw1::GetMonitorFrequency(LPDWORD) { + gog_debug("Unused function called: FakeDirectDraw1::GetMonitorFrequency"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw1::GetScanLine(LPDWORD) { + gog_debug("Unused function called: FakeDirectDraw1::GetScanLine"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw1::GetVerticalBlankStatus(LPBOOL) { + gog_debug("Unused function called: FakeDirectDraw1::GetVerticalBlankStatus"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw1::Initialize(GUID *) { + gog_debug("Unused function called: FakeDirectDraw1::Initialize"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw1::RestoreDisplayMode(void) { + return DD_OK; +} + +HRESULT FakeDirectDraw1::SetCooperativeLevel(HWND hwnd, DWORD a3) { + if (!hwnd) + return DD_OK; + if (gog::g_hWnd) { + if (gog::g_hWnd != hwnd) { + gog_debug("Assertion failed: FakeDirectDraw1::SetCooperativeLevel:1436"); + return DD_OK; + } + return DD_OK; + } + gog::g_hWnd = hwnd; + HRESULT hr; + if (cfg::iRealFullscreen) + hr = orig::pIDirectDraw4->SetCooperativeLevel(hwnd, 0x11); + else + hr = orig::pIDirectDraw4->SetCooperativeLevel(hwnd, 0x8); + if (FAILED(hr)) { + gog_debugf("Assertion failed: FakeDirectDraw1::SetCooperativeLevel:1445 with HRESULT 0x%x", hr); + return hr; + } + DDSURFACEDESC2 surfDesc; + memset(&surfDesc, 0, sizeof(surfDesc)); + surfDesc.dwSize = 124; + static_assert(sizeof(DDSURFACEDESC2) == 124); + surfDesc.dwFlags = 1; + surfDesc.ddsCaps.dwCaps = 0x200; + hr = orig::pIDirectDraw4->CreateSurface(&surfDesc, &orig::pIDirectDrawSurface4_coop, 0); + if (FAILED(hr)) { + gog_debugf("Assertion failed: FakeDirectDraw1::SetCooperativeLevel:1451 with HRESULT 0x%x", hr); + } + hr = orig::pIDirectDraw4->QueryInterface(IID_IDirect3D3, (LPVOID *) &orig::pIDirect3D3); + if (FAILED(hr)) { + gog_debugf("Assertion failed: FakeDirectDraw1::SetCooperativeLevel:1453 with HRESULT 0x%x", hr); + } + if (!gog::g_isAntialiasGt10) return DD_OK; + memset(&surfDesc, 0, sizeof(surfDesc)); + surfDesc.dwSize = 124; + static_assert(sizeof(DDSURFACEDESC2) == 124); + surfDesc.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT); + static_assert(sizeof(DDPIXELFORMAT) == 32); + surfDesc.ddpfPixelFormat.dwFlags = 0x40; + surfDesc.ddpfPixelFormat.dwRGBBitCount = 32; + surfDesc.ddpfPixelFormat.dwRBitMask = 0xFF0000; + surfDesc.ddpfPixelFormat.dwGBitMask = 0xFF00; + surfDesc.ddpfPixelFormat.dwBBitMask = 0xFF; + surfDesc.dwFlags = 0x1007; + surfDesc.ddsCaps.dwCaps = 0x4040; + surfDesc.dwWidth = 640; + surfDesc.dwHeight = 480; + hr = orig::pIDirectDraw4->CreateSurface(&surfDesc, &orig::pIDirectDrawSurface4_640x480, NULL); + if (FAILED(hr)) { + gog_debugf("Assertion failed: FakeDirectDraw1::SetCooperativeLevel:1474 with HRESULT 0x%x", hr); + } + return DD_OK; +} + +HRESULT FakeDirectDraw1::SetDisplayMode(DWORD width, DWORD height, DWORD a4) { + if (FakeSurface::instance_mod) { + FakeSurface::instance_mod->Release(); + FakeSurface::instance_mod = nullptr; + } + if (FakeSurface::instance_cpy) { + FakeSurface::instance_cpy->Release(); + FakeSurface::instance_cpy = nullptr; + } + if (orig::pIDirectDrawSurface4_zbuf) { + orig::pIDirectDrawSurface4_zbuf->Release(); + orig::pIDirectDrawSurface4_zbuf = nullptr; + } + g_dwWidth = width; + g_dwHeight = height; + if (a4 != 32) gog_debug("Assertion failed: FakeDirectDraw1::SetDisplayMode:1488"); + if (cfg::iNotOnTop) + SetWindowPos(g_hWnd, (HWND) 0xFFFFFFFE, 0, 0, 0, 0, 3u); + gog_debugf("Screen mode set: %dx%d", width, height); + Fake_InitRenderRect(); + if (!orig::pIDirectDrawSurface4_coop) + return DD_OK; + DDBLTFX bitblt; + memset(&bitblt, 0, sizeof(bitblt)); + bitblt.dwSize = 100; + orig::pIDirectDrawSurface4_coop->Blt(NULL, NULL, NULL, 1024, &bitblt); + return DD_OK; +} + +HRESULT FakeDirectDraw1::WaitForVerticalBlank(DWORD, HANDLE) { + gog_debug("Unused function called: FakeDirectDraw1::WaitForVerticalBlank"); + return DDERR_GENERIC; +} + + diff --git a/src/patches/gog_patch_dll/fake/FakeDirectDraw1.h b/src/patches/gog_patch_dll/fake/FakeDirectDraw1.h new file mode 100644 index 0000000..734fc6a --- /dev/null +++ b/src/patches/gog_patch_dll/fake/FakeDirectDraw1.h @@ -0,0 +1,47 @@ +// +// Created by DiaLight on 20.01.2023. +// + +#ifndef EMBER_FAKEDIRECTDRAW1_H +#define EMBER_FAKEDIRECTDRAW1_H + +#include +#include + +namespace gog { + + class FakeDirectDraw1 : public FakeUnknown { + + public: + /*** IUnknown methods ***/ + STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR * ppvObj) override; + + /*** IDirectDraw methods ***/ + STDMETHOD(Compact)(THIS) override; + STDMETHOD(CreateClipper)(THIS_ DWORD, LPDIRECTDRAWCLIPPER FAR*, IUnknown FAR * ) override; + STDMETHOD(CreatePalette)(THIS_ DWORD, LPPALETTEENTRY, LPDIRECTDRAWPALETTE FAR*, IUnknown FAR * ) override; + STDMETHOD(CreateSurface)(THIS_ LPDDSURFACEDESC, LPDIRECTDRAWSURFACE FAR *, IUnknown FAR *) override; + STDMETHOD(DuplicateSurface)( THIS_ LPDIRECTDRAWSURFACE, LPDIRECTDRAWSURFACE FAR * ) override; + STDMETHOD(EnumDisplayModes)( THIS_ DWORD, LPDDSURFACEDESC, LPVOID, LPDDENUMMODESCALLBACK ) override; + STDMETHOD(EnumSurfaces)(THIS_ DWORD, LPDDSURFACEDESC, LPVOID,LPDDENUMSURFACESCALLBACK ) override; + STDMETHOD(FlipToGDISurface)(THIS) override; + STDMETHOD(GetCaps)( THIS_ LPDDCAPS, LPDDCAPS) override; + STDMETHOD(GetDisplayMode)( THIS_ LPDDSURFACEDESC) override; + STDMETHOD(GetFourCCCodes)(THIS_ LPDWORD, LPDWORD ) override; + STDMETHOD(GetGDISurface)(THIS_ LPDIRECTDRAWSURFACE FAR *) override; + STDMETHOD(GetMonitorFrequency)(THIS_ LPDWORD) override; + STDMETHOD(GetScanLine)(THIS_ LPDWORD) override; + STDMETHOD(GetVerticalBlankStatus)(THIS_ LPBOOL ) override; + STDMETHOD(Initialize)(THIS_ GUID FAR *) override; + STDMETHOD(RestoreDisplayMode)(THIS) override; + STDMETHOD(SetCooperativeLevel)(THIS_ HWND, DWORD) override; + STDMETHOD(SetDisplayMode)(THIS_ DWORD, DWORD,DWORD) override; + STDMETHOD(WaitForVerticalBlank)(THIS_ DWORD, HANDLE ) override; + + static FakeDirectDraw1 *instance; + + }; + +} + +#endif //EMBER_FAKEDIRECTDRAW1_H diff --git a/src/patches/gog_patch_dll/fake/FakeDirectDraw2.cpp b/src/patches/gog_patch_dll/fake/FakeDirectDraw2.cpp new file mode 100644 index 0000000..50a98df --- /dev/null +++ b/src/patches/gog_patch_dll/fake/FakeDirectDraw2.cpp @@ -0,0 +1,182 @@ +// +// Created by DiaLight on 20.01.2023. +// +#include +#include +#include +#include +#include + +using namespace gog; + +FakeDirectDraw2 *FakeDirectDraw2::instance = nullptr; + +HRESULT FakeDirectDraw2::QueryInterface(REFIID riid, LPVOID FAR *ppvObj) { + gog_debug("Unused function called: FakeDirectDraw2::QueryInterface"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw2::Compact(void) { + gog_debug("Unused function called: FakeDirectDraw2::Compact"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw2::CreateClipper(DWORD, LPDIRECTDRAWCLIPPER *, IUnknown *) { + gog_debug("Unused function called: FakeDirectDraw2::CreateClipper"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw2::CreatePalette(DWORD, LPPALETTEENTRY, LPDIRECTDRAWPALETTE *, IUnknown *) { + gog_debug("Unused function called: FakeDirectDraw2::CreatePalette"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw2::CreateSurface(LPDDSURFACEDESC pDesc, LPDIRECTDRAWSURFACE *ppSurf, IUnknown *a4) { + if (!gog::g_isMsgSent) { + if (gog::g_hWnd) { + g_isMsgSent = true; + if (cfg::iRestoreMode == 1) { + SendMessageA(gog::g_hWnd, WM_ACTIVATE, WA_ACTIVE, (LPARAM) (HWND) NULL); + } + } + } + if (pDesc->ddpfPixelFormat.dwFlags != 4) gog_debug("Assertion failed: FakeDirectDraw2::CreateSurface:1161"); + if (cfg::iDisableFourCC) + return DDERR_INVALIDPIXELFORMAT; + *(LPDIRECTDRAWSURFACE2 *) ppSurf = new FakeSurface((LPDDSURFACEDESC2) pDesc); + return DD_OK; +} + +HRESULT FakeDirectDraw2::DuplicateSurface(LPDIRECTDRAWSURFACE, LPDIRECTDRAWSURFACE *) { + gog_debug("Unused function called: FakeDirectDraw2::DuplicateSurface"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw2::EnumDisplayModes(DWORD, LPDDSURFACEDESC, LPVOID, LPDDENUMMODESCALLBACK) { + gog_debug("Unused function called: FakeDirectDraw2::EnumDisplayModes"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw2::EnumSurfaces(DWORD, LPDDSURFACEDESC, LPVOID, LPDDENUMSURFACESCALLBACK) { + gog_debug("Unused function called: FakeDirectDraw2::EnumSurfaces"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw2::FlipToGDISurface(void) { + gog_debug("Unused function called: FakeDirectDraw2::FlipToGDISurface"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw2::GetCaps(LPDDCAPS hwCaps, LPDDCAPS halCaps) { + DDCAPS caps; + caps.dwSize = sizeof(DDCAPS); + static_assert(sizeof(DDCAPS) == 380); + caps.dwCaps = 0x95C07FC1; + caps.dwCaps2 = 0x806AB230; + caps.dwCKeyCaps = 0x311; + caps.dwFXCaps = 0x22AD5420; + memset(&caps.dwFXAlphaCaps, 0, 0x28); + caps.dwVidMemTotal = 0xAF42C000; + caps.dwVidMemFree = 0xAEEC0800; + caps.dwMaxVisibleOverlays = 1; + caps.dwCurrVisibleOverlays = 0; + caps.dwNumFourCCCodes = 21; + memset(&caps.dwAlignBoundarySrc, 0, 0x2C); + caps.dwRops[6] = 0x1000; + caps.dwRops[7] = 0; + caps.ddsOldCaps.dwCaps = 0x304672FC; + caps.dwMinOverlayStretch = 0x20; + caps.dwMaxOverlayStretch = 0x7D000; + memset(&caps.dwMinLiveVideoStretch, 0, 0x1C); + caps.dwSVBCaps = 0x40; + memset(&caps.dwSVBCKeyCaps, 0, 0x20); + caps.dwSVBRops[6] = 0x1000; + caps.dwSVBRops[7] = 0; + caps.dwVSBCaps = 0x40; + memset(&caps.dwVSBCKeyCaps, 0, 0x20); + caps.dwVSBRops[6] = 0x1000; + memset(&caps.dwVSBRops[7], 0, 0x3C); + caps.dwNLVBCaps = 0x95C07FC1; + caps.dwNLVBCaps2 = 0x8062B230; + caps.dwNLVBCKeyCaps = 0x311; + caps.dwNLVBFXCaps = 0x22AD5420; + memset(caps.dwNLVBRops, 0, 0x18); + caps.dwNLVBRops[6] = 0x1000; + caps.dwNLVBRops[7] = 0; + caps.ddsCaps.dwCaps = 0x304672FC; + caps.ddsCaps.dwCaps2 = 0x200; + caps.ddsCaps.dwCaps3 = 0; + caps.ddsCaps.dwCaps4 = 0; + if (hwCaps) + memcpy(hwCaps, &caps, hwCaps->dwSize); + if (halCaps) + memcpy(halCaps, &caps, halCaps->dwSize); + return DD_OK; +} + +HRESULT FakeDirectDraw2::GetDisplayMode(LPDDSURFACEDESC) { + gog_debug("Unused function called: FakeDirectDraw2::GetDisplayMode"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw2::GetFourCCCodes(LPDWORD a2, LPDWORD a3) { + *a2 = 0; + if (a3) + *a3 = 0; + return DD_OK; +} + +HRESULT FakeDirectDraw2::GetGDISurface(LPDIRECTDRAWSURFACE *) { + gog_debug("Unused function called: FakeDirectDraw2::GetGDISurface"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw2::GetMonitorFrequency(LPDWORD) { + gog_debug("Unused function called: FakeDirectDraw2::GetMonitorFrequency"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw2::GetScanLine(LPDWORD) { + gog_debug("Unused function called: FakeDirectDraw2::GetScanLine"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw2::GetVerticalBlankStatus(LPBOOL) { + gog_debug("Unused function called: FakeDirectDraw2::GetVerticalBlankStatus"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw2::Initialize(GUID *) { + gog_debug("Unused function called: FakeDirectDraw2::Initialize"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw2::RestoreDisplayMode(void) { + gog_debug("Unused function called: FakeDirectDraw2::RestoreDisplayMode"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw2::SetCooperativeLevel(HWND, DWORD) { + gog_debug("Unused function called: FakeDirectDraw2::SetCooperativeLevel"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw2::SetDisplayMode(DWORD, DWORD, DWORD, DWORD, DWORD) { + gog_debug("Unused function called: FakeDirectDraw2::SetDisplayMode"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw2::WaitForVerticalBlank(DWORD, HANDLE) { + gog_debug("Unused function called: FakeDirectDraw2::WaitForVerticalBlank"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw2::GetAvailableVidMem(LPDDSCAPS, LPDWORD a3, LPDWORD a4) { + if (a3) + *a3 = 0x2000000; + if (a4) + *a4 = 0x2000000; + return DD_OK; +} + + diff --git a/src/patches/gog_patch_dll/fake/FakeDirectDraw2.h b/src/patches/gog_patch_dll/fake/FakeDirectDraw2.h new file mode 100644 index 0000000..f54b8fd --- /dev/null +++ b/src/patches/gog_patch_dll/fake/FakeDirectDraw2.h @@ -0,0 +1,49 @@ +// +// Created by DiaLight on 20.01.2023. +// + +#ifndef EMBER_FAKEDIRECTDRAW2_H +#define EMBER_FAKEDIRECTDRAW2_H + +#include +#include + +namespace gog { + + class FakeDirectDraw2 : public FakeUnknown { + + public: + /*** IUnknown methods ***/ + STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR * ppvObj) override; + + /*** IDirectDraw methods ***/ + STDMETHOD(Compact)(THIS) override; + STDMETHOD(CreateClipper)(THIS_ DWORD, LPDIRECTDRAWCLIPPER FAR*, IUnknown FAR * ) override; + STDMETHOD(CreatePalette)(THIS_ DWORD, LPPALETTEENTRY, LPDIRECTDRAWPALETTE FAR*, IUnknown FAR * ) override; + STDMETHOD(CreateSurface)(THIS_ LPDDSURFACEDESC, LPDIRECTDRAWSURFACE FAR *, IUnknown FAR *) override; + STDMETHOD(DuplicateSurface)( THIS_ LPDIRECTDRAWSURFACE, LPDIRECTDRAWSURFACE FAR * ) override; + STDMETHOD(EnumDisplayModes)( THIS_ DWORD, LPDDSURFACEDESC, LPVOID, LPDDENUMMODESCALLBACK ) override; + STDMETHOD(EnumSurfaces)(THIS_ DWORD, LPDDSURFACEDESC, LPVOID,LPDDENUMSURFACESCALLBACK ) override; + STDMETHOD(FlipToGDISurface)(THIS) override; + STDMETHOD(GetCaps)( THIS_ LPDDCAPS, LPDDCAPS) override; + STDMETHOD(GetDisplayMode)( THIS_ LPDDSURFACEDESC) override; + STDMETHOD(GetFourCCCodes)(THIS_ LPDWORD, LPDWORD ) override; + STDMETHOD(GetGDISurface)(THIS_ LPDIRECTDRAWSURFACE FAR *) override; + STDMETHOD(GetMonitorFrequency)(THIS_ LPDWORD) override; + STDMETHOD(GetScanLine)(THIS_ LPDWORD) override; + STDMETHOD(GetVerticalBlankStatus)(THIS_ LPBOOL ) override; + STDMETHOD(Initialize)(THIS_ GUID FAR *) override; + STDMETHOD(RestoreDisplayMode)(THIS) override; + STDMETHOD(SetCooperativeLevel)(THIS_ HWND, DWORD) override; + STDMETHOD(SetDisplayMode)(THIS_ DWORD, DWORD,DWORD, DWORD, DWORD) override; + STDMETHOD(WaitForVerticalBlank)(THIS_ DWORD, HANDLE ) override; + /*** Added in the v2 interface ***/ + STDMETHOD(GetAvailableVidMem)(THIS_ LPDDSCAPS, LPDWORD, LPDWORD) override; + + static FakeDirectDraw2 *instance; + + }; + +} + +#endif //EMBER_FAKEDIRECTDRAW2_H diff --git a/src/patches/gog_patch_dll/fake/FakeDirectDraw4.cpp b/src/patches/gog_patch_dll/fake/FakeDirectDraw4.cpp new file mode 100644 index 0000000..b942299 --- /dev/null +++ b/src/patches/gog_patch_dll/fake/FakeDirectDraw4.cpp @@ -0,0 +1,199 @@ +// +// Created by DiaLight on 20.01.2023. +// +#include +#include +#include +#include + +using namespace gog; + +FakeDirectDraw4 *FakeDirectDraw4::instance = nullptr; + +HRESULT FakeDirectDraw4::QueryInterface(REFIID riid, LPVOID FAR *ppvObj) { + if (IsEqualGUID(IID_IDirect3D3, riid)) { + *ppvObj = FakeD3D3::instance; + return DD_OK; + } + gog_debug("Unused function called: FakeDirectDraw4::QueryInterface"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw4::Compact(void) { + gog_debug("Unused function called: FakeDirectDraw4::Compact"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw4::CreateClipper(DWORD, LPDIRECTDRAWCLIPPER *, IUnknown *) { + gog_debug("Unused function called: FakeDirectDraw4::CreateClipper"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw4::CreatePalette(DWORD, LPPALETTEENTRY, LPDIRECTDRAWPALETTE *, IUnknown *) { + gog_debug("Unused function called: FakeDirectDraw4::CreatePalette"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw4::CreateSurface(LPDDSURFACEDESC2 pDesc, LPDIRECTDRAWSURFACE4 *ppSurf, IUnknown *a4) { + if (!pDesc) gog_debug("Assertion failed: FakeDirectDraw4::CreateSurface:1053"); + if (a4) gog_debug("Assertion failed: FakeDirectDraw4::CreateSurface:1054"); + auto *surf = new FakeSurface4(pDesc); + if (!surf->orig()) gog_debug("Assertion failed: FakeDirectDraw4::CreateSurface:1056"); + *ppSurf = surf; + return DD_OK; +} + +HRESULT FakeDirectDraw4::DuplicateSurface(LPDIRECTDRAWSURFACE4, LPDIRECTDRAWSURFACE4 *) { + gog_debug("Unused function called: FakeDirectDraw4::DuplicateSurface"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw4::EnumDisplayModes(DWORD, LPDDSURFACEDESC2, LPVOID, LPDDENUMMODESCALLBACK2) { + gog_debug("Unused function called: FakeDirectDraw4::EnumDisplayModes"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw4::EnumSurfaces(DWORD, LPDDSURFACEDESC2, LPVOID, LPDDENUMSURFACESCALLBACK2) { + gog_debug("Unused function called: FakeDirectDraw4::EnumSurfaces"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw4::FlipToGDISurface(void) { + gog_debug("Unused function called: FakeDirectDraw4::FlipToGDISurface"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw4::GetCaps(LPDDCAPS hwCaps, LPDDCAPS halCaps) { + if (!hwCaps) gog_debug("Assertion failed: FakeDirectDraw4::GetCaps:1065"); + if (halCaps) gog_debug("Assertion failed: FakeDirectDraw4::GetCaps:1066"); + DDCAPS hwCaps_; + hwCaps_.dwSize = sizeof(DDCAPS); + static_assert(sizeof(DDCAPS) == 380); + hwCaps_.dwCaps = 0x95C07FC1; + hwCaps_.dwCaps2 = 0x806AB230; + hwCaps_.dwCKeyCaps = 0x311; + hwCaps_.dwFXCaps = 0x22AD5420; + memset(&hwCaps_.dwFXAlphaCaps, 0, 0x29); + hwCaps_.dwVidMemTotal = 0xAF42C000; + hwCaps_.dwVidMemFree = 0xAEEC0800; + hwCaps_.dwMaxVisibleOverlays = 1; + hwCaps_.dwCurrVisibleOverlays = 0; + hwCaps_.dwNumFourCCCodes = 21; + memset(&hwCaps_.dwAlignBoundarySrc, 0, 0x2C); + hwCaps_.dwRops[6] = 0x1000; + hwCaps_.dwRops[7] = 0; + hwCaps_.ddsOldCaps.dwCaps = 0x304672FC; + hwCaps_.dwMinOverlayStretch = 0x20; + hwCaps_.dwMaxOverlayStretch = 0x7D000; + memset(&hwCaps_.dwMinLiveVideoStretch, 0, 0x1C); + hwCaps_.dwSVBCaps = 0x40; + memset(&hwCaps_.dwSVBCKeyCaps, 0, 0x20); + hwCaps_.dwSVBRops[6] = 0x1000; + hwCaps_.dwSVBRops[7] = 0; + hwCaps_.dwVSBCaps = 0x40; + memset(&hwCaps_.dwVSBCKeyCaps, 0, 0x20); + hwCaps_.dwVSBRops[6] = 0x1000; + memset(&hwCaps_.dwVSBRops[7], 0, 0x3C); + hwCaps_.dwNLVBCaps = 0x95C07FC1; + hwCaps_.dwNLVBCaps2 = 0x8062B230; + hwCaps_.dwNLVBCKeyCaps = 0x311; + hwCaps_.dwNLVBFXCaps = 0x22AD5420; + memset(hwCaps_.dwNLVBRops, 0, 0x18); + hwCaps_.dwNLVBRops[6] = 0x1000; + hwCaps_.dwNLVBRops[7] = 0; + hwCaps_.ddsCaps.dwCaps = 0x304672FC; + hwCaps_.ddsCaps.dwCaps2 = 0x200; + hwCaps_.ddsCaps.dwCaps3 = 0; + hwCaps_.ddsCaps.dwCaps4 = 0; + DWORD dwSize = hwCaps->dwSize; + memcpy(hwCaps, &hwCaps_, dwSize); + return DD_OK; +} + +HRESULT FakeDirectDraw4::GetDisplayMode(LPDDSURFACEDESC2) { + gog_debug("Unused function called: FakeDirectDraw4::GetDisplayMode"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw4::GetFourCCCodes(LPDWORD, LPDWORD) { + gog_debug("Unused function called: FakeDirectDraw4::GetFourCCCodes"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw4::GetGDISurface(LPDIRECTDRAWSURFACE4 *) { + gog_debug("Unused function called: FakeDirectDraw4::GetGDISurface"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw4::GetMonitorFrequency(LPDWORD) { + gog_debug("Unused function called: FakeDirectDraw4::GetMonitorFrequency"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw4::GetScanLine(LPDWORD) { + gog_debug("Unused function called: FakeDirectDraw4::GetScanLine"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw4::GetVerticalBlankStatus(LPBOOL) { + gog_debug("Unused function called: FakeDirectDraw4::GetVerticalBlankStatus"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw4::Initialize(GUID *) { + gog_debug("Unused function called: FakeDirectDraw4::Initialize"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw4::RestoreDisplayMode(void) { + gog_debug("Unused function called: FakeDirectDraw4::RestoreDisplayMode"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw4::SetCooperativeLevel(HWND, DWORD) { + gog_debug("Unused function called: FakeDirectDraw4::SetCooperativeLevel"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw4::SetDisplayMode(DWORD, DWORD, DWORD, DWORD, DWORD) { + gog_debug("Unused function called: FakeDirectDraw4::SetDisplayMode"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw4::WaitForVerticalBlank(DWORD, HANDLE) { + gog_debug("Unused function called: FakeDirectDraw4::WaitForVerticalBlank"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw4::GetAvailableVidMem(LPDDSCAPS2, LPDWORD, LPDWORD) { + gog_debug("Unused function called: FakeDirectDraw4::GetAvailableVidMem"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw4::GetSurfaceFromDC(HDC, LPDIRECTDRAWSURFACE4 *) { + gog_debug("Unused function called: FakeDirectDraw4::GetSurfaceFromDC"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw4::RestoreAllSurfaces(void) { + gog_debug("Unused function called: FakeDirectDraw4::RestoreAllSurfaces"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw4::TestCooperativeLevel(void) { + gog_debug("Unused function called: FakeDirectDraw4::TestCooperativeLevel"); + return DDERR_GENERIC; +} + +HRESULT FakeDirectDraw4::GetDeviceIdentifier(LPDDDEVICEIDENTIFIER pDevId, DWORD) { + DDDEVICEIDENTIFIER devId; + if (!pDevId) gog_debug("Assertion failed: FakeDirectDraw4::GetDeviceIdentifier:1126"); + memset(&devId, 0, sizeof(devId)); + devId.guidDeviceIdentifier = IID_IDirectDraw7; + strcpy_s(devId.szDriver, 0x200u, "RandomFakeDriver"); + strcpy_s(devId.szDescription, 0x200u, "DX6 compatibility layer"); + memcpy(pDevId, &devId, sizeof(tagDDDEVICEIDENTIFIER)); + return 0; +} + + diff --git a/src/patches/gog_patch_dll/fake/FakeDirectDraw4.h b/src/patches/gog_patch_dll/fake/FakeDirectDraw4.h new file mode 100644 index 0000000..6d404e9 --- /dev/null +++ b/src/patches/gog_patch_dll/fake/FakeDirectDraw4.h @@ -0,0 +1,54 @@ +// +// Created by DiaLight on 20.01.2023. +// + +#ifndef EMBER_FAKEDIRECTDRAW4_H +#define EMBER_FAKEDIRECTDRAW4_H + +#include +#include + +namespace gog { + + class FakeDirectDraw4 : public FakeUnknown { + + public: + /*** IUnknown methods ***/ + STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR * ppvObj) override; + + /*** IDirectDraw methods ***/ + STDMETHOD(Compact)(THIS) override; + STDMETHOD(CreateClipper)(THIS_ DWORD, LPDIRECTDRAWCLIPPER FAR*, IUnknown FAR * ) override; + STDMETHOD(CreatePalette)(THIS_ DWORD, LPPALETTEENTRY, LPDIRECTDRAWPALETTE FAR*, IUnknown FAR * ) override; + STDMETHOD(CreateSurface)(THIS_ LPDDSURFACEDESC2, LPDIRECTDRAWSURFACE4 FAR *, IUnknown FAR *) override; + STDMETHOD(DuplicateSurface)( THIS_ LPDIRECTDRAWSURFACE4, LPDIRECTDRAWSURFACE4 FAR * ) override; + STDMETHOD(EnumDisplayModes)( THIS_ DWORD, LPDDSURFACEDESC2, LPVOID, LPDDENUMMODESCALLBACK2 ) override; + STDMETHOD(EnumSurfaces)(THIS_ DWORD, LPDDSURFACEDESC2, LPVOID,LPDDENUMSURFACESCALLBACK2 ) override; + STDMETHOD(FlipToGDISurface)(THIS) override; + STDMETHOD(GetCaps)( THIS_ LPDDCAPS, LPDDCAPS) override; + STDMETHOD(GetDisplayMode)( THIS_ LPDDSURFACEDESC2) override; + STDMETHOD(GetFourCCCodes)(THIS_ LPDWORD, LPDWORD ) override; + STDMETHOD(GetGDISurface)(THIS_ LPDIRECTDRAWSURFACE4 FAR *) override; + STDMETHOD(GetMonitorFrequency)(THIS_ LPDWORD) override; + STDMETHOD(GetScanLine)(THIS_ LPDWORD) override; + STDMETHOD(GetVerticalBlankStatus)(THIS_ LPBOOL ) override; + STDMETHOD(Initialize)(THIS_ GUID FAR *) override; + STDMETHOD(RestoreDisplayMode)(THIS) override; + STDMETHOD(SetCooperativeLevel)(THIS_ HWND, DWORD) override; + STDMETHOD(SetDisplayMode)(THIS_ DWORD, DWORD,DWORD, DWORD, DWORD) override; + STDMETHOD(WaitForVerticalBlank)(THIS_ DWORD, HANDLE ) override; + /*** Added in the v2 interface ***/ + STDMETHOD(GetAvailableVidMem)(THIS_ LPDDSCAPS2, LPDWORD, LPDWORD) override; + /*** Added in the V4 Interface ***/ + STDMETHOD(GetSurfaceFromDC) (THIS_ HDC, LPDIRECTDRAWSURFACE4 *) override; + STDMETHOD(RestoreAllSurfaces)(THIS) override; + STDMETHOD(TestCooperativeLevel)(THIS) override; + STDMETHOD(GetDeviceIdentifier)(THIS_ LPDDDEVICEIDENTIFIER, DWORD ) override; + + static FakeDirectDraw4 *instance; + + }; + +} + +#endif //EMBER_FAKEDIRECTDRAW4_H diff --git a/src/patches/gog_patch_dll/fake/FakeGammaControl.cpp b/src/patches/gog_patch_dll/fake/FakeGammaControl.cpp new file mode 100644 index 0000000..18167d9 --- /dev/null +++ b/src/patches/gog_patch_dll/fake/FakeGammaControl.cpp @@ -0,0 +1,23 @@ +// +// Created by DiaLight on 20.01.2023. +// +#include +#include + +using namespace gog; + +FakeGammaControl *FakeGammaControl::instance = nullptr; + +HRESULT FakeGammaControl::QueryInterface(REFIID riid, LPVOID FAR *ppvObj) { + gog_debug("Unused function called: FakeGammaControl::QueryInterface"); + return DDERR_GENERIC; +} + +HRESULT FakeGammaControl::GetGammaRamp(DWORD, LPDDGAMMARAMP) { + gog_debug("Unused function called: FakeGammaControl::GetGammaRamp"); + return DDERR_GENERIC; +} + +HRESULT FakeGammaControl::SetGammaRamp(DWORD, LPDDGAMMARAMP) { + return DD_OK; +} diff --git a/src/patches/gog_patch_dll/fake/FakeGammaControl.h b/src/patches/gog_patch_dll/fake/FakeGammaControl.h new file mode 100644 index 0000000..f22bf08 --- /dev/null +++ b/src/patches/gog_patch_dll/fake/FakeGammaControl.h @@ -0,0 +1,30 @@ +// +// Created by DiaLight on 20.01.2023. +// + +#ifndef EMBER_FAKEGAMMACONTROL_H +#define EMBER_FAKEGAMMACONTROL_H + +#include +#include + +namespace gog { + + class FakeGammaControl : public FakeUnknown { + + public: + + /*** IUnknown methods ***/ + STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR * ppvObj) override; + + /*** IDirectDrawGammaControl methods ***/ + STDMETHOD(GetGammaRamp)(THIS_ DWORD, LPDDGAMMARAMP) override; + STDMETHOD(SetGammaRamp)(THIS_ DWORD, LPDDGAMMARAMP) override; + + static FakeGammaControl *instance; + + }; + +} + +#endif //EMBER_FAKEGAMMACONTROL_H diff --git a/src/patches/gog_patch_dll/fake/FakeSurface.cpp b/src/patches/gog_patch_dll/fake/FakeSurface.cpp new file mode 100644 index 0000000..62a2a16 --- /dev/null +++ b/src/patches/gog_patch_dll/fake/FakeSurface.cpp @@ -0,0 +1,481 @@ +// +// Created by DiaLight on 20.01.2023. +// +#include +#include +#include +#include +#include +#include + +using namespace gog; + +FakeSurface *FakeSurface::instance_mod = nullptr; +FakeSurface *FakeSurface::instance_cpy = nullptr; + +FakeSurface::FakeSurface(IDirectDrawSurface4 *orig_surf) { + this->f84_isModSurf = false; + this->f8C_lockedRect.left = 0; + this->f8C_lockedRect.top = 0; + this->f8C_lockedRect.right = 0; + this->f8C_lockedRect.bottom = 0; + this->f9C_pLockedRect = nullptr; + this->f88_orig_surf = orig_surf; + memset(&this->f8_surfDesc, 0, sizeof(this->f8_surfDesc)); + this->f8_surfDesc.dwSize = 124; + HRESULT hr = this->f88_orig_surf->GetSurfaceDesc(&this->f8_surfDesc); + if (FAILED(hr)) { + gog_debugf("Assertion failed: FakeSurface::FakeSurface:364 with HRESULT 0x%x", hr); + } + this->f88_orig_surf->AddRef(); +} + +FakeSurface::FakeSurface(DDSURFACEDESC2 *desc) { + this->f8C_lockedRect.left = 0; + this->f8C_lockedRect.top = 0; + this->f8C_lockedRect.right = 0; + this->f8C_lockedRect.bottom = 0; + this->f9C_pLockedRect = 0; + DDSURFACEDESC2 descCpy; + memset(&descCpy, 0, sizeof(descCpy)); + memcpy(&descCpy, desc, desc->dwSize); + DWORD dwFlags = descCpy.dwFlags; + descCpy.dwSize = 124; + if ( + (descCpy.dwFlags & 1) != 0 && + (descCpy.ddsCaps.dwCaps & 0x200) != 0 && + (descCpy.dwFlags & 4) == 0 + ) { + if (FakeSurface::instance_mod) { + gog_debug("Assertion failed: FakeSurface::FakeSurface:377"); + dwFlags = descCpy.dwFlags; + } + static_assert(8 == DDSCAPS_COMPLEX); + static_assert(0x10 == DDSCAPS_FLIP); + if ((descCpy.ddsCaps.dwCaps & DDSCAPS_COMPLEX) == 0 || (descCpy.ddsCaps.dwCaps & DDSCAPS_FLIP) == 0) { + gog_debug("Assertion failed: FakeSurface::FakeSurface:379"); + dwFlags = descCpy.dwFlags; + } + DWORD v4 = gog::g_dwWidth; + descCpy.ddsCaps.dwCaps &= 0xFFFFDDE7; + this->f84_isModSurf = true; + if (v4 == 640 && g_isAntialiasGt10) + descCpy.ddsCaps.dwCaps |= 0x840u; + dwFlags = dwFlags ^ 0x20 | 0x1006; + descCpy.dwFlags = dwFlags; + descCpy.dwHeight = g_dwHeight; + descCpy.dwBackBufferCount = 0; + descCpy.dwWidth = v4; + descCpy.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT); + static_assert(sizeof(DDPIXELFORMAT) == 0x20); + descCpy.ddpfPixelFormat.dwFlags = DDPF_RGB; + descCpy.ddpfPixelFormat.dwRGBBitCount = 32; + descCpy.ddpfPixelFormat.dwRBitMask = 0xFF0000; + descCpy.ddpfPixelFormat.dwGBitMask = 0xFF00; + descCpy.ddpfPixelFormat.dwBBitMask = 0xFF; + descCpy.ddpfPixelFormat.dwRGBAlphaBitMask = 0; + descCpy.ddpfPixelFormat.dwFourCC = 0; + FakeSurface::instance_mod = this; + } else { + this->f84_isModSurf = false; + if ((dwFlags & 0x1000) != 0 && descCpy.ddpfPixelFormat.dwFlags != 4) { + gog_debug("Assertion failed: FakeSurface::FakeSurface:413"); + dwFlags = descCpy.dwFlags; + } + } + if ((dwFlags & 0x1000) == 0) { + dwFlags |= 0x1000u; + descCpy.dwFlags = dwFlags; + descCpy.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT); + static_assert(sizeof(DDPIXELFORMAT) == 0x20); + descCpy.ddpfPixelFormat.dwFlags = DDPF_RGB; + descCpy.ddpfPixelFormat.dwRGBBitCount = 32; + descCpy.ddpfPixelFormat.dwRBitMask = 0xFF0000; + descCpy.ddpfPixelFormat.dwGBitMask = 0xFF00; + descCpy.ddpfPixelFormat.dwBBitMask = 0xFF; + descCpy.ddpfPixelFormat.dwRGBAlphaBitMask = 0; + } + if ((dwFlags & 0x40) != 0 || (descCpy.ddsCaps.dwCaps & 0x20000) != 0) gog_debug( + "Assertion failed: FakeSurface::FakeSurface:437"); + memcpy(&this->f8_surfDesc, &descCpy, sizeof(this->f8_surfDesc)); + if (!this->f8_surfDesc.dwWidth) gog_debug("Assertion failed: FakeSurface::FakeSurface:441"); + if (!this->f8_surfDesc.dwHeight) gog_debug("Assertion failed: FakeSurface::FakeSurface:442"); + + static_assert(0x88760064 == DDERR_INVALIDCAPS); + LPDIRECTDRAWSURFACE4 *p_f88_orig_surf = &this->f88_orig_surf; + this->f88_orig_surf = nullptr; + HRESULT v6 = orig::pIDirectDraw4->CreateSurface(&this->f8_surfDesc, &this->f88_orig_surf, NULL); + if (FAILED(v6)) { + gog_debugf("Assertion failed: FakeSurface::FakeSurface:446 with HRESULT 0x%x", v6); + gog_debugf("Width = %d\nHeight = %d\nCaps = 0x%x\npfType = 0x%x", + this->f8_surfDesc.dwWidth, + this->f8_surfDesc.dwHeight, + this->f8_surfDesc.ddsCaps.dwCaps, + this->f8_surfDesc.ddpfPixelFormat.dwFlags); + *p_f88_orig_surf = nullptr; + return; + } + if (!this->f84_isModSurf) return; + if (FakeSurface::instance_cpy) { + gog_debug("Assertion failed: FakeSurface::FakeSurface:456"); + } + orig::pIDirectDrawSurface4_last = *p_f88_orig_surf; + + DDSURFACEDESC2 surfDesc; + memcpy(&surfDesc, &this->f8_surfDesc, sizeof(surfDesc)); + if (!cfg::iAntialias || g_dwWidth > 0x400u) + surfDesc.ddsCaps.dwCaps |= 0x2000u; + IDirectDrawSurface4 *orig_surf; + HRESULT v8 = orig::pIDirectDraw4->CreateSurface(&surfDesc, &orig_surf, NULL); + if (FAILED(v8)) { + gog_debugf("Assertion failed: FakeSurface::FakeSurface:467 with HRESULT 0x%x", v8); + gog_debugf("Width = %d\nHeight = %d\nCaps = 0x%x\npfType = 0x%x", + surfDesc.dwWidth, + surfDesc.dwHeight, + surfDesc.ddsCaps.dwCaps, + surfDesc.ddpfPixelFormat.dwFlags); + this->f88_orig_surf = nullptr; + return; + } + + FakeSurface::instance_cpy = new FakeSurface(orig_surf); + if (cfg::iAntialias && g_dwWidth <= 1024) { + DDSURFACEDESC2 desc3; + memcpy(&desc3, &descCpy, sizeof(desc3)); + desc3.ddsCaps.dwCaps = 24640; + desc3.ddsCaps.dwCaps2 = 0; + if (cfg::iExtraAntialias) { + desc3.ddsCaps.dwCaps2 = 256; + } + desc3.dwHeight *= cfg::iAntialias; + desc3.dwWidth *= cfg::iAntialias; + HRESULT v11 = orig::pIDirectDraw4->CreateSurface( + &desc3, + &orig::pIDirectDrawSurface4_zbuf, + NULL + ); + if (FAILED(v11)) { + gog_debugf("Assertion failed: FakeSurface::FakeSurface:489 with HRESULT 0x%x", v11); + gog_debugf("Width = %d\nHeight = %d\nCaps = 0x%x\npfType = 0x%x", + desc3.dwWidth, + desc3.dwHeight, + desc3.ddsCaps.dwCaps, + desc3.ddpfPixelFormat.dwFlags); + this->f88_orig_surf = nullptr; + return; + } + IDirectDrawSurface4 *ZBuf = (IDirectDrawSurface4 *) Fake_CreateZBuf(g_dwWidth * cfg::iAntialias, + g_dwHeight * cfg::iAntialias); + HRESULT v13 = orig::pIDirectDrawSurface4_zbuf->AddAttachedSurface(ZBuf); + if (FAILED(v13)) { + gog_debugf("Assertion failed: FakeSurface::FakeSurface:500 with HRESULT 0x%x", v13); + } + ZBuf->Release(); + } else { + IDirectDrawSurface4 *ZBuf = (IDirectDrawSurface4 *) Fake_CreateZBuf(g_dwWidth, g_dwHeight); + HRESULT v14 = orig_surf->AddAttachedSurface(ZBuf); + if (FAILED(v14)) { + gog_debugf("Assertion failed: FakeSurface::FakeSurface:504 with HRESULT 0x%x", v14); + } + ZBuf->Release(); + } +} + +HRESULT FakeSurface::QueryInterface(REFIID riid, LPVOID FAR *ppvObj) { + if (IsEqualGUID(IID_IDirectDrawSurface2, riid)) { + *ppvObj = this; + this->AddRef(); + return DD_OK; + } else if (IsEqualGUID(IID_IDirectDrawSurface4, riid)) { + *ppvObj = new FakeSurface4(this->f88_orig_surf, this->f84_isModSurf); + return DD_OK; + } else { + gog_debug("Unused function called: FakeSurface::QueryInterface"); + return DDERR_GENERIC; + } +} + +ULONG FakeSurface::Release(void) { + ULONG v1 = this->refs-- == 1; + ULONG result = this->refs; + if (v1 == 0) return result; + if (this->f84_isModSurf) { + if (FakeSurface::instance_cpy) { + FakeSurface::instance_cpy->Release(); + FakeSurface::instance_cpy = nullptr; + } + if (orig::pIDirectDrawSurface4_zbuf) { + orig::pIDirectDrawSurface4_zbuf->Release(); + orig::pIDirectDrawSurface4_zbuf = nullptr; + } + FakeSurface::instance_mod = nullptr; + } + LPDIRECTDRAWSURFACE4 f88_orig_surf = this->f88_orig_surf; + if (f88_orig_surf) { + f88_orig_surf->Release(); + this->f88_orig_surf = nullptr; + } + operator delete(this); + return 0; +} + +HRESULT FakeSurface::AddAttachedSurface(LPDIRECTDRAWSURFACE2 a2) { + if (!a2) gog_debug("Assertion failed: FakeSurface::AddAttachedSurface:539"); + if (this != FakeSurface::instance_cpy) gog_debug("Assertion failed: FakeSurface::AddAttachedSurface:540"); + return 0; +} + +HRESULT FakeSurface::AddOverlayDirtyRect(LPRECT) { + gog_debug("Unused function called: FakeSurface::AddOverlayDirtyRect"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface::Blt(LPRECT dstRect, LPDIRECTDRAWSURFACE2 srcSurf_, LPRECT srcRect, DWORD flags, LPDDBLTFX bitblt) { + auto *srcSurf = (FakeSurface *) srcSurf_; + HRESULT hr; + if (!orig::pIDirectDrawSurface4_640x480 || !this->f84_isModSurf || !srcSurf) { + IDirectDrawSurface4 *src = nullptr; + if (srcSurf) src = srcSurf->f88_orig_surf; + hr = this->f88_orig_surf->Blt(dstRect, src, srcRect, flags, bitblt); + if (FAILED(hr)) return hr; + if (this->f84_isModSurf) Fake_Redraw(); + return hr; + } + if (srcSurf->f8_surfDesc.ddpfPixelFormat.dwFlags != 4) { + hr = (HRESULT) srcSurf; + if (FAILED(hr)) return hr; + if (this->f84_isModSurf) Fake_Redraw(); + return hr; + } + hr = orig::pIDirectDrawSurface4_640x480->Blt(dstRect, srcSurf->f88_orig_surf, srcRect, flags, bitblt); + if (FAILED(hr)) { + gog_debugf("Assertion failed: FakeSurface::Blt:564 with HRESULT 0x%x", hr); + return hr; + } + hr = this->f88_orig_surf->Blt(NULL, orig::pIDirectDrawSurface4_640x480, NULL, 0x1000000, NULL); + if (FAILED(hr)) { + gog_debugf("Assertion failed: FakeSurface::Blt:567 with HRESULT 0x%x", hr); + return hr; + } + if (this->f84_isModSurf) Fake_Redraw(); + return hr; +} + +HRESULT FakeSurface::BltBatch(LPDDBLTBATCH, DWORD, DWORD) { + gog_debug("Unused function called: FakeSurface::BltBatch"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface::BltFast(DWORD x, DWORD y, LPDIRECTDRAWSURFACE2 srcSurf_, LPRECT srcRect, DWORD type) { + auto *srcSurf = (FakeSurface *) srcSurf_; + IDirectDrawSurface4 *f88_orig_surf; + int hr; + if (gog::g_isSmth_noRef && (this == FakeSurface::instance_mod || this == FakeSurface::instance_cpy)) + return 0; + if (srcSurf) { + f88_orig_surf = srcSurf->f88_orig_surf; + } else { + gog_debug("Assertion failed: FakeSurface::BltFast:580"); + f88_orig_surf = nullptr; + } + hr = this->f88_orig_surf->BltFast(x, y, f88_orig_surf, srcRect, type); + if (FAILED(hr)) return hr; + if (this->f84_isModSurf) Fake_Redraw(); + return hr; +} + +HRESULT FakeSurface::DeleteAttachedSurface(DWORD, LPDIRECTDRAWSURFACE2) { + gog_debug("Unused function called: FakeSurface::DeleteAttachedSurface"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface::EnumAttachedSurfaces(LPVOID, LPDDENUMSURFACESCALLBACK) { + gog_debug("Unused function called: FakeSurface::EnumAttachedSurfaces"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface::EnumOverlayZOrders(DWORD, LPVOID, LPDDENUMSURFACESCALLBACK) { + gog_debug("Unused function called: FakeSurface::EnumOverlayZOrders"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface::Flip(LPDIRECTDRAWSURFACE2 a2, DWORD flags) { + if (!this->f84_isModSurf) gog_debug("Assertion failed: FakeSurface::Flip:606"); + if (!orig::pIDirectDrawSurface4_coop) gog_debug("Assertion failed: FakeSurface::Flip:607"); + if (a2 && a2 != FakeSurface::instance_cpy) gog_debug("Assertion failed: FakeSurface::Flip:608"); + if (gog::g_isSceneDrawing) gog_debug("Assertion failed: FakeSurface::Flip:609"); + if (cfg::iCpuIdle) + Sleep(cfg::iCpuIdle); + this->f88_orig_surf->Blt(NULL, FakeSurface::instance_cpy->f88_orig_surf, NULL, 0x1000000, NULL); + if (cfg::iVwait) { + if (cfg::iVwait == 1) + orig::pIDirectDraw4->WaitForVerticalBlank(1, NULL); + else + orig::pIDirectDraw4->WaitForVerticalBlank(4, NULL); + } + Fake_Redraw(); + gog::g_isFlip = true; + return DD_OK; +} + +HRESULT FakeSurface::GetAttachedSurface(LPDDSCAPS a2, LPDIRECTDRAWSURFACE2 *a3) { + if (!this->f84_isModSurf) gog_debug("Assertion failed: FakeSurface::GetAttachedSurface:635"); + if ((a2->dwCaps & 4) == 0) gog_debug("Assertion failed: FakeSurface::GetAttachedSurface:636"); + *a3 = FakeSurface::instance_cpy; + FakeSurface::instance_cpy->AddRef(); + return DD_OK; +} + +HRESULT FakeSurface::GetBltStatus(DWORD) { + gog_debug("Unused function called: FakeSurface::GetBltStatus"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface::GetCaps(LPDDSCAPS) { + gog_debug("Unused function called: FakeSurface::GetCaps"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface::GetClipper(LPDIRECTDRAWCLIPPER *) { + gog_debug("Unused function called: FakeSurface::GetClipper"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface::GetColorKey(DWORD, LPDDCOLORKEY) { + gog_debug("Unused function called: FakeSurface::GetColorKey"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface::GetDC(HDC *) { + gog_debug("Unused function called: FakeSurface::GetDC"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface::GetFlipStatus(DWORD) { + gog_debug("Unused function called: FakeSurface::GetFlipStatus"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface::GetOverlayPosition(LPLONG, LPLONG) { + gog_debug("Unused function called: FakeSurface::GetOverlayPosition"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface::GetPalette(LPDIRECTDRAWPALETTE *) { + gog_debug("Unused function called: FakeSurface::GetPalette"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface::GetPixelFormat(LPDDPIXELFORMAT a2) { + memcpy(a2, &this->f8_surfDesc.ddpfPixelFormat, sizeof(DDPIXELFORMAT)); + return DD_OK; +} + +HRESULT FakeSurface::GetSurfaceDesc(LPDDSURFACEDESC pDesc) { + DDSURFACEDESC2 desc; + memset(&desc, 0, sizeof(desc)); + desc.dwSize = sizeof(DDSURFACEDESC2); + static_assert(sizeof(DDSURFACEDESC2) == 124); + HRESULT hr = this->f88_orig_surf->GetSurfaceDesc(&desc); + if (FAILED(hr)) return hr; + DWORD dwSize = pDesc->dwSize; + memcpy(pDesc, &desc, pDesc->dwSize); + pDesc->dwSize = dwSize; + return hr; +} + +HRESULT FakeSurface::Initialize(LPDIRECTDRAW, LPDDSURFACEDESC) { + gog_debug("Unused function called: FakeSurface::Initialize"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface::IsLost(void) { + return DD_OK; +} + +HRESULT FakeSurface::Lock(LPRECT pRect, LPDDSURFACEDESC pDesc, DWORD a4, HANDLE a5) { + if (g_isSmth_noRef && (this == FakeSurface::instance_mod || this == FakeSurface::instance_cpy)) + return DDERR_GENERIC; + if (this->f9C_pLockedRect) gog_debug("Assertion failed: FakeSurface::Lock:672"); + DDSURFACEDESC2 desc; + memset(&desc, 0, sizeof(desc)); + desc.dwSize = sizeof(DDSURFACEDESC2); + static_assert(sizeof(DDSURFACEDESC2) == 124); + + HRESULT hr = this->f88_orig_surf->Lock(pRect, &desc, a4, a5); + if (FAILED(hr)) return hr; + + DWORD dwSize = pDesc->dwSize; + memcpy(pDesc, &desc, pDesc->dwSize); + pDesc->dwSize = dwSize; + + if (!pRect) return hr; + this->f8C_lockedRect = *pRect; + this->f9C_pLockedRect = &this->f8C_lockedRect; + return hr; +} + +HRESULT FakeSurface::ReleaseDC(HDC) { + gog_debug("Unused function called: FakeSurface::ReleaseDC"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface::Restore(void) { + return DD_OK; +} + +HRESULT FakeSurface::SetClipper(LPDIRECTDRAWCLIPPER) { + return DD_OK; +} + +HRESULT FakeSurface::SetColorKey(DWORD a2, LPDDCOLORKEY a3) { + return this->f88_orig_surf->SetColorKey(a2, a3); +} + +HRESULT FakeSurface::SetOverlayPosition(LONG, LONG) { + gog_debug("Unused function called: FakeSurface::SetOverlayPosition"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface::SetPalette(LPDIRECTDRAWPALETTE) { + gog_debug("Unused function called: FakeSurface::SetPalette"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface::Unlock(LPVOID) { + HRESULT hr = this->f88_orig_surf->Unlock(this->f9C_pLockedRect); + if (FAILED(hr)) return hr; + if (this->f84_isModSurf) Fake_Redraw(); + return hr; +} + +HRESULT FakeSurface::UpdateOverlay(LPRECT, LPDIRECTDRAWSURFACE2, LPRECT, DWORD, LPDDOVERLAYFX) { + gog_debug("Unused function called: FakeSurface::UpdateOverlay"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface::UpdateOverlayDisplay(DWORD) { + gog_debug("Unused function called: FakeSurface::UpdateOverlayDisplay"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface::UpdateOverlayZOrder(DWORD, LPDIRECTDRAWSURFACE2) { + gog_debug("Unused function called: FakeSurface::UpdateOverlayZOrder"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface::GetDDInterface(LPVOID *) { + gog_debug("Unused function called: FakeSurface::GetDDInterface"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface::PageLock(DWORD) { + gog_debug("Unused function called: FakeSurface::PageLock"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface::PageUnlock(DWORD) { + gog_debug("Unused function called: FakeSurface::PageUnlock"); + return DDERR_GENERIC; +} + diff --git a/src/patches/gog_patch_dll/fake/FakeSurface.h b/src/patches/gog_patch_dll/fake/FakeSurface.h new file mode 100644 index 0000000..bf683b9 --- /dev/null +++ b/src/patches/gog_patch_dll/fake/FakeSurface.h @@ -0,0 +1,76 @@ +// +// Created by DiaLight on 20.01.2023. +// + +#ifndef EMBER_FAKESURFACE_H +#define EMBER_FAKESURFACE_H + +#include +#include +#include + +namespace gog { + + class FakeSurface : public FakeUnknown { + DDSURFACEDESC2 f8_surfDesc; + bool f84_isModSurf; + LPDIRECTDRAWSURFACE4 f88_orig_surf; + RECT f8C_lockedRect; + LPRECT f9C_pLockedRect; + public: + explicit FakeSurface(IDirectDrawSurface4 *orig_surf); + explicit FakeSurface(DDSURFACEDESC2 *desc); + + inline LPDIRECTDRAWSURFACE4 orig() { return f88_orig_surf; } + + /*** IUnknown methods ***/ + STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR * ppvObj) override; + STDMETHOD_(ULONG,Release) (THIS) override; + + /*** IDirectDrawSurface methods ***/ + STDMETHOD(AddAttachedSurface)(THIS_ LPDIRECTDRAWSURFACE2) override; + STDMETHOD(AddOverlayDirtyRect)(THIS_ LPRECT) override; + STDMETHOD(Blt)(THIS_ LPRECT,LPDIRECTDRAWSURFACE2, LPRECT,DWORD, LPDDBLTFX) override; + STDMETHOD(BltBatch)(THIS_ LPDDBLTBATCH, DWORD, DWORD ) override; + STDMETHOD(BltFast)(THIS_ DWORD,DWORD,LPDIRECTDRAWSURFACE2, LPRECT,DWORD) override; + STDMETHOD(DeleteAttachedSurface)(THIS_ DWORD,LPDIRECTDRAWSURFACE2) override; + STDMETHOD(EnumAttachedSurfaces)(THIS_ LPVOID,LPDDENUMSURFACESCALLBACK) override; + STDMETHOD(EnumOverlayZOrders)(THIS_ DWORD,LPVOID,LPDDENUMSURFACESCALLBACK) override; + STDMETHOD(Flip)(THIS_ LPDIRECTDRAWSURFACE2, DWORD) override; + STDMETHOD(GetAttachedSurface)(THIS_ LPDDSCAPS, LPDIRECTDRAWSURFACE2 FAR *) override; + STDMETHOD(GetBltStatus)(THIS_ DWORD) override; + STDMETHOD(GetCaps)(THIS_ LPDDSCAPS) override; + STDMETHOD(GetClipper)(THIS_ LPDIRECTDRAWCLIPPER FAR*) override; + STDMETHOD(GetColorKey)(THIS_ DWORD, LPDDCOLORKEY) override; + STDMETHOD(GetDC)(THIS_ HDC FAR *) override; + STDMETHOD(GetFlipStatus)(THIS_ DWORD) override; + STDMETHOD(GetOverlayPosition)(THIS_ LPLONG, LPLONG ) override; + STDMETHOD(GetPalette)(THIS_ LPDIRECTDRAWPALETTE FAR*) override; + STDMETHOD(GetPixelFormat)(THIS_ LPDDPIXELFORMAT) override; + STDMETHOD(GetSurfaceDesc)(THIS_ LPDDSURFACEDESC) override; + STDMETHOD(Initialize)(THIS_ LPDIRECTDRAW, LPDDSURFACEDESC) override; + STDMETHOD(IsLost)(THIS) override; + STDMETHOD(Lock)(THIS_ LPRECT,LPDDSURFACEDESC,DWORD,HANDLE) override; + STDMETHOD(ReleaseDC)(THIS_ HDC) override; + STDMETHOD(Restore)(THIS) override; + STDMETHOD(SetClipper)(THIS_ LPDIRECTDRAWCLIPPER) override; + STDMETHOD(SetColorKey)(THIS_ DWORD, LPDDCOLORKEY) override; + STDMETHOD(SetOverlayPosition)(THIS_ LONG, LONG ) override; + STDMETHOD(SetPalette)(THIS_ LPDIRECTDRAWPALETTE) override; + STDMETHOD(Unlock)(THIS_ LPVOID) override; + STDMETHOD(UpdateOverlay)(THIS_ LPRECT, LPDIRECTDRAWSURFACE2,LPRECT,DWORD, LPDDOVERLAYFX) override; + STDMETHOD(UpdateOverlayDisplay)(THIS_ DWORD) override; + STDMETHOD(UpdateOverlayZOrder)(THIS_ DWORD, LPDIRECTDRAWSURFACE2) override; + /*** Added in the v2 interface ***/ + STDMETHOD(GetDDInterface)(THIS_ LPVOID FAR *) override; + STDMETHOD(PageLock)(THIS_ DWORD) override; + STDMETHOD(PageUnlock)(THIS_ DWORD) override; + + static FakeSurface *instance_mod; + static FakeSurface *instance_cpy; + }; + static_assert(sizeof(FakeSurface) == 0xA0); + +} + +#endif //EMBER_FAKESURFACE_H diff --git a/src/patches/gog_patch_dll/fake/FakeSurface4.cpp b/src/patches/gog_patch_dll/fake/FakeSurface4.cpp new file mode 100644 index 0000000..8446b00 --- /dev/null +++ b/src/patches/gog_patch_dll/fake/FakeSurface4.cpp @@ -0,0 +1,317 @@ +// +// Created by DiaLight on 20.01.2023. +// +#include +#include +#include +#include +#include +#include + +using namespace gog; + + +FakeSurface4::FakeSurface4(LPDIRECTDRAWSURFACE4 orig_surf, bool isModSurf) { + this->f8_orig_surf = orig_surf; + orig_surf->AddRef(); + this->fC_isModSurf = isModSurf; + this->f10_lockCounter = 0; + memset(&this->f14_desc, 0, sizeof(this->f14_desc)); + this->f14_desc.dwSize = sizeof(DDSURFACEDESC2); + static_assert(sizeof(DDSURFACEDESC2) == 124); + HRESULT hr = this->f8_orig_surf->GetSurfaceDesc(&this->f14_desc); + if (FAILED(hr)) gog_debug("Assertion failed: FakeSurface4::FakeSurface4:200"); +} + +FakeSurface4::FakeSurface4(LPDDSURFACEDESC2 pDesc) { + static_assert(sizeof(DDSURFACEDESC2) == 0x7C); + DDSURFACEDESC2 desc; + memcpy(&desc, pDesc, sizeof(desc)); + DWORD dwFlags = desc.dwFlags; + if ((desc.dwFlags & 1) != 0 && (desc.ddsCaps.dwCaps & 0x200) != 0 && (desc.dwFlags & 4) == 0) { + gog_debug("Assertion failed: FakeSurface4::FakeSurface4:207"); + } else { + this->fC_isModSurf = false; + if ((dwFlags & 0x1000) == 0) gog_debug("Assertion failed: FakeSurface4::FakeSurface4:210"); + if (desc.ddpfPixelFormat.dwRGBBitCount != 32) gog_debug("Assertion failed: FakeSurface4::FakeSurface4:211"); + } + memcpy(&this->f14_desc, &desc, sizeof(this->f14_desc)); + if ((this->f14_desc.ddsCaps.dwCaps & 0x30000000) != 0) gog_debug( + "Assertion failed: FakeSurface4::FakeSurface4:216"); + if ((this->f14_desc.ddsCaps.dwCaps & 0x1000) == 0) gog_debug("Assertion failed: FakeSurface4::FakeSurface4:217"); + if ((this->f14_desc.dwFlags & 0x40) != 0) gog_debug("Assertion failed: FakeSurface4::FakeSurface4:218"); + if (!this->f14_desc.dwWidth) gog_debug("Assertion failed: FakeSurface4::FakeSurface4:219"); + if (!this->f14_desc.dwHeight) gog_debug("Assertion failed: FakeSurface4::FakeSurface4:220"); + HRESULT hr = orig::pIDirectDraw4->CreateSurface(&this->f14_desc, &this->f8_orig_surf, NULL); + if (FAILED(hr)) { + gog_debugf("Assertion failed: FakeSurface4::FakeSurface4:227 with HRESULT 0x%x", hr); + if (hr == DDERR_INVALIDCAPS) { + } + this->f8_orig_surf = nullptr; + __debugbreak(); + } +} + +HRESULT FakeSurface4::QueryInterface(REFIID riid, LPVOID FAR *ppvObj) { + if (IsEqualGUID(IID_IDirectDrawGammaControl, riid)) { + *ppvObj = FakeGammaControl::instance; + return DD_OK; + } + if (IsEqualGUID(IID_IDirect3DTexture2, riid)) { + IDirect3DTexture2 *orig_tex; + HRESULT hr = this->f8_orig_surf->QueryInterface(IID_IDirect3DTexture2, (LPVOID *) &orig_tex); + if (SUCCEEDED(hr)) { + *ppvObj = new FakeTexture(orig_tex); + } + return hr; + } + gog_debug("Unused function called: FakeSurface4::QueryInterface"); + return DDERR_GENERIC; +} + +ULONG FakeSurface4::Release(void) { + if (--this->refs != 0) + return this->refs; + if (this->f8_orig_surf) { + this->f8_orig_surf->Release(); + this->f8_orig_surf = nullptr; + } + operator delete(this); + return 0; +} + +HRESULT FakeSurface4::AddAttachedSurface(LPDIRECTDRAWSURFACE4) { + gog_debug("Unused function called: FakeSurface4::AddAttachedSurface"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::AddOverlayDirtyRect(LPRECT) { + gog_debug("Unused function called: FakeSurface4::AddOverlayDirtyRect"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::Blt(LPRECT, LPDIRECTDRAWSURFACE4, LPRECT, DWORD, LPDDBLTFX) { + gog_debug("Unused function called: FakeSurface4::Blt"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::BltBatch(LPDDBLTBATCH, DWORD, DWORD) { + gog_debug("Unused function called: FakeSurface4::BltBatch"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::BltFast(DWORD x, DWORD y, LPDIRECTDRAWSURFACE4 srcSurf_, LPRECT srcRect, DWORD a6) { + auto *srcSurf = (FakeSurface4 *) srcSurf_; + if (!srcSurf) gog_debug("Assertion failed: FakeSurface4::BltFast:264"); + if (this->fC_isModSurf) gog_debug("Assertion failed: FakeSurface4::BltFast:265"); + IDirectDrawSurface4 *srcSurf_1 = nullptr; + if (srcSurf) srcSurf_1 = srcSurf->f8_orig_surf; + HRESULT hr; + hr = this->f8_orig_surf->BltFast(x, y, srcSurf_1, srcRect, a6); + if (FAILED(hr)) { + gog_debugf("Assertion failed: FakeSurface4::BltFast:282 with HRESULT 0x%x", hr); + return hr; + } + if (!this->fC_isModSurf) return hr; + if (!orig::pIDirectDrawSurface4_coop) { + gog_debug("Assertion failed: FakeSurface4::BltFast:285"); + } + orig::pIDirectDrawSurface4_coop->Blt(&g_renderRect, this->f8_orig_surf, NULL, 0x1000000, NULL); + return hr; +} + +HRESULT FakeSurface4::DeleteAttachedSurface(DWORD, LPDIRECTDRAWSURFACE4) { + gog_debug("Unused function called: FakeSurface4::DeleteAttachedSurface"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::EnumAttachedSurfaces(LPVOID, LPDDENUMSURFACESCALLBACK2) { + gog_debug("Unused function called: FakeSurface4::EnumAttachedSurfaces"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::EnumOverlayZOrders(DWORD, LPVOID, LPDDENUMSURFACESCALLBACK2) { + gog_debug("Unused function called: FakeSurface4::EnumOverlayZOrders"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::Flip(LPDIRECTDRAWSURFACE4, DWORD) { + gog_debug("Unused function called: FakeSurface4::Flip"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::GetAttachedSurface(LPDDSCAPS2, LPDIRECTDRAWSURFACE4 *) { + gog_debug("Unused function called: FakeSurface4::GetAttachedSurface"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::GetBltStatus(DWORD) { + gog_debug("Unused function called: FakeSurface4::GetBltStatus"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::GetCaps(LPDDSCAPS2) { + gog_debug("Unused function called: FakeSurface4::GetCaps"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::GetClipper(LPDIRECTDRAWCLIPPER *) { + gog_debug("Unused function called: FakeSurface4::GetClipper"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::GetColorKey(DWORD, LPDDCOLORKEY) { + gog_debug("Unused function called: FakeSurface4::GetColorKey"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::GetDC(HDC *) { + gog_debug("Unused function called: FakeSurface4::GetDC"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::GetFlipStatus(DWORD) { + gog_debug("Unused function called: FakeSurface4::GetFlipStatus"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::GetOverlayPosition(LPLONG, LPLONG) { + gog_debug("Unused function called: FakeSurface4::GetOverlayPosition"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::GetPalette(LPDIRECTDRAWPALETTE *) { + gog_debug("Unused function called: FakeSurface4::GetPalette"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::GetPixelFormat(LPDDPIXELFORMAT) { + gog_debug("Unused function called: FakeSurface4::GetPixelFormat"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::GetSurfaceDesc(LPDDSURFACEDESC2) { + gog_debug("Unused function called: FakeSurface4::GetSurfaceDesc"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::Initialize(LPDIRECTDRAW, LPDDSURFACEDESC2) { + gog_debug("Unused function called: FakeSurface4::Initialize"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::IsLost(void) { + return DD_OK; +} + +HRESULT FakeSurface4::Lock(LPRECT pRect, LPDDSURFACEDESC2 surf, DWORD a4, HANDLE a5) { + HRESULT hr = this->f8_orig_surf->Lock(pRect, surf, a4, a5); + if (FAILED(hr)) { + gog_debugf("Assertion failed: FakeSurface4::Lock:309 with HRESULT 0x%x", hr); + return hr; + } + ++this->f10_lockCounter; + return hr; +} + +HRESULT FakeSurface4::ReleaseDC(HDC) { + gog_debug("Unused function called: FakeSurface4::ReleaseDC"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::Restore(void) { + return DD_OK; +} + +HRESULT FakeSurface4::SetClipper(LPDIRECTDRAWCLIPPER) { + gog_debug("Unused function called: FakeSurface4::SetClipper"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::SetColorKey(DWORD, LPDDCOLORKEY) { + gog_debug("Unused function called: FakeSurface4::SetColorKey"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::SetOverlayPosition(LONG, LONG) { + gog_debug("Unused function called: FakeSurface4::SetOverlayPosition"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::SetPalette(LPDIRECTDRAWPALETTE) { + gog_debug("Unused function called: FakeSurface4::SetPalette"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::Unlock(LPRECT pRect) { + HRESULT hr = this->f8_orig_surf->Unlock(pRect); + if (FAILED(hr)) { + gog_debugf("Assertion failed: FakeSurface4::Unlock:322 with HRESULT 0x%x", hr); + return hr; + } + --this->f10_lockCounter; + if (this->fC_isModSurf) { + if (!this->f10_lockCounter) Fake_Redraw(); + } + return hr; +} + +HRESULT FakeSurface4::UpdateOverlay(LPRECT, LPDIRECTDRAWSURFACE4, LPRECT, DWORD, LPDDOVERLAYFX) { + gog_debug("Unused function called: FakeSurface4::UpdateOverlay"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::UpdateOverlayDisplay(DWORD) { + gog_debug("Unused function called: FakeSurface4::UpdateOverlayDisplay"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::UpdateOverlayZOrder(DWORD, LPDIRECTDRAWSURFACE4) { + gog_debug("Unused function called: FakeSurface4::UpdateOverlayZOrder"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::GetDDInterface(LPVOID *) { + gog_debug("Unused function called: FakeSurface4::GetDDInterface"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::PageLock(DWORD) { + gog_debug("Unused function called: FakeSurface4::PageLock"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::PageUnlock(DWORD) { + gog_debug("Unused function called: FakeSurface4::PageUnlock"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::SetSurfaceDesc(LPDDSURFACEDESC2, DWORD) { + gog_debug("Unused function called: FakeSurface4::SetSurfaceDesc"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::SetPrivateData(REFGUID, LPVOID, DWORD, DWORD) { + gog_debug("Unused function called: FakeSurface4::SetPrivateData"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::GetPrivateData(REFGUID, LPVOID, LPDWORD) { + gog_debug("Unused function called: FakeSurface4::GetPrivateData"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::FreePrivateData(REFGUID) { + gog_debug("Unused function called: FakeSurface4::FreePrivateData"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::GetUniquenessValue(LPDWORD) { + gog_debug("Unused function called: FakeSurface4::GetUniquenessValue"); + return DDERR_GENERIC; +} + +HRESULT FakeSurface4::ChangeUniquenessValue(void) { + gog_debug("Unused function called: FakeSurface4::ChangeUniquenessValue"); + return DDERR_GENERIC; +} diff --git a/src/patches/gog_patch_dll/fake/FakeSurface4.h b/src/patches/gog_patch_dll/fake/FakeSurface4.h new file mode 100644 index 0000000..8974adf --- /dev/null +++ b/src/patches/gog_patch_dll/fake/FakeSurface4.h @@ -0,0 +1,81 @@ +// +// Created by DiaLight on 20.01.2023. +// + +#ifndef EMBER_FAKESURFACE4_H +#define EMBER_FAKESURFACE4_H + +#include +#include + +namespace gog { + + class FakeSurface4 : public FakeUnknown { + LPDIRECTDRAWSURFACE4 f8_orig_surf; + bool fC_isModSurf; + ULONG f10_lockCounter; + DDSURFACEDESC2 f14_desc; + public: + FakeSurface4(LPDIRECTDRAWSURFACE4 orig_surf, bool isModSurf); + explicit FakeSurface4(LPDDSURFACEDESC2 pDesc); + + inline LPDIRECTDRAWSURFACE4 orig() { return f8_orig_surf; } + + /*** IUnknown methods ***/ + STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR * ppvObj) override; + STDMETHOD_(ULONG,Release) (THIS) override; + + /*** IDirectDrawSurface methods ***/ + STDMETHOD(AddAttachedSurface)(THIS_ LPDIRECTDRAWSURFACE4) override; + STDMETHOD(AddOverlayDirtyRect)(THIS_ LPRECT) override; + STDMETHOD(Blt)(THIS_ LPRECT,LPDIRECTDRAWSURFACE4, LPRECT,DWORD, LPDDBLTFX) override; + STDMETHOD(BltBatch)(THIS_ LPDDBLTBATCH, DWORD, DWORD ) override; + STDMETHOD(BltFast)(THIS_ DWORD,DWORD,LPDIRECTDRAWSURFACE4, LPRECT,DWORD) override; + STDMETHOD(DeleteAttachedSurface)(THIS_ DWORD,LPDIRECTDRAWSURFACE4) override; + STDMETHOD(EnumAttachedSurfaces)(THIS_ LPVOID,LPDDENUMSURFACESCALLBACK2) override; + STDMETHOD(EnumOverlayZOrders)(THIS_ DWORD,LPVOID,LPDDENUMSURFACESCALLBACK2) override; + STDMETHOD(Flip)(THIS_ LPDIRECTDRAWSURFACE4, DWORD) override; + STDMETHOD(GetAttachedSurface)(THIS_ LPDDSCAPS2, LPDIRECTDRAWSURFACE4 FAR *) override; + STDMETHOD(GetBltStatus)(THIS_ DWORD) override; + STDMETHOD(GetCaps)(THIS_ LPDDSCAPS2) override; + STDMETHOD(GetClipper)(THIS_ LPDIRECTDRAWCLIPPER FAR*) override; + STDMETHOD(GetColorKey)(THIS_ DWORD, LPDDCOLORKEY) override; + STDMETHOD(GetDC)(THIS_ HDC FAR *) override; + STDMETHOD(GetFlipStatus)(THIS_ DWORD) override; + STDMETHOD(GetOverlayPosition)(THIS_ LPLONG, LPLONG ) override; + STDMETHOD(GetPalette)(THIS_ LPDIRECTDRAWPALETTE FAR*) override; + STDMETHOD(GetPixelFormat)(THIS_ LPDDPIXELFORMAT) override; + STDMETHOD(GetSurfaceDesc)(THIS_ LPDDSURFACEDESC2) override; + STDMETHOD(Initialize)(THIS_ LPDIRECTDRAW, LPDDSURFACEDESC2) override; + STDMETHOD(IsLost)(THIS) override; + STDMETHOD(Lock)(THIS_ LPRECT,LPDDSURFACEDESC2,DWORD,HANDLE) override; + STDMETHOD(ReleaseDC)(THIS_ HDC) override; + STDMETHOD(Restore)(THIS) override; + STDMETHOD(SetClipper)(THIS_ LPDIRECTDRAWCLIPPER) override; + STDMETHOD(SetColorKey)(THIS_ DWORD, LPDDCOLORKEY) override; + STDMETHOD(SetOverlayPosition)(THIS_ LONG, LONG ) override; + STDMETHOD(SetPalette)(THIS_ LPDIRECTDRAWPALETTE) override; + STDMETHOD(Unlock)(THIS_ LPRECT) override; + STDMETHOD(UpdateOverlay)(THIS_ LPRECT, LPDIRECTDRAWSURFACE4,LPRECT,DWORD, LPDDOVERLAYFX) override; + STDMETHOD(UpdateOverlayDisplay)(THIS_ DWORD) override; + STDMETHOD(UpdateOverlayZOrder)(THIS_ DWORD, LPDIRECTDRAWSURFACE4) override; + /*** Added in the v2 interface ***/ + STDMETHOD(GetDDInterface)(THIS_ LPVOID FAR *) override; + STDMETHOD(PageLock)(THIS_ DWORD) override; + STDMETHOD(PageUnlock)(THIS_ DWORD) override; + /*** Added in the v3 interface ***/ + STDMETHOD(SetSurfaceDesc)(THIS_ LPDDSURFACEDESC2, DWORD) override; + /*** Added in the v4 interface ***/ + STDMETHOD(SetPrivateData)(THIS_ REFGUID, LPVOID, DWORD, DWORD) override; + STDMETHOD(GetPrivateData)(THIS_ REFGUID, LPVOID, LPDWORD) override; + STDMETHOD(FreePrivateData)(THIS_ REFGUID) override; + STDMETHOD(GetUniquenessValue)(THIS_ LPDWORD) override; + STDMETHOD(ChangeUniquenessValue)(THIS) override; + + }; + + static_assert(sizeof(FakeSurface4) == 0x90); + +} + +#endif //EMBER_FAKESURFACE4_H diff --git a/src/patches/gog_patch_dll/fake/FakeTexture.cpp b/src/patches/gog_patch_dll/fake/FakeTexture.cpp new file mode 100644 index 0000000..9bfe01c --- /dev/null +++ b/src/patches/gog_patch_dll/fake/FakeTexture.cpp @@ -0,0 +1,42 @@ +// +// Created by DiaLight on 20.01.2023. +// +#include +#include + +using namespace gog; + +FakeTexture::FakeTexture(IDirect3DTexture2 *orig_tex) : f8_orig_tex(orig_tex) {} + +HRESULT FakeTexture::QueryInterface(const IID &riid, LPVOID *ppvObj) { + gog_debug("Unused function called: FakeTexture::QueryInterface"); + return DDERR_GENERIC; +} + +ULONG FakeTexture::Release(void) { + if (--this->refs != 0) + return this->refs; + if (this->f8_orig_tex) { + this->f8_orig_tex->Release(); + this->f8_orig_tex = nullptr; + } + operator delete(this); + return 0; +} + +HRESULT FakeTexture::GetHandle(LPDIRECT3DDEVICE2, LPD3DTEXTUREHANDLE) { + gog_debug("Unused function called: FakeTexture::GetHandle"); + return DDERR_GENERIC; +} + +HRESULT FakeTexture::PaletteChanged(DWORD, DWORD) { + gog_debug("Unused function called: FakeTexture::PaletteChanged"); + return DDERR_GENERIC; +} + +HRESULT FakeTexture::Load(LPDIRECT3DTEXTURE2) { + gog_debug("Unused function called: FakeTexture::Load"); + return DDERR_GENERIC; +} + + diff --git a/src/patches/gog_patch_dll/fake/FakeTexture.h b/src/patches/gog_patch_dll/fake/FakeTexture.h new file mode 100644 index 0000000..68c104a --- /dev/null +++ b/src/patches/gog_patch_dll/fake/FakeTexture.h @@ -0,0 +1,34 @@ +// +// Created by DiaLight on 20.01.2023. +// + +#ifndef EMBER_FAKETEXTURE_H +#define EMBER_FAKETEXTURE_H + +#include +#include + +namespace gog { + + class FakeTexture : public FakeUnknown { + IDirect3DTexture2 *f8_orig_tex; + public: + explicit FakeTexture(IDirect3DTexture2 *orig_tex); + + inline IDirect3DTexture2 *orig() { return f8_orig_tex; } + + /*** IUnknown methods ***/ + STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) override; + STDMETHOD_(ULONG,Release)(THIS) override; + + /*** IDirect3DTexture2 methods ***/ + STDMETHOD(GetHandle)(THIS_ LPDIRECT3DDEVICE2,LPD3DTEXTUREHANDLE) override; + STDMETHOD(PaletteChanged)(THIS_ DWORD,DWORD) override; + STDMETHOD(Load)(THIS_ LPDIRECT3DTEXTURE2) override; + }; + + static_assert(sizeof(FakeTexture) == 0xC); + +} + +#endif //EMBER_FAKETEXTURE_H diff --git a/src/patches/gog_patch_dll/fake/FakeUnknown.cpp b/src/patches/gog_patch_dll/fake/FakeUnknown.cpp new file mode 100644 index 0000000..dfd2cc6 --- /dev/null +++ b/src/patches/gog_patch_dll/fake/FakeUnknown.cpp @@ -0,0 +1,7 @@ +// +// Created by DiaLight on 21.01.2023. +// +#include + +using namespace gog; + diff --git a/src/patches/gog_patch_dll/fake/FakeUnknown.h b/src/patches/gog_patch_dll/fake/FakeUnknown.h new file mode 100644 index 0000000..3c5c78f --- /dev/null +++ b/src/patches/gog_patch_dll/fake/FakeUnknown.h @@ -0,0 +1,36 @@ +// +// Created by DiaLight on 21.01.2023. +// + +#ifndef EMBER_FAKEUNKNOWN_H +#define EMBER_FAKEUNKNOWN_H + + +#include + +namespace gog { + + template + class FakeUnknown : public Base { + + protected: + ULONG refs; + public: + FakeUnknown() : refs(1) {}; + + /*** IUnknown methods ***/ + STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR * ppvObj) PURE; + + STDMETHOD_(ULONG,AddRef) (THIS) override { + return ++refs; + } + STDMETHOD_(ULONG,Release) (THIS) override { + if (refs == 0) return 0; + return --refs; + } + + }; + +} + +#endif //EMBER_FAKEUNKNOWN_H diff --git a/src/patches/gog_patch_dll/fake/FakeViewport3.cpp b/src/patches/gog_patch_dll/fake/FakeViewport3.cpp new file mode 100644 index 0000000..4678c52 --- /dev/null +++ b/src/patches/gog_patch_dll/fake/FakeViewport3.cpp @@ -0,0 +1,103 @@ +// +// Created by DiaLight on 20.01.2023. +// +#include +#include + +using namespace gog; + +FakeViewport3 *FakeViewport3::instance = nullptr; + +HRESULT FakeViewport3::QueryInterface(REFIID riid, LPVOID FAR *ppvObj) { + gog_debug("Unused function called: FakeViewport3::QueryInterface"); + return DDERR_GENERIC; +} + +HRESULT FakeViewport3::Initialize(LPDIRECT3D) { + gog_debug("Unused function called: FakeViewport3::Initialize"); + return DDERR_GENERIC; +} + +HRESULT FakeViewport3::GetViewport(LPD3DVIEWPORT) { + gog_debug("Unused function called: FakeViewport3::GetViewport"); + return DDERR_GENERIC; +} + +HRESULT FakeViewport3::SetViewport(LPD3DVIEWPORT) { + gog_debug("Unused function called: FakeViewport3::SetViewport"); + return DDERR_GENERIC; +} + +HRESULT FakeViewport3::TransformVertices(DWORD, LPD3DTRANSFORMDATA, DWORD, LPDWORD) { + gog_debug("Unused function called: FakeViewport3::TransformVertices"); + return DDERR_GENERIC; +} + +HRESULT FakeViewport3::LightElements(DWORD, LPD3DLIGHTDATA) { + gog_debug("Unused function called: FakeViewport3::LightElements"); + return DDERR_GENERIC; +} + +HRESULT FakeViewport3::SetBackground(D3DMATERIALHANDLE) { + gog_debug("Unused function called: FakeViewport3::SetBackground"); + return DDERR_GENERIC; +} + +HRESULT FakeViewport3::GetBackground(LPD3DMATERIALHANDLE, LPBOOL) { + gog_debug("Unused function called: FakeViewport3::GetBackground"); + return DDERR_GENERIC; +} + +HRESULT FakeViewport3::SetBackgroundDepth(LPDIRECTDRAWSURFACE) { + gog_debug("Unused function called: FakeViewport3::SetBackgroundDepth"); + return DDERR_GENERIC; +} + +HRESULT FakeViewport3::GetBackgroundDepth(LPDIRECTDRAWSURFACE *, LPBOOL) { + gog_debug("Unused function called: FakeViewport3::GetBackgroundDepth"); + return DDERR_GENERIC; +} + +HRESULT FakeViewport3::Clear(DWORD, LPD3DRECT, DWORD) { + gog_debug("Unused function called: FakeViewport3::Clear"); + return DDERR_GENERIC; +} + +HRESULT FakeViewport3::AddLight(LPDIRECT3DLIGHT) { + gog_debug("Unused function called: FakeViewport3::AddLight"); + return DDERR_GENERIC; +} + +HRESULT FakeViewport3::DeleteLight(LPDIRECT3DLIGHT) { + gog_debug("Unused function called: FakeViewport3::DeleteLight"); + return DDERR_GENERIC; +} + +HRESULT FakeViewport3::NextLight(LPDIRECT3DLIGHT, LPDIRECT3DLIGHT *, DWORD) { + gog_debug("Unused function called: FakeViewport3::NextLight"); + return DDERR_GENERIC; +} + +HRESULT FakeViewport3::GetViewport2(LPD3DVIEWPORT2) { + gog_debug("Unused function called: FakeViewport3::GetViewport2"); + return DDERR_GENERIC; +} + +HRESULT FakeViewport3::SetViewport2(LPD3DVIEWPORT2) { + return DD_OK; +} + +HRESULT FakeViewport3::SetBackgroundDepth2(LPDIRECTDRAWSURFACE4) { + gog_debug("Unused function called: FakeViewport3::SetBackgroundDepth2"); + return DDERR_GENERIC; +} + +HRESULT FakeViewport3::GetBackgroundDepth2(LPDIRECTDRAWSURFACE4 *, LPBOOL) { + gog_debug("Unused function called: FakeViewport3::GetBackgroundDepth2"); + return DDERR_GENERIC; +} + +HRESULT FakeViewport3::Clear2(DWORD, LPD3DRECT, DWORD, D3DCOLOR, D3DVALUE, DWORD) { + gog_debug("Unused function called: FakeViewport3::Clear2"); + return DDERR_GENERIC; +} diff --git a/src/patches/gog_patch_dll/fake/FakeViewport3.h b/src/patches/gog_patch_dll/fake/FakeViewport3.h new file mode 100644 index 0000000..f0e9d3f --- /dev/null +++ b/src/patches/gog_patch_dll/fake/FakeViewport3.h @@ -0,0 +1,45 @@ +// +// Created by DiaLight on 20.01.2023. +// + +#ifndef EMBER_FAKEVIEWPORT3_H +#define EMBER_FAKEVIEWPORT3_H + +#include +#include + +namespace gog { + + class FakeViewport3 : public FakeUnknown { + + public: + /*** IUnknown methods ***/ + STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) override; + + /*** IDirect3DViewport2 methods ***/ + STDMETHOD(Initialize)(THIS_ LPDIRECT3D) override; + STDMETHOD(GetViewport)(THIS_ LPD3DVIEWPORT) override; + STDMETHOD(SetViewport)(THIS_ LPD3DVIEWPORT) override; + STDMETHOD(TransformVertices)(THIS_ DWORD,LPD3DTRANSFORMDATA,DWORD,LPDWORD) override; + STDMETHOD(LightElements)(THIS_ DWORD,LPD3DLIGHTDATA) override; + STDMETHOD(SetBackground)(THIS_ D3DMATERIALHANDLE) override; + STDMETHOD(GetBackground)(THIS_ LPD3DMATERIALHANDLE,LPBOOL) override; + STDMETHOD(SetBackgroundDepth)(THIS_ LPDIRECTDRAWSURFACE) override; + STDMETHOD(GetBackgroundDepth)(THIS_ LPDIRECTDRAWSURFACE*,LPBOOL) override; + STDMETHOD(Clear)(THIS_ DWORD,LPD3DRECT,DWORD) override; + STDMETHOD(AddLight)(THIS_ LPDIRECT3DLIGHT) override; + STDMETHOD(DeleteLight)(THIS_ LPDIRECT3DLIGHT) override; + STDMETHOD(NextLight)(THIS_ LPDIRECT3DLIGHT,LPDIRECT3DLIGHT*,DWORD) override; + STDMETHOD(GetViewport2)(THIS_ LPD3DVIEWPORT2) override; + STDMETHOD(SetViewport2)(THIS_ LPD3DVIEWPORT2) override; + STDMETHOD(SetBackgroundDepth2)(THIS_ LPDIRECTDRAWSURFACE4) override; + STDMETHOD(GetBackgroundDepth2)(THIS_ LPDIRECTDRAWSURFACE4*,LPBOOL) override; + STDMETHOD(Clear2)(THIS_ DWORD,LPD3DRECT,DWORD,D3DCOLOR,D3DVALUE,DWORD) override; + + static FakeViewport3 *instance; + + }; + +} + +#endif //EMBER_FAKEVIEWPORT3_H diff --git a/src/patches/gog_patch_dll/fake/FakeZBuffer.cpp b/src/patches/gog_patch_dll/fake/FakeZBuffer.cpp new file mode 100644 index 0000000..58fd45d --- /dev/null +++ b/src/patches/gog_patch_dll/fake/FakeZBuffer.cpp @@ -0,0 +1,178 @@ +// +// Created by DiaLight on 20.01.2023. +// +#include +#include + +using namespace gog; + + +FakeZBuffer *FakeZBuffer::instance = nullptr; + +HRESULT FakeZBuffer::QueryInterface(REFIID riid, LPVOID FAR *ppvObj) { + gog_debug("Unused function called: FakeZBuffer::QueryInterface"); + return DDERR_GENERIC; +} + +HRESULT FakeZBuffer::AddAttachedSurface(LPDIRECTDRAWSURFACE) { + gog_debug("Unused function called: FakeZBuffer::AddAttachedSurface"); + return DDERR_GENERIC; +} + +HRESULT FakeZBuffer::AddOverlayDirtyRect(LPRECT) { + gog_debug("Unused function called: FakeZBuffer::AddOverlayDirtyRect"); + return DDERR_GENERIC; +} + +HRESULT FakeZBuffer::Blt(LPRECT, LPDIRECTDRAWSURFACE a3, LPRECT, DWORD, LPDDBLTFX) { + if (a3) gog_debug("Assertion failed: FakeZBuffer::Blt:24"); + return DD_OK; +} + +HRESULT FakeZBuffer::BltBatch(LPDDBLTBATCH, DWORD, DWORD) { + gog_debug("Unused function called: FakeZBuffer::BltBatch"); + return DDERR_GENERIC; +} + +HRESULT FakeZBuffer::BltFast(DWORD, DWORD, LPDIRECTDRAWSURFACE, LPRECT, DWORD) { + gog_debug("Unused function called: FakeZBuffer::BltFast"); + return DDERR_GENERIC; +} + +HRESULT FakeZBuffer::DeleteAttachedSurface(DWORD, LPDIRECTDRAWSURFACE) { + gog_debug("Unused function called: FakeZBuffer::DeleteAttachedSurface"); + return DDERR_GENERIC; +} + +HRESULT FakeZBuffer::EnumAttachedSurfaces(LPVOID, LPDDENUMSURFACESCALLBACK) { + gog_debug("Unused function called: FakeZBuffer::EnumAttachedSurfaces"); + return DDERR_GENERIC; +} + +HRESULT FakeZBuffer::EnumOverlayZOrders(DWORD, LPVOID, LPDDENUMSURFACESCALLBACK) { + gog_debug("Unused function called: FakeZBuffer::EnumOverlayZOrders"); + return DDERR_GENERIC; +} + +HRESULT FakeZBuffer::Flip(LPDIRECTDRAWSURFACE, DWORD) { + gog_debug("Unused function called: FakeZBuffer::Flip"); + return DDERR_GENERIC; +} + +HRESULT FakeZBuffer::GetAttachedSurface(LPDDSCAPS, LPDIRECTDRAWSURFACE *) { + gog_debug("Unused function called: FakeZBuffer::GetAttachedSurface"); + return DDERR_GENERIC; +} + +HRESULT FakeZBuffer::GetBltStatus(DWORD) { + gog_debug("Unused function called: FakeZBuffer::GetBltStatus"); + return DDERR_GENERIC; +} + +HRESULT FakeZBuffer::GetCaps(LPDDSCAPS) { + gog_debug("Unused function called: FakeZBuffer::GetCaps"); + return DDERR_GENERIC; +} + +HRESULT FakeZBuffer::GetClipper(LPDIRECTDRAWCLIPPER *) { + gog_debug("Unused function called: FakeZBuffer::GetClipper"); + return DDERR_GENERIC; +} + +HRESULT FakeZBuffer::GetColorKey(DWORD, LPDDCOLORKEY) { + gog_debug("Unused function called: FakeZBuffer::GetColorKey"); + return DDERR_GENERIC; +} + +HRESULT FakeZBuffer::GetDC(HDC *) { + gog_debug("Unused function called: FakeZBuffer::GetDC"); + return DDERR_GENERIC; +} + +HRESULT FakeZBuffer::GetFlipStatus(DWORD) { + gog_debug("Unused function called: FakeZBuffer::GetFlipStatus"); + return DDERR_GENERIC; +} + +HRESULT FakeZBuffer::GetOverlayPosition(LPLONG, LPLONG) { + gog_debug("Unused function called: FakeZBuffer::GetOverlayPosition"); + return DDERR_GENERIC; +} + +HRESULT FakeZBuffer::GetPalette(LPDIRECTDRAWPALETTE *) { + gog_debug("Unused function called: FakeZBuffer::GetPalette"); + return DDERR_GENERIC; +} + +HRESULT FakeZBuffer::GetPixelFormat(LPDDPIXELFORMAT) { + gog_debug("Unused function called: FakeZBuffer::GetPixelFormat"); + return DDERR_GENERIC; +} + +HRESULT FakeZBuffer::GetSurfaceDesc(LPDDSURFACEDESC) { + gog_debug("Unused function called: FakeZBuffer::GetSurfaceDesc"); + return DDERR_GENERIC; +} + +HRESULT FakeZBuffer::Initialize(LPDIRECTDRAW, LPDDSURFACEDESC) { + gog_debug("Unused function called: FakeZBuffer::Initialize"); + return DDERR_GENERIC; +} + +HRESULT FakeZBuffer::IsLost(void) { + return DD_OK; +} + +HRESULT FakeZBuffer::Lock(LPRECT, LPDDSURFACEDESC, DWORD, HANDLE) { + gog_debug("Unused function called: FakeZBuffer::Lock"); + return DDERR_GENERIC; +} + +HRESULT FakeZBuffer::ReleaseDC(HDC) { + gog_debug("Unused function called: FakeZBuffer::ReleaseDC"); + return DDERR_GENERIC; +} + +HRESULT FakeZBuffer::Restore(void) { + return DD_OK; +} + +HRESULT FakeZBuffer::SetClipper(LPDIRECTDRAWCLIPPER) { + return DD_OK; +} + +HRESULT FakeZBuffer::SetColorKey(DWORD, LPDDCOLORKEY) { + gog_debug("Unused function called: FakeZBuffer::SetColorKey"); + return DDERR_GENERIC; +} + +HRESULT FakeZBuffer::SetOverlayPosition(LONG, LONG) { + gog_debug("Unused function called: FakeZBuffer::SetOverlayPosition"); + return DDERR_GENERIC; +} + +HRESULT FakeZBuffer::SetPalette(LPDIRECTDRAWPALETTE) { + gog_debug("Unused function called: FakeZBuffer::SetPalette"); + return DDERR_GENERIC; +} + +HRESULT FakeZBuffer::Unlock(LPVOID) { + gog_debug("Unused function called: FakeZBuffer::Unlock"); + return DDERR_GENERIC; +} + +HRESULT FakeZBuffer::UpdateOverlay(LPRECT, LPDIRECTDRAWSURFACE, LPRECT, DWORD, LPDDOVERLAYFX) { + gog_debug("Unused function called: FakeZBuffer::UpdateOverlay"); + return DDERR_GENERIC; +} + +HRESULT FakeZBuffer::UpdateOverlayDisplay(DWORD) { + gog_debug("Unused function called: FakeZBuffer::UpdateOverlayDisplay"); + return DDERR_GENERIC; +} + +HRESULT FakeZBuffer::UpdateOverlayZOrder(DWORD, LPDIRECTDRAWSURFACE) { + gog_debug("Unused function called: FakeZBuffer::UpdateOverlayZOrder"); + return DDERR_GENERIC; +} + diff --git a/src/patches/gog_patch_dll/fake/FakeZBuffer.h b/src/patches/gog_patch_dll/fake/FakeZBuffer.h new file mode 100644 index 0000000..41fc1c5 --- /dev/null +++ b/src/patches/gog_patch_dll/fake/FakeZBuffer.h @@ -0,0 +1,60 @@ +// +// Created by DiaLight on 20.01.2023. +// + +#ifndef EMBER_FAKEZBUFFER_H +#define EMBER_FAKEZBUFFER_H + +#include +#include + +namespace gog { + + class FakeZBuffer : public FakeUnknown { + + public: + /*** IUnknown methods ***/ + STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR * ppvObj) override; + + /*** IDirectDrawSurface methods ***/ + STDMETHOD(AddAttachedSurface)(THIS_ LPDIRECTDRAWSURFACE) override; + STDMETHOD(AddOverlayDirtyRect)(THIS_ LPRECT) override; + STDMETHOD(Blt)(THIS_ LPRECT,LPDIRECTDRAWSURFACE, LPRECT,DWORD, LPDDBLTFX) override; + STDMETHOD(BltBatch)(THIS_ LPDDBLTBATCH, DWORD, DWORD ) override; + STDMETHOD(BltFast)(THIS_ DWORD,DWORD,LPDIRECTDRAWSURFACE, LPRECT,DWORD) override; + STDMETHOD(DeleteAttachedSurface)(THIS_ DWORD,LPDIRECTDRAWSURFACE) override; + STDMETHOD(EnumAttachedSurfaces)(THIS_ LPVOID,LPDDENUMSURFACESCALLBACK) override; + STDMETHOD(EnumOverlayZOrders)(THIS_ DWORD,LPVOID,LPDDENUMSURFACESCALLBACK) override; + STDMETHOD(Flip)(THIS_ LPDIRECTDRAWSURFACE, DWORD) override; + STDMETHOD(GetAttachedSurface)(THIS_ LPDDSCAPS, LPDIRECTDRAWSURFACE FAR *) override; + STDMETHOD(GetBltStatus)(THIS_ DWORD) override; + STDMETHOD(GetCaps)(THIS_ LPDDSCAPS) override; + STDMETHOD(GetClipper)(THIS_ LPDIRECTDRAWCLIPPER FAR*) override; + STDMETHOD(GetColorKey)(THIS_ DWORD, LPDDCOLORKEY) override; + STDMETHOD(GetDC)(THIS_ HDC FAR *) override; + STDMETHOD(GetFlipStatus)(THIS_ DWORD) override; + STDMETHOD(GetOverlayPosition)(THIS_ LPLONG, LPLONG ) override; + STDMETHOD(GetPalette)(THIS_ LPDIRECTDRAWPALETTE FAR*) override; + STDMETHOD(GetPixelFormat)(THIS_ LPDDPIXELFORMAT) override; + STDMETHOD(GetSurfaceDesc)(THIS_ LPDDSURFACEDESC) override; + STDMETHOD(Initialize)(THIS_ LPDIRECTDRAW, LPDDSURFACEDESC) override; + STDMETHOD(IsLost)(THIS) override; + STDMETHOD(Lock)(THIS_ LPRECT,LPDDSURFACEDESC,DWORD,HANDLE) override; + STDMETHOD(ReleaseDC)(THIS_ HDC) override; + STDMETHOD(Restore)(THIS) override; + STDMETHOD(SetClipper)(THIS_ LPDIRECTDRAWCLIPPER) override; + STDMETHOD(SetColorKey)(THIS_ DWORD, LPDDCOLORKEY) override; + STDMETHOD(SetOverlayPosition)(THIS_ LONG, LONG ) override; + STDMETHOD(SetPalette)(THIS_ LPDIRECTDRAWPALETTE) override; + STDMETHOD(Unlock)(THIS_ LPVOID) override; + STDMETHOD(UpdateOverlay)(THIS_ LPRECT, LPDIRECTDRAWSURFACE,LPRECT,DWORD, LPDDOVERLAYFX) override; + STDMETHOD(UpdateOverlayDisplay)(THIS_ DWORD) override; + STDMETHOD(UpdateOverlayZOrder)(THIS_ DWORD, LPDIRECTDRAWSURFACE) override; + + static FakeZBuffer *instance; + + }; + +} + +#endif //EMBER_FAKEZBUFFER_H diff --git a/src/patches/gog_patch_dll/gog_cfg.cpp b/src/patches/gog_patch_dll/gog_cfg.cpp new file mode 100644 index 0000000..3b6e62a --- /dev/null +++ b/src/patches/gog_patch_dll/gog_cfg.cpp @@ -0,0 +1,148 @@ +// +// Created by DiaLight on 20.01.2023. +// +#include +#include +#include +#include + +using namespace gog; + +bool cfg::iDisableDEP; +DWORD cfg::iScaleMode; +bool cfg::iBumpmap; +bool cfg::iNotOnTop; +bool cfg::iAnisotropy; +bool cfg::iHighRes; +DWORD cfg::iAntialias; +DWORD cfg::iVwait; +DWORD cfg::iCpuIdle; +bool cfg::iExtraAntialias; +bool cfg::iRealFullscreen; +bool cfg::iDisableFourCC; +bool cfg::iSingleCore; +DWORD cfg::iRestoreMode; + +void cfg::load() { + WCHAR appdataDir[512]; + SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, 0, appdataDir); + wcscat_s(appdataDir, ARRAYSIZE(appdataDir), L"\\GOG\\DungeonKeeper2\\Config.ini"); + cfg::iAntialias = GetPrivateProfileIntW(L"Video", L"Antialias", 11, appdataDir); + cfg::iExtraAntialias = GetPrivateProfileIntW(L"Video", L"ExtraAntialias", 0, appdataDir) != 0; + cfg::iHighRes = GetPrivateProfileIntW(L"Video", L"HighRes", 0, appdataDir) != 0; + cfg::iAnisotropy = GetPrivateProfileIntW(L"Video", L"Anisotropy", 0, appdataDir) != 0; + cfg::iVwait = GetPrivateProfileIntW(L"Video", L"Vwait", 1, appdataDir); + cfg::iScaleMode = GetPrivateProfileIntW(L"Video", L"ScaleMode", 1, appdataDir); + cfg::iDisableFourCC = GetPrivateProfileIntW(L"Video", L"DisableFourCC", 0, appdataDir) != 0; + cfg::iBumpmap = GetPrivateProfileIntW(L"Video", L"Bumpmap", 0, appdataDir) != 0; + cfg::iRealFullscreen = GetPrivateProfileIntW(L"Video", L"RealFullscreen", 1, appdataDir) != 0; + cfg::iCpuIdle = GetPrivateProfileIntW(L"Misc", L"CpuIdle", 0, appdataDir); + cfg::iSingleCore = GetPrivateProfileIntW(L"Misc", L"SingleCore", 1, appdataDir) != 0; + cfg::iDisableDEP = GetPrivateProfileIntW(L"Misc", L"DisableDEP", 1, appdataDir) != 0; + cfg::iRestoreMode = GetPrivateProfileIntW(L"Misc", L"RestoreMode", 0, appdataDir); + cfg::iNotOnTop = GetPrivateProfileIntW(L"Misc", L"NotOnTop", 0, appdataDir) != 0; + if (cfg::iAntialias > 10) { + cfg::iAntialias -= 10; + gog::g_isAntialiasGt10 = true; + } + OSVERSIONINFOA VersionInformation; + if (cfg::iRealFullscreen) { + cfg::iRestoreMode = 2; + } else if (cfg::iRestoreMode == 0) { + memset(&VersionInformation, 0, sizeof(VersionInformation)); + VersionInformation.dwOSVersionInfoSize = sizeof(VersionInformation); + GetVersionExA(&VersionInformation); + if (VersionInformation.dwMajorVersion < 6) { + cfg::iRestoreMode = 2; + } else { + cfg::iRestoreMode = 1; + if (IsDebuggerPresent()) { + cfg::iRestoreMode = 2; + } + } + } + if (!cfg::iBumpmap) { + char Destination[512]; + LPSTR CommandLineA = GetCommandLineA(); + strcpy_s(Destination, ARRAYSIZE(Destination), CommandLineA); + _strlwr_s(Destination, ARRAYSIZE(Destination)); + if (strstr(CommandLineA, "enablebumpluminance") != nullptr || + strstr(CommandLineA, "enablebumpmapping") != nullptr) { + cfg::iBumpmap = true; + } + } +} + +int cfg::patchRegistryConfig(int *status, LPCSTR lpValueName, DWORD *pValue) { + if (strcmp(lpValueName, "Screen Depth") == 0) { + *status = 0; + *pValue = 32; + return 0; + } + if (strcmp(lpValueName, "Screen Hardware3D") == 0) { + *status = 0; + *pValue = 1; + return 0; + } + if (strcmp(lpValueName, "Screen Mode Type") == 0) { + *status = 0; + *pValue = 3; + return 0; + } + if (strcmp(lpValueName, "Engine Id") == 0) { + *status = 0; + *pValue = 2; + return 0; + } + if (strcmp(lpValueName, "Res 1024*768 Enabled") == 0) { + *status = 0; + *pValue = 1; + return 0; + } + if (strcmp(lpValueName, "Res 1280*1024 Enable") == 0) { + *status = 0; + *pValue = 1; + return 0; + } + if (strcmp(lpValueName, "Res 1600*1200 Enable") == 0) { + *status = 0; + *pValue = 1; + return 0; + } + if (strcmp(lpValueName, "Screen Windowed") == 0) { + *status = 0; + *pValue = 0; + return 0; + } + if (strcmp(lpValueName, "Cheap Lighting") == 0) { + *status = 0; + *pValue = 0; + return 0; + } + if (strcmp(lpValueName, "Engine Id") == 0) { + *status = 0; + *pValue = 2; + return 0; + } + if (strcmp(lpValueName, "EnvironmentMapping") == 0) { + *status = 0; + *pValue = 1; + return 0; + } + if (strcmp(lpValueName, "High Res Textures") == 0) { + *status = 0; + *pValue = 1; + return 0; + } + if (strcmp(lpValueName, "Machine Spec Level") == 0) { + *status = 0; + *pValue = 10; + return 0; + } + if (strcmp(lpValueName, "PMesh Reduction Level") == 0) { + *status = 0; + *pValue = 0; + return 0; + } + return -1; +} diff --git a/src/patches/gog_patch_dll/gog_cfg.h b/src/patches/gog_patch_dll/gog_cfg.h new file mode 100644 index 0000000..6eda185 --- /dev/null +++ b/src/patches/gog_patch_dll/gog_cfg.h @@ -0,0 +1,33 @@ +// +// Created by DiaLight on 20.01.2023. +// + +#ifndef EMBER_GOG_CFG_H +#define EMBER_GOG_CFG_H + +#include + +namespace gog::cfg { + + extern bool iDisableDEP; + extern DWORD iScaleMode; + extern bool iBumpmap; + extern bool iNotOnTop; + extern bool iAnisotropy; + extern bool iHighRes; + extern DWORD iAntialias; + extern DWORD iVwait; + extern DWORD iCpuIdle; + extern bool iExtraAntialias; + extern bool iRealFullscreen; + extern bool iDisableFourCC; + extern bool iSingleCore; + extern DWORD iRestoreMode; + + void load(); + + int patchRegistryConfig(int *status, LPCSTR lpValueName, DWORD *pValue); + +} + +#endif //EMBER_GOG_CFG_H diff --git a/src/patches/gog_patch_dll/gog_debug.h b/src/patches/gog_patch_dll/gog_debug.h new file mode 100644 index 0000000..b33654d --- /dev/null +++ b/src/patches/gog_patch_dll/gog_debug.h @@ -0,0 +1,20 @@ +// +// Created by DiaLight on 22.01.2023. +// + +#ifndef EMBER_GOG_DEBUG_H +#define EMBER_GOG_DEBUG_H + +#include + +void _gog_print(const char *msg); + +#define gog_debug(msg) _gog_print(msg); + +#define gog_debugf(format, ...) { \ + char msg_buf[1024]; \ + wsprintfA(msg_buf, format, __VA_ARGS__); \ + _gog_print(msg_buf); \ +} + +#endif //EMBER_GOG_DEBUG_H diff --git a/src/patches/gog_patch_dll/gog_exports.cpp b/src/patches/gog_patch_dll/gog_exports.cpp new file mode 100644 index 0000000..7ce8447 --- /dev/null +++ b/src/patches/gog_patch_dll/gog_exports.cpp @@ -0,0 +1,41 @@ +// +// Created by DiaLight on 21.01.2023. +// +#include +#include +#include +#include +#include +#include +#include + +using namespace gog; + +//#pragma comment(linker, "/EXPORT:DirectDrawCreate@12=DirectDrawCreate") +extern "C" HRESULT WINAPI fake_DirectDrawCreate(GUID FAR *lpGUID, LPDIRECTDRAW FAR *lplpDD, IUnknown FAR *pUnkOuter) { + gog_debug("Creating DX device"); + if (lpGUID != nullptr) gog_debug("Assertion failed: FakeDirectDrawCreate:1517"); + if (lplpDD == nullptr) gog_debug("Assertion failed: FakeDirectDrawCreate:1518"); + if (!orig::pIDirectDraw4) { + LPDIRECTDRAW lpDD; + HRESULT hr = DirectDrawCreate(NULL, &lpDD, NULL); + if (FAILED(hr)) + return hr; + hr = lpDD->QueryInterface(IID_IDirectDraw4, (LPVOID *) &orig::pIDirectDraw4); + if (FAILED(hr)) + return hr; + lpDD->Release(); + FakeDirectDraw1::instance = new FakeDirectDraw1(); + FakeDirectDraw2::instance = new FakeDirectDraw2(); + FakeDirectDraw4::instance = new FakeDirectDraw4(); + FakeD3D3::instance = new FakeD3D3(); + } + *lplpDD = FakeDirectDraw1::instance; + return 0; +} + +//#pragma comment(linker, "/EXPORT:DirectDrawEnumerateA@8=DirectDrawEnumerateA") +extern "C" HRESULT WINAPI fake_DirectDrawEnumerateA(LPDDENUMCALLBACKA lpCallback, LPVOID lpContext) { + lpCallback(NULL, (LPSTR) "GOG HW Patch", (LPSTR) "GOG HW Patch", lpContext); + return 0; +} \ No newline at end of file diff --git a/src/patches/gog_patch_dll/gog_exports.h b/src/patches/gog_patch_dll/gog_exports.h new file mode 100644 index 0000000..f094f37 --- /dev/null +++ b/src/patches/gog_patch_dll/gog_exports.h @@ -0,0 +1,13 @@ +// +// Created by DiaLight on 21.01.2023. +// + +#ifndef EMBER_GOG_EXPORTS_H +#define EMBER_GOG_EXPORTS_H + +#include + +extern "C" HRESULT WINAPI fake_DirectDrawCreate(GUID FAR *lpGUID, LPDIRECTDRAW FAR *lplpDD, IUnknown FAR *pUnkOuter); +extern "C" HRESULT WINAPI fake_DirectDrawEnumerateA(LPDDENUMCALLBACKA lpCallback, LPVOID lpContext); + +#endif //EMBER_GOG_EXPORTS_H diff --git a/src/patches/gog_patch_dll/gog_fake.cpp b/src/patches/gog_patch_dll/gog_fake.cpp new file mode 100644 index 0000000..da60830 --- /dev/null +++ b/src/patches/gog_patch_dll/gog_fake.cpp @@ -0,0 +1,129 @@ +// +// Created by DiaLight on 20.01.2023. +// +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +void gog::fakeInit() { + FakeGammaControl::instance = new FakeGammaControl(); + FakeViewport3::instance = new FakeViewport3(); + FakeD3D::instance = new FakeD3D(); + FakeD3D2::instance = new FakeD3D2(); + FakeZBuffer::instance = new FakeZBuffer(); +} + +LPDIRECTDRAWSURFACE4 gog::Fake_CreateZBuf(DWORD width, DWORD height) { + DDSURFACEDESC2 desc; + memset(&desc, 0, sizeof(desc)); + desc.dwSize = 124; + desc.dwFlags = 0x1007; + desc.ddsCaps.dwCaps = 0x24000; + desc.ddpfPixelFormat.dwSize = 32; + desc.ddpfPixelFormat.dwFlags = 0x400; + desc.ddpfPixelFormat.dwRGBBitCount = 32; + desc.ddpfPixelFormat.dwGBitMask = 0xFFFFFF; + desc.dwWidth = width; + desc.dwHeight = height; + gog_debug("Creating Z-Buffer."); + LPDIRECTDRAWSURFACE4 surf; + HRESULT hr; + hr = orig::pIDirectDraw4->CreateSurface(&desc, &surf, NULL); + if (SUCCEEDED(hr)) + return surf; + gog_debug("ZBuf creation failed. Retrying with alternate bit order."); + desc.ddpfPixelFormat.dwGBitMask = 0xFFFFFF00; + hr = orig::pIDirectDraw4->CreateSurface(&desc, &surf, NULL); + if (SUCCEEDED(hr)) + return surf; + gog_debug("ZBuf creation failed. Retrying with lower bit depth."); + desc.ddpfPixelFormat.dwRGBBitCount = 16; + desc.ddpfPixelFormat.dwGBitMask = 0xFFFF; + hr = orig::pIDirectDraw4->CreateSurface(&desc, &surf, NULL); + if (SUCCEEDED(hr)) + return surf; + gog_debugf("Assertion failed: CreateZBuf:146 with HRESULT 0x%x", hr); + gog_debugf("Width = %d\nHeight = %d\nCaps = 0x%x\npfType = 0x%x", + desc.dwWidth, + desc.dwHeight, + desc.ddsCaps.dwCaps, + desc.ddpfPixelFormat.dwFlags); + return surf; +} + +void gog::Fake_Redraw() { + if (orig::pIDirectDrawSurface4_coop == nullptr) { + gog_debug("Assertion failed: Redraw:51"); + } + if (g_isRendererPaused) return; + HRESULT hr = orig::pIDirectDrawSurface4_coop->Blt( + &gog::g_renderRect, + orig::pIDirectDrawSurface4_last, NULL, 0x1000000, NULL); + if (hr != DDERR_SURFACELOST) return; + static_assert(DDERR_SURFACELOST == 0x887601C2); + gog_debug("Restoring all surfaces"); + orig::pIDirectDraw4->RestoreAllSurfaces(); + if (gog::g_isColorFill) + orig::pIDirectDrawSurface4_coop->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, NULL); + static_assert((DDBLT_COLORFILL | DDBLT_WAIT) == 0x1000400); +} + +void gog::Fake_InitRenderRect() { + RECT rect; + GetClientRect(g_hWnd, &rect); + unsigned int width = rect.right - rect.left; + unsigned int height = rect.bottom - rect.top; + if (!cfg::iScaleMode) { + gog::g_renderRect = rect; + return; + } + if (cfg::iScaleMode == 2) { + if (width > gog::g_dwWidth && height > gog::g_dwHeight) { + gog::g_renderRect.left = rect.left + ((width - gog::g_dwWidth) >> 1); + gog::g_renderRect.top = rect.top + ((height - gog::g_dwHeight) >> 1); + gog::g_renderRect.right = gog::g_dwWidth + gog::g_renderRect.left; + gog::g_renderRect.bottom = gog::g_dwHeight + gog::g_renderRect.top; + gog::g_isColorFill = true; + return; + } + } else if (cfg::iScaleMode == 3 && width > gog::g_dwWidth && height > gog::g_dwHeight) { + gog::g_renderRect.top = rect.top; + gog::g_renderRect.bottom = rect.top + gog::g_dwHeight; + gog::g_renderRect.right = rect.left + gog::g_dwWidth; + gog::g_renderRect.left = rect.left; + gog::g_isColorFill = true; + return; + } + double dWidth = (double) (unsigned int) gog::g_dwWidth; + double dHeight = (double) (unsigned int) gog::g_dwHeight; + double dWigth2 = (double) width; + double dHeight2 = (double) height; + if (fabs((dWigth2 / dHeight2) - (dWidth / dHeight)) >= 0.00001) { + gog::g_isColorFill = true; + if ((dWigth2 / dHeight2) <= (dWidth / dHeight)) { + int scaledHeight = (int) (dWigth2 / dWidth * dHeight); + gog::g_renderRect.left = rect.left; + gog::g_renderRect.top = rect.top + ((height - scaledHeight) >> 1); + gog::g_renderRect.bottom = scaledHeight + gog::g_renderRect.top; + gog::g_renderRect.right = rect.right; + } else { + int scaledWidth = (int) (dWidth * (dHeight2 / dHeight)); + gog::g_renderRect.left = rect.left + ((width - scaledWidth) >> 1); + gog::g_renderRect.top = rect.top; + gog::g_renderRect.bottom = rect.bottom; + gog::g_renderRect.right = scaledWidth + gog::g_renderRect.left; + } + } else { + gog::g_renderRect = rect; + } +} + diff --git a/src/patches/gog_patch_dll/gog_fake.h b/src/patches/gog_patch_dll/gog_fake.h new file mode 100644 index 0000000..d86f875 --- /dev/null +++ b/src/patches/gog_patch_dll/gog_fake.h @@ -0,0 +1,21 @@ +// +// Created by DiaLight on 20.01.2023. +// + +#ifndef EMBER_GOG_FAKE_H +#define EMBER_GOG_FAKE_H + +#include +#include + +namespace gog { + + void fakeInit(); + + LPDIRECTDRAWSURFACE4 Fake_CreateZBuf(DWORD width, DWORD height); + void Fake_Redraw(); + void Fake_InitRenderRect(); + +} + +#endif //EMBER_GOG_FAKE_H diff --git a/src/patches/gog_patch_dll/gog_globals.cpp b/src/patches/gog_patch_dll/gog_globals.cpp new file mode 100644 index 0000000..fa736a7 --- /dev/null +++ b/src/patches/gog_patch_dll/gog_globals.cpp @@ -0,0 +1,26 @@ +// +// Created by DiaLight on 20.01.2023. +// +#include + +bool gog::g_isAntialiasGt10 = false; +bool gog::g_isRendererPaused = false; +bool gog::g_isColorFill = false; +bool gog::g_isSmth_noRef = false; +bool gog::g_isSceneDrawing = false; +bool gog::g_isFlip = false; +bool gog::g_isMsgSent = false; +HWND gog::g_hWnd = nullptr; +DWORD gog::g_dwWidth = 0; +DWORD gog::g_dwHeight = 0; +RECT gog::g_renderRect = {0}; + + +IDirectDraw4 *gog::orig::pIDirectDraw4 = nullptr; +IDirect3D3 *gog::orig::pIDirect3D3 = nullptr; +IDirect3DDevice3 *gog::orig::pIDirect3DDevice3 = nullptr; +IDirectDrawSurface4 *gog::orig::pIDirectDrawSurface4_last = nullptr; +IDirectDrawSurface4 *gog::orig::pIDirectDrawSurface4_zbuf = nullptr; +IDirectDrawSurface4 *gog::orig::pIDirectDrawSurface4_640x480 = nullptr; +IDirectDrawSurface4 *gog::orig::pIDirectDrawSurface4_coop = nullptr; +IDirect3DViewport3 *gog::orig::pIDirect3DViewport3 = nullptr; diff --git a/src/patches/gog_patch_dll/gog_globals.h b/src/patches/gog_patch_dll/gog_globals.h new file mode 100644 index 0000000..f514f7e --- /dev/null +++ b/src/patches/gog_patch_dll/gog_globals.h @@ -0,0 +1,38 @@ +// +// Created by DiaLight on 20.01.2023. +// + +#ifndef EMBER_GOG_GLOBALS_H +#define EMBER_GOG_GLOBALS_H + +#include +#include +#include + +namespace gog { + extern bool g_isAntialiasGt10; + extern bool g_isRendererPaused; + extern bool g_isColorFill; + extern bool g_isSmth_noRef; + extern bool g_isSceneDrawing; + extern bool g_isFlip; + extern bool g_isMsgSent; + extern HWND g_hWnd; + extern DWORD g_dwWidth; + extern DWORD g_dwHeight; + extern RECT g_renderRect; + + namespace orig { + extern IDirectDraw4 *pIDirectDraw4; + extern IDirect3D3 *pIDirect3D3; + extern IDirect3DDevice3 *pIDirect3DDevice3; + extern IDirectDrawSurface4 *pIDirectDrawSurface4_last; + extern IDirectDrawSurface4 *pIDirectDrawSurface4_zbuf; + extern IDirectDrawSurface4 *pIDirectDrawSurface4_640x480; + extern IDirectDrawSurface4 *pIDirectDrawSurface4_coop; + extern IDirect3DViewport3 *pIDirect3DViewport3; + } + +} + +#endif //EMBER_GOG_GLOBALS_H diff --git a/src/patches/gog_patch_dll/gog_patch.cpp b/src/patches/gog_patch_dll/gog_patch.cpp new file mode 100644 index 0000000..afe10c0 --- /dev/null +++ b/src/patches/gog_patch_dll/gog_patch.cpp @@ -0,0 +1,33 @@ +// +// Created by DiaLight on 11.09.2024. +// +#include "gog_patch.h" +#include "gog_globals.h" +#include "gog_debug.h" + +bool gog::RtGuiView_fix::enable = true; +bool gog::RegistryConfig_patch::enable = true; +bool gog::parseCommandLine_patch::enable = true; +bool gog::SurfaceHolder_setTexture_patch::enable = true; + +bool gog::BullfrogWindow_proc_patch::enable = true; +bool gog::BullfrogWindow_proc_patch::window_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { + if (!enable) return false; + switch (Msg) { + case WM_KILLFOCUS: + ShowWindow(gog::g_hWnd, SW_MINIMIZE); + break; + case WM_ACTIVATEAPP: + if (wParam) { // activated + gog::g_isRendererPaused = false; + gog_debug("Resumed Render"); + } else { // deactivated + gog::g_isRendererPaused = true; + gog_debug("Paused Render"); + } + break; + case WM_MOUSEMOVE: return true; // do not call original fun + } + if (gog::g_isRendererPaused && (0x100 <= Msg && Msg < 0x300)) return true; // do not call original fun + return false; +} diff --git a/src/patches/gog_patch_dll/gog_patch.h b/src/patches/gog_patch_dll/gog_patch.h new file mode 100644 index 0000000..87eb295 --- /dev/null +++ b/src/patches/gog_patch_dll/gog_patch.h @@ -0,0 +1,33 @@ +// +// Created by DiaLight on 10.09.2024. +// + +#ifndef FLAME_GOG_PATCH_H +#define FLAME_GOG_PATCH_H + +#include + +namespace gog { + + extern bool enable; + bool patch_init(); + + namespace RtGuiView_fix { + extern bool enable; + } + namespace RegistryConfig_patch { + extern bool enable; + } + namespace parseCommandLine_patch { + extern bool enable; + } + namespace SurfaceHolder_setTexture_patch { + extern bool enable; + } + namespace BullfrogWindow_proc_patch { + extern bool enable; + bool window_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); + } +} + +#endif //FLAME_GOG_PATCH_H diff --git a/src/patches/gog_patch_dll/gog_patch_dll.cpp b/src/patches/gog_patch_dll/gog_patch_dll.cpp new file mode 100644 index 0000000..a7015e5 --- /dev/null +++ b/src/patches/gog_patch_dll/gog_patch_dll.cpp @@ -0,0 +1,40 @@ +// +// Created by DiaLight on 20.01.2023. +// +#include +#include +#include +#include +#include + +using namespace gog; + +bool gog::enable = true; + +void _gog_print(const char *msg) { + char msg_buf[1024]; + wsprintfA(msg_buf, "[GOG] %s\n", msg); + OutputDebugStringA(msg_buf); + printf("%s", msg_buf); +} + +bool gog::patch_init() { + gog::cfg::load(); + gog::fakeInit(); + if (gog::cfg::iSingleCore) { + HANDLE hProc = GetCurrentProcess(); + SetProcessAffinityMask(hProc, 1); + } + if (gog::cfg::iDisableDEP) { + HMODULE kernel32 = LoadLibraryA("kernel32.dll"); + typedef BOOL (WINAPI *SetProcessDEPPolicy_t)(_In_ DWORD dwFlags); + auto SetProcessDEPPolicy = (SetProcessDEPPolicy_t) GetProcAddress(kernel32, "SetProcessDEPPolicy"); + if (SetProcessDEPPolicy) { + SetProcessDEPPolicy(0); + } + } + if (cfg::iCpuIdle) { + timeBeginPeriod(1u); + } + return true; +} diff --git a/src/patches/gog_patch_dll/gog_patch_dll.h b/src/patches/gog_patch_dll/gog_patch_dll.h new file mode 100644 index 0000000..d6494a8 --- /dev/null +++ b/src/patches/gog_patch_dll/gog_patch_dll.h @@ -0,0 +1,10 @@ +// +// Created by DiaLight on 19.03.2023. +// + +#ifndef EMBER_GOG_PATCH_DLL_H +#define EMBER_GOG_PATCH_DLL_H + +bool gog_patch_dll(); + +#endif //EMBER_GOG_PATCH_DLL_H diff --git a/src/patches/micro_patches.cpp b/src/patches/micro_patches.cpp index 75aa434..a4fde8a 100644 --- a/src/patches/micro_patches.cpp +++ b/src/patches/micro_patches.cpp @@ -15,8 +15,7 @@ bool add_win10_support::enabled = true; bool use_cwd_as_dk2_home_dir::enabled = true; bool notify_another_instance_is_running::enabled = true; -bool control_windowed_mode::enabled = true; -bool control_windowed_mode::disable_move_by_mouse = true; +bool control_windowed_mode::enabled = false; bool force_32bit_everything::enabled = true; bool disable_bonus_damage::enabled = false; bool backstab_fix::enabled = true; diff --git a/src/patches/micro_patches.h b/src/patches/micro_patches.h index 8d94803..3bb5218 100644 --- a/src/patches/micro_patches.h +++ b/src/patches/micro_patches.h @@ -22,7 +22,6 @@ namespace notify_another_instance_is_running { namespace control_windowed_mode { extern bool enabled; - extern bool disable_move_by_mouse; } namespace force_32bit_everything { diff --git a/src/patches/replace_mouse_dinput_to_user32.cpp b/src/patches/replace_mouse_dinput_to_user32.cpp index 93be397..f3adb98 100644 --- a/src/patches/replace_mouse_dinput_to_user32.cpp +++ b/src/patches/replace_mouse_dinput_to_user32.cpp @@ -91,12 +91,13 @@ void handle_fpv_mouse_move(HWND hWnd, POINT pos) { clientResetPos.x = (clientRect.left + clientRect.right) / 2; clientResetPos.y = (clientRect.top + clientRect.bottom) / 2; + float sensitivity = dk2::MyResources_instance.playerCfg.mouseSensitivity / 10.0; if(pos.x != lastPos.x) { - dk2::MyInputManagerCb_instance.f60_mouse->f24_flX_delta = pos.x - lastPos.x; + dk2::MyInputManagerCb_instance.f60_mouse->f24_flX_delta = (float) (pos.x - lastPos.x) * sensitivity; lastPos.x = pos.x; } if(pos.y != lastPos.y) { - dk2::MyInputManagerCb_instance.f60_mouse->f28_flY_delta = pos.y - lastPos.y; + dk2::MyInputManagerCb_instance.f60_mouse->f28_flY_delta = (float) (pos.y - lastPos.y) * sensitivity; lastPos.y = pos.y; } @@ -116,8 +117,8 @@ void handle_fpv_mouse_move(HWND hWnd, POINT pos) { // ); } } -void replace_mouse_dinput_to_user32::handle_mouse_move(HWND hWnd, POINT pos) { +void replace_mouse_dinput_to_user32::handle_mouse_move(HWND hWnd, POINT pos) { // handle gui mouse dk2::AABB renderRect = dk2::MyInputManagerCb_instance.f60_mouse->f30_aabb; dk2::Pos2i renderSize = {renderRect.maxX - renderRect.minX, renderRect.maxY - renderRect.minY}; @@ -147,6 +148,11 @@ void replace_mouse_dinput_to_user32::emulate_dinput_from_user32(HWND hWnd, UINT clientSize = {LOWORD(lParam), HIWORD(lParam)}; break; } + case WM_MOUSEMOVE: { + POINT mousePos = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)}; + handle_mouse_move(hWnd, mousePos); + break; + } case WM_LBUTTONDOWN: click_mouse(DIK_DK2_LEFTMOUSE, DK2_IsPressed | controlFlags); break; diff --git a/src/replace_globals.map b/src/replace_globals.map index 3496f3e..1de3905 100644 --- a/src/replace_globals.map +++ b/src/replace_globals.map @@ -5,6 +5,14 @@ 005B74A0 void resolveDk2HomeDir(); // --------------- /* auto */ 005A63B0 int __cdecl parse_command_line(int, const char **); /* auto */ +# engine +0058A150 void drawTexToSurfTriangles(); // ---------- /* auto */ +00592B80 void __cdecl renderer_setSurfaceHolder(SurfaceHolder *, uint32_t); /* auto */ +005573C0 BOOL collect_devices_DDEnumCB(_GUID *, const CHAR *, const CHAR *, void *); /* auto */ +00557980 BOOL collect_displayModes_DDEnumCB(_GUID *, CHAR *, CHAR *, HWND); /* auto */ +005B4DE0 int *__cdecl createDirectDrawObject(int *, _GUID *, IDirectDraw **); /* auto */ +005578E0 int getDevIdxSupportsLinearPerspective(); /* auto */ + # CFrontEndComponent.h 005340F0 void showTitleScreen(); // ----------------- /* auto */ @@ -18,6 +26,9 @@ 005BC760 int *__cdecl MyDxMouse_create(int *, MyDxMouse **); /* auto */ 005DDA90 void handleData(int); // ------------------- /* auto */ +# MyDxInputManagerCb.h +005BC210 uint32_t *onWindowActivated(uint32_t *, int); /* auto */ + # MyDxKeyboard.h 005DE260 int processKeyboardData(int); // ----------- /* auto */ @@ -28,6 +39,7 @@ 005B2E70 int __cdecl getCustomDefWindowProcA(); // -- /* auto */ # MyGame.h +00557CB0 int init(); // ----------------------------- /* auto */ 00557FB0 int isOsCompatible(); // ------------------- /* auto */ 005581B0 int prepareScreenEx(uint32_t, uint32_t, uint32_t, int, int, int); /* auto */ @@ -62,5 +74,6 @@ 00562200 uint32_t *settings_writeBytes(uint32_t *, const CHAR *, uint32_t, uint8_t *, uint32_t); /* auto */ 00562260 uint32_t *settings_readBytes(uint32_t *, const CHAR *, uint8_t *, uint32_t); /* auto */ 005622B0 uint32_t settings_readBytesCount(const CHAR *); /* auto */ +005626C0 int *settings_readValue(int *, LPCSTR, uint32_t *); /* auto */ diff --git a/tools/msvc_mangler/mangler_tests.cpp b/tools/msvc_mangler/mangler_tests.cpp index bd9a7d9..84fa93b 100644 --- a/tools/msvc_mangler/mangler_tests.cpp +++ b/tools/msvc_mangler/mangler_tests.cpp @@ -96,7 +96,7 @@ global: va=00553B90,name=MBToUni_convert,size=109 arg: kind=ptr type: kind=int,size=1 arg: kind=ptr - type: kind=int,size=2,winapi=wchar_t + type: kind=int,size=2,winapi=wchar_t,fname=wchar_t arg: kind=int,size=2,signed=True )", "?MBToUni_convert@dk2@@YAHPAEPA_WF@Z", "int __cdecl dk2::MBToUni_convert(unsigned char *,wchar_t *,short)"); // WCHAR @@ -133,9 +133,9 @@ global: va=00634E90,name=_swprintf,size=148 type: kind=function,declspec=cdecl_varargs ret: kind=int,size=4,signed=True arg: kind=ptr - type: kind=int,size=2,winapi=wchar_t + type: kind=int,size=2,winapi=wchar_t,fname=wchar_t arg: kind=ptr,is_const=True - type: kind=int,size=2,winapi=wchar_t + type: kind=int,size=2,winapi=wchar_t,fname=wchar_t )", "?_swprintf@dk2@@YAHPA_WPB_WZZ", "int __cdecl dk2::_swprintf(wchar_t *,wchar_t const *,...)"); // float assert_mangle(R"( @@ -162,7 +162,7 @@ global: va=005BAE70,name=constructor,size=61,member_of=constructor_005BAE70 assert_mangle(R"( global: va=00740780,name=g_wchar_buf,size=1024 type: kind=array,count=512 - type: kind=int,size=2,winapi=wchar_t + type: kind=int,size=2,winapi=wchar_t,fname=wchar_t )", "?g_wchar_buf@dk2@@3PA_WA", "wchar_t * dk2::g_wchar_buf"); // function arg assert_mangle(R"( @@ -198,9 +198,6 @@ global: va=005DDBC0,name=initDevice_0,size=25,member_of=vtbl_00673048 arg: kind=ptr type: kind=int,size=4,signed=True,winapi=HRESULT,fname=HRESULT )", "?initDevice_0@MyDirectInput@dk2@@QAEPAJPAJ@Z", "public: long * __thiscall dk2::MyDirectInput::initDevice_0(long *)"); -} - -void last_test() { // vftable assert_mangle(R"( struct: id=call_f0_at_005DA01F,name=DxAction_vtbl,size=4 @@ -216,6 +213,40 @@ struct: id=instance_006728F8,name=MouseRgbDxAction_vtbl,size=4,super=call_f0_at_ global: va=006728F8,name=MouseRgbDxAction_vftable,size=4 type: kind=struct,id=instance_006728F8 )", "?vftable@MouseRgbDxAction@dk2@@2PAPAXA", "void * * dk2::MouseRgbDxAction::vftable"); + // function stdcall arg + assert_mangle(R"( +struct: id=constructor_005B97B0,name=WinEventHandlers,size=0 +global: va=005B99E0,name=addHandler,size=200,member_of=constructor_005B97B0 + type: kind=function,declspec=thiscall + ret: kind=void + arg: kind=ptr + type: kind=struct,id=constructor_005B97B0 + arg: kind=int,size=4,signed=True + arg: kind=ptr + type: kind=function,declspec=stdcall + ret: kind=void + arg: kind=int,size=4,signed=True + arg: kind=int,size=4,signed=True + arg: kind=ptr + type: kind=void + arg: kind=ptr + type: kind=void +)", "?addHandler@WinEventHandlers@dk2@@QAEXHP6GXHHPAX@Z0@Z", "void __thiscall dk2::WinEventHandlers::addHandler(int,void (__stdcall*)(int,int,void *),void *)"); +} + +void last_test() { + // winapi union + assert_mangle(R"( +global: va=00653080,name=mgsr_drawTriangle24_impl5,size=2798 + type: kind=function,declspec=cdecl + ret: kind=int,size=4,signed=True + arg: kind=ptr + type: kind=winapi,name=__m64,size=8,is_union=True + arg: kind=ptr + type: kind=winapi,name=__m64,size=8,is_union=True + arg: kind=ptr + type: kind=winapi,name=__m64,size=8,is_union=True +)", "?mgsr_drawTriangle24_impl5@dk2@@YAHPAT__m64@@00@Z", "int __cdecl dk2::mgsr_drawTriangle24_impl5(union __m64 *,union __m64 *,union __m64 *)"); } int main() { diff --git a/tools/msvc_mangler/msvc_mangler.cpp b/tools/msvc_mangler/msvc_mangler.cpp index a082ef8..cbee918 100644 --- a/tools/msvc_mangler/msvc_mangler.cpp +++ b/tools/msvc_mangler/msvc_mangler.cpp @@ -56,7 +56,12 @@ void mangleTagTypeKind(std::stringstream &ss, Type *ty) { } } if(ty->kind == TK_Winapi) { - ss << 'U'; + auto *winTy = (WinapiType *) ty; + if(winTy->is_union) { + ss << 'T'; + } else { + ss << 'U'; + } } } @@ -142,6 +147,18 @@ void mangleName(std::stringstream &ss, const std::string &name, std::map &backReference); void mangleType(std::stringstream &ss, Type *ty, std::map &backReference) { if(ty->kind == TK_Int) { @@ -175,11 +192,16 @@ void mangleType(std::stringstream &ss, Type *ty, std::map & if(ty->kind == TK_Ptr) { // https://clang.llvm.org/doxygen/MicrosoftMangle_8cpp_source.html#l03186 auto *ptrTy = (PtrType *) ty; ss << 'P'; + // MicrosoftCXXNameMangler::mangleFunctionType if(ptrTy->type->kind == TK_Function) { + auto *funTy = (FunctionType *) ptrTy->type; ss << '6'; + mangleCConv(ss, funTy->cconv); + mangleType(ss, ptrTy->type, backReference); + } else { + mangleQualifiers(ss, ptrTy, false); + mangleType(ss, ptrTy->type, backReference); } - mangleQualifiers(ss, ptrTy, false); - mangleType(ss, ptrTy->type, backReference); return; } if(ty->kind == TK_Float) { @@ -254,17 +276,6 @@ void mangleFunctionArgumentType(std::stringstream &ss, Type *ty, std::map