Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions data/data_symbols.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
0x0000007101091690,_ZTI9SavedData
0x00000071010c6538,_ZTV16StructureFeature
0x00000071010c65b8,_ZTV25StructureFeatureSavedData
0x00000071010C65E8,_ZN16StructureManager15s_resourceNamesE
0x00000071010C6978,_ZTV16StructureManager
0x00000071010c69c8,_ZTV14StructurePiece
0x00000071010c6b30,_ZTV14StructureStart
0x00000071010C6B98,_ZTV17StructureTemplate
0x00000071010df050,_ZTI25StructureFeatureSavedData
0x0000007101781BBC,AABB__sThreadStorageCount
0x0000007101781BC0,AABB__sDefaultThreadStorage
0x0000007101781BE0,_ZN6Blocks8RegistryE
Expand Down Expand Up @@ -804,6 +813,8 @@
0x000000710178CAF0,_ZN13MaterialColor14TERRACOTTA_REDE
0x000000710178CAF8,_ZN13MaterialColor16TERRACOTTA_BLACKE
0x000000710178CD28,_ZN13ParticleTypes5SMOKEE
0x000000710178cd30,_ZN6Mirror4NONEE
0x000000710178cd38,_ZN6Mirror10LEFT_RIGHTE
0x000000710178CD68,_ZN11MobCategory7MONSTERE
0x000000710178CD70,_ZN11MobCategory8CREATUREE
0x000000710178CD78,_ZN11MobCategory7AMBIENTE
Expand Down Expand Up @@ -838,6 +849,7 @@
0x00000071017A1958,_ZN11PlanksBlock7Variant8VARIANTSE
0x00000071017A1988,_ZN11PlanksBlock9PREDICATEE
0x00000071017A1A30,_ZN15RangedAttribute12ATTACK_SPEEDE
0x00000071017a1a40,_ZN14DataFixerUpper16DATA_VERSION_KEYE
0x00000071017A1BB0,_ZN9Direction4Axis9PREDICATEE
0x00000071017A1E70,_ZN15PrismarineBlock7VARIANTE
0x00000071017A1E78,_ZN15PrismarineBlock7Variant8VARIANTSE
Expand Down Expand Up @@ -871,6 +883,8 @@
0x00000071017A2220,_ZN17RedSandStoneBlock7Variant6SMOOTHE
0x00000071017A2390,_ZN10ReedsBlock12sAgePropertyE
0x00000071017A2448,_ZN18RotatedPillarBlock4AXISE
0x00000071017a2450,_ZN8Rotation4NONEE
0x00000071017a2458,_ZN8Rotation12CLOCKWISE_90E
0x00000071017A2490,_ZN9SandBlock7VARIANTE
0x00000071017A2498,_ZN9SandBlock7Variant7DEFAULTE
0x00000071017A24A0,_ZN9SandBlock7Variant8VARIANTSE
Expand Down Expand Up @@ -901,6 +915,9 @@
0x00000071017A42E8,SoundType::GRASS
0x00000071017A42F0,SoundType::STONE
0x00000071017A4318,SoundType::SNOW
0x00000071017a4410,_ZN18SparseLightStorage15sRetirementSlotE
0x00000071017a4418,_ZN18SparseLightStorage8sRetiredE
0x00000071017a44c0,gSparseLightAllocatedBytes
0x00000071017A4AC0,_ZN10StoneBlock7VARIANTE
0x00000071017A4AC8,_ZN10StoneBlock7Variant5STONEE
0x00000071017A4AD0,_ZN10StoneBlock7Variant7GRANITEE
Expand All @@ -919,7 +936,9 @@
0x00000071017A4BD8,_ZN15StoneBrickBlock7Variant5MOSSYE
0x00000071017A4BE0,_ZN15StoneBrickBlock7Variant7CRACKEDE
0x00000071017A4BE8,_ZN15StoneBrickBlock7Variant8CHISELEDE
0x00000071017a5260,_ZN25StructureFeatureSavedData12FEATURES_KEYE
0x00000071017A53F8,SynchedEntityData__sIdMap
0x00000071017A58E8,_ZN4Vec34ZEROE
0x00000071017A5ED8,_ZZN10StoneBlock26createBlockStateDefinitionEvE10properties
0x00000071017A8380,_ZN3fui9sInstanceE
0x00000071017AA788,CGameNetworkManager__sInstance
Expand Down
346 changes: 173 additions & 173 deletions data/mcswitch_functions.csv

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/4JLibraries_Source/NX/Render/C4JRender.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "arm_neon.h"
#include <arm_neon.h>

class _XSOCIAL_PREVIEWIMAGE;
class ImageFileBuffer;
Expand Down Expand Up @@ -41,7 +41,7 @@ class C4JRender {
virtual void MatrixPop() = 0;
virtual void MatrixPush() = 0;
virtual float32x4_t MatrixMult(float*) = 0;
virtual void MatrixGet(int) = 0;
virtual float* MatrixGet(int) = 0;
virtual void Set_matrixDirty() = 0;
virtual void Initialise() = 0;
virtual void InitialiseContext() = 0;
Expand Down
170 changes: 168 additions & 2 deletions src/4JLibraries_Source/NX/Render/RendererCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,66 @@
#include <cstring>

__thread Renderer::Context* sContext;
static __thread MatrixStruct sMatrixResult;

extern "C" Renderer::Context* Renderer__getContext() {
return sContext;
}

static const MatrixStruct identityMatrix = {
{{1.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 0.0f, 1.0f}}};
unsigned int textureWidths[6] = {1920, 1280, 512, 256, 128, 64};
unsigned int textureHeights[6] = {1080, 720, 512, 256, 128, 64};
nn::os::MutexType someRendererMutex;

Renderer::Context::Context(Renderer*, bool a2) {
this->m_filler[0] = a2;
// NON_MATCHING: the original also creates an unused temporary state object.
Renderer::Context::Context(Renderer*, bool creationFlag) {
m_ptr1DE0 = nullptr;
m_ptr1DE8 = nullptr;
m_ptr1DF0 = nullptr;
m_creationFlag = creationFlag;
// Only the base entries are initialized; stack storage and matrix-dirty flags are preserved.
m_matrixDepth[0] = 0;
m_matrixStacks[0][0] = identityMatrix;
m_matrixDepth[1] = 0;
m_matrixDepth[2] = 0;
m_matrixDepth[3] = 0;
m_matrixMode = 0;
m_matrixStacks[1][0] = identityMatrix;
m_matrixStacks[2][0] = identityMatrix;
m_matrixStacks[3][0] = identityMatrix;
m_byte1040 = false;
m_float1044 = 1.0f;
m_lightingEnabled = false;
for (int i = 0; i < 4; i++) {
m_textureBindings[i] = 0;
m_textureBindingDirty[i] = false;
m_textureFlags[i] = false;
}
m_fogEnabled = false;
m_byte1DD8 = false;
m_commandBuffer = nullptr;
m_dword1CE0 = -1;
memset(m_data1CE8, 0, sizeof(m_data1CE8));
m_byte1CDC = false;
m_byte1D38 = false;
m_fogDirty = false;
m_byte1CE4 = false;
m_textureScaleUI[0] = 1.0f;
m_textureScaleUI[1] = 1.0f;
m_textureScaleUI[2] = 0.0f;
m_textureScaleUI[3] = 0.0f;
nvnBlendStateSetDefaults(&m_blendState);
nvnDepthStencilStateSetDefaults(&m_depthStencilState);
nvnDepthStencilStateSetDepthTestEnable(&m_depthStencilState, true);
nvnDepthStencilStateSetDepthFunc(&m_depthStencilState, NVN_DEPTH_FUNC_LEQUAL);
nvnColorStateSetDefaults(&m_colorState);
nvnPolygonStateSetDefaults(&m_polygonState);
nvnChannelMaskStateSetDefaults(&m_channelMaskState);
m_depthFunc = NVN_DEPTH_FUNC_LEQUAL;
for (int i = 0; i < 6; i++)
m_stateDirty[i] = true;
m_dword1CC0 = 0;
}

Renderer::Renderer() : C4JRender() {
Expand Down Expand Up @@ -429,3 +483,115 @@ float32x4_t Renderer::MatrixMult(float* matrix) {
void Renderer::UpdateGamma(unsigned short gamma) {
this->m_gammaIntensity = gamma;
}

void Renderer::MatrixMode(int mode) {
Renderer__getContext()->m_matrixMode = mode;
}

void Renderer::MatrixSetIdentity() {
Context* context = Renderer__getContext();
int mode = context->m_matrixMode;
MatrixStruct& top = context->m_matrixStacks[mode][context->m_matrixDepth[mode]];
top.m__[0] = identityMatrix.m__[0];
top.m__[1] = identityMatrix.m__[1];
top.m__[2] = identityMatrix.m__[2];
top.m__[3] = identityMatrix.m__[3];
context->m_matrixDirty[context->m_matrixMode] = true;
}

float32x4_t Renderer::MultWithStack(MatrixStruct input) {
Context* context = Renderer__getContext();
int mode = context->m_matrixMode;
MatrixStruct& top = context->m_matrixStacks[mode][context->m_matrixDepth[mode]];
float32x4_t a = top.m__[0];
float32x4_t b = top.m__[1];
float32x4_t c = top.m__[2];
float32x4_t d = top.m__[3];
float32x4_t result;
for (int i = 0; i < 4; i++) {
float32x4_t column = vmulq_laneq_f32(a, input.m__[i], 0);
column = vfmaq_laneq_f32(column, b, input.m__[i], 1);
column = vfmaq_laneq_f32(column, c, input.m__[i], 2);
result = vfmaq_laneq_f32(column, d, input.m__[i], 3);
top.m__[i] = result;
}
context->m_matrixDirty[context->m_matrixMode] = true;
return result;
}

void Renderer::MatrixTranslate(float x, float y, float z) {
MatrixStruct matrix = identityMatrix;
matrix.m__[3] = (float32x4_t){x, y, z, 1.0f};
MultWithStack(matrix);
}

void Renderer::MatrixScale(float x, float y, float z) {
MatrixStruct matrix
= {{{x, 0.0f, 0.0f, 0.0f}, {0.0f, y, 0.0f, 0.0f}, {0.0f, 0.0f, z, 0.0f}, {0.0f, 0.0f, 0.0f, 1.0f}}};
MultWithStack(matrix);
}

void Renderer::MatrixOrthogonal(float left, float right, float bottom, float top, float near, float far) {
float x = 1.0f / (right - left);
float y = 1.0f / (top - bottom);
float z = -1.0f / (far - near);
MatrixStruct matrix = {{{x + x, 0.0f, 0.0f, 0.0f},
{0.0f, y + y, 0.0f, 0.0f},
{0.0f, 0.0f, z, 0.0f},
{-(left + right) * x, -(bottom + top) * y, z * near, 1.0f}}};
MultWithStack(matrix);
}

void Renderer::MatrixPush() {
Context* context = Renderer__getContext();
int mode = context->m_matrixMode;
MatrixStruct* top = &context->m_matrixStacks[mode][context->m_matrixDepth[mode]];
memcpy(top + 1, top, sizeof(MatrixStruct));
context->m_matrixDepth[context->m_matrixMode]++;
}

void Renderer::MatrixPop() {
Context* context = Renderer__getContext();
context->m_matrixDepth[context->m_matrixMode]--;
context->m_matrixDirty[context->m_matrixMode] = true;
}

float* Renderer::MatrixGet(int mode) {
Context* context = Renderer__getContext();
MatrixStruct& top = context->m_matrixStacks[mode][context->m_matrixDepth[mode]];
float32x4_t a = top.m__[0];
float32x4_t b = top.m__[1];
float32x4_t c = top.m__[2];
float32x4_t d = top.m__[3];
sMatrixResult.m__[0] = a;
sMatrixResult.m__[1] = b;
sMatrixResult.m__[2] = c;
sMatrixResult.m__[3] = d;
return reinterpret_cast<float*>(&sMatrixResult);
}

void Renderer::Set_matrixDirty() {
Context* context = Renderer__getContext();
context->m_matrixStacks[0][0].m__[0] = identityMatrix.m__[0];
context->m_matrixStacks[0][0].m__[1] = identityMatrix.m__[1];
context->m_matrixStacks[0][0].m__[2] = identityMatrix.m__[2];
context->m_matrixStacks[0][0].m__[3] = identityMatrix.m__[3];
context->m_matrixStacks[1][0].m__[0] = identityMatrix.m__[0];
context->m_matrixStacks[1][0].m__[1] = identityMatrix.m__[1];
context->m_matrixStacks[1][0].m__[2] = identityMatrix.m__[2];
context->m_matrixStacks[1][0].m__[3] = identityMatrix.m__[3];
context->m_matrixStacks[3][0].m__[0] = identityMatrix.m__[0];
context->m_matrixStacks[3][0].m__[1] = identityMatrix.m__[1];
context->m_matrixStacks[3][0].m__[2] = identityMatrix.m__[2];
context->m_matrixStacks[3][0].m__[3] = identityMatrix.m__[3];
context->m_matrixStacks[2][0].m__[0] = identityMatrix.m__[0];
context->m_matrixStacks[2][0].m__[1] = identityMatrix.m__[1];
context->m_matrixStacks[2][0].m__[2] = identityMatrix.m__[2];
context->m_matrixStacks[2][0].m__[3] = identityMatrix.m__[3];
context->m_matrixDirty[0] = true;
context->m_matrixDirty[1] = true;
context->m_matrixDirty[3] = true;
context->m_matrixDirty[2] = true;
m_dword29C0 = -1;
m_dword29C4 = -1;
}
59 changes: 55 additions & 4 deletions src/4JLibraries_Source/NX/Render/RendererCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,49 @@ class Renderer : public C4JRender {
public:
Context(Renderer*, bool);

char m_filler[0x1F30];
char m_gap0[0x10];
MatrixStruct m_matrixStacks[4][16];
bool m_matrixDirty[4];
int m_matrixDepth[4];
int m_matrixMode;
int m_textureBindings[4];
bool m_textureBindingDirty[4];
bool m_textureFlags[4];
bool m_byte1040;
float m_float1044;
NVNblendState m_blendState;
NVNdepthStencilState m_depthStencilState;
NVNcolorState m_colorState;
NVNpolygonState m_polygonState;
NVNchannelMaskState m_channelMaskState;
int m_depthFunc;
bool m_stateDirty[6];
char m_gap106E[0xC52];
int m_dword1CC0;
bool m_fogEnabled;
char m_gap1CC5[0x13];
bool m_fogDirty;
bool m_lightingEnabled;
char m_gap1CDA[2];
bool m_byte1CDC;
char m_gap1CDD[3];
int m_dword1CE0;
bool m_byte1CE4;
bool m_creationFlag;
char m_gap1CE6[2];
char m_data1CE8[0x50];
bool m_byte1D38;
char m_gap1D39[0x87];
void* m_commandBuffer;
char m_gap1DC8[0x10];
bool m_byte1DD8;
char m_gap1DD9[7];
void* m_ptr1DE0;
void* m_ptr1DE8;
void* m_ptr1DF0;
char m_gap1DF8[0x28];
float m_textureScaleUI[4];
char m_gap1E30[0x100];
};

Renderer();
Expand All @@ -58,8 +100,7 @@ class Renderer : public C4JRender {

virtual void Tick();
virtual void UpdateGamma(unsigned short gamma);
// see OpenGL for more info (modes starts from 0 and ends in 2, they are in the same order as they are in
// OpenGL)
// NX maintains four independently selected matrix stacks, each with sixteen entries.
virtual void MatrixMode(int);
virtual void MatrixSetIdentity();
virtual void MatrixTranslate(float, float, float);
Expand All @@ -70,7 +111,7 @@ class Renderer : public C4JRender {
virtual void MatrixPop();
virtual void MatrixPush();
virtual float32x4_t MatrixMult(float* matrix);
virtual void MatrixGet(int);
virtual float* MatrixGet(int);
virtual void Set_matrixDirty();
// unused params were probably used in Xbox One
virtual void Initialise();
Expand Down Expand Up @@ -343,3 +384,13 @@ class Renderer : public C4JRender {
int m_elo;
int m_elo22;
};

static_assert(sizeof(MatrixStruct) == 0x40, "Matrix size");
static_assert(alignof(MatrixStruct) == 0x10, "Matrix alignment");
static_assert(sizeof(Renderer::Context) == 0x1F30, "Renderer context size");
static_assert(offsetof(Renderer::Context, m_matrixStacks) == 0x10, "Matrix stack offset");
static_assert(offsetof(Renderer::Context, m_matrixDirty) == 0x1010, "Matrix dirty offset");
static_assert(offsetof(Renderer::Context, m_matrixMode) == 0x1024, "Matrix mode offset");
static_assert(offsetof(Renderer::Context, m_blendState) == 0x1048, "Blend state offset");
static_assert(offsetof(Renderer::Context, m_creationFlag) == 0x1CE5, "Context flag offset");
static_assert(offsetof(Renderer::Context, m_textureScaleUI) == 0x1E20, "UI texture scale offset");
6 changes: 4 additions & 2 deletions src/4JLibraries_Source/XLockFreeStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@

#include <vector>

// wtf is this
// The original implementation serializes a pointer vector with a mutex.
template <typename T>
class XLockFreeStack {
public:
XLockFreeStack();
~XLockFreeStack();

void doSomething() {}
void Push(T*);
T* Pop();

std::vector<T> m_vector;
std::vector<T*> m_vector;
nn::os::MutexType m_mutex;
};

Expand Down
4 changes: 2 additions & 2 deletions src/4JLibraries_Source/fui/fui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void fui::render(fuiFile* file, float a1, float a2, float a3, float a4, float a5
}

void fui::dispatchKeyboardEvent(fuiFile* file, bool state, int c) {
FJ_FuiNode* node = file->m_data.m_fuiSymbol->m_stage; // ???
FJ_FuiNode* node = file->m_renderNodeStage->m_fuiNodeStage;

if (FJ_FuiNode* focus = static_cast<FJ_FuiNodeStage*>(node)->getFocus())
node = focus;
Expand All @@ -106,7 +106,7 @@ void fui::dispatchKeyboardEvent(fuiFile* file, bool state, int c) {

// param names guessed
void fui::dispatchMouseMoveEvent(fuiFile* file, float x, float y) {
FJ_FuiNode* node = file->m_data.m_fuiSymbol->m_stage;
FJ_FuiNode* node = file->m_renderNodeStage->m_fuiNodeStage;

if (FJ_FuiNode* focus = static_cast<FJ_FuiNodeStage*>(node)->getFocus())
node = focus;
Expand Down
Loading