Cheat prevetion for Ubytes

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
mrminecrafttnt
Posts: 131
Joined: Feb 11, 2013 12:23

Cheat prevetion for Ubytes

Post by mrminecrafttnt »

Code: Select all

type memorycell
    as ubyte cell : 1
    as ubyte paritycell : 1
    as ubyte read_write_state : 1
    as ubyte protected_mode : 1
    declare function rw_cell (value as ubyte = 0) as ubyte
    declare sub lock_cell
    declare sub unlock_cell
    declare sub write_mode
    declare sub read_mode
end type

function memorycell.rw_cell (value as ubyte = 0) as ubyte
   ' print "RW CELL"
    select case read_write_state
    case 0
        if paritycell <> cell then return cell
    case 1
        if protected_mode = 0 then
            cell = value
            paritycell = not value
        end if
    end select
end function

sub memorycell.lock_cell
   ' PRINT "LOCKCELL"
    protected_mode = 1
end sub

sub memorycell.unlock_cell
   ' PRINT "UNLOCKCELL"
    protected_mode = 0
end sub

sub memorycell.write_mode
   ' PRINT "WRITEMODE"
    read_write_state = 1
end sub

sub memorycell.read_mode
   ' PRINT "READMODE"
    read_write_state = 0
end sub

type mcell_ubyte
    dim as memorycell mcell(8)
    declare sub convert_ubyte_to_celldata(value as ubyte)
    declare function convert_celldata_to_ubyte as ubyte
end type

sub mcell_ubyte.convert_ubyte_to_celldata(value as ubyte)
    'PRINT "CONVERTING TO CELLDATA"
    for i as integer = 0 to 7
        mcell(i).unlock_cell
        mcell(i).write_mode
        mcell(i).rw_cell bit(value,i)
        mcell(i).read_mode
        mcell(i).lock_cell
    next
end sub

function mcell_ubyte.convert_celldata_to_ubyte as ubyte
    'PRINT "CONVERTING TO UBYTE"
    dim as ubyte buffer
    for i as integer = 0 to 7
        if mcell(i).rw_cell = 1 then 
            buffer = bitset(buffer,i)
        else 
            buffer = bitreset(buffer,i)
        end if
    next
    return buffer
end function


'EXAMPLE STARTS HERE
dim as mcell_ubyte health
health.convert_ubyte_to_celldata 100
locate ,,0
do
    locate 1
    print "INCRASE/DECRASE HEALTH WITH +/-"
    SELECT CASE INKEY
    CASE "+"
        health.convert_ubyte_to_celldata health.convert_celldata_to_ubyte + 1
    case "-"
        health.convert_ubyte_to_celldata health.convert_celldata_to_ubyte - 1
        
    case chr(27)
        exit do
    end select
    print "YOUR HEALTH :";health.convert_celldata_to_ubyte; " "
loop
deltarho[1859]
Posts: 4308
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Cheat prevetion for Ubytes

Post by deltarho[1859] »

@mrminecrafttnt

If I had my way I would delete your post and send you a message advising that this is a peer support forum and not a source code repository. I would then say that if any code was posted again without any explanation then it also would be deleted only no message would be sent on that occasion.
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Re: Cheat prevetion for Ubytes

Post by anonymous1337 »

deltarho[1859] wrote:@mrminecrafttnt

If I had my way I would delete your post and send you a message advising that this is a peer support forum and not a source code repository. I would then say that if any code was posted again without any explanation then it also would be deleted only no message would be sent on that occasion.
There are better ways to handle this than deleting a thread. We're also in the Tips and Tricks sub-forum. You could also just ask mrminecreattnt to provide a description. I don't think we can afford to be rude to contributors at this point.

@mrminecrafttnt So you're essentially just NOT'ing values?
deltarho[1859]
Posts: 4308
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Cheat prevetion for Ubytes

Post by deltarho[1859] »

anonymous1337 wrote:I don't think we can afford to be rude to contributors at this point.
I would normally favour a diplomatic approach but sometimes a short, sharp shock is the better tack.
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: Cheat prevetion for Ubytes

Post by Tourist Trap »

As far as I understand it, it's about locking down some of the bytes of a given buffer made with elementary bytes, some free to change, and others not.

But I don't think this is a funny implementation, this uses a user defined datatype, so outside of this very restrictive context your buffer is not really secured. I'm not sure, but more fun would be maybe to use constants and static storage, known by the compiler and the program point of view for being specific special areas for storage and theoretically protected against change. But again, not sure that it would be really effective. It would depend on the way the programer decides or not to comply with the restrictions and not starts hacking every single bytes :)

Maybe also this is totally another thing here, and I just miss the point of course.
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Re: Cheat prevetion for Ubytes

Post by anonymous1337 »

deltarho[1859] wrote:
anonymous1337 wrote:I don't think we can afford to be rude to contributors at this point.
I would normally favour a diplomatic approach but sometimes a short, sharp shock is the better tack.
Okay, so since you like a sharp shock, how about this? If I was a mod, comments that don't actually contribute toward threads and are aggressive toward users like yours would result in immediate deletion and a temporary account ban.
deltarho[1859]
Posts: 4308
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Cheat prevetion for Ubytes

Post by deltarho[1859] »

@anonymous1337

That would send a message that the style of the opening post was perfectly acceptable.

It is worth noting that nobody else has 'had a go' at me suggesting a silent agreement with what I wrote. If you have seen any of my posts over the last 18 months then you will know that it is not my usual style of communication.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Cheat prevetion for Ubytes

Post by MrSwiss »

deltarho[1859] wrote:That would send a message that the style of the opening post was perfectly acceptable.
Yes, fully agree ... (that message is simply: unacceptable!)
For a change, I'm in complete agreement, with deltarho[1859].

OP is known, to post such nonsense (related to: tips and tricks), without ever
stating a reason, giving an explanation e.t.c.
Nobody would mind, if this sort of thing was posted in "Beginners" but, "Tips
and Tricks" is definitely NOT, the right place ...
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Re: Cheat prevetion for Ubytes

Post by anonymous1337 »

deltarho[1859] wrote:@anonymous1337

That would send a message that the style of the opening post was perfectly acceptable.
I'm not saying anything about the opening post. Just your own behaviors.
It is worth noting that nobody else has 'had a go' at me suggesting a silent agreement with what I wrote.
This forum has like 5 active users lol.
IndigoFuzz
Posts: 5
Joined: Sep 21, 2014 3:25
Contact:

Re: Cheat prevetion for Ubytes

Post by IndigoFuzz »

Very interesting method :) Thanks for sharing

As for the sub-discussion:

The reason why this forum has little engagement, and this language not as popular as it should be is because of the comments like deltarho's pushing people away. See it all too often in community driven projects sadly
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Cheat prevetion for Ubytes

Post by jj2007 »

IndigoFuzz wrote:comments like deltarho's pushing people away
Actually, deltarho was right. Source code without any explanation are wasting our precious time.
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Cheat prevetion for Ubytes

Post by fxm »

Just a small remark (for the nth time) on the declaration of the arrays:
Dim name ( [lbound To] ubound [, ...] ) As DataType

So when declaring an array with the shortest syntax ('Dim name ( ubound [, ...] ) As DataType'), the single value entered for each dimension corresponds to the ubound of the dimension and not to the number of element because lbound is set to 0 per default.

Example:
Dim name ( 8 ) As DataType
is equivalent to
Dim name ( 0 To 8 ) As DataType
which is an array of 9 elements with index coming from 0 up to 8

In your code:
dim as memorycell mcell(7)
is sufficient.
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Re: Cheat prevetion for Ubytes

Post by anonymous1337 »

jj2007 wrote:
IndigoFuzz wrote:comments like deltarho's pushing people away
Actually, deltarho was right. Source code without any explanation are wasting our precious time.
If your time was really so precious, you could just skip over a thread you don't find valuable.

If we wanted to set subforum rules that posts in Tips & Tricks must come with explanations, I suppose we could do that. In the meantime, mrminecraft is free to come in and out, posting code as they please.
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: Cheat prevetion for Ubytes

Post by srvaldez »

anonymous1337 wrote:
jj2007 wrote:
IndigoFuzz wrote:In the meantime, mrminecraft is free to come in and out, posting code as they please.
with all due respespect, are you the arbitrator of wath's appropriate in this forum?
deltarho[1859]
Posts: 4308
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Cheat prevetion for Ubytes

Post by deltarho[1859] »

IndigoFuzz wrote:The reason why this forum has little engagement, and this language not as popular as it should be is because of the comments like deltarho's pushing people away.
I have only been a member since Jan 2017 but have seen very little evidence of that. If IndigoFuzz had read most of my posts then it should be clear that my initial post above is exceptionally rare with regard to its content.

I am not sure how much weight to give to IndigoFuzz's comments anyway considering this is only his 5th post since joining in Sep 2014.

Taking into account the posts by MrSwiss and jj2007 then if the opening poster was 'pushed' away I fail to see how much of a loss that would be.
Post Reply