Skip to content

Commit

Permalink
Fixed issue with savegame screenshots not updating when overwriting o…
Browse files Browse the repository at this point in the history
…ld ones
  • Loading branch information
DMD authored and DMD committed Sep 30, 2016
1 parent 1b3dea2 commit daa05e3
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions Infrastructure/include/graphics/textures.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ namespace gfx {
void FreeAllTextures();

gfx::TextureRef Resolve(const std::string& filename, bool withMipMaps);
gfx::TextureRef Override(const std::string& filename, bool withMipMaps);

gfx::TextureRef ResolveUncached(const std::string& filename, bool withMipMaps);

Expand Down
32 changes: 32 additions & 0 deletions Infrastructure/src/graphics/textures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,38 @@ gfx::TextureRef Textures::Resolve(const std::string& filename, bool withMipMaps)

}

gfx::TextureRef Textures::Override(const std::string & filename, bool withMipMaps)
{
auto filenameLower = tolower(filename);

auto it = mTexturesByName.find(filenameLower);
auto id = -1;
if (it != mTexturesByName.end()) {
//return it->second;
id = it->second.get()->GetId();
}

// Texture is not registered yet, so let's do that
if (!vfs->FileExists(filename)) {
logger->error("Cannot register texture '{}', because it does not exist.", filename);
auto result = Texture::GetInvalidTexture();
mTexturesByName[filenameLower] = result;
return result;
}

if (id == -1)
id = mNextFreeId++;

auto texture(std::make_shared<FileTexture>(mLoader, id, filename));

//Expects(mTexturesByName.find(filenameLower) == mTexturesByName.end());
//Expects(mTexturesById.find(id) == mTexturesById.end());
mTexturesByName[filenameLower] = texture;
mTexturesById[id] = texture;

return texture;
}

gfx::TextureRef Textures::ResolveUncached(const std::string & filename, bool withMipMaps)
{
// Texture is not registered yet, so let's do that
Expand Down
4 changes: 4 additions & 0 deletions TemplePlus/gamesystems/gamelib_save.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <tio/tio.h>
#include "gamesystem.h"
#include "util/savegame.h"
#include <tig/tig_texture.h>

struct GsiData {
string filename;
Expand Down Expand Up @@ -246,16 +247,19 @@ bool GameSystems::SaveGame(const string& filename, const string& displayName) {

// Rename screenshots
auto screenDestName = format("save\\{}l.jpg", filename);
int textId;
if (tio_fileexists(screenDestName.c_str())) {
tio_remove(screenDestName.c_str());
}
tio_rename("save\\templ.jpg", screenDestName.c_str());
textureFuncs.RegisterTextureOverride(screenDestName.c_str(), &textId); // override previous texture if any

screenDestName = format("save\\{}s.jpg", filename);
if (tio_fileexists(screenDestName.c_str())) {
tio_remove(screenDestName.c_str());
}
tio_rename("save\\temps.jpg", screenDestName.c_str());
textureFuncs.RegisterTextureOverride(screenDestName.c_str(), &textId);

// co8 savehook
auto saveHookArgs = Py_BuildValue("(s)", filename.c_str());
Expand Down
20 changes: 20 additions & 0 deletions TemplePlus/tig/tig_texture.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@

#include "stdafx.h"
#include "tig_texture.h"
#include <tio/tio.h>
#include "tig_startup.h"
#include <graphics/textures.h>
#include <graphics/device.h>

TextureFuncs textureFuncs;
IdxTableWrapper<TigTextureRegistryEntry> textureRegistry(0x10EF2E90);

int TextureFuncs::RegisterTextureOverride(const char * filename, int * textIdOut){

auto& textures = tig->GetRenderingDevice().GetTextures();
auto ref = textures.Override(filename, false);

if (!ref->IsValid()) {
*textIdOut = -1;
logger->error("Unable to register texture {}", filename);
return 17;
}

*textIdOut = ref->GetId();

return 0;
}
2 changes: 2 additions & 0 deletions TemplePlus/tig/tig_texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ struct TextureFuncs : temple::AddressTable {
*/
int (__cdecl *LoadTexture)(int textureId, TigTextureRegistryEntry *pTextureOut);

int RegisterTextureOverride(const char* filename, int * textIdOut);

TextureFuncs() {
rebase(CreateBuffer, 0x101DCE50);
rebase(RegisterTexture, 0x101EE7B0);
Expand Down
Binary file modified tpdata/tpgamefiles.dat
Binary file not shown.

0 comments on commit daa05e3

Please sign in to comment.