-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
312 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: Publish application | ||
on: | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
release: | ||
name: Release | ||
strategy: | ||
matrix: | ||
kind: ['windows'] | ||
include: | ||
- kind: windows | ||
os: windows-latest | ||
target: win-x64 | ||
|
||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup dotnet | ||
uses: actions/setup-dotnet@v1 | ||
with: | ||
dotnet-version: 6.0.x | ||
|
||
- name: Build | ||
shell: bash | ||
run: | | ||
# Define some variables for things we need | ||
tag=$(git describe --tags --abbrev=0) | ||
release_name="cf-java-gpu-fix-$tag" | ||
# Build everything | ||
dotnet publish cf-java-gpu-fix/cf-java-gpu-fix.csproj --runtime "${{ matrix.target }}" -c Release -o "$release_name" --self-contained | ||
# Pack files | ||
if [ "${{ matrix.target }}" == "win-x64" ]; then | ||
7z a -tzip "${release_name}.zip" "./${release_name}/*" | ||
else | ||
tar czvf "${release_name}.tar.gz" "$release_name" | ||
fi | ||
# Delete output directory | ||
rm -r "$release_name" | ||
- name: Publish | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
files: "cf-java-gpu-fix-*" | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: "CodeQL" | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
schedule: | ||
- cron: '31 3 * * 3' | ||
|
||
jobs: | ||
analyze: | ||
name: Analyze | ||
runs-on: ubuntu-latest | ||
permissions: | ||
actions: read | ||
contents: read | ||
security-events: write | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
language: [ 'csharp' ] | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Initialize CodeQL | ||
uses: github/codeql-action/init@v2 | ||
with: | ||
languages: ${{ matrix.language }} | ||
|
||
- name: Autobuild | ||
uses: github/codeql-action/autobuild@v2 | ||
|
||
|
||
- name: Perform CodeQL Analysis | ||
uses: github/codeql-action/analyze@v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: .NET Continuous Integration | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
build: | ||
name: Build GPU fixer | ||
strategy: | ||
matrix: | ||
kind: ['windows'] | ||
include: | ||
- kind: windows | ||
os: windows-latest | ||
target: win-x64 | ||
|
||
runs-on: ${{ matrix.os }} | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup dotnet | ||
uses: actions/setup-dotnet@v1 | ||
with: | ||
dotnet-version: 6.0.x | ||
|
||
- name: Restore dependencies | ||
run: dotnet restore | ||
|
||
- name: Build | ||
shell: bash | ||
run: | | ||
dotnet publish cf-java-gpu-fix/cf-java-gpu-fix.csproj --runtime "${{ matrix.target }}" -c Release -o published --self-contained |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.3.32611.2 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cf-java-gpu-fix", "cf-java-gpu-fix\cf-java-gpu-fix.csproj", "{DB6A9139-4DBA-4540-A679-64254252807B}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5A2FB001-3A27-4C77-B728-1B439EAFAE7B}" | ||
ProjectSection(SolutionItems) = preProject | ||
.github\workflows\app-release.yml = .github\workflows\app-release.yml | ||
.github\workflows\codeql-analysis.yml = .github\workflows\codeql-analysis.yml | ||
.github\workflows\dotnet-ci.yml = .github\workflows\dotnet-ci.yml | ||
EndProjectSection | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{DB6A9139-4DBA-4540-A679-64254252807B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{DB6A9139-4DBA-4540-A679-64254252807B}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{DB6A9139-4DBA-4540-A679-64254252807B}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{DB6A9139-4DBA-4540-A679-64254252807B}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {EA0CD6A5-03BF-4B80-A711-60A6130F54B2} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
using Microsoft.Win32; | ||
using System.Collections.Concurrent; | ||
using System.Security.Principal; | ||
|
||
Console.WriteLine("Hi! I will attempt to set so that your javaw.exe will use the GPU!"); | ||
|
||
const string GPURegKey = @"Software\Microsoft\DirectX\UserGpuPreferences"; | ||
|
||
var javaExecutables = new List<string>(); | ||
|
||
var winIdentity = new WindowsPrincipal(WindowsIdentity.GetCurrent()); | ||
|
||
if (!winIdentity.IsInRole(WindowsBuiltInRole.Administrator)) | ||
{ | ||
Console.WriteLine(); | ||
|
||
Console.WriteLine("Error: You need to run this program as an administrator"); | ||
Console.WriteLine("Right click me and use \"Run as administrator\""); | ||
|
||
Console.WriteLine(); | ||
|
||
Console.WriteLine("(I need it, since I'm gonna rewrite some stuff in your registry)"); | ||
|
||
Console.ReadLine(); | ||
|
||
return -1; | ||
} | ||
|
||
Console.WriteLine(); | ||
|
||
Console.WriteLine("[INFO] Checking for Overwolf/CurseForge registry keys"); | ||
var cfRegKey = Registry.CurrentUser.OpenSubKey(@"Software\Overwolf\CurseForge\"); | ||
if (cfRegKey != null) | ||
{ | ||
var cfMCRoot = cfRegKey.GetValue("minecraft_root") as string; | ||
|
||
if (!string.IsNullOrWhiteSpace(cfMCRoot)) | ||
{ | ||
Console.WriteLine($"[INFO] Found it! Modding path is: {cfMCRoot}"); | ||
var cfJavaExecutables = GetJavaExecutablesFromPath(cfMCRoot, "javaw.exe"); | ||
Console.WriteLine($"[INFO] Found {cfJavaExecutables.Count} executables, adding to list"); | ||
javaExecutables.AddRange(cfJavaExecutables.Select(j => j.FullName)); | ||
} | ||
} | ||
else | ||
{ | ||
Console.WriteLine("[INFO] Didn't find Overwolf/CurseForge.. anyhow.."); | ||
} | ||
|
||
Console.WriteLine(); | ||
|
||
if (javaExecutables.Count == 0) | ||
{ | ||
Console.WriteLine("[INFO] Well, this was awkward, we haven't found any \"important\" java executables."); | ||
Console.WriteLine("[INFO] So.. have a nice day!"); | ||
} | ||
else | ||
{ | ||
Console.WriteLine($"[INFO] Do you want to continue before setting things in the registry? Gonna write {javaExecutables.Count} new keys. [Y/N]"); | ||
var acceptedKeys = new[] { ConsoleKey.Y, ConsoleKey.N }; | ||
ConsoleKey key; | ||
do | ||
{ | ||
key = Console.ReadKey(true).Key; | ||
if (!acceptedKeys.Contains(key)) | ||
{ | ||
Console.WriteLine($"[ERROR] That was {key}, not Y or N, try again.."); | ||
} | ||
} while (!acceptedKeys.Contains(key)); | ||
|
||
if (key == ConsoleKey.N) | ||
{ | ||
Console.WriteLine("[INFO] Ok, exiting! Bye!"); | ||
return 0; | ||
} | ||
|
||
Console.WriteLine($"[INFO] Fixing {javaExecutables.Count} executables"); | ||
|
||
var gpuKey = Registry.CurrentUser.OpenSubKey(GPURegKey, true); | ||
if (gpuKey != null) | ||
{ | ||
foreach (var java in javaExecutables) | ||
{ | ||
Console.WriteLine($"[INFO] Fixing \"{java}\" for you!"); | ||
gpuKey.SetValue(java, "GpuPreference=2;"); | ||
} | ||
|
||
gpuKey.Close(); | ||
} | ||
|
||
Console.WriteLine("[INFO] All done! Happy playing!"); | ||
} | ||
|
||
Console.ReadLine(); | ||
|
||
return 0; | ||
|
||
ConcurrentStack<FileInfo> GetJavaExecutablesFromPath(string path, string searchPattern = "javaw.exe") | ||
{ | ||
string[] IgnoredFolders = new string[] { | ||
"\\$RECYCLE.BIN", | ||
"\\System Volume Information", | ||
"\\Recovery", | ||
"\\xtp", | ||
"\\Backups" | ||
}; | ||
|
||
var files = new ConcurrentStack<FileInfo>(); | ||
|
||
var rootFolderFiles = new DirectoryInfo(path).GetFiles(); | ||
|
||
foreach (var f in rootFolderFiles) | ||
{ | ||
files.Push(f); | ||
} | ||
|
||
var directories = Directory.GetDirectories(path).Where(d => !IgnoredFolders.Any(i => d.EndsWith(i))).ToList(); | ||
Parallel.ForEach(directories, dir => | ||
{ | ||
try | ||
{ | ||
var _files = new DirectoryInfo(dir).EnumerateFiles(searchPattern, SearchOption.AllDirectories).Where(d => !d.Attributes.HasFlag(FileAttributes.Directory)).ToArray(); | ||
if (_files.Length > 0) | ||
{ | ||
files.PushRange(_files); | ||
} | ||
} | ||
catch | ||
{ | ||
} | ||
}); | ||
|
||
return files; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<RootNamespace>cf_java_gpu_fix</RootNamespace> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<PublishSingleFile>true</PublishSingleFile> | ||
<PublishTrimmed>true</PublishTrimmed> | ||
<RuntimeIdentifier>win-x64</RuntimeIdentifier> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||
<DebugType>embedded</DebugType> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> | ||
<DebugType>embedded</DebugType> | ||
</PropertyGroup> | ||
|
||
</Project> |