Skip to content

Commit

Permalink
Added assignNoDestruct and game title can now be patched.
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinW1998 committed Dec 6, 2015
1 parent c31f978 commit 07ff928
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
5 changes: 4 additions & 1 deletion GameConfig/game.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ player1-controls: PLAYER 1 CONTROLS
player2-controls: PLAYER 2 CONTROLS
fullscreen-mode: FULLSCREEN MODE
windowed-mode: WINDOWED MODE
view-credits: VIEW CREDITS
view-credits: VIEW CREDITS

[general]
game-title: SMBX 1.3.0.1
10 changes: 10 additions & 0 deletions LunaDll/GameConfig/GameConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ namespace optionsMenu{
VB6StrPtr& viewCredits = *(VB6StrPtr*)0x936F72;
}

namespace general {
VB6StrPtr& gameTitle_1 = *(VB6StrPtr*)0x8BD869;
VB6StrPtr& gameTitle_2 = *(VB6StrPtr*)0x8BE25A;
VB6StrPtr& gameTitle_3 = *(VB6StrPtr*)0x96AF26;
}

void GameConfiguration::runPatchByIni(INIReader& reader)
{
if (reader.ParseError() != 0)
Expand All @@ -50,4 +56,8 @@ void GameConfiguration::runPatchByIni(INIReader& reader)
optionsMenu::windowedMode = reader.Get("option-menu", "windowed-mode", optionsMenu::windowedMode);
optionsMenu::viewCredits = reader.Get("option-menu", "view-credits", optionsMenu::viewCredits);

// References the same string memory, so do not destruct those.
general::gameTitle_1.assignNoDestruct(reader.Get("general", "game-title", general::gameTitle_1));
general::gameTitle_2.assignNoDestruct(reader.Get("general", "game-title", general::gameTitle_2));
general::gameTitle_3.assignNoDestruct(reader.Get("general", "game-title", general::gameTitle_3));
}
1 change: 0 additions & 1 deletion LunaDll/GlobalFuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,6 @@ std::wstring getLatestFile(const std::initializer_list<std::wstring>& paths)
}

if (CompareFileTime(&newest, &nextFileTime) < 0) {
std:cout << "CONFIG DEBUG: Second file is newer!" << std::endl;
memcpy(&newest, &nextFileTime, sizeof(FILETIME));
newestFileName = nextPath;
}
Expand Down
33 changes: 33 additions & 0 deletions LunaDll/Misc/VB6StrPtr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,39 @@ unsigned int VB6StrPtr::length() const
return *((unsigned int*)&((unsigned char*)ptr)[-4]) / 2;
}

void VB6StrPtr::assignNoDestruct(const VB6StrPtr & other)
{
BSTR tmp = 0;
_vbaStrCopy((VB6StrPtr*)&tmp, other.ptr);
this->ptr = tmp;
}

void VB6StrPtr::assignNoDestruct(const std::wstring & other)
{
// Allocate temporary memory of the right length so we can prefix the length header
std::size_t len = other.length();
unsigned char* tmpVBString = (unsigned char*)malloc(sizeof(unsigned int) + sizeof(wchar_t)*(len + 1));

// Copy the string data, prefixing it with the length
#pragma warning(suppress: 6011) //if we run out of memory, then it's lost anyway
*((unsigned int*)&tmpVBString[0]) = len * 2;
#pragma warning(suppress: 6011)
memcpy(&tmpVBString[4], other.c_str(), sizeof(wchar_t)*(len + 1));

// Copy the temporary string using _vbaStrCopy
BSTR tmp = 0;
_vbaStrCopy((VB6StrPtr*)&tmp, (wchar_t*)&tmpVBString[4]);
this->ptr = tmp;

// Free the temporary string
free(tmpVBString);
}

void VB6StrPtr::assignNoDestruct(const std::string & other)
{
this->assignNoDestruct(utf8_decode(other));
}

// Equality operator for VBStrPtr
bool VB6StrPtr::operator==(const VB6StrPtr &other) const
{
Expand Down
3 changes: 3 additions & 0 deletions LunaDll/Misc/VB6StrPtr.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ struct VB6StrPtr {
operator bool() const;

unsigned int length() const;
void assignNoDestruct(const VB6StrPtr& other);
void assignNoDestruct(const std::string& other);
void assignNoDestruct(const std::wstring& other);

bool operator==(const VB6StrPtr &other) const;
bool operator==(const std::wstring &other) const;
Expand Down

0 comments on commit 07ff928

Please sign in to comment.