From 0c8664b0163bcfbbf1515498359fcb608ae47199 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Mon, 25 Jan 2021 04:02:12 +0100 Subject: [PATCH] Implement Cornerstone of the World functionality --- 3rdParty/Storm/Source/storm.h | 2 +- Source/items.cpp | 35 +++++++++++++++++++++++++++++++---- SourceX/storm/storm.cpp | 2 +- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/3rdParty/Storm/Source/storm.h b/3rdParty/Storm/Source/storm.h index f86b44b0e..6c0dab25a 100644 --- a/3rdParty/Storm/Source/storm.h +++ b/3rdParty/Storm/Source/storm.h @@ -290,7 +290,7 @@ SMemFree( bool getIniBool(const char *sectionName, const char *keyName, bool defaultValue = false); bool getIniValue(const char *sectionName, const char *keyName, char *string, int stringSize, int *dataSize = NULL); -void setIniValue(const char *sectionName, const char *keyName, char *value, int len = 0); +void setIniValue(const char *sectionName, const char *keyName, const char *value, int len = 0); BOOL STORMAPI SRegLoadValue(const char *keyname, const char *valuename, BYTE flags, int *value); BOOL STORMAPI SRegSaveValue(const char *keyname, const char *valuename, BYTE flags, DWORD result); diff --git a/Source/items.cpp b/Source/items.cpp index dd1a17ab4..337196f8a 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -3037,21 +3037,47 @@ void RecreateEar(int ii, WORD ic, int iseed, int Id, int dur, int mdur, int ch, void items_427A72() { PkItemStruct id; + char hexId[sizeof(PkItemStruct) * 2 + 1]; + BYTE *buffer; + if (CornerStone.activated) { if (CornerStone.item.IDidx >= 0) { PackItem(&id, &CornerStone.item); - setIniValue("Hellfire", off_4A5AC4, (char *)&id, 19); + buffer = (BYTE *)&id; + for (int i = 0; i < sizeof(PkItemStruct); i++) { + sprintf(&hexId[i * 2], "%02X", buffer[i]); + } + + setIniValue("Hellfire", off_4A5AC4, hexId, sizeof(hexId)); } else { - setIniValue("Hellfire", off_4A5AC4, (char *)"", 1); + setIniValue("Hellfire", off_4A5AC4, "", 1); } } } +int char2int(char input) +{ + if (input >= '0' && input <= '9') + return input - '0'; + if (input >= 'A' && input <= 'F') + return input - 'A' + 10; + return 0; +} + +void hex2bin(const char *src, int bytes, char *target) +{ + for (int i = 0; i < bytes; i++, src += 2) { + target[i] = (char2int(*src) << 4) | char2int(src[1]); + } +} + void items_427ABA(int x, int y) { int i, ii; int dwSize; PkItemStruct PkSItem; + char hexPkSItem[sizeof(PkItemStruct) * 2 + 1]; + BYTE *buffer; if (CornerStone.activated || x == 0 || y == 0) { return; @@ -3070,8 +3096,9 @@ void items_427ABA(int x, int y) dItem[x][y] = 0; } dwSize = 0; - if (getIniValue("Hellfire", off_4A5AC4, (char *)&PkSItem, sizeof(PkSItem), &dwSize)) { - if (dwSize == sizeof(PkSItem)) { + if (getIniValue("Hellfire", off_4A5AC4, hexPkSItem, sizeof(hexPkSItem), &dwSize)) { + if (dwSize >= sizeof(PkItemStruct) * 2) { + hex2bin(hexPkSItem, sizeof(PkItemStruct), (char *)&PkSItem); ii = itemavail[0]; dItem[x][y] = ii + 1; itemavail[0] = itemavail[MAXITEMS - numitems - 1]; diff --git a/SourceX/storm/storm.cpp b/SourceX/storm/storm.cpp index 9c9b1fd6c..fa7ba6f07 100644 --- a/SourceX/storm/storm.cpp +++ b/SourceX/storm/storm.cpp @@ -294,7 +294,7 @@ bool getIniValue(const char *sectionName, const char *keyName, char *string, int return true; } -void setIniValue(const char *sectionName, const char *keyName, char *value, int len) +void setIniValue(const char *sectionName, const char *keyName, const char *value, int len) { radon::File &ini = getIni();