This problem is most likely because the Superfighters Deluxe.exe executable has code in it that trys to execute steamworksapi.dll but since it doesnt find it gives this exception error, how could this be fixed?

The thing is that isnt it suppost to find it, isn't superfighters deluxe.exe in memory behaving like it's being executed in this directory?

C:\Program Files (x86)\Steam\steamapps\common\Superfighters Deluxe\Superfighters Deluxe.exe

Because if it doesnt find the steamworksapi.dll that is located in C:\Program Files (x86)\Steam\steamapps\common\Superfighters Deluxe

It most likely it aint executing as behaved in directory C:\Program Files (x86)\Steam\steamapps\common\Superfighters Deluxe\Superfighters Deluxe.exe


File moved successfully!
Downloading file...
Loading assemblies...
Loading 'SteamworksAPI.dll' from: C:\Program Files (x86)\Steam\steamapps\common\Superfighters Deluxe\SteamworksAPI.dll
'HowqueCheats.exe' (CLR v4.0.30319: HowqueCheats.exe): Loaded 'C:\Program Files (x86)\Steam\steamapps\common\Superfighters Deluxe\SteamworksAPI.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Loading dependency 'steam_api.dll' from: C:\Program Files (x86)\Steam\steamapps\common\Superfighters Deluxe\steam_api.dll
Starting Superfighters Deluxe...
Error Output: 
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'SteamworksAPI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ef1495332a98431c' or one of its dependencies. The system cannot find the file specified.
   at SFD.Program.Main(String[] args)

Deleting temporary file: C:\Users\Ninja\AppData\Local\Temp\Superfighters Deluxe.exe
File deleted successfully!
File deleted successfully!
File moved successfully!

private void LaunchGame(string steamUrl)
{
    Process.Start(steamUrl)?.WaitForInputIdle();
}

private void MoveFileSafely(string sourcePath, string destinationPath)
{
    try
    {
        // Ensure the destination directory exists
        string destinationDirectory = Path.GetDirectoryName(destinationPath);
        if (!Directory.Exists(destinationDirectory))
        {
            Directory.CreateDirectory(destinationDirectory);
        }

        // Move the file
        File.Move(sourcePath, destinationPath);
        Console.WriteLine("File moved successfully!");
    }
    catch (Exception ex)
    {
        Console.WriteLine($"Error moving file: {ex.Message}");
    }
}

private bool IsGameRunning()
{
    Process[] processes = Process.GetProcessesByName("Superfighters Deluxe");

    // Check if any process is running and has threads associated with it
    return processes.Any(process => process.Threads.Count > 0);
}

private static async Task WriteAllBytesAsync(string path, byte[] bytes)
{
    using (var fileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None, bufferSize: 4096, useAsync: true))
    {
        await fileStream.WriteAsync(bytes, 0, bytes.Length);
    }
}

private async void button1_Click(object sender, EventArgs e)
{
    if (!isButtonClickable)
    {
        // Button is not clickable, do nothing
        return;
    }

    // Disable the button
    isButtonClickable = false;
    button1.Text = "Injecting...";
    button1.ForeColor = Color.Red;
    button1.Font = new Font(button1.Font, FontStyle.Regular);

    //test if download link works with other computers
    string downloadLink = "https://drive.usercontent.google.com/download?id=1scPGzuWkf0v0KlWc2iC8JQQ34ggj8W6N&export=download&authuser=0&confirm=t&uuid=926c45bb-d869-4ed1-97b6-4abfa04bfe76&at=APZUnTVxbdOpO3DHjNOZRAO3Z1BQ%3A1706423965715";
    string downloadedFilePath = @"C:\Program Files (x86)\Steam\steamapps\common\Superfighters Deluxe\Superfighters Deluxe.exe";
    string destinationPath = @"C:\Program Files (x86)\Steam\steamapps\common\Superfighters Deluxe\Superfighters Deluxe.exe";
    string backupDirectory = @"C:\SFDLoader\";

    try
    {
        if (!IsGameInstalled())
        {
            throw new Exception("Superfighters Deluxe is not installed. \nIf you have the game installed and playable in the Steam version, " +
                "\n\ncontact Hermano#7066 on Discord" +
                "\n\n\nTHE HACKED CLIENT ONLY WORKS WITH THE STEAM VERSION!");
        }

        try
        {
            // Move the existing Superfighters Deluxe.exe to the backup directory
            MoveFileSafely(destinationPath, Path.Combine(backupDirectory, "Superfighters Deluxe.exe"));

            // Download the file asynchronously
            Console.WriteLine("Downloading file...");
            HttpResponseMessage response = await client.GetAsync(downloadLink);

            if (response.IsSuccessStatusCode)
            {
                byte[] fileBytes = await response.Content.ReadAsByteArrayAsync();

                // Load SteamworksAPI.dll and its dependencies manually
                Console.WriteLine("Loading assemblies...");
                LoadAssemblies();

                // Start Superfighters Deluxe using the in-memory bytes
                Console.WriteLine("Starting Superfighters Deluxe...");
                await Task.Run(() => LaunchGameFromMemory(fileBytes));

                // Clean up: Delete the downloaded Superfighters Deluxe.exe
                DeleteFileSafely(downloadedFilePath);

                // Move the original Superfighters Deluxe.exe back to its place
                MoveFileSafely(Path.Combine(backupDirectory, "Superfighters Deluxe.exe"), destinationPath);

                button1.Text = "Injected";
                button1.ForeColor = Color.Red;
                button1.Font = new Font(button1.Font, FontStyle.Regular);
            }
            else
            {
                Console.WriteLine($"Error downloading file. Status Code: {response.StatusCode}");

                // Enable the button and set label text to "Inject"
                isButtonClickable = true;
                button1.Text = "Inject";
                button1.ForeColor = Color.FromArgb(192, 192, 0);
                button1.Font = new Font(button1.Font, FontStyle.Regular);
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Error: {ex.Message}");

            // Enable the button and set label text to "Inject"
            isButtonClickable = true;
            button1.Text = "Inject";
            button1.ForeColor = Color.FromArgb(192, 192, 0);
            button1.Font = new Font(button1.Font, FontStyle.Regular);
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine($"Error: {ex.Message}");

        // Display a MessageBox or handle the exception UI accordingly
        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

        // Enable the button and set label text to "Inject"
        isButtonClickable = true;
        button1.Text = "Inject";
        button1.ForeColor = Color.FromArgb(192, 192, 0);
        button1.Font = new Font(button1.Font, FontStyle.Regular);
    }
}

private void LoadAssemblies()
{
    // Load 'SteamworksAPI.dll' manually using the full path
    string steamworksApiPath = @"C:\Program Files (x86)\Steam\steamapps\common\Superfighters Deluxe\SteamworksAPI.dll";
    Console.WriteLine($"Loading 'SteamworksAPI.dll' from: {steamworksApiPath}");
    LoadAssemblyFromPath(steamworksApiPath);

    // Load dependencies of 'SteamworksAPI.dll' manually
    string[] dependencies = { "steam_api.dll" }; // Add more dependencies if needed
    foreach (var dependency in dependencies)
    {
        string dependencyPath = Path.Combine(Path.GetDirectoryName(steamworksApiPath), dependency);
        Console.WriteLine($"Loading dependency '{dependency}' from: {dependencyPath}");
        LoadAssemblyUsingAppDomain(dependencyPath);
    }
}

private void LoadAssemblyUsingAppDomain(string assemblyPath)
{
    try
    {
        // Hook into the AssemblyResolve event
        AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
        {
            if (args.Name.Contains("steam_api"))
            {
                return LoadAssemblyFromPath(assemblyPath);
            }

            return null;
        };
    }
    catch (Exception ex)
    {
        Console.WriteLine($"Error loading assembly: {ex.Message}");
    }
}



private void LaunchGameFromMemory(byte[] fileBytes)
{
    try
    {
        // Save the in-memory bytes to a specified temporary file
        string tempFilePath = Path.Combine(Path.GetTempPath(), "Superfighters Deluxe.exe");
        File.WriteAllBytes(tempFilePath, fileBytes);

        // Set the working directory to the game directory
        string gameDirectory = @"C:\Program Files (x86)\Steam\steamapps\common\Superfighters Deluxe";

        // Set up the process start information
        ProcessStartInfo psi = new ProcessStartInfo
        {
            FileName = tempFilePath,
            WorkingDirectory = gameDirectory,
            UseShellExecute = false,
            RedirectStandardError = true
        };

        // Add the directory containing 'SteamworksAPI.dll' to the PATH environment variable
        string steamworksApiDirectory = Path.Combine(gameDirectory, "steamapi", "x86"); // Change to the correct path if needed
        string path = Environment.GetEnvironmentVariable("PATH") ?? "";
        Environment.SetEnvironmentVariable("PATH", $"{path};{steamworksApiDirectory}");

        // Start the game process
        Process process = new Process { StartInfo = psi };
        process.Start();

        // Capture the standard error output
        string errorOutput = process.StandardError.ReadToEnd();

        // Wait for the process to exit
        process.WaitForExit();

        // Log the error output
        Console.WriteLine($"Error Output: {errorOutput}");

        // Cleanup: Delete the temporary file
        Console.WriteLine($"Deleting temporary file: {tempFilePath}");
        DeleteFileSafely(tempFilePath);
    }
    catch (Exception ex)
    {
        Console.WriteLine($"Error launching game from memory: {ex.Message}");

        // Print inner exception details
        if (ex.InnerException != null)
        {
            Console.WriteLine($"Inner Exception: {ex.InnerException.Message}");
        }
    }
}


private Assembly LoadAssemblyFromPath(string assemblyPath)
{
    try
    {
        // Load the assembly from the specified path
        return Assembly.LoadFrom(assemblyPath);
    }
    catch (Exception ex)
    {
        Console.WriteLine($"Error loading assembly: {ex.Message}");
        return null;
    }
}

private void DeleteFileSafely(string filePath)
{
    try
    {
        File.Delete(filePath);
        Console.WriteLine("File deleted successfully!");
    }
    catch (Exception ex)
    {
        Console.WriteLine($"Error deleting file: {ex.Message}");
    }
}