Various bug fixes

This commit is contained in:
Jack Andersen 2018-01-13 20:44:22 -10:00
parent e683fc223f
commit 7a179eb10a
18 changed files with 242 additions and 36 deletions

View File

@ -443,6 +443,7 @@ void WPSM<IDType>::read(athena::io::IStreamReader& r)
template <class IDType> template <class IDType>
void WPSM<IDType>::write(athena::io::IStreamWriter &w) const void WPSM<IDType>::write(athena::io::IStreamWriter &w) const
{ {
w.writeBytes("WPSM", 4);
if (x0_IORN) if (x0_IORN)
{ {
w.writeBytes("IORN", 4); w.writeBytes("IORN", 4);

View File

@ -372,9 +372,6 @@ struct SpecMP1 : SpecBase
hecl::ProjectPath mp1OutPath(outPath, _S("MP1")); hecl::ProjectPath mp1OutPath(outPath, _S("MP1"));
mp1OutPath.makeDir(); mp1OutPath.makeDir();
/* Generate original ID mapping for MLVL and SCAN entries */
OriginalIDs::Generate(m_pakRouter, m_project);
/* Extract non-pak files */ /* Extract non-pak files */
progress(_S("MP1 Root"), _S(""), 3, 0.0); progress(_S("MP1 Root"), _S(""), 3, 0.0);
int prog = 0; int prog = 0;
@ -436,6 +433,9 @@ struct SpecMP1 : SpecBase
hecl::ProjectPath noAramPath(m_project.getProjectWorkingPath(), _S("MP1/NoARAM")); hecl::ProjectPath noAramPath(m_project.getProjectWorkingPath(), _S("MP1/NoARAM"));
extractRandomStaticEntropy(m_dolBuf.get() + 0x4f60, noAramPath); extractRandomStaticEntropy(m_dolBuf.get() + 0x4f60, noAramPath);
/* Generate original ID mapping for MLVL and SCAN entries - marks complete project */
OriginalIDs::Generate(m_pakRouter, m_project);
return true; return true;
} }

View File

@ -22,11 +22,15 @@ CFactoryFnReturn CResFactory::BuildSync(const SObjectTag& tag, const CVParamTran
if (size) if (size)
ret = x5c_factoryMgr.MakeObjectFromMemory(tag, std::move(data), size, ret = x5c_factoryMgr.MakeObjectFromMemory(tag, std::move(data), size,
x4_loader.GetResourceCompression(tag), xfer, selfRef); x4_loader.GetResourceCompression(tag), xfer, selfRef);
else
ret = std::make_unique<TObjOwnerDerivedFromIObjUntyped>(nullptr);
} }
else else
{ {
if (auto rp = x4_loader.LoadNewResourceSync(tag, nullptr)) if (auto rp = x4_loader.LoadNewResourceSync(tag, nullptr))
ret = x5c_factoryMgr.MakeObject(tag, *rp, xfer, selfRef); ret = x5c_factoryMgr.MakeObject(tag, *rp, xfer, selfRef);
else
ret = std::make_unique<TObjOwnerDerivedFromIObjUntyped>(nullptr);
} }
Log.report(logvisor::Warning, "sync-built %.4s %08X", tag.type.getChars(), tag.id.Value()); Log.report(logvisor::Warning, "sync-built %.4s %08X", tag.type.getChars(), tag.id.Value());
return ret; return ret;
@ -74,6 +78,10 @@ void CResFactory::BuildAsync(const SObjectTag& tag, const CVParamTransfer& xfer,
data.x8_dvdReq = x4_loader.LoadResourceAsync(tag, data.x10_loadBuffer.get()); data.x8_dvdReq = x4_loader.LoadResourceAsync(tag, data.x10_loadBuffer.get());
AddToLoadList(std::move(data)); AddToLoadList(std::move(data));
} }
else
{
*target = std::make_unique<TObjOwnerDerivedFromIObjUntyped>(nullptr);
}
} }
} }

View File

@ -205,6 +205,7 @@ CStateManager::CStateManager(const std::weak_ptr<CRelayTracker>& relayTracker,
x90c_loaderFuncs[int(EScriptObjectType::ShadowProjector)] = ScriptLoader::LoadShadowProjector; x90c_loaderFuncs[int(EScriptObjectType::ShadowProjector)] = ScriptLoader::LoadShadowProjector;
x90c_loaderFuncs[int(EScriptObjectType::EnergyBall)] = ScriptLoader::LoadEnergyBall; x90c_loaderFuncs[int(EScriptObjectType::EnergyBall)] = ScriptLoader::LoadEnergyBall;
CGameCollision::InitCollision();
ControlMapper::ResetCommandFilters(); ControlMapper::ResetCommandFilters();
x8f0_shadowTex = g_SimplePool->GetObj("DefaultShadow"); x8f0_shadowTex = g_SimplePool->GetObj("DefaultShadow");
} }

View File

@ -42,7 +42,7 @@ void CObjectReference::Lock()
{ {
IFactory& fac = xC_objectStore->GetFactory(); IFactory& fac = xC_objectStore->GetFactory();
fac.BuildAsync(x4_objTag, x14_params, &x10_object, this); fac.BuildAsync(x4_objTag, x14_params, &x10_object, this);
x3_loading = true; x3_loading = !x10_object.operator bool();
} }
} }

View File

@ -206,17 +206,6 @@ enum class ETexelFormat
CMPRPC = 18, CMPRPC = 18,
}; };
/*
#define DEPTH_FAR 1.f
#define DEPTH_SKY 0.999f
#define DEPTH_TARGET_MANAGER 0.12500012f
#define DEPTH_WORLD (1.f / 8.f)
#define DEPTH_GUN (1.f / 32.f)
#define DEPTH_SCREEN_ACTORS (1.f / 64.f)
#define DEPTH_HUD (1.f / 512.f)
#define DEPTH_NEAR 0.f
*/
#define DEPTH_FAR 1.f #define DEPTH_FAR 1.f
#define DEPTH_SKY 0.999f #define DEPTH_SKY 0.999f
#define DEPTH_TARGET_MANAGER 0.12500012f #define DEPTH_TARGET_MANAGER 0.12500012f

View File

@ -16,6 +16,7 @@ class TObjOwnerDerivedFromIObjUntyped : public IObj
{ {
protected: protected:
void* m_objPtr; void* m_objPtr;
public:
TObjOwnerDerivedFromIObjUntyped(void* objPtr) : m_objPtr(objPtr) {} TObjOwnerDerivedFromIObjUntyped(void* objPtr) : m_objPtr(objPtr) {}
}; };

View File

@ -5,6 +5,205 @@
namespace urde::MP1 namespace urde::MP1
{ {
void CNESEmulator::DescrambleROM(u8* dataIn, u8* dataOut, u32 dataOutLen, u8 descrambleInit,
u32 descramble2Len, u32 descramble2Magic)
{
for (int i=0 ; i<256 ; ++i)
{
descrambleInit += dataIn[i];
dataIn[i] = descrambleInit;
}
for (int i=0 ; i<128 ; ++i)
std::swap(dataIn[255 - i], dataIn[i]);
struct BitstreamState
{
u32 x0_remBits = 0;
u32 x4_lastByte;
u8* x8_ptr;
BitstreamState(u8* ptr) : x8_ptr(ptr) {}
} bState = {dataIn + 256};
u8* dataOutAlpha = dataOut;
while (dataOutLen != 0)
{
u32 r12 = 0;
if (bState.x0_remBits == 0)
{
bState.x4_lastByte = *bState.x8_ptr;
bState.x8_ptr += 1;
bState.x0_remBits = 8;
}
u32 r11 = r12 << 1;
if (bState.x4_lastByte & 0x80)
r11 |= 1;
bState.x4_lastByte <<= 1;
bState.x0_remBits -= 1;
if (r11 == 1)
{
r12 = 0;
for (int i=0 ; i<4 ; ++i)
{
if (bState.x0_remBits == 0)
{
bState.x4_lastByte = *bState.x8_ptr;
bState.x8_ptr += 1;
bState.x0_remBits = 8;
}
r12 <<= 1;
if (bState.x4_lastByte & 0x80)
r12 |= 1;
bState.x4_lastByte <<= 1;
bState.x0_remBits -= 1;
if (bState.x0_remBits == 0)
{
bState.x4_lastByte = *bState.x8_ptr;
bState.x8_ptr += 1;
bState.x0_remBits = 8;
}
r12 <<= 1;
if (bState.x4_lastByte & 0x80)
r12 |= 1;
bState.x4_lastByte <<= 1;
bState.x0_remBits -= 1;
}
*dataOutAlpha++ = dataIn[r12 + 73];
}
else
{
r12 = 0;
if (bState.x0_remBits == 0)
{
bState.x4_lastByte = *bState.x8_ptr;
bState.x8_ptr += 1;
bState.x0_remBits = 8;
}
r11 = r12 << 1;
if (bState.x4_lastByte & 0x80)
r11 |= 1;
bState.x4_lastByte <<= 1;
bState.x0_remBits -= 1;
if (r11 == 1)
{
r12 = 0;
for (int i=0 ; i<3 ; ++i)
{
if (bState.x0_remBits == 0)
{
bState.x4_lastByte = *bState.x8_ptr;
bState.x8_ptr += 1;
bState.x0_remBits = 8;
}
r12 <<= 1;
if (bState.x4_lastByte & 0x80)
r12 |= 1;
bState.x4_lastByte <<= 1;
bState.x0_remBits -= 1;
if (bState.x0_remBits == 0)
{
bState.x4_lastByte = *bState.x8_ptr;
bState.x8_ptr += 1;
bState.x0_remBits = 8;
}
r12 <<= 1;
if (bState.x4_lastByte & 0x80)
r12 |= 1;
bState.x4_lastByte <<= 1;
bState.x0_remBits -= 1;
}
*dataOutAlpha++ = dataIn[r12 + 9];
}
else
{
r12 = 0;
if (bState.x0_remBits == 0)
{
bState.x4_lastByte = *bState.x8_ptr;
bState.x8_ptr += 1;
bState.x0_remBits = 8;
}
r11 = r12 << 1;
if (bState.x4_lastByte & 0x80)
r11 |= 1;
bState.x4_lastByte <<= 1;
bState.x0_remBits -= 1;
if (r11 == 1)
{
r12 = 0;
for (int i=0 ; i<3 ; ++i)
{
if (bState.x0_remBits == 0)
{
bState.x4_lastByte = *bState.x8_ptr;
bState.x8_ptr += 1;
bState.x0_remBits = 8;
}
r12 <<= 1;
if (bState.x4_lastByte & 0x80)
r12 |= 1;
bState.x4_lastByte <<= 1;
bState.x0_remBits -= 1;
}
*dataOutAlpha++ = dataIn[r12 + 1];
}
else
{
*dataOutAlpha++ = dataIn[0];
}
}
}
--dataOutLen;
}
u32 tmpWord = 0;
for (int i=0 ; i<descramble2Len ; ++i)
{
tmpWord ^= dataOut[i];
for (int j=0 ; j<8 ; ++j)
{
if (tmpWord & 0x1)
tmpWord = (tmpWord >> 1) ^ descramble2Magic;
else
tmpWord = (tmpWord >> 1);
}
}
dataOut[descramble2Len - 1] = (tmpWord >> 8) & 0xff;
dataOut[descramble2Len - 2] = tmpWord & 0xff;
}
void CNESEmulator::ProcessUserInput(const CFinalInput& input, int) void CNESEmulator::ProcessUserInput(const CFinalInput& input, int)
{ {

View File

@ -18,6 +18,8 @@ class CNESEmulator
bool x34_wantsLoad = false; bool x34_wantsLoad = false;
bool x38_stateLoaded = false; bool x38_stateLoaded = false;
u8 x39_loadState[18]; u8 x39_loadState[18];
static void DescrambleROM(u8* dataIn, u8* dataOut, u32 dataOutLen = 0x20000, u8 descrambleInit = 0xe9,
u32 descramble2Len = 0x1FFFC, u32 descramble2Magic = 0xA663);
public: public:
void ProcessUserInput(const CFinalInput& input, int); void ProcessUserInput(const CFinalInput& input, int);
void Update(); void Update();

View File

@ -26,6 +26,7 @@ CWeaponDescription* CProjectileWeaponDataFactory::CreateGeneratorDescription(CIn
{ {
CWeaponDescription* desc = new CWeaponDescription; CWeaponDescription* desc = new CWeaponDescription;
CreateWPSM(desc, in, resPool); CreateWPSM(desc, in, resPool);
return desc;
} }
return nullptr; return nullptr;
@ -47,6 +48,9 @@ bool CProjectileWeaponDataFactory::CreateWPSM(CWeaponDescription* desc, CInputSt
case SBIG('IVEC'): case SBIG('IVEC'):
desc->x4_IVEC.reset(CPF::GetVectorElement(in)); desc->x4_IVEC.reset(CPF::GetVectorElement(in));
break; break;
case SBIG('PSOV'):
desc->x8_PSOV.reset(CPF::GetVectorElement(in));
break;
case SBIG('PSVM'): case SBIG('PSVM'):
desc->xc_PSVM.reset(CPF::GetModVectorElement(in)); desc->xc_PSVM.reset(CPF::GetModVectorElement(in));
break; break;
@ -56,8 +60,8 @@ bool CProjectileWeaponDataFactory::CreateWPSM(CWeaponDescription* desc, CInputSt
case SBIG('PSLT'): case SBIG('PSLT'):
desc->x14_PSLT.reset(CPF::GetIntElement(in)); desc->x14_PSLT.reset(CPF::GetIntElement(in));
break; break;
case SBIG('PCSL'): case SBIG('PSCL'):
desc->x18_PCSL.reset(CPF::GetVectorElement(in)); desc->x18_PSCL.reset(CPF::GetVectorElement(in));
break; break;
case SBIG('PCOL'): case SBIG('PCOL'):
desc->x1c_PCOL.reset(CPF::GetColorElement(in)); desc->x1c_PCOL.reset(CPF::GetColorElement(in));

View File

@ -30,7 +30,7 @@ public:
std::unique_ptr<CModVectorElement> xc_PSVM; std::unique_ptr<CModVectorElement> xc_PSVM;
bool x10_VMD2; bool x10_VMD2;
std::unique_ptr<CIntElement> x14_PSLT; std::unique_ptr<CIntElement> x14_PSLT;
std::unique_ptr<CVectorElement> x18_PCSL; std::unique_ptr<CVectorElement> x18_PSCL;
std::unique_ptr<CColorElement> x1c_PCOL; std::unique_ptr<CColorElement> x1c_PCOL;
std::unique_ptr<CVectorElement> x20_POFS; std::unique_ptr<CVectorElement> x20_POFS;
std::unique_ptr<CVectorElement> x24_OFST; std::unique_ptr<CVectorElement> x24_OFST;

View File

@ -460,7 +460,7 @@ void CGunWeapon::LoadFxIdle(float dt, CStateManager& mgr)
{ {
if (NWeaponTypes::are_tokens_ready(x12c_deps)) if (NWeaponTypes::are_tokens_ready(x12c_deps))
{ {
if ((x210_ & 0x2) != 0 && (x210_ & 0x4) != 0 && (x210_ & 0x10) != 0) if ((x210_loadFlags & 0x2) != 0 && (x210_loadFlags & 0x4) != 0 && (x210_loadFlags & 0x10) != 0)
return; return;
bool loaded = true; bool loaded = true;
for (int i=0 ; i<2 ; ++i) for (int i=0 ; i<2 ; ++i)
@ -491,16 +491,16 @@ void CGunWeapon::LoadFxIdle(float dt, CStateManager& mgr)
if (loaded) if (loaded)
{ {
if ((x210_ & 0x2) != 0x2) if ((x210_loadFlags & 0x2) != 0x2)
{ {
LoadMuzzleFx(dt); LoadMuzzleFx(dt);
x210_ |= 0x2; x210_loadFlags |= 0x2;
} }
x210_ |= 0x10; x210_loadFlags |= 0x10;
if ((x210_ & 0x4) != 0x4) if ((x210_loadFlags & 0x4) != 0x4)
{ {
LoadProjectileData(mgr); LoadProjectileData(mgr);
x210_ |= 0x4; x210_loadFlags |= 0x4;
} }
} }
} }
@ -521,21 +521,21 @@ void CGunWeapon::Update(float dt, CStateManager& mgr)
{ {
if (x104_gunCharacter.IsLoaded()) if (x104_gunCharacter.IsLoaded())
{ {
if ((x210_ & 0x1) != 0x1) if ((x210_loadFlags & 0x1) != 0x1)
{ {
LoadGunModels(mgr); LoadGunModels(mgr);
LoadAnimations(); LoadAnimations();
x210_ |= 0x1; x210_loadFlags |= 0x1;
} }
if ((x210_ & 0x8) != 0x8) if ((x210_loadFlags & 0x8) != 0x8)
{ {
if (IsAnimsLoaded()) if (IsAnimsLoaded())
x210_ |= 0x8; x210_loadFlags |= 0x8;
} }
} }
LoadFxIdle(dt, mgr); LoadFxIdle(dt, mgr);
if ((x210_ & 0x1f) == 0x1f) if ((x210_loadFlags & 0x1f) == 0x1f)
{ {
if (x10_solidModelData->PickAnimatedModel(CModelData::EWhichModel::Normal).GetModel()-> if (x10_solidModelData->PickAnimatedModel(CModelData::EWhichModel::Normal).GetModel()->
IsLoaded(x20c_shaderIdx) && xb0_suitArmModelData->IsLoaded(0)) IsLoaded(x20c_shaderIdx) && xb0_suitArmModelData->IsLoaded(0))
@ -577,7 +577,7 @@ void CGunWeapon::Load(CStateManager& mgr, bool subtypeBasePose)
void CGunWeapon::Unload(CStateManager& mgr) void CGunWeapon::Unload(CStateManager& mgr)
{ {
UnlockTokens(); UnlockTokens();
x210_ = 0; x210_loadFlags = 0;
x204_frozenEffect = EFrozenFxType::None; x204_frozenEffect = EFrozenFxType::None;
x10_solidModelData = std::experimental::nullopt; x10_solidModelData = std::experimental::nullopt;
x60_holoModelData = std::experimental::nullopt; x60_holoModelData = std::experimental::nullopt;

View File

@ -92,7 +92,8 @@ protected:
EFrozenFxType x204_frozenEffect = EFrozenFxType::None; EFrozenFxType x204_frozenEffect = EFrozenFxType::None;
u32 x208_muzzleEffectIdx = 0; u32 x208_muzzleEffectIdx = 0;
u32 x20c_shaderIdx; u32 x20c_shaderIdx;
u32 x210_ = 0; // 0x1: load request, 0x2: muzzle fx, 0x4: projectile data, 0x8: anims, 0x10: everything else
u32 x210_loadFlags = 0;
CAssetId x214_ancsId; CAssetId x214_ancsId;
union union
{ {

2
hecl

@ -1 +1 @@
Subproject commit 4347e83abb61f8036406a7783836b7a3f8139309 Subproject commit 78c9b1fc7b1e3f4fdb516f8aae711a707b37f4ad

@ -1 +1 @@
Subproject commit 07a2123b4dae4cca7efcfd0bc1fdeb9b64f479cf Subproject commit de833d1e2d774d91d84b9778d221d1a67825eb2e

2
jbus

@ -1 +1 @@
Subproject commit 8593e06fa5b4532a898c282c49d227e6a0cd421f Subproject commit c06141af1eb303e7a4f3b7e5d0c424a7df6b12b9

2
nod

@ -1 +1 @@
Subproject commit 648c015383f7c5596e87e6f49aeee0df32e5739b Subproject commit 5197abc131d369af4f66b044242bfe61011f66be

@ -1 +1 @@
Subproject commit b949259bf13dd668a1887da8fba05ee534ec02e9 Subproject commit c22f78e2e2de5361a13c2f4b9558a52820f9db14