本帖最后由 shane007 于 2023-9-6 11:03 编辑
0 u3 G. k2 l3 ~0 b- u# x
* M6 u, I. Y5 D+ ^(nibiru.exe 772 KB (790,528 字节))/ {- |4 e& f! v' }- d* f
: [" v* N# u0 {' [3 L将sub_451390,sub_451599 这2个显示函数进行了hook.. Y$ h+ D6 l7 d( l9 m' G5 G# R
确认这2个显示函数都被调用了。3 m) @4 t9 B* w, K
第1个可能显示的是调试字符串,第2个显示游戏字幕。
z1 q8 q. z! ~$ ]$ e @3 X# k8 p1 a
$ Y6 B# Q, g0 D+ f3 s以下这句是出错的,注释之后,程序可以正常运行,但字符不再输出。
/ D0 R4 {* q5 ^/ O
) e, D7 [6 W1 k7 c //v12 这里出错
3 `1 u: X$ u5 M, a$ U/ e //GetTextMetricsA(currentHdc, (LPTEXTMETRICA)&v12);
+ T# g) m% a m8 Q3 L2 ~) x$ d, w& g* t f
输出的log为如下这样,可以推测,游戏在每帧都将font渲染一次。
; U1 h& t5 S: S: X# x这种方式显然是有问题的,会影响性能。, |" o, u4 O* n. d% x0 {0 h
在汉化的时候,我会考虑字体在初始化的时候只渲染1次,后边多次使用。
* M# Y7 }! q% |1 {/ \0 I0 g3 ?* _' K- D: H! \) W. }% r6 ^! \
- sub_451390_Font1_hk
?+ K' [& s& T U7 B g - sub_451390_Font1_hk
+ W& u+ ^7 W b4 ~' [( X5 S* H - sub_451599_Font2_hk
0 ~3 L" `, z7 o - sub_451390_Font1_hk
9 u, v& }2 \1 S - sub_451599_Font2_hk5 \! N/ }1 i* H4 \
- sub_451599_Font2_hk
! ]; ?+ s5 K6 c3 z - sub_451599_Font2_hk
/ h% `( L$ J0 }' ?5 E& f2 x - sub_451599_Font2_hk) `3 F% u0 {1 W: o+ V
- sub_451599_Font2_hk
" k r+ @) b0 ]. @8 ` - sub_451599_Font2_hk9 [' `! l2 P2 x
- sub_451599_Font2_hk
- L# W1 o( S6 @( Z) I - sub_451599_Font2_hk+ E; [) A2 g( [
- sub_451599_Font2_hk
复制代码 ! ?* G/ F1 o# i `8 n
代码
, U" k7 B: ^* e2 L0 x3 o f+ M% N- #include <windows.h>9 U9 y4 K4 `1 v$ S- _9 K' l. c5 U4 ^
- #include <stdio.h>
0 C* K* K* }. ^( K - % {5 I9 N, \' ]' v
- #include "patch.h"# z8 c) W0 Z2 o; p2 S' r& i( O
- #include "patchNibiru.h"% B, T! B/ m7 w+ d
- #include <GL/gl.h>0 Z, ? a" I6 p$ [
6 N' o q1 V% y8 j5 r4 _ u+ M
1 D1 a9 P/ X* U( Z( I, ?" ?- DWORD SUB_451810 = 0x00451810;
4 w! T/ B5 e) I - DWORD SUB_451390 = 0x00451390;
E. h3 P0 w+ l. R% x' Z! [1 k* j - DWORD SUB_451599 = 0x00451599;6 Q7 C$ ?- X, M# m! ]! @
- % s" E& X% E L9 K1 H7 Q$ i
- HDC currentHdc;
( [0 q' A0 z8 K - # ?" S9 ~$ }) K- K
- DWORD __cdecl sub_451599_Font2_hk(LPCSTR lpFileName, int a2, int a3, int a4, int a5, int a6, int a7, LPINT lpBuffer, int a9)5 Y! @- M( A4 l0 i
- {% v: O7 m# j5 H; R$ w/ ?/ U1 \* r
- DWORD v10; // [esp-450h] [ebp-450h]
$ W9 @6 |0 t, g' m6 `# K$ \5 G - int v11; // [esp-44Ch] [ebp-44Ch]
1 q$ G: N) b& ^9 b! g- b8 B% J3 J& _ - int v12; // [esp-4Ch] [ebp-4Ch]
5 {/ {0 ^' T. ]1 J - int v13; // [esp-44h] [ebp-44h]
1 e+ L& \1 s( A" p - HFONT v14; // [esp-14h] [ebp-14h]
J7 l, }, L4 |$ ~ ~* @" m - DWORD v15; // [esp-10h] [ebp-10h]) Q' K" a7 O; |; d& g; k
- int v16; // [esp-Ch] [ebp-Ch]5 p% S; z. Y# D: [. q7 }
- int* i; // [esp-8h] [ebp-8h]; S2 l, {) B& m) c
8 K- `/ R2 R, f- __asm pushad;
1 j( N1 \ w( e - FILE* trace = fopen("font_trace.txt", "at");. |0 R# D( s9 S% F, v- l
- fprintf(trace, "%s\n", "sub_451599_Font2_hk");2 D9 L' l- [: ] s
- fclose(trace);2 S2 V- ~% a# f6 R4 e `+ z
- __asm popad; t) Y. o/ V4 }4 E
-
! B* ~9 Q- S- e2 Q" e" E8 w ~ - //if (!a9)$ {, H, j7 w2 K5 a. _+ g
- //{
: R' y1 P& }4 A. I" W! B7 R& S - // AddFontResourceA(lpFileName); v. b7 Y+ W" V7 ^. L) q3 U
- // for (i = &v11; *(_BYTE*)i && *(_BYTE*)i != 46; i = (int*)((char*)i + 1))$ P5 W+ m/ k( v7 ~9 v4 P, y
- // ;8 b9 p% ^: r3 C* B
- // *(_BYTE*)i = 0;
4 b: b% l; j1 x6 @' @6 _: ~* c - //}6 J/ U$ o& W( |! b; @5 T/ b
- //if (a4 == 1): u$ A3 d* R+ U- n* Q; n" e% x7 j
- //{9 P, Y$ S: ^8 L: b6 l8 G |2 t" t
- // v16 = 100;% y9 a, S& a. F- D6 c1 ?$ v, Y, k
- //}. D! m* N. S3 ?! _' ~
- //else if (a4 == 4)# v6 g9 R8 `2 K, \1 ~7 f9 u
- //{& I- }$ F+ P" W0 D
- // v16 = 700;
# J$ n: O, D' O! f$ A - //}
( z7 s7 K6 e0 _! D - //else! O/ ~. V6 o0 }
- //{( z1 g1 ^7 j+ |, B1 K$ m
- // v16 = 400;/ O: i* B S# W- [" h; r
- //}
6 O S' S8 @% V/ [5 |$ W. S( l8 T. p - v10 = 1;
7 @* k) d5 Z; d/ U8 A# H - //switch (dword_4AA490)
. `* ~1 b; E% V2 W; [ - //{
2 E; O# C; {, E6 J) y+ \9 E7 l" r& r - //case 1250:
, [0 [7 C5 b5 g, o! z* J" M - // v10 = 238;
1 _/ O: L$ v# @; C2 e! f4 N - // break;, T: X! M3 Y7 i3 s2 Q) P* Z
- //case 1251:1 d/ t3 M4 t9 Q9 G: E$ p
- // v10 = 204;
- I% u0 `5 X) X0 }/ i' ^" T - // break;
. A' Y) T+ \. g4 e6 }2 }5 l; M - //case 1252:1 Y4 ~& s/ m! T
- // v10 = 0;
W! y; M5 p- `5 ]% G+ X - // break;
4 a/ m( n& X3 U R9 s% L1 Q - //}0 n! v3 [4 \ K2 j z
- v15 = glGenLists(256);( K7 q- b9 D# ?2 P/ n& {
- v14 = CreateFontA(-*(DWORD*)a2, 0, 0, 0, v16, a5 != 0, a6 != 0, a7 != 0, v10, 4u, 0, 4u, 0, "Arial");5 U5 j/ ?3 e1 j: y$ p7 R
- //if (!v14)
5 ]6 W! F# Q* Q v: L9 i! _ - // MessageBoxA(0, MEMORY[0x4B3540], MEMORY[0x4B3534], 0);
4 n' O# X9 p- u+ L% y - //HDC hdc = GetDC(NULL); // 获取当前设备上下文;
; t5 d: W/ s) U/ |% t i9 p - SelectObject(currentHdc, v14);) l; Z. U4 F! A- j6 p
- GetCharWidthA(currentHdc, 0, 0xFFu, lpBuffer);
- m$ |! f1 j( Z. Q
" F0 C5 |# U" k3 C' b8 j: J P; p- //v12 这次出错4 l5 u- u% m' k% f6 w6 d5 m
- //GetTextMetricsA(currentHdc, (LPTEXTMETRICA)&v12);& t6 \4 l9 p0 Z+ ?% B8 P1 r
-
. {0 r& J" X% K - //*(_DWORD*)a2 = v12;
+ \% m: c! D( R) U2 {" Q+ ` D - //*(_DWORD*)a3 = v13;( h& C% _- T2 K0 {' [3 w+ Q4 n- W
- wglUseFontBitmapsA(currentHdc, 0, 0x100u, v15);
2 j" y; x" c. ^" p6 m; R - //if (!a9)
( K8 N$ U4 l3 c: k7 J - // RemoveFontResourceA(lpFileName);$ s$ {4 L8 n* k" j4 V$ N- {
- return v15;, E' x$ k2 C' G
- }. ?9 _, V( }7 v( |, _; [$ f; R0 l
5 ?( E0 U5 Y" W$ \4 B% G v. I2 c# ]' A- //使用到
" y4 o' Z& H1 e1 m+ P - BOOL __cdecl sub_451390_Font1_hk(HDC hdc)
# @1 K/ j; m1 m6 ` - {* D" H! f m- y4 P& \6 i
- HFONT h; // [esp+4h] [ebp-8h]7 X* M: i e5 S
- DWORD iCharSet; // [esp+8h] [ebp-4h]- Y( V4 i% y, V' q7 N* K1 B9 q$ ]3 l, p
- 2 N1 ]: Z, j0 m5 h0 k
- ) {& }. i9 B* O$ Y3 J- I
- __asm pushad;/ w, T n" v7 G
- FILE* trace = fopen("font_trace.txt", "at");
2 b. P4 [+ g9 H! m% }5 D* z. O' b - fprintf(trace, "%s\n","sub_451390_Font1_hk");
9 s$ F- a- m. n+ H% h! O - fclose(trace);& T# B F) \* ~ E
- __asm popad;
$ I. j7 b0 ]2 r A1 m8 P" m5 J - 4 ^2 g- \+ ^: R4 u
- currentHdc = hdc;
! [' ~. ~4 g+ d1 h1 H - iCharSet = 1;
1 ^$ A/ r5 }% \; A" v5 J - GLuint base = glGenLists(256);
+ K. J# c0 s y* i! m - h = CreateFontA(-14, 8, 0, 0, 700, 0, 0, 0, iCharSet, 4u, 0, 4u, 0, "Arial");
* l- |+ W9 i! O% ` - //if (!h)
+ I( G: H* z p, p - // MessageBoxA(0, aCannotCreateFo, aBuildfont, 0);
6 i1 ~/ M* t* y4 H- b4 L$ f! M - SelectObject(hdc, h);
/ _5 B$ s# L0 C1 r" Z - return wglUseFontBitmapsA(hdc, 0, 0x100u, base);
" {4 k6 h5 H' k5 w6 J5 y6 U - }
! o. G1 k. ]2 c& a8 U - " C! r2 l H6 D+ |
- void __cdecl2 |; N3 p1 n+ B: S& h. h
- sub_451810_drawstr_hk(int x, int y, int a3, int a4, int a5, int a6, char* str, ...)
8 [7 s9 X+ R' a, p - {% k4 B0 i" c$ u" Z8 ?/ F! z% z
- __asm pushad;$ L. H% E% o6 ], M x; l: J
- FILE* trace = fopen("sub_trace.txt", "at");
- s3 G0 e% C- h! ^# G& s - fprintf(trace, "%d,%d,%d,%d,%d,%d,%s\n", x ,y , a3, a4, a5, a6, str);5 p2 [2 n3 n! O4 q2 K
- fclose(trace);
% a' z O8 x2 g0 q# A# H! Q - __asm popad;
% E! P+ d0 R( E - & b& z9 Q f, R- k, B/ Q) K( x3 l
- //return a1;( {+ h0 r* c! a' v6 h0 H) K3 H
- }
8 S( V" S2 X o& a - / @1 Z o$ f8 q$ L( l
- bool
+ U9 I2 `$ a! Q9 K - ApplyPatchNibiru()
# g- X; [1 j# k: } - {" q' c5 p) g% u" S
- //JmpPatch ((void *)sub_451810_drawstr_hk, SUB_451810);! r+ ]% j0 n: C' W2 D( W' \4 R
- JmpPatch((void*)sub_451390_Font1_hk, SUB_451390);
( O0 }* [/ ]8 p - JmpPatch((void*)sub_451599_Font2_hk, SUB_451599);- E$ b5 U1 V; I7 a4 H
- . i0 D! J5 C; T0 \' X6 D
^2 k! p# Y) g( B; H% r2 ^& q
* [: Y, l8 B$ i! r1 p8 d( S- return true;
* E/ }3 Z5 X% \8 ?+ r - }
' y; F) U2 ]5 |- S/ |
复制代码
6 e& J" H s8 ^6 h( P5 q( @
8 y+ \3 X0 |- g2 m7 {$ v, A. c0 x; f0 T' s2 z) i8 d
- V2 N5 a: h( g) Y; N D
|