Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Drug Wars
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

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

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

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

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

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

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

    2. Forum Support

    3. Suggestions

[BETA] GTAIV .Net ScriptHook


HazardX
 Share

Recommended Posts

Nice work on the update icon14.gif

 

But im not sure if its this new version, the game keeps on crashing ingame confused.gif

Edited by .Trooper.
Link to comment
Share on other sites

Hey HazardX can you release a version where "Numpad 5" key is not blocked? I have Simple Native Trainer and I have to press 5 for about a minute to respond. It's not a mod's fault, cuz I tried with no mods and numpad 5 was still blocked.

Link to comment
Share on other sites

Hey HazardX can you release a version where "Numpad 5" key is not blocked? I have Simple Native Trainer and I have to press 5 for about a minute to respond. It's not a mod's fault, cuz I tried with no mods and numpad 5 was still blocked.

I am investigating this. My guess is that it is a common problem when several mods use GetAsyncKeyState to check if the key was pressed.

 

Most asi mods use "bool keypressed = (GetAsyncKeyState(KEYCODE) & 0x0001);" to check if the key was pressed since they last checked. The problem: Since all asi mods run in the same application context, this function does NOT work reliable! It does not return if the key was pressed since YOU last checked it, instead it returns if the keys was pressed since ANY asi mod last checked it. Which results in asi mods "stealing" the keypresses, hiding them from all other mods.

 

On the other hand, using "bool keypressed = (GetAsyncKeyState(KEYCODE) & 0x8000);" returns whether the key is CURRENTLY pressed, no matter who else used GetAsyncKeyState on the same key earlier and thus is reliable. To get if the key was recently pressed or released you need to store the "keypressed" value from the last frame and compare it the the value of the current frame. the key was pressed or released if the value has changed. The only downside is, that keystrokes will not be detected when the time a key was pressed is shorter than one frame.

 

Using the second method is preferable, to ensure that the mod cannot be blocked by others. The scripthook uses it already. However, both will block other mods which use the first method, since both use GetAsyncKeyState. I guess i'll look for another method to check the keys that does not block others, because the first method is just too common.

Link to comment
Share on other sites

Yes hazardX. that is most likely the problem, I use a combination of both the high and low bit for keypresses, in general I use the high bit 0x8000 when keycombinations are used, mainly because using when testing for value 1, it would work even if the keys are not pressed simultaneously, ie. say I want to use CTRL+F1, if testing it on the 1 value, it would work if the user would press CTRL then F1 and the other way around.

 

Most single keypressses however I indeed use Getasynckeystate and test for the value to be 1. As obviously the problem above isn't applicable, I would be happy to check all keypresses for the high bit, if this solves the issue.

 

 

 

 

Link to comment
Share on other sites

HazardX, few questions

1. How do I use Dx stuff?

2. How to fluently change light position (I mean when I change Position property of Light object every PerFrameDrawing event it flickers, but when I used Graphics.DrawLight() in elder releases it didn't)

3. How can I run threads in scripts? When I do it game hangs. Is there any possibility to do async operations in scripts?

Edited by _hax
Link to comment
Share on other sites

HazardX, two questions

1. How do I use Dx stuff?

2. How to fluently change light position (I mean when I change Position property of Light object every PerFrameDrawing event it flickers, but when I used Graphics.DrawLight() in elder releases it didn't)

on 1: There is no direct access to DirectX functions from the scripts. I first thought about bundling the scripthook with SlimDX to allow full access to all DirectX function from .Net Scripts, but then decided against it because i didn't want to ship yet another DLL in the archive. It would have been overload anyway.

Instead the scripthook uses Direct3D internally to draw all things you can do via the Graphics class (supplied by the PerFrameDrawing event) like drawing lines, boxes and text. Drawing sprites on screen is planned already. Do you have any special wishes for Direct3D functions that should be available?

 

on 2: I just checked this. The problem is that PerFrameDrawing runs now right before the finished game scene is published on the screen. Thus is gets executed AFTER all lights have been drawn by the game already. If you now set the light position inside PerFrameDrawing, it will be drawn next frame at this position. Thus in this case the light is always 1 frame behind, which results in visual stuttering.

To Resolve this you can set the Interval of your script to 0 and set the position of the light inside the Tick event. This, however, might be a problem if your script does many other things inside Tick, since it is running every frame now and thus may result in a slowdown. In this case you could use a Timer object with an interval of ,like, 1000 and catch it's Tick event and do your other stuff there.

Link to comment
Share on other sites

Hazard what does this mean regarding D3d, when later my game froze

 

 

2009-07-27 15:45:36 - Direct3D device lost!2009-07-27 15:45:47 - Direct3D device created!

 

Link to comment
Share on other sites

 

Hazard what does this mean regarding D3d, when later my game froze

 

 

2009-07-27 15:45:36 - Direct3D device lost!2009-07-27 15:45:47 - Direct3D device created!

 

I would say you alt-tabbed out of the game and then back in again. tounge.gif

Link to comment
Share on other sites

Hazard what does this mean regarding D3d, when later my game froze

 

 

2009-07-27 15:45:36 - Direct3D device lost!2009-07-27 15:45:47 - Direct3D device created!

 

it depends... what do you mean by "later"? a second later, or minutes later?

 

there are many things that can lead to the Direct3D device being lost (like Zach said pressing Alt-Tab to switch out of the game is one of them). Additionally the message is completely normal while loading a game or closing GTA4. Usually the device should recover from it.

Link to comment
Share on other sites

One more thing

How can I run threads in scripts? When I do it game hangs. Is there any possibility to do async operations in scripts? Timers do the trick, but I need to call for example Function1() and Function2() at same time

Link to comment
Share on other sites

Hey _hax, you made that tuning mod, didn't you? Nice work smile.gif

And good luck for finding out another solution to that "key bug", cuz I don't know nothing about scripting sad.gif

Link to comment
Share on other sites

SlingShotUK

This is truly incredible news! Awesome to have you back Hazard. The .NET script hook is the heart of modding for me and I feel it opens so many new oppourtunities for creating mind blowing mods. When it appeared that the project had died I was gutted..

 

You are a total legend Hazard and I'm looking forward to seeing old mod's developed again and brand new ones from eager modders. I do intend to finally get around to getting into the script hook myself and will have a play once I've updated my game to 1.0.4 and sorted out how to get my PS3 controller working wirelessly in Vista x64.

 

It feels like modding is finally back (yes, I know it never went away but you know what I mean).. Just great to see what gets released when more people are able to mod this awesome game.

Link to comment
Share on other sites

Make sure your DirectX is updated.

 

Hazard, the DrawRectangle works fine and displays in the correct position with e.Graphics.Scaling = FontScaling.ScreenUnits. However any text doesn't it all appears in the top right hand corner.

Just quoting myself here tounge.gif Any ideas?

Link to comment
Share on other sites

Make sure your DirectX is updated.

 

Hazard, the DrawRectangle works fine and displays in the correct position with e.Graphics.Scaling = FontScaling.ScreenUnits. However any text doesn't it all appears in the top right hand corner.

Just quoting myself here tounge.gif Any ideas?

Now that you say, i have the same. I placed text at like 0.1 x 0.2 and it was in 0.0x0.0. Didnt really noticed now that you say it. I also used ScreenUnits.

Link to comment
Share on other sites

When I need to place something in screen units, I use this

 

int x = resolution.Width*0.1fint y = resolution.Height*0.1f

 

And you need to assign "resolution" property in constructor

 

this.resolution = Game.Resolution

 

 

It doesn't work when you change game resolution, but it is fast and reliable

Link to comment
Share on other sites

When I need to place something in screen units, I use this

 

int x = resolution.Width*0.1fint y = resolution.Height*0.1f

 

And you need to assign "resolution" property in constructor

 

this.resolution = Game.Resolution

 

 

It doesn't work when you change game resolution, but it is fast and reliable

Sure, this works too. But setting the Scaling once is easier if you've got multiple things to draw and it does the same internally. You also do not need to cache the resolution. Game.Resolution is cached internally, thus accessing it should not be slower.

 

I'm currently looking at the font rendering... maybe i forgot a scaling calculation somewhere.

 

BTW: I found a solution for the GetAsyncKeyState problem. I'll upload it in a few hours.

Link to comment
Share on other sites

When I need to place something in screen units, I use this

 

int x = resolution.Width*0.1fint y = resolution.Height*0.1f

 

And you need to assign "resolution" property in constructor

 

this.resolution = Game.Resolution

 

 

It doesn't work when you change game resolution, but it is fast and reliable

Sure, this works too. But setting the Scaling once is easier if you've got multiple things to draw and it does the same internally. You also do not need to cache the resolution. Game.Resolution is cached internally, thus accessing it should not be slower.

 

I'm currently looking at the font rendering... maybe i forgot a scaling calculation somewhere.

 

BTW: I found a solution for the GetAsyncKeyState problem. I'll upload it in a few hours.

cool wink.gif

I solved my thread problem, but I have yet another one - how to stop GTA.Timer? biggrin.gif

And why threads and system.timers don't work as intended? (I mean threads and async callbacks hang game, and timers do other wired stuff). How can I run multi threaded script?

Link to comment
Share on other sites

 

I solved my thread problem, but I have yet another one - how to stop GTA.Timer? biggrin.gif

And why threads and system.timers don't work as intended? (I mean threads and async callbacks hang game, and timers do other wired stuff). How can I run multi threaded script?

Set the Interval to 0 to stop the timer from firing the Tick event.

 

Threads do not work because GTA is not compatible with multithreading. Scripting threads in GTA4 never run in parallel. There is always just one thread running. As soon as it comes to a halt (for example when Wait is called) another thread starts running and so on. Thus all scripting functions are not threadsafe and will crash as soon as two parallel threads try to access the same variable or object. When you start a new thread it will run in parallel to all other GTA threads and thus leads to a crash.

 

I could add a function to the Script class that starts a given method in a new thread which is handled in the same way, but this is rather complicated at the moment. It is on my to do list, but i'm not sure how soon i'm able to implement it.

 

 

[EDIT] Okay, if found the text drawing bug too. There was a wrong conversion that rounded text coordinates to integer values.

Edited by HazardX
Link to comment
Share on other sites

I just simply created a seperate function as a quick fix to get the proper screen coords when drawing graphics, I didn't even have to mess with scaling.

 

 

float GetResF(float inRes, bool bvert){   if (bvert)   {       return Game.Resolution.Height * inRes;   }   else   {       return Game.Resolution.Width * inRes;   }}

 

 

Then if you had the draw code like this

 

 

e.Graphics.DrawRectangle(0.5f, 0.1f, 0.2f, 0.03f, Color.Black);

 

 

You can just simply rewrite it like this

 

 

e.Graphics.DrawRectangle(GetResF(0.5f, false), GetResF(0.1f, true), GetResF(0.2f, false), GetResF(0.03f, true), Color.Black);

 

 

 

It also works for text!

 

 

e.Graphics.DrawText("Text to display", GetResF(0.5f, false), GetResF(0.2f, true), Color.White);

 

 

 

PS: Hazard, how come you never reply to any of my PMs. Even if it's a simple "f*ck off loser, don't PM me anymore" it would be better than nothing at all. confused.gif

Link to comment
Share on other sites

 

I just simply created a seperate function as a quick fix to get the proper screen coords when drawing graphics, I didn't even have to mess with scaling.

 

...

 

PS: Hazard, how come you never reply to any of my PMs. Even if it's a simple "f*ck off loser, don't PM me anymore" it would be better than nothing at all. confused.gif

Well, i personally think this is simpler:

 

e.Graphics.Scaling = FontScaling.ScreenUnits;e.Graphics.DrawRectangle(0.5f, 0.1f, 0.2f, 0.03f, Color.Black);

 

wink.gif It will work correctly in the new update to be released in a few minutes.

 

 

Sorry about the PMs. I received a whole lot of PMs but was very focused on fixing the ScriptHook. I'll respond to them soon...

 

 

 

 

 

 

[EDIT] Jeez... i seriously hope all major bugs are fixed now. *sigh*

 

NEW VERSION:

 

GTAIV .Net Script Hook v0.891 BETA

 

Changes in Version 0.891 BETA:

- Fixed a problem that resulted in keystrokes not being catched by other mods

- Fixed a bug that drew some text messages at the wrong position when using ScreenUnits scaling.

Edited by HazardX
Link to comment
Share on other sites

Black Patriot

Hey Hazard,

I've been tinkering with the DX forms that you've added, specifically the windows example script you included, and I've noticed that it can really kill the FPS in game, like mine went down from 49 to 35 just opening that small window. Is that supposed to happen, or is there something wrong with my setup?

 

BTW, cheers for all the support, and for adding the DirectX stuff. biggrin.gif

Link to comment
Share on other sites

Just wanted to tell you that the problem with the key's not being registered still happens sad.gif

 

Simple Native Trainer kinda died with this.

Link to comment
Share on other sites

hi hazzard x greets from NIEDERSACHSEN ^^

 

i have a question

 

i try to use the old neon script

 

but this is what i get when i rum the script i hope u can help m e to fix this

 

 

2009-07-29 07:12:28 - Loading dynamic scriptfile 'scripts\NeonScript.vb' ...

2009-07-29 07:12:31 - 1 Errors in script 'G:\GTA 4\Grand Theft Auto IV\scripts\NeonScript.vb':

in Line 50: 'DrawLight' is not a member of 'GTA.Graphics'.

 

 

 

Link to comment
Share on other sites

 

Just wanted to tell you that the problem with the key's not being registered still happens sad.gif

 

Simple Native Trainer kinda died with this.

Are you sure? I was able to replicate the problem in the old version of the hook with Sajaak's simple trainer, but in the new version everything runs smoothly for me.

 

@Black Patriot: Yes, GTA.Forms has a serious performance impact ATM. The problem is that DirectX runs in the main thread of the hook, while each script has an own thread. Thus each draw call (each line and box) needs to be passed to the other thread in a rather complicated way. However, the whole system has lots of room left for optimization. I just didn't optimize it yet to get it finished fast and FPS aren't that important while using a window.

 

@DACK 23: greetings, federal state mate. Shifty41s_beerhatsmilie2.gif The NeonScript needs to be changed for the new version. I'll take a look at it.

Link to comment
Share on other sites

 

@DACK 23: greetings, federal state mate. Shifty41s_beerhatsmilie2.gif The NeonScript needs to be changed for the new version. I'll take a look at it.

THX for that

 

have a cookie.gif

Link to comment
Share on other sites

Quick question: how do call native functions again? I need to read the stats, but i dont want to use the enum...

Link to comment
Share on other sites

KingBulleT 8747

If i start my game, the Nethook doesnt load any scripts, i have 3 or 4 scripts inside the scripts folder, but the hook doesnt load them. Reloadscripts doesnt work.

Link to comment
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
 Share

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

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