FransBouma / InjectableGenericCameraSystem

This is a generic camera system to be used as the base for cameras for taking screenshots within games. The main purpose of the system is to hijack the in-game 3D camera by overwriting values in its camera structure with our own values so we can control where the camera is located, it's pitch/yaw/roll values, its FoV and the camera's look vector.
BSD 2-Clause "Simplified" License
718 stars 249 forks source link

Camera struct sometimes is not found in Titanfall 2 #128

Closed rs189 closed 4 years ago

rs189 commented 4 years ago

So i am working on modification for Titanfall 2 and using InjectableGenericCameraSystem as a dependency for camera manipulation stuff, but there's an annoying problem, sometimes, randomly, the camera is not being found so i have to restart the game.

I am using IGCS::GameSpecific::CameraManipulator::isCameraFound() to check if camera is being found or not.

Is there a way to force a new search for the camera process because from my understanding it's trying to find it once and if it can't it just does nothing afterward? I am not good with assembler so i may be wrong about that one.

Any help would be appreciated.

rs189 commented 4 years ago

I am also running the game in Windowed mode if that can affect it in any way.

FransBouma commented 4 years ago

It's setting a hook here: https://github.com/FransBouma/InjectableGenericCameraSystem/blob/master/Cameras/Titanfall2/InjectableGenericCameraSystem/InterceptorHelper.cpp#L125 which makes the code at AOB 89 0E 8B 48 04 89 4E 04 8B 40 08 48 8B CB 89 46 08 48 8B 03 FF 90 ?? ?? ?? ?? 8B 08 89 0F 8B 48 04 89 4F 04 8B 40 08 89 47 08 E8 ?? ?? ?? ?? 33 D2 (so the location where these bytes are in the exe in memory) be intercepted by this part: https://github.com/FransBouma/InjectableGenericCameraSystem/blob/master/Cameras/Titanfall2/InjectableGenericCameraSystem/Interceptor.asm#L87

So when the executable ends up at that spot, it'll execute that piece of asm, and then jump back to the real code in the exe, In that piece of asm, I store the address contained in the register rsi in a variable, g_cameraStructAddress, which is polled in a loop with a thread wait in system.cpp. So it'll wait indefinitely till it gets the pointer. If it doesn't find the camera, it means it never ends up there. There's no point in restarting the search as it simply waits till the execution arrives there.

It's been a while tho so I don't recall I've ran into this problem myself. You run into this frequently, also in single player? Or is it in one location or in multiplayer?

rs189 commented 4 years ago

I run it in singleplayer in Windowed mode so i can test my changes easier, and as i said its random, but for the most part it works in 80% cases, in 5% cases it does not work instantly but does find camera after 5 or so seconds, and in the remaining cases it just doesn't work at all, but what you said doesn't add up, as sometimes it works and sometimes it doesn't.

FransBouma commented 4 years ago

but what you said doesn't add up, as sometimes it works and sometimes it doesn't.

I don't know what you're referring at, as what I described is how it's setup. So if it doesn't get intercepted, the game therefore doesn't end up there (yet). Might be a cutscene which uses a different camera location/code, or other reasons, no idea.

So if it doesn't find it at all, that's odd, but as I said, it's code that writes to the camera location, so if the game calls that, it's intercepted. No idea how that 'doesn't add up'

rs189 commented 4 years ago

Not completely related to the issue above but is there any way to use IGCS as a static library?

Im hoping to utilize functions such as camera position and rotation control without need to use everything else 🙏

FransBouma commented 4 years ago

Yes I think so, you could build to a .lib file and you need to have the .h files of the code/classes you want to use. The system is started with a dllmain, but if you're using it as a .lib that's linked statically, it should be possible to just reference the functions you need by including the .h files after that. Haven't tried it tho