1116 lines
46 KiB
C++
1116 lines
46 KiB
C++
#include "player_settings.h"
|
|
#include "python_app.h"
|
|
#include "server_clock.h"
|
|
#include "generated_app_constants.h"
|
|
#include "../upstream/ava2-client/UserInterface/Locale_inc.h"
|
|
#include "src/eter_image/MarkManager.h"
|
|
#include "nonplayer_data.h"
|
|
#include "eter_net/NetworkActorManager.h"
|
|
#include "eter_render/RaceData.h"
|
|
#include "pet_skill_state.h"
|
|
#include "python_gameplay_modules.h"
|
|
#include "python_native_modules.h"
|
|
#include "python_net.h"
|
|
#include "python_runtime.h"
|
|
#include "ava2_text_file.h"
|
|
#include "python_wiki.h"
|
|
#include "shared/common/PythonUtils.h"
|
|
#include "eter_base/Random.h"
|
|
#include "eter_base/Timer.h"
|
|
#include "python_background.h"
|
|
#include "eter_ui/PythonWindowManager.h"
|
|
#include "eter_effect/EffectManager.h"
|
|
#include "eter_effect/FlyingManager.h"
|
|
#include <fstream>
|
|
#include <iostream>
|
|
#include <Python.h>
|
|
#include <chrono>
|
|
#include <utility>
|
|
#include <string>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
#include <thread>
|
|
#include <cstring>
|
|
#include <filesystem>
|
|
#include "eter_resource/ResourceManager.h"
|
|
|
|
namespace ava2 {
|
|
namespace {
|
|
|
|
std::uint32_t local_milliseconds() { return static_cast<std::uint32_t>(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count()); }
|
|
std::int64_t unix_seconds() { return std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count(); }
|
|
ServerClock server_clock(local_milliseconds());
|
|
// EterBase Timer.cpp gs_dwServerTime / gs_dwClientTime (ELTimer_*ServerMSec), separate from app.GetGlobalTime.
|
|
std::uint32_t elt_server_time=0,elt_client_time=0;
|
|
auto app_start=std::chrono::steady_clock::now();
|
|
float s_camera_distance = 1500.0f;
|
|
float s_camera_pitch = 30.0f;
|
|
float s_camera_rotation = 0.0f;
|
|
float s_camera_height = 180.0f;
|
|
float s_camera_max_distance = 2500.0f;
|
|
int s_camera_speed = 100;
|
|
float s_camera_rotate_speed = 1.0f;
|
|
float s_camera_pitch_speed = 1.0f;
|
|
float s_camera_zoom_speed = 0.05f;
|
|
bool s_special_camera_mode = false;
|
|
bool s_hair_specular = false;
|
|
bool s_armor_specular = false;
|
|
bool s_weapon_specular = false;
|
|
int twoHandedAttackSpeedDecrease=0;
|
|
PyObject* set_twohand_decrease(PyObject*,PyObject* args){int value;if(!PyArg_ParseTuple(args,"i",&value))return nullptr;twoHandedAttackSpeedDecrease=value;Py_RETURN_NONE;}
|
|
std::string s_locale_service_name = "EUROPE";
|
|
std::string s_locale_name = "en";
|
|
std::string s_locale_path = "locale/en";
|
|
|
|
bool s_test_server_flag=false;
|
|
PyObject* app_enable_test_server(PyObject*,PyObject*) { s_test_server_flag=true;Py_RETURN_NONE; }
|
|
PyObject* app_is_test_server(PyObject*,PyObject*) { return PyInt_FromLong(s_test_server_flag); }
|
|
|
|
PyObject* app_get_time(PyObject*, PyObject*) {
|
|
float sec=std::chrono::duration<float>(std::chrono::steady_clock::now()-app_start).count();
|
|
return PyFloat_FromDouble(sec);
|
|
}
|
|
|
|
PyObject* app_get_global_time(PyObject*, PyObject*) {
|
|
return PyInt_FromLong(server_clock.milliseconds(local_milliseconds()));
|
|
}
|
|
|
|
PyObject* app_get_global_timestamp(PyObject*, PyObject*) {
|
|
return PyInt_FromLong(server_clock.timestamp(unix_seconds()));
|
|
}
|
|
|
|
PyObject* app_set_camera(PyObject*, PyObject* args) {
|
|
float Distance = 0.0f, Pitch = 0.0f, Rotation = 0.0f, DestinationHeight = 0.0f;
|
|
if (!PyTuple_GetFloat(args, 0, &Distance) ||
|
|
!PyTuple_GetFloat(args, 1, &Pitch) ||
|
|
!PyTuple_GetFloat(args, 2, &Rotation) ||
|
|
!PyTuple_GetFloat(args, 3, &DestinationHeight)) {
|
|
return Py_BuildException();
|
|
}
|
|
s_camera_distance = Distance;
|
|
s_camera_pitch = Pitch;
|
|
s_camera_rotation = Rotation;
|
|
s_camera_height = DestinationHeight;
|
|
return Py_BuildNone();
|
|
}
|
|
|
|
PyObject* app_get_camera(PyObject*, PyObject*) {
|
|
return Py_BuildValue("ffff", s_camera_distance, s_camera_pitch, s_camera_rotation, s_camera_height);
|
|
}
|
|
|
|
PyObject* app_get_camera_pitch(PyObject*, PyObject*) {
|
|
return Py_BuildValue("f", s_camera_pitch);
|
|
}
|
|
|
|
PyObject* app_get_camera_rotation(PyObject*, PyObject*) {
|
|
return Py_BuildValue("f", s_camera_rotation);
|
|
}
|
|
|
|
PyObject* app_rotate_camera(PyObject*, PyObject* args) {
|
|
int iDirection = 0;
|
|
if (!PyTuple_GetInteger(args, 0, &iDirection))
|
|
return Py_BuildException();
|
|
s_camera_rotation += s_camera_rotate_speed * static_cast<float>(iDirection);
|
|
return Py_BuildNone();
|
|
}
|
|
|
|
PyObject* app_pitch_camera(PyObject*, PyObject* args) {
|
|
int iDirection = 0;
|
|
if (!PyTuple_GetInteger(args, 0, &iDirection))
|
|
return Py_BuildException();
|
|
s_camera_pitch += s_camera_pitch_speed * static_cast<float>(iDirection);
|
|
return Py_BuildNone();
|
|
}
|
|
|
|
PyObject* app_zoom_camera(PyObject*, PyObject* args) {
|
|
int iDirection = 0;
|
|
if (!PyTuple_GetInteger(args, 0, &iDirection))
|
|
return Py_BuildException();
|
|
s_camera_distance *= (1.0f + s_camera_zoom_speed * static_cast<float>(iDirection));
|
|
if (s_camera_distance > s_camera_max_distance) s_camera_distance = s_camera_max_distance;
|
|
if (s_camera_distance < 100.0f) s_camera_distance = 100.0f;
|
|
return Py_BuildNone();
|
|
}
|
|
|
|
PyObject* app_movie_rotate_camera(PyObject*, PyObject* args) {
|
|
int iDirection = 0;
|
|
if (!PyTuple_GetInteger(args, 0, &iDirection))
|
|
return Py_BuildException();
|
|
s_camera_rotation += s_camera_rotate_speed * static_cast<float>(iDirection);
|
|
return Py_BuildNone();
|
|
}
|
|
|
|
PyObject* app_movie_pitch_camera(PyObject*, PyObject* args) {
|
|
int iDirection = 0;
|
|
if (!PyTuple_GetInteger(args, 0, &iDirection))
|
|
return Py_BuildException();
|
|
s_camera_pitch += s_camera_pitch_speed * static_cast<float>(iDirection);
|
|
return Py_BuildNone();
|
|
}
|
|
|
|
PyObject* app_movie_zoom_camera(PyObject*, PyObject* args) {
|
|
int iDirection = 0;
|
|
if (!PyTuple_GetInteger(args, 0, &iDirection))
|
|
return Py_BuildException();
|
|
s_camera_distance *= (1.0f + s_camera_zoom_speed * static_cast<float>(iDirection));
|
|
return Py_BuildNone();
|
|
}
|
|
|
|
PyObject* app_movie_reset_camera(PyObject*, PyObject*) {
|
|
return Py_BuildNone();
|
|
}
|
|
|
|
PyObject* app_set_camera_speed(PyObject*, PyObject* args) {
|
|
int iPercentage = 0;
|
|
if (!PyTuple_GetInteger(args, 0, &iPercentage))
|
|
return Py_BuildException();
|
|
s_camera_speed = iPercentage;
|
|
return Py_BuildNone();
|
|
}
|
|
|
|
PyObject* app_set_camera_max_distance(PyObject*, PyObject* args) {
|
|
float fMax = 0.0f;
|
|
if (!PyTuple_GetFloat(args, 0, &fMax))
|
|
return Py_BuildException();
|
|
s_camera_max_distance = fMax;
|
|
return Py_BuildNone();
|
|
}
|
|
|
|
PyObject* app_set_camera_setting(PyObject*, PyObject* args) {
|
|
int ix = 0, iy = 0, iz = 0, iZoom = 0, iRotation = 0, iPitch = 0;
|
|
if (!PyTuple_GetInteger(args, 0, &ix) ||
|
|
!PyTuple_GetInteger(args, 1, &iy) ||
|
|
!PyTuple_GetInteger(args, 2, &iz) ||
|
|
!PyTuple_GetInteger(args, 3, &iZoom) ||
|
|
!PyTuple_GetInteger(args, 4, &iRotation) ||
|
|
!PyTuple_GetInteger(args, 5, &iPitch)) {
|
|
return Py_BuildException();
|
|
}
|
|
s_camera_distance = static_cast<float>(iZoom);
|
|
s_camera_rotation = static_cast<float>(iRotation);
|
|
s_camera_pitch = static_cast<float>(iPitch);
|
|
s_camera_height = static_cast<float>(iz);
|
|
return Py_BuildNone();
|
|
}
|
|
|
|
PyObject* app_save_camera_setting(PyObject*, PyObject* args) {
|
|
char* szFileName = nullptr;
|
|
if (!PyTuple_GetString(args, 0, &szFileName))
|
|
return Py_BuildException();
|
|
std::ofstream f(szFileName ? szFileName : "");
|
|
if (f) {
|
|
f << "camerasetting " << s_camera_distance << " " << s_camera_pitch << " " << s_camera_rotation << "\n";
|
|
}
|
|
return Py_BuildNone();
|
|
}
|
|
|
|
PyObject* app_load_camera_setting(PyObject*, PyObject* args) {
|
|
char* szFileName = nullptr;
|
|
if (!PyTuple_GetString(args, 0, &szFileName))
|
|
return Py_BuildException();
|
|
std::ifstream f(szFileName ? szFileName : "");
|
|
if (!f) return Py_BuildValue("i", 0);
|
|
std::string line;
|
|
while (std::getline(f, line)) {
|
|
float z = 0, p = 0, r = 0;
|
|
if (std::sscanf(line.c_str(), "camerasetting %f %f %f", &z, &p, &r) >= 3) {
|
|
s_camera_distance = z;
|
|
s_camera_pitch = p;
|
|
s_camera_rotation = r;
|
|
return Py_BuildValue("i", 1);
|
|
}
|
|
}
|
|
return Py_BuildValue("i", 1);
|
|
}
|
|
|
|
PyObject* app_set_default_camera(PyObject*, PyObject*) {
|
|
s_camera_distance = 1500.0f;
|
|
s_camera_pitch = 30.0f;
|
|
s_camera_rotation = 0.0f;
|
|
s_camera_height = 180.0f;
|
|
return Py_BuildNone();
|
|
}
|
|
|
|
PyObject* app_enable_special_camera_mode(PyObject*, PyObject*) {
|
|
s_special_camera_mode = true;
|
|
return Py_BuildNone();
|
|
}
|
|
|
|
static int GetRotatingDirection(float fSource, float fTarget) {
|
|
if (fSource < 180.0f) {
|
|
if (fTarget < fSource)
|
|
return 1;
|
|
else if ((360.0f - fTarget) + fSource < 180.0f)
|
|
return 1;
|
|
return 2;
|
|
} else {
|
|
if (fTarget > fSource)
|
|
return 2;
|
|
else if ((360.0f - fSource) + fTarget < 180.0f)
|
|
return 2;
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
PyObject* app_get_rotating_direction(PyObject*, PyObject* args) {
|
|
float fSource = 0.0f, fTarget = 0.0f;
|
|
if (!PyTuple_GetFloat(args, 0, &fSource) || !PyTuple_GetFloat(args, 1, &fTarget))
|
|
return Py_BuildException();
|
|
return Py_BuildValue("i", GetRotatingDirection(fSource, fTarget));
|
|
}
|
|
|
|
static float GetDegreeDifference(float fSource, float fTarget) {
|
|
if (fSource < 180.0f) {
|
|
if (fTarget < fSource)
|
|
return fSource - fTarget;
|
|
else if (fTarget - fSource > 180.0f)
|
|
return 360.0f - (fTarget - fSource);
|
|
return fTarget - fSource;
|
|
} else {
|
|
if (fTarget > fSource)
|
|
return fTarget - fSource;
|
|
else if (fSource - fTarget > 180.0f)
|
|
return 360.0f - (fSource - fTarget);
|
|
return fSource - fTarget;
|
|
}
|
|
}
|
|
|
|
PyObject* app_get_degree_difference(PyObject*, PyObject* args) {
|
|
float fSource = 0.0f, fTarget = 0.0f;
|
|
if (!PyTuple_GetFloat(args, 0, &fSource) || !PyTuple_GetFloat(args, 1, &fTarget))
|
|
return Py_BuildException();
|
|
return Py_BuildValue("f", GetDegreeDifference(fSource, fTarget));
|
|
}
|
|
|
|
PyObject* app_get_cursor_position(PyObject*, PyObject*) {
|
|
long lx = 0, ly = 0;
|
|
UI::CWindowManager::Instance().GetMousePosition(lx, ly);
|
|
return Py_BuildValue("ii", lx, ly);
|
|
}
|
|
|
|
PyObject* app_update_game(PyObject*, PyObject*) {
|
|
long lx = 0, ly = 0;
|
|
UI::CWindowManager::Instance().GetMousePosition(lx, ly);
|
|
float camX = 0.0f, camY = 0.0f, camZ = 0.0f;
|
|
auto* mainActor = NetworkActorManager::Instance().GetMainInstance();
|
|
if (mainActor) {
|
|
camX = static_cast<float>(mainActor->m_lCurX);
|
|
camY = static_cast<float>(mainActor->m_lCurY);
|
|
camZ = static_cast<float>(mainActor->m_lCurZ);
|
|
}
|
|
CPythonBackground::Instance().Update(camX, camY, camZ);
|
|
float dt = 0.033f;
|
|
NetworkActorManager::Instance().Update(dt, CPythonBackground::Instance().GetTerrain());
|
|
EffectManager::Instance().Update(dt);
|
|
static float s_flyingTime = 0.0f;
|
|
s_flyingTime += dt;
|
|
FlyingManager::Instance().Update(dt, s_flyingTime);
|
|
return Py_BuildNone();
|
|
}
|
|
|
|
PyObject* app_render_game(PyObject*, PyObject*) {
|
|
auto& bg = CPythonBackground::Instance();
|
|
bg.RenderSky();
|
|
bg.RenderBeforeLensFlare();
|
|
bg.RenderCloud();
|
|
bg.BeginEnvironment();
|
|
bg.Render();
|
|
bg.SetCharacterDirLight();
|
|
bg.SetBackgroundDirLight();
|
|
bg.RenderWater();
|
|
bg.RenderSnow();
|
|
bg.RenderEffect();
|
|
bg.EndEnvironment();
|
|
bg.BeginEnvironment();
|
|
bg.RenderPCBlocker();
|
|
bg.EndEnvironment();
|
|
bg.RenderAfterLensFlare();
|
|
return Py_BuildNone();
|
|
}
|
|
|
|
|
|
PyObject* app_set_hair_color_enable(PyObject*, PyObject* args) { int f = 0; if(!PyArg_ParseTuple(args, "i", &f)) return nullptr; NetworkActorManager::SetHairColorEnable(f != 0); Py_RETURN_NONE; }
|
|
PyObject* app_set_armor_specular_enable(PyObject*, PyObject* args) { int f = 0; if(!PyArg_ParseTuple(args, "i", &f)) return nullptr; s_armor_specular = (f != 0); NetworkActorManager::SetArmorSpecularEnable(f != 0); Py_RETURN_NONE; }
|
|
PyObject* app_set_weapon_specular_enable(PyObject*, PyObject* args) { int f = 0; if(!PyArg_ParseTuple(args, "i", &f)) return nullptr; s_weapon_specular = (f != 0); Py_RETURN_NONE; }
|
|
|
|
PyObject* app_set_mouse_handler(PyObject*, PyObject* args) { Py_RETURN_NONE; }
|
|
// appCreate: after the window, LoadPythonPlayerSettingsModuleLibrary registers the
|
|
// PythonPlayerSettingsModule tables and CPythonPlayerSettingsModule::Load runs
|
|
// introLoading.__main__ (name/title colours, title names, emotion icons, dungeon names),
|
|
// then __LoadGameNPC("npclist.txt") and the player race table (CRaceManager / .msm).
|
|
PyObject* app_create(PyObject*, PyObject* args) {
|
|
ava2::LoadPlayerSettings();
|
|
PyObject* module = PyImport_ImportModule("introLoading");
|
|
PyObject* main = module ? PyObject_GetAttrString(module, "__main__") : nullptr;
|
|
PyObject* result = main ? PyObject_CallObject(main, nullptr) : nullptr;
|
|
if (!result) PyErr_Print();
|
|
Py_XDECREF(result); Py_XDECREF(main); Py_XDECREF(module);
|
|
RaceManager::Instance().LoadGameNPC("npclist.txt");
|
|
RaceManager::Instance().LoadPlayerRaces();
|
|
Py_RETURN_NONE;
|
|
}
|
|
PyObject* app_loop(PyObject*, PyObject*) { Py_RETURN_NONE; }
|
|
PyObject* app_exit(PyObject*, PyObject*) { Py_RETURN_NONE; }
|
|
PyObject* app_abort(PyObject*, PyObject*) { Py_RETURN_NONE; }
|
|
PyObject* app_is_pressed(PyObject*, PyObject* args) { return PyInt_FromLong(0); }
|
|
|
|
PyObject* app_get_locale_service_name(PyObject*, PyObject*) {
|
|
return PyString_FromString(s_locale_service_name.c_str());
|
|
}
|
|
|
|
PyObject* app_get_locale_name(PyObject*, PyObject*) {
|
|
return PyString_FromString(s_locale_name.c_str());
|
|
}
|
|
|
|
PyObject* app_get_locale_path(PyObject*, PyObject*) {
|
|
return PyString_FromString(s_locale_path.c_str());
|
|
}
|
|
|
|
// appLoadLocaleData (AVA2 PythonApplicationModule.cpp).
|
|
PyObject* app_load_locale_data(PyObject*, PyObject* args) {
|
|
char* localePath;
|
|
if (!PyTuple_GetString(args, 0, &localePath))
|
|
return Py_BuildException();
|
|
return Py_BuildValue("i", LoadLocaleData(localePath));
|
|
}
|
|
|
|
PyObject* app_get_default_codepage(PyObject*, PyObject*) {
|
|
return PyInt_FromLong(GetDefaultCodePage());
|
|
}
|
|
|
|
// appGetRandom: EterBase random_range over the swapped bounds.
|
|
PyObject* app_get_random(PyObject*, PyObject* poArgs) {
|
|
int from;
|
|
if (!PyTuple_GetInteger(poArgs, 0, &from))
|
|
return Py_BuildException();
|
|
int to;
|
|
if (!PyTuple_GetInteger(poArgs, 1, &to))
|
|
return Py_BuildException();
|
|
if (from > to)
|
|
std::swap(from, to);
|
|
return Py_BuildValue("i", eter::random_range(from, to));
|
|
}
|
|
|
|
// CTextLineLoader / appOpenTextFile..appGetTextFileLine (PythonApplicationModule.cpp).
|
|
// Windows hands Python the heap pointer as an int; 64-bit hosts get an index instead.
|
|
std::unordered_map<int, std::vector<std::string>> s_textLineLoaders;
|
|
int s_nextTextLineLoader = 1;
|
|
|
|
PyObject* app_open_text_file(PyObject*, PyObject* args) {
|
|
const char* fileName = nullptr;
|
|
if (!PyArg_ParseTuple(args, "s", &fileName)) return nullptr;
|
|
std::vector<std::string> lines;
|
|
try { lines = ava2::ava2TextLines(ReadPackedText(fileName)); } catch (const std::exception&) {}
|
|
const int handle = s_nextTextLineLoader++;
|
|
s_textLineLoaders[handle] = std::move(lines);
|
|
return PyInt_FromLong(handle);
|
|
}
|
|
|
|
PyObject* app_close_text_file(PyObject*, PyObject* args) {
|
|
int handle = 0;
|
|
if (!PyArg_ParseTuple(args, "i", &handle)) return nullptr;
|
|
s_textLineLoaders.erase(handle);
|
|
Py_RETURN_NONE;
|
|
}
|
|
|
|
PyObject* app_get_text_file_line_count(PyObject*, PyObject* args) {
|
|
int handle = 0;
|
|
if (!PyArg_ParseTuple(args, "i", &handle)) return nullptr;
|
|
auto it = s_textLineLoaders.find(handle);
|
|
return PyInt_FromLong(it == s_textLineLoaders.end() ? 0 : long(it->second.size()));
|
|
}
|
|
|
|
PyObject* app_get_text_file_line(PyObject*, PyObject* args) {
|
|
int handle = 0, index = 0;
|
|
if (!PyArg_ParseTuple(args, "ii", &handle, &index)) return nullptr;
|
|
auto it = s_textLineLoaders.find(handle);
|
|
if (it == s_textLineLoaders.end() || index < 0 || size_t(index) >= it->second.size()) return PyString_FromString("");
|
|
return PyString_FromStringAndSize(it->second[index].data(), Py_ssize_t(it->second[index].size()));
|
|
}
|
|
|
|
PyObject* app_set_guild_mark_path(PyObject*, PyObject* args) {
|
|
const char* path = nullptr;
|
|
if (PyArg_ParseTuple(args, "s", &path) && path) {
|
|
std::string p(path);
|
|
size_t dot = p.find_last_of('.');
|
|
if (dot != std::string::npos) p = p.substr(0, dot);
|
|
ava2::GuildMarkManager::Instance().SetMarkPathPrefix(p);
|
|
}
|
|
Py_RETURN_NONE;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
std::int32_t GetServerTimeStamp() { return server_clock.timestamp(unix_seconds()); }
|
|
void SetServerTime(std::int32_t time) { server_clock.set(time,local_milliseconds(),unix_seconds()); }
|
|
std::uint32_t GetLocalMSec() { return local_milliseconds(); }
|
|
std::int32_t GetApplicationSeconds() { return static_cast<std::int32_t>(std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now()-app_start).count()); }
|
|
void SetServerMSec(std::uint32_t time) { if(time==0) return;elt_server_time=time;elt_client_time=local_milliseconds(); ELTimer_SetServerMSec(time); }
|
|
std::uint32_t GetServerMSec() { return local_milliseconds()-elt_client_time+elt_server_time; }
|
|
void ResetPythonAppState() { elt_server_time=elt_client_time=0;ELTimer_Init();server_clock=ServerClock(local_milliseconds());app_start=std::chrono::steady_clock::now();s_test_server_flag=false;twoHandedAttackSpeedDecrease=0; }
|
|
std::uint8_t GetEnterGameLanguage() {
|
|
const char* locales[]={"ymir","en","de","tr","pt","es","fr","ro","pl","it","cz","hu"};
|
|
for(std::uint8_t i=1;i<12;++i) if(s_locale_name==locales[i]) return i;
|
|
return 1;
|
|
}
|
|
// The port serves the AVA2 Latin-1 locales only (en/de/es/...), so the ANSI code page is 1252.
|
|
unsigned GetDefaultCodePage() { return 1252; }
|
|
|
|
int GetTwoHandedAttackSpeedDecrease(){return twoHandedAttackSpeedDecrease;}
|
|
bool IsYmirLocale() { return s_locale_name=="ymir"; }
|
|
|
|
namespace {
|
|
|
|
static float s_textTailLivingTime = 5000.0f;
|
|
static bool s_skillEffectUpgradeEnable = false;
|
|
static bool s_rideHorseEnable = true;
|
|
static float s_minFog = 0.0f;
|
|
static bool s_frameSkip = false;
|
|
static int s_fps = 60;
|
|
static int s_globalCenterX = 0, s_globalCenterY = 0;
|
|
static float s_centerX = 0.0f, s_centerY = 0.0f, s_centerZ = 0.0f;
|
|
static int s_cursorNum = 0;
|
|
static bool s_cursorVisible = true;
|
|
static bool s_softwareCursor = false;
|
|
static std::string s_connectIP = "";
|
|
static int s_connectPort = 0;
|
|
static std::string s_defaultFontName = "Arial:12";
|
|
static std::string s_guildSymbolPath = "mark";
|
|
static int s_sightRange = 12000;
|
|
static bool s_cheonma = false;
|
|
static float s_specularSpeed = 1.0f;
|
|
static int s_accumulationTime = 0;
|
|
static float s_specularColor[3] = {1.0f, 1.0f, 1.0f};
|
|
static bool s_visibleNotice = true;
|
|
static int s_multiFarmStatus = 0;
|
|
static std::string s_appTitle = "AVA2";
|
|
static std::string s_appMiniTitle = "AVA2";
|
|
|
|
static void tea_decode(uint32_t sz, uint32_t sy, const uint32_t* key, uint32_t* dest) {
|
|
uint32_t y = sy, z = sz;
|
|
uint32_t sum = 0x9E3779B9u * 32u;
|
|
for (int n = 0; n < 32; ++n) {
|
|
z -= ((y << 4 ^ y >> 5) + y) ^ (sum + key[sum >> 11 & 3]);
|
|
sum -= 0x9E3779B9u;
|
|
y -= ((z << 4 ^ z >> 5) + z) ^ (sum + key[sum & 3]);
|
|
}
|
|
*dest++ = y;
|
|
*dest = z;
|
|
}
|
|
|
|
static int tea_decrypt_data(uint32_t* dest, const uint32_t* src, const uint32_t* key, int size) {
|
|
int resize = (size % 8 != 0) ? (size + 8 - (size % 8)) : size;
|
|
for (int i = 0; i < resize >> 3; ++i, dest += 2, src += 2) {
|
|
tea_decode(*(src + 1), *src, key, dest);
|
|
}
|
|
return resize;
|
|
}
|
|
|
|
static PyObject* app_is_dev_stage(PyObject*, PyObject*) {
|
|
return Py_BuildValue("i", 0);
|
|
}
|
|
static PyObject* app_is_test_stage(PyObject*, PyObject*) {
|
|
return Py_BuildValue("i", 0);
|
|
}
|
|
static PyObject* app_is_live_stage(PyObject*, PyObject*) {
|
|
return Py_BuildValue("i", 1);
|
|
}
|
|
static PyObject* app_set_text_tail_living_time(PyObject*, PyObject* args) {
|
|
float livingTime = 0.0f;
|
|
if (!PyTuple_GetFloat(args, 0, &livingTime)) return Py_BuildException();
|
|
s_textTailLivingTime = livingTime * 1000.0f;
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_enable_performance_time(PyObject*, PyObject* args) {
|
|
char* mode = nullptr; int enable = 0;
|
|
if (!PyTuple_GetString(args, 0, &mode) || !PyTuple_GetInteger(args, 1, &enable)) return Py_BuildException();
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_set_skill_effect_upgrade_enable(PyObject*, PyObject* args) {
|
|
int enable = 0;
|
|
if (!PyTuple_GetInteger(args, 0, &enable)) return Py_BuildException();
|
|
s_skillEffectUpgradeEnable = (enable != 0);
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_set_ride_horse_enable(PyObject*, PyObject* args) {
|
|
int enable = 0;
|
|
if (!PyTuple_GetInteger(args, 0, &enable)) return Py_BuildException();
|
|
s_rideHorseEnable = (enable != 0);
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_set_min_fog(PyObject*, PyObject* args) {
|
|
float fog = 0.0f;
|
|
if (!PyTuple_GetFloat(args, 0, &fog)) return Py_BuildException();
|
|
s_minFog = fog;
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_set_frame_skip(PyObject*, PyObject* args) {
|
|
int skip = 0;
|
|
if (!PyTuple_GetInteger(args, 0, &skip)) return Py_BuildException();
|
|
s_frameSkip = (skip != 0);
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_get_image_info(PyObject*, PyObject* args) {
|
|
char* filename = nullptr;
|
|
if (!PyTuple_GetString(args, 0, &filename)) return Py_BuildException();
|
|
return Py_BuildValue("iii", 0, 0, 0);
|
|
}
|
|
static PyObject* app_get_info(PyObject*, PyObject* args) {
|
|
int info = 0;
|
|
if (!PyTuple_GetInteger(args, 0, &info)) return Py_BuildException();
|
|
return Py_BuildValue("s", "");
|
|
}
|
|
static PyObject* app_process(PyObject*, PyObject*) {
|
|
return Py_BuildValue("i", 1);
|
|
}
|
|
static PyObject* app_is_exist_file(PyObject*, PyObject* args) {
|
|
char* filename = nullptr;
|
|
if (!PyTuple_GetString(args, 0, &filename)) return Py_BuildException();
|
|
return Py_BuildValue("i", (CResourceManager::ResourceExists(filename) || std::filesystem::exists(filename)) ? 1 : 0);
|
|
}
|
|
static PyObject* app_get_file_list(PyObject*, PyObject* args) {
|
|
char* filter = nullptr;
|
|
if (!PyTuple_GetString(args, 0, &filter)) return Py_BuildException();
|
|
PyObject* poList = PyList_New(0);
|
|
try {
|
|
std::filesystem::path p(filter);
|
|
std::filesystem::path dir = p.parent_path();
|
|
if (dir.empty()) dir = ".";
|
|
std::string pattern = p.filename().string();
|
|
if (std::filesystem::exists(dir) && std::filesystem::is_directory(dir)) {
|
|
for (const auto& entry : std::filesystem::directory_iterator(dir)) {
|
|
std::string name = entry.path().filename().string();
|
|
if (pattern.empty() || pattern == "*.*" || pattern == "*" || name.find(pattern) != std::string::npos) {
|
|
PyList_Append(poList, PyString_FromString(name.c_str()));
|
|
}
|
|
}
|
|
}
|
|
} catch (...) {}
|
|
return poList;
|
|
}
|
|
static PyObject* app_get_update_fps(PyObject*, PyObject*) {
|
|
return Py_BuildValue("i", s_fps);
|
|
}
|
|
static PyObject* app_get_render_fps(PyObject*, PyObject*) {
|
|
return Py_BuildValue("i", s_fps);
|
|
}
|
|
static PyObject* app_get_available_texture_memory(PyObject*, PyObject*) {
|
|
return Py_BuildValue("i", 256 * 1024 * 1024);
|
|
}
|
|
static PyObject* app_get_render_time(PyObject*, PyObject*) {
|
|
return Py_BuildValue("fi", 0.016f, 16);
|
|
}
|
|
static PyObject* app_get_update_time(PyObject*, PyObject*) {
|
|
return Py_BuildValue("i", 16);
|
|
}
|
|
static PyObject* app_get_load(PyObject*, PyObject*) {
|
|
return Py_BuildValue("i", 0);
|
|
}
|
|
static PyObject* app_get_face_speed(PyObject*, PyObject*) {
|
|
return Py_BuildValue("f", 0.0f);
|
|
}
|
|
static PyObject* app_get_face_count(PyObject*, PyObject*) {
|
|
return Py_BuildValue("i", 0);
|
|
}
|
|
static PyObject* app_set_fps(PyObject*, PyObject* args) {
|
|
int fps = 0;
|
|
if (!PyTuple_GetInteger(args, 0, &fps)) return Py_BuildException();
|
|
s_fps = fps;
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_set_global_center_position(PyObject*, PyObject* args) {
|
|
int x = 0, y = 0;
|
|
if (!PyTuple_GetInteger(args, 0, &x) || !PyTuple_GetInteger(args, 1, &y)) return Py_BuildException();
|
|
s_globalCenterX = x; s_globalCenterY = y;
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_set_center_position(PyObject*, PyObject* args) {
|
|
float x = 0.0f, y = 0.0f, z = 0.0f;
|
|
if (!PyTuple_GetFloat(args, 0, &x) || !PyTuple_GetFloat(args, 1, &y) || !PyTuple_GetFloat(args, 2, &z)) return Py_BuildException();
|
|
s_centerX = x; s_centerY = y; s_centerZ = z;
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_run_python_file(PyObject*, PyObject* args) {
|
|
char* filename = nullptr;
|
|
if (!PyTuple_GetString(args, 0, &filename)) return Py_BuildException();
|
|
FILE* fp = fopen(filename, "r");
|
|
if (!fp) return Py_BuildValue("i", 0);
|
|
int res = PyRun_SimpleFile(fp, filename);
|
|
fclose(fp);
|
|
return Py_BuildValue("i", res == 0 ? 1 : 0);
|
|
}
|
|
static PyObject* app_is_web_page_mode(PyObject*, PyObject*) {
|
|
return Py_BuildValue("i", 0);
|
|
}
|
|
static PyObject* app_show_web_page(PyObject*, PyObject* args) {
|
|
char* url = nullptr;
|
|
if (!PyTuple_GetString(args, 0, &url)) return Py_BuildException();
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_move_web_page(PyObject*, PyObject*) {
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_hide_web_page(PyObject*, PyObject*) {
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_set_cursor(PyObject*, PyObject* args) {
|
|
int cursor = 0;
|
|
if (!PyTuple_GetInteger(args, 0, &cursor)) return Py_BuildException();
|
|
s_cursorNum = cursor;
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_get_cursor(PyObject*, PyObject*) {
|
|
return Py_BuildValue("i", s_cursorNum);
|
|
}
|
|
static PyObject* app_show_cursor(PyObject*, PyObject*) {
|
|
s_cursorVisible = true;
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_hide_cursor(PyObject*, PyObject*) {
|
|
s_cursorVisible = false;
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_is_show_cursor(PyObject*, PyObject*) {
|
|
return Py_BuildValue("i", s_cursorVisible ? 1 : 0);
|
|
}
|
|
static PyObject* app_is_liar_cursor_on(PyObject*, PyObject*) {
|
|
return Py_BuildValue("i", 0);
|
|
}
|
|
static PyObject* app_set_software_cursor(PyObject*, PyObject*) {
|
|
s_softwareCursor = true;
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_set_hardware_cursor(PyObject*, PyObject*) {
|
|
s_softwareCursor = false;
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_set_connect_data(PyObject*, PyObject* args) {
|
|
char* ip = nullptr; int port = 0;
|
|
if (!PyTuple_GetString(args, 0, &ip) || !PyTuple_GetInteger(args, 1, &port)) return Py_BuildException();
|
|
s_connectIP = ip; s_connectPort = port;
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_get_connect_data(PyObject*, PyObject*) {
|
|
return Py_BuildValue("si", s_connectIP.c_str(), s_connectPort);
|
|
}
|
|
static PyObject* app_sleep(PyObject*, PyObject* args) {
|
|
int ms = 0;
|
|
if (!PyTuple_GetInteger(args, 0, &ms)) return Py_BuildException();
|
|
if (ms > 0) std::this_thread::sleep_for(std::chrono::milliseconds(ms));
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_set_default_font_name(PyObject*, PyObject* args) {
|
|
char* font = nullptr;
|
|
if (!PyTuple_GetString(args, 0, &font)) return Py_BuildException();
|
|
s_defaultFontName = font;
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_set_guild_symbol_path(PyObject*, PyObject* args) {
|
|
char* path = nullptr;
|
|
if (!PyTuple_GetString(args, 0, &path)) return Py_BuildException();
|
|
s_guildSymbolPath = path;
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_set_sight_range(PyObject*, PyObject* args) {
|
|
int range = 0;
|
|
if (!PyTuple_GetInteger(args, 0, &range)) return Py_BuildException();
|
|
s_sightRange = range;
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_is_file_exist(PyObject*, PyObject* args) {
|
|
char* filename = nullptr;
|
|
if (!PyTuple_GetString(args, 0, &filename)) return Py_BuildException();
|
|
return Py_BuildValue("i", std::filesystem::exists(filename) ? 1 : 0);
|
|
}
|
|
static PyObject* app_force_set_locale(PyObject*, PyObject* args) {
|
|
char* name = nullptr; char* localePath = nullptr;
|
|
if (!PyTuple_GetString(args, 0, &name) || !PyTuple_GetString(args, 1, &localePath)) return Py_BuildException();
|
|
s_locale_name = name; s_locale_path = localePath;
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_load_locale_addr(PyObject*, PyObject* args) {
|
|
char* addrPath = nullptr;
|
|
if (!PyTuple_GetString(args, 0, &addrPath)) return Py_BuildException();
|
|
FILE* fp = fopen(addrPath, "rb");
|
|
if (!fp) return Py_BuildException("Cannot open locale addr file");
|
|
fseek(fp, 0, SEEK_END);
|
|
long size = ftell(fp);
|
|
fseek(fp, 0, SEEK_SET);
|
|
if (size <= 0) {
|
|
fclose(fp);
|
|
return Py_BuildValue("s", "");
|
|
}
|
|
std::vector<uint8_t> enc(size + 8, 0);
|
|
fread(enc.data(), size, 1, fp);
|
|
fclose(fp);
|
|
|
|
static const unsigned char rawKey[16] = {
|
|
0x82, 0x1b, 0x34, 0xae,
|
|
0x12, 0x3b, 0xfb, 0x17,
|
|
0xd7, 0x2c, 0x39, 0xae,
|
|
0x41, 0x98, 0xf1, 0x63
|
|
};
|
|
uint32_t k[4];
|
|
std::memcpy(k, rawKey, 16);
|
|
|
|
std::vector<uint32_t> buf((size + 7) / 4 + 2, 0);
|
|
tea_decrypt_data(buf.data(), reinterpret_cast<const uint32_t*>(enc.data()), k, size);
|
|
uint32_t retSize = buf[0];
|
|
const char* ret = reinterpret_cast<const char*>(buf.data()) + sizeof(uint32_t);
|
|
if (retSize > (uint32_t)(size)) retSize = 0;
|
|
return Py_BuildValue("s#", ret, retSize);
|
|
}
|
|
static PyObject* app_set_cheonma(PyObject*, PyObject* args) {
|
|
int enable = 0;
|
|
if (!PyTuple_GetInteger(args, 0, &enable)) return Py_BuildException();
|
|
s_cheonma = (enable != 0);
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_is_cheonma(PyObject*, PyObject*) {
|
|
return Py_BuildValue("i", s_cheonma ? 1 : 0);
|
|
}
|
|
static PyObject* app_set_control_fp(PyObject*, PyObject*) {
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_set_specular_speed(PyObject*, PyObject* args) {
|
|
float spd = 0.0f;
|
|
if (!PyTuple_GetFloat(args, 0, &spd)) return Py_BuildException();
|
|
s_specularSpeed = spd;
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_test_get_accumulation_time(PyObject*, PyObject*) {
|
|
return Py_BuildValue("i", s_accumulationTime);
|
|
}
|
|
static PyObject* app_test_reset_accumulation_time(PyObject*, PyObject*) {
|
|
s_accumulationTime = 0;
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_test_set_specular_color(PyObject*, PyObject* args) {
|
|
float r = 0.0f, g = 0.0f, b = 0.0f;
|
|
if (!PyTuple_GetFloat(args, 0, &r) || !PyTuple_GetFloat(args, 1, &g) || !PyTuple_GetFloat(args, 2, &b)) return Py_BuildException();
|
|
s_specularColor[0] = r; s_specularColor[1] = g; s_specularColor[2] = b;
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_set_visible_notice(PyObject*, PyObject* args) {
|
|
int flag = 0;
|
|
if (!PyTuple_GetInteger(args, 0, &flag)) return Py_BuildException();
|
|
s_visibleNotice = (flag != 0);
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_is_visible_notice(PyObject*, PyObject*) {
|
|
return Py_BuildValue("i", s_visibleNotice ? 1 : 0);
|
|
}
|
|
static PyObject* app_on_logo_update(PyObject*, PyObject*) {
|
|
return Py_BuildValue("i", 0);
|
|
}
|
|
static PyObject* app_on_logo_render(PyObject*, PyObject*) {
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_on_logo_open(PyObject*, PyObject* args) {
|
|
char* name = nullptr;
|
|
if (!PyTuple_GetString(args, 0, &name)) return Py_BuildException();
|
|
return Py_BuildValue("i", 1);
|
|
}
|
|
static PyObject* app_on_logo_close(PyObject*, PyObject*) {
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_flash_application(PyObject*, PyObject*) {
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_set_multi_farm_exe_icon(PyObject*, PyObject* args) {
|
|
int status = 0;
|
|
if (!PyTuple_GetInteger(args, 0, &status)) return Py_BuildException();
|
|
s_multiFarmStatus = status;
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_window_status(PyObject*, PyObject* args) {
|
|
int status = 0;
|
|
if (!PyTuple_GetInteger(args, 0, &status)) return Py_BuildException();
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_is_visible(PyObject*, PyObject*) {
|
|
return Py_BuildValue("i", 1);
|
|
}
|
|
static PyObject* app_set_title(PyObject*, PyObject* args) {
|
|
char* title = nullptr; char* miniTitle = nullptr;
|
|
if (!PyTuple_GetString(args, 0, &title)) return Py_BuildException();
|
|
if (PyTuple_Size(args) > 1) {
|
|
if (!PyTuple_GetString(args, 1, &miniTitle)) return Py_BuildException();
|
|
}
|
|
s_appTitle = title;
|
|
if (miniTitle) s_appMiniTitle = miniTitle;
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_set_message(PyObject*, PyObject* args) {
|
|
char* title = nullptr; char* message = nullptr;
|
|
if (!PyTuple_GetString(args, 0, &title) || !PyTuple_GetString(args, 1, &message)) return Py_BuildException();
|
|
return Py_BuildNone();
|
|
}
|
|
static PyObject* app_is_can_open_render(PyObject*, PyObject*) {
|
|
return Py_BuildValue("i", 0);
|
|
}
|
|
|
|
} // namespace
|
|
|
|
void initapp() {
|
|
static PyMethodDef methods[] = {
|
|
{"IsDevStage", app_is_dev_stage, METH_VARARGS, nullptr},
|
|
{"IsTestStage", app_is_test_stage, METH_VARARGS, nullptr},
|
|
{"IsLiveStage", app_is_live_stage, METH_VARARGS, nullptr},
|
|
{"SetTextTailLivingTime", app_set_text_tail_living_time, METH_VARARGS, nullptr},
|
|
{"EnablePerformanceTime", app_enable_performance_time, METH_VARARGS, nullptr},
|
|
{"SetHairColorEnable", app_set_hair_color_enable, METH_VARARGS, nullptr},
|
|
{"SetArmorSpecularEnable", app_set_armor_specular_enable, METH_VARARGS, nullptr},
|
|
{"SetWeaponSpecularEnable", app_set_weapon_specular_enable, METH_VARARGS, nullptr},
|
|
{"SetSkillEffectUpgradeEnable", app_set_skill_effect_upgrade_enable, METH_VARARGS, nullptr},
|
|
{"SetTwoHandedWeaponAttSpeedDecreaseValue", set_twohand_decrease, METH_VARARGS, nullptr},
|
|
{"SetRideHorseEnable", app_set_ride_horse_enable, METH_VARARGS, nullptr},
|
|
{"SetCameraMaxDistance", app_set_camera_max_distance, METH_VARARGS, nullptr},
|
|
{"SetMinFog", app_set_min_fog, METH_VARARGS, nullptr},
|
|
{"SetFrameSkip", app_set_frame_skip, METH_VARARGS, nullptr},
|
|
{"GetImageInfo", app_get_image_info, METH_VARARGS, nullptr},
|
|
{"GetInfo", app_get_info, METH_VARARGS, nullptr},
|
|
{"UpdateGame", app_update_game, METH_VARARGS, nullptr},
|
|
{"RenderGame", app_render_game, METH_VARARGS, nullptr},
|
|
{"Loop", app_loop, METH_VARARGS, nullptr},
|
|
{"Create", app_create, METH_VARARGS, nullptr},
|
|
{"Process", app_process, METH_VARARGS, nullptr},
|
|
{"Exit", app_exit, METH_VARARGS, nullptr},
|
|
{"Abort", app_abort, METH_VARARGS, nullptr},
|
|
{"SetMouseHandler", app_set_mouse_handler, METH_VARARGS, nullptr},
|
|
{"IsExistFile", app_is_exist_file, METH_VARARGS, nullptr},
|
|
{"GetFileList", app_get_file_list, METH_VARARGS, nullptr},
|
|
{"SetCamera", app_set_camera, METH_VARARGS, nullptr},
|
|
{"GetCamera", app_get_camera, METH_VARARGS, nullptr},
|
|
{"GetCameraPitch", app_get_camera_pitch, METH_VARARGS, nullptr},
|
|
{"GetCameraRotation", app_get_camera_rotation, METH_VARARGS, nullptr},
|
|
{"GetTime", app_get_time, METH_VARARGS, nullptr},
|
|
{"GetGlobalTime", app_get_global_time, METH_VARARGS, nullptr},
|
|
{"GetGlobalTimeStamp", app_get_global_timestamp, METH_VARARGS, nullptr},
|
|
{"GetUpdateFPS", app_get_update_fps, METH_VARARGS, nullptr},
|
|
{"GetRenderFPS", app_get_render_fps, METH_VARARGS, nullptr},
|
|
{"RotateCamera", app_rotate_camera, METH_VARARGS, nullptr},
|
|
{"PitchCamera", app_pitch_camera, METH_VARARGS, nullptr},
|
|
{"ZoomCamera", app_zoom_camera, METH_VARARGS, nullptr},
|
|
{"MovieRotateCamera", app_movie_rotate_camera, METH_VARARGS, nullptr},
|
|
{"MoviePitchCamera", app_movie_pitch_camera, METH_VARARGS, nullptr},
|
|
{"MovieZoomCamera", app_movie_zoom_camera, METH_VARARGS, nullptr},
|
|
{"MovieResetCamera", app_movie_reset_camera, METH_VARARGS, nullptr},
|
|
{"GetAvailableTextureMemory", app_get_available_texture_memory, METH_VARARGS, nullptr},
|
|
{"GetRenderTime", app_get_render_time, METH_VARARGS, nullptr},
|
|
{"GetUpdateTime", app_get_update_time, METH_VARARGS, nullptr},
|
|
{"GetLoad", app_get_load, METH_VARARGS, nullptr},
|
|
{"GetFaceSpeed", app_get_face_speed, METH_VARARGS, nullptr},
|
|
{"GetFaceCount", app_get_face_count, METH_VARARGS, nullptr},
|
|
{"SetFPS", app_set_fps, METH_VARARGS, nullptr},
|
|
{"SetGlobalCenterPosition", app_set_global_center_position, METH_VARARGS, nullptr},
|
|
{"SetCenterPosition", app_set_center_position, METH_VARARGS, nullptr},
|
|
{"GetCursorPosition", app_get_cursor_position, METH_VARARGS, nullptr},
|
|
{"GetRandom", app_get_random, METH_VARARGS, nullptr},
|
|
{"RunPythonFile", app_run_python_file, METH_VARARGS, nullptr},
|
|
{"IsWebPageMode", app_is_web_page_mode, METH_VARARGS, nullptr},
|
|
{"ShowWebPage", app_show_web_page, METH_VARARGS, nullptr},
|
|
{"MoveWebPage", app_move_web_page, METH_VARARGS, nullptr},
|
|
{"HideWebPage", app_hide_web_page, METH_VARARGS, nullptr},
|
|
{"IsPressed", app_is_pressed, METH_VARARGS, nullptr},
|
|
{"SetCursor", app_set_cursor, METH_VARARGS, nullptr},
|
|
{"GetCursor", app_get_cursor, METH_VARARGS, nullptr},
|
|
{"ShowCursor", app_show_cursor, METH_VARARGS, nullptr},
|
|
{"HideCursor", app_hide_cursor, METH_VARARGS, nullptr},
|
|
{"IsShowCursor", app_is_show_cursor, METH_VARARGS, nullptr},
|
|
{"IsLiarCursorOn", app_is_liar_cursor_on, METH_VARARGS, nullptr},
|
|
{"SetSoftwareCursor", app_set_software_cursor, METH_VARARGS, nullptr},
|
|
{"SetHardwareCursor", app_set_hardware_cursor, METH_VARARGS, nullptr},
|
|
{"SetConnectData", app_set_connect_data, METH_VARARGS, nullptr},
|
|
{"GetConnectData", app_get_connect_data, METH_VARARGS, nullptr},
|
|
{"GetRotatingDirection", app_get_rotating_direction, METH_VARARGS, nullptr},
|
|
{"GetDegreeDifference", app_get_degree_difference, METH_VARARGS, nullptr},
|
|
{"Sleep", app_sleep, METH_VARARGS, nullptr},
|
|
{"SetDefaultFontName", app_set_default_font_name, METH_VARARGS, nullptr},
|
|
{"SetGuildSymbolPath", app_set_guild_symbol_path, METH_VARARGS, nullptr},
|
|
{"EnableSpecialCameraMode", app_enable_special_camera_mode, METH_VARARGS, nullptr},
|
|
{"SetCameraSpeed", app_set_camera_speed, METH_VARARGS, nullptr},
|
|
{"SaveCameraSetting", app_save_camera_setting, METH_VARARGS, nullptr},
|
|
{"LoadCameraSetting", app_load_camera_setting, METH_VARARGS, nullptr},
|
|
{"SetDefaultCamera", app_set_default_camera, METH_VARARGS, nullptr},
|
|
{"SetCameraSetting", app_set_camera_setting, METH_VARARGS, nullptr},
|
|
{"SetSightRange", app_set_sight_range, METH_VARARGS, nullptr},
|
|
{"IsFileExist", app_is_file_exist, METH_VARARGS, nullptr},
|
|
{"OpenTextFile", app_open_text_file, METH_VARARGS, nullptr},
|
|
{"CloseTextFile", app_close_text_file, METH_VARARGS, nullptr},
|
|
{"GetTextFileLineCount", app_get_text_file_line_count, METH_VARARGS, nullptr},
|
|
{"GetTextFileLine", app_get_text_file_line, METH_VARARGS, nullptr},
|
|
{"GetLocaleServiceName", app_get_locale_service_name, METH_VARARGS, nullptr},
|
|
{"GetLocaleName", app_get_locale_name, METH_VARARGS, nullptr},
|
|
{"GetLocalePath", app_get_locale_path, METH_VARARGS, nullptr},
|
|
{"ForceSetLocale", app_force_set_locale, METH_VARARGS, nullptr},
|
|
{"LoadLocaleAddr", app_load_locale_addr, METH_VARARGS, nullptr},
|
|
{"LoadLocaleData", app_load_locale_data, METH_VARARGS, nullptr},
|
|
{"SetCHEONMA", app_set_cheonma, METH_VARARGS, nullptr},
|
|
{"IsCHEONMA", app_is_cheonma, METH_VARARGS, nullptr},
|
|
{"GetDefaultCodePage", app_get_default_codepage, METH_VARARGS, nullptr},
|
|
{"SetControlFP", app_set_control_fp, METH_VARARGS, nullptr},
|
|
{"SetSpecularSpeed", app_set_specular_speed, METH_VARARGS, nullptr},
|
|
{"testGetAccumulationTime", app_test_get_accumulation_time, METH_VARARGS, nullptr},
|
|
{"testResetAccumulationTime", app_test_reset_accumulation_time, METH_VARARGS, nullptr},
|
|
{"testSetSpecularColor", app_test_set_specular_color, METH_VARARGS, nullptr},
|
|
{"SetVisibleNotice", app_set_visible_notice, METH_VARARGS, nullptr},
|
|
{"IsVisibleNotice", app_is_visible_notice, METH_VARARGS, nullptr},
|
|
{"IsEnableTestServerFlag", app_is_test_server, METH_VARARGS, nullptr},
|
|
{"EnableTestServerFlag", app_enable_test_server, METH_VARARGS, nullptr},
|
|
{"SetGuildMarkPath", app_set_guild_mark_path, METH_VARARGS, nullptr},
|
|
{"OnLogoUpdate", app_on_logo_update, METH_VARARGS, nullptr},
|
|
{"OnLogoRender", app_on_logo_render, METH_VARARGS, nullptr},
|
|
{"OnLogoOpen", app_on_logo_open, METH_VARARGS, nullptr},
|
|
{"OnLogoClose", app_on_logo_close, METH_VARARGS, nullptr},
|
|
{"FlashApplication", app_flash_application, METH_VARARGS, nullptr},
|
|
{"SetMultiFarmExeIcon", app_set_multi_farm_exe_icon, METH_VARARGS, nullptr},
|
|
{"WindowStatus", app_window_status, METH_VARARGS, nullptr},
|
|
{"IsVisible", app_is_visible, METH_VARARGS, nullptr},
|
|
{"SetTitle", app_set_title, METH_VARARGS, nullptr},
|
|
{"SetMessage", app_set_message, METH_VARARGS, nullptr},
|
|
{"IsCanOpenRender", app_is_can_open_render, METH_VARARGS, nullptr},
|
|
{nullptr, nullptr, 0, nullptr}
|
|
};
|
|
auto* module = Py_InitModule("app", methods);
|
|
register_app_constants(module);
|
|
|
|
#ifdef ENABLE_MANAGER_BANK_SYSTEM
|
|
PyModule_AddIntConstant(module, "ENABLE_MANAGER_BANK_SYSTEM", 1);
|
|
#else
|
|
PyModule_AddIntConstant(module, "ENABLE_MANAGER_BANK_SYSTEM", 0);
|
|
#endif
|
|
|
|
#ifdef ENABLE_WOLFMAN_CHARACTER
|
|
PyModule_AddIntConstant(module, "ENABLE_WOLFMAN_CHARACTER", 1);
|
|
#else
|
|
PyModule_AddIntConstant(module, "ENABLE_WOLFMAN_CHARACTER", 0);
|
|
#endif
|
|
|
|
#ifdef ENABLE_SASH_SYSTEM
|
|
PyModule_AddIntConstant(module, "ENABLE_SASH_SYSTEM", 1);
|
|
#else
|
|
PyModule_AddIntConstant(module, "ENABLE_SASH_SYSTEM", 0);
|
|
#endif
|
|
|
|
#ifdef ENABLE_CONQUEROR_LEVEL
|
|
PyModule_AddIntConstant(module, "ENABLE_CONQUEROR_LEVEL", 1);
|
|
#else
|
|
PyModule_AddIntConstant(module, "ENABLE_CONQUEROR_LEVEL", 0);
|
|
#endif
|
|
|
|
#ifdef ENABLE_DISCORD_STUFF
|
|
PyModule_AddIntConstant(module, "ENABLE_DISCORD_STUFF", 1);
|
|
#else
|
|
PyModule_AddIntConstant(module, "ENABLE_DISCORD_STUFF", 0);
|
|
#endif
|
|
|
|
PyModule_AddIntConstant(module, "ENABLE_OFFLINESHOP_SYSTEM", 1);
|
|
PyModule_AddIntConstant(module, "ENABLE_STONEMINIMAP", 1);
|
|
PyModule_AddIntConstant(module, "TOURNAMENT_PVP_SYSTEM", 0);
|
|
PyModule_AddIntConstant(module, "RACE_HEIGHT", 1);
|
|
|
|
// DIK Keycodes strictly 1:1 with win32 dinput DIK_*
|
|
PyModule_AddIntConstant(module, "DIK_ESCAPE", 0x01);
|
|
PyModule_AddIntConstant(module, "DIK_ESC", 0x01);
|
|
PyModule_AddIntConstant(module, "DIK_1", 0x02);
|
|
PyModule_AddIntConstant(module, "DIK_2", 0x03);
|
|
PyModule_AddIntConstant(module, "DIK_3", 0x04);
|
|
PyModule_AddIntConstant(module, "DIK_4", 0x05);
|
|
PyModule_AddIntConstant(module, "DIK_5", 0x06);
|
|
PyModule_AddIntConstant(module, "DIK_6", 0x07);
|
|
PyModule_AddIntConstant(module, "DIK_7", 0x08);
|
|
PyModule_AddIntConstant(module, "DIK_8", 0x09);
|
|
PyModule_AddIntConstant(module, "DIK_9", 0x0A);
|
|
PyModule_AddIntConstant(module, "DIK_0", 0x0B);
|
|
PyModule_AddIntConstant(module, "DIK_RETURN", 0x1C);
|
|
PyModule_AddIntConstant(module, "DIK_TAB", 0x0F);
|
|
PyModule_AddIntConstant(module, "DIK_SPACE", 0x39);
|
|
PyModule_AddIntConstant(module, "DIK_BACK", 0x0E);
|
|
PyModule_AddIntConstant(module, "DIK_UP", 0xC8);
|
|
PyModule_AddIntConstant(module, "DIK_DOWN", 0xD0);
|
|
PyModule_AddIntConstant(module, "DIK_LEFT", 0xCB);
|
|
PyModule_AddIntConstant(module, "DIK_RIGHT", 0xCD);
|
|
|
|
PyModule_AddIntConstant(module, "INFO_ITEM", 0);
|
|
PyModule_AddIntConstant(module, "INFO_ACTOR", 1);
|
|
PyModule_AddIntConstant(module, "INFO_EFFECT", 2);
|
|
PyModule_AddIntConstant(module, "INFO_TEXTTAIL", 3);
|
|
|
|
PyModule_AddIntConstant(module, "DEGREE_DIRECTION_SAME", 0);
|
|
PyModule_AddIntConstant(module, "DEGREE_DIRECTION_RIGHT", 1);
|
|
PyModule_AddIntConstant(module, "DEGREE_DIRECTION_LEFT", 2);
|
|
|
|
PyModule_AddIntConstant(module, "CAMERA_TO_POSITIVE", 1);
|
|
PyModule_AddIntConstant(module, "CAMERA_TO_NEGATIVE", -1);
|
|
PyModule_AddIntConstant(module, "CAMERA_STOP", 0);
|
|
}
|
|
|
|
namespace {
|
|
void locale_trace_error(const std::string& text) { std::cerr << "[AVA2 TraceError] " << text << std::endl; }
|
|
bool load_text(const std::string& path, std::string* text) {
|
|
try { *text = ReadPackedText(path); return true; } catch (const std::exception&) { return false; }
|
|
}
|
|
}
|
|
|
|
// Same order, Destroy() calls and early-return points as the Windows coordinator.
|
|
// Not ported: YMIR lang%d.cvt (AVA2 runs EUROPE) - see docs/WINDOWS-PARITY.md.
|
|
bool LoadLocaleData(const std::string& localePath) {
|
|
const std::string szItemList = localePath + "/item_list.txt";
|
|
const std::string szItemProto = localePath + "/item_proto";
|
|
const std::string szItemDesc = localePath + "/itemdesc.txt";
|
|
const std::string szMobProto = localePath + "/mob_proto";
|
|
const std::string szSkillDescFileName = localePath + "/SkillDesc.txt";
|
|
const std::string szSkillTableFileName = localePath + "/SkillTable.txt";
|
|
const std::string szInsultList = localePath + "/insult.txt";
|
|
const std::string szSkillPetFileName = localePath + "/pet_skill.txt";
|
|
const std::string szMobScale = localePath + "/mob_scale.txt";
|
|
|
|
NonPlayerData& rkNPCMgr = NonPlayerData::Instance();
|
|
rkNPCMgr.clear();
|
|
ResetItemDatabase();
|
|
ResetSkillDescriptions();
|
|
GetPetSkillState().Clear();
|
|
|
|
if (!LoadItemList(szItemList))
|
|
locale_trace_error("LoadLocaleData - LoadItemList(" + szItemList + ") Error");
|
|
if (!LoadItemTable(szItemProto)) {
|
|
locale_trace_error("LoadLocaleData - LoadItemProto(" + szItemProto + ") Error");
|
|
return false;
|
|
}
|
|
LoadItemDescriptions(szItemDesc); // Tracenf only
|
|
std::string text;
|
|
if (!load_text(szMobProto, &text) || !rkNPCMgr.load(text)) {
|
|
locale_trace_error("LoadLocaleData - LoadMobProto(" + szMobProto + ") Error");
|
|
return false;
|
|
}
|
|
// The original passes szMobProto to the two skill messages.
|
|
if (!LoadSkillDescriptions(szSkillDescFileName)) {
|
|
locale_trace_error("LoadLocaleData - RegisterSkillDesc(" + szMobProto + ") Error");
|
|
return false;
|
|
}
|
|
if (!LoadSkillTable(szSkillTableFileName)) {
|
|
locale_trace_error("LoadLocaleData - RegisterSkillTable(" + szMobProto + ") Error");
|
|
return false;
|
|
}
|
|
if (!LoadPetSkills(szSkillPetFileName)) {
|
|
locale_trace_error("LoadLocaleData - RegisterSkillPet(" + szSkillPetFileName + ") Error");
|
|
return false;
|
|
}
|
|
LoadInsultList(szInsultList); // Tracenf only
|
|
rkNPCMgr.clearNPCWear();
|
|
if (load_text("locale/common/npc_wear.txt", &text))
|
|
rkNPCMgr.loadNPCWear(text);
|
|
if (!load_text(szMobScale, &text) || !rkNPCMgr.loadMobScale(text, szMobScale)) {
|
|
locale_trace_error("LoadMobScale Error(" + szMobScale + ")");
|
|
return false;
|
|
}
|
|
LoadItemScale(localePath + "/item_scale.txt"); // Tracenf only
|
|
WikiReadData(localePath); // ENABLE_WIKI
|
|
return true;
|
|
}
|
|
|
|
float GetCameraZoomSpeed() { return s_camera_zoom_speed; }
|
|
|
|
} // namespace ava2
|