Skip to content

Commit

Permalink
decomp drawable, main (#3434)
Browse files Browse the repository at this point in the history
  • Loading branch information
water111 authored Mar 24, 2024
1 parent ffe01a3 commit 9b4b549
Show file tree
Hide file tree
Showing 80 changed files with 12,118 additions and 200 deletions.
21 changes: 16 additions & 5 deletions decompiler/IR2/bitfields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -974,18 +974,29 @@ Form* cast_to_bitfield_enum(const EnumType* type_info,
if (in == -1) {
return nullptr;
}
auto elts = decompile_bitfield_enum_from_int(TypeSpec(type_info->get_name()), env.dts->ts, in);
TypeSpec ts(type_info->get_name());
auto elts = try_decompile_bitfield_enum_from_int(ts, env.dts->ts, in, no_head);
if (no_head) {
ASSERT(elts.size() >= 1);
ASSERT(elts->size() >= 1);
}

if (!elts) {
if (in == 0xffff'ffff || in == INT64_MIN) {
return pool.form<CastElement>(
ts, pool.form<SimpleAtomElement>(SimpleAtom::make_int_constant(in)));
}
// backup failed, run again to get the nice error print.
try_decompile_bitfield_enum_from_int(ts, env.dts->ts, in, true);
}

auto oper = GenericOperator::make_function(
pool.form<ConstantTokenElement>(no_head ? elts.at(0) : type_info->get_name()));
pool.form<ConstantTokenElement>(no_head ? elts->at(0) : type_info->get_name()));
if (no_head) {
elts.erase(elts.begin());
elts->erase(elts->begin());
}

std::vector<Form*> form_elts;
for (auto& x : elts) {
for (auto& x : *elts) {
form_elts.push_back(pool.form<ConstantTokenElement>(x));
}
return pool.form<GenericElement>(oper, form_elts);
Expand Down
260 changes: 138 additions & 122 deletions decompiler/config/jak3/all-types.gc

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,12 @@
],
"trajectory": [[15, "(function trajectory none)"]],
"progress": [[3, "(function int none :behavior process)"]],
"level": [[25, "(function level-group int symbol)"], [7, "(function none)"], [4, "(function load-state sound-bank-state symbol)"]]
"level": [[25, "(function level-group int symbol)"], [7, "(function none)"], [4, "(function load-state sound-bank-state symbol)"]],
"main": [
[11, "(function int none)"],
[9, "(function none)"],
[8, "(function none)"],
[7, "(function none)"],
[3, "(function symbol :behavior process)"]
]
}
6 changes: 5 additions & 1 deletion decompiler/config/jak3/ntsc_v1/hacks.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,11 @@
"draw-drawable-tree-instance-tie": [21, 23, 31, 33],
"(method 12 flow-control)": [3, 9, 22],
"(method 26 level-group)": [40, 41, 67],
"borrow-city-expansion": [0, 9, 13, 15, 17]
"borrow-city-expansion": [0, 9, 13, 15, 17],
"dma-add-process-drawable": [0, 77],
"real-main-draw-hook": [120, 122],
"display-frame-finish": [61],
"display-loop-main": [130]
},

// Sometimes the game might use format strings that are fetched dynamically,
Expand Down
7 changes: 6 additions & 1 deletion decompiler/config/jak3/ntsc_v1/stack_structures.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,11 @@
"(method 20 load-state)": [
[16, ["inline-array", "level-buffer-state", 10]],
[176, ["inline-array", "level-buffer-state", 10]]

],
"calc-vu1-lights": [
[16, "light-group"]
],
"teleport-camera-by-pos": [
[16, "vector"]
]
}
69 changes: 69 additions & 0 deletions decompiler/config/jak3/ntsc_v1/type_casts.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -2991,5 +2991,74 @@
"borrow-city-expansion": [
[23, "a0", "basic"],
[52, "s5", "basic"]
],
"find-instance-by-name-level": [
[11, "v1", "drawable-tree-instance-shrub"],
[38, "v1", "drawable-tree-instance-tie"]
],
"dma-add-process-drawable": [
[42, "a0", "foreground-work"],
[45, "a0", "foreground-work"],
[78, "a0", "foreground-work"],
[198, "t0", "(pointer int128)"]
],
"calc-shadow-masks": [
[10, "v0", "(array float)"]
],
"dma-add-process-drawable-hud": [
[[43, 59], "v1", "level"],
[11, "a0", "foreground-work"]
],
"default-init-buffer": [
[[116, 126], "a1", "dma-packet"]
],
"default-end-buffer": [
[[117, 123], "a1", "dma-packet"],
[125, "a1", "(pointer uint32)"]
],
"display-frame-start": [
[4, "v1", "vif-bank"],
[9, "a0", "vif-bank"]
],
"display-frame-finish": [
[[504, 513], "a0", "dma-packet"],
[542, "a0", "(pointer uint64)"]
],
"(method 15 drawable-tree)": [
[[1, 4], "v1", "drawable-inline-array-node"],
[[29, 34], "t0", "drawable-inline-array-node"],
[[28, 32], "t2", "drawable-inline-array-node"],
[[42, 46], "t2", "(pointer int8)"]
],
"get-shadow-by-name": [
[7, "v1", "process-drawable"]
],
"set-shadow-by-name": [
[7, "v1", "process-drawable"]
],
"find-instance-by-index": [
[26, "t1", "drawable-tree-instance-shrub"],
[40, "t1", "drawable-tree-instance-tie"]
],
"print-prototype-list": [
[25, "v1", "drawable-tree-instance-shrub"],
[104, "v1", "drawable-tree-instance-tie"]
],
"draw-instance-info": [
[[188, 203], "s5", "prototype-bucket-shrub"],
[[192, 303], "s1", "prototype-shrubbery"],
[[359, 400], "v1", "prototype-tie"],
[[44, 64], "s1", "drawable-inline-array-instance-tie"],
[[331, 450], "s5", "prototype-bucket-tie"],
[[35, 41], "v1", "drawable-tree-instance-tie"]
],
"set-graphics-mode": [[[0, 100], "gp", "gs-bank"]],
"(method 9 screen-filter)": [
[[118, 128], "t1", "rgba"]
],
"display-loop-main": [
[231, "t9", "(function none)"]
]


}
27 changes: 20 additions & 7 deletions decompiler/util/data_decompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2078,9 +2078,10 @@ std::vector<BitFieldConstantDef> decompile_bitfield_from_int(const TypeSpec& typ
return *try_decompile_bitfield_from_int(type, ts, value, true, {});
}

std::vector<std::string> decompile_bitfield_enum_from_int(const TypeSpec& type,
const TypeSystem& ts,
u64 value) {
std::optional<std::vector<std::string>> try_decompile_bitfield_enum_from_int(const TypeSpec& type,
const TypeSystem& ts,
u64 value,
bool require_success) {
u64 reconstructed = 0;
std::vector<std::string> result;
auto type_info = ts.try_enum_lookup(type.base_type());
Expand Down Expand Up @@ -2116,10 +2117,14 @@ std::vector<std::string> decompile_bitfield_enum_from_int(const TypeSpec& type,
}

if (reconstructed != value) {
throw std::runtime_error(fmt::format(
"Failed to decompile bitfield enum {}. Original value is 0x{:x} but we could only "
"make 0x{:x} using the available fields.",
type.print(), value, reconstructed));
if (require_success) {
throw std::runtime_error(fmt::format(
"Failed to decompile bitfield enum {}. Original value is 0x{:x} but we could only "
"make 0x{:x} using the available fields.",
type.print(), value, reconstructed));
} else {
return std::nullopt;
}
}

if (bit_count == (int)result.size()) {
Expand All @@ -2137,6 +2142,14 @@ std::vector<std::string> decompile_bitfield_enum_from_int(const TypeSpec& type,
return result;
}

std::vector<std::string> decompile_bitfield_enum_from_int(const TypeSpec& type,
const TypeSystem& ts,
u64 value) {
auto ret = try_decompile_bitfield_enum_from_int(type, ts, value, true);
ASSERT(ret.has_value());
return *ret;
}

std::string decompile_int_enum_from_int(const TypeSpec& type, const TypeSystem& ts, u64 value) {
auto type_info = ts.try_enum_lookup(type.base_type());
ASSERT(type_info);
Expand Down
5 changes: 4 additions & 1 deletion decompiler/util/data_decompile.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ T extract_bitfield(T input, int start_bit, int size) {
std::vector<BitFieldConstantDef> decompile_bitfield_from_int(const TypeSpec& type,
const TypeSystem& ts,
u64 value);

std::optional<std::vector<std::string>> try_decompile_bitfield_enum_from_int(const TypeSpec& type,
const TypeSystem& ts,
u64 value,
bool require_success);
std::optional<std::vector<BitFieldConstantDef>> try_decompile_bitfield_from_int(
const TypeSpec& type,
const TypeSystem& ts,
Expand Down
1 change: 1 addition & 0 deletions game/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ set(RUNTIME_SOURCE
graphics/sceGraphicsInterface.cpp
graphics/texture/jak1_tpage_dir.cpp
graphics/texture/jak2_tpage_dir.cpp
graphics/texture/jak3_tpage_dir.cpp
graphics/texture/TextureConverter.cpp
graphics/texture/TexturePool.cpp
${OG_ASM_FUNCS_FILE}
Expand Down
26 changes: 26 additions & 0 deletions game/graphics/opengl_renderer/OpenGLRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ OpenGLRenderer::OpenGLRenderer(std::shared_ptr<TexturePool> texture_pool,
case GameVersion::Jak2:
m_texture_animator = std::make_shared<TextureAnimator>(m_render_state.shaders, common_level);
break;
case GameVersion::Jak3:
// for now, no texture animation for jak3...
break;
default:
ASSERT(false);
}
Expand All @@ -114,11 +117,34 @@ OpenGLRenderer::OpenGLRenderer(std::shared_ptr<TexturePool> texture_pool,
case GameVersion::Jak2:
init_bucket_renderers_jak2();
break;
case GameVersion::Jak3:
init_bucket_renderers_jak3();
break;
default:
ASSERT(false);
}
}

void OpenGLRenderer::init_bucket_renderers_jak3() {
using namespace jak3;
m_bucket_renderers.resize((int)BucketId::MAX_BUCKETS);
m_bucket_categories.resize((int)BucketId::MAX_BUCKETS, BucketCategory::OTHER);

{
auto p = scoped_prof("render-inits");
// for now, for any unset renderers, just set them to an EmptyBucketRenderer.
for (size_t i = 0; i < m_bucket_renderers.size(); i++) {
if (!m_bucket_renderers[i]) {
init_bucket_renderer<EmptyBucketRenderer>(fmt::format("bucket-{}", i),
BucketCategory::OTHER, i);
}

m_bucket_renderers[i]->init_shaders(m_render_state.shaders);
m_bucket_renderers[i]->init_textures(*m_render_state.texture_pool, GameVersion::Jak3);
}
}
}

void OpenGLRenderer::init_bucket_renderers_jak2() {
using namespace jak2;
m_bucket_renderers.resize((int)BucketId::MAX_BUCKETS);
Expand Down
1 change: 1 addition & 0 deletions game/graphics/opengl_renderer/OpenGLRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class OpenGLRenderer {
void blit_display();
void init_bucket_renderers_jak1();
void init_bucket_renderers_jak2();
void init_bucket_renderers_jak3();
void draw_renderer_selection_window();
void finish_screenshot(const std::string& output_name,
int px,
Expand Down
6 changes: 6 additions & 0 deletions game/graphics/opengl_renderer/buckets.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,12 @@ enum class BucketId {
};
}

namespace jak3 {
enum class BucketId {
MAX_BUCKETS = 587,
};
}

enum class BucketCategory {
TFRAG,
TIE,
Expand Down
3 changes: 3 additions & 0 deletions game/graphics/texture/TexturePool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "game/graphics/pipelines/opengl.h"
#include "game/graphics/texture/jak1_tpage_dir.h"
#include "game/graphics/texture/jak2_tpage_dir.h"
#include "game/graphics/texture/jak3_tpage_dir.h"

#include "fmt/core.h"
#include "third-party/imgui/imgui.h"
Expand Down Expand Up @@ -312,6 +313,8 @@ const std::vector<u32>& get_tpage_dir(GameVersion version) {
return get_jak1_tpage_dir();
case GameVersion::Jak2:
return get_jak2_tpage_dir();
case GameVersion::Jak3:
return get_jak3_tpage_dir();
default:
ASSERT(false);
}
Expand Down
2 changes: 1 addition & 1 deletion game/graphics/texture/jak2_tpage_dir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "common/common_types.h"

#include "jak1_tpage_dir.h"
#include "game/graphics/texture/jak1_tpage_dir.h"

// clang-format off
namespace {
Expand Down
1 change: 0 additions & 1 deletion game/graphics/texture/jak2_tpage_dir.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include <string>
#include <vector>

#include "common/common_types.h"
Expand Down
Loading

0 comments on commit 9b4b549

Please sign in to comment.