twinject icon indicating copy to clipboard operation
twinject copied to clipboard

Huge lag during lasers.

Open Boii1 opened this issue 4 years ago • 9 comments

Drops FPS by huge percentages when a laser is present on the screen. This is on 1.2.108 on TH10.

Boii1 avatar Jan 21 '20 06:01 Boii1

Hi, thanks for reporting this issue.

The lag from lasers is because I used a generalized separating axis test for lasers, since they are modelled by an oriented bounding box (OBB). This implementation is optimized for complex polygons, which is overkill for this case since the hit test between the player and a laser is a simple AABB/OBB collision test. I'll probably replace it with a more efficient implementation.

Netdex avatar Jan 21 '20 14:01 Netdex

Makes sense. Another note, newer versions past 1.2.108 can't seem to boot TH10. Tried both patched and unpatched, even tried to manually build it and it could not open it.

Boii1 avatar Jan 22 '20 02:01 Boii1

Hmmm... I'm assuming 1.2.112 didn't work either? I didn't change much between 1.2.108 and 1.2.112 except retargeting to v142. If you said you could manually build it then this probably isn't the problem.

One major change in 1.3 is that I rewrote the injector from scratch, which is likely to be the cause of the issue. The injector now needs a configuration file called twinject.toml instead of twinject.ini in the same directory as twinject.exe.

I don't think I updated the deploy script to add the TOML file to the release (or the documentation), so this is probably the problem. It's supposed to print an error when it can't find the file though, so it's weird that it failed silently.

Netdex avatar Jan 22 '20 04:01 Netdex

I had gone from the topmost updated version and worked my way down. I had tested each with the specified components on the page. 1.3 would inject HOWEVER TH10 would immediately crash because of the injection. 1.3.1 would not launch whatsoever. Then each below those until I got to 1.2.108 would launch and open the game only to immediately close.

Boii1 avatar Jan 22 '20 06:01 Boii1

Interesting. Since the only thing that changed is the platform toolset and target version, my primary suspicion is that something to do with that broke MS Detours. The version included in this repo has been around since its conception, and doesn't actually support Windows 10 officially. Could you tell me the version of Windows you are using? I've verified that the injection works properly with version 1.3.1 on Windows 10 1809.

Netdex avatar Jan 23 '20 03:01 Netdex

I'm on Windows 10 Enterprise LTSC Version: 1809 Also sorry for late reply. I don't have notifications for GitHub enabled.

Boii1 avatar Jan 26 '20 06:01 Boii1

No worries, this reply wasn't very quick either ¯_(ツ)_/¯ I also happen to be using Windows 10 Enterprise LTSC 1809, which rules that out as the cause. I'm currently working on a build with updated libraries and more detailed crash information which may help.

Netdex avatar Jan 28 '20 14:01 Netdex

Maybe catch any error that occurs before the program crashes and log it into a message box or text document?

Also just a suggestion but why not build an updater? I built a way to update files by URL like this:

// I'm just pulling all the includes I used for this program but I'm sure you could sort through them if you wanted to.

#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include <array>
#include <Windows.h>
#include <vector>
#include <Urlmon.h>
#include <stdio.h>
#include <tchar.h>
#include <wininet.h>
#include <TlHelp32.h>
#pragma comment(lib, "urlmon.lib")

wstring S2WS(const string& str) {
	int length;
	int slength = (int)str.length() + 1;
	length = MultiByteToWideChar(CP_ACP, 0, str.c_str(), slength, 0, 0);
	wchar_t* buffer = new wchar_t[length];
	MultiByteToWideChar(CP_ACP, 0, str.c_str(), slength, buffer, length);
	wstring out(buffer);
	delete[] buffer;
	return out;
}

// File Downloader
int download(string url) {
	wstring wUrl = S2WS(url);
	LPCWSTR lUrl = wUrl.c_str();
	TCHAR path[MAX_PATH];
	GetCurrentDirectory(MAX_PATH, path);
	wcscat_s(path, L"\\dl.txt");
	HRESULT response = URLDownloadToFile(NULL, lUrl, path, 0, NULL);
	return 0;
}

I had this string->wstring converter since I was getting errors otherwise and URLDownloadToFile required a certain set of types making it obnoxious to use but this was as much as I had gotten. You can use it like such: download("https://www.w3.org/TR/PNG/iso_8859-1.txt");

All you'd need to do really is just change the download format to the zip file (for someone to extract or maybe find someplace it can be directly accessed unzipped?). The URL just needs to be a direct link to a file source. This allows it to work properly. Sending it to a site will attempt to download the current page if the page is served directly, meaning it can't be something like a site that hosts a download on a page and sends the file via request.

Also this took me around an hour to get properly working. It was a pain in the ass.

Boii1 avatar Jan 29 '20 18:01 Boii1

Cool idea, thanks for taking the time to write up that concept code. I'll probably consider adding an updater, since it seems like a neat idea (after sorting out the crashes, of course). I've been quite busy irl lately so I've put this project on the backburner, but I'm always willing to review pull requests or answer questions about the project.

Netdex avatar Jan 31 '20 03:01 Netdex