Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


C# decimal value type (Unity)

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
ap13ski
How do I cheat?
Reputation: 0

Joined: 17 Dec 2020
Posts: 3

PostPosted: Thu Dec 17, 2020 8:17 am    Post subject: C# decimal value type (Unity) Reply with quote

Hi Dark Byte!
Games developed on the Unity engine are not a surprise to anyone now - they are everywhere.
The main language for Unity engine is C#.
The C# language has a floating-point value type decimal that has a size of 16 bytes (see MSDN).
Quite often game developers use this value type, but due to the unavailability of this value type in the search settings, it is not possible to find addresses with the Cheat Engine directly.

1. Is it possible in the current version of Cheat Engine to somehow search for values of the decimal value type used in C#?
2. Are there any plans to add decimal value type to the standard Cheat Engine set?

P.S. Thanks for everything, Dark Byte! You are my hero!
From Russia with love.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25860
Location: The netherlands

PostPosted: Thu Dec 17, 2020 9:00 am    Post subject: Reply with quote

If someone has some documentation/code to convert to and from an string/float then a custom type can be used

e.g is it
https://en.wikipedia.org/wiki/Quadruple-precision_floating-point_format

or is it
https://en.wikipedia.org/wiki/Decimal128_floating-point_format

and if not, which one is it?
And is it big endian, or little endian, etc...
e.g for normal values it looks like the value is in bit 64+

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4725

PostPosted: Thu Dec 17, 2020 1:00 pm    Post subject: Reply with quote

Looks like neither.
https://docs.microsoft.com/en-us/dotnet/api/system.decimal?view=net-5.0
Specifically here:
Quote:
The binary representation of a Decimal value consists of a 1-bit sign, a 96-bit integer number, and a scaling factor used to divide the 96-bit integer and specify what portion of it is a decimal fraction. The scaling factor is implicitly the number 10, raised to an exponent ranging from 0 to 28. Therefore, the binary representation of a Decimal value the form, ((-2^96 to 2^96) / 10^(0 to 28)), where -(2^96-1) is equal to MinValue, and 2^96-1 is equal to MaxValue. For more information about the binary representation of Decimal values and an example, see the Decimal(Int32[]) constructor and the GetBits method.


Decimal (int[] bits); constructor:
Quote:
bits is a four-element long array of 32-bit signed integers.

bits [0], bits [1], and bits [2] contain the low, middle, and high 32 bits of the 96-bit integer number.

bits [3] contains the scale factor and sign, and consists of following parts:

Bits 0 to 15, the lower word, are unused and must be zero.

Bits 16 to 23 must contain an exponent between 0 and 28, which indicates the power of 10 to divide the integer number.

Bits 24 to 30 are unused and must be zero.

Bit 31 contains the sign; 0 meaning positive, and 1 meaning negative.

A numeric value might have several possible binary representations; all are equally valid and numerically equivalent. Note that the bit representation differentiates between negative and positive zero. These values are treated as being equal in all operations.

A custom type can be made from this.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Csimbi
I post too much
Reputation: 98

Joined: 14 Jul 2007
Posts: 3347

PostPosted: Thu Dec 17, 2020 3:46 pm    Post subject: Reply with quote

ParkourPenguin wrote:
A custom type can be made from this.

Are you gonna? Razz
An internal type might be a good idea - it's unlikely that it's going to disappear any soon.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4725

PostPosted: Thu Dec 17, 2020 8:31 pm    Post subject: Reply with quote

Probably not. It looks annoying to do correctly.

Here's the source code if anyone wants to try:
https://github.com/dotnet/runtime/blob/master/src/libraries/System.Private.CoreLib/src/System/Decimal.cs
Specifically "public static float ToSingle(decimal d)" (Decimal -> float = ConvertRoutine) and "public Decimal(float value)" (float -> Decimal = ConvertBackRoutine).

C#'s Decimal type is a bad implementation of an idea that AFAIK neither has nor will ever have hardware support for. It'll only ever be a custom type.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25860
Location: The netherlands

PostPosted: Fri Dec 18, 2020 3:27 am    Post subject: Reply with quote

Hint: write a plugin in C# that registers a custom type
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25860
Location: The netherlands

PostPosted: Fri Dec 18, 2020 3:23 pm    Post subject: Reply with quote

Since no-one posted a solution:
https://forum.cheatengine.org/viewtopic.php?t=616640

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites