Skip to content

Snippets & Examples

Here are some snippets and full code examples


Diffusing Notification (CS:GO/CSS)

This example uses constellation.memory functions and constellation.get functions to find out if anyone currently in the game is diffusing the bomb.

Ideally, this should be implemented in a package with other player checking features. Obviously, you don't want to have a bunch of browser tabs open. sdk_test.html is an example of a package of checks that updates in real-time.

$(document).ready(function() {
    /// get our current game
    game = constellation.game()

    /// bombs are only in CS:GO and CSS. TF2 and Dota, ignore.
    if (game == "CS:GO" || game == "CSS") {
        /// https://github.com/frk1/hazedumper/blob/master/config.json#L625
        m_bIsDefusing = constellation.memory.netvar("DT_CSPlayer", "m_bIsDefusing")

        /// did we fail to get this netvar?
        if (!m_bIsDefusing) {
            console.log("Failed to get \"m_bIsDefusing\".")
            return
        }

        /// start timer to refresh player information.
        window.setInterval(check_diffusers, 1000);
    }
});

function check_diffusers() {
    /// get localplayer
    var localplayer = constellation.get.localplayer()

    /// we're not in a server.
    if (localplayer == null) return

    /// get all players in the server.
    var player_database = constellation.get.players()

    /// loop through all our players
    for (const property in player_database) {
        /// parse their json data
        const json_information = JSON.parse(player_database[property])

        /// read their m_bIsDefusing property.
        var is_diffusing = constellation.memory.read(json_information.address + m_bIsDefusing)

        /// they are indeed diffusing.
        if (is_diffusing == 1) {
            /// <code>Your code here that notifies you they are diffusing</code>
            console.log(json_information.name + " is defusing...")
        }
    }
}

Uber Counting (TF2)

This is a very basic example that slowly shows your uber percentage on the page. If you use constellation.get.players based off of this example, you will be able to get the uber percentage of every medic in the game.

$(document).ready(function() {
    /// get our current game
    game = constellation.game()

    /// TF2 only.
    if (game == "TF2") {
        /// DT_WeaponMedigun -> m_flChargeLevel
        m_flChargeLevel = constellation.memory.netvar("DT_WeaponMedigun", "m_flChargeLevel")

        /// did we fail to get this netvar?
        if (!m_flChargeLevel) {
            console.log("Failed to get \"m_flChargeLevel\".")
            return
        }

        /// keep updating our percentage
        window.setInterval(check_percentage, 1000);
    }
});

function check_percentage() {
    /// get local player
    var localplayer = constellation.get.localplayer()

    /// are we ingame?
    if (localplayer == null) return

    /// get our weapon because "m_flChargeLevel" is for weapons, not players. (hint: DT_->WeaponMedigun<--)
    var weapon = constellation.get.weapon()

    /// we don't have a weapon.
    if (weapon == null) return

    /*
        are we even a medic?

        1: Scout
        2: Sniper
        3: Soldier
        4: Demoman
        5: Medic
        6: Heavy
        7: Pyro
        8: Spy
        9: Engineer
    */
    if (localplayer.class != 5) return

    /// medigun charge
    var medigun_charge = constellation.memory.read_float(weapon.address + m_flChargeLevel)

    /// uber percentage as the charge needs to be multiplied by 100.
    var uber_percentage = medigun_charge * 100

    /// you have uber, what now?
    if (uber_percentage == 100) {
        /// <code>Your code here that tells you that you have uber</code>
    }

    /// <code>Maybe your colorful and aesthetic bar that fills up using your uber percentage</code>
}

sdk_test.html

As of early December 2021, this is the latest sdk_test.html document that is downloaded with Constellation per launch. This showcases a handful of functions and how you can get player information in a timer.

<!--
    @title
        fantasy.constellation Web GUI - sdk_test.html
    @author
        typedef
    @notes
        Function References:

        ~Line 35 -> constellation.memory.module
        ~Line 65 -> constellation.memory.pattern
        ~Line 88 -> constellation.get.localplayer & constellation.get.players
        ~Line 130 -> constellation.memory.netvar
        ~Line 142 -> constellation.memory.read
        ~Line 167 -> constellation.mouse.move
-->
<html>

    <head>
        <!-- script includes -->
        <script src="https://code.jquery.com/jquery-3.6.0.js" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"></script>
        <script src="js/fantasy.constellation.js"></script>

        <!-- title -->
        <title>fantasy.constellation - sdk test.html</title>

        <!-- script -->
        <script>

            /// sdk_test.html loaded.
            $( document ).ready(function() 
            {
                /// get our current game
                game = constellation.game()

                /// get client.dll and engine.dll (engine2.dll for Dota 2)
                module_client = constellation.memory.module("client.dll")
                module_engine = constellation.memory.module("engine.dll")
                module_engine2 = constellation.memory.module("engine2.dll")

                /// check if client.dll is loaded. if not, then we're not ingame or Constellation isn't started.
                if( !module_client ) return

                /// display client.dll and engine.dll information.
                $("#game_information").html(
                    `
                        [${game}]<br />
                        client.dll: ${module_client.address}<br />
                        engine.dll: ${module_engine.address}<br />
                        engine2.dll: ${module_engine2.address}<br />
                    `
                );

                /// start timer to refresh player information.
                window.setInterval(timer_players, 1000);

                /*
                    [ignore if you don't understand memory manipulation]          
                    testing the pattern scanning function.

                    constellation.memory.pattern( mod, size, pattern, offset, extra, unrelative )
                */
                if( game == "CS:GO")
                {
                    /// https://github.com/frk1/hazedumper/blob/master/config.json#L285
                    dwLocalPlayer = constellation.memory.pattern( 
                        module_client.address, // client.dll
                        module_client.size, /// client.dll's size.
                        "8D 34 85 ? ? ? ? 89 15 ? ? ? ? 8B 41 08 8B 48 04 83 F9 FF", /// pattern
                        3, /// offset
                        4, /// extra
                        0, /// unrelativity
                     )

                     /// dwLocalPlayer should equal 14316652 | https://github.com/frk1/hazedumper/blob/master/csgo.json#L34
                     console.log( dwLocalPlayer )
                }
            });

            /// timer to refresh player information.
            function timer_players() 
            {
                /// get localplayer
                var localplayer = constellation.get.localplayer() 

                /// are we even ingame?
                if( localplayer == null ) return null

                /// we're ingame, get all players while we're at it
                var player_database = constellation.get.players() 

                /// set localplayer information.
                $("#localplayer_information").html(
                    `
                    Name: ${localplayer.name}<br />
                    Steam: ${localplayer.steam}<br />
                    X: ${localplayer.x}<br />
                    Y: ${localplayer.y}<br />
                    Z: ${localplayer.z}<br />
                    Viewangles X: ${localplayer.viewangles.x}<br />
                    Viewangles Y: ${localplayer.viewangles.y}<br />
                    Viewangles Z: ${localplayer.viewangles.z}<br />
                    `
                );   

                /// set all player information
                $('#player_information').html("<th>Name</th><th>Steam</th>")
                for( const property in player_database )
                {
                    const json_information = JSON.parse(player_database[property])
                    $('#player_information').append(`<tr><td>${json_information.name}</td><td>${json_information.steam}</td></tr>`);
                }

                ///===========================================================================
                /*
                    Testing further memory functions now.
                    Let's check if the localplayer (us) is in the middle of reloading.
                    Then display the information.
                */

                /// check if we're in CS:GO.
                if( game == "CS:GO")
                {
                    /// https://github.com/frk1/hazedumper/blob/master/config.json#L619
                    m_bInReload = constellation.memory.netvar( "DT_BaseCombatWeapon", "m_flNextPrimaryAttack" ) + 109

                    /// https://github.com/frk1/hazedumper/blob/master/config.json#L630
                    m_bIsScoped = constellation.memory.netvar( "DT_CSPlayer", "m_bIsScoped" )

                    /// it looks like we couldn't get the netvar for some reason
                    if( !m_bInReload ) return

                    /// check if we have a weapon.
                    if( !localplayer.weapon_address ) return 

                    /// read memory to check if we're scoped!
                    is_localplayer_scoped = constellation.memory.read( localplayer.address + m_bIsScoped )

                    /// read memory to check if we're reloading!
                    is_localplayer_reloading = constellation.memory.read( localplayer.weapon_address + m_bInReload )

                    /// yes, we are scoped
                    if( is_localplayer_scoped == 1 ) $("#localplayer_information").append("SCOPED!<br />");

                    /// yes, we are reloading
                    if( is_localplayer_reloading == 1 ) $("#localplayer_information").append("RELOADING!<br />");

                    /// annoying mode: make constelia talk every time you reload (not recommended)
                    ///if ( is_localplayer_scoped == 1 ) constellation.constelia.say( "Get cover! We're reloading!")
                }
            }
        </script>
    </head>

    <body>
        <div id="game_information"></div><br />
        <div id="localplayer_information"></div><br />
        <table id="player_information"></table><br />

        Mouse X: <input type="number" value="0"  id="mouse_x"><br />
        Mouse Y: <input type="number" value="0"  id="mouse_y"><br />
        <button onclick="constellation.mouse.move($('#mouse_x').val(), $('#mouse_y').val())">Move Mouse</button><br />
    </body>

</html>

Save & Load (Buttons)

This shows how to save and load your configuration. This is already found in menu.html.

<button onclick="fantasy_cmd(this, 'load')">Load Configuration</button>
<button onclick="fantasy_cmd(this, 'save')">Save Configuration</button>

Get Map Name (CS:GO)

This example shows the power of pattern scanning and getting information from your game. This will display the map name you are currently on.

$(document).ready(function() {
    /// get our current game
    game = constellation.game()

    /// get our modules
    module_engine = constellation.memory.module("engine.dll")

    /// check if engine.dll is loaded. if not, then we're not ingame or Constellation isn't started.
    if (!module_engine) return

    /// are we in CS:GO?
    if (game != "CS:GO") return

    /// get dwClientState | https://github.com/frk1/hazedumper/blob/master/config.json#L6
    dwClientState = constellation.memory.pattern(
        module_engine.address, /// engine.dll
        module_engine.size, /// engine.dll size
        "A1 ? ? ? ? 33 D2 6A 00 6A 00 33 C9 89 B0", /// pattern
        1, /// offset
        0, /// extra
        0 /// unrelativity
    )

    /// we couldn't get dwClientState
    if (!dwClientState) {
        console.log("Failed to get \"dwClientState\".")
        return
    }

    /// get dwClientState_Map | https://github.com/frk1/hazedumper/blob/master/config.json#L36
    dwClientState_Map = constellation.memory.pattern(
        module_engine.address, /// engine.dll
        module_engine.size, /// engine.dll size
        "05 ? ? ? ? C3 CC CC CC CC CC CC CC A1", /// pattern
        1, /// offset
        0, /// extra
        true /// unrelativity
    )

    /// we couldn't get dwClientState_Map
    if (!dwClientState) {
        console.log("Failed to get \"dwClientState_Map\".")
        return
    }

    /// get client state engine pointer.
    engine_pointer = constellation.memory.read(module_engine.address + dwClientState)

    /// we couldn't get engine pointer
    if (!engine_pointer) {
        console.log("Failed to get \"engine_pointer\".")
        return
    }

    /// get map
    current_map = constellation.memory.read_string(engine_pointer + dwClientState_Map)

    if (current_map == null) {
        /*
            This check wouldn't need to be done if you had used.
            constellation.get.localplayer and checked if the return
            value was null or not. But in this example, we are not using
            that function.
        */

        console.log("You are not on a server right now.")
        return
    }

    /// print our map name | I am on "aim_botz" therefore console prints "workshop/243702660/aim_botz"
    console.log(current_map)
});