PDA

View Full Version : Legends of Troy



MBRKiNG
03-17-2011, 02:05 PM
hi guys here is my save i got 2932 Kleo in hex 00000B74.

this game can be modded but i dont know how to pass the checksum.

hope anyone can do this

thx

feudalnate
03-18-2011, 01:41 AM
Check is a CRC32 ran over 0 - (EOF - 4), written @ EOF - 4 (last four bytes) . Check is the same on all files (Profile, Settings, Scenario). Too bad this game isn't going to be released in NA, it looked semi-interesting..




Sub FixTroyCRC(ByVal File As String)
Dim IO As New System.IO.FileStream(File, System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite)
Dim Buffer((IO.Length - 4) - 1) As Byte
IO.Read(Buffer, 0, (IO.Length - 4))
IO.Write(SmallCRC32.Compute(Buffer), (IO.Length - 4), 4)
IO.Flush() : IO.Close()
End Sub


Function ValidateTroyCRC(ByVal File As String) As Boolean
Dim IO As New System.IO.FileStream(File, System.IO.FileMode.Open, System.IO.FileAccess.Read)
Dim Buffer((IO.Length - 4) - 1) As Byte
IO.Read(Buffer, 0, (IO.Length - 4))
Dim Calc() As Byte = SmallCRC32.Compute(Buffer)
Dim Crnt(4 - 1) As Byte
IO.Read(Crnt, 0, 4)
IO.Close()
Return CBool(BitConverter.ToString(Calc, 0) = BitConverter.ToString(Crnt, 0))
End Function





Public Class SmallCRC32
Private Shared Table As UInt32()

Shared Function Compute(ByVal Buffer As Byte()) As Byte()
Call GenerateTable()
Dim Result As UInt32 = &HFFFFFFFFUI
For i As UInt32 = 0 To Buffer.Length - 1
Dim Index As Byte = CByte(((Result) And &HFF) Xor Buffer(i))
Result = CUInt((Result >> 8) Xor Table(Index))
Next
Return ToBytes(Not Result)
End Function

Private Shared Sub GenerateTable()
Dim Polynomial As UInt32 = &HEDB88320UI
Dim VAR As UInt32 = 0
Table = New UInt32(255) {}
For i As Int32 = 0 To Table.Length - 1
VAR = i
For u As Int32 = 8 To 1 Step -1
If (VAR And 1) = 1 Then VAR = CUInt((VAR >> 1) Xor Polynomial) : GoTo 0
VAR >>= 1
0: Next
Table(i) = VAR
Next
End Sub

Private Shared Function ToBytes(ByVal Result As UInt32) As Byte()
Dim Buffer() As Byte = BitConverter.GetBytes(Result)
Array.Reverse(Buffer)
Return Buffer
End Function
End Class