本帖最后由 shane007 于 2023-9-6 11:03 编辑 j1 B! L1 f4 I1 E/ |3 Q& D
; N) c8 j$ U. H) E: J- O
(nibiru.exe 772 KB (790,528 字节))
! x$ i! G" G% `. v4 u6 V
2 _3 a. ?$ T1 |) C* C& [将sub_451390,sub_451599 这2个显示函数进行了hook.$ _3 G/ j, ]$ c+ O' R" p
确认这2个显示函数都被调用了。
' P) }) A- }6 ^: D8 V# i第1个可能显示的是调试字符串,第2个显示游戏字幕。( N5 e* g- R. @7 o9 T
4 V' d5 e9 ^' s以下这句是出错的,注释之后,程序可以正常运行,但字符不再输出。" f! t; y: P# c* V9 I, O
$ R) r, X4 P, e# [
//v12 这里出错
; }, T* U& k+ S1 Q //GetTextMetricsA(currentHdc, (LPTEXTMETRICA)&v12);
: b' T# n u7 t3 t
$ e$ v. s2 z9 R: _输出的log为如下这样,可以推测,游戏在每帧都将font渲染一次。
- X5 J% b; w: t: q" T" c这种方式显然是有问题的,会影响性能。& `5 |* c! g/ @) \! U1 W+ ^8 b
在汉化的时候,我会考虑字体在初始化的时候只渲染1次,后边多次使用。
& O1 K' a+ \0 Q, x
- C3 f+ p3 T7 P* @4 [' v- sub_451390_Font1_hk K2 w% t( V1 h3 S n$ u( C
- sub_451390_Font1_hk3 \* r* q4 r7 u2 @; f3 C0 w w( W
- sub_451599_Font2_hk& d) D k9 F5 G- A y6 N
- sub_451390_Font1_hk+ E2 ?5 v8 D2 W" C( @6 o1 x
- sub_451599_Font2_hk
5 D1 m9 W$ Q+ z- ~ - sub_451599_Font2_hk2 ]4 T4 U9 H0 A4 S5 I
- sub_451599_Font2_hk
* N1 g3 v2 `3 p: q - sub_451599_Font2_hk
1 B+ l8 j& |, d. }/ C* ] - sub_451599_Font2_hk6 d1 E5 e- R, W9 H8 U! b6 d- @
- sub_451599_Font2_hk
. e9 M2 u! o* g - sub_451599_Font2_hk% f _9 x- S9 ^! e+ J% d
- sub_451599_Font2_hk
1 V9 ]# K% r) u1 m- p - sub_451599_Font2_hk
复制代码
0 v. Q$ N u$ Q! V' `/ j3 A8 F/ \. h代码8 A* P* K% } T; \" K
- #include <windows.h>
+ x! x5 E( d9 a9 r, b7 x, n# y - #include <stdio.h>
% S0 H9 M' f$ H - ) E' { |5 S$ B# g& o$ F6 {
- #include "patch.h"
! C$ L( C0 s5 k- M - #include "patchNibiru.h"
+ T* i2 j& }, z: X& A$ z - #include <GL/gl.h>: E- b. g- f/ P
0 |" _) N7 E) n( `9 e- , i5 ?% B% E% ?, z% Q
- DWORD SUB_451810 = 0x00451810;
7 N: f ]/ N4 } f, [0 R: W# ~ - DWORD SUB_451390 = 0x00451390;
9 c" |1 s0 [& U! f( W9 ]5 k4 u - DWORD SUB_451599 = 0x00451599;
% L" v6 j: _5 Y( F- H" i - 1 Y0 f/ y5 m; U+ v% q! a4 r
- HDC currentHdc;
7 ~7 Z; \$ V+ J; j6 M5 _+ Y - ; z" j3 o1 E7 u% W" Z& p
- DWORD __cdecl sub_451599_Font2_hk(LPCSTR lpFileName, int a2, int a3, int a4, int a5, int a6, int a7, LPINT lpBuffer, int a9)0 G4 b7 v- }' K' M q# k
- {
# f; }) a/ n7 d3 I& g, X - DWORD v10; // [esp-450h] [ebp-450h]
/ v6 h! i; |! b) l - int v11; // [esp-44Ch] [ebp-44Ch]" V1 d. U9 E2 ^
- int v12; // [esp-4Ch] [ebp-4Ch]
* N, Z G9 Y! g# m% b - int v13; // [esp-44h] [ebp-44h]! K) G5 C% H! y2 l
- HFONT v14; // [esp-14h] [ebp-14h]
7 Z% Q& j4 i6 n: @- e% y - DWORD v15; // [esp-10h] [ebp-10h]
. I/ e' C* O2 q* u - int v16; // [esp-Ch] [ebp-Ch]
5 T% z4 A2 i9 w) J6 @# M5 c6 H( i - int* i; // [esp-8h] [ebp-8h]
. u0 D% w& a5 r- R" F' u
# x+ W: T# L+ i. \- __asm pushad;
. M) ~ \5 h }) V - FILE* trace = fopen("font_trace.txt", "at");
9 |9 d% D& Z% y9 ?2 U$ x( D - fprintf(trace, "%s\n", "sub_451599_Font2_hk");! g/ h$ a5 k1 w% I$ T& q
- fclose(trace);% ~- X: \8 _/ D; V8 L
- __asm popad;+ u, ~3 z% M% W2 T- D7 r7 n# f8 v
- : Q" V* W3 O$ ?( F" x7 u
- //if (!a9)5 b8 P: t0 G n: d1 c
- //{7 t/ P3 I8 |) h
- // AddFontResourceA(lpFileName);, C/ w9 o! [1 I, |$ w' _
- // for (i = &v11; *(_BYTE*)i && *(_BYTE*)i != 46; i = (int*)((char*)i + 1))
. D5 v' D( q3 A( t - // ;/ w- w2 m& {! K @+ J6 l
- // *(_BYTE*)i = 0;
5 i9 V J7 Q- Q) N9 v - //}0 w5 ?9 ^" r4 W& v, @8 ]7 C6 [
- //if (a4 == 1)+ m6 {) K- ]4 c0 y3 k' D9 A
- //{/ Q( S: r5 v2 P O
- // v16 = 100;
' o0 M# u( P+ N! ^8 o# ?9 o - //}
q7 C" H. a) m( j5 A% p - //else if (a4 == 4)7 y( n, i& Q, \- s, i. T$ f
- //{
\6 Z, G% d1 S - // v16 = 700;
9 ^* z. p+ J$ s' i6 @ - //}2 U9 i9 |2 G, N8 P6 v) O
- //else/ m. h& I# S2 e9 X: W: g" J- g8 g/ M; Q
- //{
3 _. E& u' b5 S7 ~6 B - // v16 = 400;
8 j* Q o; \* L1 y - //}
a- [* N& @3 S( E) p+ s - v10 = 1;
8 P/ B6 W! ?& o& E8 F" T/ s - //switch (dword_4AA490)# _, ]' ?* n$ |
- //{8 x6 h+ x# Z# Q: Q- ]) R- O
- //case 1250:% _1 F& Y0 L1 n' ~! I
- // v10 = 238;: e0 Q5 R0 M' E: B. r. K3 R
- // break;
: ]9 S' h; J3 D* |+ n8 o! B+ @ - //case 1251:
, {2 p- \# A0 }9 a' E3 w3 S - // v10 = 204;( F. B3 H: E- n2 v' A3 z! d! \
- // break;! K" o- O1 p1 `& w* p; ?
- //case 1252:
- d' m- K7 ~8 \7 ~3 X" J - // v10 = 0;
! E0 Z( s ^2 B- ^2 h - // break;' g7 f: v! d/ q2 l; s0 w" F
- //}
0 E. h) ^& G* ^! ] - v15 = glGenLists(256);1 N3 T1 b. g% r+ B
- v14 = CreateFontA(-*(DWORD*)a2, 0, 0, 0, v16, a5 != 0, a6 != 0, a7 != 0, v10, 4u, 0, 4u, 0, "Arial");
+ G4 p1 p' o1 l) J - //if (!v14)" k; H, T9 V. h, E# y" E2 f- \
- // MessageBoxA(0, MEMORY[0x4B3540], MEMORY[0x4B3534], 0);" p7 e$ h" E4 |
- //HDC hdc = GetDC(NULL); // 获取当前设备上下文; - k; S' m. A: G% p! Z4 a
- SelectObject(currentHdc, v14);! j. V) c( [ N+ _& x
- GetCharWidthA(currentHdc, 0, 0xFFu, lpBuffer);" ~/ ^# W2 F) O$ e( N
- $ \ k6 r( ?$ P7 z% z( J
- //v12 这次出错
* H. g5 {9 u$ R0 m - //GetTextMetricsA(currentHdc, (LPTEXTMETRICA)&v12);
+ j* ]$ S7 Y1 c+ y$ z: V6 C+ g - ( o7 Z# f' b! ?, S- H5 z
- //*(_DWORD*)a2 = v12;
( G9 Y: @6 R9 G. l# b. c" }: M - //*(_DWORD*)a3 = v13;3 }$ ]) R! C O9 Z7 p _
- wglUseFontBitmapsA(currentHdc, 0, 0x100u, v15);1 [- k3 R+ _, Q# v8 ^9 ?
- //if (!a9)9 z9 I# ~: M+ n2 J7 F& y# ~
- // RemoveFontResourceA(lpFileName);
* G6 p s* U( ]! f - return v15;
! J7 B. h- H' u, k4 u9 l; n' J - }$ ]' V& X; p o
- V1 C* Q+ G3 X8 P/ D( P! d% S- I- //使用到
: v2 a1 H: S& C* w4 h* A5 T - BOOL __cdecl sub_451390_Font1_hk(HDC hdc)
5 m, t$ s, {6 K - {5 O9 q4 J- v, A Q! W
- HFONT h; // [esp+4h] [ebp-8h], \) a( p) _/ ~) i- g% a" v
- DWORD iCharSet; // [esp+8h] [ebp-4h]
2 @$ e* F' A7 s$ l4 H v" i+ e
) n( D1 m( P% B: P3 u& O
I. K8 g8 e- p( w4 S2 t- __asm pushad;
* f5 J$ q' g/ B - FILE* trace = fopen("font_trace.txt", "at");& V3 {* I2 E( E: X& y! q
- fprintf(trace, "%s\n","sub_451390_Font1_hk");
~7 o- U4 l( w* D4 R" z5 _5 ? - fclose(trace);
9 r- i& S9 r$ b, o. d - __asm popad;2 T. c) j7 s1 S# i6 [
) l' \& ^" B* D6 O) a) A- currentHdc = hdc;8 ?6 m* g! u( X# p7 |4 m* S
- iCharSet = 1;
" H$ G5 n8 c5 M: O* I0 ]- l5 {+ z - GLuint base = glGenLists(256);
* d# g7 S. Z$ @ ?- E - h = CreateFontA(-14, 8, 0, 0, 700, 0, 0, 0, iCharSet, 4u, 0, 4u, 0, "Arial");2 a- y. S4 ~, M% r* a
- //if (!h)3 O V0 q8 K. Z! U& L
- // MessageBoxA(0, aCannotCreateFo, aBuildfont, 0);5 W3 `! f* g g& X5 m; t
- SelectObject(hdc, h);
7 K9 U- s# V8 `5 @% E( d7 O$ J - return wglUseFontBitmapsA(hdc, 0, 0x100u, base);+ ~$ E/ O! t( X' M. M8 x3 S3 C
- }
( j6 O: Y* ]- F3 d j
" _( y& P8 q9 r/ Y5 g- void __cdecl/ v1 R6 {+ O# t
- sub_451810_drawstr_hk(int x, int y, int a3, int a4, int a5, int a6, char* str, ...)
* x- J% s) H# p+ T: t - {
9 l$ d$ b2 a0 A - __asm pushad;7 m" z# _/ `; z$ n2 m8 F9 G
- FILE* trace = fopen("sub_trace.txt", "at");0 p" ]0 o) Q" O* W1 t6 `
- fprintf(trace, "%d,%d,%d,%d,%d,%d,%s\n", x ,y , a3, a4, a5, a6, str);
0 Z4 H( C3 w2 ] - fclose(trace);9 v1 v @4 b6 E7 p% I
- __asm popad;' B3 A0 C0 X% q' V" c
( w& _9 Z& z) m& X& g! D- //return a1;5 H- \* s7 @1 y7 M( U
- }
/ u% {3 e. A5 W& {8 o; q8 U - , A7 N) d8 G* w; @
- bool
2 D8 D6 \' X8 J8 ? - ApplyPatchNibiru()
4 Y: f: M% {% q6 u - {7 _& h8 K; C; C5 O& |
- //JmpPatch ((void *)sub_451810_drawstr_hk, SUB_451810);6 D* S- J+ X( u
- JmpPatch((void*)sub_451390_Font1_hk, SUB_451390);* H3 p J2 L. C/ A/ c
- JmpPatch((void*)sub_451599_Font2_hk, SUB_451599);
% F, H; j3 a! c7 i/ D - " d1 o' A `. Q1 Z9 {7 U2 B
- ! N7 G5 w5 o' ]% _' _! i5 F
" E0 z5 H I- K m- b7 @7 g" k- return true;
( F" w7 T% o' q' Q0 K1 [' ^$ n2 L - }( s7 J7 v4 ^( X4 [' X
复制代码
3 y: _! K4 h; P* a7 P) m! I
, d, B) G9 d; M3 w! J* z5 f# o6 ^$ S' v, h
8 O% n' n& ]$ O. S% j7 f, u2 C3 l
|