Home > Software design >  The name 'api' does not exist in the current context
The name 'api' does not exist in the current context

Time:10-19

So im trying to make an executor but i got that error along with "A namespace cannot directly contain members such as field, methods or statements"

i tried looking into it myself and googling around a bit but couldnt really find a solution to the problem, any help here are of course appreciated as this is a project i would like to get working to 100% as intended.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WeAreDevs_API;

namespace ZynTap_Executor
{
    ExploitAPI api = new ExploitAPI();
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Environment.Exit(0);
        }
        Point lastPoint;
        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            lastPoint = new Point(e.X, e.Y);
        }

        private void panel1_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                this.Left  = e.X - lastPoint.X;
                this.Top  = e.Y - lastPoint.Y;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            WindowState = FormWindowState.Minimized;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            fastColoredTextBox1.Clear();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            api.SendLuaScript(fastColoredTextBox1.Text);
        }

        private void button8_Click(object sender, EventArgs e)
        {
            api.LaunchExploit();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                openFileDialog1.Title = "Open";
                fastColoredTextBox1.Text = File.ReadAllText(openFileDialog1.FileName);
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                using (Stream s = File.Open(saveFileDialog1.FileName, FileMode.CreateNew))
                using (StreamWriter sw = new StreamWriter(s))
                {
                    sw.Write(fastColoredTextBox1.Text);
                }
            }
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            fastColoredTextBox1.Text = File.ReadAllText($"./Scripts/{listBox1.SelectedItem}");
        }

        private void button7_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();//Clear Items in the LuaScriptList
            Functions.PopulateListBox(listBox1, "./Scripts", "*.txt");
            Functions.PopulateListBox(listBox1, "./Scripts", "*.lua");
        }
    }
}

CodePudding user response:

You can't put this assignment

ExploitAPI api = new ExploitAPI();

in the namespace section. You need to put it inside the Form1 class:

namespace ZynTap_Executor
{
    public partial class Form1 : Form
    {
        ExploitAPI api = new ExploitAPI();
        public Form1()
        {
            InitializeComponent();
        }
        ...
    }
}

CodePudding user response:

I see you are creating a roblox exploit using the WeAreDevs API. Make sure you put the ExploitAPI api = new ExploitAPI(); call inside of the form class. Since the WRD API is also just pieces of code and you only need to read it with your Form App, you should put it as a readonly

This is a snippet from my old outdated executor.

public partial class Form2 : Form
{
    readonly ExploitAPI api = new ExploitAPI();

    public Form2()
    {
        InitializeComponent();
    }

    private void InjectBtn_Click(object sender, EventArgs e)
    {
        api.LaunchExploit();
    }
}

Github: https://github.com/REFUZIION/refsploit-roblox/blob/master/REFSPLOiT/Form2.cs

  •  Tags:  
  • c#
  • Related