-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.cpp
177 lines (155 loc) · 6.75 KB
/
main.cpp
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include "main.hpp"
#include "GlobalNamespace/MainMenuViewController.hpp"
#include "GlobalNamespace/AudioTimeSyncController.hpp"
#include "GlobalNamespace/SharedCoroutineStarter.hpp"
#include "GlobalNamespace/GamePause.hpp"
#include "UnityEngine/GameObject.hpp"
#include "UnityEngine/PrimitiveType.hpp"
#include "UnityEngine/Material.hpp"
#include "UnityEngine/Shader.hpp"
#include "UnityEngine/Transform.hpp"
#include "UnityEngine/Vector3.hpp"
#include "UnityEngine/Quaternion.hpp"
#include "UnityEngine/MeshRenderer.hpp"
#include "UnityEngine/Renderer.hpp"
#include "UnityEngine/Component.hpp"
#include "UnityEngine/Texture.hpp"
#include "UnityEngine/Video/VideoPlayer.hpp"
#include "UnityEngine/Video/VideoClip.hpp"
#include "UnityEngine/Video/VideoRenderMode.hpp"
#include "UnityEngine/Video/VideoPlayer_EventHandler.hpp"
#include "UnityEngine/Resources.hpp"
#include "UnityEngine/WaitForSeconds.hpp"
#include "UnityEngine/MonoBehaviour.hpp"
#include "UnityEngine/AudioSource.hpp"
#include "UI/VideoMenuViewController.hpp"
#include "questui/shared/QuestUI.hpp"
#include "questui/shared/CustomTypes/Components/MainThreadScheduler.hpp"
#include "questui/shared/ArrayUtil.hpp"
#include "VideoPlayer.hpp"
#include "custom-types/shared/coroutine.hpp"
using namespace UnityEngine;
using namespace GlobalNamespace;
static ModInfo modInfo; // Stores the ID and version of our mod, and is sent to the modloader upon startup
// Loads the config from disk using our modInfo, then returns it for use
Configuration& getConfig() {
static Configuration config(modInfo);
return config;
}
// Returns a logger, useful for printing debug messages
Logger& getLogger() {
static Logger* logger = new Logger(modInfo);
return *logger;
}
// Called at the early stages of game loading
extern "C" void setup(ModInfo& info) {
info.id = ID;
info.version = VERSION;
modInfo = info;
getConfig().Load(); // Load the config file
getLogger().info("Completed setup!");
}
custom_types::Helpers::Coroutine coroutine(Cinema::VideoPlayer* videoPlayer, AudioSource* audioSource) {
while(!audioSource->get_isPlaying()) co_yield nullptr;
videoPlayer->set_time(-2040);
videoPlayer->Play();
co_return;
}
Cinema::VideoPlayer* videoPlayer = nullptr;
MAKE_HOOK_MATCH(GamePause_Resume, &GlobalNamespace::GamePause::Resume, void, GamePause* self) {
GamePause_Resume(self);
if(videoPlayer)
videoPlayer->Play();
getLogger().info("resume");
}
MAKE_HOOK_MATCH(GamePause_Pause, &GamePause::Pause, void, GamePause* self) {
GamePause_Pause(self);
if(videoPlayer) {
videoPlayer->Pause();
getLogger().info("pause");
}
}
MAKE_HOOK_MATCH(SetupSongUI, &GlobalNamespace::AudioTimeSyncController::StartSong, void, GlobalNamespace::AudioTimeSyncController* self, float startTimeOffset) {
SetupSongUI(self, startTimeOffset);
GameObject* Mesh = GameObject::CreatePrimitive(PrimitiveType::Plane);
auto material = QuestUI::ArrayUtil::Last(Resources::FindObjectsOfTypeAll<Material*>(), [](Material* x) {
return x->get_name() == "PyroVideo (Instance)";
});
if(material)
Mesh->GetComponent<Renderer*>()->set_material(material);
else
Mesh->GetComponent<Renderer*>()->set_material(Material::New_ctor(Shader::Find(il2cpp_utils::newcsstr("Unlit/Texture"))));
Mesh->get_transform()->set_position(Vector3{0.0f, 12.4f, 67.8f});
Mesh->get_transform()->set_rotation(Quaternion::Euler(90.0f, 270.0f, 90.0f));
Mesh->get_transform()->set_localScale(Vector3(5.11, 1, 3));
auto cinemaScreen = Mesh->GetComponent<Renderer*>();
videoPlayer = Mesh->AddComponent<Cinema::VideoPlayer*>();
videoPlayer->set_isLooping(true);
videoPlayer->set_playOnAwake(false);
videoPlayer->set_renderMode(Video::VideoRenderMode::MaterialOverride);
videoPlayer->set_audioOutputMode(Video::VideoAudioOutputMode::None);
videoPlayer->set_aspectRatio(Video::VideoAspectRatio::FitInside);
if(cinemaScreen)
videoPlayer->set_renderer(cinemaScreen);
videoPlayer->set_url("/sdcard/EaswWiwMVs8.mp4");
videoPlayer->Prepare();
GlobalNamespace::SharedCoroutineStarter::get_instance()->StartCoroutine(custom_types::Helpers::CoroutineHelper::New(coroutine(videoPlayer, self->audioSource)));
}
#include "pythonlib/shared/Python.hpp"
#include "pythonlib/shared/Utils/FileUtils.hpp"
#include "pythonlib/shared/Utils/StringUtils.hpp"
#include "assets.hpp"
bool DownloadVideo(std::string_view url, std::function<void(float)> status = nullptr) {
bool error = false;
std::function<void(int, char*)> eventHandler = [status, &error](int type, char* data) {
switch (type) {
case 0:
{
std::string dataString(data);
if(dataString.find("[download]", 0) != -1) {
auto pos = dataString.find("%", 0);
if(pos != -1 && pos > 5) {
auto percentange = dataString.substr(pos-5, 5);
if(percentange.find("]", 0) == 0)
percentange = percentange.substr(1);
status(std::stof(percentange));
}
}
}
break;
case 1:
error = true;
getLogger().info("Error: %s", data);
break;
}
};
Python::PythonWriteEvent += eventHandler;
std::string ytdlp = FileUtils::getScriptsPath() + "/yt_dlp";
if(!direxists(ytdlp))
FileUtils::ExtractZip(IncludedAssets::ytdlp_zip, ytdlp);
Python::PyRun_SimpleString("from yt_dlp.__init__ import _real_main");
std::string command = "_real_main([";
for(auto splitted : StringUtils::Split("--no-cache-dir -o %(id)s.%(ext)s -P /sdcard " + url, " ")) {
command += "\"" + splitted + "\",";
}
command = command.substr(0, command.length()-1) + "])";
int result = Python::PyRun_SimpleString(command.c_str());
Python::PythonWriteEvent -= eventHandler;
return !error;
}
// Called later on in the game loading - a good time to install function hooks
extern "C" void load() {
il2cpp_functions::Init();
//INSTALL_HOOK(getLogger(), MainMenu);
INSTALL_HOOK(getLogger(), SetupSongUI);
INSTALL_HOOK(getLogger(), GamePause_Resume);
INSTALL_HOOK(getLogger(), GamePause_Pause);
QuestUI::Register::RegisterGameplaySetupMenu<Cinema::VideoMenuViewController*>(modInfo, "Cinema", QuestUI::Register::MenuType::Solo);
custom_types::Register::AutoRegister();
getLogger().info("DownloadVideo Result: %d", DownloadVideo("https://youtu.be/SnP0Nqp455I", [](float percentage) {
getLogger().info("Download: %f", percentage);
}));
getLogger().info("DownloadVideo Result: %d", DownloadVideo("https://youtu.be/EaswWiwMVs8", [](float percentage) {
getLogger().info("Download: %f", percentage);
}));
}