-
Notifications
You must be signed in to change notification settings - Fork 1
/
RenderSurfaceParametersHook.cpp
1125 lines (911 loc) · 38.2 KB
/
RenderSurfaceParametersHook.cpp
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
/* Version: MPL 1.1/LGPL 3.0
*
* "The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is the Oblivion Graphics Extender, short OBGE.
*
* The Initial Developer of the Original Code is
* Ethatron <[email protected]>. Portions created by The Initial
* Developer are Copyright (C) 2011 The Initial Developer.
* All Rights Reserved.
*
* Contributor(s):
* Timeslip (Version 1)
* scanti (Version 2)
* IlmrynAkios (Version 3)
*
* Alternatively, the contents of this file may be used under the terms
* of the GNU Library General Public License Version 3 license (the
* "LGPL License"), in which case the provisions of LGPL License are
* applicable instead of those above. If you wish to allow use of your
* version of this file only under the terms of the LGPL License and not
* to allow others to use your version of this file under the MPL,
* indicate your decision by deleting the provisions above and replace
* them with the notice and other provisions required by the LGPL License.
* If you do not delete the provisions above, a recipient may use your
* version of this file under either the MPL or the LGPL License."
*/
#include <assert.h>
#include "RenderSurfaceParametersHook.hpp"
#include "windows.h"
#include "obse_common/SafeWrite.h"
#include "GlobalSettings.h"
#include "OBSEShaderInterface.h"
#include "Constants.h"
#include "D3D9.hpp"
#include "D3D9Device.hpp"
#include "D3D9Identifiers.hpp"
#include "Hooking/detours/detours.h"
static global<float> ReflectionMapSize(0, NULL, "ScreenBuffers", "iReflectionMapSize");
static global<int> WaterHeightMapSize(0, NULL, "ScreenBuffers", "iWaterHeightMapSize");
static global<int> WaterDisplacementMapSize(0, NULL, "ScreenBuffers", "iWaterDisplacementMapSize");
static global<int> AutoGenerateMipMaps(D3DTEXF_LINEAR, NULL, "ScreenBuffers", "iAutoGenerateMipMaps");
static global<int> RendererWidth(0, "Oblivion.ini", "Display", "iSize W");
static global<bool> UseWaterReflectionsMisc(0, "Oblivion.ini", "Water", "bUseWaterReflectionsMisc");
static global<bool> UseWaterReflectionsStatics(0, "Oblivion.ini", "Water", "bUseWaterReflectionsStatics");
static global<bool> UseWaterReflectionsTrees(0, "Oblivion.ini", "Water", "bUseWaterReflectionsTrees");
static global<bool> UseWaterReflectionsActors(0, "Oblivion.ini", "Water", "bUseWaterReflectionsActors");
static global<int> SurfaceTextureSize(128, "Oblivion.ini", "Water", "uSurfaceTextureSize");
static global<bool> UseWaterHiRes(0, "Oblivion.ini", "Water", "bUseWaterHiRes");
static global<float> FarDistance(283840.0f, "Oblivion.ini", "Display", "fFarDistance");
/* ------------------------------------------------------------------------------------------------- */
class Anonymous {
public:
float TrackFarPlane();
void TrackFrustum(NiFrustum *kFrustum);
void TrackCamera(float *kWorldLoc, float *kWorldDir, float *kWorldUp, float *kWorldRight, NiFrustum *kFrustum, void *kPort);
void TrackCombinerPass(int unk1);
#ifndef OBGE_NOSHADER
void TrackReflectionCull(int unk1);
void TrackReflectionPass(int unk1, int unk2);
void TrackWaterSurfacePass();
void TrackWaterSurfaceLoop();
void TrackWaterGeometryPass(int unk1, int unk2);
bool TrackShadowPass();
bool TrackShadowCanopyPass();
bool TrackHDRAlphaPass(int unk1, int unk2);
void TrackCameraPass(int unk1, int unk2);
void TrackEffectsPass(int unk1, int unk2);
void TrackHDRPass(int unk1, int unk2, int unk3, int unk4);
void TrackBlurPass(int unk1, int unk2, int unk3, int unk4);
void TrackHitPass(int unk1, int unk2, int unk3, int unk4);
void TrackMenuPass(int unk1, int unk2, int unk3, int unk4);
void TrackRefractionPass(int unk1, int unk2, int unk3, int unk4);
void TrackNighteyePass(int unk1, int unk2, int unk3, int unk4);
void TrackWaterDisplacementPass(int unk1, int unk2, int unk3, int unk4);
void TrackWaterHeightmapPass(int unk1, int unk2, int unk3, int unk4);
bool TrackVideoPass(int unk1, int unk2);
void TrackMiscPass(int unk1);
#endif
public:
void *TrackRenderedSurface(v1_2_416::NiDX9Renderer *renderer, int Width, int Height, int Flags, D3DFORMAT Format, enum SurfaceIDs SurfaceTypeID);
};
float (__thiscall Anonymous::* GetFarPlane)()/* =
(void (__thiscall TES::*)(int, int))00410EE0*/;
void (__thiscall Anonymous::* SetFrustum)(NiFrustum *)/* =
(void (__thiscall TES::*)(int, int))0070C190*/;
void (__thiscall Anonymous::* SetCamera)(float *, float *, float *, float *, NiFrustum *, void *)/* =
(void (__thiscall TES::*)(int, int))00762640*/;
void (__thiscall Anonymous::* CombinerPass)(int)/* =
(void (__thiscall TES::*)(int, int))0040C830*/;
#ifndef OBGE_NOSHADER
void (__thiscall Anonymous::* ReflectionCull)(int)/* =
(void (__thiscall TES::*)(int, int))0049CBF0*/;
void (__thiscall Anonymous::* ReflectionPass)(int, int)/* =
(void (__thiscall TES::*)(int, int))0x0049BEF0*/;
void (__thiscall Anonymous::* WaterSurfaceLoop)()/* =
(void (__thiscall TES::*)(int, int))0x0049A200*/;
void (__thiscall Anonymous::* WaterSurfacePass)()/* =
(void (__thiscall TES::*)(int, int))0x0049D7B0*/;
void (__thiscall Anonymous::* WaterGeometryPass)(int, int)/* =
(void (__thiscall TES::*)(int, int))0x0049B930*/;
bool (__thiscall Anonymous::* ShadowPass)()/* =
(void (__thiscall TES::*)(int, int))0x004073D0*/;
bool (__thiscall Anonymous::* ShadowCanopyPass)()/* =
(void (__thiscall TES::*)(int, int))0x004826F0*/;
bool (__thiscall Anonymous::* HDRAlphaPass)(int, int)/* =
(void (__thiscall TES::*)(int, int))0x007AAA30*/;
void (__thiscall Anonymous::* HDRPass)(int, int, int, int)/* =
(void (__thiscall TES::*)(int, int))0x007BDFC0*/;
void (__thiscall Anonymous::* BlurPass)(int, int, int, int)/* =
(void (__thiscall TES::*)(int, int))0x007B0170*/;
void (__thiscall Anonymous::* HitPass)(int, int, int, int)/* =
(void (__thiscall TES::*)(int, int))0x007EB3D0*/;
void (__thiscall Anonymous::* MenuPass)(int, int, int, int)/* =
(void (__thiscall TES::*)(int, int))0x007B18C0*/;
void (__thiscall Anonymous::* RefractionPass)(int, int, int, int)/* =
(void (__thiscall TES::*)(int, int))0x00800440*/;
void (__thiscall Anonymous::* NighteyePass)(int, int, int, int)/* =
(void (__thiscall TES::*)(int, int))0x007F5120*/;
void (__thiscall Anonymous::* WaterDisplacementPass)(int, int, int, int)/* =
(void (__thiscall TES::*)(int, int))0x007DE8A0*/;
void (__thiscall Anonymous::* WaterHeightmapPass)(int, int, int, int)/* =
(void (__thiscall TES::*)(int, int))0x007E17D0*/;
bool (__thiscall Anonymous::* VideoPass)(int, int)/* =
(void (__thiscall TES::*)(int, int))0x004106C0*/;
void (__thiscall Anonymous::* MiscPass)(int)/* =
(void (__thiscall TES::*)(int, int))0x0057F170*/;
void (__cdecl * IdlePass)(int, int)/* =
(void (__thiscall TES::*)(int, int))0x007D71C0*/;
bool (__cdecl * IsRunning)(int, int)/* =
(void (__thiscall TES::*)(int, int))0x004F8DB0*/;
#endif
float (__thiscall Anonymous::* TrackFarPlane)()/* =
(void (__thiscall TES::*)(int, int))00410EE0*/;
void (__thiscall Anonymous::* TrackFrustum)(NiFrustum *)/* =
(void (__thiscall TES::*)(int, int))0070C190*/;
void (__thiscall Anonymous::* TrackCamera)(float *, float *, float *, float *, NiFrustum *, void *)/* =
(void (__thiscall TES::*)(int, int))00762640*/;
void (__thiscall Anonymous::* TrackCombinerPass)(int)/* =
(void (__thiscall TES::*)(int, int))0040C830*/;
#ifndef OBGE_NOSHADER
void (__thiscall Anonymous::* TrackReflectionCull)(int)/* =
(void (__thiscall TES::*)(int, int))0049CBF0*/;
void (__thiscall Anonymous::* TrackReflectionPass)(int, int)/* =
(void (__thiscall TES::*)(int, int))0x0049BEF0*/;
void (__thiscall Anonymous::* TrackWaterSurfaceLoop)()/* =
(void (__thiscall TES::*)(int, int))0x0049A200*/;
void (__thiscall Anonymous::* TrackWaterSurfacePass)()/* =
(void (__thiscall TES::*)(int, int))0x0049D7B0*/;
void (__thiscall Anonymous::* TrackWaterGeometryPass)(int, int)/* =
(void (__thiscall TES::*)(int, int))0x0049B930*/;
bool (__thiscall Anonymous::* TrackShadowPass)()/* =
(void (__thiscall TES::*)(int, int))0x004073D0*/;
bool (__thiscall Anonymous::* TrackShadowCanopyPass)()/* =
(void (__thiscall TES::*)(int, int))0x004826F0*/;
bool (__thiscall Anonymous::* TrackHDRAlphaPass)(int, int)/* =
(void (__thiscall TES::*)(int, int))0x007AAA30*/;
void (__thiscall Anonymous::* TrackHDRPass)(int, int, int, int)/* =
(void (__thiscall TES::*)(int, int))0x007BDFC0*/;
void (__thiscall Anonymous::* TrackBlurPass)(int, int, int, int)/* =
(void (__thiscall TES::*)(int, int))0x007B0170*/;
void (__thiscall Anonymous::* TrackHitPass)(int, int, int, int)/* =
(void (__thiscall TES::*)(int, int))0x007EB3D0*/;
void (__thiscall Anonymous::* TrackMenuPass)(int, int, int, int)/* =
(void (__thiscall TES::*)(int, int))0x007B18C0*/;
void (__thiscall Anonymous::* TrackRefractionPass)(int, int, int, int)/* =
(void (__thiscall TES::*)(int, int))0x00800440*/;
void (__thiscall Anonymous::* TrackNighteyePass)(int, int, int, int)/* =
(void (__thiscall TES::*)(int, int))0x007F5120*/;
void (__thiscall Anonymous::* TrackWaterDisplacementPass)(int, int, int, int)/* =
(void (__thiscall TES::*)(int, int))0x007DE8A0*/;
void (__thiscall Anonymous::* TrackWaterHeightmapPass)(int, int, int, int)/* =
(void (__thiscall TES::*)(int, int))0x007E17D0*/;
bool (__thiscall Anonymous::* TrackVideoPass)(int, int)/* =
(void (__thiscall TES::*)(int, int))0x004106C0*/;
void (__thiscall Anonymous::* TrackMiscPass)(int)/* =
(void (__thiscall TES::*)(int, int))0x0057F170*/;
#endif
float Anonymous::TrackFarPlane() {
float fz = (this->*GetFarPlane)();
if (fz == 283840.0f) {
float fd = FarDistance.Get();
if (fz < fd)
fz = fd;
}
return fz;
}
void Anonymous::TrackFrustum(NiFrustum *kFrustum) {
NiCamera *cam = (NiCamera *)this;
(this->*SetFrustum)(kFrustum);
}
void Anonymous::TrackCamera(float *kWorldLoc, float *kWorldDir, float *kWorldUp, float *kWorldRight, NiFrustum *kFrustum, void *kPort) {
Constants.UpdateCamera(kWorldLoc, kWorldDir, kWorldUp, kWorldRight);
(this->*SetCamera)(kWorldLoc, kWorldDir, kWorldUp, kWorldRight, kFrustum, kPort);
}
void Anonymous::TrackCombinerPass(int unk1) {
#ifndef OBGE_NOSHADER
enum OBGEPass previousPass = currentPass;
currentPass = OBGEPASS_MAIN;
#endif
if (frame_log)
frame_log->Message("OD3D9: CombinerPass started");
// else
// _MESSAGE("OD3D9: CombinerPass started");
{
/* right location? */
Constants.Update();
}
(this->*CombinerPass)(unk1);
if (frame_log)
frame_log->Message("OD3D9: CombinerPass finished");
// else
// _MESSAGE("OD3D9: CombinerPass finished");
#ifndef OBGE_NOSHADER
currentPass = previousPass;
#endif
}
#ifndef OBGE_NOSHADER
void Anonymous::TrackReflectionCull(int unk1) {
*((char *)0x00B07068) = UseWaterReflectionsActors.Get(); // boolUseWaterReflectionsActors
*((char *)0x00B07070) = UseWaterReflectionsTrees.Get(); // boolUseWaterReflectionsTrees
*((char *)0x00B07078) = UseWaterReflectionsStatics.Get(); // boolUseWaterReflectionsStatics
*((char *)0x00B07080) = UseWaterReflectionsMisc.Get(); // boolUseWaterReflectionsMisc
(this->*ReflectionCull)(unk1);
}
void Anonymous::TrackReflectionPass(int unk1, int unk2) {
enum OBGEPass previousPass = currentPass;
currentPass = OBGEPASS_REFLECTION;
if (frame_log)
frame_log->Message("OD3D9: ReflectionPass started");
// else
// _MESSAGE("OD3D9: ReflectionPass started");
(this->*ReflectionPass)(unk1, unk2);
if (frame_log)
frame_log->Message("OD3D9: ReflectionPass finished");
// else
// _MESSAGE("OD3D9: ReflectionPass finished");
currentPass = previousPass;
}
void Anonymous::TrackWaterSurfaceLoop() {
enum OBGEPass previousPass = currentPass;
currentPass = OBGEPASS_WATER;
if (frame_log)
frame_log->Message("OD3D9: WaterSurfaceLoop started");
// else
// _MESSAGE("OD3D9: WaterSurfaceLoop started");
(this->*WaterSurfaceLoop)();
if (frame_log)
frame_log->Message("OD3D9: WaterSurfaceLoop finished");
// else
// _MESSAGE("OD3D9: WaterSurfaceLoop finished");
currentPass = previousPass;
}
void Anonymous::TrackWaterSurfacePass() {
enum OBGEPass previousPass = currentPass;
currentPass = OBGEPASS_WATER;
if (frame_log)
frame_log->Message("OD3D9: WaterSurfacePass started");
// else
// _MESSAGE("OD3D9: WaterSurfacePass started");
(this->*WaterSurfacePass)();
if (frame_log)
frame_log->Message("OD3D9: WaterSurfacePass finished");
// else
// _MESSAGE("OD3D9: WaterSurfacePass finished");
currentPass = previousPass;
}
void Anonymous::TrackWaterGeometryPass(int unk1, int unk2) {
enum OBGEPass previousPass = currentPass;
currentPass = OBGEPASS_WATER;
if (frame_log)
frame_log->Message("OD3D9: WaterGeometryPass started");
// else
// _MESSAGE("OD3D9: WaterGeometryPass started");
(this->*WaterGeometryPass)(unk1, unk2);
if (frame_log)
frame_log->Message("OD3D9: WaterGeometryPass finished");
// else
// _MESSAGE("OD3D9: WaterGeometryPass finished");
currentPass = previousPass;
}
bool Anonymous::TrackShadowPass() {
enum OBGEPass previousPass = currentPass;
currentPass = OBGEPASS_SHADOW;
if (frame_log)
frame_log->Message("OD3D9: ShadowPass started");
// else
// _MESSAGE("OD3D9: ShadowPass started");
bool r = (this->*ShadowPass)();
if (frame_log)
frame_log->Message("OD3D9: ShadowPass finished");
// else
// _MESSAGE("OD3D9: ShadowPass finished");
currentPass = previousPass;
return r;
}
bool Anonymous::TrackShadowCanopyPass() {
enum OBGEPass previousPass = currentPass;
currentPass = OBGEPASS_SHADOW;
if (frame_log)
frame_log->Message("OD3D9: ShadowCanopy started");
// else
// _MESSAGE("OD3D9: ShadowCanopy started");
bool r = (this->*ShadowCanopyPass)();
if (frame_log)
frame_log->Message("OD3D9: ShadowCanopy finished");
// else
// _MESSAGE("OD3D9: ShadowCanopy finished");
currentPass = previousPass;
return r;
}
bool Anonymous::TrackHDRAlphaPass(int unk1, int unk2) {
enum OBGEPass previousPass = currentPass;
currentPass = OBGEPASS_HDR;
if (frame_log)
frame_log->Message("OD3D9: HDRAlphaPass started");
// else
// _MESSAGE("OD3D9: HDRAlphaPass started");
bool r = (this->*HDRAlphaPass)(unk1, unk2);
if (frame_log)
frame_log->Message("OD3D9: HDRAlphaPass finished");
// else
// _MESSAGE("OD3D9: HDRAlphaPass finished");
currentPass = previousPass;
return r;
}
void Anonymous::TrackHDRPass(int unk1, int unk2, int unk3, int unk4) {
enum OBGEPass previousPass = currentPass;
currentPass = OBGEPASS_HDR;
if (frame_log)
frame_log->Message("OD3D9: HDRPass started");
// else
// _MESSAGE("OD3D9: HDRPass started");
(this->*HDRPass)(unk1, unk2, unk3, unk4);
if (frame_log)
frame_log->Message("OD3D9: HDRPass finished");
// else
// _MESSAGE("OD3D9: HDRPass finished");
currentPass = previousPass;
}
void Anonymous::TrackBlurPass(int unk1, int unk2, int unk3, int unk4) {
enum OBGEPass previousPass = currentPass;
currentPass = OBGEPASS_POST;
if (frame_log)
frame_log->Message("OD3D9: BlurPass started");
// else
// _MESSAGE("OD3D9: BlurPass started");
(this->*BlurPass)(unk1, unk2, unk3, unk4);
if (frame_log)
frame_log->Message("OD3D9: BlurPass finished");
// else
// _MESSAGE("OD3D9: BlurPass finished");
currentPass = previousPass;
}
void Anonymous::TrackHitPass(int unk1, int unk2, int unk3, int unk4) {
enum OBGEPass previousPass = currentPass;
currentPass = OBGEPASS_POST;
if (frame_log)
frame_log->Message("OD3D9: HitPass started");
// else
// _MESSAGE("OD3D9: HitPass started");
(this->*HitPass)(unk1, unk2, unk3, unk4);
if (frame_log)
frame_log->Message("OD3D9: HitPass finished");
// else
// _MESSAGE("OD3D9: HitPass finished");
currentPass = previousPass;
}
void Anonymous::TrackMenuPass(int unk1, int unk2, int unk3, int unk4) {
enum OBGEPass previousPass = currentPass;
currentPass = OBGEPASS_POST;
if (frame_log)
frame_log->Message("OD3D9: MenuPass started");
// else
// _MESSAGE("OD3D9: MenuPass started");
(this->*MenuPass)(unk1, unk2, unk3, unk4);
if (frame_log)
frame_log->Message("OD3D9: MenuPass finished");
// else
// _MESSAGE("OD3D9: MenuPass finished");
currentPass = previousPass;
}
void Anonymous::TrackRefractionPass(int unk1, int unk2, int unk3, int unk4) {
enum OBGEPass previousPass = currentPass;
currentPass = OBGEPASS_POST;
if (frame_log)
frame_log->Message("OD3D9: RefractionPass started");
// else
// _MESSAGE("OD3D9: RefractionPass started");
(this->*RefractionPass)(unk1, unk2, unk3, unk4);
if (frame_log)
frame_log->Message("OD3D9: RefractionPass finished");
// else
// _MESSAGE("OD3D9: RefractionPass finished");
currentPass = previousPass;
}
void Anonymous::TrackNighteyePass(int unk1, int unk2, int unk3, int unk4) {
enum OBGEPass previousPass = currentPass;
currentPass = OBGEPASS_POST;
if (frame_log)
frame_log->Message("OD3D9: NighteyePass started");
// else
// _MESSAGE("OD3D9: NighteyePass started");
(this->*NighteyePass)(unk1, unk2, unk3, unk4);
if (frame_log)
frame_log->Message("OD3D9: NighteyePass finished");
// else
// _MESSAGE("OD3D9: NighteyePass finished");
currentPass = previousPass;
}
void Anonymous::TrackWaterDisplacementPass(int unk1, int unk2, int unk3, int unk4) {
enum OBGEPass previousPass = currentPass;
currentPass = OBGEPASS_WATERDISPLACEMENT;
if (frame_log)
frame_log->Message("OD3D9: WaterDisplacementPass started");
// else
// _MESSAGE("OD3D9: WaterDisplacementPass started");
(this->*WaterDisplacementPass)(unk1, unk2, unk3, unk4);
if (frame_log)
frame_log->Message("OD3D9: WaterDisplacementPass finished");
// else
// _MESSAGE("OD3D9: WaterDisplacementPass finished");
currentPass = previousPass;
}
void Anonymous::TrackWaterHeightmapPass(int unk1, int unk2, int unk3, int unk4) {
enum OBGEPass previousPass = currentPass;
currentPass = OBGEPASS_WATERHEIGHTMAP;
if (frame_log)
frame_log->Message("OD3D9: WaterHeightmapPass started");
// else
// _MESSAGE("OD3D9: WaterHeightmapPass started");
(this->*WaterHeightmapPass)(unk1, unk2, unk3, unk4);
if (frame_log)
frame_log->Message("OD3D9: WaterHeightmapPass finished");
// else
// _MESSAGE("OD3D9: WaterHeightmapPass finished");
currentPass = previousPass;
}
bool Anonymous::TrackVideoPass(int unk1, int unk2) {
/* bink splash-video and possibly all bink playbacks
*/
enum OBGEPass previousPass = currentPass;
currentPass = OBGEPASS_VIDEO;
if (frame_log)
frame_log->Message("OD3D9: VideoPass started");
// else
// _MESSAGE("OD3D9: VideoPass started");
bool r = (this->*VideoPass)(unk1, unk2);
if (frame_log)
frame_log->Message("OD3D9: VideoPass finished");
// else
// _MESSAGE("OD3D9: VideoPass finished");
currentPass = previousPass;
return r;
}
void Anonymous::TrackMiscPass(int unk1) {
/* occurs as early as the splash-video
*/
enum OBGEPass previousPass = currentPass;
// currentPass = OBGEPASS_UNKNOWN;
currentPass = OBGEPASS_MAIN;
if (frame_log)
frame_log->Message("OD3D9: MiscPass started");
// else
// _MESSAGE("OD3D9: MiscPass started");
(this->*MiscPass)(unk1);
if (frame_log)
frame_log->Message("OD3D9: MiscPass finished");
// else
// _MESSAGE("OD3D9: MiscPass finished");
currentPass = previousPass;
}
void __cdecl TrackIdlePass(int unk1, int unk2) {
/* occurs as early as the menu
*/
enum OBGEPass previousPass = currentPass;
// currentPass = OBGEPASS_UNKNOWN;
currentPass = OBGEPASS_UNKNOWN;
if (frame_log)
frame_log->Message("OD3D9: IdlePass started");
// else
// _MESSAGE("OD3D9: IdlePass started");
// Menu?
IdlePass(unk1, unk2);
if (frame_log)
frame_log->Message("OD3D9: IdlePass finished");
// else
// _MESSAGE("OD3D9: IdlePass finished");
currentPass = previousPass;
}
bool __cdecl TrackIsRunning(int unk1, int unk2) {
bool res = false;
__try {
res = IsRunning(unk1, unk2);
}
__except (EXCEPTION_EXECUTE_HANDLER) {
res = false;
}
return res;
}
#endif
/* ------------------------------------------------------------------------------------------------- */
void *(__thiscall Anonymous::* GetRenderedSurface)(v1_2_416::NiDX9Renderer *, int Width, int Height, int Flags, D3DFORMAT Format, enum SurfaceIDs SurfaceTypeID)/* =
(void *(__thiscall *)(v1_2_416::NiDX9Renderer *, int Width, int Height, int Flags, int Format, enum SurfaceIDs SurfaceTypeID))0x007C1B50*/;
void *(__thiscall Anonymous::* TrackRenderedSurface)(v1_2_416::NiDX9Renderer *renderer, int Width, int Height, int Flags, D3DFORMAT Format, enum SurfaceIDs SurfaceTypeID)/* =
(void (__thiscall *)(v1_2_416::NiDX9Renderer *renderer, int Width, int Height, int Flags, int Format, enum SurfaceIDs SurfaceTypeID))0x007C1B50*/;
void *Anonymous::TrackRenderedSurface(v1_2_416::NiDX9Renderer *renderer, int Width, int Height, int Flags, D3DFORMAT Format, enum SurfaceIDs SurfaceTypeID) {
// assert(false);
#if 0 /* apparently the surface-type is always 0 here! Oblivion does not pass any!
* lok at the parameters function below to detect surface-types
*/
const char *SurfaceTypeName = "unknown";
switch (SurfaceTypeID) {
case SURFACE_ID_HDR0: SurfaceTypeName = "HDR-BoxSample Surface"; break;
case SURFACE_ID_HDR1: SurfaceTypeName = "HDR-PointSample Surface"; break;
case SURFACE_ID_HDR2: SurfaceTypeName = "HDR-Intermediate Surface"; break;
case SURFACE_ID_HDR3: SurfaceTypeName = "HDR-Origin Surface"; break;
case SURFACE_ID_HDR4: SurfaceTypeName = "HDR-Destination Surface"; break;
case SURFACE_ID_UNK5: break;
case SURFACE_ID_WATER6: SurfaceTypeName = "Water pre-heightmap Surface"; break;
case SURFACE_ID_WATER7: SurfaceTypeName = "Water pre-displacement Surface"; break;
case SURFACE_ID_WATER8: SurfaceTypeName = "Water[8] Surface"; break;
case SURFACE_ID_WATER9: SurfaceTypeName = "Water[9] Surface"; break;
case SURFACE_ID_WATER10: SurfaceTypeName = "Water[10] Surface"; break;
case SURFACE_ID_WATER11: SurfaceTypeName = "Water[11] Surface"; break;
case SURFACE_ID_WATER12: SurfaceTypeName = "Water[12] Surface"; break;
case SURFACE_ID_REFL13: SurfaceTypeName = "First Reflection Surface"; break;
case SURFACE_ID_REFL14: SurfaceTypeName = "Second Reflection Surface"; break;
case SURFACE_ID_NONHDR15: break;
case SURFACE_ID_NONHDR16: break;
case SURFACE_ID_NONHDR17: break;
case SURFACE_ID_NONHDR18: break;
case SURFACE_ID_NONHDR19: break;
case SURFACE_ID_UNK20: break;
case SURFACE_ID_UNK21: break;
case SURFACE_ID_UNK22: break;
case SURFACE_ID_SHADOW23: SurfaceTypeName = "First Shadowmap Surface"; break;
case SURFACE_ID_SHADOW24: SurfaceTypeName = "Second Shadowmap Surface"; break;
}
_DMESSAGE("OD3D9: Intercepted GetRenderedSurface():");
_DMESSAGE("OD3D9: Intercepted Purpose: %s [0x%02x]", SurfaceTypeName, SurfaceTypeID);
_DMESSAGE("OD3D9: Intercepted Flags: 0x%08x", Flags);
_DMESSAGE("OD3D9: Intercepted Format: %s", findFormat(Format));
_DMESSAGE("OD3D9: Intercepted {W,H}: {%d,%d}", Width, Height);
#endif
UInt32 rWidth = v1_2_416::GetRenderer()->SizeWidth;
UInt32 rHeight = v1_2_416::GetRenderer()->SizeHeight;
/* these aren't well autodetected by Oblivion, they are
* intermediate render-targets for passing data between the
* main-pass and post-passes
*/
if ((Width == rWidth) && (Height == rHeight) && !Format) {
if (IsHDR())
Format = D3DFMT_A16B16G16R16F;
else
Format = D3DFMT_A8R8G8B8;
}
return (this->*GetRenderedSurface)(renderer, Width, Height, Flags, Format, SurfaceTypeID);
// assert(NULL);
}
/* ------------------------------------------------------------------------------------------------- */
void (__stdcall * GetRenderedSurfaceParameters)(v1_2_416::NiDX9Renderer *, enum SurfaceIDs SurfaceTypeID, int *pWidth, int *pHeight, int, int *, D3DFORMAT *pFormat) =
(void (__stdcall *)(v1_2_416::NiDX9Renderer *, enum SurfaceIDs SurfaceTypeID, int *pWidth, int *pHeight, int, int *, D3DFORMAT *pFormat))0x007C0D10;
void __stdcall TrackRenderedSurfaceParameters(v1_2_416::NiDX9Renderer *renderer, enum SurfaceIDs SurfaceTypeID, int *pWidth, int *pHeight, int unk1, int *unk2, D3DFORMAT *pFormat) {
// assert(false);
GetRenderedSurfaceParameters(renderer, SurfaceTypeID, pWidth, pHeight, unk1, unk2, pFormat);
// assert(NULL);
#if 0 /* currently of no use ... maybe you find one :^) */
const char *SurfaceTypeName = "unknown";
switch (SurfaceTypeID) {
case SURFACE_ID_HDR0: SurfaceTypeName = "HDR-BoxSample Surface"; break;
case SURFACE_ID_HDR1: SurfaceTypeName = "HDR-PointSample Surface"; break;
case SURFACE_ID_HDR2: SurfaceTypeName = "HDR-Intermediate Surface"; break;
case SURFACE_ID_HDR3: SurfaceTypeName = "HDR-Origin Surface"; break;
case SURFACE_ID_HDR4: SurfaceTypeName = "HDR-Destination Surface"; break;
case SURFACE_ID_UNK5: break;
case SURFACE_ID_WATER6: SurfaceTypeName = "Water pre-heightmap Surface"; break;
case SURFACE_ID_WATER7: SurfaceTypeName = "Water pre-displacement Surface"; break;
case SURFACE_ID_WATER8: SurfaceTypeName = "Water[8] Surface"; break;
case SURFACE_ID_WATER9: SurfaceTypeName = "Water[9] Surface"; break;
case SURFACE_ID_WATER10: SurfaceTypeName = "Water[10] Surface"; break;
case SURFACE_ID_WATER11: SurfaceTypeName = "Water[11] Surface"; break;
case SURFACE_ID_WATER12: SurfaceTypeName = "Water[12] Surface"; break;
case SURFACE_ID_REFL13: SurfaceTypeName = "First Reflection Surface"; break;
case SURFACE_ID_REFL14: SurfaceTypeName = "Second Reflection Surface"; break;
case SURFACE_ID_NONHDR15: break;
case SURFACE_ID_NONHDR16: break;
case SURFACE_ID_NONHDR17: break;
case SURFACE_ID_NONHDR18: break;
case SURFACE_ID_NONHDR19: break;
case SURFACE_ID_UNK20: break;
case SURFACE_ID_UNK21: break;
case SURFACE_ID_UNK22: break;
case SURFACE_ID_SHADOW23: SurfaceTypeName = "First Shadowmap Surface"; break;
case SURFACE_ID_SHADOW24: SurfaceTypeName = "Second Shadowmap Surface"; break;
}
_DMESSAGE("OD3D9: Intercepted GetRenderedSurfaceParameters():");
_DMESSAGE("OD3D9: Intercepted Purpose: %s [0x%02x]", SurfaceTypeName, SurfaceTypeID);
// _DMESSAGE("OD3D9: Intercepted Flags: 0x%08x", Flags);
_DMESSAGE("OD3D9: Intercepted Format: %s", findFormat(*pFormat));
_DMESSAGE("OD3D9: Intercepted {W,H} before: {%d,%d}", *pWidth, *pHeight);
#endif
#if 1
#ifndef OBGE_NOSHADER
/* enable default automipmapping */
AMFilter = (D3DTEXTUREFILTERTYPE)AutoGenerateMipMaps.Get();
#endif
switch (SurfaceTypeID) {
case SURFACE_ID_WATER6:
/* Water heightmap */
if (UseWaterHiRes.Get()) {
if (WaterHeightMapSize.Get()) {
*pWidth = *pHeight = WaterHeightMapSize.Get();
}
else {
*pWidth = *pHeight = 256;
}
}
else {
if (WaterHeightMapSize.Get()) {
*pWidth = *pHeight = WaterHeightMapSize.Get();
}
else {
*pWidth = *pHeight = 128;
}
}
#ifndef OBGE_NOSHADER
{
ShaderManager *sm = ShaderManager::GetSingleton();
const float W = (float)*pWidth;
const float H = (float)*pHeight;
/* record constants */
Constants.rcpresh[0] = 1.0f / W;
Constants.rcpresh[1] = 1.0f / H;
Constants.rcpresh[2] = W / H;
Constants.rcpresh[3] = W * H;
}
#endif
break;
case SURFACE_ID_WATER7:
/* Water displacement */
if (UseWaterHiRes.Get()) {
if (WaterDisplacementMapSize.Get()) {
*pWidth = *pHeight = WaterDisplacementMapSize.Get();
}
else {
*pWidth = *pHeight = 256;
}
}
else {
if (WaterDisplacementMapSize.Get()) {
*pWidth = *pHeight = WaterDisplacementMapSize.Get();
}
else {
*pWidth = *pHeight = 256;
}
}
#ifndef OBGE_NOSHADER
{
ShaderManager *sm = ShaderManager::GetSingleton();
const float W = (float)*pWidth;
const float H = (float)*pHeight;
/* record constants */
Constants.rcpresd[0] = 1.0f / W;
Constants.rcpresd[1] = 1.0f / H;
Constants.rcpresd[2] = W / H;
Constants.rcpresd[3] = W * H;
}
#endif
break;
// case SURFACE_ID_WATER12: *pWidth = *pHeight = 256; break;
/* are these the reflection-rendertargets or water surfaces? */
case SURFACE_ID_REFL13:
case SURFACE_ID_REFL14:
/* Reflection Render-Surface Dimension (square) */
if ((ReflectionMapSize.Get() >= 256) &&
(ReflectionMapSize.Get() <= 2560)) {
*pWidth = *pHeight = ReflectionMapSize.Get();
}
else if ((ReflectionMapSize.Get() == 0) &&
(RendererWidth.Get() >= 256) &&
(RendererWidth.Get() <= 2560)) {
*pWidth = *pHeight = RendererWidth.Get();
}
else if ((ReflectionMapSize.Get() > 0) &&
(ReflectionMapSize.Get() <= 1) &&
(ReflectionMapSize.Get() * RendererWidth.Get() >= 256) &&
(ReflectionMapSize.Get() * RendererWidth.Get() <= 2560)) {
*pWidth = *pHeight = ReflectionMapSize.Get() * RendererWidth.Get();
}
break;
}
#if 0
_DMESSAGE("OD3D9: Intercepted {W,H} after: {%d,%d}", *pWidth, *pHeight);
#endif
#endif
}
/* ------------------------------------------------------------------------------------------------- */
void CreateRenderSurfaceHook(void) {
/* combined passes: 0040C830 */
/* combined reflection and water passes: 0049E880 */
/* combined hdr related: 0049E880 */
*((int *)&GetFarPlane) = 0x00410EE0;
*((int *)&SetFrustum) = 0x0070C190;
*((int *)&SetCamera) = 0x00762640;
*((int *)&CombinerPass) = 0x0040C830;
#ifndef OBGE_NOSHADER
/* ReflectionPass */
*((int *)&ReflectionCull) = 0x0049CBF0;
*((int *)&ReflectionPass) = 0x0049BEF0;
*((int *)&WaterSurfaceLoop) = 0x0049A200;
*((int *)&WaterSurfacePass) = 0x0049D7B0; // broken sub esp 8
*((int *)&WaterGeometryPass) = 0x0049B930;
*((int *)&ShadowPass) = 0x004073D0;
*((int *)&ShadowCanopyPass) = 0x004826F0;
*((int *)&HDRAlphaPass) = 0x007AAA30;
*((int *)&HDRPass) = 0x007BDFC0;
*((int *)&BlurPass) = 0x007B0170;
*((int *)&HitPass) = 0x007EB3D0;
*((int *)&MenuPass) = 0x007B18C0;
*((int *)&RefractionPass) = 0x00800440;
*((int *)&NighteyePass) = 0x007F5120;
*((int *)&WaterDisplacementPass) = 0x007DE8A0;
*((int *)&WaterHeightmapPass) = 0x007E17D0;
*((int *)&VideoPass) = 0x004106C0;
*((int *)&MiscPass) = 0x0057F170;
#endif
TrackFarPlane = &Anonymous::TrackFarPlane;
TrackFrustum = &Anonymous::TrackFrustum;
TrackCamera = &Anonymous::TrackCamera;
TrackCombinerPass = &Anonymous::TrackCombinerPass;
#ifndef OBGE_NOSHADER
TrackReflectionCull = &Anonymous::TrackReflectionCull;
TrackReflectionPass = &Anonymous::TrackReflectionPass;
TrackWaterSurfaceLoop = &Anonymous::TrackWaterSurfaceLoop; // ?
TrackWaterSurfacePass = &Anonymous::TrackWaterSurfacePass; // ?
TrackWaterGeometryPass = &Anonymous::TrackWaterGeometryPass; // ?
TrackShadowPass = &Anonymous::TrackShadowPass;
TrackShadowCanopyPass = &Anonymous::TrackShadowCanopyPass;
TrackHDRAlphaPass = &Anonymous::TrackHDRAlphaPass;
TrackHDRPass = &Anonymous::TrackHDRPass; // BSImageSpaceShader
TrackBlurPass = &Anonymous::TrackBlurPass; // BSImageSpaceShader
TrackHitPass = &Anonymous::TrackHitPass; // BSImageSpaceShader
TrackMenuPass = &Anonymous::TrackMenuPass; // BSImageSpaceShader
TrackRefractionPass = &Anonymous::TrackRefractionPass; // BSImageSpaceShader
TrackNighteyePass = &Anonymous::TrackNighteyePass; // BSImageSpaceShader
TrackWaterDisplacementPass = &Anonymous::TrackWaterDisplacementPass; // BSImageSpaceShader
TrackWaterHeightmapPass = &Anonymous::TrackWaterHeightmapPass; // BSImageSpaceShader
TrackVideoPass = &Anonymous::TrackVideoPass;
TrackMiscPass = &Anonymous::TrackMiscPass;
*((int *)&IdlePass ) = 0x007D71C0;
*((int *)&IsRunning ) = 0x004F8DB0;
#endif
/* GetRenderedSurfaceParameters */
*((int *)&GetRenderedSurface ) = 0x007C1B50;
*((int *)&GetRenderedSurfaceParameters) = 0x007C0D10;
TrackRenderedSurface = &Anonymous::TrackRenderedSurface;
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)GetFarPlane, *((PVOID *)&TrackFarPlane));
DetourAttach(&(PVOID&)SetFrustum, *((PVOID *)&TrackFrustum));
DetourAttach(&(PVOID&)SetCamera, *((PVOID *)&TrackCamera));
DetourAttach(&(PVOID&)CombinerPass, *((PVOID *)&TrackCombinerPass));
#ifndef OBGE_NOSHADER
DetourAttach(&(PVOID&)ReflectionCull, *((PVOID *)&TrackReflectionCull));
DetourAttach(&(PVOID&)ReflectionPass, *((PVOID *)&TrackReflectionPass));
// DetourAttach(&(PVOID&)WaterSurfaceLoop, *((PVOID *)&TrackWaterSurfaceLoop));
// DetourAttach(&(PVOID&)WaterSurfacePass, *((PVOID *)&TrackWaterSurfacePass));
// DetourAttach(&(PVOID&)WaterGeometryPass, *((PVOID *)&TrackWaterGeometryPass));
DetourAttach(&(PVOID&)ShadowPass, *((PVOID *)&TrackShadowPass));
DetourAttach(&(PVOID&)ShadowCanopyPass, *((PVOID *)&TrackShadowCanopyPass));
DetourAttach(&(PVOID&)HDRAlphaPass, *((PVOID *)&TrackHDRAlphaPass));
DetourAttach(&(PVOID&)HDRPass, *((PVOID *)&TrackHDRPass));
DetourAttach(&(PVOID&)BlurPass, *((PVOID *)&TrackBlurPass));
DetourAttach(&(PVOID&)HitPass, *((PVOID *)&TrackHitPass));
DetourAttach(&(PVOID&)MenuPass, *((PVOID *)&TrackMenuPass));
DetourAttach(&(PVOID&)RefractionPass, *((PVOID *)&TrackRefractionPass));
DetourAttach(&(PVOID&)NighteyePass, *((PVOID *)&TrackNighteyePass));
DetourAttach(&(PVOID&)WaterDisplacementPass, *((PVOID *)&TrackWaterDisplacementPass));
DetourAttach(&(PVOID&)WaterHeightmapPass, *((PVOID *)&TrackWaterHeightmapPass));
DetourAttach(&(PVOID&)VideoPass, *((PVOID *)&TrackVideoPass));
DetourAttach(&(PVOID&)MiscPass, *((PVOID *)&TrackMiscPass));
DetourAttach(&(PVOID&)IdlePass, TrackIdlePass);
#ifndef NDEBUG
DetourAttach(&(PVOID&)IsRunning, TrackIsRunning);
#endif
#endif
DetourAttach(&(PVOID&)GetRenderedSurface, *((PVOID *)&TrackRenderedSurface ));
DetourAttach(&(PVOID&)GetRenderedSurfaceParameters, TrackRenderedSurfaceParameters);
LONG error = DetourTransactionCommit();
// *((int *)&WaterSurfacePass) += 2; // broken sub esp 8, prefixes 2 bytes before instructions
if (error == NO_ERROR) {
_MESSAGE("Detoured GetRenderedSurfaceParameters(); succeeded");
}
else {
_MESSAGE("Detoured GetRenderedSurfaceParameters(); failed");
}
#ifndef OBGE_NOSHADER
/* enable default automipmapping */
AMFilter = (D3DTEXTUREFILTERTYPE)AutoGenerateMipMaps.Get();