本帖最后由 shane007 于 2023-9-6 11:03 编辑
5 P: a* p* ~, {* \8 q' l" D
; `, H8 Q1 O2 T% v6 z(nibiru.exe 772 KB (790,528 字节))0 n( N$ Y7 S: [' X$ ]7 M
& C" N% ^1 J0 \5 }! R4 b3 F
将sub_451390,sub_451599 这2个显示函数进行了hook. e! [$ J9 L' H. h
确认这2个显示函数都被调用了。# p& y8 z; e. J% _
第1个可能显示的是调试字符串,第2个显示游戏字幕。
! L. M* U. l& b- J( T
* ~( j! p$ A* [3 w z! W& V0 {2 m以下这句是出错的,注释之后,程序可以正常运行,但字符不再输出。
' @7 V1 g: V( i( o/ z
: s& g7 f$ P9 k. B6 W //v12 这里出错9 {# `" s. @# S7 Y4 [: M
//GetTextMetricsA(currentHdc, (LPTEXTMETRICA)&v12);
+ e" E! y8 a; L" \4 I4 e
' _* P- _4 i, ?6 h* c: y2 L& s1 ^输出的log为如下这样,可以推测,游戏在每帧都将font渲染一次。
* [2 V4 {/ `$ u c4 P7 B6 U这种方式显然是有问题的,会影响性能。
# D5 n/ [5 U: w6 l4 y在汉化的时候,我会考虑字体在初始化的时候只渲染1次,后边多次使用。
4 w% t+ ` g' W5 o/ ]$ n
, l) T" ~+ U! Q9 @9 y0 ?* C" B# Z- sub_451390_Font1_hk5 B6 `8 [6 O$ ?3 T2 _
- sub_451390_Font1_hk
& `& j% B0 Y% v4 n ]% x - sub_451599_Font2_hk) _/ }% M% t5 k7 ~! G
- sub_451390_Font1_hk
+ s! i" }2 f# g* F - sub_451599_Font2_hk* C6 P* j3 y/ a
- sub_451599_Font2_hk
3 J. S2 l# x1 o: g. C# p, [1 \7 Y - sub_451599_Font2_hk
) S3 [6 `) i; X1 K. W% U0 w - sub_451599_Font2_hk
+ K1 i7 H( D3 b+ q' O2 b! w8 ` - sub_451599_Font2_hk
+ T* W2 I/ ?, c# ~6 f9 u# i - sub_451599_Font2_hk
! Q& \8 N/ N1 f% ~$ t ~ - sub_451599_Font2_hk
& l" W( z' g; T5 S( D$ @ - sub_451599_Font2_hk
6 d1 D5 |( Q% p - sub_451599_Font2_hk
复制代码
- F- t& x9 h/ e* P2 m. `0 ]代码/ t( N7 x8 u! r- ]$ g+ I1 D
- #include <windows.h>
4 v& j) y& _9 S# [! }8 o9 c - #include <stdio.h>: ?+ L3 x6 m/ Z9 Q
# _7 \& i0 n1 Q) T# @1 [. T- #include "patch.h": B. u [. u# C
- #include "patchNibiru.h"1 A2 p9 N9 _0 P4 d2 [: H0 I2 H
- #include <GL/gl.h>
% v$ k( f! _ ]9 U E1 G - r% A! @6 n& u2 M3 u4 L, Y2 m
8 v& ], x4 L6 R, C3 P7 F9 y9 L4 S- DWORD SUB_451810 = 0x00451810;
" f3 m# e2 v" ?( d# c1 x& {6 V) ` - DWORD SUB_451390 = 0x00451390;
i, {+ i+ \7 a3 [6 K7 W7 O - DWORD SUB_451599 = 0x00451599;
+ V" ^3 B, [8 A- _2 F
) j9 {( q% s5 S- ~3 v) B; t9 l- HDC currentHdc;, F3 b3 g' K- N0 i- F
- 1 @- o2 w9 ` P7 q9 R/ _
- DWORD __cdecl sub_451599_Font2_hk(LPCSTR lpFileName, int a2, int a3, int a4, int a5, int a6, int a7, LPINT lpBuffer, int a9); i+ m) a% K& z' T6 l" X
- {/ l' B7 [3 c$ z: n1 ]6 U* p7 v9 c
- DWORD v10; // [esp-450h] [ebp-450h]
" z. e2 [" H7 f# f - int v11; // [esp-44Ch] [ebp-44Ch]
& x( `# d! n1 N% d Q1 E - int v12; // [esp-4Ch] [ebp-4Ch]( s! A/ m$ ~, c2 S' @) X# k
- int v13; // [esp-44h] [ebp-44h]
! m7 m( ~( y/ J& [ - HFONT v14; // [esp-14h] [ebp-14h]" A$ \3 U A8 |3 A
- DWORD v15; // [esp-10h] [ebp-10h]
4 T8 i/ d, I$ W, C - int v16; // [esp-Ch] [ebp-Ch]
1 ^% e5 U* L! D4 T* V7 i8 ~ - int* i; // [esp-8h] [ebp-8h]: L4 o( }1 X3 W, n
+ O. `; _6 u0 ^- __asm pushad;0 B$ n2 }: `8 N, s8 E" o
- FILE* trace = fopen("font_trace.txt", "at");; `0 M; Q7 w3 T/ R& ^& @
- fprintf(trace, "%s\n", "sub_451599_Font2_hk");
% G& \- H: I/ W: Z1 y7 Q8 ] - fclose(trace);" B3 |" {5 ?: U, z& ^+ t1 |. {
- __asm popad;
3 W9 ^9 K: q6 x# v z1 q -
6 q5 s: u. p$ X- [' \0 _. y9 V- f - //if (!a9)
, T ^, S7 @9 o, s8 v, } - //{
" J$ B" _5 ?' K) A, d* ~5 n - // AddFontResourceA(lpFileName);" [9 e! ?; g& @! m1 _8 Y: ]
- // for (i = &v11; *(_BYTE*)i && *(_BYTE*)i != 46; i = (int*)((char*)i + 1))' P9 y/ x' R7 N/ d0 ` g
- // ;
, v3 `0 X+ @9 w0 n$ ]- c2 H - // *(_BYTE*)i = 0;2 E1 o" B& H; f9 `; S; f
- //}
9 L5 G5 U% [8 }3 H# K9 J4 K - //if (a4 == 1)
: i4 M' |, |' J# k0 R1 X% T( D - //{
0 p# r1 t( G+ |2 \' P% i: s, r5 O - // v16 = 100;; K! v* r6 g2 u8 h
- //}
4 r1 M( i: ]' o) H: M - //else if (a4 == 4)
: Y$ ~3 J5 F/ U3 ` - //{
0 `# ]) _: b" Q% |% M% S g Y - // v16 = 700;
5 f: T% }( X4 y ^2 q - //}" ?+ e+ l4 V5 F
- //else
; [% R# \3 x( v1 C, ~# R: F - //{0 j% D; k% {% G W8 \0 b: `
- // v16 = 400;% A% _/ H, E+ p6 m) ~: X/ r
- //}$ m8 J+ k" M1 u1 L9 ?4 k. O& }. ^
- v10 = 1;, J, H0 M3 }7 b, Z6 W
- //switch (dword_4AA490)& B9 l7 O$ a( b4 p
- //{
, O1 a1 r' k8 Q& H& Q, M - //case 1250:, v+ l7 g1 m) ]# U2 ?9 |9 U5 h
- // v10 = 238;
! r: f4 `, x* y/ n - // break;
( g+ |# S3 ]4 `! L( v) F! v - //case 1251:
; C! }! }' ?" V7 v - // v10 = 204;+ k2 B8 B+ g3 k) i, k) V; k+ E/ d; T
- // break;
9 T3 ]2 j# \ s9 ]0 w - //case 1252:
; v+ h+ X, ~2 ]! s& W - // v10 = 0;
' b4 \1 G" p# u, P2 } - // break;
8 R: ?/ ^4 j& y: k+ t; j - //}
( {' H: w) | }: ]# I% h2 @6 E - v15 = glGenLists(256);
1 ]9 `) x0 u2 F- u, d- l - v14 = CreateFontA(-*(DWORD*)a2, 0, 0, 0, v16, a5 != 0, a6 != 0, a7 != 0, v10, 4u, 0, 4u, 0, "Arial");6 w+ G5 D) Z/ F9 @6 k/ U4 U
- //if (!v14)
?- d4 G! ^* ? - // MessageBoxA(0, MEMORY[0x4B3540], MEMORY[0x4B3534], 0);0 p9 E k/ | N( a! j
- //HDC hdc = GetDC(NULL); // 获取当前设备上下文; - Y0 [5 L1 t) ~0 A) H
- SelectObject(currentHdc, v14);) I8 n1 V4 V2 i8 w6 x0 _
- GetCharWidthA(currentHdc, 0, 0xFFu, lpBuffer);8 u2 H0 m) A* `! [9 i F- L
* O+ A9 j. d: I! l7 z3 J8 ~% n- //v12 这次出错
@, y% q# Z S' _3 K% B - //GetTextMetricsA(currentHdc, (LPTEXTMETRICA)&v12);2 c- |( z% _$ d/ K' S8 s7 ^
- & {) T; }" y+ w0 T: Z
- //*(_DWORD*)a2 = v12;; p: ~4 M& }. P7 q
- //*(_DWORD*)a3 = v13;
/ i, b% C- R- V8 j) R - wglUseFontBitmapsA(currentHdc, 0, 0x100u, v15);
: W- y$ g& ~/ H3 |5 d - //if (!a9)
, }0 `9 ~# a4 L9 T! d$ I' \ - // RemoveFontResourceA(lpFileName);
1 _8 H9 k! ]2 k k# o% M - return v15;5 G& [% a) u( g
- }
' Q2 b9 ~; G) o5 ^, u/ p/ P+ \ - 1 |/ S" D1 k1 v( a6 j. u: X
- //使用到
: `! f+ \( O& c# ~0 Q, @; O9 I' q2 N: D - BOOL __cdecl sub_451390_Font1_hk(HDC hdc): P: B1 |5 ]% a8 ~$ w+ z8 H. ^
- {4 G- L: ~$ n% ~0 o$ W/ H! O& Y
- HFONT h; // [esp+4h] [ebp-8h]; ~( q0 k. O5 B4 A# |: Q% W7 e: @) S
- DWORD iCharSet; // [esp+8h] [ebp-4h]
5 A# |) P+ ?$ G% B6 l+ n+ m - / x2 \/ n* r. O; t
- ' n7 b6 {/ l0 O2 \0 h: O* R6 _! s
- __asm pushad;
Q6 r* A' t' X3 }/ Z$ V - FILE* trace = fopen("font_trace.txt", "at");+ @7 V; c; }5 u# [/ [3 v
- fprintf(trace, "%s\n","sub_451390_Font1_hk");% C, x+ s4 L2 k* M( c
- fclose(trace);( S3 L }: e0 X0 C7 z9 l
- __asm popad;
. ?: ~3 b' R4 K7 c9 L& x4 [1 O
: I5 D: l% @6 g! h- currentHdc = hdc;
9 a* Q1 v9 L8 p/ _* } - iCharSet = 1;
# ~2 e/ a9 I# i( G" R3 g3 o - GLuint base = glGenLists(256);1 a+ L/ o- c. v! z
- h = CreateFontA(-14, 8, 0, 0, 700, 0, 0, 0, iCharSet, 4u, 0, 4u, 0, "Arial");) o; P9 Q7 h3 t0 _* \% `
- //if (!h)! f U$ {/ x0 S s+ p; ~
- // MessageBoxA(0, aCannotCreateFo, aBuildfont, 0);
+ E4 i' _; }. P+ O R - SelectObject(hdc, h);
: q* g2 s6 B% q) F" v - return wglUseFontBitmapsA(hdc, 0, 0x100u, base);
, w9 Y1 m: R( J - }
* a" W; w7 B& d& Q, V5 L7 y! h
( l2 x7 l7 _2 z* T- ~- void __cdecl5 N5 R2 O! E* v4 k& R/ t
- sub_451810_drawstr_hk(int x, int y, int a3, int a4, int a5, int a6, char* str, ...)
5 A9 x) A8 H1 p- r c) F ] - {
" {/ F! s8 l/ l* }6 ? - __asm pushad;3 D; o3 M3 A% a& E0 t& d
- FILE* trace = fopen("sub_trace.txt", "at");
1 V( S6 o) d. F# l - fprintf(trace, "%d,%d,%d,%d,%d,%d,%s\n", x ,y , a3, a4, a5, a6, str);$ F, f+ {8 R' Z, Z
- fclose(trace);5 S7 Y w9 ?4 V$ m6 d7 V, u' T
- __asm popad;* o! ^& \+ S" n/ h
0 f5 s; A' ^' f3 h7 J- //return a1;
0 W' d, L: A6 \8 G, ?; x0 j - }
( ]0 P0 F* W0 v( U2 ~ - 0 D8 W# g: P5 k7 J8 X) T4 S% i
- bool
: Q& m5 M/ A) d- ^' V - ApplyPatchNibiru()
b; [! p3 P1 f- G/ o7 D8 Q - {" x2 z$ b x& L2 @( {4 e
- //JmpPatch ((void *)sub_451810_drawstr_hk, SUB_451810);8 S; q2 i( `5 U! n
- JmpPatch((void*)sub_451390_Font1_hk, SUB_451390);0 ?. X k0 C! C8 u2 }. C2 O/ \
- JmpPatch((void*)sub_451599_Font2_hk, SUB_451599);% L [4 T1 U5 N2 t3 t; L
/ K+ X% ]( P! I( i' ^
5 Z) w% M! ` \0 k' B
4 K3 L5 O* C7 T7 N" C$ j$ r. x- return true;1 B9 n' d' R5 A' N+ q$ B6 i
- }# X/ h6 a0 `+ `
复制代码 * q$ v1 B( [9 w$ L; }+ W, f6 H
$ p, D3 e" `& ?" l
3 w: C) ?) c" w: A* ~; e: S& V/ [3 o; j( f( r, w9 S
|