Skip to content

Commit

Permalink
Restructuring and rewriting
Browse files Browse the repository at this point in the history
  • Loading branch information
surilindur committed Jan 12, 2024
1 parent 3b038af commit 2164685
Show file tree
Hide file tree
Showing 12 changed files with 600 additions and 626 deletions.
4 changes: 2 additions & 2 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"forcedInclude": [
"/usr/include/wine/windows/windows.h",
"/usr/include/wine/windows/basetsd.h",
"${workspaceFolder}/confse/winefixes.h",
"${workspaceFolder}/xobse/obse/obse_common/obse_version.h"
],
"defines": [
Expand All @@ -21,7 +20,8 @@
"_WINDOWS",
"_USRDLL",
"OBLIVION_VERSION=0x010201A0",
"OBLIVION"
"OBLIVION",
"WINE_WINTYPES_WORKAROUND"
],
"compilerPath": "/bin/clang++",
"cStandard": "c17",
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<a href="https://opensource.org/licenses/MIT"><img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-blue.svg"></a>
</p>

**ConfSE** is an experimental [Oblivion Script Extender](/llde/xOBSE) (OBSE) plugin that aims to enable the loading and saving of JSON files from within Oblivion scripts. This is accomplished through the use of OBSE's `array_var` data type, that be either an array or map. The plugin uses [an existing JSON library for C++](https://github.com/nlohmann/json) together with some simple Oblivion-specific type conversions.
**ConfSE** is an experimental [Oblivion Script Extender](https://github.com/llde/xOBSE) (OBSE) plugin that aims to enable the loading and saving of JSON files from within Oblivion scripts. This is accomplished through the use of OBSE's `array_var` data type, that be either an array or map. The plugin uses [an existing JSON library for C++](https://github.com/nlohmann/json) together with some simple Oblivion-specific type conversions.

The following type conversions are performed.

Expand All @@ -26,8 +26,8 @@ The design goal of the plugin is to offer a straightforward mapping from OBSE's

This project depends on the following external projects and libraries:

* [**Oblivion Script Extender**](/llde/xOBSE) as the targeted OBSE version
* [**JSON for Modern C++**](/nlohmann/json) as the JSON library used to load and save files
* [**Oblivion Script Extender**](https://github.com/llde/xOBSE) as the targeted OBSE version
* [**JSON for Modern C++**](https://github.com/nlohmann/json) as the JSON library used to load and save files
* **MSBuild** for building the plugin project

The latest compiled DLL at a given time should be available from the GitHub Actions artifacts for the CI workflow.
Expand Down
323 changes: 323 additions & 0 deletions confse/commands.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,323 @@
#include "obse/GameForms.h"
#include "obse/PluginAPI.h"
#include "obse/GameAPI.h"

#include "definitions.hpp"
#include "converters.hpp"
#include "jsonutils.hpp"

static bool get_string(COMMAND_ARGS)
{
char filename[ARG_MAX_CHARS], key[ARG_MAX_CHARS], default_return[ARG_MAX_CHARS];

if (ExtractArgs(PASS_EXTRACT_ARGS, &filename, &key, &default_return))
{
std::string temp_str(default_return);
objson::jsonfile json_file(filename);
json_file.get_entry(key, temp_str);
kOBSEStringVar->Assign(PASS_COMMAND_ARGS, temp_str.c_str());
*result = 0;
return true;
}

return false;
}

static bool set_string(COMMAND_ARGS)
{
char filename[ARG_MAX_CHARS], key[ARG_MAX_CHARS], value[ARG_MAX_CHARS];

if (ExtractArgs(PASS_EXTRACT_ARGS, &filename, &key, &value))
{
objson::jsonfile json_file(filename);
json_file.set_entry(key, value);
json_file.flush_to_disk();
*result = 0;
return true;
}

return false;
}

static bool get_int(COMMAND_ARGS)
{
char filename[ARG_MAX_CHARS], key[ARG_MAX_CHARS];
UInt32 default_return = 0;

if (ExtractArgs(PASS_EXTRACT_ARGS, &filename, &key, &default_return))
{
objson::jsonfile json_file(filename);
json_file.get_entry(key, default_return);
*result = default_return;
return true;
}

return false;
}

static bool set_int(COMMAND_ARGS)
{
char filename[ARG_MAX_CHARS], key[ARG_MAX_CHARS];
UInt32 value;

if (ExtractArgs(PASS_EXTRACT_ARGS, &filename, &key, &value))
{
objson::jsonfile json_file(filename);
json_file.set_entry(key, value);
json_file.flush_to_disk();
*result = 0;
return true;
}

return false;
}

static bool get_float(COMMAND_ARGS)
{
char filename[ARG_MAX_CHARS], key[ARG_MAX_CHARS];
float default_return;

if (ExtractArgs(PASS_EXTRACT_ARGS, &filename, &key, &default_return))
{
objson::jsonfile json_file(filename);
json_file.get_entry(key, default_return);
*result = default_return;
return true;
}

return false;
}

static bool set_float(COMMAND_ARGS)
{
char filename[ARG_MAX_CHARS], key[ARG_MAX_CHARS];
float value;

if (ExtractArgs(PASS_EXTRACT_ARGS, &filename, &key, &value))
{
objson::jsonfile json_file(filename);
json_file.set_entry(key, value);
json_file.flush_to_disk();
*result = 0;
return true;
}

return false;
}

static bool get_form(COMMAND_ARGS)
{
char filename[ARG_MAX_CHARS], key[ARG_MAX_CHARS];
TESForm *default_return;

if (ExtractArgsEx(PASS_EXTRACT_ARGS_EX, &filename, &key, &default_return))
{
(UInt32 *)result = default_return->refID;
std::string temp_str("");
objson::jsonfile json_file(filename);
json_file.get_entry(key, temp_str);
string_to_form_id(temp_str, (UInt32 *)result);
return true;
}

return false;
}

static bool set_form(COMMAND_ARGS)
{
char filename[ARG_MAX_CHARS], key[ARG_MAX_CHARS];
TESForm *value;

if (ExtractArgsEx(PASS_EXTRACT_ARGS_EX, &filename, &key, &value))
{
objson::jsonfile json_file(filename);
json_file.set_entry(key, form_to_string(value));
json_file.flush_to_disk();
*result = 0;
return true;
}

return false;
}

static bool erase_key(COMMAND_ARGS)
{
char filename[ARG_MAX_CHARS], key[ARG_MAX_CHARS];

if (ExtractArgs(PASS_EXTRACT_ARGS, &filename, &key))
{
objson::jsonfile json_file(filename);
json_file.remove_entry(key);
json_file.flush_to_disk();
*result = 0;
return true;
}

return false;
}

static bool list_keys(COMMAND_ARGS)
{
char filename[ARG_MAX_CHARS], key[ARG_MAX_CHARS];

if (ExtractArgs(PASS_EXTRACT_ARGS, &filename, &key))
{
objson::jsonfile json_file(filename);
std::vector<std::string> key_list;
json_file.list_keys(key, key_list);
OBSEArray *obse_array = vector_to_array(key_list, scriptObj);
kOBSEArrayVar->AssignCommandResult(obse_array, result);
*result = 0;
return true;
}

return false;
}

ParamInfo params_get_string[3] = {
{"Filename", kParamType_String, 0},
{"Key", kParamType_String, 0},
{"Default", kParamType_String, 0}};

ParamInfo params_set_string[3] = {
{"Filename", kParamType_String, 0},
{"Key", kParamType_String, 0},
{"Value", kParamType_String, 0}};

ParamInfo params_get_int[3] = {
{"Filename", kParamType_String, 0},
{"Key", kParamType_String, 0},
{"Default", kParamType_Integer, 0}};

ParamInfo params_set_int[3] = {
{"Filename", kParamType_String, 0},
{"Key", kParamType_String, 0},
{"Value", kParamType_Integer, 0}};

ParamInfo params_get_float[3] = {
{"Filename", kParamType_String, 0},
{"Key", kParamType_String, 0},
{"Default", kParamType_Float, 0}};

ParamInfo params_set_float[3] = {
{"Filename", kParamType_String, 0},
{"Key", kParamType_String, 0},
{"Value", kParamType_Float, 0}};

ParamInfo params_get_form[3] = {
{"Filename", kParamType_String, 0},
{"Key", kParamType_String, 0},
{"Default", kOBSEParamType_Form, 0}};

ParamInfo params_set_form[3] = {
{"Filename", kParamType_String, 0},
{"Key", kParamType_String, 0},
{"Value", kOBSEParamType_Form, 0}};

ParamInfo params_erase_key[2] = {
{"Filename", kParamType_String, 0},
{"Key", kParamType_String, 0}};

ParamInfo params_list_keys[2] = {
{"Filename", kParamType_String, 0},
{"KeyPath", kParamType_String, 0}};

CommandInfo commandinfo_get_string = {
"JsonGetString",
"",
0,
"Read string value from JSON",
0,
3,
params_get_string,
get_string};

CommandInfo commandinfo_set_string = {
"JsonSetString",
"",
0,
"Write string value to JSON",
0,
3,
params_set_string,
set_string};

CommandInfo commandinfo_get_int = {
"JsonGetInt",
"",
0,
"Read integer value from JSON",
0,
3,
params_get_int,
get_int};

CommandInfo commandinfo_set_int = {
"JsonSetInt",
"",
0,
"Write integer value to JSON",
0,
3,
params_set_int,
set_int};

CommandInfo commandinfo_get_float = {
"JsonGetFloat",
"",
0,
"Read floating point value from JSON",
0,
3,
params_get_float,
get_float};

CommandInfo commandinfo_set_float = {
"JsonSetFloat",
"",
0,
"Write floating point value to JSON",
0,
3,
params_set_float,
set_float};

CommandInfo commandinfo_get_form = {
"JsonGetForm",
"",
0,
"Read form value from JSON",
0,
3,
params_get_form,
get_form};

CommandInfo commandinfo_set_form = {
"JsonSetForm",
"",
0,
"Write form value to JSON",
0,
3,
params_set_form,
set_form};

CommandInfo commandinfo_erase_key = {
"JsonEraseKey",
"",
0,
"Erase key and value from JSON",
0,
2,
params_erase_key,
erase_key};

CommandInfo commandinfo_list_keys = {
"JsonListKeys",
"",
0,
"List all keys in a key path in JSON",
0,
2,
params_list_keys,
list_keys};
Loading

0 comments on commit 2164685

Please sign in to comment.