示例#1
0
void BOCTX::Pass2(EVENTLIST * elist, SAVE_LIST * save_list)
{
	assert(not elist->empty());

	LIST_TSEL tsel;

	// create tolerance squares for each event
	for (EVENTLIST::const_iterator e = elist->begin(); e != elist->end(); ++e)
	{
		TSEL e0 = { e->y, NULL };
		tsel.push_back(e0);
	}
	
	tsel.sort();
	tsel.unique();

	// simply intersect tolerance squares with each active segment
	INT32 elistx = elist->front().x;
	for (SAVE_LIST::iterator segm = save_list->begin(); segm != save_list->end(); ++segm)
		Intercept(&tsel, *segm, elistx);

	for (EVENTLIST::iterator e = elist->begin(); e != elist->end(); ++e)
	{
		if (e->GetType() == EVENT::S)
			Intercept(&tsel, e->s.s, elistx);
	}
} // BOCTX::Pass2
示例#2
0
void InitMWKeyboard()
{
	eng_input	=	GetPrivateProfileInt("General","EnglishInput",1,".\\Angel.ini");
	Intercept	( INST_CALL, hook_addr_EnterChar	, ( DWORD ) &EnterCharSTUB, 5);
	Intercept	( INST_CALL, hook_addr_EnterCharMultiString, ( DWORD ) &EnterCharMultiStringSTUB, 5);
	Intercept	( INST_CALL, hook_addr_GetKeyData, ( DWORD ) &GetKeyDataSTUB, 10);
}
void RunningRegression::Print(FILE * pFile, const char * header) const
    {
    fprintf (pFile, "\n%s\n", header);
    fprintf (pFile, "NumDataValues: %ld\n", NumDataValues());
    fprintf (pFile, "y = A + Bx ==> y = %g %+gx\n", Intercept(), Slope());
    fprintf (pFile, "Slope:           %f\n", Slope());
    fprintf (pFile, "Intercept:       %f\n", Intercept());
    fprintf (pFile, "r^2 Correlation: %f\n", Correlation());
    return;
    }
示例#4
0
//////////////////////////////////////////////////////////////////////
// ServerStop()
// -------------------------------------------------------------------
// Responsible for stopping the server.
//////////////////////////////////////////////////////////////////////
BOOL PRIVATE ServerStop(void)
{
	if(psi->TickThreadActive) {
		int i;
		// Give TickThread 2.5 seconds max to clean up before killing it
		for(psi->TickShutDown=1,i=1; i<25 && 1==psi->TickShutDown; ++i) {
			Sleep(100);
		}
		if(1==psi->TickShutDown) {
			TerminateThread(psi->TickThreadHandle, 1234);
		}
		CloseHandle(psi->TickThreadHandle);
	}

	// Unload any loaded clients
	while (ClientList.GetItemCount())
	{
		LinkedItem *li=ClientList.GetLastItem();
		CLIENTINFOSTRUCT *cds=(CLIENTINFOSTRUCT*)li->lpData;
		char t[32];
		sprintf(t, "unload %s", cds->Name);
		GameCommandLine(t);
	}


	// Un-patch intercept locations
	Intercept(INST_CALL, (DWORD)&GamePlayerInfoInterceptSTUB, psi->fps.GamePlayerInfoIntercept.AddressFound, psi->fps.GamePlayerInfoIntercept.PatchSize);
	Intercept(INST_CALL, (DWORD)&GamePacketSentInterceptSTUB, psi->fps.GamePacketSentIntercept.AddressFound, psi->fps.GamePacketSentIntercept.PatchSize);
	Intercept(INST_JMP, (DWORD)&GamePacketReceivedIntercept2STUB, psi->fps.GamePacketReceivedIntercept2.AddressFound, psi->fps.GamePacketReceivedIntercept2.PatchSize);
	Intercept(INST_CALL, (DWORD)&GamePacketReceivedInterceptSTUB, psi->fps.GamePacketReceivedIntercept.AddressFound, psi->fps.GamePacketReceivedIntercept.PatchSize);

	// Delete critical section
	DeleteCriticalSection(&psi->csData);

	// Release dll's that we loaded upon entry.
	for (int i=0; NeededDlls[i] != NULL; i++) FreeLibrary (GetModuleHandle(NeededDlls[i]));

	fep->GamePrintInfo("D2HackIt! Mk2 Unloaded.");

	delete (LPSTR)si->PluginDirectory, (LPSTR)psi->IniFile, thisgame, pfep, fep, psi, si;

	LinkedItem*	pItem;		// Delete the GetHackProfileStrings
	while ( (pItem = szBufferList.GetFirstItem()) != NULL )
	{
		delete ( pItem->lpData );
		szBufferList.RemoveItem(pItem);
	}
	return TRUE;
}
示例#5
0
  /**
   * Check whether this intersection should be added to, or updated in, the warning manager
   *
   * @param airspace Airspace corresponding to current intersection
   */
  void Intersection(const AbstractAirspace& airspace) {
    if (!airspace.IsActive())
      return; // ignore inactive airspaces completely

    if (!warning_manager.GetConfig().IsClassEnabled(airspace.GetType()) ||
        ExcludeAltitude(airspace))
      return;

    AirspaceWarning *warning = warning_manager.GetWarningPtr(airspace);
    if (warning == NULL || warning->IsStateAccepted(warning_state)) {

      AirspaceInterceptSolution solution;

      if (mode_inside) {
        airspace.Intercept(state, perf, solution, state.location, state.location);
      } else {
        solution = Intercept(airspace, state, perf);
      }
      if (!solution.IsValid())
        return;
      if (solution.elapsed_time > max_time)
        return;

      if (warning == NULL)
        warning = warning_manager.GetNewWarningPtr(airspace);

      warning->UpdateSolution(warning_state, solution);
      found = true;
    }
  }
示例#6
0
// 钩子函数
LRESULT CALLBACK ShellProc( int nCode, WPARAM wParam, LPARAM lParam )
{
	if(!g_bTryed)
	{
		g_bTryed=true;
		Intercept();
		g_bIntercepted=true;
	}

	return CallNextHookEx(g_hHook, nCode, wParam, lParam); // 钩子链
}
示例#7
0
    void intersection(const AbstractAirspace &as) {
        *fout << "# intersection point\n";
        for (auto it = intersections.begin(); it != intersections.end(); ++it) {
            const GeoPoint start = (it->first);
            const GeoPoint end = (it->second);
            *fout << start.longitude << " " << start.latitude << " " << "\n";
            *fout << end.longitude << " " << end.latitude << " " << "\n\n";
        }

        AirspaceInterceptSolution solution = Intercept(as, m_state, m_perf);
        if (solution.IsValid()) {
            *iout << "# intercept " << solution.elapsed_time << " h " << solution.altitude << "\n";
            *iout << solution.location.longitude << " " << solution.location.latitude << " " << "\n\n";
        }
    }
示例#8
0
AirspaceInterceptSolution
AbstractAirspace::Intercept(const AircraftState &state,
                            const GeoPoint &end,
                            const FlatProjection &projection,
                            const AirspaceAircraftPerformance &perf) const
{
  AirspaceInterceptSolution solution = AirspaceInterceptSolution::Invalid();
  for (const auto &i : Intersects(state.location, end, projection)) {
    auto new_solution = Intercept(state, perf, i.first, i.second);
    if (new_solution.IsEarlierThan(solution))
      solution = new_solution;
  }

  return solution;
}
示例#9
0
bool
AbstractAirspace::Intercept(const AircraftState &state,
                            const GeoPoint &end,
                            const FlatProjection &projection,
                            const AirspaceAircraftPerformance &perf,
                            AirspaceInterceptSolution &solution) const
{
  AirspaceIntersectionVector vis = Intersects(state.location, end,
                                              projection);
  if (vis.empty())
    return false;

  AirspaceInterceptSolution this_solution =
    AirspaceInterceptSolution::Invalid();
  for (const auto &i : vis)
    Intercept(state, perf, this_solution, i.first, i.second);

  if (!this_solution.IsValid())
    return false;

  solution = this_solution;
  return true;
}
示例#10
0
//////////////////////////////////////////////////////////////////////
// ServerStart()
// -------------------------------------------------------------------
// Responsible for setting up the server.
//////////////////////////////////////////////////////////////////////
BOOL PRIVATE ServerStart(HANDLE hModule)
{
	// Temporary string
	LPSTR t=NULL; 

	//////////////////////////////////////////////////////////////////
	// Before anything else, create the global structures we use in 
	// the hack. Make sure we delete these in ServerStop.
	//////////////////////////////////////////////////////////////////
	si =	new SERVERINFO;
	psi =	new PRIVATESERVERINFO;
	fep =	new FUNCTIONENTRYPOINTS;
	pfep=	new PRIVATEFUNCTIONENTRYPOINTS;

	thisgame=new THISGAMESTRUCT;
	thisgame->player=NULL;

	//////////////////////////////////////////////////////////////////
	// Force-load needed dll's so we can patch thei'r memory space.
	// We should unload these is ServerStop.
	//////////////////////////////////////////////////////////////////
	for (int i=0; NeededDlls[i] != NULL; i++) LoadLibrary(NeededDlls[i]);

	//////////////////////////////////////////////////////////////////
	// Build initial data of the SERVERINFO structure
	//////////////////////////////////////////////////////////////////
	si->Version=__SERVERVERSION__;

	// Get plugin path
	t=new char[_MAX_PATH];
	if (!GetModuleFileName((HINSTANCE)hModule, t, _MAX_PATH))
		{ MessageBox(NULL, "Unable to get PluginPath!", "D2Hackit Error!", MB_ICONERROR); return FALSE; }
	int p=strlen(t);
	while (p) 
	{
		if (t[p] == '\\')
			{ t[p] = 0; p=0;}
		else
			p--;
	}
	si->PluginDirectory=new char[strlen(t)+1];
	strcpy((LPSTR)si->PluginDirectory, t);

	psi->DontShowErrors=FALSE;
	//////////////////////////////////////////////////////////////////
	// Build initial data of the PRIVATESERVERINFO structure
	//////////////////////////////////////////////////////////////////
	sprintf(t, "%s\\D2HackIt.ini", t);
	psi->IniFile=new char[strlen(t)+1];
	strcpy((LPSTR)psi->IniFile, t);
	delete t;
	

	/* This block of code is replaced by the single GetCurrentProcessId()
	   call below.  This works because DLL initialization is performed
	   within the context of the process to which the DLL is attaching -
	   i.e. under that process's PID

	// Get Diablo II's hwnd
	psi->hwnd = FindWindow("Diablo II", "Diablo II");	// Get hwnd
		if (!psi->hwnd) { MessageBox(NULL, "Can't get Diablo II's window handle.", "D2Hackit Error!", MB_ICONERROR); return FALSE; }
	
	// Get Diablo II's pid & Process handle


	GetWindowThreadProcessId(psi->hwnd, &psi->pid);
	*/

    // Get the process ID and the process handle
	psi->pid = GetCurrentProcessId();
	psi->hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, psi->pid);
		if (!psi->hProcess) { MessageBox(NULL, "Can't get Diablo II's process handle.", "D2Hackit Error!", MB_ICONERROR); return FALSE;}


	// Get build date/time
	strcpy(psi->BuildDate, __DATE__);
	strcpy(psi->BuildTime, __TIME__);

	//////////////////////////////////////////////////////////////////
	// Build initial callbacks in the FUNCTIONENTRYPOINTS structure.
	//////////////////////////////////////////////////////////////////
//	fep->GetMemoryAddressFromPattern=&GetMemoryAddressFromPattern;
	fep->GamePrintString=&GamePrintString;
	fep->GamePrintInfo=&GamePrintInfo;
	fep->GamePrintVerbose=&GamePrintVerbose;
	fep->GamePrintError=&GamePrintError;
	fep->GetHackProfileString=&GetHackProfileString;
	fep->GetHackProfileStringEx=&GetHackProfileStringEx;
	fep->GetHackProfileSectionNames=&GetHackProfileSectionNames;
	fep->GameSendMessageToChat=&GameSendMessageToChat;

	//////////////////////////////////////////////////////////////////
	// Build initial callbacks in PRIVATEFUNCTIONENTRYPOINTS 
	//////////////////////////////////////////////////////////////////
	pfep->GetBaseAddress=&GetBaseAddress;
	pfep->GetImageSize=&GetImageSize;

	//////////////////////////////////////////////////////////////////
	// Check if D2HackIi.ini exisits
	//////////////////////////////////////////////////////////////////
	if (_access(psi->IniFile, 0))
	{ 
		LPSTR t=new char[strlen(psi->IniFile)+50];
		sprintf(t, "Unable to open ini-file:\n%s", psi->IniFile);
		MessageBox(NULL, t, "D2Hackit Error!", MB_ICONERROR); 
		delete t;
		return FALSE;
	}

	//////////////////////////////////////////////////////////////////
	// Set default prompts
	//////////////////////////////////////////////////////////////////
	t=fep->GetHackProfileString("D2HackIt", "Misc", "InfoPrompt");
	lstrcpyn(psi->InfoPrompt, (strlen(t)?t:DEFAULTINFOPROMPT),MAXPROMPTLENGTH-1);
	delete t;

	t=fep->GetHackProfileString("D2HackIt", "Misc", "ErrorPrompt");
	lstrcpyn(psi->ErrorPrompt, (strlen(t)?t:DEFAULTERRORPROMPT),MAXPROMPTLENGTH-1);
	delete t;

	t=fep->GetHackProfileString("D2HackIt", "Misc", "VerbosePrompt");
	lstrcpyn(psi->VerbosePrompt, (strlen(t)?t:DEFAULTVERBOSEPROMPT),MAXPROMPTLENGTH-1);
	
	t=fep->GetHackProfileString("D2HackIt", "Misc", "Verbose");
	if (!stricmp(t, "on"))
		psi->Verbose = TRUE;
	else
		psi->Verbose = FALSE;

	delete t;

	//////////////////////////////////////////////////////////////////
	// Start by binding a way to print to screen. This is vital, so if
	// we are unable to do this, exit with an error message!
	//////////////////////////////////////////////////////////////////
	FINGERPRINTSTRUCT fps;
	if(!GetFingerprint("D2HackIt", "GamePrintStringLocation", fps))
		{ MessageBox(NULL, "Fingerprint information for 'GamePrintStringLocation'\nmissing or corrupt!", "D2Hackit Error!", MB_ICONERROR); return FALSE; }
	
	psi->GamePrintStringLocation=fps.AddressFound;
	if (!psi->GamePrintStringLocation)
		{ MessageBox(NULL, "Unable to find entrypoint for 'GamePrintStringLocation'!", "D2Hackit Error!", MB_ICONERROR); return FALSE; }


	// Get playerinfo struct
	if (!GetFingerprint("D2HackIt", "pPlayerInfoStruct", fps)) 
		{ fep->GamePrintError("Fatal error! Exiting!"); return FALSE; }

	// Messy pointers :)
	thisgame->player=(PLAYERINFOSTRUCT*)*(DWORD*)(*(DWORD*)fps.AddressFound);


	// Get gameinfo struct
	if (!GetFingerprint("D2HackIt", "pPlayerInfoStruct", fps)) 
		{ fep->GamePrintError("Fatal error! Exiting!"); return FALSE; }

	// Get GameSendMessageToChat
	psi->GameSendMessageToChatLocation = NULL;
	if(GetFingerprint("D2HackIt", "GameSendMessageToChat", fps))
		psi->GameSendMessageToChatLocation = fps.AddressFound;

	// Messy pointers :)
	//thisgame->CurrentGame=(GAMESTRUCT*)*(DWORD*)(*(DWORD*)fps.AddressFound);
	
	// Initialize critical section
	InitializeCriticalSection(&psi->csData);

	// Initialize insert receive buffers
	psi->nRecvBufferPos = 0;
	
	//////////////////////////////////////////////////////////////////
	// Print startup banner. 
	//////////////////////////////////////////////////////////////////
	t=new char[128];
	sprintf(t, "Starting D2HackIt! Mk2 version %d.%.2d (%s@%s)",
		LOWORD(si->Version), HIWORD(si->Version), psi->BuildDate, psi->BuildTime
		);
		fep->GamePrintInfo(t);

	//////////////////////////////////////////////////////////////////
	// Get loader data
	//////////////////////////////////////////////////////////////////
	BOOL UsingD2Loader=FALSE;
	psi->DontShowErrors=TRUE;
	if (!GetFingerprint("D2HackIt", "LoaderStruct", fps))
	{
		psi->DontShowErrors=FALSE;
		sprintf(fps.ModuleName, "Diablo II.exe");
		UsingD2Loader=TRUE;
		if ((fps.AddressFound=GetMemoryAddressFromPattern(fps.ModuleName, fps.FingerPrint, fps.Offset)) < 0x100)
		{
			sprintf(fps.ModuleName, "D2Loader.exe");
			if ((fps.AddressFound=GetMemoryAddressFromPattern(fps.ModuleName, fps.FingerPrint, fps.Offset)) < 0x100)
			{
				//fep->GamePrintError("Unable to find loader data in 'Game.exe', 'Diablo II.exe' or 'D2Loader.exe'!");
				//fep->GamePrintError("Fatal error! Exiting!"); return FALSE; 
				fps.AddressFound=0;
			}	
		}
	}
	
	psi->loader = (LOADERDATA*)fps.AddressFound;

	if (psi->loader) 
	{
		sprintf(t, "Loader version ÿc4%d.%.2d. ÿc0Game is %sstarted with D2Loader.",
			LOWORD(psi->loader->LoaderVersion), HIWORD(psi->loader->LoaderVersion),
			(UsingD2Loader?"":"ÿc4not ÿc0"));
	} else {
		sprintf(t, "D2Hackit was loaded without loader");
	}
	fep->GamePrintInfo(t);

		
	//////////////////////////////////////////////////////////////////
	// Continue binding entrypoints and intercepts
	//////////////////////////////////////////////////////////////////
	sprintf(t, "Found 'GamePrintStringLocation' at %.8x", psi->GamePrintStringLocation);
	fep->GamePrintVerbose(t);

	/* 
	 * No need for this
	 *
	// Get socket location
	if (!GetFingerprint("D2HackIt", "pGameSocketLocation", fps)) 
		{ fep->GamePrintError("Fatal error! Exiting!"); return FALSE; }
	psi->GameSocketLocation=*(DWORD*)fps.AddressFound;
	*/

	// Get GamePacketReceivedIntercept
	if (!GetFingerprint("D2HackIt", "GamePacketReceivedIntercept", psi->fps.GamePacketReceivedIntercept)) 
		{ fep->GamePrintError("Fatal error! Exiting!"); return FALSE; }

	Intercept(INST_CALL, psi->fps.GamePacketReceivedIntercept.AddressFound, (DWORD)&GamePacketReceivedInterceptSTUB, psi->fps.GamePacketReceivedIntercept.PatchSize);

	// Get GamePacketReceivedIntercept2
	if (!GetFingerprint("D2HackIt", "GamePacketReceivedIntercept2", psi->fps.GamePacketReceivedIntercept2)) 
	{ 
		fep->GamePrintError("Fatal error! Exiting!"); 
		Intercept(INST_CALL, (DWORD)&GamePacketReceivedInterceptSTUB, psi->fps.GamePacketReceivedIntercept.AddressFound, psi->fps.GamePacketReceivedIntercept.PatchSize);
		return FALSE; 
	}
	Intercept(INST_JMP, psi->fps.GamePacketReceivedIntercept2.AddressFound, (DWORD)&GamePacketReceivedIntercept2STUB, psi->fps.GamePacketReceivedIntercept2.PatchSize);

	// Get GamePacketSentIntercept
	if (!GetFingerprint("D2HackIt", "GamePacketSentIntercept", psi->fps.GamePacketSentIntercept)) 
	{ 
		fep->GamePrintError("Fatal error! Exiting!"); 
		Intercept(INST_JMP, (DWORD)&GamePacketReceivedIntercept2STUB, psi->fps.GamePacketReceivedIntercept.AddressFound, psi->fps.GamePacketReceivedIntercept2.PatchSize);
		Intercept(INST_CALL, (DWORD)&GamePacketReceivedInterceptSTUB, psi->fps.GamePacketReceivedIntercept.AddressFound, psi->fps.GamePacketReceivedIntercept.PatchSize);
		return FALSE; 
	}
	Intercept(INST_CALL, psi->fps.GamePacketSentIntercept.AddressFound, (DWORD)&GamePacketSentInterceptSTUB, psi->fps.GamePacketSentIntercept.PatchSize);
	

	// Get GamePlayerInfoIntercept
	if (!GetFingerprint("D2HackIt", "GamePlayerInfoIntercept", psi->fps.GamePlayerInfoIntercept)) 
	{ 
		fep->GamePrintError("Fatal error! Exiting!"); 
		Intercept(INST_CALL, (DWORD)&GamePacketSentInterceptSTUB, psi->fps.GamePacketSentIntercept.AddressFound, psi->fps.GamePacketSentIntercept.PatchSize);
		Intercept(INST_JMP, (DWORD)&GamePacketReceivedIntercept2STUB, psi->fps.GamePacketReceivedIntercept.AddressFound, psi->fps.GamePacketReceivedIntercept2.PatchSize);
		Intercept(INST_CALL, (DWORD)&GamePacketReceivedInterceptSTUB, psi->fps.GamePacketReceivedIntercept.AddressFound, psi->fps.GamePacketReceivedIntercept.PatchSize);
		return FALSE; 
	}
	Intercept(INST_CALL, psi->fps.GamePlayerInfoIntercept.AddressFound, (DWORD)&GamePlayerInfoInterceptSTUB, psi->fps.GamePlayerInfoIntercept.PatchSize);


	// Get GameSendPacketToGameLocation
	// Thanks to TechWarrior
	if (!GetFingerprint("D2HackIt", "GameSendPacketToGameLocation", fps)) 
	{ 
		fep->GamePrintError("Fatal error! Exiting!"); 
		Intercept(INST_CALL, (DWORD)&GamePacketSentInterceptSTUB, psi->fps.GamePacketSentIntercept.AddressFound, psi->fps.GamePacketSentIntercept.PatchSize);
		Intercept(INST_JMP, (DWORD)&GamePacketReceivedIntercept2STUB, psi->fps.GamePacketReceivedIntercept.AddressFound, psi->fps.GamePacketReceivedIntercept2.PatchSize);
		Intercept(INST_CALL, (DWORD)&GamePacketReceivedInterceptSTUB, psi->fps.GamePacketReceivedIntercept.AddressFound, psi->fps.GamePacketReceivedIntercept.PatchSize);
		Intercept(INST_CALL, (DWORD)&GamePlayerInfoInterceptSTUB, psi->fps.GamePlayerInfoIntercept.AddressFound, psi->fps.GamePlayerInfoIntercept.PatchSize);
		return FALSE; 
	}
	psi->GameSendPacketToGameLocation=fps.AddressFound;

	// Start TickThread, We dont care about closing it later.
	// It will be destroyed when unloading the dll.
	DWORD dummy=0;
	psi->TickShutDown = 0;
	psi->TickThreadHandle = CreateThread(NULL,0,TickThread,(void*)&ClientList,0,&dummy);
	psi->TickThreadActive = psi->TickThreadHandle!=NULL;

	// Load any clients listed in Autorun
	t=new char[1024];
	t=fep->GetHackProfileString("D2HackIt", "Misc", "Autoload");

	if (strlen(t))
	{
		char* command[2];
		command[0]=".load";
		char *p;
		p=t;

		command[1] = p;
		while (*p != 0) {
			if (*p == ',') {
				*(p++) = 0;
				GameCommandLineLoad(command,2);
			while (*p == ' ')
						p++;
				if (*p != 0)
					command[1] = p;
			} else
				p++;
		}
		GameCommandLineLoad(command,2);
	}

	delete t;

	fep->GamePrintInfo("D2HackIt! Mk2 Loaded! Type ÿc4.helpÿc0 for help on commands.");
	return TRUE;
}
示例#11
0
文件: Main.cpp 项目: roybai/poe
//////////////////////////////////////////////////////////////////////
// WinMain
// -------------------------------------------------------------------
// The meat of the application.
//////////////////////////////////////////////////////////////////////
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	DWORD check;
	DWORD PatchAddress;
	DWORD DataAddress;
	DWORD WinProcAddress;
	char message[128];
    char windowname[128];
    char dllFullName[256];
	int x;
    int mode;

	// Sets up NumWindows, and the windolist[] array of HWND's
    // See EnumWindowsProc() for deatils.....
	EnumWindows(EnumWindowsProc, 0);
	
	if(NumWindows == 0)
		MessageBox(NULL, "No D2 Windows found!", "Loader Error", MB_ICONERROR);

	// Loop through all the D2 windows found
	for(x=0; x<NumWindows; x++) {

		// Set the HWND for the current window
		hd.hwnd = windowlist[x];
		
		// Get Diablo II's Process handle
		GetWindowThreadProcessId(hd.hwnd, &hd.pid);
		hd.hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, hd.pid);
		if (!hd.hProcess) { MessageBox(NULL, "Can't get Diablo II's process handle.", "Loader Error!", MB_ICONERROR); return -1;}
		
		// Find a good spot to put our code.  Look first for the original game.
		PatchAddress=GetBaseAddress(hd.pid, M_EXEFILE);
//		WinProcAddress =PatchAddress + 0x4262c0+11; //from spyxx
//		WinProcAddress =PatchAddress + 0x425EC0+11; //from spyxx, 1.0.5b
		WinProcAddress =PatchAddress + 0x42a2e0+11; //from spyxx, 1.0.5b
		if (!PatchAddress) { MessageBox(NULL, "Unable to find a patch location.", "Loader Error!", MB_ICONERROR); return -1;}
//		PatchAddress += 0x400;
//		PatchAddress += 0x5FBF04;
		PatchAddress += 0x1005;

		char	orig_code[10240];
		ReadProcessBYTES(hd.hProcess, PatchAddress, orig_code, 1024);
		DataAddress   = PatchAddress+DATA;

		// Get location of the game's WinProc
//		WinProcAddress = GetClassLongPtr(hd.hwnd,GCL_WNDPROC);

		if (!WinProcAddress) { MessageBox(NULL, "Unable to find WinProc entrypoint.", "Loader Error!", MB_ICONERROR); return -1;}
		
		// Initialize our data structure
		sprintf(hd.ModuleName, "%s", "findwin");

		hd.LoaderMagic      = LOADERMAGIC;
		hd.CodeLocation     = PatchAddress;
		hd.LoaderVersion    = LOADERVERSION;
		hd.WinProcLocation  = WinProcAddress;
		hd.WinProcPatchsize = 5;

		HMODULE hModule = GetModuleHandle("Kernel32.dll");
		if (!hModule) { MessageBox(NULL, "Unable to get handle of KERNEL32.DLL.", "Loader Error!", MB_ICONERROR); return -1;}
		
		// We're getting offsets to kernel functions from this userspace.
		// They will be the same inside the game, so we won't need to use
		// functions imported from the game.

		hd.pLoadLibraryA = (DWORD)GetProcAddress(hModule, "LoadLibraryA");
		if (!hd.pLoadLibraryA ) { MessageBox(NULL, "Unable to get address of LoadLibraryA in KERNEL32.DLL.", "Loader Error!", MB_ICONERROR); return -1;}

		hd.pFreeLibrary = (DWORD)GetProcAddress(hModule, "FreeLibrary");
		if (!hd.pFreeLibrary ) { MessageBox(NULL, "Unable to get address of FreeLibrary in KERNEL32.DLL.", "Loader Error!", MB_ICONERROR); return -1;}
		
		hd.pGetModuleHandleA = (DWORD)GetProcAddress(hModule, "GetModuleHandleA");
		if (!hd.pGetModuleHandleA ) { MessageBox(NULL, "Unable to get address of GetModuleHandleA in KERNEL32.DLL.", "Loader Error!", MB_ICONERROR); return -1;}

		// Get the first DWORD from DataAddress to see if we're loading or
		// unloading.  Set up the text for the message box
		ReadProcessBYTES(hd.hProcess, DataAddress, &check, sizeof(DWORD));
		if (check != LOADERMAGIC) { 
			mode = 1;		// We are loading
			strcpy(message, "LOAD ");
		} else {
			mode = 0;		// We are unloading
			strcpy(message, "UNLOAD ");
		}

		GetWindowText(hd.hwnd, windowname, 127);
		strcat(message, windowname);
		strcat(message, "?");

		// If a single window was found, or if the user chooses to do so, 
		// run the load/unload procedure against the current window
		if((NumWindows == 1) || (MessageBox(NULL, message, "Loader Question", MB_YESNO)) == IDYES) {

			// Patch in our code
			WriteProcessBYTES(hd.hProcess, PatchAddress, &AsmCode, FUNCTLEN(AsmCode));
		
			// Patch in our data
			WriteProcessBYTES(hd.hProcess, DataAddress, &hd, sizeof(LOADERDATA));
		
			// Patch in full path+filename to server dll
			GetCurrentDirectory(255, dllFullName);
			strcat(dllFullName, "\\findwin.dll");
//			strcpy(dllFullName, "c:\\bot\\d3\\findwin.dll");
			WriteProcessBYTES(hd.hProcess, DataAddress+sizeof(LOADERDATA), dllFullName, strlen(dllFullName)+1);
		
			// Now hi-jack WinProc of the game to our code
			/*
			char buf[100];
			sprintf(buf,"handle: %x, hwnd:%x, pid:%pid",hd.hProcess,hd.hwnd,hd.pid);
	MessageBox(NULL, buf, "Loader Error!", MB_ICONERROR);*/
			Intercept(hd.hProcess, INST_CALL, WinProcAddress, PatchAddress, LEN);
		
			// Send WM_APP to toggle load/unload of the dll
			SendMessage(hd.hwnd, WM_APP,0,0);
			// Give back WinProc, we don't need it anymore
			Intercept(hd.hProcess, INST_CALL, PatchAddress, WinProcAddress, LEN);
			WriteProcessBYTES(hd.hProcess, PatchAddress, orig_code, 1024);

			// If we're unloading, then clear LOADERMAGIC from the data area
			if(mode == 0) {
				check = 0;
				WriteProcessBYTES(hd.hProcess, DataAddress, &check, sizeof(DWORD));
			}
		}
	}
	return 0;
}
示例#12
0
void	MathLib::HighIntercept( long x, long y, long z, long	&r, short	&h, short	&p )	
{
	Intercept(x,y,z,r,h,p);
}