Skip to content

Commit

Permalink
better async modes and renderer test
Browse files Browse the repository at this point in the history
  • Loading branch information
ate47 committed Sep 28, 2024
1 parent 0716c9f commit 23676a7
Show file tree
Hide file tree
Showing 25 changed files with 3,000 additions and 389 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@
[submodule "deps/thread-pool"]
path = deps/thread-pool
url = https://github.com/bshoshany/thread-pool
[submodule "deps/stb"]
path = deps/stb
url = https://github.com/nothings/stb
1 change: 1 addition & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This software depends on libraries with a different License.
- [Tencent/rapidjson](https://github.com/Tencent/rapidjson) - [MIT and JSON license](https://github.com/Tencent/rapidjson/blob/master/license.txt)
- [glfw/glfw](https://github.com/glfw/glfw) - [zlib/libpng license](https://github.com/glfw/glfw/blob/master/LICENSE.md)
- [bshoshany/thread-pool](https://github.com/bshoshany/thread-pool) - [MIT license](https://github.com/bshoshany/thread-pool/blob/master/LICENSE.txt)
- [nothings/stb](https://github.com/nothings/stb) - [MIT license](https://github.com/nothings/stb/blob/master/LICENSE)


# MIT License
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ This tool is using and providing
- [Tencent/rapidjson](https://github.com/Tencent/rapidjson) - [MIT and JSON license](https://github.com/Tencent/rapidjson/blob/master/license.txt)
- [glfw/glfw](https://github.com/glfw/glfw) - [zlib/libpng license](https://github.com/glfw/glfw/blob/master/LICENSE.md)
- [bshoshany/thread-pool](https://github.com/bshoshany/thread-pool) - [MIT license](https://github.com/bshoshany/thread-pool/blob/master/LICENSE.txt)
- [nothings/stb](https://github.com/nothings/stb) - [MIT license](https://github.com/nothings/stb/blob/master/LICENSE)

## Downloads

Expand Down
1 change: 1 addition & 0 deletions deps/stb
Submodule stb added at f75e8d
3 changes: 2 additions & 1 deletion premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ project "AtianCodTools"
"deps/hw_break/HwBpLib/inc/",
"deps/glfw/include/",
"deps/imgui/",
"deps/thread-pool/include/"
"deps/thread-pool/include/",
"deps/stb/"
}

vpaths {
Expand Down
1 change: 1 addition & 0 deletions scripts/package.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ try {
Copy-Item "deps/curl/COPYING" "$base/licenses/curl.txt" > $null
Copy-Item "deps/glfw/LICENSE.md" "$base/licenses/glfw.md" > $null
Copy-Item "deps/thread-pool/LICENSE.txt" "$base/licenses/thread-pool.txt" > $null
Copy-Item "deps/stb/LICENSE" "$base/licenses/stb.txt" > $null

# Compress
Compress-Archive -LiteralPath "$base" -DestinationPath "$base.zip" > $null
Expand Down
4 changes: 2 additions & 2 deletions src/acts/hashutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ namespace {
}

namespace hashutils {
static std::mutex* GetMutex(bool forceAsync) {
if (forceAsync || !core::async::IsAsync()) {
std::mutex* GetMutex(bool forceAsync) {
if (forceAsync || !core::async::IsSync(core::async::AT_HASHES)) {
return nullptr;
}
return &asyncMutex;
Expand Down
7 changes: 7 additions & 0 deletions src/acts/hashutils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
namespace hashutils {
constexpr auto DEFAULT_HASH_FILE = "strings.txt";

/*
* Get hash mutex
* @param async run async
* @return mutex or nullptr
*/
std::mutex* GetMutex(bool async);

/*
* Get hash map
*/
Expand Down
78 changes: 49 additions & 29 deletions src/acts/tools/gsc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,6 @@ int GSCOBJHandler::PatchCode(T8GSCOBJContext& ctx) {
if (gDumpStrings) {
gDumpStringsStore.insert(cstr);
}
hashutils::Add(cstr, false, false);
hashutils::Add(cstr, false, true);
uint32_t ref = ctx.AddStringValue(cstr);

const auto* strings = reinterpret_cast<const uint32_t*>(&str[1]);
Expand Down Expand Up @@ -521,8 +519,6 @@ int GSCOBJHandler::PatchCode(T8GSCOBJContext& ctx) {
auto* s1 = DecryptString(Ptr<char>(animt->address_str1));
auto* s2 = DecryptString(Ptr<char>(animt->address_str2));

hashutils::Add(s1, true, true);
hashutils::Add(s2, true, true);
uint32_t ref1 = ctx.AddStringValue(s1);
uint32_t ref2 = ctx.AddStringValue(s2);

Expand Down Expand Up @@ -682,7 +678,6 @@ int GSCOBJHandler::PatchCode(T8GSCOBJContext& ctx) {

auto* s1 = Ptr<char>(animt->name);

hashutils::Add(s1, true, true);
uint32_t ref1 = ctx.AddStringValue(s1);

const uint32_t* vars = reinterpret_cast<const uint32_t*>(&animt[1]);
Expand Down Expand Up @@ -1037,29 +1032,31 @@ int GscInfoHandleData(byte* data, size_t size, const char* path, GscDecompilerGl
uint64_t hashField{ vmInfo->HashField(str) };
uint64_t hashFilePath{ vmInfo->HashFilePath(str) };
uint64_t hashPath{ vmInfo->HashPath(str) };

hashutils::AddPrecomputed(hashField, str);
hashutils::AddPrecomputed(hashFilePath, str);
hashutils::AddPrecomputed(hashPath, str);

if (opt.m_header) {
PrintFormattedString(actsHeader << "// - #\"", str)
<< "\" (0x" << std::hex << hashField << "/0x" << hashFilePath << "/0x" << hashPath;
}
// use all the known hashes for this VM
for (auto& [k, func] : vmInfo->hashesFunc) {
try {
int64_t hash = func.hashFunc(str);

if (hash) {
if (opt.m_header) {
actsHeader << "/" << k << '=' << std::hex << hash;
{
core::async::opt_lock_guard hlg{ hashutils::GetMutex(false) };
hashutils::AddPrecomputed(hashField, str, true);
hashutils::AddPrecomputed(hashFilePath, str, true);
hashutils::AddPrecomputed(hashPath, str, true);

if (opt.m_header) {
PrintFormattedString(actsHeader << "// - #\"", str)
<< "\" (0x" << std::hex << hashField << "/0x" << hashFilePath << "/0x" << hashPath;
}
// use all the known hashes for this VM
for (auto& [k, func] : vmInfo->hashesFunc) {
try {
int64_t hash = func.hashFunc(str);

if (hash) {
if (opt.m_header) {
actsHeader << "/" << k << '=' << std::hex << hash;
}
hashutils::AddPrecomputed(hash, str, true);
}
hashutils::AddPrecomputed(hash, str);
}
}
catch (std::exception&) {
// ignore
catch (std::exception&) {
// ignore
}
}
}
if (opt.m_header) {
Expand Down Expand Up @@ -1410,6 +1407,29 @@ int GscInfoHandleData(byte* data, size_t size, const char* path, GscDecompilerGl
actslib::profiler::ProfiledSection ps{ profiler, "patch linking"};
// unlink the script and write custom gvar/string ids
patchCodeResult = scriptfile->PatchCode(ctx);

{
core::async::opt_lock_guard hlg{ hashutils::GetMutex(false) };
for (const auto& [id, str] : ctx.m_stringRefs) {
hashutils::AddPrecomputed(vmInfo->HashField(str), str, true);
hashutils::AddPrecomputed(vmInfo->HashFilePath(str), str, true);
hashutils::AddPrecomputed(vmInfo->HashPath(str), str, true);

// use all the known hashes for this VM
for (auto& [k, func] : vmInfo->hashesFunc) {
try {
int64_t hash = func.hashFunc(str);

if (hash) {
hashutils::AddPrecomputed(hash, str, true);
}
}
catch (std::exception&) {
// ignore
}
}
}
}
}

if (opt.m_includes && scriptfile->GetIncludesOffset()) {
Expand Down Expand Up @@ -3153,8 +3173,8 @@ int tool::gsc::gscinfo(Process& proc, int argc, const char* argv[]) {
}
else {
LOG_WARNING("Using experimental async mode");
bool wasAsync = core::async::IsAsync();
core::async::SetAsync(true);
uint64_t prevAsyncTypes = core::async::GetAsyncTypes();
core::async::SetAsync(core::async::AT_ALL);

std::mutex mtx{};
gdctx.asyncMtx = &mtx;
Expand Down Expand Up @@ -3189,7 +3209,7 @@ int tool::gsc::gscinfo(Process& proc, int argc, const char* argv[]) {

pool.wait();

core::async::SetAsync(wasAsync);
core::async::SetAsync(prevAsyncTypes);
}

LOG_INFO("{} (0x{:x}) file(s) decompiled.", gdctx.decompiledFiles, gdctx.decompiledFiles);
Expand Down
4 changes: 2 additions & 2 deletions src/acts/tools/gsc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -743,10 +743,10 @@ namespace tool::gsc {
// Result context for T8GSCOBJ::PatchCode
class T8GSCOBJContext {
private:
std::unordered_map<uint16_t, uint64_t> m_gvars{};
std::unordered_map<uint32_t, const char*> m_stringRefs{};
std::vector<char*> m_allocatedStrings{};
public:
std::unordered_map<uint16_t, uint64_t> m_gvars{};
std::unordered_map<uint32_t, const char*> m_stringRefs{};
std::vector<IW23GSCImport> m_linkedImports{};
// getnumber hack
std::unordered_map<uint32_t, uint32_t> m_animTreeLocations{};
Expand Down
26 changes: 26 additions & 0 deletions src/acts/tools/nui/cascadia.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <includes.hpp>

/*
https://github.com/microsoft/cascadia-code
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
xxd -i .\cascadia_mono_semibold_12.PNG > cascadia_atlas.hpp
xxd -i .\cascadia_mono_semibold_12.json > cascadia_map.hpp
*/

#include "cascadia_atlas.hpp"
#include "cascadia_map.hpp"

namespace tool::nui::cascadia {
void* GetCascadiaFont() {
return __cascadia_mono_semibold_12_PNG;
}
size_t GetCascadiaFontLen() {
return __cascadia_mono_semibold_12_PNG_len;
}
void* GetCascadiaMap() {
return __cascadia_mono_semibold_12_json;
}
size_t GetCascadiaMapLen() {
return __cascadia_mono_semibold_12_json_len;
}
}
8 changes: 8 additions & 0 deletions src/acts/tools/nui/cascadia.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

namespace tool::nui::cascadia {
void* GetCascadiaFont();
size_t GetCascadiaFontLen();
void* GetCascadiaMap();
size_t GetCascadiaMapLen();
}
Loading

0 comments on commit 23676a7

Please sign in to comment.