wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Resources > - Submit a resource -
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 11-04-2011, 02:33 PM   #1
Bribe
User
 
Bribe's Avatar
 
Join Date: Mar 2010
Posts: 230

Submissions (1)

Bribe will become famous soon enough (26)

Send a message via AIM to Bribe
Default GameStatus

Collapse JASS:
library GameStatus initializer Ini /*
    
    GameStatus 2.0 by Bribe, special thanks to Troll-Brain
    
    Check if a game is single-player online or is a single-player replay. Due
    to Warcraft 3 limitations there is no known bugfree way to detect a multi-
    player replay.
    
    Even if you start a timer, pause the game, wait 0 seconds and unpause the
    game, the timer will show 0.025 elapsed for both online games and for re-
    plays.
    
    However, the main thing you need to detect is when the game is single-
    player, which means it's possible for the user to cheat. If you are doing
    an RPG and the user wants to play it single-player, the player can do it
    by selecting "LAN" as the method of play which doesn't even require an
    Internet connection. This way he/she can progress through the story line
    without needing other players and without you risking the player cheating.
    
    function IsGameSinglePlayer
        takes nothing
            returns boolean
    
        Returns true if the game is single player, where cheat codes can be
        used. This can be called during map initialization reliably.
    
    function OnGameStatusFound
        takes string func
            returns nothing
    
        Executes the function when the game's status has been detected. The 2
        functions "IsGameOnline" and "IsGameReplay" cannot be used reliably
        from an initializer, you must wait for this function to run first.
    
    function IsGameOnline
        takes nothing
            returns boolean
        
        Returns true if the game is being played over a network or a replay
        from a network game.
    
    function IsGameReplay
        takes nothing
            returns boolean
    
        Returns true if the game is a single-player replay. I have not been
        able to find a bug-free way to detect a replay from a game which was
        played online.
*/
    globals
        //If RGCFD returns true, cheat codes can be used (it's a non-network
        //single-player game).
        private integer iGame = IntegerTertiaryOp(ReloadGameCachesFromDisk(), 0, 1)
        private integer n = 0
        private string array funcs
    endglobals
    
    //=======================================================================
    function IsGameOnline takes nothing returns boolean
        return iGame == 2
    endfunction
    
    //=======================================================================
    function IsGameReplay takes nothing returns boolean
        return iGame == 1
    endfunction
    
    //=======================================================================
    function IsGameSinglePlayer takes nothing returns boolean
        return iGame == 0
    endfunction
    
    //=======================================================================
    function OnGameStatusFound takes string func returns nothing
        set funcs[n] = func
        set n = n + 1
    endfunction
    
    //=======================================================================
    /* private */ function GameStatus___aDs0F83254K43593Jfs takes nothing returns nothing
        call TriggerSleepAction(0)
        loop
            set n = n - 1
            exitwhen n < 0
            call ExecuteFunc(funcs[n])
        endloop
    endfunction
    
    //=======================================================================
    private function Ini takes nothing returns nothing
        call ExecuteFunc("GameStatus___aDs0F83254K43593Jfs")
        if iGame > 0 then
            //Replays ignore any thread-sleep type things which were not in
            //the original game - thus this is perfect for detecting a single-
            //player replay. TriggerSyncReady fires before TriggerSleepAction.
            call TriggerSyncReady()
            set iGame = 2
        endif
    endfunction
    
endlibrary

Last edited by Bribe : 11-14-2011 at 06:42 AM.
Bribe is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 11-04-2011, 09:59 PM   #2
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,080

Submissions (19)

Anitarf has a brilliant future (888)Anitarf has a brilliant future (888)Anitarf has a brilliant future (888)Anitarf has a brilliant future (888)Anitarf has a brilliant future (888)Anitarf has a brilliant future (888)Anitarf has a brilliant future (888)Anitarf has a brilliant future (888)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

  • return online == replay //True if both false.
    I'm not sure how both can be false considering this:
    set online = not replay


  • // Needs a module initializer because this timer has to expire before any
    // 0-second timers that depend on its results.
    I think it would be preferable from the user's perspective to provide an event for when the status is initialized, something like a onGameStatusInitializationComplete function (obviously with a shorter name), then you wouldn't need to use these module hacks and users wouldn't need to bother starting their own timers, they'd just write a callback function and pass it to GameStatus on map initialization, then GameStatus would execute it once it is initialized.
__________________
Anitarf is offline   Reply With Quote
Old 11-05-2011, 07:57 AM   #3
Bribe
User
 
Bribe's Avatar
 
Join Date: Mar 2010
Posts: 230

Submissions (1)

Bribe will become famous soon enough (26)

Send a message via AIM to Bribe
Default

If ReloadGameCachesFromDisk returns false, both will be false. I did that comparison just to avoid creating a third global.

I will look into adding an "OnGameStart" function.
Bribe is offline   Reply With Quote
Old 11-05-2011, 10:04 AM   #4
Anitarf
Procrastination Incarnate


Development Director
 
Join Date: Feb 2004
Posts: 8,080

Submissions (19)

Anitarf has a brilliant future (888)Anitarf has a brilliant future (888)Anitarf has a brilliant future (888)Anitarf has a brilliant future (888)Anitarf has a brilliant future (888)Anitarf has a brilliant future (888)Anitarf has a brilliant future (888)Anitarf has a brilliant future (888)

2008 Spell olympics - Fire - SilverApproved Map: Old School Alliance TacticsHero Contest #2 - 3rd PlaceSpell making session 2 winner

Default

I tested it and it works for single player, but I still don't understand why it works. Looking at the code, the last thing you do is set online = not replay in the timer expiration function, you don't modify the variables after that, so I don't see how they can both be false, but they can.

However, in my test, I did not get correct results when testing replays. The game was detected as online. The whole replay also started a few seconds into the game for some reason, not sure if that's normal.
__________________

Last edited by Anitarf : 11-05-2011 at 10:04 AM.
Anitarf is offline   Reply With Quote
Old 11-05-2011, 09:58 PM   #5
Bribe
User
 
Bribe's Avatar
 
Join Date: Mar 2010
Posts: 230

Submissions (1)

Bribe will become famous soon enough (26)

Send a message via AIM to Bribe
Default

Replays have always started a few seconds into the game.

Unfortunately there is a selection-event delay for replays the same as it works for online. I have almost completed a suitable alternative using a mix of a wait, game pause and a timer (as TriggerSleepAction is supposed to run during a paused game but a timer not, and replays react differently with paused games). However, I have run out of time today and have to continue this project tomorrow
Bribe is offline   Reply With Quote
Old 11-09-2011, 10:59 PM   #6
DioD
obey
 
DioD's Avatar
 
Join Date: Feb 2006
Posts: 1,532

Submissions (4)

DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)DioD is a jewel in the rough (220)

Send a message via ICQ to DioD
Default

replay cannot be paused.

usage of triggersleep (that will run ever when game is paused) and pause and timer will allow to detect pause state\event and forcepause will allow you to detect replay, in replay game cannot be paused at all.
DioD is offline   Reply With Quote
Old 11-10-2011, 10:03 AM   #7
Bribe
User
 
Bribe's Avatar
 
Join Date: Mar 2010
Posts: 230

Submissions (1)

Bribe will become famous soon enough (26)

Send a message via AIM to Bribe
Default

However I have tried it with timer and the timer is running anyway. Even through a paused game with TriggerSleepAction. However I will try it again adjusting this thing or that. But what I can say is a 0-second timer expires anyway, despite the game being paused. It's so weird.
Bribe is offline   Reply With Quote
Old 11-14-2011, 06:45 AM   #8
Bribe
User
 
Bribe's Avatar
 
Join Date: Mar 2010
Posts: 230

Submissions (1)

Bribe will become famous soon enough (26)

Send a message via AIM to Bribe
Default

Timers, paused games, selection event delays, all these things perform the same whether it's a replay or if it's an online game.

The main thing to detect is if a game can use cheats, which is already established via "ReloadGameCachesFromDisk()".

There is a way to determine if a game is a replay FROM a single player non-network game which I discovered by accident, however I can't get the difference between a network game and a replay of a network game.

The only hope is that the "igamestate" type can be used for something relevant here.
Bribe is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 12:23 AM.


Donate

Affiliates
The Hubb http://bylur.com - Warcraft, StarCraft, Diablo and DotA Blog & Forums The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2014, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services