Supercell.GUT/Supercell.GUT.Titan/Logic/DataStream/ChecksumEncoder.cs
BreadDEV 8c6a533918 [v0.0.2] you can enter menu now. but still early state
todo: improve code and finish base structures
2024-03-05 17:37:18 +07:00

98 lines
2.5 KiB
C#

using Supercell.GUT.Titan.Logic.Math;
namespace Supercell.GUT.Titan.Logic.DataStream;
public class ChecksumEncoder
{
public int CheckSum { get; set; }
public int SnapshotCheckSum { get; set; }
public bool IsChecksumEnabled { get; set; }
public ChecksumEncoder()
{
this.CheckSum = 0;
this.SnapshotCheckSum = 0;
this.IsChecksumEnabled = true;
}
public virtual bool IsCheckSumOnlyMode()
{
return true;
}
public virtual void WriteString(string? value)
{
int v2 = (this.CheckSum >> 0x1F) & 0x7FFFFFFF | (2 * this.CheckSum);
if (value != null)
this.CheckSum = value.Length + v2 + 28;
else
this.CheckSum = v2 + 0x1B;
}
public virtual void WriteBoolean(bool value)
{
int v2 = 7;
if (value)
v2 = 13;
this.CheckSum = ((this.CheckSum >> 0x1F) & 0x7FFFFFFF | (2 * this.CheckSum)) + v2;
}
public virtual void WriteInt(int value)
{
this.CheckSum = ((this.CheckSum >> 0x1F) & 0x7FFFFFFF | (2 * this.CheckSum)) + value + 9;
}
public virtual void WriteByte(byte value)
{
this.CheckSum = ((this.CheckSum >> 0x1F) & 0x7FFFFFFF | (2 * this.CheckSum)) + value + 11;
}
public virtual void WriteShort(short value)
{
this.CheckSum = ((this.CheckSum >> 0x1F) & 0x7FFFFFFF | (2 * this.CheckSum)) + value + 19;
}
public virtual void WriteBytes(byte[]? value, int length)
{
int v3 = (this.CheckSum >> 0x1F) & 0x7FFFFFFF | (2 * this.CheckSum);
if (value != null)
this.CheckSum = length + v3 + 28;
else
this.CheckSum = v3 + 0x1B;
}
public virtual void WriteLong(LogicLong logicLong)
{
logicLong.Encode(this);
}
public override bool Equals(object? obj)
{
if (obj != null && obj is ChecksumEncoder checksumEncoder)
{
bool v4 = this.IsChecksumEnabled;
int v5 = checksumEncoder.CheckSum;
bool v6 = checksumEncoder.IsChecksumEnabled;
int v7 = checksumEncoder.SnapshotCheckSum;
if (!v6)
v5 = v7;
int v8 = this.CheckSum;
int v9 = this.SnapshotCheckSum;
int v10 = v5;
if (!v4)
v8 = v9;
if (v8 == v10)
return true;
}
return false;
}
public virtual void Destruct()
{
this.CheckSum = 0;
this.SnapshotCheckSum = 0;
this.IsChecksumEnabled = true;
}
}