Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!   (85,730 visits to this link)

    2. News

    1. GTA Online

      1. Find Lobbies & Players
      2. Guides & Strategies
      3. Vehicles
      4. Content Creator
      5. Help & Support
    2. Crews

      1. Events
      2. Recruitment
    1. Grand Theft Auto Series

    2. GTA Next

    3. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    4. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA Mods
    5. GTA Chinatown Wars

    6. GTA Vice City Stories

    7. GTA Liberty City Stories

    8. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    9. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    10. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    11. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    12. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    3. Featured Mods

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption 2

    2. Red Dead Redemption

    3. Rockstar Games

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Programming
      5. Movies & TV
      6. Music
      7. Sports
      8. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Forum Support

    2. Site Suggestions

KNN.

[III] CSprite2d::SetVertices problem

Recommended Posts

KNN.

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;}
Edited by HM128

Share this post


Link to post
Share on other sites
DK22Pac

RwBool RwIm2DRenderPrimitive(RwPrimitiveType primType, RwIm2DVertex* vertices, RwInt32 numVertices) {

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

}

Share this post


Link to post
Share on other sites
KNN.

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.

Edited by HM128

Share this post


Link to post
Share on other sites
The Hero

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);

Edited by The Hero

Share this post


Link to post
Share on other sites
KNN.

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.

Edited by HM128

Share this post


Link to post
Share on other sites
DK22Pac

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.com/uc?export=download&id=0B3pQzS44FafdU1UteGZjUFotekE

https://drive.google.com/uc?export=download&id=0B3pQzS44FafdZkNNa3BZRmlJZFk

Edited by DK22Pac

Share this post


Link to post
Share on other sites
KNN.

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

 

 

struct Vertex{    BYTE r;    DWORD fvf;    DWORD vertices;    DWORD vert_count;};//III functionsauto RwRenderStateSet = (int(__cdecl*)(RwRenderState a1, int a2))0x5A43C0;auto RwIm2DRenderPrimitive = (void(__cdecl *)(DWORD primType, Vertex* vertices, int numVertices))0x5A4430;class CSprite2d;auto CTxdStore__PushCurrentTxd = (int(*)(void))0x00527900;auto CTxdStore__PopCurrentTxd = (int(*)(void))0x00527910;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 CSprite2d__Draw = (int(__cdecl *)(RwRect const&rect, RwRGBA const&color1, RwRGBA const&color2, RwRGBA const&color3, RwRGBA const&color4))0x51FA00;auto CSprite2d__SetVertices = (int(__cdecl *)(RwRect const&rect, RwRGBA const&color1, RwRGBA const&color2, RwRGBA const&color3, RwRGBA const&color4, bool 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;void CSprite2d__DrawAnyRect(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){	CSprite2d__SetVertices2(x1, y1, x2, y2, x3, y3, x4, y4, color1, color2, color3, color4);	RwRenderStateSet(rwRENDERSTATETEXTURERASTER, 0);	RwRenderStateSet(rwRENDERSTATEZTESTENABLE, 0);	RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, 0);	RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, 0);	RwIm2DRenderPrimitive(5, (Vertex*)0x6E9168, 4);	RwRenderStateSet(rwRENDERSTATEZTESTENABLE, 1);	RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, 1);}

 

 

Now works.

Edited by HM128

Share this post


Link to post
Share on other sites
KNN.

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 textureauto 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 drawauto 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;
Edited by HM128

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.