mirror of
https://github.com/esuo1198/TaikoArcadeLoader.git
synced 2026-09-28 09:47:58 +03:00
Added Logger to TAL (#13)
* Added Logger for TAL with __VA_ARGS__ support * Added Tatacon entries in SDL DB * Added comments to exported config file * Included keys for LayeredFS * Cleaned up a bit of code in JPN39 patches * Formatted all files using clang-format * Force invalid cards on original readers You can now use any cards with the original namco readers. * Move helper functions to cpp file --------- Co-authored-by: ptmaster <lty2008one@163.com>
This commit is contained in:
committed by
Farewell_
co-authored by
ptmaster
parent
3933ecab00
commit
d0374dca1b
+69
-43
@@ -1,8 +1,6 @@
|
||||
#include "helpers.h"
|
||||
#include <windows.h>
|
||||
|
||||
void *consoleHandle = 0;
|
||||
|
||||
static void
|
||||
toml_myfree (void *p) {
|
||||
if (p) {
|
||||
@@ -14,13 +12,13 @@ toml_myfree (void *p) {
|
||||
toml_table_t *
|
||||
openConfig (std::filesystem::path path) {
|
||||
if (!std::filesystem::exists (path) || !path.has_filename ()) {
|
||||
printWarning ("%s (%s): file does not exist\n", __func__, path.string ().c_str ());
|
||||
LogMessage (LOG_LEVEL_WARN, (std::string (path.string ()) + ": file does not exist").c_str ());
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::ifstream stream (path);
|
||||
if (!stream.is_open ()) {
|
||||
printWarning ("%s (%s): could not open\n", __func__, path.string ().c_str ());
|
||||
LogMessage (LOG_LEVEL_WARN, ("Could not open " + std::string (path.string ())).c_str ());
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -37,7 +35,7 @@ openConfig (std::filesystem::path path) {
|
||||
free (buf);
|
||||
|
||||
if (!config) {
|
||||
printWarning ("%s (%s): %s\n", __func__, path.string ().c_str (), errorbuf);
|
||||
LogMessage (LOG_LEVEL_WARN, (path.string () + ": " + errorbuf).c_str ());
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -48,7 +46,7 @@ toml_table_t *
|
||||
openConfigSection (toml_table_t *config, const std::string §ionName) {
|
||||
toml_table_t *section = toml_table_in (config, sectionName.c_str ());
|
||||
if (!section) {
|
||||
printWarning ("%s (%s): cannot find section\n", __func__, sectionName.c_str ());
|
||||
LogMessage (LOG_LEVEL_ERROR, ("Cannot find section " + sectionName).c_str ());
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -58,33 +56,42 @@ openConfigSection (toml_table_t *config, const std::string §ionName) {
|
||||
bool
|
||||
readConfigBool (toml_table_t *table, const std::string &key, bool notFoundValue) {
|
||||
toml_datum_t data = toml_bool_in (table, key.c_str ());
|
||||
if (!data.ok) return notFoundValue;
|
||||
|
||||
if (!data.ok) {
|
||||
LogMessage (LOG_LEVEL_WARN, ("Could not find Boolean named " + key).c_str ());
|
||||
return notFoundValue;
|
||||
}
|
||||
return (bool)data.u.b;
|
||||
}
|
||||
|
||||
int64_t
|
||||
readConfigInt (toml_table_t *table, const std::string &key, int64_t notFoundValue) {
|
||||
toml_datum_t data = toml_int_in (table, key.c_str ());
|
||||
if (!data.ok) return notFoundValue;
|
||||
|
||||
if (!data.ok) {
|
||||
LogMessage (LOG_LEVEL_WARN, ("Could not find Int named " + key).c_str ());
|
||||
return notFoundValue;
|
||||
}
|
||||
return data.u.i;
|
||||
}
|
||||
|
||||
const std::string
|
||||
readConfigString (toml_table_t *table, const std::string &key, const std::string ¬FoundValue) {
|
||||
toml_datum_t data = toml_string_in (table, key.c_str ());
|
||||
if (!data.ok) return notFoundValue;
|
||||
if (!data.ok) {
|
||||
LogMessage (LOG_LEVEL_WARN, ("Could not find String named " + key).c_str ());
|
||||
return notFoundValue;
|
||||
}
|
||||
std::string str = data.u.s;
|
||||
toml_myfree (data.u.s);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
std::vector<int64_t>
|
||||
readConfigIntArray (toml_table_t *table, const std::string &key, std::vector<int64_t> notFoundValue) {
|
||||
toml_array_t *array = toml_array_in (table, key.c_str ());
|
||||
if (!array) return notFoundValue;
|
||||
if (!array) {
|
||||
LogMessage (LOG_LEVEL_WARN, ("Could not find int Array named " + key).c_str ());
|
||||
return notFoundValue;
|
||||
}
|
||||
|
||||
std::vector<int64_t> datas;
|
||||
for (int i = 0;; i++) {
|
||||
@@ -96,32 +103,17 @@ readConfigIntArray (toml_table_t *table, const std::string &key, std::vector<int
|
||||
return datas;
|
||||
}
|
||||
|
||||
void
|
||||
printColour (int colour, const char *format, ...) {
|
||||
va_list args;
|
||||
va_start (args, format);
|
||||
|
||||
if (consoleHandle == 0) consoleHandle = GetStdHandle (STD_OUTPUT_HANDLE);
|
||||
|
||||
SetConsoleTextAttribute (consoleHandle, colour);
|
||||
vprintf (format, args);
|
||||
SetConsoleTextAttribute (consoleHandle, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED);
|
||||
|
||||
va_end (args);
|
||||
}
|
||||
|
||||
std::wstring
|
||||
replace (const std::wstring orignStr, const std::wstring oldStr, const std::wstring newStr) {
|
||||
size_t pos = 0;
|
||||
std::wstring tempStr = orignStr;
|
||||
std::wstring::size_type newStrLen = newStr.length();
|
||||
std::wstring::size_type oldStrLen = oldStr.length();
|
||||
while(true)
|
||||
{
|
||||
pos = tempStr.find(oldStr, pos);
|
||||
size_t pos = 0;
|
||||
std::wstring tempStr = orignStr;
|
||||
std::wstring::size_type newStrLen = newStr.length ();
|
||||
std::wstring::size_type oldStrLen = oldStr.length ();
|
||||
while (true) {
|
||||
pos = tempStr.find (oldStr, pos);
|
||||
if (pos == std::wstring::npos) break;
|
||||
|
||||
tempStr.replace(pos, oldStrLen, newStr);
|
||||
tempStr.replace (pos, oldStrLen, newStr);
|
||||
pos += newStrLen;
|
||||
}
|
||||
|
||||
@@ -130,18 +122,52 @@ replace (const std::wstring orignStr, const std::wstring oldStr, const std::wstr
|
||||
|
||||
std::string
|
||||
replace (const std::string orignStr, const std::string oldStr, const std::string newStr) {
|
||||
size_t pos = 0;
|
||||
std::string tempStr = orignStr;
|
||||
std::string::size_type newStrLen = newStr.length();
|
||||
std::string::size_type oldStrLen = oldStr.length();
|
||||
while(true)
|
||||
{
|
||||
pos = tempStr.find(oldStr, pos);
|
||||
size_t pos = 0;
|
||||
std::string tempStr = orignStr;
|
||||
std::string::size_type newStrLen = newStr.length ();
|
||||
std::string::size_type oldStrLen = oldStr.length ();
|
||||
while (true) {
|
||||
pos = tempStr.find (oldStr, pos);
|
||||
if (pos == std::string::npos) break;
|
||||
|
||||
tempStr.replace(pos, oldStrLen, newStr);
|
||||
tempStr.replace (pos, oldStrLen, newStr);
|
||||
pos += newStrLen;
|
||||
}
|
||||
|
||||
return tempStr;
|
||||
}
|
||||
|
||||
const char *
|
||||
GameVersionToString (GameVersion version) {
|
||||
switch (version) {
|
||||
case GameVersion::JPN00: return "JPN00";
|
||||
case GameVersion::JPN08: return "JPN08";
|
||||
case GameVersion::JPN39: return "JPN39";
|
||||
case GameVersion::CHN00: return "CHN00";
|
||||
default: return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
const char *
|
||||
languageStr (int language) {
|
||||
switch (language) {
|
||||
case 1: return "en_us";
|
||||
case 2: return "cn_tw";
|
||||
case 3: return "kor";
|
||||
case 4: return "cn_cn";
|
||||
default: return "jpn";
|
||||
}
|
||||
}
|
||||
|
||||
std::string
|
||||
ConvertWideToUtf8 (const std::wstring &wstr) {
|
||||
std::wstring_convert<std::codecvt_utf8<wchar_t> > converter;
|
||||
return converter.to_bytes (wstr);
|
||||
}
|
||||
|
||||
bool
|
||||
AreAllBytesZero (const uint8_t *array, size_t offset, size_t length) {
|
||||
for (size_t i = 0; i < length; ++i)
|
||||
if (array[offset + i] != 0x00) return false;
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user