• Visit Rebornbuddy
  • WoWDb Patchables Issue

    Discussion in 'Archives' started by Beowulfe, Dec 5, 2010.

    1. Beowulfe

      Beowulfe Community Developer

      Joined:
      Nov 4, 2010
      Messages:
      194
      Likes Received:
      20
      Trophy Points:
      0
      Hey guys,

      Messing around with a couple of the Patchables and have setup structs for them.

      Everything's going great, except for one minor issue that winds up making the code look a little messy.

      Namely, some issues with Styx.WoWInternals.WoWDb.Row.

      NOTE: To simplify things, I'm going to omit the "Styx.WoWInternals" off of the front of a number of these things, assumes a "using Styx.WoWInternals;" statement.

      I've worked out all of the value types in one of the Patchables to the following struct (with variable names removed):

      Code:
          struct
          {
              UInt32;
              UInt32;
      
              float;
              float;
              float;
      
              string;
      
              UInt64;
              UInt64;
          };
      Using this statement (Ignore the typename for the struct, it's not the real name obviously :p):

      Code:
                      WoWDb.Row dbRow = dbMain.GetRow(uiIndex);
      
                      if (!dbRow.IsValid)
                          continue;
      
                      SStructFromAbove structNode = dbRow.GetStruct<SStructFromAbove>();
      works perfectly, EXCEPT for the string variable. The string comes out either blank or garbled. HOWEVER, the following statement (which should essentially act exactly the same way):

      Code:
      string sSomeString = dbRow.GetField<string>(5);
      works perfectly and grabs the string, no problem.

      So, I assume the issue in the struct is related to string being a reference type by default, but I'm a C++ programmer, not a "pro" C# coder (though I do know my way around C# pretty well), so I figured it was possible I missed something simple on my end.

      Does anyone know if there's anything I can do to fix this myself, and if it's an issue in the GetStruct<> code for WoWDb.Row, is there any chance one of the HB devs could fix it?

      Any help is greatly appreciated, thanks. :D
       
      Last edited: Dec 5, 2010
    2. MaiN

      MaiN Moderator Staff Member Moderator Buddy Core Dev

      Joined:
      Jan 15, 2010
      Messages:
      1,017
      Likes Received:
      35
      Trophy Points:
      48
      A 'string' field in .NET is marshalled (by default) like a string pointer (like it should be). When you use GetStruct, Honorbuddy copies over the bytes from WoW into Honorbuddy and marshals the structure to a managed structure. Because the string in WoW, natively, is a "char *", the copied data only contains the string pointer to another process' memory space. Obviously the value points to something else entirely due to it being in our process.
      GetField has this inner implementation to handle strings:
      Code:
      if (typeof(T) == typeof(string))
      {
          object s = _memory.Read<string>(_memory.Read<uint>(((uint)_address.ToInt32() + (index * 4))));
          return (T)s;
      }
      
      That means in your structure you want to do stuff like this:
      Code:
      [StructLayout(LayoutKind.Sequential, Pack = 1)]
      public struct SomeStruct
      {
        public float SomeValue;
        private uint _someStringPtr;
      
        public string SomeString { get { return ObjectManager.Wow.Read<string>(_someStringPtr); } }
      }
      
       
    3. Beowulfe

      Beowulfe Community Developer

      Joined:
      Nov 4, 2010
      Messages:
      194
      Likes Received:
      20
      Trophy Points:
      0
      Thanks for the help! Appreciate it. :D

      Figured it was something like that - I had tried messing around with string pointers instead (using "unsafe" code), but HB doesn't like compiling plugins using unsafe code and I figured it was a long shot at best. I'm too used to C++, methinks. ;)

      Rep++!
       
      Last edited: Dec 6, 2010
    4. Apoc

      Apoc Moderator Staff Member Moderator

      Joined:
      Jan 16, 2010
      Messages:
      2,790
      Likes Received:
      94
      Trophy Points:
      48
      Thanks for the bug report. Never bothered to test unsafe code in CCs/Plugins. I'll add support for it now.
       

    Share This Page