reset the history pointer

This commit is contained in:
Le Duc Anh
2025-10-16 10:50:59 +07:00
parent 92352e14d9
commit ed1a00932e
3 changed files with 4 additions and 9 deletions
@@ -379,7 +379,7 @@ namespace CSNetwork
{
currentIsec = _inputSecurity;
}
DecompressArcFourSecurity._logger = _logger;
bool securityApplied =
currentIsec != null && currentIsec.GetType() != typeof(NullSecurity);
Octets dataToProcess; // This will hold the data block we decode from
@@ -12,7 +12,7 @@ namespace CSNetwork.Security
/// </summary>
public class DecompressArcFourSecurity : BaseSecurity
{
private static readonly IPrefixedLogger _logger = LoggerFactory.GetLogger(nameof(DecompressArcFourSecurity));
public static IPrefixedLogger _logger = LoggerFactory.GetLogger(nameof(DecompressArcFourSecurity));
private ARCFourSecurity _arcFour; // Internal RC4 instance
private byte[] _key;
@@ -55,7 +55,6 @@ namespace CSNetwork.Security
// or just to be safe. Ensure _arcFour.Update returns a *new* Octets.
// *** If ARCFourSecurity.Update modified the input Octets in-place, this would be wrong. ***
// *** Assuming ARCFourSecurity.Update follows the abstract Security pattern and returns new Octets ***
UnityEngine.Debug.Log($"ENCRYPTED: {data.RawBuffer[0]}");
decryptedData = _arcFour.Update(data);
}
@@ -76,15 +75,11 @@ namespace CSNetwork.Security
Octets decompressedData;
try
{
UnityEngine.Debug.Log($"DECRYPTED: {decryptedData.RawBuffer[0]}");
decompressedData = decompressor.Update(decryptedData);
}
catch (Exception ex)
{
//_logger.Log(LogType.Error, $"MPPC Decompression Error after decryption: {ex.Message}. Decrypted Length: {decryptedData.Length}");
string firstBytes = BitConverter.ToString(decryptedData.RawBuffer, 0, Math.Min(decryptedData.Length, 16));
_logger.Log(LogType.Debug, $"Decrypted Data (first {Math.Min(decryptedData.Length, 16)} bytes): {firstBytes}");
_logger.LogException(ex);
_logger.Log(LogType.Info, $"{ex.Message} - {ex.StackTrace}");
throw new InvalidDataException("MPPC decompression failed after decryption.", ex);
}
@@ -149,7 +149,7 @@ namespace CSNetwork.Security
Array.Copy(history, histhead, segment, 0, segment.Length);
output.Insert(output.Size, segment);
if (histptr - histhead == MPPC_HIST_LEN)
if (histptr == MPPC_HIST_LEN)
histptr = 0;
histhead = histptr;