• Check out the results of the Techtree Contest #19!
  • Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

[vJASS] GameStatus (Replay Detection)

Simple API for detecting if the game is online, offline, or a replay. This library is especially useful for giving the ability to run code specifically in replays. For example, you could display debug messages throughout your game that only display in replays. If someone is having an issue with your map, they can send you a replay where you can view the debug messages.

This replay detection works different than previous attempts and has significant benefits over them.
  1. Instant detection.
  2. Safe.
The previous most common use of a replay detection involved setting camera position. This however could be bypassed by minimizing your game client, causing the script to think it's a replay. This allowed players to trick maps which used the system in order to cheat. That is not the case with this library.

Uses:
  1. PlayerUtils (Optional)

JASS:
library GameStatus uses optional PlayerUtils
/***************************************************************
*
*   v1.0.0 by TriggerHappy
*   ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
*   Simple API for detecting if the game is online, offline, or a replay.
*   _________________________________________________________________________
*   1. Installation
*   ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
*   Copy the script to your map and save it (requires JassHelper *or* JNGP)
*   _________________________________________________________________________
*   2. API
*   ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
*   This library provides one function
*
*       function GetGameStatus takes nothing returns integer
*
*   It returns one of the following constants
*
*       - GAME_STATUS_OFFLINE
*       - GAME_STATUS_ONLINE
*       - GAME_STATUS_REPLAY
*
***************************************************************/

// Configuration:
globals
    // The dummy unit is only created once, and removed directly after.
    private constant integer DUMMY_UNIT_ID = 'hfoo'
endglobals
// (end)

globals
    constant integer GAME_STATUS_OFFLINE = 0
    constant integer GAME_STATUS_ONLINE  = 1
    constant integer GAME_STATUS_REPLAY  = 2
 
    private integer status = 0
endglobals

function GetGameStatus takes nothing returns integer
    return status
endfunction

private module GameStatusInit

    private static method onInit takes nothing returns nothing
        local player firstPlayer
        local unit u
        local boolean selected
   
        // find an actual player
        static if not (LIBRARY_PlayerUtils) then
            set firstPlayer = Player(0)
            loop
                exitwhen (GetPlayerController(firstPlayer) == MAP_CONTROL_USER and GetPlayerSlotState(firstPlayer) == PLAYER_SLOT_STATE_PLAYING)
                set firstPlayer = Player(GetPlayerId(firstPlayer)+1)
            endloop
        else
            set firstPlayer = User.fromPlaying(0).toPlayer()
        endif
   
        // force the player to select a dummy unit
        set u = CreateUnit(firstPlayer, DUMMY_UNIT_ID, 0, 0, 0)
        call SelectUnit(u, true)
        set selected = IsUnitSelected(u, firstPlayer)
        call RemoveUnit(u)
        set u = null
   
        if (selected) then
       
            // detect if replay or offline game
            if (ReloadGameCachesFromDisk()) then
                set status = GAME_STATUS_OFFLINE
            else
                set status = GAME_STATUS_REPLAY
            endif
       
        else
            // if the unit wasn't selected instantly, the game is online
            set status = GAME_STATUS_ONLINE
        endif
   
    endmethod
 
endmodule

private struct GameStatus
    implement GameStatusInit
endstruct

endlibrary

GameStatus - Replay Detection (GUI Demo)
 
Last edited:
Promising work on a much needed tool, my only issue on installing this is that it requires vJass and it will mess up my war3map.j formatted text and comments, which I have worked a lot to keep it tied and clean to work on! Nonetheless this looks short enough for me to translate it into jass. I will be testing it tonight.
 
Promising work on a much needed tool, my only issue on installing this is that it requires vJass and it will mess up my war3map.j formatted text and comments, which I have worked a lot to keep it tied and clean to work on! Nonetheless this looks short enough for me to translate it into jass. I will be testing it tonight.

I just uploaded a GUI version to the spells section. It should be easy to convert to JASS.
 
I just uploaded a GUI version to the spells section. It should be easy to convert to JASS.
No i found a "trick". I just used jasshelper, I took a w/e map, imported an empty war3map.j and copy paste your code + an empty "main" function. It automatically translated it.

thnx for help tho.
 
Last edited:
Haha time to necro-post, jk.

Here's a Lua version since I made Replay POV Detection require it

Lua:
if Debug then Debug.beginFile "GameStatus" end
OnInit.main("GameStatus", function()
    --[[***************************************************************
    *
    *   v1.0.0 by TriggerHappy (transpiled by InsanityAI)
    *   ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
    *   Simple API for detecting if the game is online, offline, or a replay.
    *   _________________________________________________________________________
    *   1. Installation
    *   ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
    *   Get TotalInitialization - https://www.hiveworkshop.com/threads/total-initialization.317099/post-3641920
    *   Copy this script to your map and save it
    *   _________________________________________________________________________
    *   2. API
    *   ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
    *   This library provides one function
    *
    *       function GetGameStatus(): GameStatus
    *
    *   It returns one of the following enum constants
    *
    *       - GameStatus.OFFLINE
    *       - GameStatus.ONLINE
    *       - GameStatus.REPLAY
    *
    ***************************************************************--]]

    -- Configuration:
    local DUMMY_UNIT_ID = FourCC('hfoo')

    ---@enum GameStatus
    GameStatus = {
        OFFLINE = 0,
        ONLINE = 1,
        REPLAY = 2
    }
    local status = GameStatus.OFFLINE

    ---@return GameStatus
    function GetGameStatus()
        return status
    end

    -- Game Status Initialization
    do
        -- find an actual player
        local firstPlayer = Player(0)
        while (GetPlayerController(firstPlayer) ~= MAP_CONTROL_USER or GetPlayerSlotState(firstPlayer) ~= PLAYER_SLOT_STATE_PLAYING) do
            firstPlayer = Player(GetPlayerId(firstPlayer) + 1)
        end

        -- force the player to select a dummy unit
        local u = CreateUnit(firstPlayer, DUMMY_UNIT_ID, 0, 0, 0)
        SelectUnit(u, true)
        local selected = IsUnitSelected(u, firstPlayer)
        RemoveUnit(u)

        if (selected) then
            -- detect if replay or offline game
            if (ReloadGameCachesFromDisk()) then
                status = GameStatus.OFFLINE
            else
                status = GameStatus.REPLAY
            end
        else
            -- if the unit wasn't selected instantly, the game is online
            status = GameStatus.ONLINE
        end
    end
end)
if Debug then Debug.endFile() end
 
Back
Top