• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[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:
Level 8
Joined
Jul 10, 2008
Messages
353
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.
 
Level 8
Joined
Jul 10, 2008
Messages
353
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:
Top