Skip to content
This repository has been archived by the owner on Feb 17, 2022. It is now read-only.

Commit

Permalink
Support 1.34, dlc_balt, dlc_or
Browse files Browse the repository at this point in the history
Add support for ETS2/ATS v1.34, and the Beyond the Baltic Sea (ETS2) and Oregon (ATS) DLCs.
  • Loading branch information
DaviMedrade committed Mar 10, 2019
1 parent 73311b2 commit 65fbeda
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 67 deletions.
10 changes: 5 additions & 5 deletions ETS2Sync-Helper-4.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<ProjectGuid>{C58DE3D1-9460-4ACD-A334-8A8B9991DEF4}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>Ets2SyncHelper</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
Expand Down Expand Up @@ -94,7 +94,7 @@
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;WINVER=0x0601;__WXMSW__;_wxUSE_GUI=1;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;WINVER=0x0601;__WXMSW__;_wxUSE_GUI=1;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;ZLIB_WINAPI;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(WXWIN)\include\msvc;$(WXWIN)\include;$(ZLIBDIR);$(ProjectDir)lib</AdditionalIncludeDirectories>
<ObjectFileName>$(IntDir)/%(RelativeDir)/</ObjectFileName>
<MultiProcessorCompilation>
Expand All @@ -109,7 +109,7 @@
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(WXWIN)\lib\vc_lib;$(ZLIBDIR)\contrib\vstudio\vc11\x86\ZlibStat$(Configuration)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>$(WXWIN)\lib\vc_lib;$(ZLIBDIR)\contrib\vstudio\vc14\x86\ZlibStat$(Configuration)</AdditionalLibraryDirectories>
<AdditionalDependencies>zlibstat.lib;wininet.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<ResourceCompile>
Expand All @@ -136,7 +136,7 @@
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;WINVER=0x0601;__WXMSW__;_wxUSE_GUI=1;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;WINVER=0x0601;__WXMSW__;_wxUSE_GUI=1;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;ZLIB_WINAPI;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>$(WXWIN)\include\msvc;$(WXWIN)\include;$(ZLIBDIR);$(ProjectDir)lib</AdditionalIncludeDirectories>
<ObjectFileName>$(IntDir)/%(RelativeDir)/</ObjectFileName>
<MultiProcessorCompilation>
Expand All @@ -153,7 +153,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(WXWIN)\lib\vc_lib;$(ZLIBDIR)\contrib\vstudio\vc11\x86\ZlibStat$(Configuration)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>$(WXWIN)\lib\vc_lib;$(ZLIBDIR)\contrib\vstudio\vc14\x86\ZlibStatReleaseWithoutAsm</AdditionalLibraryDirectories>
<AdditionalDependencies>zlibstat.lib;wininet.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<ResourceCompile>
Expand Down
10 changes: 5 additions & 5 deletions res/app.rc
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ END
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 5,4,0,0
PRODUCTVERSION 5,4,0,0
FILEVERSION 5,5,0,0
PRODUCTVERSION 5,5,0,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x3L
Expand All @@ -77,12 +77,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "David Santos"
VALUE "FileDescription", "ETS2Sync Helper"
VALUE "FileVersion", "5.4.0"
VALUE "FileVersion", "5.5.0"
VALUE "InternalName", "ets2sync_helper"
VALUE "LegalCopyright", "� 2018 by David Santos"
VALUE "LegalCopyright", "� 2019 by David Santos"
VALUE "OriginalFilename", "ets2sync_helper.exe"
VALUE "ProductName", "ETS2Sync Helper"
VALUE "ProductVersion", "5.4.0"
VALUE "ProductVersion", "5.5.0"
END
END
BLOCK "VarFileInfo"
Expand Down
14 changes: 11 additions & 3 deletions src/DlcSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,27 @@ DlcSelector::DlcSelector(wxWindow * parent, wxWindowID id)
vec->push_back(cb);
mDlcByCheckbox[cb] = L"heavy_cargo";

cb = new wxCheckBox(this, wxID_ANY, "Beyond the Baltic Sea");
vec->push_back(cb);
mDlcByCheckbox[cb] = L"balt";

vec = &mCheckboxesByGame[Ets2::Game::ATS];
cb = new wxCheckBox(this, wxID_ANY, "New Mexico");
vec->push_back(cb);
mDlcByCheckbox[cb] = L"nwmexico";

cb = new wxCheckBox(this, wxID_ANY, "Oregon");
vec->push_back(cb);
mDlcByCheckbox[cb] = L"oregon";

cb = new wxCheckBox(this, wxID_ANY, "Heavy Cargo Pack");
vec->push_back(cb);
mDlcByCheckbox[cb] = L"heavy";

wxBoxSizer * parentSizer = new wxBoxSizer(wxHORIZONTAL);
contentSizer->Add(parentSizer, wxSizerFlags().Expand());
for (size_t i = 0; i < std::max(mCheckboxesByGame[Ets2::Game::ETS2].size(), mCheckboxesByGame[Ets2::Game::ATS].size()); i++) {
if ((i % 3) == 0) {
if ((i % 4) == 0) {
if (i > 0) {
parentSizer->AddStretchSpacer(1);
}
Expand Down Expand Up @@ -101,14 +109,14 @@ void DlcSelector::setSave(const Ets2::Save * save) {
Layout();
}

const Ets2::Save::DlcList DlcSelector::getRefusedDlcs() const {
const Ets2::Save::DlcList DlcSelector::getDlcs() const {
Ets2::Save::DlcList dlcs = {};
if (mSave == nullptr) {
return dlcs;
}

for (auto& cb : mCheckboxesByGame.at(mSave->getGame())) {
if (cb->IsEnabled() && !cb->IsChecked()) {
if (cb->IsEnabled() && cb->IsChecked()) {
dlcs.push_back(mDlcByCheckbox.at(cb));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/DlcSelector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class DlcSelector : public Ets2StaticBox {
DlcSelector(wxWindow * parent, wxWindowID);

void setSave(const Ets2::Save * save);
const Ets2::Save::DlcList getRefusedDlcs() const;
const Ets2::Save::DlcList getDlcs() const;

private:
wxHyperlinkCtrl * mSelectAll;
Expand Down
50 changes: 37 additions & 13 deletions src/Ets2/Save.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace Ets2 {
}
dlcNameEnd = wideValue.find(L'|', dlcNameStart);
mDlcs.push_back(wideValue.substr(dlcNameStart, dlcNameEnd == std::wstring::npos ? std::wstring::npos : dlcNameEnd - dlcNameStart));
//DEBUG_LOG(L"DLC: %ls", mDlcs.at(mDlcs.size() - 1));
//DEBUG_LOG(L"%ls: DLC: %ls", mName, mDlcs.at(mDlcs.size() - 1));
}
}
}
Expand All @@ -73,15 +73,18 @@ namespace Ets2 {
}

void Save::setupBlankJob(Job& job) {
job.cargo = "null";
job.companyTruck = "";
job.variant = -1;
job.target = "";
job.urgency = -1;
job.distance = 0;
job.ferryPrice = 0;
job.ferryTime = 0;
job.trailerPlace = 0;
job.ferryPrice = 0;
job.cargo = "null";
job.companyTruck = "";
job.trailerVariant = "null";
job.trailerDefinition = "null";
job.unitsCount = 0;
job.fillRatio = 1;
job.trailerPlace = {};
}

// Returns the number of jobs inserted in the save, or -1 in case of error.
Expand Down Expand Up @@ -168,7 +171,9 @@ namespace Ets2 {
}
newSaveData.append("}\r\n");
} else {
newSaveData.append(1, ' ').append(name).append(": ");
if (!inJob || name.find("trailer_place[") != 0) {
newSaveData.append(1, ' ').append(name).append(": ");
}
newLineHasValue = false;
if (inEconomy && name == GAME_TIME_ATTRIBUTE) {
gameTime = std::stol(value);
Expand All @@ -191,8 +196,11 @@ namespace Ets2 {
newSaveData.append("\"");
}
newLineHasValue = true;
} else if (name == "variant") {
newSaveData.append(currentJob->variant == -1 ? "nil" : std::to_string(currentJob->variant));
} else if (name == "trailer_variant") {
newSaveData.append(currentJob->trailerVariant);
newLineHasValue = true;
} else if (name == "trailer_definition") {
newSaveData.append(currentJob->trailerDefinition);
newLineHasValue = true;
} else if (name == "target") {
newSaveData.append("\"").append(currentJob->target).append("\"");
Expand All @@ -217,14 +225,30 @@ namespace Ets2 {
newSaveData.append(std::to_string(currentJob->ferryPrice));
newLineHasValue = true;
} else if (name == "trailer_place") {
newSaveData.append(std::to_string(currentJob->trailerPlace));
newSaveData.append(std::to_string(currentJob->trailerPlace.size()));
int tpIdx = 0;
for (std::string p : currentJob->trailerPlace) {
newSaveData.append("\r\n trailer_place[");
newSaveData.append(std::to_string(tpIdx));
newSaveData.append("]: ");
newSaveData.append(p);
++tpIdx;
}
newLineHasValue = true;
} else if (name == "units_count") {
newSaveData.append(std::to_string(currentJob->unitsCount));
newLineHasValue = true;
} else if (name == "fill_ratio") {
newSaveData.append(std::to_string(currentJob->fillRatio));
newLineHasValue = true;
}
}
if (!newLineHasValue) {
newSaveData.append(sourceValue);
if (name.find("trailer_place[") != 0) {
if (!newLineHasValue) {
newSaveData.append(sourceValue);
}
newSaveData.append("\r\n");
}
newSaveData.append("\r\n");
}

progress = offset / (dataLength / 100);
Expand Down
7 changes: 5 additions & 2 deletions src/Ets2/Save.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ namespace Ets2 {

struct Job {
std::string cargo;
int variant;
std::string target;
int urgency;
int distance;
int ferryTime;
int ferryPrice;
std::string companyTruck;
int trailerPlace;
std::string trailerVariant;
std::string trailerDefinition;
int unitsCount;
int fillRatio;
std::vector<std::string> trailerPlace;
};

typedef std::map<std::string, std::vector<Job>> JobList;
Expand Down
59 changes: 33 additions & 26 deletions src/JobSyncer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ JobSyncer::~JobSyncer() {
}
}

void JobSyncer::start(const Ets2::Save * save, const Ets2::Save::DlcList& refusedDlcs, int jobList) {
void JobSyncer::start(const Ets2::Save * save, const Ets2::Save::DlcList& dlcs, int jobList) {
Status status = getStatus();
if (status.state >= State::STARTING && status.state < State::FINISHED) {
// Don't use SYNC_DEBUG_LOG because mSave is the save from the sync that's already running
Expand All @@ -37,7 +37,7 @@ void JobSyncer::start(const Ets2::Save * save, const Ets2::Save::DlcList& refuse
return;
}
mSave = save;
mRefusedDlcs = refusedDlcs;
mDlcs = dlcs;
mJobList = jobList;
if (mSave == nullptr) {
SYNC_DEBUG_LOG(L"Can't start sync: save is null.");
Expand Down Expand Up @@ -112,13 +112,16 @@ wxThread::ExitCode JobSyncer::Entry() {
Ets2::Save::Job job;
job.cargo = "invalid";
job.companyTruck = "invalid";
job.variant = 100;
job.trailerDefinition = "invalid";
job.trailerVariant = "invalid";
job.target = "invalid.invalid";
job.urgency = 0;
job.distance = 1000;
job.ferryPrice = 1000;
job.ferryTime = 100;
job.trailerPlace = 0;
job.trailerPlace = {};
job.unitsCount = 0;
job.fillRatio = 1;
jobs.clear();
jobs[mSave->getGame() == Ets2::Game::ETS2 ? "sanbuilders.hamburg" : "vm_car_dlr.las_vegas"].push_back(job);
}
Expand Down Expand Up @@ -154,29 +157,21 @@ bool JobSyncer::getJobs(Ets2::Save::JobList& jobs) {

std::wstring syncUrl = APP_URL_SYNC;
std::wstring gameParam = L"";
std::wstring refusedDlcsParam = L"";
std::wstring saveDlcsParam = L"";
std::wstring dlcsParam = L"";
if (mSave->getGame() == Ets2::Game::ATS) {
gameParam = L"ats";
} else {
gameParam = L"ets2";
}
for (auto&& dlc : mRefusedDlcs) {
if (!refusedDlcsParam.empty())
refusedDlcsParam.push_back(L',');
refusedDlcsParam.append(dlc);
}
if (mSave != nullptr) {
for (auto&& dlc : mSave->getDlcs()) {
if (!saveDlcsParam.empty())
saveDlcsParam.push_back(L',');
saveDlcsParam.append(dlc);
}
for (auto&& dlc : mDlcs) {
if (!dlcsParam.empty())
dlcsParam.push_back(L',');
dlcsParam.append(dlc);
}
if (mJobList != -1) {
syncUrl += L"&list=" + std::to_wstring(mJobList);
}
syncUrl += L"&game=" + gameParam + L"&refused_dlcs=" + refusedDlcsParam + "&save_dlcs=" + saveDlcsParam;
syncUrl += L"&game=" + gameParam + L"&dlcs=" + dlcsParam;

SYNC_DEBUG_LOG(L"Downloading from URL: %s", syncUrl);
HINTERNET urlHandle = InternetOpenUrl(mInternetHandle, syncUrl.data(), NULL, (DWORD)-1,
Expand Down Expand Up @@ -315,32 +310,44 @@ bool JobSyncer::getJobs(Ets2::Save::JobList& jobs) {
Ets2::Save::setupBlankJob(job);
for (Value::ConstMemberIterator propIterator = jobIterator->MemberBegin(); propIterator != jobIterator->MemberEnd(); ++propIterator) {
propName.assign(propIterator->name.GetString(), propIterator->name.GetStringLength());
if (propName == "cargo" || propName == "company_truck" || propName == "target") {
if (propName == "cargo" || propName == "company_truck" || propName == "target" || propName == "trailer_variant" || propName == "trailer_definition") {
propValue.assign(propIterator->value.GetString(), propIterator->value.GetStringLength());
if (propName == "cargo") {
job.cargo = propValue;
} else if (propName == "company_truck") {
job.companyTruck = propValue;
} else if (propName == "target") {
job.target = propValue;
} else if (propName == "trailer_variant") {
job.trailerVariant = propValue;
} else if (propName == "trailer_definition") {
job.trailerDefinition = propValue;
}
} else if (propName == "variant" || propName == "urgency" || propName == "shortest_distance_km" || propName == "ferry_time" || propName == "ferry_price" || propName == "trailer_place") {
} else if (propName == "urgency" || propName == "shortest_distance_km" || propName == "ferry_time" || propName == "ferry_price" || propName == "units_count" || propName == "fill_ratio") {
int propValueInt = propIterator->value.GetInt();
if (propName == "variant") {
job.variant = propValueInt;
} else if (propName == "urgency") {
if (propName == "urgency") {
job.urgency = propValueInt;
} else if (propName == "shortest_distance_km") {
job.distance = propValueInt;
} else if (propName == "ferry_time") {
job.ferryTime = propValueInt;
} else if (propName == "ferry_price") {
job.ferryPrice = propValueInt;
} else if (propName == "trailer_place") {
job.trailerPlace = propValueInt;
} else if (propName == "units_count") {
job.unitsCount = propValueInt;
} else if (propName == "fill_ratio") {
job.fillRatio = propValueInt;
}
} else if (propName == "trailer_place") {
job.trailerPlace = {};
auto trailerPlaceArray = propIterator->value.GetArray();
for (Value::ConstValueIterator trailerPlaceIterator = trailerPlaceArray.Begin() ; trailerPlaceIterator != trailerPlaceArray.End() ; ++trailerPlaceIterator) {
job.trailerPlace.push_back(std::string(trailerPlaceIterator->GetString(), trailerPlaceIterator->GetStringLength()));
}
} else {
throw(std::runtime_error(wxString::Format("unknown job property: '%s'", propName)));
SYNC_DEBUG_LOG(L"unknown job property: '%s'", propName);
setStatus(SET_ALL, State::FAILED, PROGRESS_UNDEFINED, wxString::Format(L"Unknown remote job property: %s", propName).ToStdWstring());
return false;
}
}
jobs[keyIterator->name.GetString()].push_back(job);
Expand Down
4 changes: 2 additions & 2 deletions src/JobSyncer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class JobSyncer : public wxEvtHandler, public wxThreadHelper {
wxString message;
};

void start(const Ets2::Save * save, const Ets2::Save::DlcList& refusedDlcs, int jobList);
void start(const Ets2::Save * save, const Ets2::Save::DlcList& dlcs, int jobList);
const Status getStatus();
void cancel();

Expand All @@ -56,7 +56,7 @@ class JobSyncer : public wxEvtHandler, public wxThreadHelper {
bool mCancel;
wxCriticalSection mCancelLock;
const Ets2::Save * mSave;
Ets2::Save::DlcList mRefusedDlcs;
Ets2::Save::DlcList mDlcs;
int mJobList;

void setStatus(int flags, State state, int progress, wxString message);
Expand Down
Loading

0 comments on commit 65fbeda

Please sign in to comment.