360haven works best with JavaScript enabled
[Release] UnrealConfigTool
Loading
Register
Results 1 to 6 of 6
  1. #1
    Divided by zero and lived

    mojobojo is offline
    Join Date : Dec 2010
    Posts : 388
    Array

    UnrealConfigTool

    Another program that I coded and never released. I coded it for unpacking and converting the unicode unreal engine ini files into regular ini files and back again. This program and source is provided as-is and I do not offer support for it. If something is wrong, fix it yourself. Its a console app, use in CMD.



    To Unpack
    Code:
    UnrealConfigTool /u /n infile.ini outdir
    To Pack
    Code:
    UnrealConfigTool /p /n outfile.ini indir
    Source Code
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    
    namespace UnrealConfigTool
    {
        class Program
        {
            enum DataModes
            {
                Null,
                Ascii,
                Unicode
            }
    
            enum ProcessModes
            {
                Null,
                Unpack,
                Pack
            }
    
            static int GetBeInt(BinaryReader br)
            {
                int tmp = br.ReadInt32();
                return 
                    (int)((tmp & 0x000000FF) << 24)|
                    (int)((tmp & 0x0000FF00) << 8) |
                    (int)((tmp & 0x00FF0000) >> 8) |
                    (int)((tmp & 0xFF000000) >> 24)
                    ;
            }
    
            static int GetInvertedBeInt(BinaryReader br)
            {
                return ~GetBeInt(br);
            }
    
            static void PutBeInt(BinaryWriter bw, int i)
            {
                int p = 
                    (int)((i & 0x000000FF) << 24)|
                    (int)((i & 0x0000FF00) << 8) |
                    (int)((i & 0x00FF0000) >> 8) |
                    (int)((i & 0xFF000000) >> 24)
                    ;
    
                bw.Write((int)p);
            }
    
            static void PutInvertedBeInt(BinaryWriter bw, int i)
            {
                PutBeInt(bw, ~i);
            }
    
            static void UnpackUnicode(string FileName, string OutDir)
            {
                BinaryReader reader = new BinaryReader(new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.Read));
    
                if (!reader.BaseStream.CanRead)
                {
                    Console.WriteLine("Unable to open file " + FileName);
                    return;
                }
    
                Directory.CreateDirectory(OutDir);
    
                StreamWriter TocWriter = new StreamWriter(OutDir + "\\TOC.txt");
    
                if (!TocWriter.BaseStream.CanWrite)
                {
                    Console.WriteLine("Unable to create table of contents file");
                    return;
                }
    
                int FilesCount = GetBeInt(reader);
    
                // Loop for each file
                for (int i = 0; i < FilesCount; i++)
                {
                    int IniFileNameSize = GetInvertedBeInt(reader);
                    string IniFileName = UnicodeEncoding.Unicode.GetString(reader.ReadBytes(IniFileNameSize * 2));
                    reader.BaseStream.Position += 2;
    
                    TocWriter.WriteLine(IniFileName);
                    TocWriter.Flush();
    
                    string OutFileName = OutDir + "\\" + IniFileName.Replace("..\\", "");
                    
                    Directory.CreateDirectory(Path.GetDirectoryName(OutFileName));
                    StreamWriter writer = new StreamWriter(OutFileName);
    
                    if (!writer.BaseStream.CanWrite)
                    {
                        Console.WriteLine("Unable to create File " + OutFileName);
                        return;
                    }
    
                    int NumOfSections = GetBeInt(reader);
    
                    // loop for each section in the file
                    for (int x = 0; x < NumOfSections; x++)
                    {
                        int SectionNameSize = GetInvertedBeInt(reader);
                        string SectionName = UnicodeEncoding.Unicode.GetString(reader.ReadBytes(SectionNameSize * 2));
    
                        writer.WriteLine(string.Format("[{0}]", SectionName));
                        writer.Flush();
    
                        reader.BaseStream.Position += 2;
    
                        int SettingCount = GetBeInt(reader);
    
                        // loop for each setting in the section
                        for (int y = 0; y < SettingCount; y++)
                        {
                            int KeySize = GetInvertedBeInt(reader);
                            string Key = UnicodeEncoding.Unicode.GetString(reader.ReadBytes(KeySize * 2));
                            reader.BaseStream.Position += 2;
    
                            int ValueNameSize = GetInvertedBeInt(reader);
    
                            string Value = "";
                            if (ValueNameSize != -1)
                            {
                                Value = UnicodeEncoding.Unicode.GetString(reader.ReadBytes(ValueNameSize * 2));
                                reader.BaseStream.Position += 2;
    
                                string ValNew = "";
                                for (int e = 0; e < Value.Length; e++)
                                {
    								// This is a workaround for the setting values that contain line endings.
                                    char c = Value[e];
                                    if (c == '\r')
                                    {
                                        ValNew += "\\x0D";
                                    }
                                    else if (c == '\n')
                                    {
                                        ValNew += "\\x0A";
                                    }
                                    else
                                    {
                                        ValNew += c.ToString();
                                        
                                    }
                                }
    
                                writer.WriteLine(string.Format("{0}={1}", Key, ValNew));
                            }
                            else
                                writer.WriteLine(string.Format("{0}=", Key));
                                
                            writer.Flush();
                        }
                    }
                }
    
                TocWriter.Close();
                reader.Close();
            }
    
            static void UnpackAscii(string FileName, string OutDir)
            {
            }
    
            static void PackUnicdoe(string FileName, string InDir)
            {
                BinaryWriter writer = new BinaryWriter(new FileStream(FileName, FileMode.Create, FileAccess.Write, FileShare.Write));
    
                if (!writer.BaseStream.CanWrite)
                {
                    Console.WriteLine("Unable to create file " + FileName);
                    return;
                }
    
                StreamReader TocReader = new StreamReader(InDir + "\\TOC.txt");
    
                if (!TocReader.BaseStream.CanRead)
                {
                    Console.WriteLine("Unable to open the Table of Contents file");
                    return;
                }
    
                List<string> FilesList = new List<string>();
                while (!TocReader.EndOfStream)
                {
                    string line = TocReader.ReadLine();
    
                    if (line == "")
                        break;
    
                    FilesList.Add(line);
                }
    
                PutBeInt(writer, FilesList.Count);
    
                foreach (string str in FilesList)
                {
                    PutInvertedBeInt(writer, str.Length);
                    writer.Write(Encoding.Unicode.GetBytes(str));
                    writer.Write((short)0);
    
                    string InFileName = InDir + "\\" + str.Replace("..\\", "");
                    StreamReader IniReader = new StreamReader(InFileName);
    
                    if (!IniReader.BaseStream.CanRead)
                    {
                        Console.WriteLine("Unable to open file " + InFileName);
                        return;
                    }
    
                    List<string> IniData = new List<string>();
    
                    while (!IniReader.EndOfStream)
                        IniData.Add(IniReader.ReadLine());
    
                    //Count the number of sections, kinda ghetto, but works
                    int SectionsCount = 0;
                    foreach (string s in IniData)
                    {
                        if (s == "")
                            continue;
    
                        if (s.StartsWith("["))
                            SectionsCount++;
                    }
    
                    PutBeInt(writer, SectionsCount);
    
                    for (int i = 0; i < IniData.Count; i++)
                    {
                        string data = IniData[i];
    
                        if (data == "")
                            continue;
    
                        if (data.StartsWith("["))
                        {
                            string SectionName = data.Substring(data.IndexOf('[') + 1, data.IndexOf(']') - 1);
                            int SectionNameLength = SectionName.Length;
                            PutInvertedBeInt(writer, SectionNameLength);
                            writer.Write(Encoding.Unicode.GetBytes(SectionName));
                            writer.Write((short)0);
    
                            int SecStart = i + 1;
    
                            string s = "";
                            List<string> Settings = new List<string>();
                            while (true)
                            {
                                if (SecStart >= IniData.Count)
                                    break;
    
                                s = IniData[SecStart];
    
                                if (s.StartsWith("["))
                                    break;
    
                                SecStart++;
                                if (s == "")
                                    continue;
    
                                Settings.Add(s);
                            }
    
                            PutBeInt(writer, (int)Settings.Count);
    
                            foreach (string set in Settings)
                            {
                                string key = set.Substring(0, set.IndexOf('='));
                                string value = set.Substring(set.IndexOf('=') + 1).Replace("\\x0A", "\n").Replace("\\x0D", "\r");
    
                                PutInvertedBeInt(writer, key.Length);
                                writer.Write(Encoding.Unicode.GetBytes(key));
                                writer.Write((short)0);
    
                                if (value.Length != 0)
                                {
                                    PutInvertedBeInt(writer, value.Length);
                                    writer.Write(Encoding.Unicode.GetBytes(value));
                                    writer.Write((short)0);
                                }
                                else
                                {
                                    PutBeInt(writer, 0);
                                }
                            }
                        }
                    }
                }
            }
    
            static void PackAscii(string FileName, string OutDir)
            {
            }
    
            static void Main(string[] args)
            {
                if (args.Length < 4)
                {
                    Console.WriteLine(
                        "Unreal Config Tool (C) Mojobojo 2011\n" +
    		         	"Usage:\n\n" +
    		           	"Unpack  /u\n" +
    			        "Pack    /p\n" +
    			        "Unicode /n\n" +
    			        "Ascii   /a\n\n" +
    			        "UnrealConfigTool <options> <in/out file> <in/out dir>\n"
                        );
    
                    return;
                }
    
                ProcessModes ProcessMode = ProcessModes.Null;
                DataModes DataMode = DataModes.Null;
                string InOutFileName;
                string InOutDir;
    
                int i = 0;
                for ( ; i < args.Length; i++)
                {
                    if (args[i][0] == '/')
                    {
                        switch (args[i][1])
                        {
                            case 'u':
                            case 'U':
                                ProcessMode = ProcessModes.Unpack;
                                break;
                            case 'p':
                            case 'P':
                                ProcessMode = ProcessModes.Pack;
                                break;
                            case 'n':
                            case 'N':
                                DataMode = DataModes.Unicode;
                                break;
                            case 'a':
                            case 'A':
                                DataMode = DataModes.Ascii;
                                break;
                            default:
                                Console.WriteLine("Unknown command");
                                break;
                        }
                    }
                    else
                        break;
                }
    
                InOutFileName = args[i++];
                InOutDir = args[i++];
    
                if (ProcessMode == ProcessModes.Unpack)
                {
                    if (DataMode == DataModes.Unicode)
                        UnpackUnicode(InOutFileName, InOutDir);
                    else if (DataMode == DataModes.Ascii)
                        UnpackAscii(InOutFileName, InOutDir);
                }
                else if (ProcessMode == ProcessModes.Pack)
                {
                    if (DataMode == DataModes.Unicode)
                        PackUnicdoe(InOutFileName, InOutDir);
                    else if (DataMode == DataModes.Ascii)
                        PackAscii(InOutFileName, InOutDir);
                }
            }
        }
    }
    Attached Files Attached Files
    Downloads : 4 || Uploads : 1 || Rep Power : 3205 || Posts : 388 || Thanks : 52 || Thanked 1,031 Times in 236 Posts



  2. The Following 7 Users Say Thank You to mojobojo For This Useful Post:


  3. #2
    Banned
    I C0z I is offline
    Join Date : Jan 2012
    Location : Martinique
    Age : 33
    Posts : 1,264
    Array

    Re: UnrealConfigTool

    nice share mojobojo very good work

  4. #3
    The Immortal God
    Rpg_Fan

    CloudStrife7x is offline
    Join Date : Dec 2010
    Location : Unknown
    Age : 29
    Posts : 18,760
    Array
    Twitter: @

    Re: UnrealConfigTool

    very awesome work as always mojobojo :)
    Downloads : 157 || Uploads : 0 || Rep Power : 22146 || Posts : 18,760 || Thanks : 4,451 || Thanked 3,095 Times in 2,607 Posts



  5. #4
    Retired Staff

    thegutta is offline
    Join Date : Jun 2011
    Location : On Top Of The World
    Posts : 10,475
    Array
    Twitter: @
    Awesome work mojobojo great share
    Downloads : 47 || Uploads : 0 || Rep Power : 13176 || Posts : 10,475 || Thanks : 3,231 || Thanked 1,396 Times in 1,224 Posts




  6. #5
    Eternal Dragoon
    Rpg_Fan

    Serious_M is offline
    Join Date : Dec 2010
    Location : Netherlands , Amsterdam
    Age : 33
    Posts : 13,032
    Array

    Re: UnrealConfigTool

    nice program mojo your awesome as always
    Downloads : 57 || Uploads : 1 || Rep Power : 16105 || Posts : 13,032 || Thanks : 3,661 || Thanked 1,791 Times in 1,446 Posts


    Serious_M

  7. #6
    GarfieldKoe

    Re: UnrealConfigTool

    nice program mojo your awesome as always

 

 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
This website uses cookies
We use cookies to store session information to facilitate remembering your login information, to allow you to save website preferences, to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners.
     

About 360haven

    360haven is an Forum Devoted To Game modding Fans from all over the world.

    An Awesome Community of Xbox 360 Gamers, Modders and Developers who Create & Share Tutorials, Applications, Gfx, Trainers and Gamesaves.

    A haven for the l33t.
    A scarce paradise for modders.

Like this page

Google+