本帖最后由 shane007 于 2023-9-6 11:03 编辑
" Y' D6 i* ~+ r& F! j* O
2 {% H: H) _/ N% M(nibiru.exe 772 KB (790,528 字节))
* z% z. w9 ^+ N Y9 y
8 b# _$ r4 n& h- s% G- ~将sub_451390,sub_451599 这2个显示函数进行了hook.
2 K! O2 C V$ l( W3 ^5 h& [' _- d4 [确认这2个显示函数都被调用了。, X3 [, T! j2 H e- n
第1个可能显示的是调试字符串,第2个显示游戏字幕。
O1 J# B$ Y- g9 j" m3 @8 E- e# a8 u0 _
以下这句是出错的,注释之后,程序可以正常运行,但字符不再输出。: l: X6 K1 p5 o. N
$ g% f' T$ R% b+ I$ `# l# ^" A //v12 这里出错
% k2 z& |/ }$ c, X3 h //GetTextMetricsA(currentHdc, (LPTEXTMETRICA)&v12);3 Y7 V% [, Q9 _
% w/ k; Q- w! t% D2 L7 o( e输出的log为如下这样,可以推测,游戏在每帧都将font渲染一次。
1 I, q2 x2 J: u: l6 _这种方式显然是有问题的,会影响性能。5 h" N: Z& J/ A# w: S! S9 Y2 n
在汉化的时候,我会考虑字体在初始化的时候只渲染1次,后边多次使用。6 N! g+ I$ G" ~9 e- V+ I
\& c, _3 Q6 [/ w' a3 {: ?( e- sub_451390_Font1_hk
8 P& e) Q! n- w6 {" y - sub_451390_Font1_hk
! M; g# J. ]" A# w% D - sub_451599_Font2_hk
2 K: e: h+ Y, @9 c8 f4 I. w- K# O - sub_451390_Font1_hk
`; C' q: M4 K - sub_451599_Font2_hk4 }8 W+ @$ F0 ]+ b/ g
- sub_451599_Font2_hk7 N: k$ J$ L" I- N, T
- sub_451599_Font2_hk, b3 s! `2 ^ ^) |" t m
- sub_451599_Font2_hk
+ L5 ~2 i; M) r& m8 | - sub_451599_Font2_hk. f e- s* \7 ^+ S- |
- sub_451599_Font2_hk. v3 a# N" t* f5 }( |
- sub_451599_Font2_hk
0 ~5 N6 X4 }) @( L - sub_451599_Font2_hk
. |+ \ ^ y! N - sub_451599_Font2_hk
复制代码 6 }- a+ ?8 G. L4 o% X
代码
# X" w( Y5 |3 W* P- #include <windows.h>! n# B0 k6 X4 [
- #include <stdio.h>
) U( N% p0 U2 v- I; I5 _* ^7 y - % \- h4 ?! S$ a. E; q, Y* t, d
- #include "patch.h"8 J9 X C, u( ]
- #include "patchNibiru.h"
$ U/ L* E* v1 h l7 Q - #include <GL/gl.h>' v' m* Y- K' D# }
- + `8 I! M7 s* c1 D# E! H; [
- . S0 Q' t8 o% \7 X$ y9 U. Q
- DWORD SUB_451810 = 0x00451810;
3 M+ D+ i. ~' ?4 v) l& { - DWORD SUB_451390 = 0x00451390;
& e. \1 O, s+ S7 b' Q/ q - DWORD SUB_451599 = 0x00451599;
3 C) ]& C2 L* w8 u( c8 J - ( s) [9 h5 t0 H- J+ M
- HDC currentHdc;
2 D- n: o7 W" o% b - , t+ x, Z* U7 N) n$ 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)
" V2 P) s! x( n - {
* b7 X7 R2 k# [( K4 l - DWORD v10; // [esp-450h] [ebp-450h]2 G3 D1 a( V5 ?- S x1 H1 a% x' }$ s
- int v11; // [esp-44Ch] [ebp-44Ch]
& ]7 m, ?$ w4 o2 M- v& S+ e$ y9 u - int v12; // [esp-4Ch] [ebp-4Ch]' z3 S4 V# V, x$ e z% E
- int v13; // [esp-44h] [ebp-44h], j- O4 [$ M$ \
- HFONT v14; // [esp-14h] [ebp-14h]( O. D; V/ Q4 n
- DWORD v15; // [esp-10h] [ebp-10h]
( [8 _4 i$ y- o7 H' J& o - int v16; // [esp-Ch] [ebp-Ch]" N' |& Z5 Q& k8 D) A
- int* i; // [esp-8h] [ebp-8h]
' J9 t. @& Q/ ?4 L1 C' T
1 ]& E$ ?5 e+ T- __asm pushad;
' q* x& w" a1 E& B; J- g8 G T - FILE* trace = fopen("font_trace.txt", "at");
6 K' |( Y! g6 \" f - fprintf(trace, "%s\n", "sub_451599_Font2_hk");; O$ E Z. m: G
- fclose(trace);
3 O+ s0 M" E6 X/ L - __asm popad;* |4 \- p5 c, b$ L: J
-
) j) ?! ^) L* D6 |9 x3 q, U - //if (!a9)% W. }4 {; _" w& X% f4 C" Q
- //{
. w- B* S3 w7 X2 L* e - // AddFontResourceA(lpFileName);3 Y' P+ V( G {. I
- // for (i = &v11; *(_BYTE*)i && *(_BYTE*)i != 46; i = (int*)((char*)i + 1))
- P1 `* Y# k( R/ w# t! M5 B9 x$ n - // ;
2 @: T T* _) ^8 { q2 V0 H - // *(_BYTE*)i = 0;
# L/ d# u; R3 i* b - //}
$ S! D+ u; E, F- s) W! X - //if (a4 == 1)) ~" `0 X/ O* f7 R/ F6 \
- //{
% T2 c; g' W: b/ F* o; a3 x - // v16 = 100;4 A! z% p4 g' G; R
- //}' A K) z3 i6 p% t9 k; h8 Y
- //else if (a4 == 4)+ [: @' k8 o9 D
- //{% z% v9 i3 y' d1 w
- // v16 = 700;
3 P, I9 s; i6 k0 l& d# D4 e7 j J, q1 N - //}
) l' E1 F9 b( b3 ^6 q0 d - //else
( I3 T" m, ~) B* \+ w% ~ - //{
/ x8 O3 e4 q1 s" H" d/ x) X ?7 j% F - // v16 = 400;
' U; |/ b7 O, O# x: A) Q - //}" k5 p+ l/ D) r1 |, f8 I
- v10 = 1;5 v9 ` ^. G6 R$ {, R
- //switch (dword_4AA490)# l# X N o$ D- L/ |7 j8 b
- //{
& j8 `- r: Y: ]9 N+ U - //case 1250:
5 R* i! d9 Q5 j2 e( [* }" _& K# M0 T - // v10 = 238;
" l6 [& u1 }7 p! }) [# V$ v - // break;
9 ~! b6 I3 d$ I9 X* \# O - //case 1251:# c1 [$ u& R$ S8 n
- // v10 = 204;
# @, Z9 h) V+ X - // break;2 i6 G' I( q2 C$ A- @, K
- //case 1252:+ g' e* r" U- f0 O% v
- // v10 = 0;$ o# F7 A2 J0 [+ ^0 i6 K4 \: A
- // break;7 t( i5 D: i$ P; v9 p6 ^0 j5 i
- //}0 Y' K, {( l3 v/ \% T( i
- v15 = glGenLists(256);
2 J: J5 y* _$ K' V! a - v14 = CreateFontA(-*(DWORD*)a2, 0, 0, 0, v16, a5 != 0, a6 != 0, a7 != 0, v10, 4u, 0, 4u, 0, "Arial");
) s( Z+ }% B) c - //if (!v14)
* G. i; p3 k/ O" D3 Y" ?( R5 ] - // MessageBoxA(0, MEMORY[0x4B3540], MEMORY[0x4B3534], 0);, c0 B) @9 I, A! \/ U# s. _# A
- //HDC hdc = GetDC(NULL); // 获取当前设备上下文;
$ d4 i: {6 v2 L% a6 Z' D - SelectObject(currentHdc, v14);
9 e) W, b/ n. W4 k5 j - GetCharWidthA(currentHdc, 0, 0xFFu, lpBuffer);
$ z- J( e" W5 v8 }) E: f
# T6 N: o4 \5 |( B$ @& P# u( b- //v12 这次出错
6 v ?/ l- f3 _, C8 k; S7 A! }. B' s - //GetTextMetricsA(currentHdc, (LPTEXTMETRICA)&v12);
! I5 I4 ~4 E6 z. Y0 l+ L - p5 v9 N& `% b* f1 _0 o
- //*(_DWORD*)a2 = v12;7 _& z" W3 N$ b- s! u T k
- //*(_DWORD*)a3 = v13;+ U0 f5 n$ d) ]
- wglUseFontBitmapsA(currentHdc, 0, 0x100u, v15);
; v' N: s, ^* n- F$ ^8 [2 ~ - //if (!a9)
1 L# j: }6 d7 t' X s& n - // RemoveFontResourceA(lpFileName);
- k. U. v4 ?: m. O8 ~9 e - return v15;
) O8 h/ G" z1 ^) G7 _1 P( g1 @ - }
# s5 A+ i2 k1 `; X3 T - 7 ~5 w1 p9 i/ v& i+ ~0 n
- //使用到
- n! t# @3 |# b - BOOL __cdecl sub_451390_Font1_hk(HDC hdc)
* x X1 T9 T" c T- ?. x - {
" \- M6 N \, q7 A9 i4 Y - HFONT h; // [esp+4h] [ebp-8h]( c }7 m0 [+ r, ^+ C
- DWORD iCharSet; // [esp+8h] [ebp-4h]
+ J/ t$ ~" m0 `5 c3 _3 P! J
b5 |" R, H; H3 r% @6 i; s0 f
i0 b9 U, e) C% E7 [- __asm pushad;
l/ q- f8 D& ^; [2 V" V9 _" X" N - FILE* trace = fopen("font_trace.txt", "at");
- |3 `7 t9 c" s; A# Z - fprintf(trace, "%s\n","sub_451390_Font1_hk");
* ]2 ~- d" t6 J& P, @ - fclose(trace);: N: O) b" J( P% T7 B0 X
- __asm popad;
4 E) L2 B, P% ^# s
' p- K" ~6 M) {; \- currentHdc = hdc;
8 d" `9 ~/ \3 |6 V5 a - iCharSet = 1;$ ?# b, h( H) l
- GLuint base = glGenLists(256);7 C7 h% a7 Q& a$ ?1 K8 F! Y: D, ^
- h = CreateFontA(-14, 8, 0, 0, 700, 0, 0, 0, iCharSet, 4u, 0, 4u, 0, "Arial");
- ~6 E& i" d) f: J, T - //if (!h)
$ s9 ^0 J2 a# v0 ? - // MessageBoxA(0, aCannotCreateFo, aBuildfont, 0);* C" I" v; O! b
- SelectObject(hdc, h);, K0 s5 V/ ^( I+ z; l2 w
- return wglUseFontBitmapsA(hdc, 0, 0x100u, base);7 K+ O" W% G: n2 b+ S* v
- }" n" X, F9 @$ _, R5 i; W9 x. S% u
8 T* Q3 Q/ Q$ Y* U @3 @1 k) h- void __cdecl
& ^8 q, K) R! x% ]) r2 M1 Y& {% w - sub_451810_drawstr_hk(int x, int y, int a3, int a4, int a5, int a6, char* str, ...)
! s, g/ J9 \. v/ r, x. p - {
( i" j8 `# [0 _ - __asm pushad;
! q7 u0 F8 P5 w6 b& I; Z - FILE* trace = fopen("sub_trace.txt", "at");+ O- b$ V7 }) l3 C
- fprintf(trace, "%d,%d,%d,%d,%d,%d,%s\n", x ,y , a3, a4, a5, a6, str);/ u* g/ G5 m/ {, p( ?
- fclose(trace);
9 W' O2 q& }% W+ {- p; {, Y - __asm popad;& Y: Q1 J+ p) [
- 3 n& S) }2 w1 S- T ]* z
- //return a1;5 b3 R! m7 @+ V% ~6 Z
- }1 ]) a% j# l5 [! q. d5 H$ R) ^
% E" |' k% s# [9 l- bool: t" _2 C2 C3 i6 ^3 Q) c& f
- ApplyPatchNibiru()+ s, T$ V/ C5 M) |
- {2 `& [! t# O4 z2 o4 ~
- //JmpPatch ((void *)sub_451810_drawstr_hk, SUB_451810);. G8 B) |" m a, ]5 Y% o5 N. `
- JmpPatch((void*)sub_451390_Font1_hk, SUB_451390);! `, T: ]3 I% Z+ @: ]* H/ H) }% D! k, S
- JmpPatch((void*)sub_451599_Font2_hk, SUB_451599);
p" w( w* V* C! p! R, q - $ o. r0 p* t# Y, s* h
9 `4 ? J9 V }( p: F1 c" P+ d
# C' w9 n, f7 d' c" o5 r- return true;) R! C& d9 z, U$ S/ C5 `, `
- }
7 O+ [& h* o% a5 r y
复制代码 * y- g; ~; E8 d7 G. {* _
3 W4 {% a- z* x" H/ u
' {& E! G# g2 F9 T3 }- y) R8 B
, y# S' O6 G. ? W) g: A |