Last active
September 25, 2015 20:07
-
-
Save dogancelik/976998 to your computer and use it in GitHub Desktop.
(C#) DecodeNDT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Project Name: DecodeNDT | |
* Descripton: Decodes NDT files from Atlantica Online | |
* Ported from Python to C# by Doğan Çelik | |
* Originally from: http://bit.ly/kilEew | |
*/ | |
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
using System.IO; | |
namespace DecodeNDT | |
{ | |
class Program | |
{ | |
const int HEADER_SIZE = 0x18; | |
static void Main(string[] args) | |
{ | |
foreach (var file in args) | |
{ | |
if (File.Exists(file)) | |
{ | |
Console.WriteLine("File found: " + file); | |
byte[] buffer = File.ReadAllBytes(file); | |
ArraySegment<byte> segment = new ArraySegment<byte>(buffer, 12, 2); | |
ushort seed = segment.Array[segment.Offset]; | |
List<byte> output = new List<byte>(); | |
for (int i = HEADER_SIZE; i < buffer.Length - 1; i++) | |
{ | |
int x = ((buffer[i] - seed) & 0xFF) ^ (buffer[i + 1]); | |
output.Add((byte)x); | |
} | |
string filename = Path.GetFileNameWithoutExtension(file) + ".txt"; | |
try | |
{ | |
BinaryWriter bw = new BinaryWriter(new FileStream(filename, FileMode.Create, FileAccess.ReadWrite)); | |
bw.Write(output.ToArray()); | |
bw.Close(); | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine("Couldn't write file:" + filename + "\nError message: " + e.Message); | |
} | |
} | |
else Console.WriteLine("File not found: " + file); | |
} | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment