Cheats are proving a problem

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Laskow
Posts: 100
Joined: Tue Feb 16, 2021 7:35 am
Preferred Pronouns: He/Him

Re: Cheats are proving a problem

Post by Laskow »

m8f wrote:The thing is, fighting with cheaters is futile. People will always find a way. Even if built-in cheats are disabled, people can load a mod that makes them invulnerable. Or open your WAD/PK3 and put medikits everywhere. Or load your game with custom modified engine version where they have infinite ammo. Or play a game in a virtual machine with save states.

Adding more cheats is doable. Here is an example made with ZScript:
custom-cheats.pk3
This mod reads player key input, and if it matches "givesoul" or "shotg", gives a soulsphere or a shotgun to the player. I tried to comment the code to make it readable. This way, you can add your own cheat codes with custom behavior. You can also add additional effects to existing Doom codes. My pk3 doesn't override original cheat codes and cannot be disabled by DisableCheats.

Edit: just to add a note, custom cheat codes were already done before. For example, SWWM GZ has them.

Edit2: update: added check for chat commands.
This is the game changer.
I thought adding custom cheat codes is barely impossible and typing commands on console is the only way, but it's not!! Very amazing work!

By the way, I want to use it for my commercial project. Can you tell me the type of license, please?
User avatar
m8f
 
 
Posts: 1457
Joined: Fri Dec 29, 2017 4:15 am
Preferred Pronouns: He/Him
Location: Siberia (UTC+7)
Contact:

Re: Cheats are proving a problem

Post by m8f »

MIT.
Laskow
Posts: 100
Joined: Tue Feb 16, 2021 7:35 am
Preferred Pronouns: He/Him

Re: Cheats are proving a problem

Post by Laskow »

m8f wrote:MIT.
Thanks!!
User avatar
Hidden Hands
Posts: 1053
Joined: Tue Sep 20, 2016 8:11 pm
Location: London, England
Contact:

Re: Cheats are proving a problem

Post by Hidden Hands »

Sorry if this is redundant, but firstly, was is MIT licence? Also, M8f, you custom cheat zscript code says VERSION 4.5 but my games engine runs on 3.3.0. I'm not able to upgrade this, so will this be compatible? I'm about to attempt implementing it again now. But I have to know its worth the time. One last thing, how do I choose what I want my cheats to be? Only I don't see anywhere to let the game know what should be typed for what result?
User avatar
m8f
 
 
Posts: 1457
Joined: Fri Dec 29, 2017 4:15 am
Preferred Pronouns: He/Him
Location: Siberia (UTC+7)
Contact:

Re: Cheats are proving a problem

Post by m8f »

First, Custom Cheats now has a repository: https://github.com/mmaulwurff/custom-cheats/
Hidden Hands wrote:was is MIT licence?
MIT license. Basically, you are free to use this code in any kind of project, as long as you include the license text and author name somewhere in your project. You also aren't allowed to blame me if it doesn't work :) Bug reports are welcome, though.
Hidden Hands wrote:my games engine runs on 3.3.0
Regarding the version - it seems to work on GZDoom version 3.3.0 if you edit the version string. I wonder why you haven't tried it yourself. However, given that LZDoom and OpenGL ES renderer exist, I cannot see any valid reason not to upgrade. That's off-topic, sorry that I bring it up.
Hidden Hands wrote:how do I choose what I want my cheats to be?
I won't tell you. But I will tell you how to find it.
1. My post says "if it matches "givesoul" or "shotg", gives a soulsphere or a shotgun to the player". This gives you two clues: strings "givesoul" or "shotg".
2. Open the code. If you are not sure where to find the code, try zscript.txt in Custom Cheats pk3. Normally it contains either the code itself, or #include paths to code files.
3. There is a feature in your text editor, called "Find". Use it with strings from step one, for example, "givesoul".
4. This gives you the line: " if (mInput == "givesoul") sendCheat("cc_givesoul");". This gives you another clue: if input matches a certain string, sendCheat function is called with a certain key. Now you have to find where that key is used.
5. Again, use Find feature with "cc_givesoul". This gives you the line "if (event.name == "cc_givesoul")". In the curly braces after that line you'll find what the cheat does.

To make your own cheats, you have to edit checks found in step 4, and reactions found in step 5.

I tried to make the code as readable for everyone, and I failed :(
User avatar
Hidden Hands
Posts: 1053
Joined: Tue Sep 20, 2016 8:11 pm
Location: London, England
Contact:

Re: Cheats are proving a problem

Post by Hidden Hands »

I changed the version at the top and I'm getting this error. This is what I feared would happen. Any ideas why? In regards to updating, I did try that a few times, and it completely breaks my commercial game. Fixing it up to work with newer builds is far too time consuming. I'm keeping it at 3.3.0 as it is stable and works properly for me.
Attachments
error.png
User avatar
ramon.dexter
Posts: 1562
Joined: Tue Oct 20, 2015 12:50 pm
Graphics Processor: nVidia with Vulkan support
Location: Kozolupy, Bohemia

Re: Cheats are proving a problem

Post by ramon.dexter »

How many zscript files are you having? Also, don't you think that you should post the affected code without us telling you to do so? Whole code, please...
User avatar
Hidden Hands
Posts: 1053
Joined: Tue Sep 20, 2016 8:11 pm
Location: London, England
Contact:

Re: Cheats are proving a problem

Post by Hidden Hands »

zscript file is:

Code: Select all

version "3.3.0"

#include "zscript/Photokakos"
#include "zscript/Kakos"
#include "zscript/Curtains"
#include "zscript/Cheats"
Okay, it's just a basic copy of the one m8f posted that's why I didnt bother. Only difference is the version: 3.3.0 instead of 4.5 It's in the ZSCRIPT directory and it is called Cheats.

Code: Select all

version 3.3.0

class cc_EventHandler : EventHandler
{

  override bool inputProcess(InputEvent event)
  {
    // Ignore input events that are not key press.
    if (event.type != InputEvent.Type_KeyDown)
    {
      return false;
    }

    // Too much time since last input - discard everything that was previously typed.
    int timeSinceLastPress = Level.time - mLastPressTime;
    if (timeSinceLastPress > STALE_INPUT_THRESHOLD)
    {
      resetInput();
    }

    // Remember input and when it was taken.
    mLastPressTime = Level.time;
    mInput.appendFormat("%c", event.keyChar);

    bool shouldInputBeIgnored = (mInput.length() > 1)
      && (isKeyForCommand(event.keyScan, "messagemode")
       || isKeyForCommand(event.keyScan, "messagemode2"));

    // Check if input matches our custom cheat codes.
    //
    // As we cannot change gameplay directly in this function (it is UI-scoped),
    // we have to pass events through network code. The receiving end is in
    // networkProcess function.
    if      (mInput == "givesoul") sendCheat("cc_givesoul");
    else if (mInput == "shotg")    sendCheat("cc_shotg");

    return shouldInputBeIgnored;
  }

  override void networkProcess(ConsoleEvent event)
  {
    // get player who did cheat input.
    let player = players[event.player].mo;
    if (player == NULL) return;

    // Check if network event matches our cheat code events.
    //
    // Remember that this function catches all network events, including not
    // related to our custom cheat codes, so we have to react only on our
    // commands.
    if (event.name == "cc_givesoul")
    {
      // Spawn a soulsphere where player stands, player automatically picks it up.
      console.printf("Soulsphere cheat code activated!");
      Actor.spawn("Soulsphere", player.pos);
    }
    else if (event.name == "cc_shotg")
    {
      // Give the player a shotgun and select it.
      console.printf("Shotgun cheat code activated!");
      player.giveInventory("Shotgun", 1);
      player.player.pendingWeapon = Weapon(player.findInventory("Shotgun"));
    }
  }

// private: ////////////////////////////////////////////////////////////////////////////////////////

  private ui void sendCheat(string cheat)
  {
    sendNetworkEvent(cheat);
    resetInput();
  }

  private ui void resetInput() { mInput = ""; }

  private static ui
  bool isKeyForCommand(int key, string command)
  {
    Array<int> keys;
    bindings.getAllKeysForCommand(keys, command);
    uint nKeys = keys.size();
    for (uint i = 0; i < nKeys; ++i)
    {
      if (keys[i] == key) return true;
    }
    return false;
  }

  const STALE_INPUT_THRESHOLD = 35;

  private ui int    mLastPressTime;
  private ui string mInput;

}
User avatar
Enjay
 
 
Posts: 26979
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: Cheats are proving a problem

Post by Enjay »

Using this, how would a console command such as "kill monsters" look. e.g. if I wanted to create a cheat code that executes that (or any other) command?

I can set up everything else, I just don't know the syntax for the line that would actually execute the cheat would look if the cheat is something that can normally be typed at the console.
User avatar
m8f
 
 
Posts: 1457
Joined: Fri Dec 29, 2017 4:15 am
Preferred Pronouns: He/Him
Location: Siberia (UTC+7)
Contact:

Re: Cheats are proving a problem

Post by m8f »

Hidden Hands: you already have version line in your zscript file. Remove it from zscript/Cheats.

Enjay: this would require custom code, because console commands cannot be directly called from ZScript. Killing all monsters on the level would look like this:

Code: Select all

      ThinkerIterator i = ThinkerIterator.Create("Actor");
      Actor a;
      while (a = Actor(i.Next()))
      {
        if (a.bIsMonster)
        {
          a.a_Die();
        }
      }
User avatar
Enjay
 
 
Posts: 26979
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: Cheats are proving a problem

Post by Enjay »

m8f wrote: Enjay: this would require custom code, because console commands cannot be directly called from ZScript.
I did wonder if that was probably the case, given that they can't be called from ACS due to safety concerns either.

Thanks for the code. I'll test it out. [edit] and, of course, it works. Thanks. :) [/edit]
User avatar
Hidden Hands
Posts: 1053
Joined: Tue Sep 20, 2016 8:11 pm
Location: London, England
Contact:

Re: Cheats are proving a problem

Post by Hidden Hands »

Thanks for the tip. I removed it from the cheat section but now I have this error... and this one is far worse becuase i literally have no idea whatsoever what its talking about. I mean I know what it says, but I cannot see a logical fix... at all.
Attachments
27873.png
User avatar
m8f
 
 
Posts: 1457
Joined: Fri Dec 29, 2017 4:15 am
Preferred Pronouns: He/Him
Location: Siberia (UTC+7)
Contact:

Re: Cheats are proving a problem

Post by m8f »

My bad. This getAllKeysForCommand function doesn't exist in GZDoom 3.3.0. I did something wrong when I checked 3.3.0 compatibility.

To fix this, change isKeysForCommand function in zscript/Cheats to the following:

Code: Select all

  private static ui
  bool isKeyForCommand(int key, string command)
  {
    int key1, key2;
    [key1, key2] = bindings.getKeysForCommand(command);
    return (key1 == key || key2 == key);
  }
User avatar
Hidden Hands
Posts: 1053
Joined: Tue Sep 20, 2016 8:11 pm
Location: London, England
Contact:

Re: Cheats are proving a problem

Post by Hidden Hands »

That fixed it, thank you. I do have one little question though as this script you've written is really something... So I'm going to post something here so tell me if I'm in the right ball park.

Your code...

Code: Select all

 if (event.name == "cc_givesoul")
    {
      // Spawn a soulsphere where player stands, player automatically picks it up.
      console.printf("Soulsphere cheat code activated!");
      Actor.spawn("Soulsphere", player.pos);
    }
This is your code to retrieve a soulsphere. Seems perfect. But I'm still a little lost at how this works.. .exactly.

Obviously, the "givesoul" is self explanetory, and it spawn on your exact position which is how you activate it. But how would one go about doing this with a noclip for example? If I want the player to clip through walls with a custom command... I assume this would be a different scripting entirely. I'm sure most people have grasped this. But I'm not quite getting it. I think I drank too much flouride becuase my mind zones out when trying to understand this.

I have cheats planned for this: Basically...

1. NoClip with a custom command
2. All wepaons, keys and ammo with a custom command
3. God mode with a custom command.

As I say, I'm sure this is simple to most other people.
User avatar
m8f
 
 
Posts: 1457
Joined: Fri Dec 29, 2017 4:15 am
Preferred Pronouns: He/Him
Location: Siberia (UTC+7)
Contact:

Re: Cheats are proving a problem

Post by m8f »

1. Toggle noclip:

Code: Select all

      PlayerInfo player = players[consolePlayer];
      if (player.cheats & CF_NOCLIP)
      {
        player.cheats &= ~CF_NOCLIP;
      }
      else
      {
        player.cheats |= CF_NOCLIP;
      }
See also other cheat flags.

2. Give all:

Code: Select all

      let player = players[consolePlayer].mo;
      if (player)
      {
        player.cheatGive("all", 0);
      }
Some othercheating functions.

3. God mode:

Code: Select all

      PlayerInfo player = players[consolePlayer];
      if (player.cheats & CF_GODMODE)
      {
        player.cheats &= ~CF_GODMODE;
      }
      else
      {
        player.cheats |= CF_GODMODE;
      }
You can find many curious things when browsing GZDoom ZScript files.
Post Reply

Return to “Scripting”