Add palette-faithful club logo import, transformations and isolated crest cells (by Codex)

This commit is contained in:
Codex committed 2026-10-31 15:29:11 +01:00
1 parent db21653b75
commit 561d290643
12 files changed
+155 -13

No files matched your search

+9 -2
View File
@@ -1176,8 +1176,8 @@ add_library(obdeddi_model STATIC src/obdeddi/document.cpp src/cli/json.cpp)
target_include_directories(obdeddi_model PUBLIC src)
target_link_libraries(obdeddi_model PUBLIC bmhcore PRIVATE bmh_miniz obdeddi_hash)
if(WIN32)
add_executable(obdeddi WIN32 src/obdeddi/main_win32.cpp)
target_link_libraries(obdeddi PRIVATE obdeddi_model comctl32 comdlg32 user32 gdi32 shell32)
add_executable(obdeddi WIN32 src/obdeddi/main_win32.cpp src/obdeddi/logo_win32.cpp src/obdeddi/logo_transform_win32.cpp)
target_link_libraries(obdeddi PRIVATE obdeddi_model comctl32 comdlg32 user32 gdi32 shell32 gdiplus)
if(MSVC)
target_compile_options(obdeddi PRIVATE /utf-8)
target_compile_options(obdeddi_model PRIVATE /utf-8)
@@ -1187,3 +1187,10 @@ endif()
add_executable(obdeddi_tests tests/obdeddi_tests.cpp)
target_link_libraries(obdeddi_tests PRIVATE obdeddi_model bmh_miniz)
add_test(NAME obdeddi_tests COMMAND obdeddi_tests)
if(WIN32)
add_executable(obdeddi_logo_tests tests/obdeddi_logo_tests.cpp src/obdeddi/logo_transform_win32.cpp)
target_include_directories(obdeddi_logo_tests PRIVATE src)
target_link_libraries(obdeddi_logo_tests PRIVATE gdiplus)
add_test(NAME obdeddi_logo_tests COMMAND obdeddi_logo_tests)
endif()
+2 -2
View File
@@ -4,9 +4,9 @@ A small native Windows data editor for the standalone OpenBMH 1.1 COMMUNITY.OBD
## Use
Extract the separate editor package and start `obdeddi.exe`. Open a COMMUNITY.OBD with the Open button or Ctrl+O. A file path may also be passed on the command line. Search and sortable virtual lists cover players and clubs; the club filter applies to players. No artwork is decoded or presented for editing.
Extract the separate editor package and start `obdeddi.exe`. Open a COMMUNITY.OBD with the Open button or Ctrl+O. A file path may also be passed on the command line. Search and sortable virtual lists cover players and clubs; the club filter applies to players. Artwork is decoded only on demand in the separate club-logo dialog.
Player fields include names, position, nationality, age, form/technique/condition, bonus and the seven Classic skills. Displayed strength is derived, not a second independent field. Club fields include names, the stored short-name span and existing kit selectors. League sizes and record counts stay fixed. Country rows and rules are not editable. League players can move between squads or swap places; temporary/reserve-table players cannot be reassigned as if they were ordinary roster members.
Player fields include names, position, nationality, age, form/technique/condition, bonus and the seven Classic skills. Displayed strength is derived, not a second independent field. Club fields include names, the stored short-name span and existing kit selectors. League sizes and record counts stay fixed. Country rows and rules are not editable. Club logos can be imported from PNG/JPEG/BMP, cropped by source-pixel coordinates, freely rotated and mirrored. The before/after preview uses the actual 38×38 Original palette and bright background; shared crest cells are cloned into a free cell. Other artwork is not editable. League players can move between squads or swap places; temporary/reserve-table players cannot be reassigned as if they were ordinary roster members.
Classic new-career generation is deliberately retained: many stored player values are randomized/recalculated when a career starts. Editing the database does not modify an existing saved game. This limitation is visible in the player form.
+38 -3
View File
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "obdeddi/document.hpp"
#include "cli/json.hpp"
#include "formats/palette.hpp"
#include "miniz.h"
#include "Sha256.h"
#include <algorithm>
@@ -108,12 +109,46 @@ void Document::move_player(size_t id,int destination,int swap){
else{word(slots,size_t(to)*2,le16(slots,size_t(from)*2));word(slots,size_t(from)*2,4095);for(int team:{source,destination}){std::vector<uint16_t> list;for(int row=0;row<24;++row){auto v=le16(slots,size_t(team*24+row)*2);if((v&4095)!=4095)list.push_back(v);}for(int row=0;row<24;++row)word(slots,size_t(team*24+row)*2,row<int(list.size())?uint16_t((list[size_t(row)]&0x7fff)|(row<11?0x8000:0)):4095);}}
db_.squad_list=std::move(slots);refresh_owners();dirty_=true;changes_.push_back("roster:player:"+std::to_string(id)+":"+std::to_string(source)+">"+std::to_string(destination));
}
std::array<uint32_t,256> Document::palette() const {
const auto& data=entries_.at(key(entries_,"M3PC.COL"));if(data.size()!=768)throw FormatError("Ungueltige Palette.");
std::array<uint32_t,256> colors{};for(size_t i=0;i<256;++i)colors[i]=0xff000000u|uint32_t(vga_dac_rgb8(data[i*3]))<<16|uint32_t(vga_dac_rgb8(data[i*3+1]))<<8|vga_dac_rgb8(data[i*3+2]);return colors;
}
Image Document::logo_sheet(int page) const {
const auto name="W/"+std::to_string(page)+".VGA";
const auto changed=changed_assets_.find(name);if(changed!=changed_assets_.end())return decode_vga(changed->second);
return decode_vga(entries_.at(key(entries_,name)));
}
std::array<uint32_t,1444> Document::logo(size_t club) const {
if(club>=profile_.national_first)throw FormatError("Kein Vereinslogo.");
const int cell=le16(db_.raw_club_badge_selectors,club*2)&511;const auto sheet=logo_sheet(cell/8);if(sheet.width!=304||sheet.height!=38)throw FormatError("Ungueltiger Wappenbogen.");
const auto colors=palette();std::array<uint32_t,1444> out{};for(int y=0;y<38;++y)for(int x=0;x<38;++x)out[size_t(y*38+x)]=colors[sheet.pixels[size_t(y*304+(cell%8)*38+x)]];return out;
}
Image Document::convert_logo(const std::array<uint32_t,1444>& rgba) const {
const auto colors=palette();Image image(38,38,94);std::map<int,Image> sheets;
for(int y=0;y<38;++y)for(int x=0;x<38;++x){int votes[4]{};for(int club=0;club<90;++club){int cell=le16(db_.raw_club_badge_selectors,size_t(club)*2)&511;auto it=sheets.find(cell/8);if(it==sheets.end())it=sheets.emplace(cell/8,logo_sheet(cell/8)).first;if(it->second.width!=304||it->second.height!=38)throw FormatError("Ungueltiger Wappenbogen.");auto value=it->second.pixels[size_t(y*304+(cell%8)*38+x)];if(value>=92&&value<=95)++votes[value-92];}
const int background=92+int(std::max_element(votes,votes+4)-votes);auto c=rgba[size_t(y*38+x)];int alpha=int(c>>24);int red=(int(c>>16&255)*alpha+int(colors[size_t(background)]>>16&255)*(255-alpha)+127)/255;int green=(int(c>>8&255)*alpha+int(colors[size_t(background)]>>8&255)*(255-alpha)+127)/255;int blue=(int(c&255)*alpha+int(colors[size_t(background)]&255)*(255-alpha)+127)/255;
int best=0,distance=2147483647;for(int i=0;i<256;++i){int dr=int(colors[size_t(i)]>>16&255)-red,dg=int(colors[size_t(i)]>>8&255)-green,db=int(colors[size_t(i)]&255)-blue;int d=dr*dr+dg*dg+db*db;if(d<distance){best=i;distance=d;}}image.at(x,y)=uint8_t(best);
}return image;
}
std::array<uint32_t,1444> Document::preview_logo(const std::array<uint32_t,1444>& rgba) const {auto image=convert_logo(rgba);auto colors=palette();std::array<uint32_t,1444> out{};for(size_t i=0;i<1444;++i)out[i]=colors[image.pixels[i]];return out;}
void Document::set_logo(size_t club,const std::array<uint32_t,1444>& rgba){
if(club>=profile_.national_first)throw FormatError("Kein Vereinslogo.");
auto selectors=db_.raw_club_badge_selectors;const auto old=le16(selectors,club*2);int cell=old&511;int references=0;bool used[512]{};
for(size_t i=0;i<db_.counts.clubs;++i){int c=le16(selectors,i*2)&511;used[c]=true;references+=c==cell;}
if(references>1){auto free=std::find(used,used+512,false);if(free==used+512)throw FormatError("Keine freie Wappenzelle vorhanden.");cell=int(free-used);}
Image sheet;try{sheet=logo_sheet(cell/8);}catch(const std::out_of_range&){sheet=Image(304,38,94);}catch(const FormatError&){if(entries_.count("W/"+std::to_string(cell/8)+".VGA"))throw;sheet=Image(304,38,94);}
if(sheet.width!=304||sheet.height!=38)throw FormatError("Ungueltiger Wappenbogen.");auto image=convert_logo(rgba);
for(int y=0;y<38;++y)for(int x=0;x<38;++x)sheet.at((cell%8)*38+x,y)=image.at(x,y);
Bytes encoded;const auto put=[&](uint32_t v,int count){for(int i=0;i<count;++i)encoded.push_back(uint8_t(v>>(8*i)));};Bytes payload;
for(size_t i=0;i<sheet.pixels.size();i+=128){auto count=std::min(size_t(128),sheet.pixels.size()-i);payload.push_back(uint8_t(count-1));payload.insert(payload.end(),sheet.pixels.begin()+i,sheet.pixels.begin()+i+count);}payload.push_back(0);put(304,2);put(38,2);put(uint32_t(payload.size()),4);encoded.insert(encoded.end(),payload.begin(),payload.end());
const auto name="W/"+std::to_string(cell/8)+".VGA";changed_assets_[name]=std::move(encoded);word(db_.raw_club_badge_selectors,club*2,uint16_t((old&~511)|cell));dirty_=true;changes_.push_back("logo:club:"+std::to_string(club));
}
std::filesystem::path Document::save(){
if(!dirty_)return {};
Lock lock(path_);if(read_file(path_)!=original_)throw FormatError("OBD wurde seit dem Oeffnen extern geaendert. Bitte neu oeffnen.");
const auto master=encode_database(db_);
if(master==entries_.at(key(entries_,"M3D.MAN"))){dirty_=false;changes_.clear();return {};}
auto changed=entries_;changed[key(changed,"M3D.MAN")]=master;
if(changed_assets_.empty()&&master==entries_.at(key(entries_,"M3D.MAN"))){dirty_=false;changes_.clear();return {};}
auto changed=entries_;changed[key(changed,"M3D.MAN")]=master;for(const auto&[name,data]:changed_assets_){auto found=std::find_if(changed.begin(),changed.end(),[&](const auto& item){return upper(item.first)==upper(name);});if(found==changed.end())changed[name]=data;else found->second=data;}
auto&manifestBytes=changed.at(key(changed,"PACKAGE.JSON"));auto manifest=cli::parse_json(std::string(manifestBytes.begin(),manifestBytes.end()));cli::Json::Object hashes;
for(const auto&[name,bytes]:changed)if(upper(name)!="PACKAGE.JSON")hashes.emplace(name,sha256(bytes));
(*manifest.object())["files"]=std::move(hashes);
@@ -136,6 +171,6 @@ std::filesystem::path Document::save(){
std::filesystem::rename(temp,path_);
#endif
}catch(...){std::error_code ec;std::filesystem::remove(temp,ec);throw;}
entries_=std::move(changed);original_=output;dirty_=false;changes_.clear();return backup;
entries_=std::move(changed);original_=output;dirty_=false;changes_.clear();changed_assets_.clear();return backup;
}
}
+9
View File
@@ -3,6 +3,8 @@
#include "formats/m3d.hpp"
#include "formats/data_profile.hpp"
#include <map>
#include <array>
#include "formats/vga.hpp"
namespace bmh::obdeddi {
struct PlayerValues {
std::string name;
@@ -20,6 +22,9 @@ public:
int club_of(size_t player) const;
void set_player(size_t,const PlayerValues&);
void set_club(size_t,std::string name,int kit,int short_start,int short_length);
std::array<uint32_t,1444> logo(size_t club) const;
std::array<uint32_t,1444> preview_logo(const std::array<uint32_t,1444>& rgba) const;
void set_logo(size_t club,const std::array<uint32_t,1444>& rgba);
void move_player(size_t player,int club,int swap_player=-1);
// Returns the verified backup path, or an empty path for a no-op.
std::filesystem::path save();
@@ -32,6 +37,10 @@ private:
bool dirty_=false;
std::vector<int> owners_;
std::vector<std::string> changes_;
std::map<std::string,Bytes> changed_assets_;
Image logo_sheet(int page) const;
Image convert_logo(const std::array<uint32_t,1444>&) const;
std::array<uint32_t,256> palette() const;
void refresh_owners();
};
std::string sha256(const Bytes&);
+14
View File
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: GPL-3.0-only
#define NOMINMAX
#include "obdeddi/logo_transform_win32.hpp"
#include <algorithm>
#include <cmath>
#include <stdexcept>
namespace bmh::obdeddi {
std::array<uint32_t,1444> transform_logo(Gdiplus::Bitmap& source,int x,int y,int width,int height,float angle,bool mirror_x,bool mirror_y){
if(x<0||y<0||width<=0||height<=0||int64_t(x)+width>source.GetWidth()||int64_t(y)+height>source.GetHeight()||!std::isfinite(angle)||std::abs(angle)>360)throw std::runtime_error("invalid logo transform");
Gdiplus::Bitmap target(38,38,PixelFormat32bppARGB);
{Gdiplus::Graphics g(&target);g.Clear(Gdiplus::Color(0,0,0,0));g.SetInterpolationMode(Gdiplus::InterpolationModeHighQualityBicubic);g.SetPixelOffsetMode(Gdiplus::PixelOffsetModeHighQuality);float radians=angle*3.14159265358979323846f/180,w=float(width),h=float(height);float extent=std::max(std::abs(std::cos(radians))*w+std::abs(std::sin(radians))*h,std::abs(std::sin(radians))*w+std::abs(std::cos(radians))*h);float scale=36/extent;g.TranslateTransform(19,19);g.RotateTransform(angle);g.ScaleTransform(mirror_x?-1.f:1.f,mirror_y?-1.f:1.f);if(g.DrawImage(&source,Gdiplus::RectF(-w*scale/2,-h*scale/2,w*scale,h*scale),float(x),float(y),w,h,Gdiplus::UnitPixel)!=Gdiplus::Ok)throw std::runtime_error("logo render failed");g.Flush(Gdiplus::FlushIntentionSync);}
std::array<uint32_t,1444> rgba{};for(int py=0;py<38;++py)for(int px=0;px<38;++px){Gdiplus::Color color;if(target.GetPixel(px,py,&color)!=Gdiplus::Ok)throw std::runtime_error("logo pixel read failed");rgba[size_t(py*38+px)]=color.GetValue();}return rgba;
}
}
+9
View File
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include <windows.h>
#include <gdiplus.h>
#include <array>
#include <cstdint>
namespace bmh::obdeddi {
std::array<uint32_t,1444> transform_logo(Gdiplus::Bitmap&,int x,int y,int width,int height,float angle,bool mirror_x,bool mirror_y);
}
+48
View File
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: GPL-3.0-only
#define UNICODE
#define _UNICODE
#define NOMINMAX
#include <windows.h>
#include <commdlg.h>
#include <gdiplus.h>
#include "obdeddi/logo_win32.hpp"
#include "obdeddi/logo_transform_win32.hpp"
#include <algorithm>
#include <cmath>
#include <memory>
#include <string>
namespace bmh::obdeddi {
namespace {
struct Dialog {
HWND window=nullptr,owner=nullptr,edits[5]{},after=nullptr,apply=nullptr;HFONT font=nullptr;
Document* document=nullptr;size_t club=0;int dpi=96;bool done=false,accepted=false,mirrorX=false,mirrorY=false;
ULONG_PTR token=0;std::unique_ptr<Gdiplus::Bitmap> source;std::array<uint32_t,1444> before{},preview{},rgba{};
int px(int n)const{return MulDiv(n,dpi,96);}
HWND child(const wchar_t* cls,const wchar_t* text,DWORD style,int id,int x,int y,int w,int h){auto c=CreateWindowExW(cls==std::wstring(L"EDIT")?WS_EX_CLIENTEDGE:0,cls,text,WS_CHILD|WS_VISIBLE|style,px(x),px(y),px(w),px(h),window,reinterpret_cast<HMENU>(INT_PTR(id)),GetModuleHandleW(nullptr),nullptr);SendMessageW(c,WM_SETFONT,reinterpret_cast<WPARAM>(font),TRUE);return c;}
std::wstring value(int n){wchar_t text[64]{};GetWindowTextW(edits[n],text,64);return text;}
void set(int n,int v){SetWindowTextW(edits[n],std::to_wstring(v).c_str());}
void whole(){if(!source)return;set(0,0);set(1,0);set(2,int(source->GetWidth()));set(3,int(source->GetHeight()));}
void update(){if(!source)return;try{int crop[4];for(int i=0;i<4;++i){auto s=value(i);size_t used=0;crop[i]=std::stoi(s,&used);if(used!=s.size())throw std::runtime_error("number");}auto angleText=value(4);std::replace(angleText.begin(),angleText.end(),L',',L'.');size_t used=0;float angle=std::stof(angleText,&used);if(used!=angleText.size()||!std::isfinite(angle)||angle < -360||angle>360)throw std::runtime_error("angle");
if(crop[0]<0||crop[1]<0||crop[2]<=0||crop[3]<=0||int64_t(crop[0])+crop[2]>source->GetWidth()||int64_t(crop[1])+crop[3]>source->GetHeight())throw std::runtime_error("crop");
rgba=transform_logo(*source,crop[0],crop[1],crop[2],crop[3],angle,mirrorX,mirrorY);preview=document->preview_logo(rgba);InvalidateRect(after,nullptr,TRUE);EnableWindow(apply,TRUE);
}catch(...){EnableWindow(apply,FALSE);MessageBoxW(window,L"Bitte einen gültigen Ausschnitt innerhalb des Bildes und einen Winkel zwischen -360 und 360 eingeben.",L"Vereinslogo",MB_OK|MB_ICONWARNING);}}
void import(){wchar_t path[32768]{};OPENFILENAMEW f{sizeof(f)};f.hwndOwner=window;f.lpstrFilter=L"Bilder (PNG, JPEG, BMP)\0*.png;*.jpg;*.jpeg;*.bmp\0\0";f.lpstrFile=path;f.nMaxFile=32768;f.Flags=OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_NOCHANGEDIR;if(!GetOpenFileNameW(&f))return;auto image=std::unique_ptr<Gdiplus::Bitmap>(Gdiplus::Bitmap::FromFile(path,FALSE));if(!image||image->GetLastStatus()!=Gdiplus::Ok||image->GetWidth()==0||image->GetHeight()==0||image->GetWidth()>16384||image->GetHeight()>16384||uint64_t(image->GetWidth())*image->GetHeight()>64000000){MessageBoxW(window,L"Das Bild konnte nicht geladen werden oder ist zu groß.",L"Vereinslogo",MB_OK|MB_ICONERROR);return;}source=std::move(image);mirrorX=mirrorY=false;set(4,0);whole();update();}
};
void draw(DRAWITEMSTRUCT* item,const std::array<uint32_t,1444>& pixels){FillRect(item->hDC,&item->rcItem,GetSysColorBrush(COLOR_WINDOW));BITMAPINFO info{};info.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);info.bmiHeader.biWidth=38;info.bmiHeader.biHeight=-38;info.bmiHeader.biPlanes=1;info.bmiHeader.biBitCount=32;info.bmiHeader.biCompression=BI_RGB;int size=std::min(int(item->rcItem.right-item->rcItem.left),int(item->rcItem.bottom-item->rcItem.top));int x=item->rcItem.left+(int(item->rcItem.right-item->rcItem.left)-size)/2,y=item->rcItem.top+(int(item->rcItem.bottom-item->rcItem.top)-size)/2;SetStretchBltMode(item->hDC,COLORONCOLOR);StretchDIBits(item->hDC,x,y,size,size,0,0,38,38,pixels.data(),&info,DIB_RGB_COLORS,SRCCOPY);}
LRESULT CALLBACK proc(HWND window,UINT message,WPARAM w,LPARAM l){auto* d=reinterpret_cast<Dialog*>(GetWindowLongPtrW(window,GWLP_USERDATA));if(message==WM_NCCREATE){d=static_cast<Dialog*>(reinterpret_cast<CREATESTRUCTW*>(l)->lpCreateParams);SetWindowLongPtrW(window,GWLP_USERDATA,reinterpret_cast<LONG_PTR>(d));d->window=window;}
if(!d)return DefWindowProcW(window,message,w,l);
if(message==WM_DRAWITEM){auto item=reinterpret_cast<DRAWITEMSTRUCT*>(l);draw(item,item->CtlID==51?d->before:d->preview);return TRUE;}
if(message==WM_COMMAND){switch(LOWORD(w)){case 10:d->import();break;case 11:d->whole();d->update();break;case 12:d->mirrorX=!d->mirrorX;d->update();break;case 13:d->mirrorY=!d->mirrorY;d->update();break;case 14:d->update();break;case IDOK:if(d->source){d->update();if(IsWindowEnabled(d->apply)){try{d->document->set_logo(d->club,d->rgba);d->accepted=true;SendMessageW(window,WM_CLOSE,0,0);}catch(const std::exception&){MessageBoxW(window,L"Das Logo konnte nicht übernommen werden. Bitte die Wappenzuordnung prüfen.",L"Vereinslogo",MB_OK|MB_ICONERROR);}}}break;case IDCANCEL:SendMessageW(window,WM_CLOSE,0,0);break;}return 0;}
if(message==WM_CLOSE){DestroyWindow(window);return 0;}if(message==WM_DESTROY){d->done=true;return 0;}return DefWindowProcW(window,message,w,l);}
}
bool edit_logo(HWND owner,Document& document,size_t club){Dialog d;d.owner=owner;d.document=&document;d.club=club;d.before=document.logo(club);d.preview=d.before;HDC dc=GetDC(owner);d.dpi=GetDeviceCaps(dc,LOGPIXELSX);ReleaseDC(owner,dc);Gdiplus::GdiplusStartupInput startup;if(Gdiplus::GdiplusStartup(&d.token,&startup,nullptr)!=Gdiplus::Ok)throw FormatError("Bildimport kann nicht gestartet werden.");
d.font=CreateFontW(-d.px(14),0,0,0,FW_NORMAL,FALSE,FALSE,FALSE,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,CLEARTYPE_QUALITY,DEFAULT_PITCH,L"Segoe UI");WNDCLASSW wc{};wc.lpfnWndProc=proc;wc.hInstance=GetModuleHandleW(nullptr);wc.hCursor=LoadCursor(nullptr,IDC_ARROW);wc.hbrBackground=GetSysColorBrush(COLOR_BTNFACE);wc.lpszClassName=L"obdeddi.logo";RegisterClassW(&wc);
CreateWindowExW(WS_EX_DLGMODALFRAME|WS_EX_CONTROLPARENT,L"obdeddi.logo",L"Vereinslogo",WS_CAPTION|WS_SYSMENU,CW_USEDEFAULT,CW_USEDEFAULT,d.px(560),d.px(580),owner,nullptr,wc.hInstance,&d);
d.child(L"STATIC",L"Bisher",0,0,18,12,230,24);d.child(L"STATIC",L"Vorschau im Originalformat",0,0,286,12,250,24);d.child(L"STATIC",L"",SS_OWNERDRAW|WS_BORDER,51,28,42,190,190);d.after=d.child(L"STATIC",L"",SS_OWNERDRAW|WS_BORDER,52,310,42,190,190);
d.child(L"BUTTON",L"Bild importieren…",WS_TABSTOP,10,18,247,220,28);d.child(L"BUTTON",L"Ganzes Bild",WS_TABSTOP,11,286,247,250,28);
const wchar_t* labels[]={L"Links",L"Oben",L"Breite",L"Höhe"};for(int i=0;i<4;++i){d.child(L"STATIC",labels[i],0,0,18+i*130,290,120,22);d.edits[i]=d.child(L"EDIT",L"0",WS_TABSTOP|ES_AUTOHSCROLL,30+i,18+i*130,315,118,24);}
d.child(L"STATIC",L"Drehung (Grad)",0,0,18,359,120,22);d.edits[4]=d.child(L"EDIT",L"0",WS_TABSTOP|ES_AUTOHSCROLL,34,150,353,86,24);d.child(L"BUTTON",L"Horizontal spiegeln",WS_TABSTOP,12,260,350,276,28);d.child(L"BUTTON",L"Vertikal spiegeln",WS_TABSTOP,13,260,386,276,28);d.child(L"BUTTON",L"Vorschau aktualisieren",WS_TABSTOP,14,18,395,220,28);
d.child(L"STATIC",L"38 × 38 Pixel, Originalpalette, heller Original-Hintergrund. Speichern erfolgt anschließend im Hauptfenster mit Backup.",0,0,18,433,518,38);d.apply=d.child(L"BUTTON",L"Übernehmen",WS_TABSTOP|BS_DEFPUSHBUTTON,IDOK,260,478,132,28);d.child(L"BUTTON",L"Abbrechen",WS_TABSTOP,IDCANCEL,402,478,134,28);EnableWindow(d.apply,FALSE);
EnableWindow(owner,FALSE);ShowWindow(d.window,SW_SHOW);UpdateWindow(d.window);MSG m{};while(!d.done&&GetMessageW(&m,nullptr,0,0)>0){if(!IsDialogMessageW(d.window,&m)){TranslateMessage(&m);DispatchMessageW(&m);}}EnableWindow(owner,TRUE);SetActiveWindow(owner);d.source.reset();DeleteObject(d.font);Gdiplus::GdiplusShutdown(d.token);return d.accepted;
}
}
+5
View File
@@ -0,0 +1,5 @@
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include <windows.h>
#include "obdeddi/document.hpp"
namespace bmh::obdeddi { bool edit_logo(HWND owner,Document&,size_t club); }
+5 -4
View File
@@ -7,6 +7,7 @@
#include <commdlg.h>
#include <shellapi.h>
#include "obdeddi/document.hpp"
#include "obdeddi/logo_win32.hpp"
#include <algorithm>
#include <cwctype>
#include <memory>
@@ -23,7 +24,7 @@ HFONT font;int dpi=96,mode=0,selected=-1,sortColumn=0,scrollPos=0;
bool ascending=true,updating=false,formDirty=false;
std::unique_ptr<Document> document;
std::vector<int> visible;std::vector<HWND> fields;std::wstring displayText;
constexpr int Open=100,Save=101,Search=102,Filter=103,Apply=104,Target=105,Swap=106,Move=107,Tabs=108;
constexpr int Open=100,Save=101,Search=102,Filter=103,Apply=104,Target=105,Swap=106,Move=107,Tabs=108,Logo=109;
int px(int n){return MulDiv(n,dpi,96);}
std::wstring wide(const std::string& text){int n=MultiByteToWideChar(CP_UTF8,MB_ERR_INVALID_CHARS,text.data(),int(text.size()),nullptr,0);std::wstring out(size_t(n),L' ');if(n)MultiByteToWideChar(CP_UTF8,0,text.data(),int(text.size()),out.data(),n);return out;}
std::wstring original(const std::string& text){return wide(bmh::iso646de_to_utf8(text.c_str()));}
@@ -56,7 +57,7 @@ void buildForm(){updating=true;formDirty=false;selected=selected<0?-1:selected;f
control(L"STATIC",L"Tauschpartner",0,0,8,588,125,24,panel);swapBox=control(L"COMBOBOX",L"",CBS_DROPDOWNLIST|WS_VSCROLL|WS_TABSTOP,Swap,138,584,228,240,panel);setSwapOptions();control(L"BUTTON",L"Kaderwechsel",WS_TABSTOP,Move,8,621,358,28,panel);bool assigned=document->club_of(size_t(selected))>=0;EnableWindow(target,assigned);EnableWindow(swapBox,assigned);EnableWindow(GetDlgItem(panel,Move),assigned);
}else{auto id=size_t(selected);formField(L"Vereinsname",0,original(db.club_names[id]));formField(L"Trikot-Farbset",1,L"",true);for(int i=0;i<256;++i){if(std::find(db.raw_club_kit_selectors.begin(),db.raw_club_kit_selectors.end(),uint8_t(i))==db.raw_club_kit_selectors.end())continue;int row=int(SendMessageW(fields[1],CB_ADDSTRING,0,reinterpret_cast<LPARAM>((L"Farbset "+std::to_wstring(i)).c_str())));SendMessageW(fields[1],CB_SETITEMDATA,WPARAM(row),i);if(db.raw_club_kit_selectors[id]==i)SendMessageW(fields[1],CB_SETCURSEL,WPARAM(row),0);}
auto span=id<db.raw_club_short_name_offsets.size()?db.raw_club_short_name_offsets[id]:uint8_t(0);formField(L"Beginn (0–15)",2,std::to_wstring(span>>4));formField(L"Länge (1–16)",3,std::to_wstring((span&15)+1));if(id>=db.raw_club_short_name_offsets.size()){EnableWindow(fields[2],FALSE);EnableWindow(fields[3],FALSE);}
control(L"STATIC",L"Liga und Datensatzanzahlen bleiben fest. Wappen und andere Assets werden nicht bearbeitet.",0,0,8,130,358,60,panel);control(L"BUTTON",L"Werte übernehmen",WS_TABSTOP,Apply,8,205,358,28,panel);
control(L"STATIC",L"Liga und Datensatzanzahlen bleiben fest. Wappen und andere Weitere Assets bleiben unverändert.",0,0,8,130,358,60,panel);control(L"BUTTON",L"Werte übernehmen",WS_TABSTOP,Apply,8,205,358,28,panel);control(L"BUTTON",L"Vereinslogo bearbeiten…",WS_TABSTOP,Logo,8,250,358,28,panel);
}
RECT r;GetClientRect(panel,&r);SCROLLINFO si{sizeof(si),SIF_RANGE|SIF_PAGE|SIF_POS,0,px(mode==0?670:250),UINT(r.bottom),0,0};SetScrollInfo(panel,SB_VERT,&si,TRUE);updating=false;
}
@@ -75,7 +76,7 @@ void open(){if(!mayClose())return;wchar_t path[32768]{};OPENFILENAMEW ofn{sizeof
LRESULT CALLBACK formProc(HWND h,UINT m,WPARAM w,LPARAM l){if(m==WM_SIZE){SCROLLINFO si{sizeof(si),SIF_PAGE};si.nPage=UINT(HIWORD(l));SetScrollInfo(h,SB_VERT,&si,TRUE);int next=GetScrollPos(h,SB_VERT);ScrollWindowEx(h,0,scrollPos-next,nullptr,nullptr,nullptr,nullptr,SW_SCROLLCHILDREN|SW_INVALIDATE|SW_ERASE);scrollPos=next;return 0;}if(m==WM_COMMAND)return SendMessageW(window,m,w,l);if(m==WM_VSCROLL||m==WM_MOUSEWHEEL){SCROLLINFO si{sizeof(si),SIF_ALL};GetScrollInfo(h,SB_VERT,&si);int next=scrollPos;if(m==WM_MOUSEWHEEL)next-=GET_WHEEL_DELTA_WPARAM(w)/WHEEL_DELTA*px(60);else switch(LOWORD(w)){case SB_LINEUP:next-=px(27);break;case SB_LINEDOWN:next+=px(27);break;case SB_PAGEUP:next-=int(si.nPage);break;case SB_PAGEDOWN:next+=int(si.nPage);break;case SB_THUMBTRACK:next=si.nTrackPos;break;};next=std::clamp(next,0,std::max(0,si.nMax-int(si.nPage)+1));ScrollWindowEx(h,0,scrollPos-next,nullptr,nullptr,nullptr,nullptr,SW_SCROLLCHILDREN|SW_INVALIDATE|SW_ERASE);scrollPos=next;SetScrollPos(h,SB_VERT,next,TRUE);return 0;}return DefWindowProcW(h,m,w,l);}
LRESULT CALLBACK proc(HWND h,UINT m,WPARAM w,LPARAM l){switch(m){case WM_SIZE:{RECT r;GetClientRect(h,&r);int right=std::max(px(420),int(r.right)-px(400));MoveWindow(list,px(12),px(92),right-px(24),r.bottom-px(132),TRUE);MoveWindow(panel,right,px(92),r.right-right-px(12),r.bottom-px(132),TRUE);MoveWindow(status,px(12),r.bottom-px(30),r.right-px(24),px(24),TRUE);return 0;}
case WM_GETMINMAXINFO:{auto p=reinterpret_cast<MINMAXINFO*>(l);p->ptMinTrackSize={px(940),px(630)};return 0;}
case WM_COMMAND:{int id=LOWORD(w),code=HIWORD(w);if(updating)return 0;if(id==Open){open();return 0;}if(id==Save){save();return 0;}if(id==Apply){if(apply())buildForm();return 0;}if(id==Search&&code==EN_CHANGE){SetTimer(h,1,180,nullptr);return 0;}if(id==Filter&&code==CBN_SELCHANGE){if(apply())rebuild();return 0;}if(id==Target&&code==CBN_SELCHANGE){setSwapOptions();return 0;}if(id==Move){if(!apply())return 0;try{int partner=int(SendMessageW(swapBox,CB_GETITEMDATA,WPARAM(combo(swapBox)),0));document->move_player(size_t(selected),combo(target),partner);caption();rebuild();}catch(const std::exception&e){error(e);}return 0;}if(id>=200&&id<220&&(code==EN_CHANGE||code==CBN_SELCHANGE))formDirty=true;return 0;}
case WM_COMMAND:{int id=LOWORD(w),code=HIWORD(w);if(updating)return 0;if(id==Open){open();return 0;}if(id==Save){save();return 0;}if(id==Apply){if(apply())buildForm();return 0;}if(id==Search&&code==EN_CHANGE){SetTimer(h,1,180,nullptr);return 0;}if(id==Filter&&code==CBN_SELCHANGE){if(apply())rebuild();return 0;}if(id==Target&&code==CBN_SELCHANGE){setSwapOptions();return 0;}if(id==Logo){if(!apply())return 0;try{if(document&&selected>=0&&bmh::obdeddi::edit_logo(window,*document,size_t(selected)))caption();}catch(const std::exception&e){error(e);}return 0;}if(id==Move){if(!apply())return 0;try{int partner=int(SendMessageW(swapBox,CB_GETITEMDATA,WPARAM(combo(swapBox)),0));document->move_player(size_t(selected),combo(target),partner);caption();rebuild();}catch(const std::exception&e){error(e);}return 0;}if(id>=200&&id<220&&(code==EN_CHANGE||code==CBN_SELCHANGE))formDirty=true;return 0;}
case WM_TIMER:KillTimer(h,1);if(apply())rebuild();return 0;
case WM_NOTIFY:{auto hdr=reinterpret_cast<NMHDR*>(l);if(hdr->hwndFrom==tab&&hdr->code==TCN_SELCHANGING)return apply()?FALSE:TRUE;if(hdr->hwndFrom==tab&&hdr->code==TCN_SELCHANGE){mode=TabCtrl_GetCurSel(tab);selected=-1;sortColumn=0;ascending=true;EnableWindow(filter,mode==0);columns();rebuild();return 0;}if(hdr->hwndFrom!=list)return 0;
if(hdr->code==LVN_GETDISPINFOW){auto info=reinterpret_cast<NMLVDISPINFOW*>(l);if(info->item.iItem>=0&&size_t(info->item.iItem)<visible.size()){displayText=cell(visible[size_t(info->item.iItem)],info->item.iSubItem);info->item.pszText=displayText.data();}return 0;}
@@ -91,6 +92,6 @@ int WINAPI wWinMain(HINSTANCE instance,HINSTANCE,PWSTR,int show){SetProcessDPIAw
control(L"BUTTON",L"Öffnen…",WS_TABSTOP,Open,12,12,94,28,window);saveButton=control(L"BUTTON",L"Speichern",WS_TABSTOP,Save,114,12,94,28,window);search=control(L"EDIT",L"",ES_AUTOHSCROLL|WS_TABSTOP,Search,228,14,265,25,window);SendMessageW(search,EM_SETCUEBANNER,TRUE,reinterpret_cast<LPARAM>(L"Suchen …"));filter=control(L"COMBOBOX",L"",CBS_DROPDOWNLIST|WS_VSCROLL|WS_TABSTOP,Filter,510,12,350,300,window);
tab=control(WC_TABCONTROLW,L"",WS_TABSTOP,Tabs,12,54,300,30,window);for(int i=0;i<2;++i){TCITEMW item{};item.mask=TCIF_TEXT;item.pszText=const_cast<wchar_t*>(i==0?L"Spieler":L"Vereine");TabCtrl_InsertItem(tab,i,&item);}
list=control(WC_LISTVIEWW,L"",LVS_REPORT|LVS_OWNERDATA|LVS_SINGLESEL|LVS_SHOWSELALWAYS|WS_TABSTOP,120,12,92,650,600,window);ListView_SetExtendedListViewStyle(list,LVS_EX_FULLROWSELECT|LVS_EX_DOUBLEBUFFER|LVS_EX_LABELTIP);
panel=control(L"obdeddi.form",L"",WS_VSCROLL|WS_CLIPCHILDREN,0,780,92,380,600,window);SetWindowLongPtrW(panel,GWL_EXSTYLE,GetWindowLongPtrW(panel,GWL_EXSTYLE)|WS_EX_CONTROLPARENT);status=control(L"STATIC",L"Eine COMMUNITY.OBD öffnen. Assets werden nicht bearbeitet.",SS_LEFT,0,12,720,1100,24,window);columns();caption();ShowWindow(window,show);SendMessageW(window,WM_SIZE,0,0);UpdateWindow(window);
panel=control(L"obdeddi.form",L"",WS_VSCROLL|WS_CLIPCHILDREN,0,780,92,380,600,window);SetWindowLongPtrW(panel,GWL_EXSTYLE,GetWindowLongPtrW(panel,GWL_EXSTYLE)|WS_EX_CONTROLPARENT);status=control(L"STATIC",L"Eine COMMUNITY.OBD öffnen. Weitere Assets bleiben unverändert.",SS_LEFT,0,12,720,1100,24,window);columns();caption();ShowWindow(window,show);SendMessageW(window,WM_SIZE,0,0);UpdateWindow(window);
int argumentCount=0;auto arguments=CommandLineToArgvW(GetCommandLineW(),&argumentCount);if(arguments&&argumentCount>1)load(arguments[1]);if(arguments)LocalFree(arguments);
ACCEL keys[]={{FVIRTKEY|FCONTROL,'O',Open},{FVIRTKEY|FCONTROL,'S',Save}};HACCEL accel=CreateAcceleratorTableW(keys,2);MSG message{};while(GetMessageW(&message,nullptr,0,0)>0){if(!TranslateAcceleratorW(window,accel,&message)&&!IsDialogMessageW(window,&message)){TranslateMessage(&message);DispatchMessageW(&message);}}DestroyAcceleratorTable(accel);DeleteObject(font);return int(message.wParam);}
+13
View File
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: GPL-3.0-only
#define NOMINMAX
#include "obdeddi/logo_transform_win32.hpp"
#include <iostream>
#include <stdexcept>
void check(bool ok,const char* message){if(!ok)throw std::runtime_error(message);}
int main()try{Gdiplus::GdiplusStartupInput input;ULONG_PTR token=0;check(Gdiplus::GdiplusStartup(&token,&input,nullptr)==Gdiplus::Ok,"GDI startup");
{Gdiplus::Bitmap source(16,8,PixelFormat32bppARGB);for(int y=0;y<8;++y)for(int x=0;x<16;++x)source.SetPixel(x,y,x<8?Gdiplus::Color(255,255,0,0):Gdiplus::Color(255,0,0,255));
auto normal=bmh::obdeddi::transform_logo(source,0,0,16,8,0,false,false);auto mirror=bmh::obdeddi::transform_logo(source,0,0,16,8,0,true,false);auto rotate=bmh::obdeddi::transform_logo(source,0,0,16,8,180,false,false);auto crop=bmh::obdeddi::transform_logo(source,0,0,8,8,0,false,false);
check((normal[19*38+8]&0xffffff)==0xff0000,"normal left color");check((mirror[19*38+8]&0xffffff)==0xff,"horizontal mirror");check((rotate[19*38+8]&0xffffff)==0xff,"rotation");check((crop[19*38+30]&0xffffff)==0xff0000,"crop respects source rectangle");check((normal[0]>>24)==0,"transparent fit border");
bool rejected=false;try{bmh::obdeddi::transform_logo(source,-1,0,16,8,0,false,false);}catch(...){rejected=true;}check(rejected,"invalid crop accepted");}
Gdiplus::GdiplusShutdown(token);std::cout<<"Native logo crop, rotation, mirroring and alpha passed\n";return 0;
}catch(const std::exception&e){std::cerr<<e.what()<<'\n';return 1;}
+2 -1
View File
@@ -22,12 +22,13 @@ int main()try{
check(app::scene_frame_delay(80)==100&&app::scene_frame_delay(0)==16,"scene pacing mapping");
auto db=synthetic();auto master=encode_database(db);check(encode_database(decode_database(master,db.counts))==master,"master roundtrip");
auto root=std::filesystem::temp_directory_path()/("obdeddi-test-"+std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()));std::filesystem::create_directories(root);
auto runtime=bytes("OBMHDAT1");runtime.resize(36);const Bytes asset{3,17,91,0,255};auto input=archive({{"M3D.MAN",master},{"RUNTIME.DAT",runtime},{"OBMHPROF.INI",bytes("[OpenBMH]\nprofile=classic-plus-1\n")},{"KB/1.VGA",asset}});auto path=root/std::filesystem::path(std::u8string(u8"Saison-ä.obd"));write(path,input);
auto runtime=bytes("OBMHDAT1");runtime.resize(36);const Bytes asset{3,17,91,0,255};Bytes palette(768,0);for(size_t i=0;i<256;++i)for(int c=0;c<3;++c)palette[i*3+size_t(c)]=uint8_t(std::min(size_t(63),i/4));palette[10*3]=63;palette[10*3+1]=palette[10*3+2]=0;palette[20*3]=palette[20*3+1]=0;palette[20*3+2]=63;Bytes pixels(304*38,94),vga;auto putHeader=[&](uint32_t v,int n){for(int b=0;b<n;++b)vga.push_back(uint8_t(v>>(b*8)));};Bytes payload;for(size_t i=0;i<pixels.size();i+=128){size_t n=std::min(size_t(128),pixels.size()-i);payload.push_back(uint8_t(n-1));payload.insert(payload.end(),pixels.begin()+i,pixels.begin()+i+n);}payload.push_back(0);putHeader(304,2);putHeader(38,2);putHeader(uint32_t(payload.size()),4);vga.insert(vga.end(),payload.begin(),payload.end());auto input=archive({{"M3D.MAN",master},{"RUNTIME.DAT",runtime},{"OBMHPROF.INI",bytes("[OpenBMH]\nprofile=classic-plus-1\n")},{"KB/1.VGA",asset},{"M3PC.COL",palette},{"W/0.VGA",vga}});auto path=root/std::filesystem::path(std::u8string(u8"Saison-ä.obd"));write(path,input);
Document doc(path);check(!doc.dirty()&&doc.save().empty()&&read_file(path)==input,"no-op wrote a file");
auto player=doc.player(0);auto high=db.players[0].w35c&~0x1fffffu;player.name="M}LLER";player.nation=61;player.age=30;player.form=75;player.skills[2]=3;doc.set_player(0,player);check((doc.database().players[0].w35c&~0x1fffffu)==high,"unrelated player bits changed");
auto invalid=player;invalid.skills[0]=4;bool rejected=false;try{doc.set_player(1,invalid);}catch(const FormatError&){rejected=true;}check(rejected,"invalid skill accepted");
doc.set_club(0,"NEUER VEREIN",3,0,12);doc.move_player(0,1);check(doc.club_of(0)==1&&doc.club_of(20)==1,"move failed");doc.move_player(1,1,20);check(doc.club_of(1)==1&&doc.club_of(20)==0,"swap failed");
auto backup=doc.save();check(!backup.empty()&&read_file(backup)==input,"backup not exact");check(entry(path,"KB/1.VGA")==asset,"asset modified");Document loaded(path);check(loaded.player(0).name=="M}LLER"&&loaded.player(0).nation==61&&loaded.database().club_names[0]=="NEUER VEREIN","edited data not persisted");check(loaded.club_of(0)==1&&loaded.club_of(20)==0,"saved roster changed");
auto logoPath=root/"logos.obd";write(logoPath,input);Document logos(logoPath);auto originalSelectors=logos.database().raw_club_badge_selectors;std::array<uint32_t,1444> rgba{};rgba.fill(0xffff0000);auto preview=logos.preview_logo(rgba);logos.set_logo(0,rgba);check(logos.logo(0)==preview,"logo preview differs from stored palette result");check(le16(logos.database().raw_club_badge_selectors,0)==1,"shared logo was not cloned");check(le16(logos.database().raw_club_badge_selectors,2)==0,"neighbour selector changed");logos.save();auto firstMaster=entry(logoPath,"M3D.MAN");auto sheet=decode_vga(entry(logoPath,"W/0.VGA"));for(int y=0;y<38;++y)for(int x=0;x<304;++x)if(x<38||x>=76)check(sheet.pixels[size_t(y*304+x)]==94,"neighbour pixels changed");rgba.fill(0xff0000ff);logos.set_logo(0,rgba);logos.save();check(entry(logoPath,"M3D.MAN")==firstMaster,"logo-only save changed database");Document logoReload(logoPath);check(logoReload.logo(0)==logoReload.preview_logo(rgba),"logo-only edit was not saved");
auto changed=loaded.player(2);changed.form=40;loaded.set_player(2,changed);auto outside=read_file(path);outside.push_back(0);write(path,outside);rejected=false;try{loaded.save();}catch(const FormatError&){rejected=true;}check(rejected&&read_file(path)==outside,"external edit overwritten");
auto failRoot=root/"backup-failure";std::filesystem::create_directory(failRoot);auto failPath=failRoot/"COMMUNITY.OBD";write(failPath,input);write(failRoot/"backups",bytes("not a directory"));Document failure(failPath);auto value=failure.player(0);value.form=12;failure.set_player(0,value);rejected=false;try{failure.save();}catch(const std::exception&){rejected=true;}check(rejected&&read_file(failPath)==input,"backup failure changed original");
auto corrupt=input;corrupt.resize(12);write(root/"bad.obd",corrupt);rejected=false;try{Document bad(root/"bad.obd");}catch(const std::exception&){rejected=true;}check(rejected,"truncated archive accepted");
+1 -1
View File
@@ -21,7 +21,7 @@ def package(build,game,out):
'Vollstaendig entpacken und obdeddi.exe starten. COMMUNITY.OBD ueber Oeffnen waehlen.\n'
'Spieler und Vereine bearbeiten; Suche, Sortierung und Kaderwechsel stehen zur Verfuegung.\n'
'Speichern ersetzt die OBD erst nach geprueftem Backup im Unterverzeichnis backups.\n'
'Assets werden nicht bearbeitet. Festes Ligaset und feste Datensatzanzahlen bleiben erhalten.\n'
'Vereinslogos: PNG/JPEG/BMP importieren, zuschneiden, drehen und spiegeln; Vorschau im Originalformat. Andere Assets bleiben unveraendert. Festes Ligaset und feste Datensatzanzahlen bleiben erhalten.\n'
'Classic-Eigenheit: Viele Werte werden beim Karrierestart neu erzeugt. Bestehende Spielstaende bleiben unveraendert.\n'
'Tasten: Strg+O oeffnen, Strg+S speichern. Alternativ: obdeddi.exe "Pfad\\COMMUNITY.OBD".\n\n'
'GPL-3.0-only; vollstaendige passende Quellen und Abhaengigkeiten separat:\n'