Various fixes and optimizations.
This commit is contained in:
parent
ac4548f4c2
commit
f509e67953
@ -97,6 +97,7 @@ workspace "iw4x"
|
||||
-- Pre-compiled header
|
||||
pchheader "STDInclude.hpp" -- must be exactly same as used in #include directives
|
||||
pchsource "src/STDInclude.cpp" -- real path
|
||||
buildoptions { "-Zm200" } -- allocate ~150mb memory for the precompiled header. This should be enough, increase if necessary
|
||||
|
||||
-- Dependency on zlib, json11 and asio
|
||||
links { "zlib", "json11", "pdcurses" }
|
||||
|
@ -2,16 +2,6 @@
|
||||
|
||||
namespace Assets
|
||||
{
|
||||
void IGfxImage::Save_GfxImageLoadDef(Components::ZoneBuilder::Zone* builder, const char* name)
|
||||
{
|
||||
Game::GfxImageLoadDef loadDef;
|
||||
ZeroMemory(&loadDef, sizeof(loadDef));
|
||||
|
||||
Utils::Stream* buffer = builder->GetBuffer();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void IGfxImage::Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
|
||||
{
|
||||
Assert_AssetStruct(Game::GfxImage, 32);
|
||||
|
@ -5,8 +5,5 @@ namespace Assets
|
||||
virtual Game::XAssetType GetType() override { return Game::XAssetType::ASSET_TYPE_IMAGE; };
|
||||
|
||||
virtual void Save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder) override;
|
||||
|
||||
private:
|
||||
void Save_GfxImageLoadDef(Components::ZoneBuilder::Zone* builder, const char* name);
|
||||
};
|
||||
}
|
@ -59,73 +59,100 @@ namespace Assets
|
||||
{
|
||||
Assert_AssetStruct(Game::MaterialTextureDef, 12);
|
||||
|
||||
buffer->Align(Utils::Stream::ALIGN_4);
|
||||
|
||||
Game::MaterialTextureDef* destTextureTable = (Game::MaterialTextureDef*)buffer->At();
|
||||
buffer->SaveArray(asset->textureTable, asset->textureCount);
|
||||
|
||||
for (char i = 0; i < asset->textureCount; i++)
|
||||
// Pointer/Offset insertion is untested, but it worked in T6, so I think it's fine
|
||||
if (builder->HasPointer(asset->textureTable))
|
||||
{
|
||||
Game::MaterialTextureDef* destTextureDef = &destTextureTable[i];
|
||||
Game::MaterialTextureDef* textureDef = &asset->textureTable[i];
|
||||
dest->textureTable = builder->GetPointer(asset->textureTable);
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer->Align(Utils::Stream::ALIGN_4);
|
||||
builder->StorePointer(asset->textureTable);
|
||||
|
||||
if (textureDef->semantic == SEMANTIC_WATER_MAP)
|
||||
Game::MaterialTextureDef* destTextureTable = (Game::MaterialTextureDef*)buffer->At();
|
||||
buffer->SaveArray(asset->textureTable, asset->textureCount);
|
||||
|
||||
for (char i = 0; i < asset->textureCount; i++)
|
||||
{
|
||||
Assert_AssetStruct(Game::water_t, 68);
|
||||
Game::MaterialTextureDef* destTextureDef = &destTextureTable[i];
|
||||
Game::MaterialTextureDef* textureDef = &asset->textureTable[i];
|
||||
|
||||
Game::water_t* destWater = (Game::water_t*)buffer->At();
|
||||
Game::water_t* water = textureDef->info.water;
|
||||
|
||||
if (water)
|
||||
if (textureDef->semantic == SEMANTIC_WATER_MAP)
|
||||
{
|
||||
buffer->Align(Utils::Stream::ALIGN_4);
|
||||
buffer->Save(water, sizeof(Game::water_t));
|
||||
destTextureDef->info.water = (Game::water_t *)-1;
|
||||
Assert_AssetStruct(Game::water_t, 68);
|
||||
|
||||
// Save_water_t
|
||||
if (water->H0X)
|
||||
Game::water_t* destWater = (Game::water_t*)buffer->At();
|
||||
Game::water_t* water = textureDef->info.water;
|
||||
|
||||
if (water)
|
||||
{
|
||||
buffer->Align(Utils::Stream::ALIGN_4);
|
||||
buffer->Save(water->H0X, 8, water->M * water->N);
|
||||
destWater->H0X = (float *)-1;
|
||||
}
|
||||
buffer->Save(water, sizeof(Game::water_t));
|
||||
destTextureDef->info.water = (Game::water_t *) - 1;
|
||||
|
||||
if (water->H0Y)
|
||||
{
|
||||
buffer->Align(Utils::Stream::ALIGN_4);
|
||||
buffer->Save(water->H0Y, 4, water->M * water->N);
|
||||
destWater->H0Y = (float *)-1;
|
||||
}
|
||||
// Save_water_t
|
||||
if (water->H0X)
|
||||
{
|
||||
buffer->Align(Utils::Stream::ALIGN_4);
|
||||
buffer->Save(water->H0X, 8, water->M * water->N);
|
||||
destWater->H0X = (float *)-1;
|
||||
}
|
||||
|
||||
if (water->image)
|
||||
{
|
||||
destWater->image = builder->RequireAsset(Game::XAssetType::ASSET_TYPE_IMAGE, water->image->name).image;
|
||||
if (water->H0Y)
|
||||
{
|
||||
buffer->Align(Utils::Stream::ALIGN_4);
|
||||
buffer->Save(water->H0Y, 4, water->M * water->N);
|
||||
destWater->H0Y = (float *)-1;
|
||||
}
|
||||
|
||||
if (water->image)
|
||||
{
|
||||
destWater->image = builder->RequireAsset(Game::XAssetType::ASSET_TYPE_IMAGE, water->image->name).image;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (textureDef->info.image)
|
||||
{
|
||||
destTextureDef->info.image = builder->RequireAsset(Game::XAssetType::ASSET_TYPE_IMAGE, textureDef->info.image->name).image;
|
||||
}
|
||||
}
|
||||
else if(textureDef->info.image)
|
||||
{
|
||||
destTextureDef->info.image = builder->RequireAsset(Game::XAssetType::ASSET_TYPE_IMAGE, textureDef->info.image->name).image;
|
||||
}
|
||||
}
|
||||
|
||||
dest->textureTable = (Game::MaterialTextureDef*)-1;
|
||||
dest->textureTable = (Game::MaterialTextureDef*) - 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (asset->constantTable)
|
||||
{
|
||||
Assert_AssetStruct(Game::MaterialConstantDef, 32);
|
||||
|
||||
buffer->Align(Utils::Stream::ALIGN_16);
|
||||
buffer->SaveArray(asset->constantTable, asset->constantCount);
|
||||
dest->constantTable = (Game::MaterialConstantDef *)-1;
|
||||
if (builder->HasPointer(asset->constantTable))
|
||||
{
|
||||
dest->constantTable = builder->GetPointer(asset->constantTable);
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer->Align(Utils::Stream::ALIGN_16);
|
||||
builder->StorePointer(asset->constantTable);
|
||||
|
||||
buffer->SaveArray(asset->constantTable, asset->constantCount);
|
||||
dest->constantTable = (Game::MaterialConstantDef *) - 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (asset->stateBitTable)
|
||||
{
|
||||
buffer->Align(Utils::Stream::ALIGN_4);
|
||||
buffer->Save(asset->stateBitTable, 8, asset->stateBitsCount);
|
||||
dest->stateBitTable = (void *)-1;
|
||||
if (builder->HasPointer(asset->stateBitTable))
|
||||
{
|
||||
dest->stateBitTable = builder->GetPointer(asset->stateBitTable);
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer->Align(Utils::Stream::ALIGN_4);
|
||||
builder->StorePointer(asset->stateBitTable);
|
||||
|
||||
buffer->Save(asset->stateBitTable, 8, asset->stateBitsCount);
|
||||
dest->stateBitTable = (void *)-1;
|
||||
}
|
||||
}
|
||||
|
||||
buffer->PopBlock();
|
||||
|
@ -60,56 +60,64 @@ namespace Assets
|
||||
|
||||
if (technique)
|
||||
{
|
||||
// Size-check is obsolete, as the structure is dynamic
|
||||
buffer->Align(Utils::Stream::ALIGN_4);
|
||||
|
||||
Game::MaterialTechnique* destTechnique = (Game::MaterialTechnique*)buffer->At();
|
||||
buffer->Save(technique, 8);
|
||||
dest->techniques[i] = (Game::MaterialTechnique*) - 1;
|
||||
|
||||
// Save_MaterialPassArray
|
||||
for (short i = 0; i < technique->numPasses; i++)
|
||||
if (builder->HasPointer(technique))
|
||||
{
|
||||
Assert_AssetStruct(Game::MaterialPass, 20);
|
||||
|
||||
Game::MaterialPass* destPass = (Game::MaterialPass*)buffer->At();
|
||||
Game::MaterialPass* pass = &technique->passes[i];
|
||||
buffer->Save(pass, sizeof(Game::MaterialPass));
|
||||
|
||||
if (pass->vertexDecl)
|
||||
{
|
||||
destPass->vertexDecl = builder->RequireAsset(Game::XAssetType::ASSET_TYPE_VERTEXDECL, pass->vertexDecl->name).vertexDecl;
|
||||
}
|
||||
|
||||
if (pass->vertexShader)
|
||||
{
|
||||
destPass->vertexShader = builder->RequireAsset(Game::XAssetType::ASSET_TYPE_VERTEXSHADER, pass->vertexShader->name).vertexShader;
|
||||
}
|
||||
|
||||
if (pass->pixelShader)
|
||||
{
|
||||
destPass->pixelShader = builder->RequireAsset(Game::XAssetType::ASSET_TYPE_PIXELSHADER, pass->pixelShader->name).pixelShader;
|
||||
}
|
||||
|
||||
if (pass->argumentDef)
|
||||
{
|
||||
buffer->Align(Utils::Stream::ALIGN_4);
|
||||
buffer->SaveArray(pass->argumentDef, pass->argCount1 + pass->argCount2 + pass->argCount3);
|
||||
destPass->argumentDef = (Game::ShaderArgumentDef*)-1;
|
||||
}
|
||||
}
|
||||
|
||||
// We absolutely have to write something here!
|
||||
if (technique->name)
|
||||
{
|
||||
buffer->SaveString(technique->name);
|
||||
dest->techniques[i] = builder->GetPointer(technique);
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer->SaveString("");
|
||||
}
|
||||
// Size-check is obsolete, as the structure is dynamic
|
||||
buffer->Align(Utils::Stream::ALIGN_4);
|
||||
builder->StorePointer(technique);
|
||||
|
||||
destTechnique->name = (char*)-1;
|
||||
Game::MaterialTechnique* destTechnique = (Game::MaterialTechnique*)buffer->At();
|
||||
buffer->Save(technique, 8);
|
||||
|
||||
// Save_MaterialPassArray
|
||||
for (short i = 0; i < technique->numPasses; i++)
|
||||
{
|
||||
Assert_AssetStruct(Game::MaterialPass, 20);
|
||||
|
||||
Game::MaterialPass* destPass = (Game::MaterialPass*)buffer->At();
|
||||
Game::MaterialPass* pass = &technique->passes[i];
|
||||
buffer->Save(pass, sizeof(Game::MaterialPass));
|
||||
|
||||
if (pass->vertexDecl)
|
||||
{
|
||||
destPass->vertexDecl = builder->RequireAsset(Game::XAssetType::ASSET_TYPE_VERTEXDECL, pass->vertexDecl->name).vertexDecl;
|
||||
}
|
||||
|
||||
if (pass->vertexShader)
|
||||
{
|
||||
destPass->vertexShader = builder->RequireAsset(Game::XAssetType::ASSET_TYPE_VERTEXSHADER, pass->vertexShader->name).vertexShader;
|
||||
}
|
||||
|
||||
if (pass->pixelShader)
|
||||
{
|
||||
destPass->pixelShader = builder->RequireAsset(Game::XAssetType::ASSET_TYPE_PIXELSHADER, pass->pixelShader->name).pixelShader;
|
||||
}
|
||||
|
||||
if (pass->argumentDef)
|
||||
{
|
||||
buffer->Align(Utils::Stream::ALIGN_4);
|
||||
buffer->SaveArray(pass->argumentDef, pass->argCount1 + pass->argCount2 + pass->argCount3);
|
||||
destPass->argumentDef = (Game::ShaderArgumentDef*) - 1;
|
||||
}
|
||||
}
|
||||
|
||||
// We absolutely have to write something here!
|
||||
if (technique->name)
|
||||
{
|
||||
buffer->SaveString(technique->name);
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer->SaveString("");
|
||||
}
|
||||
|
||||
destTechnique->name = (char*)-1;
|
||||
dest->techniques[i] = (Game::MaterialTechnique*) - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,9 @@ namespace Components
|
||||
|
||||
Discovery::Discovery()
|
||||
{
|
||||
Dvar::Register<int>("net_discoveryPortRangeMin", 25000, 0, 65535, Game::dvar_flag::DVAR_FLAG_SAVED, "Minimum scan range port for local server discovery");
|
||||
Dvar::Register<int>("net_discoveryPortRangeMax", 35000, 1, 65536, Game::dvar_flag::DVAR_FLAG_SAVED, "Maximum scan range port for local server discovery");
|
||||
|
||||
Discovery::DiscoveryContainer.Perform = false;
|
||||
Discovery::DiscoveryContainer.Terminate = false;
|
||||
Discovery::DiscoveryContainer.Thread = new std::thread([] ()
|
||||
@ -28,7 +31,9 @@ namespace Components
|
||||
Discovery::DiscoveryContainer.Challenge = Utils::VA("%d", Game::Com_Milliseconds());
|
||||
|
||||
//Network::BroadcastAll("discovery\n");
|
||||
Network::BroadcastRange(25000, 35000, Utils::VA("discovery\n%s", Discovery::DiscoveryContainer.Challenge.data()));
|
||||
unsigned int minPort = Dvar::Var("net_discoveryPortRangeMin").Get<unsigned int>();
|
||||
unsigned int maxPort = Dvar::Var("net_discoveryPortRangeMax").Get<unsigned int>();
|
||||
Network::BroadcastRange(minPort, maxPort, Utils::VA("discovery\n%s", Discovery::DiscoveryContainer.Challenge.data()));
|
||||
|
||||
Logger::Print("Discovery sent within %dms, awaiting responses...\n", Game::Com_Milliseconds() - start);
|
||||
|
||||
|
@ -42,6 +42,10 @@ namespace Components
|
||||
|
||||
return 0;
|
||||
}
|
||||
template <> unsigned int Dvar::Var::Get()
|
||||
{
|
||||
return (unsigned int)this->Get<int>();
|
||||
}
|
||||
template <> float Dvar::Var::Get()
|
||||
{
|
||||
if (this->dvar && this->dvar->type == Game::dvar_type::DVAR_TYPE_FLOAT)
|
||||
|
@ -105,6 +105,18 @@ namespace Components
|
||||
float color[4] = { 1.0f, 1.0f, 1.0f, (Game::CL_IsCgameInitialized() ? 0.3f : 1.0f) };
|
||||
Game::R_AddCmdDrawText(Utils::VA("Loading FastFile: %s", FastFiles::Current().data()), 0x7FFFFFFF, font, 5.0f, (float)(Renderer::Height() - 5), 1.0f, 1.0f, 0.0f, color, 0);
|
||||
});
|
||||
|
||||
Command::Add("loadzone", [] (Command::Params params)
|
||||
{
|
||||
if (params.Length() < 2) return;
|
||||
|
||||
Game::XZoneInfo info;
|
||||
info.name = params[1];
|
||||
info.allocFlags = 0x01000000;
|
||||
info.freeFlags = 0;
|
||||
|
||||
Game::DB_LoadXAssets(&info, 1, true);
|
||||
});
|
||||
}
|
||||
|
||||
FastFiles::~FastFiles()
|
||||
|
@ -330,6 +330,11 @@ namespace Components
|
||||
ZoneBuilder::Zone::PointerMap[pointer] = ZoneBuilder::Zone::Buffer.GetPackedOffset();
|
||||
}
|
||||
|
||||
int ZoneBuilder::Zone::AddScriptString(std::string str)
|
||||
{
|
||||
return ZoneBuilder::Zone::AddScriptString(Game::SL_GetString(str.data(), 0));
|
||||
}
|
||||
|
||||
// Mark a scriptString for writing and map it.
|
||||
int ZoneBuilder::Zone::AddScriptString(unsigned short gameIndex)
|
||||
{
|
||||
@ -405,17 +410,6 @@ namespace Components
|
||||
return (Flags::HasFlag("zonebuilder") && !Dedicated::IsDedicated());
|
||||
}
|
||||
|
||||
// TODO: Remove and replace with loadzone command
|
||||
void TestZoneLoading(Game::XZoneInfo *zoneInfo, unsigned int zoneCount, int sync)
|
||||
{
|
||||
std::vector<Game::XZoneInfo> data;
|
||||
Utils::Merge(data, zoneInfo, zoneCount);
|
||||
|
||||
data.push_back({ "penis", zoneInfo->allocFlags, zoneInfo->freeFlags });
|
||||
|
||||
Game::DB_LoadXAssets(data.data(), data.size(), sync);
|
||||
}
|
||||
|
||||
ZoneBuilder::ZoneBuilder()
|
||||
{
|
||||
static_assert(sizeof(Game::XFileHeader) == 21, "Invalid XFileHeader structure!");
|
||||
@ -449,7 +443,7 @@ namespace Components
|
||||
// Prevent destroying textures
|
||||
Utils::Hook::Set<BYTE>(0x51F03D, 0xEB);
|
||||
|
||||
Command::Add("build", [] (Command::Params params)
|
||||
Command::Add("buildzone", [] (Command::Params params)
|
||||
{
|
||||
if (params.Length() < 2) return;
|
||||
|
||||
@ -473,19 +467,5 @@ namespace Components
|
||||
}
|
||||
});
|
||||
}
|
||||
//else
|
||||
//Utils::Hook(0x4546DF, TestZoneLoading, HOOK_CALL).Install()->Quick();
|
||||
|
||||
Command::Add("loadzone", [] (Command::Params params)
|
||||
{
|
||||
if (params.Length() < 2) return;
|
||||
|
||||
Game::XZoneInfo info;
|
||||
info.name = params[1];
|
||||
info.allocFlags = 0x01000000;
|
||||
info.freeFlags = 0;
|
||||
|
||||
Game::DB_LoadXAssets(&info, 1, true);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ namespace Components
|
||||
bool LoadAsset(Game::XAssetType type, std::string name);
|
||||
|
||||
int AddScriptString(unsigned short gameIndex);
|
||||
int AddScriptString(std::string str);
|
||||
int FindScriptString(std::string str);
|
||||
|
||||
void MapScriptString(unsigned short* gameIndex);
|
||||
|
@ -121,6 +121,7 @@ namespace Game
|
||||
SetConsole_t SetConsole = (SetConsole_t)0x44F060;
|
||||
|
||||
SL_ConvertToString_t SL_ConvertToString = (SL_ConvertToString_t)0x4EC1D0;
|
||||
SL_GetString_t SL_GetString = (SL_GetString_t)0x4CDC10;
|
||||
|
||||
Steam_JoinLobby_t Steam_JoinLobby = (Steam_JoinLobby_t)0x49CF70;
|
||||
|
||||
|
@ -280,9 +280,12 @@ namespace Game
|
||||
typedef void(__cdecl * SetConsole_t)(const char* cvar, const char* value);
|
||||
extern SetConsole_t SetConsole;
|
||||
|
||||
typedef char* (__cdecl * SL_ConvertToString_t)(unsigned short);
|
||||
typedef char* (__cdecl * SL_ConvertToString_t)(unsigned short stringValue);
|
||||
extern SL_ConvertToString_t SL_ConvertToString;
|
||||
|
||||
typedef short(__cdecl * SL_GetString_t)(const char *str, unsigned int user);
|
||||
extern SL_GetString_t SL_GetString;
|
||||
|
||||
typedef void(__cdecl * Steam_JoinLobby_t)(SteamID, char);
|
||||
extern Steam_JoinLobby_t Steam_JoinLobby;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user