[Dev] Is any good programmer out there?

Results 1 to 9 of 9
  1. #1
    You won't get me... PanKJ is offline
    MemberRank
    Sep 2010 Join Date
    Too Damn HighLocation
    593Posts

    [Dev] Is any good programmer out there?

    Well, after having made a few file editing tools i had a thought that would make the whole procces of making new tools easier and more extensible. Since i noticed ALL files have a binary format of their own, tho its always fixed and the fields are always of basic data types (bytes, shorts, ints, floats and fixed length strings). Atm im developing a tool for omi.tex ep3.3 cause i need its tables. But considering ill have to make almost the same thing for ep3.2 (and maybe ep2) i think it would be way more sensible to make such a generic class that the rest will be piece of cake. After all, all binary files (from tga images and .tex files to smas) have a specified format.

    The problem here is that i cant come up with a class that works for me and is simple in the same time (some combination of fiels and records to make a table class). So id like to know if someones done something similar before or knows a way to do it effectively. If you think you can help post here (if you dont mind showing code) or pm me.


    PS: im writing in c#. Btw theres a program doing about the same thing (called structorian) but its code is mixed with the gui and has more features than needed. Also, its huge considering what we want imo.
    Last edited by PanKJ; 22-02-11 at 02:26 PM.


  2. #2
    Proficient Member lhgh20 is offline
    MemberRank
    Mar 2009 Join Date
    168Posts

    Re: [Dev] Is any good programmer out there?

    if u need .i will try, but i 'm working jave me.

    ---------- Post added at 01:42 PM ---------- Previous post was at 01:42 PM ----------

    if u need .i will try, but i 'm working java me.

  3. #3
    You won't get me... PanKJ is offline
    MemberRank
    Sep 2010 Join Date
    Too Damn HighLocation
    593Posts

    Re: [Dev] Is any good programmer out there?

    Ok, class declarations are more or less compatible. If you can make something simple that takes a string (or something anyway) as input and reads a binary file according to it then youre welcome to help.

    Im gonna post some code i came up with but isnt the best possible imo.

  4. #4
    Proficient Member lhgh20 is offline
    MemberRank
    Mar 2009 Join Date
    168Posts

    Re: [Dev] Is any good programmer out there?

    the read binary file,but i need to kown the key .

  5. #5
    You won't get me... PanKJ is offline
    MemberRank
    Sep 2010 Join Date
    Too Damn HighLocation
    593Posts

    Re: [Dev] Is any good programmer out there?

    You mean the format? Make it more generic so that itll work for any format provided it gets an input telling it what to look for. The whole point is to make a generic collection of code thats gonna read anything we give it.

  6. #6
    You won't get me... PanKJ is offline
    MemberRank
    Sep 2010 Join Date
    Too Damn HighLocation
    593Posts

    Re: [Dev] Is any good programmer out there?

    Code:
    namespace MainLib.StructuredBinaries
    {
        public delegate void SetDelegate(object value);
        public delegate object GetDelegate();
    
        public interface IFieldFormat
        {
            Table Parent { get; set; }
            string Name { get; }
            int Index { get; }
            SetDelegate GetSDelegate(List<byte[]> data, int YIndex);
            GetDelegate GetGDelegate(List<byte[]> data, int YIndex);
        }
    
        public abstract class Bool8Field : IFieldFormat
        {
            public virtual Table Parent { get { return null; } set { } }
            public virtual string Name { get { return "A bool"; } }
            public virtual int Index { get { return 0; } }
            public SetDelegate SetSDelegate(List<byte[]> data, int YIndex)
            {
                return delegate(object value) { data[YIndex][Index] = ((bool)value) ? (byte)1 : (byte)0; };
            }
            public GetDelegate GetSDelegate(List<byte[]> data, int YIndex)
            {
                return delegate() { return (data[YIndex][Index] == 1) ? true : false; };
            }
        }
        public abstract class Int8Field : IFieldFormat
        {
            public virtual Table Parent { get { return null; } set { } }
            public virtual string Name { get { return "A byte"; } }
            public virtual int Index { get { return 0; } }
            public SetDelegate SetSDelegate(List<byte[]> data, int YIndex)
            {
                return delegate(object value) { data[YIndex][Index] = (byte)value; };
            }
            public GetDelegate GetSDelegate(List<byte[]> data, int YIndex)
            {
                return delegate() { return data[YIndex][Index]; };
            }
        }
        public abstract class Int16Field : IFieldFormat
        {
            public virtual Table Parent { get { return null; } set { } }
            public virtual string Name { get { return "A short"; } }
            public virtual int Index { get { return 0; } }
            public SetDelegate SetSDelegate(List<byte[]> data, int YIndex)
            {
                return delegate(object value) { Tools.PutBytes(data[YIndex], Index, (short)value); };
            }
            public GetDelegate GetSDelegate(List<byte[]> data, int YIndex)
            {
                return delegate() { return Tools.TakeInt16(data[YIndex], Index); };
            }
        }
        public abstract class Int32Field : IFieldFormat
        {
            public virtual Table Parent { get { return null; } set { } }
            public virtual string Name { get { return "An int"; } }
            public virtual int Index { get { return 0; } }
            public SetDelegate SetSDelegate(List<byte[]> data, int YIndex)
            {
                return delegate(object value) { Tools.PutBytes(data[YIndex], Index, (int)value); };
            }
            public GetDelegate GetSDelegate(List<byte[]> data, int YIndex)
            {
                return delegate() { return Tools.TakeInt32(data[YIndex], Index); };
            }
        }
        public abstract class SingleField : IFieldFormat
        {
            public virtual Table Parent { get { return null; } set { } }
            public virtual string Name { get { return "A float"; } }
            public virtual int Index { get { return 0; } }
            public SetDelegate SetSDelegate(List<byte[]> data, int YIndex)
            {
                return delegate(object value) { Tools.PutBytes(data[YIndex], Index, (float)value); };
            }
            public GetDelegate GetSDelegate(List<byte[]> data, int YIndex)
            {
                return delegate() { return Tools.TakeSingle(data[YIndex], Index); };
            }
        }
        public abstract class StringField : IFieldFormat
        {
            public virtual Table Parent { get { return null; } set { } }
            public virtual string Name { get { return "A fixed string"; } }
            public virtual int Index { get { return 0; } }
            public virtual int Size { get { return 0; } }
            public SetDelegate SetSDelegate(List<byte[]> data, int YIndex)
            {
                return delegate(object value) { Tools.PutBytes(data[YIndex], Index, (string)value, Size); };
            }
            public GetDelegate GetSDelegate(List<byte[]> data, int YIndex)
            {
                return delegate() { return Tools.TakeString(data[YIndex], Index, Size); };
            }
        }
    
        public interface ITableFormat
        {
            Table Parent { get; set; }
            string Name { get; }
            IFieldFormat[] Fields { get; }
            int RecordLength { get; }
        }
    
        public class Table
        {
            public List<byte[]> Data;
            public ITableFormat Format;
            public int XDimension
            {
                get
                {
                    return Format.RecordLength;
                }
            }
            public int YDimension
            {
                get
                {
                    return Data.Count;
                }
            }
            public int Size
            {
                get
                {
                    return XDimension * YDimension;
                }
            }
            public byte[] Bytes
            {
                set
                {
                    if ((value.Length % XDimension) != 0) throw new ArgumentException("Invalid data for the " + Format.Name + " table");
                    byte[] temp = new byte[XDimension];
                    Data = new List<byte[]>();
                    for (int i = 0; i < (value.Length / XDimension); i++)
                    {
                        Array.ConstrainedCopy(value, i * XDimension, temp, 0, XDimension);
                        Data.Add(temp);
                    }
                }
                get
                {
                    byte[] temp = new byte[XDimension * YDimension];
                    for (int i = 0; i < YDimension; i++) Array.ConstrainedCopy(Data[i], 0, temp, i * XDimension, XDimension);
                    return temp;
                }
            }
            public object this[int YIndex, int XIndex]
            {
                get
                {
                    return Format.Fields[XIndex].GetGDelegate(Data, YIndex)();
                }
                set
                {
                    Format.Fields[XIndex].GetSDelegate(Data, YIndex)(value);
                }
            }
    
            public Table(ITableFormat format)
            {
                Format = format;
            }
            public Table(ITableFormat format, byte[] data)
            {
                Format = format;
                Bytes = data;
            }
        }
    }
    Please tell me your opinion on this. Its an improved version of what im using in the exes. The various formats are based on these classes and there is a way to make a class that dynamically creates the format of the table (but i use fixed formats to increase speed).

    PS: i think ive forgot to mark some things as static but nvm about details. Im just wondering if the concept is right, cause there seem to be numerous ways to solve the problem. Btw, since all interaction a user can have (or even importing/exporting the data to and from a db) requires strings, i use objects and the .ToString() method which converts accordingly to the type. Setting the data doesnt use strings tho, but i can easily change it.
    Last edited by PanKJ; 24-02-11 at 05:23 PM.

  7. #7
    Proficient Member lhgh20 is offline
    MemberRank
    Mar 2009 Join Date
    168Posts

    Re: [Dev] Is any good programmer out there?

    hm. my god , i discover i can't kown the C# index. i don't kown which one i will use array or one variable with java swing. but i will study and try to do.

  8. #8
    You won't get me... PanKJ is offline
    MemberRank
    Sep 2010 Join Date
    Too Damn HighLocation
    593Posts

    Re: [Dev] Is any good programmer out there?

    Hey guys. I made the the structured binaries editor work. But the fields in omi are too many. Anyone who could help me (its more like a matter of writing and counting, not thinking) pm me to give you the source and to explain you what to do (C# code, tho you dont even need programming knowledge to do this).

    Any help would be appreciated.

  9. #9
    Account Upgraded | Title Enabled! jimowns is offline
    MemberRank
    Aug 2006 Join Date
    BelgiumLocation
    440Posts

    Re: [Dev] Is any good programmer out there?

    I've made a packet for your server, this packet isn't 100%
    You need to change the values of the buffer and the size of the packets.
    Goodluck with it.
    Code:
        public class Packet
        {
            public ushort Size;
            public ushort Command;
            public ushort Unused;
            public byte[] packetBuffer = new byte[500];
    
            public Packet(ushort mycommand, ushort mySize, ushort myunused)
            {
                Command = mycommand;
                Unused = myunused;
                Size = mySize;
            }
            public Packet(ushort mycommand) 
            {
                Command = mycommand;
                Unused = 0;
                Size = 6;
            }
            public void AddByte(byte value)
            {
                packetBuffer[Size] = value;
                Size += 1;
            }
            public void AddBytes(byte[] value)
            {
                for (int i = 0; i < value.Length; i++) AddByte(value[i]);
            }
            public void AddString(string value)
            {
                byte[] charvalue = System.Text.Encoding.Default.GetBytes(value);
                for (int i = 0; i < charvalue.Length; i++) AddByte(charvalue[i]);
            }
            public string Encrypt_MD5(string Code)
            {
                MD5CryptoServiceProvider hasher = new MD5CryptoServiceProvider();
                byte[] tBytes = Encoding.ASCII.GetBytes(Code);
                byte[] hBytes = hasher.ComputeHash(tBytes);
    
                StringBuilder sb = new StringBuilder();
                for (int i = 2; i < hBytes.Length; i++)
                    sb.AppendFormat("{0:x02}", hBytes[i]);
                return (sb.ToString());
            }
        }
    Last edited by jimowns; 14-06-11 at 02:58 PM.



Advertisement