-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathreshade-installer.pl
executable file
·128 lines (106 loc) · 4.03 KB
/
reshade-installer.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/perl
use autodie;
use strict;
use warnings;
use File::Slurp;
use Archive::Zip;
use LWP::UserAgent;
use File::Spec;
use File::Path qw(make_path);
my $userAgent = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0});
$userAgent->agent("reshade-on-unix/0.1");
$userAgent->show_progress(1);
sub reShadeVersion {
my $req = HTTP::Request->new(GET => "https://api.github.com/repos/crosire/reshade/tags");
my $response = $userAgent->request($req);
$response->is_success or die $response->status_line;
my ($version) = $response->decoded_content =~ /v([\d.]+)/
or die "Could not extract version info";
return $version;
}
sub downloadFile {
my $url = $_[0];
my $file = $_[1];
my $req = HTTP::Request->new(GET => $url);
my $response = $userAgent->request($req, $file);
$response->is_success or die $response->status_line;
}
sub getGamePath {
if (defined $ARGV[0]) {
if (-d $ARGV[0]) {
return $ARGV[0]
}
else {
print "Supplied argument [${ARGV[0]}] is not a valid directory!\n"
}
}
if ($^O eq "darwin") {
my $xomGamePath = `defaults read dezent.XIV-on-Mac GamePath`;
chomp $xomGamePath;
$xomGamePath = $xomGamePath . "/game/";
if (-d $xomGamePath) {
return $xomGamePath;
}
}
print "Please enter the directory ReShade should be installed into: ";
my $path = <STDIN>;
chomp $path;
if (-d $path) {
return $path;
}
die "Provided path [${path}] is not a folder!";
}
my $gamePath = getGamePath;
my $shaderPath = File::Spec->catdir($gamePath, "reshade-shaders");
make_path($shaderPath) unless -d $shaderPath;
print "Installing ReShade into: [${gamePath}]\n";
my $reshadeSetup = $gamePath . "reshade_setup.exe";
downloadFile("https://reshade.me/downloads/ReShade_Setup_" . reShadeVersion() . "_Addon.exe", $reshadeSetup);
my $exeContent = read_file $reshadeSetup;
unlink $reshadeSetup;
my $magicBytes = pack "CC", 0x50, 0x4b, 0x03, 0x04;
my $zipOffset = index $exeContent, $magicBytes;
my $zipContent = substr $exeContent, $zipOffset;
my $reshadeZip = $gamePath . "reshade.zip";
write_file($reshadeZip, $zipContent);
my $zip = Archive::Zip->new($reshadeZip);
$zip->extractMember("ReShade64.dll", $gamePath . "dxgi.dll");
unlink $reshadeZip;
downloadFile("https://lutris.net/files/tools/dll/d3dcompiler_47.dll", $gamePath . "d3dcompiler_47.dll");
# Basic Shader URLs
my %shaders = (
"00" => "https://github.com/crosire/reshade-shaders/archive/slim.zip",
"01" => "https://github.com/CeeJayDK/SweetFX/archive/master.zip",
"02" => "https://github.com/crosire/reshade-shaders/archive/legacy.zip",
);
# Function to download and extract shaders into reshade-shaders directory
sub download_and_extract_shader {
my ($label, $url, $shader_dir) = @_;
my $zip_file = File::Spec->catfile($shader_dir, "$label.zip");
print "Downloading shader $label...\n";
downloadFile($url, $zip_file);
print "Extracting shader $label...\n";
my $zip = Archive::Zip->new($zip_file);
my $extracted_count = 0;
foreach my $member ($zip->members) {
my $extracted_name = $member->fileName;
next if $extracted_name =~ m{/$};
$extracted_name =~ s{^[^/]+/}{};
if ($extracted_name =~ m{^(Shaders|Textures)/(.+)$}) {
my $sub_dir = $1;
my $file_name = $2;
my $dest_dir = File::Spec->catdir($shader_dir, $sub_dir);
my $dest_path = File::Spec->catfile($dest_dir, $file_name);
make_path($dest_dir) unless -d $dest_dir;
$member->extractToFileNamed($dest_path);
$extracted_count++;
}
}
unlink $zip_file or warn "Could not delete $zip_file: $!\n";
print "Extracted $extracted_count files for shader $label\n";
}
# Loop through each shader and process it
foreach my $label (keys %shaders) {
download_and_extract_shader($label, $shaders{$label}, $shaderPath);
}
print "All shaders have been downloaded and extracted into 'reshade-shaders'.\n";