-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
13a7f3b
commit 7c59629
Showing
7 changed files
with
174 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include <sstream> | ||
|
||
#include "IDMap.h" | ||
#include "file/FileSystem.h" | ||
|
||
cdc::IDMap::IDMap(const char* fileName, cdc::FileSystem* fileSystem) : m_map() | ||
{ | ||
auto buffer = FSHelper_ReadFile(fileName, fileSystem); | ||
|
||
if (buffer) | ||
{ | ||
std::istringstream stream(buffer); | ||
|
||
unsigned int unk, count; | ||
|
||
// Read the header | ||
stream >> unk; | ||
stream.ignore(1); | ||
stream >> count; | ||
|
||
std::string line; | ||
std::getline(stream, line); | ||
|
||
// Read all lines | ||
for (unsigned int i = 0; i < count; i++) | ||
{ | ||
int id; | ||
|
||
stream >> id; | ||
stream.ignore(1); | ||
|
||
std::getline(stream, line); | ||
|
||
// Strip any extra values | ||
line = line.substr(0, line.find(",")); | ||
|
||
// Allocate new string | ||
auto name = new char[line.size() + 1]; | ||
strcpy(name, line.c_str()); | ||
|
||
m_map.insert({ id, name }); | ||
} | ||
|
||
// Clean up | ||
delete buffer; | ||
} | ||
} | ||
const char* cdc::IDMap::GetName(unsigned int id) | ||
{ | ||
auto name = m_map.find(id); | ||
|
||
if (name == m_map.end()) | ||
{ | ||
return ""; | ||
} | ||
|
||
return name->second; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#pragma once | ||
|
||
#include <unordered_map> | ||
|
||
#include "cdc/file/FileSystem.h" | ||
|
||
namespace cdc | ||
{ | ||
class IDMap | ||
{ | ||
private: | ||
std::unordered_map<unsigned int, const char*> m_map; | ||
|
||
public: | ||
IDMap(const char* fileName, cdc::FileSystem* fileSystem); | ||
|
||
const char* GetName(unsigned int id); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include "FileReceivers.h" | ||
#include <cstring> | ||
|
||
FileUserBufferReceiver::FileUserBufferReceiver(char* buffer) : m_buffer(buffer) | ||
{ | ||
} | ||
|
||
int FileUserBufferReceiver::ReceiveData(const char* data, unsigned int dataSize, unsigned int requestOffset) | ||
{ | ||
memcpy(&m_buffer[requestOffset], data, dataSize); | ||
return dataSize; | ||
} | ||
|
||
void FileUserBufferReceiver::ReceiveStarted(cdc::FileRequest* request, unsigned int requestSize) | ||
{ | ||
} | ||
|
||
void FileUserBufferReceiver::ReceiveCancelled(cdc::FileRequest* request) | ||
{ | ||
} | ||
|
||
void FileUserBufferReceiver::ReceiveDone(cdc::FileRequest* request) | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#pragma once | ||
|
||
#include "cdc/file/FileSystem.h" | ||
|
||
class FileUserBufferReceiver : public cdc::FileReceiver | ||
{ | ||
private: | ||
char* m_buffer; | ||
|
||
public: | ||
FileUserBufferReceiver(char* buffer); | ||
|
||
int ReceiveData(const char* data, unsigned int dataSize, unsigned int requestOffset); | ||
void ReceiveStarted(cdc::FileRequest* request, unsigned int requestSize); | ||
void ReceiveCancelled(cdc::FileRequest* request); | ||
void ReceiveDone(cdc::FileRequest* request); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,32 @@ | ||
#include "FileSystem.h" | ||
#include "FileReceivers.h" | ||
#include "util/Hooking.h" | ||
|
||
cdc::FileSystem* GetFS() | ||
{ | ||
auto addr = GET_ADDRESS(0x45C700, 0x45F640, 0x472B50); | ||
|
||
return Hooking::CallReturn<cdc::FileSystem*>(addr); | ||
} | ||
|
||
char* FSHelper_ReadFile(const char* fileName, cdc::FileSystem* fileSystem) | ||
{ | ||
auto size = fileSystem->GetFileSize(fileName); | ||
auto buffer = new char[size + 1]; | ||
|
||
auto receiver = new FileUserBufferReceiver(buffer); | ||
auto request = fileSystem->RequestRead(receiver, fileName, 0); | ||
|
||
if (request) | ||
{ | ||
request->Submit(cdc::FileRequest::HIGH); | ||
fileSystem->Synchronize(); | ||
|
||
// Null terminate the buffer | ||
buffer[size] = 0; | ||
|
||
return buffer; | ||
} | ||
|
||
return nullptr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters