dword -> octet

Results 1 to 10 of 10
  1. #1
    Black Magic Development das7002 is offline
    MemberRank
    Apr 2010 Join Date
    EarthLocation
    2,188Posts

    dword -> octet

    Thats what it says in PWGen1 but from everything I have done that is completely not it, I've been working on a web based hex data generator to hopefully eventually merge into PWAdmin to allow full editing and item creation all from a pretty web interface

    My main issue right now (all my other converters so far work fine) is figuring out how the hell it converts ints to w/e the hex they are using is... I've come up with a few formulas that sort of work but most of the time they don't at all

    I have noticed that the hex "numbers" are always the same regardless but always in a different order and can't figure out why or how to replicate that (I did sort of manage to get the part from 0 to 65535 to work though)

    So if anyone has any clue how the hell it is actually done it would be greatly appreciated.


  2. #2
    Account Upgraded | Title Enabled! ronny1982 is offline
    MemberRank
    Jan 2010 Join Date
    744Posts

    Re: dword -> octet

    on a fast overview it seems that octets are just simple byte arrays embedded in a class to provide some more properties...

    Code:
    package com.goldhuman.Common;
    
    import java.io.PrintStream;
    import java.nio.ByteBuffer;
    
    public class Octets
      implements Cloneable, Comparable
    {
      private static final int DEFAULT_SIZE = 128;
      private static String DEFAULT_CHARSET = "ISO-8859-1";
      private byte[] buffer = null;
      private int count = 0;
    
      private byte[] roundup(int paramInt)
      {
        int i = 16;
        while (paramInt > i)
          i <<= 1;
        return new byte[i];
      }
    
      public void reserve(int paramInt)
      {
        if (this.buffer == null)
        {
          this.buffer = roundup(paramInt);
        }
        else if (paramInt > this.buffer.length)
        {
          byte[] arrayOfByte = roundup(paramInt);
          System.arraycopy(this.buffer, 0, arrayOfByte, 0, this.count);
          this.buffer = arrayOfByte;
        }
      }
    
      public Octets replace(byte[] paramArrayOfByte, int paramInt1, int paramInt2)
      {
        reserve(paramInt2);
        System.arraycopy(paramArrayOfByte, paramInt1, this.buffer, 0, paramInt2);
        this.count = paramInt2;
        return this;
      }
    
      public Octets replace(Octets paramOctets, int paramInt1, int paramInt2)
      {
        return replace(paramOctets.buffer, paramInt1, paramInt2);
      }
    
      public Octets replace(byte[] paramArrayOfByte)
      {
        return replace(paramArrayOfByte, 0, paramArrayOfByte.length);
      }
    
      public Octets replace(Octets paramOctets)
      {
        return replace(paramOctets.buffer, 0, paramOctets.count);
      }
    
      public Octets()
      {
        reserve(128);
      }
    
      public Octets(int paramInt)
      {
        reserve(paramInt);
      }
    
      public Octets(Octets paramOctets)
      {
        replace(paramOctets);
      }
    
      public Octets(byte[] paramArrayOfByte)
      {
        replace(paramArrayOfByte);
      }
    
      public Octets(byte[] paramArrayOfByte, int paramInt1, int paramInt2)
      {
        replace(paramArrayOfByte, paramInt1, paramInt2);
      }
    
      public Octets(Octets paramOctets, int paramInt1, int paramInt2)
      {
        replace(paramOctets, paramInt1, paramInt2);
      }
    
      public Octets resize(int paramInt)
      {
        reserve(paramInt);
        this.count = paramInt;
        return this;
      }
    
      public int size()
      {
        return this.count;
      }
    
      public int capacity()
      {
        return this.buffer.length;
      }
    
      public Octets clear()
      {
        this.count = 0;
        return this;
      }
    
      public Octets swap(Octets paramOctets)
      {
        int i = this.count;
        this.count = paramOctets.count;
        paramOctets.count = i;
        byte[] arrayOfByte = paramOctets.buffer;
        paramOctets.buffer = this.buffer;
        this.buffer = arrayOfByte;
        return this;
      }
    
      public Octets push_back(byte paramByte)
      {
        reserve(this.count + 1);
        this.buffer[(this.count++)] = paramByte;
        return this;
      }
    
      public Octets erase(int paramInt1, int paramInt2)
      {
        System.arraycopy(this.buffer, paramInt2, this.buffer, paramInt1, this.count -= paramInt2 - paramInt1);
        return this;
      }
    
      public Octets insert(int paramInt1, byte[] paramArrayOfByte, int paramInt2, int paramInt3)
      {
        reserve(this.count + paramInt3);
        System.arraycopy(this.buffer, paramInt1, this.buffer, paramInt1 + paramInt3, this.count - paramInt1);
        System.arraycopy(paramArrayOfByte, paramInt2, this.buffer, paramInt1, paramInt3);
        this.count += paramInt3;
        return this;
      }
    
      public Octets insert(int paramInt1, Octets paramOctets, int paramInt2, int paramInt3)
      {
        return insert(paramInt1, paramOctets.buffer, paramInt2, paramInt3);
      }
    
      public Octets insert(int paramInt, byte[] paramArrayOfByte)
      {
        return insert(paramInt, paramArrayOfByte, 0, paramArrayOfByte.length);
      }
    
      public Octets insert(int paramInt, Octets paramOctets)
      {
        return insert(paramInt, paramOctets.buffer, 0, paramOctets.size());
      }
    
      public Object clone()
      {
        return new Octets(this);
      }
    
      public int compareTo(Octets paramOctets)
      {
        int i = Math.min(this.count, paramOctets.count);
        byte[] arrayOfByte1 = this.buffer;
        byte[] arrayOfByte2 = paramOctets.buffer;
        for (int j = 0; j < i; j++)
        {
          int k = arrayOfByte1[j] - arrayOfByte2[j];
          if (k != 0)
            return k;
        }
        return this.count - paramOctets.count;
      }
    
      public int compareTo(Object paramObject)
      {
        return compareTo((Octets)paramObject);
      }
    
      public byte[] getBytes()
      {
        byte[] arrayOfByte = new byte[this.count];
        System.arraycopy(this.buffer, 0, arrayOfByte, 0, this.count);
        return arrayOfByte;
      }
    
      public byte[] array()
      {
        return this.buffer;
      }
    
      public byte getByte(int paramInt)
      {
        return this.buffer[paramInt];
      }
    
      public void setByte(int paramInt, byte paramByte)
      {
        this.buffer[paramInt] = paramByte;
      }
    
      public ByteBuffer getByteBuffer(int paramInt1, int paramInt2)
      {
        return ByteBuffer.wrap(this.buffer, paramInt1, paramInt2);
      }
    
      public ByteBuffer getByteBuffer(int paramInt)
      {
        return ByteBuffer.wrap(this.buffer, paramInt, this.count - paramInt);
      }
    
      public ByteBuffer getByteBuffer()
      {
        return ByteBuffer.wrap(this.buffer, 0, this.count);
      }
    
      public String getString()
        throws Exception
      {
        return new String(this.buffer, 0, this.count, DEFAULT_CHARSET);
      }
    
      public void setString(String paramString)
        throws Exception
      {
        this.buffer = paramString.getBytes(DEFAULT_CHARSET);
        this.count = this.buffer.length;
      }
    
      public static void setDefaultCharset(String paramString)
      {
        DEFAULT_CHARSET = paramString;
      }
    
      public static void main(String[] paramArrayOfString)
      {
        Octets localOctets1 = new Octets("ddd".getBytes());
        localOctets1.replace("abc".getBytes());
        localOctets1.replace("defghijklmn".getBytes());
        try
        {
          localOctets1.replace("0123456789".getBytes("UTF-8"));
        }
        catch (Exception localException)
        {
        }
        localOctets1.insert(localOctets1.size(), "abc".getBytes());
        localOctets1.insert(localOctets1.size(), "def".getBytes());
        System.out.println(new String(localOctets1.getBytes()));
        System.out.println("size = " + localOctets1.size());
        Octets localOctets2 = new Octets("ABC".getBytes());
        localOctets1.insert(localOctets1.size(), localOctets2);
        System.out.println(new String(localOctets1.getBytes()));
        Octets localOctets3 = (Octets)localOctets1.clone();
        System.out.println(new String(localOctets3.getBytes()));
      }
    }
    so it could be done with some simple bitconverter operations like bitshifts...
    Last edited by ronny1982; 15-10-10 at 02:19 AM.

  3. #3
    Black Magic Development das7002 is offline
    MemberRank
    Apr 2010 Join Date
    EarthLocation
    2,188Posts

    Re: dword -> octet

    Quote Originally Posted by ronny1982 View Post
    on a fast overview it seems that octets are just simple byte arrays embedded in a class to provide some more properties...
    Spoiler:

    Code:
    package com.goldhuman.Common;
    
    import java.io.PrintStream;
    import java.nio.ByteBuffer;
    
    public class Octets
      implements Cloneable, Comparable
    {
      private static final int DEFAULT_SIZE = 128;
      private static String DEFAULT_CHARSET = "ISO-8859-1";
      private byte[] buffer = null;
      private int count = 0;
    
      private byte[] roundup(int paramInt)
      {
        int i = 16;
        while (paramInt > i)
          i <<= 1;
        return new byte[i];
      }
    
      public void reserve(int paramInt)
      {
        if (this.buffer == null)
        {
          this.buffer = roundup(paramInt);
        }
        else if (paramInt > this.buffer.length)
        {
          byte[] arrayOfByte = roundup(paramInt);
          System.arraycopy(this.buffer, 0, arrayOfByte, 0, this.count);
          this.buffer = arrayOfByte;
        }
      }
    
      public Octets replace(byte[] paramArrayOfByte, int paramInt1, int paramInt2)
      {
        reserve(paramInt2);
        System.arraycopy(paramArrayOfByte, paramInt1, this.buffer, 0, paramInt2);
        this.count = paramInt2;
        return this;
      }
    
      public Octets replace(Octets paramOctets, int paramInt1, int paramInt2)
      {
        return replace(paramOctets.buffer, paramInt1, paramInt2);
      }
    
      public Octets replace(byte[] paramArrayOfByte)
      {
        return replace(paramArrayOfByte, 0, paramArrayOfByte.length);
      }
    
      public Octets replace(Octets paramOctets)
      {
        return replace(paramOctets.buffer, 0, paramOctets.count);
      }
    
      public Octets()
      {
        reserve(128);
      }
    
      public Octets(int paramInt)
      {
        reserve(paramInt);
      }
    
      public Octets(Octets paramOctets)
      {
        replace(paramOctets);
      }
    
      public Octets(byte[] paramArrayOfByte)
      {
        replace(paramArrayOfByte);
      }
    
      public Octets(byte[] paramArrayOfByte, int paramInt1, int paramInt2)
      {
        replace(paramArrayOfByte, paramInt1, paramInt2);
      }
    
      public Octets(Octets paramOctets, int paramInt1, int paramInt2)
      {
        replace(paramOctets, paramInt1, paramInt2);
      }
    
      public Octets resize(int paramInt)
      {
        reserve(paramInt);
        this.count = paramInt;
        return this;
      }
    
      public int size()
      {
        return this.count;
      }
    
      public int capacity()
      {
        return this.buffer.length;
      }
    
      public Octets clear()
      {
        this.count = 0;
        return this;
      }
    
      public Octets swap(Octets paramOctets)
      {
        int i = this.count;
        this.count = paramOctets.count;
        paramOctets.count = i;
        byte[] arrayOfByte = paramOctets.buffer;
        paramOctets.buffer = this.buffer;
        this.buffer = arrayOfByte;
        return this;
      }
    
      public Octets push_back(byte paramByte)
      {
        reserve(this.count + 1);
        this.buffer[(this.count++)] = paramByte;
        return this;
      }
    
      public Octets erase(int paramInt1, int paramInt2)
      {
        System.arraycopy(this.buffer, paramInt2, this.buffer, paramInt1, this.count -= paramInt2 - paramInt1);
        return this;
      }
    
      public Octets insert(int paramInt1, byte[] paramArrayOfByte, int paramInt2, int paramInt3)
      {
        reserve(this.count + paramInt3);
        System.arraycopy(this.buffer, paramInt1, this.buffer, paramInt1 + paramInt3, this.count - paramInt1);
        System.arraycopy(paramArrayOfByte, paramInt2, this.buffer, paramInt1, paramInt3);
        this.count += paramInt3;
        return this;
      }
    
      public Octets insert(int paramInt1, Octets paramOctets, int paramInt2, int paramInt3)
      {
        return insert(paramInt1, paramOctets.buffer, paramInt2, paramInt3);
      }
    
      public Octets insert(int paramInt, byte[] paramArrayOfByte)
      {
        return insert(paramInt, paramArrayOfByte, 0, paramArrayOfByte.length);
      }
    
      public Octets insert(int paramInt, Octets paramOctets)
      {
        return insert(paramInt, paramOctets.buffer, 0, paramOctets.size());
      }
    
      public Object clone()
      {
        return new Octets(this);
      }
    
      public int compareTo(Octets paramOctets)
      {
        int i = Math.min(this.count, paramOctets.count);
        byte[] arrayOfByte1 = this.buffer;
        byte[] arrayOfByte2 = paramOctets.buffer;
        for (int j = 0; j < i; j++)
        {
          int k = arrayOfByte1[j] - arrayOfByte2[j];
          if (k != 0)
            return k;
        }
        return this.count - paramOctets.count;
      }
    
      public int compareTo(Object paramObject)
      {
        return compareTo((Octets)paramObject);
      }
    
      public byte[] getBytes()
      {
        byte[] arrayOfByte = new byte[this.count];
        System.arraycopy(this.buffer, 0, arrayOfByte, 0, this.count);
        return arrayOfByte;
      }
    
      public byte[] array()
      {
        return this.buffer;
      }
    
      public byte getByte(int paramInt)
      {
        return this.buffer[paramInt];
      }
    
      public void setByte(int paramInt, byte paramByte)
      {
        this.buffer[paramInt] = paramByte;
      }
    
      public ByteBuffer getByteBuffer(int paramInt1, int paramInt2)
      {
        return ByteBuffer.wrap(this.buffer, paramInt1, paramInt2);
      }
    
      public ByteBuffer getByteBuffer(int paramInt)
      {
        return ByteBuffer.wrap(this.buffer, paramInt, this.count - paramInt);
      }
    
      public ByteBuffer getByteBuffer()
      {
        return ByteBuffer.wrap(this.buffer, 0, this.count);
      }
    
      public String getString()
        throws Exception
      {
        return new String(this.buffer, 0, this.count, DEFAULT_CHARSET);
      }
    
      public void setString(String paramString)
        throws Exception
      {
        this.buffer = paramString.getBytes(DEFAULT_CHARSET);
        this.count = this.buffer.length;
      }
    
      public static void setDefaultCharset(String paramString)
      {
        DEFAULT_CHARSET = paramString;
      }
    
      public static void main(String[] paramArrayOfString)
      {
        Octets localOctets1 = new Octets("ddd".getBytes());
        localOctets1.replace("abc".getBytes());
        localOctets1.replace("defghijklmn".getBytes());
        try
        {
          localOctets1.replace("0123456789".getBytes("UTF-8"));
        }
        catch (Exception localException)
        {
        }
        localOctets1.insert(localOctets1.size(), "abc".getBytes());
        localOctets1.insert(localOctets1.size(), "def".getBytes());
        System.out.println(new String(localOctets1.getBytes()));
        System.out.println("size = " + localOctets1.size());
        Octets localOctets2 = new Octets("ABC".getBytes());
        localOctets1.insert(localOctets1.size(), localOctets2);
        System.out.println(new String(localOctets1.getBytes()));
        Octets localOctets3 = (Octets)localOctets1.clone();
        System.out.println(new String(localOctets3.getBytes()));
      }
    }


    so it could be done with some simple bitconverter operations like bitshifts...
    I know what they are for... and I don't think I can achieve the converting needed with bitshifting

    What I am trying to figure out is why I get 4D2 using every single tool I can think of for hex conversions BUT the second I use a pw hex tool I get D204 from 1234
    OR lets say I use 12345678 this time
    Normal Hex Tools: BC614E
    PW Hex Tool: 4E61BC00
    Which is right for the game but I can't figure out a formula that works for every single possible number which is what is annoying the hell out of me

    The other part of what I have created seemingly works just fine but I really don't get it, why make it so damn different from every hex converter out there?

  4. #4
    Account Upgraded | Title Enabled! ronny1982 is offline
    MemberRank
    Jan 2010 Join Date
    744Posts

    Re: dword -> octet

    Quote Originally Posted by das7002 View Post
    What I am trying to figure out is why I get 4D2 using every single tool I can think of for hex conversions BUT the second I use a pw hex tool I get D204 from 1234
    OR lets say I use 12345678 this time
    Normal Hex Tools: BC614E
    PW Hex Tool: 4E61BC00
    Simple reversed byte order representation

    Int(4Byte): 12345678
    Hex(4Byte): 00 BC 61 4E -> math oriented representation
    Reversed Bytes: 4E 61 BC 00 -> stream representation (in most hex editors)
    Last edited by ronny1982; 15-10-10 at 03:37 AM.

  5. #5
    Proficient Member Souris is offline
    MemberRank
    Feb 2009 Join Date
    167Posts

    Re: dword -> octet


  6. #6
    Black Magic Development das7002 is offline
    MemberRank
    Apr 2010 Join Date
    EarthLocation
    2,188Posts

    Re: dword -> octet

    Quote Originally Posted by ronny1982 View Post
    Simple reversed byte order representation

    Int(4Byte): 12345678
    Hex(4Byte): 00 BC 61 4E -> math oriented representation
    Reversed Bytes: 4E 61 BC 00 -> stream representation (in most hex editors)
    OMG, I seriously can't believe I didn't notice that and I was trying so many other ways to do it

  7. #7
    Black Magic Development das7002 is offline
    MemberRank
    Apr 2010 Join Date
    EarthLocation
    2,188Posts

    Re: dword -> octet

    Alrighty then, I've been working a bit more and have every converter working flawlessly now except for the float to oct like how PWGen and the other xml tools I have convert them, since hex doesn't directly support floats I was wondering how something like
    3.5 turns into 00006040

    I'll continue playing with it but I'm kind of lost as to how its done

  8. #8
    Proficient Member Souris is offline
    MemberRank
    Feb 2009 Join Date
    167Posts

    Re: dword -> octet

    Single precision floating-point format - Wikipedia, the free encyclopedia

    Floating Point to Hex Converter

    again, pw uses little endian so you will need to evaluate accordingly.

  9. #9
    Black Magic Development das7002 is offline
    MemberRank
    Apr 2010 Join Date
    EarthLocation
    2,188Posts

    Re: dword -> octet

    Quote Originally Posted by Souris View Post
    Single precision floating-point format - Wikipedia, the free encyclopedia

    Floating Point to Hex Converter

    again, pw uses little endian so you will need to evaluate accordingly.
    My methods of converting floats to hex never gave me results like that which is what confused the hell out of me...

  10. #10
    Black Magic Development das7002 is offline
    MemberRank
    Apr 2010 Join Date
    EarthLocation
    2,188Posts

    Re: dword -> octet

    Solved >_>



Advertisement