Quantcast

Jump to content

» «
Photo

[III] CSprite2d::SetVertices problem

Best Answer DK22Pac, 4 days ago

You can't be sure Hex-Rays decompiler will give you 100% correct function declarations (especially in case when there's a function called by a ptr).
You can always check how things look on an assembly level:

VMab6jo.png

But of course, it's a RW function, so just check RW headers :p.

In case if you want to see a correct call of 'RwIm2DRenderPrimitive' in your DB:

Way 1: Open any place where this function is called in Pseudocode window, and do this:

RMB on a function's name -> Set item type -> Delete everything -> OK -> RMB on a function's name -> Set item type -> OK
Q1jxXKw.png

Way 2: Define RwGlobals structure in your DB (together with all relative types), change 'RwEngineInstance' variable (0x661228) type to "RwGlobals *", set dOpenDevice.fpIm2DRenderPrimitive member type to


unsigned int (__cdecl *fpIm2DRenderPrimitive)(RwPrimitiveType primType, RwD3D8Vertex *vertices, int numVertices)
and enable "Force call option" for this function member.

SLQaDkF.png

PS GTA 3 1.0 RW functions (Kenking's idb & RW headers)
https://drive.google...U1UteGZjUFotekE
https://drive.google...ZkNNa3BZRmlJZFk Go to the full post


7 replies to this topic
HM128
  • HM128

    alovelyday

  • Feroci
  • Joined: 09 Jul 2006
  • European-Union
  • Best Map 2013 "ViceCityStories PC Edition"

#1

Posted 5 days ago Edited by HM128, 5 days ago.

I simply want to draw a rectangle with flexible params, but I don't get what I'm doing wrong. It crashes. Similar technique is working perfectly in (VC) but here the problem is with RwIm2DRenderPrimitive().

I have rewritten the function of drawing rectangle. It's based on function at address 0x51FA00.

 

I also used enumerations for RwRenderStateSet but I wanted to make it look like original to see what's wrong.

auto RwRenderStateSet = (int(__cdecl*)(int a1, int a2))0x5A43C0;
auto RwIm2DRenderPrimitive = (int(*)(void))0x5A4430;

auto CSprite2d__SetVertices = (int(__cdecl *)(RwRect const&rect, RwRGBA const&color1, RwRGBA const&color2, RwRGBA const&color3, RwRGBA const&color4, float nearScreenZ))0x51EE90;
auto CSprite2d__SetVertices2 = (int(__cdecl *)(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, RwRGBA const&color1, RwRGBA const&color2, RwRGBA const&color3, RwRGBA const&color4))0x51F070;

int drawRect(RwRect rect, RwRGBA color)
{
    CSprite2d__SetVertices2(rect.X1, rect.Y1, rect.X2, rect.Y1, rect.X1, rect.Y2, rect.X2, rect.Y2, color, color, color, color);
    RwRenderStateSet(1, 0);
    RwRenderStateSet(6, 0);
    //RwRenderStateSet(7, 1);
    RwRenderStateSet(8, 0);
    RwRenderStateSet(12, 0);
    RwIm2DRenderPrimitive();
    RwRenderStateSet(6, 1);
    RwRenderStateSet(8, 1);
    //RwRenderStateSet(7, 2);
    return 1;
}

DK22Pac
  • DK22Pac

  • Feroci
  • Joined: 12 Apr 2009
  • Ukraine
  • Best WIP Mod 2014 [Grand Theft Auto 3D Contribution]
    Contribution Award [Mods]

#2

Posted 5 days ago

RwBool RwIm2DRenderPrimitive(RwPrimitiveType primType, RwIm2DVertex* vertices, RwInt32 numVertices) {
    return ((RwBool(__cdecl *)(RwPrimitiveType, RwIm2DVertex*, RwInt32))0x5A4430)(primType, vertices, numVertices);
}

HM128
  • HM128

    alovelyday

  • Feroci
  • Joined: 09 Jul 2006
  • European-Union
  • Best Map 2013 "ViceCityStories PC Edition"

#3

Posted 4 days ago Edited by HM128, 4 days ago.

Ayy, tested and doesn't work. Not crashing, but also doesn't draw anything. The function doesn't take any params in III. There are few similar which takes some but they also doesn't work here.

 

Sad that III doesn't have CSprite2d__DrawAnyRect function.


The Hero
  • The Hero

    Into TheGame!!!

  • Feroci
  • Joined: 25 Jan 2005
  • Germany
  • Most Helpful Modding 2016 [Honorable mention]
    Best Script or Plugin 2016 [SkyGfx]
    Contribution Award [Mods]

#4

Posted 4 days ago Edited by The Hero, 4 days ago.

I don't know what your problem is, but RwIm2DRenderPrimitive most definitely takes exactly the arguments DK mentioned.
In your function e.g. RwIm2DRenderPrimitive(rwPRIMTYPETRIFAN, &CSprite2d::maVertices, 4);

HM128
  • HM128

    alovelyday

  • Feroci
  • Joined: 09 Jul 2006
  • European-Union
  • Best Map 2013 "ViceCityStories PC Edition"

#5

Posted 4 days ago Edited by HM128, 4 days ago.

But the function doesn't look like that in this case, it's a callvoid and just a pointer inside.

(III) 1.0 0x51F070

7e9ldU2.png

 

Anyway some of the typecasting is messed also, the function obviously takes RwRect arg1 and RwRGBA arg2.

 

I tried to find some infos about that but it looks like no one was messing with this before.


DK22Pac
  • DK22Pac

  • Feroci
  • Joined: 12 Apr 2009
  • Ukraine
  • Best WIP Mod 2014 [Grand Theft Auto 3D Contribution]
    Contribution Award [Mods]

#6

Posted 4 days ago   Best Answer Edited by DK22Pac, 3 days ago.

You can't be sure Hex-Rays decompiler will give you 100% correct function declarations (especially in case when there's a function called by a ptr).
You can always check how things look on an assembly level:

VMab6jo.png

But of course, it's a RW function, so just check RW headers :p.

In case if you want to see a correct call of 'RwIm2DRenderPrimitive' in your DB:

Way 1: Open any place where this function is called in Pseudocode window, and do this:
RMB on a function's name -> Set item type -> Delete everything -> OK -> RMB on a function's name -> Set item type -> OK
Q1jxXKw.png

Way 2: Define RwGlobals structure in your DB (together with all relative types), change 'RwEngineInstance' variable (0x661228) type to "RwGlobals *", set dOpenDevice.fpIm2DRenderPrimitive member type to


unsigned int (__cdecl *fpIm2DRenderPrimitive)(RwPrimitiveType primType, RwD3D8Vertex *vertices, int numVertices)
and enable "Force call option" for this function member.

SLQaDkF.png

PS GTA 3 1.0 RW functions (Kenking's idb & RW headers)
https://drive.google...U1UteGZjUFotekE
https://drive.google...ZkNNa3BZRmlJZFk
  • HM128 likes this

HM128
  • HM128

    alovelyday

  • Feroci
  • Joined: 09 Jul 2006
  • European-Union
  • Best Map 2013 "ViceCityStories PC Edition"

#7

Posted 4 days ago Edited by HM128, 4 days ago.

Thanks for your help. I just totally forgot about this. Too much trust for that.

Spoiler

Now works.


HM128
  • HM128

    alovelyday

  • Feroci
  • Joined: 09 Jul 2006
  • European-Union
  • Best Map 2013 "ViceCityStories PC Edition"

#8

Posted 4 days ago Edited by HM128, 4 days ago.

Interesting that GTA III is using functions like Push and Pop. It's just a note for future knowledge.

auto CTxdStore__PushCurrentTxd = (int(*)(void))0x00527900;
//Load texture
auto CTxdStore__FindTxdSlot = (int(__cdecl *)(char *name))0x5275D0;
auto CTxdStore__SetCurrent = (int(__cdecl *)(int index))0x5278C0;
auto CTxdStore__RwTextureRead = (CSprite2d *(__cdecl*)(char *name, char *mask))0x5A7580;

auto CTxdStore__PopCurrentTxd = (int(*)(void))0x00527910;

//EDIT

Another functions:

auto CSprite2d__DrawTexture = (int(__thiscall *)(CSprite2d *, RwRect const&rect, RwRGBA const&color))0x51ED50;
//used by text draw
auto CSprite2d__SetRenderState = (void(__thiscall *)(CSprite2d *))0x51F950;
auto CSprite2d__AddSpriteToBank = (void(__cdecl *)(unsigned short textureId, RwRect const&posInfo, RwRGBA const&color, float u1, float v1, float u2, float v2, float u3, float v3, float u4, float v4))0x51EBC0;





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users