Cheat prevetion for Ubytes

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

Cheat prevetion for Ubytes

Postby mrminecrafttnt » Aug 02, 2018 16:18

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: 1737
Joined: Jan 02, 2017 0:34
Location: UK

Re: Cheat prevetion for Ubytes

Postby deltarho[1859] » Aug 02, 2018 23:04

@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.
Pritchard
Posts: 5492
Joined: Sep 12, 2005 20:06
Location: Ohio, USA

Re: Cheat prevetion for Ubytes

Postby Pritchard » Aug 03, 2018 0:06

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: 1737
Joined: Jan 02, 2017 0:34
Location: UK

Re: Cheat prevetion for Ubytes

Postby deltarho[1859] » Aug 03, 2018 1:51

Pritchard 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: 2741
Joined: Jun 02, 2015 16:24

Re: Cheat prevetion for Ubytes

Postby Tourist Trap » Aug 03, 2018 5:27

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.
Pritchard
Posts: 5492
Joined: Sep 12, 2005 20:06
Location: Ohio, USA

Re: Cheat prevetion for Ubytes

Postby Pritchard » Aug 10, 2018 2:56

deltarho[1859] wrote:
Pritchard 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: 1737
Joined: Jan 02, 2017 0:34
Location: UK

Re: Cheat prevetion for Ubytes

Postby deltarho[1859] » Aug 10, 2018 5:34

@Pritchard

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: 3023
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Cheat prevetion for Ubytes

Postby MrSwiss » Aug 10, 2018 15:36

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 ...
Pritchard
Posts: 5492
Joined: Sep 12, 2005 20:06
Location: Ohio, USA

Re: Cheat prevetion for Ubytes

Postby Pritchard » Aug 11, 2018 2:51

deltarho[1859] wrote:@Pritchard

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

Postby IndigoFuzz » Aug 20, 2018 13:42

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: 1119
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Cheat prevetion for Ubytes

Postby jj2007 » Aug 20, 2018 13:57

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

Re: Cheat prevetion for Ubytes

Postby fxm » Aug 20, 2018 14:21

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.
Pritchard
Posts: 5492
Joined: Sep 12, 2005 20:06
Location: Ohio, USA

Re: Cheat prevetion for Ubytes

Postby Pritchard » Aug 20, 2018 17:06

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: 1876
Joined: Sep 25, 2005 21:54

Re: Cheat prevetion for Ubytes

Postby srvaldez » Aug 20, 2018 17:37

Pritchard 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: 1737
Joined: Jan 02, 2017 0:34
Location: UK

Re: Cheat prevetion for Ubytes

Postby deltarho[1859] » Aug 20, 2018 18:12

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.

Return to “Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 3 guests