Need help improve my anticheating engine

General FreeBASIC programming questions.
mrminecrafttnt
Posts: 85
Joined: Feb 11, 2013 12:23

Need help improve my anticheating engine

Postby mrminecrafttnt » May 14, 2019 15:17

This code is an simple anticheating engine, to defend my values in games from cheaters, based on hashed xor encrypted integers.
When an cheat was detectet is the returned value zero(0).
It is not perfect so it can be easy cracked with https://www.cheatengine.org/ as example, and this is why i need some ideas and tips to improve this one.. :)
Thanks!

Code: Select all

type nocheat_data
    value as integer
    key as integer
    hash as integer
end type

type nocheat
    private:
    ncd as nocheat_data
    public:
    declare sub set (value as integer)
    declare function get as integer
end type

sub nocheat.set (value as integer)
    ncd.key = int(rnd*9999999)+1
    ncd.value = value xor ncd.key
    ncd.hash = ncd.value * ncd.key
end sub

function nocheat.get as integer
    if ncd.hash = ncd.value * ncd.key then
        return ncd.value xor ncd.key
    end if
end function

' test function
dim as nocheat test
test.set 123456
print test.get
sleep
Tourist Trap
Posts: 2756
Joined: Jun 02, 2015 16:24

Re: Need help improve my anticheating engine

Postby Tourist Trap » May 15, 2019 9:38

mrminecrafttnt wrote:This code is an simple anticheating engine, to defend my values in games from cheaters, based on hashed xor encrypted integers.
When an cheat was detectet is the returned value zero(0).
It is not perfect so it can be easy cracked with https://www.cheatengine.org/ as example, and this is why i need some ideas and tips to improve this one.. :)

Hard to answer you from my part. I don't understand your need at all. I have those questions mainly:
What is the purpose of your program in a real case?
What is this website, cheatengine, and what do you expect from it?

Maybe you can provide those bits of info. Thanks.
mrminecrafttnt
Posts: 85
Joined: Feb 11, 2013 12:23

Re: Need help improve my anticheating engine

Postby mrminecrafttnt » May 15, 2019 11:00

Tourist Trap wrote:Hard to answer you from my part. I don't understand your need at all. I have those questions mainly:
What is the purpose of your program in a real case?
What is this website, cheatengine, and what do you expect from it?

Maybe you can provide those bits of info. Thanks.

Oh my bad but it simple:
Cheatengine is an software that can manipulate the data of other Programms in the Memory(RAM) per directly. As example can a cheater change the highscore, hp, damage in games etc. and i will make an protection for this.. :D
In an example case: An cheater will try to set the Highscore in an game from 1245670 to 99999999 so he simply uses cheatengine, scans the memory for 1245670 and sets this to 99999999. Exactly this will i prevent with any methods and ideas..
In my example code is the value xor encrypted and can't be found in chaetengine without decryption or memoryadress extraction.
Memoryadress extraction works with

Code: Select all

HEX(@value)

this returns the memory adress of the target value and can be simple entered in cheatengine to change the value.

Overall i will make an protection for cheaters, specially for cheaters who uses cheatengine.. :)

Additional i have added an other code, so i hope you understand it now, this should be show up why my idea is so weak..

Code: Select all

type anticheat
    value as integer
    key as integer
    hash as integer
    declare sub set (v as integer)
    declare function get as integer
end type

sub anticheat.set (v as integer)
    key = int(rnd*999999999)
    value = v xor key
    hash = key + value
end sub

function anticheat.get as integer
    if hash = key + value then
        return value xor key
    else
        return 0
    end if
end function


'###example starts here###

dim as anticheat score
score.set 10000
Print "CHEAT ME! INCRASE WITH + / DECRASE WITH -"

do
    locate 2
    print score.get
    print "Adresses:"
    print "VALUE ADRESS      =";HEX(@score.value)
    print "KEY  ADRESS       =";HEX(@score.key)
    print "HASH ADRESS       =";HEX(@score.hash)
    Print "Values:"
    print "VALUE (encrypted) =";score.value
    print "KEY               =";score.key
    print "HASH              =";score.hash
    select case input(1)
    case "+"
        score.set score.get + 1
    case "-"
        score.set score.get - 1
    case else
        exit do
    end select
loop
Tourist Trap
Posts: 2756
Joined: Jun 02, 2015 16:24

Re: Need help improve my anticheating engine

Postby Tourist Trap » May 15, 2019 17:06

mrminecrafttnt wrote:In an example case: An cheater will try to set the Highscore in an game from 1245670 to 99999999 so he simply uses cheatengine, scans the memory for 1245670 and sets this to 99999999. Exactly this will i prevent with any methods and ideas...

Ok, thank you :)
Now it's clear enough ! but I have no idea for now.

edit:
I have found this so far...

Code: Select all

#include "fbgfx.bi"

#macro _ExitforOnEscapeKeyPressed
  if inkey()=chr(27) then exit for
#endMacro

type SCREENTEST extends OBJECT
    'global variable container
    'storing screen parameter
    declare static sub TestScreen()
    static as integer  scrW
    static as integer  scrH
end type 'SCREENTEST <- OBJECT
dim as integer SCREENTEST.scrW       => -1
dim as integer SCREENTEST.scrH       => -1
sub SCREENTEST.TestScreen()
    screenInfo (SCREENTEST.scrW, SCREENTEST.scrH)
end sub 'SCREENTEST.TestScreen()

type INTERACTIONTEST extends SCREENTEST
    'global variable container
    'storing mouse/keyboard interaction
    declare static function TestMouse() as long
    declare static function TestKeyboard() as long
    static as long  gmX
    static as long  gmY
    static as long  gmBtn
    static as long  scanCode
end type 'INTERACTIONTEST <- SCREENTEST <- OBJECT
dim as long INTERACTIONTEST.gmX        => -1
dim as long INTERACTIONTEST.gmY        => -1
dim as long INTERACTIONTEST.gmBtn      => -1
dim as long INTERACTIONTEST.scanCode   => -1
function INTERACTIONTEST.TestMouse() as long
    return getMouse ( INTERACTIONTEST.gmX, _
                    INTERACTIONTEST.gmY, _
                    , _
                    INTERACTIONTEST.gmBtn   )
end function 'LNG:=INTERACTIONTEST.TestMouse()
function INTERACTIONTEST.TestKeyboard() as long
    dim as long scanCodeResult => -1
    if multiKey(fb.SC_BACKSPACE) then
     scanCodeResult = fb.SC_BACKSPACE
    elseif   multiKey(fb.SC_SPACE)   then
     scanCodeResult = fb.SC_SPACE
    elseif   multiKey(fb.SC_LEFT)    andAlso   multiKey(fb.SC_UP)      then
     scanCodeResult = fb.SC_LEFT + fb.SC_UP
    elseif   multiKey(fb.SC_LEFT)    andAlso   multiKey(fb.SC_DOWN)    then
     scanCodeResult = fb.SC_LEFT + fb.SC_DOWN
    elseif   multiKey(fb.SC_RIGHT)   andAlso   multiKey(fb.SC_UP)      then
     scanCodeResult = fb.SC_RIGHT + fb.SC_UP
    elseif   multiKey(fb.SC_RIGHT)   andAlso   multiKey(fb.SC_DOWN)    then
     scanCodeResult = fb.SC_RIGHT + fb.SC_DOWN
    elseif   multiKey(fb.SC_LEFT)    then
     scanCodeResult   =    fb.SC_LEFT
    elseif   multiKey(fb.SC_RIGHT)   then
     scanCodeResult = fb.SC_RIGHT
    elseif   multiKey(fb.SC_DOWN)    then
     scanCodeResult = fb.SC_DOWN
    elseif   multiKey(fb.SC_UP)      then
     scanCodeResult = fb.SC_UP
    end if
    '
    while inkey<>"" : /'clear keyboard buffer'/ :wend
    INTERACTIONTEST.scanCode = scanCodeResult
    '
    return scanCodeResult
end function 'LNG:=INTERACTIONTEST.TestMouse()

type POSXY
    as single   _x  => 0
    as single   _y  => 0
end type

type MOB extends OBJECT
    declare static sub DrawMob()
    static as POSXY     position
    static as integer   s1
    static as integer   s2
end type

dim as POSXY    MOB.position
dim as integer  MOB.s1 => any
dim as integer  MOB.s2 => any

type PLAYER extends OBJECT
    declare static sub DrawPlayer()
    declare static sub TestPlayerAgainstMob()
    static as POSXY     position
    static as integer   score
end type
sub PLAYER.DrawPlayer()
    '
end sub
sub Mob.DrawMob()
    circle (MOB.position._x - PLAYER.position._x, MOB.position._y - PLAYER.position._y), 80 , rgb(255,0,0), , , , f
end sub
sub PLAYER.TestPlayerAgainstMob()
    if PLAYER.score>(MOB.s1 + MOB.s2) then PLAYER.score = -9999
    if point(SCREENTEST.scrW\2, SCREENTEST.scrH\2)=rgb(255,0,0) then
        dim as integer  s => 3*rnd()
        MOB.s1          += s
        MOB.s2          += (3 - s)
        PLAYER.score    = (MOB.s1 + MOB.s2)
        MOB.position._x     = rnd()*SCREENTEST.scrW + SCREENTEST.scrW\2
        MOB.position._y     = rnd()*SCREENTEST.scrH + SCREENTEST.scrH\2
    end if
end sub
dim as POSXY    PLAYER.position
dim as integer  PLAYER.score => any

type FRAME extends OBJECT
    declare static sub DrawFrame()
    static as POSXY     topLeftCorner
end type
dim as POSXY    FRAME.topLeftCorner
sub FRAME.DrawFrame()
    FRAME.topLeftCorner._x = SCREENTEST.scrW\2 - PLAYER.position._x
    FRAME.topLeftCorner._y = SCREENTEST.scrH\2 - PLAYER.position._y
    circle (SCREENTEST.scrW\2, SCREENTEST.scrH\2), 2, rgb(0,255,0)
    line (FRAME.topLeftCorner._x, FRAME.topLeftCorner._y)-step(SCREENTEST.scrW, SCREENTEST.scrH), rgb(200,200,0), b
end sub
'-------------------------------------------------------------------------------
screenRes   800, 600, 32, 2
randomize TIMER
SCREENTEST.TestScreen()
PLAYER.position._x  = SCREENTEST.scrW\2
PLAYER.position._y  = SCREENTEST.scrH\2
MOB.position._x     = rnd()*SCREENTEST.scrW + SCREENTEST.scrW\2
MOB.position._y     = rnd()*SCREENTEST.scrH + SCREENTEST.scrH\2


screenSet 0, 1
do
    SCREENTEST.TestScreen()
    INTERACTIONTEST.TestMouse()
    INTERACTIONTEST.TestKeyboard()
    if INTERACTIONTEST.scanCode = fb.SC_UP      then PLAYER.position._y -= 1
    if INTERACTIONTEST.scanCode = fb.SC_UP + fb.SC_LEFT      then
        PLAYER.position._y -= 1
        PLAYER.position._x -= 1
    end if
    if INTERACTIONTEST.scanCode = fb.SC_UP + fb.SC_RIGHT      then
        PLAYER.position._y -= 1
        PLAYER.position._x += 1
    end if
    if INTERACTIONTEST.scanCode = fb.SC_DOWN    then PLAYER.position._y += 1
    if INTERACTIONTEST.scanCode = fb.SC_DOWN + fb.SC_LEFT      then
        PLAYER.position._y += 1
        PLAYER.position._x -= 1
    end if
    if INTERACTIONTEST.scanCode = fb.SC_DOWN + fb.SC_RIGHT      then
        PLAYER.position._y += 1
        PLAYER.position._x += 1
    end if
    if INTERACTIONTEST.scanCode = fb.SC_LEFT    then PLAYER.position._x -= 1
    if INTERACTIONTEST.scanCode = fb.SC_RIGHT   then PLAYER.position._x += 1
    PLAYER.TestPlayerAgainstMob()
   
    cls
    FRAME.DrawFrame()
    MOB.DrawMob()
    PLAYER.DrawPlayer()
    draw string (12, 12), str(PLAYER.SCORE), rgb(200,200,0)
    draw string (18, 28), str(MOB.s1), rgb(200,200,0)
    draw string (68, 28), str(MOB.s2), rgb(200,200,0)
   
    screenCopy 0, 1
    '
    sleep 15
loop until inkey()=chr(27)


getKey()

'(eof)


You store your score on many registers that you sum up only for display. So if you change the score at screen, it doesn't affect the true score stored in many. I don't know if it helps!

Return to “General”

Who is online

Users browsing this forum: Baidu [Spider] and 2 guests