Posted: Wed May 16, 2012 6:55 pm Post subject:
ddraw.dll alternative (Request for testing)
Subject description: A possible patch for TS that might improve performance
Hi all,
I have not compared the performance impact of the different methods like creating a compatibility shim using Microsoft's AppCompat toolkit, or using ddraw.dll in XP and earlier.
Yesterday I created yet another possible fix, which does the same as Ares does to improve rendering performance by not using VRAM.
Command & Conquer Graphics Patcher is a tool to make rendering in Tiberian Sun, Red Alert 2 and Yuri's Revenge faster.
Which games can be patched?
This works for the latest patched versions, whether they are English or German. Tiberian Sun uses a packed exe, in which I couldn't locate the spot to change. If you have an unpacked exe (like from a NoCD-Patch), this should work, too. I didn't test any other language version.
At the time of release, this project was merely a day old, so if anything does not work, send me a message. This patch is designed to improve rendering in Windows Vista and later. It might not have an effect on earlier versions of Windows, or it might even have a negative impact. This patch is also stupid, because it does not automatically distiguish between OS versions to select the best behavior. Sorry for that, but I won't change it.
Testing showed this patch is working even with mods like Twisted Insurrection for Tiberian Sun and Mental Omega 2.0psi (which is using NPatch). So chances are good it is working for other mods, too.
How to use
Download the patcher and either put in in the same directory as the game or put the game.exe/gamemd.exe file in the same folder as this patcher and run it. The patch is not applied until you apply it explicitly, and it can be undone again using the patcher.
To prevent issues with Windows Vista or later, I recommend to put the patcher into a separate folder and copy the game file into it. Copy it back after patching. Also: Back up your original game file, just to be sure.
You will need the Microsoft .net Framework 3.5 to run this tool. After all files are patched, this patcher is not needed any more.
Background
The dimetric Command & Conquer games use several temporary graphics to draw to. Some of them are allocated in Video RAM, some of them are allocated in system RAM. When the game wants to draw something, the data has to be copied from VRAM to system RAM, which is an expensive operation and it gets more obvious the more objects (units, debris, ...) are on the map. The patch changes the game to not allocate surfaces in VRAM in the first place, so this cannot become an issue.
The following bytes need to be changed. This is not optimized. If you understand the raw assembler instructions, you can optimize it by putting a jmp there.
Code:
Game Offset Original Patched
Tiberian Sun 0008AC2F 3C 01 75 0C 90 90 90 90
Red Alert 2 000AA51F 3C 01 75 0C 90 90 90 90
Yuri's Revenge 000BA61F 3C 01 75 0A 90 90 90 90
Credits
The patches solve the problem the same way as it is done by Ares, the Yuri's Revenge expansion dll. The original fix was implemented by DCoder. I applied this solution to TS and RA2 and coded the patching tool around it.
While TS works perfectly for me even without it, if I turn the gamespeed up to 6 and start building walls, there's a massive performance difference after changing the bytes in the executable compared to the normal TS exe. I'm getting no FPS drop, while with the original exe my FPS feels like halving when I'm building walls on the max gamespeed.
Appears to be working for me, except that it breaks -MPDEBUG (the modified exe crashes when I use that parameter) so I'm not able to measure how large the performance difference exactly is. But it seems to be quite large. _________________ CnCNet Client | CnCNet TS patches | More Quality-of-Life Improvements for RA Remastered
I actually only notice lag when playing on the fastest gamespeed in skirmish and letting some units move around while I build a very cheap structure; your fix seems to completely eliminate the lag for
I'll most likely end up including this with DTA's next update.
So who do I credit for this? Both you and DCoder? _________________ QUICK_EDIT
This sounds really promising, going to test it later. Would this cause slow downs or other issues on an old (pre 2000 old) computer though? Not that many people play on that old PCs, but just theoretically. Are there any other issues this could potentially cause? If it works well I will probably add this to my mod's executable by default. And finally, would it make sense to use both this AND the ddraw.dll together? _________________ QUICK_EDIT
I've asked a bunch of people to test it (Tore, OmegaBolt, Holy Master and ChronoSeth) and they all reported an increase in performance (most drastically for Holy Master and Tore, for whom TS initially lagged too much to be able to play at all). _________________ QUICK_EDIT
I had a quick look at what the hack does AlexB, and i was wondering if perhaps this was applied to one surface, if in fact, there is one surface that causes this problem.
You know more about rendering that myself I'm assuming. QUICK_EDIT
I can't imagine why -MPDEBUG stopped working. The fix doesn't touch anything close to that but maybe it's affected because the surface is now located in system memory.
The fix allocates all surfaces in system memory, so all data copying from video to system memory and back is eliminated. It should not affect anything else, but tests can never hurt.
It should be possible to use ddraw.dll with this fix. Ddraw.dll forces software emulation (which is not present in Windows Vista and later). This fix just changes the way surfaces are allocated. I'm running W7, and I haven't tested this.
@Bittah Commander: The fixes are mine, the inspiration (and the YR offset) came from DCoder's work. Not a line of Ares code is involved. I can tell you how not to credit, but not how to
@Hyper: The fix should be in the surface constructor, so every instance created using this constructor should use this fix. I haven't looked at other functions that might instantiate surfaces manually. _________________ QUICK_EDIT
This is an interesting patcher you got here. I found a similar patch which enables ddraw emulation on w7/vista the same way Msoft compatibility toolkit does. Without breaking alt tab compatiblity.
It also solves the blank menu issue on some computers.
Now we just need to know whether ddraw emulation further enhances the performance in combination with AlexB's hack or whether it's become redundant... _________________ QUICK_EDIT
@Hyper: The fix should be in the surface constructor, so every instance created using this constructor should use this fix. I haven't looked at other functions that might instantiate surfaces manually.
I checked a few xrefs and some of them force TRUE, others are dependent on a result of a previous bit of code. Interesting to see where this goes. QUICK_EDIT
So I tested with the DDraw emulation fix for windows 7 and did a hex edit of the said code. I noticed the gameplay was really smooth. Only problem was just a bit of network lag.
I've noticed in the past that YR has better latency over network/xwis games then RA2. Would it be possible to patch YR's network code into RA2? QUICK_EDIT
I wouldn't know. I can't reverse the DDraw patching..
After testing with masses of units. So many rhinos and conscripts that you can't even select them properly and then driving all of them into masses of deployed deso it seems that lag is kept to a minimum from the usual 2 fps (or around that).
Though with 100's of units on screen there is still considerable lag. (tested over a network game) QUICK_EDIT
Will try it when I get home. I don't get lag playing TS. The only problem I have is the menus doesn't refresh.
If I want to play as Nod, I can click and hear the sound but I don't know what I'm clicking at.
Already tried the microsoft compat. kit but didn't work. Just gave me a black screen like the ddraw.dll method. _________________
Team Black wrote:
interesting seeing your voxel work. They're still better than Aro's!
TS used to run well for me with ddraw.dll, but without it I would get some slowdowns. With this "fix" the game runs silk smooth, even without ddraw.dll. Probably going to scrap the whole ddraw method from my mod since this seems to work for most people and is usable on vista / win7 as well, and doesn't seem to cause any problems (at least not yet...). Awesome discovery / fix, many thanks! _________________ QUICK_EDIT
The patcher doesn't detect my game.exe it only detects gamemd.exe.
Also I edited the exe's manually with a hex editor and changed the sections that were noted on your site. Now I'm unable to create games on XWIS. QUICK_EDIT
Since you said sections; it's only 1 section per game (offset 0008AC2F for TS).
I'm still perfectly able to host games with this hack, so if you're not, you've either edited in the game.exe file than you should have or it's caused by that DDraw emulation patch. _________________ QUICK_EDIT
I accidentally went editing by fiding the actual value instead of the offset. lol. Hex editing after being up all night doesn't work out too well. QUICK_EDIT
This hack and Hyper's hacks do entirely different things, so no, it's not better; it's different.
Also, I already tried applying this hack (manually with a hex editor) to HyperPatch's Game.exe file and it works perfectly with that too. _________________ Last edited by Bittah Commander on Thu May 17, 2012 3:01 pm; edited 1 time in total QUICK_EDIT
This is unrelated to WaveClass errors, this changes the way the game creates the graphic surfaces on what units, terrain, anims, the sidebar etc are drawn. QUICK_EDIT
The patcher verifies the size and some bytes of the file to detect whether it's a TS game.exe. If the bytes at the offset on my page match the ones in the TI.exe, you can patch them manually.
I'll change the way the patcher works to accept any file as long as it is large enough.
edit: Patcher is changed to accept any TS exe. Maybe this works to patch TI. _________________ QUICK_EDIT
I can play TS, RA2 and YR just fine. My only problem is at the menu. They don't refresh. So basically, I don't know what I'm clicking at when I get into the skirmish menu. I can't see the dropdown list.
EDIT: Tried it with YR but didn't work either. My not-refreshing-menu problem is still there. I can only play (play as in no more not-refreshing-menu problem) YR if I use Mouse's fix. Third post in this topic. _________________
Team Black wrote:
interesting seeing your voxel work. They're still better than Aro's!
Tested Mouse's fix with TI game.exe, and I was quite surprised that it worked. So, whatever is in his fix, I think you should take a look at it Alex. AFAIK, only Machine and I have the stupid not-refreshing-menu problem. Not sure about other people though. Haven't seen anyone else yet that suffers my problem. _________________
Team Black wrote:
interesting seeing your voxel work. They're still better than Aro's!
My fix is not supposed to touch anything besides the surface allocation. The menu problem is quite common, but it is another issue. Intel is aware of this problem, but they haven't updated their drivers yet.
Because I don't have that problem, I cannot provide a fix that I could test. All I could do would be shots in the dark. _________________ QUICK_EDIT
i tested this hack on the DTA exe and it did not work.
with the hack the game slows down to 25 to 30% of the max speed.
It's like playing on Speed=2 or 3 in the non-hacked version.
I get the same slowdown via ddraw.dll, so this isn't helping in the non-hacked version too.
However, the game is quite well playable in the non-hacked version, so i don't really need the fix.
Laptop
WinXP SP3
2GB RAM
Intel Core2Duo CPU 2.2 GHz
ATI Mobility Radeon HD 2400 XT with 512 MB RAM _________________ SHP Artist of Twisted Insurrection: Nod buildings
This patch successfully eliminated all my slowdowns with TS. No more Fire Stealth Darken.shp explosion slowdowns. The game was much more smooth and the speed levels all felt different now, I used to play on faster which is now too fast for me
U are epic. Patch is epic. This whole thread and your homepage is frikken epic. _________________ Free Tibed!
EA for worst company of the decade! QUICK_EDIT
Tried this with TI, and I have to say that there is not a single lag at all. So, ignore my earlier post. I'm liking this. If only you could make it to work with YR patched with NPExt. _________________
Team Black wrote:
interesting seeing your voxel work. They're still better than Aro's!
The fix is supposed to make rendering faster on Vista and 7, maybe Windows 8, which can tremendously suffer from this lag. WinXP can use ddraw.dll to make rendering faster without getting a black screen, but on later versions software emulation is not supported.
@Hyper: Sure
@OrangeNero: Thanks, though I think the website looks like someone shat on the server
@Krow: Patcher is updated to accept any file size now, so if NPatch doesn't change the affected bytes, it should work now. _________________ QUICK_EDIT
I can confirm that the offset and the bytes itself are same in NPExt so the patcher should work.
I tested this one with my YR mod. Played a skirmish game with 7 AI's fighting each other, full visuals details on which encompasses Translucent=yes on most anims and also debris spawning (altough without laggy TrailerAnim= on debris graphics) and so on. FPS didn't drop below 45 a single time so it might have affected some things, I haven't done very much testing on performance yet on this new machine so I can't say for sure. _________________ QUICK_EDIT
I already told Aro how to apply the hack, so I expect the next release to include it.
Considering this hack does actually cause issues for a small amount of people (making the game entirely unplayable for them), it's best to make it optional however (in TI's case the easiest way to do this would be by including 2 Game.exe files; 1 with the hack, 1 without). _________________ QUICK_EDIT
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum