This repository was archived by the owner on Oct 4, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathBaseRender.cpp
More file actions
3222 lines (2768 loc) · 99.8 KB
/
Copy pathBaseRender.cpp
File metadata and controls
3222 lines (2768 loc) · 99.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "defs.h"
#include "_lod.h"
#include "c18.h"
#include "RenderD3D3.h"
#include "mm7_unparsed_data.h"
#include "mm7_unparsed_functions.h"
#include "data.h"
#include "Game.h"
#include "UserInput.h"
#pragma comment(lib, "libs\\legacy_dx\\lib\\ddraw.lib")
#pragma comment(lib, "libs\\legacy_dx\\lib\\dxguid.lib")
//#pragma comment(lib, "libs\\legacy_dx\\lib\\dinput8.lib")
#define FI16_565_RED_MASK 0xF800
#define FI16_565_GREEN_MASK 0x07E0
#define FI16_565_BLUE_MASK 0x001F
#define FI16_565_RED_SHIFT 11
#define FI16_565_GREEN_SHIFT 5
#define FI16_565_BLUE_SHIFT 0
static void scale_image_bicubic(unsigned char *dst, int dw, int dh,
unsigned char *src, int sw, int sh,
int bpp);
//----- (MM7exe::00452347) --------------------------------------------------------
void Render_HWLContainer_ctor(struct Render_HWLContainer *_this)
{
_this->pHWLFile = 0;
_this->dword_000004 = 0;
_this->dword_000008 = 0;
_this->uNumElements = 0;
memset(_this->pSriteNames, 0, 50000 * 4);
memset(_this->pSpriteFileOffsets, 0, 50000 * 4);
_this->dword_061A90 = 0;
_this->dword_061A94 = 0;
}
//----- (MM7.exe::0045237F) --------------------------------------------------------
int Render_HWLContainer_LoadHWLHeaders(struct Render_HWLContainer *_this, const char *pFilename)
{
int i;
_this->pHWLFile = fopen(pFilename, "rb");
if ( !_this->pHWLFile)
return false;
locked_fread(&_this->dword_000004, 1, 4, _this->pHWLFile);
if (_this->dword_000004 != 0x54443344)
return false;
locked_fread(&_this->dword_000008, 4, 1, _this->pHWLFile);
fseek(_this->pHWLFile, _this->dword_000008, 0);
locked_fread(&_this->uNumElements, 4, 1, _this->pHWLFile);
unsigned char* base= MemAlloc(unsigned char, 20*_this->uNumElements); //operator new(0x14u)
for (i = 0; i <_this->uNumElements; i++)
_this->pSriteNames[i] =base +i*20;
locked_fread(_this->pSriteNames[0],_this->uNumElements, 20, _this->pHWLFile);
locked_fread(_this->pSpriteFileOffsets, 4, _this->uNumElements, _this->pHWLFile);
_this->dword_061A90 = 0;
return true;
}
//----- (MM7.exe::0049E992) --------------------------------------------------------
BaseRender::BaseRender()
{
int v1; // eax@1
char v3; // zf@1
this->pdd4 = 0;
this->pdds4_FrontBuffer = 0;
this->pdds4_BackBuffer = 0;
this->dword_040098 = 0;
this->pdd2 = 0;
this->pdds2_FrontBuffer = 0;
this->pdds2_BackBuffer = 0;
this->dword_0400A8 = 0;
Render_HWLContainer_ctor(&this->struct_040114);
Render_HWLContainer_ctor(&this->struct_0A1BAC);
this->dword_040054 = 0;
this->bWindowMode = 1;
this->bUseDirect3D = ReadWindowsRegistry("Use D3D", false);
this->bStartInWindow = ReadWindowsRegistry("startinwindow", false);
v1 = ReadWindowsRegistry("D3D Device", true);
v3 = this->bStartInWindow == 0;
this->bStartInWindow = v3 && v1 != 1;
this->uDesiredDirect3DDevice = v1;
//force d3d
this->bUseDirect3D = true;
this->dword_000010 = 640;
this->dword_000014 = 480;
this->dword_00001C = 0;
this->dword_000020 = 0;
this->dword_000024 = 639;
this->dword_000028 = 479;
this->dword_04002C = 0;
this->dword_040030 = 0;
this->pActiveZBuffer = 0;
this->pDefaultZBuffer = 0;
this->dword_04003C = (int)&unk_4EED80;
this->dword_040040 = dword_4EED78;
this->dword_040044 = 2;
this->dword_040048 = 6;
this->pRenderD3D3 = 0;
this->bSceneBegun = 0;
this->pTargetSurface = 0;
this->uTargetSurfacePitch = 0;
this->uClipRectY = 0;
this->uClipRectX = 0;
this->uClipRectW = 480;
this->uClipRectZ = 640;
this->dword_040104 = 1;
this->dword_040108 = 0;
this->uD3D3SceneBegun = 0;
this->dword_040110 = 0;
this->bUseColoredLights = ReadWindowsRegistry("Colored Lights", false);
this->bRequiredTextureStagesAvailable = false;
this->bTinting = true;
this->uLevelOfDetail = ReadWindowsRegistry("Detail Level", 1);
this->byte_103668[0] = 0;
this->dword_1036B8 = 0;
this->dword_1036BC = 0;
Render_HWLContainer_LoadHWLHeaders(&this->struct_040114, "data\\d3dbitmap.hwl");
Render_HWLContainer_LoadHWLHeaders(&this->struct_0A1BAC, "data\\d3dsprite.hwl");
this->uNumBillboardsToDraw = 0;
}
//----- (MM7.exe::0049FBCD) --------------------------------------------------------
void Render_ClearTarget(struct BaseRender *_this, unsigned int uColor)
{
if (_this->dword_040110)
RenderD3D3_ClearTarget(_this->pRenderD3D3, 1, uColor, 0, 0.0);
}
//----- (MM7.exe::004A51CB) --------------------------------------------------------
Result::Code RenderDirect3D3::BeginScene()
{
int v1; // eax@1
//int Dst; // [sp+Ch] [bp-7Ch]@4
//int v6; // [sp+1Ch] [bp-6Ch]@5
//int v7; // [sp+30h] [bp-58h]@5
char local_0[124];
DDSURFACEDESC2 ddsd2;
v1 = this->bSceneBegun++;
if (!v1)
{
if (this->dword_040108)
{
memset(&ddsd2, 0, sizeof(DDSURFACEDESC2));
ddsd2.dwSize = sizeof(DDSURFACEDESC2);
LOBYTE(v1) = LockSurface_DDraw4(this->dword_040098, &ddsd2, 2049);
if ((_BYTE)v1)
{
this->pTargetSurface = (unsigned int *)ddsd2.lpSurface;
this->uTargetSurfacePitch = ddsd2.lPitch / (ddsd2.ddpfPixelFormat.dwRGBBitCount / 8);
this->dword_000018 = this->uTargetSurfacePitch;
goto LABEL_11;
}
this->bSceneBegun--;
return Result::Success;
}
LABEL_11:
LOBYTE(v1) = Render_RestoreFrontBuffer(this);
}
int v4, result;
result = this->uD3D3SceneBegun++;
if ( !result )
{
RenderD3D3_ClearTarget(this->pRenderD3D3, 1, result, 1, 1.0);
this->uNumBillboardsToDraw = 0;
this->pRenderD3D3->pDevice->BeginScene();
if ( uCurrentlyLoadedLevelType == 2 )
v4 = sub_47C370();
else
v4 = 0;
if ( v4 & 0xFF000000 )
{
this->pRenderD3D3->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 1);
this->pRenderD3D3->pDevice->SetRenderState(D3DRENDERSTATE_FOGCOLOR, v4 & 0xFFFFFF);
this->pRenderD3D3->pDevice->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE, 0);
this->bUsingSpecular = true;
}
else
{
this->pRenderD3D3->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, 0);
this->bUsingSpecular = false;
}
}
return Result::Success;
}
//----- (004A0BEE) --------------------------------------------------------
char Render_FillRect(struct BaseRender *_this, unsigned int uX, unsigned int uY, unsigned int uZ, unsigned int uW, unsigned int uColor)
{
int v13; // edi@21
int v14; // eax@21
int v15; // eax@22
int v16; // eax@25
int v17; // eax@27
int v18; // eax@28
int v19; // edi@30
signed __int64 v20; // qax@41
int v21; // edi@41
signed int v25; // edx@50
int v27; // esi@52
int v28; // ebx@54
int v29; // edx@55
int v30; // edi@55
int v31; // ebx@60
int v32; // edx@61
int v36; // [sp+10h] [bp-Ch]@1
__int64 v37; // [sp+14h] [bp-8h]@1
signed int v38; // [sp+18h] [bp-4h]@28
int v40; // [sp+28h] [bp+Ch]@28
int v42; // [sp+2Ch] [bp+10h]@19
int v43; // [sp+2Ch] [bp+10h]@38
unsigned int *pTargetSurface;
unsigned int uRectWidth,
uRectHeight;
unsigned int x, y;
v36 = (int)_this;
v37 = 0i64;
if (uX < _this->dword_00001C)
HIDWORD(v37) = 8;
if (uX > _this->dword_000024)
HIDWORD(v37) |= 4u;
if (uY < _this->dword_000020)
HIDWORD(v37) |= 2;
if (uY > _this->dword_000028)
HIDWORD(v37) |= 1u;
if (uZ < _this->dword_00001C)
LODWORD(v37) = 8;
if (uZ > _this->dword_000024)
LODWORD(v37) = v37 | 4;
if (uW < _this->dword_000020)
LODWORD(v37) = v37 | 2;
if (uW > _this->dword_000028)
LODWORD(v37) = v37 | 1;
if ( (_DWORD)v37 & HIDWORD(v37) )
return (_BYTE)v37;
pTargetSurface = pD3DRenderer->pTargetSurface;
for (y = uY; y < uW; ++y)
for (x = uX; x < uZ; ++x)
pTargetSurface[y * pD3DRenderer->uTargetSurfacePitch + x] = uColor;
/*
if ( !v37 )
{
LABEL_46:
uRectWidth = uZ - uX;
uRectHeight = uW - uY;
v25 = 1;
v27 = 0;
pTargetSurface = _this->pTargetSurface + uX + uY * pD3DRenderer->uTargetSurfacePitch;
if ( uRectWidth <= uRectHeight )
{
v31 = uRectHeight + 1;
if ( v31 > 0 )
{
v32 = v25;
do
{
v27 += uRectWidth;
*pTargetSurface = uColor;
pTargetSurface += pD3DRenderer->uTargetSurfacePitch;
if ( v27 > 0 )
{
v27 -= uRectHeight;
pTargetSurface += v32;
}
--v31;
}
while ( v31 );
}
}
else
{
v28 = uRectWidth + 1;
if ( uRectWidth + 1 > 0 )
{
v30 = pD3DRenderer->uTargetSurfacePitch;
v29 = v25;
do
{
v27 += uRectHeight;
*pTargetSurface = uColor;
pTargetSurface += v29;
if ( v27 > uRectWidth )
{
v27 -= uRectWidth;
pTargetSurface += v30;
}
--v28;
}
while ( v28 );
}
}
return pTargetSurface;
}
v42 = HIDWORD(v37) ^ v37;
if ( (BYTE4(v37) ^ (_BYTE)v37) & 8 )
{
if ( BYTE4(v37) & 8 )
{
v14 = (uW - uY) * (_this->dword_00001C - uX) / (uZ - uX);
v13 = v36;
uY = v14 + uY;
uX = *(_DWORD *)(v36 + 28);
goto LABEL_24;
}
v15 = (uY - uW) * (_this->dword_00001C - uZ) / (uX - uZ);
uZ = _this->dword_00001C;
uW = v15 + uW;
}
v13 = v36;
LABEL_24:
if ( v42 & 4 )
{
v16 = *(_DWORD *)(v13 + 36);
if ( BYTE4(v37) & 4 )
{
v13 = v36;
uY += (uW - uY) * (v16 - uX) / (uZ - uX);
uX = *(_DWORD *)(v36 + 36);
}
else
{
v17 = (uY - uW) * (v16 - uZ) / (uX - uZ);
uZ = *(_DWORD *)(v13 + 36);
uW += v17;
}
}
v18 = *(_DWORD *)(v13 + 32);
v38 = 0;
v40 = *(_DWORD *)(v13 + 32);
if ( uY < v18 )
v38 = 2;
v19 = *(_DWORD *)(v13 + 40);
if ( uY > v19 )
v38 |= 1u;
if ( uW >= v18 )
pTargetSurface = 0;
else
pTargetSurface = 2;
compile_error();
if ( uW > v19 )
LOBYTE(pTargetSurface) = pTargetSurface | 1;
if ( !(pTargetSurface & v38) )
{
pTargetSurface ^= v38;
v43 = pTargetSurface;
if ( pTargetSurface & 2 )
{
if ( v38 & 2 )
{
uX += (uZ - uX) * (v40 - uY) / (uW - uY);
LOBYTE(pTargetSurface) = v36;
uY = *(_DWORD *)(v36 + 32);
}
else
{
v20 = (uX - uZ) * (v40 - uW);
v21 = uY - uW;
uW = v40;
pTargetSurface = v20 / v21;
uZ += pTargetSurface;
}
}
if ( v43 & 1 )
{
if ( v38 & 1 )
{
uX += (uZ - uX) * (*(_DWORD *)(v36 + 40) - uY) / (uW - uY);
LOBYTE(pTargetSurface) = v36;
uY = *(_DWORD *)(v36 + 40);
}
else
{
pTargetSurface = (uX - uZ) * (*(_DWORD *)(v36 + 40) - uW) / (uY - uW);
uW = *(_DWORD *)(v36 + 40);
uZ += pTargetSurface;
}
}
goto LABEL_46;
}
return pTargetSurface;*/
}
//----- (MM7.exe::004A1605) --------------------------------------------------------
int Render_LockBackBuffer(struct BaseRender *_this, void **ppOutSurfacePtr, unsigned int *pOutSurfaceWidth)
{
DDSURFACEDESC2 ddsd2;
//int v6; // [sp+4h] [bp-7Ch]@4
int Dst; // [sp+14h] [bp-6Ch]@3
int v8; // [sp+24h] [bp-5Ch]@3
int v9; // [sp+28h] [bp-58h]@4
int v10; // [sp+38h] [bp-48h]@3
if (dword_F79D70 != 4 )
{
memset(&ddsd2, 0, sizeof(DDSURFACEDESC2));
ddsd2.dwSize = sizeof(DDSURFACEDESC2);
LockSurface_DDraw4(_this->pdds4_BackBuffer, &ddsd2, 1);
*ppOutSurfacePtr = ddsd2.lpSurface;
*pOutSurfaceWidth = ddsd2.lPitch / (ddsd2.ddpfPixelFormat.dwRGBBitCount / 8);
}
else
{
_asm int 3; //ddraw2
memset(&Dst, 0, 0x6Cu);
Dst = 108;
LockSurface_DDraw2(_this->pdds2_BackBuffer, (DDSURFACEDESC *)&Dst, 1);
*ppOutSurfacePtr = (void *)v10;
*pOutSurfaceWidth = v8;
}
return *pOutSurfaceWidth;
}
//----- (004A5B81) --------------------------------------------------------
void Render_Set2DClippingRect(struct BaseRender *_this, unsigned int uX, unsigned int uY, unsigned int uZ, unsigned int uW)
{
_this->uClipRectX = uX;
_this->uClipRectY = uY;
_this->uClipRectZ = uZ;
_this->uClipRectW = uW;
_this->dword_040104 = 1;
}
extern class cTexture pending_texture;
void Render_DrawIndexedTextureHandle(struct BaseRender *_this, unsigned int uX, unsigned int uY, unsigned int uTextureID)
{
//int v5; // eax@4
int v6; // ebx@4
//int v7; // edx@5
int v8; // edx@6
//int v9; // edx@7
int v10; // edx@8
int v11; // edx@9
int v12; // esi@12
int v13; // esi@15
int v14; // edx@17
int v15; // esi@18
int v16; // edx@22
char v18; // zf@26
int v19; // [sp+10h] [bp-10h]@4
int v20; // [sp+18h] [bp-8h]@4
int v21; // [sp+1Ch] [bp-4h]@4
int v22; // [sp+28h] [bp+8h]@24
int v23; // [sp+2Ch] [bp+Ch]@22
int v24; // [sp+30h] [bp+10h]@11
int v25; // [sp+30h] [bp+10h]@22
unsigned int *pSurfacePtr;
unsigned int y,
x;
unsigned int uSrcColor,
uDstColor,
uAlpha;
cTexture *pTexture;
if (uTextureID != -1)
pTexture = &LODFile_Icons_LOD.aLODHeaders[uTextureID];
else pTexture = &pending_texture;
if (!_this->bSceneBegun || !pTexture)
return;
pSurfacePtr = (unsigned int *)(_this->pTargetSurface);
for (y = 0; y < pTexture->uTextureHeight; ++y)
{
if (y + uY < _this->uClipRectY)
continue;
if (y + uY >= _this->uClipRectW)
continue;
for (x = 0; x < pTexture->uTextureWidth; ++x)
{
if (x + uX < _this->uClipRectX)
continue;
if (x + uX >= _this->uClipRectZ)
continue;
uSrcColor = pTexture->pTruecolorPixels[y * pTexture->uTextureWidth + x];
uDstColor = pSurfacePtr[(y + uY) * _this->uTargetSurfacePitch + x + uX];
uAlpha = ((uSrcColor & 0xFF000000) >> 8) | ((uSrcColor & 0xFF000000) >> 16) | ((uSrcColor & 0xFF000000) >> 24);
pSurfacePtr[(y + uY) * _this->uTargetSurfacePitch + x + uX] = (uSrcColor & uAlpha) + (uDstColor & (0x00FFFFFF - uAlpha));
}
}
}
//----- (004A5EB2) --------------------------------------------------------
void Render_DrawIndexedTexture(struct BaseRender *_this, unsigned int uX, unsigned int uY, cTexture *pTexture)
{
//int v5; // eax@4
int v6; // ebx@4
//int v7; // edx@5
int v8; // edx@6
//int v9; // edx@7
int v10; // edx@8
int v11; // edx@9
int v12; // esi@12
int v13; // esi@15
int v14; // edx@17
int v15; // esi@18
int v16; // edx@22
char v18; // zf@26
int v19; // [sp+10h] [bp-10h]@4
int v20; // [sp+18h] [bp-8h]@4
int v21; // [sp+1Ch] [bp-4h]@4
int v22; // [sp+28h] [bp+8h]@24
int v23; // [sp+2Ch] [bp+Ch]@22
int v24; // [sp+30h] [bp+10h]@11
int v25; // [sp+30h] [bp+10h]@22
unsigned int *pSurfacePtr;
unsigned int y, i,
x;
unsigned int uSrcColor,
uDstColor;
#ifdef OLD_CODE
unsigned short packedPixel;
unsigned char unpackedPixels[4];
#endif
if (!_this->bSceneBegun || !pTexture)
return;
pSurfacePtr = (unsigned int *)(_this->pTargetSurface);
for (y = 0; y < pTexture->uTextureHeight; ++y)
{
if (y + uY < _this->uClipRectY)
continue;
if (y + uY >= _this->uClipRectW)
continue;
for (x = 0; x < pTexture->uTextureWidth; ++x)
{
if (x + uX < _this->uClipRectX)
continue;
if (x + uX >= _this->uClipRectZ)
continue;
uSrcColor = pTexture->pTruecolorPixels[y * pTexture->uTextureWidth + x];
uDstColor = pSurfacePtr[(y + uY) * _this->uTargetSurfacePitch + x + uX];
pSurfacePtr[(y + uY) * _this->uTargetSurfacePitch + x + uX] = uSrcColor;
}
}
}
//----- (004A6C4F) --------------------------------------------------------
void Render_DrawText(struct BaseRender *_this, unsigned int uOutX, unsigned int uOutY,
unsigned char *pFontPixels, unsigned int uCharWidth, unsigned int uCharHeight,
unsigned short *pFontPalette, unsigned int uMainColor, unsigned int uShadowColor)
{
unsigned int *pSurfacePtr;
unsigned char *pPixel;
int x, y;
if (!_this->bSceneBegun)
return;
pSurfacePtr = (unsigned int *)(_this->pTargetSurface);
pPixel = pFontPixels;
for (y = 0; y < uCharHeight; ++y)
for (x = 0; x < uCharWidth; ++x)
{
if (*pPixel++)
{
unsigned int uSrc = pFontPalette[pPixel[-1]] == 0x0000 ? uShadowColor : uMainColor;
pSurfacePtr[(uOutY + y) * _this->uTargetSurfacePitch + uOutX + x] = uSrc;
}
}
}
//----- (004A6274) --------------------------------------------------------
void Render_DrawTransparentTexture(struct BaseRender *_this, unsigned int uX, unsigned int uY, cTexture *pTexture)
{
int v5; // eax@4
int v6; // ebx@4
int v7; // edx@5
int v8; // edx@6
int v9; // edx@7
int v10; // edx@8
int v11; // edx@9
int v12; // esi@12
int v13; // esi@15
int v14; // edx@17
int v15; // esi@18
int v16; // ebx@22
char v18; // zf@28
int v19; // [sp+10h] [bp-10h]@4
int v20; // [sp+18h] [bp-8h]@4
int v21; // [sp+1Ch] [bp-4h]@4
int v22; // [sp+28h] [bp+8h]@24
int v23; // [sp+2Ch] [bp+Ch]@22
int v24; // [sp+30h] [bp+10h]@11
int v25; // [sp+30h] [bp+10h]@22
unsigned int *pSurfacePtr;
unsigned int x, y, i;
unsigned int uSrcColor,
uDstColor,
uAlpha;
if (!_this->bSceneBegun || !pTexture)
return;
pSurfacePtr = (unsigned int *)(_this->pTargetSurface);
for (y = 0; y < pTexture->uTextureHeight; ++y)
{
if (y + uY < _this->uClipRectY)
continue;
if (y + uY >= _this->uClipRectW)
continue;
for (x = 0; x < pTexture->uTextureWidth; ++x)
{
float src_alpha,
dst_alpha;
unsigned int dst_channel[3];
if (x + uX < _this->uClipRectX)
continue;
if (x + uX >= _this->uClipRectZ)
continue;
uSrcColor = pTexture->pTruecolorPixels[y * pTexture->uTextureWidth + x];
uDstColor = pSurfacePtr[(y + uY) * _this->uTargetSurfacePitch + x + uX];
src_alpha = (uSrcColor >> 24) / 255.0f;
dst_alpha = 1.0f - src_alpha; //(uDstColor >> 24) / 255.0f
dst_channel[0] = (unsigned char)(src_alpha * ((uSrcColor >> 16) & 0xFF) + dst_alpha * ((uDstColor >> 16) & 0xFF));
dst_channel[1] = (unsigned char)(src_alpha * ((uSrcColor >> 8) & 0xFF) + dst_alpha * ((uDstColor >> 8) & 0xFF));
dst_channel[2] = (unsigned char)(src_alpha * (uSrcColor & 0xFF) + dst_alpha * (uDstColor & 0xFF));
pSurfacePtr[(y + uY) * _this->uTargetSurfacePitch + x + uX] = 0xFF000000 |
(dst_channel[0] << 16) |
(dst_channel[1] << 8) |
dst_channel[2];
}
}
}
void Render_DrawTransparentRect(struct BaseRender *_this, unsigned int uOutX, unsigned int uOutY,
unsigned int uSrcX, unsigned int uSrcY, unsigned int uSrcWidth, unsigned int uSrcHeight,
cTexture *pTexture)
{
unsigned int *pSurfacePtr;
unsigned int x, y;
unsigned int uSrcColor,
uDstColor;
if (!_this->bSceneBegun || !pTexture)
return;
pSurfacePtr = (unsigned int *)(_this->pTargetSurface);
for (y = 0; y < uSrcHeight; ++y)
for (x = 0; x < uSrcWidth; ++x)
{
float src_alpha,
dst_alpha;
unsigned int dst_channel[3];
uSrcColor = pTexture->pTruecolorPixels[(y + uSrcY) * pTexture->uTextureWidth + x + uSrcX];
uDstColor = pSurfacePtr[(y + uOutY) * _this->uTargetSurfacePitch + x + uOutX];
src_alpha = (uSrcColor >> 24) / 255.0f;
dst_alpha = 1.0f - src_alpha; //(uDstColor >> 24) / 255.0f
dst_channel[0] = (unsigned char)(src_alpha * ((uSrcColor >> 16) & 0xFF) + dst_alpha * ((uDstColor >> 16) & 0xFF));
dst_channel[1] = (unsigned char)(src_alpha * ((uSrcColor >> 8) & 0xFF) + dst_alpha * ((uDstColor >> 8) & 0xFF));
dst_channel[2] = (unsigned char)(src_alpha * (uSrcColor & 0xFF) + dst_alpha * (uDstColor & 0xFF));
pSurfacePtr[(y + uOutY) * _this->uTargetSurfacePitch + x + uOutX] = 0xFF000000 |
(dst_channel[0] << 16) |
(dst_channel[1] << 8) |
dst_channel[2];
}
}
//----- (004A172E) --------------------------------------------------------
int Render_LockFrontBuffer(struct BaseRender *_this, void **ppOutSurfacePtr, unsigned int *pOutSurfaceWidth)
{
DDSURFACEDESC2 ddsd2;
if (dword_F79D70 != 4)
{
memset(&ddsd2, 0, sizeof(DDSURFACEDESC2));
ddsd2.dwSize = sizeof(DDSURFACEDESC2);
LockSurface_DDraw4(_this->pdds4_FrontBuffer, &ddsd2, 1);
*ppOutSurfacePtr = ddsd2.lpSurface;
*pOutSurfaceWidth = ddsd2.lPitch / (ddsd2.ddpfPixelFormat.dwRGBBitCount / 8);
}
else
__asm int 3;
return *pOutSurfaceWidth;
}
//----- (004A527D) --------------------------------------------------------
Result::Code RenderDirect3D3::EndScene()
{
if (this->pRenderD3D3)
return RenderD3D3_EndScene(this->pRenderD3D3) == S_OK ? Result::Success : Result::Generic;
if (!this->bSceneBegun)
return Result::Generic;
this->bSceneBegun--;
this->pTargetSurface = 0;
this->uTargetSurfacePitch = 0;
this->dword_000018 = 0;
Render_UnlockBackBuffer(this);
return Result::Success;
}
//----- (004A16E1) --------------------------------------------------------
void *Render_UnlockBackBuffer(struct BaseRender *_this)
{
IDirectDrawSurface *v1;
HRESULT hr;
char local_0[128];
if (dword_F79D70 != 4)
v1 = (IDirectDrawSurface *)_this->pdds4_BackBuffer;
else
v1 = (IDirectDrawSurface *)_this->pdds2_BackBuffer;
hr = _this->pdds4_BackBuffer->Unlock(0);
return CheckHRESULT((void **)local_0, hr, "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Screen16.cpp", __LINE__, 0);
}
void Render_DrawRGBTexture_New(struct BaseRender *_this, unsigned int uX, unsigned int uY, unsigned int uTextureID)
{
unsigned int *pSurfacePtr;
unsigned int uColor;
int x, y;
cTexture *pTexture;
if (!_this->bSceneBegun)
return;
if (uTextureID == -1)
return;
pTexture = &LODFile_Icons_LOD.aLODHeaders[uTextureID];
pSurfacePtr = (unsigned int *)(_this->pTargetSurface);
for (y = 0; y < pTexture->uTextureHeight; ++y)
{
unsigned int startX,
endX;
if (y + uY < _this->uClipRectY)
continue;
else if (y + uY >= _this->uClipRectW)
return;
startX = _max(_this->uClipRectX, uX);
endX = _min(_min(_this->uClipRectZ, uX + pTexture->uTextureWidth), 640);
memcpy(pSurfacePtr + (y + uY) * _this->uTargetSurfacePitch + startX,
pTexture->pTruecolorPixels + y * pTexture->uTextureWidth + startX - uX,
(endX - startX) * 4);
}
}
//----- (004A5BE3) --------------------------------------------------------
void Render_DrawRGBTexture(struct BaseRender *_this, unsigned int uX, unsigned int uY, class cPCXTexture *pTexture)
{
unsigned int *pSurfacePtr;
unsigned int uColor;
int v5; // edi@3
unsigned short *v6; // esi@3
int x, y;
int v7; // ebx@4
int v8; // eax@5
int v9; // ebx@5
int v10; // eax@6
int v11; // eax@7
int v12; // ebx@8
int v13; // eax@10
int v14; // edi@11
int v15; // eax@14
int v16; // ebx@17
int v17; // eax@23
char v18; // zf@25
int v19; // [sp+10h] [bp-8h]@3
int v20; // [sp+14h] [bp-4h]@3
int v21; // [sp+20h] [bp+8h]@16
int v22; // [sp+20h] [bp+8h]@21
int v23; // [sp+24h] [bp+Ch]@21
int v24; // [sp+28h] [bp+10h]@3
if (!_this->bSceneBegun)
return;
if (!pTexture)
return;
pSurfacePtr = (unsigned int *)(_this->pTargetSurface);
for (y = 0; y < pTexture->uHeight; ++y)
{
unsigned int startX,
endX;
if (y + uY < _this->uClipRectY)
continue;
else if (y + uY >= _this->uClipRectW)
return;
startX = _max(_this->uClipRectX, uX);
endX = _min(_min(_this->uClipRectZ, uX + pTexture->uWidth), 640);
memcpy(pSurfacePtr + (y + uY) * _this->uTargetSurfacePitch + startX,
pTexture->pPixels + y * pTexture->uWidth + startX - uX,
(endX - startX) * 4);
}
}
//----- (004A05F3) --------------------------------------------------------
Result::Code RenderDirect3D3::Initialize(OSWindow *pOutputWindow)
{
int v2; // esi@1
int v7; // ecx@5
signed int v8; // eax@7
int v11; // eax@14
int v12; // eax@18
int v13; // eax@22
int v14; // eax@24
int v17; // eax@26
int v20; // eax@35
int v21; // eax@35
int v23; // eax@38
int v25; // ecx@38
D3DDEVICEDESC d3ddd2;
//int v28; // [sp+Ch] [bp-300h]@24
DDSURFACEDESC2 ddsd2;
//int v29; // [sp+108h] [bp-204h]@37
//int v30; // [sp+12Ch] [bp-1E0h]@38
D3DDEVICEDESC d3ddd1;
/*int Dst; // [sp+184h] [bp-188h]@24
unsigned int v32; // [sp+230h] [bp-DCh]@24
unsigned int v33; // [sp+234h] [bp-D8h]@24
unsigned int v34; // [sp+238h] [bp-D4h]@26
unsigned int v35; // [sp+23Ch] [bp-D0h]@26*/
int v36; // [sp+280h] [bp-8Ch]@35
int v37; // [sp+284h] [bp-88h]@35
int v38; // [sp+288h] [bp-84h]@35
int v39; // [sp+28Ch] [bp-80h]@35
int v40; // [sp+2C0h] [bp-4Ch]@35
int v41; // [sp+2C4h] [bp-48h]@35
int v42; // [sp+2E8h] [bp-24h]@35
unsigned int v43; // [sp+2FCh] [bp-10h]@2
int v44; // [sp+308h] [bp-4h]@2
unsigned int uDeviceCaps;
HRESULT hr;
pParty->dword_007778 |= 2;
v2 = (int)this;
flt_6BE3A0 = 0.55000001;
ClipCursor(0);
Viewport_fn2(pOldViewport, 36044);
InitializeCameraAndViewport();
this->dword_040108 = 0;
this->dword_040110 = 0;
sub_49FE05(this);
this->pdd4 = 0;
this->pdds4_FrontBuffer = 0;
this->pdds4_BackBuffer = 0;
this->dword_040098 = 0;
InitializeZBuffer();
this->pWindow = pOutputWindow;
if (this->bUseDirect3D)
{
this->pRenderD3D3 = NamedMemAlloc(RenderD3D3, 1, "Old D3D Render");
v43 = (int)this->pRenderD3D3;
v44 = 0;
if (this->pRenderD3D3)
RenderD3D3_FindAvailableDevices(this->pRenderD3D3);
v44 = -1;
v7 = (int)this->pRenderD3D3->pAvailableDevices;
if (this->pRenderD3D3->pAvailableDevices[this->uDesiredDirect3DDevice].bDeviceIsValid &&
this->uDesiredDirect3DDevice != 1)
{
v8 = RenderD3D3_Initialize(this->pRenderD3D3, this->uDesiredDirect3DDevice, true, this->pWindow->GetAPIHandle());
this->uAcquiredDirect3DDevice = this->uDesiredDirect3DDevice;
}
else if (this->pRenderD3D3->pAvailableDevices[0].bDeviceIsValid)
{
v8 = RenderD3D3_Initialize(this->pRenderD3D3, 0, true, this->pWindow->GetAPIHandle());
this->uAcquiredDirect3DDevice = 0;
}
else
erroneous_printf("There aren't any D3D devices to init.");
if (!v8)
erroneous_printf("D3Drend->Init failed.");
this->pdd4 = this->pRenderD3D3->pHostInterface;
this->pdds4_FrontBuffer = this->pRenderD3D3->pFontBuffer;
this->pdds4_BackBuffer = this->pRenderD3D3->pBackBuffer;
this->dword_040098 = 0;
uDeviceCaps = RenderD3D3_GetDeviceCaps(this->pRenderD3D3);
if (uDeviceCaps & CAPS_NO_CAPS)
{
v43 = *(_DWORD *)(v2 + 262280);
if ( v43 )
{
v11 = sub_49DC90(v43);
operator_delete((void *)v43);
}
*(_DWORD *)(v2 + 262280) = 0;
*(_DWORD *)(v2 + 262292) = 0;
*(_DWORD *)(v2 + 262288) = 0;
*(_DWORD *)(v2 + 262284) = 0;