| 
									
										
										
										
											2022-03-08 12:57:35 +08:00
										 |  |  |  | #include "pch.h"
 | 
					
						
							|  |  |  |  | #include "hook.h"
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | #include "sock.h"
 | 
					
						
							|  |  |  |  | #include "MinHook.h"
 | 
					
						
							|  |  |  |  | #include "squirrel.h"
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | #pragma comment(lib, "libMinHook.x86.lib")
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | uint32_t hook::H_Register_Nut(uint32_t v, void* f, int freeVarsCnt) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     static int build = 0; | 
					
						
							|  |  |  |  |     if (build == 0 && f == (void*)0x005C5980) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         squirrel::R_Register_Nut(); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     return MLnewclosure(v, f, freeVarsCnt); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void hook::H_Register_Pack(void* Ecx) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     Lpfn_Init(Ecx); | 
					
						
							|  |  |  |  |     sock::R_Register_Pack(); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-11 19:44:03 +08:00
										 |  |  |  | std::map<wchar_t*, int> bufferm; | 
					
						
							|  |  |  |  | static SqPushRootFunc* yuancall; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | uint32_t ThFunc(uint32_t v) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     int a = yuancall(v); | 
					
						
							|  |  |  |  |     //std::cout << u8"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << params << std::endl;
 | 
					
						
							|  |  |  |  |         //SQ_Get(v, -2);
 | 
					
						
							|  |  |  |  |          | 
					
						
							|  |  |  |  |         //std::cout <<u8"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ" << ParameterNum - 1 << std::endl;
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             for (int i = -3; i < 3; ++i) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                  | 
					
						
							|  |  |  |  |                 if (SQ_GetType(v, i) == 134217744) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                      | 
					
						
							|  |  |  |  |                     wchar_t* Name; | 
					
						
							|  |  |  |  |                     SQGetString(v, i, &Name); | 
					
						
							|  |  |  |  |                     if (bufferm.count(Name) == 0) | 
					
						
							|  |  |  |  |                     { | 
					
						
							|  |  |  |  |                         bufferm[Name] == 1; | 
					
						
							|  |  |  |  |                         std::wcout << u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ" << Name << std::endl; | 
					
						
							|  |  |  |  |                     } | 
					
						
							|  |  |  |  |                      | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |                  | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |          | 
					
						
							|  |  |  |  |         //SQPrintFunc(v);
 | 
					
						
							|  |  |  |  |         return a; | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-03-08 12:57:35 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | int hook::RegisterHook() | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     MH_Initialize(); | 
					
						
							|  |  |  |  |     MH_CreateHook((void*)INIT_PACK_ADDRESS, &H_Register_Pack, reinterpret_cast<void**>(&Lpfn_Init)); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     MH_CreateHook((void*)INIT_NUT_ADDRESS, &H_Register_Nut, reinterpret_cast<void**>(&MLnewclosure)); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-11 19:44:03 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     MH_CreateHook((void*)0x1358C50, &ThFunc, reinterpret_cast<void**>(&yuancall)); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-08 12:57:35 +08:00
										 |  |  |  |     MH_EnableHook((void*)INIT_PACK_ADDRESS); | 
					
						
							|  |  |  |  |     MH_EnableHook((void*)INIT_NUT_ADDRESS); | 
					
						
							| 
									
										
										
										
											2022-04-11 19:44:03 +08:00
										 |  |  |  |     | 
					
						
							| 
									
										
										
										
											2022-03-08 12:57:35 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-11 19:44:03 +08:00
										 |  |  |  |     //MH_EnableHook((void*)0x1358C50);
 | 
					
						
							| 
									
										
										
										
											2022-03-08 12:57:35 +08:00
										 |  |  |  |     return 0; | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-03-16 10:03:39 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | int hook::InitGameScript() | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2022-04-11 19:44:03 +08:00
										 |  |  |  |     MH_EnableHook((void*)0x1359280); | 
					
						
							|  |  |  |  |     /*
 | 
					
						
							| 
									
										
										
										
											2022-03-16 10:03:39 +08:00
										 |  |  |  |     uint32_t v = GetSqVm(); | 
					
						
							|  |  |  |  |     SQPushRootTable(v); | 
					
						
							|  |  |  |  |     SQPushString(v, L"SetHudUI", -1); | 
					
						
							|  |  |  |  |     SQ_Get(v, -2); | 
					
						
							|  |  |  |  |     SQPushRootTable(v); | 
					
						
							| 
									
										
										
										
											2022-04-11 19:44:03 +08:00
										 |  |  |  |     SQPushString(v, L"1.cpp", -1); | 
					
						
							| 
									
										
										
										
											2022-03-16 10:03:39 +08:00
										 |  |  |  |     SQ_Call(v, 2, 1, 0); | 
					
						
							|  |  |  |  |     SQPop(v, 2); | 
					
						
							| 
									
										
										
										
											2022-04-11 19:44:03 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     | 
					
						
							| 
									
										
										
										
											2022-03-16 10:03:39 +08:00
										 |  |  |  |     std::cout << u8"<EFBFBD><EFBFBD><EFBFBD>óɹ<EFBFBD>" << std::endl; | 
					
						
							| 
									
										
										
										
											2022-04-11 19:44:03 +08:00
										 |  |  |  |     */ | 
					
						
							| 
									
										
										
										
											2022-03-16 10:03:39 +08:00
										 |  |  |  |     return 0; | 
					
						
							|  |  |  |  | } |