126 FileStream reader{path};
131 reader.seek_in(31).read(this->
version);
133 const auto sequenceCount = reader.read<uint32_t>();
134 for (uint32_t s = 0; s < sequenceCount; s++) {
135 auto& [seqName, seqCommands] = this->
sequences.emplace_back();
136 seqName = reader.read_string(128);
138 const auto commandCount = reader.read<uint32_t>();
139 for (uint32_t c = 0; c < commandCount; c++) {
140 auto& [enabled, special, executable, arguments, ensureFileExists, pathToTheoreticallyExistingFile, useProcessWindow, waitForKeypress] = seqCommands.emplace_back();
141 enabled = reader.read<int32_t>() & 0xFF;
146 executable = reader.read_string(260);
147 arguments = reader.read_string(260);
148 reader.skip_in<int32_t>();
149 ensureFileExists = reader.read<int32_t>();
150 pathToTheoreticallyExistingFile = reader.read_string(260);
151 useProcessWindow = reader.read<int32_t>();
153 waitForKeypress = reader.read<int32_t>();
163 for (
const auto& kvSequence : cmdSeq[
"Command Sequences"].getChildren()) {
164 auto& [seqName, seqCommands] = this->
sequences.emplace_back();
165 seqName = kvSequence.getKey();
167 for (
const auto& kvCommand : kvSequence.getChildren()) {
168 auto& [enabled, special, executable, arguments, ensureFileExists, pathToTheoreticallyExistingFile, useProcessWindow, waitForKeypress] = seqCommands.emplace_back();
170 const auto specialCmd = kvCommand[
"special_cmd"].getValue();
172 string::toInt(specialCmd,
reinterpret_cast<std::underlying_type_t<Command::Special>&
>(special));
177 special = ::specialCmdFromString(specialCmd);
179 executable = kvCommand[
"run"].getValue();
180 arguments = kvCommand[
"params"].getValue();
181 string::toBool(kvCommand[
"ensure_check"].getValue(), ensureFileExists);
182 pathToTheoreticallyExistingFile = kvCommand[
"ensure_fn"].getValue();
183 string::toBool(kvCommand[
"use_process_wnd"].getValue(), useProcessWindow);
198 std::vector<std::byte> out;
199 BufferStream writer{out};
202 .write(
"Worldcraft Command Sequences\r\n\x1a", 31)
206 for (
const auto& [seqName, seqCommands] : this->
getSequences()) {
208 .write(seqName,
true, 128)
209 .write<uint32_t>(seqCommands.size());
211 for (
const auto& [enabled, special, executable, arguments, ensureFileExists, pathToTheoreticallyExistingFile, useProcessWindow, waitForKeypress] : seqCommands) {
213 .write<uint32_t>(enabled)
215 .write(executable,
true, 260)
216 .write(arguments,
true, 260)
217 .write<uint32_t>(
true)
218 .write<uint32_t>(ensureFileExists)
219 .write(pathToTheoreticallyExistingFile,
true, 260)
220 .write<uint32_t>(useProcessWindow);
223 writer.write<uint32_t>(waitForKeypress);
228 out.resize(writer.size());
234 auto& kvFile = kv.
addChild(
"Command Sequences");
235 for (
const auto& [seqName, seqCommands] : this->
getSequences()) {
236 auto& kvSequence = kvFile.addChild(seqName);
237 for (
int i = 1; i <= seqCommands.size(); i++) {
238 const auto& [enabled, special, executable, arguments, ensureFileExists, pathToTheoreticallyExistingFile, useProcessWindow, waitForKeypress] = seqCommands[i - 1];
239 auto& kvCommand = kvSequence.addChild(std::to_string(i));
240 kvCommand[
"enabled"] = enabled;
241 kvCommand[
"special_cmd"] =
static_cast<int>(special);
242 kvCommand[
"run"] = executable;
243 kvCommand[
"params"] = arguments;
244 kvCommand[
"ensure_check"] = ensureFileExists;
245 kvCommand[
"ensure_fn"] = pathToTheoreticallyExistingFile;
246 kvCommand[
"use_process_wnd"] = useProcessWindow;
247 kvCommand[
"no_wait"] = waitForKeypress;
251 const auto kvStr = kv.
bake();
252 std::vector<std::byte> out;
253 out.resize(kvStr.length());
254 std::memcpy(out.data(), kvStr.data(), kvStr.length());
bool isNumber(char c)
If a char is a numerical character (0-9).