THEAETIK Posted January 1, 2021 Share Posted January 1, 2021 (edited) I'm trying to find an alternative for the GTA.UI.WorldToScreen function that was removed a while back. This function immediately crashes my mod on newer versions of .NET past v2.10.10; forcing my users to use this specific .NET version only Quote "V3.0.0 Removed GTA.UI.WorldToScreen from v2. (impossible to implement due to how the new loader works) Scripts using this method won't work unfortunately." Any pointers appreciated.Usage: I'm using this function to render UI.DrawTexture over Peds / Vehicles. Edited January 1, 2021 by THEAETIK Link to comment Share on other sites More sharing options...
LeeC22 Posted January 1, 2021 Share Posted January 1, 2021 (edited) 3 hours ago, THEAETIK said: I'm trying to find an alternative for the GTA.UI.WorldToScreen function that was removed a while back. This function immediately crashes my mod on newer versions of .NET past v2.10.10; forcing my users to use this specific .NET version only Any pointers appreciated.Usage: I'm using this function to render UI.DrawTexture over Peds / Vehicles. You can still wrap this Native with your own function, the Native hasn't been removed, only SHVDN's function. (As far as I know anyway... I still use 2.10.10 so I might be wrong on that) BOOL GET_SCREEN_COORD_FROM_WORLD_COORD(float worldX, float worldY, float worldZ, float* screenX, float* screenY) Or you can use this as a replacement. SET_DRAW_ORIGIN(float x, float y, float z, Any p3) This is an example posted by Camxxcore in another thread. Vector3 boneCoord = somePed.GetBoneCoord(Bone.SKEL_Head); Function.Call(Hash.SET_DRAW_ORIGIN, boneCoord.X, boneCoord.Y, boneCoord.Z, 0); Function.Call(Hash.DRAW_SPRITE, "helicopterhud", "hud_corner", -0.01, -0.015, 0.013, 0.013, 0.0, 255, 0, 0, 200); Function.Call(Hash.DRAW_SPRITE, "helicopterhud", "hud_corner", 0.01, -0.015, 0.013, 0.013, 90.0, 255, 0, 0, 200); Function.Call(Hash.DRAW_SPRITE, "helicopterhud", "hud_corner", -0.01, 0.015, 0.013, 0.013, 270.0, 255, 0, 0, 200); Function.Call(Hash.DRAW_SPRITE, "helicopterhud", "hud_corner", 0.01, 0.015, 0.013, 0.013, 180.0, 255, 0, 0, 200); Function.Call(Hash.CLEAR_DRAW_ORIGIN); Edited January 1, 2021 by LeeC22 Link to comment Share on other sites More sharing options...
THEAETIK Posted January 2, 2021 Author Share Posted January 2, 2021 (edited) I assume Draw Origin only works for the native sprites (IE like SET_TEXT_COLOUR). I'd use it in a heartbeat if I wasn't using UI.DrawTexture. I'm also on 2.10.10, in the V3 update this is what happened:https://github.com/crosire/scripthookvdotnet/issues/903 Quote Yes. It was impossible to implement that after porting the codebase to C#. So it is the one and only function that had to go. Fortunately there are very little scripts that make use of it. I assume "GET_SCREEN_COORD_FROM_WORLD_COORD" is the derivative. Not going to lie, I find it baffling that only a few mods are using such and useful function, it appears most people are using GTA's native draw system then. So then, some whacky hack would be to somehow obtain the DRAWSPRITE 2-point location to use for UI.DrawTexture. Worst case scenario, Is there an online library for all of GTA's sprite textures with images (other than this one)? I know only of the Blips IDs Edited January 2, 2021 by THEAETIK Link to comment Share on other sites More sharing options...
LeeC22 Posted January 2, 2021 Share Posted January 2, 2021 (edited) 3 hours ago, THEAETIK said: I assume Draw Origin only works for the native sprites (IE like SET_TEXT_COLOUR). I'd use it in a heartbeat if I wasn't using UI.DrawTexture. I'm also on 2.10.10, in the V3 update this is what happened: It works for anything, I use it for UI.Drawtexture, UIText, UIRectangle etc... it simply sets the draw position to 0,0 at that 3D coordinate on the screen. It actually makes things much easier because you are always drawing at a position relative to the size of the thing you are drawing. So a 40 x 20 rectangle is centered by drawing it at -20, -10. I have an info system that can either be 3D which uses a scaleform, or 2D which uses a UIText. This is the 2D code. InfoDisplay2D is a UIText. public void Draw2D(Vector3 position, float size) { if (IsDisplay2DOnly) { Function.Call(Hash.SET_DRAW_ORIGIN, position.X, position.Y, position.Z, 0); InfoDisplay2D.Scale = size; InfoDisplay2D.Caption = Text; InfoDisplay2D.Position = new Point(0, 0); InfoDisplay2D.Draw(); Function.Call(Hash.CLEAR_DRAW_ORIGIN); } } Not sure about the online library, I simply exported all the images from script_txds.rpf into folders. This is an rpf you can also add your own ytd file to and then draw the sprites with either the Native sprite functions, or the SHVDN UISprite class. Edit: Crap... I was sure I had used this for UI.Drawtexture() but it doesn't seem to work. Really sorry about that, I should have re-checked before I said so. Edit: This works with SHVDN 3.0 as a V2.0 script function: private unsafe Point GetScreenCoordFromWorldCoord(Vector3 worldCoord) { float x; float y; // GET_SCREEN_COORD_FROM_WORLD_COORD Function.Call((Hash)0x34E82F05DF2974F5, worldCoord.X, worldCoord.Y, worldCoord.Z, &x, &y); return new Point((int)(UI.WIDTH * x), (int)(UI.HEIGHT * y)); } That was in a test script built against 2.10.10 running with 2.10.13 in release 3.0.4 Edited January 2, 2021 by LeeC22 THEAETIK 1 Link to comment Share on other sites More sharing options...
LeeC22 Posted January 3, 2021 Share Posted January 3, 2021 (edited) Just been tinkering with the source for the latest SHVDN. I have a build that puts V2 back to .Net 4.5.2 as a test to try some of my mods against it. All my mods are built against 4.5.2 and when you have close to 300 mods, many of them library or shared function mods, you don't just rebuild everything because of a .net change for no good reason. I don't care about v3, I will never use it. But I digress... What shocked me was that not only did they remove that function but they didn't do the seemingly obvious solution of moving it into a different Namespace to ensure it was still available. I have just added a version of the function above into the World namespace, which means you can do World.GetScreenCoordFromWorldCoord(coord) and it quite happily returns a PointF with the screen ratios. Why didn't they do that? If I add a couple of consts for WIDTH and HEIGHT, it could return a Point with the actual screen coords instead, I just did a simple test to check if it worked. Yes that would still result in broken mods but it would only require a simple namespace change to get them working again. Instead people have to create their own function to do it and then build that into an extension class if they want it in several mods. I have re-wrapped a lot of the SHVDN functionality now and just use SHVDN as a simple Function.Call library. I can guarantee things work by doing that. Edited January 3, 2021 by LeeC22 THEAETIK 1 Link to comment Share on other sites More sharing options...
THEAETIK Posted January 11, 2021 Author Share Posted January 11, 2021 Thanks for your help, LeeC22 You are correct, the replacement works perfectly well on V2 from V3, But I'm extremely baffled. I wouldn't say I have the largest mod but I do use many function. I've noticed all kinds of weirdness. While the code compiles properly and everything without a single error; the Hydra landing gear function is suddenly broken, but more importantly, my enemies are dying in one hit, I was starting to grab my hair hoping it was just V2 from V3. So, compile from V2, and Compile using V2 on V3... every enemy dies in one hit. I revert my GTA scripthook to v2.10.10 and the weirdness goes away. I'm so out of this at this point. Too bad. Makes me wish they had stopped development at v2.10.10 honestly. LeeC22 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now