FunkyFr3sh / cnc-ddraw

GDI, OpenGL and Direct3D 9 re-implementation of the DirectDraw API for classic 2D games for better compatibility with Windows 2000, XP, Vista, 7, 8, 10, 11, Wine (Linux/macOS/Android) and Virtual Machines
https://discord.gg/afWXJNDDF5
MIT License
2.22k stars 142 forks source link

Toontown Online - unusually high CPU usage (5.1.0.0) #217

Closed toontownlpz closed 1 year ago

toontownlpz commented 1 year ago

When running the game via integrated graphics on my laptop without modification, the CPU only showed around 2% usage during play sessions. With cnc-ddraw on my main PC, the CPU usage appears to fluctuate between 50%-60%. Not sure what causes this. It's not to do with CPU differences either, because my friend experienced a high CPU usage as well, and his CPU is better than both of my devices.

The alleged issue with the final Toontown Online client is that the game struggles to detect your GPU's memory amount if it's above 2GB, thus causing an inappropriate length of time to boot. By this, I mean it could take literally an hour for the game to boot, and I am not willing to test this theory. This might be in tandem with the fact it's a 32-bit game, but still. I cannot launch Toontown Online on my main PC without cnc-ddraw as my GPU has 4GB of VRAM.

This is typically considered a tough one to debug since the official Toontown Online service provided by Disney had been discontinued, however there are fan-run servers to allow the original client to be played, which is how this issue had been discovered in the first place.

If you'd like to look into this more, feel free to join our Discord server. We're the only public Toontown Online server emulator, as far as I know.

https://sunrise.games/

FunkyFr3sh commented 1 year ago

Just tested the game and it does not use DirectDraw, so cnc-ddraw is actually doing nothing. I checked CPU usage with and without cnc-ddraw and for me it's the same.

But you are right, the game is using ddraw.dll just to call IDirectDraw__GetAvailableVidMem which cnc-ddraw does support and returns a fake value to avoid some issues like the one you did mention.

Unfortunately there isn't much I can do here, cnc-ddraw does only support DirectDraw and not Direct3d.

Here's also the cnc-ddraw.log file

[1780] 10:33:57.690 -> DirectDrawEnumerateExA(lpCallback=05D8F4B0, lpContext=0486ADB0, dwFlags=5)
[1780] 10:33:57.697 <- DirectDrawEnumerateExA
[1780] 10:33:57.697 -> DirectDrawCreateEx(lpGUID=00000000, lplpDD=0012D9A8, riid=05DB2A7C, pUnkOuter=00000000)
[1780] 10:33:57.710      Using auto renderer
[1780] 10:33:57.712      GUID = 15E65EC0 (IID_IDirectDrawX), ddraw = 015EC190
[1780] 10:33:57.712 -> IDirectDraw__AddRef(This=015EC190)
[1780] 10:33:57.712 <- IDirectDraw__AddRef(This ref=1, global ref=1)
[1780] 10:33:57.712 <- DirectDrawCreateEx
[1780] 10:33:57.712 NOT_IMPLEMENTED -> IDirectDraw__GetDeviceIdentifier(This=015EC190, pDDDI=0012D9D8, dwFlags=00000000)
[1780] 10:33:57.712 NOT_IMPLEMENTED <- IDirectDraw__GetDeviceIdentifier
[1780] 10:33:57.712 -> IDirectDraw__GetAvailableVidMem(This=015EC190, lpDDCaps=0012D9AC, lpdwTotal=0012D998, lpdwFree=0012D9A4)
[1780] 10:33:57.712 <- IDirectDraw__GetAvailableVidMem
[1780] 10:33:57.712 -> IDirectDraw__GetAvailableVidMem(This=015EC190, lpDDCaps=0012D9AC, lpdwTotal=0012D998, lpdwFree=0012D9A4)
[1780] 10:33:57.712 <- IDirectDraw__GetAvailableVidMem
[1780] 10:33:57.712 -> IDirectDraw__Release(This=015EC190)
[1780] 10:33:57.712      Released (015EC190)

The only thing we could try is to return a different value, maybe the game changes its behavior depending on the amount of available video memory?

https://github.com/FunkyFr3sh/cnc-ddraw/blob/5fc842490b971d4b09cc6cfc9d73a30d8e6e2fe2/src/dd.c#L1130

toontownlpz commented 1 year ago

image The memory usage is about what you'd expect so no concerns there, but the CPU usage seems unusually high... which I don't think was ever the case with the original game.

The game allegedly functions perfectly fine with as little as 32 MB of VRAM, according to archives of the original Disney's Toontown Online website, but to be on the safe side something like 128 MB would suffice. I say this because Disney didn't put too much care into the game after its first few years of existence, so it might be outdated information.

Apologies if I sound dumb - I am not this level of tech-savvy. What do you propose I could do to rectify this? Do you know if there's a Direct3D wrapper that allows me to set a false VRAM amount?

I just find it weird because I've tried wrappers with just "d3d9.dll" and the game doesn't boot. It only ever boots with a "ddraw.dll" wrapper, but you're saying it has nothing to do with DirectDraw so I am a little confused.

FunkyFr3sh commented 1 year ago

The memory usage is about what you'd expect so no concerns there, but the CPU usage seems unusually high... which I don't think was ever the case with the original game.

The game allegedly functions perfectly fine with as little as 32 MB of VRAM, according to archives of the original Disney's Toontown Online website, but to be on the safe side something like 128 MB would suffice. I say this because Disney didn't put too much care into the game after its first few years of existence, so it might be outdated information.

Here's one with 32mb and one with 128mb (the original 5.1.0.0 release was using 16mb BTW):

cnc-ddraw_128mb-VRAM.zip cnc-ddraw_32mb-VRAM.zip

Apologies if I sound dumb - I am not this level of tech-savvy. What do you propose I could do to rectify this? Do you know if there's a Direct3D wrapper that allows me to set a false VRAM amount?

I just find it weird because I've tried wrappers with just "d3d9.dll" and the game doesn't boot. It only ever boots with a "ddraw.dll" wrapper, but you're saying it has nothing to do with DirectDraw so I am a little confused.

You'll need both, a ddraw.dll wrapper to fix the startup issue with the faked VRAM amount and if there are any other issues then you'll need a d3d9.dll wrapper to cure those. The ddraw.dll wrapper really only reports the amount of VRAM to the game, it's not being used as the renderer.

toontownlpz commented 1 year ago

I see.

So basically I just need the "ddraw.dll". The main issue is the game refusing to boot with GPUs containing more than 2GB of VRAM. I have doubts a Direct3D 9 wrapper will rectify the high CPU usage, but I guess there's no harm in looking.

From what I can tell, there's no difference between the 32MB and 128MB ddraw's you've provided me in regards to performance, so I can only assume that "telling the game how much VRAM you have" is pretty pointless outside of the initial load point. That being said, I imagine just using the base cnc-ddraw 5.1.0.0 release will still be fine, as I experienced no performance hitches there either.

Is there any benefit to setting a higher "fake" VRAM in this case?

toontownlpz commented 1 year ago

Okay, I have found that the 128MB ddraw.dll allowed a Direct3D 9 to Vulkan wrapper to work. The 16MB 5.1.0.0 release simply crashed on boot, so I imagine the change in video memory size had something to do with it.

FunkyFr3sh commented 1 year ago

Ah, nice! Yeah, I don't really know what the game is doing and if theres any difference between the 128/16mb versions. Could be that the game only has the initial check or maybe it does a few other things later on.