1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Here is how to set AI Traffic density from a custom DLL inside FSX

Discussion in 'Tools programming' started by Manuel Ambulo, 2/3/08.

  1. Manuel Ambulo

    Manuel Ambulo

    Joined:
    29/9/06
    Messages:
    162
    Country:
    panama
    Here is how to set AI Traffic density from a custom DLL loaded by FSX

    Hi,

    I just discovered a way for set the AI Traffic density, automatly, from a DLL written in C++. Here is the basic code:

    Code:
    // FS10 FS-TRAFFIC.DLL - Settings Structure
    typedef struct FS10TRAFFIC_SETTINGS
    {
        unsigned long Traffic_Density; // Traffic Density %(percent, from 0 to 100)
    	unsigned long IFR_or_VFR; // 0 = IFR and VFR, 1 = IFR (Only)
    	unsigned long Airline; // 0 = Disable, 1 = Enabled
    	unsigned long General_Aviation; // 0 = Disable, 1 = Enabled
    } FS10TRAFFIC_SETTINGS;
    
    
    // FS10 - Exported Function Pointers Types Definitions
    typedef void  (FSAPI *FS10TRAFFICWRITESETTINGS)(FS10TRAFFIC_SETTINGS* info);
    typedef void  (FSAPI *FS10TRAFFICREADSETTINGS)(FS10TRAFFIC_SETTINGS* info);
    
    
    FS10TRAFFIC_SETTINGS FS10Traffic_Settings;
    
    
    // Initializate this structure
    memset(&FS10Traffic_Settings, 0, sizeof(FS10TRAFFIC_SETTINGS));
    
    
    // Get the handle of the TRAFFIC.DLL module
    hTraffic = GetModuleHandle("FS-TRAFFIC.DLL");
    
    
    // READ AND CHANGE THE TRAFFIC SETTINGS
    // If we got the handle of the TRAFFIC.DLL module then
    if (hTraffic != NULL)
    {
    	// 1) READ THE CURRENT TRAFFIC SETTINGS
    	// Get a pointer to the TRAFFIC.DLL module's exported function
    	FS10ReadTrafficSettings = (FS10TRAFFICREADSETTINGS)GetProcAddress(hTraffic, (char*)6);
    
    	// If we got a pointer to the TRAFFIC.DLL module's exported function then
    	if (FS10ReadTrafficSettings != NULL)
    	{
    		// Get the *CURRENT* traffic settings
    		FS10ReadTrafficSettings(&FS10Traffic_Settings);
    
    		// Notify to user
    		MessageBox(hWnd, "The traffic settings had been read SUCCESSFULLY!", "FSIntruder.dll - Message", 0);
    	}
    
    	// 2) CHANGE THE TRAFFIC SETTINGS
    	// Get a pointer to the TRAFFIC.DLL module's exported function
    	FS10WriteTrafficSettings = (FS10TRAFFICWRITESETTINGS)GetProcAddress(hTraffic, (char*)5);
    
    	// If we got a pointer to the TRAFFIC.DLL module's exported function then
    	if (FS10WriteTrafficSettings != NULL)
    	{
    		// Build the new traffic settings structure
    		FS10Traffic_Settings.Traffic_Density = 100; // 100% of Traffic density
    		FS10Traffic_Settings.IFR_or_VFR = 0; // IFR and VFR
    		FS10Traffic_Settings.Airline = TRUE; // Enabled
    		FS10Traffic_Settings.General_Aviation = TRUE; // Enabled
    
    		// Set the *NEW* traffic settings
    		FS10WriteTrafficSettings(&FS10Traffic_Settings);
    
    		// Notify to user
    		MessageBox(hWnd, "The traffic settings had been CHANGED SUCCESSFULLY!", "FSIntruder.dll - Message", 0);
    	}
    }
    
    This is for anyone wanting to change the traffic settings dynamicly from your DLL...


    Manuel Ambulo
    Last edited: 2/3/08
  2. Paavo

    Paavo

    Joined:
    20/5/06
    Messages:
    140
    Country:
    estonia
    What tools do you use to explore exported functions?
    Last edited: 2/3/08
  3. Manuel Ambulo

    Manuel Ambulo

    Joined:
    29/9/06
    Messages:
    162
    Country:
    panama
    I had learnned from this thread:

    http://www.fsdeveloper.com/forum/showthread.php?t=3330&highlight=AdvBar

    Since that time i had tried to see if i can call some of the exported functions from the FSX DLLs and tried to see what do they do. That process needs a lot of patients, and time....then after hours trying, i found a little number of functions but what is impressive is the job that the author of FSUIPC did with all FS versions, he figured out almost all of the functions used in FS2002/2004/X, that is something that is admirable and impressive, hehehehe.... :). In FSX, i use the Dependency Walker, but the problem is that the exported functions are not exported with the functions names, but only with the ordinal number....so then the pain comes when then you need to figure out what arguments to pass to the function and what it does returns or if it doesnt returns anything....and also to see what does it does....

    Best Regards,

    Manuel Ambulo
    Last edited: 10/3/08

Share This Page