Problems hacking properties

Blitz3D Forums/Blitz3D Programming/Problems hacking properties

Hi
I'm currently working on a SaveMEsh command that will use the correct settings for everything: textures, brushes, etc. etc.
I successfully hacked most properties that make sense when saving a mesh(such as GetBrushAlpha(brush) etc.)

I failed to access the following so far:

Texture scale
texture position
texture rotation

Brush color

How would you access these properties?

BTW I want to make this work with meshes I used to load with LoadMesh, so "store your settings in variables" is not a solution. I know, I could utilize Rickies Load-Save-AnimB3d code. But I'd really like to have these functions working
(GetBrushRed(brush), GetTextureScaleX() etc.)

BTW the entity offsets have been altered in the past compiler releases!
I also remember we had a discussion here about these offsets, but the thread was deleted due to database size (post number 27000 or so). Additionally halo released some access info some time ago, but I can't find it anymore.
Furthermore there's Tom's DLL to obtain properties mainly of cameras and brushes, still doesn't cover all my needs.

IMHO these functions (a complete GetProperty range for all settings that may be used) is a significant lack. Things like GetBrushTexture and GetTexturePath were added recently, but what was needed is a systematic wrap of all properties in all command families. Just go trough the docs section by section and note every setting command.

Any help is welcome!


EDIT: could it be that some settings are "shoot and forget"? I doubt Mark would do this, but it seems I cannot detect some settings even when I scale larger amounts of RAM around the pointers found around the handle-pointer.

There must be half a dozen save mesh code archive entries - I've not looked at them - but I mention it anyway.

This may help - not sure if the offsets are still valid though..
;Texture

;Function GetTextureFlags(texture)
;  Return RtlPeekInt(texture + 32)
;End Function 

Function GetTextureBlend(texture)
  Return RtlPeekInt(texture + 48)
End Function 

Function GetTextureCoords(texture)
  Return RtlPeekInt(texture + 52)
End Function 

Function GetTextureScaleU#(texture)
  Return 1.0 / RtlPeekFloat(texture + 60)
End Function 

Function GetTextureScaleV#(texture)
  Return 1.0 / RtlPeekFloat(texture + 64)
End Function 

Function GetTexturePositionU#(texture)
  Return -RtlPeekFloat(texture + 68)
End Function 

Function GetTexturePositionV#(texture)
  Return -RtlPeekFloat(texture + 72)
End Function 

Function GetTextureRotation#(texture)
  Return (-360.0 * RtlPeekFloat(texture + 76)) / (2.0 / Pi)
End Function 

;Use this funcs if you retrieve texture with GetBrushTexture

;Function GetBrushTextureFlags(texture)  
;  Return 1;RtlPeekInt(RtlPeekInt(texture) + 8)
;End Function 

Function GetBrushTextureBlend(texture)
  Return RtlPeekInt(RtlPeekInt(texture) + 24)
End Function 

Function GetBrushTextureCoords(texture)
  Return RtlPeekInt(RtlPeekInt(texture) + 28)
End Function 

Function GetBrushTextureScaleU#(texture)
  Return 1.0 / RtlPeekFloat(RtlPeekInt(texture) + 36)
End Function 

Function GetBrushTextureScaleV#(texture)
  Return 1.0 / RtlPeekFloat(RtlPeekInt(texture) + 40)
End Function 

Function GetBrushTexturePositionU#(texture)
  Return - RtlPeekFloat(RtlPeekInt(texture) + 44)
End Function 

Function GetBrushTexturePositionV#(texture)
  Return - RtlPeekFloat(RtlPeekInt(texture) + 48)
End Function 

Function GetBrushTextureRotation#(texture)
  Return (-360.0 * RtlPeekFloat(RtlPeekInt(texture) + 52)) / (2.0 / Pi)
End Function 

;Brush

Function GetBrushBlend(brush)
  Return RtlPeekInt(RtlPeekInt(brush) + 4)
End Function 

Function GetBrushColorRGB(brush)
  Return (GetBrushColorR(brush) Shl 16) Or (GetBrushColorG(brush) Shl 8) Or GetBrushColorB(brush)
End Function 

Function GetBrushColorR(brush)  
  Return RtlPeekFloat(RtlPeekInt(brush) + 16)*255  
End Function 

Function GetBrushColorG(brush)
  Return RtlPeekFloat(RtlPeekInt(brush) + 20)*255  
End Function 

Function GetBrushColorB(brush)
  Return RtlPeekFloat(RtlPeekInt(brush) + 24)*255  
End Function 

Function GetBrushFX(brush)
 Return RtlPeekInt(RtlPeekInt(brush) + 40)
End Function 

Function GetBrushShininess#(brush)
 Return RtlPeekFloat(RtlPeekInt(brush) + 28)
End Function 

Function GetBrushAlpha#(brush)
 Return RtlPeekFloat(RtlPeekInt(brush) + 32)
End Function 


;Entity

;Quaternions (local only)

Function EntityQuatW#(entity)
  Return RtlPeekFloat(entity + 48)
End Function 

Function EntityQuatX#(entity)
  Return RtlPeekFloat(entity + 52)
End Function 

Function EntityQuatY#(entity)
  Return RtlPeekFloat(entity + 56)
End Function 

Function EntityQuatZ#(entity)
  Return RtlPeekFloat(entity + 60)
End Function 

Function SetEntityQuat(entity, w#, x#, y#, z#)
  RtlPokeFloat(entity + 48, w#)
  RtlPokeFloat(entity + 52, x#)
  RtlPokeFloat(entity + 56, y#)
  RtlPokeFloat(entity + 60, z#)
  TurnEntity entity,0,0,0
End Function 

;EntityScale funcs based on original code of Mikkel Fredborg

Function EntityScaleX#(Entity, glob=False)

ScaleX# = RtlPeekFloat(Entity + 76)

If glob

Vx# = GetMatElement(Entity, 0, 0)

Vy# = GetMatElement(Entity, 0, 1)

Vz# = GetMatElement(Entity, 0, 2)

ScaleX# = Sgn(ScaleX) * Sqr(Vx#*Vx# + Vy#*Vy# + Vz#*Vz#)

EndIf


Return ScaleX


End Function

Function EntityScaleY#(Entity, glob=False)

ScaleY# = RtlPeekFloat(Entity + 80)

If glob 

Vx# = GetMatElement(Entity, 1, 0)

Vy# = GetMatElement(Entity, 1, 1)

Vz# = GetMatElement(Entity, 1, 2)

ScaleY# = Sgn(ScaleY) * Sqr(Vx#*Vx# + Vy#*Vy# + Vz#*Vz#)

End If


Return ScaleY


End Function

Function EntityScaleZ#(Entity, glob=False)

ScaleZ# = RtlPeekFloat(Entity + 84)

If glob

Vx# = GetMatElement(Entity, 2, 0)

Vy# = GetMatElement(Entity, 2, 1)

Vz# = GetMatElement(Entity, 2, 2)

ScaleZ# = Sgn(ScaleZ) * Sqr(Vx#*Vx# + Vy#*Vy# + Vz#*Vz#)

End If


Return ScaleZ


End Function


;Internal
Function RtlPeekInt%(addr)
  Bank = CreateBank(4) 
  Kernel32_RtlMoveMemory2(Bank,addr,4) 
  Value = PeekInt(Bank, 0)
  FreeBank(Bank)
  Return Value
End Function 

Function RtlPokeInt(addr, value)
  Bank = CreateBank(4) 
  PokeInt Bank, 0, value
  Kernel32_RtlMoveMemory(addr,Bank,4)   
  FreeBank(Bank)  
End Function

Function RtlPeekFloat#(addr)
  Bank = CreateBank(4) 
  Kernel32_RtlMoveMemory2(Bank,addr,4) 
  Value# = PeekFloat(Bank, 0)
  FreeBank(Bank)
  Return Value
End Function

Function RtlPokeFloat(addr, value#)
  Bank = CreateBank(4) 
  PokeFloat Bank, 0, value
  Kernel32_RtlMoveMemory(addr,Bank,4)   
  FreeBank(Bank)  
End Function


.decls

.lib "kernel32.dll"
Kernel32_RtlMoveMemory%(Destination,Source*,Length) : "RtlMoveMemory" 
Kernel32_RtlMoveMemory2%(Destination*,Source,Length) : "RtlMoveMemory"


Wow, thanks a lot!!! Saves me a lot of work!

Ok, some of them still work, some don't

Especially those GetTextureScaleU etc. don't work anymore, where their counterparts for the handles obtained by GetTextureBrush (eg GetTextureBrushScaleU) will now work also for loaded and created textures right away.

GetBrushTextureFlags is currently driving me mad.
I put the output as a binary value onto the screen. First there's the 16th bit that is set all the time.

Bit values 1 and 2 work normally. Bit value 4 will return 7, the same as bit value 7!

eg:
tex=loadtexture("map.jpg",4)
will give me
%0000000111

just like
tex=loadtexture("map.jpg",7)

no idea why...

Bit values 8 to 128 are working as expected.

Bit 256 to 32768 will not affect the int found at offset 8 at all.

So it seem the bits are laying around all over :o, Unfort. I really need the flags, they're most important to me.

Uh, kind of russian roulette is it. Maybe I better use your B3D loader noless. I could combine it: obtain the properties using the loader, then load the mesh using LoadMesh. Tho, the loading order of the surfaces still has to be sorted due to DXs fancy loading order scrambling.

This was kinda waste of time, I wish I used your loader in the first place, Ricky, it's perfect!

I guessed some of the offsets may be out of date due to the changes in versions etc. It's a pity they couldn't be republished.
My loader is ok but needs a lot of tidying and optimising.