Skip to content

SxLib API

Euphoriahh edited this page Oct 31, 2023 · 1 revision

SxLib API

Users who wish to write their own UIs for Synapse (or wanted to automate S^X usage) used to have to used the complex and hard to use WebSocket API in order to make their applications work. Now, you do not need to do this anymore. A new and much easier library to use - SxLib - makes it stupidly easy to make your own, fully custom UI or application using Synapse X with minimal effort and boilerplate code.

Introduction

SxLib is made in .NET and works for all .NET based languages (C#, VB, etc) - please note that this tutorial will use C# exclusively, but using it in VB has the same API set.

SxLib requires .NET Framework 4.6.1 or higher in your application. Please make sure to set that in your project settings before starting to use SxLib.

Getting Started

The first thing you will want to do is to add SxLib to your project. Add a reference in your Visual Studio project and go to your bin\sxlib folder in your Synapse X home directory. You will see sxlib.dll, which you can add as a reference to your project.

After that, we can start actually making an example interface using SxLib.

Initializing SxLib

After you add the reference to your project, its time to start actually programming in SxLib.

At this point, you will want to tell SxLib what application framework you are using so it can adjust its internal parameters accordingly. The SxLib.InitializeWinForms, SxLib.InitializeWPF, and SxLib.InitializeOffscreen methods will create an instance of SxLib for you to use with those parameters set.

The first parameter to the initialize method is important - you need to pass it your base Synapse X directory. For testing, we can set it to a constant path, but for actual release UIs you will want to have a prompt so the user can select their own path.

For WinForms or WPF based projects, you need to pass it an instance of your form or window aswell. You can usually use this for this purpose.

Whenever you switch forms in SxLib (for WinForms or WPF SxLib), use the SetWindow function in order to make sure that Window threads are sync'd.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using sxlib;

namespace SxLibTesting
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //Edit this to your own path.
            var SLib = SxLib.InitializeOffscreen(@"D:\Folders\Downloads\Synapse X v1.0.0");
        }
    }
}

Loading SxLib

The next step is to tell SxLib to update Synapse X and setup for execution. We can do this via the Load method. Note though, we have something we need to do first - we have to attach an event handler so we can check the progress of this. We can use the LoadEvent handler for this purpose.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using sxlib;

namespace SxLibTesting
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var SLib = SxLib.InitializeOffscreen(@"D:\Folders\Downloads\Synapse X v1.0.0");

            SLib.LoadEvent += Ev =>
            {
                //Print out the progress of Synapse X loading.
                Console.WriteLine(Ev);
            };

            SLib.Load();

            //This is so our program does not exit pre-maturely.
            Thread.Sleep(int.MaxValue);
        }
    }
}

If we run this program, we will see (if everything goes well) the following sequence:

CHECKING_WL
DOWNLOADING_DATA
CHECKING_DATA
READY

After READY, SxLib loading has completed and we can start now actually using Synapse X.

Attaching SxLib

Before we can start executing scripts though, we have to actually attach Synapse X. SxLib gives you the Attach method in order to do this process for you. We have to register an event handler (AttachEvent) for this aswell. In some cases, Attach does not needed to be called:

  • If the user has Auto-Launch enabled, you will automatically get event callbacks even if you did not call Attach.
  • The same goes for Auto-Attach.

Note if Synapse X detects that an attachable process is not open, it will send a FAILED_TO_FIND event into your AttachEvent handler.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using sxlib;
using sxlib.Specialized;

namespace SxLibTesting
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var SLib = SxLib.InitializeOffscreen(@"D:\Folders\Downloads\Synapse X v1.0.0");

            SLib.LoadEvent += Ev =>
            {
                if (Ev == SxLibBase.SynLoadEvents.READY)
                {
                    Console.WriteLine("Loading complete! Now attaching.");

                    //Register a handler for AttachEvent.
                    SLib.AttachEvent += SLibOnAttachEvent;

                    //Attach Synapse X.
                    SLib.Attach();

                    return;
                }

                //Print out the progress of Synapse X loading.
                Console.WriteLine($"Loading: {Ev}");
            };

            SLib.Load();

            //This is so our program does not exit pre-maturely.
            Thread.Sleep(int.MaxValue);
        }

        private static void SLibOnAttachEvent(SxLibBase.SynAttachEvents Ev)
        {
            //Print out progress of Synapse X attaching.
            Console.WriteLine($"Attaching: {Ev}");
        }
    }
}

If everything goes well, the following output will be observed:

Loading: CHECKING_WL
Loading: DOWNLOADING_DATA
Loading: CHECKING_DATA
Loading complete! Now attaching.
Attaching: CHECKING
Attaching: INJECTING
Attaching: CHECKING_WHITELIST
Attaching: SCANNING
Attaching: READY

If we run this program without an attachable process though, we will get the following output instead:

Loading: CHECKING_WL
Loading: DOWNLOADING_DATA
Loading: CHECKING_DATA
Loading complete! Now attaching.
Attaching: FAILED_TO_FIND

Some other events might be sent along this pipeline - the PROC_CREATED event will come through if Synapse X detects an attachable process has been created (you can use this for animations/etc like the default UI does) and the PROC_DELETED event will come through if an attachable process is exited out.

You only need to call Load once. After that, you can call Attach as many times as you want whenever an attachable process is created.

Executing Scripts with SxLib

Now since we are now loaded and attached, we can begin executing scripts. AutoExec scripts are handled internally, you do not need to deal with them yourself.

We can use the Execute method in order to execute scripts. Note, if you attempt to execute a script without being attached, you will get a NOT_INJECTED event across your attach pipeline.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using sxlib;
using sxlib.Specialized;

namespace SxLibTesting
{
    public class Program
    {
        private static SxLibOffscreen SLib;

        public static void Main(string[] args)
        {
            SLib = SxLib.InitializeOffscreen(@"D:\Folders\Downloads\Synapse X v1.0.0");

            SLib.LoadEvent += Ev =>
            {
                if (Ev == SxLibBase.SynLoadEvents.READY)
                {
                    Console.WriteLine("Loading complete! Now attaching.");

                    //Register a handler for AttachEvent.
                    SLib.AttachEvent += SLibOnAttachEvent;

                    //Attach Synapse X.
                    SLib.Attach();

                    return;
                }

                //Print out the progress of Synapse X loading.
                Console.WriteLine($"Loading: {Ev}");
            };

            SLib.Load();

            //This is so our program does not exit pre-maturely.
            Thread.Sleep(int.MaxValue);
        }

        private static void SLibOnAttachEvent(SxLibBase.SynAttachEvents Ev)
        {
            //Print out progress of Synapse X attaching.
            Console.WriteLine($"Attaching: {Ev}");

            if (Ev == SxLibBase.SynAttachEvents.READY)
            {
                //Execute our first script.
                SLib.Execute("print'Hello, world!'");
            }
        }
    }
}

If we run this program:

68747470733a2f2f692e646f6e616c646a7472756d702e696f2f3030653169366a6e2e706e67

Voila! We have now got script execution within Synapse X. We can now do practically whatever we want.

Executing Script Hub Scripts with SxLib

Of course, we still have one thing we wish to implement - the script hub. We can use the ScriptHub method in order to get us the current script hub. The ScriptHubEvent handler will return a list of SynHubEntry objects - which have a few properties:

  • Name: This is the name of the script in the script hub.
  • Description: This is a descrption of the script in the script hub.
  • Picture: A URL to a picture of the script in use.
  • Execute: This method will internally download and execute the script for you. You have to be attached in order to use this method - if you are not, you will get a NOT_INJECTED event in your attach pipeline.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using sxlib;
using sxlib.Specialized;

namespace SxLibTesting
{
    public class Program
    {
        private static SxLibOffscreen SLib;

        public static void Main(string[] args)
        {
            SLib = SxLib.InitializeOffscreen(@"D:\Folders\Downloads\Synapse X v1.0.0");

            SLib.LoadEvent += Ev =>
            {
                if (Ev == SxLibBase.SynLoadEvents.READY)
                {
                    Console.WriteLine("Loading complete! Now getting the script hub.");

                    //Register a handler for AttachEvent.
                    SLib.ScriptHubEvent += SLibOnScriptHubEvent;

                    //Attach Synapse X.
                    SLib.ScriptHub();

                    return;
                }

                //Print out the progress of Synapse X loading.
                Console.WriteLine($"Loading: {Ev}");
            };

            SLib.Load();

            //This is so our program does not exit pre-maturely.
            Thread.Sleep(int.MaxValue);
        }

        private static void SLibOnScriptHubEvent(List<SxLibBase.SynHubEntry> Entries)
        {
            //Iterate over each entry.
            foreach (var Entry in Entries)
            {
                Console.WriteLine($"Entry: \"{Entry.Name}\", \"{Entry.Description}\", \"{Entry.Picture}\"");
            }
        }
    }
}

If we execute this program, the following output is observed:

Loading: CHECKING_WL
Loading: DOWNLOADING_DATA
Loading: CHECKING_DATA
Loading complete! Now getting the script hub.
Entry: "Dark Dex", "A version of the popular Dex explorer with patches specifically for Synapse.
Bypasses most anti-exploits aswell.", "https://i.gyazo.com/bc1c2bc1fa799eac9c5810378cf63b25.png"
Entry: "Unnamed ESP", "ESP Made by ic3w0lf using the Drawing API, should be undetectable by every game", "https://i.gyazo.com/cc4a987a12f23e41a59ed079da70f524.png"
Entry: "JailbreakHaxx", "Synapse's exclusive Jailbreak GUI!", "https://i.gyazo.com/59328e0d858575495975efef4c328478.png"
Entry: "MadCityHaxx", "Synapse's exclusive Mad City GUI! Currently in open beta.", "https://i.gyazo.com/344032712d7bbd77393aedf078f0f7ee.png"
Entry: "PFHaxx", "Synapse's exclusive Phantom Forces GUI! (by Racist Dolphin)", "https://i.gyazo.com/622501ad369e94a1c7be8481e585602f.png"
Entry: "Stream Sniper", "Allows you to join a user, even if they have joining disabled in privacy settings. Bypasses blocking aswell.", "https://i.gyazo.com/45868ea2fa7acff79f3e896d525cda14.png"
Entry: "Remote Spy", "Allows you to view RemoteEvents and RemoteFunctions called by the game.", "https://i.gyazo.com/98fdddeb2a1198c5358241ecdf254420.png"
Entry: "Script Dumper", "Dumps all LocalScripts and ModuleScripts in the game. Works even if they attempt to hide their scripts.", "https://i.gyazo.com/349b3e9039ecd80b24c807ed008fe588.png"

We can then do Execute in order to execute the specific script you request.

Conclusion

SxLib is an easy to use and powerful API for making UIs and automating Synapse X. I will be making a video tutorial soon on how to use SxLib within your own custom UI, but this is a good starting point. Enjoy!