More tests

This commit is contained in:
momo5502 2016-10-01 02:03:12 +02:00
parent 0e9de1c152
commit 8e1e179d84
4 changed files with 169 additions and 1 deletions

View File

@ -117,7 +117,7 @@ namespace Components
{
const char* name = Game::DB_GetXAssetNameHandlers[type](asset);
if (name == "props/icicle_tall_des"s)
if (name == "com_pipe_8x128_ceramic"s)
{
OutputDebugStringA("");
}

View File

@ -694,6 +694,8 @@ namespace Components
return Game::Load_Stream(atStreamStart, buffer, size);
}
Utils::Hook LoadStreamHook;
DWORD Load_Texture(Game::GfxImageLoadDef** loadDef, Game::GfxImage* image)
{
// if (!(*loadDef)->dataSize)
@ -703,6 +705,7 @@ namespace Components
if (FastFiles::Current() == "mp_cargoship_sh" || FastFiles::Current() == "mp_cargoship_sh_load")
{
LoadStreamHook.Install();
OutputDebugStringA("");
}
@ -712,6 +715,17 @@ namespace Components
return result;
}
bool LoadStream(bool atStreamStart, void* buffer, int size)
{
LoadStreamHook.Uninstall();
bool result = Game::Load_Stream(atStreamStart, buffer, size);
LoadStreamHook.Install();
OutputDebugStringA(Utils::String::VA("Loading %d bytes from stream %d at %X (%d)\n", size, *(DWORD*)0x16E5578, (DWORD)_ReturnAddress(), atStreamStart & 1));
return result;
}
void Zones::InstallPatches(int version)
{
@ -872,6 +886,8 @@ namespace Components
Utils::Hook(0x4D32A9, Load_GfxImageLoadStruct, HOOK_CALL).Install()->Quick();
Utils::Hook(0x4D32BC, Load_Texture, HOOK_CALL).Install()->Quick();
LoadStreamHook.Initialize(Game::Load_Stream, LoadStream, HOOK_JUMP);
}
Zones::~Zones()

View File

@ -86,6 +86,7 @@
#include "Utils\IO.hpp"
#include "Utils\CSV.hpp"
#include "Utils\Chain.hpp"
#include "Utils\Utils.hpp"
#include "Utils\WebIO.hpp"
#include "Utils\Memory.hpp"

151
src/Utils/Chain.hpp Normal file
View File

@ -0,0 +1,151 @@
namespace Utils
{
template <typename T>
class Chain
{
public:
class Entry
{
private:
std::shared_ptr<T> Object;
std::shared_ptr<Entry> Next;
public:
bool HasNext()
{
return (this->Next.use_count() > 0);
}
bool IsValid()
{
return (this->Object.use_count() > 0);
}
void Set(T object)
{
this->Object = std::shared_ptr<T>(new T());
*this->Object.get() = object;
}
std::shared_ptr<T> Get()
{
return this->Object;
}
Entry GetNext()
{
if (this->HasNext())
{
return *(this->Next.get());
}
else
{
return Entry();
}
}
std::shared_ptr<Entry> GetNextEntry()
{
return this->Next;
}
void SetNextEntry(std::shared_ptr<Entry> entry)
{
this->Next = entry;
}
T *operator->()
{
return (this->Object.get());
}
Entry& operator++ ()
{
*this = this->GetNext();
return *this;
}
Entry operator++ (int)
{
Entry result = *this;
this->operator++();
return result;
}
};
private:
std::mutex Mutex;
Entry Object;
public:
void Add(T object)
{
this->Mutex.lock();
if (!this->Empty())
{
// Create new chain entry
std::shared_ptr<Entry> currentObject = std::shared_ptr<Entry>(new Entry);
*currentObject.get() = this->Object;
// Add it to the chain
this->Object = Entry();
this->Object.SetNextEntry(currentObject);
}
this->Object.Set(object);
this->Mutex.unlock();
}
void Remove(std::shared_ptr<T> object)
{
this->Mutex.lock();
if (!this->Empty())
{
if (this->Object.Get().get() == object.get())
{
this->Object = this->Object.GetNext();
}
else if(this->Object.HasNext())
{
for (auto entry = this->Object; entry.IsValid(); ++entry)
{
auto next = entry.GetNext();
if (next.IsValid() && next.Get().get() == object.get())
{
*entry.GetNextEntry().get() = next.GetNext();
}
}
}
}
this->Mutex.unlock();
}
void Remove(Entry entry)
{
if (entry.IsValid())
{
this->Remove(entry.Get());
}
}
bool Empty()
{
return !this->Object.IsValid();
}
Entry Begin()
{
return this->Object;
}
void Clear()
{
this->Object = Entry();
}
};
}