Skip to content

Commit e34dfed

Browse files
committed
1 parent 7218415 commit e34dfed

5 files changed

Lines changed: 274 additions & 1 deletion

File tree

assets/ParametricBoxFrameHD.shader

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#version 300 es
2+
#ifndef UNITY_RUNTIME_INSTANCING_ARRAY_SIZE
3+
#define UNITY_RUNTIME_INSTANCING_ARRAY_SIZE 2
4+
#endif
5+
precision highp float;
6+
precision highp int;
7+
#define HLSLCC_ENABLE_UNIFORM_BUFFERS 1
8+
#if HLSLCC_ENABLE_UNIFORM_BUFFERS
9+
#define UNITY_UNIFORM
10+
#else
11+
#define UNITY_UNIFORM uniform
12+
#endif
13+
#define UNITY_SUPPORTS_UNIFORM_LOCATION 1
14+
#if UNITY_SUPPORTS_UNIFORM_LOCATION
15+
#define UNITY_LOCATION(x) layout(location = x)
16+
#define UNITY_BINDING(x) layout(binding = x, std140)
17+
#else
18+
#define UNITY_LOCATION(x)
19+
#define UNITY_BINDING(x) layout(std140)
20+
#endif
21+
uniform int unity_BaseInstanceID;
22+
uniform mediump float _CustomFogAttenuation;
23+
uniform mediump float _CustomFogOffset;
24+
uniform mediump float _CustomFogHeightFogStartY;
25+
uniform mediump float _CustomFogHeightFogHeight;
26+
uniform mediump float _BaseColorBoost;
27+
uniform mediump float _BaseColorBoostThreshold;
28+
uniform float _FogStartOffset;
29+
uniform float _FogScale;
30+
uniform mediump float _FogHeightScale;
31+
uniform mediump float _FogHeightOffset;
32+
uniform float _CutoutTexScale;
33+
#if HLSLCC_ENABLE_UNIFORM_BUFFERS
34+
UNITY_BINDING(0) uniform UnityStereoGlobals {
35+
#endif
36+
UNITY_UNIFORM vec4 Xhlslcc_UnusedXhlslcc_mtx4x4unity_StereoMatrixP[8];
37+
UNITY_UNIFORM vec4 Xhlslcc_UnusedXhlslcc_mtx4x4unity_StereoMatrixV[8];
38+
UNITY_UNIFORM vec4 Xhlslcc_UnusedXhlslcc_mtx4x4unity_StereoMatrixInvV[8];
39+
UNITY_UNIFORM vec4 hlslcc_mtx4x4unity_StereoMatrixVP[8];
40+
UNITY_UNIFORM vec4 Xhlslcc_UnusedXhlslcc_mtx4x4unity_StereoCameraProjection[8];
41+
UNITY_UNIFORM vec4 Xhlslcc_UnusedXhlslcc_mtx4x4unity_StereoCameraInvProjection[8];
42+
UNITY_UNIFORM vec4 Xhlslcc_UnusedXhlslcc_mtx4x4unity_StereoWorldToCamera[8];
43+
UNITY_UNIFORM vec4 Xhlslcc_UnusedXhlslcc_mtx4x4unity_StereoCameraToWorld[8];
44+
UNITY_UNIFORM vec3 unity_StereoWorldSpaceCameraPos[2];
45+
UNITY_UNIFORM vec4 Xhlslcc_UnusedXunity_StereoScaleOffset[2];
46+
#if HLSLCC_ENABLE_UNIFORM_BUFFERS
47+
};
48+
#endif
49+
struct unity_Builtins0Array_Type {
50+
vec4 hlslcc_mtx4x4unity_ObjectToWorldArray[4];
51+
vec4 hlslcc_mtx4x4unity_WorldToObjectArray[4];
52+
};
53+
#if HLSLCC_ENABLE_UNIFORM_BUFFERS
54+
UNITY_BINDING(1) uniform UnityInstancing_PerDraw0 {
55+
#endif
56+
UNITY_UNIFORM unity_Builtins0Array_Type unity_Builtins0Array[128];
57+
#if HLSLCC_ENABLE_UNIFORM_BUFFERS
58+
};
59+
#endif
60+
struct PropsArray_Type {
61+
mediump vec4 _Color;
62+
mediump vec4 _SizeParams;
63+
float _Cutout;
64+
vec4 _CutoutTexOffset;
65+
};
66+
#if HLSLCC_ENABLE_UNIFORM_BUFFERS
67+
UNITY_BINDING(2) uniform UnityInstancing_Props {
68+
#endif
69+
UNITY_UNIFORM PropsArray_Type PropsArray[128];
70+
#if HLSLCC_ENABLE_UNIFORM_BUFFERS
71+
};
72+
#endif
73+
UNITY_LOCATION(0) uniform mediump sampler3D _CutoutTex;
74+
UNITY_LOCATION(1) uniform mediump sampler2D _BloomPrePassTexture;
75+
in highp vec3 vs_TEXCOORD1;
76+
in mediump vec4 vs_TEXCOORD2;
77+
flat in highp uint vs_SV_InstanceID0;
78+
layout(location = 0) out mediump vec4 SV_Target0;
79+
float u_xlat0;
80+
ivec2 u_xlati0;
81+
mediump float u_xlat16_1;
82+
mediump float u_xlat16_2;
83+
vec3 u_xlat3;
84+
mediump vec3 u_xlat16_3;
85+
bool u_xlatb3;
86+
mediump vec3 u_xlat16_4;
87+
mediump float u_xlat16_7;
88+
void main()
89+
{
90+
u_xlati0.x = int(vs_SV_InstanceID0) + unity_BaseInstanceID;
91+
u_xlati0.xy = ivec2(u_xlati0.x << (int(2) & int(0x1F)), u_xlati0.x << (int(3) & int(0x1F)));
92+
u_xlat3.xyz = vs_TEXCOORD1.xyz + (-unity_Builtins0Array[u_xlati0.y / 8].hlslcc_mtx4x4unity_ObjectToWorldArray[3].xyz);
93+
u_xlat3.xyz = u_xlat3.xyz + PropsArray[u_xlati0.x / 4]._CutoutTexOffset.xyz;
94+
u_xlat3.xyz = u_xlat3.xyz * vec3(_CutoutTexScale);
95+
u_xlat16_3.x = texture(_CutoutTex, u_xlat3.xyz).w;
96+
u_xlat3.x = (-PropsArray[u_xlati0.x / 4]._Cutout) * 1.10000002 + u_xlat16_3.x;
97+
u_xlat3.x = u_xlat3.x + 0.100000001;
98+
u_xlatb3 = u_xlat3.x<0.0;
99+
if(u_xlatb3){discard;}
100+
u_xlat3.xyz = vs_TEXCOORD1.xyz + (-unity_StereoWorldSpaceCameraPos[0].xyz);
101+
u_xlat3.x = dot(u_xlat3.xyz, u_xlat3.xyz);
102+
u_xlat16_1 = u_xlat3.x + (-_FogStartOffset);
103+
u_xlat16_1 = max(u_xlat16_1, 0.0);
104+
u_xlat16_1 = u_xlat16_1 * _FogScale + (-_CustomFogOffset);
105+
u_xlat16_1 = max(u_xlat16_1, 0.0);
106+
u_xlat16_1 = u_xlat16_1 * _CustomFogAttenuation + 1.0;
107+
u_xlat16_1 = float(1.0) / u_xlat16_1;
108+
u_xlat3.x = vs_TEXCOORD1.y * _FogHeightScale + _FogHeightOffset;
109+
u_xlat16_4.x = _CustomFogHeightFogHeight + _CustomFogHeightFogStartY;
110+
u_xlat16_4.x = u_xlat3.x + (-u_xlat16_4.x);
111+
u_xlat16_4.x = u_xlat16_4.x / _CustomFogHeightFogHeight;
112+
u_xlat16_4.x = clamp(u_xlat16_4.x, 0.0, 1.0);
113+
u_xlat16_7 = u_xlat16_4.x * u_xlat16_4.x;
114+
u_xlat16_4.x = (-u_xlat16_4.x) * 2.0 + 3.0;
115+
u_xlat16_4.x = u_xlat16_4.x * u_xlat16_7;
116+
u_xlat16_1 = u_xlat16_4.x * (-u_xlat16_1) + 1.0;
117+
u_xlat16_4.xy = vs_TEXCOORD2.xy / vs_TEXCOORD2.ww;
118+
u_xlat16_3.xyz = texture(_BloomPrePassTexture, u_xlat16_4.xy).xyz;
119+
u_xlat16_4.xyz = u_xlat16_3.xyz + (-PropsArray[u_xlati0.x / 4]._Color.xyz);
120+
SV_Target0.xyz = vec3(u_xlat16_1) * u_xlat16_4.xyz + PropsArray[u_xlati0.x / 4]._Color.xyz;
121+
u_xlat0 = PropsArray[u_xlati0.x / 4]._Color.w + PropsArray[u_xlati0.x / 4]._Color.w;
122+
SV_Target0.w = u_xlat16_1 * (-u_xlat0) + u_xlat0;
123+
return;
124+
}

assets/SaberBlade.shader

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#version 320 es
2+
#ifndef UNITY_RUNTIME_INSTANCING_ARRAY_SIZE
3+
#define UNITY_RUNTIME_INSTANCING_ARRAY_SIZE 2
4+
#endif
5+
6+
precision highp float;
7+
precision highp int;
8+
#define HLSLCC_ENABLE_UNIFORM_BUFFERS 1
9+
#if HLSLCC_ENABLE_UNIFORM_BUFFERS
10+
#define UNITY_UNIFORM
11+
#else
12+
#define UNITY_UNIFORM uniform
13+
#endif
14+
#define UNITY_SUPPORTS_UNIFORM_LOCATION 1
15+
#if UNITY_SUPPORTS_UNIFORM_LOCATION
16+
#define UNITY_LOCATION(x) layout(location = x)
17+
#define UNITY_BINDING(x) layout(binding = x, std140)
18+
#else
19+
#define UNITY_LOCATION(x)
20+
#define UNITY_BINDING(x) layout(std140)
21+
#endif
22+
uniform vec4 _Time;
23+
uniform int unity_BaseInstanceID;
24+
uniform vec4 _MainTex_ST;
25+
uniform mediump vec2 _MainTexSpeed;
26+
uniform mediump float _Brightness;
27+
uniform vec4 _TimeHelperOffset;
28+
struct PropsArray_Type {
29+
mediump vec4 _TintColor;
30+
};
31+
#if HLSLCC_ENABLE_UNIFORM_BUFFERS
32+
UNITY_BINDING(0) uniform UnityInstancing_Props {
33+
#endif
34+
UNITY_UNIFORM PropsArray_Type PropsArray[128];
35+
#if HLSLCC_ENABLE_UNIFORM_BUFFERS
36+
};
37+
#endif
38+
UNITY_LOCATION(0) uniform mediump sampler2D _MainTex;
39+
in highp vec2 vs_TEXCOORD0;
40+
in highp float vs_TEXCOORD1;
41+
flat in highp uint vs_SV_InstanceID0;
42+
layout(location = 0) out mediump vec4 SV_Target0;
43+
vec4 u_xlat0;
44+
mediump float u_xlat16_0;
45+
mediump vec4 u_xlat16_1;
46+
vec4 u_xlat2;
47+
float u_xlat3;
48+
vec2 u_xlat6;
49+
int u_xlati6;
50+
void main()
51+
{
52+
u_xlat0.x = _Time.x + _TimeHelperOffset.x;
53+
u_xlat0.xy = u_xlat0.xx * _MainTexSpeed.xy;
54+
u_xlat6.xy = vs_TEXCOORD0.xy * _MainTex_ST.xy + _MainTex_ST.zw;
55+
u_xlat0.xy = u_xlat0.xy * _MainTex_ST.xy + u_xlat6.xy;
56+
u_xlat16_0 = texture(_MainTex, u_xlat0.xy).x;
57+
u_xlat3 = u_xlat16_0 * _Brightness + vs_TEXCOORD1;
58+
u_xlati6 = int(vs_SV_InstanceID0) + unity_BaseInstanceID;
59+
u_xlat16_1.xyz = vec3(u_xlat16_0) * vec3(vec3(_Brightness, _Brightness, _Brightness)) + PropsArray[u_xlati6]._TintColor.xyz;
60+
u_xlat16_1.xyz = clamp(u_xlat16_1.xyz, 0.0, 1.0);
61+
u_xlat16_1.w = 0.0;
62+
u_xlat16_1.w = clamp(u_xlat16_1.w, 0.0, 1.0);
63+
u_xlat2 = (-u_xlat16_1) + PropsArray[u_xlati6]._TintColor;
64+
u_xlat0 = vec4(u_xlat3) * u_xlat2 + u_xlat16_1;
65+
SV_Target0 = u_xlat0;
66+
return;
67+
}

include/assets.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include "kaleb/shared/kaleb.hpp"
33

44
DECLARE_FILE(_binary_AdvancedSettingsView_bsml, Assets, AdvancedSettingsView_bsml);
5+
DECLARE_FILE(_binary_ParametricBoxFrameHD_shader, Assets, ParametricBoxFrameHD_shader);
56
DECLARE_FILE(_binary_PresetsView_bsml, Assets, PresetsView_bsml);
7+
DECLARE_FILE(_binary_SaberBlade_shader, Assets, SaberBlade_shader);
68
DECLARE_FILE(_binary_SettingsView_bsml, Assets, SettingsView_bsml);
79
DECLARE_FILE(_binary_fpscounter_bund, Assets, fpscounter_bund);

include/basic_string.hpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#pragma once
2+
3+
#include <cstdint>
4+
5+
struct StackAllocated {
6+
char data[31];
7+
char flags;
8+
};
9+
10+
struct HeapAllocated {
11+
public:
12+
const char* data; // 0x0
13+
__int64_t capacity; // 0x8
14+
__int64_t size; // 0x10
15+
char padding[7]; // padding
16+
char flags; // 31
17+
};
18+
19+
namespace core
20+
{
21+
class basic_string
22+
{
23+
public:
24+
basic_string() = default;
25+
26+
union
27+
{
28+
StackAllocated embedded;
29+
HeapAllocated heap;
30+
};
31+
32+
char const* c_str() const {
33+
if (this->heap.flags < 0x40) {
34+
return this->embedded.data;
35+
}
36+
37+
return this->heap.data;
38+
}
39+
};
40+
}

src/main.cpp

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@
4848
#include "BeatSaber/Settings/QualitySettings.hpp"
4949
#include "GraphicsTweaksConfig.hpp"
5050
#include "FPSCounter.hpp"
51-
51+
#include "basic_string.hpp"
5252
#include "UnityEngine/Graphics.hpp"
5353
#include "PlatformDetector.hpp"
5454
#include "Utils.hpp"
55+
#include "assets.hpp"
5556

5657
inline modloader::ModInfo modInfo = {
5758
MOD_ID, VERSION, GIT_COMMIT}; // Stores the ID and version of our mod, and
@@ -416,9 +417,48 @@ MAKE_HOOK_MATCH(MainFlowCoordinator_DidActivate,
416417
}
417418
}
418419

420+
// TODO: Make more supportable
421+
MAKE_HOOK(hCompileProgramImpl, nullptr, void,
422+
unsigned int& unknown,
423+
core::basic_string const& shaderName,
424+
core::basic_string const* vertex,
425+
core::basic_string& fragment,
426+
core::basic_string const& geometry,
427+
core::basic_string const& hull,
428+
core::basic_string const& domain,
429+
int& shader, int a, int * b, int *c, int* d) {
430+
431+
auto shaderName_c = shaderName.c_str();
432+
// TODO: Figure out how to fix for mirror?
433+
if (strcmp(shaderName_c, "Custom/ParametricBoxFrameHD") == 0 && fragment.heap.size > 5400 && fragment.heap.size < 5500) {
434+
DEBUG("Patching ParametricBoxFrameHD shader");
435+
memcpy((void*)fragment.heap.data, Assets::ParametricBoxFrameHD_shader.dataStart, Assets::ParametricBoxFrameHD_shader.data_length);
436+
fragment.heap.size = Assets::ParametricBoxFrameHD_shader.data_length;
437+
}
438+
439+
// Vertex and Fragment check to make sure it only changes for the player and not mirror
440+
if (strcmp(shaderName_c, "Custom/SaberBlade") == 0 && fragment.heap.size == 2188 && vertex->heap.size == 5265) {
441+
DEBUG("Patching SaberBlade shader");
442+
memcpy((void*)fragment.heap.data, Assets::SaberBlade_shader.dataStart, Assets::SaberBlade_shader.data_length);
443+
fragment.heap.size = Assets::SaberBlade_shader.data_length;
444+
}
445+
446+
hCompileProgramImpl(unknown, shaderName, vertex, fragment, geometry, hull, domain, shader, a, b, c, d);
447+
}
448+
419449
// Called later on in the game loading - a good time to install function hooks
420450
GT_EXPORT_FUNC void load() {
421451
INFO("Loading GraphicsTweaks...");
452+
// TODO: Document how to get this address for the newer versions of unity
453+
// Scary direct offset hook
454+
void* jniOnUnload = dlsym(modloader_unity_handle, "JNI_OnUnload");
455+
// GlslGpuProgramGLES::CompileProgramImpl
456+
if (auto const CompileProgramImpl = static_cast<char*>(jniOnUnload) + 0x6E8EE0) {
457+
DEBUG("Found CompileProgramImpl at offset 0x6E8EE0");
458+
INSTALL_HOOK_DIRECT(Logger, hCompileProgramImpl, CompileProgramImpl);
459+
}
460+
461+
DEBUG("Installed direct offset hooks!");
422462
il2cpp_functions::Init();
423463
custom_types::Register::AutoRegister();
424464
BSML::Init();

0 commit comments

Comments
 (0)